Search in sources :

Example 71 with ServiceCoded

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

the class RPBlockServiceApiImpl method deleteVolumes.

/**
 * {@inheritDoc}
 *
 * @throws InternalException
 */
@Override
public void deleteVolumes(final URI systemURI, final List<URI> volumeURIs, final String deletionType, final String task) throws InternalException {
    _log.info("Request to delete {} volume(s) with RP Protection", volumeURIs.size());
    try {
        // check to make sure no target volumes were passed in
        Iterator<Volume> dbVolumeIter = _dbClient.queryIterativeObjects(Volume.class, volumeURIs);
        while (dbVolumeIter.hasNext()) {
            Volume vol = dbVolumeIter.next();
            if (vol.checkPersonality(Volume.PersonalityTypes.TARGET)) {
                throw APIException.badRequests.deactivateRPTargetNotSupported(vol.getLabel());
            }
        }
        super.deleteVolumes(systemURI, volumeURIs, deletionType, task);
    } catch (Exception e) {
        // Set the task to failed
        for (URI volumeID : volumeURIs) {
            if (e instanceof ServiceCoded) {
                _dbClient.error(Volume.class, volumeID, task, (ServiceCoded) e);
            } else {
                _dbClient.error(Volume.class, volumeID, task, RecoverPointException.exceptions.deletingRPVolume(e));
            }
        }
        throw RecoverPointException.exceptions.deletingRPVolume(e);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException)

Example 72 with ServiceCoded

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

the class SRDFBlockServiceApiImpl method upgradeToSRDFTargetVolume.

/**
 * Upgrade a local block volume to a protected SRDF volume
 *
 * @param volume
 *            -- srdf source volume (existing).
 * @param vpool
 *            -- Requested vpool.
 * @param taskId
 * @throws InternalException
 */
private List<VolumeDescriptor> upgradeToSRDFTargetVolume(final Volume volume, final VirtualPool vpool, final VirtualPoolChangeParam cosChangeParam, final String taskId) throws InternalException {
    VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
    capabilities.put(VirtualPoolCapabilityValuesWrapper.BLOCK_CONSISTENCY_GROUP, volume.getConsistencyGroup());
    List<Recommendation> recommendations = getRecommendationsForVirtualPoolChangeRequest(volume, vpool, cosChangeParam);
    if (recommendations.isEmpty()) {
        throw APIException.badRequests.noStorageFoundForVolume();
    }
    // Call out to the respective block service implementation to prepare and create the
    // volumes based on the recommendations.
    Project project = _dbClient.queryObject(Project.class, volume.getProject());
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, volume.getVirtualArray());
    // Generate a VolumeCreate object that contains the information that createVolumes likes to
    // consume.
    VolumeCreate param = new VolumeCreate(volume.getLabel(), String.valueOf(volume.getCapacity()), 1, vpool.getId(), volume.getVirtualArray(), volume.getProject().getURI());
    capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, new Integer(1));
    if (volume.getIsComposite()) {
        // add meta volume properties to the capabilities instance
        capabilities.put(VirtualPoolCapabilityValuesWrapper.IS_META_VOLUME, volume.getIsComposite());
        capabilities.put(VirtualPoolCapabilityValuesWrapper.META_VOLUME_TYPE, volume.getCompositionType());
        capabilities.put(VirtualPoolCapabilityValuesWrapper.META_VOLUME_MEMBER_COUNT, volume.getMetaMemberCount());
        capabilities.put(VirtualPoolCapabilityValuesWrapper.META_VOLUME_MEMBER_SIZE, volume.getMetaMemberSize());
        _log.debug(String.format("Capabilities : isMeta: %s, Meta Type: %s, Member size: %s, Count: %s", capabilities.getIsMetaVolume(), capabilities.getMetaVolumeType(), capabilities.getMetaVolumeMemberSize(), capabilities.getMetaVolumeMemberCount()));
    }
    TaskList taskList = new TaskList();
    // Prepare the Bourne Volumes to be created and associated
    // with the actual storage system volumes created. Also create
    // a BlockTaskList containing the list of task resources to be
    // returned for the purpose of monitoring the volume creation
    // operation for each volume to be created.
    String volumeLabel = param.getName();
    final BlockConsistencyGroup consistencyGroup = capabilities.getBlockConsistencyGroup() == null ? null : _dbClient.queryObject(BlockConsistencyGroup.class, capabilities.getBlockConsistencyGroup());
    // prepare the volumes
    List<URI> volumeURIs = prepareRecommendedVolumes(taskId, taskList, project, varray, vpool, capabilities.getResourceCount(), recommendations, consistencyGroup, volumeLabel, param.getSize());
    List<VolumeDescriptor> resultListVolumeDescriptors = new ArrayList<>();
    // Execute the volume creations requests for each recommendation.
    Iterator<Recommendation> recommendationsIter = recommendations.iterator();
    while (recommendationsIter.hasNext()) {
        Recommendation recommendation = recommendationsIter.next();
        try {
            List<VolumeDescriptor> volumeDescriptors = createVolumeDescriptors((SRDFRecommendation) recommendation, volumeURIs, capabilities);
            // Log volume descriptor information
            logVolumeDescriptorPrecreateInfo(volumeDescriptors, taskId);
            resultListVolumeDescriptors.addAll(volumeDescriptors);
        } catch (InternalException e) {
            if (_log.isErrorEnabled()) {
                _log.error("Controller error", e);
            }
            String errorMsg = String.format("Controller error: %s", e.getMessage());
            if (volumeURIs != null) {
                for (URI volumeURI : volumeURIs) {
                    Volume volume1 = _dbClient.queryObject(Volume.class, volumeURI);
                    if (volume1 != null) {
                        Operation op = new Operation();
                        ServiceCoded coded = ServiceError.buildServiceError(ServiceCode.API_RP_VOLUME_CREATE_ERROR, errorMsg.toString());
                        op.setMessage(errorMsg);
                        op.error(coded);
                        _dbClient.createTaskOpStatus(Volume.class, volumeURI, taskId, op);
                        TaskResourceRep volumeTask = toTask(volume1, taskId, op);
                        if (volume1.getPersonality() != null && volume1.getPersonality().equals(Volume.PersonalityTypes.SOURCE.toString())) {
                            taskList.getTaskList().add(volumeTask);
                        }
                    }
                }
            }
            // the user what succeeded and what failed.
            throw APIException.badRequests.cannotCreateSRDFVolumes(e);
        }
    }
    return resultListVolumeDescriptors;
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) 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) MetaVolumeRecommendation(com.emc.storageos.volumecontroller.impl.smis.MetaVolumeRecommendation) SRDFCopyRecommendation(com.emc.storageos.volumecontroller.SRDFCopyRecommendation) Recommendation(com.emc.storageos.volumecontroller.Recommendation) SRDFRecommendation(com.emc.storageos.volumecontroller.SRDFRecommendation) VolumeCreate(com.emc.storageos.model.block.VolumeCreate) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded)

