Search in sources :

Example 26 with WBEMClient

use of javax.wbem.client.WBEMClient 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)

Example 27 with WBEMClient

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

the class XIVSmisCommandHelper method getStoragePortsFromScsiProtocolController.

/**
 * Given a CIMInstance of a IBMTSDS_SCSIProtocolController return a list of storage ports that
 * it references.
 *
 * @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 List of port name String values. The WWNs will have colons separating the hex digits.
 */
public List<String> getStoragePortsFromScsiProtocolController(StorageSystem storage, CIMObjectPath controllerPath) {
    List<String> storagePorts = new ArrayList<String>();
    CloseableIterator<CIMObjectPath> iterator = null;
    try {
        WBEMClient client = getConnection(storage).getCimClient();
        iterator = client.associatorNames(controllerPath, null, CIM_PROTOCOL_ENDPOINT, null, null);
        while (iterator.hasNext()) {
            CIMObjectPath endpointPath = iterator.next();
            String portName = endpointPath.getKeyValue(CP_NAME).toString();
            String fixedName = Initiator.toPortNetworkId(portName);
            storagePorts.add(fixedName);
        }
    } catch (WBEMException we) {
        _log.error("Caught an error while attempting to get storage ports from " + "masking instance", we);
    } finally {
        if (iterator != null) {
            iterator.close();
        }
    }
    return storagePorts;
}
Also used : ArrayList(java.util.ArrayList) CIMObjectPath(javax.cim.CIMObjectPath) WBEMClient(javax.wbem.client.WBEMClient) WBEMException(javax.wbem.WBEMException)

Example 28 with WBEMClient

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

the class XIVSmisCommandHelper method invokeMethod.

/**
 * Invoke CIM method.
 */
@SuppressWarnings("rawtypes")
public void invokeMethod(StorageSystem storageDevice, CIMObjectPath objectPath, String methodName, CIMArgument[] inArgs, CIMArgument[] outArgs) throws Exception {
    CimConnection connection = getConnection(storageDevice);
    WBEMClient client = connection.getCimClient();
    int index = 0;
    StringBuilder inputInfoBuffer = new StringBuilder();
    inputInfoBuffer.append("\nSMI-S Provider: ").append(connection.getHost()).append(" -- Attempting invokeMethod ").append(methodName).append(" on\n").append("  objectPath=").append(objectPath.toString()).append(" with arguments: \n");
    for (CIMArgument arg : inArgs) {
        inputInfoBuffer.append("    inArg[").append(index++).append("]=").append(arg.toString()).append('\n');
    }
    _log.info(inputInfoBuffer.toString());
    long start = System.nanoTime();
    // workaround for CTRL-8024 (CIMError: "request-not-well-formed" ...)
    // retry CIM_MAX_RETRY_COUNT times if encounter the error
    // the invoke method will return quickly with the error, so extensive retry (e.g., 25 times), won't be a big overhead
    Object obj = null;
    int retryCount = 0;
    while (true) {
        try {
            _log.info("Invoke method {}, attempt {}", methodName, retryCount);
            obj = client.invokeMethod(objectPath, methodName, inArgs, outArgs);
        } 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;
    }
    String total = String.format("%2.6f", ((System.nanoTime() - start) / 1000000000.0));
    StringBuilder outputInfoBuffer = new StringBuilder();
    outputInfoBuffer.append("\nSMI-S Provider: ").append(connection.getHost()).append(" -- Completed invokeMethod ").append(methodName).append(" on\n").append("  objectPath=").append(objectPath.toString()).append("\n  Returned: ").append(obj.toString()).append(" with output arguments: \n");
    int returnCode = NumberUtils.toInt(obj.toString(), INVALID_RETURN_CODE);
    for (CIMArgument arg : outArgs) {
        if (arg != null) {
            if (returnCode == CIM_SUCCESS_CODE) {
                outputInfoBuffer.append("    outArg=").append(arg.toString()).append('\n');
            } else {
                outputInfoBuffer.append("    outArg=").append(arg.getName()).append("=").append(arg.getValue()).append(" (Type ").append(arg.getDataType()).append(")\n");
            }
        }
    }
    outputInfoBuffer.append("  Execution time: ").append(total).append(" seconds.\n");
    _log.info(outputInfoBuffer.toString());
    if (returnCode == CIM_MAPPING_NOT_DEFINED && methodName.equals(HIDE_PATHS)) {
    // ignore the error
    } else if (returnCode == this.CIM_DUPLICATED_HOST_NAME && methodName.equals(CREATE_HARDWARE_ID_COLLECTION)) {
        outArgs[0] = null;
    } else if (returnCode == this.CIM_OPERATION_PARTIALLY_SUCCEEDED && methodName.equals(ADD_HARDWARE_IDS_TO_COLLECTION)) {
        outArgs[0] = null;
    } else if (returnCode == CIM_DUPLICATED_CG_NAME_CODE) {
        throw new Exception(DUPLICATED_CG_NAME_ERROR);
    } else if (returnCode == CIM_ONLY_ALLOWED_ON_EMPTY_CG_CODE && methodName.equals(REMOVE_MEMBERS)) {
        // after this call
        throw new Exception("Failed with return code: " + obj);
    } else if (returnCode != CIM_SUCCESS_CODE && methodName.equals(CREATE_OR_MODIFY_ELEMENTS_FROM_STORAGE_POOL) && checkIfVolumeSizeExceedingPoolSize(inArgs, outArgs)) {
        throw DeviceControllerException.exceptions.volumeSizeExceedingPoolSize(getVolumeName(inArgs));
    } else if (returnCode != CIM_SUCCESS_CODE) {
        throw new Exception("Failed with return code: " + obj);
    }
}
Also used : CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) BlockObject(com.emc.storageos.db.client.model.BlockObject) DataObject(com.emc.storageos.db.client.model.DataObject) WBEMClient(javax.wbem.client.WBEMClient) WBEMException(javax.wbem.WBEMException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) CIMArgument(javax.cim.CIMArgument)

