use of com.emc.storageos.model.file.policy.FileSnapshotPolicyExpireParam in project coprhd-controller by CoprHD.
the class FilePolicyApiTest method testCreatePolicyWithInValidPolicyScheduleDayOfMonth.
@Test
public void testCreatePolicyWithInValidPolicyScheduleDayOfMonth() {
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("MONTHS");
// Invalid day of month(not in range of 1-31)
policySchedule.setScheduleDayOfWeek("34");
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());
}
use of com.emc.storageos.model.file.policy.FileSnapshotPolicyExpireParam 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());
}
use of com.emc.storageos.model.file.policy.FileSnapshotPolicyExpireParam 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());
}
use of com.emc.storageos.model.file.policy.FileSnapshotPolicyExpireParam in project coprhd-controller by CoprHD.
the class FilePolicyService method updateFileSnapshotPolicy.
/**
* Update snapshot policy.
*
* @param param
* @param fileSnapshotPolicy
* @return
*/
private void updateFileSnapshotPolicy(FilePolicy fileSnapshotPolicy, FilePolicyUpdateParam param) {
StringBuilder errorMsg = new StringBuilder();
// validate and update common parameters!!
updatePolicyCommonParameters(fileSnapshotPolicy, param);
// Validate snapshot policy expire parameters..
if (param.getSnapshotPolicyPrams() != null) {
// Validate snapshot policy schedule parameters
if (param.getSnapshotPolicyPrams().getPolicySchedule() != null) {
boolean isValidSchedule = FilePolicyServiceUtils.validateAndUpdatePolicyScheduleParam(param.getSnapshotPolicyPrams().getPolicySchedule(), fileSnapshotPolicy, errorMsg);
if (!isValidSchedule) {
_log.error("Failed to update file snapshot policy due to {} ", errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyScheduleParam(fileSnapshotPolicy.getFilePolicyName(), errorMsg.toString());
}
if (param.getSnapshotPolicyPrams().getPolicySchedule().getScheduleFrequency() != null && !param.getSnapshotPolicyPrams().getPolicySchedule().getScheduleFrequency().isEmpty()) {
fileSnapshotPolicy.setScheduleFrequency(param.getSnapshotPolicyPrams().getPolicySchedule().getScheduleFrequency());
}
}
if (param.getSnapshotPolicyPrams().getSnapshotExpireParams() != null) {
// Validate the snapshot expire parameters!!
FileSnapshotPolicyExpireParam snapExpireParam = param.getSnapshotPolicyPrams().getSnapshotExpireParams();
FilePolicyServiceUtils.validateSnapshotPolicyExpireParam(param.getSnapshotPolicyPrams());
if (snapExpireParam.getExpireType() != null) {
fileSnapshotPolicy.setSnapshotExpireType(snapExpireParam.getExpireType());
if (!SnapshotExpireType.NEVER.toString().equalsIgnoreCase(snapExpireParam.getExpireType())) {
fileSnapshotPolicy.setSnapshotExpireTime((long) snapExpireParam.getExpireValue());
} else {
fileSnapshotPolicy.setSnapshotExpireTime(0L);
}
}
}
if (param.getSnapshotPolicyPrams().getSnapshotNamePattern() != null) {
fileSnapshotPolicy.setSnapshotNamePattern(param.getSnapshotPolicyPrams().getSnapshotNamePattern());
}
}
}
use of com.emc.storageos.model.file.policy.FileSnapshotPolicyExpireParam in project coprhd-controller by CoprHD.
the class FileProtectionPolicies method updatePolicyParam.
private static FilePolicyParam updatePolicyParam(SchedulePolicyForm schedulePolicy, FilePolicyParam param, String policyType) {
param.setPolicyName(schedulePolicy.policyName);
if (schedulePolicy.appliedAt != null) {
param.setApplyAt(schedulePolicy.appliedAt);
}
if (schedulePolicy.description != null && !schedulePolicy.description.isEmpty()) {
param.setPolicyDescription(schedulePolicy.description);
}
if (policyType == null) {
policyType = schedulePolicy.policyType;
}
FilePolicyScheduleParams scheduleParam = new FilePolicyScheduleParams();
if (policyType.equalsIgnoreCase("file_snapshot") || policyType.equalsIgnoreCase("file_replication")) {
scheduleParam.setScheduleTime(schedulePolicy.scheduleHour + ":" + schedulePolicy.scheduleMin);
scheduleParam.setScheduleFrequency(schedulePolicy.frequency);
scheduleParam.setScheduleRepeat(schedulePolicy.repeat);
if (schedulePolicy.frequency != null && "weeks".equals(schedulePolicy.frequency)) {
if (schedulePolicy.scheduleDayOfWeek != null) {
scheduleParam.setScheduleDayOfWeek(schedulePolicy.scheduleDayOfWeek);
}
} else if (schedulePolicy.frequency != null && "months".equals(schedulePolicy.frequency)) {
scheduleParam.setScheduleDayOfMonth(schedulePolicy.scheduleDayOfMonth);
}
}
if (policyType.equalsIgnoreCase("file_snapshot")) {
FileSnapshotPolicyParam snapshotParam = new FileSnapshotPolicyParam();
snapshotParam.setSnapshotNamePattern(schedulePolicy.snapshotNamePattern);
snapshotParam.setPolicySchedule(scheduleParam);
FileSnapshotPolicyExpireParam snapExpireParam = new FileSnapshotPolicyExpireParam();
if (schedulePolicy.expiration != null && !"NEVER".equals(schedulePolicy.expiration)) {
snapExpireParam.setExpireType(schedulePolicy.expireType);
snapExpireParam.setExpireValue(schedulePolicy.expireValue);
snapshotParam.setSnapshotExpireParams(snapExpireParam);
param.setSnapshotPolicyPrams(snapshotParam);
}
if ("NEVER".equals(schedulePolicy.expiration)) {
snapExpireParam.setExpireType("never");
snapshotParam.setSnapshotExpireParams(snapExpireParam);
param.setSnapshotPolicyPrams(snapshotParam);
}
} else if (policyType.equalsIgnoreCase("file_replication")) {
FileReplicationPolicyParam replicationPolicyParams = new FileReplicationPolicyParam();
replicationPolicyParams.setReplicationCopyMode(schedulePolicy.replicationCopyType);
replicationPolicyParams.setReplicationType(schedulePolicy.replicationType);
replicationPolicyParams.setPolicySchedule(scheduleParam);
param.setPriority(schedulePolicy.priority);
param.setNumWorkerThreads(schedulePolicy.numWorkerThreads);
param.setReplicationPolicyParams(replicationPolicyParams);
}
return param;
}
Aggregations