Search in sources :

Example 6 with IsilonApi

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

the class IsilonFileStorageDevice method createIsilonSnapshotPolicySchedule.

private void createIsilonSnapshotPolicySchedule(StorageSystem storageObj, FilePolicy filePolicy, String path, String snapshotSchedulePolicyName, FileDeviceInputOutput args, String filePolicyBasePath) {
    String pattern = snapshotSchedulePolicyName + "_%Y-%m-%d_%H-%M";
    String scheduleValue = getIsilonPolicySchedule(filePolicy);
    Integer expireValue = getIsilonSnapshotExpireValue(filePolicy);
    _log.info("File Policy : {} creation started", filePolicy.toString());
    try {
        IsilonApi isi = getIsilonDevice(storageObj);
        isi.createDir(path, true);
        String scheduleId = isi.createSnapshotSchedule(snapshotSchedulePolicyName, path, scheduleValue, pattern, expireValue);
        _log.info("Isilon File Policy {} created successfully.", snapshotSchedulePolicyName);
        FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, storageObj, filePolicy, args, filePolicyBasePath, snapshotSchedulePolicyName, scheduleId, null, null, null);
    } catch (IsilonException e) {
        throw e;
    }
}
Also used : IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 7 with IsilonApi

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

the class IsilonFileStorageDevice method doesSnapshotExistsForFSPath.

private boolean doesSnapshotExistsForFSPath(StorageSystem storageSystem, String isilonAccessZone, String path) throws IsilonCollectionException {
    URI storageSystemId = storageSystem.getId();
    String resumeToken = null;
    try {
        _log.info("Checking snapshots for path {}  on Isilon storage system: {} in access zone {} - start", path, storageSystem.getLabel(), isilonAccessZone);
        IsilonApi isilonApi = getIsilonDevice(storageSystem);
        do {
            IsilonList<IsilonSnapshot> isilonSnapshots = isilonApi.listSnapshots(resumeToken, path);
            List<IsilonSnapshot> snpashots = isilonSnapshots.getList();
            for (IsilonSnapshot snapshot : snpashots) {
                if (snapshot.getPath() == null || snapshot.getPath().isEmpty()) {
                    _log.info("Ignoring snapshot {} as it is not having any path", snapshot);
                    continue;
                }
                if (snapshot.getPath().equals(path)) {
                    _log.info("Found snapshot on path {} in Ision: {}", path, storageSystem.getLabel());
                    return true;
                }
            }
            resumeToken = isilonSnapshots.getToken();
        } while (resumeToken != null);
        _log.info("Snapshots not found with path {} on Ision: {} in access zone: {}", path, storageSystem.getLabel(), isilonAccessZone);
        return false;
    } catch (IsilonException ie) {
        _log.error("doesSnapshotExistsForFSPath failed. Storage system: {}", storageSystemId, ie);
        IsilonCollectionException ice = new IsilonCollectionException("doesSnapshotExistsForFSPath failed. Storage system: " + storageSystemId);
        ice.initCause(ie);
        throw ice;
    } catch (Exception e) {
        _log.error("doesSnapshotExistsForFSPath failed. Storage system: {}", storageSystemId, e);
        IsilonCollectionException ice = new IsilonCollectionException("doesSnapshotExistsForFSPath failed. Storage system: " + storageSystemId);
        ice.initCause(e);
        throw ice;
    }
}
Also used : IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) IsilonCollectionException(com.emc.storageos.plugins.metering.isilon.IsilonCollectionException) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IsilonCollectionException(com.emc.storageos.plugins.metering.isilon.IsilonCollectionException) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 8 with IsilonApi

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

the class IsilonFileStorageDevice method checkFileReplicationPolicyExistsOrCreate.

