use of com.emc.storageos.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.
the class NetworkDeviceController method addRemoveZones.
/**
* Add/remove a group of zones as given by their NetworkFabricInfo structures.
* ALL fabricInfos must be using the same NetworkDevice, and the same fabricId. There is a higher level
* subroutine to split complex requests into sets of requests with the same NetworkDevice and fabricId.
*
* @param networkSystem NetworkDevice
* @param fabricId String
* @param exportGroupUri The ExportGroup URI. Used for reference counting.
* @param fabricInfos - Describe each zone.
* @param activateZones - activate active zoneset after zones change
* @param retryAltNetworkDevice - a boolean to indicate if re-try to be done.
* This is to stop this function from running again after the alternate
* system is retried once.
* @return BiosCommandResult
* @throws ControllerException
*/
private BiosCommandResult addRemoveZones(NetworkSystem networkSystem, String fabricId, String fabricWwn, URI exportGroupUri, List<NetworkFCZoneInfo> fabricInfos, boolean doRemove, boolean retryAltNetworkDevice) throws ControllerException {
BiosCommandResult result = null;
String taskId = UUID.randomUUID().toString();
List<Zone> zones = new ArrayList<Zone>();
// Make the zone operations. Don't make the same zone more than once,
// as determined by its key. The same zone shows up multiple times because it
// must be recorded for each volume in the FCZoneReference table.
HashSet<String> keySet = new HashSet<String>();
for (NetworkFCZoneInfo fabricInfo : fabricInfos) {
String key = fabricInfo.makeEndpointsKey();
if (false == keySet.contains(key)) {
keySet.add(key);
// neither create nor delete zones found on the switch
if (fabricInfo.isExistingZone()) {
_log.info("Zone {} will not be created or removed on {}, as it is not vipr created. ", fabricInfo.getZoneName(), fabricInfo.toString());
// neither create nor delete zones found on the switch
continue;
}
// Don't actually remove the zone if it's not the last reference
if (doRemove && !fabricInfo._isLastReference) {
_log.info("Zone {} will not be removed on {}, as still the zone is used to expose other volumes in export groups ", fabricInfo.getZoneName(), fabricInfo.toString());
continue;
}
Zone zone = new Zone(fabricInfo.getZoneName());
for (String address : fabricInfo.getEndPoints()) {
ZoneMember member = new ZoneMember(address, ConnectivityMemberType.WWPN);
zone.getMembers().add(member);
}
zones.add(zone);
}
}
// Get the network device reference for the type of network device managed
// by the controller.
NetworkSystemDevice networkDevice = getDevice(networkSystem.getSystemType());
if (networkDevice == null) {
throw NetworkDeviceControllerException.exceptions.addRemoveZonesFailedNull(networkSystem.getSystemType());
}
// Lock to prevent concurrent operations on the same VSAN / FABRIC.
InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricId, _coordinator);
try {
if (doRemove) {
/* Removing zones */
result = networkDevice.removeZones(networkSystem, zones, fabricId, fabricWwn, true);
if (result.isCommandSuccess()) {
for (NetworkFCZoneInfo fabricInfo : fabricInfos) {
String refKey = fabricInfo.getZoneName() + " " + fabricInfo.getFcZoneReferenceId().toString();
try {
FCZoneReference ref = deleteFCZoneReference(fabricInfo);
if (ref != null && !zones.isEmpty()) {
recordZoneEvent(ref, OperationTypeEnum.REMOVE_SAN_ZONE.name(), OperationTypeEnum.REMOVE_SAN_ZONE.getDescription());
}
} catch (DatabaseException ex) {
_log.error("Could not delete FCZoneReference: " + refKey);
}
}
}
} else {
/* Adding zones */
_log.debug("Adding zones on network system {} ", networkSystem.getNativeGuid());
result = networkDevice.addZones(networkSystem, zones, fabricId, fabricWwn, true);
if (result.isCommandSuccess()) {
for (NetworkFCZoneInfo fabricInfo : fabricInfos) {
String refKey = fabricInfo.getZoneName() + " " + fabricInfo.getVolumeId().toString();
try {
String[] newOrExisting = new String[1];
FCZoneReference ref = addZoneReference(exportGroupUri, fabricInfo, newOrExisting);
// this is needed for rollback
fabricInfo.setFcZoneReferenceId(ref.getId());
_log.info(String.format("%s FCZoneReference key: %s volume %s group %s", newOrExisting[0], ref.getPwwnKey(), ref.getVolumeUri(), exportGroupUri));
if (!zones.isEmpty()) {
recordZoneEvent(ref, OperationTypeEnum.ADD_SAN_ZONE.name(), OperationTypeEnum.ADD_SAN_ZONE.getDescription());
}
} catch (DatabaseException ex) {
_log.error("Could not persist FCZoneReference: " + refKey);
}
}
}
}
// Update the FCZoneInfo structures if we changed device state for rollback.
Map<String, String> map = (Map<String, String>) result.getObjectList().get(0);
for (NetworkFCZoneInfo info : fabricInfos) {
if (NetworkSystemDevice.SUCCESS.equals(map.get(info.getZoneName()))) {
info.setCanBeRolledBack(true);
} else {
info.setCanBeRolledBack(false);
}
}
if (!result.isCommandSuccess()) {
ServiceError serviceError = NetworkDeviceControllerException.errors.addRemoveZonesFailed(networkSystem.getSystemType());
setStatus(ExportGroup.class, exportGroupUri, taskId, false, serviceError);
} else {
setStatus(ExportGroup.class, exportGroupUri, taskId, true, null);
}
return result;
} catch (ControllerException ex) {
String operation = doRemove ? "Remove Zones" : "Add Zones";
_log.info(String.format("waiting for 2 min before retrying %s with alternate device", operation));
try {
Thread.sleep(1000 * 120);
} catch (InterruptedException e) {
_log.warn("Thread sleep interrupted. Allowing to continue without sleep");
}
NetworkFCZoneInfo fabricInfo = fabricInfos.get(0);
URI primaryUri = fabricInfo.getNetworkDeviceId();
URI altUri = fabricInfo.getAltNetworkDeviceId();
// If we took an error, attempt a retry with an alternate device if possible.
if (altUri != null && retryAltNetworkDevice) {
NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
fabricLock = null;
_log.error("Zone operation failed using device: " + primaryUri + " retrying with alternate device: " + altUri);
fabricInfo.setNetworkDeviceId(altUri);
networkSystem = getNetworkSystemObject(altUri);
return addRemoveZones(networkSystem, fabricId, fabricWwn, exportGroupUri, fabricInfos, doRemove, false);
} else {
if (result != null) {
if (!result.isCommandSuccess()) {
ServiceError serviceError = NetworkDeviceControllerException.errors.addRemoveZonesFailed(networkSystem.getSystemType());
setStatus(ExportGroup.class, exportGroupUri, taskId, false, serviceError);
} else {
setStatus(ExportGroup.class, exportGroupUri, taskId, true, null);
}
}
throw ex;
}
} finally {
NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.
the class NetworkDeviceController method removeZone.
/**
* Remove a zone.
*
* @param volUri URI of the Volume
* @param fabricInfo NetworkFabricInfo generated by NetworkScheduler
* @return BiosCommandResult
*/
public BiosCommandResult removeZone(URI volUri, NetworkFCZoneInfo fabricInfo, boolean activateZones) throws ControllerException {
ServiceError serviceError = NetworkDeviceControllerException.errors.zoningFailedArgs(volUri.toString());
BiosCommandResult result = BiosCommandResult.createErrorResult(serviceError);
List<Zone> zones = new ArrayList<Zone>();
Zone zone = new Zone(fabricInfo.getZoneName());
zones.add(zone);
String taskId = UUID.randomUUID().toString();
for (String address : fabricInfo.getEndPoints()) {
ZoneMember member = new ZoneMember(address, ConnectivityMemberType.WWPN);
zone.getMembers().add(member);
}
// Lock to prevent concurrent operations on the same VSAN / FABRIC.
InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricInfo.getFabricId(), _coordinator);
try {
NetworkSystem device = getNetworkSystemObject(fabricInfo.getNetworkDeviceId());
// Get the file device reference for the type of file device managed
// by the controller.
NetworkSystemDevice networkDevice = getDevice(device.getSystemType());
if (networkDevice == null) {
throw NetworkDeviceControllerException.exceptions.removeZoneFailedNull(device.getSystemType());
}
if (fabricInfo.isLastReference() == true && !fabricInfo.isExistingZone()) {
result = networkDevice.removeZones(device, zones, fabricInfo.getFabricId(), fabricInfo.getFabricWwn(), activateZones);
} else {
// This is not the last reference, just mark our FCZoneReference for deletion
result = BiosCommandResult.createSuccessfulResult();
}
if (result.isCommandSuccess()) {
if (fabricInfo.getFcZoneReferenceId() != null) {
try {
// Mark our FcZoneReference object for removal
FCZoneReference reference = _dbClient.queryObject(FCZoneReference.class, fabricInfo.getFcZoneReferenceId());
if (reference != null) {
_dbClient.markForDeletion(reference);
recordZoneEvent(reference, OperationTypeEnum.REMOVE_SAN_ZONE.name(), OperationTypeEnum.REMOVE_SAN_ZONE.getDescription());
}
} catch (Exception ex) {
_log.error("Can't mark object for removal: " + fabricInfo.getFcZoneReferenceId());
}
}
}
if (!result.isCommandSuccess()) {
ServiceError svcError = NetworkDeviceControllerException.errors.removeZoneFailed(volUri.toString(), device.getSystemType());
setStatus(Volume.class, volUri, taskId, false, svcError);
} else {
setStatus(Volume.class, volUri, taskId, true, null);
}
} catch (ControllerException ex) {
_log.info("waiting for 2 min before retrying removeZone with alternate device");
try {
Thread.sleep(1000 * 120);
} catch (InterruptedException e) {
_log.warn("Thread sleep interrupted. Allowing to continue without sleep");
}
URI primaryUri = fabricInfo.getNetworkDeviceId();
URI altUri = fabricInfo.getAltNetworkDeviceId();
if (altUri != null && altUri != primaryUri) {
NetworkFabricLocker.unlockFabric(fabricInfo.getFabricId(), fabricLock);
fabricLock = null;
_log.error("Remove Zone failed using device: " + primaryUri + " retrying with alternate device: " + altUri);
fabricInfo.setNetworkDeviceId(altUri);
return removeZone(volUri, fabricInfo, activateZones);
} else {
ServiceError svcError = NetworkDeviceControllerException.errors.removeZoneFailedExc(volUri.toString());
setStatus(Volume.class, volUri, taskId, false, svcError);
throw ex;
}
} finally {
NetworkFabricLocker.unlockFabric(fabricInfo.getFabricId(), fabricLock);
}
return result;
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceError 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.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.
the class NetworkDeviceController method updateSanZones.
@Override
public void updateSanZones(URI uri, String fabricId, String fabricWwn, List<ZoneUpdate> zones, boolean activateZones, String taskId) throws ControllerException {
NetworkSystem device = getNetworkSystemObject(uri);
// Lock to prevent concurrent operations on the same VSAN / FABRIC.
InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricId, _coordinator);
try {
// Get the file device reference for the type of file device managed
// by the controller.
NetworkSystemDevice networkDevice = getDevice(device.getSystemType());
if (networkDevice == null) {
throw NetworkDeviceControllerException.exceptions.updateSanZonesFailedNull(device.getSystemType());
}
BiosCommandResult result = networkDevice.updateZones(device, zones, fabricId, fabricWwn, activateZones);
setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
_auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.UPDATE_SAN_ZONE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL());
} catch (Exception ex) {
ServiceError serviceError = NetworkDeviceControllerException.errors.updateSanZonesFailedExc(device.getSystemType(), ex);
_dbClient.error(NetworkSystem.class, device.getId(), taskId, serviceError);
} finally {
NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.
the class NetworkDeviceController method addSanZones.
@Override
public void addSanZones(URI uri, String fabricId, String fabricWwn, List<Zone> zones, boolean activateZones, String taskId) throws ControllerException {
NetworkSystem device = getNetworkSystemObject(uri);
// Lock to prevent concurrent operations on the same VSAN / FABRIC.
InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricId, _coordinator);
try {
// Get the file device reference for the type of file device managed
// by the controller.
NetworkSystemDevice networkDevice = getDevice(device.getSystemType());
if (networkDevice == null) {
throw NetworkDeviceControllerException.exceptions.addSanZonesFailedNull(device.getSystemType());
}
BiosCommandResult result = networkDevice.addZones(device, zones, fabricId, fabricWwn, activateZones);
setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
_auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.ADD_SAN_ZONE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL());
} catch (Exception ex) {
ServiceError serviceError = NetworkDeviceControllerException.errors.addSanZonesFailedExc(device.getSystemType(), ex);
_dbClient.error(NetworkSystem.class, device.getId(), taskId, serviceError);
} finally {
NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
}
}
Aggregations