Skip to content
Snippets Groups Projects
Commit f262dc95 authored by Konstantinos Poulakakis's avatar Konstantinos Poulakakis
Browse files

refactor: Make more simple the addPolicyDevice and deletePolicy.

parent 26e30e50
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!197Resolve "(UBI) Refactor Policy"
...@@ -322,74 +322,91 @@ public class PolicyServiceImpl implements PolicyService { ...@@ -322,74 +322,91 @@ public class PolicyServiceImpl implements PolicyService {
return areDevicesValid return areDevicesValid
.onItem() .onItem()
.transform( .transform(areDevices -> addDeviceOnContext(areDevices, policyRuleDevice, policyRuleBasic));
areDevices -> { }
if (areDevices.contains(false)) {
var policyRuleState =
new PolicyRuleState(
PolicyRuleStateEnum.POLICY_FAILED,
String.format(
INVALID_MESSAGE,
policyRuleDevice.getPolicyRuleBasic().getPolicyRuleId()));
return policyRuleState;
}
final var policyRuleTypeDevice = new PolicyRuleTypeDevice(policyRuleDevice); private PolicyRuleState addDeviceOnContext(
final var policyRule = new PolicyRule(policyRuleTypeDevice); List<Boolean> areDevices,
PolicyRuleDevice policyRuleDevice,
final var alarmDescriptorList = createAlarmDescriptorList(policyRule); PolicyRuleBasic policyRuleBasic) {
if (alarmDescriptorList.isEmpty()) { if (areDevices.contains(false)) {
var policyRuleState = var policyRuleState =
new PolicyRuleState( new PolicyRuleState(
PolicyRuleStateEnum.POLICY_FAILED, PolicyRuleStateEnum.POLICY_FAILED,
String.format( String.format(
"Invalid PolicyRuleConditions in PolicyRule with ID: %s", INVALID_MESSAGE, policyRuleDevice.getPolicyRuleBasic().getPolicyRuleId()));
policyRuleBasic.getPolicyRuleId()));
return policyRuleState;
}
contextService.setPolicyRule(policyRule).subscribe().with(x -> {}); return policyRuleState;
setPolicyRuleDeviceToContext(policyRuleDevice, VALIDATED_POLICYRULE_STATE); }
noAlarms = 0;
List<Uni<String>> alarmIds = new ArrayList<Uni<String>>(); final var policyRuleTypeDevice = new PolicyRuleTypeDevice(policyRuleDevice);
for (AlarmDescriptor alarmDescriptor : alarmDescriptorList) { final var policyRule = new PolicyRule(policyRuleTypeDevice);
LOGGER.infof("alarmDescriptor:");
LOGGER.infof(alarmDescriptor.toString());
alarmIds.add(monitoringService.setKpiAlarm(alarmDescriptor));
}
// Transform the alarmIds into promised alarms returned from the final var alarmDescriptorList = createAlarmDescriptorList(policyRule);
// getAlarmResponseStream if (alarmDescriptorList.isEmpty()) {
List<Multi<AlarmResponse>> alarmResponseStreamList = new ArrayList<>(); var policyRuleState =
for (Uni<String> alarmId : alarmIds) { new PolicyRuleState(
alarmResponseStreamList.add( PolicyRuleStateEnum.POLICY_FAILED,
alarmId String.format(
.onItem() "Invalid PolicyRuleConditions in PolicyRule with ID: %s",
.transformToMulti( policyRuleBasic.getPolicyRuleId()));
id -> { return policyRuleState;
alarmPolicyRuleDeviceMap.put(id, policyRuleDevice); }
// TODO: Create infinite subscription
var alarmSubscription = new AlarmSubscription(id, 259200, 5000);
return monitoringService.getAlarmResponseStream(alarmSubscription);
}));
}
// Merge the promised alarms into one stream (Multi Object) contextService.setPolicyRule(policyRule).subscribe().with(x -> {});
final var multi = Multi.createBy().merging().streams(alarmResponseStreamList); setPolicyRuleDeviceToContext(policyRuleDevice, VALIDATED_POLICYRULE_STATE);
setPolicyRuleDeviceToContext(policyRuleDevice, PROVISIONED_POLICYRULE_STATE); noAlarms = 0;
monitorAlarmResponseForDevice(multi); List<Uni<String>> alarmIds = getAlarmIds(alarmDescriptorList);
// TODO: Resubscribe to the stream, if it has ended List<Multi<AlarmResponse>> alarmResponseStreamList =
getAlarmResponse(alarmIds, policyRuleDevice);
// TODO: Redesign evaluation of action // Merge the promised alarms into one stream (Multi Object)
// evaluateAction(policyRule, alarmDescriptorList, multi); final var multi = Multi.createBy().merging().streams(alarmResponseStreamList);
setPolicyRuleDeviceToContext(policyRuleDevice, PROVISIONED_POLICYRULE_STATE);
return VALIDATED_POLICYRULE_STATE; monitorAlarmResponseForDevice(multi);
});
// TODO: Resubscribe to the stream, if it has ended
// TODO: Redesign evaluation of action
// evaluateAction(policyRule, alarmDescriptorList, multi);
return VALIDATED_POLICYRULE_STATE;
}
private List<Multi<AlarmResponse>> getAlarmResponse(
List<Uni<String>> alarmIds, PolicyRuleDevice policyRuleDevice) {
// Transform the alarmIds into promised alarms returned from the
// getAlarmResponseStream
List<Multi<AlarmResponse>> alarmResponseStreamList = new ArrayList<>();
for (Uni<String> alarmId : alarmIds) {
alarmResponseStreamList.add(
alarmId
.onItem()
.transformToMulti(
id -> setPolicyMonitoringDevice(policyRuleDevice, id)));
}
return alarmResponseStreamList;
}
private Multi<AlarmResponse> setPolicyMonitoringDevice(PolicyRuleDevice policyRuleDevice, String id){
alarmPolicyRuleDeviceMap.put(id, policyRuleDevice);
// TODO: Create infinite subscription
var alarmSubscription = new AlarmSubscription(id, 259200, 5000);
return monitoringService.getAlarmResponseStream(alarmSubscription);
}
private List<Uni<String>> getAlarmIds(List<AlarmDescriptor> alarmDescriptorList) {
List<Uni<String>> alarmIds = new ArrayList<Uni<String>>();
for (AlarmDescriptor alarmDescriptor : alarmDescriptorList) {
LOGGER.infof("alarmDescriptor:");
LOGGER.infof(alarmDescriptor.toString());
alarmIds.add(monitoringService.setKpiAlarm(alarmDescriptor));
}
return alarmIds;
} }
@Override @Override
...@@ -477,32 +494,30 @@ public class PolicyServiceImpl implements PolicyService { ...@@ -477,32 +494,30 @@ public class PolicyServiceImpl implements PolicyService {
final var getPolicyRule = contextService.getPolicyRule(policyRuleId); final var getPolicyRule = contextService.getPolicyRule(policyRuleId);
return getPolicyRule return getPolicyRule.onItem().transform(policyRule -> removePolicyFromContext(policyRule));
.onItem() }
.transform(
policyRule -> {
var policyRuleBasic = policyRule.getPolicyRuleType().getPolicyRuleBasic();
String policyId = policyRuleBasic.getPolicyRuleId();
policyRule private PolicyRuleState removePolicyFromContext(PolicyRule policyRule) {
.getPolicyRuleType() var policyRuleBasic = policyRule.getPolicyRuleType().getPolicyRuleBasic();
.getPolicyRuleBasic() String policyId = policyRuleBasic.getPolicyRuleId();
.setPolicyRuleState(REMOVED_POLICYRULE_STATE);
contextService policyRule
.setPolicyRule(policyRule) .getPolicyRuleType()
.subscribe() .getPolicyRuleBasic()
.with( .setPolicyRuleState(REMOVED_POLICYRULE_STATE);
tmp ->
LOGGER.infof( contextService
"DeletePolicy with id: " + VALID_MESSAGE, .setPolicyRule(policyRule)
policyRuleBasic.getPolicyRuleId())); .subscribe()
.with(
tmp ->
LOGGER.infof(
"DeletePolicy with id: " + VALID_MESSAGE, policyRuleBasic.getPolicyRuleId()));
contextService.removePolicyRule(policyId).subscribe().with(x -> {}); contextService.removePolicyRule(policyId).subscribe().with(x -> {});
subscriptionList.get(policyId).cancel(); subscriptionList.get(policyId).cancel();
return policyRuleBasic.getPolicyRuleState(); return policyRuleBasic.getPolicyRuleState();
});
} }
private Uni<List<Boolean>> returnInvalidDeviceIds(List<String> deviceIds) { private Uni<List<Boolean>> returnInvalidDeviceIds(List<String> deviceIds) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment