Search in sources :

Example 31 with CIMConnectionFactory

use of com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory in project coprhd-controller by CoprHD.

the class SmisBlockCreateMirrorJob method updateStatus.

@Override
public void updateStatus(JobContext jobContext) throws Exception {
    CloseableIterator<CIMObjectPath> syncVolumeIter = null;
    DbClient dbClient = jobContext.getDbClient();
    BlockMirrorCreateCompleter completer = null;
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == JobStatus.IN_PROGRESS) {
            return;
        }
        completer = (BlockMirrorCreateCompleter) getTaskCompleter();
        BlockMirror mirror = dbClient.queryObject(BlockMirror.class, completer.getMirrorURI());
        StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
        CIMConnectionFactory cimConnectionFactory;
        WBEMClient client = null;
        // from pool's reserved capacity map.
        if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            cimConnectionFactory = jobContext.getCimConnectionFactory();
            client = getWBEMClient(dbClient, cimConnectionFactory);
            URI poolURI = mirror.getPool();
            SmisUtils.updateStoragePoolCapacity(dbClient, client, poolURI);
            StoragePool pool = dbClient.queryObject(StoragePool.class, poolURI);
            StringMap reservationMap = pool.getReservedCapacityMap();
            // remove from reservation map
            reservationMap.remove(mirror.getId().toString());
            dbClient.persistObject(pool);
        }
        if (jobStatus == JobStatus.SUCCESS) {
            _log.info("Mirror creation success");
            cimConnectionFactory = jobContext.getCimConnectionFactory();
            client = getWBEMClient(dbClient, cimConnectionFactory);
            syncVolumeIter = client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
            if (syncVolumeIter.hasNext()) {
                // Get the target mirror volume native device id
                CIMObjectPath targetVolumePath = syncVolumeIter.next();
                CIMInstance syncVolume = client.getInstance(targetVolumePath, false, false, null);
                String syncDeviceID = targetVolumePath.getKey(SmisConstants.CP_DEVICE_ID).getValue().toString();
                String elementName = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_ELEMENT_NAME);
                String wwn = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_WWN_NAME);
                String alternateName = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_NAME);
                CIMInstance syncInstance = getStorageSyncInstanceFromVolume(client, targetVolumePath);
                // Lookup the associated source volume based on the volume native device id
                mirror.setProvisionedCapacity(getProvisionedCapacityInformation(client, syncVolume));
                mirror.setAllocatedCapacity(getAllocatedCapacityInformation(client, syncVolume));
                mirror.setWWN(wwn);
                mirror.setAlternateName(alternateName);
                mirror.setNativeId(syncDeviceID);
                mirror.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, mirror));
                mirror.setDeviceLabel(elementName);
                mirror.setInactive(false);
                mirror.setSynchronizedInstance(syncInstance.getObjectPath().toString());
                updateSynchronizationAspects(client, mirror);
                // mirror.setIsSyncActive(_wantSyncActive);
                Volume volume = dbClient.queryObject(Volume.class, mirror.getSource().getURI());
                _log.info(String.format("For target mirror volume %1$s, going to set BlockMirror %2$s nativeId to %3$s (%4$s). Associated volume is %5$s (%6$s)", targetVolumePath.toString(), mirror.getId().toString(), syncDeviceID, elementName, volume.getNativeId(), volume.getDeviceLabel()));
                dbClient.persistObject(mirror);
            }
        } else if (isJobInTerminalFailedState()) {
            _log.info("Failed to create mirror");
            completer.error(dbClient, DeviceControllerException.exceptions.attachVolumeMirrorFailed(getMessage()));
            mirror.setInactive(true);
            dbClient.persistObject(mirror);
        }
    } catch (Exception e) {
        setFatalErrorStatus("Encountered an internal error during block create mirror job status processing: " + e.getMessage());
        _log.error("Caught an exception while trying to updateStatus for SmisBlockCreateMirrorJob", e);
        if (completer != null) {
            completer.error(dbClient, DeviceControllerException.errors.jobFailed(e));
        }
    } finally {
        if (syncVolumeIter != null) {
            syncVolumeIter.close();
        }
        super.updateStatus(jobContext);
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) DbClient(com.emc.storageos.db.client.DbClient) BlockMirror(com.emc.storageos.db.client.model.BlockMirror) StoragePool(com.emc.storageos.db.client.model.StoragePool) CIMObjectPath(javax.cim.CIMObjectPath) BlockMirrorCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorCreateCompleter) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) Volume(com.emc.storageos.db.client.model.Volume) WBEMClient(javax.wbem.client.WBEMClient) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 32 with CIMConnectionFactory

