use of com.emc.storageos.volumecontroller.ControllerException in project coprhd-controller by CoprHD.
the class BlockDeviceController method createFullCopy.
@Override
public void createFullCopy(URI storage, List<URI> fullCopyVolumes, Boolean createInactive, String taskId) throws ControllerException {
_log.info("START fullCopyVolumes");
TaskCompleter taskCompleter = new CloneCreateWorkflowCompleter(fullCopyVolumes, taskId);
Volume clone = _dbClient.queryObject(Volume.class, fullCopyVolumes.get(0));
URI sourceVolume = clone.getAssociatedSourceVolume();
try {
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storage);
Workflow workflow = _workflowService.getNewWorkflow(this, FULL_COPY_WORKFLOW, true, taskId);
boolean isCG = false;
Volume source = URIUtil.isType(sourceVolume, Volume.class) ? _dbClient.queryObject(Volume.class, sourceVolume) : null;
VolumeGroup volumeGroup = (source != null) ? source.getApplication(_dbClient) : null;
if (volumeGroup != null) {
/**
* If a Volume is in Volume Group (COPY type),
* Query all volumes belonging to that Volume Group,
* Group full-copies by Array Replication Group and create workflow step for each Array Group,
* these steps runs in parallel
*/
_log.info("Creating full copy for Application {}", volumeGroup.getLabel());
createFullCopyForApplicationCGs(workflow, volumeGroup, fullCopyVolumes, createInactive, taskCompleter);
} else if (checkCloneConsistencyGroup(fullCopyVolumes.get(0), _dbClient, taskCompleter)) {
// check if the clone is in a CG
isCG = true;
_log.info("Creating group full copy");
createCGFullCopy(storage, sourceVolume, fullCopyVolumes, storageSystem, workflow, createInactive, isCG);
} else {
for (URI uri : fullCopyVolumes) {
Workflow.Method createMethod = createFullCopyVolumeMethod(storage, sourceVolume, Arrays.asList(uri), createInactive, isCG);
Workflow.Method rollbackMethod = rollbackFullCopyVolumeMethod(storage, asList(uri));
workflow.createStep(FULL_COPY_CREATE_STEP_GROUP, "Creating full copy", null, storage, storageSystem.getSystemType(), getClass(), createMethod, rollbackMethod, null);
// clone state.
if (!createInactive && !getDriverManager().isDriverManaged(storageSystem.getSystemType())) {
// After all full copies have been created, wait for synchronization to complete
Workflow.Method waitForSyncMethod = waitForSynchronizedMethod(Volume.class, storage, Arrays.asList(uri), isCG);
String waitForSyncStep = workflow.createStep(FULL_COPY_WFS_STEP_GROUP, "Waiting for synchronization", FULL_COPY_CREATE_STEP_GROUP, storage, storageSystem.getSystemType(), getClass(), waitForSyncMethod, rollbackMethodNullMethod(), null);
Volume cloneVol = _dbClient.queryObject(Volume.class, uri);
BlockObject sourceObj = BlockObject.fetch(_dbClient, cloneVol.getAssociatedSourceVolume());
// detach if source is snapshot, or storage system is not vmax/vnx/hds
if (storageSystem.deviceIsType(Type.openstack)) {
setCloneReplicaStateStep(workflow, storageSystem, asList(uri), waitForSyncStep, ReplicationState.SYNCHRONIZED);
} else if (sourceObj instanceof BlockSnapshot || !(storageSystem.deviceIsType(Type.vmax) || storageSystem.deviceIsType(Type.hds) || storageSystem.deviceIsType(Type.vnxblock))) {
Workflow.Method detachMethod = detachFullCopyMethod(storage, asList(uri));
workflow.createStep(FULL_COPY_DETACH_STEP_GROUP, "Detaching full copy", waitForSyncStep, storage, storageSystem.getSystemType(), getClass(), detachMethod, rollbackMethodNullMethod(), null);
} else if (storageSystem.deviceIsType(Type.vnxblock)) {
workflow.createStep(FULL_COPY_FRACTURE_STEP_GROUP, "fracture full copy", waitForSyncStep, storage, storageSystem.getSystemType(), BlockDeviceController.class, fractureCloneMethod(storage, Arrays.asList(uri), isCG), rollbackMethodNullMethod(), null);
} else {
setCloneReplicaStateStep(workflow, storageSystem, asList(uri), waitForSyncStep, ReplicationState.SYNCHRONIZED);
}
}
}
}
String successMsg = String.format("Full copy of %s to %s successful", sourceVolume, fullCopyVolumes);
workflow.executePlan(taskCompleter, successMsg);
} catch (InternalException e) {
_log.error("Failed to create full copy of volume", e);
doFailTask(Volume.class, sourceVolume, taskId, e);
WorkflowStepCompleter.stepFailed(taskId, e);
} catch (Exception e) {
_log.error("Failed to create full copy of volume", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
doFailTask(Volume.class, sourceVolume, taskId, serviceError);
WorkflowStepCompleter.stepFailed(taskId, serviceError);
}
}
use of com.emc.storageos.volumecontroller.ControllerException in project coprhd-controller by CoprHD.
the class FileDeviceController method performFileReplicationOperation.
@Override
public void performFileReplicationOperation(URI storage, URI sourceFSURI, String opType, String opId) throws ControllerException {
StorageSystem system = _dbClient.queryObject(StorageSystem.class, storage);
FileShare fileShare = _dbClient.queryObject(FileShare.class, sourceFSURI);
TaskCompleter completer = null;
BiosCommandResult result = new BiosCommandResult();
WorkflowStepCompleter.stepExecuting(opId);
_log.info("file replication operation {} started for file systerm {}", opType, fileShare.getName());
try {
if ("pause".equalsIgnoreCase(opType)) {
completer = new MirrorFilePauseTaskCompleter(FileShare.class, sourceFSURI, opId);
result = getDevice(system.getSystemType()).doPauseLink(system, fileShare);
} else if ("resume".equalsIgnoreCase(opType)) {
completer = new MirrorFileResumeTaskCompleter(FileShare.class, sourceFSURI, opId);
result = getDevice(system.getSystemType()).doResumeLink(system, fileShare, completer);
} else if ("start".equalsIgnoreCase(opType)) {
completer = new MirrorFileStartTaskCompleter(FileShare.class, sourceFSURI, opId);
result = getDevice(system.getSystemType()).doStartMirrorLink(system, fileShare, completer);
} else if ("refresh".equalsIgnoreCase(opType)) {
completer = new MirrorFileRefreshTaskCompleter(FileShare.class, sourceFSURI, opId);
result = getDevice(system.getSystemType()).doRefreshMirrorLink(system, fileShare);
} else if ("resync".equalsIgnoreCase(opType)) {
completer = new MirrorFileResyncTaskCompleter(FileShare.class, sourceFSURI, opId);
result = getDevice(system.getSystemType()).doResyncLink(system, fileShare, completer);
}
if (result.getCommandSuccess()) {
_log.info("file replication operation {} finished successfully for file systerm {}", opType, fileShare.getName());
completer.ready(_dbClient);
} else if (result.getCommandPending()) {
completer.statusPending(_dbClient, result.getMessage());
} else {
completer.error(_dbClient, result.getServiceCoded());
}
} catch (Exception e) {
_log.error("unable to perform mirror operation {} on file system {} ", opType, sourceFSURI, e);
updateTaskStatus(opId, fileShare, e);
ServiceError error = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, error);
}
}
use of com.emc.storageos.volumecontroller.ControllerException in project coprhd-controller by CoprHD.
the class FileDeviceController method unassignFilePolicy.
/**
* @param storage
* @param filePolicy
* URI of the file policy to be applied
* @param policyStorageResource
* @param opId
* @throws ControllerException
*/
public void unassignFilePolicy(URI storage, URI policyURI, URI policyStorageResource, String opId) throws ControllerException {
StorageSystem storageObj = null;
FilePolicy filePolicy = null;
PolicyStorageResource policyRes = null;
try {
FileDeviceInputOutput args = new FileDeviceInputOutput();
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
filePolicy = _dbClient.queryObject(FilePolicy.class, policyURI);
policyRes = _dbClient.queryObject(PolicyStorageResource.class, policyStorageResource);
args.setFileProtectionPolicy(filePolicy);
args.setPolicyStorageResource(policyRes);
WorkflowStepCompleter.stepExecuting(opId);
_log.info("Unassigning file policy: {} from resource: {}", policyURI.toString(), policyRes.getAppliedAt().toString());
BiosCommandResult result = getDevice(storageObj.getSystemType()).doUnassignFilePolicy(storageObj, args);
if (result.getCommandPending()) {
return;
} else if (result.isCommandSuccess()) {
// decouple the replication relation for the policy!!
resetReplicationFileSystemsRelation(filePolicy, policyRes);
filePolicy.removePolicyStorageResources(policyRes.getId());
_dbClient.markForDeletion(policyRes);
_dbClient.updateObject(filePolicy);
_log.info("Unassigning file policy: {} from resource: {} finished successfully", policyURI.toString(), policyRes.getAppliedAt().toString());
WorkflowStepCompleter.stepSucceded(opId);
} else {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
}
}
use of com.emc.storageos.volumecontroller.ControllerException in project coprhd-controller by CoprHD.
the class FileDeviceController method delete.
@Override
public void delete(URI storage, URI pool, URI uri, boolean forceDelete, String deleteType, String opId) throws ControllerException {
ControllerUtils.setThreadLocalLogData(uri, opId);
StorageSystem storageObj = null;
FileObject fileObject = null;
FileShare fsObj = null;
Snapshot snapshotObj = null;
try {
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
String[] params = { storage.toString(), uri.toString(), String.valueOf(forceDelete), deleteType };
_log.info("Delete : storage : {}, URI : {}, forceDelete : {}, delete_type : {} ", params);
FileDeviceInputOutput args = new FileDeviceInputOutput();
boolean isFile = false;
args.setOpId(opId);
if (URIUtil.isType(uri, FileShare.class)) {
isFile = true;
args.setForceDelete(forceDelete);
fsObj = _dbClient.queryObject(FileShare.class, uri);
setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
fileObject = fsObj;
args.addFileShare(fsObj);
args.setFileOperation(isFile);
BiosCommandResult result;
WorkflowStepCompleter.stepExecuting(opId);
if (FileControllerConstants.DeleteTypeEnum.VIPR_ONLY.toString().equalsIgnoreCase(deleteType) && !fsObj.getInactive()) {
result = BiosCommandResult.createSuccessfulResult();
} else {
if (!fsObj.getInactive()) {
// Acquire lock for VNXFILE Storage System
acquireStepLock(storageObj, opId);
result = getDevice(storageObj.getSystemType()).doDeleteFS(storageObj, args);
} else {
result = BiosCommandResult.createSuccessfulResult();
}
}
// In case of VNXe
if (result.getCommandPending()) {
return;
}
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
if (result.isCommandSuccess() && (FileControllerConstants.DeleteTypeEnum.FULL.toString().equalsIgnoreCase(deleteType))) {
fsObj.setInactive(true);
if (forceDelete) {
// Delete Snapshot and its references from DB
doDeleteSnapshotsFromDB(fsObj, true, null, args);
args.addQuotaDirectory(null);
// Delete Quota Directory from DB
doFSDeleteQuotaDirsFromDB(args);
// Delete CIFS Share ACLs from DB
deleteShareACLsFromDB(args);
// Delete Export Rules from DB
doDeleteExportRulesFromDB(true, null, args);
// Remove FileShare Reference from File Policy
doDeletePolicyReferenceFromDB(fsObj);
}
WorkflowStepCompleter.stepSucceded(opId);
} else if (!result.getCommandPending() && FileControllerConstants.DeleteTypeEnum.FULL.toString().equalsIgnoreCase(deleteType)) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
if (result.isCommandSuccess() && (FileControllerConstants.DeleteTypeEnum.VIPR_ONLY.toString().equalsIgnoreCase(deleteType))) {
boolean snapshotsExist = snapshotsExistsOnFS(fsObj);
boolean quotaDirsExist = quotaDirectoriesExistsOnFS(fsObj);
boolean policyExists = fileProtectionPoliciesExistsOnFS(fsObj);
boolean fsCheck = getDevice(storageObj.getSystemType()).doCheckFSExists(storageObj, args);
if (fsCheck) {
String errMsg = null;
if (snapshotsExist) {
errMsg = new String("delete file system from ViPR database failed because snapshots exist for file system " + fsObj.getLabel() + " and once deleted the snapshot cannot be ingested into ViPR");
} else if (quotaDirsExist && !quotaDirectoryIngestionSupported(storageObj.getSystemType())) {
errMsg = new String("delete file system from ViPR database failed because quota directories exist for file system " + fsObj.getLabel() + " and once deleted the quota directory cannot be ingested into ViPR");
} else if (policyExists) {
errMsg = new String("delete file system from ViPR database failed because file protection policies exist for file system " + fsObj.getLabel() + " and once deleted the policy cannot be ingested into ViPR");
}
if (errMsg != null) {
_log.error(errMsg);
final ServiceCoded serviceCoded = DeviceControllerException.errors.jobFailedOpMsg(OperationTypeEnum.DELETE_FILE_SYSTEM.toString(), errMsg);
result = BiosCommandResult.createErrorResult(serviceCoded);
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM, result.isCommandSuccess(), "", "", fsObj, storageObj);
_dbClient.updateObject(fsObj);
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
return;
}
}
// Delete Snapshot and its references from DB
doDeleteSnapshotsFromDB(fsObj, true, null, args);
args.addQuotaDirectory(null);
doFSDeleteQuotaDirsFromDB(args);
deleteShareACLsFromDB(args);
doDeleteExportRulesFromDB(true, null, args);
// Remove FileShare Reference from File Policy
doDeletePolicyReferenceFromDB(fsObj);
SMBShareMap cifsSharesMap = fsObj.getSMBFileShares();
if (cifsSharesMap != null && !cifsSharesMap.isEmpty()) {
cifsSharesMap.clear();
}
fsObj.setInactive(true);
WorkflowStepCompleter.stepSucceded(opId);
} else if (!result.getCommandPending() && FileControllerConstants.DeleteTypeEnum.VIPR_ONLY.toString().equalsIgnoreCase(deleteType)) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
_dbClient.updateObject(fsObj);
recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM, result.isCommandSuccess(), "", "", fsObj, storageObj);
} else {
snapshotObj = _dbClient.queryObject(Snapshot.class, uri);
fileObject = snapshotObj;
args.addSnapshot(snapshotObj);
fsObj = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
args.addFileShare(fsObj);
args.setFileOperation(isFile);
WorkflowStepCompleter.stepExecuting(opId);
// Acquire lock for VNXFILE Storage System
acquireStepLock(storageObj, opId);
BiosCommandResult result = getDevice(storageObj.getSystemType()).doDeleteSnapshot(storageObj, args);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
snapshotObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
if (result.isCommandSuccess()) {
WorkflowStepCompleter.stepSucceded(opId);
snapshotObj.setInactive(true);
// delete the corresponding export rules if available.
args.addSnapshot(snapshotObj);
doDeleteExportRulesFromDB(true, null, args);
}
_dbClient.updateObject(snapshotObj);
recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SNAPSHOT, result.isCommandSuccess(), "", "", snapshotObj, fsObj, storageObj);
}
} catch (Exception e) {
String[] params = { storage.toString(), uri.toString(), String.valueOf(forceDelete), e.getMessage() };
_log.error("Unable to delete file system or snapshot: storage {}, FS/snapshot {}, forceDelete {}: {}", params);
updateTaskStatus(opId, fileObject, e);
// work flow fail for fileshare delete
if (URIUtil.isType(uri, FileShare.class)) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
}
if (URIUtil.isType(uri, FileShare.class)) {
if ((fsObj != null) && (storageObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM, false, e.getMessage(), "", fsObj, storageObj);
}
} else {
if ((fsObj != null) && (storageObj != null) && (snapshotObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fsObj, storageObj);
}
}
}
}
use of com.emc.storageos.volumecontroller.ControllerException in project coprhd-controller by CoprHD.
the class FileDeviceController method disconnectStorage.
/**
* Removes a connection that was previously established for monitoring
* events from the storage identified by the passed URI.
*
* @param storage
* A database client URI that identifies the storage to be
* disconnected.
*
* @throws ControllerException
* When errors occur disconnecting the storage
* for event monitoring.
*/
@Override
public void disconnectStorage(URI storage) throws ControllerException {
// Retrieve the storage device info from the database.
StorageSystem storageObj = null;
try {
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
} catch (Exception e) {
throw DeviceControllerException.exceptions.unableToDisconnectStorageDeviceMonitoringDbException(storage.toString(), e);
}
// Verify non-null storage device returned from the database client.
if (storageObj == null) {
String msg = String.format("Failed disconnecting %1$s for monitoring. Database returned a null reference.", storage);
_log.error(msg);
throw DeviceControllerException.exceptions.unableToDisconnectStorageDeviceMonitoringDbNullRef(storage.toString());
}
// Get the file device reference for the type of file device managed
// by the controller.
FileStorageDevice storageDevice = getDevice(storageObj.getSystemType());
if (storageDevice == null) {
String devType = String.format("%1$s", getDevice(storageObj.getSystemType()));
String msg = String.format("Failed disconnecting %1$s for monitoring. No device for type %2$s.", storage, devType);
_log.error(msg);
throw DeviceControllerException.exceptions.unableToDisconnectStorageDeviceMonitoringNoDevice(storage.toString(), devType);
}
storageDevice.doDisconnect(storageObj);
_log.info("Removing storage device from work pool: {}", storageObj.getId());
}
Aggregations