Merge "Fixed SO request creation"
authorPamela Dragosh <pdragosh@research.att.com>
Fri, 14 Jun 2019 02:22:53 +0000 (02:22 +0000)
committerGerrit Code Review <gerrit@onap.org>
Fri, 14 Jun 2019 02:22:53 +0000 (02:22 +0000)
50 files changed:
models-base/pom.xml
models-dao/pom.xml
models-decisions/pom.xml
models-errors/pom.xml
models-examples/pom.xml
models-interactions/model-actors/actor.appc/pom.xml
models-interactions/model-actors/actor.appclcm/pom.xml
models-interactions/model-actors/actor.sdnc/pom.xml
models-interactions/model-actors/actor.sdnr/pom.xml
models-interactions/model-actors/actor.so/pom.xml
models-interactions/model-actors/actor.test/pom.xml
models-interactions/model-actors/actor.vfc/pom.xml
models-interactions/model-actors/actorServiceProvider/pom.xml
models-interactions/model-actors/pom.xml
models-interactions/model-impl/aai/pom.xml
models-interactions/model-impl/appc/pom.xml
models-interactions/model-impl/appclcm/pom.xml
models-interactions/model-impl/cds/pom.xml [new file with mode: 0644]
models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/api/CdsProcessorListener.java [new file with mode: 0644]
models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/BasicAuthClientHeaderInterceptor.java [new file with mode: 0644]
models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorGrpcClient.java [new file with mode: 0644]
models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorHandler.java [new file with mode: 0644]
models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/properties/CdsServerProperties.java [new file with mode: 0644]
models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/api/TestCdsProcessorListenerImpl.java [new file with mode: 0644]
models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/BasicAuthClientHeaderInterceptorTest.java [new file with mode: 0644]
models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java [new file with mode: 0644]
models-interactions/model-impl/events/pom.xml
models-interactions/model-impl/pom.xml
models-interactions/model-impl/rest/pom.xml
models-interactions/model-impl/sdc/pom.xml
models-interactions/model-impl/sdnc/pom.xml
models-interactions/model-impl/sdnr/pom.xml
models-interactions/model-impl/so/pom.xml
models-interactions/model-impl/vfc/pom.xml
models-interactions/model-simulators/pom.xml
models-interactions/model-yaml/pom.xml
models-interactions/pom.xml
models-pap/pom.xml
models-pdp/pom.xml
models-provider/pom.xml
models-sim/models-sim-dmaap/pom.xml
models-sim/models-sim-dmaap/src/main/package/docker/Dockerfile
models-sim/policy-models-sim-pdp/pom.xml
models-sim/policy-models-sim-pdp/src/main/package/docker/Dockerfile
models-sim/pom.xml
models-tosca/pom.xml
models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java
models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java
pom.xml
version.properties

index 03e047e..d40a6e4 100644 (file)
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.onap.policy.models</groupId>
         <artifactId>policy-models</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>policy-models-base</artifactId>
index d778679..7346303 100644 (file)
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.onap.policy.models</groupId>
         <artifactId>policy-models</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>policy-models-dao</artifactId>
index 89a13af..94062d1 100644 (file)
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.onap.policy.models</groupId>
         <artifactId>policy-models</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>policy-models-decisions</artifactId>
index 8c26836..dc9b999 100644 (file)
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.onap.policy.models</groupId>
         <artifactId>policy-models</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>policy-models-errors</artifactId>
index 427e850..a67a288 100644 (file)
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.onap.policy.models</groupId>
         <artifactId>policy-models</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>policy-models-examples</artifactId>
index 5528fc3..f54130d 100644 (file)
@@ -24,7 +24,7 @@
   <parent>
    <groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
     <artifactId>model-actors</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>actor.appc</artifactId>
index e16206b..4b8d44e 100644 (file)
@@ -24,7 +24,7 @@
   <parent>
    <groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
     <artifactId>model-actors</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>actor.appclcm</artifactId>
index a212175..271e1a7 100644 (file)
@@ -24,7 +24,7 @@
   <parent>
    <groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
     <artifactId>model-actors</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>actor.sdnc</artifactId>
index 675ce13..00b3997 100644 (file)
@@ -24,7 +24,7 @@
   <parent>
    <groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
     <artifactId>model-actors</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>actor.sdnr</artifactId>
index e2bd277..de7d5ed 100644 (file)
@@ -24,7 +24,7 @@
   <parent>
    <groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
     <artifactId>model-actors</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>actor.so</artifactId>
index 919e49b..f9d0d77 100644 (file)
@@ -24,7 +24,7 @@
   <parent>
    <groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
     <artifactId>model-actors</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>actor.test</artifactId>
index 81c1306..b61e217 100644 (file)
@@ -24,7 +24,7 @@
   <parent>
    <groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
     <artifactId>model-actors</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>actor.vfc</artifactId>
index 86d7b7e..eb1ce68 100644 (file)
@@ -24,7 +24,7 @@
   <parent>
    <groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
     <artifactId>model-actors</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>actorServiceProvider</artifactId>
