From 804942a67bfc0baacb2fa53923a77e8f41cc1079 Mon Sep 17 00:00:00 2001 From: "Kalkere Ramesh, Sharan (sk720x)" Date: Wed, 9 Sep 2020 09:28:56 -0400 Subject: Bpmn to cnf adapter implementation testing bpmn BPMN changes related to CNF Adapter Change-Id: I9ccff712cc731bcd7469bd2b6dadaae49133e20f Issue-ID: SO-3199 Signed-off-by: Kalkere Ramesh, Sharan --- .../subprocess/BuildingBlock/CnfAdapterBB.bpmn | 2 +- .../adapter/cnf/tasks/CnfAdapter.java | 24 +++++++++++++------- .../adapter/cnf/tasks/CnfAdapterCreateTasks.java | 2 +- .../so/client/adapter/cnf/CnfAdapterClient.java | 26 ++++++++++++++++++++-- .../adapter/cnf/entities/InstanceRequest.java | 26 +++++++++++----------- 5 files changed, 55 insertions(+), 25 deletions(-) diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfAdapterBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfAdapterBB.bpmn index 6cd2c20ab9..1dc371e054 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfAdapterBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfAdapterBB.bpmn @@ -1,6 +1,6 @@ - + SequenceFlow_0xb4elc diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapter.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapter.java index c21b467a95..a556d3088c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapter.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapter.java @@ -1,19 +1,16 @@ package org.onap.so.bpmn.infrastructure.adapter.cnf.tasks; -import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowAction; import org.onap.so.client.adapter.cnf.CnfAdapterClient; -import org.onap.so.client.adapter.cnf.CnfAdapterClientException; import org.onap.so.client.adapter.cnf.entities.InstanceRequest; import org.onap.so.client.adapter.cnf.entities.InstanceResponse; +import org.onap.so.client.adapter.cnf.entities.Labels; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; @Component public class CnfAdapter { @@ -25,8 +22,19 @@ public class CnfAdapter { public void callCnfAdapter(DelegateExecution execution) throws Exception { try { - final String instanceRequest = (String) execution.getVariable("instanceRequest"); - InstanceRequest request = new ObjectMapper().readValue(instanceRequest, InstanceRequest.class); + InstanceRequest request = new InstanceRequest(); + request.setRbName("test-rbdef"); + request.setRbVersion("v1"); + request.setCloudRegion("krd"); + request.setVfModuleUUID("VF module UUID"); + request.setProfileName("p1"); + Map overrideValues = new HashMap<>(); + overrideValues.put("image.tag", "latest"); + overrideValues.put("dcae_collector_ip", "1.2.3.4"); + Map labels = new HashMap(); + labels.put("custom-label-1", "abcdef"); + request.setLabels(labels); + request.setOverrideValues(overrideValues); InstanceResponse response = cnfAdapterClient.createVfModule(request); } catch (Exception ex) { logger.error("Exception in callCnfAdapter", ex); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java index 93d30512b6..7624bcb811 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java @@ -112,7 +112,7 @@ public class CnfAdapterCreateTasks { request.setRbName(vfModule.getModelInfoVfModule().getModelInvariantUUID()); request.setRbVersion(vfModule.getModelInfoVfModule().getModelUUID()); request.setCloudRegion(cloudRegion.getLcpCloudRegionId()); - request.setReleaseName(vfModule.getVfModuleId()); + request.setVfModuleUUID(vfModule.getVfModuleId()); request.setProfileName(sdncDirectives.get("k8s-rb-profile-name")); request.setOverrideValues(sdncDirectives); return request; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java index f44c15ac54..b74aa9056d 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java @@ -34,6 +34,7 @@ import org.springframework.core.env.Environment; 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.retry.annotation.Backoff; import org.springframework.retry.annotation.Retryable; @@ -75,11 +76,32 @@ public class CnfAdapterClient { } } + @Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000)) + public InstanceResponse healthcheck() throws CnfAdapterClientException { + try { + // String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well + // for configuration + String uri = "https://localhost:32780"; // TODO: What is the correct uri? + String endpoint = UriBuilder.fromUri(uri).path("/api/cnf-adapter/v1/healthcheck").build().toString(); + HttpEntity entity = new HttpEntity<>(getHttpHeaders()); + ResponseEntity result = + restTemplate.exchange(endpoint, HttpMethod.GET, entity, InstanceResponse.class); + return result.getBody(); + } catch (HttpClientErrorException e) { + logger.error("Error Calling CNF Adapter, e"); + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException(e.getResponseBodyAsString()); + } + throw e; + } + } + protected HttpHeaders getHttpHeaders() { HttpHeaders headers = new HttpHeaders(); - List acceptableMediaTypes = new ArrayList<>(); - acceptableMediaTypes.add(org.springframework.http.MediaType.APPLICATION_JSON); + List acceptableMediaTypes = new ArrayList<>(); + acceptableMediaTypes.add(MediaType.APPLICATION_JSON); headers.setAccept(acceptableMediaTypes); + headers.setContentType(MediaType.APPLICATION_JSON); /* * try { String userCredentials = CryptoUtils.decrypt(env.getRequiredProperty("mso.cnf.adapter.auth"), * env.getRequiredProperty("mso.msoKey")); if (userCredentials != null) { headers.add(HttpHeaders.AUTHORIZATION, diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java index e4058097ab..37d4e41553 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java @@ -11,18 +11,18 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; "override-values"}) public class InstanceRequest { - @JsonProperty("rb-name") + @JsonProperty("modelInvariantId") private String rbName; - @JsonProperty("rb-version") + @JsonProperty("modelVersionId") private String rbVersion; - @JsonProperty("profile-name") + @JsonProperty("k8sRBProfileName") private String profileName; - @JsonProperty("release-name") - private String releaseName; - @JsonProperty("cloud-region") + @JsonProperty("vfModuleUUID") + private String vfModuleUUID; + @JsonProperty("cloudRegionId") private String cloudRegion; @JsonProperty("labels") - private Labels labels; + private Map labels; @JsonProperty(value = "override-values") private Map overrideValues; @@ -67,21 +67,21 @@ public class InstanceRequest { } @JsonProperty("labels") - public Labels getLabels() { + public Map getLabels() { return labels; } @JsonProperty("labels") - public void setLabels(Labels labels) { + public void setLabels(Map labels) { this.labels = labels; } - public String getReleaseName() { - return releaseName; + public String getVfModuleUUID() { + return vfModuleUUID; } - public void setReleaseName(String releaseName) { - this.releaseName = releaseName; + public void setVfModuleUUID(String vfModuleUUID) { + this.vfModuleUUID = vfModuleUUID; } public Map getOverrideValues() { -- cgit 1.2.3-korg