Search in sources :

Example 21 with WBEMClient

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

the class VnxExportOperations method findExportMasks.

/**
 * This call can be used to look up the passed in initiator/port names and find (if
 * any) to which export masks they belong on the 'storage' array.
 *
 * @param storage
 *            [in] - StorageSystem object representing the array
 * @param initiatorNames
 *            [in] - Port identifiers (WWPN or iSCSI name)
 * @param mustHaveAllPorts
 *            [in] NOT APPLICABLE FOR VNX
 * @return Map of port name to Set of ExportMask URIs
 */
@Override
public Map<String, Set<URI>> findExportMasks(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) throws DeviceControllerException {
    long startTime = System.currentTimeMillis();
    Map<String, Set<URI>> matchingMasks = new HashMap<String, Set<URI>>();
    CloseableIterator<CIMInstance> lunMaskingIter = null;
    try {
        StringBuilder builder = new StringBuilder();
        WBEMClient client = _helper.getConnection(storage).getCimClient();
        lunMaskingIter = _helper.getClarLunMaskingProtocolControllers(storage);
        while (lunMaskingIter.hasNext()) {
            CIMInstance instance = lunMaskingIter.next();
            String systemName = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_SYSTEM_NAME);
            if (!systemName.contains(storage.getSerialNumber())) {
                // SMISProvider pointed to by 'storage' system.
                continue;
            }
            String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_ELEMENT_NAME);
            CIMProperty<String> deviceIdProperty = (CIMProperty<String>) instance.getObjectPath().getKey(SmisConstants.CP_DEVICE_ID);
            // Get volumes and initiators for the masking instance
            Map<String, Integer> volumeWWNs = _helper.getVolumesFromLunMaskingInstance(client, instance);
            List<String> initiatorPorts = _helper.getInitiatorsFromLunMaskingInstance(client, instance);
            // Find out if the port is in this masking container
            List<String> matchingInitiators = new ArrayList<String>();
            for (String port : initiatorNames) {
                String normalizedName = Initiator.normalizePort(port);
                if (initiatorPorts.contains(normalizedName)) {
                    matchingInitiators.add(normalizedName);
                }
            }
            builder.append(String.format("%nXM:%s I:{%s} V:{%s}%n", name, Joiner.on(',').join(initiatorPorts), Joiner.on(',').join(volumeWWNs.keySet())));
            if (!matchingInitiators.isEmpty()) {
                // Look up ExportMask by deviceId/name and storage URI
                ExportMask exportMask = ExportMaskUtils.getExportMaskByName(_dbClient, storage.getId(), name);
                boolean foundMaskInDb = (exportMask != null);
                // then create a new one
                if (!foundMaskInDb) {
                    exportMask = new ExportMask();
                    exportMask.setMaskName(name);
                    exportMask.setNativeId(deviceIdProperty.getValue());
                    exportMask.setStorageDevice(storage.getId());
                    exportMask.setId(URIUtil.createId(ExportMask.class));
                    exportMask.setCreatedBySystem(false);
                    // Grab the storage ports that have been allocated for this
                    // existing mask and add them.
                    List<String> storagePorts = _helper.getStoragePortsFromLunMaskingInstance(client, instance);
                    List<String> storagePortURIs = ExportUtils.storagePortNamesToURIs(_dbClient, storagePorts);
                    exportMask.setStoragePorts(storagePortURIs);
                    builder.append(String.format("   ----> SP { %s }\n" + "         URI{ %s }\n", Joiner.on(',').join(storagePorts), Joiner.on(',').join(storagePortURIs)));
                } else {
                    // refresh the export mask
                    refreshExportMask(storage, exportMask);
                    builder.append('\n');
                }
                // Update the tracking containers
                exportMask.addToExistingVolumesIfAbsent(volumeWWNs);
                exportMask.addToExistingInitiatorsIfAbsent(matchingInitiators);
                // Update the initiator list to include existing initiators if we know about them.
                for (String port : matchingInitiators) {
                    Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
                    if (existingInitiator != null) {
                        exportMask.addInitiator(existingInitiator);
                        exportMask.addToUserCreatedInitiators(existingInitiator);
                        exportMask.removeFromExistingInitiators(existingInitiator);
                    }
                }
                // so, add them to the initiator list and remove them from existing as well.
                for (String port : initiatorPorts) {
                    Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
                    if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(exportMask, existingInitiator)) {
                        exportMask.addInitiator(existingInitiator);
                        exportMask.addToUserCreatedInitiators(existingInitiator);
                        exportMask.removeFromExistingInitiators(existingInitiator);
                    }
                }
                // Update the volume list to include existing volumes if know about them.
                if (volumeWWNs != null) {
                    for (String wwn : volumeWWNs.keySet()) {
                        URIQueryResultList results = new URIQueryResultList();
                        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn.toUpperCase()), results);
                        if (results != null) {
                            Iterator<URI> resultsIter = results.iterator();
                            if (resultsIter.hasNext()) {
                                Volume volume = _dbClient.queryObject(Volume.class, resultsIter.next());
                                if (volume != null) {
                                    Integer hlu = volumeWWNs.get(wwn);
                                    if (hlu == null) {
                                        _log.warn(String.format("The HLU for %s could not be found from the provider. Setting this to -1 (Unknown).", wwn));
                                        hlu = -1;
                                    }
                                    exportMask.addVolume(volume.getId(), hlu);
                                    exportMask.removeFromExistingVolumes(volume);
                                }
                            }
                        }
                    }
                }
                Set existingInitiators = (exportMask.getExistingInitiators() != null) ? exportMask.getExistingInitiators() : Collections.emptySet();
                Set existingVolumes = (exportMask.getExistingVolumes() != null) ? exportMask.getExistingVolumes().keySet() : Collections.emptySet();
                builder.append(String.format("XM:%s is matching. " + "EI: { %s }, EV: { %s }", name, Joiner.on(',').join(existingInitiators), Joiner.on(',').join(existingVolumes)));
                if (foundMaskInDb) {
                    ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, exportMask);
                    _dbClient.updateObject(exportMask);
                } else {
                    _dbClient.createObject(exportMask);
                }
                for (String it : matchingInitiators) {
                    Set<URI> maskURIs = matchingMasks.get(it);
                    if (maskURIs == null) {
                        maskURIs = new HashSet<URI>();
                        matchingMasks.put(it, maskURIs);
                    }
                    maskURIs.add(exportMask.getId());
                }
            }
        }
        _log.info(builder.toString());
    } catch (Exception e) {
        String msg = "Error when attempting to query LUN masking information: " + e.getMessage();
        _log.error(MessageFormat.format("Encountered an SMIS error when attempting to query existing exports: {0}", msg), e);
        throw SmisException.exceptions.queryExistingMasksFailure(msg, e);
    } finally {
        if (lunMaskingIter != null) {
            lunMaskingIter.close();
        }
        long totalTime = System.currentTimeMillis() - startTime;
        _log.info(String.format("findExportMasks took %f seconds", (double) totalTime / (double) 1000));
    }
    return matchingMasks;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) CIMProperty(javax.cim.CIMProperty) Initiator(com.emc.storageos.db.client.model.Initiator) WBEMClient(javax.wbem.client.WBEMClient) ExportMask(com.emc.storageos.db.client.model.ExportMask) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) Volume(com.emc.storageos.db.client.model.Volume)