Example 29 with WBEMClient

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

the class XIVSmisStorageDevicePostProcessor method processSnapshotCreation.

@SuppressWarnings("rawtypes")
public void processSnapshotCreation(StorageSystem storageSystem, URI snapshotURI, boolean wantSyncActive, CIMArgument[] outArgs, BlockSnapshotCreateCompleter taskCompleter) throws Exception {
    StringBuilder logMsgBuilder = new StringBuilder(String.format("Processing snapshot creation - "));
    CimConnection connection = _cimConnection.getConnection(storageSystem);
    WBEMClient client = connection.getCimClient();
    BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotURI);
    CIMObjectPath syncVolumePath = (CIMObjectPath) _cimPath.getFromOutputArgs(outArgs, IBMSmisConstants.CP_TARGET_ELEMENT);
    if (syncVolumePath != null) {
        // Get the sync volume native device id
        CIMInstance syncVolume = client.getInstance(syncVolumePath, false, false, null);
        String syncDeviceID = syncVolumePath.getKey(IBMSmisConstants.CP_DEVICE_ID).getValue().toString();
        String elementName = CIMPropertyFactory.getPropertyValue(syncVolume, IBMSmisConstants.CP_ELEMENT_NAME);
        String wwn = CIMPropertyFactory.getPropertyValue(syncVolume, IBMSmisConstants.CP_NAME);
        snapshot.setNativeId(syncDeviceID);
        snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
        snapshot.setLabel(elementName);
        snapshot.setDeviceLabel(elementName);
        snapshot.setInactive(false);
        snapshot.setIsSyncActive(wantSyncActive);
        snapshot.setCreationTime(Calendar.getInstance());
        snapshot.setWWN(wwn.toUpperCase());
        snapshot.setAlternateName(wwn);
        snapshot.setProvisionedCapacity(getProvisionedCapacityInformation(syncVolume));
        snapshot.setAllocatedCapacity(getAllocatedCapacityInformation(client, syncVolume));
        logMsgBuilder.append(String.format("For sync volume path %1$s, going to set blocksnapshot %2$s nativeId to %3$s.", syncVolumePath.toString(), snapshot.getId().toString(), syncDeviceID));
        taskCompleter.ready(_dbClient);
    } else {
        snapshot.setInactive(true);
        ServiceError error = DeviceControllerErrors.smis.unableToFindSynchPath("");
        logMsgBuilder.append("Failed due to no target element path");
        taskCompleter.error(_dbClient, error);
    }
    _dbClient.persistObject(snapshot);
    _log.info(logMsgBuilder.toString());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CIMObjectPath(javax.cim.CIMObjectPath) WBEMClient(javax.wbem.client.WBEMClient) CIMInstance(javax.cim.CIMInstance)

Example 30 with WBEMClient

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

the class XIVSmisStorageDevicePostProcessor method processCGSnapshotCreation.

