incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject [2/6] git commit: Provisioning Service: register Pod, Cluster, Deregister Zone/Pod/Cluster and unit tests
Date Thu, 03 Jan 2013 19:54:03 GMT
Provisioning Service: register Pod, Cluster, Deregister Zone/Pod/Cluster and unit tests


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

Branch: refs/heads/javelin
Commit: 3ff3a47e36d9d0f8776ff8a5f575fdd18a0e4b7b
Parents: 1eb64e6
Author: Prachi Damle <prachi@cloud.com>
Authored: Thu Dec 20 18:19:16 2012 +0530
Committer: Prachi Damle <prachi@cloud.com>
Committed: Thu Jan 3 11:44:37 2013 -0800

----------------------------------------------------------------------
 .../datacenter/entity/api/ClusterEntity.java       |   22 +-
 .../engine/datacenter/entity/api/PodEntity.java    |   17 +-
 .../engine/datacenter/entity/api/ZoneEntity.java   |    6 +-
 .../engine/entity/api/CloudStackEntity.java        |    1 +
 .../rest/service/api/ProvisioningRestService.java  |   84 ++++
 .../engine/service/api/ProvisioningService.java    |   12 +-
 .../datacenter/entity/api/ClusterEntityImpl.java   |  193 ++++++++++
 .../entity/api/DataCenterResourceManager.java      |   12 +-
 .../entity/api/DataCenterResourceManagerImpl.java  |   61 +++-
 .../datacenter/entity/api/PodEntityImpl.java       |  109 +++---
 .../datacenter/entity/api/ZoneEntityImpl.java      |   29 +-
 .../engine/datacenter/entity/api/db/ClusterVO.java |  235 ++++++++++++
 .../datacenter/entity/api/db/DataCenterVO.java     |    1 +
 .../engine/datacenter/entity/api/db/HostPodVO.java |  241 ++++++++++++
 .../datacenter/entity/api/db/dao/ClusterDao.java   |   38 ++
 .../entity/api/db/dao/ClusterDaoImpl.java          |  295 +++++++++++++++
 .../datacenter/entity/api/db/dao/HostPodDao.java   |   36 ++
 .../entity/api/db/dao/HostPodDaoImpl.java          |  188 +++++++++
 .../service/api/ProvisioningServiceImpl.java       |   70 ++--
 .../provisioning/test/ChildTestConfiguration.java  |   12 +
 .../engine/provisioning/test/ProvisioningTest.java |   53 +++-
 21 files changed, 1589 insertions(+), 126 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ClusterEntity.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ClusterEntity.java b/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ClusterEntity.java
index bec5a4c..d4d3a8c 100755
--- a/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ClusterEntity.java
+++ b/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ClusterEntity.java
@@ -18,8 +18,26 @@
  */
 package org.apache.cloudstack.engine.datacenter.entity.api;
 
