summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java10
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java8
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java29
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java59
-rw-r--r--adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java2
-rw-r--r--adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/impl/SDNCRestClientTest.java10
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java32
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java120
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIClient.java1
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryResultWrapper.java4
-rw-r--r--common/src/main/java/org/onap/so/openpojo/rules/EqualsAndHashCodeTester.java12
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java15
12 files changed, 255 insertions, 47 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
index 20498cb694..ddc725188f 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -21,7 +23,6 @@
package org.onap.so.openstack.utils;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
@@ -29,7 +30,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Optional;
import java.util.Set;
import org.onap.so.adapters.vdu.CloudInfo;
@@ -55,7 +55,6 @@ import org.onap.so.db.catalog.beans.ServerType;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
-import org.onap.so.openstack.beans.HeatCacheEntry;
import org.onap.so.openstack.beans.HeatStatus;
import org.onap.so.openstack.beans.StackInfo;
import org.onap.so.openstack.exceptions.MsoAdapterException;
@@ -72,7 +71,6 @@ import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
-import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.woorea.openstack.base.client.OpenStackConnectException;
@@ -298,9 +296,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
// Get a Heat client. They are cached between calls (keyed by tenantId:cloudId)
// This could throw MsoTenantNotFound or MsoOpenstackException (both propagated)
Heat heatClient = getHeatClient (cloudSite, tenantId);
- if (heatClient != null) {
- LOGGER.debug("Found: " + heatClient.toString());
- }
+ LOGGER.debug("Found: " + heatClient.toString());
LOGGER.debug ("Ready to Create Stack (" + heatTemplate + ") with input params: " + stackInputs);
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java
index 087ac6f17b..9cfdf53094 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/BaseTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -86,7 +88,7 @@ public abstract class BaseTest extends TestDataSetup {
.withStatus(HttpStatus.SC_OK)));
}
- private CloudIdentity getCloudIdentity() {
+ protected CloudIdentity getCloudIdentity() {
CloudIdentity identity = new CloudIdentity();
identity.setId("mtn13");
identity.setMsoId("m93945");
@@ -100,7 +102,7 @@ public abstract class BaseTest extends TestDataSetup {
return identity;
}
- private CloudSite getCloudSite(CloudIdentity identity) {
+ protected CloudSite getCloudSite(CloudIdentity identity) {
CloudSite cloudSite = new CloudSite();
cloudSite.setId("MTN13");
cloudSite.setCloudVersion("3.0");
@@ -123,4 +125,4 @@ public abstract class BaseTest extends TestDataSetup {
return sb.toString();
}
}
-} \ No newline at end of file
+}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java
index f5867befc0..0820076c66 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -20,12 +22,6 @@
package org.onap.so;
-import org.apache.http.HttpStatus;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.delete;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
@@ -35,6 +31,11 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import org.apache.http.HttpStatus;
+
public class StubOpenStack {
public static void mockOpenStackResponseAccess(int port) throws IOException {
@@ -43,11 +44,27 @@ public class StubOpenStack {
.withStatus(HttpStatus.SC_OK)));
}
+ public static void mockOpenStackResponseUnauthorized(int port) throws IOException {
+ stubFor(
+ post(urlPathEqualTo("/v2.0/tokens"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_UNAUTHORIZED)));
+ }
+
public static void mockOpenStackDelete(String id) {
stubFor(delete(urlMatching("/mockPublicUrl/stacks/" + id)).willReturn(aResponse()
.withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
}
+ public static void mockOpenStackGet(String id) {
+ stubFor(
+ get(urlPathEqualTo("/mockPublicUrl/stacks/" + id))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Stack_Created.json")
+ .withStatus(HttpStatus.SC_OK)));
+ }
+
public static void mockOpenStackPostStack_200(String filename) {
stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")).willReturn(aResponse()
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
index 6517122475..f9fc9284fe 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -26,17 +28,19 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.shazam.shazamcrest.MatcherAssert.assertThat;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertNotNull;
+import com.woorea.openstack.heat.Heat;
+import com.woorea.openstack.heat.model.CreateStackParam;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
-import com.woorea.openstack.heat.model.CreateStackParam;
import org.apache.http.HttpStatus;
import org.junit.Assert;
import org.junit.Test;
+import org.onap.so.BaseTest;
import org.onap.so.StubOpenStack;
import org.onap.so.adapters.vdu.CloudInfo;
import org.onap.so.adapters.vdu.PluginAction;
@@ -46,13 +50,13 @@ import org.onap.so.adapters.vdu.VduInstance;
import org.onap.so.adapters.vdu.VduModelInfo;
import org.onap.so.adapters.vdu.VduStateType;
import org.onap.so.adapters.vdu.VduStatus;
-import org.onap.so.cloud.CloudConfig;
-import org.onap.so.BaseTest;
+import org.onap.so.db.catalog.beans.CloudIdentity;
import org.onap.so.db.catalog.beans.CloudSite;
-import org.onap.so.openstack.beans.HeatStatus;
import org.onap.so.openstack.beans.StackInfo;
+import org.onap.so.openstack.exceptions.MsoAdapterException;
import org.onap.so.openstack.exceptions.MsoException;
-
+import org.onap.so.openstack.exceptions.MsoIOException;
+import org.onap.so.openstack.exceptions.MsoOpenstackException;
import org.springframework.beans.factory.annotation.Autowired;
public class MsoHeatUtilsTest extends BaseTest{
@@ -187,6 +191,47 @@ public class MsoHeatUtilsTest extends BaseTest{
heatUtils.copyBaseOutputsToInputs(inputs, otherStackOutputs, null, aliases);
Assert.assertEquals("str",otherStackOutputs.get("str"));
}
-
+ @Test
+ public final void getHeatClientSuccessTest() throws MsoException, IOException {
+ CloudSite cloudSite = getCloudSite(getCloudIdentity());
+ StubOpenStack.mockOpenStackResponseAccess(wireMockPort);
+ Heat heatClient = heatUtils.getHeatClient(cloudSite, "TEST-tenant");
+ assertNotNull(heatClient);
+ }
+
+ @Test(expected = MsoOpenstackException.class)
+ public final void getHeatClientOpenStackResponseException404Test() throws MsoException, IOException {
+ CloudSite cloudSite = getCloudSite(getCloudIdentity());
+ // mo mocks setup will cause 404 response from wiremock
+ heatUtils.getHeatClient(cloudSite, "TEST-tenant");
+ }
+
+ @Test(expected = MsoAdapterException.class)
+ public final void getHeatClientOpenStackResponseException401Test() throws MsoException, IOException {
+ CloudSite cloudSite = getCloudSite(getCloudIdentity());
+ StubOpenStack.mockOpenStackResponseUnauthorized(wireMockPort);
+ heatUtils.getHeatClient(cloudSite, "TEST-tenant");
+ }
+
+ @Test(expected = MsoIOException.class)
+ public final void getHeatClientOpenStackConnectExceptionTest() throws MsoException, IOException {
+ CloudIdentity identity = getCloudIdentity();
+ identity.setIdentityUrl("http://unreachable");
+ CloudSite cloudSite = getCloudSite(identity);
+ // mo mocks setup will cause 404 response from wiremock
+ heatUtils.getHeatClient(cloudSite, "TEST-tenant");
+ }
+
+ @Test
+ public final void createStackSuccessTest() throws MsoException, IOException {
+ CloudSite cloudSite = getCloudSite(getCloudIdentity());
+ StubOpenStack.mockOpenStackResponseAccess(wireMockPort);
+ StubOpenStack.mockOpenStackPostStack_200("OpenstackResponse_Stack_Created.json");
+ StubOpenStack.mockOpenStackGet("TEST-stack/stackId");
+ StackInfo stackInfo = heatUtils.createStack(cloudSite.getId(), "tenantId", "TEST-stack",
+ "TEST-heat", new HashMap<>(), false, 1, "TEST-env",
+ new HashMap<>(), new HashMap<>(), false);
+ assertNotNull(stackInfo);
+ }
}
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 65c7d093a9..59884f25b8 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
@@ -6,6 +6,7 @@
* Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
* ================================================================================
* Modifications Copyright (C) 2018 IBM.
+ * Modifications Copyright (c) 2019 Samsung
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -90,6 +91,7 @@ public class SDNCRestClient{
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
+ Thread.currentThread().interrupt();
}
String action = bpelRequest.getRequestHeader().getSvcAction();
diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/impl/SDNCRestClientTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/impl/SDNCRestClientTest.java
index 076a9f3c6a..01fa3db960 100644
--- a/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/impl/SDNCRestClientTest.java
+++ b/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/impl/SDNCRestClientTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -30,6 +32,7 @@ import org.junit.Test;
import org.onap.so.adapters.sdnc.BaseTest;
import org.springframework.beans.factory.annotation.Autowired;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
+import static org.junit.Assert.assertTrue;
public class SDNCRestClientTest extends BaseTest {
@@ -51,4 +54,11 @@ public class SDNCRestClientTest extends BaseTest {
SDNCResponse response = sdncClient.getSdncResp("", rt);
assertNotNull(response);
}
+
+ @Test
+ public void executeRequestInterrupted() {
+ Thread.currentThread().interrupt();
+ sdncClient.executeRequest(null);
+ assertTrue(Thread.interrupted());
+ }
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java
index 798837fa7d..e0cbb82484 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -21,23 +23,20 @@
package org.onap.so.bpmn.infrastructure.appc.tasks;
import java.util.HashMap;
-import java.util.List;
import java.util.Optional;
-
-import org.camunda.bpm.engine.delegate.BpmnError;
+import org.onap.appc.client.lcm.model.Action;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
-import org.onap.so.db.catalog.client.CatalogDbClient;
-import org.onap.so.db.catalog.beans.ControllerSelectionReference;
+import org.onap.so.client.appc.ApplicationControllerAction;
import org.onap.so.client.exception.BBObjectNotFoundException;
import org.onap.so.client.exception.ExceptionBuilder;
-import org.onap.appc.client.lcm.model.Action;
-import org.onap.so.bpmn.common.BuildingBlockExecution;
-import org.onap.so.client.appc.ApplicationControllerAction;
+import org.onap.so.db.catalog.beans.ControllerSelectionReference;
+import org.onap.so.db.catalog.client.CatalogDbClient;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -84,13 +83,20 @@ public class AppcRunTasks {
} catch (BBObjectNotFoundException e) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "No valid VNF exists");
}
- String vnfId = vnf.getVnfId();
+ String vnfId = null;
+ String vnfName = null;
+ String vnfType = null;
+ String vnfHostIpAddress = null;
+
+ if (vnf != null) {
+ vnfId = vnf.getVnfId();
+ vnfName = vnf.getVnfName();
+ vnfType = vnf.getVnfType();
+ vnfHostIpAddress = vnf.getIpv4OamAddress();
+ }
String msoRequestId = gBBInput.getRequestContext().getMsoRequestId();
- String vnfName = vnf.getVnfName();
- String vnfType = vnf.getVnfType();
-
+
String aicIdentity = execution.getVariable("aicIdentity");
- String vnfHostIpAddress = vnf.getIpv4OamAddress();
String vmIdList = execution.getVariable("vmIdList");
String vserverIdList = execution.getVariable("vserverIdList");
String identityUrl = execution.getVariable("identityUrl");
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java
index 114066aae3..7495cc1e8d 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -20,19 +22,32 @@
package org.onap.so.bpmn.infrastructure.appc.tasks;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import org.junit.Test;
+import org.mockito.InjectMocks;
import org.onap.appc.client.lcm.model.Action;
+import org.onap.so.bpmn.BaseTaskTest;
import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
+import org.onap.so.client.exception.BBObjectNotFoundException;
+import org.onap.so.db.catalog.beans.ControllerSelectionReference;
-public class AppcRunTasksTest {
+public class AppcRunTasksTest extends BaseTaskTest {
-
+ @InjectMocks
private AppcRunTasks appcRunTasks = new AppcRunTasks();
+
@Test
public void mapRollbackVariablesTest() {
@@ -53,4 +68,101 @@ public class AppcRunTasksTest {
appcRunTasks.mapRollbackVariables(mock, Action.ResumeTraffic, "0");
verify(mock, times(1)).setVariable("rollbackQuiesceTraffic", false);
}
+
+ @Test
+ public void runAppcCommandVnfNull() throws BBObjectNotFoundException {
+ execution.getLookupMap().put(ResourceKey.GENERIC_VNF_ID, "NULL-TEST");
+ fillRequiredAppcExecutionFields();
+ when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.GENERIC_VNF_ID), eq("NULL-TEST")))
+ .thenReturn(null);
+ when(catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(
+ isNull(), eq(Action.Lock.toString()))).
+ thenThrow(new IllegalArgumentException("name or values is null"));
+
+ appcRunTasks.runAppcCommand(execution, Action.Lock);
+
+ // if vnf = null -> vnfType = null ->
+ // IllegalArgumentException will be thrown in catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory
+ verify(exceptionUtil, times(1)).
+ buildAndThrowWorkflowException(
+ any(BuildingBlockExecution.class), eq(1002), eq("name or values is null"));
+ }
+
+ @Test
+ public void runAppcCommandBBObjectNotFoundException() throws BBObjectNotFoundException {
+ execution.getLookupMap().put(ResourceKey.GENERIC_VNF_ID, "EXCEPTION-TEST");
+ fillRequiredAppcExecutionFields();
+ when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.GENERIC_VNF_ID), eq("EXCEPTION-TEST")))
+ .thenThrow(new BBObjectNotFoundException());
+
+ appcRunTasks.runAppcCommand(execution, Action.Lock);
+
+ verify(exceptionUtil, times(1)).
+ buildAndThrowWorkflowException(
+ any(BuildingBlockExecution.class), eq(7000), eq("No valid VNF exists"));
+ }
+
+ @Test
+ public void runAppcCommandVfModuleNull() throws BBObjectNotFoundException {
+ execution.getLookupMap().put(ResourceKey.GENERIC_VNF_ID, "SUCCESS-TEST");
+ fillRequiredAppcExecutionFields();
+ GenericVnf genericVnf = getTestGenericVnf();
+ when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.GENERIC_VNF_ID), eq("SUCCESS-TEST")))
+ .thenReturn(genericVnf);
+ mockReferenceResponse();
+ execution.getLookupMap().put(ResourceKey.VF_MODULE_ID, "VF-MODULE-ID-TEST");
+ when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.VF_MODULE_ID), eq("VF-MODULE-ID-TEST")))
+ .thenReturn(null);
+ when(appCClient.getErrorCode()).thenReturn("0");
+
+ appcRunTasks.runAppcCommand(execution, Action.Lock);
+
+ assertEquals(true, execution.getVariable("rollbackVnfLock"));
+ }
+
+ @Test
+ public void runAppcCommand() throws BBObjectNotFoundException {
+ execution.getLookupMap().put(ResourceKey.GENERIC_VNF_ID, "SUCCESS-TEST");
+ fillRequiredAppcExecutionFields();
+ GenericVnf genericVnf = getTestGenericVnf();
+ when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.GENERIC_VNF_ID), eq("SUCCESS-TEST")))
+ .thenReturn(genericVnf);
+ mockReferenceResponse();
+ execution.getLookupMap().put(ResourceKey.VF_MODULE_ID, "VF-MODULE-ID-TEST");
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleId("VF-MODULE-ID");
+ when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.VF_MODULE_ID), eq("VF-MODULE-ID-TEST")))
+ .thenReturn(vfModule);
+ when(appCClient.getErrorCode()).thenReturn("0");
+
+ appcRunTasks.runAppcCommand(execution, Action.Lock);
+
+ assertEquals(true, execution.getVariable("rollbackVnfLock"));
+ }
+
+ private void mockReferenceResponse() {
+ ControllerSelectionReference reference = new ControllerSelectionReference();
+ reference.setControllerName("TEST-CONTROLLER-NAME");
+ when(catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(
+ eq("TEST-VNF-TYPE"), eq(Action.Lock.toString()))).thenReturn(reference);
+ }
+
+ private void fillRequiredAppcExecutionFields() {
+ RequestContext context = new RequestContext();
+ context.setMsoRequestId("TEST-MSO-ID");
+ execution.setVariable("aicIdentity", "AIC-TEST");
+ execution.setVariable("vmIdList", "VM-ID-LIST-TEST");
+ execution.setVariable("vserverIdList", "VSERVER-ID-LIST");
+ execution.setVariable("identityUrl", "IDENTITY-URL-TEST");
+ execution.getGeneralBuildingBlock().setRequestContext(context);
+ }
+
+ private GenericVnf getTestGenericVnf() {
+ GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId("TEST-VNF-ID");
+ genericVnf.setVnfType("TEST-VNF-TYPE");
+ genericVnf.setVnfName("TEST-VNF-NAME");
+ genericVnf.setIpv4OamAddress("129.0.0.1");
+ return genericVnf;
+ }
}
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIClient.java b/common/src/main/java/org/onap/so/client/aai/AAIClient.java
index 21bbc51f89..72a381a048 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAIClient.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAIClient.java
@@ -44,6 +44,7 @@ public class AAIClient extends GraphInventoryClient {
protected AAIClient(AAIVersion version) {
super(AAIProperties.class);
+ this.version = version;
}
@Override
protected URI constructPath(GraphInventoryUri uri) {
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryResultWrapper.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryResultWrapper.java
index cc1ce0063b..2f71358f04 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryResultWrapper.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryResultWrapper.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -59,7 +61,7 @@ public class GraphInventoryResultWrapper implements Serializable {
try {
return mapper.writeValueAsString(aaiObject);
} catch (JsonProcessingException e) {
- logger.warn("could not parse object into json - defaulting to {}");
+ logger.warn("could not parse object into json - defaulting to empty object");
return "{}";
}
}
diff --git a/common/src/main/java/org/onap/so/openpojo/rules/EqualsAndHashCodeTester.java b/common/src/main/java/org/onap/so/openpojo/rules/EqualsAndHashCodeTester.java
index 5433681b83..88a83db7e2 100644
--- a/common/src/main/java/org/onap/so/openpojo/rules/EqualsAndHashCodeTester.java
+++ b/common/src/main/java/org/onap/so/openpojo/rules/EqualsAndHashCodeTester.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -59,6 +61,10 @@ public class EqualsAndHashCodeTester implements Tester {
this.onlyDeclaredMethods = true;
return this;
}
+
+ // Marks sonar warnings about object being compared to itself as false positive
+ // https://sonar.onap.org/coding_rules#rule_key=squid%3AS1764
+ @SuppressWarnings("squid:S1764")
@Override
public void run(PojoClass pojoClass) {
Class<?> clazz = pojoClass.getClazz();
@@ -104,9 +110,9 @@ public class EqualsAndHashCodeTester implements Tester {
Affirm.affirmTrue("Equals test failed for [" + classInstanceOne.getClass().getName() + "]", classInstanceOne.equals(classInstanceTwo));
- Affirm.affirmTrue("Equals test failed for [" + classInstanceOne.getClass().getName() + "]", classInstanceOne.equals(
- classInstanceOne));
-
+ Affirm.affirmTrue("Expected true for comparison of the same references [" + classInstanceOne.getClass().getName() + "]",
+ classInstanceOne.equals(classInstanceOne));
+
Affirm.affirmTrue("HashCode test failed for [" + classInstanceOne.getClass().getName() + "]", classInstanceOne.hashCode() == classInstanceTwo.hashCode());
Affirm.affirmFalse("Expected false for comparison of two unlike objects", classInstanceOne.equals("test"));
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
index 66b04b6fdb..312db9a338 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
@@ -81,6 +81,7 @@ import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
import org.onap.so.serviceinstancebeans.VfModules;
import org.onap.so.serviceinstancebeans.Vnfs;
+import org.onap.so.utils.CryptoUtils;
import org.onap.so.utils.UUIDChecker;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
@@ -111,6 +112,7 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.net.URL;
+import java.security.GeneralSecurityException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
@@ -1176,7 +1178,7 @@ public class ServiceInstances {
String requestId = duplicateRecord.getRequestId();
String path = env.getProperty("mso.camunda.rest.history.uri") + requestId;
String targetUrl = env.getProperty("mso.camundaURL") + path;
- HttpHeaders headers = setHeaders(env.getProperty("mso.camundaAuth"));
+ HttpHeaders headers = setHeaders(env.getRequiredProperty("mso.camundaAuth"), env.getRequiredProperty("mso.msoKey"));
HttpEntity<?> requestEntity = new HttpEntity<>(headers);
ResponseEntity<List<HistoricProcessInstanceEntity>> response = null;
try{
@@ -1200,12 +1202,19 @@ public class ServiceInstances {
}
return false;
}
- private HttpHeaders setHeaders(String auth) {
+ private HttpHeaders setHeaders(String auth, String msoKey) {
HttpHeaders headers = new HttpHeaders();
List<org.springframework.http.MediaType> acceptableMediaTypes = new ArrayList<>();
acceptableMediaTypes.add(org.springframework.http.MediaType.APPLICATION_JSON);
headers.setAccept(acceptableMediaTypes);
- headers.add(HttpHeaders.AUTHORIZATION, auth);
+ try {
+ String userCredentials = CryptoUtils.decrypt(auth, msoKey);
+ if(userCredentials != null) {
+ headers.add(HttpHeaders.AUTHORIZATION, userCredentials);
+ }
+ } catch(GeneralSecurityException e) {
+ msoLogger.error("Security exception", e);
+ }
return headers;
}