@SuppressWarnings("rawtypes")
public void processCGSnapshotCreation(StorageSystem storageSystem, List<URI> snapshotURIs, boolean wantSyncActive, String snapshotGroupName, BlockSnapshotCreateCompleter taskCompleter) throws Exception {
    _log.info("Processing CG snapshot creation");
    CloseableIterator<CIMObjectPath> volumeIter = null;
    CimConnection connection = _cimConnection.getConnection(storageSystem);
    WBEMClient client = connection.getCimClient();
    try {
        List<BlockSnapshot> snapshots = _dbClient.queryObject(BlockSnapshot.class, taskCompleter.getSnapshotURIs());
        // Create mapping of volume.nativeDeviceId to BlockSnapshot object
        Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
        for (BlockSnapshot snapshot : snapshots) {
            Volume volume = _dbClient.queryObject(Volume.class, snapshot.getParent());
            volumeToSnapMap.put(volume.getNativeId(), snapshot);
        }
        // Iterate through the snapshot elements and try to match them up
        // with the appropriate BlockSnapshot
        // Note, NULL_IBM_CIM_OBJECT_PATH is used here. The snapshot group object will be looked up by snapshot group name
        List<CIMObjectPath> objectPaths = _helper.getSGMembers(storageSystem, SmisConstants.NULL_IBM_CIM_OBJECT_PATH, snapshotGroupName, snapshotURIs.size());
        List<BlockSnapshot> objectsToSave = new ArrayList<BlockSnapshot>(snapshotURIs.size());
        Calendar now = Calendar.getInstance();
        for (CIMObjectPath syncVolumePath : objectPaths) {
            CIMInstance syncVolume = client.getInstance(syncVolumePath, false, false, null);
            String syncDeviceID = syncVolumePath.getKey(IBMSmisConstants.CP_DEVICE_ID).getValue().toString();
            String elementName = CIMPropertyFactory.getPropertyValue(syncVolume, IBMSmisConstants.CP_ELEMENT_NAME);
            // Get the associated volume for this sync volume
            CIMObjectPath volumePath = null;
            volumeIter = client.associatorNames(syncVolumePath, null, IBMSmisConstants.CIM_STORAGE_VOLUME, null, null);
            volumePath = volumeIter.next();
            if (_log.isDebugEnabled()) {
                _log.debug("volumePath - " + volumePath);
            }
            volumeIter.close();
            String volumeDeviceID = volumePath.getKey(IBMSmisConstants.CP_DEVICE_ID).getValue().toString();
            String wwn = CIMPropertyFactory.getPropertyValue(syncVolume, IBMSmisConstants.CP_NAME);
            String alternativeName = wwn;
            // Lookup the associated snapshot based on the volume native
            // device id
            BlockSnapshot snapshot = volumeToSnapMap.get(volumeDeviceID);
            if (snapshot != null) {
                snapshot.setNativeId(syncDeviceID);
                snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
                snapshot.setReplicationGroupInstance(snapshotGroupName);
                snapshot.setLabel(elementName);
                snapshot.setDeviceLabel(elementName);
                snapshot.setInactive(false);
                snapshot.setIsSyncActive(wantSyncActive);
                snapshot.setCreationTime(now);
                snapshot.setWWN(wwn.toUpperCase());
                snapshot.setAlternateName(alternativeName);
                snapshot.setProvisionedCapacity(getProvisionedCapacityInformation(syncVolume));
                snapshot.setAllocatedCapacity(getAllocatedCapacityInformation(client, syncVolume));
                _log.info(String.format("For sync volume path %1$s, going to set blocksnapshot %2$s nativeId to %3$s (%4$s). " + "Replication Group instance is %5$s. Associated volume is %6$s", syncVolumePath.toString(), snapshot.getId().toString(), syncDeviceID, elementName, snapshotGroupName, volumePath.toString()));
                objectsToSave.add(snapshot);
            }
        }
        if (!objectsToSave.isEmpty()) {
            _dbClient.persistObject(objectsToSave);
            taskCompleter.ready(_dbClient);
        } else {
            _log.info("Failed to create snapshot");
            for (BlockSnapshot snapshot : snapshots) {
                snapshot.setInactive(true);
            }
            _dbClient.persistObject(snapshots);
            ServiceError error = DeviceControllerErrors.smis.noBlockSnapshotsFound();
            taskCompleter.error(_dbClient, error);
        }
    } catch (Exception e) {
        _log.error("Caught an exception while trying to process CG snapshotCreation", e);
        throw e;
    } finally {
        if (volumeIter != null) {
            volumeIter.close();
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) Calendar(java.util.Calendar) CIMObjectPath(javax.cim.CIMObjectPath) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) IOException(java.io.IOException) Volume(com.emc.storageos.db.client.model.Volume) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) WBEMClient(javax.wbem.client.WBEMClient)

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