@Override
public BiosCommandResult checkFileReplicationPolicyExistsOrCreate(StorageSystem sourceStorageObj, StorageSystem targetStorageObj, FileDeviceInputOutput sourceSytemArgs, FileDeviceInputOutput targetSytemArgs) {
    FilePolicy filePolicy = sourceSytemArgs.getFileProtectionPolicy();
    // Source Path
    String sourcePath = getFilePolicyPath(sourceStorageObj, filePolicy.getApplyAt(), sourceSytemArgs);
    String targetPath = getFilePolicyPath(targetStorageObj, filePolicy.getApplyAt(), targetSytemArgs);
    if (FileReplicationType.LOCAL.name().equalsIgnoreCase(filePolicy.getFileReplicationType())) {
        targetPath = targetPath + "_localTarget";
    }
    // Policy Name
    BiosCommandResult result = null;
    try {
        IsilonApi sourceIsi = getIsilonDevice(sourceStorageObj);
        IsilonApi targetIsi = getIsilonDevice(targetStorageObj);
        String sourceClusterName = sourceIsi.getClusterConfig().getName();
        String targetClusterName = targetIsi.getClusterConfig().getName();
        checkAppliedResourceNamePartOfFilePolicyPath(sourcePath, filePolicy, sourceSytemArgs);
        String policyName = FileOrchestrationUtils.generateNameForSyncIQPolicy(sourceClusterName, targetClusterName, filePolicy, null, sourceSytemArgs, sourcePath);
        ArrayList<IsilonSyncPolicy> isiReplicationPolicies = sourceIsi.getReplicationPolicies().getList();
        IsilonSyncPolicy isilonReplicationSchedule = checkForReplicationPolicyOnIsilon(isiReplicationPolicies, filePolicy, sourcePath, targetPath);
        if (isilonReplicationSchedule != null) {
            boolean validPolicy = validateIsilonReplicationPolicy(isilonReplicationSchedule, filePolicy, targetPath, targetStorageObj, sourceStorageObj);
            if (validPolicy) {
                // Verify the policy was mapped to FileStorageResource
                if (null == FileOrchestrationUtils.findPolicyStorageResourceByNativeId(_dbClient, sourceStorageObj, filePolicy, sourceSytemArgs, sourcePath)) {
                    _log.info("Isilon policy found for {}, creating policy storage resouce to further management", filePolicy.getFilePolicyName());
                    FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, sourceStorageObj, filePolicy, sourceSytemArgs, sourcePath, isilonReplicationSchedule.getName(), isilonReplicationSchedule.getId(), targetStorageObj, targetSytemArgs.getvNAS(), targetPath);
                }
                result = BiosCommandResult.createSuccessfulResult();
            } else {
                throw DeviceControllerException.exceptions.assignFilePolicyFailed(filePolicy.getFilePolicyName(), filePolicy.getApplyAt(), "File policy and Isilon syncIQ policy differs for path: " + sourcePath);
            }
        } else {
            // to avoid DL
            if (targetIsi.existsDir(targetPath) && targetIsi.fsDirHasData(targetPath)) {
                // Fail to assign policy to target which has data in it!!!
                String errMsg = String.format("Target %s:%s directory has content in it", targetClusterName, targetPath);
                _log.error("Unable create policy due to, {}", errMsg);
                throw DeviceControllerException.exceptions.assignFilePolicyFailed(filePolicy.getFilePolicyName(), filePolicy.getApplyAt(), errMsg);
            }
            // Create replication sync policy.
            createIsilonSyncPolicy(sourceStorageObj, targetStorageObj, filePolicy, sourcePath, targetPath, policyName, sourceSytemArgs, targetSytemArgs);
            result = BiosCommandResult.createSuccessfulResult();
        }
    } catch (IsilonException e) {
        _log.error("Assigning file policy failed.", e);
        result = BiosCommandResult.createErrorResult(e);
    }
    return result;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonSyncPolicy(com.emc.storageos.isilon.restapi.IsilonSyncPolicy) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 9 with IsilonApi

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

the class IsilonFileStorageDevice method doDeleteShare.

@Override
public BiosCommandResult doDeleteShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
    try {
        _log.info("IsilonFileStorageDevice doDeleteShare: {} - start");
        IsilonApi isi = getIsilonDevice(storage);
        isiDeleteShare(isi, args, smbFileShare);
        _log.info("IsilonFileStorageDevice doDeleteShare {} - complete");
        return BiosCommandResult.createSuccessfulResult();
    } catch (IsilonException e) {
        _log.error("doDeleteShare failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 10 with IsilonApi

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

the class IsilonFileStorageDevice method doUnassignFilePolicy.

@Override
public BiosCommandResult doUnassignFilePolicy(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    try {
        IsilonApi isi = getIsilonDevice(storage);
        FilePolicy filePolicy = args.getFileProtectionPolicy();
        PolicyStorageResource policyResource = args.getPolicyStorageResource();
        if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
            // Get the policy details by id
            IsilonSyncPolicy isiSyncPolicy = isi.getReplicationPolicy(policyResource.getPolicyNativeId());
            if (isiSyncPolicy != null) {
                _log.info("deleting Isilon replication policy: {}", isiSyncPolicy.toString());
                String policyName = isiSyncPolicy.getName();
                JobState policyState = isiSyncPolicy.getLastJobState();
                if (policyState.equals(JobState.running) || policyState.equals(JobState.paused)) {
                    _log.info("Canceling Replication Policy  -{} because policy is in - {} state ", policyName, policyState);
                    // If the policy is running, Cancel the job before unassign policy!!
                    BiosCommandResult cmdResult = mirrorOperations.doCancelReplicationPolicy(isi, isiSyncPolicy.getName());
                    if (!cmdResult.isCommandSuccess()) {
                        return cmdResult;
                    } else {
                        // If the replication job still running through exception
                        isiSyncPolicy = isi.getReplicationPolicy(isiSyncPolicy.getName());
                        if (isiSyncPolicy.getLastJobState().equals(JobState.running)) {
                            ServiceError error = DeviceControllerErrors.isilon.jobFailed("Unable Stop Replication policy and policy state  :" + isiSyncPolicy.getLastJobState().toString());
                            return BiosCommandResult.createErrorResult(error);
                        }
                    }
                }
                // delete replication policy using policy id
                isi.deleteReplicationPolicy(isiSyncPolicy.getId());
            } else {
                _log.info("replication policy: {} doesn't exists on storage system", filePolicy.toString());
            }
            return BiosCommandResult.createSuccessfulResult();
        } else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
            IsilonSnapshotSchedule isiSchedulePolicy = getEquivalentIsilonSnapshotSchedule(isi, policyResource.getResourcePath());
            if (isiSchedulePolicy != null) {
                _log.info("deleting Isilon Snapshot schedule: {}", isiSchedulePolicy.toString());
                isi.deleteSnapshotSchedule(policyResource.getPolicyNativeId());
            } else {
                _log.info("snapshot schedule: {} doesn't exists on storage system", filePolicy.toString());
            }
            return BiosCommandResult.createSuccessfulResult();
        }
        return BiosCommandResult.createSuccessfulResult();
    } catch (IsilonException e) {
        _log.error("unassign file policy failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) JobState(com.emc.storageos.isilon.restapi.IsilonSyncPolicy.JobState) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) IsilonSyncPolicy(com.emc.storageos.isilon.restapi.IsilonSyncPolicy) IsilonSnapshotSchedule(com.emc.storageos.isilon.restapi.IsilonSnapshotSchedule) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

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