Search in sources :

Example 1 with FileSnapshotPolicyParam

use of com.emc.storageos.model.file.policy.FileSnapshotPolicyParam in project coprhd-controller by CoprHD.

the class FilePolicyApiTest method testCreatePolicyWithInValidPolicyScheduleDayOfWeek.

@Test
public void testCreatePolicyWithInValidPolicyScheduleDayOfWeek() {
    FilePolicyCreateParam param = new FilePolicyCreateParam();
    setFilePolicyMandatoryParams(param);
    FileSnapshotPolicyParam snapshotPolicyParam = new FileSnapshotPolicyParam();
    FileSnapshotPolicyExpireParam snapshotExpireParams = new FileSnapshotPolicyExpireParam();
    snapshotExpireParams.setExpireType(SnapshotExpireType.NEVER.toString());
    snapshotPolicyParam.setSnapshotExpireParams(snapshotExpireParams);
    FilePolicyScheduleParams policySchedule = new FilePolicyScheduleParams();
    policySchedule.setScheduleRepeat(6L);
    policySchedule.setScheduleTime("13:00");
    policySchedule.setScheduleFrequency("WEEKS");
    // Invalid day of month
    policySchedule.setScheduleDayOfWeek("invalid day");
    snapshotPolicyParam.setPolicySchedule(policySchedule);
    param.setSnapshotPolicyPrams(snapshotPolicyParam);
    ClientResponse createFilePolicyResp = rSys.path(FILE_POLICIES).post(ClientResponse.class, param);
    Assert.assertEquals(createFilePolicyResp.toString(), HttpStatus.SC_BAD_REQUEST, createFilePolicyResp.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileSnapshotPolicyExpireParam(com.emc.storageos.model.file.policy.FileSnapshotPolicyExpireParam) FilePolicyCreateParam(com.emc.storageos.model.file.policy.FilePolicyCreateParam) FileSnapshotPolicyParam(com.emc.storageos.model.file.policy.FileSnapshotPolicyParam) FilePolicyScheduleParams(com.emc.storageos.model.file.policy.FilePolicyScheduleParams) Test(org.junit.Test)

Example 2 with FileSnapshotPolicyParam

use of com.emc.storageos.model.file.policy.FileSnapshotPolicyParam in project coprhd-controller by CoprHD.

the class FilePolicyApiTest method testFileSnapshotPolicyCreate.

@Test
public void testFileSnapshotPolicyCreate() {
    FilePolicyCreateParam param = new FilePolicyCreateParam();
    param.setPolicyName(filePolicyName);
    param.setPolicyDescription(filePolicyName);
    param.setPolicyType(FilePolicyType.file_snapshot.name());
    param.setApplyAt(FilePolicy.FilePolicyApplyLevel.vpool.toString());
    FilePolicyScheduleParams policySchedule = new FilePolicyScheduleParams();
    policySchedule.setScheduleFrequency("DAYS");
    policySchedule.setScheduleRepeat(6L);
    policySchedule.setScheduleTime("12:00");
    FileSnapshotPolicyParam snapshotPolicyParam = new FileSnapshotPolicyParam();
    snapshotPolicyParam.setSnapshotNamePattern("snapshot policy 1");
    snapshotPolicyParam.setPolicySchedule(policySchedule);
    FileSnapshotPolicyExpireParam snapshotExpireParams = new FileSnapshotPolicyExpireParam();
    snapshotExpireParams.setExpireType(SnapshotExpireType.NEVER.toString());
    snapshotPolicyParam.setSnapshotExpireParams(snapshotExpireParams);
    param.setSnapshotPolicyPrams(snapshotPolicyParam);
    ClientResponse createFilePolicyResp = rSys.path(FILE_POLICIES).post(ClientResponse.class, param);
    Assert.assertEquals(HttpStatus.SC_OK, createFilePolicyResp.getStatus());
    FilePolicyCreateResp createdFilePolicy = createFilePolicyResp.getEntity(FilePolicyCreateResp.class);
    Assert.assertTrue(filePolicyName.equals(createdFilePolicy.getName()));
    createdFileSnapshotPolicyURI = createdFilePolicy.getId();
    System.out.println("New snapshot policy ID: " + createdFileSnapshotPolicyURI);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileSnapshotPolicyExpireParam(com.emc.storageos.model.file.policy.FileSnapshotPolicyExpireParam) FilePolicyCreateParam(com.emc.storageos.model.file.policy.FilePolicyCreateParam) FilePolicyCreateResp(com.emc.storageos.model.file.policy.FilePolicyCreateResp) FileSnapshotPolicyParam(com.emc.storageos.model.file.policy.FileSnapshotPolicyParam) FilePolicyScheduleParams(com.emc.storageos.model.file.policy.FilePolicyScheduleParams) Test(org.junit.Test)

Example 3 with FileSnapshotPolicyParam

use of com.emc.storageos.model.file.policy.FileSnapshotPolicyParam in project coprhd-controller by CoprHD.

the class FilePolicyApiTest method testCreatePolicyWithInValidPolicyScheduleFrequency.

@Test
public void testCreatePolicyWithInValidPolicyScheduleFrequency() {
    FilePolicyCreateParam param = new FilePolicyCreateParam();
    setFilePolicyMandatoryParams(param);
    FilePolicyScheduleParams policySchedule = new FilePolicyScheduleParams();
    policySchedule.setScheduleRepeat(6L);
    policySchedule.setScheduleTime("12:00");
    policySchedule.setScheduleFrequency("some_invalid_value");
    FileSnapshotPolicyParam snapshotPolicyParam = new FileSnapshotPolicyParam();
    snapshotPolicyParam.setPolicySchedule(policySchedule);
    param.setSnapshotPolicyPrams(snapshotPolicyParam);
    FileSnapshotPolicyExpireParam snapshotExpireParams = new FileSnapshotPolicyExpireParam();
    snapshotExpireParams.setExpireType(SnapshotExpireType.NEVER.toString());
    snapshotPolicyParam.setSnapshotExpireParams(snapshotExpireParams);
    ClientResponse createFilePolicyResp = rSys.path(FILE_POLICIES).post(ClientResponse.class, param);
    Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, createFilePolicyResp.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileSnapshotPolicyExpireParam(com.emc.storageos.model.file.policy.FileSnapshotPolicyExpireParam) FilePolicyCreateParam(com.emc.storageos.model.file.policy.FilePolicyCreateParam) FileSnapshotPolicyParam(com.emc.storageos.model.file.policy.FileSnapshotPolicyParam) FilePolicyScheduleParams(com.emc.storageos.model.file.policy.FilePolicyScheduleParams) Test(org.junit.Test)

Example 4 with FileSnapshotPolicyParam

use of com.emc.storageos.model.file.policy.FileSnapshotPolicyParam in project coprhd-controller by CoprHD.

the class FilePolicyApiTest method testCreatePolicyWithInValidPolicyScheduleTime.

@Test
public void testCreatePolicyWithInValidPolicyScheduleTime() {
    FilePolicyCreateParam param = new FilePolicyCreateParam();
    setFilePolicyMandatoryParams(param);
    FileSnapshotPolicyParam snapshotPolicyParam = new FileSnapshotPolicyParam();
    FileSnapshotPolicyExpireParam snapshotExpireParams = new FileSnapshotPolicyExpireParam();
    snapshotExpireParams.setExpireType(SnapshotExpireType.NEVER.toString());
    snapshotPolicyParam.setSnapshotExpireParams(snapshotExpireParams);
    FilePolicyScheduleParams policySchedule = new FilePolicyScheduleParams();
    policySchedule.setScheduleRepeat(6L);
    // Invalid TIME
    policySchedule.setScheduleTime("67:00");
    policySchedule.setScheduleFrequency("DAYS");
    snapshotPolicyParam.setPolicySchedule(policySchedule);
    param.setSnapshotPolicyPrams(snapshotPolicyParam);
    ClientResponse createFilePolicyResp = rSys.path(FILE_POLICIES).post(ClientResponse.class, param);
    Assert.assertEquals(createFilePolicyResp.toString(), HttpStatus.SC_BAD_REQUEST, createFilePolicyResp.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileSnapshotPolicyExpireParam(com.emc.storageos.model.file.policy.FileSnapshotPolicyExpireParam) FilePolicyCreateParam(com.emc.storageos.model.file.policy.FilePolicyCreateParam) FileSnapshotPolicyParam(com.emc.storageos.model.file.policy.FileSnapshotPolicyParam) FilePolicyScheduleParams(com.emc.storageos.model.file.policy.FilePolicyScheduleParams) Test(org.junit.Test)

Example 5 with FileSnapshotPolicyParam

use of com.emc.storageos.model.file.policy.FileSnapshotPolicyParam in project coprhd-controller by CoprHD.

the class IsilonFileStorageDevice method updateStorageSystemFileSnapshotPolicy.

private BiosCommandResult updateStorageSystemFileSnapshotPolicy(IsilonApi isi, PolicyStorageResource policyRes, FilePolicy viprPolicy, FilePolicyUpdateParam policyUpdateParam) {
    try {
        ArrayList<IsilonSnapshotSchedule> isiSnapshotPolicies = isi.getSnapshotSchedules().getList();
        IsilonSnapshotSchedule snapPolicyAtPath = null;
        _log.info("Checking the right snapshotIQ policy ...");
        for (IsilonSnapshotSchedule snapPolicy : isiSnapshotPolicies) {
            // Hence identify the storage system policy in either way
            if (snapPolicy.getPath() != null && snapPolicy.getPath().equalsIgnoreCase(policyRes.getResourcePath()) && policyRes.getPolicyNativeId() != null && (policyRes.getPolicyNativeId().equalsIgnoreCase(snapPolicy.getName()) || policyRes.getPolicyNativeId().equalsIgnoreCase(snapPolicy.getId().toString()))) {
                snapPolicyAtPath = snapPolicy;
                break;
            }
        }
        if (snapPolicyAtPath != null) {
            _log.info("Found SnapshotIQ policy{} for path {} ", snapPolicyAtPath.getName(), snapPolicyAtPath.getPath());
            boolean bModifyPolicy = false;
            // Temp policy to store modified values.
            IsilonSnapshotSchedule modifiedPolicy = new IsilonSnapshotSchedule();
            modifiedPolicy.setName(snapPolicyAtPath.getName());
            if (policyUpdateParam.getSnapshotPolicyPrams() != null) {
                FileSnapshotPolicyParam snapParam = policyUpdateParam.getSnapshotPolicyPrams();
                if (snapParam.getSnapshotExpireParams() != null) {
                    Integer expireTime = getSnapshotExpireValue(snapParam.getSnapshotExpireParams());
                    if (expireTime != null && snapPolicyAtPath.getDuration() != null) {
                        if (snapPolicyAtPath.getDuration().intValue() != expireTime.intValue()) {
                            modifiedPolicy.setDuration(expireTime);
                            bModifyPolicy = true;
                        }
                    } else if (expireTime != null && snapPolicyAtPath.getDuration() == null) {
                        modifiedPolicy.setDuration(expireTime);
                        bModifyPolicy = true;
                    } else if (snapPolicyAtPath.getDuration() != null) {
                        modifiedPolicy.setDuration(0);
                        bModifyPolicy = true;
                    }
                }
                if (snapParam.getPolicySchedule() != null) {
                    String strSchedule = getIsilonPolicySchedule(snapParam.getPolicySchedule());
                    if (strSchedule != null && !strSchedule.isEmpty() && !strSchedule.equalsIgnoreCase(snapPolicyAtPath.getSchedule())) {
                        modifiedPolicy.setSchedule(strSchedule);
                        bModifyPolicy = true;
                    }
                }
            }
            if (bModifyPolicy) {
                isi.modifySnapshotSchedule(snapPolicyAtPath.getName(), modifiedPolicy);
                // if the existing policy is modified save policy details in db
                policyRes.setPolicyNativeId(snapPolicyAtPath.getId().toString());
                policyRes.setName(snapPolicyAtPath.getName());
                _dbClient.updateObject(policyRes);
                _log.info("Modify Snapshot Policy- {} finished successfully", snapPolicyAtPath.getName());
                return BiosCommandResult.createSuccessfulResult();
            } else {
                _log.info("No parameters changed to modify Snapshot Policy- {} finished successfully", snapPolicyAtPath.getName());
                return BiosCommandResult.createSuccessfulResult();
            }
        } else {
            _log.error("No SnapshotIQ policy found at path {} , Hence can't be MODIFIED", policyRes.getResourcePath());
            ServiceError error = DeviceControllerErrors.isilon.jobFailed("Modify Snapshot policy Failed as : No SnapshotIQ policy found at given path.");
            return BiosCommandResult.createErrorResult(error);
        }
    } catch (IsilonException e) {
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FileSnapshotPolicyParam(com.emc.storageos.model.file.policy.FileSnapshotPolicyParam) IsilonSnapshotSchedule(com.emc.storageos.isilon.restapi.IsilonSnapshotSchedule) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Aggregations

FileSnapshotPolicyParam (com.emc.storageos.model.file.policy.FileSnapshotPolicyParam)10 FilePolicyScheduleParams (com.emc.storageos.model.file.policy.FilePolicyScheduleParams)9 FileSnapshotPolicyExpireParam (com.emc.storageos.model.file.policy.FileSnapshotPolicyExpireParam)9 FilePolicyCreateParam (com.emc.storageos.model.file.policy.FilePolicyCreateParam)8 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 Test (org.junit.Test)8 IsilonException (com.emc.storageos.isilon.restapi.IsilonException)1 IsilonSnapshotSchedule (com.emc.storageos.isilon.restapi.IsilonSnapshotSchedule)1 FilePolicyCreateResp (com.emc.storageos.model.file.policy.FilePolicyCreateResp)1 FileReplicationPolicyParam (com.emc.storageos.model.file.policy.FileReplicationPolicyParam)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1