index d766b24..793f9e4 100644 (file)
@@ -24,7 +24,7 @@
   <parent>
     <groupId>org.onap.policy.models</groupId>
     <artifactId>policy-models-interactions</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
   
   <groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
index 0930a2d..8b6b296 100644 (file)
@@ -27,7 +27,7 @@
     <parent>
         <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
         <artifactId>model-impl</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>aai</artifactId>
index a72386c..94de35e 100644 (file)
@@ -26,7 +26,7 @@
   <parent>
     <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
     <artifactId>model-impl</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>appc</artifactId>
index 790fe4a..b9a7742 100644 (file)
@@ -26,7 +26,7 @@
   <parent>
     <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
     <artifactId>model-impl</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>appclcm</artifactId>
diff --git a/models-interactions/model-impl/cds/pom.xml b/models-interactions/model-impl/cds/pom.xml
new file mode 100644 (file)
index 0000000..9e3b55b
--- /dev/null
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ============LICENSE_START=======================================================
+  Copyright (C) 2019 Bell Canada.
+  ================================================================================
+  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>
+    <artifactId>model-impl</artifactId>
+    <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
+    <version>2.1.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>cds</artifactId>
+  <name>${project.artifactId}</name>
+  <description>gRPC client implementation to send process message to CDS blueprint processor gRPC endpoint.</description>
+
+  <properties>
+    <grpc.version>1.17.1</grpc.version>
+    <protobuf.version>3.6.1</protobuf.version>
+    <grpc.netty.version>4.1.30.Final</grpc.netty.version>
+    <ccsdk.version>0.4.4</ccsdk.version>
+  </properties>
+
+  <dependencies>
+    <!-- CDS dependencies -->
+    <dependency>
+      <groupId>org.onap.ccsdk.cds.components</groupId>
+      <artifactId>proto-definition</artifactId>
+      <version>${ccsdk.version}</version>
+    </dependency>
+
+    <!-- protobuf dependencies -->
+    <dependency>
+      <groupId>com.google.protobuf</groupId>
+      <artifactId>protobuf-java</artifactId>
+      <version>${protobuf.version}</version>
+    </dependency>
+
+    <!-- gRPC dependencies -->
+    <dependency>
+      <groupId>io.grpc</groupId>
+      <artifactId>grpc-protobuf</artifactId>
+      <version>${grpc.version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>com.google.code.findbugs</groupId>
+          <artifactId>jsr305</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>io.grpc</groupId>
+      <artifactId>grpc-stub</artifactId>
+      <version>${grpc.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>io.grpc</groupId>
+      <artifactId>grpc-netty</artifactId>
+      <version>${grpc.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>io.grpc</groupId>
+      <artifactId>grpc-testing</artifactId>
+      <version>${grpc.version}</version>
+      <scope>test</scope>
+    </dependency>
+
+    <!-- Policy dependencies -->
+    <dependency>
+      <groupId>org.onap.policy.common</groupId>
+      <artifactId>common-parameters</artifactId>
+      <version>${policy.common.version}</version>
+    </dependency>
+
+    <!-- junit dependencies -->
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <version>2.13.0</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/api/CdsProcessorListener.java b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/api/CdsProcessorListener.java
new file mode 100644 (file)
index 0000000..c07c559
--- /dev/null
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * 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.cds.api;
+
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
+
+/**
+ * <p>
+ * In order for the caller of {@link org.onap.policy.cds.client.CdsProcessorGrpcClient} to manage the callback to handle
+ * the received messages appropriately, it needs to implement {@link CdsProcessorListener}.
+ * </p>
+ *
+ * <p>Here is a sample implementation of a listener:
+ * <pre>
+ * new CdsProcessorListener {
+ *
+ *     &#64;Override
+ *     public void onMessage(ExecutionServiceOutput message) {
+ *         log.info("Received notification from CDS: {}", message);
+ *     }
+ *
+ *     &#64;Override
+ *     public void onError(Throwable throwable) {
+ *         Status status = Status.fromThrowable(throwable);
+ *         log.error("Failed processing blueprint {}", status, throwable);
+ *     }
+ * }
+ * </pre>
+ * </p>
+ */
+public interface CdsProcessorListener {
+
+    /**
+     * Implements the workflow upon receiving the message from the server side.
+     *
+     * <p>Note that the CDS client-server communication is configured to use a streaming approach, which means when
+     * client
+     * sends an event, the server can reply with multiple sub-responses until full completion of the processing. Hence,
+     * it is up to the implementation of this method to process the received message using {@link
+     * ExecutionServiceOutput#getStatus()#getEventType()}</p>
+     *
+     * @param message ExecutionServiceOutput received by the CDS grpc server
+     */
+    void onMessage(ExecutionServiceOutput message);
+
+    /**
+     * Implements the workflow when an error is received from the server side.
+     *
+     * @param throwable Throwable object received from CDS grpc server upon error
+     */
+    void onError(Throwable throwable);
+
+}
diff --git a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/BasicAuthClientHeaderInterceptor.java b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/BasicAuthClientHeaderInterceptor.java
new file mode 100644 (file)
index 0000000..3957fe5
--- /dev/null
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * 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.cds.client;
+
+import io.grpc.CallOptions;
+import io.grpc.Channel;
+import io.grpc.ClientCall;
+import io.grpc.ClientInterceptor;
+import io.grpc.ForwardingClientCall;
+import io.grpc.Metadata;
+import io.grpc.Metadata.Key;
+import io.grpc.MethodDescriptor;
+import org.onap.policy.cds.properties.CdsServerProperties;
+
+/**
+ * An interceptor to insert the client authHeader.
+ *
+ * <p>The {@link BasicAuthClientHeaderInterceptor} implements {@link ClientInterceptor} to insert authorization
+ * header data provided by {@link CdsServerProperties#getBasicAuth()} to all the outgoing calls.</p>
+ *
+ * <p>On the client context, we add metadata with "Authorization" as the key and "Basic" followed by base64 encoded
+ * username:password as its value.
+ * On the server side, CDS BasicAuthServerInterceptor (1) gets the client metadata from the server context, (2) extract
+ * the "Authorization" header key and finally (3) decodes the username and password from the authHeader.</p>
+ */
+public class BasicAuthClientHeaderInterceptor implements ClientInterceptor {
+
+    static final String BASIC_AUTH_HEADER_KEY = "Authorization";
+    private CdsServerProperties props;
+
+    BasicAuthClientHeaderInterceptor(CdsServerProperties props) {
+        this.props = props;
+    }
+
+    @Override
+    public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method,
+        CallOptions callOptions, Channel channel) {
+        Key<String> authHeader = Key.of(BASIC_AUTH_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER);
+        return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(channel.newCall(method, callOptions)) {
+            @Override
+            public void start(Listener<RespT> responseListener, Metadata headers) {
+                headers.put(authHeader, props.getBasicAuth());
+                super.start(responseListener, headers);
+            }
+        };
+    }
+}
+
diff --git a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorGrpcClient.java b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorGrpcClient.java
new file mode 100644 (file)
index 0000000..b8ec7ac
--- /dev/null
@@ -0,0 +1,94 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * 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.cds.client;
+
+import com.google.common.base.Preconditions;
+import io.grpc.ManagedChannel;
+import io.grpc.internal.DnsNameResolverProvider;
+import io.grpc.internal.PickFirstLoadBalancerProvider;
+import io.grpc.netty.NettyChannelBuilder;
+import java.util.concurrent.CountDownLatch;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
+import org.onap.policy.cds.api.CdsProcessorListener;
+import org.onap.policy.cds.properties.CdsServerProperties;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <p>
+ * The CDS processor client uses gRPC for communication between Policy and CDS. This communication is configured to use
+ * a streaming approach, which means the client sends an event to which the server can reply with multiple
+ * sub-responses, until full completion of the processing.
+ * </p>
+ */
+public class CdsProcessorGrpcClient implements AutoCloseable {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(CdsProcessorGrpcClient.class);
+
+    private ManagedChannel channel;
+    private CdsProcessorHandler handler;
+
+    /**
+     * Constructor, create a CDS processor gRPC client.
+     *
+     * @param listener the listener to listen on
+     */
+    public CdsProcessorGrpcClient(final CdsProcessorListener listener, CdsServerProperties props) {
+        final GroupValidationResult validationResult = props.validate();
+        Preconditions.checkState(validationResult.getStatus().isValid(), "Error validating CDS server "
+            + "properties: " + validationResult.getResult());
+
+        this.channel = NettyChannelBuilder.forAddress(props.getHost(), props.getPort())
+            .nameResolverFactory(new DnsNameResolverProvider())
+            .loadBalancerFactory(new PickFirstLoadBalancerProvider())
+            .intercept(new BasicAuthClientHeaderInterceptor(props)).usePlaintext().build();
+        this.handler = new CdsProcessorHandler(listener);
+        LOGGER.info("CdsProcessorListener started");
+    }
+
+    CdsProcessorGrpcClient(final ManagedChannel channel, final CdsProcessorHandler handler) {
+        this.channel = channel;
+        this.handler = handler;
+    }
+
+    /**
+     * Sends a request to the CDS backend micro-service.
+     *
+     * <p>The caller will be returned a CountDownLatch that can be used to define how long the processing can wait. The
+     * CountDownLatch is initiated with just 1 count. When the client receives an #onCompleted callback, the counter
+     * will decrement.</p>
+     *
+     * <p>It is the user responsibility to close the client.</p>
+     *
+     * @param input request to send
+     * @return CountDownLatch instance that can be use to #await for completeness of processing
+     */
+    public CountDownLatch sendRequest(ExecutionServiceInput input) {
+        return handler.process(input, channel);
+    }
+
+    @Override
+    public void close() {
+        if (channel != null) {
+            channel.shutdown();
+        }
+        LOGGER.info("CdsProcessorListener stopped");
+    }
+}
diff --git a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorHandler.java b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorHandler.java
new file mode 100644 (file)
index 0000000..9dd249c
--- /dev/null
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * 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.cds.client;
+
+import io.grpc.ManagedChannel;
+import io.grpc.stub.StreamObserver;
+import java.util.concurrent.CountDownLatch;
+import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceStub;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
+import org.onap.policy.cds.api.CdsProcessorListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class CdsProcessorHandler {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(CdsProcessorHandler.class);
+
+    private CdsProcessorListener listener;
+
+    CdsProcessorHandler(final CdsProcessorListener listener) {
+        this.listener = listener;
+    }
+
+    CountDownLatch process(ExecutionServiceInput request, ManagedChannel channel) {
+        final ActionIdentifiers header = request.getActionIdentifiers();
+        LOGGER.info("Processing blueprint({}:{}) for action({})", header.getBlueprintVersion(),
+            header.getBlueprintName(), header.getBlueprintVersion());
+
+        final CountDownLatch finishLatch = new CountDownLatch(1);
+        final BluePrintProcessingServiceStub asyncStub = BluePrintProcessingServiceGrpc.newStub(channel);
+        final StreamObserver<ExecutionServiceOutput> responseObserver = new StreamObserver<ExecutionServiceOutput>() {
+            @Override
+            public void onNext(ExecutionServiceOutput output) {
+                listener.onMessage(output);
+            }
+
+            @Override
+            public void onError(Throwable throwable) {
+                listener.onError(throwable);
+                finishLatch.countDown();
+            }
+
+            @Override
+            public void onCompleted() {
+                LOGGER.info("Completed blueprint({}:{}) for action({})", header.getBlueprintVersion(),
+                    header.getBlueprintName(), header.getBlueprintVersion());
+                finishLatch.countDown();
+            }
+        };
+
+        final StreamObserver<ExecutionServiceInput> requestObserver = asyncStub.process(responseObserver);
+        try {
+            // Send the message to CDS backend for processing
+            requestObserver.onNext(request);
+            // Mark the end of requests
+            requestObserver.onCompleted();
+        } catch (RuntimeException e) {
+            requestObserver.onError(e);
+        }
+        return finishLatch;
+    }
+}
diff --git a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/properties/CdsServerProperties.java b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/properties/CdsServerProperties.java
new file mode 100644 (file)
index 0000000..94a336b
--- /dev/null
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * 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.cds.properties;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterRuntimeException;
+import org.onap.policy.common.parameters.annotations.Max;
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotNull;
+
+@Getter
+@Setter
+@ToString
+public class CdsServerProperties implements ParameterGroup {
+
+    // Port range constants
+    private static final int MIN_USER_PORT = 1024;
+    private static final int MAX_USER_PORT = 65535;
+
+    private static final String INVALID_PROP = "Invalid CDS property: ";
+    private static final String SERVER_PROPERTIES_TYPE = "CDS gRPC Server Properties";
+
+    // CDS carrier properties
+    @Min(value = 1)
+    private int timeout;
+
+    @Min(value = MIN_USER_PORT)
+    @Max(value = MAX_USER_PORT)
+    private int port;
+
+    @NotNull
+    private String host;
+
+    @NotNull
+    private String username;
+
+    @NotNull
+    private String password;
+
+
+    @Override
+    public String getName() {
+        return SERVER_PROPERTIES_TYPE;
+    }
+
+    @Override
+    public void setName(final String name) {
+        throw new ParameterRuntimeException("The name of this ParameterGroup implementation is always " + getName());
+    }
+
+    @Override
+    public GroupValidationResult validate() {
+        return new GroupValidationResult(this);
+    }
+
+    /**
+     * Generate base64-encoded Authorization header from username and password.
+     *
+     * @return Base64 encoded string
+     */
+    public String getBasicAuth() {
+        return Base64.getEncoder().encodeToString(String.format("%s:%s", getUsername(), getPassword())
+            .getBytes(StandardCharsets.UTF_8));
+    }
+}
diff --git a/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/api/TestCdsProcessorListenerImpl.java b/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/api/TestCdsProcessorListenerImpl.java
new file mode 100644 (file)
index 0000000..6dfd70d
--- /dev/null
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * 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.cds.api;
+
+import io.grpc.Status;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Used as a helper for the gRPC client unit test.
+ */
+public class TestCdsProcessorListenerImpl implements CdsProcessorListener {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(TestCdsProcessorListenerImpl.class);
+
+    /**
+     * Used to verify/inspect message received from server.
+     */
+    @Override
+    public void onMessage(final ExecutionServiceOutput message) {
+        LOGGER.info("Received notification from CDS: {}", message);
+    }
+
+    /**
+     * Used to verify/inspect error received from server.
+     */
+    @Override
+    public void onError(final Throwable throwable) {
+        Status status = Status.fromThrowable(throwable);
+        LOGGER.error("Failed processing blueprint {}", status, throwable);
+    }
+}
diff --git a/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/BasicAuthClientHeaderInterceptorTest.java b/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/BasicAuthClientHeaderInterceptorTest.java
new file mode 100644 (file)
index 0000000..3b6ad7d
--- /dev/null
@@ -0,0 +1,138 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * 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.cds.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.AdditionalAnswers.delegatesTo;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import io.grpc.ClientInterceptors;
+import io.grpc.ManagedChannel;
+import io.grpc.Metadata;
+import io.grpc.Metadata.Key;
+import io.grpc.ServerCall;
+import io.grpc.ServerCall.Listener;
+import io.grpc.ServerCallHandler;
+import io.grpc.ServerInterceptor;
+import io.grpc.ServerInterceptors;
+import io.grpc.inprocess.InProcessChannelBuilder;
+import io.grpc.inprocess.InProcessServerBuilder;
+import io.grpc.stub.StreamObserver;
+import io.grpc.testing.GrpcCleanupRule;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatchers;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceStub;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
+import org.onap.policy.cds.properties.CdsServerProperties;
+
+public class BasicAuthClientHeaderInterceptorTest {
+
+    // Generate a unique in-process server name.
+    private static final String SERVER_NAME = InProcessServerBuilder.generateName();
+    private static final String CREDS = "test";
+
+    // Manages automatic graceful shutdown for the registered server and client channels at the end of test.
+    @Rule
+    public final GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();
+
+    private final ServerInterceptor mockCdsGrpcServerInterceptor = mock(ServerInterceptor.class,
+        delegatesTo(new TestServerInterceptor()));
+
+    private final CdsServerProperties props = new CdsServerProperties();
+
+    private ManagedChannel channel;
+
+    /**
+     * Setup the test.
+     *
+     * @throws IOException on failure to register the test grpc server for graceful shutdown
+     */
+    @Before
+    public void setUp() throws IOException {
+        // Setup the CDS properties
+        props.setHost(SERVER_NAME);
+        props.setPort(2000);
+        props.setUsername(CREDS);
+        props.setPassword(CREDS);
+        props.setTimeout(60);
+
+        // Implement the test gRPC server
+        BluePrintProcessingServiceImplBase testCdsBlueprintServerImpl = new BluePrintProcessingServiceImplBase() {};
+
+        // Create a server, add service, start, and register for automatic graceful shutdown.
+        grpcCleanup.register(InProcessServerBuilder.forName(SERVER_NAME).directExecutor()
+            .addService(ServerInterceptors.intercept(testCdsBlueprintServerImpl, mockCdsGrpcServerInterceptor)).build()
+            .start());
+
+        // Create a client channel and register for automatic graceful shutdown
+        channel = grpcCleanup.register(InProcessChannelBuilder.forName(SERVER_NAME).directExecutor().build());
+    }
+
+    @Test
+    public void testIfBasicAuthHeaderIsDeliveredToCdsServer() {
+        BluePrintProcessingServiceStub bpProcessingSvcStub = BluePrintProcessingServiceGrpc
+            .newStub(ClientInterceptors.intercept(channel, new BasicAuthClientHeaderInterceptor(props)));
+        ArgumentCaptor<Metadata> metadataCaptor = ArgumentCaptor.forClass(Metadata.class);
+        bpProcessingSvcStub.process(new StreamObserver<ExecutionServiceOutput>() {
+            @Override
+            public void onNext(final ExecutionServiceOutput executionServiceOutput) {
+                // Test purpose only
+            }
+
+            @Override
+            public void onError(final Throwable throwable) {
+                // Test purpose only
+            }
+
+            @Override
+            public void onCompleted() {
+                // Test purpose only
+            }
+        });
+        verify(mockCdsGrpcServerInterceptor).interceptCall(ArgumentMatchers.any(), metadataCaptor.capture(),
+            ArgumentMatchers.any());
+
+        Key<String> authHeader = Key
+            .of(BasicAuthClientHeaderInterceptor.BASIC_AUTH_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER);
+        String expectedBaseAuth = Base64.getEncoder().encodeToString(String.format("%s:%s", CREDS, CREDS)
+            .getBytes(StandardCharsets.UTF_8));
+        assertEquals(expectedBaseAuth, metadataCaptor.getValue().get(authHeader));
+    }
+
+    private static class TestServerInterceptor implements ServerInterceptor {
+
+        @Override
+        public <ReqT, RespT> Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> serverCall,
+            final Metadata metadata,
+            final ServerCallHandler<ReqT, RespT> serverCallHandler) {
+            return serverCallHandler.startCall(serverCall, metadata);
+        }
+    }
+}
+
+
diff --git a/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java b/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java
new file mode 100644 (file)
index 0000000..b9a9a84
--- /dev/null
@@ -0,0 +1,182 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * 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.cds.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import io.grpc.ManagedChannel;
+import io.grpc.inprocess.InProcessChannelBuilder;
+import io.grpc.inprocess.InProcessServerBuilder;
+import io.grpc.stub.StreamObserver;
+import io.grpc.testing.GrpcCleanupRule;
+import io.grpc.util.MutableHandlerRegistry;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
+import org.onap.policy.cds.api.CdsProcessorListener;
+import org.onap.policy.cds.api.TestCdsProcessorListenerImpl;
+import org.onap.policy.cds.properties.CdsServerProperties;
+
+public class CdsProcessorGrpcClientTest {
+
+    // Generate a unique in-process server name.
+    private static final String SERVER_NAME = InProcessServerBuilder.generateName();
+
+    // Manages automatic graceful shutdown for the registered server and client channels at the end of test.
+    @Rule
+    public final GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();
+
+    private final CdsProcessorListener listener = spy(new TestCdsProcessorListenerImpl());
+    private final CdsServerProperties props = new CdsServerProperties();
+    private final MutableHandlerRegistry serviceRegistry = new MutableHandlerRegistry();
+    private final AtomicReference<StreamObserver<ExecutionServiceOutput>> responseObserverRef = new AtomicReference<>();
+    private final List<String> messagesDelivered = new ArrayList<>();
+    private final CountDownLatch allRequestsDelivered = new CountDownLatch(1);
+
+    private CdsProcessorGrpcClient client;
+
+    /**
+     * Setup the test.
+     *
+     * @throws IOException on failure to register the test grpc server for graceful shutdown
+     */
+    @Before
+    public void setUp() throws IOException {
+        // Setup the CDS properties
+        props.setHost(SERVER_NAME);
+        props.setPort(2000);
+        props.setUsername("testUser");
+        props.setPassword("testPassword");
+        props.setTimeout(60);
+
+        // Create a server, add service, start, and register for automatic graceful shutdown.
+        grpcCleanup.register(InProcessServerBuilder.forName(SERVER_NAME)
+            .fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start());
+
+        // Create a client channel and register for automatic graceful shutdown
+        ManagedChannel channel = grpcCleanup
+            .register(InProcessChannelBuilder.forName(SERVER_NAME).directExecutor().build());
+
+        // Create an instance of the gRPC client
+        client = new CdsProcessorGrpcClient(channel, new CdsProcessorHandler(listener));
+
+        // Implement the test gRPC server
+        BluePrintProcessingServiceImplBase testCdsBlueprintServerImpl = new BluePrintProcessingServiceImplBase() {
+            @Override
+            public StreamObserver<ExecutionServiceInput> process(
+                final StreamObserver<ExecutionServiceOutput> responseObserver) {
+                responseObserverRef.set(responseObserver);
+
+                return new StreamObserver<ExecutionServiceInput>() {
+                    @Override
+                    public void onNext(final ExecutionServiceInput executionServiceInput) {
+                        messagesDelivered.add(executionServiceInput.getActionIdentifiers().getActionName());
+                    }
+
+                    @Override
+                    public void onError(final Throwable throwable) {
+                        // Test method
+                    }
+
+                    @Override
+                    public void onCompleted() {
+                        allRequestsDelivered.countDown();
+                    }
+                };
+            }
+        };
+        serviceRegistry.addService(testCdsBlueprintServerImpl);
+    }
+
+    @After
+    public void tearDown() {
+        client.close();
+    }
+
+    @Test
+    public void testCdsProcessorGrpcClientConstructor() {
+        new CdsProcessorGrpcClient(listener, props);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testCdsProcessorGrpcClientConstructorFailure() {
+        props.setHost(null);
+        new CdsProcessorGrpcClient(listener, props);
+    }
+
+    @Test
+    public void testSendRequestFail() throws InterruptedException {
+        // Setup
+        ExecutionServiceInput testReq = ExecutionServiceInput.newBuilder()
+            .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("policy-to-cds").build())
+            .build();
+
+        // Act
+        CountDownLatch finishLatch = client.sendRequest(testReq);
+        responseObserverRef.get().onError(new Throwable("failed to send testReq."));
+
+        verify(listener).onError(any(Throwable.class));
+        assertTrue(finishLatch.await(0, TimeUnit.SECONDS));
+    }
+
+    @Test
+    public void testSendRequestSuccess() throws InterruptedException {
+        // Setup request
+        ExecutionServiceInput testReq1 = ExecutionServiceInput.newBuilder()
+            .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("policy-to-cds-req1").build()).build();
+
+        // Act
+        final CountDownLatch finishLatch = client.sendRequest(testReq1);
+
+        // Assert that request message was sent and delivered once to the server
+        assertTrue(allRequestsDelivered.await(1, TimeUnit.SECONDS));
+        assertEquals(Collections.singletonList("policy-to-cds-req1"), messagesDelivered);
+
+        // Setup the server to send out two simple response messages and verify that the client receives them.
+        ExecutionServiceOutput testResp1 = ExecutionServiceOutput.newBuilder()
+            .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("policy-to-cds-resp1").build()).build();
+        ExecutionServiceOutput testResp2 = ExecutionServiceOutput.newBuilder()
+            .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("policy-to-cds-resp2").build()).build();
+        responseObserverRef.get().onNext(testResp1);
+        verify(listener).onMessage(testResp1);
+        responseObserverRef.get().onNext(testResp2);
+        verify(listener).onMessage(testResp2);
+
+        // let server complete.
+        responseObserverRef.get().onCompleted();
+        assertTrue(finishLatch.await(0, TimeUnit.SECONDS));
+    }
+}
index 854d4d1..122b01e 100644 (file)
@@ -26,7 +26,7 @@
   <parent>
     <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
     <artifactId>model-impl</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>events</artifactId>
