use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXUnitySnapshotOperations method restoreSingleVolumeSnapshot.
@Override
public void restoreSingleVolumeSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
try {
BlockSnapshot snapshotObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
VNXeApiClient apiClient = getVnxeClient(storage);
Snap snap = apiClient.getSnapshot(snapshotObj.getNativeId());
// Error out if the snapshot is attached
if (snap.isAttached()) {
log.error("Snapshot {})is exported and cannot be used for restore, please unexport it first", snapshotObj.getLabel());
ServiceError error = DeviceControllerErrors.vnxe.cannotRestoreAttachedSnapshot(snapshotObj.getLabel());
taskCompleter.error(_dbClient, error);
}
VNXeCommandJob job = apiClient.restoreSnap(snap.getId());
if (job != null) {
ControllerServiceImpl.enqueueJob(new QueueJob(new VNXUnityRestoreSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
}
} catch (Exception ex) {
log.error("Restore snapshot got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("RestoreSnapshotJob", ex.getMessage());
taskCompleter.error(_dbClient, error);
}
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXUnityCreateFileSystemQuotaDirectoryJob method updateStatus.
/**
* Called to update the job status when the file system Quota Directory create job completes.
*
* @param jobContext
* The job context.
*/
@Override
public void updateStatus(JobContext jobContext) throws Exception {
DbClient dbClient = jobContext.getDbClient();
try {
if (_status == JobStatus.IN_PROGRESS) {
return;
}
String opId = getTaskCompleter().getOpId();
StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, _status.name()));
VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
URI quotaId = getTaskCompleter().getId();
QuotaDirectory quotaObj = dbClient.queryObject(QuotaDirectory.class, quotaId);
URI fsUri = quotaObj.getParent().getURI();
FileShare fsObj = dbClient.queryObject(FileShare.class, fsUri);
String event = null;
if (_status == JobStatus.SUCCESS && quotaObj != null) {
updateQuota(quotaObj, dbClient, logMsgBuilder, vnxeApiClient);
event = String.format("Create file system quota directory successfully for URI: %s", getTaskCompleter().getId());
} else if (_status == JobStatus.FAILED && quotaObj != null) {
if (!quotaObj.getInactive()) {
quotaObj.setInactive(true);
dbClient.updateObject(quotaObj);
}
event = String.format("Task %s failed to create file system quota directory: %s", opId, quotaObj.getName());
logMsgBuilder.append("\n");
logMsgBuilder.append(event);
} else {
logMsgBuilder.append(String.format("Could not find the quota directory:%s", quotaId.toString()));
}
_logger.info(logMsgBuilder.toString());
FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, _isSuccess, event, "", quotaObj, fsObj);
} catch (Exception e) {
_logger.error("Caught an exception while trying to updateStatus for VNXUnityCreateFileSystemQuotaDirectoryJob", e);
setErrorStatus("Encountered an internal error during file system quota create job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXeUnManagedObjectDiscoverer method discoverUnManagedVolumes.
public void discoverUnManagedVolumes(AccessProfile accessProfile, DbClient dbClient, CoordinatorClient coordinator, PartitionManager partitionManager) throws Exception {
log.info("Started discovery of UnManagedVolumes for system {}", accessProfile.getSystemId());
VNXeApiClient apiClient = getVnxeClient(accessProfile);
unManagedVolumesInsert = new ArrayList<UnManagedVolume>();
unManagedVolumesUpdate = new ArrayList<UnManagedVolume>();
StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
List<VNXeLun> luns = apiClient.getAllLuns();
if (luns != null && !luns.isEmpty()) {
Map<String, StoragePool> pools = getStoragePoolMap(storageSystem, dbClient);
for (VNXeLun lun : luns) {
UnManagedVolume unManagedVolume = null;
String managedVolumeNativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(storageSystem.getNativeGuid(), lun.getId());
if (null != DiscoveryUtils.checkStorageVolumeExistsInDB(dbClient, managedVolumeNativeGuid)) {
log.info("Skipping volume {} as it is already managed by ViPR", managedVolumeNativeGuid);
}
StoragePool storagePool = getStoragePoolOfUnManagedObject(lun.getPool().getId(), storageSystem, pools);
if (null == storagePool) {
log.error("Skipping unmanaged volume discovery as the volume {} storage pool doesn't exist in ViPR", lun.getId());
continue;
}
String unManagedVolumeNatvieGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingVolume(storageSystem.getNativeGuid(), lun.getId());
unManagedVolume = DiscoveryUtils.checkUnManagedVolumeExistsInDB(dbClient, unManagedVolumeNatvieGuid);
unManagedVolume = createUnManagedVolume(unManagedVolume, unManagedVolumeNatvieGuid, lun, storageSystem, storagePool, dbClient);
unManagedVolumesReturnedFromProvider.add(unManagedVolume.getId());
}
if (!unManagedVolumesInsert.isEmpty()) {
partitionManager.insertInBatches(unManagedVolumesInsert, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_VOLUME);
}
if (!unManagedVolumesUpdate.isEmpty()) {
partitionManager.updateAndReIndexInBatches(unManagedVolumesUpdate, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_VOLUME);
}
// Process those active unmanaged volume objects available in database but not in newly discovered items, to mark them inactive.
DiscoveryUtils.markInActiveUnManagedVolumes(storageSystem, unManagedVolumesReturnedFromProvider, dbClient, partitionManager);
} else {
log.info("There are no luns found on the system: {}", storageSystem.getId());
}
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXeBlockCreateCGSnapshotJob method updateStatus.
public void updateStatus(JobContext jobContext) throws Exception {
DbClient dbClient = jobContext.getDbClient();
try {
if (_status == JobStatus.IN_PROGRESS) {
return;
}
BlockSnapshotCreateCompleter completer = (BlockSnapshotCreateCompleter) getTaskCompleter();
List<BlockSnapshot> snapshots = dbClient.queryObject(BlockSnapshot.class, completer.getSnapshotURIs());
StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
if (_status == JobStatus.SUCCESS) {
VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
ParametersOut output = vnxeJob.getParametersOut();
// get the luns belonging to the lun group
String lunGroupSnapId = output.getId();
VNXeLunGroupSnap groupSnap = vnxeApiClient.getLunGroupSnapshot(lunGroupSnapId);
List<VNXeLun> groupLuns = vnxeApiClient.getLunByStorageResourceId(groupSnap.getStorageResource().getId());
// 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);
}
for (VNXeLun groupLun : groupLuns) {
BlockSnapshot snapshot = volumeToSnapMap.get(groupLun.getId());
if (snapshot == null) {
_logger.info("No snapshot found for the vnxe lun - ", groupLun.getId());
continue;
}
snapshot.setNativeId(output.getId());
snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
snapshot.setDeviceLabel(groupLun.getName());
snapshot.setReplicationGroupInstance(lunGroupSnapId);
snapshot.setIsSyncActive(true);
snapshot.setInactive(false);
snapshot.setCreationTime(Calendar.getInstance());
snapshot.setWWN(groupLun.getSnapWwn());
snapshot.setAllocatedCapacity(groupLun.getSnapsSizeAllocated());
snapshot.setProvisionedCapacity(groupLun.getSnapsSize());
_logger.info(String.format("Going to set blocksnapshot %1$s nativeId to %2$s (%3$s). Associated lun is %4$s (%5$s)", snapshot.getId().toString(), output.getId(), snapshot.getLabel(), groupLun.getId(), groupLun.getName()));
dbClient.persistObject(snapshot);
}
} else if (_status == JobStatus.FAILED) {
_logger.info("Failed to create snapshot");
for (BlockSnapshot snapshot : snapshots) {
snapshot.setInactive(true);
}
dbClient.persistObject(snapshots);
}
} catch (Exception e) {
_logger.error("Caught an exception while trying to updateStatus for VNXeBlockCreateCGSnapshotJob", e);
setErrorStatus("Encountered an internal error during group snapshot create job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.
the class VNXeJob method poll.
@Override
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
String currentJob = _jobIds.get(0);
try {
_logger.info("VNXeJob: Looking up job: id {}", _jobIds.get(0));
VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
StringBuilder prettyMsg = new StringBuilder();
if (vnxeApiClient == null) {
String errorMessage = "No VNXe client found for: " + _storageSystemUri;
processTransientError(currentJob, trackingPeriodInMillis, errorMessage, null);
} else {
_pollResult.setJobName(_jobName);
_pollResult.setJobId(_taskCompleter.getOpId());
int completeCount = 0;
boolean isSuccess = true;
StringBuilder msg = new StringBuilder();
for (String jobId : _jobIds) {
currentJob = jobId;
VNXeCommandJob jobResult = vnxeApiClient.getJob(jobId);
MessageOut msgOut = jobResult.getMessageOut();
int progressPct = jobResult.getProgressPct();
int state = jobResult.getState();
if (state == VNXeCommandJob.JobStatusEnum.FAILED.getValue()) {
completeCount++;
isSuccess = false;
msg.append("Async task failed for jobID ");
msg.append(jobId);
if (msgOut != null) {
msg.append(" " + msgOut.getMessage());
String cleanMsg = msgOut.getMessage().split("\\(Error Code")[0];
prettyMsg.append(cleanMsg);
}
continue;
}
if (progressPct == 100 && state != VNXeCommandJob.JobStatusEnum.RUNNING.getValue()) {
completeCount++;
if (state != VNXeCommandJob.JobStatusEnum.COMPLETED.getValue()) {
msg.append("Async task failed for jobID ");
msg.append(jobId);
if (msgOut != null) {
msg.append(" " + msgOut.getMessage());
String cleanMsg = msgOut.getMessage().split("\\(Error Code")[0];
prettyMsg.append(cleanMsg);
}
}
}
}
if (completeCount == _jobIds.size()) {
// all completed
_pollResult.setJobPercentComplete(100);
if (isSuccess) {
_status = JobStatus.SUCCESS;
_logger.info("Job: {} succeeded", _jobName);
} else {
_status = JobStatus.FAILED;
_errorDescription = prettyMsg.toString();
_logger.info(msg.toString());
}
} else {
_pollResult.setJobPercentComplete(100 * completeCount / _jobIds.size());
}
}
} catch (Exception e) {
processTransientError(currentJob, trackingPeriodInMillis, e.getMessage(), e);
} finally {
try {
updateStatus(jobContext);
} catch (Exception e) {
setErrorStatus(e.getMessage());
_logger.error("Problem while trying to update status", e);
}
}
_pollResult.setJobStatus(_status);
_pollResult.setErrorDescription(_errorDescription);
return _pollResult;
}
Aggregations