Search in sources :

Example 76 with ServiceCoded

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

the class CreateExportGroupUpdateSchedulingThread method run.

@Override
public void run() {
    _log.info("Starting scheduling for export group update thread...");
    try {
        Map<URI, Integer> newVolumesMap = exportGroupService.getUpdatedVolumesMap(exportUpdateParam, exportGroup);
        Map<URI, Map<URI, Integer>> storageMap = exportGroupService.computeAndValidateVolumes(newVolumesMap, exportGroup, exportUpdateParam);
        _log.info("Updated volumes belong to storage systems: {}", Joiner.on(',').join(storageMap.keySet()));
        // Convert the storageMap to a list of added and removed Block Objects
        newVolumesMap.clear();
        for (Map.Entry<URI, Map<URI, Integer>> entry : storageMap.entrySet()) {
            newVolumesMap.putAll(entry.getValue());
        }
        Map<URI, Integer> addedBlockObjectsMap = new HashMap<URI, Integer>();
        Map<URI, Integer> removedBlockObjectsMap = new HashMap<URI, Integer>();
        ExportUtils.getAddedAndRemovedBlockObjects(newVolumesMap, exportGroup, addedBlockObjectsMap, removedBlockObjectsMap);
        _log.info("Added volumes: {}", Joiner.on(',').join(addedBlockObjectsMap.keySet()));
        _log.info("Removed volumes: {}", Joiner.on(',').join(removedBlockObjectsMap.keySet()));
        // If ExportPathParameter block is present, and volumes are added, capture ExportPathParameters arguments.
        // This looks weird, but isn't. We use the added volumes from ExportCreateParam instead of addedBlockObjectsMap
        // because the user may want to change the parameters for volumes that are already exported. In this way,
        // the same volume can have different parameters to different hosts.
        Map<URI, Integer> addedVolumeParams = exportGroupService.getChangedVolumes(exportUpdateParam, true);
        ExportPathParams exportPathParam = null;
        if (exportUpdateParam.getExportPathParameters() != null && !addedVolumeParams.keySet().isEmpty()) {
            exportPathParam = exportGroupService.validateAndCreateExportPathParam(exportUpdateParam.getExportPathParameters(), exportGroup, addedVolumeParams.keySet());
            exportGroupService.validatePortGroupWhenAddVolumesForExportGroup(addedVolumeParams.keySet(), exportUpdateParam.getExportPathParameters().getPortGroup(), exportGroup);
            exportGroupService.addBlockObjectsToPathParamMap(addedVolumeParams.keySet(), exportPathParam.getId(), exportGroup);
        } else if (!addedVolumeParams.keySet().isEmpty()) {
            // exportPathParam is null
            exportGroupService.validatePortGroupWhenAddVolumesForExportGroup(addedVolumeParams.keySet(), null, exportGroup);
        }
        // Remove the block objects being deleted from any existing path parameters.
        exportGroupService.removeBlockObjectsFromPathParamMap(removedBlockObjectsMap.keySet(), exportGroup);
        Set<URI> addedClusters = new HashSet<>();
        Set<URI> removedClusters = new HashSet<>();
        Set<URI> addedHosts = new HashSet<>();
        Set<URI> removedHosts = new HashSet<>();
        Set<URI> addedInitiators = new HashSet<>();
        Set<URI> removedInitiators = new HashSet<>();
        // Validate updated entries
        List<URI> newInitiators = StringSetUtil.stringSetToUriList(exportGroup.getInitiators());
        List<URI> newHosts = StringSetUtil.stringSetToUriList(exportGroup.getHosts());
        List<URI> newClusters = StringSetUtil.stringSetToUriList(exportGroup.getClusters());
        exportGroupService.validateClientsAndUpdate(exportGroup, project, storageMap.keySet(), exportUpdateParam, newClusters, newHosts, newInitiators, addedClusters, removedClusters, addedHosts, removedHosts, addedInitiators, removedInitiators);
        _log.info("All clients were successfully validated");
        dbClient.persistObject(exportGroup);
        if (exportPathParam != null) {
            dbClient.createObject(exportPathParam);
        }
        // push it to storage devices
        BlockExportController exportController = exportGroupService.getExportController();
        _log.info("Submitting export group update request.");
        exportController.exportGroupUpdate(exportGroup.getId(), addedBlockObjectsMap, removedBlockObjectsMap, addedClusters, removedClusters, addedHosts, removedHosts, addedInitiators, removedInitiators, task);
    } catch (Exception ex) {
        if (ex instanceof ServiceCoded) {
            dbClient.error(ExportGroup.class, taskRes.getResource().getId(), taskRes.getOpId(), (ServiceCoded) ex);
        } else {
            dbClient.error(ExportGroup.class, taskRes.getResource().getId(), taskRes.getOpId(), InternalServerErrorException.internalServerErrors.unexpectedErrorExportGroupPlacement(ex));
        }
        _log.error(ex.getMessage(), ex);
        taskRes.setMessage(ex.getMessage());
    }
    _log.info("Ending export group update scheduling thread...");
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) BlockExportController(com.emc.storageos.volumecontroller.BlockExportController) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) HashMap(java.util.HashMap) Map(java.util.Map) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams) HashSet(java.util.HashSet)

