use of com.emc.storageos.db.client.model.PolicyStorageResource 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.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method updateFileProtectionPolicy.
@Override
public void updateFileProtectionPolicy(URI policy, FilePolicyUpdateParam param, String taskId) {
FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, policy);
String opName = ResourceOperationTypeEnum.UPDATE_FILE_PROTECTION_POLICY.getName();
FileProtectionPolicyUpdateCompleter completer = new FileProtectionPolicyUpdateCompleter(policy, taskId);
try {
String waitFor = null;
Workflow workflow = _workflowService.getNewWorkflow(this, UPDATE_FILE_POLICY_WF_NAME, false, taskId, completer);
completer.setWorkFlowId(workflow.getWorkflowURI());
// Get the file policy storage resources!!!
List<PolicyStorageResource> policyStorageResources = FileOrchestrationUtils.getFilePolicyStorageResources(s_dbClient, filePolicy);
if (policyStorageResources != null && !policyStorageResources.isEmpty()) {
s_logger.info("Generating steps for updating file policy {} ", filePolicy.getFilePolicyName());
for (PolicyStorageResource policyStorageRes : policyStorageResources) {
StorageSystem system = s_dbClient.queryObject(StorageSystem.class, policyStorageRes.getStorageSystem());
String stepId = workflow.createStepId();
String stepDes = String.format("Updating policy on storage system %s, at path: %s", system.getLabel(), policyStorageRes.getResourcePath());
Object[] args = new Object[] { policyStorageRes.getStorageSystem(), policy, policyStorageRes.getId(), param };
// Try to update all storage system policies
// Dont use waitFor for next step!!!
_fileDeviceController.createMethod(workflow, waitFor, UPDATE_STORAGE_SYSTEM_FILE_PROTECTION_POLICY_METHOD, stepId, stepDes, policyStorageRes.getStorageSystem(), args);
}
String successMessage = String.format("Updating file policy {} is successful.", filePolicy.getFilePolicyName());
workflow.executePlan(completer, successMessage);
} else {
s_logger.info("No File Policy Storage resource for policy {} to update", filePolicy.getFilePolicyName());
}
} catch (Exception ex) {
s_logger.error(String.format("Updating file protection policy {} failed", filePolicy.getFilePolicyName()), ex);
ServiceError serviceError = DeviceControllerException.errors.updateFilePolicyFailed(filePolicy.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 FileOrchestrationUtils method getAllProjectLevelPolices.
/**
* Return list of policies to be applied at project
*
* @param dbClient
* @param project
* @param storageSystem
* @return
*/
public static List<FilePolicy> getAllProjectLevelPolices(DbClient dbClient, Project project, VirtualPool vpool, URI storageSystem, URI nasServer) {
List<FilePolicy> filePoliciesToCreate = new ArrayList<FilePolicy>();
StringSet fileProjectPolicies = project.getFilePolicies();
if (fileProjectPolicies != null && !fileProjectPolicies.isEmpty()) {
for (String fileProjectPolicy : fileProjectPolicies) {
FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, URIUtil.uri(fileProjectPolicy));
if (NullColumnValueGetter.isNullURI(filePolicy.getFilePolicyVpool()) || !filePolicy.getFilePolicyVpool().toString().equals(vpool.getId().toString())) {
continue;
}
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 != null && strRes.getAppliedAt().toString().equals(project.getId().toString()) && strRes.getStorageSystem().toString().equals(storageSystem.toString()) && strRes.getNasServer().toString().equalsIgnoreCase(nasServer.toString())) {
_log.info("File Policy {} is already exists for project {} , storage system {} and nas server {}", filePolicy.getFilePolicyName(), project.getLabel(), storageSystem.toString(), strRes);
filePoliciesToCreate.remove(filePolicy);
break;
}
}
}
}
}
return filePoliciesToCreate;
}
use of com.emc.storageos.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class FilePolicyService method getFilePolicyStorageResources.
/**
* @brief Get the list of policy storage resources of a file policy.
*
* @param id of the file policy.
* @return List of policy storage resource information.
*/
@GET
@Path("/{id}/policy-storage-resources")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public FilePolicyStorageResources getFilePolicyStorageResources(@PathParam("id") URI id) {
_log.info("Request recieved to list storage resources for the policy {}", id);
FilePolicy filepolicy = queryResource(id);
ArgValidator.checkEntity(filepolicy, id, true);
FilePolicyStorageResources resources = new FilePolicyStorageResources();
List<FilePolicyStorageResourceRestRep> policyResources = new ArrayList<FilePolicyStorageResourceRestRep>();
for (PolicyStorageResource storageRes : FileOrchestrationUtils.getFilePolicyStorageResources(_dbClient, filepolicy)) {
policyResources.add(FilePolicyMapper.mapPolicyStorageResource(storageRes, filepolicy, _dbClient));
}
resources.setStorageResources(policyResources);
return resources;
}
use of com.emc.storageos.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class FileSnapshotPolicyMigration method updatePolicyStorageResouce.
private void updatePolicyStorageResouce(StorageSystem system, FilePolicy fileSnapshotPolicy, FileShare fs) {
logger.info("Creating policy storage resource for storage {} fs {} and policy {} ", system.getLabel(), fs.getLabel(), fileSnapshotPolicy.getFilePolicyName());
PolicyStorageResource policyStorageResource = new PolicyStorageResource();
policyStorageResource.setId(URIUtil.createId(PolicyStorageResource.class));
policyStorageResource.setFilePolicyId(fileSnapshotPolicy.getId());
policyStorageResource.setStorageSystem(system.getId());
policyStorageResource.setPolicyNativeId(fileSnapshotPolicy.getFilePolicyName() + "_" + 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(), fileSnapshotPolicy.getFilePolicyType(), fs.getNativeId()));
}
dbClient.createObject(policyStorageResource);
fileSnapshotPolicy.addPolicyStorageResources(policyStorageResource.getId());
fileSnapshotPolicy.addAssignedResources(fs.getId());
logger.info("PolicyStorageResource object created successfully for {} ", system.getLabel() + policyStorageResource.getAppliedAt());
}
Aggregations