Example 73 with ServiceCoded

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

the class SRDFBlockServiceApiImpl method createVolumes.

@Override
public TaskList createVolumes(final VolumeCreate param, final Project project, final VirtualArray varray, final VirtualPool vpool, final Map<VpoolUse, List<Recommendation>> recommendationMap, TaskList taskList, final String task, final VirtualPoolCapabilityValuesWrapper capabilities) throws InternalException {
    List<Recommendation> volRecommendations = recommendationMap.get(VpoolUse.ROOT);
    Long size = SizeUtil.translateSize(param.getSize());
    BlockOrchestrationController controller = getController(BlockOrchestrationController.class, BlockOrchestrationController.BLOCK_ORCHESTRATION_DEVICE);
    for (Recommendation volRecommendation : volRecommendations) {
        List<VolumeDescriptor> existingDescriptors = new ArrayList<VolumeDescriptor>();
        List<VolumeDescriptor> volumeDescriptors = createVolumesAndDescriptors(existingDescriptors, param.getName(), size, project, varray, vpool, volRecommendations, taskList, task, capabilities);
        List<URI> volumeURIs = VolumeDescriptor.getVolumeURIs(volumeDescriptors);
        try {
            controller.createVolumes(volumeDescriptors, task);
        } catch (InternalException e) {
            if (_log.isErrorEnabled()) {
                _log.error("Controller error", e);
            }
            String errorMsg = String.format("Controller error: %s", e.getMessage());
            if (volumeURIs != null) {
                for (URI volumeURI : volumeURIs) {
                    Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
                    if (volume != null) {
                        Operation op = new Operation();
                        ServiceCoded coded = ServiceError.buildServiceError(ServiceCode.API_RP_VOLUME_CREATE_ERROR, errorMsg.toString());
                        op.setMessage(errorMsg);
                        op.error(coded);
                        _dbClient.createTaskOpStatus(Volume.class, volumeURI, task, op);
                        TaskResourceRep volumeTask = toTask(volume, task, op);
                        if (volume.getPersonality() != null && volume.getPersonality().equals(Volume.PersonalityTypes.SOURCE.toString())) {
                            taskList.getTaskList().add(volumeTask);
                        }
                    }
                }
            }
        }
    }
    return taskList;
}
Also used : BlockOrchestrationController(com.emc.storageos.blockorchestrationcontroller.BlockOrchestrationController) VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) 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) MetaVolumeRecommendation(com.emc.storageos.volumecontroller.impl.smis.MetaVolumeRecommendation) SRDFCopyRecommendation(com.emc.storageos.volumecontroller.SRDFCopyRecommendation) Recommendation(com.emc.storageos.volumecontroller.Recommendation) SRDFRecommendation(com.emc.storageos.volumecontroller.SRDFRecommendation) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded)

