use of com.emc.storageos.model.file.policy.FileReplicationPolicyParam in project coprhd-controller by CoprHD.
the class FilePolicyService method updateFileReplicationPolicy.
/**
* Update the replication policy.
*
* @param fileReplicationPolicy
* @param param
* @return
*/
private void updateFileReplicationPolicy(FilePolicy fileReplicationPolicy, FilePolicyUpdateParam param) {
StringBuilder errorMsg = new StringBuilder();
// validate and update common parameters!!
updatePolicyCommonParameters(fileReplicationPolicy, param);
if (param.getPriority() != null) {
ArgValidator.checkFieldValueFromEnum(param.getPriority(), "priority", EnumSet.allOf(FilePolicyPriority.class));
fileReplicationPolicy.setPriority(param.getPriority());
}
if (param.getNumWorkerThreads() > 0) {
fileReplicationPolicy.setNumWorkerThreads((long) param.getNumWorkerThreads());
}
// validate and update replication parameters!!!
if (param.getReplicationPolicyParams() != null) {
FileReplicationPolicyParam replParam = param.getReplicationPolicyParams();
if (replParam.getReplicationCopyMode() != null && !replParam.getReplicationCopyMode().isEmpty()) {
ArgValidator.checkFieldValueFromEnum(replParam.getReplicationCopyMode(), "replicationCopyMode", EnumSet.allOf(FilePolicy.FileReplicationCopyMode.class));
fileReplicationPolicy.setFileReplicationCopyMode(replParam.getReplicationCopyMode());
}
if (replParam.getReplicationType() != null && !replParam.getReplicationType().isEmpty()) {
ArgValidator.checkFieldValueFromEnum(replParam.getReplicationType(), "replicationType", EnumSet.allOf(FilePolicy.FileReplicationType.class));
// Dont change the replication type, if policy was applied to storage resources!!
if (!replParam.getReplicationType().equalsIgnoreCase(fileReplicationPolicy.getFileReplicationType())) {
if (fileReplicationPolicy.getPolicyStorageResources() != null && !fileReplicationPolicy.getPolicyStorageResources().isEmpty()) {
errorMsg.append("Active resources exist on the policy");
_log.error("Failed to update file replication policy due to {} ", errorMsg.toString());
throw APIException.badRequests.invalidFileReplicationPolicyParam(fileReplicationPolicy.getFilePolicyName(), errorMsg.toString());
} else {
fileReplicationPolicy.setFileReplicationType(replParam.getReplicationType());
}
}
}
// Validate replication policy schedule parameters
if (replParam.getPolicySchedule() != null) {
boolean isValidSchedule = FilePolicyServiceUtils.validateAndUpdatePolicyScheduleParam(replParam.getPolicySchedule(), fileReplicationPolicy, errorMsg);
if (!isValidSchedule && errorMsg.length() > 0) {
_log.error("Failed to update file replication policy due to {} ", errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyScheduleParam(fileReplicationPolicy.getFilePolicyName(), errorMsg.toString());
}
if (replParam.getPolicySchedule().getScheduleFrequency() != null && !replParam.getPolicySchedule().getScheduleFrequency().isEmpty()) {
fileReplicationPolicy.setScheduleFrequency(replParam.getPolicySchedule().getScheduleFrequency());
}
}
}
}
use of com.emc.storageos.model.file.policy.FileReplicationPolicyParam in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method updateStorageSystemFileReplicationPolicy.
private BiosCommandResult updateStorageSystemFileReplicationPolicy(IsilonApi isi, PolicyStorageResource policyRes, FilePolicy viprPolicy, FilePolicyUpdateParam policyUpdateParam, boolean isVersion8above) {
try {
IsilonSyncPolicy syncpolicyAtPath = getSyncPolicy(isi, policyRes);
if (syncpolicyAtPath != null) {
_log.info("Found SyncIQ policy{} for path {} ", syncpolicyAtPath.getName(), syncpolicyAtPath.getSourceRootPath());
boolean bModifyPolicy = false;
// Temp policy to store modified values.
IsilonSyncPolicy modifiedPolicy = new IsilonSyncPolicy();
modifiedPolicy.setName(syncpolicyAtPath.getName());
if (policyUpdateParam.getNumWorkerThreads() > 0 && syncpolicyAtPath.getWorkersPerNode() != policyUpdateParam.getNumWorkerThreads()) {
_log.debug("Changing NumWorkerThreads to {} ", policyUpdateParam.getNumWorkerThreads());
modifiedPolicy.setWorkersPerNode(policyUpdateParam.getNumWorkerThreads());
bModifyPolicy = true;
}
if (policyUpdateParam.getPolicyDescription() != null && !policyUpdateParam.getPolicyDescription().isEmpty() && !policyUpdateParam.getPolicyDescription().equalsIgnoreCase(syncpolicyAtPath.getDescription())) {
modifiedPolicy.setDescription(policyUpdateParam.getPolicyDescription());
bModifyPolicy = true;
}
if (policyUpdateParam.getReplicationPolicyParams() != null) {
FileReplicationPolicyParam replParam = policyUpdateParam.getReplicationPolicyParams();
if (replParam.getReplicationCopyMode() != null && !replParam.getReplicationCopyMode().isEmpty() && !FileReplicationCopyMode.ASYNC.name().equalsIgnoreCase(replParam.getReplicationCopyMode())) {
_log.warn("Replication copy mode {} is not supported by Isilon {} ", replParam.getReplicationCopyMode());
}
if (replParam.getPolicySchedule() != null) {
String strSchedule = getIsilonPolicySchedule(replParam.getPolicySchedule());
if (strSchedule != null && !strSchedule.isEmpty() && !strSchedule.equalsIgnoreCase(syncpolicyAtPath.getSchedule())) {
modifiedPolicy.setSchedule(strSchedule);
bModifyPolicy = true;
}
}
}
/*
* Changes made for addressing new fields added in sync Policy in OneFSv 8.0 and above
*/
IsilonSyncPolicy8Above modifiedPolicycopy = new IsilonSyncPolicy8Above();
IsilonSyncPolicy8Above syncpolicyAtPath8 = null;
if (isVersion8above && policyUpdateParam.getPriority() != null) {
syncpolicyAtPath8 = isi.getReplicationPolicy8above(syncpolicyAtPath.getName());
modifiedPolicycopy = modifiedPolicycopy.copy(modifiedPolicy);
if (syncpolicyAtPath8 != null) {
if (FilePolicyPriority.valueOf(policyUpdateParam.getPriority()).ordinal() != syncpolicyAtPath8.getPriority()) {
modifiedPolicycopy.setPriority(FilePolicyPriority.valueOf(policyUpdateParam.getPriority()).ordinal());
bModifyPolicy = true;
}
}
}
if (bModifyPolicy) {
JobState policyState = syncpolicyAtPath.getLastJobState();
if (!policyState.equals(JobState.running) && !policyState.equals(JobState.paused)) {
if (isVersion8above) {
// Possible NPE..syncpolicyAtPath8 can be null here if policyUpdateParam.getPriority() is NULL..
// Better to use syncpolicyAtPath.getName()..
isi.modifyReplicationPolicy8above(syncpolicyAtPath.getName(), modifiedPolicycopy);
_log.info("Modify Replication Policy- {} finished successfully", syncpolicyAtPath.getName());
} else {
isi.modifyReplicationPolicy(syncpolicyAtPath.getName(), modifiedPolicy);
_log.info("Modify Replication Policy- {} finished successfully", syncpolicyAtPath.getName());
}
// set native id and policy existing and then update the DB
if (null == policyRes.getName()) {
// before fix,
policyRes.setLabel(policyRes.getPolicyNativeId());
policyRes.setName(syncpolicyAtPath.getName());
policyRes.setPolicyNativeId(syncpolicyAtPath.getId());
_dbClient.updateObject(policyRes);
} else {
policyRes.setName(syncpolicyAtPath.getName());
_dbClient.updateObject(policyRes);
}
return BiosCommandResult.createSuccessfulResult();
} else {
_log.error("Replication Policy - {} can't be MODIFIED because policy has an active job", syncpolicyAtPath.getName());
ServiceError error = DeviceControllerErrors.isilon.jobFailed("doModifyReplicationPolicy as : The policy has an active job and cannot be modified.");
return BiosCommandResult.createErrorResult(error);
}
} else {
_log.info("No parameters changed to modify Replication Policy- {} finished successfully", syncpolicyAtPath.getName());
return BiosCommandResult.createSuccessfulResult();
}
} else {
_log.error("No SyncIQ policy found at path {} , Hence can't be MODIFIED", policyRes.getResourcePath());
ServiceError error = DeviceControllerErrors.isilon.jobFailed("doModifyReplicationPolicy as : No SyncIQ policy found at given path.");
return BiosCommandResult.createErrorResult(error);
}
} catch (IsilonException e) {
return BiosCommandResult.createErrorResult(e);
}
}
use of com.emc.storageos.model.file.policy.FileReplicationPolicyParam 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