aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-impl
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-impl')
-rw-r--r--models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java24
-rw-r--r--models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiManagerTest.java14
-rw-r--r--models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java100
-rw-r--r--models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PairTest.java43
-rw-r--r--models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java290
-rw-r--r--models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java13
-rw-r--r--models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java10
-rw-r--r--models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java99
-rw-r--r--models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java16
-rw-r--r--models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java10
10 files changed, 283 insertions, 336 deletions
diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java
index 81aea9f98..76817dfc6 100644
--- a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java
+++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java
@@ -3,7 +3,7 @@
* aai
* ================================================================================
* Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,6 +29,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.Pair;
import org.json.JSONArray;
import org.json.JSONObject;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -37,7 +38,6 @@ import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.rest.RestManager;
-import org.onap.policy.rest.RestManager.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -154,17 +154,17 @@ public final class AaiManager {
return null;
}
- int httpResponseCode = httpDetails.first;
+ int httpResponseCode = httpDetails.getLeft();
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, url, "Response code: " + httpResponseCode);
- NetLoggerUtil.getNetworkLogger().debug(httpDetails.second);
+ NetLoggerUtil.getNetworkLogger().debug(httpDetails.getRight());
logger.debug(url);
logger.debug("{}", httpResponseCode);
- logger.debug(httpDetails.second);
+ logger.debug(httpDetails.getRight());
- if (httpDetails.second != null) {
- return new AaiCqResponse(httpDetails.second);
+ if (httpDetails.getRight() != null) {
+ return new AaiCqResponse(httpDetails.getRight());
}
return null;
}
@@ -197,17 +197,17 @@ public final class AaiManager {
return null;
}
- int httpResponseCode = httpDetailsGet.first;
+ int httpResponseCode = httpDetailsGet.getLeft();
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, url, "Response code: " + httpResponseCode);
- NetLoggerUtil.getNetworkLogger().debug(httpDetailsGet.second);
+ NetLoggerUtil.getNetworkLogger().debug(httpDetailsGet.getRight());
logger.debug(urlGet);
logger.debug("{}", httpResponseCode);
- logger.debug(httpDetailsGet.second);
+ logger.debug(httpDetailsGet.getRight());
- if (httpResponseCode == 200 && httpDetailsGet.second != null) {
- return httpDetailsGet.second;
+ if (httpResponseCode == 200 && httpDetailsGet.getRight() != null) {
+ return httpDetailsGet.getRight();
}
try {
Thread.sleep(1000);
diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiManagerTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiManagerTest.java
index 8a007fb4a..33934d937 100644
--- a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiManagerTest.java
+++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiManagerTest.java
@@ -3,7 +3,7 @@
* aai
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,10 +37,10 @@ import java.io.IOException;
import java.nio.file.Files;
import java.util.Map;
import java.util.UUID;
+import org.apache.commons.lang3.tuple.Pair;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.rest.RestManager;
-import org.onap.policy.rest.RestManager.Pair;
public class AaiManagerTest {
private static final String CQ_QUERY_URL = "http://testing.cq.query";
@@ -66,10 +66,10 @@ public class AaiManagerTest {
String aaiCqResponse = new AaiCqResponseTest().getAaiCqResponse();
String tenantResponse = this.getTenantQueryResponse();
- httpCqResponseOk = restManagerMock.new Pair<>(200, aaiCqResponse);
- httpTenantResponseOk = restManagerMock.new Pair<>(200, tenantResponse);
- httpResponseErr0 = restManagerMock.new Pair<>(200, null);
- httpResponseErr1 = restManagerMock.new Pair<>(200, "{");
+ httpCqResponseOk = Pair.of(200, aaiCqResponse);
+ httpTenantResponseOk = Pair.of(200, tenantResponse);
+ httpResponseErr0 = Pair.of(200, null);
+ httpResponseErr1 = Pair.of(200, "{");
}
@@ -128,7 +128,7 @@ public class AaiManagerTest {
String pnfResponse = "{\"pnf-name\":" + pnfName
+ ",\"pnf-id\":\"123456\",\"in-maint\":false,\"ipaddress-v4-oam\":\"1.1.1.1\"}";
- Pair<Integer, String> pnfHttpResponse = restManagerMock.new Pair<>(200, pnfResponse);
+ Pair<Integer, String> pnfHttpResponse = Pair.of(200, pnfResponse);
when(restManagerMock.get(contains(pnfName), eq(DOROTHY), eq("Gale"), anyMap()))
.thenReturn(pnfHttpResponse);
diff --git a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java
index a452c142f..4f37e9592 100644
--- a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java
+++ b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java
@@ -3,7 +3,7 @@
* rest
* ================================================================================
* Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.bind.DatatypeConverter;
+import org.apache.commons.lang3.tuple.Pair;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
@@ -47,29 +48,19 @@ public class RestManager {
// Constants for string literals
private static final String CONTENT_TYPE = "Content-Type";
- public class Pair<A, B> {
- public final A first;
- public final B second;
-
- public Pair(A first, B second) {
- this.first = first;
- this.second = second;
- }
- }
-
/**
* Perform REST PUT.
*
- * @param url the url
- * @param username the user name
- * @param password the password
- * @param headers any headers
+ * @param url the url
+ * @param username the user name
+ * @param password the password
+ * @param headers any headers
* @param contentType what the content type is
- * @param body body to send
+ * @param body body to send
* @return the response status code and the body
*/
- public Pair<Integer, String> put(String url, String username, String password,
- Map<String, String> headers, String contentType, String body) {
+ public Pair<Integer, String> put(String url, String username, String password, Map<String, String> headers,
+ String contentType, String body) {
HttpPut put = new HttpPut(url);
addHeaders(put, username, password, headers);
put.addHeader(CONTENT_TYPE, contentType);
@@ -87,16 +78,16 @@ public class RestManager {
/**
* Perform REST Post.
*
- * @param url the url
- * @param username the user name
- * @param password the password
- * @param headers any headers
+ * @param url the url
+ * @param username the user name
+ * @param password the password
+ * @param headers any headers
* @param contentType what the content type is
- * @param body body to send
+ * @param body body to send
* @return the response status code and the body
*/
- public Pair<Integer, String> post(String url, String username, String password,
- Map<String, String> headers, String contentType, String body) {
+ public Pair<Integer, String> post(String url, String username, String password, Map<String, String> headers,
+ String contentType, String body) {
HttpPost post = new HttpPost(url);
addHeaders(post, username, password, headers);
post.addHeader(CONTENT_TYPE, contentType);
@@ -114,14 +105,13 @@ public class RestManager {
/**
* Do a REST get.
*
- * @param url URL
+ * @param url URL
* @param username user name
* @param password password
- * @param headers any headers to add
+ * @param headers any headers to add
* @return a Pair for the response status and the body
*/
- public Pair<Integer, String> get(String url, String username, String password,
- Map<String, String> headers) {
+ public Pair<Integer, String> get(String url, String username, String password, Map<String, String> headers) {
HttpGet get = new HttpGet(url);
addHeaders(get, username, password, headers);
return sendRequest(get);
@@ -131,16 +121,16 @@ public class RestManager {
* Perform REST Delete. <br/>
* <i>Note: Many REST endpoints will return a 400 error for delete requests with a non-empty body</i>
*
- * @param url the url
- * @param username the user name
- * @param password the password
- * @param headers any headers
+ * @param url the url
+ * @param username the user name
+ * @param password the password
+ * @param headers any headers
* @param contentType what the content type is
- * @param body body (optional) to send
+ * @param body body (optional) to send
* @return the response status code and the body
*/
public Pair<Integer, String> delete(String url, String username, String password, Map<String, String> headers,
- String contentType, String body) {
+ String contentType, String body) {
HttpDeleteWithBody delete = new HttpDeleteWithBody(url);
addHeaders(delete, username, password, headers);
if (body != null && !body.isEmpty()) {
@@ -160,10 +150,10 @@ public class RestManager {
/**
* Perform REST Delete.
*
- * @param url the url
- * @param username the user name
- * @param password the password
- * @param headers any headers
+ * @param url the url
+ * @param username the user name
+ * @param password the password
+ * @param headers any headers
* @return the response status code and the body
*/
public Pair<Integer, String> delete(String url, String username, String password, Map<String, String> headers) {
@@ -175,15 +165,15 @@ public class RestManager {
/**
* Perform REST Patch.
*
- * @param url the url
- * @param username the user name
- * @param password the password
- * @param headers any headers
- * @param body body to send
+ * @param url the url
+ * @param username the user name
+ * @param password the password
+ * @param headers any headers
+ * @param body body to send
* @return the response status code and the body
*/
- public Pair<Integer, String> patch(String url, String username, String password,
- Map<String, String> headers, String body) {
+ public Pair<Integer, String> patch(String url, String username, String password, Map<String, String> headers,
+ String body) {
String contentType = "application/merge-patch+json";
HttpPatch patch = new HttpPatch(url);
addHeaders(patch, username, password, headers);
@@ -211,20 +201,15 @@ public class RestManager {
}
try (CloseableHttpClient client =
- HttpClientBuilder
- .create()
- .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
- .build()) {
+ HttpClientBuilder.create().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build()) {
HttpResponse response = client.execute(request);
if (response != null) {
String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8");
- logger.debug("HTTP Response Status Code: {}",
- response.getStatusLine().getStatusCode());
+ logger.debug("HTTP Response Status Code: {}", response.getStatusLine().getStatusCode());
logger.debug("HTTP Response Body:");
logger.debug(returnBody);
- return new Pair<>(response.getStatusLine().getStatusCode(),
- returnBody);
+ return Pair.of(response.getStatusLine().getStatusCode(), returnBody);
} else {
logger.error("Response from {} is null", request.getURI());
return null;
@@ -238,13 +223,12 @@ public class RestManager {
/**
* Add header to the request.
*
- * @param request http request to send
+ * @param request http request to send
* @param username the user name
* @param password the password
- * @param headers any headers
+ * @param headers any headers
*/
- private void addHeaders(HttpRequestBase request, String username, String password, Map<String,
- String> headers) {
+ private void addHeaders(HttpRequestBase request, String username, String password, Map<String, String> headers) {
String authHeader = makeAuthHeader(username, password);
if (headers != null) {
for (Entry<String, String> entry : headers.entrySet()) {
diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PairTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PairTest.java
deleted file mode 100644
index 2db9ebca0..000000000
--- a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PairTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * rest
- * ================================================================================
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved
- * Modifications Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.rest;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.onap.policy.rest.RestManager.Pair;
-
-public class PairTest {
-
- @Test
- public void testPair() {
- RestManager mgr = new RestManager();
-
- Pair<Integer, Integer> pii = mgr.new Pair<>(1, 2);
- assertEquals((Integer) 1, pii.first);
- assertEquals((Integer) 2, pii.second);
-
- Pair<Integer, String> pis = mgr.new Pair<>(1, "test");
- assertEquals((Integer) 1, pis.first);
- assertEquals("test", pis.second);
- }
-}
diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java
index 8c241c83e..52c0912e3 100644
--- a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java
+++ b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java
@@ -3,7 +3,7 @@
* rest
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,13 +41,13 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
+import org.apache.commons.lang3.tuple.Pair;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
import org.onap.policy.common.utils.network.NetworkUtil;
-import org.onap.policy.rest.RestManager.Pair;
@Path("RestTest")
public class RestTest {
@@ -144,58 +144,60 @@ public class RestTest {
RestManager mgr = new RestManager();
Pair<Integer, String> result = mgr.get(getUri, null, null, null);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("GOT: " + EXPECT_STRING, result.second);
+
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("GOT: " + EXPECT_STRING, result.getRight());
result = mgr.delete(deleteUri, null, null, null, null, null);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("DELETE: " + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("DELETE: " + EXPECT_STRING, result.getRight());
result = mgr.delete(deleteUri, null, null, null);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("DELETE: " + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("DELETE: " + EXPECT_STRING, result.getRight());
result = mgr.put(putUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight());
result = mgr.put(putUriBlank, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight());
result = mgr.post(postUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight());
result = mgr.post(postUriBlank, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight());
result = mgr.patch(patchUri, null, null, null, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight());
result = mgr.patch(patchUriBlank, null, null, null, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight());
+
}
@Test
@@ -203,52 +205,54 @@ public class RestTest {
RestManager mgr = new RestManager();
Pair<Integer, String> result = mgr.get(getUri, "", null, null);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("GOT: " + EXPECT_STRING, result.second);
+
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("GOT: " + EXPECT_STRING, result.getRight());
result = mgr.delete(deleteUri, "", null, null, null, null);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("DELETE: " + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("DELETE: " + EXPECT_STRING, result.getRight());
result = mgr.put(putUri, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight());
result = mgr.put(putUriBlank, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight());
result = mgr.post(postUri, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight());
result = mgr.post(postUriBlank, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight());
result = mgr.patch(patchUri, "", null, null, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight());
result = mgr.patch(patchUriBlank, "", null, null, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight());
+
}
@Test
@@ -256,52 +260,54 @@ public class RestTest {
RestManager mgr = new RestManager();
Pair<Integer, String> result = mgr.get(getUri, "user", null, null);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("GOT: " + EXPECT_STRING, result.second);
+
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("GOT: " + EXPECT_STRING, result.getRight());
result = mgr.delete(deleteUri, "user", null, null, null, null);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("DELETE: " + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("DELETE: " + EXPECT_STRING, result.getRight());
result = mgr.put(putUri, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight());
result = mgr.put(putUriBlank, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight());
result = mgr.post(postUri, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight());
result = mgr.post(postUriBlank, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight());
result = mgr.patch(patchUri, "user", null, null, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight());
result = mgr.patch(patchUriBlank, "user", null, null, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight());
+
}
@Test
@@ -309,19 +315,21 @@ public class RestTest {
RestManager mgr = new RestManager();
Pair<Integer, String> result = mgr.get(baseUri + "RestTest/GetHello/", null, null, null);
- assertEquals((Integer) 404, result.first);
+
+ assertEquals((Integer) 404, result.getLeft());
result = mgr.delete(baseUri + "RestTest/DeleteHello/", null, null, null, null, null);
- assertEquals((Integer) 404, result.first);
+ assertEquals((Integer) 404, result.getLeft());
result = mgr.put(baseUri + "RestTest/PutHello/", null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 404, result.first);
+ assertEquals((Integer) 404, result.getLeft());
result = mgr.post(baseUri + "RestTest/PostHello/", null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 404, result.first);
+ assertEquals((Integer) 404, result.getLeft());
result = mgr.patch(baseUri + "RestTest/PatchHello/", null, null, null, PAYLOAD);
- assertEquals((Integer) 404, result.first);
+ assertEquals((Integer) 404, result.getLeft());
+
}
@Test
@@ -329,36 +337,38 @@ public class RestTest {
RestManager mgr = new RestManager();
Pair<Integer, String> result = mgr.get(baseUri + "RestTest/GetHello/" + NAME_PARAM, null, null, null);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("GOT: " + RETURN_STRING + NAME_PARAM + " aged 90", result.second);
+
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("GOT: " + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight());
result = mgr.delete(baseUri + "RestTest/DeleteHello/" + NAME_PARAM, null, null, null, null, null);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("DELETE: " + RETURN_STRING + NAME_PARAM + " aged 90", result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("DELETE: " + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight());
result = mgr.put(baseUri + "RestTest/PutHello/" + NAME_PARAM, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PUT: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PUT: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight());
result = mgr.post(baseUri + "RestTest/PostHello/" + NAME_PARAM, null, null,
null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("POST: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("POST: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight());
result = mgr.patch(baseUri + "RestTest/PatchHello/" + NAME_PARAM, null, null,
null, PAYLOAD);
- assertEquals((Integer) 200, result.first);
- assertTrue(result.second != null);
- assertTrue(result.second.length() > 0);
- assertEquals("PATCH: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.second);
+ assertEquals((Integer) 200, result.getLeft());
+ assertTrue(result.getRight() != null);
+ assertTrue(result.getRight().length() > 0);
+ assertEquals("PATCH: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight());
+
}
@Test
@@ -366,19 +376,21 @@ public class RestTest {
RestManager mgr = new RestManager();
Pair<Integer, String> result = mgr.get(baseUri + "NonExistant/URL/", null, null, null);
- assertEquals((Integer) 404, result.first);
+
+ assertEquals((Integer) 404, result.getLeft());
result = mgr.delete(baseUri + "NonExistant/URL/", null, null, null, null, null);
- assertEquals((Integer) 404, result.first);
+ assertEquals((Integer) 404, result.getLeft());
result = mgr.put(baseUri + "NonExistant/URL/", null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 404, result.first);
+ assertEquals((Integer) 404, result.getLeft());
result = mgr.post(baseUri + "NonExistant/URL/", null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 404, result.first);
+ assertEquals((Integer) 404, result.getLeft());
result = mgr.patch(baseUri + "NonExistant/URL/", null, null, null, PAYLOAD);
- assertEquals((Integer) 404, result.first);
+ assertEquals((Integer) 404, result.getLeft());
+
}
@Test
@@ -386,22 +398,24 @@ public class RestTest {
RestManager mgr = new RestManager();
Pair<Integer, String> result = mgr.get(deleteUri, null, null, null);
- assertEquals((Integer) 405, result.first);
+
+ assertEquals((Integer) 405, result.getLeft());
result = mgr.delete(getUri, null, null, null, null, null);
- assertEquals((Integer) 405, result.first);
+ assertEquals((Integer) 405, result.getLeft());
result = mgr.delete(getUri, null, null, null);
- assertEquals((Integer) 405, result.first);
+ assertEquals((Integer) 405, result.getLeft());
result = mgr.put(getUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 405, result.first);
+ assertEquals((Integer) 405, result.getLeft());
result = mgr.post(getUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD);
- assertEquals((Integer) 405, result.first);
+ assertEquals((Integer) 405, result.getLeft());
result = mgr.patch(getUri, null, null, null, PAYLOAD);
- assertEquals((Integer) 405, result.first);
+ assertEquals((Integer) 405, result.getLeft());
+
}
@GET
diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
index 65b655936..ec423c758 100644
--- a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
+++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
@@ -3,7 +3,7 @@
* Copyright (C) 2018 Huawei. All rights reserved.
* ================================================================================
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,11 +25,11 @@ package org.onap.policy.sdnc;
import com.google.gson.JsonSyntaxException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.rest.RestManager;
-import org.onap.policy.rest.RestManager.Pair;
import org.onap.policy.sdnc.util.Serialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -125,9 +125,9 @@ public final class SdncManager implements Runnable {
}
try {
- SdncResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SdncResponse.class);
- NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, sdncUrl, httpDetails.second);
- logger.info("[IN|{}|{}|]{}{}", "Sdnc", sdncUrl, NetLoggerUtil.SYSTEM_LS, httpDetails.second);
+ SdncResponse response = Serialization.gsonPretty.fromJson(httpDetails.getRight(), SdncResponse.class);
+ NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, sdncUrl, httpDetails.getRight());
+ logger.info("[IN|{}|{}|]{}{}", "Sdnc", sdncUrl, NetLoggerUtil.SYSTEM_LS, httpDetails.getRight());
String body = Serialization.gsonPretty.toJson(response);
logger.info("Response to Sdnc Heal post:");
logger.info(body);
@@ -135,7 +135,8 @@ public final class SdncManager implements Runnable {
if (!"200".equals(response.getResponseOutput().getResponseCode())) {
logger.info(
- "Sdnc Heal Restcall failed with http error code {} {}", httpDetails.first, httpDetails.second
+ "Sdnc Heal Restcall failed with http error code {} {}",
+ httpDetails.getLeft(), httpDetails.getRight()
);
}
diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java
index b962ce8c7..45461de43 100644
--- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java
+++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java
@@ -5,7 +5,7 @@
* Copyright (C) 2018 Huawei. All rights reserved.
* ================================================================================
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,10 +34,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.UUID;
+import org.apache.commons.lang3.tuple.Pair;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.rest.RestManager;
-import org.onap.policy.rest.RestManager.Pair;
import org.onap.policy.sdnc.SdncManager.SdncCallback;
import org.onap.policy.sdnc.util.Serialization;
@@ -62,9 +62,9 @@ public class SdncManagerTest implements SdncCallback {
public void setupMockedRest() {
mockedRestManager = mock(RestManager.class);
- httpResponsePutOk = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
- httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null));
- httpResponseErr = mockedRestManager.new Pair<>(200, null);
+ httpResponsePutOk = Pair.of(202, Serialization.gsonPretty.toJson(response));
+ httpResponseBadResponse = Pair.of(202, Serialization.gsonPretty.toJson(null));
+ httpResponseErr = Pair.of(200, null);
}
/**
diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java
index 51cca5225..5b8aef264 100644
--- a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java
+++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java
@@ -3,7 +3,7 @@
* so
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,19 +30,18 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.rest.RestManager;
-import org.onap.policy.rest.RestManager.Pair;
import org.onap.policy.so.util.Serialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
- * This class handles the interface towards SO (Service Orchestrator) for the ONAP Policy
- * Framework. The SO API is defined at this link:
+ * This class handles the interface towards SO (Service Orchestrator) for the ONAP Policy Framework. The SO API is
+ * defined at this link:
* http://onap.readthedocs.io/en/latest/submodules/so.git/docs/SO_R1_Interface.html#get-orchestration-request
*
*/
@@ -97,13 +96,13 @@ public final class SoManager {
* @return the SO Response object
*/
public SoResponse createModuleInstance(final String url, final String urlBase, final String username,
- final String password, final SoRequest request) {
+ final String password, final SoRequest request) {
// Issue the HTTP POST request to SO to create the service instance
String requestJson = Serialization.gsonPretty.toJson(request);
NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|{}|{}|{}|{}|]{}{}", "SO", url, username, password,
- createSimpleHeaders(), MEDIA_TYPE, LINE_SEPARATOR, requestJson);
+ createSimpleHeaders(), MEDIA_TYPE, LINE_SEPARATOR, requestJson);
Pair<Integer, String> httpResponse =
- restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, requestJson);
+ restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, requestJson);
// Process the response from SO
SoResponse response = waitForSoOperationCompletion(urlBase, username, password, url, httpResponse);
@@ -115,34 +114,29 @@ public final class SoManager {
}
/**
- * Works just like SOManager#asyncSORestCall(String, WorkingMemory, String, String, String, SORequest)
- * except the vfModuleInstanceId is always null.
+ * Works just like SOManager#asyncSORestCall(String, WorkingMemory, String, String, String, SORequest) except the
+ * vfModuleInstanceId is always null.
*
*/
public Future<SoResponse> asyncSoRestCall(final String requestId, final SoCallback callback,
- final String serviceInstanceId, final String vnfInstanceId,
- final SoRequest request) {
+ final String serviceInstanceId, final String vnfInstanceId, final SoRequest request) {
return asyncSoRestCall(requestId, callback, serviceInstanceId, vnfInstanceId, null, request);
}
/**
- * This method makes an asynchronous Rest call to MSO and inserts the response into
- * Drools working memory.
+ * This method makes an asynchronous Rest call to MSO and inserts the response into Drools working memory.
*
- * @param requestId the request id
- * @param callback callback method
- * @param serviceInstanceId service instance id to construct the request url
- * @param vnfInstanceId vnf instance id to construct the request url
+ * @param requestId the request id
+ * @param callback callback method
+ * @param serviceInstanceId service instance id to construct the request url
+ * @param vnfInstanceId vnf instance id to construct the request url
* @param vfModuleInstanceId vfModule instance id to construct the request url (required in case of delete vf
- * module)
- * @param request the SO request
+ * module)
+ * @param request the SO request
* @return a concurrent Future for the thread that handles the request
*/
- public Future<SoResponse> asyncSoRestCall(final String requestId,
- final SoCallback callback,
- final String serviceInstanceId,
- final String vnfInstanceId,
- final String vfModuleInstanceId,
+ public Future<SoResponse> asyncSoRestCall(final String requestId, final SoCallback callback,
+ final String serviceInstanceId, final String vnfInstanceId, final String vfModuleInstanceId,
final SoRequest request) {
return executors.submit(new AsyncSoRestCallThread(requestId, callback, serviceInstanceId, vnfInstanceId,
vfModuleInstanceId, request, this));
@@ -165,17 +159,15 @@ public final class SoManager {
/**
* Constructor, sets the context of the request.
*
- * @param requestID The request ID
- * @param wm reference to the Drools working memory
- * @param serviceInstanceId the service instance in SO to use
- * @param vnfInstanceId the VNF instance that is the subject of the request
+ * @param requestID The request ID
+ * @param wm reference to the Drools working memory
+ * @param serviceInstanceId the service instance in SO to use
+ * @param vnfInstanceId the VNF instance that is the subject of the request
* @param vfModuleInstanceId the vf module instance id (not null in case of delete vf module request)
- * @param request the request itself
+ * @param request the request itself
*/
- private AsyncSoRestCallThread(final String requestId,
- final SoCallback callback, final String serviceInstanceId,
- final String vnfInstanceId, final String vfModuleInstanceId,
- final SoRequest request,
+ private AsyncSoRestCallThread(final String requestId, final SoCallback callback, final String serviceInstanceId,
+ final String vnfInstanceId, final String vfModuleInstanceId, final SoRequest request,
final SoManager callingSoManager) {
this.requestId = requestId;
this.callback = callback;
@@ -199,15 +191,14 @@ public final class SoManager {
String initialUrl = null;
Pair<Integer, String> httpResponse = null;
- if (request.getOperationType() != null && request.getOperationType()
- .equals(SoOperationType.SCALE_OUT)) {
+ if (request.getOperationType() != null && request.getOperationType().equals(SoOperationType.SCALE_OUT)) {
initialUrl = this.baseUrl + "/serviceInstantiation/v7/serviceInstances/" + serviceInstanceId + "/vnfs/"
- + vnfInstanceId + "/vfModules/scaleOut";
+ + vnfInstanceId + "/vfModules/scaleOut";
NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, initialUrl, soJson);
- httpResponse = restManager.post(initialUrl, this.user, this.password, createSimpleHeaders(),
- MEDIA_TYPE, soJson);
- } else if (request.getOperationType() != null && request.getOperationType()
- .equals(SoOperationType.DELETE_VF_MODULE)) {
+ httpResponse = restManager.post(initialUrl, this.user, this.password, createSimpleHeaders(), MEDIA_TYPE,
+ soJson);
+ } else if (request.getOperationType() != null
+ && request.getOperationType().equals(SoOperationType.DELETE_VF_MODULE)) {
initialUrl = this.baseUrl + "/serviceInstances/v7/" + serviceInstanceId + "/vnfs/" + vnfInstanceId
+ "/vfModules/" + vfModuleInstanceId;
NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, initialUrl, soJson);
@@ -218,8 +209,8 @@ public final class SoManager {
}
// Process the response from SO
- SoResponse response = waitForSoOperationCompletion(this.baseUrl, this.user, this.password, initialUrl,
- httpResponse);
+ SoResponse response =
+ waitForSoOperationCompletion(this.baseUrl, this.user, this.password, initialUrl, httpResponse);
// Return the response to Drools in its working memory
SoResponseWrapper soWrapper = new SoResponseWrapper(response, requestId);
@@ -242,8 +233,7 @@ public final class SoManager {
* @return The parsed final response of SO to the request
*/
private SoResponse waitForSoOperationCompletion(final String urlBaseSo, final String username,
- final String password, final String initialRequestUrl,
- final Pair<Integer, String> initialHttpResponse) {
+ final String password, final String initialRequestUrl, final Pair<Integer, String> initialHttpResponse) {
// Process the initial response from SO, the response to a post
SoResponse response = processSoResponse(initialRequestUrl, initialHttpResponse);
if (SO_RESPONSE_ERROR == response.getHttpResponseCode()) {
@@ -278,7 +268,7 @@ public final class SoManager {
// Issue a GET to find the current status of our request
NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|{}|{}|{}|{}|]{}", "SO", urlGet, username, password,
- createSimpleHeaders(), MEDIA_TYPE, LINE_SEPARATOR);
+ createSimpleHeaders(), MEDIA_TYPE, LINE_SEPARATOR);
Pair<Integer, String> httpResponse = restManager.get(urlGet, username, password, createSimpleHeaders());
// Get our response
@@ -309,7 +299,7 @@ public final class SoManager {
// A null httpDetails indicates a HTTP problem, a valid response from SO must be
// either 200
// or 202
- if (!httpResultIsNullFree(httpResponse) || (httpResponse.first != 200 && httpResponse.first != 202)) {
+ if (!httpResultIsNullFree(httpResponse) || (httpResponse.getLeft() != 200 && httpResponse.getLeft() != 202)) {
logger.error("Invalid HTTP response received from SO");
response.setHttpResponseCode(SO_RESPONSE_ERROR);
return response;
@@ -317,7 +307,7 @@ public final class SoManager {
// Parse the JSON of the response into our POJO
try {
- response = Serialization.gsonPretty.fromJson(httpResponse.second, SoResponse.class);
+ response = Serialization.gsonPretty.fromJson(httpResponse.getRight(), SoResponse.class);
} catch (JsonSyntaxException e) {
logger.error("Failed to deserialize HTTP response into SOResponse: ", e);
response.setHttpResponseCode(SO_RESPONSE_ERROR);
@@ -326,14 +316,14 @@ public final class SoManager {
// Set the HTTP response code of the response if needed
if (response.getHttpResponseCode() == 0) {
- response.setHttpResponseCode(httpResponse.first);
+ response.setHttpResponseCode(httpResponse.getLeft());
}
- NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, requestUrl, httpResponse.second);
+ NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, requestUrl, httpResponse.getRight());
if (logger.isDebugEnabled()) {
logger.debug("***** Response to SO Request to URL {}:", requestUrl);
- logger.debug(httpResponse.second);
+ logger.debug(httpResponse.getRight());
}
return response;
@@ -356,7 +346,7 @@ public final class SoManager {
*/
private boolean isRequestStateDefined(final SoResponse response) {
return response != null && response.getRequest() != null && response.getRequest().getRequestStatus() != null
- && response.getRequest().getRequestStatus().getRequestState() != null;
+ && response.getRequest().getRequestStatus().getRequestState() != null;
}
/**
@@ -367,7 +357,7 @@ public final class SoManager {
* @return true if the request for the response is finished
*/
private boolean isRequestStateFinished(final Pair<Integer, String> latestHttpDetails, final SoResponse response) {
- if (latestHttpDetails != null && 200 == latestHttpDetails.first && isRequestStateDefined(response)) {
+ if (latestHttpDetails != null && 200 == latestHttpDetails.getLeft() && isRequestStateDefined(response)) {
String requestState = response.getRequest().getRequestStatus().getRequestState();
return "COMPLETE".equalsIgnoreCase(requestState) || "FAILED".equalsIgnoreCase(requestState);
} else {
@@ -382,7 +372,8 @@ public final class SoManager {
* @return true if no nulls are found
*/
private boolean httpResultIsNullFree(Pair<Integer, String> httpOperationResult) {
- return httpOperationResult != null && httpOperationResult.first != null && httpOperationResult.second != null;
+ return httpOperationResult != null && httpOperationResult.getLeft() != null
+ && httpOperationResult.getRight() != null;
}
/**
diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java
index 17f8a58f3..64d60ba1e 100644
--- a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java
+++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2017-2019 Intel Corp. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2018-2019 AT&T Corporation. All rights reserved.
* Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
* ================================================================================
@@ -24,11 +24,11 @@ package org.onap.policy.vfc;
import com.google.gson.JsonSyntaxException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.rest.RestManager;
-import org.onap.policy.rest.RestManager.Pair;
import org.onap.policy.vfc.util.Serialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -117,7 +117,7 @@ public final class VfcManager implements Runnable {
return;
}
- if (httpDetails.first != 202) {
+ if (httpDetails.getLeft() != 202) {
logger.warn("VFC Heal Restcall failed");
return;
}
@@ -144,8 +144,8 @@ public final class VfcManager implements Runnable {
*/
private void handleVfcResponse(Map<String, String> headers, Pair<Integer, String> httpDetails, String vfcUrl)
throws InterruptedException {
- VfcResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, VfcResponse.class);
- NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetails.second);
+ VfcResponse response = Serialization.gsonPretty.fromJson(httpDetails.getRight(), VfcResponse.class);
+ NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetails.getRight());
String body = Serialization.gsonPretty.toJson(response);
logger.debug("Response to VFC Heal post:");
logger.debug(body);
@@ -159,15 +159,15 @@ public final class VfcManager implements Runnable {
while (attemptsLeft-- > 0) {
NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|]", "VFC", urlGet);
Pair<Integer, String> httpDetailsGet = restManager.get(urlGet, username, password, headers);
- responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.second, VfcResponse.class);
- NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetailsGet.second);
+ responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.getRight(), VfcResponse.class);
+ NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetailsGet.getRight());
responseGet.setRequestId(vfcRequest.getRequestId().toString());
body = Serialization.gsonPretty.toJson(responseGet);
logger.debug("Response to VFC Heal get:");
logger.debug(body);
String responseStatus = responseGet.getResponseDescriptor().getStatus();
- if (httpDetailsGet.first == 200
+ if (httpDetailsGet.getLeft() == 200
&& ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) {
logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus());
this.callback.onResponse(responseGet);
diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
index 8db3438cc..fbe29c384 100644
--- a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
+++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
@@ -3,7 +3,7 @@
* vfc
* ================================================================================
* Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.. All rights reserved.
* Modifications Copyright (C) 2018-2019 AT&T Corporation. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,10 +35,10 @@ import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
+import org.apache.commons.lang3.tuple.Pair;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.rest.RestManager;
-import org.onap.policy.rest.RestManager.Pair;
import org.onap.policy.vfc.VfcManager.VfcCallback;
import org.onap.policy.vfc.util.Serialization;
@@ -64,9 +64,9 @@ public class VfcManagerTest implements VfcCallback {
public void setupMockedRest() {
mockedRestManager = mock(RestManager.class);
- httpResponsePutOk = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
- httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null));
- httpResponseErr = mockedRestManager.new Pair<>(200, null);
+ httpResponsePutOk = Pair.of(202, Serialization.gsonPretty.toJson(response));
+ httpResponseBadResponse = Pair.of(202, Serialization.gsonPretty.toJson(null));
+ httpResponseErr = Pair.of(200, null);
}
/**