Search in sources :

Example 11 with ServiceCoded

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);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Example 12 with 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);
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Host(com.emc.storageos.db.client.model.Host) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Example 13 with ServiceCoded

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);
    }
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 14 with ServiceCoded

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;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 15 with ServiceCoded

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;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) SnapshotSessionUnlinkTargetParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Aggregations

ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)94 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)48 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)44 URI (java.net.URI)41 Volume (com.emc.storageos.db.client.model.Volume)31 ControllerException (com.emc.storageos.volumecontroller.ControllerException)27 NamedURI (com.emc.storageos.db.client.model.NamedURI)26 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)22 WorkflowException (com.emc.storageos.workflow.WorkflowException)22 ArrayList (java.util.ArrayList)22 BlockObject (com.emc.storageos.db.client.model.BlockObject)18 Operation (com.emc.storageos.db.client.model.Operation)17 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)17 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)16 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)15 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)14 HashMap (java.util.HashMap)14 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)13 URISyntaxException (java.net.URISyntaxException)13 Host (com.emc.storageos.db.client.model.Host)12