Search in sources :

Example 91 with WBEMClient

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

the class SmisCommandHelper method removeVolumeFromStorageGroupsIfVolumeIsNotInAnyMV.

/**
 * Removes the volume from storage groups if the volume is not in any Masking View.
 * This will be called just before deleting the volume (for VMAX2).
 *
 * @param storageSystem
 *            the storage system
 * @param volume
 *            the volume
 */
public void removeVolumeFromStorageGroupsIfVolumeIsNotInAnyMV(StorageSystem storage, BlockObject bo) {
    /**
     * If Volume is not associated with any MV, then remove the volume from its associated SGs.
     */
    CloseableIterator<CIMObjectPath> mvPathItr = null;
    CloseableIterator<CIMInstance> sgInstancesItr = null;
    boolean isSGInAnyMV = true;
    try {
        _log.info("Checking if device {} needs to be removed from Storage Groups which is not in any Masking View", bo.getNativeGuid());
        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()) {
            isSGInAnyMV = false;
        }
        if (!isSGInAnyMV) {
            _log.info("Device {} is not in any Masking View, hence removing it from Storage Groups if any", bo.getNativeGuid());
            boolean forceFlag = ExportUtils.useEMCForceFlag(_dbClient, bo.getId());
            // Get all the storage groups associated with this volume
            sgInstancesItr = getAssociatorInstances(storage, volumePath, null, SmisConstants.SE_DEVICE_MASKING_GROUP, null, null, PS_ELEMENT_NAME);
            while (sgInstancesItr.hasNext()) {
                CIMInstance sgPath = sgInstancesItr.next();
                String storageGroupName = CIMPropertyFactory.getPropertyValue(sgPath, SmisConstants.CP_ELEMENT_NAME);
                // Double check: check if SG is part of MV
                if (!checkStorageGroupInAnyMaskingView(storage, sgPath.getObjectPath())) {
                    // if last volume, dis-associate FAST
                    int sgVolumeCount = getVMAXStorageGroupVolumeCount(storage, storageGroupName);
                    if (sgVolumeCount == 1) {
                        WBEMClient client = getConnection(storage).getCimClient();
                        removeVolumeGroupFromPolicyAndLimitsAssociation(client, storage, sgPath.getObjectPath());
                    }
                    removeVolumesFromStorageGroup(storage, storageGroupName, Collections.singletonList(bo.getId()), forceFlag);
                    // If there was only one volume in the SG, it would be empty after removing that last volume.
                    if (sgVolumeCount == 1) {
                        _log.info("Deleting Empty Storage Group {}", storageGroupName);
                        deleteMaskingGroup(storage, storageGroupName, SmisCommandHelper.MASKING_GROUP_TYPE.SE_DeviceMaskingGroup);
                    }
                }
            }
        } else {
            _log.info("Found that Device {} is part of Masking View {}", bo.getNativeGuid(), mvPathItr.next());
        }
    } catch (Exception e) {
        _log.warn("Exception while trying to remove device {} from Storage Groups which is not in any Masking View", bo.getNativeGuid(), e);
    } finally {
        closeCIMIterator(mvPathItr);
        closeCIMIterator(sgInstancesItr);
    }
}
Also used : CIMObjectPath(javax.cim.CIMObjectPath) WBEMClient(javax.wbem.client.WBEMClient) CIMInstance(javax.cim.CIMInstance) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) 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)

Example 92 with WBEMClient

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

the class SmisCommandHelper method getInstances.

/**
 * This is a 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
 */
public 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 93 with WBEMClient

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

the class SmisCommandHelper method checkConnectionliveness.

public boolean checkConnectionliveness(StorageSystem storageDevice) {
    boolean isLive = false;
    try {
        CimConnection connection = getConnection(storageDevice);
        WBEMClient client = connection.getCimClient();
        // Call the provider to get computer systems.
        client.enumerateInstanceNames(_cop);
        isLive = true;
    } catch (Exception wbemEx) {
        _log.error("Invalid connection found for Provider: {}", storageDevice.getActiveProviderURI());
    }
    return isLive;
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) WBEMClient(javax.wbem.client.WBEMClient) 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)

Example 94 with WBEMClient

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

the class IBMCIMObjectPathFactory method executeQuery.

/**
 * Executes query
 *
 * @param storageSystem
 * @param query
 * @param queryLanguage
 * @return list of matched instances
 */
public List<CIMInstance> executeQuery(StorageSystem storageSystem, CIMObjectPath objectPath, String query, String queryLanguage) {
    CloseableIterator<CIMInstance> iterator = null;
    CimConnection connection = _cimConnection.getConnection(storageSystem);
    WBEMClient client = connection.getCimClient();
    _log.info(String.format("Executing query: %s, objectPath: %s, query language: %s", query, objectPath, queryLanguage));
    List<CIMInstance> instanceList = new ArrayList<CIMInstance>();
    try {
        iterator = client.execQuery(objectPath, query, queryLanguage);
        while (iterator.hasNext()) {
            CIMInstance instance = iterator.next();
            instanceList.add(instance);
        }
    } catch (WBEMException we) {
        _log.error("Caught an error while attempting to execute query and process query result. Query: " + query, we);
    } finally {
        if (iterator != null) {
            iterator.close();
        }
    }
    return instanceList;
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) ArrayList(java.util.ArrayList) WBEMClient(javax.wbem.client.WBEMClient) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance)

Example 95 with WBEMClient

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

the class XIVSmisCommandHelper method getInstance.

/*
     * Return CIM instance of the given object path.
     */
public CIMInstance getInstance(StorageSystem storage, CIMObjectPath objectPath, boolean propagated, boolean includeClassOrigin, String[] propertyList) throws Exception {
    CimConnection connection = _cimConnection.getConnection(storage);
    WBEMClient client = connection.getCimClient();
    // CTRL-9069 workaround CIM_BAD_REQUEST error
    CIMInstance instance = null;
    int retryCount = 0;
    while (true) {
        try {
            _log.info("Calling getInstance, attempt {}", retryCount);
            instance = client.getInstance(objectPath, propagated, includeClassOrigin, propertyList);
        } catch (WBEMException e) {
            if (CIM_BAD_REQUEST.equals(e.getMessage())) {
                if (retryCount < CIM_MAX_RETRY_COUNT) {
                    _log.warn("Encountered 'request-not-well-formed' error. Retry...");
                    retryCount++;
                    try {
                        Thread.sleep(CIM_RETRY_WAIT_INTERVAL);
                    } catch (InterruptedException ie) {
                        _log.warn("Thread: " + Thread.currentThread().getName() + " interrupted.");
                        throw e;
                    }
                    continue;
                }
                _log.warn("Exhausted {} retries", CIM_MAX_RETRY_COUNT);
            }
            // other WBEMException, or reach the max retry count
            throw e;
        }
        // no exception
        break;
    }
    return instance;
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) 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