use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method deleteBlockBootVolume.
/**
* Deactivates or deletes the boot volume
*
* @param hostId
* {@link URI} hostId URI
* @param volumeDescriptors
* {@link List<VolumeDescriptor>} list of boot volumes to delete
* @param stepId
* {@link String} step id
*/
public void deleteBlockBootVolume(URI hostId, List<VolumeDescriptor> volumeDescriptors, String stepId) {
log.info("deleteBlockBootVolume");
Host host = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
host = _dbClient.queryObject(Host.class, hostId);
if (host == null) {
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
String task = stepId;
URI bootVolumeId = getBootVolumeIdFromDescriptors(volumeDescriptors, host);
Volume bootVolume = _dbClient.queryObject(Volume.class, bootVolumeId);
if (bootVolume == null) {
// No boot volume found, so it was already deleted.
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
Operation op = _dbClient.createTaskOpStatus(Volume.class, bootVolume.getId(), task, ResourceOperationTypeEnum.DELETE_BLOCK_VOLUME);
bootVolume.getOpStatus().put(task, op);
_dbClient.updateObject(bootVolume);
final String workflowKey = "deleteVolumes";
if (!WorkflowService.getInstance().hasWorkflowBeenCreated(task, workflowKey)) {
blockOrchestrationController.deleteVolumes(volumeDescriptors, task);
// Mark this workflow as created/executed so we don't do it
// again on retry/resume
WorkflowService.getInstance().markWorkflowBeenCreated(task, workflowKey);
}
} catch (Exception exception) {
ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToDeactivateHost(host != null ? host.getHostName() : hostId.toString(), exception);
WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method deactivateComputeSystemHost.
/**
* Deactivate compute system host
*
* @param csId
* {@link URI} compute system URI
* @param hostId
* {@link URI} host URI
* @param stepId
* step id
*/
public void deactivateComputeSystemHost(URI csId, URI hostId, String stepId) {
log.info("deactivateComputeSystemHost");
Host host = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, csId);
host = _dbClient.queryObject(Host.class, hostId);
if (null != host) {
// Added check before we get here
if (NullColumnValueGetter.isNullURI(host.getComputeElement()) && NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
// NO-OP
log.info("Host " + host.getLabel() + " has no computeElement association and no service profile association");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
getDevice(cs.getSystemType()).deactivateHost(cs, host);
} else {
throw new RuntimeException("Host null for uri " + hostId);
}
} catch (Exception exception) {
log.error("Error on deactivate ComputeSystemHost with hostid {} and computementid {}", hostId, csId, exception);
ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToDeactivateHost(host != null ? host.getHostName() : hostId.toString(), exception);
WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
return;
}
WorkflowStepCompleter.stepSucceded(stepId);
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method rebindHostToTemplateStep.
/**
* Bind host to a service profile template step
*
* @param computeSystemId
* {@link URI} computeSystem URI
* @param hostId
* {@link URI} host URI
* @param stepId
* {@link String} step id
*/
public void rebindHostToTemplateStep(URI computeSystemId, URI hostId, String stepId) {
log.info("rebindHostToTemplateStep");
ComputeSystem computeSystem = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
computeSystem = _dbClient.queryObject(ComputeSystem.class, hostId);
rebindHostToTemplate(computeSystemId, hostId);
// TODO COP-28961 process the return value, and mark step as failed in case of error
WorkflowStepCompleter.stepSucceded(stepId);
} catch (InternalException e) {
String opName = ResourceOperationTypeEnum.INSTALL_OPERATING_SYSTEM.getName();
ServiceCoded sce = ImageServerControllerException.exceptions.unexpectedException(opName, e);
if (computeSystem != null) {
sce = ComputeSystemControllerException.exceptions.unableToUpdateHostAfterOSInstall(hostId.toString(), e);
}
log.error("Exception rebindHostToTemplateStep: " + e.getMessage(), e);
WorkflowStepCompleter.stepFailed(stepId, sce);
} catch (Exception e) {
String opName = ResourceOperationTypeEnum.INSTALL_OPERATING_SYSTEM.getName();
ImageServerControllerException controllerException = ImageServerControllerException.exceptions.unexpectedException(opName, e);
log.error("Unexpected exception rebindHostToTemplateStep: " + e.getMessage(), e);
WorkflowStepCompleter.stepFailed(stepId, controllerException);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionManager method relinkTargetVolumesToSnapshotSession.
/**
* Implements a request to relink the passed targets from the
* BlockSnapshotSession instance with the passed URI.
*
* @param snapSessionURI The URI of a BlockSnapshotSession instance.
* @param param The linked target information.
*
* @return A TaskList.
*/
public TaskList relinkTargetVolumesToSnapshotSession(URI snapSessionURI, SnapshotSessionRelinkTargetsParam param) {
s_logger.info("START relink targets to snapshot session {}", snapSessionURI);
// Get the snapshot session.
BlockSnapshotSession snapSession = BlockSnapshotSessionUtils.querySnapshotSession(snapSessionURI, _uriInfo, _dbClient, true);
BlockObject snapSessionSourceObj = null;
List<BlockObject> snapSessionSourceObjs = getAllSnapshotSessionSources(snapSession);
snapSessionSourceObj = snapSessionSourceObjs.get(0);
// Get the project for the snapshot session source object.
Project project = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(snapSessionSourceObj, _dbClient);
// Get the platform specific block snapshot session implementation.
BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(snapSessionSourceObj);
// Get the target information.
List<URI> linkedTargetURIs = param.getLinkedTargetIds();
// Validate that the requested targets can be re-linked to the snapshot session.
snapSessionApiImpl.validateRelinkSnapshotSessionTargets(snapSessionSourceObj, snapSession, project, linkedTargetURIs, _uriInfo);
// Create a unique task identifier.
String taskId = UUID.randomUUID().toString();
// Create a task for the snapshot session.
Operation op = new Operation();
op.setResourceType(getRelinkResourceOperationTypeEnum(snapSession));
_dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
snapSession.getOpStatus().put(taskId, op);
TaskResourceRep response = toTask(snapSession, taskId);
TaskList taskList = new TaskList();
taskList.addTask(response);
// Re-link the targets to the snapshot session.
try {
snapSessionApiImpl.relinkTargetVolumesToSnapshotSession(snapSessionSourceObj, snapSession, linkedTargetURIs, taskId);
} catch (Exception e) {
String errorMsg = format("Failed to relink targets to snapshot session %s: %s", snapSessionURI, e.getMessage());
ServiceCoded sc = null;
if (e instanceof ServiceCoded) {
sc = (ServiceCoded) e;
} else {
sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
}
cleanupFailure(Arrays.asList(response), new ArrayList<DataObject>(), errorMsg, taskId, sc);
throw e;
}
// Create the audit log entry.
auditOp(OperationTypeEnum.RELINK_SNAPSHOT_SESSION_TARGET, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObj.getId().toString(), snapSessionSourceObj.getStorageController().toString());
s_logger.info("FINISH relink targets to snapshot session {}", snapSessionURI);
return taskList;
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionManager method unlinkTargetVolumesFromSnapshotSession.
/**
* Implements a request to unlink the passed targets from the
* BlockSnapshotSession instance with the passed URI.
*
* @param snapSessionURI The URI of a BlockSnapshotSession instance.
* @param param The linked target information.
* @param opType The operation type for the audit and event logs.
*
* @return A TaskResourceRep.
*/
public TaskResourceRep unlinkTargetVolumesFromSnapshotSession(URI snapSessionURI, SnapshotSessionUnlinkTargetsParam param, OperationTypeEnum opType) {
s_logger.info("START unlink targets from snapshot session {}", snapSessionURI);
// Get the snapshot session.
BlockSnapshotSession snapSession = BlockSnapshotSessionUtils.querySnapshotSession(snapSessionURI, _uriInfo, _dbClient, true);
BlockObject snapSessionSourceObj = null;
List<BlockObject> snapSessionSourceObjs = getAllSnapshotSessionSources(snapSession);
snapSessionSourceObj = snapSessionSourceObjs.get(0);
// Get the project for the snapshot session source object.
Project project = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(snapSessionSourceObj, _dbClient);
BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(snapSessionSourceObj);
// Get the target information.
Map<URI, Boolean> targetMap = new HashMap<>();
for (SnapshotSessionUnlinkTargetParam targetInfo : param.getLinkedTargets()) {
URI targetURI = targetInfo.getId();
Boolean deleteTarget = targetInfo.getDeleteTarget();
if (deleteTarget == null) {
deleteTarget = Boolean.FALSE;
}
targetMap.put(targetURI, deleteTarget);
}
// Validate that the requested targets can be unlinked from the snapshot session.
snapSessionApiImpl.validateUnlinkSnapshotSessionTargets(snapSession, snapSessionSourceObj, project, targetMap, _uriInfo);
// Create a unique task identifier.
String taskId = UUID.randomUUID().toString();
// Create a task for the snapshot session.
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.UNLINK_SNAPSHOT_SESSION_TARGETS);
_dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
snapSession.getOpStatus().put(taskId, op);
TaskResourceRep response = toTask(snapSession, taskId);
// Unlink the targets from the snapshot session.
try {
snapSessionApiImpl.unlinkTargetVolumesFromSnapshotSession(snapSessionSourceObj, snapSession, targetMap, opType, taskId);
} catch (Exception e) {
String errorMsg = format("Failed to unlink targets from snapshot session %s: %s", snapSessionURI, e.getMessage());
ServiceCoded sc = null;
if (e instanceof ServiceCoded) {
sc = (ServiceCoded) e;
} else {
sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
}
cleanupFailure(Arrays.asList(response), new ArrayList<DataObject>(), errorMsg, taskId, sc);
throw e;
}
// Create the audit log entry.
auditOp(opType, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObj.getId().toString(), snapSessionSourceObj.getStorageController().toString());
s_logger.info("FINISH unlink targets from snapshot session {}", snapSessionURI);
return response;
}
Aggregations