Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TFS
controller
Commits
f262dc95
Commit
f262dc95
authored
1 year ago
by
Konstantinos Poulakakis
Browse files
Options
Downloads
Patches
Plain Diff
refactor: Make more simple the addPolicyDevice and deletePolicy.
parent
26e30e50
No related branches found
No related tags found
2 merge requests
!235
Release TeraFlowSDN 3.0
,
!197
Resolve "(UBI) Refactor Policy"
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java
+96
-81
96 additions, 81 deletions
.../src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java
with
96 additions
and
81 deletions
src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java
+
96
−
81
View file @
f262dc95
...
@@ -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
;
monitorA
larm
R
es
ponseForDevice
(
multi
);
List
<
Uni
<
String
>>
alarmIds
=
getAlarmIds
(
a
larm
D
es
criptorList
);
// 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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment