use of com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method removeHostFromVcenterCluster.
/**
* This will attempt to remove host from vCenter cluster.
*
* @param hostId
* @param stepId
*/
public void removeHostFromVcenterCluster(URI hostId, String stepId) {
log.info("removeHostFromVcenterCluster {}", hostId);
Host host = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
host = _dbClient.queryObject(Host.class, hostId);
if (NullColumnValueGetter.isNullURI(host.getVcenterDataCenter())) {
log.info("datacenter is null, nothing to do");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
if (NullColumnValueGetter.isNullURI(host.getCluster())) {
log.warn("cluster is null, nothing to do");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_068);
String taskId = stepId;
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.UPDATE_VCENTER_CLUSTER);
_dbClient.createTaskOpStatus(VcenterDataCenter.class, host.getVcenterDataCenter(), taskId, op);
AsyncTask task = new AsyncTask(VcenterDataCenter.class, host.getVcenterDataCenter(), taskId);
final String workflowKey = "updateVcenterCluster";
if (!WorkflowService.getInstance().hasWorkflowBeenCreated(taskId, workflowKey)) {
vcenterController.updateVcenterCluster(task, host.getCluster(), null, new URI[] { host.getId() }, null);
// Mark this workflow as created/executed so we don't do it
// again on retry/resume
WorkflowService.getInstance().markWorkflowBeenCreated(taskId, workflowKey);
}
} catch (VcenterControllerException e) {
log.warn("VcenterControllerException when trying to removeHostFromVcenterCluster: " + e.getMessage(), e);
if (e.getCause() instanceof VcenterObjectNotFoundException) {
log.info("did not find the host, considering success");
WorkflowStepCompleter.stepSucceded(stepId);
} else if (e.getCause() instanceof VcenterObjectConnectionException) {
log.info("host is not connected, considering success");
WorkflowStepCompleter.stepSucceded(stepId);
} else {
log.error("failure " + e);
WorkflowStepCompleter.stepFailed(stepId, e);
}
} catch (InternalException e) {
log.error("InternalException when trying to removeHostFromVcenterCluster: " + e.getMessage(), e);
WorkflowStepCompleter.stepFailed(stepId, e);
} catch (Exception e) {
log.error("unexpected exception: " + e.getMessage(), e);
ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToRemoveHostVcenterCluster(host != null ? host.getHostName() : hostId.toString(), e);
WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
}
}
use of com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException 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.vcentercontroller.exceptions.VcenterControllerException in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method putHostInMaintenanceMode.
/**
* This will attempt to put host into maintenance mode on a Vcenter.
*
* @param hostId
* @param stepId
*/
public void putHostInMaintenanceMode(URI hostId, String stepId) {
log.info("putHostInMaintenanceMode {}", hostId);
Host host = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
host = _dbClient.queryObject(Host.class, hostId);
if (NullColumnValueGetter.isNullURI(host.getVcenterDataCenter())) {
log.info("datacenter is null, nothing to do");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
if (NullColumnValueGetter.isNullURI(host.getCluster())) {
log.warn("cluster is null, nothing to do");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
vcenterController.enterMaintenanceMode(host.getVcenterDataCenter(), host.getCluster(), host.getId());
WorkflowStepCompleter.stepSucceded(stepId);
} catch (VcenterControllerException e) {
log.warn("VcenterControllerException when trying to putHostInMaintenanceMode: " + e.getMessage(), e);
if (e.getCause() instanceof VcenterObjectNotFoundException) {
if (checkPreviouslyFailedDecommission(host)) {
log.info("did not find the host, considering success based on previous delete host operation");
WorkflowStepCompleter.stepSucceded(stepId);
} else {
log.info("did not find the host, considering failure as no previous delete host operation found");
WorkflowStepCompleter.stepFailed(stepId, e);
}
} else if (e.getCause() instanceof VcenterObjectConnectionException) {
if (checkPreviouslyFailedDecommission(host)) {
log.info("host is not connected, considering success based on previous delete host operation");
WorkflowStepCompleter.stepSucceded(stepId);
} else {
log.info("host is not connected, considering failure as no previous delete host operation found");
WorkflowStepCompleter.stepFailed(stepId, e);
}
} else {
log.error("failure " + e);
WorkflowStepCompleter.stepFailed(stepId, e);
}
} catch (InternalException e) {
log.error("InternalException when trying to putHostInMaintenanceMode: " + e.getMessage(), e);
WorkflowStepCompleter.stepFailed(stepId, e);
} catch (Exception e) {
log.error("unexpected exception" + e.getMessage(), e);
ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToPutHostInMaintenanceMode(host != null ? host.getHostName() : hostId.toString(), e);
WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
}
}
use of com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException 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