Search in sources :

Example 1 with DatabaseException

use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.

the class RPDeviceController method disableImageForSnapshots.

/**
 * Disable image access for RP snapshots.
 *
 * @param protectionDevice
 *            protection system
 * @param snapshotList
 *            list of snapshots to enable
 * @param setSnapshotSyncActive
 *            true if the isSyncActive field on BlockSnapshot should be true, false otherwise.
 * @param opId
 * @throws ControllerException
 */
private void disableImageForSnapshots(URI protectionDevice, List<URI> snapshotList, boolean setSnapshotSyncActive, String opId) throws ControllerException {
    BlockSnapshotDeactivateCompleter completer = null;
    try {
        _log.info("Deactivating a bookmark on the RP CG(s)");
        completer = new BlockSnapshotDeactivateCompleter(snapshotList, setSnapshotSyncActive, opId);
        ProtectionSystem system = null;
        try {
            system = _dbClient.queryObject(ProtectionSystem.class, protectionDevice);
        } catch (DatabaseException e) {
            throw DeviceControllerExceptions.recoverpoint.databaseExceptionDeactivateSnapshot(protectionDevice);
        }
        if (system == null) {
            throw DeviceControllerExceptions.recoverpoint.databaseExceptionDeactivateSnapshot(protectionDevice);
        }
        // Keep a mapping of the emNames(bookmark names) to target copy volume WWNs
        Map<String, Set<String>> emNamesToVolumeWWNs = new HashMap<String, Set<String>>();
        // Keep a mapping of the emNames(bookmark names) to BlockSnapshot objects
        Map<String, Set<URI>> emNamesToSnapshots = new HashMap<String, Set<URI>>();
        for (URI snapshotID : snapshotList) {
            BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotID);
            // Determine if we can actually disable image access to the copy associated with the snapshot first
            if (!doDisableImageCopies(snapshot)) {
                // Skip this snapshot because we cannot disable image access. Likely due to the snapshot
                // being exported to multiple hosts.
                _log.warn(String.format("Cannot disable image access for snapshot %s so it will be skipped.  Likely due to the snapshot being exported to multiple hosts", snapshot.getId()));
                continue;
            }
            String emName = snapshot.getEmName();
            if (NullColumnValueGetter.isNotNullValue(emName)) {
                if (!emNamesToVolumeWWNs.containsKey(emName)) {
                    emNamesToVolumeWWNs.put(emName, new HashSet<String>());
                }
                if (!emNamesToSnapshots.containsKey(emName)) {
                    emNamesToSnapshots.put(emName, new HashSet<URI>());
                }
                emNamesToSnapshots.get(emName).add(snapshotID);
            } else {
                throw DeviceControllerExceptions.recoverpoint.failedToDeactivateSnapshotEmNameMissing(snapshotID);
            }
            // Get the volume associated with this snapshot
            Volume volume = _dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
            // Fetch the VPLEX volume that is created with this volume as the back-end volume.
            if (Volume.checkForVplexBackEndVolume(_dbClient, volume)) {
                volume = Volume.fetchVplexVolume(_dbClient, volume);
            }
            String wwn = null;
            // If the personality is SOURCE, then the enable image access request is part of export operation.
            if (volume.checkPersonality(Volume.PersonalityTypes.TARGET.toString())) {
                wwn = RPHelper.getRPWWn(volume.getId(), _dbClient);
            } else {
                // Now determine the target volume that corresponds to the site of the snapshot
                ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
                Volume targetVolume = ProtectionSet.getTargetVolumeFromSourceAndInternalSiteName(_dbClient, protectionSet, volume, snapshot.getEmInternalSiteName());
                wwn = RPHelper.getRPWWn(targetVolume.getId(), _dbClient);
            }
            // Add the volume WWN
            emNamesToVolumeWWNs.get(emName).add(wwn);
        }
        // Now disable image access on the bookmark copies
        RecoverPointClient rp = RPHelper.getRecoverPointClient(system);
        // correponding to each emName.
        for (Map.Entry<String, Set<String>> emNameEntry : emNamesToVolumeWWNs.entrySet()) {
            MultiCopyDisableImageRequestParams request = new MultiCopyDisableImageRequestParams();
            request.setVolumeWWNSet(emNameEntry.getValue());
            request.setEmName(emNameEntry.getKey());
            MultiCopyDisableImageResponse response = rp.disableImageCopies(request);
            if (response == null) {
                throw DeviceControllerExceptions.recoverpoint.failedDisableAccessOnRP();
            }
            // Let the completer know about the deactivated snapshots (ones who's associated copies
            // had image access disabled). This will be used to update the BlockSnapshot fields accordingly.
            // This is done because not all snapshots used when creating the completer will be deactivated.
            // We need to maintain a collection of snapshots so that those exported to multiple hosts to not
            // get deactivated.
            completer.addDeactivatedSnapshots(emNamesToSnapshots.get(emNameEntry.getKey()));
        }
        completer.ready(_dbClient);
    } catch (InternalException e) {
        _log.error("Operation failed with Exception: ", e);
        if (completer != null) {
            completer.error(_dbClient, e);
        }
    } catch (URISyntaxException e) {
        _log.error("Operation failed with Exception: ", e);
        if (completer != null) {
            completer.error(_dbClient, DeviceControllerException.errors.invalidURI(e));
        }
    } catch (Exception e) {
        _log.error("Operation failed with Exception: ", e);
        if (completer != null) {
            completer.error(_dbClient, DeviceControllerException.errors.jobFailed(e));
        }
    }
}
Also used : ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) URISyntaxException(java.net.URISyntaxException) MultiCopyDisableImageRequestParams(com.emc.storageos.recoverpoint.requests.MultiCopyDisableImageRequestParams) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) LockRetryException(com.emc.storageos.locking.LockRetryException) FunctionalAPIActionFailedException_Exception(com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) FunctionalAPIInternalError_Exception(com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) MultiCopyDisableImageResponse(com.emc.storageos.recoverpoint.responses.MultiCopyDisableImageResponse) Volume(com.emc.storageos.db.client.model.Volume) RecoverPointClient(com.emc.storageos.recoverpoint.impl.RecoverPointClient) BlockSnapshotDeactivateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotDeactivateCompleter) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap)

