Search in sources :

Example 6 with IsilonException

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

the class IsilonFileStorageDevice method doApplyFilePolicy.

@Override
public BiosCommandResult doApplyFilePolicy(StorageSystem storageObj, FileDeviceInputOutput args) {
    FileShare fs = args.getFs();
    try {
        FilePolicy filePolicy = args.getFileProtectionPolicy();
        String policyPath = generatePathForPolicy(filePolicy, fs, args);
        // Verify the ViPR resource on which the policy is applying is present in
        // Isilon path definition.
        // Otherwise, this method throws corresponding exception.
        checkAppliedResourceNamePartOfFilePolicyPath(policyPath, filePolicy, args);
        // Otherwise applied the policy on corresponding Isilon device path.
        if (checkPolicyAppliedOnPath(storageObj, args, policyPath)) {
            String msg = String.format("File Policy template %s is already applied on storage system %s path %s", filePolicy.getFilePolicyName(), storageObj.getLabel(), policyPath);
            _log.info(msg);
            return BiosCommandResult.createSuccessfulResult();
        } else {
            if (filePolicy.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_replication.name())) {
                doApplyFileReplicationPolicy(filePolicy, args, fs, storageObj);
            } else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
                doApplyFileSnapshotPolicy(filePolicy, args, fs, storageObj);
            }
            return BiosCommandResult.createSuccessfulResult();
        }
    } catch (IsilonException e) {
        _log.error("apply file policy failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 7 with IsilonException

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

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

use of com.emc.storageos.isilon.restapi.IsilonException 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)

Example 10 with IsilonException

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

the class IsilonFileStorageDevice method getIdForDomainUserOrGroup.

/**
 * It search all the provider configured in NASServer and gives sid for the user/group and Domain
 * if checkUidRange is enable and uid value is between 1,000,000-2,000,000 return sid,.Otherwise uid or gid
 *
 * @param isi Isilon Api to connect with Isilon
 * @param nas - NASServer object to get all the provider info.
 * @param domain -domain should be in FQDN format
 * @param user name of the user
 * @param type can be user or group
 * @param checkUidRangeEnable to enable the uid range check
 * @return sidOrUid if found or else empty String
 */
private String getIdForDomainUserOrGroup(IsilonApi isi, NASServer nas, String domain, String user, String type, boolean checkUidRangeEnable) {
    // we can get all auth providers and zone name from NASServer
    String sidOrUid = "";
    boolean sidOrUidfound = false;
    try {
        String zone = nas.getNasName();
        List<String> authProviders = new ArrayList<String>();
        CifsServerMap cifsServersMap = nas.getCifsServersMap();
        authProviders = getAuthProviderListFromCifsServerMap(cifsServersMap);
        _log.info("Auth providers for NASServer {} are {} ", nas.getNasName(), authProviders);
        for (String provider : authProviders) {
            if ("user".equals(type)) {
                // no need of resume token as we are expecting only one result.
                List<IsilonUser> userDetails = isi.getUsersDetail(zone, provider, domain, user, "");
                if (!CollectionUtils.isEmpty(userDetails)) {
                    IsilonIdentity sid = userDetails.get(0).getSid();
                    sidOrUid = sid.getId();
                    sidOrUidfound = true;
                    // Range check is only done for nfsacl, should be true for it.
                    if (checkUidRangeEnable) {
                        // For gid, check what range it�s in. If it�s 1,000,000-2,000,000,
                        // it�s generated by OneFS and you should use the SID. Otherwise you should use the unix gid.
                        IsilonIdentity uid = userDetails.get(0).getUid();
                        if (isUidInRange(uid)) {
                            _log.debug("using uid {} instead of sid {} ", uid.getId(), sidOrUid);
                            sidOrUid = uid.getId();
                        }
                    }
                    _log.info("For user name {} and domain {} sid/uid is {}", user, domain, sidOrUid);
                    break;
                }
            } else {
                List<IsilonGroup> groupDetails = isi.getGroupsDetail(zone, provider, domain, user, "");
                // no need of resume token as we are expecting only one result.
                if (!CollectionUtils.isEmpty(groupDetails)) {
                    IsilonIdentity id = groupDetails.get(0).getSid();
                    sidOrUid = id.getId();
                    sidOrUidfound = true;
                    if (checkUidRangeEnable) {
                        // For gid, check what range it�s in. If it�s 1,000,000-2,000,000,
                        // it�s generated by OneFS and you should use the SID. Otherwise you should use the unix gid.
                        IsilonIdentity gid = groupDetails.get(0).getGid();
                        if (isUidInRange(gid)) {
                            _log.debug("using gid {} instead of sid {} ", gid.getId(), sidOrUid);
                            sidOrUid = gid.getId();
                        }
                    }
                    _log.info("For group name {} and domain {} sid is {}", user, domain, sidOrUid);
                    break;
                }
            }
        }
    } catch (IsilonException e) {
        _log.error("Error while finding sid/uid for name {} and domain {} ", user, domain, e);
    }
    if (sidOrUidfound) {
        _log.info("Sid/uid for user name {}, type {} and domain {} is {}", user, type, domain, sidOrUid);
    } else {
        _log.error("No sid/uid found for user name {}, type {} and domain {} ", user, type, domain);
    }
    return sidOrUid;
}
Also used : CifsServerMap(com.emc.storageos.db.client.model.CifsServerMap) ArrayList(java.util.ArrayList) IsilonUser(com.emc.storageos.isilon.restapi.IsilonUser) IsilonIdentity(com.emc.storageos.isilon.restapi.IsilonIdentity) IsilonGroup(com.emc.storageos.isilon.restapi.IsilonGroup) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Aggregations

IsilonException (com.emc.storageos.isilon.restapi.IsilonException)62 IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)53 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)15 URISyntaxException (java.net.URISyntaxException)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)12 IsilonSyncPolicy (com.emc.storageos.isilon.restapi.IsilonSyncPolicy)12 IsilonCollectionException (com.emc.storageos.plugins.metering.isilon.IsilonCollectionException)12 URI (java.net.URI)12 ArrayList (java.util.ArrayList)10 FileShare (com.emc.storageos.db.client.model.FileShare)9 Test (org.junit.Test)8 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)7 ControllerException (com.emc.storageos.volumecontroller.ControllerException)7 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)7 NamedURI (com.emc.storageos.db.client.model.NamedURI)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)5 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)5 FileDeviceInputOutput (com.emc.storageos.volumecontroller.FileDeviceInputOutput)5 IOException (java.io.IOException)5