Search in sources :

Example 1 with ZoneReferencesRemoveCompleter

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ZoneReferencesRemoveCompleter 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 2 with ZoneReferencesRemoveCompleter

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ZoneReferencesRemoveCompleter in project coprhd-controller by CoprHD.

the class NetworkDeviceController method zoneExportRemoveInitiators.

/**
 * This will remove zones for all the initiators in the NetworkZoningParam zoneMap.
 * Note: these arguments (except stepId) must match zoneExportRemoveInitiatorsMethod above.
 * This routine executes as a Workflow Step.
 *
 * @param zoningParams -- List of NetworkZoningParam zoning parameter blocks corresponding to ExportMasks
 * @param stepId -- step id in Workflow
 * @return
 * @throws ControllerException
 */
public boolean zoneExportRemoveInitiators(List<NetworkZoningParam> zoningParams, String stepId) throws ControllerException {
    boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(stepId);
    boolean isOperationSuccessful = false;
    TaskCompleter taskCompleter = null;
    if (zoningParams.isEmpty()) {
        _log.info("zoningParams is empty, returning");
        WorkflowStepCompleter.stepSucceded(stepId);
        return true;
    }
    NetworkFCContext context = new NetworkFCContext();
    boolean status = false;
    URI exportGroupId = zoningParams.get(0).getExportGroupId();
    URI virtualArray = zoningParams.get(0).getVirtualArray();
    _log.info(String.format("Entering zoneExportRemoveInitiators for ExportGroup: %s", zoningParams.get(0).getExportGroupDisplay()));
    try {
        if (!checkZoningRequired(stepId, virtualArray)) {
            return true;
        }
        context.setAddingZones(false);
        // Get the zoning targets to be removed.
        List<NetworkFCZoneInfo> zoneInfos = _networkScheduler.getZoningRemoveTargets(zoningParams, null);
        context.getZoneInfos().addAll(zoneInfos);
        logZones(zoneInfos);
        // If there are no zones to do, we were successful.
        if (context.getZoneInfos().isEmpty()) {
            isOperationSuccessful = true;
            WorkflowStepCompleter.stepSucceded(stepId);
            return true;
        }
        // Create a local completer to handle DB cleanup in the case of failure.
        taskCompleter = new ZoneReferencesRemoveCompleter(NetworkUtil.getFCZoneReferences(context.getZoneInfos()), true, stepId);
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_024);
        // Now call removeZones to remove all the required zones.
        BiosCommandResult result = addRemoveZones(exportGroupId, context.getZoneInfos(), true);
        status = result.isCommandSuccess();
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_025);
        // Update the workflow state.
        completeWorkflowState(taskCompleter, stepId, "zoneExportRemoveInitiators", result, null);
        if (result.isCommandSuccess()) {
            isOperationSuccessful = true;
        }
        return status;
    } catch (Exception ex) {
        _log.error("Exception zoning remove initiators", ex);
        ServiceError svcError = NetworkDeviceControllerException.errors.zoneExportRemoveInitiatorsFailed(ex.getMessage(), ex);
        taskCompleter.error(_dbClient, svcError);
        WorkflowStepCompleter.stepFailed(stepId, svcError);
        return status;
    } finally {
        // clean up the zoning map too if the result is success or a rollback
        if (isOperationSuccessful || isRollback) {
            removeInitiatorsFromZoningMap(zoningParams);
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) NetworkFCContext(com.emc.storageos.networkcontroller.NetworkFCContext) ZoneReferencesRemoveCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ZoneReferencesRemoveCompleter) URI(java.net.URI) 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 3 with ZoneReferencesRemoveCompleter

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ZoneReferencesRemoveCompleter in project coprhd-controller by CoprHD.

the class NetworkDeviceController method doZoneExportMasksDelete.