Example 77 with ServiceCoded

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

the class VirtualDataCenterService method enqueueJob.

private TaskResourceRep enqueueJob(VirtualDataCenter vdc, JobType jobType, List<Object> params) {
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(VirtualDataCenter.class, vdc.getId(), taskId, jobType.toResourceOperationType());
    // add to the job queue
    try {
        GeoServiceJob job = new GeoServiceJob(vdc, taskId, jobType, params);
        _geoHelper.enqueueJob(job);
    } catch (Exception ex) {
        _log.error("Exception occurred while enqueue job on due to:", ex);
        ServiceCoded coded = ServiceError.buildServiceError(ServiceCode.COORDINATOR_UNABLE_TO_QUEUE_JOB, ex.getMessage());
        op.error(coded);
    }
    return TaskMapper.toTask(vdc, taskId, op);
}
Also used : GeoServiceJob(com.emc.storageos.security.geo.GeoServiceJob) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) KeyStoreException(java.security.KeyStoreException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) SecurityException(com.emc.storageos.security.exceptions.SecurityException) UnknownHostException(java.net.UnknownHostException)

Example 78 with ServiceCoded

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

the class AbstractConsistencyGroupManager method removeVolumesFromCG.

/**
 * The method called by the workflow to remove VPLEX volumes from a VPLEX
 * consistency group.
 *
 * @param vplexURI The URI of the VPLEX storage system.
 * @param cgURI The URI of the consistency group.
 * @param vplexVolumeURIs The URIs of the volumes to be removed from the
 *            consistency group.
 * @param stepId The workflow step id.
 *
 * @throws WorkflowException When an error occurs updating the workflow step
 *             state.
 */
