From 8b24430dae2d60a0059415c501dcb9538cf22116 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Tue, 30 Jan 2024 15:31:41 +0200 Subject: [PATCH 1/7] refactor: Refactor addPolicyService function on separate sub functions for more clean code. --- .../etsi/tfs/policy/PolicyServiceImpl.java | 182 ++++++++------ .../grpc/context/ContextOuterClass.java | 224 ++++++++++-------- src/policy/target/kubernetes/kubernetes.yml | 108 --------- 3 files changed, 232 insertions(+), 282 deletions(-) delete mode 100644 src/policy/target/kubernetes/kubernetes.yml diff --git a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java index b5f1d85eb..0d7117d4e 100644 --- a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java +++ b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java @@ -38,6 +38,7 @@ import org.etsi.tfs.policy.context.model.Constraint; import org.etsi.tfs.policy.context.model.ConstraintCustom; import org.etsi.tfs.policy.context.model.ConstraintTypeCustom; import org.etsi.tfs.policy.context.model.ServiceConfig; +import org.etsi.tfs.policy.context.model.ServiceId; import org.etsi.tfs.policy.device.DeviceService; import org.etsi.tfs.policy.model.BooleanOperator; import org.etsi.tfs.policy.model.PolicyRule; @@ -176,81 +177,118 @@ public class PolicyServiceImpl implements PolicyService { return isServiceValid .onItem() .transform( - isService -> { - if (!isService) { - var policyRuleState = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_FAILED, - String.format(INVALID_MESSAGE, serviceId)); + isService -> + constructPolicyStateBasedOnCriteria( + isService, serviceId, policyRuleService, policyRuleBasic)); + } - return policyRuleState; - } + private PolicyRuleState constructPolicyStateBasedOnCriteria( + Boolean isService, + ServiceId serviceId, + PolicyRuleService policyRuleService, + PolicyRuleBasic policyRuleBasic) { - final var policyRuleTypeService = new PolicyRuleTypeService(policyRuleService); - final var policyRule = new PolicyRule(policyRuleTypeService); - final var alarmDescriptorList = createAlarmDescriptorList(policyRule); + if (!isService) { + var policyRuleState = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_FAILED, String.format(INVALID_MESSAGE, serviceId)); - if (alarmDescriptorList.isEmpty()) { - var policyRuleState = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_FAILED, - String.format( - "Invalid PolicyRuleConditions in PolicyRule with ID: %s", - policyRuleBasic.getPolicyRuleId())); - return policyRuleState; - } else { - contextService - .setPolicyRule(policyRule) - .subscribe() - .with( - policyId -> { - setPolicyRuleServiceToContext( - policyRuleService, VALIDATED_POLICYRULE_STATE); - noAlarms = 0; - - // Create an alarmIds list that contains the promised ids returned from - // setKpiAlarm - List> alarmIds = new ArrayList>(); - for (AlarmDescriptor alarmDescriptor : alarmDescriptorList) { - LOGGER.infof("alarmDescriptor:"); - LOGGER.infof(alarmDescriptor.toString()); - alarmIds.add(monitoringService.setKpiAlarm(alarmDescriptor)); - } - // Transform the alarmIds into promised alarms returned from the - // getAlarmResponseStream - List> alarmResponseStreamList = new ArrayList<>(); - for (Uni alarmId : alarmIds) { - alarmResponseStreamList.add( - alarmId - .onItem() - .transformToMulti( - id -> { - alarmPolicyRuleServiceMap.put(id, policyRuleService); - - // TODO: Create infinite subscription - var alarmSubscription = - new AlarmSubscription(id, 259200, 5000); - return monitoringService.getAlarmResponseStream( - alarmSubscription); - })); - } - - // Merge the promised alarms into one stream (Multi Object) - final var multi = - Multi.createBy().merging().streams(alarmResponseStreamList); - setPolicyRuleServiceToContext( - policyRuleService, PROVISIONED_POLICYRULE_STATE); - - subscriptionList.put(policyId, monitorAlarmResponseForService(multi)); - - // TODO: Resubscribe to the stream, if it has ended - - // TODO: Redesign evaluation of action - // evaluateAction(policyRule, alarmDescriptorList, multi); - }); - return VALIDATED_POLICYRULE_STATE; - } - }); + return policyRuleState; + } + + final var policyRuleTypeService = new PolicyRuleTypeService(policyRuleService); + final var policyRule = new PolicyRule(policyRuleTypeService); + final var alarmDescriptorList = createAlarmDescriptorList(policyRule); + + if (alarmDescriptorList.isEmpty()) { + var policyRuleState = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_FAILED, + String.format( + "Invalid PolicyRuleConditions in PolicyRule with ID: %s", + policyRuleBasic.getPolicyRuleId())); + return policyRuleState; + } + + return setPolicyRuleOnContextAndReturnState(policyRule, policyRuleService, alarmDescriptorList); + } + + private PolicyRuleState setPolicyRuleOnContextAndReturnState( + PolicyRule policyRule, + PolicyRuleService policyRuleService, + List alarmDescriptorList) { + contextService + .setPolicyRule(policyRule) + .subscribe() + .with(policyId -> startMonitoringBasedOnAlarmDescriptors(policyId, policyRuleService, alarmDescriptorList)); + return VALIDATED_POLICYRULE_STATE; + } + + private void startMonitoringBasedOnAlarmDescriptors( + String policyId, + PolicyRuleService policyRuleService, + List alarmDescriptorList) { + setPolicyRuleServiceToContext(policyRuleService, VALIDATED_POLICYRULE_STATE); + noAlarms = 0; + + List> alarmIds = + createAlarmList(alarmDescriptorList); // setAllarmtomonitoring get back alarmid + + List> alarmResponseStreamList = + transformAlarmIds(alarmIds, policyRuleService); + + // Merge the promised alarms into one stream (Multi Object) + final var multi = Multi.createBy().merging().streams(alarmResponseStreamList); + setPolicyRuleServiceToContext(policyRuleService, PROVISIONED_POLICYRULE_STATE); + + subscriptionList.put(policyId, monitorAlarmResponseForService(multi)); + + // TODO: Resubscribe to the stream, if it has ended + + // TODO: Redesign evaluation of action + // evaluateAction(policyRule, alarmDescriptorList, multi); + } + + /** + * Transform the alarmIds into promised alarms returned from the getAlarmResponseStream + * + * @param alarmIds the list of alarm ids + * @param policyRuleService the policy rule service + * @return + */ + private List> transformAlarmIds(List> alarmIds, PolicyRuleService policyRuleService) { + List> alarmResponseStreamList = new ArrayList<>(); + for (Uni alarmId : alarmIds) { + Multi alarmResponseStream = + alarmId.onItem().transformToMulti(id -> setPolicyMonitor(policyRuleService, id)); + + alarmResponseStreamList.add(alarmResponseStream); + } + return alarmResponseStreamList; + } + + private Multi setPolicyMonitor(PolicyRuleService policyRuleService, String id) { + alarmPolicyRuleServiceMap.put(id, policyRuleService); + + // TODO: Create infinite subscription + var alarmSubscription = new AlarmSubscription(id, 259200, 5000); + return monitoringService.getAlarmResponseStream(alarmSubscription); + } + + /** + * Create an alarmIds list that contains the promised ids returned from setKpiAlarm + * + * @param alarmDescriptorList the list of alarm descriptors + * @return the list of alarm descriptors + */ + public List> createAlarmList(List alarmDescriptorList) { + List> alarmIds = new ArrayList>(); + for (AlarmDescriptor alarmDescriptor : alarmDescriptorList) { + LOGGER.infof("alarmDescriptor:"); + LOGGER.infof(alarmDescriptor.toString()); + alarmIds.add(monitoringService.setKpiAlarm(alarmDescriptor)); + } + return alarmIds; } @Override diff --git a/src/policy/target/generated-sources/grpc/context/ContextOuterClass.java b/src/policy/target/generated-sources/grpc/context/ContextOuterClass.java index a25798b88..0672727a3 100644 --- a/src/policy/target/generated-sources/grpc/context/ContextOuterClass.java +++ b/src/policy/target/generated-sources/grpc/context/ContextOuterClass.java @@ -185,6 +185,10 @@ public final class ContextOuterClass { * DEVICEDRIVER_GNMI_OPENCONFIG = 8; */ DEVICEDRIVER_GNMI_OPENCONFIG(8), + /** + * DEVICEDRIVER_FLEXSCALE = 9; + */ + DEVICEDRIVER_FLEXSCALE(9), UNRECOGNIZED(-1), ; @@ -228,6 +232,10 @@ public final class ContextOuterClass { * DEVICEDRIVER_GNMI_OPENCONFIG = 8; */ public static final int DEVICEDRIVER_GNMI_OPENCONFIG_VALUE = 8; + /** + * DEVICEDRIVER_FLEXSCALE = 9; + */ + public static final int DEVICEDRIVER_FLEXSCALE_VALUE = 9; public final int getNumber() { @@ -263,6 +271,7 @@ public final class ContextOuterClass { case 6: return DEVICEDRIVER_XR; case 7: return DEVICEDRIVER_IETF_L2VPN; case 8: return DEVICEDRIVER_GNMI_OPENCONFIG; + case 9: return DEVICEDRIVER_FLEXSCALE; default: return null; } } @@ -461,6 +470,10 @@ public final class ContextOuterClass { * SERVICETYPE_TE = 4; */ SERVICETYPE_TE(4), + /** + * SERVICETYPE_E2E = 5; + */ + SERVICETYPE_E2E(5), UNRECOGNIZED(-1), ; @@ -484,6 +497,10 @@ public final class ContextOuterClass { * SERVICETYPE_TE = 4; */ public static final int SERVICETYPE_TE_VALUE = 4; + /** + * SERVICETYPE_E2E = 5; + */ + public static final int SERVICETYPE_E2E_VALUE = 5; public final int getNumber() { @@ -515,6 +532,7 @@ public final class ContextOuterClass { case 2: return SERVICETYPE_L2NM; case 3: return SERVICETYPE_TAPI_CONNECTIVITY_SERVICE; case 4: return SERVICETYPE_TE; + case 5: return SERVICETYPE_E2E; default: return null; } } @@ -75826,114 +75844,116 @@ public final class ContextOuterClass { "\0132\022.context.ContextId\022\025\n\rauthenticated\030\002" + " \001(\010*j\n\rEventTypeEnum\022\027\n\023EVENTTYPE_UNDEF" + "INED\020\000\022\024\n\020EVENTTYPE_CREATE\020\001\022\024\n\020EVENTTYP" + - "E_UPDATE\020\002\022\024\n\020EVENTTYPE_REMOVE\020\003*\231\002\n\020Dev" + + "E_UPDATE\020\002\022\024\n\020EVENTTYPE_REMOVE\020\003*\265\002\n\020Dev" + "iceDriverEnum\022\032\n\026DEVICEDRIVER_UNDEFINED\020" + "\000\022\033\n\027DEVICEDRIVER_OPENCONFIG\020\001\022\036\n\032DEVICE" + "DRIVER_TRANSPORT_API\020\002\022\023\n\017DEVICEDRIVER_P" + "4\020\003\022&\n\"DEVICEDRIVER_IETF_NETWORK_TOPOLOG" + "Y\020\004\022\033\n\027DEVICEDRIVER_ONF_TR_532\020\005\022\023\n\017DEVI" + "CEDRIVER_XR\020\006\022\033\n\027DEVICEDRIVER_IETF_L2VPN" + - "\020\007\022 \n\034DEVICEDRIVER_GNMI_OPENCONFIG\020\010*\217\001\n" + - "\033DeviceOperationalStatusEnum\022%\n!DEVICEOP" + - "ERATIONALSTATUS_UNDEFINED\020\000\022$\n DEVICEOPE" + - "RATIONALSTATUS_DISABLED\020\001\022#\n\037DEVICEOPERA" + - "TIONALSTATUS_ENABLED\020\002*\225\001\n\017ServiceTypeEn" + - "um\022\027\n\023SERVICETYPE_UNKNOWN\020\000\022\024\n\020SERVICETY" + - "PE_L3NM\020\001\022\024\n\020SERVICETYPE_L2NM\020\002\022)\n%SERVI" + - "CETYPE_TAPI_CONNECTIVITY_SERVICE\020\003\022\022\n\016SE" + - "RVICETYPE_TE\020\004*\304\001\n\021ServiceStatusEnum\022\033\n\027" + - "SERVICESTATUS_UNDEFINED\020\000\022\031\n\025SERVICESTAT" + - "US_PLANNED\020\001\022\030\n\024SERVICESTATUS_ACTIVE\020\002\022\032" + - "\n\026SERVICESTATUS_UPDATING\020\003\022!\n\035SERVICESTA" + - "TUS_PENDING_REMOVAL\020\004\022\036\n\032SERVICESTATUS_S" + - "LA_VIOLATED\020\005*\251\001\n\017SliceStatusEnum\022\031\n\025SLI" + - "CESTATUS_UNDEFINED\020\000\022\027\n\023SLICESTATUS_PLAN" + - "NED\020\001\022\024\n\020SLICESTATUS_INIT\020\002\022\026\n\022SLICESTAT" + - "US_ACTIVE\020\003\022\026\n\022SLICESTATUS_DEINIT\020\004\022\034\n\030S" + - "LICESTATUS_SLA_VIOLATED\020\005*]\n\020ConfigActio" + - "nEnum\022\032\n\026CONFIGACTION_UNDEFINED\020\000\022\024\n\020CON" + - "FIGACTION_SET\020\001\022\027\n\023CONFIGACTION_DELETE\020\002" + - "*m\n\024ConstraintActionEnum\022\036\n\032CONSTRAINTAC" + - "TION_UNDEFINED\020\000\022\030\n\024CONSTRAINTACTION_SET" + - "\020\001\022\033\n\027CONSTRAINTACTION_DELETE\020\002*\203\002\n\022Isol" + - "ationLevelEnum\022\020\n\014NO_ISOLATION\020\000\022\026\n\022PHYS" + - "ICAL_ISOLATION\020\001\022\025\n\021LOGICAL_ISOLATION\020\002\022" + - "\025\n\021PROCESS_ISOLATION\020\003\022\035\n\031PHYSICAL_MEMOR" + - "Y_ISOLATION\020\004\022\036\n\032PHYSICAL_NETWORK_ISOLAT" + - "ION\020\005\022\036\n\032VIRTUAL_RESOURCE_ISOLATION\020\006\022\037\n" + - "\033NETWORK_FUNCTIONS_ISOLATION\020\007\022\025\n\021SERVIC" + - "E_ISOLATION\020\0102\245\026\n\016ContextService\022:\n\016List" + - "ContextIds\022\016.context.Empty\032\026.context.Con" + - "textIdList\"\000\0226\n\014ListContexts\022\016.context.E" + - "mpty\032\024.context.ContextList\"\000\0224\n\nGetConte" + - "xt\022\022.context.ContextId\032\020.context.Context" + - "\"\000\0224\n\nSetContext\022\020.context.Context\032\022.con" + - "text.ContextId\"\000\0225\n\rRemoveContext\022\022.cont" + - "ext.ContextId\032\016.context.Empty\"\000\022=\n\020GetCo" + - "ntextEvents\022\016.context.Empty\032\025.context.Co" + - "ntextEvent\"\0000\001\022@\n\017ListTopologyIds\022\022.cont" + - "ext.ContextId\032\027.context.TopologyIdList\"\000" + - "\022=\n\016ListTopologies\022\022.context.ContextId\032\025" + - ".context.TopologyList\"\000\0227\n\013GetTopology\022\023" + - ".context.TopologyId\032\021.context.Topology\"\000" + - "\022E\n\022GetTopologyDetails\022\023.context.Topolog" + - "yId\032\030.context.TopologyDetails\"\000\0227\n\013SetTo" + - "pology\022\021.context.Topology\032\023.context.Topo" + - "logyId\"\000\0227\n\016RemoveTopology\022\023.context.Top" + - "ologyId\032\016.context.Empty\"\000\022?\n\021GetTopology" + - "Events\022\016.context.Empty\032\026.context.Topolog" + - "yEvent\"\0000\001\0228\n\rListDeviceIds\022\016.context.Em" + - "pty\032\025.context.DeviceIdList\"\000\0224\n\013ListDevi" + - "ces\022\016.context.Empty\032\023.context.DeviceList" + - "\"\000\0221\n\tGetDevice\022\021.context.DeviceId\032\017.con" + - "text.Device\"\000\0221\n\tSetDevice\022\017.context.Dev" + - "ice\032\021.context.DeviceId\"\000\0223\n\014RemoveDevice" + - "\022\021.context.DeviceId\032\016.context.Empty\"\000\022;\n" + - "\017GetDeviceEvents\022\016.context.Empty\032\024.conte" + - "xt.DeviceEvent\"\0000\001\022<\n\014SelectDevice\022\025.con" + - "text.DeviceFilter\032\023.context.DeviceList\"\000" + - "\022I\n\021ListEndPointNames\022\027.context.EndPoint" + - "IdList\032\031.context.EndPointNameList\"\000\0224\n\013L" + - "istLinkIds\022\016.context.Empty\032\023.context.Lin" + - "kIdList\"\000\0220\n\tListLinks\022\016.context.Empty\032\021" + - ".context.LinkList\"\000\022+\n\007GetLink\022\017.context" + - ".LinkId\032\r.context.Link\"\000\022+\n\007SetLink\022\r.co" + - "ntext.Link\032\017.context.LinkId\"\000\022/\n\nRemoveL" + - "ink\022\017.context.LinkId\032\016.context.Empty\"\000\0227" + - "\n\rGetLinkEvents\022\016.context.Empty\032\022.contex" + - "t.LinkEvent\"\0000\001\022>\n\016ListServiceIds\022\022.cont" + - "ext.ContextId\032\026.context.ServiceIdList\"\000\022" + - ":\n\014ListServices\022\022.context.ContextId\032\024.co" + - "ntext.ServiceList\"\000\0224\n\nGetService\022\022.cont" + - "ext.ServiceId\032\020.context.Service\"\000\0224\n\nSet" + - "Service\022\020.context.Service\032\022.context.Serv" + - "iceId\"\000\0226\n\014UnsetService\022\020.context.Servic" + - "e\032\022.context.ServiceId\"\000\0225\n\rRemoveService" + - "\022\022.context.ServiceId\032\016.context.Empty\"\000\022=" + - "\n\020GetServiceEvents\022\016.context.Empty\032\025.con" + - "text.ServiceEvent\"\0000\001\022?\n\rSelectService\022\026" + - ".context.ServiceFilter\032\024.context.Service" + - "List\"\000\022:\n\014ListSliceIds\022\022.context.Context" + - "Id\032\024.context.SliceIdList\"\000\0226\n\nListSlices" + - "\022\022.context.ContextId\032\022.context.SliceList" + - "\"\000\022.\n\010GetSlice\022\020.context.SliceId\032\016.conte" + - "xt.Slice\"\000\022.\n\010SetSlice\022\016.context.Slice\032\020" + - ".context.SliceId\"\000\0220\n\nUnsetSlice\022\016.conte" + - "xt.Slice\032\020.context.SliceId\"\000\0221\n\013RemoveSl" + - "ice\022\020.context.SliceId\032\016.context.Empty\"\000\022" + - "9\n\016GetSliceEvents\022\016.context.Empty\032\023.cont" + - "ext.SliceEvent\"\0000\001\0229\n\013SelectSlice\022\024.cont" + - "ext.SliceFilter\032\022.context.SliceList\"\000\022D\n" + - "\021ListConnectionIds\022\022.context.ServiceId\032\031" + - ".context.ConnectionIdList\"\000\022@\n\017ListConne" + - "ctions\022\022.context.ServiceId\032\027.context.Con" + - "nectionList\"\000\022=\n\rGetConnection\022\025.context" + - ".ConnectionId\032\023.context.Connection\"\000\022=\n\r" + - "SetConnection\022\023.context.Connection\032\025.con" + - "text.ConnectionId\"\000\022;\n\020RemoveConnection\022" + - "\025.context.ConnectionId\032\016.context.Empty\"\000" + - "\022C\n\023GetConnectionEvents\022\016.context.Empty\032" + - "\030.context.ConnectionEvent\"\0000\001b\006proto3" + "\020\007\022 \n\034DEVICEDRIVER_GNMI_OPENCONFIG\020\010\022\032\n\026" + + "DEVICEDRIVER_FLEXSCALE\020\t*\217\001\n\033DeviceOpera" + + "tionalStatusEnum\022%\n!DEVICEOPERATIONALSTA" + + "TUS_UNDEFINED\020\000\022$\n DEVICEOPERATIONALSTAT" + + "US_DISABLED\020\001\022#\n\037DEVICEOPERATIONALSTATUS" + + "_ENABLED\020\002*\252\001\n\017ServiceTypeEnum\022\027\n\023SERVIC" + + "ETYPE_UNKNOWN\020\000\022\024\n\020SERVICETYPE_L3NM\020\001\022\024\n" + + "\020SERVICETYPE_L2NM\020\002\022)\n%SERVICETYPE_TAPI_" + + "CONNECTIVITY_SERVICE\020\003\022\022\n\016SERVICETYPE_TE" + + "\020\004\022\023\n\017SERVICETYPE_E2E\020\005*\304\001\n\021ServiceStatu" + + "sEnum\022\033\n\027SERVICESTATUS_UNDEFINED\020\000\022\031\n\025SE" + + "RVICESTATUS_PLANNED\020\001\022\030\n\024SERVICESTATUS_A" + + "CTIVE\020\002\022\032\n\026SERVICESTATUS_UPDATING\020\003\022!\n\035S" + + "ERVICESTATUS_PENDING_REMOVAL\020\004\022\036\n\032SERVIC" + + "ESTATUS_SLA_VIOLATED\020\005*\251\001\n\017SliceStatusEn" + + "um\022\031\n\025SLICESTATUS_UNDEFINED\020\000\022\027\n\023SLICEST" + + "ATUS_PLANNED\020\001\022\024\n\020SLICESTATUS_INIT\020\002\022\026\n\022" + + "SLICESTATUS_ACTIVE\020\003\022\026\n\022SLICESTATUS_DEIN" + + "IT\020\004\022\034\n\030SLICESTATUS_SLA_VIOLATED\020\005*]\n\020Co" + + "nfigActionEnum\022\032\n\026CONFIGACTION_UNDEFINED" + + "\020\000\022\024\n\020CONFIGACTION_SET\020\001\022\027\n\023CONFIGACTION" + + "_DELETE\020\002*m\n\024ConstraintActionEnum\022\036\n\032CON" + + "STRAINTACTION_UNDEFINED\020\000\022\030\n\024CONSTRAINTA" + + "CTION_SET\020\001\022\033\n\027CONSTRAINTACTION_DELETE\020\002" + + "*\203\002\n\022IsolationLevelEnum\022\020\n\014NO_ISOLATION\020" + + "\000\022\026\n\022PHYSICAL_ISOLATION\020\001\022\025\n\021LOGICAL_ISO" + + "LATION\020\002\022\025\n\021PROCESS_ISOLATION\020\003\022\035\n\031PHYSI" + + "CAL_MEMORY_ISOLATION\020\004\022\036\n\032PHYSICAL_NETWO" + + "RK_ISOLATION\020\005\022\036\n\032VIRTUAL_RESOURCE_ISOLA" + + "TION\020\006\022\037\n\033NETWORK_FUNCTIONS_ISOLATION\020\007\022" + + "\025\n\021SERVICE_ISOLATION\020\0102\245\026\n\016ContextServic" + + "e\022:\n\016ListContextIds\022\016.context.Empty\032\026.co" + + "ntext.ContextIdList\"\000\0226\n\014ListContexts\022\016." + + "context.Empty\032\024.context.ContextList\"\000\0224\n" + + "\nGetContext\022\022.context.ContextId\032\020.contex" + + "t.Context\"\000\0224\n\nSetContext\022\020.context.Cont" + + "ext\032\022.context.ContextId\"\000\0225\n\rRemoveConte" + + "xt\022\022.context.ContextId\032\016.context.Empty\"\000" + + "\022=\n\020GetContextEvents\022\016.context.Empty\032\025.c" + + "ontext.ContextEvent\"\0000\001\022@\n\017ListTopologyI" + + "ds\022\022.context.ContextId\032\027.context.Topolog" + + "yIdList\"\000\022=\n\016ListTopologies\022\022.context.Co" + + "ntextId\032\025.context.TopologyList\"\000\0227\n\013GetT" + + "opology\022\023.context.TopologyId\032\021.context.T" + + "opology\"\000\022E\n\022GetTopologyDetails\022\023.contex" + + "t.TopologyId\032\030.context.TopologyDetails\"\000" + + "\0227\n\013SetTopology\022\021.context.Topology\032\023.con" + + "text.TopologyId\"\000\0227\n\016RemoveTopology\022\023.co" + + "ntext.TopologyId\032\016.context.Empty\"\000\022?\n\021Ge" + + "tTopologyEvents\022\016.context.Empty\032\026.contex" + + "t.TopologyEvent\"\0000\001\0228\n\rListDeviceIds\022\016.c" + + "ontext.Empty\032\025.context.DeviceIdList\"\000\0224\n" + + "\013ListDevices\022\016.context.Empty\032\023.context.D" + + "eviceList\"\000\0221\n\tGetDevice\022\021.context.Devic" + + "eId\032\017.context.Device\"\000\0221\n\tSetDevice\022\017.co" + + "ntext.Device\032\021.context.DeviceId\"\000\0223\n\014Rem" + + "oveDevice\022\021.context.DeviceId\032\016.context.E" + + "mpty\"\000\022;\n\017GetDeviceEvents\022\016.context.Empt" + + "y\032\024.context.DeviceEvent\"\0000\001\022<\n\014SelectDev" + + "ice\022\025.context.DeviceFilter\032\023.context.Dev" + + "iceList\"\000\022I\n\021ListEndPointNames\022\027.context" + + ".EndPointIdList\032\031.context.EndPointNameLi" + + "st\"\000\0224\n\013ListLinkIds\022\016.context.Empty\032\023.co" + + "ntext.LinkIdList\"\000\0220\n\tListLinks\022\016.contex" + + "t.Empty\032\021.context.LinkList\"\000\022+\n\007GetLink\022" + + "\017.context.LinkId\032\r.context.Link\"\000\022+\n\007Set" + + "Link\022\r.context.Link\032\017.context.LinkId\"\000\022/" + + "\n\nRemoveLink\022\017.context.LinkId\032\016.context." + + "Empty\"\000\0227\n\rGetLinkEvents\022\016.context.Empty" + + "\032\022.context.LinkEvent\"\0000\001\022>\n\016ListServiceI" + + "ds\022\022.context.ContextId\032\026.context.Service" + + "IdList\"\000\022:\n\014ListServices\022\022.context.Conte" + + "xtId\032\024.context.ServiceList\"\000\0224\n\nGetServi" + + "ce\022\022.context.ServiceId\032\020.context.Service" + + "\"\000\0224\n\nSetService\022\020.context.Service\032\022.con" + + "text.ServiceId\"\000\0226\n\014UnsetService\022\020.conte" + + "xt.Service\032\022.context.ServiceId\"\000\0225\n\rRemo" + + "veService\022\022.context.ServiceId\032\016.context." + + "Empty\"\000\022=\n\020GetServiceEvents\022\016.context.Em" + + "pty\032\025.context.ServiceEvent\"\0000\001\022?\n\rSelect" + + "Service\022\026.context.ServiceFilter\032\024.contex" + + "t.ServiceList\"\000\022:\n\014ListSliceIds\022\022.contex" + + "t.ContextId\032\024.context.SliceIdList\"\000\0226\n\nL" + + "istSlices\022\022.context.ContextId\032\022.context." + + "SliceList\"\000\022.\n\010GetSlice\022\020.context.SliceI" + + "d\032\016.context.Slice\"\000\022.\n\010SetSlice\022\016.contex" + + "t.Slice\032\020.context.SliceId\"\000\0220\n\nUnsetSlic" + + "e\022\016.context.Slice\032\020.context.SliceId\"\000\0221\n" + + "\013RemoveSlice\022\020.context.SliceId\032\016.context" + + ".Empty\"\000\0229\n\016GetSliceEvents\022\016.context.Emp" + + "ty\032\023.context.SliceEvent\"\0000\001\0229\n\013SelectSli" + + "ce\022\024.context.SliceFilter\032\022.context.Slice" + + "List\"\000\022D\n\021ListConnectionIds\022\022.context.Se" + + "rviceId\032\031.context.ConnectionIdList\"\000\022@\n\017" + + "ListConnections\022\022.context.ServiceId\032\027.co" + + "ntext.ConnectionList\"\000\022=\n\rGetConnection\022" + + "\025.context.ConnectionId\032\023.context.Connect" + + "ion\"\000\022=\n\rSetConnection\022\023.context.Connect" + + "ion\032\025.context.ConnectionId\"\000\022;\n\020RemoveCo" + + "nnection\022\025.context.ConnectionId\032\016.contex" + + "t.Empty\"\000\022C\n\023GetConnectionEvents\022\016.conte" + + "xt.Empty\032\030.context.ConnectionEvent\"\0000\001b\006" + + "proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, diff --git a/src/policy/target/kubernetes/kubernetes.yml b/src/policy/target/kubernetes/kubernetes.yml deleted file mode 100644 index 5cd1f1c4c..000000000 --- a/src/policy/target/kubernetes/kubernetes.yml +++ /dev/null @@ -1,108 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - app.quarkus.io/commit-id: 46486023929121fc955e9550fc8fd625ded433d2 - app.quarkus.io/build-timestamp: 2023-12-15 - 11:56:20 +0000 - prometheus.io/scrape: "true" - prometheus.io/path: /q/metrics - prometheus.io/port: "8080" - prometheus.io/scheme: http - labels: - app.kubernetes.io/name: policyservice - app: policyservice - name: policyservice -spec: - ports: - - name: grpc-server - port: 6060 - targetPort: 6060 - - name: http - port: 9192 - targetPort: 8080 - selector: - app.kubernetes.io/name: policyservice - type: ClusterIP ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - app.quarkus.io/commit-id: 46486023929121fc955e9550fc8fd625ded433d2 - app.quarkus.io/build-timestamp: 2023-12-15 - 11:56:20 +0000 - prometheus.io/scrape: "true" - prometheus.io/path: /q/metrics - prometheus.io/port: "8080" - prometheus.io/scheme: http - labels: - app: policyservice - app.kubernetes.io/name: policyservice - name: policyservice -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/name: policyservice - template: - metadata: - annotations: - app.quarkus.io/commit-id: 46486023929121fc955e9550fc8fd625ded433d2 - app.quarkus.io/build-timestamp: 2023-12-15 - 11:56:20 +0000 - prometheus.io/scrape: "true" - prometheus.io/path: /q/metrics - prometheus.io/port: "8080" - prometheus.io/scheme: http - labels: - app: policyservice - app.kubernetes.io/name: policyservice - spec: - containers: - - env: - - name: KUBERNETES_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: CONTEXT_SERVICE_HOST - value: contextservice - - name: MONITORING_SERVICE_HOST - value: monitoringservice - - name: SERVICE_SERVICE_HOST - value: serviceservice - image: labs.etsi.org:5050/tfs/controller/policy:0.1.0 - imagePullPolicy: Always - livenessProbe: - failureThreshold: 3 - httpGet: - path: /q/health/live - port: 8080 - scheme: HTTP - initialDelaySeconds: 2 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 10 - name: policyservice - ports: - - containerPort: 6060 - name: grpc-server - protocol: TCP - - containerPort: 8080 - name: http - protocol: TCP - readinessProbe: - failureThreshold: 3 - httpGet: - path: /q/health/ready - port: 8080 - scheme: HTTP - initialDelaySeconds: 2 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 10 - resources: - limits: - cpu: 500m - memory: 2048Mi - requests: - cpu: 50m - memory: 512Mi -- GitLab From 26e30e5036753fadd7a435611738745efa65db1c Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Tue, 30 Jan 2024 16:07:48 +0200 Subject: [PATCH 2/7] refactor: spotless apply. --- .../java/org/etsi/tfs/policy/PolicyServiceImpl.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java index 0d7117d4e..faf288cf6 100644 --- a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java +++ b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java @@ -178,7 +178,7 @@ public class PolicyServiceImpl implements PolicyService { .onItem() .transform( isService -> - constructPolicyStateBasedOnCriteria( + constructPolicyStateBasedOnCriteria( isService, serviceId, policyRuleService, policyRuleBasic)); } @@ -220,7 +220,10 @@ public class PolicyServiceImpl implements PolicyService { contextService .setPolicyRule(policyRule) .subscribe() - .with(policyId -> startMonitoringBasedOnAlarmDescriptors(policyId, policyRuleService, alarmDescriptorList)); + .with( + policyId -> + startMonitoringBasedOnAlarmDescriptors( + policyId, policyRuleService, alarmDescriptorList)); return VALIDATED_POLICYRULE_STATE; } @@ -256,7 +259,8 @@ public class PolicyServiceImpl implements PolicyService { * @param policyRuleService the policy rule service * @return */ - private List> transformAlarmIds(List> alarmIds, PolicyRuleService policyRuleService) { + private List> transformAlarmIds( + List> alarmIds, PolicyRuleService policyRuleService) { List> alarmResponseStreamList = new ArrayList<>(); for (Uni alarmId : alarmIds) { Multi alarmResponseStream = -- GitLab From f262dc955cd56d3564fd35af1581cfd95a804ee9 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Thu, 1 Feb 2024 10:03:47 +0200 Subject: [PATCH 3/7] refactor: Make more simple the addPolicyDevice and deletePolicy. --- .../etsi/tfs/policy/PolicyServiceImpl.java | 177 ++++++++++-------- 1 file changed, 96 insertions(+), 81 deletions(-) diff --git a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java index faf288cf6..3ef1987db 100644 --- a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java +++ b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java @@ -322,74 +322,91 @@ public class PolicyServiceImpl implements PolicyService { return areDevicesValid .onItem() - .transform( - areDevices -> { - if (areDevices.contains(false)) { - var policyRuleState = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_FAILED, - String.format( - INVALID_MESSAGE, - policyRuleDevice.getPolicyRuleBasic().getPolicyRuleId())); - - return policyRuleState; - } + .transform(areDevices -> addDeviceOnContext(areDevices, policyRuleDevice, policyRuleBasic)); + } - final var policyRuleTypeDevice = new PolicyRuleTypeDevice(policyRuleDevice); - final var policyRule = new PolicyRule(policyRuleTypeDevice); - - final var alarmDescriptorList = createAlarmDescriptorList(policyRule); - if (alarmDescriptorList.isEmpty()) { - var policyRuleState = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_FAILED, - String.format( - "Invalid PolicyRuleConditions in PolicyRule with ID: %s", - policyRuleBasic.getPolicyRuleId())); - return policyRuleState; - } + private PolicyRuleState addDeviceOnContext( + List areDevices, + PolicyRuleDevice policyRuleDevice, + PolicyRuleBasic policyRuleBasic) { + if (areDevices.contains(false)) { + var policyRuleState = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_FAILED, + String.format( + INVALID_MESSAGE, policyRuleDevice.getPolicyRuleBasic().getPolicyRuleId())); - contextService.setPolicyRule(policyRule).subscribe().with(x -> {}); - setPolicyRuleDeviceToContext(policyRuleDevice, VALIDATED_POLICYRULE_STATE); - noAlarms = 0; + return policyRuleState; + } - List> alarmIds = new ArrayList>(); - for (AlarmDescriptor alarmDescriptor : alarmDescriptorList) { - LOGGER.infof("alarmDescriptor:"); - LOGGER.infof(alarmDescriptor.toString()); - alarmIds.add(monitoringService.setKpiAlarm(alarmDescriptor)); - } + final var policyRuleTypeDevice = new PolicyRuleTypeDevice(policyRuleDevice); + final var policyRule = new PolicyRule(policyRuleTypeDevice); - // Transform the alarmIds into promised alarms returned from the - // getAlarmResponseStream - List> alarmResponseStreamList = new ArrayList<>(); - for (Uni alarmId : alarmIds) { - alarmResponseStreamList.add( - alarmId - .onItem() - .transformToMulti( - id -> { - alarmPolicyRuleDeviceMap.put(id, policyRuleDevice); - - // TODO: Create infinite subscription - var alarmSubscription = new AlarmSubscription(id, 259200, 5000); - return monitoringService.getAlarmResponseStream(alarmSubscription); - })); - } + final var alarmDescriptorList = createAlarmDescriptorList(policyRule); + if (alarmDescriptorList.isEmpty()) { + var policyRuleState = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_FAILED, + String.format( + "Invalid PolicyRuleConditions in PolicyRule with ID: %s", + policyRuleBasic.getPolicyRuleId())); + return policyRuleState; + } - // Merge the promised alarms into one stream (Multi Object) - final var multi = Multi.createBy().merging().streams(alarmResponseStreamList); - setPolicyRuleDeviceToContext(policyRuleDevice, PROVISIONED_POLICYRULE_STATE); + contextService.setPolicyRule(policyRule).subscribe().with(x -> {}); + setPolicyRuleDeviceToContext(policyRuleDevice, VALIDATED_POLICYRULE_STATE); + noAlarms = 0; - monitorAlarmResponseForDevice(multi); + List> alarmIds = getAlarmIds(alarmDescriptorList); - // TODO: Resubscribe to the stream, if it has ended + List> alarmResponseStreamList = + getAlarmResponse(alarmIds, policyRuleDevice); - // TODO: Redesign evaluation of action - // evaluateAction(policyRule, alarmDescriptorList, multi); + // Merge the promised alarms into one stream (Multi Object) + 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> getAlarmResponse( + List> alarmIds, PolicyRuleDevice policyRuleDevice) { + // Transform the alarmIds into promised alarms returned from the + // getAlarmResponseStream + List> alarmResponseStreamList = new ArrayList<>(); + for (Uni alarmId : alarmIds) { + alarmResponseStreamList.add( + alarmId + .onItem() + .transformToMulti( + id -> setPolicyMonitoringDevice(policyRuleDevice, id))); + } + return alarmResponseStreamList; + } + + private Multi 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> getAlarmIds(List alarmDescriptorList) { + List> alarmIds = new ArrayList>(); + for (AlarmDescriptor alarmDescriptor : alarmDescriptorList) { + LOGGER.infof("alarmDescriptor:"); + LOGGER.infof(alarmDescriptor.toString()); + alarmIds.add(monitoringService.setKpiAlarm(alarmDescriptor)); + } + return alarmIds; } @Override @@ -477,32 +494,30 @@ public class PolicyServiceImpl implements PolicyService { final var getPolicyRule = contextService.getPolicyRule(policyRuleId); - return getPolicyRule - .onItem() - .transform( - policyRule -> { - var policyRuleBasic = policyRule.getPolicyRuleType().getPolicyRuleBasic(); - String policyId = policyRuleBasic.getPolicyRuleId(); + return getPolicyRule.onItem().transform(policyRule -> removePolicyFromContext(policyRule)); + } - policyRule - .getPolicyRuleType() - .getPolicyRuleBasic() - .setPolicyRuleState(REMOVED_POLICYRULE_STATE); + private PolicyRuleState removePolicyFromContext(PolicyRule policyRule) { + var policyRuleBasic = policyRule.getPolicyRuleType().getPolicyRuleBasic(); + String policyId = policyRuleBasic.getPolicyRuleId(); - contextService - .setPolicyRule(policyRule) - .subscribe() - .with( - tmp -> - LOGGER.infof( - "DeletePolicy with id: " + VALID_MESSAGE, - policyRuleBasic.getPolicyRuleId())); + policyRule + .getPolicyRuleType() + .getPolicyRuleBasic() + .setPolicyRuleState(REMOVED_POLICYRULE_STATE); + + contextService + .setPolicyRule(policyRule) + .subscribe() + .with( + tmp -> + LOGGER.infof( + "DeletePolicy with id: " + VALID_MESSAGE, policyRuleBasic.getPolicyRuleId())); - contextService.removePolicyRule(policyId).subscribe().with(x -> {}); - subscriptionList.get(policyId).cancel(); + contextService.removePolicyRule(policyId).subscribe().with(x -> {}); + subscriptionList.get(policyId).cancel(); - return policyRuleBasic.getPolicyRuleState(); - }); + return policyRuleBasic.getPolicyRuleState(); } private Uni> returnInvalidDeviceIds(List deviceIds) { -- GitLab From 0d501c7522c4ab1d032474e2255802664880a4e4 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Thu, 1 Feb 2024 12:26:35 +0200 Subject: [PATCH 4/7] refactor: spotless apply. --- .../main/java/org/etsi/tfs/policy/PolicyServiceImpl.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java index 3ef1987db..716949e65 100644 --- a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java +++ b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java @@ -383,15 +383,13 @@ public class PolicyServiceImpl implements PolicyService { List> alarmResponseStreamList = new ArrayList<>(); for (Uni alarmId : alarmIds) { alarmResponseStreamList.add( - alarmId - .onItem() - .transformToMulti( - id -> setPolicyMonitoringDevice(policyRuleDevice, id))); + alarmId.onItem().transformToMulti(id -> setPolicyMonitoringDevice(policyRuleDevice, id))); } return alarmResponseStreamList; } - private Multi setPolicyMonitoringDevice(PolicyRuleDevice policyRuleDevice, String id){ + private Multi setPolicyMonitoringDevice( + PolicyRuleDevice policyRuleDevice, String id) { alarmPolicyRuleDeviceMap.put(id, policyRuleDevice); // TODO: Create infinite subscription -- GitLab From bb8344033c6afaaec1bbce62dbea7d04f130d8e4 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Fri, 9 Feb 2024 15:47:12 +0200 Subject: [PATCH 5/7] refactor: refactor add policy device two add the policyId to the subscription list. --- .../etsi/tfs/policy/PolicyServiceImpl.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java index 716949e65..e276694a7 100644 --- a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java +++ b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java @@ -322,10 +322,10 @@ public class PolicyServiceImpl implements PolicyService { return areDevicesValid .onItem() - .transform(areDevices -> addDeviceOnContext(areDevices, policyRuleDevice, policyRuleBasic)); + .transform(areDevices -> areDeviceOnContext(areDevices, policyRuleDevice, policyRuleBasic)); } - private PolicyRuleState addDeviceOnContext( + private PolicyRuleState areDeviceOnContext( List areDevices, PolicyRuleDevice policyRuleDevice, PolicyRuleBasic policyRuleBasic) { @@ -353,7 +353,22 @@ public class PolicyServiceImpl implements PolicyService { return policyRuleState; } - contextService.setPolicyRule(policyRule).subscribe().with(x -> {}); + contextService + .setPolicyRule(policyRule) + .subscribe() + .with( + policyId -> { + startMonitoringBasedOnAlarmDescriptors( + policyId, policyRuleDevice, alarmDescriptorList); + }); + + return VALIDATED_POLICYRULE_STATE; + } + + private void startMonitoringBasedOnAlarmDescriptors( + String policyId, + PolicyRuleDevice policyRuleDevice, + List alarmDescriptorList) { setPolicyRuleDeviceToContext(policyRuleDevice, VALIDATED_POLICYRULE_STATE); noAlarms = 0; @@ -366,14 +381,12 @@ public class PolicyServiceImpl implements PolicyService { final var multi = Multi.createBy().merging().streams(alarmResponseStreamList); setPolicyRuleDeviceToContext(policyRuleDevice, PROVISIONED_POLICYRULE_STATE); - monitorAlarmResponseForDevice(multi); + subscriptionList.put(policyId, 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> getAlarmResponse( @@ -569,8 +582,8 @@ public class PolicyServiceImpl implements PolicyService { }); } - private void monitorAlarmResponseForDevice(Multi multi) { - multi + private Cancellable monitorAlarmResponseForDevice(Multi multi) { + return multi .subscribe() .with( alarmResponse -> { -- GitLab From 5e893e034025f8cf23049762b63846ec9ddfbb82 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Fri, 9 Feb 2024 16:55:16 +0200 Subject: [PATCH 6/7] refactor: add kubernetes.yml file --- src/policy/target/kubernetes/kubernetes.yml | 108 ++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/policy/target/kubernetes/kubernetes.yml diff --git a/src/policy/target/kubernetes/kubernetes.yml b/src/policy/target/kubernetes/kubernetes.yml new file mode 100644 index 000000000..22f4c6c29 --- /dev/null +++ b/src/policy/target/kubernetes/kubernetes.yml @@ -0,0 +1,108 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + app.quarkus.io/commit-id: b20b6dc3df9cb82052d2ddf933eb17df1d34d9ee + app.quarkus.io/build-timestamp: 2024-02-09 - 14:55:10 +0000 + prometheus.io/scrape: "true" + prometheus.io/path: /q/metrics + prometheus.io/port: "8080" + prometheus.io/scheme: http + labels: + app.kubernetes.io/name: policyservice + app: policyservice + name: policyservice +spec: + ports: + - name: grpc-server + port: 6060 + targetPort: 6060 + - name: http + port: 9192 + targetPort: 8080 + selector: + app.kubernetes.io/name: policyservice + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + app.quarkus.io/commit-id: b20b6dc3df9cb82052d2ddf933eb17df1d34d9ee + app.quarkus.io/build-timestamp: 2024-02-09 - 14:55:10 +0000 + prometheus.io/scrape: "true" + prometheus.io/path: /q/metrics + prometheus.io/port: "8080" + prometheus.io/scheme: http + labels: + app: policyservice + app.kubernetes.io/name: policyservice + name: policyservice +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: policyservice + template: + metadata: + annotations: + app.quarkus.io/commit-id: b20b6dc3df9cb82052d2ddf933eb17df1d34d9ee + app.quarkus.io/build-timestamp: 2024-02-09 - 14:55:10 +0000 + prometheus.io/scrape: "true" + prometheus.io/path: /q/metrics + prometheus.io/port: "8080" + prometheus.io/scheme: http + labels: + app: policyservice + app.kubernetes.io/name: policyservice + spec: + containers: + - env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: MONITORING_SERVICE_HOST + value: monitoringservice + - name: CONTEXT_SERVICE_HOST + value: contextservice + - name: SERVICE_SERVICE_HOST + value: serviceservice + image: labs.etsi.org:5050/tfs/controller/policy:0.1.0 + imagePullPolicy: Always + livenessProbe: + failureThreshold: 3 + httpGet: + path: /q/health/live + port: 8080 + scheme: HTTP + initialDelaySeconds: 2 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 10 + name: policyservice + ports: + - containerPort: 6060 + name: grpc-server + protocol: TCP + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + failureThreshold: 3 + httpGet: + path: /q/health/ready + port: 8080 + scheme: HTTP + initialDelaySeconds: 2 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 10 + resources: + limits: + cpu: 500m + memory: 2048Mi + requests: + cpu: 50m + memory: 512Mi -- GitLab From 7697bae0fb3d34846c6d7a5512c0aa6768cea052 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Mon, 12 Feb 2024 12:17:16 +0200 Subject: [PATCH 7/7] refactor: add monitoring service object on tests for warning correction even if we don't use them. --- .../src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java | 2 ++ .../test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java | 3 +++ .../test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java | 3 +++ 3 files changed, 8 insertions(+) diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java index 3c4a1577b..7c7c6b1b5 100644 --- a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java @@ -42,6 +42,7 @@ import org.etsi.tfs.policy.model.PolicyRuleCondition; import org.etsi.tfs.policy.model.PolicyRuleDevice; import org.etsi.tfs.policy.model.PolicyRuleState; import org.etsi.tfs.policy.model.PolicyRuleStateEnum; +import org.etsi.tfs.policy.monitoring.MonitoringService; import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue; import org.etsi.tfs.policy.monitoring.model.KpiValue; import org.junit.jupiter.api.BeforeAll; @@ -57,6 +58,7 @@ class PolicyAddDeviceTest { @InjectMock ContextService contextService; + @InjectMock MonitoringService monitoringService; static PolicyRuleBasic policyRuleBasic; static PolicyRuleDevice policyRuleDevice; diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java index a62c5dd3d..56e686bf6 100644 --- a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java @@ -46,6 +46,7 @@ import org.etsi.tfs.policy.model.PolicyRuleState; import org.etsi.tfs.policy.model.PolicyRuleStateEnum; import org.etsi.tfs.policy.model.PolicyRuleType; import org.etsi.tfs.policy.model.PolicyRuleTypeService; +import org.etsi.tfs.policy.monitoring.MonitoringService; import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue; import org.etsi.tfs.policy.monitoring.model.KpiValue; import org.junit.jupiter.api.BeforeAll; @@ -58,6 +59,8 @@ class PolicyDeleteServiceTest { @Inject PolicyServiceImpl policyService; @InjectMock ContextService contextService; + @InjectMock MonitoringService monitoringService; + static PolicyRuleBasic policyRuleBasic; static PolicyRuleService policyRuleService; diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java index 0cc2d5a70..ac8757508 100644 --- a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java @@ -41,6 +41,7 @@ import org.etsi.tfs.policy.model.PolicyRuleCondition; import org.etsi.tfs.policy.model.PolicyRuleDevice; import org.etsi.tfs.policy.model.PolicyRuleState; import org.etsi.tfs.policy.model.PolicyRuleStateEnum; +import org.etsi.tfs.policy.monitoring.MonitoringService; import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue; import org.etsi.tfs.policy.monitoring.model.KpiValue; import org.junit.jupiter.api.BeforeAll; @@ -54,6 +55,8 @@ class PolicyUpdateDeviceTest { @InjectMock PolicyRuleConditionValidator policyRuleConditionValidator; + @InjectMock MonitoringService monitoringService; + static PolicyRuleBasic policyRuleBasic; static PolicyRuleDevice policyRuleDevice; -- GitLab