Search in sources :

Example 6 with CimConnection

use of com.emc.storageos.cimadapter.connections.cim.CimConnection 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 7 with CimConnection

use of com.emc.storageos.cimadapter.connections.cim.CimConnection in project coprhd-controller by CoprHD.

the class XIVExportOperations method createSMISExportMask.

private void createSMISExportMask(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("{} createExportMask START...", storage.getLabel());
    try {
        _log.info("createExportMask: Export mask id: {}", exportMaskURI);
        _log.info("createExportMask: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
        _log.info("createExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
        _log.info("createExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
        CIMInstance controllerInst = null;
        boolean createdBySystem = true;
        Map<String, Initiator> initiatorMap = _helper.getInitiatorMap(initiatorList);
        String[] initiatorNames = initiatorMap.keySet().toArray(new String[] {});
        List<Initiator> userAddedInitiators = new ArrayList<Initiator>();
        Map<String, CIMObjectPath> existingHwStorageIds = getStorageHardwareIds(storage);
        // note - the initiator list maybe just a subset of all initiators on a host, need to
        // get all the initiators from the host, and check here
        // a special case is that there is a host on array side with i1 and i2,
        // while there is a host with initiator i2 and i3 on ViPR side,
        // we will not be able to match the two hosts if there is common initiator(s)
        // if an HBA get moved from one host to another, it need to be removed on array side manually
        List<Initiator> allInitiators;
        Host host = null;
        Initiator firstInitiator = initiatorList.get(0);
        String label;
        if (initiatorList.get(0).getHost() != null) {
            allInitiators = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Initiator.class, ContainmentConstraint.Factory.getContainedObjectsConstraint(firstInitiator.getHost(), Initiator.class, "host"));
            host = _dbClient.queryObject(Host.class, firstInitiator.getHost());
            label = host.getLabel();
        } else {
            allInitiators = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, Initiator.class, "hostname", firstInitiator.getHostName());
            label = firstInitiator.getHostName();
        }
        for (Initiator initiator : allInitiators) {
            String normalizedPortName = Initiator.normalizePort(initiator.getInitiatorPort());
            CIMObjectPath initiatorPath = existingHwStorageIds.get(normalizedPortName);
            if (initiatorPath != null) {
                _log.info(String.format("Initiator %s already exists", initiator.getInitiatorPort()));
                createdBySystem = false;
                // get controller instance
                controllerInst = getSCSIProtocolControllerInstanceByHwId(storage, initiatorPath);
                if (controllerInst == null) {
                    _log.debug("createExportMask failed. No protocol controller created.");
                    ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
                    taskCompleter.error(_dbClient, error);
                    _log.info("{} createExportMask END...", storage.getLabel());
                    return;
                }
                // get initiators
                Map<String, CIMObjectPath> initiatorPortPaths = _helper.getInitiatorsFromScsiProtocolController(storage, controllerInst.getObjectPath());
                Set<String> existingInitiatorPorts = initiatorPortPaths.keySet();
                // check if initiators need to be added
                List<String> initiatorsToAdd = new ArrayList<String>();
                for (String port : initiatorNames) {
                    if (!existingInitiatorPorts.contains(port)) {
                        initiatorsToAdd.add(port);
                        userAddedInitiators.add(initiatorMap.get(port));
                    }
                }
                if (!initiatorsToAdd.isEmpty()) {
                    // add initiator to host on array side
                    CIMObjectPath specificCollectionPath = getSystemSpecificCollectionPathByHwId(storage, initiatorPath);
                    CIMArgument[] outArgs = new CIMArgument[5];
                    _helper.addHardwareIDsToCollection(storage, specificCollectionPath, initiatorsToAdd.toArray(new String[] {}), outArgs);
                    if (outArgs[0] == null) {
                        Set<String> hwIds = hasHwIdsInCollection(storage, specificCollectionPath);
                        if (!hwIds.containsAll(initiatorsToAdd)) {
                            throw new Exception("Failed to add initiator: " + Joiner.on(',').join(initiatorsToAdd));
                        }
                    }
                }
                // same host/controller on both ViPR and array sides
                break;
            }
        }
        // no matched initiator on array side, now try to find host with the given name
        if (controllerInst == null) {
            String query = String.format("Select * From %s Where ElementName=\"%s\"", IBMSmisConstants.CP_SYSTEM_SPECIFIC_COLLECTION, label);
            CIMObjectPath hostPath = CimObjectPathCreator.createInstance(IBMSmisConstants.CP_SYSTEM_SPECIFIC_COLLECTION, Constants.IBM_NAMESPACE, null);
            List<CIMInstance> hostInstances = _helper.executeQuery(storage, hostPath, query, "WQL");
            if (!hostInstances.isEmpty()) {
                CIMObjectPath specificCollectionPath = hostInstances.get(0).getObjectPath();
                if (!hasHwIdInCollection(storage, specificCollectionPath)) {
                    createdBySystem = false;
                    userAddedInitiators = initiatorList;
                    // re-use the empty host
                    CIMArgument[] outArgs = new CIMArgument[5];
                    _helper.addHardwareIDsToCollection(storage, specificCollectionPath, initiatorNames, outArgs);
                    if (outArgs[0] == null) {
                        Set<String> hwIds = hasHwIdsInCollection(storage, specificCollectionPath);
                        if (!hwIds.containsAll(new ArrayList<String>(Arrays.asList(initiatorNames)))) {
                            throw new Exception("Failed to add initiator: " + Joiner.on(',').join(initiatorNames));
                        }
                    }
                    controllerInst = getSCSIProtocolControllerInstanceByIdCollection(storage, specificCollectionPath);
                    if (controllerInst == null) {
                        _log.debug("createExportMask failed. No protocol controller created.");
                        ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
                        taskCompleter.error(_dbClient, error);
                        _log.info("{} createExportMask END...", storage.getLabel());
                        return;
                    }
                }
            }
        }
        // create new protocol controller
        if (controllerInst == null) {
            // create host first so that the desired host label could be used
            CIMObjectPath sysSpecificCollectionPath = getSystemSpecificCollectionPath(storage, label, initiatorNames);
            if (sysSpecificCollectionPath == null) {
                _log.debug("createExportMask failed. No host created.");
                ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
                taskCompleter.error(_dbClient, error);
                _log.info("{} createExportMask END...", storage.getLabel());
                return;
            }
            controllerInst = getSCSIProtocolControllerInstanceByIdCollection(storage, sysSpecificCollectionPath);
        }
        if (controllerInst != null) {
            String elementName = CIMPropertyFactory.getPropertyValue(controllerInst, SmisConstants.CP_ELEMENT_NAME);
            // set host tag is needed
            if (host != null) {
                if (label.equals(elementName)) {
                    _helper.unsetTag(host, storage.getSerialNumber());
                } else {
                    _helper.setTag(host, storage.getSerialNumber(), elementName);
                }
            }
            CIMObjectPath controller = controllerInst.getObjectPath();
            ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
            if (!createdBySystem) {
                exportMask.setCreatedBySystem(createdBySystem);
                exportMask.addToUserCreatedInitiators(userAddedInitiators);
            }
            // SCSIProtocolController.ElementName
            exportMask.setMaskName(elementName);
            // is the same as
            // SystemSpecificCollection.ElementName
            exportMask.setLabel(elementName);
            CIMProperty<String> deviceId = (CIMProperty<String>) controller.getKey(IBMSmisConstants.CP_DEVICE_ID);
            exportMask.setNativeId(deviceId.getValue());
            _dbClient.persistObject(exportMask);
            CIMArgument[] inArgs = _helper.getExposePathsInputArguments(volumeURIHLUs, null, controller);
            CIMArgument[] outArgs = new CIMArgument[5];
            // don't care if the volumes/initiators have already been in the
            // mask
            _helper.invokeMethod(storage, _cimPath.getControllerConfigSvcPath(storage), IBMSmisConstants.EXPOSE_PATHS, inArgs, outArgs);
            CIMObjectPath[] protocolControllers = _cimPath.getProtocolControllersFromOutputArgs(outArgs);
            CIMObjectPath protocolController = protocolControllers[0];
            // for debug only
            if (_log.isDebugEnabled()) {
                List<String> targetEndpoints = getTargetEndpoints(protocolController, storage);
                _log.debug(String.format("ProtocolController %s with target ports: %s", protocolController.getObjectName(), Joiner.on(',').join(targetEndpoints)));
            }
            CimConnection cimConnection = _helper.getConnection(storage);
            // Call populateDeviceNumberFromProtocolControllers only after
            // initiators
            // have been added. HLU's will not be reported till the Device
            // is Host visible
            ExportMaskOperationsHelper.populateDeviceNumberFromProtocolControllers(_dbClient, cimConnection, exportMaskURI, volumeURIHLUs, protocolControllers, taskCompleter);
            taskCompleter.ready(_dbClient);
        } else {
            _log.debug("createExportMask failed. No protocol controller created.");
            ServiceError error = DeviceControllerErrors.smis.noProtocolControllerCreated();
            taskCompleter.error(_dbClient, error);
        }
    } catch (Exception e) {
        _log.error("Unexpected error: createExportMask failed.", e);
        ServiceError error = DeviceControllerErrors.smis.methodFailed("createExportMask", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
    _log.info("{} createExportMask END...", storage.getLabel());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) CIMObjectPath(javax.cim.CIMObjectPath) Host(com.emc.storageos.db.client.model.Host) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) Initiator(com.emc.storageos.db.client.model.Initiator) CIMProperty(javax.cim.CIMProperty) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) CIMArgument(javax.cim.CIMArgument)

Example 8 with CimConnection

use of com.emc.storageos.cimadapter.connections.cim.CimConnection 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 9 with CimConnection

use of com.emc.storageos.cimadapter.connections.cim.CimConnection 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 10 with CimConnection

use of com.emc.storageos.cimadapter.connections.cim.CimConnection in project coprhd-controller by CoprHD.

the class XIVSmisCommandHelper method getSGMembers.

/*
     * Get snapshot group members. Note the members may not be available.
     *
     * Called from IBMSmisSynchSubTaskJob
     */
public List<CIMObjectPath> getSGMembers(StorageSystem storageDevice, String sgName) throws WBEMException {
    CimConnection connection = getConnection(storageDevice);
    WBEMClient client = connection.getCimClient();
    CloseableIterator<CIMObjectPath> syncVolumeIter = null;
    List<CIMObjectPath> objectPaths = new ArrayList<CIMObjectPath>();
    try {
        // find out the real object path for the SG
        // workaround for provider bug (CTRL-8947, provider doesn't keep InstanceID of snapshot group constant)
        CIMObjectPath sgPath = _cimPath.getSnapshotGroupPath(storageDevice, sgName);
        if (sgPath == null) {
            return objectPaths;
        }
        syncVolumeIter = client.associatorNames(sgPath, IBMSmisConstants.CP_SNAPSHOT_GROUP_TO_ORDERED_MEMBERS, IBMSmisConstants.CP_STORAGE_VOLUME, null, null);
        while (syncVolumeIter.hasNext()) {
            CIMObjectPath syncVolumePath = syncVolumeIter.next();
            objectPaths.add(syncVolumePath);
            if (_log.isDebugEnabled()) {
                _log.debug("syncVolumePath - " + syncVolumePath);
            }
        }
    } finally {
        if (syncVolumeIter != null) {
            syncVolumeIter.close();
        }
    }
    return objectPaths;
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) WBEMClient(javax.wbem.client.WBEMClient)

Aggregations

CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)45 WBEMException (javax.wbem.WBEMException)24 WBEMClient (javax.wbem.client.WBEMClient)24 CIMObjectPath (javax.cim.CIMObjectPath)20 CIMInstance (javax.cim.CIMInstance)16 IOException (java.io.IOException)13 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 ArrayList (java.util.ArrayList)12 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)10 ConnectionManagerException (com.emc.storageos.cimadapter.connections.ConnectionManagerException)9 Volume (com.emc.storageos.db.client.model.Volume)8 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)8 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)6 CIMArgument (javax.cim.CIMArgument)6 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)5 URI (java.net.URI)5 BlockObject (com.emc.storageos.db.client.model.BlockObject)4 StoragePool (com.emc.storageos.db.client.model.StoragePool)4 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)3 ExportMask (com.emc.storageos.db.client.model.ExportMask)3