use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method vcenterClusterAddHostOperation.
public void vcenterClusterAddHostOperation(URI vcenterId, URI vcenterDataCenterId, URI clusterId, URI hostId, String stepId) {
VcenterApiClient vcenterApiClient = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDataCenterId);
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterId);
Host host = _dbClient.queryObject(Host.class, hostId);
vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
String key = vcenterApiClient.addHost(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName(), host.getUsername(), host.getPassword());
_log.info("Successfully added or located host " + host.getHostName() + " " + key);
host.setVcenterDataCenter(vcenterDataCenter.getId());
_dbClient.updateAndReindexObject(host);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception e) {
_log.error("vcenterClusterAddHostOperation exception " + e);
WorkflowStepCompleter.stepFailed(stepId, VcenterControllerException.exceptions.hostException(e.getLocalizedMessage(), e));
} finally {
if (vcenterApiClient != null) {
vcenterApiClient.destroy();
}
}
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method vcenterClusterCreateDatastoreOperation.
public void vcenterClusterCreateDatastoreOperation(URI vcenterId, URI vcenterDataCenterId, URI clusterId, URI volumeId, String selectHostStepId, String stepId) {
VcenterApiClient vcenterApiClient = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
URI hostId = (URI) _workflowService.loadStepData(selectHostStepId);
if (hostId == null) {
_log.error("Workflow loadStepData on " + selectHostStepId + " is null");
throw new Exception("Workflow loadStepData on " + selectHostStepId + " is null");
}
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDataCenterId);
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterId);
Host host = _dbClient.queryObject(Host.class, hostId);
Volume volume = _dbClient.queryObject(Volume.class, volumeId);
vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
String key = vcenterApiClient.createDatastore(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName(), volume.getWWN(), volume.getLabel());
_log.info("Successfully created or located datastore " + volume.getLabel() + " " + key);
host.setVcenterDataCenter(vcenterDataCenter.getId());
_dbClient.updateAndReindexObject(host);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception e) {
_log.error("vcenterClusterCreateDatastoreOperation exception " + e);
WorkflowStepCompleter.stepFailed(stepId, VcenterControllerException.exceptions.hostException(e.getLocalizedMessage(), e));
} finally {
if (vcenterApiClient != null) {
vcenterApiClient.destroy();
}
}
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method removeVcenterCluster.
/**
* Remove cluster from vCenter.
*
* @param clusterId
* @param datacenterId
* @param stepId
*/
public void removeVcenterCluster(URI clusterId, URI datacenterId, String stepId) {
log.info("removeVcenterCluster {} {}", clusterId, datacenterId);
Cluster cluster = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
cluster = _dbClient.queryObject(Cluster.class, clusterId);
vcenterController.removeVcenterCluster(datacenterId, clusterId);
log.info("Remove vCenter cluster success");
WorkflowStepCompleter.stepSucceded(stepId);
} catch (VcenterControllerException e) {
log.warn("VcenterControllerException when trying to removeVcenterCluster: " + e.getMessage(), e);
if (e.getCause() instanceof VcenterObjectNotFoundException) {
log.info("did not find the datacenter or cluster, considering success");
WorkflowStepCompleter.stepSucceded(stepId);
} else {
log.error("failure " + e);
WorkflowStepCompleter.stepFailed(stepId, e);
}
} catch (InternalException e) {
log.error("InternalException when trying to removeVcenterCluster: " + e.getMessage(), e);
WorkflowStepCompleter.stepFailed(stepId, e);
} catch (Exception e) {
log.error("unexpected exception " + e);
ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToRemoveVcenterCluster(cluster != null ? cluster.getLabel() : clusterId.toString(), e);
WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
}
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method addStepsVcenterClusterCleanup.
/**
* A cluster could have only discovered hosts, only provisioned hosts, or mixed.
* If cluster has only provisioned hosts, then the hosts will be deleted from vCenter.
* If cluster has only discovered hosts, then the hosts will not be deleted from vCenter.
* If cluster is mixed, then the hosts will not be deleted from the vCenter; however, the
* provisioned hosts will still be decommissioned, and their state in vCenter will be "disconnected".
* If a cluster is provisioned or mixed, then check VMs step will be executed since hosts with running
* VMs may endup decommissioned.
*/
@Override
public String addStepsVcenterClusterCleanup(Workflow workflow, String waitFor, URI clusterId, boolean deactivateCluster) throws InternalException {
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
if (null == cluster) {
log.info("Could not find cluster instance for cluster having id {}", clusterId.toString());
return waitFor;
}
if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
log.info("cluster is not synced to vcenter");
return waitFor;
}
List<URI> clusterHosts = ComputeSystemHelper.getChildrenUris(_dbClient, clusterId, Host.class, "cluster");
// Before we get to this cluster removal, ClusterService has a precheck to verify the matching environments
if (deactivateCluster && (null == clusterHosts || clusterHosts.isEmpty())) {
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, cluster.getVcenterDataCenter());
log.info("Cluster has no hosts, removing empty cluster : {}, from vCenter : {}", cluster.getLabel(), vcenterDataCenter.getLabel());
waitFor = workflow.createStep(REMOVE_VCENTER_CLUSTER, "If synced with vCenter, remove the cluster", waitFor, clusterId, clusterId.toString(), this.getClass(), new Workflow.Method("removeVcenterCluster", cluster.getId(), cluster.getVcenterDataCenter()), null, null);
return waitFor;
}
boolean hasDiscoveredHosts = false;
boolean hasProvisionedHosts = false;
List<Host> hosts = _dbClient.queryObject(Host.class, clusterHosts);
for (Host host : hosts) {
if (NullColumnValueGetter.isNullURI(host.getComputeElement())) {
hasDiscoveredHosts = true;
} else {
hasProvisionedHosts = true;
}
}
log.info("cluster has provisioned hosts: {}, and discovered hosts: {}", hasProvisionedHosts, hasDiscoveredHosts);
/*
* Check for VMs only if the cluster was provisioned or is mixed.
*/
if (hasProvisionedHosts) {
waitFor = workflow.createStep(CHECK_CLUSTER_VMS, "If synced with vCenter, check if there are VMs in the cluster", waitFor, clusterId, clusterId.toString(), this.getClass(), new Workflow.Method("checkClusterVms", cluster.getId(), cluster.getVcenterDataCenter()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
}
/*
* Remove cluster from vcenter only if all hosts are provisioned.
*/
if (hasProvisionedHosts && !hasDiscoveredHosts && deactivateCluster) {
waitFor = workflow.createStep(REMOVE_VCENTER_CLUSTER, "If synced with vCenter, remove the cluster", waitFor, clusterId, clusterId.toString(), this.getClass(), new Workflow.Method("removeVcenterCluster", cluster.getId(), cluster.getVcenterDataCenter()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
}
return waitFor;
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method checkClusterVms.
/**
* Checks if the cluster in Vcenter has VMs. Exception is thrown if VMs are
* present.
*
* @param clusterId
* @param datacenterId
* @param stepId
*/
// TODO COP-28962 verify whether this really throws an exception
// seems like we throw an exception, and catch it again, and throw another exception
// logic is somewhat difficult to understand
public void checkClusterVms(URI clusterId, URI datacenterId, String stepId) {
log.info("checkClusterVms {} {}", clusterId, datacenterId);
Cluster cluster = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
cluster = _dbClient.queryObject(Cluster.class, clusterId);
List<String> vmList = vcenterController.getVirtualMachines(datacenterId, clusterId);
if (!vmList.isEmpty()) {
log.error("there are {} VMs in the cluster", vmList.size());
throw ComputeSystemControllerException.exceptions.clusterHasVms(cluster != null ? cluster.getLabel() : clusterId.toString());
} else {
log.info("there are no VMs in the cluster, step successful");
}
WorkflowStepCompleter.stepSucceded(stepId);
} catch (VcenterControllerException e) {
log.warn("VcenterControllerException when trying to checkClusterVms: " + e.getMessage(), e);
if (e.getCause() instanceof VcenterObjectNotFoundException) {
log.info("did not find the datacenter or cluster, considering success");
WorkflowStepCompleter.stepSucceded(stepId);
} else {
log.error("failure " + e);
WorkflowStepCompleter.stepFailed(stepId, e);
}
} catch (InternalException e) {
log.error("InternalException when trying to checkClusterVms: " + e.getMessage(), e);
WorkflowStepCompleter.stepFailed(stepId, e);
} catch (Exception e) {
log.error("unexpected exception " + e);
ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToCheckClusterVms(cluster != null ? cluster.getLabel() : clusterId.toString(), e);
WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
}
}
Aggregations