summaryrefslogtreecommitdiffstats
path: root/tutorials
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2023-12-18 17:57:33 +0000
committeradheli.tavares <adheli.tavares@est.tech>2023-12-19 13:00:57 +0000
commitef722a6ef6a64b69bf152c0187992f0ee91a2682 (patch)
treec721bb2967b2924fdd961a2552735b1651058935 /tutorials
parent84b2b25e91bfdda81239dea6eee000758c8c861b (diff)
Allow xacml-pdp to use kafka
Issue-ID: POLICY-4202 Change-Id: Idaff733d93cbfcb9a32731eb3b811e423942f834 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'tutorials')
-rw-r--r--tutorials/tutorial-xacml-application/src/main/docker/config/sim/simParameters.json15
-rw-r--r--tutorials/tutorial-xacml-application/src/main/docker/docker-compose.yml186
-rwxr-xr-xtutorials/tutorial-xacml-application/src/main/docker/run-tutorial.sh2
-rw-r--r--tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialApplication.java7
-rw-r--r--tutorials/tutorial-xacml-application/src/test/java/org/onap/policy/tutorial/tutorial/TutorialApplicationTest.java45
5 files changed, 118 insertions, 137 deletions
diff --git a/tutorials/tutorial-xacml-application/src/main/docker/config/sim/simParameters.json b/tutorials/tutorial-xacml-application/src/main/docker/config/sim/simParameters.json
deleted file mode 100644
index bd435201..00000000
--- a/tutorials/tutorial-xacml-application/src/main/docker/config/sim/simParameters.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "dmaapProvider": {
- "name": "DMaaP simulator",
- "topicSweepSec": 300
- },
- "restServers": [
- {
- "name": "DMaaP simulator",
- "providerClass": "org.onap.policy.models.sim.dmaap.rest.DmaapSimRestControllerV1",
- "host": "0.0.0.0",
- "port": 3904,
- "https": false
- }
- ]
-} \ No newline at end of file
diff --git a/tutorials/tutorial-xacml-application/src/main/docker/docker-compose.yml b/tutorials/tutorial-xacml-application/src/main/docker/docker-compose.yml
index f0b153f9..48d246be 100644
--- a/tutorials/tutorial-xacml-application/src/main/docker/docker-compose.yml
+++ b/tutorials/tutorial-xacml-application/src/main/docker/docker-compose.yml
@@ -16,90 +16,104 @@
#
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=========================================================
-version: '2'
+version: '3'
services:
- mariadb:
- image: ${CONTAINER_LOCATION}mariadb:${POLICY_MARIADB_VER}
- container_name: mariadb
- hostname: mariadb
- command: ['--lower-case-table-names=1', '--wait_timeout=28800']
- env_file: config/db/db.conf
- volumes:
- - ./config/db:/docker-entrypoint-initdb.d
- expose:
- - 3306
- message-router:
- image: ${CONTAINER_LOCATION}onap/policy-models-simulator:${POLICY_MODELS_VERSION}
- container_name: dmaap-simulator
- hostname: dmaap-simulator
- volumes:
- - ./config/sim:/opt/app/policy/simulators/etc/mounted:ro
- ports:
- - "3904:3904"
- expose:
- - 3904
- api:
- image: ${CONTAINER_LOCATION}onap/policy-api:${POLICY_API_VERSION}
- container_name: policy-api
- depends_on:
- - mariadb
- hostname: policy-api
- ports:
- - "6767:6969"
- expose:
- - 6767
- pap:
- image: ${CONTAINER_LOCATION}onap/policy-pap:${POLICY_PAP_VERSION}
- container_name: policy-pap
- depends_on:
- - mariadb
- - message-router
- - api
- hostname: policy-pap
- ports:
- - "6868:6969"
- expose:
- - 6868
- xacml-pdp:
- image: onap/policy-xacml-tutorial:${POLICY_XACML_TUTORIAL_VERSION}
- container_name: policy-xacml-pdp
- depends_on:
- - mariadb
- - message-router
- - api
- - pap
- hostname: policy-xacml-pdp
- ports:
- - "6969:6969"
- expose:
- - 6969
- start_dependencies:
- image: dadarek/wait-for-dependencies
- environment:
- TIMEOUT_LENGTH: 60
- container_name: policy-wait
- depends_on:
- - mariadb
- - message-router
- hostname: policy-wait
- command:
- mariadb:3306
- message-router:3904
- start_all:
- image: dadarek/wait-for-dependencies
- environment:
- TIMEOUT_LENGTH: 60
- container_name: policy-wait-all
- depends_on:
- - mariadb
- - message-router
- - api
- - pap
- - xacml-pdp
- hostname: policy-wait-all
- command:
- mariadb:3306
- message-router:3904
- api:6969
- pap:6969
- xacml-pdp:6969
+ mariadb:
+ image: ${CONTAINER_LOCATION}mariadb:${POLICY_MARIADB_VER}
+ container_name: mariadb
+ hostname: mariadb
+ command: [ '--lower-case-table-names=1', '--wait_timeout=28800' ]
+ env_file: config/db/db.conf
+ volumes:
+ - ./config/db:/docker-entrypoint-initdb.d
+ expose:
+ - 3306
+ api:
+ image: ${CONTAINER_LOCATION}onap/policy-api:${POLICY_API_VERSION}
+ container_name: policy-api
+ depends_on:
+ - mariadb
+ hostname: policy-api
+ ports:
+ - "6767:6969"
+ expose:
+ - 6767
+ pap:
+ image: ${CONTAINER_LOCATION}onap/policy-pap:${POLICY_PAP_VERSION}
+ container_name: policy-pap
+ depends_on:
+ - mariadb
+ - kafka
+ - api
+ hostname: policy-pap
+ ports:
+ - "6868:6969"
+ expose:
+ - 6868
+ xacml-pdp:
+ image: onap/policy-xacml-tutorial:${POLICY_XACML_TUTORIAL_VERSION}
+ container_name: policy-xacml-pdp
+ depends_on:
+ - mariadb
+ - pap
+ hostname: policy-xacml-pdp
+ ports:
+ - "6969:6969"
+ expose:
+ - 6969
+ start_dependencies:
+ image: dadarek/wait-for-dependencies
+ environment:
+ TIMEOUT_LENGTH: 60
+ container_name: policy-wait
+ depends_on:
+ - mariadb
+ - kafka
+ hostname: policy-wait
+ command:
+ mariadb:3306
+ kafka:9092
+ start_all:
+ image: dadarek/wait-for-dependencies
+ environment:
+ TIMEOUT_LENGTH: 60
+ container_name: policy-wait-all
+ depends_on:
+ - mariadb
+ - kafka
+ - api
+ - pap
+ - xacml-pdp
+ hostname: policy-wait-all
+ command:
+ mariadb:3306
+ kafka:9092
+ api:6969
+ pap:6969
+ xacml-pdp:6969
+ zookeeper:
+ image: confluentinc/cp-zookeeper:latest
+ environment:
+ ZOOKEEPER_CLIENT_PORT: 2181
+ ZOOKEEPER_TICK_TIME: 2000
+ ports:
+ - "2181:2181"
+ kafka:
+ image: confluentinc/cp-kafka:latest
+ container_name: kafka
+ depends_on:
+ - zookeeper
+ networks:
+ default:
+ aliases:
+ - message-router
+ ports:
+ - "29092:29092"
+ - "9092:9092"
+ environment:
+ KAFKA_BROKER_ID: 1
+ KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
+ KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
+ KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
+ KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
+ KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
diff --git a/tutorials/tutorial-xacml-application/src/main/docker/run-tutorial.sh b/tutorials/tutorial-xacml-application/src/main/docker/run-tutorial.sh
index 1576ad0e..82750c41 100755
--- a/tutorials/tutorial-xacml-application/src/main/docker/run-tutorial.sh
+++ b/tutorials/tutorial-xacml-application/src/main/docker/run-tutorial.sh
@@ -35,7 +35,7 @@ POLICY_XACML_TUTORIAL_VERSION=$(
if [ -z "$POLICY_XACML_TUTORIAL_VERSION" ]
then
- echo "Look up of the XACML tutorial version failed, have you built the tutorial docker iamge?"
+ echo "Look up of the XACML tutorial version failed, have you built the tutorial docker image?"
exit 1
else
export POLICY_XACML_TUTORIAL_VERSION
diff --git a/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialApplication.java b/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialApplication.java
index 5d486c42..7d978dd6 100644
--- a/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialApplication.java
+++ b/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialApplication.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021, 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
package org.onap.policy.tutorial.tutorial;
-import java.util.Arrays;
import java.util.List;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
@@ -38,12 +37,12 @@ public class TutorialApplication extends StdXacmlApplicationServiceProvider {
@Override
public List<String> actionDecisionsSupported() {
- return Arrays.asList("authorize");
+ return List.of("authorize");
}
@Override
public synchronized List<ToscaConceptIdentifier> supportedPolicyTypes() {
- return Arrays.asList(supportedPolicyType);
+ return List.of(supportedPolicyType);
}
@Override
diff --git a/tutorials/tutorial-xacml-application/src/test/java/org/onap/policy/tutorial/tutorial/TutorialApplicationTest.java b/tutorials/tutorial-xacml-application/src/test/java/org/onap/policy/tutorial/tutorial/TutorialApplicationTest.java
index a6f0e944..ee089195 100644
--- a/tutorials/tutorial-xacml-application/src/test/java/org/onap/policy/tutorial/tutorial/TutorialApplicationTest.java
+++ b/tutorials/tutorial-xacml-application/src/test/java/org/onap/policy/tutorial/tutorial/TutorialApplicationTest.java
@@ -38,7 +38,6 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.TextFileUtils;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
-import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.onap.policy.pdp.xacml.xacmltest.TestUtils;
@@ -47,27 +46,26 @@ import org.slf4j.LoggerFactory;
public class TutorialApplicationTest {
private static final Logger LOGGER = LoggerFactory.getLogger(TutorialApplicationTest.class);
- private static Properties properties = new Properties();
- private static File propertiesFile;
+ private static final Properties properties = new Properties();
private static XacmlApplicationServiceProvider service;
- private static StandardCoder gson = new StandardCoder();
+ private static final StandardCoder gson = new StandardCoder();
@ClassRule
public static final TemporaryFolder policyFolder = new TemporaryFolder();
/**
- * setup the tests.
+ * set up the tests.
*
* @throws Exception Should not have exceptions thrown.
*/
@BeforeClass
public static void setup() throws Exception {
//
- // Setup our temporary folder
+ // Set up our temporary folder
//
- XacmlPolicyUtils.FileCreator myCreator = (String filename) -> policyFolder.newFile(filename);
- propertiesFile = XacmlPolicyUtils.copyXacmlPropertiesContents("src/test/resources/xacml.properties", properties,
- myCreator);
+ XacmlPolicyUtils.FileCreator myCreator = policyFolder::newFile;
+ File propertiesFile = XacmlPolicyUtils
+ .copyXacmlPropertiesContents("src/test/resources/xacml.properties", properties, myCreator);
//
// Load XacmlApplicationServiceProvider service
//
@@ -96,7 +94,7 @@ public class TutorialApplicationTest {
}
@Test
- public void testSingleDecision() throws CoderException, XacmlApplicationException, IOException {
+ public void testSingleDecision() throws CoderException, IOException {
//
// Load a Decision request
//
@@ -116,7 +114,7 @@ public class TutorialApplicationTest {
assertThat(decision.getLeft().getAttributes()).isNotNull().hasSize(1)
.containsKey(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE.stringValue());
//
- // This should be a deny
+ // This should be a "deny"
//
decisionRequest.getResource().put("user", "audit");
LOGGER.info("{}", gson.encode(decisionRequest, true));
@@ -132,7 +130,7 @@ public class TutorialApplicationTest {
@Test
- public void testMultiDecision() throws CoderException, XacmlApplicationException, IOException {
+ public void testMultiDecision() throws CoderException, IOException {
//
// Load a Decision request
//
@@ -156,7 +154,7 @@ public class TutorialApplicationTest {
assertThat(decision.getLeft()).isInstanceOf(TutorialResponse.class);
TutorialResponse tutorialResponse = (TutorialResponse) decision.getLeft();
assertThat(tutorialResponse.getPermissions()).hasSize(7);
- tutorialResponse.getPermissions().forEach(p -> checkPermission(p));
+ tutorialResponse.getPermissions().forEach(this::checkPermission);
}
private void checkPermission(TutorialResponsePermission permission) {
@@ -164,28 +162,13 @@ public class TutorialApplicationTest {
Object resourceAttributes = permission.getAttributes().get(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE.stringValue());
assertThat(resourceAttributes).isNotNull().isInstanceOf(Map.class);
@SuppressWarnings("unchecked")
- String multiId = ((Map<String, String>) resourceAttributes).get("urn:org:onap:tutorial-multi-id").toString();
+ String multiId = ((Map<String, String>) resourceAttributes).get("urn:org:onap:tutorial-multi-id");
assertThat(Integer.parseInt(multiId)).isBetween(1, 7);
switch (multiId) {
- case "1":
+ case "1", "2", "4":
assertThat(permission.getStatus()).isEqualTo("Permit");
return;
- case "2":
- assertThat(permission.getStatus()).isEqualTo("Permit");
- return;
- case "3":
- assertThat(permission.getStatus()).isEqualTo("Deny");
- return;
- case "4":
- assertThat(permission.getStatus()).isEqualTo("Permit");
- return;
- case "5":
- assertThat(permission.getStatus()).isEqualTo("Deny");
- return;
- case "6":
- assertThat(permission.getStatus()).isEqualTo("Deny");
- return;
- case "7":
+ case "3", "5", "6", "7":
assertThat(permission.getStatus()).isEqualTo("Deny");
return;
default: