You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by sa...@apache.org on 2013/05/23 03:50:42 UTC

[01/10] git commit: updated refs/heads/vmware-datamodel to 599b826

Updated Branches:
  refs/heads/vmware-datamodel 8996ea386 -> 599b82695


CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Plugin, API & DB changes


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3a37fa1e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3a37fa1e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3a37fa1e

Branch: refs/heads/vmware-datamodel
Commit: 3a37fa1e73268a96d307ca8647b8350f016275c7
Parents: 49e39e5
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Fri May 3 22:38:57 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Wed May 22 19:25:55 2013 +0530

----------------------------------------------------------------------
 client/tomcatconf/nonossComponentContext.xml.in    |    2 +
 .../cloud/hypervisor/vmware/VmwareDatacenter.java  |   23 ++
 .../hypervisor/vmware/VmwareDatacenterService.java |   15 +
 .../hypervisor/vmware/VmwareDatacenterVO.java      |  155 ++++++++
 .../hypervisor/vmware/VmwareDatacenterZoneMap.java |   13 +
 .../vmware/VmwareDatacenterZoneMapVO.java          |   77 ++++
 .../hypervisor/vmware/VmwareServerDiscoverer.java  |   80 ++++-
 .../hypervisor/vmware/dao/VmwareDatacenterDao.java |   48 +++
 .../vmware/dao/VmwareDatacenterDaoImpl.java        |   87 +++++
 .../vmware/dao/VmwareDatacenterZoneMapDao.java     |   18 +
 .../vmware/dao/VmwareDatacenterZoneMapDaoImpl.java |   61 +++
 .../vmware/manager/VmwareManagerImpl.java          |  302 ++++++++++++++-
 .../api/command/admin/zone/AddVmwareDcCmd.java     |  103 +++++
 .../api/command/admin/zone/RemoveVmwareDcCmd.java  |   80 ++++
 .../api/response/VmwareDatacenterResponse.java     |   34 ++
 setup/db/db/schema-410to420.sql                    |   18 +
 .../hypervisor/vmware/mo/CustomFieldConstants.java |    1 +
 .../cloud/hypervisor/vmware/mo/DatacenterMO.java   |    5 +
 18 files changed, 1118 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/client/tomcatconf/nonossComponentContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/nonossComponentContext.xml.in b/client/tomcatconf/nonossComponentContext.xml.in
index 1b6ee6e..99ef8df 100644
--- a/client/tomcatconf/nonossComponentContext.xml.in
+++ b/client/tomcatconf/nonossComponentContext.xml.in
@@ -77,6 +77,8 @@
   </bean>
   <bean id="VmwareManager" class="com.cloud.hypervisor.vmware.manager.VmwareManagerImpl"/>
   <bean id="vmwareContextFactory" class="com.cloud.hypervisor.vmware.resource.VmwareContextFactory" />
