use of com.emc.storageos.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method listSanpshotByPolicy.
@Override
public BiosCommandResult listSanpshotByPolicy(StorageSystem storageObj, FileDeviceInputOutput args) {
FilePolicy sp = args.getFileProtectionPolicy();
FileShare fs = args.getFs();
String snapshotScheduleName = sp.getFilePolicyName() + "_" + args.getFsName();
if (sp.getPolicyStorageResources() != null && !sp.getPolicyStorageResources().isEmpty()) {
for (String uriResource : sp.getPolicyStorageResources()) {
PolicyStorageResource policyRes = _dbClient.queryObject(PolicyStorageResource.class, URI.create(uriResource));
if (policyRes != null && policyRes.getStorageSystem().equals(storageObj.getId())) {
snapshotScheduleName = policyRes.getPolicyNativeId();
break;
}
}
}
IsilonApi isi = getIsilonDevice(storageObj);
String resumeToken = null;
try {
do {
IsilonList<IsilonSnapshot> snapshots = isi.listSnapshotsCreatedByPolicy(resumeToken, snapshotScheduleName);
if (snapshots != null) {
for (IsilonSnapshot islon_snap : snapshots.getList()) {
_log.info("file policy snapshot is : " + islon_snap.getName());
Snapshot snap = new Snapshot();
snap.setLabel(islon_snap.getName());
snap.setMountPath(islon_snap.getPath());
snap.setName(islon_snap.getName());
snap.setId(URIUtil.createId(Snapshot.class));
snap.setOpStatus(new OpStatusMap());
snap.setProject(new NamedURI(fs.getProject().getURI(), islon_snap.getName()));
snap.setMountPath(getSnapshotPath(islon_snap.getPath(), islon_snap.getName()));
snap.setParent(new NamedURI(fs.getId(), islon_snap.getName()));
StringMap map = new StringMap();
Long createdTime = Long.parseLong(islon_snap.getCreated()) * SEC_IN_MILLI;
String expiresTime = "Never";
if (islon_snap.getExpires() != null && !islon_snap.getExpires().isEmpty()) {
Long expTime = Long.parseLong(islon_snap.getExpires()) * SEC_IN_MILLI;
expiresTime = expTime.toString();
}
map.put("created", createdTime.toString());
map.put("expires", expiresTime);
map.put("schedule", sp.getFilePolicyName());
snap.setExtensions(map);
_dbClient.updateObject(snap);
}
resumeToken = snapshots.getToken();
}
} while (resumeToken != null && !resumeToken.equalsIgnoreCase("null"));
} catch (IsilonException e) {
_log.error("listing snapshot by file policy failed.", e);
return BiosCommandResult.createErrorResult(e);
}
Task task = TaskUtils.findTaskForRequestId(_dbClient, fs.getId(), args.getOpId());
// set task to completed and progress to 100 and store in DB, so waiting thread in apisvc can read it.
task.ready();
task.setProgress(100);
_dbClient.updateObject(task);
return BiosCommandResult.createSuccessfulResult();
}
use of com.emc.storageos.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method doResyncLink.
@Override
public BiosCommandResult doResyncLink(StorageSystem system, FileShare fs, TaskCompleter completer) {
FileShare sourceFS = null;
FileShare targetFS = null;
StorageSystem targetSystem = null;
StorageSystem sourceSystem = null;
boolean isMirrorPolicy = false;
if (fs.getPersonality().equals(PersonalityTypes.TARGET.name())) {
sourceFS = _dbClient.queryObject(FileShare.class, fs.getParentFileShare());
targetFS = fs;
isMirrorPolicy = true;
} else if (fs.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
sourceFS = fs;
if (null != fs.getMirrorfsTargets() && !fs.getMirrorfsTargets().isEmpty()) {
List<String> targetfileUris = new ArrayList<String>();
targetfileUris.addAll(fs.getMirrorfsTargets());
targetFS = _dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
} else {
ServiceError serviceError = DeviceControllerErrors.isilon.unableToGetTargetFileSystem(sourceFS.getLabel());
return BiosCommandResult.createErrorResult(serviceError);
}
}
targetSystem = _dbClient.queryObject(StorageSystem.class, targetFS.getStorageDevice());
sourceSystem = _dbClient.queryObject(StorageSystem.class, sourceFS.getStorageDevice());
PolicyStorageResource policyStrRes = getEquivalentPolicyStorageResource(sourceFS, _dbClient);
if (policyStrRes != null) {
IsilonSyncPolicy syncTargetPolicy = policyNativeIdValidation(sourceSystem, policyStrRes);
// In case of failback step 4 we do resysc on the target file system, so we need to append _mirror
if (isMirrorPolicy) {
String mirrorPolicyName = syncTargetPolicy.getName();
mirrorPolicyName = mirrorPolicyName.concat(MIRROR_POLICY);
// 'resync-prep' on target mirror policy
return doResyncPrepTargetPolicy(sourceSystem, syncTargetPolicy.getName(), targetSystem, mirrorPolicyName, completer);
} else {
// 'resync-prep' operation on source storagesystem
return doResyncPrepSourcePolicy(sourceSystem, targetSystem, syncTargetPolicy.getId(), completer);
}
}
ServiceError serviceError = DeviceControllerErrors.isilon.unableToGetPolicy(system.getLabel(), "Unable to get policy details");
return BiosCommandResult.createErrorResult(serviceError);
}
use of com.emc.storageos.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class VirtualPoolFileReplicationPolicyMigration method updatePolicyStorageResouce.
private void updatePolicyStorageResouce(StorageSystem system, FilePolicy filePolicy, FileShare fs) {
logger.info("Creating policy storage resource for storage {} fs {} and policy {} ", system.getLabel(), fs.getLabel(), filePolicy.getFilePolicyName());
PolicyStorageResource policyStorageResource = new PolicyStorageResource();
policyStorageResource.setId(URIUtil.createId(PolicyStorageResource.class));
policyStorageResource.setFilePolicyId(filePolicy.getId());
policyStorageResource.setStorageSystem(system.getId());
policyStorageResource.setPolicyNativeId(fs.getName());
policyStorageResource.setAppliedAt(fs.getId());
policyStorageResource.setResourcePath(fs.getNativeId());
NASServer nasServer = null;
if (fs.getVirtualNAS() != null) {
nasServer = dbClient.queryObject(VirtualNAS.class, fs.getVirtualNAS());
} else {
// Get the physical NAS for the storage system!!
PhysicalNAS pNAS = getSystemPhysicalNAS(system);
if (pNAS != null) {
nasServer = pNAS;
}
}
if (nasServer != null) {
logger.info("Found NAS server {} ", nasServer.getNasName());
policyStorageResource.setNasServer(nasServer.getId());
policyStorageResource.setNativeGuid(generateNativeGuidForFilePolicyResource(system, nasServer.getNasName(), filePolicy.getFilePolicyType(), fs.getNativeId()));
}
if (fs.getMirrorfsTargets() != null && !fs.getMirrorfsTargets().isEmpty()) {
String[] targetFSs = fs.getMirrorfsTargets().toArray(new String[fs.getMirrorfsTargets().size()]);
// Today we support single target!!
FileShare fsTarget = dbClient.queryObject(FileShare.class, URI.create(targetFSs[0]));
// In older release, policy name was set to target file system lable!!
policyStorageResource.setPolicyNativeId(fsTarget.getLabel());
// Update the target resource details!!!
FileReplicaPolicyTargetMap fileReplicaPolicyTargetMap = new FileReplicaPolicyTargetMap();
FileReplicaPolicyTarget target = new FileReplicaPolicyTarget();
target.setAppliedAt(filePolicy.getApplyAt());
target.setStorageSystem(fsTarget.getStorageDevice().toString());
target.setPath(fsTarget.getNativeId());
NASServer targetNasServer = null;
if (fsTarget.getVirtualNAS() != null) {
targetNasServer = dbClient.queryObject(VirtualNAS.class, fsTarget.getVirtualNAS());
} else {
StorageSystem targetSystem = dbClient.queryObject(StorageSystem.class, fsTarget.getStorageDevice());
// Get the physical NAS for the storage system!!
PhysicalNAS pNAS = getSystemPhysicalNAS(targetSystem);
if (pNAS != null) {
targetNasServer = pNAS;
}
}
if (targetNasServer != null) {
target.setNasServer(targetNasServer.getId().toString());
}
String key = target.getFileTargetReplicaKey();
fileReplicaPolicyTargetMap.put(key, target);
policyStorageResource.setFileReplicaPolicyTargetMap(fileReplicaPolicyTargetMap);
}
dbClient.createObject(policyStorageResource);
filePolicy.addPolicyStorageResources(policyStorageResource.getId());
filePolicy.addAssignedResources(fs.getId());
logger.info("PolicyStorageResource object created successfully for {} ", system.getLabel() + policyStorageResource.getAppliedAt());
}
use of com.emc.storageos.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method unassignFilePolicy.
@Override
public void unassignFilePolicy(URI policy, Set<URI> unassignFrom, String taskId) throws InternalException {
FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, policy);
FilePolicyUnAssignWorkflowCompleter completer = new FilePolicyUnAssignWorkflowCompleter(policy, unassignFrom, taskId);
try {
Workflow workflow = _workflowService.getNewWorkflow(this, UNASSIGN_FILE_POLICY_WF_NAME, false, taskId, completer);
completer.setWorkFlowId(workflow.getWorkflowURI());
s_logger.info("Generating steps for unassigning file policy {} from resources", policy);
Set<String> policyResources = filePolicy.getPolicyStorageResources();
if (policyResources != null && !policyResources.isEmpty()) {
for (URI uri : unassignFrom) {
for (String policyResource : policyResources) {
PolicyStorageResource policyStorage = s_dbClient.queryObject(PolicyStorageResource.class, URI.create(policyResource));
if (policyStorage.getAppliedAt().toString().equals(uri.toString())) {
StorageSystem storageSystem = s_dbClient.queryObject(StorageSystem.class, policyStorage.getStorageSystem());
String stepId = workflow.createStepId();
String stepDes = String.format("unassigning file policy : %s, from resource: %s,", filePolicy.getId(), uri);
Object[] args = new Object[] { storageSystem.getId(), policy, policyStorage.getId() };
_fileDeviceController.createMethod(workflow, null, UNASSIGN_FILE_POLICY_METHOD, stepId, stepDes, storageSystem.getId(), args);
}
}
}
} else {
s_logger.info("file policy {} is not applied to any storage system", policy);
for (URI uri : unassignFrom) {
filePolicy.removeAssignedResources(uri);
FileOrchestrationUtils.updateUnAssignedResource(filePolicy, uri, s_dbClient);
}
// If no other resources are assigned to replication policy
// Remove the replication topology from the policy
FileOrchestrationUtils.removeTopologyInfo(filePolicy, s_dbClient);
s_dbClient.updateObject(filePolicy);
s_logger.info("Unassigning file policy: {} from resources: {} finished successfully", policy.toString(), unassignFrom.toString());
}
String successMessage = String.format("unassigning file policy : %s, from resources: %s finsihed successfully,", filePolicy.getId(), unassignFrom);
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error(String.format("unassigning file policy : %s, from resource: %s failed,", filePolicy.getId(), unassignFrom), ex);
ServiceError serviceError = DeviceControllerException.errors.unassignFilePolicyFailed(policy.toString(), ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
use of com.emc.storageos.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method doPauseLink.
@Override
public BiosCommandResult doPauseLink(StorageSystem system, FileShare source) {
IsilonSyncPolicy syncpolicy = null;
PolicyStorageResource policyStrRes = getEquivalentPolicyStorageResource(source, _dbClient);
if (policyStrRes != null) {
syncpolicy = policyNativeIdValidation(system, policyStrRes);
String policyId = syncpolicy.getId();
JobState policyState = syncpolicy.getLastJobState();
if (policyState.equals(JobState.running) || policyState.equals(JobState.paused)) {
mirrorOperations.doCancelReplicationPolicy(system, policyId);
}
return mirrorOperations.doStopReplicationPolicy(system, policyId);
}
ServiceError serviceError = DeviceControllerErrors.isilon.unableToCreateFileShare();
return BiosCommandResult.createErrorResult(serviceError);
}
Aggregations