use of com.emc.storageos.vcentercontroller.VcenterClusterCompleter in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method createOrUpdateVcenterCluster.
private void createOrUpdateVcenterCluster(boolean createCluster, AsyncTask task, URI clusterUri, URI[] addHostUris, URI[] removeHostUris, URI[] volumeUris) throws InternalException {
TaskCompleter completer = null;
try {
_log.info("createOrUpdateVcenterCluster " + createCluster + " " + task + " " + clusterUri + " " + addHostUris + " " + removeHostUris);
if (task == null) {
_log.error("AsyncTask is null");
throw new Exception("AsyncTask is null");
}
URI vcenterDataCenterId = task._id;
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDataCenterId);
if (clusterUri == null) {
_log.error("Cluster URI is null");
throw new Exception("Cluster URI is null");
}
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
_log.info("Request to create or update cluster " + vcenter.getIpAddress() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel());
Collection<Host> addHosts = new ArrayList<Host>();
if (addHostUris == null || addHostUris.length == 0) {
_log.info("Add host URIs is null or empty - Cluster will be created without hosts");
} else {
for (URI hostUri : addHostUris) {
_log.info("createOrUpdateVcenterCluster " + clusterUri + " with add host " + hostUri);
}
addHosts = _dbClient.queryObject(Host.class, addHostUris);
}
Collection<Host> removeHosts = new ArrayList<Host>();
if (removeHostUris == null || removeHostUris.length == 0) {
_log.info("Remove host URIs is null or empty - Cluster will have no removed hosts");
} else {
for (URI hostUri : removeHostUris) {
_log.info("createOrUpdateVcenterCluster " + clusterUri + " with remove host " + hostUri);
}
removeHosts = _dbClient.queryObject(Host.class, removeHostUris);
}
Collection<Volume> volumes = new ArrayList<Volume>();
if (volumeUris == null || volumeUris.length == 0) {
_log.info("Volume URIs is null or empty - Cluster will be created without datastores");
} else {
for (URI volumeUri : volumeUris) {
_log.info("createOrUpdateVcenterCluster " + clusterUri + " with volume " + volumeUri);
}
volumes = _dbClient.queryObject(Volume.class, volumeUris);
}
completer = new VcenterClusterCompleter(vcenterDataCenterId, task._opId, OperationTypeEnum.CREATE_UPDATE_VCENTER_CLUSTER, "VCENTER_CONTROLLER");
Workflow workflow = _workflowService.getNewWorkflow(this, "CREATE_UPDATE_VCENTER_CLUSTER_WORKFLOW", true, task._opId);
String clusterStep = workflow.createStep("CREATE_UPDATE_VCENTER_CLUSTER_STEP", String.format("vCenter cluster operation in vCenter datacenter %s", vcenterDataCenterId), null, vcenterDataCenterId, vcenterDataCenterId.toString(), this.getClass(), new Workflow.Method("createUpdateVcenterClusterOperation", createCluster, vcenter.getId(), vcenterDataCenter.getId(), cluster.getId()), null, null);
String lastStep = clusterStep;
if (!removeHosts.isEmpty()) {
for (Host host : removeHosts) {
String hostStep = workflow.createStep("VCENTER_CLUSTER_REMOVE_HOST", String.format("vCenter cluster remove host operation %s", host.getId()), clusterStep, vcenterDataCenterId, vcenterDataCenterId.toString(), this.getClass(), new Workflow.Method("vcenterClusterRemoveHostOperation", vcenter.getId(), vcenterDataCenter.getId(), cluster.getId(), host.getId()), null, null);
// add host will wait on last of these
lastStep = hostStep;
}
}
if (!addHosts.isEmpty()) {
for (Host host : addHosts) {
String hostStep = workflow.createStep("VCENTER_CLUSTER_ADD_HOST", String.format("vCenter cluster add host operation %s", host.getId()), lastStep, vcenterDataCenterId, vcenterDataCenterId.toString(), this.getClass(), new Workflow.Method("vcenterClusterAddHostOperation", vcenter.getId(), vcenterDataCenter.getId(), cluster.getId(), host.getId()), null, null);
}
}
workflow.executePlan(completer, "Success");
} catch (Exception e) {
_log.error("createOrUpdateVcenterCluster caught an exception.", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
completer.error(_dbClient, serviceError);
}
}
Aggregations