Search in sources :

Example 46 with IsilonApi

use of com.emc.storageos.isilon.restapi.IsilonApi in project coprhd-controller by CoprHD.

the class IsilonFileStorageDevice method doApplyFileReplicationPolicy.

private BiosCommandResult doApplyFileReplicationPolicy(FilePolicy filePolicy, FileDeviceInputOutput args, FileShare fs, StorageSystem storageObj) {
    IsilonApi isi = getIsilonDevice(storageObj);
    FileShare targetFS = null;
    String sourcePath = generatePathForPolicy(filePolicy, fs, args);
    String scheduleValue = getIsilonPolicySchedule(filePolicy);
    String targetPath = null;
    String targetHost = null;
    StorageSystem targetSystem = null;
    NASServer targetNasServer = null;
    if (fs.getPersonality() != null && PersonalityTypes.SOURCE.name().equalsIgnoreCase(fs.getPersonality())) {
        String targetFs = fs.getMirrorfsTargets().iterator().next();
        targetFS = _dbClient.queryObject(FileShare.class, URI.create(targetFs));
        targetPath = generatePathForPolicy(filePolicy, targetFS, args);
        // Add the suffix only for local replication policy at higher level
        if (filePolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.LOCAL.name()) && !FilePolicyApplyLevel.file_system.name().equalsIgnoreCase(filePolicy.getApplyAt())) {
            targetPath = targetPath + "_localTarget";
        }
        // Get the target smart connect zone!!
        targetHost = FileOrchestrationUtils.getTargetHostPortForReplication(_dbClient, targetFS);
        targetSystem = _dbClient.queryObject(StorageSystem.class, targetFS.getStorageDevice());
        if (targetFS.getVirtualNAS() != null) {
            targetNasServer = _dbClient.queryObject(VirtualNAS.class, targetFS.getVirtualNAS());
        }
    }
    IsilonApi isiApiOfTarget = getIsilonDevice(targetSystem);
    String targetClusterName = isiApiOfTarget.getClusterConfig().getName();
    String sourceClustername = isi.getClusterConfig().getName();
    String policyName = FileOrchestrationUtils.generateNameForSyncIQPolicy(sourceClustername, targetClusterName, filePolicy, fs, args, sourcePath);
    IsilonSyncPolicy isiSynIQPolicy = getEquivalentIsilonSyncIQPolicy(isi, sourcePath);
    PolicyStorageResource policyStorageResource = null;
    if (isiSynIQPolicy != null) {
        boolean validPolicy = validateIsilonReplicationPolicy(isiSynIQPolicy, filePolicy, targetPath, targetSystem, storageObj);
        if (validPolicy) {
            _log.info("File Policy {} is already applied and running.", filePolicy.toString());
            // Verify the policy was mapped to FileStorageResource
            if (null == FileOrchestrationUtils.findPolicyStorageResourceByNativeId(_dbClient, storageObj, filePolicy, args, sourcePath)) {
                _log.info("Isilon policy found for {}, creating policy storage resouce to further management", filePolicy.getFilePolicyName());
                // update the policy object in DB
                policyStorageResource = FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, storageObj, filePolicy, args, sourcePath, isiSynIQPolicy.getName(), isiSynIQPolicy.getId(), targetSystem, targetNasServer, targetPath);
                // for existing policy's on device
                // label - label is generated from ViPR
                policyStorageResource.setLabel(policyName);
                _dbClient.updateObject(policyStorageResource);
            }
            return BiosCommandResult.createSuccessfulResult();
        } else {
            throw DeviceControllerException.exceptions.assignFilePolicyFailed(filePolicy.getFilePolicyName(), filePolicy.getApplyAt(), "File policy and Isilon syncIQ policy differs for path: " + sourcePath);
        }
    } else {
        IsilonSyncPolicy policy = new IsilonSyncPolicy(policyName, sourcePath, targetPath, targetHost, IsilonSyncPolicy.Action.sync);
        IsilonSyncPolicy8Above policycopy = new IsilonSyncPolicy8Above();
        if (scheduleValue != null && !scheduleValue.isEmpty()) {
            policy.setSchedule(scheduleValue);
        }
        if (filePolicy.getFilePolicyDescription() != null) {
            policy.setDescription(filePolicy.getFilePolicyDescription());
        }
        if (filePolicy.getNumWorkerThreads() != null && filePolicy.getNumWorkerThreads() > 0) {
            policy.setWorkersPerNode(filePolicy.getNumWorkerThreads().intValue());
        }
        policy.setEnabled(true);
        String policyId = null;
        if (VersionChecker.verifyVersionDetails(ONEFS_V8, storageObj.getFirmwareVersion()) >= 0) {
            if (filePolicy.getPriority() != null) {
                policycopy = policycopy.copy(policy);
                policycopy.setPriority(FilePolicyPriority.valueOf(filePolicy.getPriority()).ordinal());
            }
            policyId = isi.createReplicationPolicy8above(policycopy);
        } else {
            policyId = isi.createReplicationPolicy(policy);
        }
        if (policyId != null) {
            _log.info("Isilon File Policy {} created successfully with id {}", policyName, policyId);
            // update the policy object in DB
            FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, storageObj, filePolicy, args, sourcePath, policyName, policyId, targetSystem, targetNasServer, targetPath);
            return BiosCommandResult.createSuccessfulResult();
        }
    }
    return BiosCommandResult.createSuccessfulResult();
}
Also used : NASServer(com.emc.storageos.db.client.model.NASServer) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) IsilonSyncPolicy8Above(com.emc.storageos.isilon.restapi.IsilonSyncPolicy8Above) IsilonSyncPolicy(com.emc.storageos.isilon.restapi.IsilonSyncPolicy) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 47 with IsilonApi