-import com.cloud.org.Cluster;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.org.Cluster.ClusterType;
+import com.cloud.org.Grouping.AllocationState;
+import com.cloud.org.Managed.ManagedState;
+
+public interface ClusterEntity extends DataCenterResourceEntity, OrganizationScope {
+	
+    String getName();
+
+    long getDataCenterId();
+
+    long getPodId();
+
+    HypervisorType getHypervisorType();
+
+    ClusterType getClusterType();
+
+    AllocationState getAllocationState();
+
+    ManagedState getManagedState();
 
-public interface ClusterEntity extends DataCenterResourceEntity, Cluster, OrganizationScope {
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntity.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntity.java b/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntity.java
index 2cc6625..6eda5dd 100755
--- a/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntity.java
+++ b/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntity.java
@@ -22,9 +22,24 @@ import java.util.List;
 
 import com.cloud.dc.Pod;
 import com.cloud.org.Cluster;
+import com.cloud.org.Grouping.AllocationState;
 
-public interface PodEntity extends DataCenterResourceEntity, Pod {
+public interface PodEntity extends DataCenterResourceEntity {
 
     List<Cluster> listClusters();
+    
+    String getCidrAddress();
+
+    int getCidrSize();
+
+    String getGateway();
+
+    long getDataCenterId();
+
+    String getName();
+
+    AllocationState getAllocationState();
+
+    boolean getExternalDhcp();
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntity.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntity.java b/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntity.java
index 106e18d..c9ed9fb 100755
--- a/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntity.java
+++ b/engine/api/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntity.java
@@ -41,7 +41,7 @@ public interface ZoneEntity extends DataCenterResourceEntity {
     @Url(clazz=ProvisioningService.class, method="getPod", name="id", type=List.class)
     List<String> listPodIds();
 
-    @Override
-    @Path("/enable")
-    boolean enable();
+
+	String getName();
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/api/src/org/apache/cloudstack/engine/entity/api/CloudStackEntity.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/entity/api/CloudStackEntity.java b/engine/api/src/org/apache/cloudstack/engine/entity/api/CloudStackEntity.java
index e1f41fa..09130d1 100755
--- a/engine/api/src/org/apache/cloudstack/engine/entity/api/CloudStackEntity.java
+++ b/engine/api/src/org/apache/cloudstack/engine/entity/api/CloudStackEntity.java
@@ -92,4 +92,5 @@ public interface CloudStackEntity {
      * @return list of actions that can be performed on the object in its current state
      */
     List<Method> getApplicableActions();
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ProvisioningRestService.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ProvisioningRestService.java b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ProvisioningRestService.java
new file mode 100644
index 0000000..fdfd17a
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ProvisioningRestService.java
@@ -0,0 +1,84 @@
+/*
+ * 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.engine.rest.service.api;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
+import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
+import org.apache.cloudstack.engine.rest.datacenter.entity.api.PodRestTO;
+import org.apache.cloudstack.engine.rest.datacenter.entity.api.ZoneRestTO;
+import org.apache.cloudstack.engine.service.api.ProvisioningService;
+import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
+
+
+@Service("provisioningRestService")
+@Path("/provisioning")
+@Produces({"application/xml", "application/json"})
+@Component
+public class ProvisioningRestService {
+    @Inject
+    ProvisioningService _provisioningService;
+
+    @GET
+    @Path("/{zoneid}")
+    public ZoneRestTO getZone(@Context UriInfo ui, @PathParam("zoneid") String id) {
+        UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getZone");
+        ZoneEntity entity = _provisioningService.getZone(id);
+        return new ZoneRestTO(ui, entity, ub.build(entity.getUuid()));
+    }
+
+    @GET
+    @Path("/zones")
+    public ZoneRestTO[] listZones(@Context UriInfo ui) {
+        List<ZoneEntity> zones = _provisioningService.listZones();
+        ZoneRestTO[] tos = new ZoneRestTO[zones.size()];
+        UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getZone");
+        Iterator<ZoneEntity> it = zones.iterator();
+        for (int i = 0; i < tos.length; i++) {
+            ZoneEntity entity = it.next();
+            tos[i] = new ZoneRestTO(ui, entity, ub.build(entity.getUuid()));
+        }
+        return tos;
+    }
+
+    @GET
+    @Path("/zone/{zoneid}/pods") 
+    public PodRestTO[] listPods(@PathParam("zoneid") String zoneId) {
+        List<PodEntity> pods = _provisioningService.listPods();
+        PodRestTO[] tos = new PodRestTO[pods.size()];
+        Iterator<PodEntity> it = pods.iterator();
+        for (int i = 0; i < tos.length; i++) {
+            PodEntity pod = it.next();
+            tos[i] = new PodRestTO(pod);
+        }
+        return tos;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/api/src/org/apache/cloudstack/engine/service/api/ProvisioningService.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/service/api/ProvisioningService.java b/engine/api/src/org/apache/cloudstack/engine/service/api/ProvisioningService.java
index 8b28aee..e451742 100755
--- a/engine/api/src/org/apache/cloudstack/engine/service/api/ProvisioningService.java
+++ b/engine/api/src/org/apache/cloudstack/engine/service/api/ProvisioningService.java
@@ -42,22 +42,22 @@ public interface ProvisioningService {
     StorageEntity registerStorage(String name, List<String> tags, Map<String, String> details);
 
     @POST
-    ZoneEntity registerZone(String zoneUuid, String owner, List<String> tags, Map<String, String> details);
+    ZoneEntity registerZone(String zoneUuid, String name, String owner, List<String> tags, Map<String, String> details);
 
     @POST
-    PodEntity registerPod(String name, Long zoneId, String gateway, String cidr, String startIp, String endIp, List<String> tags, Map<String, String> details);
+    PodEntity registerPod(String podUuid, String name, String owner, String zoneUuid, List<String> tags, Map<String, String> details);
 
-    ClusterEntity registerCluster(String name, List<String> tags, Map<String, String> details);
+    ClusterEntity registerCluster(String clusterUuid, String name, String owner, List<String> tags, Map<String, String> details);
 
     String registerHost(String name, List<String> tags, Map<String, String> details);
 
     void deregisterStorage(String uuid);
 
-    void deregisterZone();
+    void deregisterZone(String uuid);
 
-    void deregisterPod();
+    void deregisterPod(String uuid);
 
-    void deregisterCluster();
+    void deregisterCluster(String uuid);
 
     void deregisterHost();
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ClusterEntityImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ClusterEntityImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ClusterEntityImpl.java
new file mode 100644
index 0000000..20ffcb1
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ClusterEntityImpl.java
@@ -0,0 +1,193 @@
+
+package org.apache.cloudstack.engine.datacenter.entity.api;
+
+import java.lang.reflect.Method;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.ClusterVO;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.org.Cluster.ClusterType;
+import com.cloud.org.Grouping.AllocationState;
+import com.cloud.org.Managed.ManagedState;
+import com.cloud.utils.fsm.NoTransitionException;
+
+
+public class ClusterEntityImpl implements ClusterEntity {
+	
+	
+	private DataCenterResourceManager manager;
+
+	private ClusterVO clusterVO;
+	
+	
+	public ClusterEntityImpl(String clusterId, DataCenterResourceManager manager) {
+		this.manager = manager;
+    	this.clusterVO = this.manager.loadCluster(clusterId);
+    }	
+
+	@Override
+	public boolean enable() {
+		try {
+			manager.changeState(this, Event.EnableRequest);
+		} catch (NoTransitionException e) {
+			return false;
+		}
+    	return true;
+	}
+
+	@Override
+	public boolean disable() {
+		try {
+			manager.changeState(this, Event.DisableRequest);
+		} catch (NoTransitionException e) {
+			return false;
+		}
+    	return true;
+	}
+
+	@Override
+	public boolean deactivate() {
+		try {
+			manager.changeState(this, Event.DeactivateRequest);
+		} catch (NoTransitionException e) {
+			return false;
+		}
+    	return true;
+	}
+
+
+	@Override
+	public boolean reactivate() {
+		try {
+			manager.changeState(this, Event.ActivatedRequest);
+		} catch (NoTransitionException e) {
+			return false;
+		}
+    	return true;
+	}
+
+
+	@Override
+	public State getState() {
+		return clusterVO.getState();
+	}
+
+	@Override
+	public void persist() {
+		manager.saveCluster(clusterVO);
+	}
+
+	@Override
+	public String getUuid() {
+		return clusterVO.getUuid();
+	}
+
+	@Override
+	public long getId() {
+		return clusterVO.getId();
+	}
+
+	@Override
+	public String getCurrentState() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public String getDesiredState() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public Date getCreatedTime() {
+		return clusterVO.getCreated();
+	}
+
+	@Override
+	public Date getLastUpdatedTime() {
+		return clusterVO.getLastUpdated();
+	}
+
+	@Override
+	public String getOwner() {
+		return clusterVO.getOwner();
+	}
+
+	@Override
+	public Map<String, String> getDetails() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public void addDetail(String name, String value) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void delDetail(String name, String value) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void updateDetail(String name, String value) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public List<Method> getApplicableActions() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public String getName() {
+		return clusterVO.getName();
+	}
+
+	@Override
+	public long getDataCenterId() {
+		return clusterVO.getDataCenterId();
+	}
+
+	@Override
+	public long getPodId() {
+		return clusterVO.getPodId();
+	}
+
+	@Override
+	public HypervisorType getHypervisorType() {
+		return clusterVO.getHypervisorType();
+	}
+
+	@Override
+	public ClusterType getClusterType() {
+		return clusterVO.getClusterType();
+	}
+
+	@Override
+	public AllocationState getAllocationState() {
+		return clusterVO.getAllocationState();
+	}
+
+	@Override
+	public ManagedState getManagedState() {
+		return clusterVO.getManagedState();
+	}
+
+	public void setOwner(String owner) {
+		clusterVO.setOwner(owner);
+	}
+
+	public void setName(String name) {
+		clusterVO.setName(name);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManager.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManager.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManager.java
index 8bd3ca4..11e24cb 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManager.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManager.java
@@ -2,7 +2,9 @@ package org.apache.cloudstack.engine.datacenter.entity.api;
 
 
 import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.ClusterVO;
 import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.HostPodVO;
 
 import com.cloud.utils.fsm.NoTransitionException;
 
@@ -14,6 +16,14 @@ public interface DataCenterResourceManager {
 	
 	void saveDataCenter(DataCenterVO dc);
 	
-	boolean changeState(ZoneEntity dc, Event event) throws NoTransitionException;
+	void savePod(HostPodVO dc);
+	
+	void saveCluster(ClusterVO cluster);
+	
+	boolean changeState(DataCenterResourceEntity entity, Event event) throws NoTransitionException;
+	
+	HostPodVO loadPod(String uuid);
+	
+	ClusterVO loadCluster(String uuid);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java
index b36b11d..161d00e 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java
@@ -4,24 +4,32 @@ import javax.inject.Inject;
 
 import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
 import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.ClusterVO;
 import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.HostPodVO;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.ClusterDao;
 import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DataCenterDao;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.HostPodDao;
 import org.springframework.stereotype.Component;
 
-import com.cloud.dc.DataCenter;
+
 import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.utils.Pair;
 import com.cloud.utils.fsm.NoTransitionException;
 import com.cloud.utils.fsm.StateMachine2;
-import com.cloud.vm.VirtualMachine;
 
 @Component
 public class DataCenterResourceManagerImpl implements DataCenterResourceManager {
 
-   // @Inject
+	@Inject
     DataCenterDao _dataCenterDao;
-    
-    protected StateMachine2<State, Event, DataCenterResourceEntity> _stateMachine;
+
+	@Inject
+	HostPodDao _podDao;
+
+	@Inject
+	ClusterDao _clusterDao;
+	
+    protected StateMachine2<State, Event, DataCenterResourceEntity> _stateMachine = DataCenterResourceEntity.State.s_fsm;
 
 	@Override
 	public DataCenterVO loadDataCenter(String dataCenterId) {
@@ -39,8 +47,45 @@ public class DataCenterResourceManagerImpl implements DataCenterResourceManager
 	}
 
 	@Override
-	public boolean changeState(ZoneEntity entity, Event event) throws NoTransitionException {
-		return _stateMachine.transitTo((DataCenterResourceEntity)entity, event, null, _dataCenterDao);
+	public boolean changeState(DataCenterResourceEntity entity, Event event) throws NoTransitionException {
+		
+		if(entity  instanceof ZoneEntity){
+				return _stateMachine.transitTo((DataCenterResourceEntity)entity, event, null, _dataCenterDao);
+		}else if(entity  instanceof PodEntity){
+			return _stateMachine.transitTo((DataCenterResourceEntity)entity, event, null, _podDao);
+		}else if(entity  instanceof ClusterEntity){
+			return _stateMachine.transitTo((DataCenterResourceEntity)entity, event, null, _clusterDao);
+		}
+
+		return false;
+	}
+
+	@Override
+	public HostPodVO loadPod(String uuid) {
+		HostPodVO pod = _podDao.findByUUID(uuid);
+    	if(pod == null){
+    		throw new InvalidParameterValueException("Pod does not exist");
+    	}
+		return pod;
+	}
+
+	@Override
+	public ClusterVO loadCluster(String uuid) {
+		ClusterVO cluster = _clusterDao.findByUUID(uuid);
+    	if(cluster == null){
+    		throw new InvalidParameterValueException("Pod does not exist");
+    	}
+		return cluster;
+	}
+
+	@Override
+	public void savePod(HostPodVO pod) {
+		_podDao.persist(pod);
+	}
+
+	@Override
+	public void saveCluster(ClusterVO cluster) {
+		_clusterDao.persist(cluster);		
 	}
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntityImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntityImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntityImpl.java
index ba42959..e17e391 100755
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntityImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/PodEntityImpl.java
@@ -23,62 +23,84 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.HostPodVO;
+
 import com.cloud.org.Cluster;
+import com.cloud.org.Grouping.AllocationState;
+import com.cloud.utils.fsm.NoTransitionException;
 
 public class PodEntityImpl implements PodEntity {
-    String _uuid;
-    String _name;
 
-    public PodEntityImpl(String uuid, String name) {
-        _uuid = uuid;
-        _name = name;
+	
+	private DataCenterResourceManager manager;
+    
+    private HostPodVO podVO;
+
+    public PodEntityImpl(String uuid, DataCenterResourceManager manager) {
+    	this.manager = manager;
+    	podVO = manager.loadPod(uuid);
     }
 
     @Override
     public boolean enable() {
-        // TODO Auto-generated method stub
-        return false;
+    	try {
+			manager.changeState(this, Event.EnableRequest);
+		} catch (NoTransitionException e) {
+			return false;
+		}
+    	return true;
     }
 
     @Override
     public boolean disable() {
-        // TODO Auto-generated method stub
-        return false;
+    	try {
+			manager.changeState(this, Event.DisableRequest);
+		} catch (NoTransitionException e) {
+			return false;
+		}
+    	return true;
     }
 
     @Override
     public boolean deactivate() {
-        // TODO Auto-generated method stub
-        return false;
+    	try {
+			manager.changeState(this, Event.DeactivateRequest);
+		} catch (NoTransitionException e) {
+			return false;
+		}
+    	return true;
     }
 
     @Override
     public boolean reactivate() {
-        // TODO Auto-generated method stub
-        return false;
+    	try {
+			manager.changeState(this, Event.ActivatedRequest);
+		} catch (NoTransitionException e) {
+			return false;
+		}
+    	return true;
     }
 
     @Override
     public State getState() {
-        // TODO Auto-generated method stub
-        return null;
+        return podVO.getState();
     }
 
     @Override
     public String getUuid() {
-        return _uuid;
+        return podVO.getUuid();
     }
 
     @Override
     public long getId() {
-        // TODO Auto-generated method stub
-        return 0;
+        return podVO.getId();
     }
 
     @Override
     public String getCurrentState() {
         // TODO Auto-generated method stub
-        return null;
+    	return null;
     }
 
     @Override
@@ -89,20 +111,17 @@ public class PodEntityImpl implements PodEntity {
 
     @Override
     public Date getCreatedTime() {
-        // TODO Auto-generated method stub
-        return null;
+        return podVO.getCreated();
     }
 
     @Override
     public Date getLastUpdatedTime() {
-        // TODO Auto-generated method stub
-        return null;
+        return podVO.getLastUpdated();
     }
 
     @Override
     public String getOwner() {
-        // TODO Auto-generated method stub
-        return null;
+        return podVO.getOwner();
     }
 
 
@@ -114,49 +133,37 @@ public class PodEntityImpl implements PodEntity {
 
     @Override
     public String getCidrAddress() {
-        // TODO Auto-generated method stub
-        return null;
+        return podVO.getCidrAddress();
     }
 
     @Override
     public int getCidrSize() {
-        // TODO Auto-generated method stub
-        return 0;
+        return podVO.getCidrSize();
     }
 
     @Override
     public String getGateway() {
-        // TODO Auto-generated method stub
-        return null;
+        return podVO.getGateway();
     }
 
     @Override
     public long getDataCenterId() {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-    @Override
-    public String getDescription() {
-        // TODO Auto-generated method stub
-        return null;
+        return podVO.getDataCenterId();
     }
 
     @Override
     public String getName() {
-        return _name;
+        return podVO.getName();
     }
 
     @Override
     public AllocationState getAllocationState() {
-        // TODO Auto-generated method stub
-        return null;
+        return podVO.getAllocationState();
     }
 
     @Override
     public boolean getExternalDhcp() {
-        // TODO Auto-generated method stub
-        return false;
+        return podVO.getExternalDhcp();
     }
 
     @Override
@@ -167,13 +174,12 @@ public class PodEntityImpl implements PodEntity {
 
 	@Override
 	public void persist() {
-		// TODO Auto-generated method stub
+		manager.savePod(podVO);
 		
 	}
 
 	@Override
 	public Map<String, String> getDetails() {
-		// TODO Auto-generated method stub
 		return null;
 	}
 
@@ -191,8 +197,15 @@ public class PodEntityImpl implements PodEntity {
 
 	@Override
 	public void updateDetail(String name, String value) {
-		// TODO Auto-generated method stub
-		
+
+	}
+
+	public void setOwner(String owner) {
+		podVO.setOwner(owner);		
 	}
 
+	public void setName(String name) {
+		podVO.setName(name);
+	}
+	
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntityImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntityImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntityImpl.java
index ae35536..e87cc4b 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntityImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/ZoneEntityImpl.java
@@ -23,36 +23,26 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
-
-import javax.inject.Inject;
 import javax.ws.rs.GET;
-import javax.ws.rs.POST;
 import javax.ws.rs.Path;
-
 import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
 import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO;
-import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DataCenterDao;
-import org.apache.cloudstack.engine.service.api.ProvisioningService;
-
-import org.springframework.stereotype.Component;
-
 import com.cloud.utils.fsm.FiniteStateObject;
 import com.cloud.utils.fsm.NoTransitionException;
 
 
-@Component
 @Path("/zone/{id}")
 public class ZoneEntityImpl implements ZoneEntity, FiniteStateObject<DataCenterResourceEntity.State, DataCenterResourceEntity.State.Event> {
 	
-	@Inject
-	DataCenterResourceManager manager;
-
 	
+	private DataCenterResourceManager manager;
+
 	private DataCenterVO dataCenterVO;
 	
 	
-	public ZoneEntityImpl(String dataCenterId) {
-    	this.dataCenterVO = manager.loadDataCenter(dataCenterId);
+	public ZoneEntityImpl(String dataCenterId, DataCenterResourceManager manager) {
+		this.manager = manager;
+    	this.dataCenterVO = this.manager.loadDataCenter(dataCenterId);
     }
 
 	@Override
@@ -133,6 +123,7 @@ public class ZoneEntityImpl implements ZoneEntity, FiniteStateObject<DataCenterR
         return dataCenterVO.getOwner();
     }
 
+    
     public void setOwner(String owner) {
     	dataCenterVO.setOwner(owner);
     }
@@ -191,6 +182,10 @@ public class ZoneEntityImpl implements ZoneEntity, FiniteStateObject<DataCenterR
 		manager.saveDataCenter(dataCenterVO);
 	}
 
+    @Override
+    public String getName() {
+        return dataCenterVO.getName();
+    }
 
     @Override
     public List<String> listPodIds() {
@@ -199,4 +194,8 @@ public class ZoneEntityImpl implements ZoneEntity, FiniteStateObject<DataCenterR
         podIds.add("pod-uuid-2");
         return podIds;
     }
+
+	public void setName(String name) {
+		dataCenterVO.setName(name);
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/ClusterVO.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/ClusterVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/ClusterVO.java
new file mode 100644
index 0000000..f13bde6
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/ClusterVO.java
@@ -0,0 +1,235 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by 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.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package org.apache.cloudstack.engine.datacenter.entity.api.db;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
+
+import com.cloud.api.Identity;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.org.Cluster;
+import com.cloud.org.Managed.ManagedState;
+import com.cloud.org.Grouping;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.db.StateMachine;
+
+@Entity
+@Table(name="cluster")
+public class ClusterVO implements Cluster, Identity {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name="id")
+    long id;
+    
+    @Column(name="name")
+    String name;
+    
+    @Column(name="guid")
+    String guid;
+    
+    @Column(name="data_center_id")
+    long dataCenterId;
+    
+    @Column(name="pod_id")
+    long podId;
+    
+    @Column(name="hypervisor_type")
+    String hypervisorType;
+
+    @Column(name="cluster_type")
+    @Enumerated(value=EnumType.STRING)
+    Cluster.ClusterType clusterType;
+    
+    @Column(name="allocation_state")
+    @Enumerated(value=EnumType.STRING)
+    AllocationState allocationState;
+    
+    @Column(name="managed_state")
+    @Enumerated(value=EnumType.STRING)
+    ManagedState managedState;
+    
+    @Column(name=GenericDao.REMOVED_COLUMN)
+    private Date removed;
+
+    @Column(name="uuid")
+    String uuid;
+    
+    //orchestration
+    
+    @Column(name="owner")
+    private String owner = null;
+    
+    @Column(name=GenericDao.CREATED_COLUMN)
+    protected Date created;
+
+    @Column(name="lastUpdated", updatable=true)
+    @Temporal(value=TemporalType.TIMESTAMP)
+    protected Date lastUpdated;
+    
+    /**
+     * Note that state is intentionally missing the setter.  Any updates to
+     * the state machine needs to go through the DAO object because someone
+     * else could be updating it as well.
+     */
+    @Enumerated(value=EnumType.STRING)
+    @StateMachine(state=State.class, event=Event.class)
+    @Column(name="state", updatable=true, nullable=false, length=32)
+    protected State state = null;
+    
+    
+    public ClusterVO() {
+    	clusterType = Cluster.ClusterType.CloudManaged;
+    	allocationState = Grouping.AllocationState.Enabled;
+    	
+    	this.uuid = UUID.randomUUID().toString();
+    	this.state = State.Disabled;
+    }
+    
+    public ClusterVO(long dataCenterId, long podId, String name) {
+        this.dataCenterId = dataCenterId;
+        this.podId = podId;
+        this.name = name;
+    	this.clusterType = Cluster.ClusterType.CloudManaged;
+    	this.allocationState = Grouping.AllocationState.Enabled;
+    	this.managedState = ManagedState.Managed;
+    	this.uuid = UUID.randomUUID().toString();
+    	this.state = State.Disabled;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public long getDataCenterId() {
+        return dataCenterId;
+    }
+
+    public long getPodId() {
+        return podId;
+    }
+    
+    public Cluster.ClusterType getClusterType() {
+    	return clusterType;
+    }
+    
+    public void setClusterType(Cluster.ClusterType clusterType) {
+    	this.clusterType = clusterType;
+    }
+    
+    public AllocationState getAllocationState() {
+    	return allocationState;
+    }
+    
+    public void setAllocationState(AllocationState allocationState) {
+		this.allocationState = allocationState;
+    }
+    
+    public ManagedState getManagedState() {
+        return managedState;
+    }
+
+    public void setManagedState(ManagedState managedState) {
+        this.managedState = managedState;
+    }
+
+    public ClusterVO(long clusterId) {
+        this.id = clusterId;
+    }
+
+    @Override
+    public int hashCode() {
+        return NumbersUtil.hash(id);
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof ClusterVO)) {
+            return false;
+        }
+        ClusterVO that = (ClusterVO)obj;
+        return this.id == that.id;
+    }
+    
+    public HypervisorType getHypervisorType() {
+    	return HypervisorType.getType(hypervisorType);
+    }
+
+	public void setHypervisorType(String hy) {
+    	hypervisorType = hy;
+    }
+	
+    public String getGuid() {
+        return guid;
+    }
+	
+    public void setGuid(String guid) {
+        this.guid = guid;
+    }
+
+    public Date getRemoved() {
+        return removed;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+    @Override
+    public String getUuid() {
+    	return this.uuid;
+    }
+    
+    public void setUuid(String uuid) {
+    	this.uuid = uuid;
+    }
+    
+	public String getOwner() {
+		return owner;
+	}
+
+	public void setOwner(String owner) {
+		this.owner = owner;
+	}
+
+	public Date getCreated() {
+		return created;
+	}
+
+	public Date getLastUpdated() {
+		return lastUpdated;
+	}
+
+	public State getState() {
+		return state;
+	}    
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/DataCenterVO.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/DataCenterVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/DataCenterVO.java
index 9047cb9..beccb6f 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/DataCenterVO.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/DataCenterVO.java
@@ -240,6 +240,7 @@ public class DataCenterVO implements DataCenter, Identity {
         this.zoneToken = zoneToken;
         this.domain = domainSuffix;
         this.uuid = UUID.randomUUID().toString();
+        this.state = State.Disabled;
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/HostPodVO.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/HostPodVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/HostPodVO.java
new file mode 100644
index 0000000..6467a4b
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/HostPodVO.java
@@ -0,0 +1,241 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by 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.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package org.apache.cloudstack.engine.datacenter.entity.api.db;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
+
+import com.cloud.api.Identity;
+import com.cloud.dc.Pod;
+import com.cloud.org.Grouping;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.db.StateMachine;
+
+@Entity
+@Table(name = "host_pod_ref")
+public class HostPodVO implements Pod, Identity {
+	@Id
+	@GeneratedValue(strategy = GenerationType.IDENTITY)
+	long id;
+
+	@Column(name = "name")
+	private String name = null;
+
+	@Column(name = "data_center_id")
+	private long dataCenterId;
+	
+	@Column(name = "gateway")
+	private String gateway;
+
+	@Column(name = "cidr_address")
+	private String cidrAddress;
+
+	@Column(name = "cidr_size")
+	private int cidrSize;
+
+	@Column(name = "description")
+	private String description;
+	
+    @Column(name="allocation_state")
+    @Enumerated(value=EnumType.STRING)
+    AllocationState allocationState;
+
+	@Column(name = "external_dhcp")
+	private Boolean externalDhcp;
+	
+    @Column(name=GenericDao.REMOVED_COLUMN)
+    private Date removed;
+
+	@Column(name = "uuid")
+	private String uuid;
+	
+    //orchestration
+    @Column(name="owner")
+    private String owner = null;
+    
+    @Column(name=GenericDao.CREATED_COLUMN)
+    protected Date created;
+
+    @Column(name="lastUpdated", updatable=true)
+    @Temporal(value=TemporalType.TIMESTAMP)
+    protected Date lastUpdated;    
+    
+    /**
+     * Note that state is intentionally missing the setter.  Any updates to
+     * the state machine needs to go through the DAO object because someone
+     * else could be updating it as well.
+     */
+    @Enumerated(value=EnumType.STRING)
+    @StateMachine(state=State.class, event=Event.class)
+    @Column(name="state", updatable=true, nullable=false, length=32)
+    protected State state = null;
+
+	public HostPodVO(String name, long dcId, String gateway, String cidrAddress, int cidrSize, String description) {
+		this.name = name;
+		this.dataCenterId = dcId;
+		this.gateway = gateway;
+		this.cidrAddress = cidrAddress;
+		this.cidrSize = cidrSize;
+		this.description = description;
+		this.allocationState = Grouping.AllocationState.Enabled;
+		this.externalDhcp = false;
+		this.uuid = UUID.randomUUID().toString();
+		this.state = State.Disabled;
+	}
+
+	/*
+	 * public HostPodVO(String name, long dcId) { this(null, name, dcId); }
+	 */
+	protected HostPodVO() {
+		this.uuid = UUID.randomUUID().toString();
+	}
+
+	@Override
+    public long getId() {
+		return id;
+	}
+
+	public long getDataCenterId() {
+		return dataCenterId;
+	}
+
+	public void setDataCenterId(long dataCenterId) {
+		this.dataCenterId = dataCenterId;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	@Override
+    public String getCidrAddress() {
+		return cidrAddress;
+	}
+
+	public void setCidrAddress(String cidrAddress) {
+		this.cidrAddress = cidrAddress;
+	}
+
+	@Override
+    public int getCidrSize() {
+		return cidrSize;
+	}
+
+	public void setCidrSize(int cidrSize) {
+		this.cidrSize = cidrSize;
+	}
+	
+	@Override
+    public String getGateway() {
+		return gateway;
+	}
+	
+	public void setGateway(String gateway) {
+		this.gateway = gateway;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+	
+    public AllocationState getAllocationState() {
+    	return allocationState;
+    }
+    
+    public void setAllocationState(AllocationState allocationState) {
+		this.allocationState = allocationState;
+    }
+	
+	// Use for comparisons only.
+	public HostPodVO(Long id) {
+	    this.id = id;
+	}
+	
+	@Override
+    public int hashCode() {
+	    return  NumbersUtil.hash(id);
+	}
+	
+	public boolean getExternalDhcp() {
+		return externalDhcp;
+	}
+	
+	public void setExternalDhcp(boolean use) {
+		externalDhcp = use;
+	}
+	
+	@Override
+    public boolean equals(Object obj) {
+	    if (obj instanceof HostPodVO) {
+	        return id == ((HostPodVO)obj).id;
+	    } else {
+	        return false;
+	    }
+	}
+	
+    public Date getRemoved() {
+        return removed;
+    }
+    
+    @Override
+    public String getUuid() {
+    	return this.uuid;
+    }
+    
+    public void setUuid(String uuid) {
+    	this.uuid = uuid;
+    }
+    
+	public String getOwner() {
+		return owner;
+	}
+
+	public void setOwner(String owner) {
+		this.owner = owner;
+	}
+	
+	public Date getCreated() {
+		return created;
+	}
+
+	public Date getLastUpdated() {
+		return lastUpdated;
+	}
+	
+	public State getState() {
+		return state;
+	}	
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java
new file mode 100644
index 0000000..771b64d
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java
@@ -0,0 +1,38 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by 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.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package org.apache.cloudstack.engine.datacenter.entity.api.db.dao;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.ClusterVO;
+
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.fsm.StateDao;
+
+public interface ClusterDao extends GenericDao<ClusterVO, Long>, StateDao<DataCenterResourceEntity.State, DataCenterResourceEntity.State.Event, DataCenterResourceEntity> {
+    List<ClusterVO> listByPodId(long podId);
+    ClusterVO findBy(String name, long podId);
+    List<ClusterVO> listByHyTypeWithoutGuid(String hyType);
+    List<ClusterVO> listByZoneId(long zoneId);
+
+    List<HypervisorType> getAvailableHypervisorInZone(Long zoneId);
+    List<ClusterVO> listByDcHyType(long dcId, String hyType);
+    Map<Long, List<Long>> getPodClusterIdMap(List<Long> clusterIds);
+    List<Long> listDisabledClusters(long zoneId, Long podId);
+    List<Long> listClustersWithDisabledPods(long zoneId);
+	ClusterVO findByUUID(String uuid);
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
new file mode 100644
index 0000000..ff2e911
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java
@@ -0,0 +1,295 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by 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.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package org.apache.cloudstack.engine.datacenter.entity.api.db.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.ClusterVO;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.HostPodVO;
+import org.apache.log4j.Logger;
+
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.org.Grouping;
+import com.cloud.utils.component.ComponentLocator;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.JoinBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.UpdateBuilder;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Local(value=ClusterDao.class)
+public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements ClusterDao {
+	private static final Logger s_logger = Logger.getLogger(ClusterDaoImpl.class);
+	
+    protected final SearchBuilder<ClusterVO> PodSearch;
+    protected final SearchBuilder<ClusterVO> HyTypeWithoutGuidSearch;
+    protected final SearchBuilder<ClusterVO> AvailHyperSearch;
+    protected final SearchBuilder<ClusterVO> ZoneSearch;
+    protected final SearchBuilder<ClusterVO> ZoneHyTypeSearch;
+    protected SearchBuilder<ClusterVO> StateChangeSearch;
+	protected SearchBuilder<ClusterVO> UUIDSearch;
+	
+    private static final String GET_POD_CLUSTER_MAP_PREFIX = "SELECT pod_id, id FROM cloud.cluster WHERE cluster.id IN( ";
+    private static final String GET_POD_CLUSTER_MAP_SUFFIX = " )";
+    
+    protected final HostPodDaoImpl _hostPodDao = ComponentLocator.inject(HostPodDaoImpl.class);
+    
+    protected ClusterDaoImpl() {
+        super();
+        
+        HyTypeWithoutGuidSearch = createSearchBuilder();
+        HyTypeWithoutGuidSearch.and("hypervisorType", HyTypeWithoutGuidSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ);
+        HyTypeWithoutGuidSearch.and("guid", HyTypeWithoutGuidSearch.entity().getGuid(), SearchCriteria.Op.NULL);
+        HyTypeWithoutGuidSearch.done();
+        
+        ZoneHyTypeSearch = createSearchBuilder();
+        ZoneHyTypeSearch.and("hypervisorType", ZoneHyTypeSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ);
+        ZoneHyTypeSearch.and("dataCenterId", ZoneHyTypeSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        ZoneHyTypeSearch.done();
+        
+        PodSearch = createSearchBuilder();
+        PodSearch.and("pod", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
+        PodSearch.and("name", PodSearch.entity().getName(), SearchCriteria.Op.EQ);
+        PodSearch.done();
+        
+        ZoneSearch = createSearchBuilder();
+        ZoneSearch.and("dataCenterId", ZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        ZoneSearch.groupBy(ZoneSearch.entity().getHypervisorType());
+        ZoneSearch.done();
+        
+        AvailHyperSearch = createSearchBuilder();
+        AvailHyperSearch.and("zoneId", AvailHyperSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        AvailHyperSearch.select(null, Func.DISTINCT, AvailHyperSearch.entity().getHypervisorType());
+        AvailHyperSearch.done();
+        
+	    UUIDSearch = createSearchBuilder();
+	    UUIDSearch.and("uuid", UUIDSearch.entity().getUuid(), SearchCriteria.Op.EQ);
+	    UUIDSearch.done();
+	    
+        StateChangeSearch = createSearchBuilder();
+        StateChangeSearch.and("id", StateChangeSearch.entity().getId(), SearchCriteria.Op.EQ);
+        StateChangeSearch.and("state", StateChangeSearch.entity().getState(), SearchCriteria.Op.EQ);
+        StateChangeSearch.done();	    
+    }
+    
+    @Override
+    public List<ClusterVO> listByZoneId(long zoneId) {
+        SearchCriteria<ClusterVO> sc = ZoneSearch.create();
+        sc.setParameters("dataCenterId", zoneId);        
+        return listBy(sc);
+    }
+    
+    @Override
+    public List<ClusterVO> listByPodId(long podId) {
+        SearchCriteria<ClusterVO> sc = PodSearch.create();
+        sc.setParameters("pod", podId);
+        
+        return listBy(sc);
+    }
+    
+    @Override
+    public ClusterVO findBy(String name, long podId) {
+        SearchCriteria<ClusterVO> sc = PodSearch.create();
+        sc.setParameters("pod", podId);
+        sc.setParameters("name", name);
+        
+        return findOneBy(sc);
+    }
+    
+    @Override
+    public List<ClusterVO> listByHyTypeWithoutGuid(String hyType) {
+        SearchCriteria<ClusterVO> sc = HyTypeWithoutGuidSearch.create();
+        sc.setParameters("hypervisorType", hyType);
+        
+        return listBy(sc);
+    }
+    
+    @Override
+    public List<ClusterVO> listByDcHyType(long dcId, String hyType) {
+        SearchCriteria<ClusterVO> sc = ZoneHyTypeSearch.create();
+        sc.setParameters("dataCenterId", dcId);
+        sc.setParameters("hypervisorType", hyType);
+        return listBy(sc);
+    }
+    
+    @Override
+    public List<HypervisorType> getAvailableHypervisorInZone(Long zoneId) {
+        SearchCriteria<ClusterVO> sc = AvailHyperSearch.create();
+        if (zoneId != null) {
+            sc.setParameters("zoneId", zoneId);
+        }
+        List<ClusterVO> clusters = listBy(sc);
+        List<HypervisorType> hypers = new ArrayList<HypervisorType>(4);
+        for (ClusterVO cluster : clusters) {
+            hypers.add(cluster.getHypervisorType());
+        }
+        
+        return hypers;
+    }
+    
+    @Override
+    public Map<Long, List<Long>> getPodClusterIdMap(List<Long> clusterIds){
+    	Transaction txn = Transaction.currentTxn();
+        PreparedStatement pstmt = null;
+        Map<Long, List<Long>> result = new HashMap<Long, List<Long>>();
+
+        try {
+            StringBuilder sql = new StringBuilder(GET_POD_CLUSTER_MAP_PREFIX);
+            if (clusterIds.size() > 0) {
+                for (Long clusterId : clusterIds) {
+                    sql.append(clusterId).append(",");
+                }
+                sql.delete(sql.length()-1, sql.length());
+                sql.append(GET_POD_CLUSTER_MAP_SUFFIX);
+            }
+            
+            pstmt = txn.prepareAutoCloseStatement(sql.toString());
+            ResultSet rs = pstmt.executeQuery();
+            while (rs.next()) {
+            	Long podId = rs.getLong(1);
+            	Long clusterIdInPod  = rs.getLong(2);
+                if(result.containsKey(podId)){
+                   	List<Long> clusterList = result.get(podId);
+                	clusterList.add(clusterIdInPod);
+                	result.put(podId, clusterList);
+                }else{
+                	List<Long> clusterList = new ArrayList<Long>();
+                	clusterList.add(clusterIdInPod);
+                	result.put(podId, clusterList);
+                }
+            }
+            return result;
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("DB Exception on: " + GET_POD_CLUSTER_MAP_PREFIX, e);
+        } catch (Throwable e) {
+            throw new CloudRuntimeException("Caught: " + GET_POD_CLUSTER_MAP_PREFIX, e);
+        }
+    }
+    
+    @Override
+    public List<Long> listDisabledClusters(long zoneId, Long podId) {
+    	GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
+    	clusterIdSearch.selectField(clusterIdSearch.entity().getId());
+    	clusterIdSearch.and("dataCenterId", clusterIdSearch.entity().getDataCenterId(), Op.EQ);
+    	if(podId != null){
+    		clusterIdSearch.and("podId", clusterIdSearch.entity().getPodId(), Op.EQ);
+    	}
+    	clusterIdSearch.and("allocationState", clusterIdSearch.entity().getAllocationState(), Op.EQ);
+    	clusterIdSearch.done();
+
+    	
+    	SearchCriteria<Long> sc = clusterIdSearch.create();
+        sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
+        if (podId != null) {
+	        sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
+	    }
+        sc.addAnd("allocationState", SearchCriteria.Op.EQ, Grouping.AllocationState.Disabled);
+        return customSearch(sc, null);
+    }
+
+    @Override
+    public List<Long> listClustersWithDisabledPods(long zoneId) {
+    	
+    	GenericSearchBuilder<HostPodVO, Long> disabledPodIdSearch = _hostPodDao.createSearchBuilder(Long.class);
+    	disabledPodIdSearch.selectField(disabledPodIdSearch.entity().getId());
+    	disabledPodIdSearch.and("dataCenterId", disabledPodIdSearch.entity().getDataCenterId(), Op.EQ);
+    	disabledPodIdSearch.and("allocationState", disabledPodIdSearch.entity().getAllocationState(), Op.EQ);
+
+    	GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
+    	clusterIdSearch.selectField(clusterIdSearch.entity().getId());
+    	clusterIdSearch.join("disabledPodIdSearch", disabledPodIdSearch, clusterIdSearch.entity().getPodId(), disabledPodIdSearch.entity().getId(), JoinBuilder.JoinType.INNER);
+    	clusterIdSearch.done();
+
+    	
+    	SearchCriteria<Long> sc = clusterIdSearch.create();
+        sc.setJoinParameters("disabledPodIdSearch", "dataCenterId", zoneId);
+        sc.setJoinParameters("disabledPodIdSearch", "allocationState", Grouping.AllocationState.Disabled);
+        
+        return customSearch(sc, null);
+    }
+    
+    @Override
+    public boolean remove(Long id) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        ClusterVO cluster = createForUpdate();
+        cluster.setName(null);
+        cluster.setGuid(null);
+        
+        update(id, cluster);
+
+        boolean result = super.remove(id);
+        txn.commit();
+        return result;
+    }
+    
+    
+	@Override
+	public ClusterVO findByUUID(String uuid) {
+    	SearchCriteria<ClusterVO> sc = UUIDSearch.create();
+    	sc.setParameters("uuid", uuid);
+        return findOneBy(sc);
+	}
+
+	@Override
+	public boolean updateState(State currentState, Event event, State nextState, DataCenterResourceEntity clusterEntity, Object data) {
+		
+		ClusterVO vo = findById(clusterEntity.getId());
+		
+		Date oldUpdatedTime = vo.getLastUpdated();
+
+		SearchCriteria<ClusterVO> sc = StateChangeSearch.create();
+        sc.setParameters("id", vo.getId());
+        sc.setParameters("state", currentState);
+
+        UpdateBuilder builder = getUpdateBuilder(vo);
+        builder.set(vo, "state", nextState);
+        builder.set(vo, "lastUpdated", new Date());
+
+        int rows = update((ClusterVO) vo, sc);
+        
+        if (rows == 0 && s_logger.isDebugEnabled()) {
+        	ClusterVO dbCluster = findByIdIncludingRemoved(vo.getId());
+            if (dbCluster != null) {
+                StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
+                str.append(": DB Data={id=").append(dbCluster.getId()).append("; state=").append(dbCluster.getState()).append(";updatedTime=")
+                        .append(dbCluster.getLastUpdated());
+                str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatedTime=").append(vo.getLastUpdated());
+                str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatedTime=").append(oldUpdatedTime);
+            } else {
+                s_logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore");
+            }
+        }
+        return rows > 0;
+		
+	}
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java
new file mode 100644
index 0000000..bfdbaae
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java
@@ -0,0 +1,36 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by 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.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package org.apache.cloudstack.engine.datacenter.entity.api.db.dao;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.HostPodVO;
+
+
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.fsm.StateDao;
+
+public interface HostPodDao extends GenericDao<HostPodVO, Long>, StateDao<DataCenterResourceEntity.State, DataCenterResourceEntity.State.Event, DataCenterResourceEntity> {
+	public List<HostPodVO> listByDataCenterId(long id);
+	
+	public HostPodVO findByName(String name, long dcId);
+	
+	public HashMap<Long, List<Object>> getCurrentPodCidrSubnets(long zoneId, long podIdToSkip);
+
+    public List<Long> listDisabledPods(long zoneId);
+
+	public HostPodVO findByUUID(String uuid);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
new file mode 100644
index 0000000..df52ed6
--- /dev/null
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java
@@ -0,0 +1,188 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by 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.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package org.apache.cloudstack.engine.datacenter.entity.api.db.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
+import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.HostPodVO;
+import org.apache.log4j.Logger;
+
+
+import com.cloud.org.Grouping;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.UpdateBuilder;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={HostPodDao.class})
+public class HostPodDaoImpl extends GenericDaoBase<HostPodVO, Long> implements HostPodDao {
+    private static final Logger s_logger = Logger.getLogger(HostPodDaoImpl.class);
+	
+	protected SearchBuilder<HostPodVO> DataCenterAndNameSearch;
+	protected SearchBuilder<HostPodVO> DataCenterIdSearch;
+	protected SearchBuilder<HostPodVO> UUIDSearch;
+    protected SearchBuilder<HostPodVO> StateChangeSearch;	
+	
+	protected HostPodDaoImpl() {
+	    DataCenterAndNameSearch = createSearchBuilder();
+	    DataCenterAndNameSearch.and("dc", DataCenterAndNameSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+	    DataCenterAndNameSearch.and("name", DataCenterAndNameSearch.entity().getName(), SearchCriteria.Op.EQ);
+	    DataCenterAndNameSearch.done();
+	    
+	    DataCenterIdSearch = createSearchBuilder();
+	    DataCenterIdSearch.and("dcId", DataCenterIdSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+	    DataCenterIdSearch.done();
+	    
+	    
+	    UUIDSearch = createSearchBuilder();
+	    UUIDSearch.and("uuid", UUIDSearch.entity().getUuid(), SearchCriteria.Op.EQ);
+	    UUIDSearch.done();
+	    
+        StateChangeSearch = createSearchBuilder();
+        StateChangeSearch.and("id", StateChangeSearch.entity().getId(), SearchCriteria.Op.EQ);
+        StateChangeSearch.and("state", StateChangeSearch.entity().getState(), SearchCriteria.Op.EQ);
+        StateChangeSearch.done();		    
+	    		
+	}
+	
+	@Override
+    public List<HostPodVO> listByDataCenterId(long id) {
+		SearchCriteria<HostPodVO> sc = DataCenterIdSearch.create();
+		sc.setParameters("dcId", id);
+		
+	    return listBy(sc);
+	}
+	
+	@Override
+    public HostPodVO findByName(String name, long dcId) {
+	    SearchCriteria<HostPodVO> sc = DataCenterAndNameSearch.create();
+	    sc.setParameters("dc", dcId);
+	    sc.setParameters("name", name);
+	    
+	    return findOneBy(sc);
+	}
+	
+	@Override
+	public HashMap<Long, List<Object>> getCurrentPodCidrSubnets(long zoneId, long podIdToSkip) {
+		HashMap<Long, List<Object>> currentPodCidrSubnets = new HashMap<Long, List<Object>>();
+		
+		String selectSql = "SELECT id, cidr_address, cidr_size FROM host_pod_ref WHERE data_center_id=" + zoneId +" and removed IS NULL";
+		Transaction txn = Transaction.currentTxn();
+		try {
+        	PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
+        	ResultSet rs = stmt.executeQuery();
+        	while (rs.next()) {
+        		Long podId = rs.getLong("id");
+        		if (podId.longValue() == podIdToSkip) {
+                    continue;
+                }
+        		String cidrAddress = rs.getString("cidr_address");
+        		long cidrSize = rs.getLong("cidr_size");
+        		List<Object> cidrPair = new ArrayList<Object>();
+        		cidrPair.add(0, cidrAddress);
+        		cidrPair.add(1, new Long(cidrSize));
+        		currentPodCidrSubnets.put(podId, cidrPair);
+        	}
+        } catch (SQLException ex) {
+        	s_logger.warn("DB exception " + ex.getMessage(), ex);
+            return null;
+        }
+        
+        return currentPodCidrSubnets;
+	}
+	
+    @Override
+    public boolean remove(Long id) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        HostPodVO pod = createForUpdate();
+        pod.setName(null);
+        
+        update(id, pod);
+
+        boolean result = super.remove(id);
+        txn.commit();
+        return result;
+    }
+
+    @Override
+    public List<Long> listDisabledPods(long zoneId) {
+        GenericSearchBuilder<HostPodVO, Long> podIdSearch = createSearchBuilder(Long.class);
+        podIdSearch.selectField(podIdSearch.entity().getId());
+        podIdSearch.and("dataCenterId", podIdSearch.entity().getDataCenterId(), Op.EQ);
+        podIdSearch.and("allocationState", podIdSearch.entity().getAllocationState(), Op.EQ);
+        podIdSearch.done();
+
+        
+        SearchCriteria<Long> sc = podIdSearch.create();
+        sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
+        sc.addAnd("allocationState", SearchCriteria.Op.EQ, Grouping.AllocationState.Disabled);
+        return customSearch(sc, null);
+    }
+
+	@Override
+	public HostPodVO findByUUID(String uuid) {
+    	SearchCriteria<HostPodVO> sc = UUIDSearch.create();
+    	sc.setParameters("uuid", uuid);
+        return findOneBy(sc);
+	}
+	
+	@Override
+	public boolean updateState(State currentState, Event event, State nextState, DataCenterResourceEntity podEntity, Object data) {
+		
+		HostPodVO vo = findById(podEntity.getId());
+		
+		Date oldUpdatedTime = vo.getLastUpdated();
+
+		SearchCriteria<HostPodVO> sc = StateChangeSearch.create();
+        sc.setParameters("id", vo.getId());
+        sc.setParameters("state", currentState);
+
+        UpdateBuilder builder = getUpdateBuilder(vo);
+        builder.set(vo, "state", nextState);
+        builder.set(vo, "lastUpdated", new Date());
+
+        int rows = update((HostPodVO) vo, sc);
+        
+        if (rows == 0 && s_logger.isDebugEnabled()) {
+        	HostPodVO dbDC = findByIdIncludingRemoved(vo.getId());
+            if (dbDC != null) {
+                StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
+                str.append(": DB Data={id=").append(dbDC.getId()).append("; state=").append(dbDC.getState()).append(";updatedTime=")
+                        .append(dbDC.getLastUpdated());
+                str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatedTime=").append(vo.getLastUpdated());
+                str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatedTime=").append(oldUpdatedTime);
+            } else {
+                s_logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore");
+            }
+        }
+        return rows > 0;
+		
+	}
+    	
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java
index a6dda3a..2dc652f 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java
@@ -29,6 +29,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 
 import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity;
+import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntityImpl;
 import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
 import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceManager;
 import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
@@ -50,6 +51,8 @@ import com.cloud.storage.StoragePool;
 @Path("/provisioning")
 public class ProvisioningServiceImpl implements ProvisioningService {
 
+	@Inject
+	DataCenterResourceManager manager;
 	
 	@Override
     public StorageEntity registerStorage(String name, List<String> tags, Map<String, String> details) {
@@ -58,27 +61,31 @@ public class ProvisioningServiceImpl implements ProvisioningService {
     }
 
     @Override
-    public ZoneEntity registerZone(String zoneUuid, String owner, List<String> tags, Map<String, String> details) {
-
-    	ZoneEntityImpl zoneEntity = new ZoneEntityImpl(zoneUuid);
+    public ZoneEntity registerZone(String zoneUuid, String name, String owner, List<String> tags, Map<String, String> details) {
+    	ZoneEntityImpl zoneEntity = new ZoneEntityImpl(zoneUuid, manager);
+    	zoneEntity.setName(name);
     	zoneEntity.setOwner(owner);
     	zoneEntity.setDetails(details);
-    	zoneEntity.setState(State.Disabled);
     	zoneEntity.persist();
-    	
     	return zoneEntity;
     }
 
-  //  @Override
-   // public PodEntity registerPod(String name, List<String> tags, Map<String, String> details) {
-     //   // TODO Auto-generated method stub
-     //   return null;
-    //}
+    @Override
+    public PodEntity registerPod(String podUuid, String name, String owner, String zoneUuid, List<String> tags, Map<String, String> details) {
+    	PodEntityImpl podEntity = new PodEntityImpl(podUuid, manager);
+    	podEntity.setOwner(owner);
+    	podEntity.setName(name);
+    	podEntity.persist();
+    	return podEntity;
+    }
 
     @Override
-    public ClusterEntity registerCluster(String name, List<String> tags, Map<String, String> details) {
-        // TODO Auto-generated method stub
-        return null;
+    public ClusterEntity registerCluster(String clusterUuid, String name, String owner, List<String> tags, Map<String, String> details) {
+    	ClusterEntityImpl clusterEntity = new ClusterEntityImpl(clusterUuid, manager);
+    	clusterEntity.setOwner(owner);
+    	clusterEntity.setName(name);
+    	clusterEntity.persist();
+    	return clusterEntity;
     }
 
     @Override
@@ -94,20 +101,21 @@ public class ProvisioningServiceImpl implements ProvisioningService {
     }
 
     @Override
-    public void deregisterZone() {
-        // TODO Auto-generated method stub
-
+    public void deregisterZone(String uuid) {
+    	ZoneEntityImpl zoneEntity = new ZoneEntityImpl(uuid, manager);
+    	zoneEntity.disable();
     }
 
     @Override
-    public void deregisterPod() {
-        // TODO Auto-generated method stub
-
+    public void deregisterPod(String uuid) {
+    	PodEntityImpl podEntity = new PodEntityImpl(uuid, manager);
+    	podEntity.disable();
     }
 
     @Override
-    public void deregisterCluster() {
-        // TODO Auto-generated method stub
+    public void deregisterCluster(String uuid) {
+    	ClusterEntityImpl clusterEntity = new ClusterEntityImpl(uuid, manager);
+    	clusterEntity.disable();
 
     }
 
@@ -132,16 +140,16 @@ public class ProvisioningServiceImpl implements ProvisioningService {
     @Override
     public List<PodEntity> listPods() {
         List<PodEntity> pods = new ArrayList<PodEntity>();
-        pods.add(new PodEntityImpl("pod-uuid-1", "pod1"));
-        pods.add(new PodEntityImpl("pod-uuid-2", "pod2"));
+        //pods.add(new PodEntityImpl("pod-uuid-1", "pod1"));
+        //pods.add(new PodEntityImpl("pod-uuid-2", "pod2"));
         return null;
     }
 
     @Override
     public List<ZoneEntity> listZones() {
         List<ZoneEntity> zones = new ArrayList<ZoneEntity>();
-        zones.add(new ZoneEntityImpl("zone-uuid-1"));
-        zones.add(new ZoneEntityImpl("zone-uuid-2"));
+        //zones.add(new ZoneEntityImpl("zone-uuid-1"));
+        //zones.add(new ZoneEntityImpl("zone-uuid-2"));
         return zones;
     }
 
@@ -153,18 +161,8 @@ public class ProvisioningServiceImpl implements ProvisioningService {
 
     @Override
     public ZoneEntity getZone(String uuid) {
-        ZoneEntityImpl impl = new ZoneEntityImpl(uuid);
+        ZoneEntityImpl impl = new ZoneEntityImpl(uuid, manager);
         return impl;
     }
 
-    @Override
-
-	public PodEntity registerPod(String arg0, Long arg1, String arg2,
-			String arg3, String arg4, String arg5, List<String> arg6,
-			Map<String, String> arg7) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ChildTestConfiguration.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ChildTestConfiguration.java b/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ChildTestConfiguration.java
index a8b2030..13e44ab 100644
--- a/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ChildTestConfiguration.java
+++ b/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ChildTestConfiguration.java
@@ -1,7 +1,9 @@
 package org.apache.cloudstack.engine.provisioning.test;
 
 
+import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.ClusterDao;
 import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DataCenterDao;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.HostPodDao;
 import org.mockito.Mockito;
 import org.springframework.context.annotation.Bean;
 
@@ -14,5 +16,15 @@ public class ChildTestConfiguration {
 	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);
+	}
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ff3a47e/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java b/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java
index a7135fe..72ad834 100644
--- a/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java
+++ b/engine/orchestration/test/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java
@@ -4,13 +4,19 @@
 package org.apache.cloudstack.engine.provisioning.test;
 
 import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 
 import javax.inject.Inject;
 
+import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity;
 import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
+import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
 import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.ClusterDao;
 import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DataCenterDao;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.HostPodDao;
 import org.apache.cloudstack.engine.service.api.ProvisioningService;
 import org.junit.Before;
 import org.junit.Test;
@@ -19,7 +25,10 @@ import org.mockito.Mockito;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
+import org.apache.cloudstack.engine.datacenter.entity.api.db.ClusterVO;
 import org.apache.cloudstack.engine.datacenter.entity.api.db.DataCenterVO;
+import org.apache.cloudstack.engine.datacenter.entity.api.db.HostPodVO;
+
 import com.cloud.dc.DataCenter.NetworkType;
 
 import junit.framework.TestCase;
@@ -34,27 +43,59 @@ public class ProvisioningTest extends TestCase {
 	@Inject
 	DataCenterDao dcDao;
 	
+	@Inject
+	HostPodDao _podDao;
+
+	@Inject
+	ClusterDao _clusterDao;
+
+	
     @Before
 	public void setUp() {
-    	
     	DataCenterVO dc = 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);
-    	
-		Mockito.when(dcDao.findById(Mockito.anyLong())).thenReturn(dc);
-		Mockito.when(dcDao.persist((DataCenterVO) Mockito.anyObject())).thenReturn(dc);    	    	
+		Mockito.when(dcDao.findByUUID(Mockito.anyString())).thenReturn(dc);
+		Mockito.when(dcDao.persist((DataCenterVO) Mockito.anyObject())).thenReturn(dc);
+		
+		HostPodVO pod = new HostPodVO("lab", 123, "10.0.0.1", "10.0.0.1", 24, "test");
+		Mockito.when(_podDao.findByUUID(Mockito.anyString())).thenReturn(pod);
+		Mockito.when(_podDao.persist((HostPodVO) Mockito.anyObject())).thenReturn(pod);    	    	
+		
+    	ClusterVO cluster = new ClusterVO();
+		Mockito.when(_clusterDao.findByUUID(Mockito.anyString())).thenReturn(cluster);
+		Mockito.when(_clusterDao.persist((ClusterVO) Mockito.anyObject())).thenReturn(cluster);    	    	
     }
 
 	private void registerAndEnableZone() {
-		ZoneEntity zone = service.registerZone("47547648", "owner", null, new HashMap<String, String>());
+		ZoneEntity zone = service.registerZone("47547648", "lab","owner", null, new HashMap<String, String>());
 		State state = zone.getState();
 		System.out.println("state:"+state);
 		boolean result = zone.enable();
-		System.out.println("state:"+zone.getState());
+		System.out.println("result:"+result);
+
+	}
+	
+	private void registerAndEnablePod() {
+		PodEntity pod = service.registerPod("47547648", "lab","owner", "8709874074", null, new HashMap<String, String>());
+		State state = pod.getState();
+		System.out.println("state:"+state);
+		boolean result = pod.enable();
+		System.out.println("result:"+result);
+	}
+	
+	private void registerAndEnableCluster() {
+		ClusterEntity cluster = service.registerCluster("1265476542", "lab","owner", null, new HashMap<String, String>());
+		State state = cluster.getState();
+		System.out.println("state:"+state);
+		boolean result = cluster.enable();
+		System.out.println("result:"+result);
 	}
 
 	@Test
 	public void testProvisioning() {
 		registerAndEnableZone();
+		registerAndEnablePod();
+		registerAndEnableCluster();
 	}
 
 


Mime
View raw message