use of com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory in project coprhd-controller by CoprHD.

the class DataCollectionTest method setup.

@Before
public void setup() {
    try {
        for (Lock lock : Lock.values()) {
            Method method = lock.getClass().getDeclaredMethod("setLock", InterProcessLock.class);
            method.setAccessible(true);
            Object[] parameters = new Object[1];
            parameters[0] = _coordinator.getLock(lock.name());
            method.invoke(lock, parameters);
        }
        _dbClient.start();
        if (_provider != null) {
            String providerKey = _provider.getIPAddress() + "-" + _provider.getPortNumber();
            List<StorageProvider> providers = CustomQueryUtility.getActiveStorageProvidersByProviderId(_dbClient, providerKey);
            if (providers != null && !providers.isEmpty()) {
                _providerURI = providers.get(0).getId();
                _logger.warn("Provider has already been in db.");
            } else if (isTestNewProvider) {
                _providerURI = URIUtil.createId(StorageProvider.class);
                _provider.setId(_providerURI);
                _dbClient.createObject(_provider);
            }
        }
        CIMConnectionFactory cimConnectionFactory = new CIMConnectionFactory();
        cimConnectionFactory.setDbClient(_dbClient);
        cimConnectionFactory.setConnectionManager(_connectionManager);
        DataCollectionJobScheduler scheduler = new DataCollectionJobScheduler();
        scheduler.setConfigInfo(_configInfo);
        scheduler.setConnectionFactory(cimConnectionFactory);
        scheduler.setCoordinator(_coordinator);
        scheduler.setDbClient(_dbClient);
        _jobUtil = new DataCollectionJobUtil();
        _jobUtil.setDbClient(_dbClient);
        _jobUtil.setConfigInfo(_configInfo);
        _jobConsumer = new TestDataCollectionJobConsumer();
        _jobConsumer.setConfigInfo(_configInfo);
        _jobConsumer.setConnectionFactory(cimConnectionFactory);
        _jobConsumer.setCoordinator(_coordinator);
        _jobConsumer.setDbClient(_dbClient);
        _jobConsumer.setUtil(_jobUtil);
        _jobConsumer.setJobScheduler(scheduler);
        VersionChecker versionChecker = new VersionChecker();
        versionChecker.setCoordinator(_coordinator);
    } catch (Exception e) {
        _logger.error("Failed to run setup. Exception - " + e.getMessage());
        _logger.error(e.getMessage(), e);
    }
}
Also used : Method(java.lang.reflect.Method) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) Lock(com.emc.storageos.volumecontroller.impl.ControllerServiceImpl.Lock) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) VersionChecker(com.emc.storageos.util.VersionChecker) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) DataObject(com.emc.storageos.db.client.model.DataObject) Before(org.junit.Before)

Aggregations

CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)32 DbClient (com.emc.storageos.db.client.DbClient)28 WBEMClient (javax.wbem.client.WBEMClient)27 CIMObjectPath (javax.cim.CIMObjectPath)18 Volume (com.emc.storageos.db.client.model.Volume)14 CIMInstance (javax.cim.CIMInstance)14 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)13 URI (java.net.URI)11 BlockMirror (com.emc.storageos.db.client.model.BlockMirror)5 BlockObject (com.emc.storageos.db.client.model.BlockObject)5 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)5 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 CIMProperty (javax.cim.CIMProperty)5 StoragePool (com.emc.storageos.db.client.model.StoragePool)4 StringMap (com.emc.storageos.db.client.model.StringMap)4 ArrayList (java.util.ArrayList)4 CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)3 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)3 SMIPluginException (com.emc.storageos.plugins.metering.smis.SMIPluginException)3 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)3