use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class SmisMaskingViewAddVolumeJob method updateStatus.
@Override
public void updateStatus(JobContext jobContext) throws Exception {
DbClient dbClient = jobContext.getDbClient();
JobStatus jobStatus = getJobStatus();
_log.info("Updating status of SmisMaskingViewAddVolumeJob");
try {
if (jobStatus == JobStatus.SUCCESS) {
StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
CimConnection cimConnection = jobContext.getCimConnectionFactory().getConnection(storageSystem);
List<URI> volumeUriList = new ArrayList<URI>();
// Now perform RP protection tagging, if required for the
// objects being added.
SmisCommandHelper helper = jobContext.getSmisCommandHelper();
for (VolumeURIHLU volumeUriHlu : _volumeURIHLUs) {
BlockObject bo = Volume.fetchExportMaskBlockObject(dbClient, volumeUriHlu.getVolumeURI());
if (bo != null && bo instanceof Volume) {
Volume volume = (Volume) bo;
if (volume != null && volume.checkForRp()) {
List<CIMObjectPath> volumePathList = new ArrayList<CIMObjectPath>();
volumePathList.add(helper.getVolumeMember(storageSystem, volume));
helper.setRecoverPointTag(storageSystem, volumePathList, true);
}
}
volumeUriList.add(volumeUriHlu.getVolumeURI());
}
// for proper roll back , that is volume removal, if exception is thrown during update
if (_newCreatedGroup != null) {
helper.setHostIOLimits(cimConnection.getCimClient(), _newCreatedGroup, _volumeURIHLUs);
}
String[] volumeNames = ExportMaskUtils.getBlockObjectAlternateNames(volumeUriList, dbClient);
CIMObjectPath[] volumes = _cimPath.getVolumePaths(storageSystem, volumeNames);
_log.info("{} volumes processed for HLU updation", volumes.length);
// Now set the HLU on the volume URIs, if they haven't been set// by user.
ExportMaskOperationsHelper.setHLUFromProtocolControllersOnAddVolume(dbClient, cimConnection, _exportMaskURI, _volumeURIHLUs, volumes, getTaskCompleter());
}
} catch (WBEMException e) {
_log.error(String.format("updateHostIOLimits failed - new created group: %s", _newCreatedGroup.toString()), e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
getTaskCompleter().error(dbClient, serviceError);
} catch (Exception e) {
_log.error("Caught an exception while trying to updateStatus for SmisMaskingViewAddVolumeJob", e);
setPostProcessingErrorStatus("Encountered an internal error during add volume to masking view job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class SmisVnxCreateCGMirrorJob method updateStatus.
public void updateStatus(JobContext jobContext) throws Exception {
CloseableIterator<CIMInstance> syncVolumeIter = null;
DbClient dbClient = jobContext.getDbClient();
JobStatus jobStatus = getJobStatus();
try {
if (jobStatus == JobStatus.IN_PROGRESS) {
return;
}
BlockMirrorCreateCompleter completer = (BlockMirrorCreateCompleter) getTaskCompleter();
List<BlockMirror> mirrors = dbClient.queryObject(BlockMirror.class, completer.getIds());
CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
updatePools(client, dbClient, mirrors);
}
if (jobStatus == JobStatus.SUCCESS) {
syncVolumeIter = client.associatorInstances(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null, false, _volumeProps);
StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
processCGMirrors(syncVolumeIter, client, dbClient, storage, mirrors, UUID.randomUUID().toString());
} else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
_log.info("Failed to create group mirrors");
for (BlockMirror mirror : mirrors) {
mirror.setInactive(true);
}
dbClient.persistObject(mirrors);
}
} catch (Exception e) {
setPostProcessingErrorStatus("Encountered an internal error during create CG mirror job status processing: " + e.getMessage());
_log.error("Caught an exception while trying to updateStatus for SmisVnxCreateCGMirrorJob", e);
} finally {
if (syncVolumeIter != null) {
syncVolumeIter.close();
}
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class SmisVolumeExpandJob method updateStatus.
/**
* Called to update the job status when the volume expand job completes.
*
* @param jobContext The job context.
*/
public void updateStatus(JobContext jobContext) throws Exception {
CloseableIterator<CIMObjectPath> associatorIterator = null;
CloseableIterator<CIMInstance> instanceIterator = null;
JobStatus jobStatus = getJobStatus();
try {
if (jobStatus == JobStatus.IN_PROGRESS) {
return;
}
DbClient dbClient = jobContext.getDbClient();
CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
// from pool's reserved capacity map.
if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
SmisUtils.updateStoragePoolCapacity(dbClient, client, _storagePoolURI);
StoragePool pool = dbClient.queryObject(StoragePool.class, _storagePoolURI);
StringMap reservationMap = pool.getReservedCapacityMap();
URI volumeId = getTaskCompleter().getId();
// remove from reservation map
reservationMap.remove(volumeId.toString());
dbClient.persistObject(pool);
}
String opId = getTaskCompleter().getOpId();
StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s, task: %s", this.getJobName(), jobStatus.name(), opId));
if (jobStatus == JobStatus.SUCCESS) {
VolumeExpandCompleter taskCompleter = (VolumeExpandCompleter) getTaskCompleter();
Volume volume = dbClient.queryObject(Volume.class, taskCompleter.getId());
// set requested capacity
volume.setCapacity(taskCompleter.getSize());
// set meta related properties
volume.setTotalMetaMemberCapacity(taskCompleter.getTotalMetaMembersSize());
volume.setMetaMemberCount(taskCompleter.getMetaMemberCount());
volume.setMetaMemberSize(taskCompleter.getMetaMemberSize());
volume.setIsComposite(taskCompleter.isComposite());
volume.setCompositionType(taskCompleter.getMetaVolumeType());
// set provisioned capacity
associatorIterator = client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
if (associatorIterator.hasNext()) {
CIMObjectPath volumePath = associatorIterator.next();
CIMInstance volumeInstance = client.getInstance(volumePath, true, false, null);
if (volumeInstance != null) {
CIMProperty consumableBlocks = volumeInstance.getProperty(SmisConstants.CP_CONSUMABLE_BLOCKS);
CIMProperty blockSize = volumeInstance.getProperty(SmisConstants.CP_BLOCK_SIZE);
// calculate provisionedCapacity = consumableBlocks * block size
Long provisionedCapacity = Long.valueOf(consumableBlocks.getValue().toString()) * Long.valueOf(blockSize.getValue().toString());
volume.setProvisionedCapacity(provisionedCapacity);
}
// set allocated capacity
instanceIterator = client.referenceInstances(volumePath, SmisConstants.CIM_ALLOCATED_FROM_STORAGEPOOL, null, false, SmisConstants.PS_SPACE_CONSUMED);
if (instanceIterator.hasNext()) {
CIMInstance allocatedFromStoragePoolPath = instanceIterator.next();
CIMProperty spaceConsumed = allocatedFromStoragePoolPath.getProperty(SmisConstants.CP_SPACE_CONSUMED);
if (null != spaceConsumed) {
volume.setAllocatedCapacity(Long.valueOf(spaceConsumed.getValue().toString()));
}
}
}
logMsgBuilder.append(String.format("%n Capacity: %s, Provisioned capacity: %s, Allocated Capacity: %s", volume.getCapacity(), volume.getProvisionedCapacity(), volume.getAllocatedCapacity()));
if (volume.getIsComposite()) {
logMsgBuilder.append(String.format("%n Is Meta: %s, Total meta member capacity: %s, Meta member count %s, Meta member size: %s", volume.getIsComposite(), volume.getTotalMetaMemberCapacity(), volume.getMetaMemberCount(), volume.getMetaMemberSize()));
}
_log.info(logMsgBuilder.toString());
// Reset list of meta member volumes in the volume
if (volume.getMetaVolumeMembers() != null) {
volume.getMetaVolumeMembers().clear();
}
StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, volume.getStorageController());
// set the RP tag on the volume if the volume is RP protected
if (volume.checkForRp()) {
SmisCommandHelper helper = jobContext.getSmisCommandHelper();
boolean tagSet = helper.doApplyRecoverPointTag(storageSystem, volume, true);
if (!tagSet) {
_log.error("Encountered an error while trying to enable the RecoverPoint tag.");
jobStatus = JobStatus.FAILED;
}
}
dbClient.persistObject(volume);
// Reset list of meta members native ids in WF data (when meta is created meta members are removed from array)
WorkflowService.getInstance().storeStepData(opId, new ArrayList<String>());
}
} catch (Exception e) {
_log.error("Caught an exception while trying to updateStatus for SmisVolumeExpandJob", e);
setPostProcessingErrorStatus("Encountered an internal error during volume expand job status processing : " + e.getMessage());
} finally {
_metaVolumeTaskCompleter.setLastStepStatus(jobStatus);
if (associatorIterator != null) {
associatorIterator.close();
}
if (instanceIterator != null) {
instanceIterator.close();
}
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class VdcUtilTest method shouldReturnDefaultVersionIfNoGeoVersion.
@Test
public void shouldReturnDefaultVersionIfNoGeoVersion() {
DbClient dbClientMock = EasyMock.createMock(DbClient.class);
EasyMock.expect(dbClientMock.queryByType(VdcVersion.class, true)).andReturn(new ArrayList<URI>());
EasyMock.expect(dbClientMock.queryObject(VdcVersion.class, new ArrayList<URI>())).andReturn(new ArrayList<VdcVersion>());
EasyMock.expect(dbClientMock.queryByType(VirtualDataCenter.class, true)).andReturn(new ArrayList<URI>());
EasyMock.replay(dbClientMock);
VdcUtil.setDbClient(dbClientMock);
String minialVdcVersion = VdcUtil.getMinimalVdcVersion();
String expectedVdcVersion = DbConfigConstants.DEFAULT_VDC_DB_VERSION;
Assert.assertEquals(expectedVdcVersion, minialVdcVersion);
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class VdcUtilTest method shouldReturnDefaultVersionIfMissVdcVersion.
@Test
public void shouldReturnDefaultVersionIfMissVdcVersion() {
List<VdcVersion> geoVersions = new ArrayList<VdcVersion>();
List<URI> vdcIds = new ArrayList<URI>();
geoVersions.add(VDC2_GEO_VERSION);
vdcIds.add(VDC1_ID);
vdcIds.add(VDC2_ID);
DbClient dbClientMock = EasyMock.createMock(DbClient.class);
EasyMock.expect(dbClientMock.queryByType(VdcVersion.class, true)).andReturn(new ArrayList<URI>());
EasyMock.expect(dbClientMock.queryObject(VdcVersion.class, new ArrayList<URI>())).andReturn(geoVersions);
EasyMock.expect(dbClientMock.queryByType(VirtualDataCenter.class, true)).andReturn(vdcIds);
EasyMock.replay(dbClientMock);
VdcUtil.setDbClient(dbClientMock);
String minialVdcVersion = VdcUtil.getMinimalVdcVersion();
String expectedVdcVersion = DbConfigConstants.DEFAULT_VDC_DB_VERSION;
Assert.assertEquals(expectedVdcVersion, minialVdcVersion);
}
Aggregations