index 8184a98..48ab79a 100644 (file)
@@ -27,7 +27,7 @@
   <parent>
       <groupId>org.onap.policy.models</groupId>
       <artifactId>policy-models-interactions</artifactId>
-      <version>2.0.2-SNAPSHOT</version>
+      <version>2.1.0-SNAPSHOT</version>
   </parent>
   
   <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
@@ -44,7 +44,6 @@
       <module>sdc</module>
       <module>vfc</module>
       <module>sdnc</module>
+      <module>cds</module>
   </modules>
-
-
 </project>
index 8629067..eda1373 100644 (file)
@@ -26,7 +26,7 @@
   <parent>
     <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
     <artifactId>model-impl</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>rest</artifactId>
index db833b2..dd94200 100644 (file)
@@ -26,7 +26,7 @@
     <parent>
         <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
         <artifactId>model-impl</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>sdc</artifactId>
index bd5000e..4fc3375 100644 (file)
@@ -24,7 +24,7 @@
   <parent>
         <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
         <artifactId>model-impl</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>sdnc</artifactId>
index 9b00f02..54d73b3 100644 (file)
@@ -27,7 +27,7 @@
   <parent>
         <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
         <artifactId>model-impl</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
    </parent>
 
   <artifactId>sdnr</artifactId>
