Search in sources :

Example 1 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FileDeviceController method listSanpshotByPolicy.

@Override
public void listSanpshotByPolicy(URI storage, URI fsURI, URI policy, String opId) throws InternalException {
    ControllerUtils.setThreadLocalLogData(fsURI, opId);
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    FileShare fs = null;
    try {
        fs = _dbClient.queryObject(FileShare.class, fsURI);
        FilePolicy fp = _dbClient.queryObject(FilePolicy.class, policy);
        if (fs != null && fp != null) {
            StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
            _log.info("Controller Recieved File Policy  {}", policy);
            args.addFSFileObject(fs);
            args.setFileSystemPath(fs.getPath());
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
            args.setFileProtectionPolicy(fp);
            args.setFileOperation(true);
            args.setOpId(opId);
            // Do the Operation on device.
            BiosCommandResult result = getDevice(storageObj.getSystemType()).listSanpshotByPolicy(storageObj, args);
            fs.getOpStatus().updateTaskStatus(opId, result.toOperation());
        } else {
            throw DeviceControllerException.exceptions.invalidObjectNull();
        }
    } catch (Exception e) {
        String[] params = { storage.toString(), fsURI.toString(), e.getMessage() };
        _log.error("Unable to get schedule snapshots : storage {}, FS URI {},: Error {}", params);
        updateTaskStatus(opId, fs, e);
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) StoragePool(com.emc.storageos.db.client.model.StoragePool) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) 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 FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FileDeviceController method assignFileSnapshotPolicyToProjects.

@Override
public void assignFileSnapshotPolicyToProjects(URI storageSystemURI, URI vNASURI, URI filePolicyToAssign, URI vpoolURI, URI projectURI, String opId) throws InternalException {
    try {
        WorkflowStepCompleter.stepExecuting(opId);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
        FilePolicy filePolicy = _dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
        VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, vpoolURI);
        Project project = _dbClient.queryObject(Project.class, projectURI);
        TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg());
        if (vNASURI != null) {
            VirtualNAS vNAS = _dbClient.queryObject(VirtualNAS.class, vNASURI);
            args.setvNAS(vNAS);
        }
        args.setFileProtectionPolicy(filePolicy);
        args.setVPool(vpool);
        args.setProject(project);
        args.setTenantOrg(tenant);
        _log.info("Assigning file snapshot policy: {} to vpool {} and project: {}", filePolicyToAssign, vpoolURI, projectURI);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).checkFilePolicyExistsOrCreate(storageObj, args);
        if (result.getCommandPending()) {
            return;
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        if (result.isCommandSuccess()) {
            WorkflowStepCompleter.stepSucceded(opId);
        }
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) 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 3 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FileDeviceController method assignFileReplicationPolicyToVirtualPools.

@Override
public void assignFileReplicationPolicyToVirtualPools(URI storageSystemURI, URI targetSystemURI, URI sourceVNasURI, URI targetVArrayURI, URI targetVNasURI, URI filePolicyToAssign, URI vpoolURI, String opId) throws ControllerException {
    try {
        WorkflowStepCompleter.stepExecuting(opId);
        StorageSystem sourceSystem = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
        StorageSystem targetSystem = _dbClient.queryObject(StorageSystem.class, targetSystemURI);
        FilePolicy filePolicy = _dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
        VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, vpoolURI);
        VirtualArray targetVarray = _dbClient.queryObject(VirtualArray.class, targetVArrayURI);
        VirtualNAS sourceVNAS = null;
        VirtualNAS targetVNAS = null;
        FileDeviceInputOutput sourceArgs = new FileDeviceInputOutput();
        FileDeviceInputOutput targetArgs = new FileDeviceInputOutput();
        targetArgs.setVarray(targetVarray);
        sourceArgs.setFileProtectionPolicy(filePolicy);
        sourceArgs.setVPool(vpool);
        if (sourceVNasURI != null) {
            sourceVNAS = _dbClient.queryObject(VirtualNAS.class, sourceVNasURI);
            sourceArgs.setvNAS(sourceVNAS);
            targetArgs.setSourceVNAS(sourceVNAS);
        }
        targetArgs.setSourceSystem(sourceSystem);
        targetArgs.setVPool(vpool);
        targetArgs.setTarget(true);
        if (targetVNasURI != null) {
            targetVNAS = _dbClient.queryObject(VirtualNAS.class, targetVNasURI);
            targetArgs.setvNAS(targetVNAS);
        }
        _log.info("Assigning file replication policy: {} to vpool: {}", filePolicyToAssign, vpoolURI);
        BiosCommandResult result = getDevice(sourceSystem.getSystemType()).checkFileReplicationPolicyExistsOrCreate(sourceSystem, targetSystem, sourceArgs, targetArgs);
        if (result.getCommandPending()) {
            return;
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        if (result.isCommandSuccess()) {
            WorkflowStepCompleter.stepSucceded(opId);
        }
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) 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 4 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy 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 5 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy 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)

Aggregations

FilePolicy (com.emc.storageos.db.client.model.FilePolicy)70 URI (java.net.URI)25 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)21 FileShare (com.emc.storageos.db.client.model.FileShare)18 StringSet (com.emc.storageos.db.client.model.StringSet)18 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)18 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)18 ControllerException (com.emc.storageos.volumecontroller.ControllerException)18 ArrayList (java.util.ArrayList)18 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)16 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)15 WorkflowException (com.emc.storageos.workflow.WorkflowException)15 PolicyStorageResource (com.emc.storageos.db.client.model.PolicyStorageResource)14 MapFilePolicy (com.emc.storageos.api.mapper.functions.MapFilePolicy)13 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)13 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)13 Path (javax.ws.rs.Path)13 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)12 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 URISyntaxException (java.net.URISyntaxException)12