/**
 * Remove ExportMasks or delete Volumes from ExportMasks.
 *
 * @param zoningParamss -- List of NetworkZoningParam block obtained from ExportMask
 * @param volumeURIs -- Collection of all volumes being removed
 * @param stepId - Step id.
 * @return status -- true if success
 */
private boolean doZoneExportMasksDelete(List<NetworkZoningParam> zoningParams, Collection<URI> volumeURIs, String stepId) {
    NetworkFCContext context = new NetworkFCContext();
    TaskCompleter taskCompleter = null;
    boolean status = false;
    try {
        if (zoningParams.isEmpty()) {
            _log.info("zoningParams is empty, returning");
            WorkflowStepCompleter.stepSucceded(stepId);
            return true;
        }
        URI exportGroupId = zoningParams.get(0).getExportGroupId();
        URI virtualArray = zoningParams.get(0).getVirtualArray();
        if (!checkZoningRequired(stepId, virtualArray)) {
            return true;
        }
        volumeURIs = removeDuplicateURIs(volumeURIs);
        // Compute the zones for the ExportGroup
        context.setAddingZones(false);
        List<NetworkFCZoneInfo> zones = _networkScheduler.getZoningRemoveTargets(zoningParams, volumeURIs);
        context.getZoneInfos().addAll(zones);
        logZones(zones);
        // If there are no zones to do, we were successful.
        if (context.getZoneInfos().isEmpty()) {
            _log.info("No zoning information provided.");
            WorkflowStepCompleter.stepSucceded(stepId);
            return true;
        }
        // Generate warning message if required.
        String warningMessage = generateExistingZoneWarningMessages(context.getZoneInfos());
        // 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()) {
                rollbackList.add(info);
            }
        }
        // Create a local completer to handle DB cleanup in the case of failure.
        taskCompleter = new ZoneReferencesRemoveCompleter(NetworkUtil.getFCZoneReferences(context.getZoneInfos()), true, stepId);
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_007);
        // Now call removeZones to remove all the required zones.
        BiosCommandResult result = addRemoveZones(exportGroupId, context.getZoneInfos(), true);
        status = result.isCommandSuccess();
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_008);
        List<URI> exportMaskURIs = new ArrayList<URI>();
        for (NetworkZoningParam zoningParam : zoningParams) {
            exportMaskURIs.add(zoningParam.getMaskId());
        }
        // if they still exist.
        if (status && !lastReferenceZoneInfo.isEmpty()) {
            _log.info("There seems to be last reference zones that were removed, clean those zones from the ExportMask zoning map.");
            updateZoningMap(lastReferenceZoneInfo, exportGroupId, exportMaskURIs);
        }
        // Update the workflow state.
        completeWorkflowState(taskCompleter, stepId, "zoneExportMasksDelete", result, warningMessage.toString());
        _log.info("Successfully removed zones for ExportGroup: {}", exportGroupId.toString());
    } catch (Exception ex) {
        _log.error("Exception zoning delete Export Masks", ex);
        WorkflowService.getInstance().storeStepData(stepId, context);
        ServiceError svcError = NetworkDeviceControllerException.errors.zoneExportGroupDeleteFailed(ex.getMessage(), ex);
        if (taskCompleter != null) {
            taskCompleter.error(_dbClient, svcError);
        } else {
            WorkflowStepCompleter.stepFailed(stepId, svcError);
        }
    }
    return status;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ArrayList(java.util.ArrayList) NetworkFCContext(com.emc.storageos.networkcontroller.NetworkFCContext) URI(java.net.URI) 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) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) ZoneReferencesRemoveCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ZoneReferencesRemoveCompleter)

Aggregations

DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)3 NetworkFCContext (com.emc.storageos.networkcontroller.NetworkFCContext)3 NetworkFCZoneInfo (com.emc.storageos.networkcontroller.NetworkFCZoneInfo)3 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)3 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)3 ControllerException (com.emc.storageos.volumecontroller.ControllerException)3 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)3 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)3 ZoneReferencesRemoveCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ZoneReferencesRemoveCompleter)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2