Search in sources :

Example 31 with WBEMClient

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

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

Example 33 with WBEMClient

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

the class SmisAbstractCreateVolumeJob method updateStatus.

/**
 * Called to update the job status when the volume create job completes.
 * <p/>
 * This is common update code for volume create operations.
 *
 * @param jobContext The job context.
 */
@Override
public void updateStatus(JobContext jobContext) throws Exception {
    CloseableIterator<CIMObjectPath> iterator = null;
    DbClient dbClient = jobContext.getDbClient();
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == JobStatus.IN_PROGRESS) {
            return;
        }
        int volumeCount = 0;
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, jobStatus.name()));
        CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
        WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
        iterator = client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
        Calendar now = Calendar.getInstance();
        // from pool's reserved capacity map.
        if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            SmisUtils.updateStoragePoolCapacity(dbClient, client, _storagePool);
            StoragePool pool = dbClient.queryObject(StoragePool.class, _storagePool);
            StringMap reservationMap = pool.getReservedCapacityMap();
            for (URI volumeId : getTaskCompleter().getIds()) {
                // remove from reservation map
                reservationMap.remove(volumeId.toString());
            }
            dbClient.persistObject(pool);
        }
        if (jobStatus == JobStatus.SUCCESS) {
            List<URI> volumes = new ArrayList<URI>();
            while (iterator.hasNext()) {
                CIMObjectPath volumePath = iterator.next();
                CIMProperty<String> deviceID = (CIMProperty<String>) volumePath.getKey(SmisConstants.CP_DEVICE_ID);
                String nativeID = deviceID.getValue();
                URI volumeId = getTaskCompleter().getId(volumeCount++);
                volumes.add(volumeId);
                persistVolumeNativeID(dbClient, volumeId, nativeID, now);
                processVolume(jobContext, volumePath, nativeID, volumeId, client, dbClient, logMsgBuilder, now);
            }
            // Add Volumes to Consistency Group (if needed)
            addVolumesToConsistencyGroup(jobContext, volumes);
        } else if (jobStatus == JobStatus.FAILED) {
            if (iterator.hasNext()) {
                while (iterator.hasNext()) {
                    CIMObjectPath volumePath = iterator.next();
                    CIMProperty<String> deviceID = (CIMProperty<String>) volumePath.getKey(SmisConstants.CP_DEVICE_ID);
                    String nativeID = deviceID.getValue();
                    URI volumeId = getTaskCompleter().getId(volumeCount++);
                    if ((nativeID != null) && (nativeID.length() != 0)) {
                        persistVolumeNativeID(dbClient, volumeId, nativeID, now);
                        processVolume(jobContext, volumePath, nativeID, volumeId, client, dbClient, logMsgBuilder, now);
                    } else {
                        logMsgBuilder.append("\n");
                        logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, volumeId));
                        Volume volume = dbClient.queryObject(Volume.class, volumeId);
                        volume.setInactive(true);
                        dbClient.persistObject(volume);
                    }
                }
            } else {
                for (URI id : getTaskCompleter().getIds()) {
                    logMsgBuilder.append("\n");
                    logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, id.toString()));
                    Volume volume = dbClient.queryObject(Volume.class, id);
                    volume.setInactive(true);
                    dbClient.persistObject(volume);
                }
            }
        }
        _log.info(logMsgBuilder.toString());
    } catch (Exception e) {
        _log.error("Caught an exception while trying to updateStatus for SmisCreateVolumeJob", e);
        setPostProcessingErrorStatus("Encountered an internal error during volume create job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
        if (iterator != null) {
            iterator.close();
        }
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) DbClient(com.emc.storageos.db.client.DbClient) StoragePool(com.emc.storageos.db.client.model.StoragePool) Calendar(java.util.Calendar) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) URI(java.net.URI) WBEMException(javax.wbem.WBEMException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) CIMProperty(javax.cim.CIMProperty) Volume(com.emc.storageos.db.client.model.Volume) WBEMClient(javax.wbem.client.WBEMClient)

Example 34 with WBEMClient

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

the class SmisBlockCreateCGMirrorJob method updateStatus.

public void updateStatus(JobContext jobContext) throws Exception {
    CloseableIterator<CIMInstance> syncVolumeIter = null;
    CloseableIterator<CIMObjectPath> repGroupPathIter = null;
    DbClient dbClient = jobContext.getDbClient();
    BlockMirrorCreateCompleter completer = (BlockMirrorCreateCompleter) getTaskCompleter();
    ;
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == JobStatus.IN_PROGRESS) {
            return;
        }
        CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
        WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
        List<BlockMirror> mirrors = dbClient.queryObject(BlockMirror.class, completer.getIds());
        if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            updatePools(client, dbClient, mirrors);
        }
        if (jobStatus == JobStatus.SUCCESS) {
            _log.info("Group mirror creation success");
            repGroupPathIter = client.associatorNames(getCimJob(), null, SmisConstants.SE_REPLICATION_GROUP, null, null);
            CIMObjectPath repGroupPath = repGroupPathIter.next();
            StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
            String repGroupID = (String) repGroupPath.getKey(SmisConstants.CP_INSTANCE_ID).getValue();
            repGroupID = SmisUtils.getTargetGroupName(repGroupID, storage.getUsingSmis80());
            CIMInstance syncInst = getSynchronizedInstance(client, repGroupPath);
            String syncType = CIMPropertyFactory.getPropertyValue(syncInst, SmisConstants.CP_SYNC_TYPE);
            syncVolumeIter = client.associatorInstances(repGroupPath, null, SmisConstants.CIM_STORAGE_VOLUME, null, null, false, _volumeProps);
            processCGMirrors(syncVolumeIter, client, dbClient, jobContext.getSmisCommandHelper(), storage, mirrors, repGroupID, syncInst.getObjectPath().toString(), syncType);
        } else if (isJobInTerminalFailedState()) {
            _log.info("Failed to create group mirrors");
            completer.error(dbClient, DeviceControllerException.exceptions.attachVolumeMirrorFailed(getMessage()));
            for (BlockMirror mirror : mirrors) {
                mirror.setInactive(true);
            }
            dbClient.persistObject(mirrors);
        }
    } catch (Exception e) {
        setPostProcessingErrorStatus("Encountered an internal error during block create CG mirror job status processing: " + e.getMessage());
        _log.error("Caught an exception while trying to updateStatus for SmisBlockCreateCGMirrorJob", e);
    } finally {
        if (syncVolumeIter != null) {
            syncVolumeIter.close();
        }
        if (repGroupPathIter != null) {
            repGroupPathIter.close();
        }
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) BlockMirror(com.emc.storageos.db.client.model.BlockMirror) CIMObjectPath(javax.cim.CIMObjectPath) BlockMirrorCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorCreateCompleter) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) WBEMClient(javax.wbem.client.WBEMClient) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 35 with WBEMClient

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

the class ValidateVolumeIdentity method validate.

@Override
public boolean validate() throws Exception {
    getLogger().setLog(log);
    for (Volume volume : volumes) {
        CIMObjectPath volumePath = getCimPath().getBlockObjectPath(system, volume);
        CimConnection connection = getHelper().getConnection(system);
        WBEMClient cimClient = connection.getCimClient();
        CIMInstance instance = cimClient.getInstance(volumePath, false, false, PROP_KEYS);
        checkForDifferences(instance, volume);
    }
    return getLogger().hasErrors();
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) CIMObjectPath(javax.cim.CIMObjectPath) CimConnection(com.emc.storageos.cimadapter.connections.cim.CimConnection) WBEMClient(javax.wbem.client.WBEMClient) 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