Search in sources :

Example 6 with ServiceError

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

the class ImageServerControllerImpl method deleteImage.

/**
 * Delete image from all available imageServers
 *
 * @param task {@link AsyncTask} instance
 */
@Override
public void deleteImage(AsyncTask task) throws InternalException {
    log.info("deleteImage " + task._id);
    URI ciId = task._id;
    TaskCompleter completer = null;
    try {
        completer = new ComputeImageCompleter(ciId, task._opId, OperationTypeEnum.DELETE_COMPUTE_IMAGE, EVENT_SERVICE_TYPE);
        Workflow workflow = workflowService.getNewWorkflow(this, DELETE_IMAGE_WF, true, task._opId);
        List<URI> ids = dbClient.queryByType(ComputeImageServer.class, true);
        for (URI imageServerId : ids) {
            ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
            if (imageServer.getComputeImages() != null && imageServer.getComputeImages().contains(ciId.toString())) {
                boolean imageServerVerified = verifyImageServer(imageServer);
                if (!imageServerVerified) {
                    throw ImageServerControllerException.exceptions.imageServerNotSetup("Can't delete image: " + imageServerErrorMsg);
                }
                workflow.createStep(DELETE_IMAGE_STEP, String.format("removing image %s", ciId), null, ciId, ciId.toString(), this.getClass(), new Workflow.Method("deleteImageMethod", ciId, imageServer.getId()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
            }
            // So this cleanup needs to be performed.
            if (imageServer.getFailedComputeImages() != null && imageServer.getFailedComputeImages().contains(ciId.toString())) {
                imageServer.getFailedComputeImages().remove(ciId.toString());
                dbClient.updateObject(imageServer);
            }
        }
        workflow.executePlan(completer, SUCCESS);
    } catch (Exception e) {
        log.error("deleteImage caught an exception.", e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        completer.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ComputeImageCompleter(com.emc.storageos.imageservercontroller.ComputeImageCompleter) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Workflow(com.emc.storageos.workflow.Workflow) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)

Example 7 with ServiceError

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

the class ImageServerControllerImpl method importImageToServers.

/**
 * Import image to all available imageServer
 *
 * @param task {@link AsyncTask} instance
 */
@Override
public void importImageToServers(AsyncTask task) throws InternalException {
    log.info("importImage");
    URI ciId = task._id;
    boolean wfHasSteps = false;
    Workflow workflow = workflowService.getNewWorkflow(this, IMPORT_IMAGE_WF, true, task._opId);
    TaskCompleter completer = new ComputeImageCompleter(ciId, task._opId, OperationTypeEnum.CREATE_COMPUTE_IMAGE, EVENT_SERVICE_TYPE);
    try {
        List<URI> ids = dbClient.queryByType(ComputeImageServer.class, true);
        for (URI imageServerId : ids) {
            log.info("import to server:" + imageServerId.toString());
            ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
            if (imageServer.getComputeImages() == null || !imageServer.getComputeImages().contains(ciId.toString())) {
                log.info("verify Image Server");
                String verifyServerStepId = workflow.createStep(IMAGESERVER_VERIFICATION_STEP, String.format("Verifying ImageServer %s", imageServerId), null, imageServerId, imageServerId.toString(), this.getClass(), new Workflow.Method("verifyComputeImageServer", imageServerId), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
                workflow.createStep(IMPORT_IMAGE_TO_SERVER_STEP, String.format("Importing image for %s", imageServerId), verifyServerStepId, imageServerId, imageServerId.toString(), this.getClass(), new Workflow.Method("importImageMethod", ciId, imageServer, null), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
                wfHasSteps = true;
            }
        }
        if (wfHasSteps) {
            workflow.executePlan(completer, SUCCESS);
        }
    } catch (Exception e) {
        log.error("importImage caught an exception.", e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        completer.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ComputeImageCompleter(com.emc.storageos.imageservercontroller.ComputeImageCompleter) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Workflow(com.emc.storageos.workflow.Workflow) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)

Example 8 with ServiceError

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

the class NetworkDeviceController method zoneRollback.

/**
 * Rollback any of the zoning operations.
 *
 * @param exportGroupURI
 *            -- The ExportGroup URI
 * @param contextKey
 *            -- The context which indicates what zones were configured on the device.
 * @param taskId
 *            -- String task identifier for WorkflowTaskCompleter.
 * @return
 * @throws DeviceControllerException
 */
public boolean zoneRollback(URI exportGroupURI, String contextKey, String taskId) throws DeviceControllerException {
    TaskCompleter taskCompleter = null;
    try {
        NetworkFCContext context = (NetworkFCContext) WorkflowService.getInstance().loadStepData(contextKey);
        if (context == null) {
            _log.warn("No zone rollback information for Step: " + contextKey + " , Export Group: " + exportGroupURI.toString() + ", and Task: " + taskId + ". The zoning step either did not complete or encountered an error.");
            WorkflowStepCompleter.stepSucceded(taskId);
            return true;
        }
        logZones(context.getZoneInfos());
        WorkflowStepCompleter.stepExecuting(taskId);
        _log.info("Beginning zone rollback");
        _log.info("context.isAddingZones -{}", context.isAddingZones());
        // Determine what needs to be rolled back.
        List<NetworkFCZoneInfo> lastReferenceZoneInfo = new ArrayList<NetworkFCZoneInfo>();
        List<NetworkFCZoneInfo> rollbackList = new ArrayList<NetworkFCZoneInfo>();
        for (NetworkFCZoneInfo info : context.getZoneInfos()) {
            if (info.canBeRolledBack()) {
                // We should not blindly set last reference to true, removed code which does that earlier.
                rollbackList.add(info);
            } else {
                // Even though we cannot rollback the zone (because we didn't create it, it previously existed,
                // must remove the FCZoneReference that we created.
                deleteFCZoneReference(info);
            }
        }
        // Update the zone infos with the correct lastRef setting for those zones that can be rolled back
        _networkScheduler.determineIfLastZoneReferences(rollbackList);
        taskCompleter = new ZoneReferencesRemoveCompleter(NetworkUtil.getFCZoneReferences(rollbackList), context.isAddingZones(), taskId);
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_020);
        // Changed this parameter to true, so that the last reference validation runs all the time in placeZones()
        BiosCommandResult result = addRemoveZones(exportGroupURI, rollbackList, true);
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_021);
        if (result.isCommandSuccess() && !lastReferenceZoneInfo.isEmpty()) {
            _log.info("There seems to be last reference zones that were removed, clean those zones from the zoning map.");
            updateZoningMap(lastReferenceZoneInfo, exportGroupURI, null);
        }
        completeWorkflowState(taskCompleter, taskId, "ZoneRollback", result, null);
        return result.isCommandSuccess();
    } catch (Exception ex) {
        _log.error("Exception occurred while doing zone rollback", ex);
        ServiceError svcError = NetworkDeviceControllerException.errors.zoneRollbackFailedExc(exportGroupURI.toString(), ex);
        taskCompleter.error(_dbClient, svcError);
        WorkflowStepCompleter.stepFailed(taskId, svcError);
        return false;
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ArrayList(java.util.ArrayList) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) NetworkFCContext(com.emc.storageos.networkcontroller.NetworkFCContext) ZoneReferencesRemoveCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ZoneReferencesRemoveCompleter) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 9 with ServiceError

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

the class NetworkDeviceController method testCommunication.

@Override
public void testCommunication(URI network, String task) throws ControllerException {
    try {
        BiosCommandResult result = doConnect(network);
        if (result.isCommandSuccess()) {
            Operation op = new Operation();
            op.setMessage(result.getMessage());
            _dbClient.ready(NetworkSystem.class, network, task);
        } else {
            String opName = ResourceOperationTypeEnum.UPDATE_NETWORK.getName();
            ServiceError serviceError = NetworkDeviceControllerException.errors.testCommunicationFailed(opName, network.toString());
            _dbClient.error(NetworkSystem.class, network, task, serviceError);
        }
    } catch (Exception e) {
        _log.error("Exception while trying update task status");
        try {
            String opName = ResourceOperationTypeEnum.UPDATE_NETWORK.getName();
            ServiceError serviceError = NetworkDeviceControllerException.errors.testCommunicationFailedExc(opName, network.toString(), e);
            _dbClient.error(NetworkSystem.class, network, task, serviceError);
        } catch (DatabaseException ioe) {
            _log.error(ioe.getMessage());
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) Operation(com.emc.storageos.db.client.model.Operation) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 10 with ServiceError

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

the class NetworkDeviceController method removeSanZones.

@Override
public void removeSanZones(URI uri, String fabricId, String fabricWwn, List<Zone> zones, boolean activateZones, String taskId) throws ControllerException {
    NetworkSystem networkSytem = getNetworkSystemObject(uri);
    // Lock to prevent concurrent operations on the same VSAN / FABRIC.
    InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricId, _coordinator);
    try {
        // Get the network system reference for the type of network system managed
        // by the controller.
        NetworkSystemDevice networkDevice = getDevice(networkSytem.getSystemType());
        if (networkDevice == null) {
            throw NetworkDeviceControllerException.exceptions.removeSanZonesFailedNull(networkSytem.getSystemType());
        }
        BiosCommandResult result = networkDevice.removeZones(networkSytem, zones, fabricId, fabricWwn, activateZones);
        setStatus(NetworkSystem.class, networkSytem.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
        _auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.REMOVE_SAN_ZONE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, networkSytem.getId().toString(), networkSytem.getLabel(), networkSytem.getPortNumber(), networkSytem.getUsername(), networkSytem.getSmisProviderIP(), networkSytem.getSmisPortNumber(), networkSytem.getSmisUserName(), networkSytem.getSmisUseSSL());
    } catch (Exception ex) {
        ServiceError serviceError = NetworkDeviceControllerException.errors.removeSanZonesFailedExc(networkSytem.getSystemType(), ex);
        _dbClient.error(NetworkSystem.class, networkSytem.getId(), taskId, serviceError);
    } finally {
        NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Aggregations

ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)707 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)625 ControllerException (com.emc.storageos.volumecontroller.ControllerException)345 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)289 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)270 WorkflowException (com.emc.storageos.workflow.WorkflowException)258 URI (java.net.URI)250 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)246 ArrayList (java.util.ArrayList)238 Volume (com.emc.storageos.db.client.model.Volume)206 Workflow (com.emc.storageos.workflow.Workflow)127 WBEMException (javax.wbem.WBEMException)124 CIMObjectPath (javax.cim.CIMObjectPath)118 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)113 ExportMask (com.emc.storageos.db.client.model.ExportMask)107 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)105 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)104 URISyntaxException (java.net.URISyntaxException)94 HashMap (java.util.HashMap)86 NamedURI (com.emc.storageos.db.client.model.NamedURI)82