Search in sources :

Example 76 with WBEMException

use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.

the class SmisCommandHelper method groupVolumesByStorageGroupWithHostIOLimit.

/**
 * Group volumes by storage group which has host IO limit set.
 *
 * @param storage the storage
 * @param volumeURIs the volume uris
 * @return the sgToVolumesMap storage group to volumes map
 * @throws WBEMException the WBEM exception
 */
public Map<String, List<URI>> groupVolumesByStorageGroupWithHostIOLimit(StorageSystem storage, Set<URI> volumeURIs) throws Exception {
    CloseableIterator<CIMObjectPath> mvPathItr = null;
    CloseableIterator<CIMObjectPath> sgItr = null;
    Map<String, List<URI>> sgToVolumesMap = new HashMap<String, List<URI>>();
    List<String> processedGroups = new ArrayList<String>();
    try {
        _log.info("Trying to find existing Storage groups for given volumes which have Host IO Limit set..");
        List<? extends BlockObject> blockObjects = BlockObject.fetchAll(_dbClient, volumeURIs);
        for (BlockObject bo : blockObjects) {
            CIMObjectPath volumePath = _cimPath.getBlockObjectPath(storage, bo);
            // See if Volume is associated with MV
            mvPathItr = getAssociatorNames(storage, volumePath, null, SYMM_LUN_MASKING_VIEW, null, null);
            if (mvPathItr.hasNext()) {
                sgItr = getAssociatorNames(storage, volumePath, null, SE_DEVICE_MASKING_GROUP, null, null);
                while (sgItr.hasNext()) {
                    CIMObjectPath sgPath = sgItr.next();
                    String instanceId = sgPath.getKey(CP_INSTANCE_ID).getValue().toString();
                    if (!processedGroups.contains(instanceId)) {
                        CIMInstance sgInstance = getInstance(storage, sgPath, false, false, new String[] { CP_ELEMENT_NAME, EMC_MAX_BANDWIDTH, EMC_MAX_IO });
                        String groupName = CIMPropertyFactory.getPropertyValue(sgInstance, CP_ELEMENT_NAME);
                        String hostIOLimitBandwidth = CIMPropertyFactory.getPropertyValue(sgInstance, EMC_MAX_BANDWIDTH);
                        String hostIOLimitIOPs = CIMPropertyFactory.getPropertyValue(sgInstance, EMC_MAX_IO);
                        if ((!StringUtils.isEmpty(hostIOLimitBandwidth) && Integer.parseInt(hostIOLimitBandwidth) > 0) || (!StringUtils.isEmpty(hostIOLimitIOPs) && Integer.parseInt(hostIOLimitIOPs) > 0)) {
                            // SG has Host IO Limit set
                            List<URI> sgVolumes = sgToVolumesMap.get(groupName);
                            if (sgVolumes == null) {
                                sgVolumes = new ArrayList<URI>();
                                sgToVolumesMap.put(groupName, sgVolumes);
                            }
                            sgVolumes.add(bo.getId());
                        }
                        processedGroups.add(instanceId);
                    }
                }
            }
        }
    } catch (Exception ex) {
        _log.error("Error occurred while looking for volumes' storage groups for Host IO Limit", ex);
        throw ex;
    } finally {
        closeCIMIterator(mvPathItr);
        closeCIMIterator(sgItr);
    }
    return sgToVolumesMap;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) IOException(java.io.IOException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 77 with WBEMException

use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.

the class SmisCommandHelper method createVolumeGroupBasedOnSLO.

/**
 * Creates storage group based on fast setting.
 *
 * @param forProvider
 *            The storage provider where the query executes
 * @param storageSystem
 *            The reference to the storage system
 * @param slo
 *            The slo name for the fast setting
 * @param workload
 *            The workload name for the fast setting
 * @param srp
 *            The srp name for the fast setting
 *
 * @return returns the storage group path for the storage group created
 */
public CIMObjectPath createVolumeGroupBasedOnSLO(StorageSystem forProvider, StorageSystem storageSystem, String slo, String workload, String srp) {
    String groupName = generateGroupName(slo, workload, srp);
    String lockName = generateParkingSLOSGLockName(storageSystem, groupName);
    boolean gotLock = false;
    CIMObjectPath volumeGroupObjectPath = null;
    try {
        // this call to create the SG needs distributed process protection
        if (_locker.acquireLock(lockName, PARKING_SLO_SG_LOCK_WAIT_SECS)) {
            gotLock = true;
            // Since we locked this operation, we need to make sure that some other system
            // did not already create the StorageGroup. So, check for it here.
            volumeGroupObjectPath = _cimPath.getStorageGroupObjectPath(groupName, storageSystem);
            CIMInstance instance = checkExists(forProvider, volumeGroupObjectPath, false, false);
            if (instance == null) {
                // Nothing created yet and we have the lock, so let's create it ...
                CIMArgument[] inArgs = getCreateVolumeGroupInputArguments(storageSystem, groupName, slo, srp, workload, null, false);
                CIMArgument[] outArgs = new CIMArgument[5];
                invokeMethod(forProvider, _cimPath.getControllerConfigSvcPath(storageSystem), "CreateGroup", inArgs, outArgs);
                volumeGroupObjectPath = _cimPath.getCimObjectPathFromOutputArgs(outArgs, "MaskingGroup");
            }
        } else {
            _log.warn(String.format("Could not get lock %s while trying to createVolumeGroupBasedOnSLO", lockName));
            throw DeviceControllerException.exceptions.failedToAcquireLock(lockName, "createVolumeGroupBasedOnSLO");
        }
    } catch (WBEMException we) {
        _log.info(storageSystem.getSystemType() + " Problem when trying to create volume group for SLO: " + slo + " SRP: " + srp + " Workload:  " + workload, we);
        throw new DeviceControllerException(we);
    } catch (Exception e) {
        _log.error("An exception while processing createVolumeGroupBasedOnSLO", e);
    } finally {
        if (gotLock) {
            _locker.releaseLock(lockName);
        }
    }
    return volumeGroupObjectPath;
}
Also used : CIMObjectPath(javax.cim.CIMObjectPath) WBEMException(javax.wbem.WBEMException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) CIMInstance(javax.cim.CIMInstance) IOException(java.io.IOException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) CIMArgument(javax.cim.CIMArgument)

Example 78 with WBEMException

use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.

the class SmisCommandHelper method getInitiatorsFromLunMaskingInstance.

/**
 * Will return a list of port names for the LunMasking container 'instance'.
 *
 * @param client
 *            [in] - WBEM client used to read data from SMI-S
 * @param instance
 *            [in] - Instance of CIM_LunMaskingSCSIProtocolController, holding a representation
 *            of an array masking container.
 * @return - Will return a list of port names for the LunMasking container.
 * @throws WBEMException
 */
public List<String> getInitiatorsFromLunMaskingInstance(WBEMClient client, CIMInstance instance) throws WBEMException {
    List<String> initiatorPorts = new ArrayList<String>();
    CloseableIterator<CIMInstance> iterator = null;
    try {
        iterator = client.associatorInstances(instance.getObjectPath(), null, CP_SE_STORAGE_HARDWARE_ID, null, null, false, PS_STORAGE_ID);
        while (iterator.hasNext()) {
            CIMInstance cimInstance = iterator.next();
            String initiator = CIMPropertyFactory.getPropertyValue(cimInstance, CP_STORAGE_ID);
            // initiator could be iSCSI or a WWN. We need to normalize if it is a
            // WWN, so that we can compare appropriately.
            String it = Initiator.normalizePort(initiator);
            initiatorPorts.add(it);
        }
    } catch (WBEMException we) {
        _log.error("Caught an error while attempting to get initiator list from " + "masking instance", we);
        throw we;
    } finally {
        closeCIMIterator(iterator);
    }
    return initiatorPorts;
}
Also used : ArrayList(java.util.ArrayList) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance)