index 1d23c2e..59a0e7e 100644 (file)
@@ -26,7 +26,7 @@
   <parent>
         <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
         <artifactId>model-impl</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>so</artifactId>
index 08a7dee..4d7a7ad 100644 (file)
@@ -24,7 +24,7 @@
   <parent>
         <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
         <artifactId>model-impl</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
   <artifactId>vfc</artifactId>
index e03cda6..a9aa644 100644 (file)
@@ -25,7 +25,7 @@
   <parent>
     <groupId>org.onap.policy.models</groupId>
     <artifactId>policy-models-interactions</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <groupId>org.onap.policy.models.policy-models-interactions</groupId>
index 875a685..fad8419 100644 (file)
@@ -25,7 +25,7 @@
   <parent>
     <groupId>org.onap.policy.models</groupId>
     <artifactId>policy-models-interactions</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <groupId>org.onap.policy.models.policy-models-interactions</groupId>
index 3858225..5694391 100644 (file)
@@ -23,7 +23,7 @@
   <parent>
     <groupId>org.onap.policy.models</groupId>
     <artifactId>policy-models</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
   <artifactId>policy-models-interactions</artifactId>
   <packaging>pom</packaging>
index 208558d..0b71e9a 100644 (file)
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.onap.policy.models</groupId>
         <artifactId>policy-models</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>policy-models-pap</artifactId>
