Search in sources :

Example 21 with PolicyStorageResource

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

the class IsilonFileStorageDevice method listSanpshotByPolicy.

@Override
public BiosCommandResult listSanpshotByPolicy(StorageSystem storageObj, FileDeviceInputOutput args) {
    FilePolicy sp = args.getFileProtectionPolicy();
    FileShare fs = args.getFs();
    String snapshotScheduleName = sp.getFilePolicyName() + "_" + args.getFsName();
    if (sp.getPolicyStorageResources() != null && !sp.getPolicyStorageResources().isEmpty()) {
        for (String uriResource : sp.getPolicyStorageResources()) {
            PolicyStorageResource policyRes = _dbClient.queryObject(PolicyStorageResource.class, URI.create(uriResource));
            if (policyRes != null && policyRes.getStorageSystem().equals(storageObj.getId())) {
                snapshotScheduleName = policyRes.getPolicyNativeId();
                break;
            }
        }
    }
    IsilonApi isi = getIsilonDevice(storageObj);
    String resumeToken = null;
    try {
        do {
            IsilonList<IsilonSnapshot> snapshots = isi.listSnapshotsCreatedByPolicy(resumeToken, snapshotScheduleName);
            if (snapshots != null) {
                for (IsilonSnapshot islon_snap : snapshots.getList()) {
                    _log.info("file policy snapshot is  : " + islon_snap.getName());
                    Snapshot snap = new Snapshot();
                    snap.setLabel(islon_snap.getName());
                    snap.setMountPath(islon_snap.getPath());
                    snap.setName(islon_snap.getName());
                    snap.setId(URIUtil.createId(Snapshot.class));
                    snap.setOpStatus(new OpStatusMap());
                    snap.setProject(new NamedURI(fs.getProject().getURI(), islon_snap.getName()));
                    snap.setMountPath(getSnapshotPath(islon_snap.getPath(), islon_snap.getName()));
                    snap.setParent(new NamedURI(fs.getId(), islon_snap.getName()));
                    StringMap map = new StringMap();
                    Long createdTime = Long.parseLong(islon_snap.getCreated()) * SEC_IN_MILLI;
                    String expiresTime = "Never";
                    if (islon_snap.getExpires() != null && !islon_snap.getExpires().isEmpty()) {
                        Long expTime = Long.parseLong(islon_snap.getExpires()) * SEC_IN_MILLI;
                        expiresTime = expTime.toString();
                    }
                    map.put("created", createdTime.toString());
                    map.put("expires", expiresTime);
                    map.put("schedule", sp.getFilePolicyName());
                    snap.setExtensions(map);
                    _dbClient.updateObject(snap);
                }
                resumeToken = snapshots.getToken();
            }
        } while (resumeToken != null && !resumeToken.equalsIgnoreCase("null"));
    } catch (IsilonException e) {
        _log.error("listing snapshot by file policy failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
    Task task = TaskUtils.findTaskForRequestId(_dbClient, fs.getId(), args.getOpId());
    // set task to completed and progress to 100 and store in DB, so waiting thread in apisvc can read it.
    task.ready();
    task.setProgress(100);
    _dbClient.updateObject(task);
    return BiosCommandResult.createSuccessfulResult();
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) Task(com.emc.storageos.db.client.model.Task) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) NamedURI(com.emc.storageos.db.client.model.NamedURI) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) Snapshot(com.emc.storageos.db.client.model.Snapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 22 with PolicyStorageResource

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

the class IsilonFileStorageDevice method doResyncLink.

@Override
public BiosCommandResult doResyncLink(StorageSystem system, FileShare fs, TaskCompleter completer) {
    FileShare sourceFS = null;
    FileShare targetFS = null;
    StorageSystem targetSystem = null;
    StorageSystem sourceSystem = null;
    boolean isMirrorPolicy = false;
    if (fs.getPersonality().equals(PersonalityTypes.TARGET.name())) {
        sourceFS = _dbClient.queryObject(FileShare.class, fs.getParentFileShare());
        targetFS = fs;
        isMirrorPolicy = true;
    } else if (fs.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
        sourceFS = fs;
        if (null != fs.getMirrorfsTargets() && !fs.getMirrorfsTargets().isEmpty()) {
            List<String> targetfileUris = new ArrayList<String>();
            targetfileUris.addAll(fs.getMirrorfsTargets());
            targetFS = _dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        } else {
            ServiceError serviceError = DeviceControllerErrors.isilon.unableToGetTargetFileSystem(sourceFS.getLabel());
            return BiosCommandResult.createErrorResult(serviceError);
        }
    }
    targetSystem = _dbClient.queryObject(StorageSystem.class, targetFS.getStorageDevice());
    sourceSystem = _dbClient.queryObject(StorageSystem.class, sourceFS.getStorageDevice());
    PolicyStorageResource policyStrRes = getEquivalentPolicyStorageResource(sourceFS, _dbClient);
    if (policyStrRes != null) {
        IsilonSyncPolicy syncTargetPolicy = policyNativeIdValidation(sourceSystem, policyStrRes);
        // In case of failback step 4 we do resysc on the target file system, so we need to append _mirror
        if (isMirrorPolicy) {
            String mirrorPolicyName = syncTargetPolicy.getName();
            mirrorPolicyName = mirrorPolicyName.concat(MIRROR_POLICY);
            // 'resync-prep' on target mirror policy
            return doResyncPrepTargetPolicy(sourceSystem, syncTargetPolicy.getName(), targetSystem, mirrorPolicyName, completer);
        } else {
            // 'resync-prep' operation on source storagesystem
            return doResyncPrepSourcePolicy(sourceSystem, targetSystem, syncTargetPolicy.getId(), completer);
        }
    }
    ServiceError serviceError = DeviceControllerErrors.isilon.unableToGetPolicy(system.getLabel(), "Unable to get policy details");
    return BiosCommandResult.createErrorResult(serviceError);
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) IsilonList(com.emc.storageos.isilon.restapi.IsilonApi.IsilonList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) IsilonSyncPolicy(com.emc.storageos.isilon.restapi.IsilonSyncPolicy) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 23 with PolicyStorageResource

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

the class VirtualPoolFileReplicationPolicyMigration method updatePolicyStorageResouce.

private void updatePolicyStorageResouce(StorageSystem system, FilePolicy filePolicy, FileShare fs) {
    logger.info("Creating policy storage resource for storage {} fs {} and policy {} ", system.getLabel(), fs.getLabel(), filePolicy.getFilePolicyName());
    PolicyStorageResource policyStorageResource = new PolicyStorageResource();
    policyStorageResource.setId(URIUtil.createId(PolicyStorageResource.class));
    policyStorageResource.setFilePolicyId(filePolicy.getId());
    policyStorageResource.setStorageSystem(system.getId());
    policyStorageResource.setPolicyNativeId(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(), filePolicy.getFilePolicyType(), fs.getNativeId()));
    }
    if (fs.getMirrorfsTargets() != null && !fs.getMirrorfsTargets().isEmpty()) {
        String[] targetFSs = fs.getMirrorfsTargets().toArray(new String[fs.getMirrorfsTargets().size()]);
        // Today we support single target!!
        FileShare fsTarget = dbClient.queryObject(FileShare.class, URI.create(targetFSs[0]));
        // In older release, policy name was set to target file system lable!!
        policyStorageResource.setPolicyNativeId(fsTarget.getLabel());
        // Update the target resource details!!!
        FileReplicaPolicyTargetMap fileReplicaPolicyTargetMap = new FileReplicaPolicyTargetMap();
        FileReplicaPolicyTarget target = new FileReplicaPolicyTarget();
        target.setAppliedAt(filePolicy.getApplyAt());
        target.setStorageSystem(fsTarget.getStorageDevice().toString());
        target.setPath(fsTarget.getNativeId());
        NASServer targetNasServer = null;
        if (fsTarget.getVirtualNAS() != null) {
            targetNasServer = dbClient.queryObject(VirtualNAS.class, fsTarget.getVirtualNAS());
        } else {
            StorageSystem targetSystem = dbClient.queryObject(StorageSystem.class, fsTarget.getStorageDevice());
            // Get the physical NAS for the storage system!!
            PhysicalNAS pNAS = getSystemPhysicalNAS(targetSystem);
            if (pNAS != null) {
                targetNasServer = pNAS;
            }
        }
        if (targetNasServer != null) {
            target.setNasServer(targetNasServer.getId().toString());
        }
        String key = target.getFileTargetReplicaKey();
        fileReplicaPolicyTargetMap.put(key, target);
        policyStorageResource.setFileReplicaPolicyTargetMap(fileReplicaPolicyTargetMap);
    }
    dbClient.createObject(policyStorageResource);
    filePolicy.addPolicyStorageResources(policyStorageResource.getId());
    filePolicy.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) FileReplicaPolicyTargetMap(com.emc.storageos.db.client.model.FileReplicaPolicyTargetMap) FileReplicaPolicyTarget(com.emc.storageos.db.client.model.FileReplicaPolicyTarget) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) PhysicalNAS(com.emc.storageos.db.client.model.PhysicalNAS) FileShare(com.emc.storageos.db.client.model.FileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 24 with PolicyStorageResource

use of com.emc.storageos.db.client.model.PolicyStorageResource 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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FilePolicyUnAssignWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FilePolicyUnAssignWorkflowCompleter) Workflow(com.emc.storageos.workflow.Workflow) FileObject(com.emc.storageos.db.client.model.FileObject) URI(java.net.URI) 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 25 with PolicyStorageResource

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

the class IsilonFileStorageDevice method doPauseLink.

@Override
public BiosCommandResult doPauseLink(StorageSystem system, FileShare source) {
    IsilonSyncPolicy syncpolicy = null;
    PolicyStorageResource policyStrRes = getEquivalentPolicyStorageResource(source, _dbClient);
    if (policyStrRes != null) {
        syncpolicy = policyNativeIdValidation(system, policyStrRes);
        String policyId = syncpolicy.getId();
        JobState policyState = syncpolicy.getLastJobState();
        if (policyState.equals(JobState.running) || policyState.equals(JobState.paused)) {
            mirrorOperations.doCancelReplicationPolicy(system, policyId);
        }
        return mirrorOperations.doStopReplicationPolicy(system, policyId);
    }
    ServiceError serviceError = DeviceControllerErrors.isilon.unableToCreateFileShare();
    return BiosCommandResult.createErrorResult(serviceError);
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) JobState(com.emc.storageos.isilon.restapi.IsilonSyncPolicy.JobState) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) IsilonSyncPolicy(com.emc.storageos.isilon.restapi.IsilonSyncPolicy)

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