Example 22 with WBEMClient

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

the class SmisStorageDevicePreProcessor method createStoragePoolSetting.

/**
 * Create StoragePool Setting for a given pool. This will be useful before
 * Here are the steps to create a new PoolSetting.
 * 1. First find the storagePoolCapability for a given storagepool.
 * 2. Use the capability to create a new StoragePool Setting.
 * 3. Update instance to set the
 *
 * creating a volume.
 *
 * @param storageSystem
 * @param storagePool
 * @param thinVolumePreAllocateSize
 * @throws Exception
 */
public CIMInstance createStoragePoolSetting(StorageSystem storageSystem, StoragePool storagePool, long thinVolumePreAllocateSize) throws Exception {
    _log.info(String.format("Create StoragePool Setting Start - Array: %s, Pool: %s, %n   thinVolumePreAllocateSize: %s", storageSystem.getSerialNumber(), storagePool.getNativeId(), thinVolumePreAllocateSize));
    CIMObjectPath poolSvcPath = _cimPath.getStoragePoolPath(storageSystem, storagePool);
    CimConnection connection = _cimConnection.getConnection(storageSystem);
    WBEMClient client = connection.getCimClient();
    CIMInstance modifiedSettingInstance = null;
    try {
        _log.debug("Op1 start: Getting poolCapabilities associated with this pool");
        final Iterator<?> it = client.associatorNames(poolSvcPath, SmisConstants.CIM_ELEMENTCAPABILITIES, SmisConstants.SYMM_STORAGEPOOL_CAPABILITIES, null, null);
        if (it.hasNext()) {
            final CIMObjectPath poolCapabilityPath = (CIMObjectPath) it.next();
            _log.debug("Op1 end: received pool capability from provider {}", poolCapabilityPath);
            CIMArgument<?>[] outputArgs = new CIMArgument<?>[1];
            _log.info("Invoking CIMClient to create to create a new Setting");
            client.invokeMethod(poolCapabilityPath, SmisConstants.CP_CREATE_SETTING, _helper.getCreatePoolSettingArguments(), outputArgs);
            CIMObjectPath settingPath = _cimPath.getCimObjectPathFromOutputArgs(outputArgs, SmisConstants.CP_NEWSETTING);
            modifiedSettingInstance = new CIMInstance(settingPath, _helper.getModifyPoolSettingArguments(thinVolumePreAllocateSize));
            client.modifyInstance(modifiedSettingInstance, SmisConstants.PS_THIN_VOLUME_INITIAL_RESERVE);
            _log.info("Modified the poolSetting instance to set ThinProvisionedInitialReserve");
        }
    } catch (WBEMException e) {
        _log.error("Problem making SMI-S call: ", e);
        throw e;
    } catch (Exception e) {
        _log.error("Problem in createStoragePoolSetting: " + storagePool.getNativeId(), e);
        throw e;
    } finally {
        _log.info(String.format("Create StoragePool Setting End - Array:%s, Pool: %s", storageSystem.getSerialNumber(), storagePool.getNativeId()));
    }
    return modifiedSettingInstance;
}
Also used : CIMObjectPath(javax.cim.CIMObjectPath) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) WBEMClient(javax.wbem.client.WBEMClient) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) CIMArgument(javax.cim.CIMArgument)

