diff options
Diffstat (limited to 'controlloop')
25 files changed, 908 insertions, 267 deletions
diff --git a/controlloop/build/docker-cl b/controlloop/build/docker-cl index 659c2bad9..6c1d65fbf 100644 --- a/controlloop/build/docker-cl +++ b/controlloop/build/docker-cl @@ -45,7 +45,12 @@ function build { tags="${tags} --tag ${tag}" done - (set -x; docker build ${BUILD_ARGS} ${tags} ${IMAGE_PATH}) + ( + set -x; + docker pull "${DOCKER_PULL_REPOSITORY}"/onap/policy-drools:"${MAJOR_MINOR_VERSION}"-latest + docker tag "${DOCKER_PULL_REPOSITORY}"/onap/policy-drools:"${MAJOR_MINOR_VERSION}"-latest onap/policy-drools:"${MAJOR_MINOR_VERSION}"-latest + docker build ${BUILD_ARGS} ${tags} ${IMAGE_PATH} + ) if [[ $? != 0 ]]; then echo -e "\nERROR: docker build\n" @@ -131,7 +136,7 @@ function run { ( set -x docker run --rm ${debugEnv} -it -v "${volume}":/tmp/policy-install/config -p 9696:9696 \ - --name pdpd-cl onap/policy-pdpd-cl ${cmd} + --name pdpd-cl onap/"${IMAGE}" ${cmd} ) return $? @@ -153,7 +158,8 @@ if [[ ! -f "${VERSION_PATH}" ]]; then fi fi -DOCKER_REPOSITORY="nexus3.onap.org:10003" +DOCKER_PULL_REPOSITORY="nexus3.onap.org:10001" +DOCKER_PUSH_REPOSITORY="nexus3.onap.org:10003" IMAGE=policy-pdpd-cl IMAGE_PATH="controlloop/packages/docker-controlloop/target/${IMAGE}" @@ -186,17 +192,17 @@ echo -e "BUILD INFO:" echo -e "\timage: ${IMAGE}" echo -e "\timage-path: ${IMAGE_PATH}" echo -e "\timage: ${IMAGE}" -echo -e "\tregistry: ${DOCKER_REPOSITORY}" +echo -e "\tregistry: ${DOCKER_PUSH_REPOSITORY}" echo -e "\tpatch: ${VERSION}" echo -e "\tversion: ${MAJOR_MINOR_VERSION}" echo -e "\ttimestamp: ${TIMESTAMP}" echo TAG_LATEST="onap/${IMAGE}:latest" -TAG_REPO_LATEST="${DOCKER_REPOSITORY}/onap/${IMAGE}:latest" -TAG_REPO_VERSION_LATEST="${DOCKER_REPOSITORY}/onap/${IMAGE}:${MAJOR_MINOR_VERSION}-latest" -TAG_REPO_VERSION_TIMESTAMP="${DOCKER_REPOSITORY}/onap/${IMAGE}:${VERSION}-${TIMESTAMP}Z" -TAG_REPO_VERSION_STAGING_TIMESTAMP="${DOCKER_REPOSITORY}/onap/${IMAGE}:${VERSION}-STAGING-${TIMESTAMP}Z" +TAG_REPO_LATEST="${DOCKER_PUSH_REPOSITORY}/onap/${IMAGE}:latest" +TAG_REPO_VERSION_LATEST="${DOCKER_PUSH_REPOSITORY}/onap/${IMAGE}:${MAJOR_MINOR_VERSION}-latest" +TAG_REPO_VERSION_TIMESTAMP="${DOCKER_PUSH_REPOSITORY}/onap/${IMAGE}:${VERSION}-${TIMESTAMP}Z" +TAG_REPO_VERSION_STAGING_TIMESTAMP="${DOCKER_PUSH_REPOSITORY}/onap/${IMAGE}:${VERSION}-STAGING-${TIMESTAMP}Z" VERIFY_BUILD_TAGS="${TAG_LATEST} ${TAG_REPO_VERSION_LATEST} ${TAG_REPO_VERSION_TIMESTAMP}" diff --git a/controlloop/common/coordination/pom.xml b/controlloop/common/coordination/pom.xml new file mode 100644 index 000000000..1c6e44d41 --- /dev/null +++ b/controlloop/common/coordination/pom.xml @@ -0,0 +1,89 @@ +<!-- + ============LICENSE_START======================================================= + drools-applications + ================================================================================ + Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.drools-applications.controlloop.common</groupId> + <artifactId>common</artifactId> + <version>1.4.0-SNAPSHOT</version> + </parent> + + <artifactId>coordination</artifactId> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.drools-pdp</groupId> + <artifactId>policy-management</artifactId> + <version>${version.policy.drools-pdp}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> +</dependency> + </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-checkstyle-plugin</artifactId> + <executions> + <execution> + <id>onap-java-style</id> + <goals> + <goal>check</goal> + </goals> + <phase>process-sources</phase> + <configuration> + <!-- Use Google Java Style Guide: + https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml + with minor changes --> + <configLocation>onap-checkstyle/onap-java-style.xml</configLocation> + <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory --> + <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> + <includeResources>true</includeResources> + <includeTestSourceDirectory>true</includeTestSourceDirectory> + <includeTestResources>true</includeTestResources> + <excludes> + </excludes> + <consoleOutput>true</consoleOutput> + <failsOnViolation>true</failsOnViolation> + <violationSeverity>warning</violationSeverity> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.onap.oparent</groupId> + <artifactId>checkstyle</artifactId> + <version>${oparent.version}</version> + <scope>compile</scope> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> +</project> diff --git a/controlloop/common/coordination/src/main/java/org/onap/policy/coordination/CoordinationDirective.java b/controlloop/common/coordination/src/main/java/org/onap/policy/coordination/CoordinationDirective.java new file mode 100644 index 000000000..6ba4ca478 --- /dev/null +++ b/controlloop/common/coordination/src/main/java/org/onap/policy/coordination/CoordinationDirective.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * guard + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.coordination; + +import java.util.List; + +public class CoordinationDirective { + + private List<String> controlLoop; + private String coordinationFunction; + + public List<String> getControlLoop() { + return controlLoop; + } + + /** + * gets the ith control loop. + * + * @param index the control loop's index + * @return the CoordinationDirective's string representation + */ + public String getControlLoop(int index) { + return controlLoop.get(index); + } + + public void setControlLoop(List<String> controlLoop) { + this.controlLoop = controlLoop; + } + + public String getCoordinationFunction() { + return coordinationFunction; + } + + public void setCoordinationFunction(String coordinationFunction) { + this.coordinationFunction = coordinationFunction; + } + + /** + * toString. + * + * @return the CoordinationDirective's string representation + */ + public String toString() { + return "CoordinationDirective[ " + + String.join(" / ", controlLoop) + + " / " + coordinationFunction + "]"; + } + +} diff --git a/controlloop/common/coordination/src/main/java/org/onap/policy/coordination/Util.java b/controlloop/common/coordination/src/main/java/org/onap/policy/coordination/Util.java new file mode 100644 index 000000000..d76684093 --- /dev/null +++ b/controlloop/common/coordination/src/main/java/org/onap/policy/coordination/Util.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.coordination; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; + + +public final class Util { + + private static final Logger logger = LoggerFactory.getLogger(Util.class); + + /** + * Load YAML coordination directive. + * + * @param directiveFilename yaml directive file to load + * @return the CoordinationDirective + */ + public static CoordinationDirective loadCoordinationDirectiveFromFile(String directiveFilename) { + try (InputStream is = new FileInputStream(new File(directiveFilename))) { + String contents = IOUtils.toString(is, StandardCharsets.UTF_8); + // + // Read the yaml into our Java Object + // + Yaml yaml = new Yaml(new Constructor(CoordinationDirective.class)); + Object obj = yaml.load(contents); + + logger.debug(contents); + + return (CoordinationDirective) obj; + } catch (IOException e) { + logger.error("Error while loading YAML coordination directive", e); + } + return null; + } + + /** + * Generate Xacml rule implementing specified CoordinationDirective. + * + * @param cd the CoordinationDirective + * @param protoDir the directory containing Xacml implementation prototypes + * @return the generated Xacml policy + */ + public static String generateXacmlFromCoordinationDirective(CoordinationDirective cd, + String protoDir) { + /* + * Determine file names + */ + String xacmlProtoFilename = protoDir + File.separator + cd.getCoordinationFunction() + ".xml"; + logger.debug("xacmlProtoFilename={}", xacmlProtoFilename); + /* + * Values to be used for placeholders + */ + final String uniqueId = UUID.randomUUID().toString(); + final String cLOne = cd.getControlLoop(0); + final String cLTwo = cd.getControlLoop(1); + /* + * Replace prototype placeholders with appropriate values + */ + String xacmlPolicy = null; + try (Stream<String> stream = Files.lines(Paths.get(xacmlProtoFilename))) { + xacmlPolicy = stream.map(s -> s.replaceAll("UNIQUE_ID", uniqueId)) + .map(s -> s.replaceAll("CONTROL_LOOP_ONE", cLOne)) + .map(s -> s.replaceAll("CONTROL_LOOP_TWO", cLTwo)) + .collect(Collectors.joining(System.lineSeparator())); + } catch (IOException e) { + logger.error("Error while generating XACML policy for coordination directive", e); + } + return xacmlPolicy; + } + +} diff --git a/controlloop/common/coordination/src/test/java/org/onap/policy/coordination/CoordinationDirectiveTest.java b/controlloop/common/coordination/src/test/java/org/onap/policy/coordination/CoordinationDirectiveTest.java new file mode 100644 index 000000000..30606d1fd --- /dev/null +++ b/controlloop/common/coordination/src/test/java/org/onap/policy/coordination/CoordinationDirectiveTest.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.coordination; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.Arrays; +import org.assertj.core.api.Assertions; +import org.junit.Test; + +public class CoordinationDirectiveTest { + + @Test + public void test() { + + CoordinationDirective cd1 = new CoordinationDirective(); + + assertNotNull(cd1); + + assertNull(cd1.getControlLoop()); + assertNull(cd1.getCoordinationFunction()); + + cd1.setControlLoop(Arrays.asList("cl1", "cl2")); + cd1.setCoordinationFunction("firstBlocksSecond"); + + assertNotNull(cd1.getControlLoop()); + assertNotNull(cd1.getControlLoop(0)); + assertNotNull(cd1.getControlLoop(1)); + assertThatThrownBy(() -> { + cd1.getControlLoop(2); + }).isInstanceOf(IndexOutOfBoundsException.class); + assertNotNull(cd1.getCoordinationFunction()); + } +} diff --git a/controlloop/common/coordination/src/test/java/org/onap/policy/coordination/UtilTest.java b/controlloop/common/coordination/src/test/java/org/onap/policy/coordination/UtilTest.java new file mode 100644 index 000000000..76ae3b41c --- /dev/null +++ b/controlloop/common/coordination/src/test/java/org/onap/policy/coordination/UtilTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.coordination; + +import static org.assertj.core.api.Assertions.assertThatNullPointerException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import org.junit.Test; + +public class UtilTest { + + @Test + public void test() { + + String filename = "src/test/resources/test_coordination_directive.yaml"; + CoordinationDirective cd1 = Util.loadCoordinationDirectiveFromFile(filename); + + assertNotNull(cd1); + + assertNotNull(cd1.getControlLoop(0)); + assertNotNull(cd1.getControlLoop(1)); + assertNotNull(cd1.getCoordinationFunction()); + + assertEquals("cl1", cd1.getControlLoop(0)); + assertEquals("cl2", cd1.getControlLoop(1)); + assertEquals("cf", cd1.getCoordinationFunction()); + + filename = "src/test/resources/non_existent_coordination_directive.yaml"; + CoordinationDirective cd2 = Util.loadCoordinationDirectiveFromFile(filename); + + assertNull(cd2); + + assertThatNullPointerException().isThrownBy(() -> { + Util.generateXacmlFromCoordinationDirective(cd2, ""); + }); + } +} diff --git a/controlloop/common/coordination/src/test/resources/test_coordination_directive.yaml b/controlloop/common/coordination/src/test/resources/test_coordination_directive.yaml new file mode 100644 index 000000000..ede643c90 --- /dev/null +++ b/controlloop/common/coordination/src/test/resources/test_coordination_directive.yaml @@ -0,0 +1,20 @@ +# Copyright 2019 AT&T Intellectual Property. All rights reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +!!org.onap.policy.coordination.CoordinationDirective + +controlLoop: +- cl1 +- cl2 +coordinationFunction: cf
\ No newline at end of file diff --git a/controlloop/common/feature-controlloop-amsterdam/src/main/feature/config/amsterdam-controller.properties b/controlloop/common/feature-controlloop-amsterdam/src/main/feature/config/amsterdam-controller.properties index d7dc0c1c0..b52b1f4eb 100644 --- a/controlloop/common/feature-controlloop-amsterdam/src/main/feature/config/amsterdam-controller.properties +++ b/controlloop/common/feature-controlloop-amsterdam/src/main/feature/config/amsterdam-controller.properties @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # ONAP # ================================================================================ -# Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,67 +20,52 @@ controller.name=amsterdam -dmaap.source.topics=${{DCAE_TOPIC}},APPC-CL,APPC-LCM-WRITE,SDNR-CL-RSP +dmaap.source.topics=DCAE_TOPIC,APPC-CL,APPC-LCM-WRITE,SDNR-CL-RSP -dmaap.source.topics.${{DCAE_TOPIC}}.servers=${{DCAE_SERVERS}} -dmaap.source.topics.${{DCAE_TOPIC}}.apiKey= -dmaap.source.topics.${{DCAE_TOPIC}}.apiSecret= -dmaap.source.topics.${{DCAE_TOPIC}}.consumerGroup=${{DCAE_CONSUMER_GROUP}} -dmaap.source.topics.${{DCAE_TOPIC}}.events=org.onap.policy.controlloop.VirtualControlLoopEvent -dmaap.source.topics.${{DCAE_TOPIC}}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=closedLoopEventStatus=.* -dmaap.source.topics.${{DCAE_TOPIC}}.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gson -dmaap.source.topics.${{DCAE_TOPIC}}.https=true +dmaap.source.topics.DCAE_TOPIC.effectiveTopic=${env:DCAE_TOPIC} +dmaap.source.topics.DCAE_TOPIC.servers=${env:DMAAP_SERVERS} +dmaap.source.topics.DCAE_TOPIC.consumerGroup=${env:DCAE_CONSUMER_GROUP} +dmaap.source.topics.DCAE_TOPIC.events=org.onap.policy.controlloop.VirtualControlLoopEvent +dmaap.source.topics.DCAE_TOPIC.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=[?($.closedLoopEventStatus =~ /.*/)] +dmaap.source.topics.DCAE_TOPIC.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gson +dmaap.source.topics.DCAE_TOPIC.https=true -dmaap.source.topics.APPC-CL.servers=${{DMAAP_SERVERS}} -dmaap.source.topics.APPC-CL.apiKey= -dmaap.source.topics.APPC-CL.apiSecret= +dmaap.source.topics.APPC-CL.servers=${env:DMAAP_SERVERS} dmaap.source.topics.APPC-CL.events=org.onap.policy.appc.Response -dmaap.source.topics.APPC-CL.events.org.onap.policy.appc.Response.filter=CommonHeader\=.*,Status\=.* +dmaap.source.topics.APPC-CL.events.org.onap.policy.appc.Response.filter=[?($.CommonHeader =~ /.*/ && $.Status =~ /.*/)] dmaap.source.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty dmaap.source.topics.APPC-CL.servers.https=true -dmaap.source.topics.APPC-LCM-WRITE.servers=${{DMAAP_SERVERS}} -dmaap.source.topics.APPC-LCM-WRITE.apiKey= -dmaap.source.topics.APPC-LCM-WRITE.apiSecret= +dmaap.source.topics.APPC-LCM-WRITE.servers=${env:DMAAP_SERVERS} dmaap.source.topics.APPC-LCM-WRITE.events=org.onap.policy.appclcm.LcmResponseWrapper -dmaap.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter=type\=response +dmaap.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter=[?($.type == 'response')] dmaap.source.topics.APPC-LCM-WRITE.events.custom.gson=org.onap.policy.appclcm.util.Serialization,gson dmaap.source.topics.APPC-LCM-WRITE.https=true -dmaap.source.topics.SDNR-CL-RSP.servers=${{DMAAP_SERVERS}} -dmaap.source.topics.SDNR-CL-RSP.apiKey= -dmaap.source.topics.SDNR-CL-RSP.apiSecret= +dmaap.source.topics.SDNR-CL-RSP.servers=${env:DMAAP_SERVERS} dmaap.source.topics.SDNR-CL-RSP.events=org.onap.policy.sdnr.PciResponseWrapper -dmaap.source.topics.SDNR-CL-RSP.events.org.onap.policy.sdnr.PciResponseWrapper.filter=type\=response +dmaap.source.topics.SDNR-CL-RSP.events.org.onap.policy.sdnr.PciResponseWrapper.filter=[?($.type == 'response')] dmaap.source.topics.SDNR-CL-RSP.events.custom.gson=org.onap.policy.sdnr.util.Serialization,gson dmaap.source.topics.SDNR-CL-RSP.https=true dmaap.sink.topics=APPC-CL,APPC-LCM-READ,POLICY-CL-MGT,SDNR-CL -dmaap.sink.topics.APPC-CL.servers=${{DMAAP_SERVERS}} -dmaap.sink.topics.APPC-CL.apiKey= -dmaap.sink.topics.APPC-CL.apiSecret= +dmaap.sink.topics.APPC-CL.servers=${env:DMAAP_SERVERS} dmaap.sink.topics.APPC-CL.events=org.onap.policy.appc.Request dmaap.sink.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty dmaap.sink.topics.APPC-CL.https=true -dmaap.sink.topics.APPC-LCM-READ.servers=${{DMAAP_SERVERS}} -dmaap.sink.topics.APPC-LCM-READ.apiKey= -dmaap.sink.topics.APPC-LCM-READ.apiSecret= +dmaap.sink.topics.APPC-LCM-READ.servers=${env:DMAAP_SERVERS} dmaap.sink.topics.APPC-LCM-READ.events=org.onap.policy.appclcm.LcmRequestWrapper dmaap.sink.topics.APPC-LCM-READ.events.custom.gson=org.onap.policy.appclcm.util.Serialization,gson dmaap.sink.topics.APPC-LCM-READ.https=true -dmaap.sink.topics.POLICY-CL-MGT.servers=${{DMAAP_SERVERS}} -dmaap.sink.topics.POLICY-CL-MGT.apiKey= -dmaap.sink.topics.POLICY-CL-MGT.apiSecret= +dmaap.sink.topics.POLICY-CL-MGT.servers=${env:DMAAP_SERVERS} dmaap.sink.topics.POLICY-CL-MGT.events=org.onap.policy.controlloop.VirtualControlLoopNotification dmaap.sink.topics.POLICY-CL-MGT.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty dmaap.sink.topics.POLICY-CL-MGT.https=true -dmaap.sink.topics.SDNR-CL.servers=${{DMAAP_SERVERS}} -dmaap.sink.topics.SDNR-CL.apiKey= -dmaap.sink.topics.SDNR-CL.apiSecret= +dmaap.sink.topics.SDNR-CL.servers=${env:DMAAP_SERVERS} dmaap.sink.topics.SDNR-CL.events=org.onap.policy.sdnr.PciRequestWrapper dmaap.sink.topics.SDNR-CL.events.custom.gson=org.onap.policy.sdnr.util.Serialization,gson dmaap.sink.topics.SDNR-CL.https=true diff --git a/controlloop/common/feature-controlloop-amsterdam/src/main/feature/config/logback-include-amsterdam.xml b/controlloop/common/feature-controlloop-amsterdam/src/main/feature/config/logback-include-amsterdam.xml new file mode 100644 index 000000000..780fbdb3a --- /dev/null +++ b/controlloop/common/feature-controlloop-amsterdam/src/main/feature/config/logback-include-amsterdam.xml @@ -0,0 +1,56 @@ +<!-- + ============LICENSE_START======================================================= + feature-controlloop-amsterdam + ================================================================================ + Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + --> + +<!-- + The logger configurations in this file are for each individual controller + to have their own network logger for topic traffic. This is an extension of + logback.xml or logback-eelf.xml. + + NOTE: Each logger MUST contain the same name as the control loop's controller. +--> +<included> + + <property name="logDir" value="${POLICY_LOGS}" /> + <property name="amsterdamLog" value="amsterdam-network" /> + <property name="networkPattern" value="[%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00, UTC}|%t]%m%n" /> + + <!-- Amsterdam Network Logging Properties --> + <appender name="AmsterdamOut" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDir}/${amsterdamLog}.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> + <fileNamePattern>${logDir}/${amsterdamLog}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern> + <maxFileSize>50MB</maxFileSize> + <maxHistory>30</maxHistory> + <totalSizeCap>10GB</totalSizeCap> + </rollingPolicy> + <encoder> + <pattern>${networkPattern}</pattern> + </encoder> + </appender> + + <appender name="AsyncAmsterdamOut" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="AmsterdamOut" /> + </appender> + + <logger name="amsterdam" level="INFO" additivity="false"> + <appender-ref ref="AsyncAmsterdamOut" /> + </logger> + +</included>
\ No newline at end of file diff --git a/controlloop/common/feature-controlloop-casablanca/src/main/feature/config/casablanca-controller.properties b/controlloop/common/feature-controlloop-casablanca/src/main/feature/config/casablanca-controller.properties index 3ec25f7a2..08482e001 100644 --- a/controlloop/common/feature-controlloop-casablanca/src/main/feature/config/casablanca-controller.properties +++ b/controlloop/common/feature-controlloop-casablanca/src/main/feature/config/casablanca-controller.properties @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # ONAP # ================================================================================ -# Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,59 +20,47 @@ controller.name=casablanca -dmaap.source.topics=${{PDPD_CONFIGURATION_TOPIC}},${{DCAE_TOPIC}},APPC-CL,APPC-LCM-WRITE,SDNR-CL-RSP +dmaap.source.topics=${env:PDPD_CONFIGURATION_TOPIC},${env:DCAE_TOPIC},APPC-CL,APPC-LCM-WRITE,SDNR-CL-RSP -dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.servers=${{PDPD_CONFIGURATION_SERVERS}} -dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.apiKey= -dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.apiSecret= -dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.events=org.onap.policy.controlloop.params.ControlLoopParams -dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.events.org.onap.policy.controlloop.params.ControlLoopParams.filter=closedLoopControlName=.*,controlLoopYaml=.* -dmaap.source.topics.${{PDPD_CONFIGURATION_TOPIC}}.https=true +dmaap.source.topics.PDPD-CONFIGURATION.effectiveTopic=${env:PDPD_CONFIGURATION_TOPIC} +dmaap.source.topics.PDPD-CONFIGURATION.servers=${env:PDPD_CONFIGURATION_SERVERS} +dmaap.source.topics.PDPD-CONFIGURATION.events=org.onap.policy.controlloop.params.ControlLoopParams +dmaap.source.topics.PDPD-CONFIGURATION.events.org.onap.policy.controlloop.params.ControlLoopParams.filter=[?($.closedLoopControlName =~ /.*/ && $.controlLoopYaml =~ /.*/)] +dmaap.source.topics.PDPD-CONFIGURATION.https=true -dmaap.source.topics.${{DCAE_TOPIC}}.servers=${{DCAE_SERVERS}} -dmaap.source.topics.${{DCAE_TOPIC}}.apiKey= -dmaap.source.topics.${{DCAE_TOPIC}}.apiSecret= -dmaap.source.topics.${{DCAE_TOPIC}}.consumerGroup=${{DCAE_CONSUMER_GROUP}} -dmaap.source.topics.${{DCAE_TOPIC}}.events=org.onap.policy.controlloop.VirtualControlLoopEvent -dmaap.source.topics.${{DCAE_TOPIC}}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=closedLoopEventStatus=.* -dmaap.source.topics.${{DCAE_TOPIC}}.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gson -dmaap.source.topics.${{DCAE_TOPIC}}.https=true +dmaap.source.topics.DCAE_TOPIC.effectiveTopic=${env:DCAE_TOPIC} +dmaap.source.topics.DCAE_TOPIC.servers=${env:DMAAP_SERVERS} +dmaap.source.topics.DCAE_TOPIC.consumerGroup=${env:DCAE_CONSUMER_GROUP} +dmaap.source.topics.DCAE_TOPIC.events=org.onap.policy.controlloop.VirtualControlLoopEvent +dmaap.source.topics.DCAE_TOPIC.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=[?($.closedLoopEventStatus =~ /.*/)] +dmaap.source.topics.DCAE_TOPIC.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gson +dmaap.source.topics.DCAE_TOPIC.https=true -dmaap.source.topics.APPC-CL.servers=${{DMAAP_SERVERS}} -dmaap.source.topics.APPC-CL.apiKey= -dmaap.source.topics.APPC-CL.apiSecret= +dmaap.source.topics.APPC-CL.servers=${env:DMAAP_SERVERS} dmaap.source.topics.APPC-CL.events=org.onap.policy.appc.Response -dmaap.source.topics.APPC-CL.events.org.onap.policy.appc.Response.filter=CommonHeader\=.*,Status\=.* +dmaap.source.topics.APPC-CL.events.org.onap.policy.appc.Response.filter=[?($.CommonHeader =~ /.*/ && $.Status =~ /.*/)] dmaap.source.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty dmaap.source.topics.APPC-CL.https=true -dmaap.source.topics.APPC-LCM-WRITE.servers=${{DMAAP_SERVERS}} -dmaap.source.topics.APPC-LCM-WRITE.apiKey= -dmaap.source.topics.APPC-LCM-WRITE.apiSecret= +dmaap.source.topics.APPC-LCM-WRITE.servers=${env:DMAAP_SERVERS} dmaap.source.topics.APPC-LCM-WRITE.events=org.onap.policy.appclcm.LcmResponseWrapper -dmaap.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter=type\=response +dmaap.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter=[?($.type == 'response')] dmaap.source.topics.APPC-LCM-WRITE.events.custom.gson=org.onap.policy.appclcm.util.Serialization,gson dmaap.source.topics.APPC-LCM-WRITE.https=true dmaap.sink.topics=APPC-CL,APPC-LCM-READ,POLICY-CL-MGT,SDNR-CL -dmaap.sink.topics.APPC-CL.servers=${{DMAAP_SERVERS}} -dmaap.sink.topics.APPC-CL.apiKey= -dmaap.sink.topics.APPC-CL.apiSecret= +dmaap.sink.topics.APPC-CL.servers=${env:DMAAP_SERVERS} dmaap.sink.topics.APPC-CL.events=org.onap.policy.appc.Request dmaap.sink.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty dmaap.sink.topics.APPC-CL.https=true -dmaap.sink.topics.APPC-LCM-READ.servers=${{DMAAP_SERVERS}} -dmaap.sink.topics.APPC-LCM-READ.apiKey= -dmaap.sink.topics.APPC-LCM-READ.apiSecret= +dmaap.sink.topics.APPC-LCM-READ.servers=${env:DMAAP_SERVERS} dmaap.sink.topics.APPC-LCM-READ.events=org.onap.policy.appclcm.LcmRequestWrapper dmaap.sink.topics.APPC-LCM-READ.events.custom.gson=org.onap.policy.appclcm.util.Serialization,gson dmaap.sink.topics.APPC-LCM-READ.https=true -dmaap.sink.topics.POLICY-CL-MGT.servers=${{DMAAP_SERVERS}} -dmaap.sink.topics.POLICY-CL-MGT.apiKey= -dmaap.sink.topics.POLICY-CL-MGT.apiSecret= +dmaap.sink.topics.POLICY-CL-MGT.servers=${env:DMAAP_SERVERS} dmaap.sink.topics.POLICY-CL-MGT.events=org.onap.policy.controlloop.VirtualControlLoopNotification dmaap.sink.topics.POLICY-CL-MGT.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty dmaap.sink.topics.POLICY-CL-MGT.https=true @@ -81,17 +69,13 @@ rules.groupId=${project.groupId} rules.artifactId=controller-casablanca rules.version=${project.version} -dmaap.sink.topics.SDNR-CL.servers=${{DMAAP_SERVERS}} -dmaap.sink.topics.SDNR-CL.apiKey= -dmaap.sink.topics.SDNR-CL.apiSecret= +dmaap.sink.topics.SDNR-CL.servers=${env:DMAAP_SERVERS} dmaap.sink.topics.SDNR-CL.events=org.onap.policy.sdnr.PciRequestWrapper dmaap.sink.topics.SDNR-CL.events.custom.gson=org.onap.policy.sdnr.util.Serialization,gson dmaap.sink.topics.SDNR-CL.https=true -dmaap.source.topics.SDNR-CL-RSP.servers=${{DMAAP_SERVERS}} -dmaap.source.topics.SDNR-CL-RSP.apiKey= -dmaap.source.topics.SDNR-CL-RSP.apiSecret= +dmaap.source.topics.SDNR-CL-RSP.servers=${env:DMAAP_SERVERS} dmaap.source.topics.SDNR-CL-RSP.events=org.onap.policy.sdnr.PciResponseWrapper -dmaap.source.topics.SDNR-CL-RSP.events.org.onap.policy.sdnr.PciResponseWrapper.filter=type\=response +dmaap.source.topics.SDNR-CL-RSP.events.org.onap.policy.sdnr.PciResponseWrapper.filter=[?($.type == 'response')] dmaap.source.topics.SDNR-CL-RSP.events.custom.gson=org.onap.policy.sdnr.util.Serialization,gson dmaap.source.topics.SDNR-CL-RSP.https=true diff --git a/controlloop/common/feature-controlloop-casablanca/src/main/feature/config/logback-include-casablanca.xml b/controlloop/common/feature-controlloop-casablanca/src/main/feature/config/logback-include-casablanca.xml new file mode 100644 index 000000000..292da7d27 --- /dev/null +++ b/controlloop/common/feature-controlloop-casablanca/src/main/feature/config/logback-include-casablanca.xml @@ -0,0 +1,56 @@ +<!-- + ============LICENSE_START======================================================= + feature-controlloop-casablanca + ================================================================================ + Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + --> + +<!-- + The logger configurations in this file are for each individual controller + to have their own network logger for topic traffic. This is an extension of + logback.xml or logback-eelf.xml. + + NOTE: Each logger MUST contain the same name as the control loop's controller. +--> +<included> + + <property name="logDir" value="${POLICY_LOGS}" /> + <property name="casablancaLog" value="casablanca-network" /> + <property name="networkPattern" value="[%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00, UTC}|%t]%m%n" /> + + <!-- Casablanca Network Logging Properties --> + <appender name="CasablancaOut" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDir}/${casablancaLog}.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> + <fileNamePattern>${logDir}/${casablancaLog}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern> + <maxFileSize>50MB</maxFileSize> + <maxHistory>30</maxHistory> + <totalSizeCap>10GB</totalSizeCap> + </rollingPolicy> + <encoder> + <pattern>${networkPattern}</pattern> + </encoder> + </appender> + + <appender name="AsyncCasablancaOut" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="CasablancaOut" /> + </appender> + + <logger name="casablanca" level="INFO" additivity="false"> + <appender-ref ref="AsyncCasablancaOut" /> + </logger> + +</included>
\ No newline at end of file diff --git a/controlloop/common/feature-controlloop-management/src/main/feature/config/controlloop.properties.environment b/controlloop/common/feature-controlloop-management/src/main/feature/config/controlloop.properties.environment index 2b63d51ad..e87df42c3 100644 --- a/controlloop/common/feature-controlloop-management/src/main/feature/config/controlloop.properties.environment +++ b/controlloop/common/feature-controlloop-management/src/main/feature/config/controlloop.properties.environment @@ -22,33 +22,33 @@ # directory, it will be automatically loaded by PDP-D, after being expanded # by installation scripts. -sql.db.host=${{SQL_HOST}} -sql.db.username=${{SQL_USER}} -sql.db.password=${{SQL_PASSWORD}} - -aai.url=${{AAI_URL}} -aai.username=${{AAI_USERNAME}} -aai.password=${{AAI_PASSWORD}} - -so.url=${{SO_URL}} -so.username=${{SO_USERNAME}} -so.password=${{SO_PASSWORD}} - -vfc.url=${{VFC_URL}} -vfc.username=${{VFC_USERNAME}} -vfc.password=${{VFC_PASSWORD}} - -pdpx.host=${{PDP_HOST}} -pdpx.username=${{PDP_USERNAME}} -pdpx.password=${{PDP_PASSWORD}} -pdpx.environment=${{PDP_ENVIRONMENT}} -pdpx.client.username=${{PDP_CLIENT_USERNAME}} -pdpx.client.password=${{PDP_CLIENT_PASSWORD}} - -guard.url=https://${{PDP_HOST}}:8081/pdp/api/getDecision -guard.jdbc.url=jdbc:mariadb://${{SQL_HOST}}:3306/onap_sdk +sql.db.host=${env:SQL_HOST} +sql.db.username=${env:SQL_USER} +sql.db.password=${env:SQL_PASSWORD} + +aai.url=${env:AAI_URL} +aai.username=${env:AAI_USERNAME} +aai.password=${env:AAI_PASSWORD} + +so.url=${env:SO_URL} +so.username=${env:SO_USERNAME} +so.password=${env:SO_PASSWORD} + +vfc.url=${env:VFC_URL} +vfc.username=${env:VFC_USERNAME} +vfc.password=${env:VFC_PASSWORD} + +pdpx.host=${env:PDP_HOST} +pdpx.username=${env:PDP_USERNAME} +pdpx.password=${env:PDP_PASSWORD} +pdpx.environment=${env:PDP_ENVIRONMENT} +pdpx.client.username=${env:PDP_CLIENT_USERNAME} +pdpx.client.password=${env:PDP_CLIENT_PASSWORD} + +guard.url=https://${env:PDP_HOST}:8081/pdp/api/getDecision +guard.jdbc.url=jdbc:mariadb://${env:SQL_HOST}:3306/onap_sdk guard.disabled=false -sdnc.url=${{SDNC_URL}} -sdnc.username=${{SDNC_USERNAME}} -sdnc.password=${{SDNC_PASSWORD}} +sdnc.url=${env:SDNC_URL} +sdnc.username=${env:SDNC_USERNAME} +sdnc.password=${env:SDNC_PASSWORD} diff --git a/controlloop/common/pom.xml b/controlloop/common/pom.xml index a0d003c9f..bab8de9d5 100644 --- a/controlloop/common/pom.xml +++ b/controlloop/common/pom.xml @@ -2,14 +2,14 @@ ============LICENSE_START======================================================= Drools PDP Application Common Models ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,7 +21,7 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <packaging>pom</packaging> - + <parent> <groupId>org.onap.policy.drools-applications.controlloop</groupId> <artifactId>controlloop</artifactId> @@ -34,6 +34,7 @@ <modules> <module>actors</module> <module>guard</module> + <module>coordination</module> <module>eventmanager</module> <module>model-impl</module> <module>policy-yaml</module> diff --git a/controlloop/packages/docker-controlloop/src/main/docker/Dockerfile b/controlloop/packages/docker-controlloop/src/main/docker/Dockerfile index 7bb2006cf..28631c7e6 100644 --- a/controlloop/packages/docker-controlloop/src/main/docker/Dockerfile +++ b/controlloop/packages/docker-controlloop/src/main/docker/Dockerfile @@ -3,5 +3,31 @@ FROM onap/policy-drools:1.4-SNAPSHOT-latest ARG BUILD_VERSION_APP_CL=${BUILD_VERSION_APP_CL} ENV BUILD_VERSION_APP_CL=${BUILD_VERSION_APP_CL} -ADD apps-controlloop.zip ./ -RUN unzip apps-controlloop.zip +SHELL ["/bin/bash", "-l", "-c"] + +COPY apps-controlloop.zip ./ +RUN unzip apps-controlloop.zip && \ + mkdir -p ${POLICY_HOME}/logs ${POLICY_HOME}/config ${HOME}/.m2 && \ + tar -C ${POLICY_HOME} -xvf base-${BUILD_VERSION}.tar.gz --no-same-owner && \ + tar -C ${POLICY_HOME} -xvf basex-controlloop-${BUILD_VERSION_APP_CL}.tar.gz --no-same-owner && \ + unzip policy-management-${BUILD_VERSION}.zip -d ${POLICY_HOME} && \ + echo "source ${POLICY_HOME}/etc/profile.d/env.sh" >> "${HOME}/.bashrc" && \ + sed -i -e 's!${{POLICY_HOME}}!'"${POLICY_HOME}!g" ${POLICY_HOME}/etc/profile.d/env.sh && \ + chmod 700 ${POLICY_HOME}/bin/* && \ + chmod 600 ${POLICY_HOME}/config/* && \ + rm -f ${POLICY_INSTALL}/*.conf + +RUN source ${POLICY_HOME}/etc/profile.d/env.sh && \ + mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get \ + --settings=${POLICY_HOME}/etc/m2/standalone-settings.xml \ + -DartifactId=feature-controlloop-management \ + -DgroupId=org.onap.policy.drools-applications.controlloop.common -Dversion=${BUILD_VERSION_APP_CL} && \ + ${POLICY_HOME}/bin/features install healthcheck distributed-locking && \ + ${POLICY_HOME}/bin/features install controlloop-utils controlloop-trans controlloop-management && \ + ${POLICY_HOME}/bin/features install controlloop-amsterdam controlloop-casablanca && \ + ${POLICY_HOME}/bin/features enable healthcheck distributed-locking && \ + ${POLICY_HOME}/bin/features enable controlloop-utils controlloop-trans controlloop-management && \ + ${POLICY_HOME}/bin/features enable controlloop-amsterdam controlloop-casablanca && \ + rm ${POLICY_INSTALL}/*.zip ${POLICY_INSTALL}/*.gz 2> /dev/null + +CMD bash -l diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties index 3e67dca51..4799c6567 100644 --- a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties +++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # archetype-closed-loop-demo-rules # ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ dmaap.source.topics.${dcaeTopic}.servers=${dcaeServers} dmaap.source.topics.${dcaeTopic}.apiKey= dmaap.source.topics.${dcaeTopic}.apiSecret= dmaap.source.topics.${dcaeTopic}.events=org.onap.policy.controlloop.VirtualControlLoopEvent -dmaap.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=closedLoopEventStatus=.* +dmaap.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=[?($.closedLoopEventStatus =~ /.*/)] dmaap.source.topics.${dcaeTopic}.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gson dmaap.source.topics.${dcaeTopic}.https=true @@ -34,7 +34,7 @@ dmaap.source.topics.APPC-CL.servers=${dmaapServers} dmaap.source.topics.APPC-CL.apiKey= dmaap.source.topics.APPC-CL.apiSecret= dmaap.source.topics.APPC-CL.events=org.onap.policy.appc.Response -dmaap.source.topics.APPC-CL.events.org.onap.policy.appc.Response.filter=CommonHeader\=.*,Status\=.* +dmaap.source.topics.APPC-CL.events.org.onap.policy.appc.Response.filter=[?($.CommonHeader =~ /.*/ && $.Status =~ /.*/)] dmaap.source.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty dmaap.source.topics.APPC-CL.https=true @@ -42,7 +42,7 @@ dmaap.source.topics.APPC-LCM-WRITE.servers=${dmaapServers} dmaap.source.topics.APPC-LCM-WRITE.apiKey= dmaap.source.topics.APPC-LCM-WRITE.apiSecret= dmaap.source.topics.APPC-LCM-WRITE.events=org.onap.policy.appclcm.LcmResponseWrapper -dmaap.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter=type\=response +dmaap.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter=[?($.type == 'response')] dmaap.source.topics.APPC-LCM-WRITE.events.custom.gson=org.onap.policy.appclcm.util.Serialization,gson dmaap.source.topics.APPC-LCM-WRITE.https=true @@ -50,7 +50,7 @@ dmaap.source.topics.SDNR-CL-RSP.servers=${dmaapServers} dmaap.source.topics.SDNR-CL-RSP.apiKey= dmaap.source.topics.SDNR-CL-RSP.apiSecret= dmaap.source.topics.SDNR-CL-RSP.events=org.onap.policy.sdnr.PciResponseWrapper -dmaap.source.topics.SDNR-CL-RSP.events.org.onap.policy.sdnr.PciResponseWrapper.filter=type\=response +dmaap.source.topics.SDNR-CL-RSP.events.org.onap.policy.sdnr.PciResponseWrapper.filter=[?($.type == 'response')] dmaap.source.topics.SDNR-CL-RSP.events.custom.gson=org.onap.policy.sdnr.util.Serialization,gson dmaap.source.topics.SDNR-CL-RSP.https=true diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json index 97506277e..8f6d39d88 100644 --- a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json +++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json @@ -5,22 +5,22 @@ "ueb.source.topics.${dcaeTopic}.servers": "${dcaeServers}", "ueb.source.topics.${dcaeTopic}.events": "org.onap.policy.controlloop.VirtualControlLoopEvent", - "ueb.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter": "closedLoopEventStatus=.*", + "ueb.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter": "[?($.closedLoopEventStatus =~ /.*/)]", "ueb.source.topics.${dcaeTopic}.events.custom.gson": "org.onap.policy.controlloop.util.Serialization,gson", "ueb.source.topics.APPC-CL.servers": "${dmaapServers}", "ueb.source.topics.APPC-CL.events": "org.onap.policy.appc.Response", - "ueb.source.topics.APPC-CL.events.org.onap.policy.appclcm.LcmResponseWrapper.filter": "CommonHeader=.*,Status=.*", + "ueb.source.topics.APPC-CL.events.org.onap.policy.appc.Response.filter": "[?($.CommonHeader =~ /.*/ && $.Status =~ /.*/)]", "ueb.source.topics.APPC-CL.events.custom.gson": "org.onap.policy.appc.util.Serialization,gsonPretty", "ueb.source.topics.APPC-LCM-WRITE.servers": "${dmaapServers}", "ueb.source.topics.APPC-LCM-WRITE.events": "org.onap.policy.appclcm.LcmResponseWrapper", - "ueb.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter": "type=response", + "ueb.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter": "[?($.type == 'response')]", "ueb.source.topics.APPC-LCM-WRITE.events.custom.gson": "org.onap.policy.appclcm.util.Serialization,gson", "ueb.source.topics.SDNR-CL-RSP.servers": "${dmaapServers}", "ueb.source.topics.SDNR-CL-RSP.events": "org.onap.policy.sdnr.PciResponseWrapper", - "ueb.source.topics.SDNR-CL-RSP.events.org.onap.policy.sdnr.PciResponseWrapper.filter": "type=response", + "ueb.source.topics.SDNR-CL-RSP.events.org.onap.policy.sdnr.PciResponseWrapper.filter": "[?($.type == 'response')]", "ueb.source.topics.SDNR-CL-RSP.events.custom.gson": "org.onap.policy.sdnr.util.Serialization,gson", "noop.sink.topics": "APPC-CL,APPC-LCM-READ,POLICY-CL-MGT,SDNR-CL", diff --git a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties index a6df015a8..fb516ed13 100644 --- a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties +++ b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.properties @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # archetype-closed-loop-demo-rules # ================================================================================ -# Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,14 +26,14 @@ dmaap.source.topics.${brmsgwTopic}.servers=${brmsgwServers} dmaap.source.topics.${brmsgwTopic}.apiKey= dmaap.source.topics.${brmsgwTopic}.apiSecret= dmaap.source.topics.${brmsgwTopic}.events=org.onap.policy.controlloop.params.ControlLoopParams -dmaap.source.topics.${brmsgwTopic}.events.org.onap.policy.controlloop.params.ControlLoopParams.filter=closedLoopControlName=.*,controlLoopYaml=.* +dmaap.source.topics.${brmsgwTopic}.events.org.onap.policy.controlloop.params.ControlLoopParams.filter=[?($.closedLoopControlName =~ /.*/ && $.controlLoopYaml =~ /.*/)] dmaap.source.topics.${brmsgwTopic}.https=true dmaap.source.topics.${dcaeTopic}.servers=${dcaeServers} dmaap.source.topics.${dcaeTopic}.apiKey= dmaap.source.topics.${dcaeTopic}.apiSecret= dmaap.source.topics.${dcaeTopic}.events=org.onap.policy.controlloop.VirtualControlLoopEvent -dmaap.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=closedLoopEventStatus=.* +dmaap.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=[?($.closedLoopEventStatus =~ /.*/)] dmaap.source.topics.${dcaeTopic}.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gson dmaap.source.topics.${dcaeTopic}.https=true @@ -41,7 +41,7 @@ dmaap.source.topics.APPC-CL.servers=${dmaapServers} dmaap.source.topics.APPC-CL.apiKey= dmaap.source.topics.APPC-CL.apiSecret= dmaap.source.topics.APPC-CL.events=org.onap.policy.appc.Response -dmaap.source.topics.APPC-CL.events.org.onap.policy.appc.Response.filter=CommonHeader\=.*,Status\=.* +dmaap.source.topics.APPC-CL.events.org.onap.policy.appc.Response.filter=[?($.CommonHeader =~ /.*/ && $.Status =~ /.*/)] dmaap.source.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty dmaap.source.topics.APPC-CL.https=true @@ -49,7 +49,7 @@ dmaap.source.topics.APPC-LCM-WRITE.servers=${dmaapServers} dmaap.source.topics.APPC-LCM-WRITE.apiKey= dmaap.source.topics.APPC-LCM-WRITE.apiSecret= dmaap.source.topics.APPC-LCM-WRITE.events=org.onap.policy.appclcm.LcmResponseWrapper -dmaap.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter=type\=response +dmaap.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter=[?($.type == 'response')] dmaap.source.topics.APPC-LCM-WRITE.events.custom.gson=org.onap.policy.appclcm.util.Serialization,gson dmaap.source.topics.APPC-LCM-WRITE.https=true diff --git a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json index 148e35562..b5dc418f0 100644 --- a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json +++ b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/__artifactId__-controller.rest.json @@ -5,21 +5,21 @@ "ueb.source.topics.${brmsgwTopic}.servers": "${brmsgwServers}", "ueb.source.topics.${brmsgwTopic}.events": "org.onap.policy.controlloop.params.ControlLoopParams", - "ueb.source.topics.${brmsgwTopic}.events.org.onap.policy.controlloop.params.ControlLoopParams.filter": "closedLoopControlName=.*,controlLoopYaml=.*", + "ueb.source.topics.${brmsgwTopic}.events.org.onap.policy.controlloop.params.ControlLoopParams.filter": "[?($.closedLoopControlName =~ /.*/ && $.controlLoopYaml =~ /.*/)]", "ueb.source.topics.${dcaeTopic}.servers": "${dcaeServers}", "ueb.source.topics.${dcaeTopic}.events": "org.onap.policy.controlloop.VirtualControlLoopEvent", - "ueb.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter": "closedLoopEventStatus=.*", + "ueb.source.topics.${dcaeTopic}.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter": "[?($.closedLoopEventStatus =~ /.*/)]", "ueb.source.topics.${dcaeTopic}.events.custom.gson": "org.onap.policy.controlloop.util.Serialization,gson", "ueb.source.topics.APPC-CL.servers": "${dmaapServers}", "ueb.source.topics.APPC-CL.events": "org.onap.policy.appc.Response", - "ueb.source.topics.APPC-CL.events.org.onap.policy.appclcm.LcmResponseWrapper.filter": "CommonHeader=.*,Status=.*", + "ueb.source.topics.APPC-CL.events.org.onap.policy.appc.Response.filter": "[?($.CommonHeader =~ /.*/ && $.Status =~ /.*/)]", "ueb.source.topics.APPC-CL.events.custom.gson": "org.onap.policy.appc.util.Serialization,gsonPretty", "ueb.source.topics.APPC-LCM-WRITE.servers": "${dmaapServers}", "ueb.source.topics.APPC-LCM-WRITE.events": "org.onap.policy.appclcm.LcmResponseWrapper", - "ueb.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter": "type=response", + "ueb.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.LcmResponseWrapper.filter": "[?($.type == 'response')]", "ueb.source.topics.APPC-LCM-WRITE.events.custom.gson": "org.onap.policy.appclcm.util.Serialization,gson", "noop.sink.topics": "APPC-CL,APPC-LCM-READ,POLICY-CL-MGT", diff --git a/controlloop/templates/template.demo.clc/pom.xml b/controlloop/templates/template.demo.clc/pom.xml index 5e80ad225..917b72fae 100644 --- a/controlloop/templates/template.demo.clc/pom.xml +++ b/controlloop/templates/template.demo.clc/pom.xml @@ -99,7 +99,7 @@ <artifactId>sdnc</artifactId> <version>${project.version}</version> <scope>provided</scope> - </dependency> + </dependency> <dependency> <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> <artifactId>events</artifactId> @@ -113,6 +113,12 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>org.onap.policy.drools-applications.controlloop.common</groupId> + <artifactId>coordination</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> <artifactId>aai</artifactId> <version>${project.version}</version> @@ -182,7 +188,7 @@ <artifactId>actor.sdnc</artifactId> <version>${project.version}</version> <scope>provided</scope> - </dependency> + </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> @@ -213,4 +219,3 @@ </dependency> </dependencies> </project> - diff --git a/controlloop/templates/template.demo.clc/src/main/resources/coordination/prototype/firstBlocksSecond.xml b/controlloop/templates/template.demo.clc/src/main/resources/coordination/prototype/firstBlocksSecond.xml new file mode 100644 index 000000000..54cda9575 --- /dev/null +++ b/controlloop/templates/template.demo.clc/src/main/resources/coordination/prototype/firstBlocksSecond.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<!-- + ============LICENSE_START======================================================= + drools-applications + ================================================================================ + Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + --> + +<!-- +# PIP Engine Definition +# +xacml.pip.engines=getstatus +getstatus.classname=org.onap.policy.guard.PipEngineGetStatus +getstatus.issuer=org:onap:policy:guard:getstatus +--> + +<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="urn:com:att:xacml:policy:id:son:guard:UNIQUE_ID" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny"> + <Description>Policy for first_blocks_second coordination (if first running and second requests to run, deny second).</Description> + <Target> + <AnyOf> + <AllOf> + <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match"> + <!-- value to be autofilled by yaml from a xacml template --> + <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">CONTROL_LOOP_TWO</AttributeValue> + <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/> + </Match> + </AllOf> + </AnyOf> + </Target> + + <Rule RuleId="urn:com:att:xacml:rule:id:1" Effect="Deny"> + <Description>First Is Running</Description> + <Condition> + <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"> + <VariableReference VariableId="clc_status"/> + <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Success</AttributeValue> + </Apply> + </Condition> + </Rule> + + <VariableDefinition VariableId="clc_status"> + <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only"> + <!-- to be autofilled by yaml from a xacml template --> + <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="com:att:research:xacml:test:sql:resource:operations:status" DataType="http://www.w3.org/2001/XMLSchema#string" Issuer="org:onap:policy:guard:getstatus:clname:CONTROL_LOOP_ONE" MustBePresent="false"/> + </Apply> + </VariableDefinition> +</Policy> diff --git a/controlloop/templates/template.demo.clc/src/test/java/org/onap/policy/template/demo/clc/ControlLoopCoordinationTest.java b/controlloop/templates/template.demo.clc/src/test/java/org/onap/policy/template/demo/clc/ControlLoopCoordinationTest.java index 4d8fca83b..ee5eceba9 100644 --- a/controlloop/templates/template.demo.clc/src/test/java/org/onap/policy/template/demo/clc/ControlLoopCoordinationTest.java +++ b/controlloop/templates/template.demo.clc/src/test/java/org/onap/policy/template/demo/clc/ControlLoopCoordinationTest.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,9 +27,13 @@ import static org.junit.Assert.fail; import com.google.gson.Gson; +import java.io.File; import java.io.IOException; +import java.io.PrintWriter; import java.lang.StringBuilder; import java.net.URLEncoder; +import java.nio.file.Files; +import java.nio.file.Paths; import java.time.Instant; import java.util.HashMap; import java.util.List; @@ -59,6 +63,8 @@ import org.onap.policy.controlloop.ControlLoopTargetType; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.policy.ControlLoopPolicy; +import org.onap.policy.coordination.CoordinationDirective; +import org.onap.policy.coordination.Util; import org.onap.policy.drools.protocol.coders.EventProtocolCoder; import org.onap.policy.drools.protocol.coders.EventProtocolParams; import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; @@ -89,9 +95,11 @@ public class ControlLoopCoordinationTest implements TopicListener { /** * Setup simulator. + * + * @throws IOException when thrown by buildAaiSim */ @BeforeClass - public static void setUpSimulator() { + public static void setUpSimulator() throws Exception { PolicyEngine.manager.configure(new Properties()); assertTrue(PolicyEngine.manager.start()); Properties noopSinkProperties = new Properties(); @@ -119,34 +127,69 @@ public class ControlLoopCoordinationTest implements TopicListener { .eventClass("org.onap.policy.appclcm.LcmRequestWrapper") .protocolFilter(new JsonProtocolFilter()) .modelClassLoaderHash(1111)); - try { - SupportUtil.buildAaiSim(); - } catch (Exception e) { - fail(e.getMessage()); - } - + SupportUtil.buildAaiSim(); + /* + * Apply the coordination directive + */ + final String coordinationDir = "src/test/resources/coordination"; + final String coordinationProtoDir = "src/main/resources/coordination/prototype"; + final String coordinationDirectiveName = "synthetic_control_loop_one_blocks_synthetic_control_loop_two"; + final String propertiesDir = "src/test/resources/properties"; + final String propertiesProtoDir = "src/test/resources/properties/prototype"; + final String xacmlDir = "src/test/resources/xacml"; + final String yamlDir = "src/test/resources/yaml"; + + String coordinationDirectiveFile = coordinationDir + File.separator + coordinationDirectiveName + ".yaml"; + /* + * Load the coordination directive from the Yaml encoding + */ + CoordinationDirective cd = Util.loadCoordinationDirectiveFromFile(coordinationDirectiveFile); + logger.info("CoordinationDirective={}", cd.toString()); + /* + * Generate the Xacml policy from the coordination directive + */ + String xacmlPolicy = Util.generateXacmlFromCoordinationDirective(cd, coordinationProtoDir); + /* + * Create directory for Xacml output file, if necessary + */ + Files.createDirectories(Paths.get(xacmlDir)); + /* + * Write Xacml policy to file + */ + String xacmlFilename = xacmlDir + File.separator + + cd.getCoordinationFunction() + + cd.getControlLoop(0) + + cd.getControlLoop(1) + + ".xml"; + File xacmlFile = new File(xacmlFilename); + PrintWriter xacmlFileWriter = new PrintWriter(xacmlFile); + xacmlFileWriter.println(xacmlPolicy); + xacmlFileWriter.flush(); + /* + * Remove Xacml file after test + */ + xacmlFile.deleteOnExit(); + /* + * Insert the Xacml policy file into the PDP + */ + SupportUtil.insertXacmlPolicy(xacmlFilename, propertiesProtoDir, propertiesDir); /* * Start the kie sessions */ - try { - kieSession1 = startSession( + kieSession1 = startSession( controlLoopOneName, "src/main/resources/__closedLoopControlName__.drl", - "src/test/resources/yaml/policy_ControlLoop_SyntheticOne.yaml", + yamlDir + "/policy_ControlLoop_SyntheticOne.yaml", "service=ServiceDemo;resource=Res1Demo;type=operational", "SyntheticControlLoopOnePolicy", "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0"); - kieSession2 = startSession( + kieSession2 = startSession( controlLoopTwoName, "src/main/resources/__closedLoopControlName__.drl", - "src/test/resources/yaml/policy_ControlLoop_SyntheticTwo.yaml", + yamlDir + "/policy_ControlLoop_SyntheticTwo.yaml", "service=ServiceDemo;resource=Res1Demo;type=operational", "SyntheticControlLoopTwoPolicy", "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0"); - } catch (IOException e) { - logger.debug("Could not create kieSession, exception {}", e.getMessage()); - fail("Could not create kieSession"); - } } /** @@ -168,7 +211,7 @@ public class ControlLoopCoordinationTest implements TopicListener { /** * Set expected decision. - * + * * @param ed the expected decision ("PERMIT" or "DENY") */ public void expectedDecisionIs(String ed) { @@ -180,7 +223,7 @@ public class ControlLoopCoordinationTest implements TopicListener { * This method is used to simulate event messages from DCAE * that start the control loop (onset message) or end the * control loop (abatement message). - * + * * @param controlLoopName the control loop name * @param requestId the requestId for this event * @param status could be onset or abated @@ -188,7 +231,7 @@ public class ControlLoopCoordinationTest implements TopicListener { * @param kieSession the kieSession to which this event is being sent */ protected void sendEvent(String controlLoopName, - UUID requestId, + UUID requestId, ControlLoopEventStatus status, String target, KieSession kieSession) { @@ -206,14 +249,14 @@ public class ControlLoopCoordinationTest implements TopicListener { Gson gson = new Gson(); String json = gson.toJson(event); logger.debug("sendEvent {}", json); - + kieSession.insert(event); } - + /** * Simulate an event by inserting into kieSession and firing rules as needed. - * + * * @param cles the ControlLoopEventStatus * @param rid the request ID * @param controlLoopName the control loop name @@ -234,12 +277,12 @@ public class ControlLoopCoordinationTest implements TopicListener { } // // simulate sending event - // + // sendEvent(controlLoopName, rid, cles, target, kieSession); kieSession.fireUntilHalt(); // // get dump of database entries and log - // + // List<?> entries = SupportUtil.dumpDb(); assertNotNull(entries); logger.debug("dumpDB, {} entries", entries.size()); @@ -248,17 +291,17 @@ public class ControlLoopCoordinationTest implements TopicListener { } // // we are done - // + // logger.info("simulateEvent: done"); } /** * Simulate an onset event. - * + * * @param rid the request ID * @param controlLoopName the control loop name * @param kieSession the kieSession to which this event is being sent - * @param expectedDecision the expected decision + * @param expectedDecision the expected decision */ public void simulateOnset(UUID rid, String controlLoopName, @@ -270,7 +313,7 @@ public class ControlLoopCoordinationTest implements TopicListener { /** * Simulate an abated event. - * + * * @param rid the request ID * @param controlLoopName the control loop name * @param kieSession the kieSession to which this event is being sent @@ -281,10 +324,10 @@ public class ControlLoopCoordinationTest implements TopicListener { KieSession kieSession) { simulateEvent(ControlLoopEventStatus.ABATED, rid, controlLoopName, target, kieSession, null); } - + /** * This method will start a kie session and instantiate the Policy Engine. - * + * * @param droolsTemplate the DRL rules file * @param yamlFile the yaml file containing the policies * @param policyScope scope for policy @@ -312,11 +355,11 @@ public class ControlLoopCoordinationTest implements TopicListener { controlLoopName.append(pair.first.getControlLoop().getControlLoopName()); String yamlContents = pair.second; - + /* * Construct a kie session */ - final KieSession kieSession = SupportUtil.buildContainer(droolsTemplate, + final KieSession kieSession = SupportUtil.buildContainer(droolsTemplate, controlLoopName.toString(), policyScope, policyName, @@ -336,7 +379,7 @@ public class ControlLoopCoordinationTest implements TopicListener { /* * (non-Javadoc) - * + * * @see org.onap.policy.drools.PolicyEngineListener#newEventNotification(java.lang.String) */ @Override @@ -400,7 +443,7 @@ public class ControlLoopCoordinationTest implements TopicListener { logger.debug("Halting kieSession2"); kieSession2.halt(); } else { - fail("Unknown ControlLoop"); + fail("Unknown ControlLoop"); } } } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) { @@ -435,7 +478,7 @@ public class ControlLoopCoordinationTest implements TopicListener { /** * This method will dump all the facts in the working memory. - * + * * @param kieSession the session containing the facts */ public void dumpFacts(KieSession kieSession) { @@ -454,14 +497,14 @@ public class ControlLoopCoordinationTest implements TopicListener { logger.info("Beginning testSyntheticControlLoopOneBlocksSyntheticControlLoopTwo"); /* * Allows the PolicyEngine to callback to this object to - * notify that there is an event ready to be pulled + * notify that there is an event ready to be pulled * from the queue */ for (TopicSink sink : noopTopics) { assertTrue(sink.start()); sink.register(this); } - + /* * Create unique requestIds */ @@ -475,25 +518,33 @@ public class ControlLoopCoordinationTest implements TopicListener { final String t1 = "TARGET_1"; final String t2 = "TARGET_2"; - logger.info("@@@@@@@@@@ cl2 ONSET t1 (Success) @@@@@@@@@@"); + logger.info("@@@@@@@@@@ cl2 ONSET t1 (Success) @@@@@@@@@@"); simulateOnset(requestId1, cl2, t1, kieSession2,"PERMIT"); - logger.info("@@@@@@@@@@ cl1 ONSET t1 @@@@@@@@@@"); + + logger.info("@@@@@@@@@@ cl1 ONSET t1 @@@@@@@@@@"); simulateOnset(requestId2, cl1, t1, kieSession1,"PERMIT"); - logger.info("@@@@@@@@@@ cl2 ABATED t1 @@@@@@@@@@"); + + logger.info("@@@@@@@@@@ cl2 ABATED t1 @@@@@@@@@@"); simulateAbatement(requestId1, cl2, t1, kieSession2); - logger.info("@@@@@@@@@@ cl2 ONSET t1 (Fail) @@@@@@@@@@"); + + logger.info("@@@@@@@@@@ cl2 ONSET t1 (Fail) @@@@@@@@@@"); simulateOnset(requestId3, cl2, t1, kieSession2,"DENY"); + logger.info("@@@@@@@@@@ cl2 ONSET t2 (Success) @@@@@@@@@@"); simulateOnset(requestId4, cl2, t2, kieSession2,"PERMIT"); - logger.info("@@@@@@@@@@ cl2 ABATED t2 @@@@@@@@@@"); + + logger.info("@@@@@@@@@@ cl2 ABATED t2 @@@@@@@@@@"); simulateAbatement(requestId4, cl2, t2, kieSession2); - logger.info("@@@@@@@@@@ cl1 ABATED t1 @@@@@@@@@@"); + + logger.info("@@@@@@@@@@ cl1 ABATED t1 @@@@@@@@@@"); simulateAbatement(requestId2, cl1, t1, kieSession1); - logger.info("@@@@@@@@@@ cl2 ONSET t1 (Success) @@@@@@@@@@"); + + logger.info("@@@@@@@@@@ cl2 ONSET t1 (Success) @@@@@@@@@@"); simulateOnset(requestId5, cl2, t1, kieSession2,"PERMIT"); - logger.info("@@@@@@@@@@ cl2 ABATED t1 @@@@@@@@@@"); + + logger.info("@@@@@@@@@@ cl2 ABATED t1 @@@@@@@@@@"); simulateAbatement(requestId5, cl2, t1, kieSession2); - + /* * Print what's left in memory */ @@ -501,4 +552,3 @@ public class ControlLoopCoordinationTest implements TopicListener { dumpFacts(kieSession2); } } - diff --git a/controlloop/templates/template.demo.clc/src/test/java/org/onap/policy/template/demo/clc/SupportUtil.java b/controlloop/templates/template.demo.clc/src/test/java/org/onap/policy/template/demo/clc/SupportUtil.java index bf2038cc2..a9f0a04e4 100644 --- a/controlloop/templates/template.demo.clc/src/test/java/org/onap/policy/template/demo/clc/SupportUtil.java +++ b/controlloop/templates/template.demo.clc/src/test/java/org/onap/policy/template/demo/clc/SupportUtil.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * demo * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,17 +22,23 @@ package org.onap.policy.template.demo.clc; import static org.junit.Assert.fail; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; +import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Stream; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; @@ -49,6 +55,8 @@ import org.kie.api.runtime.KieSession; import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.guard.ControlLoopGuard; +import org.onap.policy.controlloop.policy.guard.ControlLoopGuard; +import org.onap.policy.coordination.CoordinationDirective; import org.onap.policy.drools.system.PolicyEngine; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -78,7 +86,7 @@ public final class SupportUtil { /** * Load YAML. - * + * * @param testFile test file to load * @return the Pair of a policy and the yaml contents */ @@ -95,6 +103,7 @@ public final class SupportUtil { return new Pair<ControlLoopPolicy, String>((ControlLoopPolicy) obj, contents); } catch (IOException e) { + logger.error("Error while loading YAML", e); fail(e.getLocalizedMessage()); } return null; @@ -102,7 +111,7 @@ public final class SupportUtil { /** * Load the YAML guard policy. - * + * * @param testFile the test file to load * @return return the guard object */ @@ -116,11 +125,70 @@ public final class SupportUtil { Object obj = yaml.load(contents); return (ControlLoopGuard) obj; } catch (IOException e) { + logger.error("Error while loading YAML guard", e); fail(e.getLocalizedMessage()); } return null; } + /** + * Insert the Xacml policy into the PDP. + * Achieved by configuring the properties file to load the Xacml policy and required PIP(s). + * + * @param xacmlFile the Xacml policy file's path + * @param propProtoDir the directory containing Xacml implementation prototypes + * @param propDir the directory to which the Xacml rule should be output + */ + public static void insertXacmlPolicy(String xacmlFile, + String propProtoDir, + String propDir) { + String propName = "xacml_guard_clc"; + String propProtoFile = propProtoDir + File.separator + propName + ".properties"; + String propFilename = propDir + File.separator + propName + ".properties"; + + String addXacmlFileToRoot = "# Policies to load\n" + + "xacml.rootPolicies=p1\n" + + "p1.file=" + xacmlFile + "\n"; + + File propFile = new File(propFilename); + try (Stream<String> stream = Files.lines(Paths.get(propProtoFile)); + PrintWriter output = new PrintWriter(propFile)) { + /* + * Remove file after test + */ + propFile.deleteOnExit(); + /* + * Copy the property prototype + */ + stream.forEach(output::println); + /* + * Add the Xacml policy to the set of root policies + */ + output.println(addXacmlFileToRoot); + /* + * Obtain PIP Engine definitions from Xacml policy + * and insert into property file. + */ + try (BufferedReader br = new BufferedReader(new FileReader(xacmlFile))) { + boolean select = false; + for (String line; (line = br.readLine()) != null; ) { + if (line.contains("PIP Engine Definition")) { + select = true; + } + if (line.contains("-->")) { + select = false; + } + if (select) { + output.println(line); + } + } + } + } catch (Exception e) { + logger.error("Error when trying to create test propery file", e); + fail(e.getMessage()); + } + } + public static HttpServletServer buildAaiSim() throws InterruptedException, IOException { return org.onap.policy.simulators.Util.buildAaiSim(); } @@ -244,7 +312,7 @@ public final class SupportUtil { * Guard PDP-x connection Properties. No URL specified -> use embedded PDPEngine. */ PolicyEngine.manager.setEnvironmentProperty("prop.guard.propfile", - "src/test/resources/xacml/xacml_guard_clc.properties"); + "src/test/resources/properties/xacml_guard_clc.properties"); PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, "python"); PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, "test"); PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_CLIENT_USER, "python"); @@ -252,7 +320,7 @@ public final class SupportUtil { PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_ENV, "TEST"); PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_DISABLED, "false"); } - + /** * Set the operation history properties. */ diff --git a/controlloop/templates/template.demo.clc/src/test/resources/coordination/synthetic_control_loop_one_blocks_synthetic_control_loop_two.yaml b/controlloop/templates/template.demo.clc/src/test/resources/coordination/synthetic_control_loop_one_blocks_synthetic_control_loop_two.yaml new file mode 100644 index 000000000..7b69c3a0c --- /dev/null +++ b/controlloop/templates/template.demo.clc/src/test/resources/coordination/synthetic_control_loop_one_blocks_synthetic_control_loop_two.yaml @@ -0,0 +1,20 @@ +# Copyright 2019 AT&T Intellectual Property. All rights reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +!!org.onap.policy.coordination.CoordinationDirective + +controlLoop: +- SyntheticControlLoopOne +- SyntheticControlLoopTwo +coordinationFunction: firstBlocksSecond
\ No newline at end of file diff --git a/controlloop/templates/template.demo.clc/src/test/resources/xacml/xacml_guard_clc.properties b/controlloop/templates/template.demo.clc/src/test/resources/properties/prototype/xacml_guard_clc.properties index 5f5e0c8b2..edc76517a 100644 --- a/controlloop/templates/template.demo.clc/src/test/resources/xacml/xacml_guard_clc.properties +++ b/controlloop/templates/template.demo.clc/src/test/resources/properties/prototype/xacml_guard_clc.properties @@ -2,14 +2,14 @@ # ============LICENSE_START======================================================= # ONAP # ================================================================================ -# Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,13 +19,6 @@ ### # # -# This files defines PIPs that will be used by XACML Guard Policies. One PIP per time window (5 min, 10min,...,1 month). -# -# -# - -# -# Default XACML Properties File # Standard API Factories # xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory @@ -48,18 +41,6 @@ xacml.att.policyFinderFactory=com.att.research.xacmlatt.pdp.std.StdPolicyFinderF # the embedded PDP uses. # -# In case we have multiple applicable Guard policies, we will deny if any of them denies. +# In case we have multiple applicable Guard policies, we will deny if any of them denies. #xacml.att.policyFinderFactory.combineRootPolicies=urn:com:att:xacml:3.0:policy-combining-algorithm:combined-deny-overrides xacml.att.policyFinderFactory.combineRootPolicies=urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:permit-unless-deny - - -# Policies to load -# -xacml.rootPolicies=p1 -p1.file=src/test/resources/xacml/synthetic_control_loop_one_blocks_synthetic_control_loop_two.xml - -# PIP Engine Definition -# -xacml.pip.engines=getstatus -getstatus.classname=org.onap.policy.guard.PipEngineGetStatus -getstatus.issuer=org:onap:policy:guard:getstatus diff --git a/controlloop/templates/template.demo.clc/src/test/resources/xacml/synthetic_control_loop_one_blocks_synthetic_control_loop_two.xml b/controlloop/templates/template.demo.clc/src/test/resources/xacml/synthetic_control_loop_one_blocks_synthetic_control_loop_two.xml deleted file mode 100644 index f503a2b11..000000000 --- a/controlloop/templates/template.demo.clc/src/test/resources/xacml/synthetic_control_loop_one_blocks_synthetic_control_loop_two.xml +++ /dev/null @@ -1,51 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes"?> -<!-- - ============LICENSE_START======================================================= - drools-applications - ================================================================================ - Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ============LICENSE_END========================================================= - --> -<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="urn:com:att:xacml:policy:id:son:guard:5" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny"> -<Description>Policy for first_blocks_second coordination (if first running and second requests to run, deny second).</Description> -<Target> - <AnyOf> - <AllOf> - <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match"> - <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">SyntheticControlLoopTwo</AttributeValue> - <!-- value should be autofilled by yaml from a xacml template --> - <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/> - </Match> - </AllOf> - </AnyOf> -</Target> - -<Rule RuleId="urn:com:att:xacml:rule:id:1" Effect="Deny"> - <Description>First Is Running</Description> - <Condition> - <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"> - <VariableReference VariableId="clc_status"/> - <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Success</AttributeValue> - </Apply> - </Condition> -</Rule> - -<!-- 'action_one' should be autofilled by yaml from a xacml template --> -<VariableDefinition VariableId="clc_status"> - <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only"> - <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="com:att:research:xacml:test:sql:resource:operations:status" DataType="http://www.w3.org/2001/XMLSchema#string" Issuer="org:onap:policy:guard:getstatus:clname:SyntheticControlLoopOne" MustBePresent="false"/> - </Apply> -</VariableDefinition> -</Policy> |