Search in sources :

Example 1 with PolicyStorageResource

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 2 with PolicyStorageResource

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileProtectionPolicyUpdateCompleter(com.emc.storageos.volumecontroller.impl.file.FileProtectionPolicyUpdateCompleter) Workflow(com.emc.storageos.workflow.Workflow) FileObject(com.emc.storageos.db.client.model.FileObject) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 3 with PolicyStorageResource

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;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource)

Example 4 with PolicyStorageResource

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;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) ArrayList(java.util.ArrayList) FilePolicyStorageResourceRestRep(com.emc.storageos.model.file.policy.FilePolicyStorageResourceRestRep) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) FilePolicyStorageResources(com.emc.storageos.model.file.policy.FilePolicyStorageResources) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with PolicyStorageResource

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());
}
Also used : NASServer(com.emc.storageos.db.client.model.NASServer) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) PhysicalNAS(com.emc.storageos.db.client.model.PhysicalNAS)

Aggregations

PolicyStorageResource (com.emc.storageos.db.client.model.PolicyStorageResource)29 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)14 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)11 ArrayList (java.util.ArrayList)11 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)9 IsilonSyncPolicy (com.emc.storageos.isilon.restapi.IsilonSyncPolicy)8 FileShare (com.emc.storageos.db.client.model.FileShare)6 StringSet (com.emc.storageos.db.client.model.StringSet)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 NASServer (com.emc.storageos.db.client.model.NASServer)5 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)5 IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)5 URI (java.net.URI)5 PhysicalNAS (com.emc.storageos.db.client.model.PhysicalNAS)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)4 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)4 ControllerException (com.emc.storageos.volumecontroller.ControllerException)4 WorkflowException (com.emc.storageos.workflow.WorkflowException)4 FileReplicaPolicyTarget (com.emc.storageos.db.client.model.FileReplicaPolicyTarget)3 FileReplicaPolicyTargetMap (com.emc.storageos.db.client.model.FileReplicaPolicyTargetMap)3