Example 23 with WBEMClient

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

the class XIVSmisCommandHelper method getInstances.

/**
 * Wrapper for the WBEMClient enumerateInstances method.
 *
 * @param storage
 *            - StorageArray reference, will be used to lookup SMI-S connection
 * @param namespace
 *            - Namespace to use
 * @param className
 *            - Name of the class on the provider to query
 * @param deep
 *            - If true, this specifies that, for each returned Instance of the Class, all
 *            properties of the Instance must be present (subject to constraints imposed by the
 *            other parameters), including any which were added by subclassing the specified
 *            Class. If false, each returned Instance includes only properties defined for the
 *            specified Class in path.
 * @param localOnly
 *            - If true, only elements values that were instantiated in the instance is
 *            returned.
 * @param includeClassOrigin
 *            - The class origin attribute is the name of the class that first defined the
 *            property. If true, the class origin attribute will be present for each property on
 *            all returned CIMInstances. If false, the class origin will not be present.
 * @param propertyList
 *            - An array of property names used to filter what is contained in the instances
 *            returned. Each instance returned only contains elements for the properties of the
 *            names specified. Duplicate and invalid property names are ignored and the request
 *            is otherwise processed normally. An empty array indicates that no properties
 *            should be returned. A null value indicates that all properties should be returned.
 * @return - CloseableIterator of CIMInstance values representing the instances of the specified
 *         class.
 * @throws Exception
 */