Example 2 with DatabaseException

use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.

the class RPDeviceController method enableImageForSnapshots.

/**
 * Enable image access for RP snapshots.
 *
 * @param protectionDevice
 *            protection system
 * @param storageDevice
 *            storage device of the backing (parent) volume
 * @param snapshotList
 *            list of snapshots to enable
 * @param opId
 *            task ID
 * @return true if operation was successful
 * @throws ControllerException
 * @throws URISyntaxException
 */
private boolean enableImageForSnapshots(URI protectionDevice, URI storageDevice, List<URI> snapshotList, String opId) throws ControllerException, URISyntaxException {
    TaskCompleter completer = null;
    try {
        _log.info("Activating a bookmark on the RP CG(s)");
        completer = new BlockSnapshotActivateCompleter(snapshotList, opId);
        ProtectionSystem system = null;
        try {
            system = _dbClient.queryObject(ProtectionSystem.class, protectionDevice);
        } catch (DatabaseException e) {
            throw DeviceControllerExceptions.recoverpoint.databaseExceptionActivateSnapshot(protectionDevice);
        }
        // Verify non-null storage device returned from the database client.
        if (system == null) {
            throw DeviceControllerExceptions.recoverpoint.databaseExceptionActivateSnapshot(protectionDevice);
        }
        // is still creating the snapshot
        if (snapshotList != null && !snapshotList.isEmpty()) {
            BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotList.get(0));
            Volume parent = _dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
            final List<Volume> vplexVolumes = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Volume.class, getVolumesByAssociatedId(parent.getId().toString()));
            if (vplexVolumes != null && !vplexVolumes.isEmpty()) {
                parent = vplexVolumes.get(0);
            }
            String lockName = ControllerLockingUtil.getConsistencyGroupStorageKey(_dbClient, parent.getConsistencyGroup(), system.getId());
            if (null != lockName) {
                List<String> locks = new ArrayList<String>();
                locks.add(lockName);
                acquireWorkflowLockOrThrow(_workflowService.getWorkflowFromStepId(opId), locks);
            }
        }
        // Keep a mapping of the emNames(bookmark names) to target copy volume WWNs
        Map<String, Set<String>> emNamesToVolumeWWNs = new HashMap<String, Set<String>>();
        // Keep a mapping of the emNames(bookmark names) to BlockSnapshot objects
        Map<String, Set<URI>> emNamesToSnapshots = new HashMap<String, Set<URI>>();
        for (URI snapshotID : snapshotList) {
            BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotID);
            String emName = snapshot.getEmName();
            if (NullColumnValueGetter.isNotNullValue(emName)) {
                if (!emNamesToVolumeWWNs.containsKey(emName)) {
                    emNamesToVolumeWWNs.put(emName, new HashSet<String>());
                }
                if (!emNamesToSnapshots.containsKey(emName)) {
                    emNamesToSnapshots.put(emName, new HashSet<URI>());
                }
                emNamesToSnapshots.get(emName).add(snapshotID);
            } else {
                throw DeviceControllerExceptions.recoverpoint.failedToActivateSnapshotEmNameMissing(snapshotID);
            }
            // Get the volume associated with this snapshot
            Volume volume = _dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
            // Fetch the VPLEX volume that is created with this volume as the back-end volume.
            if (Volume.checkForVplexBackEndVolume(_dbClient, volume)) {
                volume = Volume.fetchVplexVolume(_dbClient, volume);
            }
            String wwn = null;
            // If the personality is SOURCE, then the enable image access request is part of export operation.
            if (volume.checkPersonality(Volume.PersonalityTypes.TARGET.toString())) {
                wwn = RPHelper.getRPWWn(volume.getId(), _dbClient);
            } else {
                // Now determine the target volume that corresponds to the site of the snapshot
                ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
                Volume targetVolume = ProtectionSet.getTargetVolumeFromSourceAndInternalSiteName(_dbClient, protectionSet, volume, snapshot.getEmInternalSiteName());
                wwn = RPHelper.getRPWWn(targetVolume.getId(), _dbClient);
            }
            // Add the volume WWN
            emNamesToVolumeWWNs.get(emName).add(wwn);
        }
        // Now enable image access to that bookmark
        RecoverPointClient rp = RPHelper.getRecoverPointClient(system);
        // correponding to each emName.
        for (Map.Entry<String, Set<String>> emNameEntry : emNamesToVolumeWWNs.entrySet()) {
            MultiCopyEnableImageRequestParams request = new MultiCopyEnableImageRequestParams();
            request.setVolumeWWNSet(emNameEntry.getValue());
            request.setBookmark(emNameEntry.getKey());
            MultiCopyEnableImageResponse response = rp.enableImageCopies(request);
            if (response == null) {
                throw DeviceControllerExceptions.recoverpoint.failedEnableAccessOnRP();
            }
        }
        completer.ready(_dbClient);
        return true;
    } catch (InternalException e) {
        _log.error("Operation failed with Exception: ", e);
        if (completer != null) {
            completer.error(_dbClient, e);
        }
        throw e;
    } catch (URISyntaxException e) {
        _log.error("Operation failed with Exception: ", e);
        if (completer != null) {
            completer.error(_dbClient, DeviceControllerException.errors.invalidURI(e));
        }
        throw e;
    } catch (Exception e) {
        _log.error("Operation failed with Exception: ", e);
        if (completer != null) {
            completer.error(_dbClient, DeviceControllerException.errors.jobFailed(e));
        }
        throw e;
    }
}
Also used : ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) MultiCopyEnableImageResponse(com.emc.storageos.recoverpoint.responses.MultiCopyEnableImageResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) URISyntaxException(java.net.URISyntaxException) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) RecoverPointClient(com.emc.storageos.recoverpoint.impl.RecoverPointClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) LockRetryException(com.emc.storageos.locking.LockRetryException) FunctionalAPIActionFailedException_Exception(com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) FunctionalAPIInternalError_Exception(com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroupUpdateTaskCompleter(com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) VolumeVpoolChangeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeVpoolChangeTaskCompleter) RPCGProtectionTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.RPCGProtectionTaskCompleter) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) BlockSnapshotActivateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotActivateCompleter) MultiCopyEnableImageRequestParams(com.emc.storageos.recoverpoint.requests.MultiCopyEnableImageRequestParams)