use of com.emc.storageos.isilon.restapi.IsilonApi in project coprhd-controller by CoprHD.

the class IsilonFileStorageDevice method createIsilonSyncPolicy.

private String createIsilonSyncPolicy(StorageSystem storageObj, StorageSystem targetStorage, FilePolicy filePolicy, String sourcePath, String targetPath, String syncPolicyName, FileDeviceInputOutput sourceSystemArgs, FileDeviceInputOutput targetSystemArgs) {
    String scheduleValue = getIsilonPolicySchedule(filePolicy);
    _log.info("File replication policy : {} creation started", filePolicy.toString());
    try {
        VirtualNAS targetVNas = targetSystemArgs.getvNAS();
        URI targetVNasURI = null;
        if (targetVNas != null) {
            targetVNasURI = targetVNas.getId();
        }
        String targetHost = FileOrchestrationUtils.getTargetHostPortForReplication(_dbClient, targetStorage.getId(), targetSystemArgs.getVarray().getId(), targetVNasURI);
        IsilonApi isi = getIsilonDevice(storageObj);
        isi.createDir(sourcePath, true);
        IsilonSyncPolicy replicationPolicy = new IsilonSyncPolicy(syncPolicyName, sourcePath, targetPath, targetHost, Action.sync);
        if (scheduleValue != null && !scheduleValue.isEmpty()) {
            replicationPolicy.setSchedule(scheduleValue);
        }
        if (filePolicy.getFilePolicyDescription() != null) {
            replicationPolicy.setDescription(filePolicy.getFilePolicyDescription());
        }
        if (filePolicy.getNumWorkerThreads() != null && filePolicy.getNumWorkerThreads() > 0) {
            replicationPolicy.setWorkersPerNode(filePolicy.getNumWorkerThreads().intValue());
        }
        replicationPolicy.setEnabled(true);
        replicationPolicy.setSchedule(scheduleValue);
        String scheduleId;
        if (VersionChecker.verifyVersionDetails(ONEFS_V8, storageObj.getFirmwareVersion()) >= 0) {
            IsilonSyncPolicy8Above replicationPolicyCopy = new IsilonSyncPolicy8Above();
            replicationPolicyCopy = replicationPolicyCopy.copy(replicationPolicy);
            if (filePolicy.getPriority() != null) {
                replicationPolicyCopy.setPriority(FilePolicyPriority.valueOf(filePolicy.getPriority()).ordinal());
            }
            scheduleId = isi.createReplicationPolicy8above(replicationPolicyCopy);
        } else {
            scheduleId = isi.createReplicationPolicy(replicationPolicy);
        }
        FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, storageObj, filePolicy, sourceSystemArgs, sourcePath, syncPolicyName, scheduleId, targetStorage, targetSystemArgs.getvNAS(), targetPath);
        return scheduleId;
    } catch (IsilonException e) {
        throw e;
    }
}
Also used : VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonSyncPolicy8Above(com.emc.storageos.isilon.restapi.IsilonSyncPolicy8Above) IsilonSyncPolicy(com.emc.storageos.isilon.restapi.IsilonSyncPolicy) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 48 with IsilonApi

