use of com.cloud.dc.ClusterVO in project cloudstack by apache.
the class ClusterDaoImpl method getSupportsResigning.
@Override
public boolean getSupportsResigning(long clusterId) {
ClusterVO cluster = findById(clusterId);
if (cluster == null || cluster.getAllocationState() != Grouping.AllocationState.Enabled) {
return false;
}
ClusterDetailsVO clusterDetailsVO = clusterDetailsDao.findDetail(clusterId, "supportsResign");
if (clusterDetailsVO != null) {
String value = clusterDetailsVO.getValue();
return Boolean.parseBoolean(value);
}
return false;
}
use of com.cloud.dc.ClusterVO in project cloudstack by apache.
the class SnapshotTest 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();
imageStore = this.imageStoreDao.findByName(imageStoreName);
} else {
// 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(this.getHypervisor().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(this.getHypervisor());
host.setClusterId(cluster.getId());
host = hostDao.persist(host);
imageStore = new ImageStoreVO();
imageStore.setName(imageStoreName);
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);
}
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 = imageDataDao.persist(image);
/*
* TemplateDataStoreVO templateStore = new TemplateDataStoreVO();
*
* templateStore.setDataStoreId(imageStore.getId());
* templateStore.setDownloadPercent(100);
* templateStore.setDownloadState(Status.DOWNLOADED);
* templateStore.setDownloadUrl(imageStore.getUrl());
* templateStore.setInstallPath(this.getImageInstallPath());
* templateStore.setTemplateId(image.getId());
* templateStoreDao.persist(templateStore);
*/
DataStore store = this.dataStoreMgr.getDataStore(imageStore.getId(), DataStoreRole.Image);
TemplateInfo template = templateFactory.getTemplate(image.getId(), DataStoreRole.Image);
DataObject templateOnStore = store.create(template);
TemplateObjectTO to = new TemplateObjectTO();
to.setPath(this.getImageInstallPath());
to.setFormat(ImageFormat.VHD);
to.setSize(1000L);
CopyCmdAnswer answer = new CopyCmdAnswer(to);
templateOnStore.processEvent(Event.CreateOnlyRequested);
templateOnStore.processEvent(Event.OperationSuccessed, answer);
}
use of com.cloud.dc.ClusterVO 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());
}
}
}
}
use of com.cloud.dc.ClusterVO in project cloudstack by apache.
the class ExplicitDedicationProcessor method updateAvoidList.
private ExcludeList updateAvoidList(List<DedicatedResourceVO> dedicatedResources, ExcludeList avoidList, DataCenter dc) {
ExcludeList includeList = new ExcludeList();
for (DedicatedResourceVO dr : dedicatedResources) {
if (dr.getHostId() != null) {
includeList.addHost(dr.getHostId());
HostVO dedicatedHost = _hostDao.findById(dr.getHostId());
includeList.addCluster(dedicatedHost.getClusterId());
includeList.addPod(dedicatedHost.getPodId());
}
if (dr.getClusterId() != null) {
includeList.addCluster(dr.getClusterId());
// add all hosts inside this in includeList
List<HostVO> hostList = _hostDao.findByClusterId(dr.getClusterId());
for (HostVO host : hostList) {
DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null && !dedicatedResources.contains(dHost)) {
avoidList.addHost(host.getId());
} else {
includeList.addHost(host.getId());
}
}
ClusterVO dedicatedCluster = _clusterDao.findById(dr.getClusterId());
includeList.addPod(dedicatedCluster.getPodId());
}
if (dr.getPodId() != null) {
includeList.addPod(dr.getPodId());
// add all cluster under this pod in includeList
List<ClusterVO> clusterList = _clusterDao.listByPodId(dr.getPodId());
for (ClusterVO cluster : clusterList) {
DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
if (dCluster != null && !dedicatedResources.contains(dCluster)) {
avoidList.addCluster(cluster.getId());
} else {
includeList.addCluster(cluster.getId());
}
}
// add all hosts inside this pod in includeList
List<HostVO> hostList = _hostDao.findByPodId(dr.getPodId());
for (HostVO host : hostList) {
DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null && !dedicatedResources.contains(dHost)) {
avoidList.addHost(host.getId());
} else {
includeList.addHost(host.getId());
}
}
}
if (dr.getDataCenterId() != null) {
includeList.addDataCenter(dr.getDataCenterId());
// add all Pod under this data center in includeList
List<HostPodVO> podList = _podDao.listByDataCenterId(dr.getDataCenterId());
for (HostPodVO pod : podList) {
DedicatedResourceVO dPod = _dedicatedDao.findByPodId(pod.getId());
if (dPod != null && !dedicatedResources.contains(dPod)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Avoiding POD %s [%s] because it is not dedicated.", pod.getName(), pod.getUuid()));
}
avoidList.addPod(pod.getId());
} else {
includeList.addPod(pod.getId());
}
}
List<ClusterVO> clusterList = _clusterDao.listClustersByDcId(dr.getDataCenterId());
for (ClusterVO cluster : clusterList) {
DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
if (dCluster != null && !dedicatedResources.contains(dCluster)) {
avoidList.addCluster(cluster.getId());
} else {
includeList.addCluster(cluster.getId());
}
}
// add all hosts inside this in includeList
List<HostVO> hostList = _hostDao.listByDataCenterId(dr.getDataCenterId());
for (HostVO host : hostList) {
DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null && !dedicatedResources.contains(dHost)) {
avoidList.addHost(host.getId());
} else {
includeList.addHost(host.getId());
}
}
}
}
// Update avoid list using includeList.
// add resources in avoid list which are not in include list.
List<HostPodVO> pods = _podDao.listByDataCenterId(dc.getId());
List<ClusterVO> clusters = _clusterDao.listClustersByDcId(dc.getId());
List<HostVO> hosts = _hostDao.listByDataCenterId(dc.getId());
Set<Long> podsInIncludeList = includeList.getPodsToAvoid();
Set<Long> clustersInIncludeList = includeList.getClustersToAvoid();
Set<Long> hostsInIncludeList = includeList.getHostsToAvoid();
for (HostPodVO pod : pods) {
if (podsInIncludeList != null && !podsInIncludeList.contains(pod.getId())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Avoiding POD %s [%s], as it is not in include list.", pod.getName(), pod.getUuid()));
}
avoidList.addPod(pod.getId());
}
}
for (ClusterVO cluster : clusters) {
if (clustersInIncludeList != null && !clustersInIncludeList.contains(cluster.getId())) {
avoidList.addCluster(cluster.getId());
}
}
for (HostVO host : hosts) {
if (hostsInIncludeList != null && !hostsInIncludeList.contains(host.getId())) {
avoidList.addHost(host.getId());
}
}
return avoidList;
}
use of com.cloud.dc.ClusterVO in project cloudstack by apache.
the class VmwareManagerImpl method updateClusterNativeHAState.
@DB
private void updateClusterNativeHAState(Host host, StartupCommand cmd) {
ClusterVO cluster = clusterDao.findById(host.getClusterId());
if (cluster.getClusterType() == ClusterType.ExternalManaged) {
if (cmd instanceof StartupRoutingCommand) {
StartupRoutingCommand hostStartupCmd = (StartupRoutingCommand) cmd;
Map<String, String> details = hostStartupCmd.getHostDetails();
if (details.get("NativeHA") != null && details.get("NativeHA").equalsIgnoreCase("true")) {
clusterDetailsDao.persist(host.getClusterId(), "NativeHA", "true");
} else {
clusterDetailsDao.persist(host.getClusterId(), "NativeHA", "false");
}
}
}
}
Aggregations