diff options
Diffstat (limited to 'adapters')
40 files changed, 407 insertions, 277 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java index f717144562..35c928c3b5 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java @@ -72,9 +72,7 @@ public class KeystoneV3Authentication { OpenStackRequest<Token> v3Request = keystoneTenantClient.tokens().authenticate(v3Credentials); - KeystoneAuthHolder holder = makeRequest(v3Request, type, region); - - return holder; + return makeRequest(v3Request, type, region); } protected KeystoneAuthHolder makeRequest(OpenStackRequest<Token> v3Request, String type, String region) { diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfoBuilder.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfoBuilder.java index 02ace5665d..072bf404e7 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfoBuilder.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfoBuilder.java @@ -72,22 +72,22 @@ public final class DeploymentInfoBuilder { this.errorMessage = execution.getError(); // Compute the status based on the last workflow - if (lastAction.equals("install")) { - if (actionStatus.equals("terminated")) { + if (("install").equals(lastAction)) { + if (("terminated").equals(actionStatus)) { this.deploymentStatus = DeploymentStatus.INSTALLED; - } else if (actionStatus.equals("failed")) { + } else if (("failed").equals(actionStatus)) { this.deploymentStatus = DeploymentStatus.FAILED; - } else if (actionStatus.equals("started") || actionStatus.equals("pending")) { + } else if (("started").equals(actionStatus) || ("pending").equals(actionStatus)) { this.deploymentStatus = DeploymentStatus.INSTALLING; } else { this.deploymentStatus = DeploymentStatus.UNKNOWN; } - } else if (lastAction.equals("uninstall")) { - if (actionStatus.equals("terminated")) { + } else if (("uninstall").equals(lastAction)) { + if (("terminated").equals(actionStatus)) { this.deploymentStatus = DeploymentStatus.CREATED; - } else if (actionStatus.equals("failed")) { + } else if (("failed").equals(actionStatus)) { this.deploymentStatus = DeploymentStatus.FAILED; - } else if (actionStatus.equals("started") || actionStatus.equals("pending")) { + } else if (("started").equals(actionStatus) || ("pending").equals(actionStatus)) { this.deploymentStatus = DeploymentStatus.UNINSTALLING; } else { this.deploymentStatus = DeploymentStatus.UNKNOWN; diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowException.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowException.java index 5c2348dffa..2251575671 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowException.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowException.java @@ -38,8 +38,8 @@ public class MsoCloudifyWorkflowException extends MsoCloudifyException { super(0, "Workflow Exception", "Workflow " + workflowId + " failed on deployment " + deploymentId + ": " + message); this.workflowStatus = workflowStatus; - if (workflowStatus.equals("pending") || workflowStatus.equals("started") || workflowStatus.equals("cancelling") - || workflowStatus.equals("force_cancelling")) { + if (("pending").equals(workflowStatus) || ("started").equals(workflowStatus) + || ("cancelling").equals(workflowStatus) || ("force_cancelling").equals(workflowStatus)) { workflowStillRunning = true; } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoYamlEditorWithEnvt.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoYamlEditorWithEnvt.java index 0541a8f51b..9ee8a09ea6 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoYamlEditorWithEnvt.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoYamlEditorWithEnvt.java @@ -40,6 +40,7 @@ import org.yaml.snakeyaml.Yaml; public class MsoYamlEditorWithEnvt { private static final Logger logger = LoggerFactory.getLogger(MsoYamlEditorWithEnvt.class); + public static final String EXCEPTION = "Exception:"; private Map<String, Object> yml; private Yaml yaml = new Yaml(); @@ -68,7 +69,7 @@ public class MsoYamlEditorWithEnvt { try { resourceMap = (Map<String, Object>) yml.get("parameters"); } catch (Exception e) { - logger.debug("Exception:", e); + logger.debug(EXCEPTION, e); return paramSet; } if (resourceMap == null) { @@ -89,7 +90,7 @@ public class MsoYamlEditorWithEnvt { try { value = JSON_MAPPER.writeValueAsString(obj); } catch (Exception e) { - logger.debug("Exception:", e); + logger.debug(EXCEPTION, e); value = "_BAD_JSON_MAPPING"; } } else { @@ -118,7 +119,7 @@ public class MsoYamlEditorWithEnvt { } return resourceList; } catch (Exception e) { - logger.debug("Exception:", e); + logger.debug(EXCEPTION, e); } return null; } @@ -137,7 +138,7 @@ public class MsoYamlEditorWithEnvt { try { value = resourceEntry.get("default"); } catch (ClassCastException cce) { - logger.debug("Exception:", cce); + logger.debug(EXCEPTION, cce); // This exception only - the value is an integer. For what we're doing // here - we don't care - so set value to something - and it will // get marked as not being required - which is correct. diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateHeatResponse.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateHeatResponse.java index a4cdba22a1..16671bbe50 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateHeatResponse.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateHeatResponse.java @@ -31,7 +31,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({"id", "links"}) public class MulticloudCreateHeatResponse implements Serializable { - private final static long serialVersionUID = -5215028275577848311L; + private static final long serialVersionUID = -5215028275577848311L; @JsonProperty("id") private String id; diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateLinkResponse.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateLinkResponse.java index e8a5b1480e..1f55aa92a2 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateLinkResponse.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateLinkResponse.java @@ -31,7 +31,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({"href", "rel"}) public class MulticloudCreateLinkResponse implements Serializable { - private final static long serialVersionUID = -5215028275577848311L; + private static final long serialVersionUID = -5215028275577848311L; @JsonProperty("href") private String href; diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateResponse.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateResponse.java index bb15e58c88..fc08201bcb 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateResponse.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateResponse.java @@ -30,7 +30,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({"template_type", "workload_id", "template_response"}) public class MulticloudCreateResponse implements Serializable { - private final static long serialVersionUID = -5215028275577848311L; + private static final long serialVersionUID = -5215028275577848311L; @JsonProperty("template_type") private String templateType; diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateStackResponse.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateStackResponse.java index 67cb73539d..67d1cbff4e 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateStackResponse.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateStackResponse.java @@ -30,7 +30,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({"stack"}) public class MulticloudCreateStackResponse implements Serializable { - private final static long serialVersionUID = -5215028275577848311L; + private static final long serialVersionUID = -5215028275577848311L; @JsonProperty("stack") private MulticloudCreateHeatResponse stack; diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java index a22937aea3..ad37b39f30 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java @@ -31,7 +31,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({"template_type", "workload_id", "workload_status", "workload_status_reason"}) public class MulticloudQueryResponse implements Serializable { - private final static long serialVersionUID = -5215028275577848311L; + private static final long serialVersionUID = -5215028275577848311L; @JsonProperty("template_type") private String templateType; diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java index b733552a2b..95dd48caa6 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java @@ -33,7 +33,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; "vf-module-model-customization-id", "oof_directives", "sdnc_directives", "user_directives", "template_type", "template_data"}) public class MulticloudRequest implements Serializable { - private final static long serialVersionUID = -5215028275577848311L; + private static final long serialVersionUID = -5215028275577848311L; @JsonProperty("generic-vnf-id") private String genericVnfId; diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/VfResponseCommon.java b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/VfResponseCommon.java index 23bbbb3f43..7a2d4ec3e1 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/VfResponseCommon.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/VfResponseCommon.java @@ -24,6 +24,8 @@ package org.onap.so.adapters.vnfrest; import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.HashMap; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import com.fasterxml.jackson.databind.ObjectMapper; @@ -71,7 +73,7 @@ public abstract class VfResponseCommon { public String toXmlString() { try { ByteArrayOutputStream bs = new ByteArrayOutputStream(); - JAXBContext context = JAXBContext.newInstance(this.getClass()); + JAXBContext context = JAXBContext.newInstance(this.getClass(), ArrayList.class, HashMap.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // pretty print XML marshaller.marshal(this, bs); diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java index d20d2b7758..0327fd67a3 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java @@ -20,9 +20,16 @@ package org.onap.so.openstack.mappers; +import java.util.List; +import java.util.Map; import javax.xml.bind.annotation.XmlElement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; public class MapElements { + private static final Logger logger = LoggerFactory.getLogger(MapElements.class); @XmlElement public String key; @XmlElement @@ -32,6 +39,21 @@ public class MapElements { public MapElements(String key, Object value) { this.key = key; - this.value = value; + // this is required to handle marshalling raw json + // always write values as strings for XML + if (value != null) { + if (value instanceof List || value instanceof Map) { + try { + this.value = new ObjectMapper().writeValueAsString(value); + } catch (JsonProcessingException e) { + logger.warn("could not marshal value to json, calling toString"); + this.value = value.toString(); + } + } else { + this.value = value; + } + } else { + this.value = value; + } } } diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/mappers/JAXBMarshallingTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/mappers/JAXBMarshallingTest.java index 8d27e54892..189d4cca3e 100644 --- a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/mappers/JAXBMarshallingTest.java +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/mappers/JAXBMarshallingTest.java @@ -24,17 +24,19 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.Arrays; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import org.junit.Test; import org.onap.so.adapters.vnfrest.CreateVfModuleRequest; +import com.fasterxml.jackson.databind.ObjectMapper; public class JAXBMarshallingTest { @Test - public void xmlMarshalTest() throws IOException, JAXBException { + public void xmlUnMarshalTest() throws IOException, JAXBException { JAXBContext context = JAXBContext.newInstance(CreateVfModuleRequest.class); CreateVfModuleRequest request = (CreateVfModuleRequest) context.createUnmarshaller().unmarshal( @@ -43,6 +45,20 @@ public class JAXBMarshallingTest { assertEquals("ubuntu-16-04-cloud-amd64", request.getVfModuleParams().get("vcpe_image_name")); assertEquals("10.2.0.0/24", request.getVfModuleParams().get("cpe_public_net_cidr")); assertEquals("", request.getVfModuleParams().get("workload_context")); + assertEquals("[\"a\",\"b\",\"c\"]", request.getVfModuleParams().get("raw-json-param")); + } + + @Test + public void xmlMarshalTest() throws IOException, JAXBException { + + CreateVfModuleRequest request = new CreateVfModuleRequest(); + request.getVfModuleParams().put("test-null", null); + request.getVfModuleParams().put("test array", Arrays.asList("a", "b", "c")); + + assertEquals("documents are equal", + new String(Files + .readAllBytes(Paths.get("src/test/resources/VfRequest-marshalled-with-complex-object.xml"))), + request.toXmlString()); } diff --git a/adapters/mso-adapters-rest-interface/src/test/resources/VfRequest-marshalled-with-complex-object.xml b/adapters/mso-adapters-rest-interface/src/test/resources/VfRequest-marshalled-with-complex-object.xml new file mode 100644 index 0000000000..ce175127df --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/resources/VfRequest-marshalled-with-complex-object.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<createVfModuleRequest> + <failIfExists>false</failIfExists> + <backout>true</backout> + <vfModuleParams> + <entry> + <key>test array</key> + <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">["a","b","c"]</value> + </entry> + <entry> + <key>test-null</key> + </entry> + </vfModuleParams> + <msoRequest/> +</createVfModuleRequest> diff --git a/adapters/mso-adapters-rest-interface/src/test/resources/createVfModuleRequest-with-params.xml b/adapters/mso-adapters-rest-interface/src/test/resources/createVfModuleRequest-with-params.xml index 1ff24a50f6..2718f1df61 100644 --- a/adapters/mso-adapters-rest-interface/src/test/resources/createVfModuleRequest-with-params.xml +++ b/adapters/mso-adapters-rest-interface/src/test/resources/createVfModuleRequest-with-params.xml @@ -1,4 +1,4 @@ -<createVfModuleRequest> + <createVfModuleRequest> <cloudSiteId>RegionOne</cloudSiteId> <cloudOwner>CloudOwner</cloudOwner> <tenantId>09d8566ea45e43aa974cf447ed591d77</tenantId> @@ -196,7 +196,10 @@ <key>vf_module_index</key> <value>0</value> </entry> - + <entry> + <key>raw-json-param</key> + <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">["a","b","c"]</value> + </entry> </vfModuleParams> <msoRequest> <requestId>11c8ec20-a1f8-4aa2-926f-e55d67a30f8b</requestId> diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml b/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml index aa9317c920..b1528a0897 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml +++ b/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml @@ -52,4 +52,4 @@ management: prometheus: enabled: true # Whether exporting of metrics to Prometheus is enabled. step: 1m # Step size (i.e. reporting frequency) to use. -
\ No newline at end of file + diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.11__AddVnfResourceOrder.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.11__AddVnfResourceOrder.sql index fabb005567..16e6ecf4bf 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.11__AddVnfResourceOrder.sql +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.11__AddVnfResourceOrder.sql @@ -1,3 +1,7 @@ use catalogdb; + ALTER TABLE vnf_resource_customization -ADD VNFCINSTANCEGROUP_ORDER varchar(255);
\ No newline at end of file +ADD VNFCINSTANCEGROUP_ORDER varchar(255); + +ALTER TABLE vnfc_customization +ADD RESOURCE_INPUT varchar(2000);
\ No newline at end of file diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java index 38dd9089e1..b4cdcb45e2 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java @@ -20,7 +20,6 @@ package org.onap.so.adapters.inventory.create; -import java.io.IOException; import org.camunda.bpm.client.task.ExternalTask; import org.camunda.bpm.client.task.ExternalTaskService; import org.onap.logging.ref.slf4j.ONAPLogConstants; @@ -47,17 +46,16 @@ public class CreateInventoryTask { public Environment env; protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) { + setupMDC(externalTask); boolean success = true; String auditInventoryString = externalTask.getVariable("auditInventoryResult"); - GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); AAIObjectAuditList auditInventory = null; try { + GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); auditInventory = objectMapper.getMapper().readValue(auditInventoryString, AAIObjectAuditList.class); - } catch (IOException e1) { - success = false; + } catch (Exception e) { + logger.error("Error Parsing Audit Results", e); } - setupMDC(externalTask); - if (auditInventory != null) { try { logger.info("Executing External Task Create Inventory, Retry Number: {} \n {}", auditInventory, @@ -96,9 +94,13 @@ public class CreateInventoryTask { } private void setupMDC(ExternalTask externalTask) { - String msoRequestId = (String) externalTask.getVariable("mso-request-id"); - if (msoRequestId != null && !msoRequestId.isEmpty()) - MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId); + try { + String msoRequestId = (String) externalTask.getVariable("mso-request-id"); + if (msoRequestId != null && !msoRequestId.isEmpty()) + MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId); + } catch (Exception e) { + logger.error("Error in setting up MDC", e); + } } protected long calculateRetryDelay(int currentRetries) { diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java index b59a1fa79a..bac41a1f8b 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java @@ -6,6 +6,7 @@ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. * ================================================================================ * Modifications Copyright (c) 2019 Samsung + * Modifications Copyright (c) 2019 IBM * ================================================================================ * 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,6 @@ import org.onap.so.entity.MsoRequest; import org.onap.so.logger.ErrorCode; import org.onap.so.heatbridge.HeatBridgeApi; import org.onap.so.heatbridge.HeatBridgeImpl; -import org.onap.so.heatbridge.openstack.api.OpenstackClient; import org.onap.so.logger.MessageEnum; import org.onap.so.openstack.beans.HeatStatus; import org.onap.so.openstack.beans.StackInfo; @@ -189,7 +189,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { String vfModuleId = ""; // Create a hook here to catch shortcut createVf requests: if (requestType != null && requestType.startsWith("VFMOD")) { - logger.debug("Calling createVfModule from createVnf -- requestType=" + requestType); + logger.debug("Calling createVfModule from createVnf -- requestType={}", requestType); String newRequestType = requestType.substring(5); String vfVolGroupHeatStackId = ""; String vfBaseHeatStackId = ""; @@ -251,13 +251,11 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { Holder<Boolean> vnfExists, Holder<String> vnfId, Holder<VnfStatus> status, Holder<Map<String, String>> outputs) throws VnfException { - logger.debug("Querying VNF {} in {}", vnfName, cloudSiteId + "/" + tenantId); + logger.debug("Querying VNF {} in {}/{}", vnfName, cloudSiteId, tenantId); // Will capture execution time for metrics - long startTime = System.currentTimeMillis(); - StackInfo heatStack = null; - long subStartTime = System.currentTimeMillis(); + StackInfo heatStack; try { heatStack = heat.queryStack(cloudSiteId, cloudOwner, tenantId, vnfName); } catch (MsoException me) { @@ -310,14 +308,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { throws VnfException { logger.debug("Deleting VNF {} in {}", vnfName, cloudSiteId + "/" + tenantId); - // Will capture execution time for metrics - long startTime = System.currentTimeMillis(); - // Use the MsoHeatUtils to delete the stack. Set the polling flag to true. - // The possible outcomes of deleteStack are a StackInfo object with status - // of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException - // could be thrown. - long subStartTime = System.currentTimeMillis(); try { heat.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfName, true); } catch (MsoException me) { @@ -344,7 +335,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { */ @Override public void rollbackVnf(VnfRollback rollback) throws VnfException { - long startTime = System.currentTimeMillis(); // rollback may be null (e.g. if stack already existed when Create was called) if (rollback == null) { logger.info(MessageEnum.RA_ROLLBACK_NULL.toString(), OPENSTACK, "rollbackVnf"); @@ -437,13 +427,13 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { logger.debug(" HeatBridgeMain.py returned {} with code {}", wait, p.exitValue()); return wait && p.exitValue() == 0; } catch (IOException e) { - logger.debug(" HeatBridgeMain.py failed with IO Exception! " + e); + logger.debug(" HeatBridgeMain.py failed with IO Exception! {}", e); return false; } catch (RuntimeException e) { - logger.debug(" HeatBridgeMain.py failed during runtime!" + e); + logger.debug(" HeatBridgeMain.py failed during runtime! {}", e); return false; } catch (Exception e) { - logger.debug(" HeatBridgeMain.py failed for unknown reasons! " + e); + logger.debug(" HeatBridgeMain.py failed for unknown reasons! {}", e); return false; } } @@ -461,7 +451,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity, cloudOwner, cloudSiteId, tenantId); - OpenstackClient openstackClient = heatBridgeClient.authenticate(); List<Resource> stackResources = heatBridgeClient.queryNestedHeatStackResources(heatStackId); List<Server> osServers = heatBridgeClient.getAllOpenstackServers(stackResources); @@ -590,7 +579,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { useMCUuid = false; mcu = ""; } else { - logger.debug("Found modelCustomizationUuid! Will use that: " + mcu); + logger.debug("Found modelCustomizationUuid! Will use that: {}", mcu); useMCUuid = true; } } @@ -1277,7 +1266,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { logger.debug("VF Module {} successfully created", vfModuleName); // call heatbridge heatbridge(heatStack, cloudOwner, cloudSiteId, tenantId, genericVnfName, vfModuleId); - return; } catch (Exception e) { logger.debug("unhandled exception in create VF", e); throw new VnfException("Exception during create VF " + e.getMessage()); @@ -1290,7 +1278,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { logger.debug("Deleting VF {} in ", vnfName, cloudOwner + "/" + cloudSiteId + "/" + tenantId); // Will capture execution time for metrics - long startTime = System.currentTimeMillis(); // 1702 capture the output parameters on a delete // so we'll need to query first @@ -1323,11 +1310,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { msoRequest, failRequestOnValetFailure); } - // Use the MsoHeatUtils to delete the stack. Set the polling flag to true. - // The possible outcomes of deleteStack are a StackInfo object with status - // of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException - // could be thrown. - long subStartTime = System.currentTimeMillis(); try { heat.deleteStack(tenantId, cloudOwner, cloudSiteId, vnfName, true); } catch (MsoException me) { @@ -2033,7 +2015,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { outputs.value = copyStringOutputs(heatStack.getOutputs()); rollback.value = vfRollback; - return; } private String getVfModuleNameFromModuleStackId(String vfModuleStackId) { @@ -2199,13 +2180,13 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { Map<String, Object> newInputs = vur.getParameters(); if (newInputs != null) { Map<String, Object> oldGold = goldenInputs; - logger.debug("parameters before being modified by valet:{}", oldGold.toString()); - goldenInputs = new HashMap<String, Object>(); + logger.debug("parameters before being modified by valet:{}", oldGold); + goldenInputs = new HashMap<>(); for (String key : newInputs.keySet()) { goldenInputs.put(key, newInputs.get(key)); } valetModifiedParamsHolder.value = goldenInputs; - logger.debug("parameters after being modified by valet:{}", goldenInputs.toString()); + logger.debug("parameters after being modified by valet:{}", goldenInputs); valetSucceeded = true; } } else { diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java new file mode 100644 index 0000000000..03622db655 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java @@ -0,0 +1,36 @@ +package org.onap.so.adapters.inventory.create; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import org.camunda.bpm.client.task.ExternalTask; +import org.camunda.bpm.client.task.ExternalTaskService; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +public class CreateInventoryTaskTest { + + @Mock + ExternalTask externalTask; + + @Mock + ExternalTaskService externalTaskService; + + @InjectMocks + CreateInventoryTask inventoryTask; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void test_Runtime_Parse_Exception() { + doReturn(null).when(externalTask).getVariable("auditInventoryResult"); + inventoryTask.executeExternalTask(externalTask, externalTaskService); + Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure"); + } +} diff --git a/adapters/mso-openstack-adapters/src/test/resources/schema.sql b/adapters/mso-openstack-adapters/src/test/resources/schema.sql index 5e986ab34d..1cf28be926 100644 --- a/adapters/mso-openstack-adapters/src/test/resources/schema.sql +++ b/adapters/mso-openstack-adapters/src/test/resources/schema.sql @@ -1134,6 +1134,7 @@ CREATE TABLE `vnfc_customization` ( `MODEL_NAME` varchar(200) NOT NULL, `TOSCA_NODE_TYPE` varchar(200) NOT NULL, `DESCRIPTION` varchar(1200) DEFAULT NULL, + `RESOURCE_INPUT` varchar(20000) DEFAULT NULL, `CREATION_TIMESTAMP` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`MODEL_CUSTOMIZATION_UUID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java index 21ce06eaf1..7d412b77ad 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java @@ -5,7 +5,7 @@ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. * ================================================================================ - * Modifications Copyright (C) 2018 IBM. + * Modifications Copyright (C) 2019 IBM. * Modifications Copyright (c) 2019 Samsung * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -77,13 +77,12 @@ public class SDNCRestClient { private static Logger logger = LoggerFactory.getLogger(SDNCRestClient.class); private static final String EXCEPTION_MSG = "Exception while evaluate xpath"; - private static final String MSO_INTERNAL_ERROR = "MsoInternalError"; private static final String CAMUNDA = "Camunda"; @Async public void executeRequest(SDNCAdapterRequest bpelRequest) { - logger.debug("BPEL Request:" + bpelRequest.toString()); + logger.debug("BPEL Request: {}", bpelRequest); // Added delay to allow completion of create request to SDNC // before executing activate of create request. @@ -96,8 +95,6 @@ public class SDNCRestClient { Thread.currentThread().interrupt(); } - String action = bpelRequest.getRequestHeader().getSvcAction(); - String operation = bpelRequest.getRequestHeader().getSvcOperation(); String bpelReqId = bpelRequest.getRequestHeader().getRequestId(); String callbackUrl = bpelRequest.getRequestHeader().getCallbackUrl(); @@ -118,12 +115,9 @@ public class SDNCRestClient { Document reqDoc = node.getOwnerDocument(); sdncReqBody = Utils.genSdncPutReq(reqDoc, rt); } - long sdncStartTime = System.currentTimeMillis(); SDNCResponse sdncResp = getSdncResp(sdncReqBody, rt); logger.debug("Got the SDNC Response: {}", sdncResp.getSdncRespXml()); - long bpelStartTime = System.currentTimeMillis(); sendRespToBpel(callbackUrl, sdncResp); - return; } public SDNCResponse getSdncResp(String sdncReqBody, RequestTunables rt) { @@ -288,7 +282,6 @@ public class SDNCRestClient { try { wsdlUrl = new URL(bpelUrl); } catch (MalformedURLException e1) { - error = "Caught exception initializing Callback wsdl " + e1.getMessage(); logger.error("{} {} {} {}", MessageEnum.RA_INIT_CALLBACK_WSDL_ERR.toString(), CAMUNDA, ErrorCode.DataError.getValue(), "Exception initializing Callback wsdl", e1); @@ -317,7 +310,6 @@ public class SDNCRestClient { reqCtx.put(MessageContext.HTTP_REQUEST_HEADERS, headers); headers.put("Authorization", Collections.singletonList(basicAuth)); } catch (Exception e2) { - error = "Unable to set authorization in callback request " + e2.getMessage(); logger.error("{} {} {} {}", MessageEnum.RA_SET_CALLBACK_AUTH_EXC.toString(), CAMUNDA, ErrorCode.BusinessProcesssError.getValue(), "Exception - Unable to set authorization in callback request", e2); @@ -333,6 +325,5 @@ public class SDNCRestClient { MessageEnum.RA_CALLBACK_BPEL_EXC.toString(), error, e); } logger.info(MessageEnum.RA_CALLBACK_BPEL_COMPLETE.name(), CAMUNDA); - return; } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml index 66a1cb1ca7..9d9e33a524 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml +++ b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml @@ -100,5 +100,10 @@ <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency> + <dependency> + <groupId>com.squareup.okio</groupId> + <artifactId>okio</artifactId> + <version>1.13.0</version> + </dependency> </dependencies> </project> diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-ext-clients/pom.xml b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-ext-clients/pom.xml index da778d286e..91478e1f8e 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-ext-clients/pom.xml +++ b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-ext-clients/pom.xml @@ -62,7 +62,6 @@ <apiPackage>org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.api</apiPackage> <modelPackage>org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model</modelPackage> <configOptions> - <jackson>true</jackson> <sourceFolder>src/gen/java/main</sourceFolder> <withXml>true</withXml> <useRxJava2>true</useRxJava2> @@ -79,15 +78,16 @@ <inputSpec>${basedir}/src/main/resources/SOL003-VNFLifecycleOperationGranting-API.json </inputSpec> <language>java</language> - <library>retrofit2</library> + <library>okhttp-gson</library> <output>${project.build.directory}/generated-sources/sol003-vnf-grant</output> - <generateApis>false</generateApis> + <apiPackage>org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.api</apiPackage> <modelPackage>org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model</modelPackage> <configOptions> <generateSupportingFiles>false</generateSupportingFiles> <sourceFolder>src/gen/java/main</sourceFolder> <withXml>true</withXml> <useRxJava2>true</useRxJava2> + <serializableModel>true</serializableModel> </configOptions> </configuration> </execution> diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml index c561721b3e..09c28f93f1 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml @@ -63,6 +63,12 @@ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java index 30ce0c2253..62d2f7e2a9 100755 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java @@ -20,11 +20,13 @@ package org.onap.so.adapters.vnfmadapter; +import static org.slf4j.LoggerFactory.getLogger; import org.onap.so.adapters.vnfmadapter.rest.VnfmAdapterController; import org.slf4j.Logger; import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; -import static org.slf4j.LoggerFactory.getLogger; +import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; /** * The spring boot application for the VNFM (Virtual Network Function Manager) Adapter. @@ -36,6 +38,7 @@ import static org.slf4j.LoggerFactory.getLogger; * SOL003 v2.5.1</a> */ @SpringBootApplication(scanBasePackages = {"org.onap.so"}) +@EnableAutoConfiguration(exclude = {JacksonAutoConfiguration.class}) public class VnfmAdapterApplication { private static final Logger logger = getLogger(VnfmAdapterApplication.class); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/SdcPackageProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/SdcPackageProvider.java index f1074bcba8..fd92910e36 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/SdcPackageProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/SdcPackageProvider.java @@ -22,20 +22,21 @@ package org.onap.so.adapters.vnfmadapter.extclients; +import static com.google.common.base.Splitter.on; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.io.ByteStreams.toByteArray; +import static java.lang.String.format; +import static org.apache.http.HttpHeaders.ACCEPT; +import static org.apache.http.HttpHeaders.AUTHORIZATION; +import static org.onap.so.adapters.vnfmadapter.NvfmAdapterUtils.abortOperation; +import static org.onap.so.adapters.vnfmadapter.NvfmAdapterUtils.child; +import static org.onap.so.adapters.vnfmadapter.NvfmAdapterUtils.childElement; +import static org.onap.so.adapters.vnfmadapter.NvfmAdapterUtils.children; +import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE; import com.google.common.io.ByteStreams; import com.google.gson.Gson; import com.google.gson.JsonObject; -import org.apache.commons.codec.binary.Base64; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.onap.so.utils.CryptoUtils; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; -import org.yaml.snakeyaml.Yaml; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -48,25 +49,24 @@ import java.util.NoSuchElementException; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import static com.google.common.base.Splitter.on; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.io.ByteStreams.toByteArray; -import static java.lang.String.format; -import static org.apache.http.HttpHeaders.ACCEPT; -import static org.apache.http.HttpHeaders.AUTHORIZATION; -import static org.onap.so.adapters.vnfmadapter.NvfmAdapterUtils.abortOperation; -import static org.onap.so.adapters.vnfmadapter.NvfmAdapterUtils.child; -import static org.onap.so.adapters.vnfmadapter.NvfmAdapterUtils.childElement; -import static org.onap.so.adapters.vnfmadapter.NvfmAdapterUtils.children; -import static org.slf4j.LoggerFactory.getLogger; -import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE; +import org.apache.commons.codec.binary.Base64; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.onap.so.utils.CryptoUtils; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.yaml.snakeyaml.Yaml; @Component public class SdcPackageProvider { - private static final String GET_PACKAGE_URL = "%s/catalog/resources/%s/toscaModel"; + private static final String GET_PACKAGE_URL = "%s/sdc/v1/catalog/resources/%s/toscaModel"; @Value("${sdc.toscametapath:TOSCA-Metadata/TOSCA.meta}") private List<String> toscaMetaPaths; - private final String TOSCA_VNFD_KEY = "Entry-Definitions"; + private static final String TOSCA_VNFD_KEY = "Entry-Definitions"; private static Logger logger = getLogger(SdcPackageProvider.class); @Value("${sdc.username}") @@ -78,7 +78,7 @@ public class SdcPackageProvider { @Value("${sdc.endpoint}") private String baseUrl; - public String getVnfdId(String csarId) { + public String getVnfdId(final String csarId) { return getVnfNodeProperty(csarId, "descriptor_id"); } @@ -96,7 +96,7 @@ public class SdcPackageProvider { for (final JsonObject child : children(nodeTemplates)) { final String type = childElement(child, "type").getAsString(); String propertyValue = null; - if (type.equals("tosca.nodes.nfv.VNF")) { + if ("tosca.nodes.nfv.VNF".equals(type)) { final JsonObject properties = child(child, "properties"); logger.debug("properties: " + properties.toString()); @@ -119,7 +119,7 @@ public class SdcPackageProvider { final JsonObject nodeTypes = child(root, "node_types"); final JsonObject nodeType = child(nodeTypes, nodeTypeName); - if (childElement(nodeType, "derived_from").getAsString().equals("tosca.nodes.nfv.VNF")) { + if ("tosca.nodes.nfv.VNF".equals(childElement(nodeType, "derived_from").getAsString())) { final JsonObject properties = child(nodeType, "properties"); logger.debug("properties: " + properties.toString()); final JsonObject property = child(properties, propertyName); @@ -130,34 +130,33 @@ public class SdcPackageProvider { return null; } - private byte[] getPackage(String csarId) { + private byte[] getPackage(final String csarId) { final String SERVICE_NAME = "vnfm-adapter"; try (CloseableHttpClient client = HttpClients.createDefault()) { - HttpGet httpget = new HttpGet(format(GET_PACKAGE_URL, baseUrl, csarId)); + final HttpGet httpget = new HttpGet(format(GET_PACKAGE_URL, baseUrl, csarId)); httpget.setHeader(ACCEPT, APPLICATION_OCTET_STREAM_VALUE); httpget.setHeader("X-ECOMP-InstanceID", SERVICE_NAME); httpget.setHeader("X-FromAppId", SERVICE_NAME); - String auth = sdcUsername + ":" + CryptoUtils.decrypt(sdcPassword, sdcKey); - byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)); - String authHeader = "Basic " + new String(encodedAuth); + final String auth = sdcUsername + ":" + CryptoUtils.decrypt(sdcPassword, sdcKey); + final byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)); + final String authHeader = "Basic " + new String(encodedAuth); httpget.setHeader(AUTHORIZATION, authHeader); logger.debug("Fetching from SDC: " + httpget); - CloseableHttpResponse response = client.execute(httpget); - HttpEntity entity = response.getEntity(); - InputStream is = entity.getContent(); - byte[] bytes = toByteArray(is); - return bytes; - } catch (Exception e) { + final CloseableHttpResponse response = client.execute(httpget); + final HttpEntity entity = response.getEntity(); + final InputStream is = entity.getContent(); + return toByteArray(is); + } catch (final Exception e) { throw abortOperation("Unable to download " + csarId + " package from SDC", e); } } - private String getVnfdLocation(InputStream stream) throws IOException { - Iterator pathIterator = toscaMetaPaths.iterator(); + private String getVnfdLocation(final InputStream stream) throws IOException { + final Iterator<String> pathIterator = toscaMetaPaths.iterator(); while (pathIterator.hasNext()) { - String toscaMetadata = new String(getFileInZip(stream, pathIterator.next().toString()).toByteArray()); + final String toscaMetadata = new String(getFileInZip(stream, pathIterator.next()).toByteArray()); if (!toscaMetadata.isEmpty()) { - String toscaVnfdLine = + final String toscaVnfdLine = filter(on("\n").split(toscaMetadata), line -> line.contains(TOSCA_VNFD_KEY)).iterator().next(); return toscaVnfdLine.replace(TOSCA_VNFD_KEY + ":", "").trim(); } @@ -165,20 +164,21 @@ public class SdcPackageProvider { throw abortOperation("Unable to find valid Tosca Path"); } - private static ByteArrayOutputStream getFileInZip(InputStream zip, String path) throws IOException { - ZipInputStream zipInputStream = new ZipInputStream(zip); - ByteArrayOutputStream fileContent = getFileInZip(zipInputStream, path); + private static ByteArrayOutputStream getFileInZip(final InputStream zip, final String path) throws IOException { + final ZipInputStream zipInputStream = new ZipInputStream(zip); + final ByteArrayOutputStream fileContent = getFileInZip(zipInputStream, path); zipInputStream.close(); return fileContent; } - private static ByteArrayOutputStream getFileInZip(ZipInputStream zipInputStream, String path) throws IOException { + private static ByteArrayOutputStream getFileInZip(final ZipInputStream zipInputStream, final String path) + throws IOException { ZipEntry zipEntry; - Set<String> items = new HashSet<>(); + final Set<String> items = new HashSet<>(); while ((zipEntry = zipInputStream.getNextEntry()) != null) { items.add(zipEntry.getName()); if (zipEntry.getName().matches(path)) { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ByteStreams.copy(zipInputStream, byteArrayOutputStream); return byteArrayOutputStream; } @@ -187,7 +187,7 @@ public class SdcPackageProvider { throw new NoSuchElementException("Unable to find the " + path + " in archive found: " + items); } - public String getFlavourId(String csarId) { + public String getFlavourId(final String csarId) { return getVnfNodeProperty(csarId, "flavour_id"); } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java index 50fd5bcf3a..867b6522f5 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java @@ -20,6 +20,9 @@ package org.onap.so.adapters.vnfmadapter.extclients.aai; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import org.onap.aai.domain.yang.EsrSystemInfo; import org.onap.aai.domain.yang.EsrSystemInfoList; import org.onap.aai.domain.yang.EsrVnfm; @@ -40,9 +43,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; /** * Provides helper methods for interactions with AAI. @@ -257,7 +257,12 @@ public class AaiHelper { relationship.setRelatedTo("tenant"); relationship.setRelatedLink("/aai/" + AAIVersion.LATEST + AAIUriFactory.createResourceUri(AAIObjectType.TENANT, tenant.getCloudOwner(), tenant.getRegionName(), tenant.getTenantId()).build().toString()); + relationship.getRelationshipData() + .add(createRelationshipData("cloud-region.cloud-owner", tenant.getCloudOwner())); + relationship.getRelationshipData() + .add(createRelationshipData("cloud-region.cloud-region-id", tenant.getRegionName())); relationship.getRelationshipData().add(createRelationshipData("tenant.tenant-id", tenant.getTenantId())); return relationship; } + } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java index f991ffafba..7021c02511 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java @@ -24,9 +24,9 @@ import org.onap.aai.domain.yang.EsrSystemInfoList; import org.onap.aai.domain.yang.EsrVnfm; import org.onap.aai.domain.yang.EsrVnfmList; import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.GenericVnfs; import org.onap.aai.domain.yang.Vserver; import org.onap.vnfmadapter.v1.model.Tenant; -import java.util.List; /** * Provides methods for invoking REST calls to AAI. @@ -47,7 +47,7 @@ public interface AaiServiceProvider { * @param selfLink the selfLink * @return the matching generic vnfs */ - List<GenericVnf> invokeQueryGenericVnf(final String selfLink); + GenericVnfs invokeQueryGenericVnf(final String selfLink); /** * Invoke a GET request for the VNFMs. diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java index fa07ab5720..50e579dd83 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java @@ -24,6 +24,7 @@ import org.onap.aai.domain.yang.EsrSystemInfoList; import org.onap.aai.domain.yang.EsrVnfm; import org.onap.aai.domain.yang.EsrVnfmList; import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.GenericVnfs; import org.onap.aai.domain.yang.Vserver; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.entities.uri.AAIUriFactory; @@ -32,7 +33,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; @Service public class AaiServiceProviderImpl implements AaiServiceProvider { @@ -56,9 +56,9 @@ public class AaiServiceProviderImpl implements AaiServiceProvider { } @Override - public List<GenericVnf> invokeQueryGenericVnf(final String selfLink) { + public GenericVnfs invokeQueryGenericVnf(final String selfLink) { return aaiClientProvider.getAaiClient() - .get(List.class, + .get(GenericVnfs.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNFS).queryParam("selflink", selfLink)) .orElseGet(() -> { logger.debug("No vnf found in AAI with selflink: {}", selfLink); @@ -104,7 +104,7 @@ public class AaiServiceProviderImpl implements AaiServiceProvider { @Override public void invokePutVserver(final String cloudOwner, final String cloudRegion, final String tenant, final Vserver vserver) { - aaiClientProvider.getAaiClient().update(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, + aaiClientProvider.getAaiClient().create(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenant, vserver.getVserverId()), vserver); } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java index 31399f7720..249cf74cb2 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java @@ -20,10 +20,16 @@ package org.onap.so.adapters.vnfmadapter.extclients.vnfm; +import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL; +import static org.onap.so.adapters.vnfmadapter.Constants.OPERATION_NOTIFICATION_ENDPOINT; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import org.onap.aai.domain.yang.EsrSystemInfo; import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiServiceProvider; import org.onap.so.adapters.vnfmadapter.extclients.vim.model.AccessInfo; @@ -40,7 +46,7 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsFilte import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsFilterVnfInstanceSubscriptionFilter; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.VnfInstancesvnfInstanceIdinstantiateExtVirtualLinks; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.VnfInstancesvnfInstanceIdinstantiateVimConnectionInfo; -import org.onap.so.security.WebSecurityConfig; +import org.onap.so.utils.CryptoUtils; import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.ExternalVirtualLink; import org.onap.vnfmadapter.v1.model.Tenant; @@ -49,11 +55,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL; -import static org.onap.so.adapters.vnfmadapter.Constants.OPERATION_NOTIFICATION_ENDPOINT; /** * Provides helper methods for interactions with VNFM. @@ -64,15 +65,19 @@ public class VnfmHelper { private static final Logger logger = LoggerFactory.getLogger(VnfmHelper.class); private static final String SEPARATOR = "_"; private final AaiServiceProvider aaiServiceProvider; - private final WebSecurityConfig webSecurityConfig; @Value("${vnfmadapter.endpoint}") private String vnfmAdapterEndoint; + @Value("${vnfmadapter.auth:E39823AAB2739CC654C4E92B52C05BC34149342D0A46451B00CA508C8EDC62242CE4E9DA9445D3C01A3F13}") + private String vnfmAdapterAuth; + + @Value("${mso.key}") + private String msoEncryptionKey; + @Autowired - public VnfmHelper(final AaiServiceProvider aaiServiceProvider, final WebSecurityConfig webSecurityConfig) { + public VnfmHelper(final AaiServiceProvider aaiServiceProvider) { this.aaiServiceProvider = aaiServiceProvider; - this.webSecurityConfig = webSecurityConfig; } /** @@ -171,8 +176,10 @@ public class VnfmHelper { * * @param the ID of the VNF notifications are required for * @return the request + * @throws GeneralSecurityException */ - public LccnSubscriptionRequest createNotificationSubscriptionRequest(final String vnfId) { + public LccnSubscriptionRequest createNotificationSubscriptionRequest(final String vnfId) + throws GeneralSecurityException { final LccnSubscriptionRequest lccnSubscriptionRequest = new LccnSubscriptionRequest(); lccnSubscriptionRequest.setAuthentication(getSubscriptionsAuthentication()); lccnSubscriptionRequest.setCallbackUri(vnfmAdapterEndoint + BASE_URL + OPERATION_NOTIFICATION_ENDPOINT); @@ -186,12 +193,11 @@ public class VnfmHelper { return lccnSubscriptionRequest; } - private SubscriptionsAuthentication getSubscriptionsAuthentication() { + private SubscriptionsAuthentication getSubscriptionsAuthentication() throws GeneralSecurityException { final SubscriptionsAuthenticationParamsBasic basicAuthParams = new SubscriptionsAuthenticationParamsBasic(); - basicAuthParams.setUserName("vnfm"); - basicAuthParams.setPassword(webSecurityConfig.getUsercredentials().stream() - .filter(userCredentials -> "vnfm".equals(userCredentials.getUsername())).findFirst().get() - .getPassword()); + final String[] decrypedAuth = CryptoUtils.decrypt(vnfmAdapterAuth, msoEncryptionKey).split(":"); + basicAuthParams.setUserName(decrypedAuth[0]); + basicAuthParams.setPassword(decrypedAuth[1]); final SubscriptionsAuthentication authentication = new SubscriptionsAuthentication(); authentication.addAuthTypeItem(AuthTypeEnum.BASIC); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java index 951c6f187b..645f37e72f 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java @@ -84,10 +84,12 @@ public class VnfmServiceProviderImpl implements VnfmServiceProvider { @Override public InlineResponse2001 subscribeForNotifications(final String vnfmId, final LccnSubscriptionRequest subscriptionRequest) { + logger.info("Subscribing for notifications {}", subscriptionRequest); final String url = urlProvider.getSubscriptionsUrl(vnfmId); ResponseEntity<InlineResponse2001> response = null; try { response = httpServiceProvider.postHttpRequest(subscriptionRequest, url, InlineResponse2001.class); + logger.info("Subscribing for notifications response {}", response); } catch (final Exception exception) { final String errorMessage = "Subscription to VNFM " + vnfmId + " resulted in exception" + subscriptionRequest; @@ -146,6 +148,7 @@ public class VnfmServiceProviderImpl implements VnfmServiceProvider { @Override public Optional<InlineResponse201> createVnf(final String vnfmId, final CreateVnfRequest createVnfRequest) { final String url = urlProvider.getCreationUrl(vnfmId); + logger.debug("Sending create request {} to : {}", createVnfRequest, url); try { return httpServiceProvider.post(createVnfRequest, url, InlineResponse201.class); } catch (final Exception exception) { diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java index d4aa65d159..f948f3cfac 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java @@ -20,6 +20,8 @@ package org.onap.so.adapters.vnfmadapter.extclients.vnfm; +import static org.slf4j.LoggerFactory.getLogger; +import java.net.URI; import org.onap.aai.domain.yang.EsrSystemInfo; import org.onap.aai.domain.yang.EsrSystemInfoList; import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiServiceProvider; @@ -28,8 +30,6 @@ import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.util.UriComponentsBuilder; -import java.net.URI; -import static org.slf4j.LoggerFactory.getLogger; /** * Provides URLs for REST calls to a VNFM. diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java index e6b787bacc..32bb9b93a4 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java @@ -21,6 +21,7 @@ package org.onap.so.adapters.vnfmadapter.lifecycle; import com.google.common.base.Optional; +import java.util.Map; import org.onap.aai.domain.yang.EsrVnfm; import org.onap.aai.domain.yang.GenericVnf; import org.onap.so.adapters.vnfmadapter.extclients.SdcPackageProvider; @@ -46,7 +47,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.Map; /** * Manages lifecycle operations towards the VNFMs. @@ -64,7 +64,7 @@ public class LifecycleManager { @Autowired LifecycleManager(final AaiServiceProvider aaiServiceProvider, final AaiHelper aaiHelper, final VnfmHelper vnfmHelper, final VnfmServiceProvider vnfmServiceProvider, final JobManager jobManager, - SdcPackageProvider packageProvider) { + final SdcPackageProvider packageProvider) { this.aaiServiceProvider = aaiServiceProvider; this.vnfmServiceProvider = vnfmServiceProvider; this.aaiHelper = aaiHelper; @@ -90,7 +90,11 @@ public class LifecycleManager { aaiHelper.addRelationshipFromGenericVnfToVnfm(genericVnf, vnfm.getVnfmId()); } aaiHelper.addRelationshipFromGenericVnfToTenant(genericVnf, request.getTenant()); - InlineResponse201 vnfmResponse = sendCreateRequestToVnfm(request, genericVnf, vnfIdInAai, vnfm.getVnfmId()); + final InlineResponse201 vnfmResponse = + sendCreateRequestToVnfm(request, genericVnf, vnfIdInAai, vnfm.getVnfmId()); + + logger.info("Create response: {}", vnfmResponse); + genericVnf.setSelflink(vnfmResponse.getLinks().getSelf().getHref()); aaiServiceProvider.invokePutGenericVnf(genericVnf); final String vnfIdInVnfm = vnfmResponse.getId(); @@ -135,18 +139,18 @@ public class LifecycleManager { } } - private InlineResponse201 sendCreateRequestToVnfm(CreateVnfRequest aaiRequest, GenericVnf genericVnf, - String vnfIdInAai, String vnfmId) { + private InlineResponse201 sendCreateRequestToVnfm(final CreateVnfRequest aaiRequest, final GenericVnf genericVnf, + final String vnfIdInAai, final String vnfmId) { logger.debug("Sending a create request to SVNFM " + aaiRequest); - org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest vnfmRequest = + final org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest vnfmRequest = new org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest(); - String vnfdId = packageProvider.getVnfdId(genericVnf.getModelVersionId()); + final String vnfdId = packageProvider.getVnfdId(genericVnf.getModelVersionId()); vnfmRequest.setVnfdId(vnfdId); vnfmRequest.setVnfInstanceName(aaiRequest.getName().replaceAll(" ", "_")); vnfmRequest.setVnfInstanceDescription(vnfIdInAai); - Optional<InlineResponse201> optionalResponse = vnfmServiceProvider.createVnf(vnfmId, vnfmRequest); + final Optional<InlineResponse201> optionalResponse = vnfmServiceProvider.createVnf(vnfmId, vnfmRequest); try { return optionalResponse.get(); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java index a339b9be70..d39a2cb761 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/notificationhandling/NotificationHandler.java @@ -20,6 +20,10 @@ package org.onap.so.adapters.vnfmadapter.notificationhandling; +import static org.slf4j.LoggerFactory.getLogger; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.json.JSONException; import org.json.JSONObject; import org.onap.aai.domain.yang.GenericVnf; @@ -36,10 +40,6 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201VimConnectionInfo; import org.onap.so.adapters.vnfmadapter.jobmanagement.JobManager; import org.slf4j.Logger; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import static org.slf4j.LoggerFactory.getLogger; /** * Performs updates to AAI based on a received notification. The updates are executed in a separate thread so as the @@ -93,8 +93,8 @@ public class NotificationHandler implements Runnable { } private void handleVnfInstantiateCompleted() { - final GenericVnf genericVnf = - aaiServiceProvider.invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).get(0); + final GenericVnf genericVnf = aaiServiceProvider + .invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).getGenericVnf().get(0); setOamIpAddress(genericVnf, vnfInstance); genericVnf.setOrchestrationStatus("Created"); @@ -141,16 +141,16 @@ public class NotificationHandler implements Runnable { } private void handleVnfTerminateFailed() { - final GenericVnf genericVnf = - aaiServiceProvider.invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).get(0); + final GenericVnf genericVnf = aaiServiceProvider + .invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).getGenericVnf().get(0); updateVservers(vnfLcmOperationOccurrenceNotification, genericVnf.getVnfId(), vnfInstance.getVimConnectionInfo()); jobManager.notificationProcessedForOperation(vnfLcmOperationOccurrenceNotification.getId(), false); } private void handleVnfTerminateCompleted() { - final GenericVnf genericVnf = - aaiServiceProvider.invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).get(0); + final GenericVnf genericVnf = aaiServiceProvider + .invokeQueryGenericVnf(vnfInstance.getLinks().getSelf().getHref()).getGenericVnf().get(0); updateVservers(vnfLcmOperationOccurrenceNotification, genericVnf.getVnfId(), vnfInstance.getVimConnectionInfo()); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java index 6b8802eed2..e241d0de7e 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java @@ -20,6 +20,11 @@ package org.onap.so.adapters.vnfmadapter.rest; +import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import javax.ws.rs.core.MediaType; import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiHelper; import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiServiceProvider; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmHelper; @@ -36,15 +41,10 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import javax.ws.rs.core.MediaType; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL; +import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping(value = BASE_URL, produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON) @@ -52,9 +52,6 @@ public class Sol003GrantController { private static final String SEPARATOR = "_"; private static final String VIM_TYPE = "OPENSTACK"; - private static final String CLOUD_OWNER = "myTestCloudOwner"; - private static final String REGION = "myTestRegion"; - private static final String TENANT_ID = "myTestTenantId"; private static final Logger logger = LoggerFactory.getLogger(Sol003GrantController.class); public final AaiServiceProvider aaiServiceProvider; public final AaiHelper aaiHelper; @@ -71,7 +68,7 @@ public class Sol003GrantController { @GetMapping(value = "/grants/{grantId}") public ResponseEntity<InlineResponse201> grantsGrantIdGet(@PathVariable("grantId") final String grantId) { logger.info("Get grant received from VNFM, grant id: " + grantId); - return new ResponseEntity<InlineResponse201>(HttpStatus.NOT_IMPLEMENTED); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @PostMapping(value = "/grants") @@ -80,7 +77,7 @@ public class Sol003GrantController { final InlineResponse201 grantResponse = createGrantResponse(grantRequest); logger.info("Grant request returning to VNFM: " + grantResponse); - return new ResponseEntity<InlineResponse201>(grantResponse, HttpStatus.CREATED); + return new ResponseEntity<>(grantResponse, HttpStatus.CREATED); } private InlineResponse201 createGrantResponse(final GrantRequest grantRequest) { @@ -88,8 +85,9 @@ public class Sol003GrantController { grantResponse.setId(UUID.randomUUID().toString()); grantResponse.setVnfInstanceId(grantRequest.getVnfInstanceId()); grantResponse.setVnfLcmOpOccId(grantRequest.getVnfLcmOpOccId()); - final Tenant tenant = - aaiHelper.getAssignedTenant(aaiServiceProvider.invokeGetGenericVnf((grantRequest.getVnfInstanceId()))); + final String vnfSelfLink = grantRequest.getLinks().getVnfInstance().getHref(); + final Tenant tenant = aaiHelper + .getAssignedTenant(aaiServiceProvider.invokeQueryGenericVnf(vnfSelfLink).getGenericVnf().get(0)); String vimConnectionId = ""; final InlineResponse201VimConnections vimConnection = vnfmHelper.getVimConnections(tenant); @@ -104,14 +102,6 @@ public class Sol003GrantController { return grantResponse; } - private InlineResponse201VimConnections getVimConnectionsItem(final Tenant tenant) { - final InlineResponse201VimConnections vimConnection = new InlineResponse201VimConnections(); - vimConnection.setId(createVimConnectionId(tenant.getCloudOwner(), tenant.getRegionName())); - vimConnection.setVimId(vimConnection.getId()); - vimConnection.setVimType(VIM_TYPE); - return vimConnection; - } - private List<InlineResponse201AddResources> getResources(final List<GrantsAddResources> requestResources, final String vimId) { final List<InlineResponse201AddResources> resources = new ArrayList<>(); @@ -123,8 +113,4 @@ public class Sol003GrantController { } return resources; } - - private String createVimConnectionId(String cloudOwner, String cloudRegionId) { - return cloudOwner + SEPARATOR + cloudRegionId; - } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml index 4fb110349d..951d4a3bb9 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml @@ -11,6 +11,19 @@ # 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. +spring: + security: + usercredentials: + - username: test + password: '$2a$12$Zi3AuYcZoZO/gBQyUtST2.F5N6HqcTtaNci2Et.ufsQhski56srIu' + role: BPEL-Client + - username: vnfm + password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' + role: BPEL-Client + http: + converters: + preferred-json-mapper: gson + server: port: 9092 tomcat: @@ -29,6 +42,9 @@ sdc: password: sdcPassword key: adadadadad endpoint: http://sdc.onap/1234A + +vnfmadapter: + endpoint: http://so-vnfm-adapter.onap:9092 #Actuator management: diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java index b7f5e96eab..4af0da1485 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java @@ -20,7 +20,14 @@ package org.onap.so.adapters.vnfmadapter.rest; -import com.google.gson.Gson; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Before; @@ -30,6 +37,7 @@ import org.mockito.hamcrest.MockitoHamcrest; import org.onap.aai.domain.yang.EsrSystemInfo; import org.onap.aai.domain.yang.EsrSystemInfoList; import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.GenericVnfs; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.RelationshipList; @@ -38,6 +46,8 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantRequest import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantRequest.OperationEnum; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources.TypeEnum; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsLinks; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsLinksVnfLcmOpOcc; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201VimConnections; import org.onap.so.client.aai.AAIResourcesClient; @@ -54,12 +64,6 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; -import java.util.Optional; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; @RunWith(SpringRunner.class) @SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) @@ -84,7 +88,6 @@ public class Sol003GrantControllerTest { @Autowired private Sol003GrantController controller; - private final Gson gson = new Gson(); @Before public void setUp() throws Exception { @@ -94,17 +97,17 @@ public class Sol003GrantControllerTest { @Test public void grantRequest_ValidRequestInstantiate_GrantApproved() { - GrantRequest grantRequest = createGrantRequest("INSTANTIATE"); + final GrantRequest grantRequest = createGrantRequest("INSTANTIATE"); setUpGenericVnfWithVnfmRelationshipInMockAai("vnfmType", "vnfm1"); final ResponseEntity<InlineResponse201> response = controller.grantsPost(grantRequest); assertEquals(HttpStatus.CREATED, response.getStatusCode()); assertEquals(1, response.getBody().getAddResources().size()); assertEquals(vimConnectionId, response.getBody().getAddResources().get(0).getVimConnectionId()); - assertEquals("myTestVnfId", response.getBody().getVnfInstanceId()); + assertEquals("myTestVnfIdOnVnfm", response.getBody().getVnfInstanceId()); assertEquals("123456", response.getBody().getVnfLcmOpOccId()); - InlineResponse201VimConnections vimConnections = response.getBody().getVimConnections().get(0); + final InlineResponse201VimConnections vimConnections = response.getBody().getVimConnections().get(0); assertEquals(vimConnectionId, vimConnections.getVimId()); assertEquals("OPENSTACK", vimConnections.getVimType()); assertNotNull(vimConnections.getAccessInfo()); @@ -120,17 +123,17 @@ public class Sol003GrantControllerTest { @Test public void grantRequest_ValidRequestTerminate_GrantApproved() { - GrantRequest grantRequest = createGrantRequest("TERMINATE"); + final GrantRequest grantRequest = createGrantRequest("TERMINATE"); setUpGenericVnfWithVnfmRelationshipInMockAai("vnfmType", "vnfm1"); final ResponseEntity<InlineResponse201> response = controller.grantsPost(grantRequest); assertEquals(HttpStatus.CREATED, response.getStatusCode()); assertEquals(1, response.getBody().getAddResources().size()); assertEquals(vimConnectionId, response.getBody().getAddResources().get(0).getVimConnectionId()); - assertEquals("myTestVnfId", response.getBody().getVnfInstanceId()); + assertEquals("myTestVnfIdOnVnfm", response.getBody().getVnfInstanceId()); assertEquals("123456", response.getBody().getVnfLcmOpOccId()); - InlineResponse201VimConnections vimConnections = response.getBody().getVimConnections().get(0); + final InlineResponse201VimConnections vimConnections = response.getBody().getVimConnections().get(0); assertEquals(vimConnectionId, vimConnections.getVimId()); assertEquals("OPENSTACK", vimConnections.getVimType()); assertNotNull(vimConnections.getAccessInfo()); @@ -139,19 +142,21 @@ public class Sol003GrantControllerTest { } - private GrantRequest createGrantRequest(String operation) { - GrantRequest grantRequest = new GrantRequest(); - grantRequest.setVnfInstanceId("myTestVnfId"); + private GrantRequest createGrantRequest(final String operation) { + final GrantRequest grantRequest = new GrantRequest(); + grantRequest.setVnfInstanceId("myTestVnfIdOnVnfm"); grantRequest.setVnfLcmOpOccId("123456"); + grantRequest.links(new GrantsLinks() + .vnfInstance(new GrantsLinksVnfLcmOpOcc().href("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"))); if (operation == "INSTANTIATE") { grantRequest.setOperation(OperationEnum.INSTANTIATE); - GrantsAddResources resource = new GrantsAddResources(); + final GrantsAddResources resource = new GrantsAddResources(); resource.setId("123"); resource.setType(TypeEnum.COMPUTE); grantRequest.addAddResourcesItem(resource); } else if (operation == "TERMINATE") { grantRequest.setOperation(OperationEnum.TERMINATE); - GrantsAddResources resource = new GrantsAddResources(); + final GrantsAddResources resource = new GrantsAddResources(); resource.setId("123"); resource.setType(TypeEnum.COMPUTE); grantRequest.addRemoveResourcesItem(resource); @@ -210,6 +215,14 @@ public class Sol003GrantControllerTest { doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class), MockitoHamcrest.argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId"))); + + final List<GenericVnf> listOfGenericVnfs = new ArrayList<>(); + listOfGenericVnfs.add(genericVnf); + final GenericVnfs genericVnfs = new GenericVnfs(); + genericVnfs.getGenericVnf().addAll(listOfGenericVnfs); + doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class), + MockitoHamcrest.argThat(new AaiResourceUriMatcher( + "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm"))); } private class AaiResourceUriMatcher extends BaseMatcher<AAIResourceUri> { diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java index 66e8e99f72..822201ea1c 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java @@ -20,7 +20,25 @@ package org.onap.so.adapters.vnfmadapter.rest; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; import com.google.gson.Gson; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.inject.Inject; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Before; @@ -29,6 +47,7 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.hamcrest.MockitoHamcrest; import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.GenericVnfs; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.Vserver; import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; @@ -64,24 +83,6 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; -import javax.inject.Inject; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; @RunWith(SpringRunner.class) @SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) @@ -166,9 +167,11 @@ public class Sol003LcnControllerTest { .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON)); final GenericVnf genericVnf = createGenericVnf("vnfmType1"); - final List<GenericVnf> genericVnfs = new ArrayList<>(); - genericVnfs.add(genericVnf); - doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(List.class), + final List<GenericVnf> listOfGenericVnfs = new ArrayList<>(); + listOfGenericVnfs.add(genericVnf); + final GenericVnfs genericVnfs = new GenericVnfs(); + genericVnfs.getGenericVnf().addAll(listOfGenericVnfs); + doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class), MockitoHamcrest.argThat(new AaiResourceUriMatcher( "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm"))); @@ -176,23 +179,27 @@ public class Sol003LcnControllerTest { controller.lcnVnfLcmOperationOccurrenceNotificationPost(vnfLcmOperationOccurrenceNotification); assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - final ArgumentCaptor<Object> bodyArgument = ArgumentCaptor.forClass(Object.class); - final ArgumentCaptor<AAIResourceUri> uriArgument = ArgumentCaptor.forClass(AAIResourceUri.class); + final ArgumentCaptor<Object> bodyArgument1 = ArgumentCaptor.forClass(Object.class); + final ArgumentCaptor<AAIResourceUri> uriArgument1 = ArgumentCaptor.forClass(AAIResourceUri.class); - verify(aaiResourcesClient, timeout(1000).times(2)).update(uriArgument.capture(), bodyArgument.capture()); + verify(aaiResourcesClient, timeout(1000)).update(uriArgument1.capture(), bodyArgument1.capture()); assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", - uriArgument.getAllValues().get(0).build().toString()); - final GenericVnf updatedGenericVnf = (GenericVnf) bodyArgument.getAllValues().get(0); + uriArgument1.getAllValues().get(0).build().toString()); + final GenericVnf updatedGenericVnf = (GenericVnf) bodyArgument1.getAllValues().get(0); assertEquals("10.10.10.10", updatedGenericVnf.getIpv4OamAddress()); assertEquals("Created", updatedGenericVnf.getOrchestrationStatus()); + final ArgumentCaptor<Object> bodyArgument2 = ArgumentCaptor.forClass(Object.class); + final ArgumentCaptor<AAIResourceUri> uriArgument2 = ArgumentCaptor.forClass(AAIResourceUri.class); + verify(aaiResourcesClient, timeout(1000)).create(uriArgument2.capture(), bodyArgument2.capture()); + assertEquals( "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/" + TENANT_ID + "/vservers/vserver/myVnfc1", - uriArgument.getAllValues().get(1).build().toString()); + uriArgument2.getAllValues().get(0).build().toString()); - final Vserver vserver = (Vserver) bodyArgument.getAllValues().get(1); + final Vserver vserver = (Vserver) bodyArgument2.getAllValues().get(0); assertEquals("myVnfc1", vserver.getVserverId()); final Relationship relationship = vserver.getRelationshipList().getRelationship().get(0); assertEquals("generic-vnf", relationship.getRelatedTo()); @@ -218,9 +225,12 @@ public class Sol003LcnControllerTest { final GenericVnf genericVnf = createGenericVnf("vnfmType1"); genericVnf.setSelflink("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"); - final List<GenericVnf> genericVnfs = new ArrayList<>(); - genericVnfs.add(genericVnf); - doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(List.class), + final List<GenericVnf> listOfGenericVnfs = new ArrayList<>(); + listOfGenericVnfs.add(genericVnf); + final GenericVnfs genericVnfs = new GenericVnfs(); + genericVnfs.getGenericVnf().addAll(listOfGenericVnfs); + + doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class), MockitoHamcrest.argThat(new AaiResourceUriMatcher( "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm"))); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java index 20a074b2ba..73a49e9c40 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java @@ -20,7 +20,21 @@ package org.onap.so.adapters.vnfmadapter.rest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; import com.google.gson.Gson; +import java.net.URI; +import java.util.Optional; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Before; @@ -36,24 +50,23 @@ import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.RelationshipList; +import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; +import org.onap.so.adapters.vnfmadapter.extclients.SdcPackageProvider; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse2001; +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201Links; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201LinksSelf; +import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; import org.onap.vnfmadapter.v1.model.OperationEnum; import org.onap.vnfmadapter.v1.model.OperationStateEnum; import org.onap.vnfmadapter.v1.model.QueryJobResponse; -import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; -import org.onap.so.adapters.vnfmadapter.extclients.SdcPackageProvider; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.*; -import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException; -import org.onap.so.client.aai.AAIResourcesClient; -import org.onap.so.client.aai.entities.uri.AAIResourceUri; -import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.Tenant; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse2001; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; @@ -72,18 +85,6 @@ import org.springframework.web.client.RestTemplate; import org.threeten.bp.LocalDateTime; import org.threeten.bp.OffsetDateTime; import org.threeten.bp.ZoneOffset; -import java.net.URI; -import java.util.Optional; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.*; @RunWith(SpringRunner.class) @SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) @@ -131,7 +132,7 @@ public class VnfmAdapterControllerTest { setUpVimInMockAai(); final String expectedsubscriptionRequest = - "{\"filter\":{\"vnfInstanceSubscriptionFilter\":{\"vnfInstanceIds\":[\"vnfId\"]},\"notificationTypes\":[\"VnfLcmOperationOccurrenceNotification\"]},\"callbackUri\":\"https://so-vnfm-adapter.onap:30406/so/vnfm-adapter/v1/lcn/VnfLcmOperationOccurrenceNotification\",\"authentication\":{\"authType\":[\"BASIC\"],\"paramsBasic\":{\"userName\":\"vnfm\",\"password\":\"$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke\"}}}"; + "{\"filter\":{\"vnfInstanceSubscriptionFilter\":{\"vnfInstanceIds\":[\"vnfId\"]},\"notificationTypes\":[\"VnfLcmOperationOccurrenceNotification\"]},\"callbackUri\":\"https://so-vnfm-adapter.onap:30406/so/vnfm-adapter/v1/lcn/VnfLcmOperationOccurrenceNotification\",\"authentication\":{\"authType\":[\"BASIC\"],\"paramsBasic\":{\"userName\":\"vnfm\",\"password\":\"password1$\"}}}"; final InlineResponse2001 subscriptionResponse = new InlineResponse2001(); final InlineResponse201 createResponse = createCreateResponse(); |