Example 79 with WBEMException

use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.

the class SmisCommandHelper method checkDeviceGroupExists.

public CIMObjectPath checkDeviceGroupExists(final String cgName, final StorageSystem forProvider, final StorageSystem system) {
    CloseableIterator<CIMObjectPath> names = null;
    try {
        CIMObjectPath path = _cimPath.getStorageSystem(system);
        names = getAssociatorNames(forProvider, path, null, SE_REPLICATION_GROUP, null, null);
        while (names.hasNext()) {
            CIMObjectPath replicationGroupPath = names.next();
            String instanceId = replicationGroupPath.getKey(CP_INSTANCE_ID).getValue().toString();
            // Format
            // VMAX2: SE_ReplicationGroup.InstanceID="SynchCG+1+SYMMETRIX+000195701505"
            // VMAX3: SE_ReplicationGroup.InstanceID="000196700572+testRG"
            String repName = null;
            if (forProvider.getUsingSmis80()) {
                repName = instanceId.split(Constants.PATH_DELIMITER_REGEX)[1];
            } else {
                repName = instanceId.split(Constants.PATH_DELIMITER_REGEX)[0];
            }
            if (repName.equalsIgnoreCase(cgName)) {
                return replicationGroupPath;
            }
        }
    } catch (WBEMException e) {
        _log.warn("Failed to get Device Group {}", cgName, e);
    } finally {
        if (null != names) {
            names.close();
        }
    }
    return null;
}
Also used : CIMObjectPath(javax.cim.CIMObjectPath) WBEMException(javax.wbem.WBEMException)

Example 80 with WBEMException

use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.

the class SmisCommandHelper method getVolumesFromLunMaskingInstance.

/**
 * Will return a map of the volume WWNs to their HLU values for an instance of LunMasking
 * container on the array.
 *
 * @param client
 *            [in] - WBEM client used to read data from SMI-S
 * @param instance
 *            [in] - Instance of CIM_LunMaskingSCSIProtocolController, holding a representation
 *            of an array masking container.
 * @return - Will return a map of the volume WWNs to their HLU values for an instance of
 *         LunMasking container on the array.
 * @throws WBEMException
 */
public Map<String, Integer> getVolumesFromLunMaskingInstance(WBEMClient client, CIMInstance instance) throws WBEMException {
    Map<String, Integer> wwnToHLU = new HashMap<String, Integer>();
    CloseableIterator<CIMInstance> iterator = null;
    CloseableIterator<CIMInstance> protocolControllerForUnitIter = null;
    try {
        int retry = 0;
        boolean failures = true;
        Map<String, Integer> deviceIdToHLU = new HashMap<String, Integer>();
        while (failures) {
            failures = false;
            deviceIdToHLU.clear();
            protocolControllerForUnitIter = client.referenceInstances(instance.getObjectPath(), CIM_PROTOCOL_CONTROLLER_FOR_UNIT, null, false, PS_DEVICE_NUMBER);
            while (protocolControllerForUnitIter.hasNext()) {
                CIMInstance pcu = protocolControllerForUnitIter.next();
                CIMObjectPath pcuPath = pcu.getObjectPath();
                CIMProperty<CIMObjectPath> dependentVolumePropery = (CIMProperty<CIMObjectPath>) pcuPath.getKey(CP_DEPENDENT);
                CIMObjectPath dependentVolumePath = dependentVolumePropery.getValue();
                String deviceId = dependentVolumePath.getKey(CP_DEVICE_ID).getValue().toString();
                String deviceNumber = CIMPropertyFactory.getPropertyValue(pcu, CP_DEVICE_NUMBER);
                try {
                    Integer decimalHLU = (int) Long.parseLong(deviceNumber, 16);
                    deviceIdToHLU.put(deviceId, decimalHLU);
                } catch (NumberFormatException nfe) {
                    // We've found in testing when users remove volumes from masks, the volume will still be in the
                    // provider, but the HLU will get returned as an empty string, causing the overall operation to
                    // fail. This retry loop will ensure that we wait until the provider is returning only volumes
                    // with valid HLUs, thus removing any volumes from the mask that are in-flight outside of the
                    // controller.
                    _log.error(String.format("deviceId: %s returned an invalid HLU.  It may be currently getting removed from the mask.", deviceId));
                    failures = true;
                    if (retry++ > GET_VOLUMES_BAD_HLU_RETRIES) {
                        // rethrow
                        throw nfe;
                    }
                    try {
                        _log.warn("Retrying query operation for volumes and HLU after 10 seconds");
                        Thread.sleep(GET_VOLUMES_BAD_HLU_RETRY_SLEEP_MSEC);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                    }
                }
            }
        }
        _log.debug(String.format("getVolumesFromLunMaskingInstance(%s) - deviceIdToHLU map = %s", instance.getObjectPath().toString(), Joiner.on(',').join(deviceIdToHLU.entrySet())));
        iterator = client.associatorInstances(instance.getObjectPath(), null, CIM_STORAGE_VOLUME, null, null, false, PS_EMCWWN);
        while (iterator.hasNext()) {
            CIMInstance cimInstance = iterator.next();
            String deviceId = cimInstance.getObjectPath().getKey(CP_DEVICE_ID).getValue().toString();
            String wwn = CIMPropertyFactory.getPropertyValue(cimInstance, CP_WWN_NAME);
            wwnToHLU.put(wwn.toUpperCase(), deviceIdToHLU.get(deviceId));
        }
        _log.debug(String.format("getVolumesFromLunMaskingInstance(%s) - wwnToHLU map = %s", instance.getObjectPath().toString(), Joiner.on(',').join(wwnToHLU.entrySet())));
    } catch (WBEMException we) {
        _log.error("Caught an error will attempting to get volume list from " + "masking instance", we);
        throw we;
    } finally {
        closeCIMIterator(iterator);
        closeCIMIterator(protocolControllerForUnitIter);
    }
    return wwnToHLU;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CIMObjectPath(javax.cim.CIMObjectPath) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) CIMProperty(javax.cim.CIMProperty)

Aggregations

WBEMException (javax.wbem.WBEMException)122 CIMObjectPath (javax.cim.CIMObjectPath)90 CIMInstance (javax.cim.CIMInstance)63 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)60 CIMArgument (javax.cim.CIMArgument)52 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)38 ArrayList (java.util.ArrayList)29 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)27 Volume (com.emc.storageos.db.client.model.Volume)22 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)19 WBEMClient (javax.wbem.client.WBEMClient)19 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)16 HashSet (java.util.HashSet)15 URI (java.net.URI)13 HashMap (java.util.HashMap)13 BlockObject (com.emc.storageos.db.client.model.BlockObject)10 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)10 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)10 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)9 CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)8