use of com.emc.storageos.networkcontroller.NetworkFCContext 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;
}
}
use of com.emc.storageos.networkcontroller.NetworkFCContext 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);
}
}
}
use of com.emc.storageos.networkcontroller.NetworkFCContext 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;
}
use of com.emc.storageos.networkcontroller.NetworkFCContext in project coprhd-controller by CoprHD.
the class NetworkDeviceController method zoneExportRemovePaths.
/**
* Handle zoning when removing paths from export masks
* @param zoningParams NetworkZoningParam list
* @param taskCompleter -- Task completer to be called
* @param token -- Step id
* @return true if successful
*/
public boolean zoneExportRemovePaths(List<NetworkZoningParam> zoningParams, TaskCompleter taskCompleter, String token) {
if (zoningParams.isEmpty()) {
_log.info("zoningParams is empty, returning");
taskCompleter.ready(_dbClient);
return true;
}
NetworkFCContext context = new NetworkFCContext();
boolean completedSuccessfully = false;
URI exportGroupId = zoningParams.get(0).getExportGroupId();
URI virtualArray = zoningParams.get(0).getVirtualArray();
_log.info(String.format("Entering zoneExportRemovePaths for ExportGroup: %s", zoningParams.get(0).getExportGroupDisplay()));
try {
if (!isZoningRequired(virtualArray)) {
taskCompleter.ready(_dbClient);
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()) {
taskCompleter.ready(_dbClient);
return true;
}
// Now call addRemoveZones to remove all the required zones.
BiosCommandResult result = addRemoveZones(exportGroupId, context.getZoneInfos(), true);
completedSuccessfully = result.isCommandSuccess();
if (completedSuccessfully) {
taskCompleter.ready(_dbClient);
} else {
ServiceError svcError = NetworkDeviceControllerException.errors.zoneExportRemovePathsError(result.getMessage());
taskCompleter.error(_dbClient, svcError);
}
} catch (Exception ex) {
_log.error("Exception zoning remove initiators", ex);
ServiceError svcError = NetworkDeviceControllerException.errors.zoneExportRemovePathsFailed(ex.getMessage(), ex);
taskCompleter.error(_dbClient, svcError);
}
return completedSuccessfully;
}
use of com.emc.storageos.networkcontroller.NetworkFCContext in project coprhd-controller by CoprHD.
the class NetworkDeviceController method zoneExportAddPaths.
/**
* Handle zoning when adding paths to ExportMasks
* @param systemURI -- Storage system URI
* @param exportGroupURI -- Export Group URI
* @param exportMaskURIs -- List of ExportMask URIs
* @param newPaths -- Zoning map of the new paths to be added
* @param taskCompleter -- Task completer to be called
* @param token -- Step id
* @return true if successful
* @throws ControllerException
*/
public boolean zoneExportAddPaths(URI systemURI, URI exportGroupURI, Collection<URI> exportMaskURIs, Map<URI, List<URI>> newPaths, TaskCompleter taskCompleter, String token) throws ControllerException {
NetworkFCContext context = new NetworkFCContext();
boolean completedSucessfully = false;
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
_log.info(String.format("Entering zoneExportAddPaths for ExportGroup: %s (%s)", exportGroup.getLabel(), exportGroup.getId()));
try {
if (!isZoningRequired(exportGroup.getVirtualArray())) {
_log.info("The zoning is not required.");
taskCompleter.ready(_dbClient);
return true;
}
// get existing zones on the switch
Map<String, List<Zone>> zonesMap = getExistingZonesMap(exportMaskURIs, token);
// Compute zones that are required.
List<NetworkFCZoneInfo> zoneInfos = _networkScheduler.getZoningTargetsForPaths(systemURI, exportGroup, exportMaskURIs, newPaths, zonesMap, _dbClient);
context.getZoneInfos().addAll(zoneInfos);
logZones(zoneInfos);
// If there are no zones to do, we were successful.
if (context.getZoneInfos().isEmpty()) {
taskCompleter.ready(_dbClient);
;
return true;
}
// Now call addRemoveZones to add all the required zones.
BiosCommandResult result = addRemoveZones(exportGroup.getId(), context.getZoneInfos(), false);
completedSucessfully = result.isCommandSuccess();
if (completedSucessfully) {
taskCompleter.ready(_dbClient);
} else {
ServiceError svcError = NetworkDeviceControllerException.errors.zoneExportAddPathsError(result.getMessage());
taskCompleter.error(_dbClient, svcError);
}
} catch (Exception ex) {
_log.error("Exception zoning add paths", ex);
ServiceError svcError = NetworkDeviceControllerException.errors.zoneExportAddPathsFailed(ex.getMessage(), ex);
taskCompleter.error(_dbClient, svcError);
}
return completedSucessfully;
}
Aggregations