summaryrefslogtreecommitdiffstats
path: root/participant
diff options
context:
space:
mode:
authorSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-08-31 11:25:34 +0100
committerSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-09-01 16:48:18 +0100
commit83b5318e545fbc72e3612c4300c4d738b0b577de (patch)
treec4429d0f64b16f510ca00160cd1eb49d91657b45 /participant
parentbd376e1dd5e8ccb1893ef244dcd9e4b1a0686150 (diff)
Send ToscaServiceTemplateFragment with policies, policy-types
ToscaServiceTemplateFragment contains policies, policy-types and respective datatypes to be sent to Policy participant, and there on to Policy Framework to create new policies or policy-types that doesnot exist in the database. https://wiki.onap.org/display/DW/The+CLAMP+Policy+Framework+Participant Issue-ID: POLICY-3607 Signed-off-by: Sirisha_Manchikanti <sirisha.manchikanti@est.tech> Change-Id: I2b98d7dc6946b0c27763f1a150d1bf4adca90a2f
Diffstat (limited to 'participant')
-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
10 files changed, 134 insertions, 108 deletions
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 febdf6b08..2ceba005c 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 4c87e0875..52ec98ea2 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 83ef68e86..fa87d5c24 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 49ad6dab1..56fddd6ff 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.getParticipantId().equals(participantType)) {