use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded 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);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method untagBlockBootVolume.
/**
* Untags the boot volume before it is deleted.
*
* @param hostId
* {@link URI} hostId URI
* @param volumeDescriptors
* {@link List<VolumeDescriptor>} list of boot volumes to untag
* @param stepId
* {@link String} step id
*/
public void untagBlockBootVolume(URI hostId, List<VolumeDescriptor> volumeDescriptors, String stepId) {
log.info("untagBlockBootVolume START");
Host host = null;
Volume bootVolume = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
host = _dbClient.queryObject(Host.class, hostId);
if (host == null || NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
WorkflowStepCompleter.stepSucceded(stepId);
log.info("untagBlockBootVolume END");
return;
}
URI bootVolumeId = getBootVolumeIdFromDescriptors(volumeDescriptors, host);
bootVolume = _dbClient.queryObject(Volume.class, bootVolumeId);
if (bootVolume == null || (bootVolume.getTag() == null)) {
WorkflowStepCompleter.stepSucceded(stepId);
log.info("untagBlockBootVolume END");
return;
}
// Untag volume. Slightly unconventional way of doing it, however our scope and label
// both contain colons and equal signs making the ScopedLabel constructor and ScopedLabelSet.contains()
// difficult to trust.
String tagLabel = TagUtils.getBootVolumeTagName() + "=" + host.getId().toASCIIString();
ScopedLabel foundSL = null;
for (ScopedLabel sl : bootVolume.getTag()) {
if (sl.getLabel().contains(tagLabel)) {
foundSL = sl;
break;
}
}
if (foundSL != null) {
bootVolume.getTag().remove(foundSL);
}
// If we are deleting a boot volume, there may still be a reference to the volume
// in the decommissioned host. We will clear out this reference in the host.
host.setBootVolumeId(NullColumnValueGetter.getNullURI());
_dbClient.updateObject(host);
_dbClient.updateObject(bootVolume);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception exception) {
ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToUntagVolume(bootVolume != null ? bootVolume.forDisplay() : "none found", host != null ? host.getHostName() : hostId.toString(), exception);
WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
}
log.info("untagBlockBootVolume END");
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method validateBootVolumeExport.
public void validateBootVolumeExport(URI hostId, URI volumeId, String stepId) throws ControllerException {
_log.info("validateBootVolumeExport :" + hostId.toString() + " volume: " + volumeId.toString());
Host host = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
host = _dbClient.queryObject(Host.class, hostId);
if (host == null) {
throw ComputeSystemControllerException.exceptions.hostNotFound(hostId.toString());
}
Volume volume = _dbClient.queryObject(Volume.class, volumeId);
if (volume == null) {
throw ComputeSystemControllerException.exceptions.volumeNotFound(volumeId.toString());
}
boolean validExport = computeDeviceController.validateBootVolumeExport(hostId, volumeId);
if (validExport) {
WorkflowStepCompleter.stepSucceded(stepId);
} else {
ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.invalidBootVolumeExport(host.getLabel(), volume.getLabel());
WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
}
} catch (Exception e) {
_log.error("unexpected exception: " + e.getMessage(), e);
String hostString = hostId.toString();
if (host != null) {
hostString = host.getHostName();
}
ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToValidateBootVolumeExport(hostString, volumeId.toString(), e);
WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method setHostSanBootTargets.
public void setHostSanBootTargets(URI hostId, URI volumeId, String stepId) throws ControllerException {
Host host = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
host = _dbClient.queryObject(Host.class, hostId);
if (host == null) {
throw ComputeSystemControllerException.exceptions.hostNotFound(hostId.toString());
}
if (host.getComputeElement() != null) {
ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
if (computeElement != null) {
computeDeviceController.setSanBootTarget(computeElement.getComputeSystem(), computeElement.getId(), hostId, volumeId, false);
} else {
_log.error("Invalid compute element association");
throw ComputeSystemControllerException.exceptions.cannotSetSanBootTargets(host.getHostName(), "Invalid compute elemnt association");
}
} else {
_log.error("Host " + host.getHostName() + " does not have a compute element association.");
throw ComputeSystemControllerException.exceptions.cannotSetSanBootTargets(host.getHostName(), "Host does not have a blade association");
}
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception e) {
_log.error("unexpected exception: " + e.getMessage(), e);
String hostString = hostId.toString();
if (host != null) {
hostString = host.getHostName();
}
ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToSetSanBootTargets(hostString, e);
WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class VPlexBlockServiceApiImpl method deactivateMirror.
/**
* {@inheritDoc}
*/
@Override
public TaskList deactivateMirror(StorageSystem vplexStorageSystem, URI mirrorURI, String taskId, String deleteType) {
TaskList taskList = new TaskList();
try {
VplexMirror mirror = _dbClient.queryObject(VplexMirror.class, mirrorURI);
Volume sourceVolume = _dbClient.queryObject(Volume.class, mirror.getSource().getURI());
Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, mirror.getId().toString());
taskList.getTaskList().add(toTask(sourceVolume, Arrays.asList(mirror), taskId, op));
if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType)) {
s_logger.info("Perform ViPR-only delete for VPLEX mirrors %s", mirrorURI);
// Perform any database cleanup that is required.
cleanupForViPROnlyMirrorDelete(Arrays.asList(mirrorURI));
// Mark them inactive.
_dbClient.markForDeletion(_dbClient.queryObject(VplexMirror.class, mirrorURI));
// We must get the volume from the DB again, to properly update the status.
sourceVolume = _dbClient.queryObject(Volume.class, mirror.getSource().getURI());
op = sourceVolume.getOpStatus().get(taskId);
op.ready("VPLEX continuous copy succesfully deleted from ViPR");
sourceVolume.getOpStatus().updateTaskStatus(taskId, op);
_dbClient.updateObject(sourceVolume);
} else {
List<VolumeDescriptor> descriptors = new ArrayList<VolumeDescriptor>();
// Add a descriptor for each of the associated volumes.There will be only one associated volume
if (mirror.getAssociatedVolumes() != null) {
for (String assocVolId : mirror.getAssociatedVolumes()) {
Volume assocVolume = _dbClient.queryObject(Volume.class, URI.create(assocVolId));
if (assocVolume != null && !assocVolume.getInactive() && assocVolume.getNativeId() != null) {
// In order to add descriptor for the the backend volumes that needs to be
// deleted we are checking for volume nativeId as well, because its possible
// that we were not able to create backend volume due to SMIS communication
// and rollback didn't clean up VplexMirror and its associated volumes in
// database. So in such a case nativeId will be null and we just want to skip
// sending this volume to SMIS, else it fails with null reference when user
// attempts to cleanup this failed mirror.
VolumeDescriptor assocDesc = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, assocVolume.getStorageController(), assocVolume.getId(), null, null);
descriptors.add(assocDesc);
}
}
}
VPlexController controller = getController();
controller.deactivateMirror(vplexStorageSystem.getId(), mirror.getId(), descriptors, taskId);
}
} catch (ControllerException e) {
String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirrorURI.toString(), e.getMessage());
s_logger.error(errorMsg, e);
for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(errorMsg);
_dbClient.error(Volume.class, taskResourceRep.getResource().getId(), taskId, e);
}
} catch (Exception e) {
String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirrorURI.toString(), e.getMessage());
s_logger.error(errorMsg, e);
ServiceCoded sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(sc.getMessage());
_dbClient.error(Volume.class, taskResourceRep.getResource().getId(), taskId, sc);
}
}
return taskList;
}
Aggregations