private CloseableIterator<CIMInstance> getInstances(StorageSystem storage, String namespace, String className, boolean deep, boolean localOnly, boolean includeClassOrigin, String[] propertyList) throws Exception {
    CloseableIterator<CIMInstance> cimInstances;
    CimConnection connection = _cimConnection.getConnection(storage);
    WBEMClient client = connection.getCimClient();
    String classKey = namespace + className;
    CIMObjectPath cimObjectPath = CIM_OBJECT_PATH_HASH_MAP.get(classKey);
    if (cimObjectPath == null) {
        cimObjectPath = CimObjectPathCreator.createInstance(className, namespace);
        CIM_OBJECT_PATH_HASH_MAP.putIfAbsent(classKey, cimObjectPath);
    }
    cimInstances = client.enumerateInstances(cimObjectPath, deep, localOnly, includeClassOrigin, propertyList);
    return cimInstances;
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) CIMObjectPath(javax.cim.CIMObjectPath) WBEMClient(javax.wbem.client.WBEMClient) CIMInstance(javax.cim.CIMInstance)

Example 24 with WBEMClient

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

the class XIVSmisCommandHelper method getGroupSyncObjectPaths.

public CIMObjectPath[] getGroupSyncObjectPaths(StorageSystem storage, CIMObjectPath cgPath) throws WBEMException {
    CimConnection connection = getConnection(storage);
    WBEMClient client = connection.getCimClient();
    CloseableIterator<CIMObjectPath> groupSyncIter = null;
    List<CIMObjectPath> objPaths = new ArrayList<CIMObjectPath>();
    try {
        groupSyncIter = client.referenceNames(cgPath, CP_GROUP_SYNCHRONIZED, CP_SYSTEM_ELEMENT);
        while (groupSyncIter.hasNext()) {
            objPaths.add(groupSyncIter.next());
        }
    } finally {
        if (groupSyncIter != null) {
            groupSyncIter.close();
        }
    }
    return objPaths.toArray(new CIMObjectPath[objPaths.size()]);
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) WBEMClient(javax.wbem.client.WBEMClient)

Example 25 with WBEMClient

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

the class XIVSmisCommandHelper method getInitiatorsFromScsiProtocolController.

/**
 * Returns a map of normalized port name to port path for the masking.
 *
 * @param storage
 *            [in] - StorageSystem that the masking belongs to
 * @param controllerPath
 *            [in] - CIMObjectPath of IBMTSDS_SCSIProtocolController, holding a representation
 *            of an array masking container.
 * @return - a map of port name to port path for the container.
 */
public Map<String, CIMObjectPath> getInitiatorsFromScsiProtocolController(StorageSystem storage, CIMObjectPath controllerPath) {
    Map<String, CIMObjectPath> initiatorPortPaths = new HashMap<String, CIMObjectPath>();
    CloseableIterator<CIMInstance> iterator = null;
    try {
        WBEMClient client = getConnection(storage).getCimClient();
        iterator = client.associatorInstances(controllerPath, CP_SHWID_TO_SPC, CP_STORAGE_HARDWARE_ID, null, null, false, PS_STORAGE_ID);
        while (iterator.hasNext()) {
            CIMInstance cimInstance = iterator.next();
            String initiator = CIMPropertyFactory.getPropertyValue(cimInstance, CP_STORAGE_ID);
            initiatorPortPaths.put(Initiator.normalizePort(initiator), cimInstance.getObjectPath());
        }
    } catch (WBEMException we) {
        _log.error("Caught an error while attempting to get initiator list from " + "masking instance", we);
    } finally {
        if (iterator != null) {
            iterator.close();
        }
    }
    return initiatorPortPaths;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CIMObjectPath(javax.cim.CIMObjectPath) WBEMClient(javax.wbem.client.WBEMClient) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance)

Aggregations

WBEMClient (javax.wbem.client.WBEMClient)110 CIMObjectPath (javax.cim.CIMObjectPath)75 CIMInstance (javax.cim.CIMInstance)69 WBEMException (javax.wbem.WBEMException)42 ArrayList (java.util.ArrayList)39 URI (java.net.URI)35 DbClient (com.emc.storageos.db.client.DbClient)29 Volume (com.emc.storageos.db.client.model.Volume)29 CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)27 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)25 HashSet (java.util.HashSet)25 CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)24 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)18 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)18 HashMap (java.util.HashMap)17 ExportMask (com.emc.storageos.db.client.model.ExportMask)16 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)16 CIMProperty (javax.cim.CIMProperty)14 UnsignedInteger32 (javax.cim.UnsignedInteger32)14 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)13