Search in sources :

Example 11 with CimConnection

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

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

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

Example 14 with CimConnection

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

the class XIVSmisStorageDevicePostProcessor method processVolumeDeletion.

/**
 * Update DB with SMI-S output, also set task completer status.
 */
public List<Volume> processVolumeDeletion(StorageSystem storageSystem, List<Volume> volumes, CIMArgument[] outArgs, MultiVolumeTaskCompleter multiVolumeTaskCompleter) throws Exception {
    CimConnection connection = _cimConnection.getConnection(storageSystem);
    WBEMClient client = connection.getCimClient();
    List<Volume> volumesToProcess = new ArrayList<Volume>();
    for (Volume vol : volumes) {
        Volume volume = _dbClient.queryObject(Volume.class, vol.getId());
        volumesToProcess.add(volume);
        StoragePool storagePool = _dbClient.queryObject(StoragePool.class, volume.getPool());
        updateStoragePoolCapacity(client, storagePool);
    }
    StringBuilder logMsgBuilder = new StringBuilder();
    UnsignedInteger32[] returnCoedes = (UnsignedInteger32[]) _cimPath.getFromOutputArgs(outArgs, IBMSmisConstants.CP_RETURN_CODES);
    List<Volume> volumesToSave = new ArrayList<Volume>(returnCoedes.length);
    for (int i = 0; i < returnCoedes.length; i++) {
        Volume volume = volumesToProcess.get(i);
        VolumeTaskCompleter deleteTaskCompleter = multiVolumeTaskCompleter.skipTaskCompleter(volume.getId());
        if (returnCoedes[i].longValue() == 0L) {
            volume.setInactive(true);
            volume.setConsistencyGroup(NullColumnValueGetter.getNullURI());
            _dbClient.updateAndReindexObject(volume);
            deleteTaskCompleter.ready(_dbClient);
            if (logMsgBuilder.length() != 0) {
                logMsgBuilder.append("\n");
            }
            logMsgBuilder.append(String.format("Successfully deleted volume %s", volume.getId()));
        } else {
            // cannot delete volume
            String errorMessage = String.format("Failed to delete volume: %s , nativeId: %s with return code: %s", volume.getId(), volume.getNativeId(), returnCoedes[i].toString());
            ServiceError error = DeviceControllerErrors.smis.methodFailed("doDeleteVolume", errorMessage);
            deleteTaskCompleter.error(_dbClient, error);
            if (logMsgBuilder.length() != 0) {
                logMsgBuilder.append("\n");
            }
            logMsgBuilder.append(errorMessage);
        }
    }
    if (logMsgBuilder.length() > 0) {
        _log.info(logMsgBuilder.toString());
    }
    return volumesToSave;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) ArrayList(java.util.ArrayList) UnsignedInteger32(javax.cim.UnsignedInteger32) VolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter) MultiVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter) Volume(com.emc.storageos.db.client.model.Volume) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) WBEMClient(javax.wbem.client.WBEMClient)

Example 15 with CimConnection

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

the class XIVSmisStorageDevicePostProcessor method processVolumeExpansion.

/**
 * Update DB with SMI-S output.
 */
public void processVolumeExpansion(StorageSystem storageSystem, URI storagePoolURI, URI volumeId, CIMArgument[] outArgs) throws Exception {
    StringBuilder logMsgBuilder = new StringBuilder(String.format("Processing volume expansion - "));
    CimConnection connection = _cimConnection.getConnection(storageSystem);
    WBEMClient client = connection.getCimClient();
    StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolURI);
    StringMap reservationMap = storagePool.getReservedCapacityMap();
    reservationMap.remove(volumeId.toString());
    updateStoragePoolCapacity(client, storagePool);
    _dbClient.persistObject(storagePool);
    Volume volume = _dbClient.queryObject(Volume.class, volumeId);
    CIMObjectPath volumePath = (CIMObjectPath) _cimPath.getFromOutputArgs(outArgs, IBMSmisConstants.CP_THE_ELEMENT);
    boolean isSuccess = false;
    if (volumePath != null) {
        CIMInstance volumeInstance = client.getInstance(volumePath, true, false, null);
        if (volumeInstance != null) {
            isSuccess = true;
            volume.setProvisionedCapacity(getProvisionedCapacityInformation(volumeInstance));
            volume.setAllocatedCapacity(getAllocatedCapacityInformation(client, volumeInstance));
            _dbClient.persistObject(volume);
            logMsgBuilder.append(String.format("%n   Capacity: %s, Provisioned capacity: %s, Allocated Capacity: %s", volume.getCapacity(), volume.getProvisionedCapacity(), volume.getAllocatedCapacity()));
        }
    }
    if (!isSuccess) {
        UnsignedInteger32 returnCoede = (UnsignedInteger32) _cimPath.getFromOutputArgs(outArgs, IBMSmisConstants.CP_RETURN_CODE);
        logMsgBuilder.append("\n");
        logMsgBuilder.append(String.format("Failed to expand volume: %s with return code: %s", volume.getId(), returnCoede.toString()));
    }
    _log.info(logMsgBuilder.toString());
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) StoragePool(com.emc.storageos.db.client.model.StoragePool) Volume(com.emc.storageos.db.client.model.Volume) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) CIMObjectPath(javax.cim.CIMObjectPath) UnsignedInteger32(javax.cim.UnsignedInteger32) WBEMClient(javax.wbem.client.WBEMClient) CIMInstance(javax.cim.CIMInstance)

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