index 76a59ab..13f8599 100644 (file)
@@ -25,7 +25,7 @@
     <parent>
         <groupId>org.onap.policy.models</groupId>
         <artifactId>policy-models</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>policy-models-pdp</artifactId>
index e6ca59c..d3186fa 100644 (file)
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.onap.policy.models</groupId>
         <artifactId>policy-models</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>policy-models-provider</artifactId>
index a70e214..6253436 100644 (file)
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.onap.policy.models.sim</groupId>
         <artifactId>policy-models-sim</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>policy-models-sim-dmaap</artifactId>
index fa11474..75f08a1 100644 (file)
@@ -1,6 +1,7 @@
 #
 # ============LICENSE_START=======================================================
 #  Copyright (C) 2019 Nordix Foundation.
+#  Modifications Copyright (C) 2019 AT&T Intellectual Property.
 # ================================================================================
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -66,7 +67,7 @@ RUN tar xvfz /packages/policy-models-sim-dmaap-tarball.tar.gz --directory ${POLI
 COPY dmaap-sim.sh ${POLICY_HOME}/dmaap-sim/bin
 RUN find /opt/app -type d -perm 755 \
     && find /opt/app -type f -perm 644 \
-    && chmod a+x ${POLICY_HOME}/dmaap-sim/bin/*
+    && chmod 755 ${POLICY_HOME}/dmaap-sim/bin/*
 
 USER policy
 ENV PATH ${POLICY_HOME}/dmaap-sim/bin:$PATH
index 01cedd4..110a4aa 100644 (file)
@@ -5,7 +5,7 @@
   <parent>
     <groupId>org.onap.policy.models.sim</groupId>
     <artifactId>policy-models-sim</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
   <artifactId>policy-models-sim-pdp</artifactId>
   <name>policy-models-sim-pdp</name>
index 93a3c9b..51e7eaa 100644 (file)
@@ -1,6 +1,7 @@
 #
 # ============LICENSE_START=======================================================
 #  Copyright (C) 2019 Nordix Foundation.
+#  Modifications Copyright (C) 2019 AT&T Intellectual Property.
 # ================================================================================
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -66,7 +67,7 @@ RUN tar xvfz /packages/policy-models-sim-pdp-tarball.tar.gz --directory ${POLICY
 COPY pdp-sim.sh ${POLICY_HOME}/pdp-sim/bin
 RUN find /opt/app -type d -perm 755 \
     && find /opt/app -type f -perm 644 \
-    && chmod a+x ${POLICY_HOME}/pdp-sim/bin/*
+    && chmod 755 ${POLICY_HOME}/pdp-sim/bin/*
 
 USER policy
 ENV PATH ${POLICY_HOME}/pdp-sim/bin:$PATH
index d638b07..66865c1 100644 (file)
@@ -23,7 +23,7 @@
   <parent>
     <groupId>org.onap.policy.models</groupId>
     <artifactId>policy-models</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
   </parent>
 
   <groupId>org.onap.policy.models.sim</groupId>
index 3072ce3..0b45799 100644 (file)
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.onap.policy.models</groupId>
         <artifactId>policy-models</artifactId>
-        <version>2.0.2-SNAPSHOT</version>
+        <version>2.1.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>policy-models-tosca</artifactId>
index 1c414ee..a664010 100644 (file)
@@ -115,7 +115,7 @@ public class LegacyGuardPolicyMapper
 
             final LegacyGuardPolicyOutput legacyGuardPolicyOutput = new LegacyGuardPolicyOutput();
             legacyGuardPolicyOutput.setType(toscaPolicy.getType().getName());
-            legacyGuardPolicyOutput.setVersion(toscaPolicy.getType().getVersion());
+            legacyGuardPolicyOutput.setVersion(toscaPolicy.getKey().getVersion());
 
             if (toscaPolicy.getMetadata() == null) {
                 String errorMessage = "no metadata defined on TOSCA policy";
@@ -123,14 +123,11 @@ public class LegacyGuardPolicyMapper
                 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
             }
 
-            final Map<String, Object> metadata = new LinkedHashMap<>();
-            for (Entry<String, String> metadataEntry : toscaPolicy.getMetadata().entrySet()) {
-                if (POLICY_VERSION.equals(metadataEntry.getKey())) {
-                    metadata.put(POLICY_VERSION, Integer.parseInt(metadataEntry.getValue()));
-                } else {
-                    metadata.put(metadataEntry.getKey(), metadataEntry.getValue());
-                }
-            }
+            final Map<String, Object> metadata = new LinkedHashMap<>(toscaPolicy.getMetadata());
+
+            // if version exists, convert it to int
+            metadata.computeIfPresent(POLICY_VERSION, (key,val) -> Integer.parseInt(val.toString()));
+
             legacyGuardPolicyOutput.setMetadata(metadata);
 
             if (toscaPolicy.getProperties() == null) {
index f2fb53d..6d32c6d 100644 (file)
 package org.onap.policy.models.tosca.legacy.mapping;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
 
 import java.util.LinkedHashMap;
-
+import java.util.Map;
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@@ -44,7 +46,7 @@ public class LegacyGuardPolicyMapperTest {
         serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
         serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
 
-        JpaToscaPolicy policy = new JpaToscaPolicy(new PfConceptKey("PolicyName", "0.0.1"));
+        JpaToscaPolicy policy = new JpaToscaPolicy(new PfConceptKey("PolicyName", "2.0.0"));
         serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy.getKey(), policy);
 
         assertThatThrownBy(() -> {
@@ -55,5 +57,11 @@ public class LegacyGuardPolicyMapperTest {
         assertThatThrownBy(() -> {
             new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
         }).hasMessageContaining("no properties defined on TOSCA policy");
+
+        policy.setProperties(new LinkedHashMap<>());
+        Map<String, LegacyGuardPolicyOutput> guardPolicyMap =
+                new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
+        LegacyGuardPolicyOutput guardPolicy = guardPolicyMap.values().iterator().next();
+        assertEquals("2.0.0", guardPolicy.getVersion());
     }
 }
diff --git a/pom.xml b/pom.xml
index 48f1d60..bf97d1c 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     <parent>
         <groupId>org.onap.policy.parent</groupId>
         <artifactId>integration</artifactId>
-        <version>2.1.0</version>
+        <version>3.0.0-SNAPSHOT</version>
         <relativePath/>
     </parent>
 
     <groupId>org.onap.policy.models</groupId>
     <artifactId>policy-models</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
 
     <packaging>pom</packaging>
     <name>policy-models</name>
     <properties>
         <derby.version>10.13.1.1</derby.version>
         <javax.ws.rs-api.version>2.0.1</javax.ws.rs-api.version>
-        <policy.common.version>1.4.0</policy.common.version>
 
         <!-- sonar/jacoco overrides -->
         <!-- Overriding oparent default sonar/jacoco settings Combine all our reports into one file shared across sub-modules -->
         <sonar.jacoco.reportPath>${project.basedir}/../target/code-coverage/jacoco-ut.exec</sonar.jacoco.reportPath>
         <sonar.jacoco.itReportPath>${project.basedir}/../target/code-coverage/jacoco-it.exec</sonar.jacoco.itReportPath>
         <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
+
+        <policy.common.version>1.5.0-SNAPSHOT</policy.common.version>
     </properties>
 
     <modules>
index bb52871..614e56e 100644 (file)
@@ -3,8 +3,8 @@
 # because they are used in Jenkins, whose plug-in doesn't support
 
 major=2
-minor=0
-patch=2
+minor=1
+patch=0
 
 base_version=${major}.${minor}.${patch}