Skip to content
Snippets Groups Projects
Commit e31aec70 authored by famelis's avatar famelis
Browse files

feat: move policy component from policy_dev

parent fc765453
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!122Minor fixes
Showing
with 327 additions and 427 deletions
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -79,21 +79,21 @@ unit_test policy:
- manifests/${IMAGE_NAME_POLICY}service.yaml
- .gitlab-ci.yml
## Deployment of policy service in Kubernetes Cluster
#deploy policy:
# stage: deploy
# needs:
# - build policy
# - unit_test policy
# script:
# - kubectl version
# - kubectl get all
# - kubectl delete --ignore-not-found=true -f "manifests/policyservice.yaml"
# - kubectl apply -f "manifests/policyservice.yaml"
# - kubectl delete pods --selector app=policyservice
# - kubectl get all
# rules:
# - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
# when: manual
# - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
# when: manual
\ No newline at end of file
# Deployment of policy service in Kubernetes Cluster
deploy policy:
stage: deploy
needs:
- build policy
- unit_test policy
script:
- kubectl version
- kubectl get all
- kubectl delete --ignore-not-found=true -f "manifests/policyservice.yaml"
- kubectl apply -f "manifests/policyservice.yaml"
- kubectl delete pods --selector app=policyservice
- kubectl get all
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
when: manual
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
when: manual
\ No newline at end of file
File mode changed from 100644 to 100755
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -51,6 +51,7 @@ RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \
&& chmod 540 /deployments/run-java.sh \
&& echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/conf/security/java.security
ENV QUARKUS_LAUNCH_DEVMODE="true"
# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size.
ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
# We make four distinct layers so if there are application changes the library layers can be re-used
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -21,6 +21,7 @@ import eu.teraflow.policy.context.model.Device;
import eu.teraflow.policy.context.model.EndPointId;
import eu.teraflow.policy.context.model.Service;
import eu.teraflow.policy.context.model.ServiceId;
import eu.teraflow.policy.model.PolicyRuleService;
import io.smallrye.mutiny.Uni;
import java.util.ArrayList;
import java.util.List;
......@@ -42,73 +43,44 @@ public class PolicyRuleConditionValidator {
this.contextService = contextService;
}
public Uni<Boolean> validateDeviceId(String deviceId) {
final var isDeviceIdValid = isDeviceIdValid(deviceId);
isDeviceIdValid
.subscribe()
.with(
deviceIdIdBooleanValue -> {
if (Boolean.FALSE.equals(deviceIdIdBooleanValue)) {
LOGGER.errorf(INVALID_MESSAGE, deviceId);
}
LOGGER.infof(VALID_MESSAGE, deviceId);
});
return isDeviceIdValid;
}
public Uni<Boolean> validateServiceId(ServiceId serviceId) {
final var isServiceIdValid = isServiceIdValid(serviceId);
isServiceIdValid
.subscribe()
.with(
serviceIdBooleanValue -> {
if (Boolean.FALSE.equals(serviceIdBooleanValue)) {
LOGGER.errorf(INVALID_MESSAGE, serviceId);
}
});
return isServiceIdValid;
}
public Uni<Boolean> validateUpdatedPolicyRuleId(String updatedPolicyRuleId) {
final var isUpdatedPolicyRuleIdValid = isUpdatedPolicyRuleIdValid(updatedPolicyRuleId);
isUpdatedPolicyRuleIdValid
.subscribe()
.with(
serviceIdBooleanValue -> {
if (Boolean.FALSE.equals(serviceIdBooleanValue)) {
LOGGER.errorf(INVALID_MESSAGE, updatedPolicyRuleId);
}
});
return isUpdatedPolicyRuleIdValid;
}
private Uni<Boolean> isDeviceIdValid(String deviceId) {
public Uni<Boolean> isDeviceIdValid(String deviceId) {
return contextService
.getDevice(deviceId)
.onFailure()
.recoverWithItem((Device) null)
.onItem()
.transform(device -> checkIfDeviceIdExists(device, deviceId));
}
private boolean checkIfDeviceIdExists(Device device, String deviceId) {
final var deviceDeviceId = device.getDeviceId();
if (device == null) {
return false;
}
final var deviceDeviceId = device.getDeviceId();
return deviceDeviceId.equals(deviceId);
}
private Uni<Boolean> isServiceIdValid(ServiceId serviceId) {
public Uni<Boolean> isServiceIdValid(ServiceId serviceId, List<String> deviceIds) {
return contextService
.getService(serviceId)
.onFailure()
.recoverWithItem((Service) null)
.onItem()
.transform(service -> checkIfServiceIdExists(service, serviceId));
.transform(service -> checkIfServiceIsValid(service, serviceId, deviceIds));
}
private boolean checkIfServiceIsValid(
Service service, ServiceId serviceId, List<String> deviceIds) {
return (checkIfServiceIdExists(service, serviceId)
&& checkIfServicesDeviceIdsExist(service, deviceIds));
}
private boolean checkIfServiceIdExists(Service service, ServiceId serviceId) {
if (service == null) {
return false;
}
final var serviceServiceIdServiceId = service.getServiceId();
final var serviceServiceIdContextId = serviceServiceIdServiceId.getContextId();
final var serviceServiceIdId = serviceServiceIdServiceId.getId();
......@@ -117,14 +89,11 @@ public class PolicyRuleConditionValidator {
&& serviceServiceIdId.equals(serviceId.getId());
}
public Uni<Boolean> isServicesDeviceIdsValid(ServiceId serviceId, List<String> deviceIds) {
return contextService
.getService(serviceId)
.onItem()
.transform(service -> checkIfServicesDeviceIdsExist(service, deviceIds));
}
private boolean checkIfServicesDeviceIdsExist(Service service, List<String> deviceIds) {
if (deviceIds.isEmpty()) {
return true;
}
List<String> serviceDeviceIds = new ArrayList<>();
for (EndPointId serviceEndPointId : service.getServiceEndPointIds()) {
serviceDeviceIds.add(serviceEndPointId.getDeviceId());
......@@ -133,7 +102,7 @@ public class PolicyRuleConditionValidator {
return deviceIds.containsAll(serviceDeviceIds);
}
private Uni<Boolean> isUpdatedPolicyRuleIdValid(String updatedPolicyRuleId) {
public Uni<Boolean> isUpdatedPolicyRuleIdValid(String updatedPolicyRuleId) {
return contextService
.getPolicyRule(updatedPolicyRuleId)
.onItem()
......@@ -146,4 +115,25 @@ public class PolicyRuleConditionValidator {
.ifNull()
.continueWith(false);
}
public Uni<Boolean> isPolicyRuleServiceValid(String updatedPolicyRuleId, ServiceId serviceId) {
return contextService
.getPolicyRule(updatedPolicyRuleId)
.onItem()
.ifNotNull()
.transform(
policyRule -> {
var policyRuleService =
(PolicyRuleService) policyRule.getPolicyRuleType().getPolicyRuleType();
if (policyRuleService.getServiceId().getId().equals(serviceId.getId())) {
return true;
}
return false;
})
.onItem()
.ifNull()
.continueWith(false)
.onFailure()
.recoverWithItem(false);
}
}
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
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