summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdate.java3
-rw-r--r--participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java1
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java2
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java31
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java9
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java27
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java153
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java1
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java7
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java5
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java6
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java36
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java2
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java1
-rw-r--r--runtime-controlloop/src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml6
16 files changed, 180 insertions, 114 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java
index b99759eb3..67bcb5348 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java
@@ -31,6 +31,7 @@ import lombok.ToString;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
* Class to represent a control loop instance.
@@ -57,6 +58,8 @@ public class ControlLoopElement {
@NonNull
private ControlLoopOrderedState orderedState = ControlLoopOrderedState.UNINITIALISED;
+ private ToscaServiceTemplate toscaServiceTemplateFragment;
+
private String description;
private ClElementStatistics clElementStatistics;
@@ -77,6 +80,7 @@ public class ControlLoopElement {
this.participantId = new ToscaConceptIdentifier(otherElement.participantId);
this.state = otherElement.state;
this.orderedState = otherElement.orderedState;
+ this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment;
this.description = otherElement.description;
this.clElementStatistics = otherElement.clElementStatistics;
this.commonPropertiesMap = PfUtils.mapMap(otherElement.commonPropertiesMap, UnaryOperator.identity());
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdate.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdate.java
index 5c1b67905..51cce5377 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdate.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdate.java
@@ -41,8 +41,6 @@ public class ParticipantUpdate extends ParticipantMessage {
// A list of updates to ParticipantDefinitions
private List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
- private ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
-
/**
* Constructor for instantiating ParticipantUpdate class with message name.
*
@@ -61,6 +59,5 @@ public class ParticipantUpdate extends ParticipantMessage {
this.participantDefinitionUpdates = PfUtils.mapList(source.participantDefinitionUpdates,
ParticipantDefinition::new);
- this.toscaServiceTemplate = source.toscaServiceTemplate;
}
}
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java
index da65f7e15..26f9cd4b9 100644
--- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java
@@ -236,7 +236,6 @@ public class TestListenerUtils {
}
participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates);
- participantUpdateMsg.setToscaServiceTemplate(toscaServiceTemplate);
return participantUpdateMsg;
}
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java
index b17ae4311..4f8dcf1f9 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java
@@ -130,7 +130,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
throws PfModelException {
intermediaryApi.updateControlLoopElementState(element.getId(), element.getOrderedState(),
ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE);
- ToscaServiceTemplate controlLoopDefinition = intermediaryApi.getToscaServiceTemplate();
+ ToscaServiceTemplate controlLoopDefinition = element.getToscaServiceTemplateFragment();
if (controlLoopDefinition.getToscaTopologyTemplate() != null) {
if (controlLoopDefinition.getPolicyTypes() != null) {
for (ToscaPolicyType policyType : controlLoopDefinition.getPolicyTypes().values()) {
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
index f8b8e2cad..a33fa0a58 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
@@ -50,6 +50,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,6 +61,8 @@ public class TestListenerUtils {
static CommonTestData commonTestData = new CommonTestData();
private static final Logger LOGGER = LoggerFactory.getLogger(TestListenerUtils.class);
private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
+ private static final String POLICY_TYPE_ID = "policy_type_id";
+ private static final String POLICY_ID = "policy_id";
private TestListenerUtils() {}
@@ -147,6 +150,7 @@ public class TestListenerUtils {
Map<UUID, ControlLoopElement> elements = new LinkedHashMap<>();
ToscaServiceTemplate toscaServiceTemplate = testControlLoopRead();
+ TestListenerUtils.addPoliciesToToscaServiceTemplate(toscaServiceTemplate);
Map<String, ToscaNodeTemplate> nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) {
@@ -176,12 +180,38 @@ public class TestListenerUtils {
List<ParticipantUpdates> participantUpdates = new ArrayList<>();
for (ControlLoopElement element : elements.values()) {
+ populateToscaNodeTemplateFragment(element, toscaServiceTemplate);
prepareParticipantUpdateForControlLoop(element, participantUpdates);
}
clUpdateMsg.setParticipantUpdatesList(participantUpdates);
return clUpdateMsg;
}
+ private static void populateToscaNodeTemplateFragment(ControlLoopElement clElement,
+ ToscaServiceTemplate toscaServiceTemplate) {
+ ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate
+ .getToscaTopologyTemplate().getNodeTemplates().get(clElement.getDefinition().getName());
+ // If the ControlLoopElement has policy_type_id or policy_id, identify it as a PolicyControlLoopElement
+ // and pass respective PolicyTypes or Policies as part of toscaServiceTemplateFragment
+ if ((toscaNodeTemplate.getProperties().get(POLICY_TYPE_ID) != null)
+ || (toscaNodeTemplate.getProperties().get(POLICY_ID) != null)) {
+ // ControlLoopElement for policy framework, send policies and policyTypes to participants
+ if ((toscaServiceTemplate.getPolicyTypes() != null)
+ || (toscaServiceTemplate.getToscaTopologyTemplate().getPolicies() != null)) {
+ ToscaServiceTemplate toscaServiceTemplateFragment = new ToscaServiceTemplate();
+ toscaServiceTemplateFragment.setPolicyTypes(toscaServiceTemplate.getPolicyTypes());
+
+ ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate();
+ toscaTopologyTemplate.setPolicies(toscaServiceTemplate.getToscaTopologyTemplate().getPolicies());
+ toscaServiceTemplateFragment.setToscaTopologyTemplate(toscaTopologyTemplate);
+
+ toscaServiceTemplateFragment.setDataTypes(toscaServiceTemplate.getDataTypes());
+
+ clElement.setToscaServiceTemplateFragment(toscaServiceTemplateFragment);
+ }
+ }
+ }
+
private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement,
List<ParticipantUpdates> participantUpdates) {
if (participantUpdates.isEmpty()) {
@@ -248,7 +278,6 @@ public class TestListenerUtils {
}
participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates);
- participantUpdateMsg.setToscaServiceTemplate(toscaServiceTemplate);
return participantUpdateMsg;
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
index e84a7fc0a..16da5cf7f 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
@@ -22,7 +22,9 @@ package org.onap.policy.clamp.controlloop.participant.simulator.config;
import java.util.List;
import org.springframework.context.annotation.Configuration;
+import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@@ -30,6 +32,11 @@ public class YamlConfiguration implements WebMvcConfigurer {
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
- converters.add(new YamlHttpMessageConverter<>());
+ converters.add(new YamlHttpMessageConverter<>("yaml"));
+ converters.add(new YamlHttpMessageConverter<>("json"));
+
+ StringHttpMessageConverter converter = new StringHttpMessageConverter();
+ converter.setSupportedMediaTypes(List.of(MediaType.TEXT_PLAIN));
+ converters.add(converter);
}
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java
index 3e1059835..d9a72ce10 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java
@@ -23,20 +23,29 @@
package org.onap.policy.clamp.controlloop.participant.simulator.config;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
+import javax.ws.rs.core.Response;
+import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.AbstractHttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
-import org.yaml.snakeyaml.Yaml;
public class YamlHttpMessageConverter<T> extends AbstractHttpMessageConverter<T> {
- public YamlHttpMessageConverter() {
- super(new MediaType("application", "yaml"));
+ private Coder coder;
+
+ public YamlHttpMessageConverter(String type) {
+ super(new MediaType("application", type, StandardCharsets.UTF_8));
+ this.coder = "json".equals(type) ? new StandardCoder() : new StandardYamlCoder();
}
@Override
@@ -47,16 +56,20 @@ public class YamlHttpMessageConverter<T> extends AbstractHttpMessageConverter<T>
@Override
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
- var yaml = new Yaml();
- return yaml.loadAs(inputMessage.getBody(), clazz);
+ try (var is = new InputStreamReader(inputMessage.getBody(), StandardCharsets.UTF_8)) {
+ return coder.decode(is, clazz);
+ } catch (CoderException e) {
+ throw new ControlLoopRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e);
+ }
}
@Override
protected void writeInternal(T t, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
- var yaml = new Yaml();
try (var writer = new OutputStreamWriter(outputMessage.getBody(), StandardCharsets.UTF_8)) {
- yaml.dump(t, writer);
+ coder.encode(writer, t);
+ } catch (CoderException e) {
+ throw new ControlLoopRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e);
}
}
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
index a9dea1748..14f51269a 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
@@ -25,10 +25,20 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
@@ -45,21 +55,13 @@ import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.C
import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.AbstractRestController;
import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.TestListenerUtils;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
-import org.springframework.core.ParameterizedTypeReference;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -73,8 +75,6 @@ class ParticipantSimulatorTest {
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
private static final String TOPIC = "my-topic";
- public static final Coder coder = new StandardCoder();
-
@Value("${spring.security.user.name}")
private String user;
@@ -85,9 +85,6 @@ class ParticipantSimulatorTest {
private int randomServerPort;
@Autowired
- private TestRestTemplate restTemplate;
-
- @Autowired
private ParticipantIntermediaryApi participantIntermediaryApi;
@Autowired
@@ -100,11 +97,9 @@ class ParticipantSimulatorTest {
synchronized (lockit) {
if (!check) {
check = true;
- ControlLoopUpdateListener clUpdateListener =
- new ControlLoopUpdateListener(participantHandler);
+ ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
- ControlLoopUpdate controlLoopUpdateMsg =
- TestListenerUtils.createControlLoopUpdateMsg();
+ ControlLoopUpdate controlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
clUpdateListener.onTopicEvent(INFRA, TOPIC, null, controlLoopUpdateMsg);
}
@@ -116,11 +111,18 @@ class ParticipantSimulatorTest {
}
void testSwagger(String endPoint) {
- HttpEntity<Void> request = new HttpEntity<>(null, createHttpHeaders());
- ResponseEntity<String> response =
- restTemplate.exchange(getPath("api-docs"), HttpMethod.GET, request, String.class);
- assertThat(response.getStatusCodeValue()).isEqualTo(200);
- assertTrue(response.getBody().contains("/onap/participantsim/v2/" + endPoint));
+ final Client client = ClientBuilder.newBuilder().build();
+
+ client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
+ client.register(GsonMessageBodyHandler.class);
+ client.register(HttpAuthenticationFeature.basic(user, password));
+
+ final WebTarget webTarget = client.target(getPath("api-docs"));
+
+ Response response = webTarget.request(MediaType.APPLICATION_JSON).get();
+
+ assertThat(response.getStatus()).isEqualTo(200);
+ assertTrue(response.readEntity(String.class).contains("/onap/participantsim/v2/" + endPoint));
}
@Test
@@ -135,59 +137,49 @@ class ParticipantSimulatorTest {
@Test
void testProducerYaml() {
- MediaType yamlMediaType = new MediaType("application", "yaml");
- HttpHeaders headers = createHttpHeaders();
- headers.setAccept(Collections.singletonList(yamlMediaType));
- HttpEntity<Void> request = new HttpEntity<>(null, headers);
+ final Client client = ClientBuilder.newBuilder().build();
+
+ client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
+ client.register(GsonMessageBodyHandler.class);
+ client.register(HttpAuthenticationFeature.basic(user, password));
+
String path = getPath(PARTICIPANTS_ENDPOINT + "/org.onap.PM_CDS_Blueprint/1");
+ final WebTarget webTarget = client.target(path);
- ResponseEntity<String> response = restTemplate.exchange(path, HttpMethod.GET, request, String.class);
+ Response response = webTarget.request("application/yaml").get();
- assertThat(response.getStatusCodeValue()).isEqualTo(200);
- assertTrue(response.getHeaders().getContentType().isCompatibleWith(yamlMediaType));
+ assertThat(response.getStatus()).isEqualTo(200);
}
@Test
void testQuery_Unauthorized() throws Exception {
- String path = getPath(PARTICIPANTS_ENDPOINT + "/org.onap.PM_CDS_Blueprint/1");
+ String path = PARTICIPANTS_ENDPOINT + "/org.onap.PM_CDS_Blueprint/1";
- // authorized call
- ResponseEntity<String> response =
- restTemplate.exchange(path, HttpMethod.GET, new HttpEntity<>(null, createHttpHeaders()), String.class);
- assertThat(response.getStatusCodeValue()).isEqualTo(200);
+ Response response = performRequest(path, true, null).get();
+ assertThat(response.getStatus()).isEqualTo(200);
// unauthorized call
- response = restTemplate.exchange(path, HttpMethod.GET, new HttpEntity<>(null, new HttpHeaders()), String.class);
- assertThat(response.getStatusCodeValue()).isEqualTo(401);
+ response = performRequest(path, false, null).get();
+ assertThat(response.getStatus()).isEqualTo(401);
}
- private HttpHeaders createHttpHeaders() {
- HttpHeaders headers = new HttpHeaders();
- headers.setBasicAuth(user, password);
- return headers;
- }
+ private Invocation.Builder performRequest(String endpoint, boolean includeAuth, UUID uuid) {
+ final Client client = ClientBuilder.newBuilder().build();
- protected <T> ResponseEntity<T> performGet(String endpoint, Class<T> responseType, UUID uuid) throws Exception {
- HttpHeaders httpHeaders = createHttpHeaders();
+ client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
+ client.register(GsonMessageBodyHandler.class);
+ if (includeAuth) {
+ client.register(HttpAuthenticationFeature.basic(user, password));
+ }
+ Invocation.Builder builder = client.target(getPath(endpoint)).request(MediaType.APPLICATION_JSON);
if (uuid != null) {
- httpHeaders.add(AbstractRestController.REQUEST_ID_NAME, uuid.toString());
+ builder = builder.header(AbstractRestController.REQUEST_ID_NAME, uuid.toString());
}
- HttpEntity<Void> request = new HttpEntity<>(null, httpHeaders);
- return restTemplate.exchange(getPath(endpoint), HttpMethod.GET, request, responseType);
+ return builder;
}
- protected <T> ResponseEntity<T> performGet(String endpoint, Class<T> responseType) throws Exception {
- return performGet(endpoint, responseType, null);
- }
-
- protected <T, R> ResponseEntity<R> performPut(String path, T body, ParameterizedTypeReference<R> responseType,
- UUID uuid) throws Exception {
- HttpHeaders httpHeaders = createHttpHeaders();
- if (uuid != null) {
- httpHeaders.add(AbstractRestController.REQUEST_ID_NAME, uuid.toString());
- }
- HttpEntity<T> request = new HttpEntity<>(body, httpHeaders);
- return restTemplate.exchange(getPath(path), HttpMethod.PUT, request, responseType);
+ private Response performGet(String endpoint, UUID uuid) throws Exception {
+ return performRequest(endpoint, true, uuid).get();
}
@Test
@@ -200,29 +192,30 @@ class ParticipantSimulatorTest {
UUID uuid = UUID.randomUUID();
// GET REST call for querying the participants
- ResponseEntity<String> response = performGet(
+ Response response = performGet(
PARTICIPANTS_ENDPOINT + "/" + participant.getKey().getName() + "/" + participant.getKey().getVersion(),
- String.class, uuid);
+ uuid);
checkResponseEntity(response, 200, uuid);
- Participant[] returnValue = coder.decode(response.getBody(), Participant[].class);
+ Participant[] returnValue = response.readEntity(Participant[].class);
assertThat(returnValue).hasSize(1);
// Verify the result of GET participants with what is stored
assertEquals(participant.getDefinition(), returnValue[0].getDefinition());
}
- private <T> void checkResponseEntity(ResponseEntity<T> response, int status, UUID uuid) {
- assertThat(response.getStatusCodeValue()).isEqualTo(status);
+ private <T> void checkResponseEntity(Response response, int status, UUID uuid) {
+ assertThat(response.getStatus()).isEqualTo(status);
assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_MINOR_NAME)).isEqualTo("0");
assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_PATCH_NAME)).isEqualTo("0");
assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_LATEST_NAME)).isEqualTo("1.0.0");
assertThat(getHeader(response.getHeaders(), AbstractRestController.REQUEST_ID_NAME)).isEqualTo(uuid.toString());
}
- private String getHeader(HttpHeaders httpHeaders, String param) {
- List<String> list = httpHeaders.get(param);
+ private String getHeader(MultivaluedMap<String, Object> httpHeaders, String param) {
+ List<Object> list = httpHeaders.get(param);
assertThat(list).hasSize(1);
- return list.get(0);
+ assertThat(list.get(0)).isNotNull();
+ return (String) list.get(0);
}
@Test
@@ -232,16 +225,19 @@ class ParticipantSimulatorTest {
ToscaConceptIdentifier participantId = CommonTestData.getParticipantId();
// GET REST call for querying the controlLoop elements
- ResponseEntity<String> response =
- performGet(ELEMENTS_ENDPOINT + "/" + participantId.getName() + "/" + participantId.getVersion(),
- String.class, uuid);
+ Response response =
+ performGet(ELEMENTS_ENDPOINT + "/" + participantId.getName() + "/" + participantId.getVersion(), uuid);
checkResponseEntity(response, 200, uuid);
- Map<?, ?> returnValue = coder.decode(response.getBody(), Map.class);
+ Map<?, ?> returnValue = response.readEntity(Map.class);
// Verify the result of GET controlloop elements with what is stored
assertThat(returnValue).isEmpty();
}
+ private Response performPut(String endpoint, final Entity<?> entity, UUID uuid) throws Exception {
+ return performRequest(endpoint, true, uuid).put(entity);
+ }
+
@Test
void testUpdateParticipant() throws Exception {
setUp();
@@ -253,11 +249,11 @@ class ParticipantSimulatorTest {
UUID uuid = UUID.randomUUID();
// PUT REST call for updating Participant
- ResponseEntity<TypedSimpleResponse<Participant>> response = performPut(PARTICIPANTS_ENDPOINT,
- participants.get(0), new ParameterizedTypeReference<TypedSimpleResponse<Participant>>() {}, uuid);
+ Response response = performPut(PARTICIPANTS_ENDPOINT, Entity.json(participants.get(0)), uuid);
checkResponseEntity(response, 200, uuid);
- TypedSimpleResponse<Participant> resp = response.getBody();
+ TypedSimpleResponse<Participant> resp =
+ response.readEntity(new GenericType<TypedSimpleResponse<Participant>>() {});
assertNotNull(resp.getResponse());
// Verify the response and state returned by PUT REST call for updating participants
assertEquals(participants.get(0).getDefinition(), resp.getResponse().getDefinition());
@@ -275,13 +271,12 @@ class ParticipantSimulatorTest {
ControlLoopElement controlLoopElement = controlLoopElements.get(uuid);
controlLoopElement.setOrderedState(ControlLoopOrderedState.PASSIVE);
-
// PUT REST call for updating ControlLoopElement
- ResponseEntity<TypedSimpleResponse<ControlLoopElement>> response = performPut(ELEMENTS_ENDPOINT,
- controlLoopElement, new ParameterizedTypeReference<TypedSimpleResponse<ControlLoopElement>>() {}, uuid);
+ Response response = performPut(ELEMENTS_ENDPOINT, Entity.json(controlLoopElement), uuid);
checkResponseEntity(response, 200, uuid);
- TypedSimpleResponse<ControlLoopElement> resp = response.getBody();
+ TypedSimpleResponse<ControlLoopElement> resp =
+ response.readEntity(new GenericType<TypedSimpleResponse<ControlLoopElement>>() {});
assertNotNull(resp.getResponse());
// Verify the response and state returned by PUT REST call for updating participants
assertEquals(controlLoopElement.getDefinition(), resp.getResponse().getDefinition());
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
index 2759a9390..56be0817f 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
@@ -243,7 +243,6 @@ public class TestListenerUtils {
}
participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates);
- participantUpdateMsg.setToscaServiceTemplate(toscaServiceTemplate);
return participantUpdateMsg;
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
index ed0aea4b3..2ca14fdea 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
@@ -101,13 +101,6 @@ public interface ParticipantIntermediaryApi {
Map<UUID, ControlLoopElement> getControlLoopElements(String name, String version);
/**
- * Get ToscaServiceTemplate from the intermediary API.
- *
- * @return the control loop element
- */
- ToscaServiceTemplate getToscaServiceTemplate();
-
- /**
* Get control loop element from the intermediary API.
*
* @param id control loop element ID
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
index ded102f5a..f6d7cd161 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
@@ -122,11 +122,6 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
}
@Override
- public ToscaServiceTemplate getToscaServiceTemplate() {
- return participantHandler.getToscaServiceTemplate();
- }
-
- @Override
public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState currentState,
ControlLoopState newState, ParticipantMessageType messageType) {
return participantHandler.getControlLoopHandler().updateControlLoopElementState(id, currentState, newState,
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
index 134bda6bb..072a2ebc1 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
@@ -59,7 +59,6 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.comm.Participa
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -86,8 +85,6 @@ public class ParticipantHandler {
private final List<ControlLoopElementDefinition> clElementDefsOnThisParticipant = new ArrayList<>();
- private ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
-
/**
* Constructor, set the participant ID and sender.
*
@@ -292,8 +289,7 @@ public class ParticipantHandler {
return;
}
- toscaServiceTemplate = participantUpdateMsg.getToscaServiceTemplate();
- if (toscaServiceTemplate != null) {
+ if (!participantUpdateMsg.getParticipantDefinitionUpdates().isEmpty()) {
// This message is to commission the controlloop
for (ParticipantDefinition participantDefinition : participantUpdateMsg.getParticipantDefinitionUpdates()) {
if (participantDefinition.getParticipantType().equals(participantType)) {
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java
index 6df030d32..d68a643d2 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java
@@ -31,6 +31,11 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUpdates;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -43,6 +48,9 @@ import org.springframework.stereotype.Component;
public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<ControlLoopUpdate> {
private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopUpdatePublisher.class);
+ private static final String POLICY_TYPE_ID = "policy_type_id";
+ private static final String POLICY_ID = "policy_id";
+ private final PolicyModelsProvider modelsProvider;
/**
* Send ControlLoopUpdate to Participant.
@@ -54,9 +62,37 @@ public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<Con
controlLoopUpdateMsg.setControlLoopId(controlLoop.getKey().asIdentifier());
controlLoopUpdateMsg.setMessageId(UUID.randomUUID());
controlLoopUpdateMsg.setTimestamp(Instant.now());
+ ToscaServiceTemplate toscaServiceTemplate;
+ try {
+ toscaServiceTemplate = modelsProvider.getServiceTemplateList(null, null).get(0);
+ } catch (PfModelException pfme) {
+ LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
+ return;
+ }
List<ParticipantUpdates> participantUpdates = new ArrayList<>();
for (ControlLoopElement element : controlLoop.getElements().values()) {
+ ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate
+ .getToscaTopologyTemplate().getNodeTemplates().get(element.getDefinition().getName());
+ // If the ControlLoopElement has policy_type_id or policy_id, identify it as a PolicyControlLoopElement
+ // and pass respective PolicyTypes or Policies as part of toscaServiceTemplateFragment
+ if ((toscaNodeTemplate.getProperties().get(POLICY_TYPE_ID) != null)
+ || (toscaNodeTemplate.getProperties().get(POLICY_ID) != null)) {
+ // ControlLoopElement for policy framework, send policies and policyTypes to participants
+ if ((toscaServiceTemplate.getPolicyTypes() != null)
+ || (toscaServiceTemplate.getToscaTopologyTemplate().getPolicies() != null)) {
+ ToscaServiceTemplate toscaServiceTemplateFragment = new ToscaServiceTemplate();
+ toscaServiceTemplateFragment.setPolicyTypes(toscaServiceTemplate.getPolicyTypes());
+
+ ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate();
+ toscaTopologyTemplate.setPolicies(toscaServiceTemplate.getToscaTopologyTemplate().getPolicies());
+ toscaServiceTemplateFragment.setToscaTopologyTemplate(toscaTopologyTemplate);
+
+ toscaServiceTemplateFragment.setDataTypes(toscaServiceTemplate.getDataTypes());
+
+ element.setToscaServiceTemplateFragment(toscaServiceTemplateFragment);
+ }
+ }
prepareParticipantUpdate(element, participantUpdates);
}
controlLoopUpdateMsg.setParticipantUpdatesList(participantUpdates);
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java
index 41ed4e291..c820bf3f1 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java
@@ -95,11 +95,9 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
if (commissionFlag) {
// Commission the controlloop but sending participantdefinitions to participants
message.setParticipantDefinitionUpdates(participantDefinitionUpdates);
- message.setToscaServiceTemplate(toscaServiceTemplate);
} else {
// DeCommission the controlloop but deleting participantdefinitions on participants
message.setParticipantDefinitionUpdates(null);
- message.setToscaServiceTemplate(null);
}
LOGGER.debug("Participant Update sent {}", message);
super.send(message);
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
index 4cfcf1508..64bf6b009 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -206,7 +206,6 @@ class SupervisionMessagesTest extends CommonRestController {
}
participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates);
- participantUpdateMsg.setToscaServiceTemplate(toscaServiceTemplate);
synchronized (lockit) {
ParticipantUpdatePublisher participantUpdatePublisher =
new ParticipantUpdatePublisher(modelsProvider);
diff --git a/runtime-controlloop/src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml b/runtime-controlloop/src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml
index 9acff1356..9c440b42b 100644
--- a/runtime-controlloop/src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml
+++ b/runtime-controlloop/src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml
@@ -188,6 +188,9 @@ topology_template:
policy_type_id:
name: onap.policies.monitoring.pm-subscription-handler
version: 1.0.0
+ policy_id:
+ name: onap.policies.monitoring.pm-subscription-handler
+ version: 1.0.0
org.onap.domain.pmsh.PMSD_OperationalPolicyControlLoopElement:
version: 1.2.3
type: org.onap.policy.clamp.controlloop.PolicyTypeControlLoopElement
@@ -201,6 +204,9 @@ topology_template:
policy_type_id:
name: onap.policies.operational.pm-subscription-handler
version: 1.0.0
+ policy_id:
+ name: onap.policies.monitoring.pm-subscription-handler
+ version: 1.0.0
org.onap.domain.pmsh.PMSD_CDS_ControlLoopElement:
version: 1.2.3
type: org.onap.policy.clamp.controlloop.ControlLoopElement