Example 3 with DatabaseException

use of com.emc.storageos.db.exceptions.DatabaseException 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 4 with DatabaseException

use of com.emc.storageos.db.exceptions.DatabaseException 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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) ArrayList(java.util.ArrayList) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ZoneInfoMap(com.emc.storageos.db.client.model.ZoneInfoMap) Map(java.util.Map) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) HashSet(java.util.HashSet)

Example 5 with DatabaseException

use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.

the class NetworkDiscoveryWorker method updatePhysicalInventory.

/**
 * Update the network system physical inventory and creates/updates the discovered FC transport
 * zones as needed. The physical inventory is primarily the FCEndpoints (FCPortConnections),
 * which contains a record for each endpoint logged into the Fiber Channel Nameserver database.
 * The endpoints per fabric (vsan) constitute an FC transport zone which get created/updated
 * based on the FCEndpoints discovered.
 *
 * @param uri - Device URI
 */
public void updatePhysicalInventory(URI uri) throws ControllerException {
    // Retrieve the storage device info from the database.
    long start = System.currentTimeMillis();
    NetworkSystem networkDev = getDeviceObject(uri);
    String msg = "unknown status";
    NetworkSystemDevice networkDevice = getDevice();
    if (networkDevice == null) {
        throw NetworkDeviceControllerException.exceptions.updatePhysicalInventoryFailedNull(uri.toString(), networkDev.getSystemType());
    }
    try {
        // === Reconcile the FCEndpoints of this device ===
        List<FCEndpoint> currentConnections = new ArrayList<FCEndpoint>();
        // IN/OUT parameter to get the routed endpoints map - Fabric-WWN-to-endpoints-WWN
        Map<String, Set<String>> routedEndpoints = new HashMap<String, Set<String>>();
        try {
            currentConnections = networkDevice.getPortConnections(networkDev, routedEndpoints);
            msg = MessageFormat.format("Retrieved {0} connections from device {1} at {2}", new Integer(currentConnections.size()), uri, new Date());
            _log.info(msg);
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed getting port connections for Network System : {0}", uri.toString());
            throw (e);
        }
        try {
            reconcileFCEndpoints(networkDev, currentConnections);
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed reconciling FC endpoints for Network System : {0}", uri.toString());
            throw (e);
        }
        // ==== Reconcile the discovered transport zones ======
        try {
            reconcileTransportZones(networkDev, routedEndpoints);
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed reconciling networks for Network System : {0}", uri.toString());
            throw (e);
        }
        try {
            networkDev.setUptime(networkDevice.getUptime(networkDev));
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed setting version/uptime for Network System : {0}", uri.toString());
            throw (e);
        }
        // discovery succeeds
        msg = MessageFormat.format("Discovery completed successfully for Network System : {0}", uri.toString());
    } catch (Exception ex) {
        Date date = new Date();
        throw NetworkDeviceControllerException.exceptions.updatePhysicalInventoryFailedExc(uri.toString(), date.toString(), ex);
    } finally {
        if (networkDev != null) {
            try {
                // set detailed message
                networkDev.setLastDiscoveryStatusMessage(msg);
                dbClient.updateObject(networkDev);
                _log.info("Discovery took {}", (System.currentTimeMillis() - start));
            } catch (DatabaseException ex) {
                _log.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) ArrayList(java.util.ArrayList) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) Date(java.util.Date) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Aggregations

DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)109 URI (java.net.URI)70 ArrayList (java.util.ArrayList)29 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)22 IOException (java.io.IOException)21 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)20 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)19 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)18 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)17 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)16 NamedURI (com.emc.storageos.db.client.model.NamedURI)14 ControllerException (com.emc.storageos.volumecontroller.ControllerException)13 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)12 HashSet (java.util.HashSet)12 StoragePool (com.emc.storageos.db.client.model.StoragePool)11 StoragePort (com.emc.storageos.db.client.model.StoragePort)11 Volume (com.emc.storageos.db.client.model.Volume)11 HashMap (java.util.HashMap)11 List (java.util.List)11 WBEMException (javax.wbem.WBEMException)11