Search in sources :

Example 11 with FilePolicyCreateParam

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

the class FilePolicyApiTest method testCreateSnapshotPolicyInvalidExpireValue.

@Test
public void testCreateSnapshotPolicyInvalidExpireValue() {
    FilePolicyCreateParam param = new FilePolicyCreateParam();
    setFilePolicyMandatoryParams(param);
    FileSnapshotPolicyParam snapshotPolicyParam = new FileSnapshotPolicyParam();
    FilePolicyScheduleParams policySchedule = new FilePolicyScheduleParams();
    setFilePolicyScheduleParams(policySchedule);
    snapshotPolicyParam.setPolicySchedule(policySchedule);
    param.setSnapshotPolicyPrams(snapshotPolicyParam);
    FileSnapshotPolicyExpireParam snapshotExpireParams = new FileSnapshotPolicyExpireParam();
    snapshotExpireParams.setExpireType("HOURS");
    // Some invalid value less than 2 hours or greater than 2 years
    snapshotExpireParams.setExpireValue(1);
    snapshotPolicyParam.setSnapshotExpireParams(snapshotExpireParams);
    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 12 with FilePolicyCreateParam

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

the class FilePolicyApiTest method testCreateSnapshotPolicyInvalidExpireType.

@Test
public void testCreateSnapshotPolicyInvalidExpireType() {
    FilePolicyCreateParam param = new FilePolicyCreateParam();
    setFilePolicyMandatoryParams(param);
    FileSnapshotPolicyParam snapshotPolicyParam = new FileSnapshotPolicyParam();
    FilePolicyScheduleParams policySchedule = new FilePolicyScheduleParams();
    setFilePolicyScheduleParams(policySchedule);
    snapshotPolicyParam.setPolicySchedule(policySchedule);
    param.setSnapshotPolicyPrams(snapshotPolicyParam);
    FileSnapshotPolicyExpireParam snapshotExpireParams = new FileSnapshotPolicyExpireParam();
    // Invalid Expire Type
    snapshotExpireParams.setExpireType("some_junk_value");
    snapshotPolicyParam.setSnapshotExpireParams(snapshotExpireParams);
    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 13 with FilePolicyCreateParam

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

the class FilePolicyApiTest method testCreatePolicyWithoutName.

@Test
public void testCreatePolicyWithoutName() {
    FilePolicyCreateParam param = new FilePolicyCreateParam();
    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) FilePolicyCreateParam(com.emc.storageos.model.file.policy.FilePolicyCreateParam) Test(org.junit.Test)

Example 14 with FilePolicyCreateParam

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

the class FileProtectionPolicies method save.

@FlashException(keep = true, referrer = { "create", "edit" })
public static void save(SchedulePolicyForm schedulePolicy) {
    if (schedulePolicy == null) {
        Logger.error("No policy parameters passed");
        badRequest("No policy parameters passed");
        return;
    }
    schedulePolicy.validate("schedulePolicy");
    if (Validation.hasErrors()) {
        Common.handleError();
    }
    schedulePolicy.id = params.get("id");
    URI policyId = null;
    if (schedulePolicy.isNew()) {
        schedulePolicy.tenantId = Models.currentAdminTenant();
        FilePolicyCreateParam policyParam = new FilePolicyCreateParam();
        updatePolicyParam(schedulePolicy, policyParam, null);
        policyParam.setPolicyType(schedulePolicy.policyType);
        if (schedulePolicy.description != null && !schedulePolicy.description.isEmpty()) {
            policyParam.setPolicyDescription(schedulePolicy.description);
        }
        FilePolicyCreateResp createdPolicy = getViprClient().fileProtectionPolicies().create(policyParam);
        policyId = createdPolicy.getId();
    } else {
        FilePolicyRestRep schedulePolicyRestRep = getViprClient().fileProtectionPolicies().get(uri(schedulePolicy.id));
        FilePolicyUpdateParam input = new FilePolicyUpdateParam();
        updatePolicyParam(schedulePolicy, input, schedulePolicyRestRep.getType());
        getViprClient().fileProtectionPolicies().update(schedulePolicyRestRep.getId(), input);
        policyId = schedulePolicyRestRep.getId();
    }
    // Update the ACLs
    com.emc.vipr.client.core.FileProtectionPolicies filePolicies = getViprClient().fileProtectionPolicies();
    schedulePolicy.saveTenantACLs(filePolicies, policyId);
    flash.success(MessagesUtils.get("schedulepolicies.saved", schedulePolicy.policyName));
    if (StringUtils.isNotBlank(schedulePolicy.referrerUrl)) {
        redirect(schedulePolicy.referrerUrl);
    } else {
        list();
    }
}
Also used : FilePolicyUpdateParam(com.emc.storageos.model.file.policy.FilePolicyUpdateParam) FilePolicyCreateParam(com.emc.storageos.model.file.policy.FilePolicyCreateParam) FilePolicyCreateResp(com.emc.storageos.model.file.policy.FilePolicyCreateResp) FilePolicyRestRep(com.emc.storageos.model.file.policy.FilePolicyRestRep) URI(java.net.URI) FlashException(controllers.util.FlashException)

Aggregations

FilePolicyCreateParam (com.emc.storageos.model.file.policy.FilePolicyCreateParam)14 ClientResponse (com.sun.jersey.api.client.ClientResponse)13 Test (org.junit.Test)13 FilePolicyScheduleParams (com.emc.storageos.model.file.policy.FilePolicyScheduleParams)8 FileSnapshotPolicyExpireParam (com.emc.storageos.model.file.policy.FileSnapshotPolicyExpireParam)8 FileSnapshotPolicyParam (com.emc.storageos.model.file.policy.FileSnapshotPolicyParam)8 FilePolicyCreateResp (com.emc.storageos.model.file.policy.FilePolicyCreateResp)2 FilePolicyRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep)1 FilePolicyUpdateParam (com.emc.storageos.model.file.policy.FilePolicyUpdateParam)1 FlashException (controllers.util.FlashException)1 URI (java.net.URI)1