use of com.emc.storageos.model.file.policy.FilePolicyCreateResp in project coprhd-controller by CoprHD.
the class FilePolicyService method createFileSnapshotPolicy.
/**
* Validate and create snapshot policy.
*
* @param param
* @return
*/
private FilePolicyCreateResp createFileSnapshotPolicy(FilePolicyCreateParam param) {
StringBuilder errorMsg = new StringBuilder();
FilePolicy fileSnapshotPolicy = new FilePolicy();
if (param.getSnapshotPolicyPrams() == null) {
errorMsg.append("Required parameter snapshot_params was missing or empty");
_log.error("Failed to create snapshot policy due to {} ", errorMsg.toString());
throw APIException.badRequests.invalidFileSnapshotPolicyParam(param.getPolicyName(), errorMsg.toString());
}
// Validate snapshot policy schedule parameters
boolean isValidSchedule = FilePolicyServiceUtils.validateAndUpdatePolicyScheduleParam(param.getSnapshotPolicyPrams().getPolicySchedule(), fileSnapshotPolicy, errorMsg);
if (!isValidSchedule && errorMsg.length() > 0) {
_log.error("Failed to create file snapshot policy due to {} ", errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyScheduleParam(param.getPolicyName(), errorMsg.toString());
}
// Validate snapshot policy expire parameters..
FilePolicyServiceUtils.validateSnapshotPolicyExpireParam(param.getSnapshotPolicyPrams());
fileSnapshotPolicy.setId(URIUtil.createId(FilePolicy.class));
fileSnapshotPolicy.setLabel(param.getPolicyName());
fileSnapshotPolicy.setFilePolicyType(param.getPolicyType());
fileSnapshotPolicy.setFilePolicyName(param.getPolicyName());
fileSnapshotPolicy.setLabel(param.getPolicyName());
if (param.getPolicyDescription() != null && !param.getPolicyDescription().isEmpty()) {
fileSnapshotPolicy.setFilePolicyDescription(param.getPolicyDescription());
}
fileSnapshotPolicy.setScheduleFrequency(param.getSnapshotPolicyPrams().getPolicySchedule().getScheduleFrequency());
fileSnapshotPolicy.setSnapshotExpireType(param.getSnapshotPolicyPrams().getSnapshotExpireParams().getExpireType());
fileSnapshotPolicy.setSnapshotNamePattern(param.getSnapshotPolicyPrams().getSnapshotNamePattern());
fileSnapshotPolicy.setApplyAt(param.getApplyAt());
if (!param.getSnapshotPolicyPrams().getSnapshotExpireParams().getExpireType().equalsIgnoreCase(SnapshotExpireType.NEVER.toString())) {
fileSnapshotPolicy.setSnapshotExpireTime((long) param.getSnapshotPolicyPrams().getSnapshotExpireParams().getExpireValue());
} else {
fileSnapshotPolicy.setSnapshotExpireTime(0L);
}
_dbClient.createObject(fileSnapshotPolicy);
_log.info("Snapshot policy {} created successfully", fileSnapshotPolicy);
return new FilePolicyCreateResp(fileSnapshotPolicy.getId(), toLink(ResourceTypeEnum.FILE_POLICY, fileSnapshotPolicy.getId()), fileSnapshotPolicy.getLabel());
}
use of com.emc.storageos.model.file.policy.FilePolicyCreateResp in project coprhd-controller by CoprHD.
the class FilePolicyService method createFilePolicy.
/**
* @brief Create file policy for file snapshot, file replication or file quota
*
* @param param
* FilePolicyCreateParam
* @return FilePolicyCreateResp
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public FilePolicyCreateResp createFilePolicy(FilePolicyCreateParam param) {
FilePolicyCreateResp resp = new FilePolicyCreateResp();
// Make policy name as mandatory field
ArgValidator.checkFieldNotNull(param.getPolicyName(), "policyName");
// Make apply at as mandatory field
ArgValidator.checkFieldNotNull(param.getApplyAt(), "apply_at");
// Check for duplicate policy name
if (param.getPolicyName() != null && !param.getPolicyName().isEmpty()) {
checkForDuplicateName(param.getPolicyName(), FilePolicy.class);
}
// check policy type is valid or not
ArgValidator.checkFieldValueFromEnum(param.getPolicyType(), "policy_type", EnumSet.allOf(FilePolicyType.class));
// check the policy apply level is valid or not
ArgValidator.checkFieldValueFromEnum(param.getApplyAt(), "apply_at", EnumSet.allOf(FilePolicyApplyLevel.class));
_log.info("file policy creation started -- ");
if (param.getPolicyType().equals(FilePolicyType.file_replication.name())) {
return createFileReplicationPolicy(param);
} else if (param.getPolicyType().equals(FilePolicyType.file_snapshot.name())) {
return createFileSnapshotPolicy(param);
}
return resp;
}
use of com.emc.storageos.model.file.policy.FilePolicyCreateResp 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);
}
use of com.emc.storageos.model.file.policy.FilePolicyCreateResp in project coprhd-controller by CoprHD.
the class FilePolicyService method createFileReplicationPolicy.
/**
* Validate and create replication policy.
*
* @param param
* @return
*/
private FilePolicyCreateResp createFileReplicationPolicy(FilePolicyCreateParam param) {
StringBuilder errorMsg = new StringBuilder();
FilePolicy fileReplicationPolicy = new FilePolicy();
if (param.getReplicationPolicyParams() == null) {
errorMsg.append("Required parameter replication_params was missing or empty");
_log.error("Failed to create snapshot policy due to {} ", errorMsg.toString());
throw APIException.badRequests.invalidFileReplicationPolicyParam(param.getPolicyName(), errorMsg.toString());
}
// Make sure replication type and copy mode are provided
ArgValidator.checkFieldNotNull(param.getReplicationPolicyParams().getReplicationCopyMode(), "replication_copy_mode");
ArgValidator.checkFieldNotNull(param.getReplicationPolicyParams().getReplicationType(), "replication_type");
// Validate replication policy schedule parameters
boolean isValidSchedule = FilePolicyServiceUtils.validateAndUpdatePolicyScheduleParam(param.getReplicationPolicyParams().getPolicySchedule(), fileReplicationPolicy, errorMsg);
if (!isValidSchedule && errorMsg.length() > 0) {
_log.error("Failed to create file replication policy due to {} ", errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyScheduleParam(param.getPolicyName(), errorMsg.toString());
}
// validate replication type and copy mode parameters
ArgValidator.checkFieldValueFromEnum(param.getReplicationPolicyParams().getReplicationType(), "replicationType", EnumSet.allOf(FilePolicy.FileReplicationType.class));
ArgValidator.checkFieldValueFromEnum(param.getReplicationPolicyParams().getReplicationCopyMode(), "replicationCopyMode", EnumSet.allOf(FilePolicy.FileReplicationCopyMode.class));
fileReplicationPolicy.setId(URIUtil.createId(FilePolicy.class));
fileReplicationPolicy.setFilePolicyName(param.getPolicyName());
fileReplicationPolicy.setLabel(param.getPolicyName());
fileReplicationPolicy.setFilePolicyType(param.getPolicyType());
if (param.getPriority() != null) {
ArgValidator.checkFieldValueFromEnum(param.getPriority(), "priority", EnumSet.allOf(FilePolicyPriority.class));
fileReplicationPolicy.setPriority(param.getPriority());
}
fileReplicationPolicy.setNumWorkerThreads((long) param.getNumWorkerThreads());
if (param.getPolicyDescription() != null && !param.getPolicyDescription().isEmpty()) {
fileReplicationPolicy.setFilePolicyDescription(param.getPolicyDescription());
}
fileReplicationPolicy.setScheduleFrequency(param.getReplicationPolicyParams().getPolicySchedule().getScheduleFrequency());
fileReplicationPolicy.setFileReplicationType(param.getReplicationPolicyParams().getReplicationType());
fileReplicationPolicy.setFileReplicationCopyMode(param.getReplicationPolicyParams().getReplicationCopyMode());
fileReplicationPolicy.setApplyAt(param.getApplyAt());
_dbClient.createObject(fileReplicationPolicy);
_log.info("Policy {} created successfully", fileReplicationPolicy);
return new FilePolicyCreateResp(fileReplicationPolicy.getId(), toLink(ResourceTypeEnum.FILE_POLICY, fileReplicationPolicy.getId()), fileReplicationPolicy.getLabel());
}
use of com.emc.storageos.model.file.policy.FilePolicyCreateResp 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();
}
}
Aggregations