+  <bean id="VmwareDatacenterDaoImpl" class="com.cloud.hypervisor.vmware.dao.VmwareDatacenterDaoImpl" />
+  <bean id="VmwareDatacenterZoneMapDaoImpl" class="com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDaoImpl" />
 
   <!--
     Nicira support components

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
new file mode 100644
index 0000000..246b477
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
@@ -0,0 +1,23 @@
+package com.cloud.hypervisor.vmware;
+
+import org.apache.cloudstack.api.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+import com.vmware.vim25.ManagedObjectReference;
+
+public interface VmwareDatacenter extends Identity, InternalIdentity {
+
+    String getVmwareDatacenterName();
+
+    ManagedObjectReference getVmwareDatacenterMor();
+
+    String getGuid();
+
+    String getVcenterHost();
+
+    long getId();
+
+    String getPassword();
+
+    String getUser();
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
new file mode 100644
index 0000000..f04b2b5
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
@@ -0,0 +1,15 @@
+package com.cloud.hypervisor.vmware;
+
+import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
+import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd;
+
+import com.cloud.exception.DiscoveryException;
+import com.cloud.exception.ResourceInUseException;
+import com.cloud.utils.component.PluggableService;
+
+public interface VmwareDatacenterService extends PluggableService {
+
+    public VmwareDatacenterVO addVmwareDatacenter(AddVmwareDcCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException, Exception;
+
+    public boolean removeVmwareDatacenter(RemoveVmwareDcCmd cmd) throws IllegalArgumentException, ResourceInUseException, Exception;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
new file mode 100644
index 0000000..aaeccc2
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
@@ -0,0 +1,155 @@
+package com.cloud.hypervisor.vmware;
+
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.db.Encrypt;
+import com.vmware.vim25.ManagedObjectReference;
+
+/**
+ * VmwareDatacenterVO contains information of Vmware Datacenter associated with a CloudStack zone.
+ */
+
+@Entity
+@Table(name="vmware_data_center")
+public class VmwareDatacenterVO implements VmwareDatacenter {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "guid")
+    private String guid;
+
+    @Column(name = "name")
+    private String name;
+
+    @Column(name = "vcenter_host")
+    private String vCenterHost;
+
+    @Column(name = "uuid")
+    private String uuid;
+
+    @Column(name = "username")
+    private String user;
+
+    @Encrypt
+    @Column(name = "password")
+    private String password;
+
+    @Override
+    public String getUuid() {
+        return uuid;
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public String getVmwareDatacenterName() {
+        return name;
+    }
+
+    @Override
+    public String getGuid() {
+        return guid;
+    }
+
+    @Override
+    public String getUser() {
+        return user;
+    }
+
+    @Override
+    public String getPassword() {
+        return password;
+    }
+
+    @Override
+    public ManagedObjectReference getVmwareDatacenterMor() {
+        String morString = guid.split("@")[0];
+        ManagedObjectReference mor = new ManagedObjectReference();
+
+        mor.setType(morString.split(":")[0]);
+        mor.setValue(morString.split(":")[1]);
+
+        return mor;
+    }
+
+    @Override
+    public String getVcenterHost() {
+        return vCenterHost;
+    }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
+
+    public void setGuid(String guid) {
+        this.guid = guid;
+    }
+
+    public void setVmwareDatacenterName(String name) {
+        this.name = name;
+    }
+
+    public void setVcenterHost(String vCenterHost) {
+        this.vCenterHost = vCenterHost;
+    }
+
+    public void setUser(String user) {
+        this.user = user; ;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    @Override
+    public String toString() {
+        return new StringBuilder("VmwareDatacenter[").append(guid).append("]").toString();
+    }
+
+    @Override
+    public int hashCode() {
+        return NumbersUtil.hash(id);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof VmwareDatacenterVO) {
+            return ((VmwareDatacenterVO)obj).getId() == this.getId();
+        } else {
+            return false;
+        }
+    }
+
+    public VmwareDatacenterVO(String guid, String name, String vCenterHost, String user, String password) {
+        this.uuid = UUID.randomUUID().toString();
+        this.name = name;
+        this.guid = guid;
+        this.vCenterHost = vCenterHost;
+        this.user = user;
+        this.password = password;
+    }
+
+    public VmwareDatacenterVO(long id, String guid, String name, String vCenterHost, String user, String password) {
+        this(guid, name, vCenterHost, user, password);
+        this.id = id;
+    }
+
+    public VmwareDatacenterVO() {
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java
new file mode 100644
index 0000000..840c633
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java
@@ -0,0 +1,13 @@
+package com.cloud.hypervisor.vmware;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import com.cloud.org.Grouping;
+
+public interface VmwareDatacenterZoneMap extends Grouping, InternalIdentity {
+    public long getId();
+
+    public long getZoneId();
+
+    public long getVmwareDcId();
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
new file mode 100644
index 0000000..e20386d
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
@@ -0,0 +1,77 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied.  See the License for the
+//specific language governing permissions and limitations
+//under the License.
+package com.cloud.hypervisor.vmware;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+
+//NOTE: This particular table is totally internal to the CS MS.
+//Do not ever include a uuid/guid field in this table. We just
+//need it map zone ids with VMware datacenter Ids.
+
+@Entity
+@Table(name="vmware_data_center_zone_map")
+public class VmwareDatacenterZoneMapVO implements VmwareDatacenterZoneMap {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name="id")
+    private long id;
+
+    @Column(name="zone_id")
+    private long zoneId;
+
+    @Column(name="vmware_data_center_id")
+    private long vmwareDcId;
+
+    public VmwareDatacenterZoneMapVO(long zoneId, long vmwareDcId) {
+        this.zoneId = zoneId;
+        this.vmwareDcId = vmwareDcId;
+    }
+
+    public VmwareDatacenterZoneMapVO() {
+        // Do nothing.
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+    
+    @Override
+    public long getZoneId() {
+        return zoneId;
+    }
+
+    @Override
+    public long getVmwareDcId() {
+        return vmwareDcId;
+    }
+
+     public void setZoneId(long zoneId) {
+        this.zoneId = zoneId;
+    }
+
+    public void setVsmId(long vmwareDcId) {
+        this.vmwareDcId = vmwareDcId;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
index 2f82b53..aec44b3 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
@@ -30,6 +30,7 @@ import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
 import org.apache.cloudstack.api.ApiConstants;
+import org.springframework.beans.NullValueInNestedPathException;
 
 import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.api.StartupRoutingCommand;
@@ -51,6 +52,8 @@ import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
+import com.cloud.hypervisor.vmware.dao.VmwareDatacenterDao;
+import com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDao;
 import com.cloud.hypervisor.vmware.manager.VmwareManager;
 import com.cloud.hypervisor.vmware.mo.ClusterMO;
 import com.cloud.hypervisor.vmware.mo.HostMO;
@@ -107,11 +110,16 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
 	@Inject
 	CiscoNexusVSMDeviceDao _nexusDao;
 	@Inject
-	CiscoNexusVSMElementService _nexusElement;
+	CiscoNexusVSMElement _nexusElement;
 	@Inject
     NetworkModel _netmgr;
     @Inject
     HypervisorCapabilitiesDao _hvCapabilitiesDao;
+    @Inject
+    VmwareDatacenterZoneMapDao _vmwareDcZoneMapDao;
+    @Inject
+    VmwareDatacenterDao _vmwareDcDao;
+
     protected Map<String, String> _urlParams;
     protected boolean useDVS = false;
     protected boolean nexusDVS = false;
@@ -140,6 +148,18 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
 			return null;
 		}
 
+        Map<String, String> clusterDetails = _clusterDetailsDao.findDetails(clusterId);
+        boolean legacyZone = false;
+        //Check if NOT a legacy zone.
+        if (!legacyZone) {
+            String updatedInventoryPath = validateCluster(dcId, url, username, password);
+            if (url.getPath() != updatedInventoryPath) {
+                // If url from API doesn't specifiy DC then update url in database with DC assocaited with this zone.
+                clusterDetails.put("url", url.getScheme() + "://" + url.getHost() + updatedInventoryPath);
+                _clusterDetailsDao.persist(clusterId, clusterDetails);
+            }
+        }
+
         List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
         if (hosts != null && hosts.size() > 0) {
             int maxHostsPerCluster = _hvCapabilitiesDao.getMaxHostsPerCluster(hosts.get(0).getHypervisorType(), hosts.get(0).getHypervisorVersion());
@@ -164,7 +184,6 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
 
         VmwareTrafficLabel guestTrafficLabelObj = new VmwareTrafficLabel(TrafficType.Guest);
         VmwareTrafficLabel publicTrafficLabelObj = new VmwareTrafficLabel(TrafficType.Public);
-        Map<String, String> clusterDetails = _clusterDetailsDao.findDetails(clusterId);
         DataCenterVO zone = _dcDao.findById(dcId);
         NetworkType zoneType = zone.getNetworkType();
         _readGlobalConfigParameters();
@@ -395,6 +414,63 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
 		}
 	}
 
+    private String validateCluster(Long dcId, URI url, String username, String password) throws DiscoveryException {
+        String msg;
+        long vmwareDcId;
+        VmwareDatacenterVO vmwareDc;
+        String vmwareDcNameFromDb;
+        String vmwareDcNameFromApi;
+        String vCenterHost;
+        String updatedInventoryPath = url.getPath();
+        String clusterName = null;
+
+        // Check if zone is associated with DC
+        VmwareDatacenterZoneMapVO vmwareDcZone = _vmwareDcZoneMapDao.findByZoneId(dcId);
+        if (vmwareDcZone == null) {
+            msg = "Zone " + dcId + " is not associated with any VMware DC yet. "
+                        + "Please add VMware DC to this zone first and then try to add clusters.";
+            s_logger.error(msg);
+            throw new DiscoveryException(msg);
+        }
+
+        // Retrieve DC added to this zone from database
+        vmwareDcId = vmwareDcZone.getVmwareDcId();
+        vmwareDc = _vmwareDcDao.findById(vmwareDcId);
+        vmwareDcNameFromApi = vmwareDcNameFromDb = vmwareDc.getVmwareDatacenterName();
+        vCenterHost = vmwareDc.getVcenterHost();
+        String inventoryPath = url.getPath();
+
+        assert (inventoryPath != null);
+
+        String[] pathTokens = inventoryPath.split("/");
+        if (pathTokens.length == 2) {
+            // DC name is not present in url.
+            // Using DC name read from database.
+            clusterName = pathTokens[1];
+            updatedInventoryPath = "/" + vmwareDcNameFromDb + "/" + clusterName;
+        } else if (pathTokens.length == 3) {
+            vmwareDcNameFromApi = pathTokens[1];
+            clusterName = pathTokens[2];
+        }
+
+        if (!vCenterHost.equalsIgnoreCase(url.getHost())) {
+            msg = "This cluster " + clusterName + " belongs to vCenter " + url.getHost()
+                + " .But this zone is associated with VMware DC from vCenter " + vCenterHost
+                + ". Make sure the cluster being added belongs to vCenter " + vCenterHost
+                + " and DC " + vmwareDcNameFromDb;
+            s_logger.error(msg);
+            throw new DiscoveryException(msg);
+        } else if (!vmwareDcNameFromDb.equalsIgnoreCase(vmwareDcNameFromApi)) {
+            msg = "This cluster " + clusterName + " belongs to VMware DC " + vmwareDcNameFromApi
+                + " .But this zone is associated with VMware DC " + vmwareDcNameFromDb
+                + ". Make sure the cluster being added belongs to DC " + vmwareDcNameFromDb
+                + " in vCenter " + vCenterHost;
+            s_logger.error(msg);
+            throw new DiscoveryException(msg);
+        }
+        return updatedInventoryPath;
+    }
+
 	private boolean validateDiscoveredHosts(VmwareContext context,
 			ManagedObjectReference morCluster,
 			List<ManagedObjectReference> morHosts) throws Exception {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
new file mode 100644
index 0000000..e339604
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
@@ -0,0 +1,48 @@
+package com.cloud.hypervisor.vmware.dao;
+
+import java.util.List;
+
+import com.cloud.hypervisor.vmware.VmwareDatacenterVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface VmwareDatacenterDao extends GenericDao<VmwareDatacenterVO, Long> {
+
+    /**
+     * Return a VMware Datacenter given guid 
+     * @param guid of VMware datacenter
+     * @return VmwareDatacenterVO for the VMware datacenter having the specified guid.
+     */
+    VmwareDatacenterVO getVmwareDatacenterByGuid(String guid);
+
+    /**
+     * Return a VMware Datacenter given name and vCenter host. 
+     * For legacy zones multiple records will be present in the table.
+     * @param name of VMware datacenter
+     * @param vCenter host
+     * @return VmwareDatacenterVO for the VMware datacenter with given name and
+     * belonging to specified vCenter host.
+     */
+    List<VmwareDatacenterVO> getVmwareDatacenterByNameAndVcenter(String name, String vCenterHost);
+
+    /**
+     * Return a list of VMware Datacenter given name.
+     * @param name of Vmware datacenter
+     * @return list of VmwareDatacenterVO for VMware datacenters having the specified name.
+     */
+    List<VmwareDatacenterVO> listVmwareDatacenterByName(String name);
+
+    /**
+     * Return a list of VMware Datacenters belonging to specified vCenter
+     * @param vCenter Host
+     * @return list of VmwareDatacenterVO for all VMware datacenters belonging to 
+     * specified vCenter
+     */
+    List<VmwareDatacenterVO> listVmwareDatacenterByVcenter(String vCenterHost);
+
+    /**
+     * Lists all associated VMware datacenter on the management server.
+     * @return list of VmwareDatacenterVO for all associated VMware datacenters 
+     */
+    List<VmwareDatacenterVO> listAllVmwareDatacenters();
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java
new file mode 100644
index 0000000..b8fa715
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java
@@ -0,0 +1,87 @@
+package com.cloud.hypervisor.vmware.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.hypervisor.vmware.VmwareDatacenterVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+@Local(value=VmwareDatacenterDao.class) @DB(txn=false)
+public class VmwareDatacenterDaoImpl extends GenericDaoBase<VmwareDatacenterVO, Long> implements VmwareDatacenterDao {
+    protected static final Logger s_logger = Logger.getLogger(VmwareDatacenterDaoImpl.class);
+
+    final SearchBuilder<VmwareDatacenterVO> nameSearch;
+    final SearchBuilder<VmwareDatacenterVO> guidSearch;
+    final SearchBuilder<VmwareDatacenterVO> vcSearch;
+    final SearchBuilder<VmwareDatacenterVO> nameVcSearch;
+    final SearchBuilder<VmwareDatacenterVO> fullTableSearch;
+
+    public VmwareDatacenterDaoImpl() {
+        super();
+
+        nameSearch = createSearchBuilder();
+        nameSearch.and("name", nameSearch.entity().getVmwareDatacenterName(), Op.EQ);
+        nameSearch.done();
+
+        nameVcSearch = createSearchBuilder();
+        nameVcSearch.and("name", nameVcSearch.entity().getVmwareDatacenterName(), Op.EQ);
+        nameVcSearch.and("vCenterHost", nameVcSearch.entity().getVcenterHost(), Op.EQ);
+        nameVcSearch.done();
+
+        vcSearch = createSearchBuilder();
+        vcSearch.and("vCenterHost", vcSearch.entity().getVcenterHost(), Op.EQ);
+        vcSearch.done();
+
+        guidSearch = createSearchBuilder();
+        guidSearch.and("guid", guidSearch.entity().getGuid(), Op.EQ);
+        guidSearch.done();
+
+        fullTableSearch = createSearchBuilder();
+        fullTableSearch.done();
+    }
+
+    @Override
+    public VmwareDatacenterVO getVmwareDatacenterByGuid(String guid) {
+        SearchCriteria<VmwareDatacenterVO> sc = guidSearch.create();
+        sc.setParameters("guid", guid);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public List<VmwareDatacenterVO> getVmwareDatacenterByNameAndVcenter(String name, String vCenterHost) {
+        SearchCriteria<VmwareDatacenterVO> sc = guidSearch.create();
+        sc.setParameters("name", name);
+        sc.setParameters("vCenterHost", vCenterHost);
+        return search(sc, null);
+    }
+
+    @Override
+    public List<VmwareDatacenterVO> listVmwareDatacenterByName(String name) {
+        SearchCriteria<VmwareDatacenterVO> sc = guidSearch.create();
+        sc.setParameters("name", name);
+        return search(sc, null);
+    }
+
+    @Override
+    public List<VmwareDatacenterVO> listVmwareDatacenterByVcenter(String vCenterHost) {
+        SearchCriteria<VmwareDatacenterVO> sc = vcSearch.create();
+        sc.setParameters("vCenterHost", vCenterHost);
+        return search(sc, null);
+    }
+
+    @Override
+    public List<VmwareDatacenterVO> listAllVmwareDatacenters() {
+        SearchCriteria<VmwareDatacenterVO> sc = fullTableSearch.create();
+        return search(sc, null);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java
new file mode 100644
index 0000000..dff9bb0
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java
@@ -0,0 +1,18 @@
+package com.cloud.hypervisor.vmware.dao;
+
+import com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface VmwareDatacenterZoneMapDao extends GenericDao<VmwareDatacenterZoneMapVO, Long> {
+    /**
+     * @param id of zone
+     * @return map object of VMware datacenter & zone
+     */
+    VmwareDatacenterZoneMapVO findByZoneId(long zoneId);
+
+    /**
+     * @param id of VMware datacenter
+     * @return map object of VMware datacenter & zone
+     */
+    VmwareDatacenterZoneMapVO findByVmwareDcId(long vmwareDcId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDaoImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDaoImpl.java
new file mode 100644
index 0000000..1c13269
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDaoImpl.java
@@ -0,0 +1,61 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied.  See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+package com.cloud.hypervisor.vmware.dao;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+@Local(value=VmwareDatacenterZoneMapDao.class)
+public class VmwareDatacenterZoneMapDaoImpl extends GenericDaoBase<VmwareDatacenterZoneMapVO, Long>
+     implements VmwareDatacenterZoneMapDao {
+
+ protected final SearchBuilder<VmwareDatacenterZoneMapVO> zoneSearch;
+ protected final SearchBuilder<VmwareDatacenterZoneMapVO> vmwareDcSearch;
+
+ public VmwareDatacenterZoneMapDaoImpl() {
+     zoneSearch = createSearchBuilder();
+     zoneSearch.and("zoneId", zoneSearch.entity().getZoneId(), Op.EQ);
+     zoneSearch.done();
+
+     vmwareDcSearch = createSearchBuilder();
+     vmwareDcSearch.and("vmwareDcId", vmwareDcSearch.entity().getVmwareDcId(), Op.EQ);
+     vmwareDcSearch.done();
+ }
+
+    @Override
+    public VmwareDatacenterZoneMapVO findByZoneId(long zoneId) {
+        SearchCriteria<VmwareDatacenterZoneMapVO> sc = zoneSearch.create();
+        sc.setParameters("zoneId", zoneId);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public VmwareDatacenterZoneMapVO findByVmwareDcId(long vmwareDcId) {
+        SearchCriteria<VmwareDatacenterZoneMapVO> sc = vmwareDcSearch.create();
+        sc.setParameters("vmwareDcId", vmwareDcId);
+        return findOneBy(sc);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index 9f260f1..3b94537 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -35,6 +36,8 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
+import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
@@ -51,15 +54,28 @@ import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.ClusterDetailsDao;
 import com.cloud.dc.ClusterVO;
 import com.cloud.dc.ClusterVSMMapVO;
+import com.cloud.dc.DataCenterVO;
 import com.cloud.dc.dao.ClusterDao;
 import com.cloud.dc.dao.ClusterVSMMapDao;
+import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.exception.DiscoveredWithErrorException;
+import com.cloud.exception.DiscoveryException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceInUseException;
 import com.cloud.host.HostVO;
 import com.cloud.host.Status;
 import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
 import com.cloud.hypervisor.vmware.VmwareCleanupMaid;
+import com.cloud.hypervisor.vmware.VmwareDatacenterService;
+import com.cloud.hypervisor.vmware.VmwareDatacenterVO;
+import com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO;
+import com.cloud.hypervisor.vmware.dao.VmwareDatacenterDao;
+import com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDao;
+import com.cloud.hypervisor.vmware.mo.CustomFieldConstants;
+import com.cloud.hypervisor.vmware.mo.CustomFieldsManagerMO;
+import com.cloud.hypervisor.vmware.mo.DatacenterMO;
 import com.cloud.hypervisor.vmware.mo.DiskControllerType;
 import com.cloud.hypervisor.vmware.mo.HostFirewallSystemMO;
 import com.cloud.hypervisor.vmware.mo.HostMO;
@@ -68,8 +84,10 @@ import com.cloud.hypervisor.vmware.mo.TaskMO;
 import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
 import com.cloud.hypervisor.vmware.mo.VmwareHostType;
 import com.cloud.utils.ssh.SshHelper;
+import com.cloud.hypervisor.vmware.resource.VmwareContextFactory;
 import com.cloud.hypervisor.vmware.util.VmwareClient;
 import com.cloud.hypervisor.vmware.util.VmwareContext;
+import com.cloud.hypervisor.vmware.util.VmwareHelper;
 import com.cloud.network.CiscoNexusVSMDeviceVO;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
@@ -83,11 +101,13 @@ import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.utils.FileUtil;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
+import com.cloud.utils.UriUtils;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GlobalLock;
+import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.Script;
 import com.cloud.utils.ssh.SshHelper;
@@ -98,8 +118,8 @@ import com.vmware.vim25.HostConnectSpec;
 import com.vmware.vim25.ManagedObjectReference;
 
 
-@Local(value = {VmwareManager.class})
-public class VmwareManagerImpl extends ManagerBase implements VmwareManager, VmwareStorageMount, Listener {
+@Local(value = {VmwareManager.class, VmwareDatacenterService.class})
+public class VmwareManagerImpl extends ManagerBase implements VmwareManager, VmwareStorageMount, Listener, VmwareDatacenterService {
     private static final Logger s_logger = Logger.getLogger(VmwareManagerImpl.class);
 
     private static final int STARTUP_DELAY = 60000; 				// 60 seconds
@@ -124,6 +144,9 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
     @Inject ConfigurationDao _configDao;
     @Inject ConfigurationServer _configServer;
     @Inject HypervisorCapabilitiesDao _hvCapabilitiesDao;
+    @Inject DataCenterDao _dcDao;
+    @Inject VmwareDatacenterDao _vmwareDcDao;
+    @Inject VmwareDatacenterZoneMapDao _vmwareDcZoneMapDao;
 
     String _mountParent;
     StorageLayer _storage;
@@ -865,4 +888,279 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
     public String getRootDiskController() {
         return _rootDiskController;
     }
+
+    @Override
+    public List<Class<?>> getCommands() {
+        List<Class<?>> cmdList = new ArrayList<Class<?>>();
+        cmdList.add(AddVmwareDcCmd.class);
+        cmdList.add(RemoveVmwareDcCmd.class);
+        return cmdList;
+    }
+
+    @Override
+    @DB
+    public VmwareDatacenterVO addVmwareDatacenter(AddVmwareDcCmd cmd) throws Exception {
+        VmwareDatacenterVO vmwareDc = null;
+        Long zoneId = cmd.getZoneId();
+        String url = cmd.getUrl();
+        String userName = cmd.getUsername();
+        String password = cmd.getPassword();
+        String vmwareDcName = cmd.getName();
+
+        // Zone validation
+        validateZone(zoneId, "add VMware datacenter to zone");
+
+        // Check if the zone exists in the system
+        //      If no, throw invalid param value exception
+        DataCenterVO zone = _dcDao.findById(zoneId);
+        if (zone == null) {
+            InvalidParameterValueException ex = new InvalidParameterValueException(
+                    "Can't find zone by the id specified");
+            ex.addProxyObject(zone, zoneId, "dcId");
+            throw ex;
+        }
+
+        VmwareDatacenterZoneMapVO vmwareDcZoneMap = _vmwareDcZoneMapDao.findByZoneId(zoneId);
+        // Check if zone is associated with VMware DC
+        if (vmwareDcZoneMap != null) {
+            throw new CloudRuntimeException("Zone " + zoneId + " is already associated with a VMware datacenter.");
+        }
+
+        // Check if zone has resources? - For now look for clusters
+        //      If yes, throw resource in use execption
+        List<ClusterVO> clusters = _clusterDao.listByZoneId(zoneId);
+        if (clusters != null) {
+            try {
+            if (clusters.size() > 0) {
+                throw new ResourceInUseException("Zone has one or more clusters."
+                        + " Can't add VMware datacenter to zone which already has clusters.");
+            }}catch(Throwable t) {
+                s_logger.error(t);
+            }
+        }
+
+        // Validate url and get uri
+        URI uri = getUri(url);
+
+        // Validate username and password and DC name
+        if (userName == null) {
+            throw new InvalidParameterValueException("Invalid parameter username.");
+        }
+
+        if (password == null) {
+            throw new InvalidParameterValueException("Invalid parameter password.");
+        }
+
+        if (vmwareDcName == null) {
+            throw new InvalidParameterValueException("Invalid parameter name. Please provide valid VMware datacenter name.");
+        }
+
+        // Check if DC is already part of zone
+        // In that case vmware_data_center table should have the DC
+        String vCenterHost = uri.getHost();
+        List<VmwareDatacenterVO> vmwareDcs = _vmwareDcDao.getVmwareDatacenterByNameAndVcenter(vmwareDcName, vCenterHost);
+        if (vmwareDcs != null && vmwareDcs.size() != 0) {
+            throw new ResourceInUseException("This DC is already part of other CloudStack zone(s). Cannot add this DC to more zones.");
+        }
+
+        VmwareContext context = null;
+        DatacenterMO dcMo = null;
+        String dcCustomFieldValue;
+        boolean addDcCustomFieldDef = false;
+        boolean dcInUse = false;
+        String guid;
+        ManagedObjectReference dcMor;
+        try {
+            context = VmwareContextFactory.create(vCenterHost, userName, password);
+
+            // Check if DC exists on vCenter
+            try {
+                dcMo = new DatacenterMO(context, vmwareDcName);
+            } catch(Throwable t) {
+                String msg = "Unable to find DC " + vmwareDcName + " in vCenter " + vCenterHost;
+                s_logger.error(msg);
+                throw new DiscoveryException(msg);
+            }
+            assert (dcMo != null);
+
+            // Check if DC is already associated with another cloudstack deployment
+            // Get custom field property cloud.zone over this DC
+            dcMor = dcMo.getMor();
+            guid = dcMor.getType() + ":" + dcMor.getValue() + "@" + vCenterHost;
+
+            dcCustomFieldValue = dcMo.getCustomFieldValue(CustomFieldConstants.CLOUD_ZONE);
+            if (dcCustomFieldValue == null) {
+                addDcCustomFieldDef = true;
+            }
+            dcInUse = Boolean.parseBoolean(dcCustomFieldValue);
+            if (dcInUse) {
+                throw new ResourceInUseException("This DC is being managed by other CloudStack deployment. Cannot add this DC to zone.");
+            }
+
+            // Add DC to database into vmware_data_center table
+            vmwareDc = new VmwareDatacenterVO(guid, vmwareDcName, vCenterHost, userName, password);
+            Transaction txn = Transaction.currentTxn();
+            try {
+                txn.start();
+                vmwareDc = _vmwareDcDao.persist(vmwareDc);
+                txn.commit();
+            } catch (Exception e) {
+                txn.rollback();
+                s_logger.error("Failed to persist VMware datacenter details to database. Exception: " + e.getMessage());
+                throw new CloudRuntimeException(e.getMessage());
+            }
+
+            // Map zone with vmware datacenter
+            vmwareDcZoneMap = new VmwareDatacenterZoneMapVO(zoneId, vmwareDc.getId());
+
+            txn = Transaction.currentTxn();
+            try {
+                txn.start();
+                vmwareDcZoneMap = _vmwareDcZoneMapDao.persist(vmwareDcZoneMap);
+                txn.commit();
+            } catch (Exception e) {
+                txn.rollback();
+                s_logger.error("Failed to associate VMware datacenter with zone " + zoneId + ". Exception: " + e.getMessage());
+                // Removing VMware datacenter from vmware_data_center table because association with zone failed.
+                _vmwareDcDao.remove(vmwareDcZoneMap.getId());
+                throw new CloudRuntimeException(e.getMessage());
+            }
+
+            // Set custom field for this DC
+            if (addDcCustomFieldDef) {
+                dcMo.ensureCustomFieldDef(CustomFieldConstants.CLOUD_ZONE);
+            }
+            dcMo.setCustomFieldValue(CustomFieldConstants.CLOUD_ZONE, "true");
+
+        } catch (Exception e) {
+            String msg = "VMware DC discovery failed due to : " + VmwareHelper.getExceptionMessage(e);
+            s_logger.error(msg);
+            throw new CloudRuntimeException(msg);
+        } finally {
+            if (context != null)
+                context.close();
+            context = null;
+        }
+        return vmwareDc;
+    }
+
+    @Override
+    public boolean removeVmwareDatacenter(RemoveVmwareDcCmd cmd) throws Exception {
+        Long zoneId = cmd.getZoneId();
+        // Validate zone
+        validateZone(zoneId, "remove VMware datacenter from zone");
+
+        // Get DC associated with this zone
+        VmwareDatacenterZoneMapVO vmwareDcZoneMap;
+        VmwareDatacenterVO vmwareDatacenter;
+        String vmwareDcName;
+        long vmwareDcId;
+        String vCenterHost;
+        String userName;
+        String password;
+        DatacenterMO dcMo = null;
+        Transaction txn;
+
+        vmwareDcZoneMap = _vmwareDcZoneMapDao.findByZoneId(zoneId);
+        // Check if zone is associated with VMware DC
+        if (vmwareDcZoneMap == null) {
+            throw new CloudRuntimeException("Zone " + zoneId + " is not associated with any VMware datacenter.");
+        }
+
+        vmwareDcId = vmwareDcZoneMap.getVmwareDcId();
+        vmwareDatacenter = _vmwareDcDao.findById(vmwareDcId);
+        vmwareDcName = vmwareDatacenter.getVmwareDatacenterName();
+        vCenterHost = vmwareDatacenter.getVcenterHost();
+        userName = vmwareDatacenter.getUser();
+        password = vmwareDatacenter.getPassword();
+        txn = Transaction.currentTxn();
+        try {
+            txn.start();
+            // Remove the VMware datacenter entry in table vmware_data_center
+            _vmwareDcDao.remove(vmwareDcId);
+            // Remove the map entry in table vmware_data_center_zone_map
+            _vmwareDcZoneMapDao.remove(vmwareDcZoneMap.getId());
+            txn.commit();
+        } catch (Exception e) {
+            s_logger.info("Caught exception when trying to delete VMware datacenter record.." + e.getMessage());
+            throw new CloudRuntimeException("Failed to delete VMware datacenter ");
+        }
+
+        // Construct context
+        VmwareContext context = null;
+        try {
+            context = VmwareContextFactory.create(vCenterHost, userName, password);
+
+            // Check if DC exists on vCenter
+            try {
+                dcMo = new DatacenterMO(context, vmwareDcName);
+            } catch(Throwable t) {
+                String msg = "able to find DC " + vmwareDcName + " in vCenter " + vCenterHost;
+                s_logger.error(msg);
+                throw new DiscoveryException(msg);
+            }
+
+            assert (dcMo != null);
+
+            // Reset custom field property cloud.zone over this DC
+            dcMo.setCustomFieldValue(CustomFieldConstants.CLOUD_ZONE, "false");
+            s_logger.info("Sucessfully reset custom field property cloud.zone over DC " + vmwareDcName);
+        } catch (Exception e) {
+            String msg = "Unable to reset custom field property cloud.zone over DC " + vmwareDcName
+                       + " due to : " + VmwareHelper.getExceptionMessage(e);
+            s_logger.error(msg);
+            throw new CloudRuntimeException(msg);
+        } finally {
+            if (context != null)
+                context.close();
+            context = null;
+        }
+        return true;
+    }
+
+    private void validateZone(Long zoneId, String errStr) throws ResourceInUseException {
+        // Check if zone with specified id exists
+        DataCenterVO zone = _dcDao.findById(zoneId);
+        if (zone == null) {
+            InvalidParameterValueException ex = new InvalidParameterValueException(
+                    "Can't find zone by the id specified");
+            ex.addProxyObject(zone, zoneId, "dcId");
+            throw ex;
+        }
+
+        // Check if zone has resources? - For now look for clusters
+        List<ClusterVO> clusters = _clusterDao.listByZoneId(zoneId);
+        if(clusters != null && clusters.size() != 0) {
+            throw new ResourceInUseException("Zone has one or more clusters."
+                        + " Can't " + errStr + " which already has clusters.");
+        }
+    }
+
+    private URI getUri(String url) throws InvalidParameterValueException {
+        if (url == null) {
+            throw new InvalidParameterValueException("Invalid url.");
+        }
+
+        URI uri = null;
+        try {
+            uri = new URI(UriUtils.encodeURIComponent(url));
+            if (uri.getScheme() == null) {
+                throw new InvalidParameterValueException(
+                        "uri.scheme is null " + url
+                                + ", add http:// as a prefix");
+            } else if (uri.getScheme().equalsIgnoreCase("http")) {
+                if (uri.getHost() == null
+                        || uri.getHost().equalsIgnoreCase("")
+                        || uri.getPath() == null
+                        || uri.getPath().equalsIgnoreCase("")) {
+                    throw new InvalidParameterValueException(
+                            "Your host and/or path is wrong.  Make sure it's of the format http://hostname/path");
+                }
+            }
+        } catch (URISyntaxException e) {
+            throw new InvalidParameterValueException(url
+                    + " is not a valid uri");
+        }
+        return uri;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
new file mode 100644
index 0000000..3d9101b
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
@@ -0,0 +1,103 @@
+package org.apache.cloudstack.api.command.admin.zone;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.VmwareDatacenterResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.DiscoveryException;
+import com.cloud.exception.ResourceInUseException;
+import com.cloud.hypervisor.vmware.VmwareDatacenterService;
+import com.cloud.hypervisor.vmware.VmwareDatacenterVO;
+import com.cloud.user.Account;
+
+@APICommand(name = "addVmwareDc", description="Adds a VMware datacenter to specified zone", responseObject=VmwareDatacenterResponse.class)
+public class AddVmwareDcCmd extends BaseCmd {
+
+    @Inject public VmwareDatacenterService _vmwareDatacenterService;
+
+    public static final Logger s_logger = Logger.getLogger(AddVmwareDcCmd.class.getName());
+
+    private static final String s_name = "addvmwaredcresponse";
+
+    @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="Name of VMware datacenter to be added to specified zone.")
+    private String name;
+
+    @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required=false, description="The URL of vCenter.")
+    private String url;
+
+    @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required=false, description="The Username required to connect to resource.")
+    private String username;
+
+    @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required=false, description="The password for specified username.")
+    private String password;
+
+    @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class, required=true, description="The Zone ID.")
+    private Long zoneId;
+
+    public String getName() {
+        return name;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public Long getZoneId() {
+        return zoneId;
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+    @Override
+    public void execute() {
+        try {
+            VmwareDatacenterResponse response = new VmwareDatacenterResponse(); 
+            VmwareDatacenterVO result = _vmwareDatacenterService.addVmwareDatacenter(this);
+            if (result != null){
+                response.setId(result.getUuid());
+                response.setName(result.getVmwareDatacenterName());
+                response.setResponseName(getCommandName());
+            } else {
+                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add VMware Datacenter to zone.");
+            }
+            this.setResponseObject(response);
+        } catch (DiscoveryException ex) {
+            s_logger.warn("Exception: ", ex);
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
+        } catch (ResourceInUseException ex) {
+            s_logger.warn("Exception: ", ex);
+            ServerApiException e = new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
+            for (String proxyObj : ex.getIdProxyList()) {
+                e.addProxyObject(proxyObj);
+            }
+            throw e;
+        } catch (IllegalArgumentException ex) {
+            throw new IllegalArgumentException(ex.getMessage());
+        } catch (Exception e) {
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
new file mode 100644
index 0000000..cf54698
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
@@ -0,0 +1,80 @@
+package org.apache.cloudstack.api.command.admin.zone;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.BaseCmd.CommandType;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.DiscoveryException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.NetworkRuleConflictException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceInUseException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.hypervisor.vmware.VmwareDatacenterService;
+import com.cloud.network.element.CiscoNexusVSMElementService;
+import com.cloud.user.Account;
+
+@APICommand(name = "removeVmwareDc", responseObject=SuccessResponse.class, description="Remove a VMware datacenter from a zone.")
+public class RemoveVmwareDcCmd extends BaseCmd {
+
+    @Inject public VmwareDatacenterService _vmwareDatacenterService;
+    
+    public static final Logger s_logger = Logger.getLogger(AddVmwareDcCmd.class.getName());
+    
+    private static final String s_name = "removevmwaredcresponse";
+
+    @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class, required=true,
+                description="The id of Zone from which VMware datacenter has to be removed.")
+
+    private Long zoneId;
+
+    public Long getZoneId() {
+        return zoneId;
+    }
+
+    @Override
+    public void execute() {
+        SuccessResponse response = new SuccessResponse();
+        try {
+            boolean result = _vmwareDatacenterService.removeVmwareDatacenter(this);
+            if (result) {
+                response.setResponseName(getCommandName());
+                this.setResponseObject(response);
+            } else {
+                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove VMware datacenter from zone");
+            }
+        } catch (ResourceInUseException ex) {
+            s_logger.warn("The zone has one or more resources (like cluster), hence not able to remove VMware datacenter from zone."
+                        + " Please remove all resource from zone, and retry. Exception: ", ex);
+            ServerApiException e = new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
+            for (String proxyObj : ex.getIdProxyList()) {
+                e.addProxyObject(proxyObj);
+            }
+            throw e;
+        } catch (IllegalArgumentException ex) {
+            throw new IllegalArgumentException(ex.getMessage());
+        } catch (Exception e) {
+        }
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
new file mode 100644
index 0000000..151d037
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
@@ -0,0 +1,34 @@
+package org.apache.cloudstack.api.response;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.api.EntityReference;
+
+import com.cloud.hypervisor.vmware.VmwareDatacenter;
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+@EntityReference(value = VmwareDatacenter.class)
+public class VmwareDatacenterResponse extends BaseResponse {
+    @SerializedName(ApiConstants.ID) @Param(description="The VMware Datacenter ID")
+    private String id;
+
+    @SerializedName(ApiConstants.NAME) @Param(description="The VMware Datacenter name")
+    private String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 7b5e9cb..65479fd 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -979,6 +979,24 @@ CREATE TABLE `cloud`.`network_asa1000v_map` (
   CONSTRAINT `fk_network_asa1000v_map__asa1000v_id` FOREIGN KEY (`asa1000v_id`) REFERENCES `external_cisco_asa1000v_devices`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+CREATE TABLE `cloud`.`vmware_data_center` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
+  `uuid` varchar(255) UNIQUE,
+  `name` varchar(255) NOT NULL COMMENT 'Name of VMware datacenter',
+  `guid` varchar(255) NOT NULL UNIQUE COMMENT 'id of VMware datacenter',
+  `vcenter_host` varchar(255) NOT NULL COMMENT 'vCenter host containing this VMware datacenter',
+  `username` varchar(255) NOT NULL COMMENT 'Name of vCenter host user',
+  `password` varchar(255) NOT NULL COMMENT 'Password of vCenter host user',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE `cloud`.`vmware_data_center_zone_map` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
+  `zone_id` bigint unsigned NOT NULL UNIQUE COMMENT 'id of CloudStack zone',
+  `vmware_data_center_id` bigint unsigned NOT NULL UNIQUE COMMENT 'id of VMware datacenter',
+  PRIMARY KEY (`id`),
+  CONSTRAINT `fk_vmware_data_center_zone_map__vmware_data_center_id` FOREIGN KEY (`vmware_data_center_id`) REFERENCES `vmware_data_center`(`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `eip_associate_public_ip` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if public IP is associated with user VM creation by default when EIP service is enabled.' AFTER `elastic_ip_service`;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/vmware-base/src/com/cloud/hypervisor/vmware/mo/CustomFieldConstants.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/CustomFieldConstants.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/CustomFieldConstants.java
index 4cd5f9b..11bc157 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/CustomFieldConstants.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/CustomFieldConstants.java
@@ -21,4 +21,5 @@ public interface CustomFieldConstants {
 	public final static String CLOUD_GC = "cloud.gc";
 	public final static String CLOUD_GC_DVP = "cloud.gc.dvp";	
 	public final static String CLOUD_NIC_MASK = "cloud.nic.mask";
+    public final static String CLOUD_ZONE = "cloud.zone";
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a37fa1e/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
index 0a3e20b..cabb60a 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
@@ -488,4 +488,9 @@ public class DatacenterMO extends BaseMO {
         dvSwitchMor = _context.getVimClient().getDecendentMoRef(networkFolderMor, "VmwareDistributedVirtualSwitch", dvSwitchName);
         return dvSwitchMor;
     }
+
+    public boolean ensureCustomFieldDef(String fieldName) throws Exception {
+        CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager());
+        return cfmMo.ensureCustomFieldDef("Datacenter", fieldName) > 0;
+    }
 }


[04/10] git commit: updated refs/heads/vmware-datamodel to 599b826

Posted by sa...@apache.org.
Legacy zone support.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2abe5e92
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2abe5e92
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2abe5e92

Branch: refs/heads/vmware-datamodel
Commit: 2abe5e9288cf45715e555293a874986a3eda03d0
Parents: 579a812
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Sat May 4 23:20:59 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Thu May 23 06:37:24 2013 +0530

----------------------------------------------------------------------
 setup/db/db/schema-410to420.sql |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2abe5e92/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index e4baacd..7199fd3 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -1117,6 +1117,7 @@ CREATE VIEW `cloud`.`account_view` AS
     select
         account.id,
         account.uuid,
+        account.uuid,
         account.account_name,
         account.type,
         account.state,


[02/10] git commit: updated refs/heads/vmware-datamodel to 599b826

Posted by sa...@apache.org.
Legacy zone support.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3db1cdfe
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3db1cdfe
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3db1cdfe

Branch: refs/heads/vmware-datamodel
Commit: 3db1cdfef94a22ea378230c430247ae641928e26
Parents: 3a37fa1
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Sat May 4 23:20:59 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Wed May 22 19:25:56 2013 +0530

----------------------------------------------------------------------
 setup/db/db/schema-410to420.sql |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3db1cdfe/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 65479fd..7199fd3 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -998,6 +998,13 @@ CREATE TABLE `cloud`.`vmware_data_center_zone_map` (
   CONSTRAINT `fk_vmware_data_center_zone_map__vmware_data_center_id` FOREIGN KEY (`vmware_data_center_id`) REFERENCES `vmware_data_center`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+CREATE TABLE `cloud`.`legacy_zones` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
+  `zone_id` bigint unsigned NOT NULL UNIQUE COMMENT 'id of CloudStack zone',
+  PRIMARY KEY (`id`),
+  CONSTRAINT `fk_legacy_zones__zone_id` FOREIGN KEY (`zone_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
 ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `eip_associate_public_ip` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if public IP is associated with user VM creation by default when EIP service is enabled.' AFTER `elastic_ip_service`;
 
 
@@ -1110,6 +1117,7 @@ CREATE VIEW `cloud`.`account_view` AS
     select
         account.id,
         account.uuid,
+        account.uuid,
         account.account_name,
         account.type,
         account.state,


[09/10] git commit: updated refs/heads/vmware-datamodel to 599b826

Posted by sa...@apache.org.
Added Apache license header


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ce2c3406
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ce2c3406
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ce2c3406

Branch: refs/heads/vmware-datamodel
Commit: ce2c3406949229c3ba6c9c95b5f9b9301b4d797e
Parents: 8b312e2
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Thu May 23 07:11:18 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Thu May 23 07:11:18 2013 +0530

----------------------------------------------------------------------
 .../cloud/hypervisor/vmware/VmwareDatacenter.java  |   17 +++++++++++++++
 .../hypervisor/vmware/VmwareDatacenterService.java |   17 +++++++++++++++
 .../hypervisor/vmware/VmwareDatacenterVO.java      |   17 +++++++++++++++
 .../hypervisor/vmware/VmwareDatacenterZoneMap.java |   17 +++++++++++++++
 .../vmware/VmwareDatacenterZoneMapVO.java          |    1 +
 .../hypervisor/vmware/dao/VmwareDatacenterDao.java |   17 +++++++++++++++
 .../vmware/dao/VmwareDatacenterDaoImpl.java        |   17 +++++++++++++++
 .../vmware/dao/VmwareDatacenterZoneMapDao.java     |   17 +++++++++++++++
 .../api/command/admin/zone/AddVmwareDcCmd.java     |   17 +++++++++++++++
 .../api/command/admin/zone/RemoveVmwareDcCmd.java  |   17 +++++++++++++++
 .../api/response/VmwareDatacenterResponse.java     |   17 +++++++++++++++
 .../vmware/VmwareDatacenterApiUnitTest.java        |   15 +++++++++++++
 12 files changed, 186 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
index b978cd9..6d6d2eb 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
@@ -1,3 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
 package com.cloud.hypervisor.vmware;
 
 import org.apache.cloudstack.api.Identity;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
index f04b2b5..fc77d65 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
@@ -1,3 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
 package com.cloud.hypervisor.vmware;
 
 import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
index 9d8fb7d..a13e59e 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
@@ -1,3 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
 package com.cloud.hypervisor.vmware;
 
 import java.util.UUID;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java
index 840c633..f70a541 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java
@@ -1,3 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
 package com.cloud.hypervisor.vmware;
 
 import org.apache.cloudstack.api.InternalIdentity;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
index 4e2cbe9..93b0e26 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
@@ -14,6 +14,7 @@
 //KIND, either express or implied.  See the License for the
 //specific language governing permissions and limitations
 //under the License.
+
 package com.cloud.hypervisor.vmware;
 
 import javax.persistence.Column;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
index c3f92ae..2754e91 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
@@ -1,3 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
 package com.cloud.hypervisor.vmware.dao;
 
 import java.util.List;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java
index b8fa715..8324e93 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java
@@ -1,3 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
 package com.cloud.hypervisor.vmware.dao;
 
 import java.util.List;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java
index dff9bb0..be693aa 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java
@@ -1,3 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
 package com.cloud.hypervisor.vmware.dao;
 
 import com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
index 0d9057e..0011e10 100644
--- a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
+++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
@@ -1,3 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
 package org.apache.cloudstack.api.command.admin.zone;
 
 import javax.inject.Inject;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
index 7de9056..1c549db 100644
--- a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
+++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
@@ -1,3 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
 package org.apache.cloudstack.api.command.admin.zone;
 
 import javax.inject.Inject;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
index 151d037..420320b 100644
--- a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
+++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
@@ -1,3 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
 package org.apache.cloudstack.api.response;
 
 import org.apache.cloudstack.api.ApiConstants;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce2c3406/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java b/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java
index ff98556..6730b22 100644
--- a/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java
+++ b/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java
@@ -1,4 +1,19 @@
 // Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 
 package com.cloud.hypervisor.vmware;
 


[05/10] git commit: updated refs/heads/vmware-datamodel to 599b826

Posted by sa...@apache.org.
CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Upgrade changes with legacy zone support

CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Plugin, API & DB changes

CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Upgrade changes with legacy zone support

CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter Upgrade changes with legacy zone support

DC-Zone mapping constraints should allow multiple hypervisors per zone.
Such zones would just be ignored.
Looking for only VMware clusters in the zone while associating a VMware DC with a zone.
Fixed upgrade path for zones with 1 cluster from 1 DC/vCenter. Auto-associating in this case.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/037627e0
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/037627e0
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/037627e0

Branch: refs/heads/vmware-datamodel
Commit: 037627e02991e73b9d34934c718f6fa9376f5996
Parents: 2abe5e9
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Mon May 6 15:59:24 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Thu May 23 06:37:26 2013 +0530

----------------------------------------------------------------------
 .../src/com/cloud/upgrade/dao/Upgrade410to420.java |    1 -
 .../cloud/hypervisor/vmware/VmwareDatacenter.java  |    2 --
 .../hypervisor/vmware/VmwareDatacenterVO.java      |    4 ----
 setup/db/db/schema-410to420.sql                    |    1 -
 4 files changed, 0 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/037627e0/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index 0d630a0..352e54a 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -423,7 +423,6 @@ public class Upgrade410to420 implements DbUpgrade {
         }
     }
 
->>>>>>> CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
     private void createPlaceHolderNics(Connection conn) {
         PreparedStatement pstmt = null;
         ResultSet rs = null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/037627e0/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
index c5d35b1..b978cd9 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
@@ -3,8 +3,6 @@ package com.cloud.hypervisor.vmware;
 import org.apache.cloudstack.api.Identity;
 import org.apache.cloudstack.api.InternalIdentity;
 
-import com.vmware.vim25.ManagedObjectReference;
-
 public interface VmwareDatacenter extends Identity, InternalIdentity {
 
     String getVmwareDatacenterName();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/037627e0/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
index 4b08d9e..9d8fb7d 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
@@ -140,8 +140,4 @@ public class VmwareDatacenterVO implements VmwareDatacenter {
         this.uuid = UUID.randomUUID().toString();
     }
 
-<<<<<<< HEAD
 }
-=======
-}
->>>>>>> CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/037627e0/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 7199fd3..e4baacd 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -1117,7 +1117,6 @@ CREATE VIEW `cloud`.`account_view` AS
     select
         account.id,
         account.uuid,
-        account.uuid,
         account.account_name,
         account.type,
         account.state,


[07/10] git commit: updated refs/heads/vmware-datamodel to 599b826

Posted by sa...@apache.org.
Unit tests for zone to vmware datacenter mapping model.

Cleanup

Removed mock for VmwareManager

Added tests for removal of VMware dc from cloudstack zone.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/fba45a10
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/fba45a10
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/fba45a10

Branch: refs/heads/vmware-datamodel
Commit: fba45a107c145d15c9f97825c36b4060767c66b9
Parents: 36feef9
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Wed May 22 07:11:43 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Thu May 23 06:37:50 2013 +0530

----------------------------------------------------------------------
 .../vmware/manager/VmwareManagerImpl.java          |    1 -
 .../vmware/VmwareDatacenterApiUnitTest.java        |  405 +++++++++++++++
 2 files changed, 405 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fba45a10/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index c90a8ff..9956a28 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -1100,7 +1100,6 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
         if (zone == null) {
             InvalidParameterValueException ex = new InvalidParameterValueException(
                     "Can't find zone by the id specified");
-            ex.addProxyObject(zone, zoneId, "dcId");
             throw ex;
         }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fba45a10/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java b/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java
new file mode 100644
index 0000000..ff98556
--- /dev/null
+++ b/plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java
@@ -0,0 +1,405 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+
+package com.cloud.hypervisor.vmware;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import junit.framework.TestCase;
+
+import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
+import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd;
+import org.apache.cloudstack.test.utils.SpringUtils;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.core.type.classreading.MetadataReader;
+import org.springframework.core.type.classreading.MetadataReaderFactory;
+import org.springframework.core.type.filter.TypeFilter;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.AnnotationConfigContextLoader;
+
+import com.cloud.agent.AgentManager;
+import com.cloud.cluster.ClusterManager;
+import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.dc.ClusterDetailsDao;
+import com.cloud.dc.ClusterDetailsVO;
+import com.cloud.dc.DataCenter.NetworkType;
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.HostPodVO;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.dc.dao.ClusterVSMMapDao;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.HostPodDao;
+import com.cloud.event.dao.EventDao;
+import com.cloud.exception.DiscoveryException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceInUseException;
+import com.cloud.host.dao.HostDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
+import com.cloud.hypervisor.vmware.dao.VmwareDatacenterDao;
+import com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDao;
+import com.cloud.hypervisor.vmware.manager.VmwareManager;
+import com.cloud.hypervisor.vmware.manager.VmwareManagerImpl;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
+import com.cloud.org.Cluster.ClusterType;
+import com.cloud.org.Managed.ManagedState;
+import com.cloud.secstorage.CommandExecLogDao;
+import com.cloud.server.ConfigurationServer;
+import com.cloud.storage.secondary.SecondaryStorageVmManager;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.AccountService;
+import com.cloud.user.AccountVO;
+import com.cloud.user.UserContext;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.dao.UserVmDao;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
+public class VmwareDatacenterApiUnitTest {
+
+    @Inject
+    VmwareDatacenterService _vmwareDatacenterService;
+
+    @Inject
+    DataCenterDao _dcDao;
+
+    @Inject
+    HostPodDao _podDao;
+
+    @Inject
+    VmwareDatacenterDao _vmwareDcDao;
+
+    @Inject
+    VmwareDatacenterZoneMapDao _vmwareDcZoneMapDao;
+
+    @Inject
+    ClusterDao _clusterDao;
+
+    @Inject
+    ClusterDetailsDao _clusterDetailsDao;
+
+    @Inject 
+    ConfigurationDao _configDao;
+
+    @Inject
+    AccountDao _accountDao;
+
+    @Inject
+    AccountManager _acctMgr;
+
+    long zoneId;
+    long podId;
+    long clusterId;
+    long vmwareDcId;
+    private static long domainId = 5L;
+    private static String vmwareDcName = "dc";
+    private static String clusterName = "cluster";
+    private static String vCenterHost = "10.1.1.100";
+    private static String url = "http://" + vCenterHost + "/" + vmwareDcName + "/" + clusterName;
+    private static String user = "administrator";
+    private static String password = "password";
+    private static String guid = vmwareDcName + "@" + vCenterHost;
+
+    private static VmwareDatacenterVO dc;
+    private static List<VmwareDatacenterVO> vmwareDcs;
+    private static ClusterVO cluster;
+    private static VmwareDatacenterZoneMapVO dcZoneMap;
+    private static List<ClusterVO> clusterList;
+    private static ClusterDetailsVO clusterDetails;
+
+    @Mock
+    private static AddVmwareDcCmd addCmd;
+    @Mock
+    private static RemoveVmwareDcCmd removeCmd;
+
+    @BeforeClass
+    public static void setUp() throws ConfigurationException {
+    }
+
+    @Before
+    public void testSetUp() {
+        Mockito.when(_configDao.isPremium()).thenReturn(true);
+        ComponentContext.initComponentsLifeCycle();
+        MockitoAnnotations.initMocks(this);
+
+        DataCenterVO zone = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null,  "10.0.0.1/24", 
+                null, null, NetworkType.Basic, null, null, true,  true, null, null);
+        zoneId = 1L;
+
+        HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), zoneId, "192.168.56.1", "192.168.56.0/24", 8, "test");
+        podId = 1L;
+
+        AccountVO acct = new AccountVO(200L);
+        acct.setType(Account.ACCOUNT_TYPE_ADMIN);
+        acct.setAccountName("admin");
+        acct.setDomainId(domainId);
+        UserContext.registerContext(1, acct, null, true);
+
+        when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
+
+        dc = new VmwareDatacenterVO(guid, vmwareDcName, vCenterHost, user, password);
+        vmwareDcs = new ArrayList<VmwareDatacenterVO>();
+        vmwareDcs.add(dc);
+        vmwareDcId = dc.getId();
+
+        cluster = new ClusterVO(zone.getId(), pod.getId(), "vmwarecluster");
+        cluster.setHypervisorType(HypervisorType.VMware.toString());
+        cluster.setClusterType(ClusterType.ExternalManaged);
+        cluster.setManagedState(ManagedState.Managed);
+        clusterId = 1L;
+        clusterList = new ArrayList<ClusterVO>();
+        clusterList.add(cluster);
+
+        clusterDetails = new ClusterDetailsVO(clusterId, "url", url);
+
+        dcZoneMap = new VmwareDatacenterZoneMapVO(zoneId, vmwareDcId);
+
+        Mockito.when(_dcDao.persist(Mockito.any(DataCenterVO.class))).thenReturn(zone);
+        Mockito.when(_dcDao.findById(1L)).thenReturn(zone);
+        Mockito.when(_podDao.persist(Mockito.any(HostPodVO.class))).thenReturn(pod);
+        Mockito.when(_podDao.findById(1L)).thenReturn(pod);
+        Mockito.when(_clusterDao.persist(Mockito.any(ClusterVO.class))).thenReturn(cluster);
+        Mockito.when(_clusterDao.findById(1L)).thenReturn(cluster);
+        Mockito.when(_clusterDao.listByZoneId(1L)).thenReturn(null);
+        Mockito.when(_clusterDao.expunge(1L)).thenReturn(true);
+        Mockito.when(_clusterDetailsDao.persist(Mockito.any(ClusterDetailsVO.class))).thenReturn(clusterDetails);
+        Mockito.when(_clusterDetailsDao.expunge(1L)).thenReturn(true);
+        Mockito.when(_vmwareDcDao.persist(Mockito.any(VmwareDatacenterVO.class))).thenReturn(dc);
+        Mockito.when(_vmwareDcDao.findById(1L)).thenReturn(null);
+        Mockito.when(_vmwareDcDao.expunge(1L)).thenReturn(true);
+        Mockito.when(_vmwareDcDao.getVmwareDatacenterByNameAndVcenter(vmwareDcName, vCenterHost)).thenReturn(null);
+        Mockito.when(_vmwareDcZoneMapDao.persist(Mockito.any(VmwareDatacenterZoneMapVO.class))).thenReturn(dcZoneMap);
+        Mockito.when(_vmwareDcZoneMapDao.findByZoneId(1L)).thenReturn(null);
+        Mockito.when(_vmwareDcZoneMapDao.expunge(1L)).thenReturn(true);
+        Mockito.when(addCmd.getZoneId()).thenReturn(1L);
+        Mockito.when(addCmd.getUrl()).thenReturn(url);
+        Mockito.when(addCmd.getUsername()).thenReturn(user);
+        Mockito.when(addCmd.getPassword()).thenReturn(password);
+        Mockito.when(addCmd.getName()).thenReturn(vmwareDcName);
+        Mockito.when(removeCmd.getZoneId()).thenReturn(1L);
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void testAddVmwareDcToInvalidZone() throws ResourceInUseException, IllegalArgumentException, DiscoveryException, Exception {
+        Mockito.when(addCmd.getZoneId()).thenReturn(2L);
+        _vmwareDatacenterService.addVmwareDatacenter(addCmd);
+    }
+
+    @Test(expected = ResourceInUseException.class)
+    public void testAddVmwareDcToZoneWithClusters() throws ResourceInUseException, IllegalArgumentException, DiscoveryException, Exception {
+        Mockito.when(_clusterDao.listByZoneId(1L)).thenReturn(clusterList);
+        _vmwareDatacenterService.addVmwareDatacenter(addCmd);
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void testRemoveVmwareDcToInvalidZone() throws ResourceInUseException, IllegalArgumentException, DiscoveryException, Exception {
+        Mockito.when(removeCmd.getZoneId()).thenReturn(2L);
+        _vmwareDatacenterService.removeVmwareDatacenter(removeCmd);
+    }
+
+    @Test(expected = ResourceInUseException.class)
+    public void testRemoveVmwareDcToZoneWithClusters() throws ResourceInUseException, IllegalArgumentException, DiscoveryException, Exception {
+        Mockito.when(_clusterDao.listByZoneId(1L)).thenReturn(clusterList);
+        _vmwareDatacenterService.removeVmwareDatacenter(removeCmd);
+    }
+
+    @Test(expected = ResourceInUseException.class)
+    public void testAddVmwareDcToZoneWithVmwareDc() throws ResourceInUseException, IllegalArgumentException, DiscoveryException, Exception {
+        Mockito.when(_vmwareDcDao.getVmwareDatacenterByNameAndVcenter(vmwareDcName, vCenterHost)).thenReturn(vmwareDcs);
+        _vmwareDatacenterService.addVmwareDatacenter(addCmd);
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void testAddVmwareDcWithNullUser() throws ResourceInUseException, IllegalArgumentException, DiscoveryException, Exception {
+        Mockito.when(addCmd.getUsername()).thenReturn(null);
+        _vmwareDatacenterService.addVmwareDatacenter(addCmd);
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void testAddVmwareDcWithNullPassword() throws ResourceInUseException, IllegalArgumentException, DiscoveryException, Exception {
+        Mockito.when(addCmd.getPassword()).thenReturn(null);
+        _vmwareDatacenterService.addVmwareDatacenter(addCmd);
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void testAddVmwareDcWithNullUrl() throws ResourceInUseException, IllegalArgumentException, DiscoveryException, Exception {
+        Mockito.when(addCmd.getUrl()).thenReturn(null);
+        _vmwareDatacenterService.addVmwareDatacenter(addCmd);
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void testAddVmwareDcWithNullDcName() throws ResourceInUseException, IllegalArgumentException, DiscoveryException, Exception {
+        Mockito.when(addCmd.getName()).thenReturn(null);
+        _vmwareDatacenterService.addVmwareDatacenter(addCmd);
+    }
+
+    @Test(expected = CloudRuntimeException.class)
+    public void testReAddVmwareDc() throws ResourceInUseException, IllegalArgumentException, DiscoveryException, Exception {
+        Mockito.when(_vmwareDcZoneMapDao.findByZoneId(1L)).thenReturn(dcZoneMap);
+        _vmwareDatacenterService.addVmwareDatacenter(addCmd);
+    }
+
+    @Test(expected = CloudRuntimeException.class)
+    public void testRemoveNonexistingVmwareDc() throws ResourceInUseException, IllegalArgumentException, DiscoveryException, Exception {
+        Mockito.when(_vmwareDcZoneMapDao.findByZoneId(1L)).thenReturn(null);
+        _vmwareDatacenterService.removeVmwareDatacenter(removeCmd);
+    }
+
+    @Configuration
+    @ComponentScan(basePackageClasses = {VmwareManagerImpl.class}, includeFilters = {@Filter(value = TestConfiguration.Library.class, type = FilterType.CUSTOM)}, useDefaultFilters = false)
+    public static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration {
+
+        @Bean
+        public AccountDao accountDao() {
+            return Mockito.mock(AccountDao.class);
+        }
+
+        @Bean
+        public AccountService accountService() {
+            return Mockito.mock(AccountService.class);
+        }
+
+        @Bean
+        public DataCenterDao dataCenterDao() {
+            return Mockito.mock(DataCenterDao.class);
+        }
+
+        @Bean
+        public HostPodDao hostPodDao() {
+            return Mockito.mock(HostPodDao.class);
+        }
+
+        @Bean
+        public ClusterDao clusterDao() {
+            return Mockito.mock(ClusterDao.class);
+        }
+
+        @Bean
+        public ClusterDetailsDao clusterDetailsDao() {
+            return Mockito.mock(ClusterDetailsDao.class);
+        }
+
+        @Bean
+        public VmwareDatacenterDao vmwareDatacenterDao() {
+            return Mockito.mock(VmwareDatacenterDao.class);
+        }
+
+        @Bean
+        public VmwareDatacenterZoneMapDao vmwareDatacenterZoneMapDao() {
+            return Mockito.mock(VmwareDatacenterZoneMapDao.class);
+        }
+
+        @Bean
+        public AgentManager agentManager() {
+            return Mockito.mock(AgentManager.class);
+        }
+
+        @Bean
+        public HostDao hostDao() {
+            return Mockito.mock(HostDao.class);
+        }
+
+        @Bean
+        public NetworkModel networkModel() {
+            return Mockito.mock(NetworkModel.class);
+        }
+
+        @Bean
+        public ClusterManager clusterManager() {
+            return Mockito.mock(ClusterManager.class);
+        }
+
+        @Bean
+        public SecondaryStorageVmManager secondaryStorageVmManager() {
+            return Mockito.mock(SecondaryStorageVmManager.class);
+        }
+
+        @Bean
+        public CommandExecLogDao commandExecLogDao() {
+            return Mockito.mock(CommandExecLogDao.class);
+        }
+
+        @Bean
+        public CiscoNexusVSMDeviceDao ciscoNexusVSMDeviceDao() {
+            return Mockito.mock(CiscoNexusVSMDeviceDao.class);
+        }
+
+        @Bean
+        public ClusterVSMMapDao clusterVSMMapDao() {
+            return Mockito.mock(ClusterVSMMapDao.class);
+        }
+
+        @Bean
+        public ConfigurationDao configurationDao() {
+            return Mockito.mock(ConfigurationDao.class);
+        }
+
+        @Bean
+        public ConfigurationServer configurationServer() {
+            return Mockito.mock(ConfigurationServer.class);
+        }
+
+        @Bean
+        public HypervisorCapabilitiesDao hypervisorCapabilitiesDao() {
+            return Mockito.mock(HypervisorCapabilitiesDao.class);
+        }
+
+        @Bean
+        public AccountManager accountManager() {
+            return Mockito.mock(AccountManager.class);
+        }
+
+        @Bean
+        public EventDao eventDao() {
+            return Mockito.mock(EventDao.class);
+        }
+
+        @Bean
+        public UserVmDao userVMDao() {
+            return Mockito.mock(UserVmDao.class);
+        }
+
+        public AddVmwareDcCmd addVmwareDatacenterCmd() {
+            return Mockito.mock(AddVmwareDcCmd.class);
+        }
+
+        public RemoveVmwareDcCmd removeVmwareDcCmd() {
+            return Mockito.mock(RemoveVmwareDcCmd.class);
+        }
+
+        public static class Library implements TypeFilter {
+
+            @Override
+            public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
+                ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class);
+                return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
+            }
+        }
+    }
+}


[10/10] git commit: updated refs/heads/vmware-datamodel to 599b826

Posted by sa...@apache.org.
Merge branch 'vmware-datamodel' of https://git-wip-us.apache.org/repos/asf/cloudstack into vmware-datamodel

Conflicts:
	plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
	plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
	plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
	plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java
	plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
	plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
	plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java
	plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java
	plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
	plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
	plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
	plugins/hypervisors/vmware/src/org/apache/cloudstack/api/response/VmwareDatacenterResponse.java
	plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/599b8269
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/599b8269
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/599b8269

Branch: refs/heads/vmware-datamodel
Commit: 599b826957c43452656a4fcf1b8472db3d231fc5
Parents: ce2c340 8996ea3
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Thu May 23 07:18:54 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Thu May 23 07:18:54 2013 +0530

----------------------------------------------------------------------
 .../hypervisor/vmware/VmwareDatacenterService.java |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/599b8269/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
----------------------------------------------------------------------
diff --cc plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
index fc77d65,f04b2b5..d1d0c9a
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterService.java
@@@ -29,4 -12,4 +29,4 @@@ public interface VmwareDatacenterServic
      public VmwareDatacenterVO addVmwareDatacenter(AddVmwareDcCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException, Exception;
  
      public boolean removeVmwareDatacenter(RemoveVmwareDcCmd cmd) throws IllegalArgumentException, ResourceInUseException, Exception;
--}
++}


[08/10] git commit: updated refs/heads/vmware-datamodel to 599b826

Posted by sa...@apache.org.
Remove old Upgrade410to420


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/8b312e20
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/8b312e20
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/8b312e20

Branch: refs/heads/vmware-datamodel
Commit: 8b312e201b65dfd824453982c80347f3c3687459
Parents: fba45a1
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Wed May 22 19:24:46 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Thu May 23 06:37:54 2013 +0530

----------------------------------------------------------------------
 .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  562 ---------------
 1 files changed, 0 insertions(+), 562 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8b312e20/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade410to420.java b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
deleted file mode 100644
index 0c53280..0000000
--- a/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ /dev/null
@@ -1,562 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package com.cloud.upgrade.dao;
-
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.script.Script;
-import org.apache.log4j.Logger;
-
-import java.io.File;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-public class Upgrade410to420 implements DbUpgrade {
-	final static Logger s_logger = Logger.getLogger(Upgrade410to420.class);
-
-	@Override
-	public String[] getUpgradableVersionRange() {
-		return new String[] { "4.1.0", "4.2.0" };
-	}
-
-	@Override
-	public String getUpgradedVersion() {
-		return "4.2.0";
-	}
-
-	@Override
-	public boolean supportsRollingUpgrade() {
-		return false;
-	}
-
-	@Override
-	public File[] getPrepareScripts() {
-		String script = Script.findScript("", "db/schema-410to420.sql");
-        if (script == null) {
-            throw new CloudRuntimeException("Unable to find db/schema-410to420.sql");
-        }
-
-        return new File[] { new File(script) };
-	}
-
-	@Override
-	public void performDataMigration(Connection conn) {
-        upgradeVmwareLabels(conn);
-        persistLegacyZones(conn);
-        createPlaceHolderNics(conn);
-        updateRemoteAccessVpn(conn);
-        updateSystemVmTemplates(conn);
-        updateCluster_details(conn);
-        updatePrimaryStore(conn);
-        addEgressFwRulesForSRXGuestNw(conn);
-        upgradeEIPNetworkOfferings(conn);
-    }
-
-	private void updateSystemVmTemplates(Connection conn) {
-	    PreparedStatement sql = null;
-        try {
-            sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
-            sql.executeUpdate();
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString());
-        } finally {
-            if (sql != null) {
-                try {
-                    sql.close();
-                } catch (SQLException e) {
-                }
-            }
-        }
-	}
-	
-	private void updatePrimaryStore(Connection conn) {
-	    PreparedStatement sql = null;
-	    PreparedStatement sql2 = null;
-        try {
-            sql = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type = 'Filesystem' or pool_type = 'LVM'");
-            sql.setString(1, "ancient primary data store provider");
-            sql.setString(2, "HOST");
-            sql.executeUpdate();
-            
-            sql2 = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type != 'Filesystem' and pool_type != 'LVM'");
-            sql2.setString(1, "ancient primary data store provider");
-            sql2.setString(2, "CLUSTER");
-            sql2.executeUpdate();
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString());
-        } finally {
-            if (sql != null) {
-                try {
-                    sql.close();
-                } catch (SQLException e) {
-                }
-            }
-            
-            if (sql2 != null) {
-                try {
-                    sql2.close();
-                } catch (SQLException e) {
-                }
-            }
-        }
-	}
-
-    //update the cluster_details table with default overcommit ratios.
-    private void updateCluster_details(Connection conn) {
-        PreparedStatement pstmt = null;
-        PreparedStatement pstmt1 = null;
-        PreparedStatement pstmt2 =null;
-        ResultSet rs = null;
-
-        try {
-            pstmt = conn.prepareStatement("select id from `cloud`.`cluster`");
-            pstmt1=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value)  VALUES(?, 'cpuOvercommitRatio', '1')");
-            pstmt2=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value)  VALUES(?, 'memoryOvercommitRatio', '1')");
-            rs = pstmt.executeQuery();
-            while (rs.next()) {
-                long id = rs.getLong(1);
-                //update cluster_details table with the default overcommit ratios.
-                pstmt1.setLong(1,id);
-                pstmt1.execute();
-                pstmt2.setLong(1,id);
-                pstmt2.execute();
-            }
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Unable to update cluster_details with default overcommit ratios.", e);
-        } finally {
-            try {
-                if (rs != null) {
-                    rs.close();
-                }
-                if (pstmt != null) {
-                    pstmt.close();
-                }
-            } catch (SQLException e) {
-            }
-        }
-    }
-
-
-	@Override
-	public File[] getCleanupScripts() {
-        String script = Script.findScript("", "db/schema-410to420-cleanup.sql");
-        if (script == null) {
-            throw new CloudRuntimeException("Unable to find db/schema-410to420-cleanup.sql");
-        }
-
-        return new File[] { new File(script) };
-    }
-
-    private String getNewLabel(ResultSet rs, String oldParamValue) {
-        int separatorIndex;
-        String oldGuestLabel;
-        String newGuestLabel = oldParamValue;
-        try {
-            // No need to iterate because the global param setting applies to all physical networks irrespective of traffic type
-            if (rs.next()) {
-                oldGuestLabel = rs.getString("vmware_network_label");
-                // guestLabel is in format [[<VSWITCHNAME>],VLANID]
-                separatorIndex = oldGuestLabel.indexOf(",");
-                if(separatorIndex > -1) {
-                    newGuestLabel += oldGuestLabel.substring(separatorIndex);
-                }
-            }
-        } catch (SQLException e) {
-            s_logger.error(new CloudRuntimeException("Failed to read vmware_network_label : " + e));
-        } finally {
-            try {
-                if (rs != null) {
-                    rs.close();
-                }
-            } catch (SQLException e) {
-            }
-        }
-        return newGuestLabel;
-    }
-
-    private void upgradeVmwareLabels(Connection conn) {
-        PreparedStatement pstmt = null;
-        ResultSet rsParams = null;
-        ResultSet rsLabel = null;
-        String newLabel;
-        String trafficType = null;
-        String trafficTypeVswitchParam;
-        String trafficTypeVswitchParamValue;
-
-        try {
-            // update the existing vmware traffic labels
-            pstmt = conn.prepareStatement("select name,value from `cloud`.`configuration` where category='Hidden' and value is not NULL and name REGEXP 'vmware\\.*\\.vswitch';");
-            rsParams = pstmt.executeQuery();
-            while (rsParams.next()) {
-                trafficTypeVswitchParam = rsParams.getString("name");
-                trafficTypeVswitchParamValue = rsParams.getString("value");
-                // When upgraded from 4.0 to 4.1 update physical network traffic label with trafficTypeVswitchParam
-                if (trafficTypeVswitchParam.equals("vmware.private.vswitch")) {
-                    trafficType = "Management"; //TODO(sateesh): Ignore storage traffic, as required physical network already implemented, anything else tobe done?
-                } else if (trafficTypeVswitchParam.equals("vmware.public.vswitch")) {
-                    trafficType = "Public";
-                } else if (trafficTypeVswitchParam.equals("vmware.guest.vswitch")) {
-                    trafficType = "Guest";
-                }
-                s_logger.debug("Updating vmware label for " + trafficType + " traffic. Update SQL statement is " + pstmt);
-                pstmt = conn.prepareStatement("select physical_network_id, traffic_type, vmware_network_label from physical_network_traffic_types where vmware_network_label is not NULL and traffic_type='" + trafficType + "';");
-                rsLabel = pstmt.executeQuery();
-                newLabel = getNewLabel(rsLabel, trafficTypeVswitchParamValue);
-                pstmt = conn.prepareStatement("update physical_network_traffic_types set vmware_network_label = " + newLabel + " where traffic_type = '" + trafficType + "' and vmware_network_label is not NULL;");
-                pstmt.executeUpdate();
-            }
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Unable to set vmware traffic labels ", e);
-        } finally {
-            try {
-                if (rsParams != null) {
-                    rsParams.close();
-                }
-                if (pstmt != null) {
-                    pstmt.close();
-                }
-            } catch (SQLException e) {
-            }
-        }
-    }
-
-    private void persistLegacyZones(Connection conn) {
-        List<Long> listOfLegacyZones = new ArrayList<Long>();
-        PreparedStatement pstmt = null;
-        PreparedStatement clustersQuery = null;
-        PreparedStatement clusterDetailsQuery = null;
-        ResultSet rs = null;
-        ResultSet clusters = null;
-        ResultSet clusterDetails = null;
-        ResultSet dcInfo = null;
-        Long vmwareDcId = 1L;
-        Long zoneId;
-        Long clusterId;
-        String clusterHypervisorType;
-        boolean legacyZone;
-        boolean ignoreZone;
-        Long count;
-        String dcOfPreviousCluster = null;
-        String dcOfCurrentCluster = null;
-        String[] tokens;
-        String url;
-        String user;
-        String password;
-        String vc = "";
-        String dcName = "";
-        String guid;
-
-        try {
-            clustersQuery = conn.prepareStatement("select id, hypervisor_type from `cloud`.`cluster` where removed is NULL");
-            pstmt = conn.prepareStatement("select id from `cloud`.`data_center` where removed is NULL");
-            rs = pstmt.executeQuery();
-
-            while (rs.next()) {
-                zoneId = rs.getLong("id");
-                legacyZone = false;
-                ignoreZone = true;
-                count = 0L;
-                // Legacy zone term is meant only for VMware
-                // Legacy zone is a zone with atleast 2 clusters & with multiple DCs or VCs
-                clusters = clustersQuery.executeQuery();
-                if (!clusters.next()) {
-                    continue; // Ignore the zone without any clusters
-                } else {
-                    dcOfPreviousCluster = null;
-                    dcOfCurrentCluster = null;
-                    do {
-                        clusterHypervisorType = clusters.getString("hypervisor_type");
-                        clusterId = clusters.getLong("id");
-                        if (clusterHypervisorType.equalsIgnoreCase("VMware")) {
-                            ignoreZone = false;
-                            if (count > 0) {
-                                dcOfPreviousCluster = dcOfCurrentCluster;
-                                clusterDetailsQuery = conn.prepareStatement("select value,username,password from `cloud`.`cluster_details` where name='url' and cluster_id=?");
-                                clusterDetailsQuery.setLong(1, clusterId);
-                                clusterDetails = clusterDetailsQuery.executeQuery();
-                                url = clusterDetails.getString("value");
-                                tokens = url.split("/"); // url format - http://vcenter/dc/cluster
-                                vc = tokens[2];
-                                dcName = tokens[3];
-                                dcOfCurrentCluster = dcName + "@" + vc;
-                                if (!dcOfPreviousCluster.equals(dcOfCurrentCluster)) {
-                                    legacyZone = true;
-                                    s_logger.debug("Marking the zone " + zoneId + " as legacy zone.");
-                                }
-                            }
-                        } else {
-                            s_logger.debug("Ignoring zone " + zoneId + " with hypervisor type " + clusterHypervisorType);
-                            break;
-                        }
-                        count++;
-                    } while (clusters.next());
-                    if (ignoreZone) {
-                        continue; // Ignore the zone with hypervisors other than VMware
-                    }
-                }
-                if (legacyZone) {
-                    listOfLegacyZones.add(zoneId);
-                } else {
-                    user = clusterDetails.getString("username");
-                    password = clusterDetails.getString("password");
-                    guid = dcName + "@" + vc;
-
-                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`vmware_data_center` (uuid, name, guid, vcenter_host, username, password) values(?, ?, ?, ?, ?, ?)");
-                    pstmt.setString(1, UUID.randomUUID().toString());
-                    pstmt.setString(2, dcName);
-                    pstmt.setString(3, guid);
-                    pstmt.setString(4, vc);
-                    pstmt.setString(5, user);
-                    pstmt.setString(6, password);
-                    pstmt.executeUpdate();
-
-                    pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`vmware_data_center` where guid=?");
-                    pstmt.setString(1, guid);
-                    dcInfo = pstmt.executeQuery();
-                    if(dcInfo.next()) {
-                        vmwareDcId = dcInfo.getLong("id");
-                    }
-
-                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`vmware_data_center_zone_map` (zone_id, vmware_data_center_id) values(?, ?)");
-                    pstmt.setLong(1, zoneId);
-                    pstmt.setLong(2, vmwareDcId);
-                    pstmt.executeUpdate();
-                }
-            }
-            updateLegacyZones(conn, listOfLegacyZones);
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Unable to load legacy zones into cloud.legacy_zones table.", e);
-        } finally {
-            try {
-                if (rs != null) {
-                    rs.close();
-                }
-                if (pstmt != null) {
-                    pstmt.close();
-                }
-                if (dcInfo != null) {
-                    dcInfo.close();
-                }
-                if (clusters != null) {
-                    clusters.close();
-                }
-                if (clusterDetails != null) {
-                    clusterDetails.close();
-                }
-                if (clustersQuery != null) {
-                    clustersQuery.close();
-                }
-                if (clusterDetailsQuery != null) {
-                    clusterDetailsQuery.close();
-                }
-            } catch (SQLException e) {
-            }
-        }
-    }
-
-    private void updateLegacyZones(Connection conn, List<Long> zones) {
-        PreparedStatement legacyZonesQuery = null;
-        //Insert legacy zones into table for legacy zones.
-        try {
-            legacyZonesQuery = conn.prepareStatement("INSERT INTO `cloud`.`legacy_zones` (zone_id) VALUES (?)");
-            for(Long zoneId : zones) {
-                legacyZonesQuery.setLong(1, zoneId);
-                legacyZonesQuery.executeUpdate();
-                s_logger.debug("Inserted zone " + zoneId + " into cloud.legacyzones table");
-            }
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Unable add zones to cloud.legacyzones table.", e);
-        } finally {
-            try {
-                if (legacyZonesQuery != null) {
-                    legacyZonesQuery.close();
-                }
-            } catch (SQLException e) {
-            }
-        }
-    }
-
-    private void createPlaceHolderNics(Connection conn) {
-        PreparedStatement pstmt = null;
-        ResultSet rs = null;
-
-        try {
-            pstmt = conn.prepareStatement("SELECT network_id, gateway, ip4_address FROM `cloud`.`nics` WHERE reserver_name IN ('DirectNetworkGuru','DirectPodBasedNetworkGuru') and vm_type='DomainRouter' AND removed IS null");
-            rs = pstmt.executeQuery();
-            while (rs.next()) {
-                    Long networkId = rs.getLong(1);
-                    String gateway = rs.getString(2);
-                    String ip = rs.getString(3);
-                    String uuid = UUID.randomUUID().toString();
-                    //Insert placeholder nic for each Domain router nic in Shared network
-                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`nics` (uuid, ip4_address, gateway, network_id, state, strategy, vm_type) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder', 'DomainRouter')");
-                    pstmt.setString(1, uuid);
-                    pstmt.setString(2, ip);
-                    pstmt.setString(3, gateway);
-                    pstmt.setLong(4, networkId);
-                    pstmt.executeUpdate();
-                    s_logger.debug("Created placeholder nic for the ipAddress " + ip);
-                
-            }
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Unable to create placeholder nics", e);
-        } finally {
-            try {
-                if (rs != null) {
-                    rs.close();
-                }
-                if (pstmt != null) {
-                    pstmt.close();
-                }
-            } catch (SQLException e) {
-            }
-        }
-    }
-    
-    
-    private void updateRemoteAccessVpn(Connection conn) {
-        PreparedStatement pstmt = null;
-        ResultSet rs = null;
-
-        try {
-            pstmt = conn.prepareStatement("SELECT vpn_server_addr_id FROM `cloud`.`remote_access_vpn`");
-            rs = pstmt.executeQuery();
-            long id=1;
-            while (rs.next()) {
-                    String uuid = UUID.randomUUID().toString();
-                    Long ipId = rs.getLong(1);
-                    pstmt = conn.prepareStatement("UPDATE `cloud`.`remote_access_vpn` set uuid=?, id=? where vpn_server_addr_id=?");
-                    pstmt.setString(1, uuid);
-                    pstmt.setLong(2, id);
-                    pstmt.setLong(3, ipId);
-                    pstmt.executeUpdate();
-                    id++;
-            }
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Unable to update id/uuid of remote_access_vpn table", e);
-        } finally {
-            try {
-                if (rs != null) {
-                    rs.close();
-                }
-                if (pstmt != null) {
-                    pstmt.close();
-                }
-            } catch (SQLException e) {
-            }
-        }
-    }
-    private void addEgressFwRulesForSRXGuestNw(Connection conn) {
-        PreparedStatement pstmt = null;
-        ResultSet rs = null;
-        ResultSet rsId = null;
-        ResultSet rsNw = null;
-        try {
-            pstmt = conn.prepareStatement("select network_id FROM `cloud`.`ntwk_service_map` where service='Firewall' and provider='JuniperSRX' ");
-            rs = pstmt.executeQuery();
-            while (rs.next()) {
-                long netId = rs.getLong(1);
-                //checking for Isolated OR Virtual
-                pstmt = conn.prepareStatement("select account_id, domain_id FROM `cloud`.`networks` where (guest_type='Isolated' OR guest_type='Virtual') and traffic_type='Guest' and vpc_id is NULL and (state='implemented' OR state='Shutdown') and id=? ");
-                pstmt.setLong(1, netId);
-                s_logger.debug("Getting account_id, domain_id from networks table: " + pstmt);
-                rsNw = pstmt.executeQuery();
-
-                if(rsNw.next()) {
-                    long accountId = rsNw.getLong(1);
-                    long domainId = rsNw.getLong(2);
-
-                    //Add new rule for the existing networks
-                    s_logger.debug("Adding default egress firewall rule for network " + netId);
-                    pstmt = conn.prepareStatement("INSERT INTO firewall_rules (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created,  traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), 'Egress')");
-                    pstmt.setString(1, UUID.randomUUID().toString());
-                    pstmt.setLong(2, accountId);
-                    pstmt.setLong(3, domainId);
-                    pstmt.setLong(4, netId);
-                    pstmt.setString(5, UUID.randomUUID().toString());
-                    s_logger.debug("Inserting default egress firewall rule " + pstmt);
-                    pstmt.executeUpdate();
-
-                    pstmt = conn.prepareStatement("select id from firewall_rules where protocol='all' and network_id=?");
-                    pstmt.setLong(1, netId);
-                    rsId = pstmt.executeQuery();
-
-                    long firewallRuleId;
-                    if(rsId.next()) {
-                        firewallRuleId = rsId.getLong(1);
-                        pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')");
-                        pstmt.setLong(1, firewallRuleId);
-                        s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt);
-                        pstmt.executeUpdate();
-                    }
-                }
-            }
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Unable to set egress firewall rules ", e);
-        } finally {
-            try {
-                if (rs != null) {
-                    rs.close();
-                }
-                if (pstmt != null) {
-                    pstmt.close();
-                }
-            } catch (SQLException e) {
-            }
-        }
-    }
-
-    private void upgradeEIPNetworkOfferings(Connection conn) {
-
-        PreparedStatement pstmt = null;
-        ResultSet rs = null;
-
-        try {
-            pstmt = conn.prepareStatement("select id, elastic_ip_service from `cloud`.`network_offerings` where traffic_type='Guest'");
-            rs = pstmt.executeQuery();
-            while (rs.next()) {
-                long id = rs.getLong(1);
-                // check if elastic IP service is enabled for network offering
-                if (rs.getLong(2) != 0) {
-                    //update network offering with eip_associate_public_ip set to true
-                    pstmt = conn.prepareStatement("UPDATE `cloud`.`network_offerings` set eip_associate_public_ip=? where id=?");
-                    pstmt.setBoolean(1, true);
-                    pstmt.setLong(2, id);
-                    pstmt.executeUpdate();
-                }
-            }
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Unable to set elastic_ip_service for network offerings with EIP service enabled.", e);
-        } finally {
-            try {
-                if (rs != null) {
-                    rs.close();
-                }
-                if (pstmt != null) {
-                    pstmt.close();
-                }
-            } catch (SQLException e) {
-            }
-        }
-    }
-}


[06/10] git commit: updated refs/heads/vmware-datamodel to 599b826

Posted by sa...@apache.org.
Fix trailing white spaces.

Minor fixes, removed duplicate entry for a column in schema-410-420.
Renamed a method.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/36feef96
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/36feef96
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/36feef96

Branch: refs/heads/vmware-datamodel
Commit: 36feef9697879eda6cdb6ead51c0b3a44f4e50c3
Parents: 037627e
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Sun May 19 17:22:34 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Thu May 23 06:37:45 2013 +0530

----------------------------------------------------------------------
 .../vmware/VmwareDatacenterZoneMapVO.java          |    6 +++---
 .../hypervisor/vmware/dao/VmwareDatacenterDao.java |    8 ++++----
 .../api/command/admin/zone/AddVmwareDcCmd.java     |    2 +-
 .../api/command/admin/zone/RemoveVmwareDcCmd.java  |    4 ++--
 .../src/com/cloud/upgrade/dao/Upgrade410to420.java |    2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36feef96/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
index e20386d..4e2cbe9 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java
@@ -56,7 +56,7 @@ public class VmwareDatacenterZoneMapVO implements VmwareDatacenterZoneMap {
     public long getId() {
         return id;
     }
-    
+
     @Override
     public long getZoneId() {
         return zoneId;
@@ -71,7 +71,7 @@ public class VmwareDatacenterZoneMapVO implements VmwareDatacenterZoneMap {
         this.zoneId = zoneId;
     }
 
-    public void setVsmId(long vmwareDcId) {
+    public void setVmwareDcId(long vmwareDcId) {
         this.vmwareDcId = vmwareDcId;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36feef96/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
index e339604..c3f92ae 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java
@@ -8,14 +8,14 @@ import com.cloud.utils.db.GenericDao;
 public interface VmwareDatacenterDao extends GenericDao<VmwareDatacenterVO, Long> {
 
     /**
-     * Return a VMware Datacenter given guid 
+     * Return a VMware Datacenter given guid
      * @param guid of VMware datacenter
      * @return VmwareDatacenterVO for the VMware datacenter having the specified guid.
      */
     VmwareDatacenterVO getVmwareDatacenterByGuid(String guid);
 
     /**
-     * Return a VMware Datacenter given name and vCenter host. 
+     * Return a VMware Datacenter given name and vCenter host.
      * For legacy zones multiple records will be present in the table.
      * @param name of VMware datacenter
      * @param vCenter host
@@ -34,14 +34,14 @@ public interface VmwareDatacenterDao extends GenericDao<VmwareDatacenterVO, Long
     /**
      * Return a list of VMware Datacenters belonging to specified vCenter
      * @param vCenter Host
-     * @return list of VmwareDatacenterVO for all VMware datacenters belonging to 
+     * @return list of VmwareDatacenterVO for all VMware datacenters belonging to
      * specified vCenter
      */
     List<VmwareDatacenterVO> listVmwareDatacenterByVcenter(String vCenterHost);
 
     /**
      * Lists all associated VMware datacenter on the management server.
-     * @return list of VmwareDatacenterVO for all associated VMware datacenters 
+     * @return list of VmwareDatacenterVO for all associated VMware datacenters
      */
     List<VmwareDatacenterVO> listAllVmwareDatacenters();
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36feef96/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
index 3d9101b..0d9057e 100644
--- a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
+++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
@@ -75,7 +75,7 @@ public class AddVmwareDcCmd extends BaseCmd {
     @Override
     public void execute() {
         try {
-            VmwareDatacenterResponse response = new VmwareDatacenterResponse(); 
+            VmwareDatacenterResponse response = new VmwareDatacenterResponse();
             VmwareDatacenterVO result = _vmwareDatacenterService.addVmwareDatacenter(this);
             if (result != null){
                 response.setId(result.getUuid());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36feef96/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
index cf54698..7de9056 100644
--- a/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
+++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
@@ -28,9 +28,9 @@ import com.cloud.user.Account;
 public class RemoveVmwareDcCmd extends BaseCmd {
 
     @Inject public VmwareDatacenterService _vmwareDatacenterService;
-    
+
     public static final Logger s_logger = Logger.getLogger(AddVmwareDcCmd.class.getName());
-    
+
     private static final String s_name = "removevmwaredcresponse";
 
     @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class, required=true,

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36feef96/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade410to420.java b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
index c3e37de..0c53280 100644
--- a/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -71,7 +71,7 @@ public class Upgrade410to420 implements DbUpgrade {
         addEgressFwRulesForSRXGuestNw(conn);
         upgradeEIPNetworkOfferings(conn);
     }
-	
+
 	private void updateSystemVmTemplates(Connection conn) {
 	    PreparedStatement sql = null;
         try {


[03/10] git commit: updated refs/heads/vmware-datamodel to 599b826

Posted by sa...@apache.org.
CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Upgrade changes with legacy zone support

CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Plugin, API & DB changes

CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Upgrade changes with legacy zone support

CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter Upgrade changes with legacy zone support

DC-Zone mapping constraints should allow multiple hypervisors per zone.
Such zones would just be ignored.
Looking for only VMware clusters in the zone while associating a VMware DC with a zone.
Fixed upgrade path for zones with 1 cluster from 1 DC/vCenter. Auto-associating in this case.

CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
Plugin, API & DB changes


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/579a8121
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/579a8121
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/579a8121

Branch: refs/heads/vmware-datamodel
Commit: 579a8121128ad6eab784d7faf680c17fbf0fc792
Parents: 3db1cdf
Author: Sateesh Chodapuneedi <sa...@apache.org>
Authored: Mon May 6 15:59:24 2013 +0530
Committer: Sateesh Chodapuneedi <sa...@apache.org>
Committed: Thu May 23 06:36:29 2013 +0530

----------------------------------------------------------------------
 .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  179 +++++
 .../cloud/hypervisor/vmware/VmwareDatacenter.java  |    2 -
 .../hypervisor/vmware/VmwareDatacenterVO.java      |   18 +-
 .../vmware/manager/VmwareManagerImpl.java          |   35 +-
 .../src/com/cloud/upgrade/dao/Upgrade410to420.java |  562 +++++++++++++++
 setup/db/db/schema-410to420.sql                    |    1 -
 6 files changed, 754 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/579a8121/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index c03d377..0d630a0 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -18,6 +18,7 @@
 package com.cloud.upgrade.dao;
 
 import com.cloud.deploy.DeploymentPlanner;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.Script;
 import org.apache.log4j.Logger;
@@ -28,6 +29,8 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Types;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.UUID;
 import com.cloud.network.vpc.NetworkACL;
 
@@ -62,6 +65,7 @@ public class Upgrade410to420 implements DbUpgrade {
 	@Override
 	public void performDataMigration(Connection conn) {
         upgradeVmwareLabels(conn);
+        persistLegacyZones(conn);
         createPlaceHolderNics(conn);
         updateRemoteAccessVpn(conn);
         updateSystemVmTemplates(conn);
@@ -245,6 +249,181 @@ public class Upgrade410to420 implements DbUpgrade {
         }
     }
 
+    private void persistLegacyZones(Connection conn) {
+        List<Long> listOfLegacyZones = new ArrayList<Long>();
+        PreparedStatement pstmt = null;
+        PreparedStatement clustersQuery = null;
+        PreparedStatement clusterDetailsQuery = null;
+        ResultSet rs = null;
+        ResultSet clusters = null;
+        ResultSet clusterDetails = null;
+        ResultSet dcInfo = null;
+        Long vmwareDcId = 1L;
+        Long zoneId;
+        Long clusterId;
+        String clusterHypervisorType;
+        boolean legacyZone;
+        boolean ignoreZone;
+        Long count;
+        String dcOfPreviousCluster = null;
+        String dcOfCurrentCluster = null;
+        String[] tokens;
+        String url;
+        String user = "";
+        String password = "";
+        String vc = "";
+        String dcName = "";
+        String guid;
+        String key;
+        String value;
+
+        try {
+            clustersQuery = conn.prepareStatement("select id, hypervisor_type from `cloud`.`cluster` where removed is NULL");
+            pstmt = conn.prepareStatement("select id from `cloud`.`data_center` where removed is NULL");
+            rs = pstmt.executeQuery();
+
+            while (rs.next()) {
+                zoneId = rs.getLong("id");
+                legacyZone = false;
+                ignoreZone = true;
+                count = 0L;
+                // Legacy zone term is meant only for VMware
+                // Legacy zone is a zone with atleast 2 clusters & with multiple DCs or VCs
+                clusters = clustersQuery.executeQuery();
+                if (!clusters.next()) {
+                    continue; // Ignore the zone without any clusters
+                } else {
+                    dcOfPreviousCluster = null;
+                    dcOfCurrentCluster = null;
+                    do {
+                        clusterHypervisorType = clusters.getString("hypervisor_type");
+                        clusterId = clusters.getLong("id");
+                        if (clusterHypervisorType.equalsIgnoreCase("VMware")) {
+                            ignoreZone = false;
+                            clusterDetailsQuery = conn.prepareStatement("select value from `cloud`.`cluster_details` where name='url' and cluster_id=?");
+                            clusterDetailsQuery.setLong(1, clusterId);
+                            clusterDetails = clusterDetailsQuery.executeQuery();
+                            clusterDetails.next();
+                            url = clusterDetails.getString("value");
+                            tokens = url.split("/"); // url format - http://vcenter/dc/cluster
+                            vc = tokens[2];
+                            dcName = tokens[3];
+                            if (count > 0) {
+                                dcOfPreviousCluster = dcOfCurrentCluster;
+                                dcOfCurrentCluster = dcName + "@" + vc;
+                                if (!dcOfPreviousCluster.equals(dcOfCurrentCluster)) {
+                                    legacyZone = true;
+                                    s_logger.debug("Marking the zone " + zoneId + " as legacy zone.");
+                                }
+                            }
+                        } else {
+                            s_logger.debug("Ignoring zone " + zoneId + " with hypervisor type " + clusterHypervisorType);
+                            break;
+                        }
+                        count++;
+                    } while (clusters.next());
+                    if (ignoreZone) {
+                        continue; // Ignore the zone with hypervisors other than VMware
+                    }
+                }
+                if (legacyZone) {
+                    listOfLegacyZones.add(zoneId);
+                } else {
+                    assert(clusterDetails != null) : "Couldn't retrieve details of cluster!";
+                    s_logger.debug("Discovered non-legacy zone " + zoneId + ". Processing the zone to associate with VMware datacenter.");
+
+                    clusterDetailsQuery = conn.prepareStatement("select name, value from `cloud`.`cluster_details` where cluster_id=?");
+                    clusterDetailsQuery.setLong(1, clusterId);
+                    clusterDetails = clusterDetailsQuery.executeQuery();
+                    while (clusterDetails.next()) {
+                        key = clusterDetails.getString(1);
+                        value = clusterDetails.getString(2);
+                        if (key.equalsIgnoreCase("username")) {
+                            user = value;
+                        } else if (key.equalsIgnoreCase("password")) {
+                            password = value;
+                        }
+                    }
+                    guid = dcName + "@" + vc;
+
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`vmware_data_center` (uuid, name, guid, vcenter_host, username, password) values(?, ?, ?, ?, ?, ?)");
+                    pstmt.setString(1, UUID.randomUUID().toString());
+                    pstmt.setString(2, dcName);
+                    pstmt.setString(3, guid);
+                    pstmt.setString(4, vc);
+                    pstmt.setString(5, user);
+                    pstmt.setString(6, password);
+                    pstmt.executeUpdate();
+
+                    pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`vmware_data_center` where guid=?");
+                    pstmt.setString(1, guid);
+                    dcInfo = pstmt.executeQuery();
+                    if(dcInfo.next()) {
+                        vmwareDcId = dcInfo.getLong("id");
+                    }
+
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`vmware_data_center_zone_map` (zone_id, vmware_data_center_id) values(?, ?)");
+                    pstmt.setLong(1, zoneId);
+                    pstmt.setLong(2, vmwareDcId);
+                    pstmt.executeUpdate();
+                }
+            }
+            updateLegacyZones(conn, listOfLegacyZones);
+        } catch (SQLException e) {
+            String msg = "Unable to discover legacy zones." + e.getMessage();
+            s_logger.error(msg);
+            throw new CloudRuntimeException(msg, e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+                if (dcInfo != null) {
+                    dcInfo.close();
+                }
+                if (clusters != null) {
+                    clusters.close();
+                }
+                if (clusterDetails != null) {
+                    clusterDetails.close();
+                }
+                if (clustersQuery != null) {
+                    clustersQuery.close();
+                }
+                if (clusterDetailsQuery != null) {
+                    clusterDetailsQuery.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+    private void updateLegacyZones(Connection conn, List<Long> zones) {
+        PreparedStatement legacyZonesQuery = null;
+        //Insert legacy zones into table for legacy zones.
+        try {
+            legacyZonesQuery = conn.prepareStatement("INSERT INTO `cloud`.`legacy_zones` (zone_id) VALUES (?)");
+            for(Long zoneId : zones) {
+                legacyZonesQuery.setLong(1, zoneId);
+                legacyZonesQuery.executeUpdate();
+                s_logger.debug("Inserted zone " + zoneId + " into cloud.legacyzones table");
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable add zones to cloud.legacyzones table.", e);
+        } finally {
+            try {
+                if (legacyZonesQuery != null) {
+                    legacyZonesQuery.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+>>>>>>> CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter
     private void createPlaceHolderNics(Connection conn) {
         PreparedStatement pstmt = null;
         ResultSet rs = null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/579a8121/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
index 246b477..c5d35b1 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java
@@ -9,8 +9,6 @@ public interface VmwareDatacenter extends Identity, InternalIdentity {
 
     String getVmwareDatacenterName();
 
-    ManagedObjectReference getVmwareDatacenterMor();
-
     String getGuid();
 
     String getVcenterHost();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/579a8121/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
index aaeccc2..4b08d9e 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java
@@ -11,7 +11,6 @@ import javax.persistence.Table;
 
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.db.Encrypt;
-import com.vmware.vim25.ManagedObjectReference;
 
 /**
  * VmwareDatacenterVO contains information of Vmware Datacenter associated with a CloudStack zone.
@@ -76,17 +75,6 @@ public class VmwareDatacenterVO implements VmwareDatacenter {
     }
 
     @Override
-    public ManagedObjectReference getVmwareDatacenterMor() {
-        String morString = guid.split("@")[0];
-        ManagedObjectReference mor = new ManagedObjectReference();
-
-        mor.setType(morString.split(":")[0]);
-        mor.setValue(morString.split(":")[1]);
-
-        return mor;
-    }
-
-    @Override
     public String getVcenterHost() {
         return vCenterHost;
     }
@@ -152,4 +140,8 @@ public class VmwareDatacenterVO implements VmwareDatacenter {
         this.uuid = UUID.randomUUID().toString();
     }
 
-}
\ No newline at end of file
+<<<<<<< HEAD
+}
+=======
+}
+>>>>>>> CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/579a8121/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index 3b94537..c90a8ff 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -910,35 +910,12 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
         // Zone validation
         validateZone(zoneId, "add VMware datacenter to zone");
 
-        // Check if the zone exists in the system
-        //      If no, throw invalid param value exception
-        DataCenterVO zone = _dcDao.findById(zoneId);
-        if (zone == null) {
-            InvalidParameterValueException ex = new InvalidParameterValueException(
-                    "Can't find zone by the id specified");
-            ex.addProxyObject(zone, zoneId, "dcId");
-            throw ex;
-        }
-
         VmwareDatacenterZoneMapVO vmwareDcZoneMap = _vmwareDcZoneMapDao.findByZoneId(zoneId);
         // Check if zone is associated with VMware DC
         if (vmwareDcZoneMap != null) {
             throw new CloudRuntimeException("Zone " + zoneId + " is already associated with a VMware datacenter.");
         }
 
-        // Check if zone has resources? - For now look for clusters
-        //      If yes, throw resource in use execption
-        List<ClusterVO> clusters = _clusterDao.listByZoneId(zoneId);
-        if (clusters != null) {
-            try {
-            if (clusters.size() > 0) {
-                throw new ResourceInUseException("Zone has one or more clusters."
-                        + " Can't add VMware datacenter to zone which already has clusters.");
-            }}catch(Throwable t) {
-                s_logger.error(t);
-            }
-        }
-
         // Validate url and get uri
         URI uri = getUri(url);
 
@@ -985,8 +962,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
 
             // Check if DC is already associated with another cloudstack deployment
             // Get custom field property cloud.zone over this DC
-            dcMor = dcMo.getMor();
-            guid = dcMor.getType() + ":" + dcMor.getValue() + "@" + vCenterHost;
+            guid = vmwareDcName + "@" + vCenterHost;
 
             dcCustomFieldValue = dcMo.getCustomFieldValue(CustomFieldConstants.CLOUD_ZONE);
             if (dcCustomFieldValue == null) {
@@ -1130,9 +1106,14 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
 
         // Check if zone has resources? - For now look for clusters
         List<ClusterVO> clusters = _clusterDao.listByZoneId(zoneId);
-        if(clusters != null && clusters.size() != 0) {
-            throw new ResourceInUseException("Zone has one or more clusters."
+        if (clusters != null && clusters.size() > 0) {
+            // Look for VMware hypervisor.
+            for (ClusterVO cluster : clusters) {
+                if (cluster.getHypervisorType().equals(HypervisorType.VMware)) {
+                    throw new ResourceInUseException("Zone has one or more clusters."
                         + " Can't " + errStr + " which already has clusters.");
+                }
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/579a8121/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade410to420.java b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
new file mode 100644
index 0000000..c3e37de
--- /dev/null
+++ b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -0,0 +1,562 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.upgrade.dao;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+import org.apache.log4j.Logger;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+public class Upgrade410to420 implements DbUpgrade {
+	final static Logger s_logger = Logger.getLogger(Upgrade410to420.class);
+
+	@Override
+	public String[] getUpgradableVersionRange() {
+		return new String[] { "4.1.0", "4.2.0" };
+	}
+
+	@Override
+	public String getUpgradedVersion() {
+		return "4.2.0";
+	}
+
+	@Override
+	public boolean supportsRollingUpgrade() {
+		return false;
+	}
+
+	@Override
+	public File[] getPrepareScripts() {
+		String script = Script.findScript("", "db/schema-410to420.sql");
+        if (script == null) {
+            throw new CloudRuntimeException("Unable to find db/schema-410to420.sql");
+        }
+
+        return new File[] { new File(script) };
+	}
+
+	@Override
+	public void performDataMigration(Connection conn) {
+        upgradeVmwareLabels(conn);
+        persistLegacyZones(conn);
+        createPlaceHolderNics(conn);
+        updateRemoteAccessVpn(conn);
+        updateSystemVmTemplates(conn);
+        updateCluster_details(conn);
+        updatePrimaryStore(conn);
+        addEgressFwRulesForSRXGuestNw(conn);
+        upgradeEIPNetworkOfferings(conn);
+    }
+	
+	private void updateSystemVmTemplates(Connection conn) {
+	    PreparedStatement sql = null;
+        try {
+            sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
+            sql.executeUpdate();
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString());
+        } finally {
+            if (sql != null) {
+                try {
+                    sql.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+	}
+	
+	private void updatePrimaryStore(Connection conn) {
+	    PreparedStatement sql = null;
+	    PreparedStatement sql2 = null;
+        try {
+            sql = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type = 'Filesystem' or pool_type = 'LVM'");
+            sql.setString(1, "ancient primary data store provider");
+            sql.setString(2, "HOST");
+            sql.executeUpdate();
+            
+            sql2 = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type != 'Filesystem' and pool_type != 'LVM'");
+            sql2.setString(1, "ancient primary data store provider");
+            sql2.setString(2, "CLUSTER");
+            sql2.executeUpdate();
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString());
+        } finally {
+            if (sql != null) {
+                try {
+                    sql.close();
+                } catch (SQLException e) {
+                }
+            }
+            
+            if (sql2 != null) {
+                try {
+                    sql2.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+	}
+
+    //update the cluster_details table with default overcommit ratios.
+    private void updateCluster_details(Connection conn) {
+        PreparedStatement pstmt = null;
+        PreparedStatement pstmt1 = null;
+        PreparedStatement pstmt2 =null;
+        ResultSet rs = null;
+
+        try {
+            pstmt = conn.prepareStatement("select id from `cloud`.`cluster`");
+            pstmt1=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value)  VALUES(?, 'cpuOvercommitRatio', '1')");
+            pstmt2=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value)  VALUES(?, 'memoryOvercommitRatio', '1')");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                long id = rs.getLong(1);
+                //update cluster_details table with the default overcommit ratios.
+                pstmt1.setLong(1,id);
+                pstmt1.execute();
+                pstmt2.setLong(1,id);
+                pstmt2.execute();
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to update cluster_details with default overcommit ratios.", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+
+	@Override
+	public File[] getCleanupScripts() {
+        String script = Script.findScript("", "db/schema-410to420-cleanup.sql");
+        if (script == null) {
+            throw new CloudRuntimeException("Unable to find db/schema-410to420-cleanup.sql");
+        }
+
+        return new File[] { new File(script) };
+    }
+
+    private String getNewLabel(ResultSet rs, String oldParamValue) {
+        int separatorIndex;
+        String oldGuestLabel;
+        String newGuestLabel = oldParamValue;
+        try {
+            // No need to iterate because the global param setting applies to all physical networks irrespective of traffic type
+            if (rs.next()) {
+                oldGuestLabel = rs.getString("vmware_network_label");
+                // guestLabel is in format [[<VSWITCHNAME>],VLANID]
+                separatorIndex = oldGuestLabel.indexOf(",");
+                if(separatorIndex > -1) {
+                    newGuestLabel += oldGuestLabel.substring(separatorIndex);
+                }
+            }
+        } catch (SQLException e) {
+            s_logger.error(new CloudRuntimeException("Failed to read vmware_network_label : " + e));
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+        return newGuestLabel;
+    }
+
+    private void upgradeVmwareLabels(Connection conn) {
+        PreparedStatement pstmt = null;
+        ResultSet rsParams = null;
+        ResultSet rsLabel = null;
+        String newLabel;
+        String trafficType = null;
+        String trafficTypeVswitchParam;
+        String trafficTypeVswitchParamValue;
+
+        try {
+            // update the existing vmware traffic labels
+            pstmt = conn.prepareStatement("select name,value from `cloud`.`configuration` where category='Hidden' and value is not NULL and name REGEXP 'vmware\\.*\\.vswitch';");
+            rsParams = pstmt.executeQuery();
+            while (rsParams.next()) {
+                trafficTypeVswitchParam = rsParams.getString("name");
+                trafficTypeVswitchParamValue = rsParams.getString("value");
+                // When upgraded from 4.0 to 4.1 update physical network traffic label with trafficTypeVswitchParam
+                if (trafficTypeVswitchParam.equals("vmware.private.vswitch")) {
+                    trafficType = "Management"; //TODO(sateesh): Ignore storage traffic, as required physical network already implemented, anything else tobe done?
+                } else if (trafficTypeVswitchParam.equals("vmware.public.vswitch")) {
+                    trafficType = "Public";
+                } else if (trafficTypeVswitchParam.equals("vmware.guest.vswitch")) {
+                    trafficType = "Guest";
+                }
+                s_logger.debug("Updating vmware label for " + trafficType + " traffic. Update SQL statement is " + pstmt);
+                pstmt = conn.prepareStatement("select physical_network_id, traffic_type, vmware_network_label from physical_network_traffic_types where vmware_network_label is not NULL and traffic_type='" + trafficType + "';");
+                rsLabel = pstmt.executeQuery();
+                newLabel = getNewLabel(rsLabel, trafficTypeVswitchParamValue);
+                pstmt = conn.prepareStatement("update physical_network_traffic_types set vmware_network_label = " + newLabel + " where traffic_type = '" + trafficType + "' and vmware_network_label is not NULL;");
+                pstmt.executeUpdate();
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to set vmware traffic labels ", e);
+        } finally {
+            try {
+                if (rsParams != null) {
+                    rsParams.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+    private void persistLegacyZones(Connection conn) {
+        List<Long> listOfLegacyZones = new ArrayList<Long>();
+        PreparedStatement pstmt = null;
+        PreparedStatement clustersQuery = null;
+        PreparedStatement clusterDetailsQuery = null;
+        ResultSet rs = null;
+        ResultSet clusters = null;
+        ResultSet clusterDetails = null;
+        ResultSet dcInfo = null;
+        Long vmwareDcId = 1L;
+        Long zoneId;
+        Long clusterId;
+        String clusterHypervisorType;
+        boolean legacyZone;
+        boolean ignoreZone;
+        Long count;
+        String dcOfPreviousCluster = null;
+        String dcOfCurrentCluster = null;
+        String[] tokens;
+        String url;
+        String user;
+        String password;
+        String vc = "";
+        String dcName = "";
+        String guid;
+
+        try {
+            clustersQuery = conn.prepareStatement("select id, hypervisor_type from `cloud`.`cluster` where removed is NULL");
+            pstmt = conn.prepareStatement("select id from `cloud`.`data_center` where removed is NULL");
+            rs = pstmt.executeQuery();
+
+            while (rs.next()) {
+                zoneId = rs.getLong("id");
+                legacyZone = false;
+                ignoreZone = true;
+                count = 0L;
+                // Legacy zone term is meant only for VMware
+                // Legacy zone is a zone with atleast 2 clusters & with multiple DCs or VCs
+                clusters = clustersQuery.executeQuery();
+                if (!clusters.next()) {
+                    continue; // Ignore the zone without any clusters
+                } else {
+                    dcOfPreviousCluster = null;
+                    dcOfCurrentCluster = null;
+                    do {
+                        clusterHypervisorType = clusters.getString("hypervisor_type");
+                        clusterId = clusters.getLong("id");
+                        if (clusterHypervisorType.equalsIgnoreCase("VMware")) {
+                            ignoreZone = false;
+                            if (count > 0) {
+                                dcOfPreviousCluster = dcOfCurrentCluster;
+                                clusterDetailsQuery = conn.prepareStatement("select value,username,password from `cloud`.`cluster_details` where name='url' and cluster_id=?");
+                                clusterDetailsQuery.setLong(1, clusterId);
+                                clusterDetails = clusterDetailsQuery.executeQuery();
+                                url = clusterDetails.getString("value");
+                                tokens = url.split("/"); // url format - http://vcenter/dc/cluster
+                                vc = tokens[2];
+                                dcName = tokens[3];
+                                dcOfCurrentCluster = dcName + "@" + vc;
+                                if (!dcOfPreviousCluster.equals(dcOfCurrentCluster)) {
+                                    legacyZone = true;
+                                    s_logger.debug("Marking the zone " + zoneId + " as legacy zone.");
+                                }
+                            }
+                        } else {
+                            s_logger.debug("Ignoring zone " + zoneId + " with hypervisor type " + clusterHypervisorType);
+                            break;
+                        }
+                        count++;
+                    } while (clusters.next());
+                    if (ignoreZone) {
+                        continue; // Ignore the zone with hypervisors other than VMware
+                    }
+                }
+                if (legacyZone) {
+                    listOfLegacyZones.add(zoneId);
+                } else {
+                    user = clusterDetails.getString("username");
+                    password = clusterDetails.getString("password");
+                    guid = dcName + "@" + vc;
+
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`vmware_data_center` (uuid, name, guid, vcenter_host, username, password) values(?, ?, ?, ?, ?, ?)");
+                    pstmt.setString(1, UUID.randomUUID().toString());
+                    pstmt.setString(2, dcName);
+                    pstmt.setString(3, guid);
+                    pstmt.setString(4, vc);
+                    pstmt.setString(5, user);
+                    pstmt.setString(6, password);
+                    pstmt.executeUpdate();
+
+                    pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`vmware_data_center` where guid=?");
+                    pstmt.setString(1, guid);
+                    dcInfo = pstmt.executeQuery();
+                    if(dcInfo.next()) {
+                        vmwareDcId = dcInfo.getLong("id");
+                    }
+
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`vmware_data_center_zone_map` (zone_id, vmware_data_center_id) values(?, ?)");
+                    pstmt.setLong(1, zoneId);
+                    pstmt.setLong(2, vmwareDcId);
+                    pstmt.executeUpdate();
+                }
+            }
+            updateLegacyZones(conn, listOfLegacyZones);
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to load legacy zones into cloud.legacy_zones table.", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+                if (dcInfo != null) {
+                    dcInfo.close();
+                }
+                if (clusters != null) {
+                    clusters.close();
+                }
+                if (clusterDetails != null) {
+                    clusterDetails.close();
+                }
+                if (clustersQuery != null) {
+                    clustersQuery.close();
+                }
+                if (clusterDetailsQuery != null) {
+                    clusterDetailsQuery.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+    private void updateLegacyZones(Connection conn, List<Long> zones) {
+        PreparedStatement legacyZonesQuery = null;
+        //Insert legacy zones into table for legacy zones.
+        try {
+            legacyZonesQuery = conn.prepareStatement("INSERT INTO `cloud`.`legacy_zones` (zone_id) VALUES (?)");
+            for(Long zoneId : zones) {
+                legacyZonesQuery.setLong(1, zoneId);
+                legacyZonesQuery.executeUpdate();
+                s_logger.debug("Inserted zone " + zoneId + " into cloud.legacyzones table");
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable add zones to cloud.legacyzones table.", e);
+        } finally {
+            try {
+                if (legacyZonesQuery != null) {
+                    legacyZonesQuery.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+    private void createPlaceHolderNics(Connection conn) {
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+
+        try {
+            pstmt = conn.prepareStatement("SELECT network_id, gateway, ip4_address FROM `cloud`.`nics` WHERE reserver_name IN ('DirectNetworkGuru','DirectPodBasedNetworkGuru') and vm_type='DomainRouter' AND removed IS null");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                    Long networkId = rs.getLong(1);
+                    String gateway = rs.getString(2);
+                    String ip = rs.getString(3);
+                    String uuid = UUID.randomUUID().toString();
+                    //Insert placeholder nic for each Domain router nic in Shared network
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`nics` (uuid, ip4_address, gateway, network_id, state, strategy, vm_type) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder', 'DomainRouter')");
+                    pstmt.setString(1, uuid);
+                    pstmt.setString(2, ip);
+                    pstmt.setString(3, gateway);
+                    pstmt.setLong(4, networkId);
+                    pstmt.executeUpdate();
+                    s_logger.debug("Created placeholder nic for the ipAddress " + ip);
+                
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to create placeholder nics", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+    
+    
+    private void updateRemoteAccessVpn(Connection conn) {
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+
+        try {
+            pstmt = conn.prepareStatement("SELECT vpn_server_addr_id FROM `cloud`.`remote_access_vpn`");
+            rs = pstmt.executeQuery();
+            long id=1;
+            while (rs.next()) {
+                    String uuid = UUID.randomUUID().toString();
+                    Long ipId = rs.getLong(1);
+                    pstmt = conn.prepareStatement("UPDATE `cloud`.`remote_access_vpn` set uuid=?, id=? where vpn_server_addr_id=?");
+                    pstmt.setString(1, uuid);
+                    pstmt.setLong(2, id);
+                    pstmt.setLong(3, ipId);
+                    pstmt.executeUpdate();
+                    id++;
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to update id/uuid of remote_access_vpn table", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+    private void addEgressFwRulesForSRXGuestNw(Connection conn) {
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+        ResultSet rsId = null;
+        ResultSet rsNw = null;
+        try {
+            pstmt = conn.prepareStatement("select network_id FROM `cloud`.`ntwk_service_map` where service='Firewall' and provider='JuniperSRX' ");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                long netId = rs.getLong(1);
+                //checking for Isolated OR Virtual
+                pstmt = conn.prepareStatement("select account_id, domain_id FROM `cloud`.`networks` where (guest_type='Isolated' OR guest_type='Virtual') and traffic_type='Guest' and vpc_id is NULL and (state='implemented' OR state='Shutdown') and id=? ");
+                pstmt.setLong(1, netId);
+                s_logger.debug("Getting account_id, domain_id from networks table: " + pstmt);
+                rsNw = pstmt.executeQuery();
+
+                if(rsNw.next()) {
+                    long accountId = rsNw.getLong(1);
+                    long domainId = rsNw.getLong(2);
+
+                    //Add new rule for the existing networks
+                    s_logger.debug("Adding default egress firewall rule for network " + netId);
+                    pstmt = conn.prepareStatement("INSERT INTO firewall_rules (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created,  traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), 'Egress')");
+                    pstmt.setString(1, UUID.randomUUID().toString());
+                    pstmt.setLong(2, accountId);
+                    pstmt.setLong(3, domainId);
+                    pstmt.setLong(4, netId);
+                    pstmt.setString(5, UUID.randomUUID().toString());
+                    s_logger.debug("Inserting default egress firewall rule " + pstmt);
+                    pstmt.executeUpdate();
+
+                    pstmt = conn.prepareStatement("select id from firewall_rules where protocol='all' and network_id=?");
+                    pstmt.setLong(1, netId);
+                    rsId = pstmt.executeQuery();
+
+                    long firewallRuleId;
+                    if(rsId.next()) {
+                        firewallRuleId = rsId.getLong(1);
+                        pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')");
+                        pstmt.setLong(1, firewallRuleId);
+                        s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt);
+                        pstmt.executeUpdate();
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to set egress firewall rules ", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+    private void upgradeEIPNetworkOfferings(Connection conn) {
+
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+
+        try {
+            pstmt = conn.prepareStatement("select id, elastic_ip_service from `cloud`.`network_offerings` where traffic_type='Guest'");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                long id = rs.getLong(1);
+                // check if elastic IP service is enabled for network offering
+                if (rs.getLong(2) != 0) {
+                    //update network offering with eip_associate_public_ip set to true
+                    pstmt = conn.prepareStatement("UPDATE `cloud`.`network_offerings` set eip_associate_public_ip=? where id=?");
+                    pstmt.setBoolean(1, true);
+                    pstmt.setLong(2, id);
+                    pstmt.executeUpdate();
+                }
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to set elastic_ip_service for network offerings with EIP service enabled.", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/579a8121/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 7199fd3..e4baacd 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -1117,7 +1117,6 @@ CREATE VIEW `cloud`.`account_view` AS
     select
         account.id,
         account.uuid,
-        account.uuid,
         account.account_name,
         account.type,
         account.state,