use of com.cloud.dc.DataCenterVO in project cloudstack by apache.
the class NetworkOrchestrator method shutdownNetwork.
@Override
@DB
public boolean shutdownNetwork(final long networkId, final ReservationContext context, final boolean cleanupElements) {
NetworkVO network = _networksDao.findById(networkId);
if (network.getState() == Network.State.Allocated) {
s_logger.debug("Network is already shutdown: " + network);
return true;
}
if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) {
s_logger.debug("Network is not implemented: " + network);
return false;
}
try {
//do global lock for the network
network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
if (network == null) {
s_logger.warn("Unable to acquire lock for the network " + network + " as a part of network shutdown");
return false;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Lock is acquired for network " + network + " as a part of network shutdown");
}
if (network.getState() == Network.State.Allocated) {
s_logger.debug("Network is already shutdown: " + network);
return true;
}
if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) {
s_logger.debug("Network is not implemented: " + network);
return false;
}
if (isSharedNetworkWithServices(network)) {
network.setState(Network.State.Shutdown);
_networksDao.update(network.getId(), network);
} else {
try {
stateTransitTo(network, Event.DestroyNetwork);
} catch (final NoTransitionException e) {
network.setState(Network.State.Shutdown);
_networksDao.update(network.getId(), network);
}
}
final boolean success = shutdownNetworkElementsAndResources(context, cleanupElements, network);
final NetworkVO networkFinal = network;
final boolean result = Transaction.execute(new TransactionCallback<Boolean>() {
@Override
public Boolean doInTransaction(final TransactionStatus status) {
boolean result = false;
if (success) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now.");
}
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, networkFinal.getGuruName());
final NetworkProfile profile = convertNetworkToNetworkProfile(networkFinal.getId());
guru.shutdown(profile, _networkOfferingDao.findById(networkFinal.getNetworkOfferingId()));
applyProfileToNetwork(networkFinal, profile);
final DataCenterVO zone = _dcDao.findById(networkFinal.getDataCenterId());
if (isSharedNetworkOfferingWithServices(networkFinal.getNetworkOfferingId()) && zone.getNetworkType() == NetworkType.Advanced) {
networkFinal.setState(Network.State.Setup);
} else {
try {
stateTransitTo(networkFinal, Event.OperationSucceeded);
} catch (final NoTransitionException e) {
networkFinal.setState(Network.State.Allocated);
networkFinal.setRestartRequired(false);
}
}
_networksDao.update(networkFinal.getId(), networkFinal);
_networksDao.clearCheckForGc(networkId);
result = true;
} else {
try {
stateTransitTo(networkFinal, Event.OperationFailed);
} catch (final NoTransitionException e) {
networkFinal.setState(Network.State.Implemented);
_networksDao.update(networkFinal.getId(), networkFinal);
}
result = false;
}
return result;
}
});
return result;
} finally {
if (network != null) {
_networksDao.releaseFromLockTable(network.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Lock is released for network " + network + " as a part of network shutdown");
}
}
}
}
use of com.cloud.dc.DataCenterVO in project cloudstack by apache.
the class NetworkOrchestrator method reallocate.
@DB
@Override
public boolean reallocate(final VirtualMachineProfile vm, final DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException {
final VMInstanceVO vmInstance = _vmDao.findById(vm.getId());
final DataCenterVO dc = _dcDao.findById(vmInstance.getDataCenterId());
if (dc.getNetworkType() == NetworkType.Basic) {
final List<NicVO> nics = _nicDao.listByVmId(vmInstance.getId());
final NetworkVO network = _networksDao.findById(nics.get(0).getNetworkId());
final LinkedHashMap<Network, List<? extends NicProfile>> profiles = new LinkedHashMap<Network, List<? extends NicProfile>>();
profiles.put(network, new ArrayList<NicProfile>());
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientCapacityException>() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) throws InsufficientCapacityException {
cleanupNics(vm);
allocate(vm, profiles);
}
});
}
return true;
}
use of com.cloud.dc.DataCenterVO in project cloudstack by apache.
the class TemplateTest method setUp.
@Test(priority = -1)
public void setUp() {
ComponentContext.initComponentsLifeCycle();
// create data center
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, null, null);
dc = dcDao.persist(dc);
dcId = dc.getId();
imageStore = new ImageStoreVO();
imageStore.setName("test");
imageStore.setDataCenterId(dcId);
imageStore.setProviderName(DataStoreProvider.NFS_IMAGE);
imageStore.setRole(DataStoreRole.Image);
imageStore.setUrl(this.getSecondaryStorage());
imageStore.setUuid(UUID.randomUUID().toString());
imageStore.setProtocol("nfs");
imageStore = imageStoreDao.persist(imageStore);
VMTemplateVO image = new VMTemplateVO();
image.setTemplateType(TemplateType.USER);
image.setUrl(this.getTemplateUrl());
image.setUniqueName(UUID.randomUUID().toString());
image.setName(UUID.randomUUID().toString());
image.setPublicTemplate(true);
image.setFeatured(true);
image.setRequiresHvm(true);
image.setBits(64);
image.setFormat(Storage.ImageFormat.VHD);
image.setEnablePassword(true);
image.setEnableSshKey(true);
image.setGuestOSId(1);
image.setBootable(true);
image.setPrepopulate(true);
image.setCrossZones(true);
image.setExtractable(true);
// image.setImageDataStoreId(storeId);
image = templateDao.persist(image);
templateId = image.getId();
// inject mockito
LocalHostEndpoint ep = new LocalHostEndpoint();
ep.setResource(new MockLocalNfsSecondaryStorageResource());
Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep);
Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep);
}
use of com.cloud.dc.DataCenterVO in project cloudstack by apache.
the class VolumeServiceTest method setUp.
@Test(priority = -1)
public void setUp() {
ComponentContext.initComponentsLifeCycle();
host = hostDao.findByGuid(this.getHostGuid());
if (host != null) {
dcId = host.getDataCenterId();
clusterId = host.getClusterId();
podId = host.getPodId();
return;
}
// create data center
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, null, null);
dc = dcDao.persist(dc);
dcId = dc.getId();
// create pod
HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(), this.getHostCidr(), 8, "test");
pod = podDao.persist(pod);
podId = pod.getId();
// create xenserver cluster
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
cluster.setHypervisorType(HypervisorType.XenServer.toString());
cluster.setClusterType(ClusterType.CloudManaged);
cluster.setManagedState(ManagedState.Managed);
cluster = clusterDao.persist(cluster);
clusterId = cluster.getId();
// create xenserver host
host = new HostVO(this.getHostGuid());
host.setName("devcloud xenserver host");
host.setType(Host.Type.Routing);
host.setPrivateIpAddress(this.getHostIp());
host.setDataCenterId(dc.getId());
host.setVersion("6.0.1");
host.setAvailable(true);
host.setSetup(true);
host.setPodId(podId);
host.setLastPinged(0);
host.setResourceState(ResourceState.Enabled);
host.setHypervisorType(HypervisorType.XenServer);
host.setClusterId(cluster.getId());
host = hostDao.persist(host);
imageStore = new ImageStoreVO();
imageStore.setName("test");
imageStore.setDataCenterId(dcId);
imageStore.setProviderName("CloudStack ImageStore Provider");
imageStore.setRole(DataStoreRole.Image);
imageStore.setUrl(this.getSecondaryStorage());
imageStore.setUuid(UUID.randomUUID().toString());
imageStore = imageStoreDao.persist(imageStore);
}
use of com.cloud.dc.DataCenterVO in project cloudstack by apache.
the class ExplicitDedicationProcessor method process.
/**
* This method will process the affinity group of type 'Explicit Dedication' for a deployment of a VM that demands dedicated resources.
* For ExplicitDedicationProcessor we need to add dedicated resources into the IncludeList based on the level we have dedicated resources available.
* For eg. if admin dedicates a pod to a domain, then all the user in that domain can use the resources of that pod.
* We need to take care of the situation when dedicated resources further have resources dedicated to sub-domain/account.
* This IncludeList is then used to update the avoid list for a given data center.
*/
@Override
public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException {
VirtualMachine vm = vmProfile.getVirtualMachine();
List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
DataCenter dc = _dcDao.findById(vm.getDataCenterId());
List<DedicatedResourceVO> resourceList = new ArrayList<DedicatedResourceVO>();
if (vmGroupMappings != null && !vmGroupMappings.isEmpty()) {
for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
if (vmGroupMapping != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Processing affinity group " + vmGroupMapping.getAffinityGroupId() + "of type 'ExplicitDedication' for VM Id: " + vm.getId());
}
long affinityGroupId = vmGroupMapping.getAffinityGroupId();
List<DedicatedResourceVO> dr = _dedicatedDao.listByAffinityGroupId(affinityGroupId);
resourceList.addAll(dr);
}
}
boolean canUse = false;
if (plan.getHostId() != null) {
HostVO host = _hostDao.findById(plan.getHostId());
ClusterVO clusterofHost = _clusterDao.findById(host.getClusterId());
HostPodVO podOfHost = _podDao.findById(host.getPodId());
DataCenterVO zoneOfHost = _dcDao.findById(host.getDataCenterId());
if (resourceList != null && resourceList.size() != 0) {
for (DedicatedResourceVO resource : resourceList) {
if ((resource.getHostId() != null && resource.getHostId().longValue() == plan.getHostId().longValue()) || (resource.getClusterId() != null && resource.getClusterId().longValue() == clusterofHost.getId()) || (resource.getPodId() != null && resource.getPodId().longValue() == podOfHost.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId().longValue() == zoneOfHost.getId())) {
canUse = true;
}
}
}
if (!canUse) {
throw new CloudRuntimeException("Cannot use this host " + host.getName() + " for explicit dedication");
}
} else if (plan.getClusterId() != null) {
ClusterVO cluster = _clusterDao.findById(plan.getClusterId());
HostPodVO podOfCluster = _podDao.findById(cluster.getPodId());
DataCenterVO zoneOfCluster = _dcDao.findById(cluster.getDataCenterId());
List<HostVO> hostToUse = new ArrayList<HostVO>();
// check whether this cluster or its pod is dedicated
if (resourceList != null && resourceList.size() != 0) {
for (DedicatedResourceVO resource : resourceList) {
if ((resource.getClusterId() != null && resource.getClusterId() == cluster.getId()) || (resource.getPodId() != null && resource.getPodId() == podOfCluster.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfCluster.getId())) {
canUse = true;
}
// cluster
if (!canUse) {
if (resource.getHostId() != null) {
HostVO dHost = _hostDao.findById(resource.getHostId());
if (dHost.getClusterId() == cluster.getId()) {
hostToUse.add(dHost);
}
}
}
}
}
if (hostToUse.isEmpty() && !canUse) {
throw new CloudRuntimeException("Cannot use this cluster " + cluster.getName() + " for explicit dedication");
}
if (hostToUse != null && hostToUse.size() != 0) {
// add other non-dedicated hosts to avoid list
List<HostVO> hostList = _hostDao.findByClusterId(cluster.getId());
for (HostVO host : hostList) {
if (!hostToUse.contains(host)) {
avoid.addHost(host.getId());
}
}
}
} else if (plan.getPodId() != null) {
HostPodVO pod = _podDao.findById(plan.getPodId());
DataCenterVO zoneOfPod = _dcDao.findById(pod.getDataCenterId());
List<ClusterVO> clustersToUse = new ArrayList<ClusterVO>();
List<HostVO> hostsToUse = new ArrayList<HostVO>();
// check whether this cluster or its pod is dedicated
if (resourceList != null && resourceList.size() != 0) {
for (DedicatedResourceVO resource : resourceList) {
if ((resource.getPodId() != null && resource.getPodId() == pod.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfPod.getId())) {
canUse = true;
}
// this pod
if (!canUse) {
if (resource.getClusterId() != null) {
ClusterVO dCluster = _clusterDao.findById(resource.getClusterId());
if (dCluster.getPodId() == pod.getId()) {
clustersToUse.add(dCluster);
}
}
if (resource.getHostId() != null) {
HostVO dHost = _hostDao.findById(resource.getHostId());
if (dHost.getPodId() == pod.getId()) {
hostsToUse.add(dHost);
}
}
}
}
}
if (hostsToUse.isEmpty() && clustersToUse.isEmpty() && !canUse) {
throw new CloudRuntimeException("Cannot use this pod " + pod.getName() + " for explicit dedication");
}
if (clustersToUse != null && clustersToUse.size() != 0) {
// add other non-dedicated clusters to avoid list
List<ClusterVO> clusterList = _clusterDao.listByPodId(pod.getId());
for (ClusterVO cluster : clusterList) {
if (!clustersToUse.contains(cluster)) {
avoid.addCluster(cluster.getId());
}
}
}
if (hostsToUse != null && hostsToUse.size() != 0) {
// add other non-dedicated hosts to avoid list
List<HostVO> hostList = _hostDao.findByPodId(pod.getId());
for (HostVO host : hostList) {
if (!hostsToUse.contains(host)) {
avoid.addHost(host.getId());
}
}
}
} else {
// check all resources under this zone
if (resourceList != null && resourceList.size() != 0) {
avoid = updateAvoidList(resourceList, avoid, dc);
} else {
avoid.addDataCenter(dc.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("No dedicated resources available for this domain or account under this group");
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("ExplicitDedicationProcessor returns Avoid List as: Deploy avoids pods: " + avoid.getPodsToAvoid() + ", clusters: " + avoid.getClustersToAvoid() + ", hosts: " + avoid.getHostsToAvoid());
}
}
}
}
Aggregations