public void removeVolumesFromCG(URI vplexURI, URI cgURI, List<URI> vplexVolumeURIs, String stepId) throws WorkflowException {
    try {
        // Update workflow step.
        WorkflowStepCompleter.stepExecuting(stepId);
        log.info("Updated workflow step state to execute for remove volumes from consistency group.");
        ServiceCoded codedError = removeVolumesFromCGInternal(vplexURI, cgURI, vplexVolumeURIs);
        if (codedError != null) {
            WorkflowStepCompleter.stepFailed(stepId, codedError);
        } else {
            WorkflowStepCompleter.stepSucceded(stepId);
        }
    } catch (Exception ex) {
        log.error("Exception removing volumes from consistency group: " + ex.getMessage(), ex);
        String opName = ResourceOperationTypeEnum.DELETE_CG_VOLUME.getName();
        ServiceError serviceError = VPlexApiException.errors.removeVolumesFromCGFailed(opName, ex);
        WorkflowStepCompleter.stepFailed(stepId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException)

Example 79 with ServiceCoded

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

the class VPlexConsistencyGroupManager method removeVplexVolumesFromSRDFTargetCG.

/**
 * Removes volumes from SRDF Target.
 * @param vplexURI
 * @param vplexVolumeURIs
 * @param stepId
 * @throws WorkflowException
 */
public void removeVplexVolumesFromSRDFTargetCG(URI vplexURI, List<URI> vplexVolumeURIs, String stepId) throws WorkflowException {
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        Volume protoVolume = dbClient.queryObject(Volume.class, vplexVolumeURIs.get(0));
        if (NullColumnValueGetter.isNullURI(protoVolume.getConsistencyGroup())) {
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, protoVolume.getConsistencyGroup());
        if (consistencyGroup == null) {
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        // Remove the volumes from the ConsistencyGroup. Returns a codedError if failure.
        ServiceCoded codedError = removeVolumesFromCGInternal(vplexURI, protoVolume.getConsistencyGroup(), vplexVolumeURIs);
        if (codedError != null) {
            WorkflowStepCompleter.stepFailed(stepId, codedError);
            return;
        }
        // Determine if there are any remaining Vplex volumes in the consistency group.
        List<Volume> vplexVolumesInCG = BlockConsistencyGroupUtils.getActiveVplexVolumesInCG(consistencyGroup, dbClient, null);
        if (vplexVolumesInCG.isEmpty()) {
            ClusterConsistencyGroupWrapper clusterCGWrapper = getClusterConsistencyGroup(protoVolume, consistencyGroup);
            // No vplex volumes left, clean up the Vplex part of the consistency group.
            // deleteCG will call the step completer.
            deleteCG(vplexURI, consistencyGroup.getId(), clusterCGWrapper.getCgName(), clusterCGWrapper.getClusterName(), false, stepId);
        } else {
            // Vplex volumes left... we're finished.
            WorkflowStepCompleter.stepSucceded(stepId);
        }
    } catch (Exception ex) {
        log.info("Exception removing Vplex volumes from SRDF Target CG: " + ex.getMessage(), ex);
        ServiceError svcError = VPlexApiException.errors.jobFailed(ex);
        WorkflowStepCompleter.stepFailed(stepId, svcError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ClusterConsistencyGroupWrapper(com.emc.storageos.volumecontroller.impl.utils.ClusterConsistencyGroupWrapper) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 80 with ServiceCoded

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

the class NestedWorkflowRollbackHandler method rollbackComplete.

@Override
public void rollbackComplete(Workflow workflow, Object[] args) {
    Workflow.WorkflowRollbackHandler originalHandler = (Workflow.WorkflowRollbackHandler) args[indexOfNestedHandler(args)];
    if (originalHandler != null) {
        originalHandler.initiatingRollback(workflow, args);
    }
    Map<String, StepStatus> stepToStepStatus = workflow.getStepStatusMap();
    boolean rollbackError = false;
    StringBuilder builder = new StringBuilder();
    for (StepStatus stepStatus : stepToStepStatus.values()) {
        if (stepStatus.description.startsWith("Rollback ") && stepStatus.state == StepState.ERROR) {
            if (builder.length() > 0) {
                builder.append("\n");
            }
            builder.append(stepStatus.message);
            rollbackError = true;
        }
    }
    String parentStepId = (String) args[indexOfParentStepId(args)];
    if (rollbackError) {
        ServiceCoded coded = WorkflowException.exceptions.innerWorkflowRollbackError(workflow.getWorkflowURI().toString(), builder.toString());
        WorkflowStepCompleter.stepFailed(parentStepId, coded);
    } else {
        WorkflowStepCompleter.stepSucceded(parentStepId);
    }
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) StepStatus(com.emc.storageos.workflow.Workflow.StepStatus)

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