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 bec5a4c6d1a..d4d3a8cfac2 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 { } 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 2cc66258282..6eda5dd1ad9 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 listClusters(); + + String getCidrAddress(); + + int getCidrSize(); + + String getGateway(); + + long getDataCenterId(); + + String getName(); + + AllocationState getAllocationState(); + + boolean getExternalDhcp(); } 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 106e18de9f3..c9ed9fbbe1b 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 listPodIds(); - @Override - @Path("/enable") - boolean enable(); + + String getName(); + } 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 e1f41fa9505..09130d1d995 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 getApplicableActions(); + } 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 00000000000..fdfd17a68be --- /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 zones = _provisioningService.listZones(); + ZoneRestTO[] tos = new ZoneRestTO[zones.size()]; + UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getZone"); + Iterator 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 pods = _provisioningService.listPods(); + PodRestTO[] tos = new PodRestTO[pods.size()]; + Iterator it = pods.iterator(); + for (int i = 0; i < tos.length; i++) { + PodEntity pod = it.next(); + tos[i] = new PodRestTO(pod); + } + return tos; + } +} 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 8b28aee0d64..e4517422061 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 tags, Map details); @POST - ZoneEntity registerZone(String zoneUuid, String owner, List tags, Map details); + ZoneEntity registerZone(String zoneUuid, String name, String owner, List tags, Map details); @POST - PodEntity registerPod(String name, Long zoneId, String gateway, String cidr, String startIp, String endIp, List tags, Map details); + PodEntity registerPod(String podUuid, String name, String owner, String zoneUuid, List tags, Map details); - ClusterEntity registerCluster(String name, List tags, Map details); + ClusterEntity registerCluster(String clusterUuid, String name, String owner, List tags, Map details); String registerHost(String name, List tags, Map 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(); 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 00000000000..20ffcb198c2 --- /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 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 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); + } + +} 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 8bd3ca4f061..11e24cb287b 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); } 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 b36b11dd798..161d00e34b7 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 _stateMachine; + + @Inject + HostPodDao _podDao; + + @Inject + ClusterDao _clusterDao; + + protected StateMachine2 _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); } } 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 ba4295934b7..e17e3912508 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 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); + } + } 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 ae35536bfa8..e87cc4b9e9d 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 { - @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 listPodIds() { @@ -199,4 +194,8 @@ public class ZoneEntityImpl implements ZoneEntity, FiniteStateObject, StateDao { + List listByPodId(long podId); + ClusterVO findBy(String name, long podId); + List listByHyTypeWithoutGuid(String hyType); + List listByZoneId(long zoneId); + + List getAvailableHypervisorInZone(Long zoneId); + List listByDcHyType(long dcId, String hyType); + Map> getPodClusterIdMap(List clusterIds); + List listDisabledClusters(long zoneId, Long podId); + List listClustersWithDisabledPods(long zoneId); + ClusterVO findByUUID(String uuid); +} 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 00000000000..ff2e911f309 --- /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 implements ClusterDao { + private static final Logger s_logger = Logger.getLogger(ClusterDaoImpl.class); + + protected final SearchBuilder PodSearch; + protected final SearchBuilder HyTypeWithoutGuidSearch; + protected final SearchBuilder AvailHyperSearch; + protected final SearchBuilder ZoneSearch; + protected final SearchBuilder ZoneHyTypeSearch; + protected SearchBuilder StateChangeSearch; + protected SearchBuilder 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 listByZoneId(long zoneId) { + SearchCriteria sc = ZoneSearch.create(); + sc.setParameters("dataCenterId", zoneId); + return listBy(sc); + } + + @Override + public List listByPodId(long podId) { + SearchCriteria sc = PodSearch.create(); + sc.setParameters("pod", podId); + + return listBy(sc); + } + + @Override + public ClusterVO findBy(String name, long podId) { + SearchCriteria sc = PodSearch.create(); + sc.setParameters("pod", podId); + sc.setParameters("name", name); + + return findOneBy(sc); + } + + @Override + public List listByHyTypeWithoutGuid(String hyType) { + SearchCriteria sc = HyTypeWithoutGuidSearch.create(); + sc.setParameters("hypervisorType", hyType); + + return listBy(sc); + } + + @Override + public List listByDcHyType(long dcId, String hyType) { + SearchCriteria sc = ZoneHyTypeSearch.create(); + sc.setParameters("dataCenterId", dcId); + sc.setParameters("hypervisorType", hyType); + return listBy(sc); + } + + @Override + public List getAvailableHypervisorInZone(Long zoneId) { + SearchCriteria sc = AvailHyperSearch.create(); + if (zoneId != null) { + sc.setParameters("zoneId", zoneId); + } + List clusters = listBy(sc); + List hypers = new ArrayList(4); + for (ClusterVO cluster : clusters) { + hypers.add(cluster.getHypervisorType()); + } + + return hypers; + } + + @Override + public Map> getPodClusterIdMap(List clusterIds){ + Transaction txn = Transaction.currentTxn(); + PreparedStatement pstmt = null; + Map> result = new HashMap>(); + + 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 clusterList = result.get(podId); + clusterList.add(clusterIdInPod); + result.put(podId, clusterList); + }else{ + List clusterList = new ArrayList(); + 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 listDisabledClusters(long zoneId, Long podId) { + GenericSearchBuilder 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 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 listClustersWithDisabledPods(long zoneId) { + + GenericSearchBuilder 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 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 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 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 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; + + } + +} 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 00000000000..bfdbaaef31b --- /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, StateDao { + public List listByDataCenterId(long id); + + public HostPodVO findByName(String name, long dcId); + + public HashMap> getCurrentPodCidrSubnets(long zoneId, long podIdToSkip); + + public List listDisabledPods(long zoneId); + + public HostPodVO findByUUID(String uuid); + +} 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 00000000000..df52ed626bc --- /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 implements HostPodDao { + private static final Logger s_logger = Logger.getLogger(HostPodDaoImpl.class); + + protected SearchBuilder DataCenterAndNameSearch; + protected SearchBuilder DataCenterIdSearch; + protected SearchBuilder UUIDSearch; + protected SearchBuilder 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 listByDataCenterId(long id) { + SearchCriteria sc = DataCenterIdSearch.create(); + sc.setParameters("dcId", id); + + return listBy(sc); + } + + @Override + public HostPodVO findByName(String name, long dcId) { + SearchCriteria sc = DataCenterAndNameSearch.create(); + sc.setParameters("dc", dcId); + sc.setParameters("name", name); + + return findOneBy(sc); + } + + @Override + public HashMap> getCurrentPodCidrSubnets(long zoneId, long podIdToSkip) { + HashMap> currentPodCidrSubnets = new HashMap>(); + + 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 cidrPair = new ArrayList(); + 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 listDisabledPods(long zoneId) { + GenericSearchBuilder 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 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 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 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; + + } + + +} 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 a6dda3a3315..2dc652f20d5 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 tags, Map details) { @@ -58,27 +61,31 @@ public class ProvisioningServiceImpl implements ProvisioningService { } @Override - public ZoneEntity registerZone(String zoneUuid, String owner, List tags, Map details) { - - ZoneEntityImpl zoneEntity = new ZoneEntityImpl(zoneUuid); + public ZoneEntity registerZone(String zoneUuid, String name, String owner, List tags, Map 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 tags, Map details) { - // // TODO Auto-generated method stub - // return null; - //} + @Override + public PodEntity registerPod(String podUuid, String name, String owner, String zoneUuid, List tags, Map details) { + PodEntityImpl podEntity = new PodEntityImpl(podUuid, manager); + podEntity.setOwner(owner); + podEntity.setName(name); + podEntity.persist(); + return podEntity; + } @Override - public ClusterEntity registerCluster(String name, List tags, Map details) { - // TODO Auto-generated method stub - return null; + public ClusterEntity registerCluster(String clusterUuid, String name, String owner, List tags, Map 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 listPods() { List pods = new ArrayList(); - 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 listZones() { List zones = new ArrayList(); - 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 arg6, - Map arg7) { - // TODO Auto-generated method stub - return null; - } - - } 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 a8b20307967..13e44abd68f 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); + } } 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 a7135fe3c9f..72ad83402af 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()); + ZoneEntity zone = service.registerZone("47547648", "lab","owner", null, new HashMap()); 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()); + 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()); + 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(); }