use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.
the class ResourceManagerImpl method updateCluster.
@Override
@DB
public Cluster updateCluster(final Cluster clusterToUpdate, final String clusterType, final String hypervisor, final String allocationState, final String managedstate) {
final ClusterVO cluster = (ClusterVO) clusterToUpdate;
// Verify cluster information and update the cluster if needed
boolean doUpdate = false;
if (hypervisor != null && !hypervisor.isEmpty()) {
final Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.getType(hypervisor);
if (hypervisorType == null) {
s_logger.error("Unable to resolve " + hypervisor + " to a valid supported hypervisor type");
throw new InvalidParameterValueException("Unable to resolve " + hypervisor + " to a supported type");
} else {
cluster.setHypervisorType(hypervisor);
doUpdate = true;
}
}
final Cluster.ClusterType newClusterType;
if (clusterType != null && !clusterType.isEmpty()) {
try {
newClusterType = Cluster.ClusterType.valueOf(clusterType);
} catch (final IllegalArgumentException ex) {
throw new InvalidParameterValueException("Unable to resolve " + clusterType + " to a supported type");
}
if (newClusterType == null) {
s_logger.error("Unable to resolve " + clusterType + " to a valid supported cluster type");
throw new InvalidParameterValueException("Unable to resolve " + clusterType + " to a supported type");
} else {
cluster.setClusterType(newClusterType);
doUpdate = true;
}
}
final AllocationState newAllocationState;
if (allocationState != null && !allocationState.isEmpty()) {
try {
newAllocationState = AllocationState.valueOf(allocationState);
} catch (final IllegalArgumentException ex) {
throw new InvalidParameterValueException("Unable to resolve Allocation State '" + allocationState + "' to a supported state");
}
if (newAllocationState == null) {
s_logger.error("Unable to resolve " + allocationState + " to a valid supported allocation State");
throw new InvalidParameterValueException("Unable to resolve " + allocationState + " to a supported state");
} else {
cluster.setAllocationState(newAllocationState);
doUpdate = true;
}
}
Managed.ManagedState newManagedState = null;
final Managed.ManagedState oldManagedState = cluster.getManagedState();
if (managedstate != null && !managedstate.isEmpty()) {
try {
newManagedState = Managed.ManagedState.valueOf(managedstate);
} catch (final IllegalArgumentException ex) {
throw new InvalidParameterValueException("Unable to resolve Managed State '" + managedstate + "' to a supported state");
}
if (newManagedState == null) {
s_logger.error("Unable to resolve Managed State '" + managedstate + "' to a supported state");
throw new InvalidParameterValueException("Unable to resolve Managed State '" + managedstate + "' to a supported state");
} else {
doUpdate = true;
}
}
if (doUpdate) {
_clusterDao.update(cluster.getId(), cluster);
}
if (newManagedState != null && !newManagedState.equals(oldManagedState)) {
if (newManagedState.equals(Managed.ManagedState.Unmanaged)) {
boolean success = false;
try {
cluster.setManagedState(Managed.ManagedState.PrepareUnmanaged);
_clusterDao.update(cluster.getId(), cluster);
List<HostVO> hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
for (final HostVO host : hosts) {
if (host.getType().equals(Host.Type.Routing) && !host.getStatus().equals(Status.Down) && !host.getStatus().equals(Status.Disconnected) && !host.getStatus().equals(Status.Up) && !host.getStatus().equals(Status.Alert)) {
final String msg = "host " + host.getPrivateIpAddress() + " should not be in " + host.getStatus().toString() + " status";
throw new CloudRuntimeException("PrepareUnmanaged Failed due to " + msg);
}
}
for (final HostVO host : hosts) {
if (host.getStatus().equals(Status.Up)) {
umanageHost(host.getId());
}
}
final int retry = 40;
boolean lsuccess;
for (int i = 0; i < retry; i++) {
lsuccess = true;
try {
Thread.sleep(5 * 1000);
} catch (final Exception e) {
}
hosts = listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
for (final HostVO host : hosts) {
if (!host.getStatus().equals(Status.Down) && !host.getStatus().equals(Status.Disconnected) && !host.getStatus().equals(Status.Alert)) {
lsuccess = false;
break;
}
}
if (lsuccess == true) {
success = true;
break;
}
}
if (success == false) {
throw new CloudRuntimeException("PrepareUnmanaged Failed due to some hosts are still in UP status after 5 Minutes, please try later ");
}
} finally {
cluster.setManagedState(success ? Managed.ManagedState.Unmanaged : Managed.ManagedState.PrepareUnmanagedError);
_clusterDao.update(cluster.getId(), cluster);
}
} else if (newManagedState.equals(Managed.ManagedState.Managed)) {
cluster.setManagedState(Managed.ManagedState.Managed);
_clusterDao.update(cluster.getId(), cluster);
}
}
return cluster;
}
use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.
the class ResourceManagerImpl method getDefaultHypervisor.
@Override
public HypervisorType getDefaultHypervisor(final long zoneId) {
HypervisorType defaultHyper = HypervisorType.None;
if (_defaultSystemVMHypervisor != HypervisorType.None) {
defaultHyper = _defaultSystemVMHypervisor;
}
final DataCenterVO dc = _dcDao.findById(zoneId);
if (dc == null) {
return HypervisorType.None;
}
_dcDao.loadDetails(dc);
final String defaultHypervisorInZone = dc.getDetail("defaultSystemVMHypervisorType");
if (defaultHypervisorInZone != null) {
defaultHyper = HypervisorType.getType(defaultHypervisorInZone);
}
final List<VMTemplateVO> systemTemplates = _templateDao.listAllSystemVMTemplates();
boolean isValid = false;
for (final VMTemplateVO template : systemTemplates) {
if (template.getHypervisorType() == defaultHyper) {
isValid = true;
break;
}
}
if (isValid) {
final List<ClusterVO> clusters = _clusterDao.listByDcHyType(zoneId, defaultHyper.toString());
if (clusters.size() <= 0) {
isValid = false;
}
}
if (isValid) {
return defaultHyper;
} else {
return HypervisorType.None;
}
}
use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.
the class DedicatedResourceManagerImpl method dedicateCluster.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_DEDICATE_RESOURCE, eventDescription = "dedicating a Cluster")
public List<DedicatedResourceVO> dedicateCluster(final Long clusterId, final Long domainId, final String accountName) {
Long accountId = null;
List<HostVO> hosts = null;
if (accountName != null) {
final Account caller = CallContext.current().getCallingAccount();
final Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId, null);
accountId = owner.getId();
}
final List<Long> childDomainIds = getDomainChildIds(domainId);
childDomainIds.add(domainId);
checkAccountAndDomain(accountId, domainId);
final ClusterVO cluster = _clusterDao.findById(clusterId);
if (cluster == null) {
throw new InvalidParameterValueException("Unable to find cluster by id " + clusterId);
} else {
final DedicatedResourceVO dedicatedCluster = _dedicatedDao.findByClusterId(clusterId);
final DedicatedResourceVO dedicatedPodOfCluster = _dedicatedDao.findByPodId(cluster.getPodId());
final DedicatedResourceVO dedicatedZoneOfCluster = _dedicatedDao.findByZoneId(cluster.getDataCenterId());
// check if cluster is dedicated
if (dedicatedCluster != null) {
s_logger.error("Cluster " + cluster.getName() + " is already dedicated");
throw new CloudRuntimeException("Cluster " + cluster.getName() + " is already dedicated");
}
if (dedicatedPodOfCluster != null) {
final boolean domainIdInChildreanList = getDomainChildIds(dedicatedPodOfCluster.getDomainId()).contains(domainId);
// can dedicate a cluster to an account/domain if pod is dedicated to parent-domain
if (dedicatedPodOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfCluster.getDomainId().equals(domainId) || domainIdInChildreanList))) {
s_logger.error("Cannot dedicate Cluster. Its Pod is already dedicated");
final HostPodVO pod = _podDao.findById(cluster.getPodId());
throw new CloudRuntimeException("Cluster's Pod " + pod.getName() + " is already dedicated");
}
}
if (dedicatedZoneOfCluster != null) {
final boolean domainIdInChildreanList = getDomainChildIds(dedicatedZoneOfCluster.getDomainId()).contains(domainId);
// can dedicate a cluster to an account/domain if zone is dedicated to parent-domain
if (dedicatedZoneOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfCluster.getDomainId().equals(domainId) || domainIdInChildreanList))) {
s_logger.error("Cannot dedicate Cluster. Its zone is already dedicated");
final Zone zone = zoneRepository.findOne(cluster.getDataCenterId());
throw new CloudRuntimeException("Cluster's Zone " + zone.getName() + " is already dedicated");
}
}
// check if any resource under this cluster is dedicated to different account or sub-domain
hosts = _hostDao.findByClusterId(cluster.getId());
final List<DedicatedResourceVO> hostsToRelease = new ArrayList<>();
for (final HostVO host : hosts) {
final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null) {
if (!(childDomainIds.contains(dHost.getDomainId()))) {
throw new CloudRuntimeException("Host " + host.getName() + " under this Cluster " + cluster.getName() + " is dedicated to different account/domain");
}
/*if all dedicated resources belongs to same account and domain then we should release dedication
and make new entry for this cluster */
if (accountId != null) {
if (dHost.getAccountId().equals(accountId)) {
hostsToRelease.add(dHost);
} else {
s_logger.error("Cannot dedicate Cluster " + cluster.getName() + " to account" + accountName);
throw new CloudRuntimeException("Cannot dedicate Cluster " + cluster.getName() + " to account" + accountName);
}
} else {
if (dHost.getAccountId() == null && dHost.getDomainId().equals(domainId)) {
hostsToRelease.add(dHost);
}
}
}
}
for (final DedicatedResourceVO dr : hostsToRelease) {
releaseDedicatedResource(null, null, null, dr.getHostId());
}
}
checkHostsSuitabilityForExplicitDedication(accountId, childDomainIds, hosts);
final Long accountIdFinal = accountId;
return Transaction.execute(new TransactionCallback<List<DedicatedResourceVO>>() {
@Override
public List<DedicatedResourceVO> doInTransaction(final TransactionStatus status) {
// find or create the affinity group by name under this account/domain
final AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal);
if (group == null) {
s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group");
throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support.");
}
DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, null, clusterId, null, null, null, group.getId());
try {
dedicatedResource.setDomainId(domainId);
if (accountIdFinal != null) {
dedicatedResource.setAccountId(accountIdFinal);
}
dedicatedResource = _dedicatedDao.persist(dedicatedResource);
} catch (final Exception e) {
s_logger.error("Unable to dedicate host due to " + e.getMessage(), e);
throw new CloudRuntimeException("Failed to dedicate cluster. Please contact Cloud Support.");
}
final List<DedicatedResourceVO> result = new ArrayList<>();
result.add(dedicatedResource);
return result;
}
});
}
use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.
the class DedicatedResourceManagerImpl method createDedicateClusterResponse.
@Override
public DedicateClusterResponse createDedicateClusterResponse(final DedicatedResources resource) {
final DedicateClusterResponse dedicateClusterResponse = new DedicateClusterResponse();
final ClusterVO cluster = _clusterDao.findById(resource.getClusterId());
final DomainVO domain = _domainDao.findById(resource.getDomainId());
final AccountVO account = _accountDao.findById(resource.getAccountId());
final AffinityGroup group = _affinityGroupDao.findById(resource.getAffinityGroupId());
dedicateClusterResponse.setId(resource.getUuid());
dedicateClusterResponse.setClusterId(cluster.getUuid());
dedicateClusterResponse.setClusterName(cluster.getName());
dedicateClusterResponse.setDomainId(domain.getUuid());
dedicateClusterResponse.setDomainName(domain.getName());
dedicateClusterResponse.setAffinityGroupId(group.getUuid());
if (account != null) {
dedicateClusterResponse.setAccountId(account.getUuid());
dedicateClusterResponse.setAccountName(account.getAccountName());
}
dedicateClusterResponse.setObjectName("dedicatedcluster");
return dedicateClusterResponse;
}
use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.
the class DedicatedResourceManagerImpl method dedicatePod.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_DEDICATE_RESOURCE, eventDescription = "dedicating a Pod")
public List<DedicatedResourceVO> dedicatePod(final Long podId, final Long domainId, final String accountName) {
Long accountId = null;
if (accountName != null) {
final Account caller = CallContext.current().getCallingAccount();
final Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId, null);
accountId = owner.getId();
}
final List<Long> childDomainIds = getDomainChildIds(domainId);
childDomainIds.add(domainId);
checkAccountAndDomain(accountId, domainId);
final HostPodVO pod = _podDao.findById(podId);
List<HostVO> hosts = null;
if (pod == null) {
throw new InvalidParameterValueException("Unable to find pod by id " + podId);
} else {
final DedicatedResourceVO dedicatedPod = _dedicatedDao.findByPodId(podId);
final DedicatedResourceVO dedicatedZoneOfPod = _dedicatedDao.findByZoneId(pod.getDataCenterId());
// check if pod is dedicated
if (dedicatedPod != null) {
s_logger.error("Pod " + pod.getName() + " is already dedicated");
throw new CloudRuntimeException("Pod " + pod.getName() + " is already dedicated");
}
if (dedicatedZoneOfPod != null) {
final boolean domainIdInChildreanList = getDomainChildIds(dedicatedZoneOfPod.getDomainId()).contains(domainId);
// can dedicate a pod to an account/domain if zone is dedicated to parent-domain
if (dedicatedZoneOfPod.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfPod.getDomainId().equals(domainId) || domainIdInChildreanList))) {
final Zone zone = zoneRepository.findOne(pod.getDataCenterId());
s_logger.error("Cannot dedicate Pod. Its zone is already dedicated");
throw new CloudRuntimeException("Pod's Zone " + zone.getName() + " is already dedicated");
}
}
// check if any resource under this pod is dedicated to different account or sub-domain
final List<ClusterVO> clusters = _clusterDao.listByPodId(pod.getId());
final List<DedicatedResourceVO> clustersToRelease = new ArrayList<>();
final List<DedicatedResourceVO> hostsToRelease = new ArrayList<>();
for (final ClusterVO cluster : clusters) {
final DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
if (dCluster != null) {
if (!(childDomainIds.contains(dCluster.getDomainId()))) {
throw new CloudRuntimeException("Cluster " + cluster.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain");
}
/*if all dedicated resources belongs to same account and domain then we should release dedication
and make new entry for this Pod*/
if (accountId != null) {
if (dCluster.getAccountId().equals(accountId)) {
clustersToRelease.add(dCluster);
} else {
s_logger.error("Cluster " + cluster.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain");
throw new CloudRuntimeException("Cluster " + cluster.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain");
}
} else {
if (dCluster.getAccountId() == null && dCluster.getDomainId().equals(domainId)) {
clustersToRelease.add(dCluster);
}
}
}
}
for (final DedicatedResourceVO dr : clustersToRelease) {
releaseDedicatedResource(null, null, dr.getClusterId(), null);
}
hosts = _hostDao.findByPodId(pod.getId());
for (final HostVO host : hosts) {
final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
if (dHost != null) {
if (!(getDomainChildIds(domainId).contains(dHost.getDomainId()))) {
throw new CloudRuntimeException("Host " + host.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain");
}
if (accountId != null) {
if (dHost.getAccountId().equals(accountId)) {
hostsToRelease.add(dHost);
} else {
s_logger.error("Host " + host.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain");
throw new CloudRuntimeException("Host " + host.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain");
}
} else {
if (dHost.getAccountId() == null && dHost.getDomainId().equals(domainId)) {
hostsToRelease.add(dHost);
}
}
}
}
for (final DedicatedResourceVO dr : hostsToRelease) {
releaseDedicatedResource(null, null, null, dr.getHostId());
}
}
checkHostsSuitabilityForExplicitDedication(accountId, childDomainIds, hosts);
final Long accountIdFinal = accountId;
return Transaction.execute(new TransactionCallback<List<DedicatedResourceVO>>() {
@Override
public List<DedicatedResourceVO> doInTransaction(final TransactionStatus status) {
// find or create the affinity group by name under this account/domain
final AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal);
if (group == null) {
s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group");
throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support.");
}
DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, podId, null, null, null, null, group.getId());
try {
dedicatedResource.setDomainId(domainId);
if (accountIdFinal != null) {
dedicatedResource.setAccountId(accountIdFinal);
}
dedicatedResource = _dedicatedDao.persist(dedicatedResource);
} catch (final Exception e) {
s_logger.error("Unable to dedicate pod due to " + e.getMessage(), e);
throw new CloudRuntimeException("Failed to dedicate pod. Please contact Cloud Support.");
}
final List<DedicatedResourceVO> result = new ArrayList<>();
result.add(dedicatedResource);
return result;
}
});
}
Aggregations