Example 74 with ServiceCoded

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

the class FileSnapshotService method restore.

/**
 * Call will restore this snapshot to the File system that it is associated with.
 *
 * @param id
 *            [required] - the URN of a ViPR file snapshot to restore from
 * @brief Restore file snapshot
 * @return TaskResourceRep - Task resource object for tracking this operation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
@Path("/{id}/restore")
public TaskResourceRep restore(@PathParam("id") URI id) throws InternalException {
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snap = queryResource(id);
    FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
    String task = UUID.randomUUID().toString();
    Operation op = null;
    if ((snap != null) && (!(snap.getInactive()))) {
        StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
        StorageSystem.Type storageSystemType = StorageSystem.Type.valueOf(device.getSystemType());
        if (storageSystemType.equals(DiscoveredDataObject.Type.isilon)) {
            _log.error("Invalid Operation. Restore snapshot is not supported by ISILON");
            throw APIException.badRequests.isilonSnapshotRestoreNotSupported();
        }
        _log.info(String.format("Snapshot restore --- Snapshot id: %1$s, FileShare: %2$s, task %3$s", id, fs.getId(), task));
        _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.RESTORE_FILE_SNAPSHOT);
        op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.RESTORE_FILE_SNAPSHOT);
        FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
        fileServiceApi.restoreFS(device.getId(), fs.getId(), snap.getId(), task);
        auditOp(OperationTypeEnum.RESTORE_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snap.getId().toString(), fs.getId().toString());
    } else {
        StringBuilder msg = new StringBuilder("Attempt to use deleted snapshot: " + snap.getName());
        msg.append(" to restore File: " + fs.getName());
        op = new Operation();
        ServiceCoded coded = ServiceError.buildServiceError(ServiceCode.API_BAD_REQUEST, msg.toString());
        op.error(coded);
        op.setMessage(msg.toString());
        op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, op);
        _log.error(msg.toString());
    }
    return toTask(snap, task, op);
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 75 with ServiceCoded

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

the class CreateExportGroupSchedulingThread method run.

@Override
public void run() {
    _log.info("Starting scheduling for export group create thread...");
    // Call out placementManager to get the recommendation for placement.
    try {
        // validate clients (initiators, hosts clusters) input and package them
        // This call may take a long time.
        List<URI> affectedInitiators = this.exportGroupService.validateClientsAndPopulate(exportGroup, project, virtualArray, storageMap.keySet(), clusters, hosts, initiators, volumeMap.keySet(), pathParam);
        _log.info("Initiators {} will be used.", affectedInitiators);
        // If ExportPathParameter block is present, and volumes are present, capture those arguments.
        if (pathParam != null && !volumeMap.keySet().isEmpty()) {
            ExportPathParams exportPathParam = exportGroupService.validateAndCreateExportPathParam(pathParam, exportGroup, volumeMap.keySet());
            exportGroupService.addBlockObjectsToPathParamMap(volumeMap.keySet(), exportPathParam.getId(), exportGroup);
            exportGroupService._dbClient.createObject(exportPathParam);
        }
        this.exportGroupService._dbClient.updateObject(exportGroup);
        // If initiators list is empty or storage map is empty, there's no work to do (yet).
        if (storageMap.isEmpty() || affectedInitiators.isEmpty()) {
            this.exportGroupService._dbClient.ready(ExportGroup.class, taskRes.getResource().getId(), taskRes.getOpId());
            return;
        }
        // push it to storage devices
        BlockExportController exportController = this.exportGroupService.getExportController();
        _log.info("createExportGroup request is submitted.");
        exportController.exportGroupCreate(exportGroup.getId(), volumeMap, affectedInitiators, task);
    } catch (Exception ex) {
        if (ex instanceof ServiceCoded) {
            this.exportGroupService._dbClient.error(ExportGroup.class, taskRes.getResource().getId(), taskRes.getOpId(), (ServiceCoded) ex);
        } else {
            this.exportGroupService._dbClient.error(ExportGroup.class, taskRes.getResource().getId(), taskRes.getOpId(), InternalServerErrorException.internalServerErrors.unexpectedErrorExportGroupPlacement(ex));
        }
        _log.error(ex.getMessage(), ex);
        taskRes.setMessage(ex.getMessage());
        // Mark the export group to be deleted
        this.exportGroupService._dbClient.markForDeletion(exportGroup);
    }
    _log.info("Ending export group create scheduling thread...");
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) BlockExportController(com.emc.storageos.volumecontroller.BlockExportController) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) URI(java.net.URI) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams)

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