use of com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel in project coprhd-controller by CoprHD.
the class FileOrchestrationUtils method updateUnAssignedResource.
public static void updateUnAssignedResource(FilePolicy filePolicy, URI unassignRes, DbClient dbClient) {
FilePolicyApplyLevel applyLevel = FilePolicyApplyLevel.valueOf(filePolicy.getApplyAt());
switch(applyLevel) {
case vpool:
VirtualPool vpool = dbClient.queryObject(VirtualPool.class, unassignRes);
vpool.removeFilePolicy(filePolicy.getId());
dbClient.updateObject(vpool);
break;
case project:
Project project = dbClient.queryObject(Project.class, unassignRes);
project.removeFilePolicy(project, filePolicy.getId());
dbClient.updateObject(project);
break;
case file_system:
FileShare fs = dbClient.queryObject(FileShare.class, unassignRes);
fs.removeFilePolicy(filePolicy.getId());
dbClient.updateObject(fs);
break;
default:
_log.error("Not a valid policy apply level: " + applyLevel);
}
}
use of com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel in project coprhd-controller by CoprHD.
the class FilePolicyService method assignFilePolicy.
/**
* Assign File Policy
*
* @param id
* of the file policy.
* @param param
* FilePolicyAssignParam
* @brief Assign file policy to vpool, project, file system
* @return FilePolicyAssignResp
*/
@POST
@Path("/{id}/assign-policy")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.TENANT_ADMIN })
public TaskResourceRep assignFilePolicy(@PathParam("id") URI id, FilePolicyAssignParam param) {
ArgValidator.checkFieldUriType(id, FilePolicy.class, "id");
FilePolicy filepolicy = this._dbClient.queryObject(FilePolicy.class, id);
ArgValidator.checkEntity(filepolicy, id, true);
// Verify user has permission to assign policy
canUserAssignPolicyAtGivenLevel(filepolicy);
String applyAt = filepolicy.getApplyAt();
FilePolicyApplyLevel appliedAt = FilePolicyApplyLevel.valueOf(applyAt);
switch(appliedAt) {
case vpool:
return assignFilePolicyToVpools(param, filepolicy);
case project:
return assignFilePolicyToProjects(param, filepolicy);
default:
throw APIException.badRequests.invalidFilePolicyApplyLevel(appliedAt.name());
}
}
use of com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel in project coprhd-controller by CoprHD.
the class FilePolicyAssignWorkflowCompleter method updatePolicyAssignedResources.
private void updatePolicyAssignedResources(DbClient dbClient, FilePolicy filePolicy, Status status, ServiceCoded coded) {
for (URI resourceURI : assignToResource) {
filePolicy.addAssignedResources(resourceURI);
FilePolicyApplyLevel applyAt = FilePolicyApplyLevel.valueOf(filePolicy.getApplyAt());
switch(applyAt) {
case project:
Project project = dbClient.queryObject(Project.class, resourceURI);
project.addFilePolicy(filePolicy.getId());
dbClient.updateObject(project);
if (projectVPool != null) {
filePolicy.setFilePolicyVpool(projectVPool);
}
break;
case vpool:
VirtualPool vpool = dbClient.queryObject(VirtualPool.class, resourceURI);
vpool.addFilePolicy(filePolicy.getId());
dbClient.updateObject(vpool);
break;
default:
break;
}
}
dbClient.updateObject(filePolicy);
}
use of com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel in project coprhd-controller by CoprHD.
the class FilePolicyUnAssignWorkflowCompleter method updatePolicyUnAssignedResources.
protected void updatePolicyUnAssignedResources(DbClient dbClient, FilePolicy filePolicy, Status status, ServiceCoded coded) {
for (URI resourceURI : unassignFromResource) {
filePolicy.removeAssignedResources(resourceURI);
FilePolicyApplyLevel applyLevel = FilePolicyApplyLevel.valueOf(filePolicy.getApplyAt());
switch(applyLevel) {
case vpool:
VirtualPool vpool = dbClient.queryObject(VirtualPool.class, resourceURI);
vpool.removeFilePolicy(filePolicy.getId());
dbClient.updateObject(vpool);
break;
case project:
Project project = dbClient.queryObject(Project.class, resourceURI);
project.removeFilePolicy(project, filePolicy.getId());
dbClient.updateObject(project);
break;
case file_system:
FileShare fs = dbClient.queryObject(FileShare.class, resourceURI);
fs.removeFilePolicy(filePolicy.getId());
dbClient.updateObject(fs);
break;
default:
_log.error("Not a valid policy apply level: " + applyLevel);
}
}
if (filePolicy.getAssignedResources() == null || filePolicy.getAssignedResources().isEmpty()) {
// remove the file policy vpool
if (!NullColumnValueGetter.isNullURI(filePolicy.getFilePolicyVpool())) {
filePolicy.setFilePolicyVpool(NullColumnValueGetter.getNullURI());
}
// If no other resources are assigned to replication policy
// Remove the replication topology from the policy
FileOrchestrationUtils.removeTopologyInfo(filePolicy, dbClient);
}
dbClient.updateObject(filePolicy);
}
use of com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method generatePathForPolicy.
private String generatePathForPolicy(FilePolicy filePolicy, FileShare fileShare, FileDeviceInputOutput args) {
String policyPath = "";
FilePolicyApplyLevel applyLevel = FilePolicyApplyLevel.valueOf(filePolicy.getApplyAt());
switch(applyLevel) {
case vpool:
String vpool = getNameWithNoSpecialCharacters(args.getVPool().getLabel(), args);
if (fileShare.getNativeId().contains(vpool)) {
policyPath = fileShare.getNativeId().split(vpool)[0] + vpool;
} else {
_log.info("File system path {} does not contain vpool name {}", fileShare.getNativeId(), vpool);
}
break;
case project:
String project = getNameWithNoSpecialCharacters(args.getProject().getLabel(), args);
if (fileShare.getNativeId().contains(project)) {
policyPath = fileShare.getNativeId().split(project)[0] + project;
} else {
_log.info("File system path {} does not contain project name {}", fileShare.getNativeId(), project);
}
break;
case file_system:
policyPath = fileShare.getNativeId();
break;
default:
_log.error("Not a valid policy applied at level {} ", applyLevel);
}
return policyPath;
}
Aggregations