use of com.emc.storageos.isilon.restapi.IsilonApi 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 49 with IsilonApi

use of com.emc.storageos.isilon.restapi.IsilonApi in project coprhd-controller by CoprHD.

the class IsilonFileStorageDevice method updateSidInfoForNfsACE.

private void updateSidInfoForNfsACE(FileDeviceInputOutput args, StorageSystem storage) {
    IsilonApi isi = getIsilonDevice(storage);
    List<NfsACE> list = new ArrayList<NfsACE>();
    list.addAll(args.getNfsAclsToAdd());
    list.addAll(args.getNfsAclsToModify());
    list.addAll(args.getNfsAclsToDelete());
    for (NfsACE nfsACE : list) {
        String id = getIdForDomainUserOrGroup(isi, args.getvNAS(), nfsACE.getDomain(), nfsACE.getUser(), nfsACE.getType(), true);
        if (!id.isEmpty()) {
            nfsACE.setSid(id);
        }
    }
}
Also used : NfsACE(com.emc.storageos.model.file.NfsACE) ArrayList(java.util.ArrayList) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi)

Example 50 with IsilonApi

use of com.emc.storageos.isilon.restapi.IsilonApi in project coprhd-controller by CoprHD.

the class IsilonFileStorageDevice method isValidTargetHostOnExistingPolicy.

private boolean isValidTargetHostOnExistingPolicy(String existingPolicyTargetHost, StorageSystem system) {
    if (existingPolicyTargetHost != null && !existingPolicyTargetHost.isEmpty()) {
        // target cluster IP address is matching????
        if (existingPolicyTargetHost.equalsIgnoreCase(system.getIpAddress())) {
            return true;
        }
        IsilonApi isi = getIsilonDevice(system);
        String targetClusterName = isi.getClusterConfig().getName();
        // target cluster name is matching????
        if (existingPolicyTargetHost.equalsIgnoreCase(targetClusterName)) {
            return true;
        }
        // target cluster smart connect zone is matching???
        for (com.emc.storageos.db.client.model.StoragePort port : FileOrchestrationUtils.getStorageSystemPorts(_dbClient, system)) {
            if (existingPolicyTargetHost.equalsIgnoreCase(port.getPortName())) {
                return true;
            } else if (existingPolicyTargetHost.equalsIgnoreCase(port.getPortNetworkId())) {
                return true;
            }
        }
    }
    return false;
}
Also used : IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi)

Aggregations

IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)81 IsilonException (com.emc.storageos.isilon.restapi.IsilonException)64 URISyntaxException (java.net.URISyntaxException)31 URI (java.net.URI)22 IsilonCollectionException (com.emc.storageos.plugins.metering.isilon.IsilonCollectionException)21 ArrayList (java.util.ArrayList)18 IsilonSyncPolicy (com.emc.storageos.isilon.restapi.IsilonSyncPolicy)14 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)13 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)12 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)12 IOException (java.io.IOException)12 JSONException (org.codehaus.jettison.json.JSONException)12 FileShare (com.emc.storageos.db.client.model.FileShare)11 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)11 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)10 HashMap (java.util.HashMap)10 ControllerException (com.emc.storageos.volumecontroller.ControllerException)9 Test (org.junit.Test)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7