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
9dd92558
Commit
9dd92558
authored
2 years ago
by
Vasilis Katopodis
Browse files
Options
Downloads
Patches
Plain Diff
Log and setPolicyRule in one method
parent
ee2d064c
No related branches found
No related tags found
1 merge request
!3
feat(policy): policy rule add/update/delete RPCs
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/policy/src/main/java/eu/teraflow/policy/PolicyServiceImpl.java
+59
-91
59 additions, 91 deletions
...y/src/main/java/eu/teraflow/policy/PolicyServiceImpl.java
with
59 additions
and
91 deletions
src/policy/src/main/java/eu/teraflow/policy/PolicyServiceImpl.java
+
59
−
91
View file @
9dd92558
...
...
@@ -130,10 +130,6 @@ public class PolicyServiceImpl implements PolicyService {
this
.
policyRuleConditionFieldsGetter
=
policyRuleConditionFieldsGetter
;
}
private
static
PolicyRuleState
createFailedPolicyRuleState
(
String
message
)
{
return
new
PolicyRuleState
(
PolicyRuleStateEnum
.
POLICY_FAILED
,
message
);
}
private
static
String
gen
()
{
Random
r
=
new
Random
(
System
.
currentTimeMillis
());
return
String
.
valueOf
((
1
+
r
.
nextInt
(
2
))
*
10000
+
r
.
nextInt
(
10000
));
...
...
@@ -244,10 +240,7 @@ public class PolicyServiceImpl implements PolicyService {
.
with
(
alarmId
->
alarmSubscriptionList
.
add
(
new
AlarmSubscription
(
alarmId
,
0
,
0
)));
}
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
PROVISIONED_POLICYRULE_STATE
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
PROVISIONED_POLICYRULE_STATE
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
setState
(
policyRuleBasic
,
PROVISIONED_POLICYRULE_STATE
);
getAlarmResponseStream
(
policyRuleBasic
,
alarmDescriptorList
,
alarmSubscriptionList
,
isService
);
}
...
...
@@ -294,13 +287,11 @@ public class PolicyServiceImpl implements PolicyService {
LOGGER
.
infof
(
"Alarm [%s] has been deleted.\n"
,
alarmDescriptor
.
getAlarmId
()));
}
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
INEFFECTIVE_POLICYRULE_STATE
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
INEFFECTIVE_POLICYRULE_STATE
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
setState
(
policyRuleBasic
,
INEFFECTIVE_POLICYRULE_STATE
);
}
else
{
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
EFFECTIVE_POLICYRULE_STATE
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
EFFECTIVE_POLICYRULE_STATE
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
setState
(
policyRuleBasic
,
EFFECTIVE_POLICYRULE_STATE
);
multi
.
subscribe
()
...
...
@@ -325,9 +316,7 @@ public class PolicyServiceImpl implements PolicyService {
// In case additional PolicyRuleAction for Devices will be added
}
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
ACTIVE_POLICYRULE_STATE
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
ACTIVE_POLICYRULE_STATE
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
setState
(
policyRuleBasic
,
ACTIVE_POLICYRULE_STATE
);
List
<
String
>
deviceIds
=
policyRuleDevice
.
getDeviceIds
();
List
<
String
>
actionParameters
=
...
...
@@ -345,9 +334,7 @@ public class PolicyServiceImpl implements PolicyService {
activateDevice
(
deviceIds
.
get
(
i
),
deviceActions
);
}
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
ENFORCED_POLICYRULE_STATE
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
ENFORCED_POLICYRULE_STATE
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
setState
(
policyRuleBasic
,
ENFORCED_POLICYRULE_STATE
);
}
private
void
activateDevice
(
String
deviceId
,
List
<
String
>
actionParameters
)
{
...
...
@@ -442,11 +429,7 @@ public class PolicyServiceImpl implements PolicyService {
deserializedService
->
{
deserializedService
.
appendServiceConstraints
(
constraintList
);
serviceService
.
updateService
(
deserializedService
);
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
ENFORCED_POLICYRULE_STATE
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
ENFORCED_POLICYRULE_STATE
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
setState
(
policyRuleBasic
,
ENFORCED_POLICYRULE_STATE
);
});
}
...
...
@@ -455,9 +438,7 @@ public class PolicyServiceImpl implements PolicyService {
PolicyRuleBasic
policyRuleBasic
=
policyRuleService
.
getPolicyRuleBasic
();
PolicyRuleAction
policyRuleAction
=
policyRuleActionMap
.
get
(
alarmId
);
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
ACTIVE_POLICYRULE_STATE
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
ACTIVE_POLICYRULE_STATE
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
setState
(
policyRuleBasic
,
ACTIVE_POLICYRULE_STATE
);
switch
(
policyRuleAction
.
getPolicyRuleActionEnum
())
{
case
POLICY_RULE_ACTION_ADD_SERVICE_CONSTRAINT:
...
...
@@ -476,20 +457,22 @@ public class PolicyServiceImpl implements PolicyService {
final
var
invalidDeviceIds
=
returnInvalidDeviceIds
(
deviceIds
);
if
(!
invalidDeviceIds
.
isEmpty
())
{
var
policyRuleState
=
createFailedPolicyRuleState
(
"The Devices of PolicyRuleDevice "
+
policyRuleBasic
.
getPolicyRuleId
()
+
" are not valid"
);
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
policyRuleState
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
policyRuleState
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
String
message
=
String
.
format
(
"he Devices of PolicyRuleDevice %s are not valid"
,
policyRuleBasic
.
getPolicyRuleId
());
setState
(
policyRuleBasic
,
new
PolicyRuleState
(
PolicyRuleStateEnum
.
POLICY_FAILED
,
message
));
return
;
}
createAlarmDescriptorsForDevices
(
policyRuleDevice
);
}
private
void
setState
(
PolicyRuleBasic
policyRuleBasic
,
PolicyRuleState
policyRuleState
)
{
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
policyRuleState
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
policyRuleState
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
}
private
void
createAlarmDescriptorsForDevices
(
PolicyRuleDevice
policyRuleDevice
)
{
final
var
policyRuleBasic
=
policyRuleDevice
.
getPolicyRuleBasic
();
...
...
@@ -497,21 +480,15 @@ public class PolicyServiceImpl implements PolicyService {
parsePolicyRuleCondition
(
policyRuleDevice
.
getPolicyRuleBasic
());
if
(
alarmDescriptorList
.
isEmpty
())
{
var
policyRuleState
=
createFailedPolicyRuleState
(
"The PolicyRuleConditions of PolicyRuleDevice "
+
policyRuleBasic
.
getPolicyRuleId
()
+
" are not valid"
);
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
policyRuleState
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
policyRuleState
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
String
message
=
String
.
format
(
"The Devices of PolicyRuleDevice %s are not valid"
,
policyRuleBasic
.
getPolicyRuleId
());
setState
(
policyRuleBasic
,
new
PolicyRuleState
(
PolicyRuleStateEnum
.
POLICY_FAILED
,
message
));
return
;
}
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
VALIDATED_POLICYRULE_STATE
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
VALIDATED_POLICYRULE_STATE
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
setState
(
policyRuleBasic
,
VALIDATED_POLICYRULE_STATE
);
for
(
AlarmDescriptor
alarmDescriptor
:
alarmDescriptorList
)
{
alarmPolicyRuleDeviceMap
.
put
(
alarmDescriptor
.
getAlarmId
(),
policyRuleDevice
);
}
...
...
@@ -531,14 +508,14 @@ public class PolicyServiceImpl implements PolicyService {
.
with
(
policyRuleBoolean
->
{
if
(
Boolean
.
FALSE
.
equals
(
isUpdatedPolicyRuleValid
))
{
var
policyRuleState
=
createFailedPolicyRuleState
(
"The requested PolicyRuleService to update: "
+
policyRuleBasic
.
getPolicyRuleId
()
+
" is not valid"
);
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
policyRuleState
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
policyRuleState
);
contextService
.
set
PolicyRule
(
p
olicyRule
Basic
);
String
message
=
String
.
format
(
"The requested PolicyRuleService to update: %s is not valid"
,
policyRuleBasic
.
getPolicyRuleId
()
);
setState
(
policyRuleBasic
,
new
PolicyRule
State
(
P
olicyRule
StateEnum
.
POLICY_FAILED
,
message
)
);
return
;
}
...
...
@@ -557,14 +534,13 @@ public class PolicyServiceImpl implements PolicyService {
.
with
(
policyRuleBoolean
->
{
if
(
Boolean
.
FALSE
.
equals
(
isUpdatedPolicyRuleValid
))
{
var
policyRuleState
=
createFailedPolicyRuleState
(
"The requested PolicyRuleDevice to update: "
+
policyRuleBasic
.
getPolicyRuleId
()
+
" is not valid"
);
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
policyRuleState
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
policyRuleState
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
String
message
=
String
.
format
(
"The requested PolicyRuleDevice to update: %s is not valid"
,
policyRuleBasic
.
getPolicyRuleId
());
setState
(
policyRuleBasic
,
new
PolicyRuleState
(
PolicyRuleStateEnum
.
POLICY_FAILED
,
message
));
return
;
}
validateDevice
(
policyRuleDevice
);
...
...
@@ -580,14 +556,12 @@ public class PolicyServiceImpl implements PolicyService {
policyRuleConditionValidator
.
validateServiceId
(
serviceId
).
await
().
indefinitely
();
if
(!
isServiceIdValid
)
{
LOGGER
.
errorf
(
INVALID_MESSAGE
,
serviceId
);
var
policyRuleState
=
createFailedPolicyRuleState
(
"The Service of PolicyRuleService "
+
policyRuleBasic
.
getPolicyRuleId
()
+
" is not valid"
);
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
policyRuleState
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
policyRuleState
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
String
message
=
String
.
format
(
"The Service of PolicyRuleService %s is not valid"
,
policyRuleBasic
.
getPolicyRuleId
());
setState
(
policyRuleBasic
,
new
PolicyRuleState
(
PolicyRuleStateEnum
.
POLICY_FAILED
,
message
));
return
;
}
...
...
@@ -598,14 +572,12 @@ public class PolicyServiceImpl implements PolicyService {
.
indefinitely
();
if
(!
isServicesDeviceIdsValid
)
{
var
policyRuleState
=
createFailedPolicyRuleState
(
"The Devices of PolicyRuleService "
+
policyRuleBasic
.
getPolicyRuleId
()
+
" are not valid"
);
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
policyRuleState
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
policyRuleState
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
String
message
=
String
.
format
(
"he Devices of PolicyRuleService %s are not valid"
,
policyRuleBasic
.
getPolicyRuleId
());
setState
(
policyRuleBasic
,
new
PolicyRuleState
(
PolicyRuleStateEnum
.
POLICY_FAILED
,
message
));
return
;
}
...
...
@@ -622,19 +594,15 @@ public class PolicyServiceImpl implements PolicyService {
parsePolicyRuleCondition
(
policyRuleService
.
getPolicyRuleBasic
());
if
(
alarmDescriptorList
.
isEmpty
())
{
var
policyRuleState
=
createFailedPolicyRuleState
(
"The PolicyRuleConditions of PolicyRuleDevice "
+
policyRuleBasic
.
getPolicyRuleId
()
+
" are not valid"
);
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
policyRuleState
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
policyRuleState
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
String
message
=
String
.
format
(
"The PolicyRuleConditions of PolicyRuleDevice %s are not valid"
,
policyRuleBasic
.
getPolicyRuleId
());
setState
(
policyRuleBasic
,
new
PolicyRuleState
(
PolicyRuleStateEnum
.
POLICY_FAILED
,
message
));
return
;
}
LOGGER
.
infof
(
"Setting Policy Rule state to [%s]"
,
VALIDATED_POLICYRULE_STATE
.
toString
());
policyRuleBasic
.
setPolicyRuleState
(
VALIDATED_POLICYRULE_STATE
);
contextService
.
setPolicyRule
(
policyRuleBasic
);
setState
(
policyRuleBasic
,
VALIDATED_POLICYRULE_STATE
);
for
(
AlarmDescriptor
alarmDescriptor
:
alarmDescriptorList
)
{
alarmPolicyRuleServiceMap
.
put
(
alarmDescriptor
.
getAlarmId
(),
policyRuleService
);
...
...
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