Search in sources :

Example 6 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.

the class BlockSnapshotService method deactivateSnapshot.

/**
 * Deactivate volume snapshot, will result in permanent deletion of the requested snapshot from the storage system it was created on
 * and will move the snapshot to a "marked-for-delete" state after the deletion happens on the array side.
 * It will be deleted by the garbage collector on a subsequent iteration
 * If this snapshot was created from a volume that is part of a consistency group,
 * then all the related snapshots will be deactivated, as well.
 *
 * If "?type=VIPR_ONLY" is added to the path, it will delete snapshot only from ViPR data base and leaves the snapshot on storage array
 * as it is.
 * Possible value for attribute type : FULL, VIPR_ONLY
 * FULL : Deletes the snapshot permanently on array and ViPR data base.
 * VIPR_ONLY : Deletes the snapshot only from ViPR data base and leaves the snapshot on array as it is.
 *
 * @prereq none
 * @param id the URN of a ViPR snapshot
 * @param type the type of deletion {@link DefaultValue} FULL
 * @brief Delete snapshot
 * @return Snapshot information
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskList deactivateSnapshot(@PathParam("id") URI id, @DefaultValue("FULL") @QueryParam("type") String type) {
    _log.info("Executing {} snapshot delete for snapshot {}", type, id);
    String opStage = null;
    boolean successStatus = true;
    String taskId = UUID.randomUUID().toString();
    TaskList response = new TaskList();
    // Get the snapshot.
    BlockSnapshot snap = (BlockSnapshot) queryResource(id);
    // We can ignore dependencies on BlockSnapshotSession. In this case
    // the BlockSnapshot instance is a linked target for a BlockSnapshotSession
    // and we will unlink the snapshot from the session and delete it.
    List<Class<? extends DataObject>> excludeTypes = new ArrayList<Class<? extends DataObject>>();
    excludeTypes.add(BlockSnapshotSession.class);
    if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(type)) {
        excludeTypes.add(ExportGroup.class);
        excludeTypes.add(ExportMask.class);
    }
    ArgValidator.checkReference(BlockSnapshot.class, id, checkForDelete(snap, excludeTypes));
    if (!VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(type)) {
        // The audit log message operation stage.
        opStage = AuditLogManager.AUDITOP_BEGIN;
        // If the BlockSnapshot instance represents a linked target, then
        // we need to unlink the target form the snapshot session and then
        // delete the target.
        URIQueryResultList snapSessionURIs = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getLinkedTargetSnapshotSessionConstraint(id), snapSessionURIs);
        Iterator<URI> snapSessionURIsIter = snapSessionURIs.iterator();
        if (snapSessionURIsIter.hasNext()) {
            _log.info("Snapshot is linked target for a snapshot session");
            SnapshotSessionUnlinkTargetsParam param = new SnapshotSessionUnlinkTargetsParam();
            List<SnapshotSessionUnlinkTargetParam> targetInfoList = new ArrayList<SnapshotSessionUnlinkTargetParam>();
            SnapshotSessionUnlinkTargetParam targetInfo = new SnapshotSessionUnlinkTargetParam(id, Boolean.TRUE);
            targetInfoList.add(targetInfo);
            param.setLinkedTargets(targetInfoList);
            response.getTaskList().add(getSnapshotSessionManager().unlinkTargetVolumesFromSnapshotSession(snapSessionURIsIter.next(), param, OperationTypeEnum.DELETE_VOLUME_SNAPSHOT));
            return response;
        }
        // Not an error if the snapshot we try to delete is already deleted
        if (snap.getInactive()) {
            _log.info("Snapshot is already inactive");
            Operation op = new Operation();
            op.ready("The snapshot has already been deleted");
            op.setResourceType(ResourceOperationTypeEnum.DELETE_VOLUME_SNAPSHOT);
            _dbClient.createTaskOpStatus(BlockSnapshot.class, snap.getId(), taskId, op);
            response.getTaskList().add(toTask(snap, taskId, op));
            return response;
        }
    }
    // Get the storage system.
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, snap.getStorageController());
    // Determine all snapshots to delete.
    List<BlockSnapshot> snapshots = new ArrayList<BlockSnapshot>();
    final URI cgId = snap.getConsistencyGroup();
    if (!NullColumnValueGetter.isNullURI(cgId) && !NullColumnValueGetter.isNullValue(snap.getReplicationGroupInstance())) {
        // Collect all the BlockSnapshots if part of a CG.
        snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snap, _dbClient);
    } else {
        // Snap is not part of a CG so only delete the snap
        snapshots.add(snap);
    }
    // Get the snapshot parent volume.
    Volume parentVolume = _permissionsHelper.getObjectById(snap.getParent(), Volume.class);
    // Check that there are no pending tasks for these snapshots.
    checkForPendingTasks(Arrays.asList(parentVolume.getTenant().getURI()), snapshots);
    // Create tasks on the volume.
    for (BlockSnapshot snapshot : snapshots) {
        Operation snapOp = _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), taskId, ResourceOperationTypeEnum.DELETE_VOLUME_SNAPSHOT);
        response.getTaskList().add(toTask(snapshot, taskId, snapOp));
    }
    // should be returned.
    try {
        BlockServiceApi blockServiceApiImpl = BlockService.getBlockServiceImpl(parentVolume, _dbClient);
        blockServiceApiImpl.deleteSnapshot(snap, snapshots, taskId, type);
    } catch (APIException | InternalException e) {
        successStatus = false;
        String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snap.getId(), e.getMessage());
        _log.error(errorMsg);
        for (TaskResourceRep taskResourceRep : response.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(errorMsg);
            _dbClient.error(BlockSnapshot.class, taskResourceRep.getResource().getId(), taskId, e);
        }
    } catch (Exception e) {
        successStatus = false;
        String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snap.getId(), e.getMessage());
        _log.error(errorMsg);
        ServiceCoded sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
        for (TaskResourceRep taskResourceRep : response.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(sc.getMessage());
            _dbClient.error(BlockSnapshot.class, taskResourceRep.getResource().getId(), taskId, sc);
        }
    }
    auditOp(OperationTypeEnum.DELETE_VOLUME_SNAPSHOT, successStatus, opStage, id.toString(), snap.getLabel(), snap.getParent().getName(), device.getId().toString());
    return response;
}
Also used : TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) SnapshotSessionUnlinkTargetsParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetsParam) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) MapBlockSnapshot(com.emc.storageos.api.mapper.functions.MapBlockSnapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DataObject(com.emc.storageos.db.client.model.DataObject) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SnapshotSessionUnlinkTargetParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.

the class CreateFileSystemSchedulingThread method run.

@Override
public void run() {
    _log.info("Starting scheduling placement thread for task {}", task);
    try {
        // Call out placementManager to get the recommendation for placement.
        List recommendations = this.fileService._filePlacementManager.getRecommendationsForFileCreateRequest(varray, project, vpool, capabilities);
        if (recommendations == null || recommendations.isEmpty()) {
            throw APIException.badRequests.noMatchingStoragePoolsForVpoolAndVarray(vpool.getLabel(), varray.getLabel());
        } else {
            // Call out to the respective file service implementation to prepare
            // and create the fileshares based on the recommendations.
            fileServiceImpl.createFileSystems(param, project, varray, vpool, tenantOrg, flags, recommendations, taskList, task, capabilities);
        }
    } catch (Exception ex) {
        for (TaskResourceRep taskObj : taskList.getTaskList()) {
            if (ex instanceof ServiceCoded) {
                this.fileService._dbClient.error(FileShare.class, taskObj.getResource().getId(), taskObj.getOpId(), (ServiceCoded) ex);
            } else {
                this.fileService._dbClient.error(FileShare.class, taskObj.getResource().getId(), taskObj.getOpId(), InternalServerErrorException.internalServerErrors.unexpectedErrorVolumePlacement(ex));
            }
            _log.error(ex.getMessage(), ex);
            taskObj.setMessage(ex.getMessage());
            // Set the fileshare to inactive
            FileShare file = this.fileService._dbClient.queryObject(FileShare.class, taskObj.getResource().getId());
            file.setInactive(true);
            this.fileService._dbClient.updateObject(file);
        }
    }
    _log.info("Ending scheduling/placement thread...");
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) List(java.util.List) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)

Example 8 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.

the class ComputeSystemControllerImpl method rollbackHostBootVolumeId.

public void rollbackHostBootVolumeId(URI hostId, URI volumeId, String stepId) throws ControllerException {
    _log.info("rollbackHostBootVolumeId:" + hostId.toString());
    Host host = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (host == null) {
            throw ComputeSystemControllerException.exceptions.hostNotFound(hostId.toString());
        }
        _log.info("Rolling back boot volume association for host");
        host.setBootVolumeId(NullColumnValueGetter.getNullURI());
        _dbClient.persistObject(host);
        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.unableToRollbackBootVolume(hostString, e);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Host(com.emc.storageos.db.client.model.Host) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) RemoteException(java.rmi.RemoteException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) ClientControllerException(com.emc.storageos.exceptions.ClientControllerException)

Example 9 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.

the class ComputeSystemControllerImpl method setHostBootVolumeId.

public void setHostBootVolumeId(URI hostId, URI volumeId, String stepId) throws ControllerException {
    _log.info("setHostBootVolumeId :" + hostId.toString());
    Host host = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (host == null) {
            throw ComputeSystemControllerException.exceptions.hostNotFound(hostId.toString());
        }
        _log.info("Setting boot volume association for host");
        host.setBootVolumeId(volumeId);
        _dbClient.persistObject(host);
        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.unableToSetBootVolume(hostString, e);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Host(com.emc.storageos.db.client.model.Host) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) RemoteException(java.rmi.RemoteException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) ClientControllerException(com.emc.storageos.exceptions.ClientControllerException)

Example 10 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method unbindHostFromTemplateStep.

/**
 * Unbind host from service profile template
 *
 * @param computeSystemId
 *            {@link URI} computeSystem URI
 * @param hostId
 *            {@link URI} host URI
 * @param stepId
 *            {@link String} step id
 */
public void unbindHostFromTemplateStep(URI computeSystemId, URI hostId, String stepId) {
    log.info("unbindHostFromTemplateStep");
    ComputeSystem computeSystem = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        computeSystem = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
        String sptDn = unbindHostFromTemplate(computeSystemId, hostId);
        _workflowService.storeStepData(stepId, sptDn);
        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 unbindHostFromTemplateStep: " + 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 unbindHostFromTemplateStep: " + 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)

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