use of com.emc.storageos.db.client.model.FilePolicy 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.FilePolicy in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method getVpoolLevelPolices.
/**
* Get the valid policy templates which are applied at vpool level
*
* @param vpool
* @return List of policies at the given vpool level
*/
private static List<FilePolicy> getVpoolLevelPolices(VirtualPool vpool) {
StringSet vPoolFilePolicies = vpool.getFilePolicies();
List<FilePolicy> filePoliciesToCreate = new ArrayList<FilePolicy>();
if (!CollectionUtils.isEmpty(vPoolFilePolicies)) {
for (String fileVpoolPolicy : vPoolFilePolicies) {
FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, URIUtil.uri(fileVpoolPolicy));
if (filePolicy != null && !filePolicy.getInactive()) {
filePoliciesToCreate.add(filePolicy);
}
}
}
return filePoliciesToCreate;
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FileOrchestrationUtils method getFilePolicyStorageResources.
/**
* Get the set of file policy storage resource for given policy
*
* @param dbClient
* @param policy
* @return
*/
public static List<PolicyStorageResource> getFilePolicyStorageResources(DbClient dbClient, VirtualPool vpool, Project project, FileShare fs) {
// Get the replication policies for vpool/project/fs!!
List<PolicyStorageResource> policyStorageResources = new ArrayList<PolicyStorageResource>();
List<FilePolicy> replicationPolicies = getReplicationPolices(dbClient, vpool, project, fs);
if (replicationPolicies != null && !replicationPolicies.isEmpty()) {
if (replicationPolicies.size() > 1) {
_log.error("More than one replication policy could not be applied accross vpool/project/fs");
throw APIException.badRequests.moreThanOneReplicationPolicySpecified();
} else {
FilePolicy policy = replicationPolicies.get(0);
for (PolicyStorageResource strRes : getFilePolicyStorageResources(dbClient, policy)) {
if (strRes != null) {
if (FilePolicyApplyLevel.project.name().equalsIgnoreCase(policy.getApplyAt()) && strRes.getAppliedAt().toString().equals(project.getId().toString())) {
policyStorageResources.add(strRes);
} else if (FilePolicyApplyLevel.vpool.name().equalsIgnoreCase(policy.getApplyAt()) && strRes.getAppliedAt().toString().equals(vpool.getId().toString())) {
policyStorageResources.add(strRes);
}
}
}
}
}
return policyStorageResources;
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FileOrchestrationUtils method isReplicationPolicyExistsOnTarget.
/**
* Verify the replication policy was applied at given level
*
* @param dbClient
* @param system
* @param nasServer
* @param vpool
* @param project
* @param fs
* @return
*/
public static Boolean isReplicationPolicyExistsOnTarget(DbClient dbClient, StorageSystem system, VirtualPool vpool, Project project, FileShare fs) {
if (fs.getPersonality() != null && fs.getPersonality().equalsIgnoreCase(PersonalityTypes.TARGET.name())) {
List<FilePolicy> replicationPolicies = getReplicationPolices(dbClient, vpool, project, fs);
if (replicationPolicies != null && !replicationPolicies.isEmpty()) {
if (replicationPolicies.size() > 1) {
_log.warn("More than one replication policy found {}", replicationPolicies.size());
} else {
FilePolicy replPolicy = replicationPolicies.get(0);
FileShare sourceFS = dbClient.queryObject(FileShare.class, fs.getParentFileShare().getURI());
StorageSystem sourceStorage = dbClient.queryObject(StorageSystem.class, sourceFS.getStorageDevice());
NASServer nasServer = null;
if (sourceFS != null && sourceFS.getVirtualNAS() != null) {
nasServer = dbClient.queryObject(VirtualNAS.class, sourceFS.getVirtualNAS());
} else {
// Get the physical NAS for the storage system!!
nasServer = FileOrchestrationUtils.getSystemPhysicalNAS(dbClient, sourceStorage);
}
if (replPolicy.getApplyAt().equalsIgnoreCase(FilePolicyApplyLevel.vpool.name())) {
return isvPoolPolicyAppliedOnStorageSystem(dbClient, sourceStorage, nasServer, vpool, replPolicy);
} else if (replPolicy.getApplyAt().equalsIgnoreCase(FilePolicyApplyLevel.project.name())) {
return isProjectPolicyAppliedOnStorageSystem(dbClient, sourceStorage, nasServer, project, replPolicy);
} else if (replPolicy.getApplyAt().equalsIgnoreCase(FilePolicyApplyLevel.file_system.name())) {
FileShare fsParent = dbClient.queryObject(FileShare.class, fs.getParentFileShare());
return isFSPolicyAppliedOnStorageSystem(dbClient, sourceStorage, nasServer, fsParent, replPolicy);
}
}
}
}
return false;
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FileOrchestrationUtils method getAllVpoolLevelPolices.
/**
* Return list of policies to be applied at vpool
*
* @param dbClient
* @param vpool
* @param storageSystem
* @return
*/
public static List<FilePolicy> getAllVpoolLevelPolices(DbClient dbClient, VirtualPool vpool, URI storageSystem, URI nasServer) {
List<FilePolicy> filePoliciesToCreate = new ArrayList<FilePolicy>();
StringSet fileVpoolPolicies = vpool.getFilePolicies();
if (fileVpoolPolicies != null && !fileVpoolPolicies.isEmpty()) {
for (String fileVpoolPolicy : fileVpoolPolicies) {
FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, URIUtil.uri(fileVpoolPolicy));
filePoliciesToCreate.add(filePolicy);
StringSet policyStrRes = filePolicy.getPolicyStorageResources();
if (policyStrRes != null && !policyStrRes.isEmpty()) {
for (String policyStrRe : policyStrRes) {
PolicyStorageResource strRes = dbClient.queryObject(PolicyStorageResource.class, URIUtil.uri(policyStrRe));
if (strRes.getAppliedAt().toString().equals(vpool.getId().toString()) && strRes.getStorageSystem().toString().equals(storageSystem.toString()) && strRes.getNasServer().toString().equalsIgnoreCase(nasServer.toString())) {
_log.info("File Policy {} is already exists for vpool {} , storage system {} and nas server {}", filePolicy.getFilePolicyName(), vpool.getLabel(), storageSystem.toString(), strRes);
filePoliciesToCreate.remove(filePolicy);
break;
}
}
}
}
}
return filePoliciesToCreate;
}
Aggregations