aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common')
-rwxr-xr-xvid-app-common/pom.xml10
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java9
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java526
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/asdc/beans/Service.java183
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/asdc/rest/SdcRestClient.java2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java15
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/LoggerController.java6
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java14
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/MsoController.java3
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt9
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt23
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java3
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java6
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java186
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java24
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java81
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/properties/Features.java1
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java28
-rw-r--r--vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties1
-rw-r--r--vid-app-common/src/main/webapp/WEB-INF/conf/onap.features.properties1
-rwxr-xr-xvid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js1
-rwxr-xr-xvid-app-common/src/main/webapp/app/vid/scripts/controller/ServiceModelController.js4
-rw-r--r--vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js14
-rwxr-xr-xvid-app-common/src/main/webapp/app/vid/scripts/view-models/serviceModels.htm2
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java56
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java123
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientITTest.java16
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerNewTest.java4
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java6
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/job/command/ResourceCommandTest.java90
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/job/command/ServiceInProgressStatusCommandTest.java7
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java2
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java218
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java6
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java4
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java4
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java269
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java31
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AaiServiceTest.java21
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/JobsBrokerServiceTest.java112
42 files changed, 776 insertions, 1349 deletions
diff --git a/vid-app-common/pom.xml b/vid-app-common/pom.xml
index 78d9af771..21a67695e 100755
--- a/vid-app-common/pom.xml
+++ b/vid-app-common/pom.xml
@@ -607,6 +607,16 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-filter-base</artifactId>
+ <version>1.5.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-filter-spring</artifactId>
+ <version>1.5.1</version>
+ </dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
index 7e96c93cd..159401009 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
@@ -459,7 +459,7 @@ public class AaiClient implements AaiClientInterface {
}
@Override
- public AaiResponse getVNFData(String globalSubscriberId, String serviceType) {
+ public AaiResponse<AaiGetVnfResponse> getVNFData(String globalSubscriberId, String serviceType) {
String payload = "{\"start\": [\"business/customers/customer/" + globalSubscriberId + SERVICE_SUBSCRIPTIONS_PATH + encodePathSegment(serviceType) +"/service-instances\"]," +
"\"query\": \"query/vnf-topology-fromServiceInstance\"}";
Response resp = doAaiPut(QUERY_FORMAT_SIMPLE, payload, false);
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java
index af5429c28..2a879e295 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java
@@ -65,7 +65,7 @@ public interface AaiClientInterface extends ProbeInterface {
AaiResponse getInstanceGroupsByCloudRegion(String cloudOwner, String cloudRegionId, String networkFunction);
- AaiResponse getVNFData(String globalSubscriberId, String serviceType);
+ AaiResponse<AaiGetVnfResponse> getVNFData(String globalSubscriberId, String serviceType);
AaiResponse getVNFData(String globalSubscriberId, String serviceType, String serviceInstanceId);
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java
index f2f6ca50a..099f2449b 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java
@@ -32,6 +32,7 @@ public class ModelVer {
private String distributionStatus;
private String resourceVersion;
private String modelDescription;
+ private String orchestrationType;
@@ -89,4 +90,12 @@ public class ModelVer {
this.modelDescription = modelDescription;
}
+ public String getOrchestrationType() {
+ return orchestrationType;
+ }
+
+ @JsonAlias("orchestration-type")
+ public void setOrchestrationType(String orchestrationType) {
+ this.orchestrationType = orchestrationType;
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
index 034800516..4369c17fc 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
@@ -8,9 +8,9 @@
* 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.
@@ -22,7 +22,8 @@ package org.onap.vid.aai.util;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
-import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
+import static org.onap.vid.logging.Headers.INVOCATION_ID;
+import static org.onap.vid.logging.Headers.PARTNER_NAME;
import com.att.eelf.configuration.EELFLogger;
import java.io.UnsupportedEncodingException;
@@ -30,6 +31,7 @@ import java.net.URI;
import java.net.URLEncoder;
import java.util.Optional;
import java.util.UUID;
+import java.util.function.Supplier;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
@@ -41,6 +43,7 @@ import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.aai.ExceptionWithRequestInfo;
import org.onap.vid.aai.ResponseWithRequestInfo;
import org.onap.vid.aai.exceptions.InvalidPropertyException;
+import org.onap.vid.logging.RequestIdHeader;
import org.onap.vid.utils.Logging;
import org.onap.vid.utils.Unchecked;
import org.springframework.beans.factory.annotation.Autowired;
@@ -52,305 +55,222 @@ import org.springframework.http.HttpMethod;
*/
public class AAIRestInterface {
- /** The logger. */
- protected EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AAIRestInterface.class);
-
- protected final EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("aai");
-
- /** The client. */
- private Client client = null;
-
- /** The rest srvr base URL. */
- private String restSrvrBaseURL;
-
- @Autowired
- protected HttpsAuthClient httpsAuthClientFactory;
- private final ServletRequestHelper servletRequestHelper;
- private final SystemPropertyHelper systemPropertyHelper;
- protected final Logging loggingService;
-
- protected static final String START_STRING = " start";
- protected static final String TRANSACTION_ID_HEADER = "X-TransactionId";
- protected static final String FROM_APP_ID_HEADER = "X-FromAppId";
- protected static final String SUCCESSFUL_API_MESSAGE = " REST api call was successful!";
- protected static final String URL_DECLARATION = ", url=";
-
- public AAIRestInterface(HttpsAuthClient httpsAuthClientFactory,
- ServletRequestHelper servletRequestHelper,
- SystemPropertyHelper systemPropertyHelper,
- Logging loggingService) {
- this.httpsAuthClientFactory = httpsAuthClientFactory;
- this.servletRequestHelper = servletRequestHelper;
- this.systemPropertyHelper = systemPropertyHelper;
- this.loggingService = loggingService;
- initRestClient();
- }
-
- /**
- * For testing purpose
- */
- AAIRestInterface(Optional<Client> client,
- HttpsAuthClient httpsAuthClientFactory,
- ServletRequestHelper servletRequestHelper,
- SystemPropertyHelper systemPropertyHelper,
- Logging loggingService){
- this.httpsAuthClientFactory = httpsAuthClientFactory;
- this.servletRequestHelper = servletRequestHelper;
- this.systemPropertyHelper = systemPropertyHelper;
- this.loggingService = loggingService;
- if (client != null && client.isPresent()){
- this.client = client.get();
- }
-
- }
-
- /**
- * Encode URL.
- *
- * @param nodeKey the node key
- * @return the string
- * @throws UnsupportedEncodingException the unsupported encoding exception
- */
- public String encodeURL (String nodeKey) throws UnsupportedEncodingException {
- return URLEncoder.encode(nodeKey, "UTF-8").replaceAll("\\+", "%20");
- }
-
- protected void initRestClient() {
- initRestClient(false);
- }
-
-
- private void initRestClient(boolean propagateExceptions) {
- if (client == null) {
- try {
- client = httpsAuthClientFactory.getClient(HttpClientMode.WITH_KEYSTORE);
- } catch (Exception e) {
- logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient" + e.toString());
- logger.debug(EELFLoggerDelegate.debugLogger, "Exception in REST call to DB : " + e.toString());
- if (propagateExceptions) {
- ExceptionUtils.rethrow(e);
- }
- }
- }
- }
-
-
-
- /**
- * Sets the rest srvr base URL.
- *
- * @param baseURL the base URL
- */
- public void setRestSrvrBaseURL(String baseURL)
- {
- if (baseURL == null) {
- logger.info(EELFLoggerDelegate.errorLogger, "REST Server base URL cannot be null.");
- logger.debug(EELFLoggerDelegate.debugLogger, "REST Server base URL cannot be null.");
- }
-
- restSrvrBaseURL = baseURL;
- }
-
- /**
- * Gets the rest srvr base URL.
- *
- * @return the rest srvr base URL
- */
- public String getRestSrvrBaseURL() {
- return restSrvrBaseURL;
- }
-
-
- /**
- * Rest get.
- *
- * @param fromAppId the from app id
- * @param transId the trans id
- * @param requestUri the request uri
- * @param xml the xml
- * @return the string
- */
- public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml) {
- return RestGet(fromAppId, transId, requestUri, xml, false);
- }
-
- public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml, boolean propagateExceptions) {
- return doRest(fromAppId, transId, requestUri, null, HttpMethod.GET, xml, propagateExceptions);
- }
-
- public ResponseWithRequestInfo doRest(String fromAppId, String transId, URI requestUri, String payload, HttpMethod method, boolean xml, boolean propagateExceptions) {
- String url = null;
- String methodName = "Rest"+method.name();
- try {
-
- url = systemPropertyHelper.getFullServicePath(requestUri);
-
- initRestClient(propagateExceptions);
-
- logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING);
- logger.debug(EELFLoggerDelegate.debugLogger, url + " for the get REST API");
-
- loggingService.logRequest(outgoingRequestsLogger, method, url, payload);
-
- final Response response;
- Invocation.Builder requestBuilder = client.target(url)
- .request()
- .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON)
- .header(TRANSACTION_ID_HEADER, transId)
- .header(FROM_APP_ID_HEADER, fromAppId)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId());
-
- requestBuilder = systemPropertyHelper.isClientCertEnabled() ?
- requestBuilder : authenticateRequest(requestBuilder);
-
- Invocation restInvocation = StringUtils.isEmpty(payload) ?
- requestBuilder.build(method.name()) :
- requestBuilder.build(method.name(), Entity.entity(payload, MediaType.APPLICATION_JSON));
-
- response = restInvocation.invoke();
- loggingService.logResponse(outgoingRequestsLogger, method, url, response);
-
- if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
- logger.debug(EELFLoggerDelegate.debugLogger, methodName + SUCCESSFUL_API_MESSAGE);
- logger.info(EELFLoggerDelegate.errorLogger, methodName + SUCCESSFUL_API_MESSAGE);
- } else {
- logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response));
- }
- return new ResponseWithRequestInfo(response, url, method);
- } catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
- if (propagateExceptions) {
- throw new ExceptionWithRequestInfo(method, defaultIfNull(url, requestUri.toASCIIString()), e);
- } else {
- return new ResponseWithRequestInfo(null, url, method);
- }
- }
- }
-
- protected String extractOrGenerateRequestId() {
- return servletRequestHelper.extractOrGenerateRequestId();
- }
-
-
- /**
- * Delete.
- *
- * @param sourceID the source ID
- * @param transId the trans id
- * @param path the path
- * @return true, if successful
- */
- public boolean Delete(String sourceID, String transId, String path) {
- String methodName = "Delete";
- transId += ":" + UUID.randomUUID().toString();
- logger.debug(methodName + START_STRING);
- Boolean response = false;
- String url = systemPropertyHelper.getFullServicePath(path);
- try {
-
- initRestClient();
- loggingService.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url);
- final Response cres = client.target(url)
- .request()
- .accept(MediaType.APPLICATION_JSON)
- .header(TRANSACTION_ID_HEADER, transId)
- .header(FROM_APP_ID_HEADER, sourceID)
- .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
- .delete();
- loggingService.logResponse(outgoingRequestsLogger, HttpMethod.DELETE, url, cres);
- if (cres.getStatusInfo().equals(Response.Status.NOT_FOUND)) {
- logger.debug(EELFLoggerDelegate.debugLogger, "Resource does not exist...: " + cres.getStatus()
- + ":" + cres.readEntity(String.class));
- response = false;
- } else if (cres.getStatusInfo().equals(Response.Status.OK) || cres.getStatusInfo().equals(Response.Status.NO_CONTENT)) {
- logger.debug(EELFLoggerDelegate.debugLogger, "Resource " + url + " deleted");
- logger.info(EELFLoggerDelegate.errorLogger, "Resource " + url + " deleted");
- response = true;
- } else {
- logger.debug(EELFLoggerDelegate.debugLogger, "Deleting Resource failed: " + cres.getStatus()
- + ":" + cres.readEntity(String.class));
- response = false;
- }
-
- } catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
- }
- return response;
- }
-
-
- /**
- * Rest put.
- *
- * @param fromAppId the from app id
- * @param path the path
- * @param payload the payload
- * @param xml the xml
- * @param propagateExceptions
- * @return the string
- */
- public ResponseWithRequestInfo RestPut(String fromAppId, String path, String payload, boolean xml, boolean propagateExceptions) {
- return doRest(fromAppId, UUID.randomUUID().toString(), Unchecked.toURI(path), payload, HttpMethod.PUT, xml, propagateExceptions);
- }
-
-
-
- /**
- * Rest post.
- *
- * @param fromAppId the from app id
- * @param path the path
- * @param payload the payload
- * @param xml the xml
- * @return the string
- */
- public Response RestPost(String fromAppId, String path, String payload, boolean xml) {
- String methodName = "RestPost";
- String url=systemPropertyHelper.getServiceBasePath(path);
- String transId = UUID.randomUUID().toString();
- logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING);
-
- Response response = null;
- try {
- initRestClient();
- loggingService.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload);
- response = authenticateRequest(client.target(url)
- .request()
- .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON)
- .header(TRANSACTION_ID_HEADER, transId)
- .header(FROM_APP_ID_HEADER, fromAppId))
- .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
- .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
- loggingService.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, response);
-
- if (response.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) {
- logger.info(EELFLoggerDelegate.errorLogger, getValidResponseLogMessage(methodName));
- logger.debug(EELFLoggerDelegate.debugLogger, getValidResponseLogMessage(methodName));
- } else {
- logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response));
- }
- } catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
- }
- return response;
- }
-
- protected String getFailedResponseLogMessage(String path, String methodName, Exception e) {
- return methodName + URL_DECLARATION + path + ", Exception: " + e.toString();
- }
-
- protected String getValidResponseLogMessage(String methodName) {
- return methodName + URL_DECLARATION;
- }
-
- protected String getInvalidResponseLogMessage(String path, String methodName, Response cres) {
- return methodName + " with status=" + cres.getStatus() + URL_DECLARATION + path;
- }
-
- private Invocation.Builder authenticateRequest(Invocation.Builder requestBuilder) throws InvalidPropertyException, UnsupportedEncodingException {
- return requestBuilder
- .header("Authorization", "Basic " + systemPropertyHelper.getEncodedCredentials());
- }
+ /** The logger. */
+ protected EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AAIRestInterface.class);
+
+ protected final EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("aai");
+
+ /** The client. */
+ private Client client = null;
+
+ /** The rest srvr base URL. */
+ private String restSrvrBaseURL;
+
+ @Autowired
+ protected HttpsAuthClient httpsAuthClientFactory;
+ private final ServletRequestHelper servletRequestHelper;
+ private final SystemPropertyHelper systemPropertyHelper;
+ protected final Logging loggingService;
+
+ protected static final String START_STRING = " start";
+ protected static final String TRANSACTION_ID_HEADER = "X-TransactionId";
+ protected static final String FROM_APP_ID_HEADER = "X-FromAppId";
+ protected static final String SUCCESSFUL_API_MESSAGE = " REST api call was successful!";
+ protected static final String URL_DECLARATION = ", url=";
+
+ public AAIRestInterface(HttpsAuthClient httpsAuthClientFactory,
+ ServletRequestHelper servletRequestHelper,
+ SystemPropertyHelper systemPropertyHelper,
+ Logging loggingService) {
+ this.httpsAuthClientFactory = httpsAuthClientFactory;
+ this.servletRequestHelper = servletRequestHelper;
+ this.systemPropertyHelper = systemPropertyHelper;
+ this.loggingService = loggingService;
+ initRestClient();
+ }
+
+ /**
+ * For testing purpose
+ */
+ AAIRestInterface(Optional<Client> client,
+ HttpsAuthClient httpsAuthClientFactory,
+ ServletRequestHelper servletRequestHelper,
+ SystemPropertyHelper systemPropertyHelper,
+ Logging loggingService){
+ this.httpsAuthClientFactory = httpsAuthClientFactory;
+ this.servletRequestHelper = servletRequestHelper;
+ this.systemPropertyHelper = systemPropertyHelper;
+ this.loggingService = loggingService;
+ if (client != null && client.isPresent()){
+ this.client = client.get();
+ }
+
+ }
+
+ /**
+ * Encode URL.
+ *
+ * @param nodeKey the node key
+ * @return the string
+ * @throws UnsupportedEncodingException the unsupported encoding exception
+ */
+ public String encodeURL (String nodeKey) throws UnsupportedEncodingException {
+ return URLEncoder.encode(nodeKey, "UTF-8").replaceAll("\\+", "%20");
+ }
+
+ protected void initRestClient() {
+ initRestClient(false);
+ }
+
+
+ private void initRestClient(boolean propagateExceptions) {
+ if (client == null) {
+ try {
+ client = httpsAuthClientFactory.getClient(HttpClientMode.WITH_KEYSTORE);
+ } catch (Exception e) {
+ logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient" + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, "Exception in REST call to DB : " + e.toString());
+ if (propagateExceptions) {
+ ExceptionUtils.rethrow(e);
+ }
+ }
+ }
+ }
+
+
+
+ /**
+ * Sets the rest srvr base URL.
+ *
+ * @param baseURL the base URL
+ */
+ public void setRestSrvrBaseURL(String baseURL)
+ {
+ if (baseURL == null) {
+ logger.info(EELFLoggerDelegate.errorLogger, "REST Server base URL cannot be null.");
+ logger.debug(EELFLoggerDelegate.debugLogger, "REST Server base URL cannot be null.");
+ }
+
+ restSrvrBaseURL = baseURL;
+ }
+
+ /**
+ * Gets the rest srvr base URL.
+ *
+ * @return the rest srvr base URL
+ */
+ public String getRestSrvrBaseURL() {
+ return restSrvrBaseURL;
+ }
+
+
+ public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml) {
+ return RestGet(fromAppId, transId, requestUri, xml, false);
+ }
+
+ public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml, boolean propagateExceptions) {
+ return doRest(fromAppId, transId, requestUri, null, HttpMethod.GET, xml, propagateExceptions);
+ }
+
+ public ResponseWithRequestInfo doRest(String fromAppId, String transId, URI requestUri, String payload, HttpMethod method, boolean xml, boolean propagateExceptions) {
+ return doRest(fromAppId, transId, ()->systemPropertyHelper.getFullServicePath(requestUri), payload, method, xml, propagateExceptions);
+ }
+
+
+ public ResponseWithRequestInfo doRest(String fromAppId, String transId, Supplier<String> urlSupplier, String payload, HttpMethod method, boolean xml, boolean propagateExceptions) {
+ String url = null;
+ String methodName = "Rest"+method.name();
+ try {
+
+ url = urlSupplier.get();
+
+ initRestClient(propagateExceptions);
+
+ logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING);
+ logger.debug(EELFLoggerDelegate.debugLogger, url + " for the get REST API");
+
+ loggingService.logRequest(outgoingRequestsLogger, method, url, payload);
+
+ final Response response;
+
+ String requestId = extractOrGenerateRequestId();
+
+ Invocation.Builder requestBuilder = client.target(url)
+ .request()
+ .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON)
+ .header(PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue())
+ .header(TRANSACTION_ID_HEADER, transId)
+ .header(FROM_APP_ID_HEADER, fromAppId)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .header(RequestIdHeader.ONAP_ID.getHeaderName(), requestId)
+ .header(RequestIdHeader.ECOMP_ID.getHeaderName(), requestId)
+ .header(INVOCATION_ID.getHeaderName(), INVOCATION_ID.getHeaderValue())
+ ;
+
+ requestBuilder = systemPropertyHelper.isClientCertEnabled() ?
+ requestBuilder : authenticateRequest(requestBuilder);
+
+ Invocation restInvocation = StringUtils.isEmpty(payload) ?
+ requestBuilder.build(method.name()) :
+ requestBuilder.build(method.name(), Entity.entity(payload, MediaType.APPLICATION_JSON));
+
+ response = restInvocation.invoke();
+ loggingService.logResponse(outgoingRequestsLogger, method, url, response);
+
+ if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
+ logger.debug(EELFLoggerDelegate.debugLogger, methodName + SUCCESSFUL_API_MESSAGE);
+ logger.info(EELFLoggerDelegate.errorLogger, methodName + SUCCESSFUL_API_MESSAGE);
+ } else {
+ logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response));
+ }
+ return new ResponseWithRequestInfo(response, url, method);
+ } catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
+ if (propagateExceptions) {
+ throw new ExceptionWithRequestInfo(method, defaultIfNull(url, ""), e);
+ } else {
+ return new ResponseWithRequestInfo(null, url, method);
+ }
+ }
+ }
+
+ protected String extractOrGenerateRequestId() {
+ return servletRequestHelper.extractOrGenerateRequestId();
+ }
+
+
+ public ResponseWithRequestInfo RestPut(String fromAppId, String path, String payload, boolean xml, boolean propagateExceptions) {
+ return doRest(fromAppId, UUID.randomUUID().toString(), Unchecked.toURI(path), payload, HttpMethod.PUT, xml, propagateExceptions);
+ }
+
+
+ public Response RestPost(String fromAppId, String path, String payload, boolean xml) {
+ ResponseWithRequestInfo response = doRest(
+ fromAppId,
+ UUID.randomUUID().toString(),
+ ()->systemPropertyHelper.getServiceBasePath(path),
+ payload,
+ HttpMethod.POST,
+ xml,
+ false);
+ return response.getResponse();
+ }
+
+ protected String getFailedResponseLogMessage(String path, String methodName, Exception e) {
+ return methodName + URL_DECLARATION + path + ", Exception: " + e.toString();
+ }
+
+ protected String getValidResponseLogMessage(String methodName) {
+ return methodName + URL_DECLARATION;
+ }
+
+ protected String getInvalidResponseLogMessage(String path, String methodName, Response cres) {
+ return methodName + " with status=" + cres.getStatus() + URL_DECLARATION + path;
+ }
+
+ private Invocation.Builder authenticateRequest(Invocation.Builder requestBuilder) throws InvalidPropertyException, UnsupportedEncodingException {
+ return requestBuilder
+ .header("Authorization", "Basic " + systemPropertyHelper.getEncodedCredentials());
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/Service.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/Service.java
index ca151a731..0d37fb39e 100644
--- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/Service.java
+++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/Service.java
@@ -23,88 +23,59 @@ package org.onap.vid.asdc.beans;
import java.util.Collection;
import java.util.UUID;
-/**
- * The Class Service.
- */
public class Service {
- /**
- * The Enum DistributionStatus.
- */
public enum DistributionStatus {
- /** The distribution not approved. */
DISTRIBUTION_NOT_APPROVED,
- /** The distribution approved. */
DISTRIBUTION_APPROVED,
- /** The distributed. */
DISTRIBUTED,
- /** The distribution rejected. */
DISTRIBUTION_REJECTED,
- /** The destributed for tenant isolation. */
DISTRIBUTION_COMPLETE_OK
}
- /**
- * The Enum LifecycleState.
- */
public enum LifecycleState {
- /** The not certified checkout. */
NOT_CERTIFIED_CHECKOUT,
- /** The not certified checkin. */
NOT_CERTIFIED_CHECKIN,
- /** The ready for certification. */
READY_FOR_CERTIFICATION,
- /** The certification in progress. */
CERTIFICATION_IN_PROGRESS,
- /** The certified. */
CERTIFIED
}
- /** The uuid. */
private String uuid;
- /** The invariant UUID. */
private String invariantUUID;
- /** The name. */
private String name;
- /** The version. */
private String version;
- /** The tosca model URL. */
private String toscaModelURL;
- /** The category. */
private String category;
- /** The lifecycle state. */
private Service.LifecycleState lifecycleState;
- /** The last updater user uid. */
private String lastUpdaterUserId;
- /** The last updater full name. */
private String lastUpdaterFullName;
- /** The distribution status. */
private String distributionStatus;
- /** The artifacts. */
private Collection<Artifact> artifacts;
- /** The resources. */
private Collection<SubResource> resources;
+
+ private String orchestrationType;
public static class ServiceBuilder {
@@ -118,6 +89,7 @@ public class Service {
private String distributionStatus;
private Collection<Artifact> artifacts;
private Collection<SubResource> resources;
+ private String orchestrationType;
public ServiceBuilder setUuid(String uuid) {
this.uuid = uuid;
@@ -169,253 +141,131 @@ public class Service {
return this;
}
+ public ServiceBuilder setOrchestrationType(String orchestrationType) {
+ this.orchestrationType = orchestrationType;
+ return this;
+ }
+
public Service build() {
return new Service(this);
}
}
- /**
- * Gets the uuid.
- *
- * @return the uuid
- */
public String getUuid() {
return uuid;
}
- /**
- * Gets the invariant UUID.
- *
- * @return the invariant UUID
- */
public String getInvariantUUID() {
return invariantUUID;
}
- /**
- * Gets the name.
- *
- * @return the name
- */
public String getName() {
return name;
}
- /**
- * Gets the version.
- *
- * @return the version
- */
public String getVersion() {
return version;
}
- /**
- * Gets the tosca model URL.
- *
- * @return the tosca model URL
- */
public String getToscaModelURL() {
return toscaModelURL;
}
- /**
- * Gets the category.
- *
- * @return the category
- */
public String getCategory() {
return category;
}
- /**
- * Gets the lifecycle state.
- *
- * @return the lifecycle state
- */
public Service.LifecycleState getLifecycleState() {
return lifecycleState;
}
- /**
- * Gets the last updater user uid.
- *
- * @return the last updater user uid
- */
public String getLastUpdaterUserId() {
return lastUpdaterUserId;
}
- /**
- * Gets the last updater full name.
- *
- * @return the last updater full name
- */
public String getLastUpdaterFullName() {
return lastUpdaterFullName;
}
- /**
- * Gets the distribution status.
- *
- * @return the distribution status
- */
public String getDistributionStatus() {
return distributionStatus;
}
- /**
- * Gets the artifacts.
- *
- * @return the artifacts
- */
public Collection<Artifact> getArtifacts() {
return artifacts;
}
- /**
- * Gets the resources.
- *
- * @return the resources
- */
public Collection<SubResource> getResources() {
return resources;
}
- /**
- * Sets the uuid.
- *
- * @param uuid the new uuid
- */
+ public String getOrchestrationType() {
+ return orchestrationType;
+ }
+
public void setUuid(String uuid) {
this.uuid = uuid;
}
- /**
- * Sets the invariant UUID.
- *
- * @param invariantUUID the new invariant UUID
- */
public void setInvariantUUID(String invariantUUID) {
this.invariantUUID = invariantUUID;
}
- /**
- * Sets the name.
- *
- * @param name the new name
- */
public void setName(String name) {
this.name = name;
}
- /**
- * Sets the version.
- *
- * @param version the new version
- */
public void setVersion(String version) {
this.version = version;
}
- /**
- * Sets the tosca model URL.
- *
- * @param toscaModelURL the new tosca model URL
- */
public void setToscaModelURL(String toscaModelURL) {
this.toscaModelURL = toscaModelURL;
}
- /**
- * Sets the category.
- *
- * @param category the new category
- */
public void setCategory(String category) {
this.category = category;
}
- /**
- * Sets the lifecycle state.
- *
- * @param lifecycleState the new lifecycle state
- */
public void setLifecycleState(Service.LifecycleState lifecycleState) {
this.lifecycleState = lifecycleState;
}
- /**
- * Sets the last updater user uid.
- *
- * @param lastUpdaterUserId the new last updater user uid
- */
public void set(String lastUpdaterUserId) {
this.lastUpdaterUserId = lastUpdaterUserId;
}
- /**
- * Sets the last updater full name.
- *
- * @param lastUpdaterFullName the new last updater full name
- */
public void setLastUpdaterFullName(String lastUpdaterFullName) {
this.lastUpdaterFullName = lastUpdaterFullName;
}
- /**
- * Sets the distribution status.
- *
- * @param distributionStatus the new distribution status
- */
public void setDistributionStatus(String distributionStatus) {
this.distributionStatus = distributionStatus;
}
- /**
- * Sets the artifacts.
- *
- * @param artifacts the new artifacts
- */
public void setArtifacts(Collection<Artifact> artifacts) {
this.artifacts = artifacts;
}
- /**
- * Sets the resources.
- *
- * @param resources the new resources
- */
public void setResources(Collection<SubResource> resources) {
this.resources = resources;
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
+ public void setOrchestrationType(String orchestrationType) {
+ this.orchestrationType = orchestrationType;
+ }
+
@Override
public String toString() {
return uuid;
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
@Override
public int hashCode() {
return UUID.fromString(getUuid()).hashCode();
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
@Override
public boolean equals(Object o) {
if (o == this)
@@ -442,5 +292,6 @@ public class Service {
this.distributionStatus = serviceBuilder.distributionStatus;
this.artifacts = serviceBuilder.artifacts;
this.resources = serviceBuilder.resources;
+ this.orchestrationType = serviceBuilder.orchestrationType;
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/rest/SdcRestClient.java b/vid-app-common/src/main/java/org/onap/vid/asdc/rest/SdcRestClient.java
index 9e139a02a..96be59123 100644
--- a/vid-app-common/src/main/java/org/onap/vid/asdc/rest/SdcRestClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/asdc/rest/SdcRestClient.java
@@ -29,6 +29,7 @@ import static org.onap.vid.client.SyncRestClientInterface.HEADERS.AUTHORIZATION;
import static org.onap.vid.client.SyncRestClientInterface.HEADERS.CONTENT_TYPE;
import static org.onap.vid.client.SyncRestClientInterface.HEADERS.X_ECOMP_INSTANCE_ID;
import static org.onap.vid.client.UnirestPatchKt.extractRawAsString;
+import static org.onap.vid.logging.Headers.PARTNER_NAME;
import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
import com.att.eelf.configuration.EELFLogger;
@@ -152,6 +153,7 @@ public class SdcRestClient implements AsdcClient {
private Map<String, String> prepareHeaders(String auth, String contentType) {
return ImmutableMap.of(
X_ECOMP_INSTANCE_ID, SystemProperties.getProperty(APP_DISPLAY_NAME),
+ PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue(),
AUTHORIZATION, auth,
REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId(),
CONTENT_TYPE, contentType
diff --git a/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java b/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java
index 3c061986c..5607018b0 100644
--- a/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java
@@ -21,14 +21,11 @@
package org.onap.vid.client;
-import org.glassfish.jersey.client.ClientConfig;
-import org.glassfish.jersey.client.ClientProperties;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.springframework.beans.factory.annotation.Autowired;
-
import javax.servlet.ServletContext;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.springframework.beans.factory.annotation.Autowired;
/**
* General HTTP client.
@@ -51,10 +48,8 @@ public class HttpBasicClient{
*/
public static Client getClient() {
- ClientConfig config = new ClientConfig();
- config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
-
- return ClientBuilder.newClient(config)
- .register(org.onap.vid.aai.util.CustomJacksonJaxBJsonProvider.class);
+ return ClientBuilder
+ .newClient()
+ .register(org.onap.vid.aai.util.CustomJacksonJaxBJsonProvider.class);
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/LoggerController.java b/vid-app-common/src/main/java/org/onap/vid/controller/LoggerController.java
index b7ff82afe..928e19357 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/LoggerController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/LoggerController.java
@@ -20,6 +20,8 @@
package org.onap.vid.controller;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import java.io.File;
import java.io.IOException;
import java.util.List;
@@ -63,7 +65,7 @@ public class LoggerController extends RestrictedBaseController {
this.logfilePathCreator = logfilePathCreator;
}
- @GetMapping(value = "/{loggerName:audit|error|metrics}")
+ @GetMapping(value = "/{loggerName:audit|audit2019|error|metrics}")
public String getLog(@PathVariable String loggerName, HttpServletRequest request,
@RequestParam(value="limit", defaultValue = "5000") Integer limit) throws IOException {
@@ -74,7 +76,7 @@ public class LoggerController extends RestrictedBaseController {
}
String logfilePath = logfilePathCreator.getLogfilePath(loggerName);
- try (final ReversedLinesFileReader reader = new ReversedLinesFileReader(new File(logfilePath))) {
+ try (final ReversedLinesFileReader reader = new ReversedLinesFileReader(new File(logfilePath), UTF_8)) {
Supplier<String> reverseLinesSupplier = () -> {
try {
return reader.readLine();
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java b/vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java
index 5b05caa7a..4e7a77cd3 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java
@@ -30,6 +30,7 @@ import org.onap.vid.mso.MsoBusinessLogic;
import org.onap.vid.mso.MsoBusinessLogicImpl;
import org.onap.vid.mso.MsoInterface;
import org.onap.vid.mso.MsoProperties;
+import org.onap.vid.mso.RestMsoImplementation;
import org.onap.vid.mso.rest.MsoRestClientNew;
import org.onap.vid.services.CloudOwnerService;
import org.onap.vid.services.CloudOwnerServiceImpl;
@@ -49,14 +50,23 @@ public class MsoConfig {
}
@Bean
- public MsoRestClientNew msoClient(ObjectMapper unirestObjectMapper,
- HttpsAuthClient httpsAuthClient,
+ public MsoRestClientNew msoRestClientNew(ObjectMapper unirestObjectMapper,
SystemPropertiesWrapper systemPropertiesWrapper,
Logging loggingService){
// Satisfy both interfaces -- MsoInterface and RestMsoImplementation
return new MsoRestClientNew(
new SyncRestClient(unirestObjectMapper, loggingService),
SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL),
+ systemPropertiesWrapper
+ );
+ }
+
+ @Bean
+ public RestMsoImplementation restMsoImplementation(HttpsAuthClient httpsAuthClient,
+ SystemPropertiesWrapper systemPropertiesWrapper,
+ Logging loggingService){
+ // Satisfy both interfaces -- MsoInterface and RestMsoImplementation
+ return new RestMsoImplementation(
httpsAuthClient,
systemPropertiesWrapper,
loggingService
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/MsoController.java b/vid-app-common/src/main/java/org/onap/vid/controller/MsoController.java
index 535c97ce7..da66e8951 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/MsoController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/MsoController.java
@@ -38,7 +38,6 @@ import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.MsoResponseWrapper2;
import org.onap.vid.mso.RestMsoImplementation;
import org.onap.vid.mso.RestObject;
-import org.onap.vid.mso.rest.MsoRestClientNew;
import org.onap.vid.mso.rest.Request;
import org.onap.vid.mso.rest.RequestDetails;
import org.onap.vid.mso.rest.RequestDetailsWrapper;
@@ -90,7 +89,7 @@ public class MsoController extends RestrictedBaseController {
private final CloudOwnerService cloudOwnerService;
@Autowired
- public MsoController(MsoBusinessLogic msoBusinessLogic, MsoRestClientNew msoClientInterface, CloudOwnerService cloudOwnerService) {
+ public MsoController(MsoBusinessLogic msoBusinessLogic, RestMsoImplementation msoClientInterface, CloudOwnerService cloudOwnerService) {
this.msoBusinessLogic = msoBusinessLogic;
this.restMso = msoClientInterface;
this.cloudOwnerService = cloudOwnerService;
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt
index ac5c2751c..df97f89f8 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt
@@ -427,14 +427,17 @@ abstract class ResourceCommand(
protected fun pushChildrenJobsToBroker(children:Collection<BaseResource>,
dataForChild: Map<String, Any>,
jobType: JobType?=null): List<String> {
- var counter = 0;
- return children
- .map {Pair(it, counter++)}
+ return setPositionWhereIsMissing(children)
.map { jobAdapter.createChildJob(jobType ?: it.first.jobType, it.first, sharedData, dataForChild, it.second) }
.map { jobsBrokerService.add(it) }
.map { it.toString() }
}
+ protected fun setPositionWhereIsMissing(children: Collection<BaseResource>): List<Pair<BaseResource, Int>> {
+ var orderingPosition = children.map{ defaultIfNull(it.position, 0) }.max() ?: 0
+ return children
+ .map {Pair(it, it.position ?: ++orderingPosition)}
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt b/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt
index a0bbceea1..e9f83ef22 100644
--- a/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt
@@ -4,18 +4,35 @@ package org.onap.vid.logging
import org.onap.portalsdk.core.util.SystemProperties
import org.onap.vid.logging.RequestIdHeader.*
+import java.util.*
import javax.servlet.http.HttpServletRequest
-enum class RequestIdHeader(val headerName: String) {
+interface Header {
+ val headerName: String
+ fun stringEquals(header: String): Boolean = headerName.equals(header, true)
+}
+
+abstract class NamedHeader(override val headerName: String) : Header {
+ abstract fun getHeaderValue(): String
+}
+
+@JvmField
+val PARTNER_NAME = object : NamedHeader("X-ONAP-PartnerName") {
+ override fun getHeaderValue() = "VID.VID"
+}
+
+@JvmField
+val INVOCATION_ID = object : NamedHeader("X-InvocationID") {
+ override fun getHeaderValue() = UUID.randomUUID().toString()
+}
+enum class RequestIdHeader(override val headerName: String) : Header {
ONAP_ID("X-ONAP-RequestID"),
REQUEST_ID("X-RequestID"),
TRANSACTION_ID("X-TransactionID"),
ECOMP_ID(SystemProperties.ECOMP_REQUEST_ID),
;
- fun stringEquals(header: String) = headerName.equals(header, true)
-
fun getHeaderValue(request: HttpServletRequest): String? = request.getHeader(headerName)
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java
index 3d980dce8..8f9b98a55 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java
@@ -30,6 +30,7 @@ import static org.onap.vid.controller.MsoController.REQUEST_TYPE;
import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
import static org.onap.vid.controller.MsoController.WORKFLOW_ID;
+import static org.onap.vid.logging.Headers.PARTNER_NAME;
import static org.onap.vid.mso.MsoProperties.MSO_REST_API_CLOUD_RESOURCES_REQUEST_STATUS;
import static org.onap.vid.mso.MsoProperties.MSO_REST_API_OPERATIONAL_ENVIRONMENT_ACTIVATE;
import static org.onap.vid.mso.MsoProperties.MSO_REST_API_OPERATIONAL_ENVIRONMENT_CREATE;
@@ -230,7 +231,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic {
UUID requestId = UUID.randomUUID();
extraHeaders.put("X-ONAP-RequestID",requestId.toString());
- extraHeaders.put("X-ONAP-PartnerName","VID");
+ extraHeaders.put(PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue());
extraHeaders.put("X-RequestorID",userId);
return msoClientInterface.invokeWorkflow(request,final_endpoint,extraHeaders);
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java
index d1cb3a37b..a16b44925 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java
@@ -21,14 +21,13 @@
package org.onap.vid.mso;
import io.joshworks.restclient.http.HttpResponse;
+import java.util.Map;
import org.onap.vid.aai.HttpResponseWithRequestInfo;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
-import org.onap.vid.model.SOWorkflowList;
import org.onap.vid.changeManagement.WorkflowRequestDetail;
+import org.onap.vid.model.SOWorkflowList;
import org.onap.vid.mso.rest.RequestDetails;
-import java.util.Map;
-
/**
* Created by pickjonathan on 21/06/2017.
*/
@@ -124,6 +123,5 @@ public interface MsoInterface {
<T> HttpResponse<T> post(String path, RequestDetailsWrapper<?> requestDetailsWrapper, Class<T> responseClass);
- <T> HttpResponse<T> post(String path, RequestDetails requestDetails, Class<T> responseClass);
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java
index ee1eb0429..91b288998 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java
@@ -20,6 +20,8 @@
package org.onap.vid.mso;
+import static org.onap.vid.logging.Headers.INVOCATION_ID;
+import static org.onap.vid.logging.Headers.PARTNER_NAME;
import static org.onap.vid.utils.Logging.ONAP_REQUEST_ID_HEADER_KEY;
import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
import static org.onap.vid.utils.Logging.getMethodCallerName;
@@ -36,15 +38,12 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.Response;
import org.apache.commons.codec.binary.Base64;
-import org.apache.http.HttpException;
import org.eclipse.jetty.util.security.Password;
+import org.glassfish.jersey.client.ClientProperties;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.vid.aai.ExceptionWithRequestInfo;
import org.onap.vid.aai.util.HttpClientMode;
import org.onap.vid.aai.util.HttpsAuthClient;
import org.onap.vid.client.HttpBasicClient;
-import org.onap.vid.exceptions.GenericUncheckedException;
-import org.onap.vid.mso.rest.RestInterface;
import org.onap.vid.utils.Logging;
import org.onap.vid.utils.SystemPropertiesWrapper;
import org.springframework.beans.factory.annotation.Autowired;
@@ -53,7 +52,7 @@ import org.springframework.http.HttpMethod;
/**
* Created by pickjonathan on 26/06/2017.
*/
-public class RestMsoImplementation implements RestInterface {
+public class RestMsoImplementation {
/**
@@ -85,7 +84,7 @@ public class RestMsoImplementation implements RestInterface {
*/
@Autowired
- protected RestMsoImplementation(HttpsAuthClient httpsAuthClient, SystemPropertiesWrapper systemProperties, Logging loggingService){
+ public RestMsoImplementation(HttpsAuthClient httpsAuthClient, SystemPropertiesWrapper systemProperties, Logging loggingService){
this.httpsAuthClient=httpsAuthClient;
this.systemProperties = systemProperties;
this.loggingService = loggingService;
@@ -108,12 +107,12 @@ public class RestMsoImplementation implements RestInterface {
MultivaluedHashMap<String, Object> commonHeaders = new MultivaluedHashMap();
commonHeaders.put("Authorization", Collections.singletonList(("Basic " + authStringEnc)));
- commonHeaders.put("X-ONAP-PartnerName", Collections.singletonList("VID"));
+ commonHeaders.put(PARTNER_NAME.getHeaderName(), Collections.singletonList(PARTNER_NAME.getHeaderValue()));
String requestIdValue = Logging.extractOrGenerateRequestId();
commonHeaders.put(REQUEST_ID_HEADER_KEY, Collections.singletonList(requestIdValue));
commonHeaders.put(ONAP_REQUEST_ID_HEADER_KEY, Collections.singletonList(requestIdValue));
-
+ commonHeaders.put(INVOCATION_ID.getHeaderName(), Collections.singletonList(INVOCATION_ID.getHeaderValue()));
boolean useSsl = true;
if ( (mso_url != null) && ( !(mso_url.isEmpty()) ) ) {
@@ -136,52 +135,6 @@ public class RestMsoImplementation implements RestInterface {
return commonHeaders;
}
- public <T> RestObjectWithRequestInfo<T> Get(T t, String path, RestObject<T> restObject, boolean warpException) {
- String methodName = "Get";
-
- logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_LOG);
-
- String url = null;
- String rawData = null;
- Integer status = null;
-
- try {
- restObject.set(t);
- url = systemProperties.getProperty(MsoProperties.MSO_SERVER_URL) + path;
-
- MultivaluedHashMap<String, Object> commonHeaders = initMsoClient();
- loggingService.logRequest(outgoingRequestsLogger, HttpMethod.GET, url);
- final Response cres = client.target(url)
- .request()
- .accept(APPLICATION_JSON)
- .headers(commonHeaders)
- .get();
- loggingService.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, cres);
-
- cres.bufferEntity();
- status = cres.getStatus();
- rawData = cres.readEntity(String.class);
-
- restObject.setStatusCode(status);
-
- if (status == 200 || status == 202) {
- t = (T) cres.readEntity(t.getClass());
- restObject.set(t);
- logger.debug(EELFLoggerDelegate.debugLogger, methodName + REST_API_SUCCESSFULL_LOG);
-
- } else {
- throw new GenericUncheckedException(new HttpException(methodName + WITH_STATUS + status + " (200 or 202 expected), url= " + url));
- }
-
- logger.debug(EELFLoggerDelegate.debugLogger, methodName + " received status=" + status);
-
- return new RestObjectWithRequestInfo<>(HttpMethod.GET, url, restObject, status, rawData);
- } catch (RuntimeException e) {
- throw warpException ? new ExceptionWithRequestInfo(HttpMethod.GET, url, rawData, status, e) : e;
- }
- }
-
- @Override
public <T> RestObject<T> GetForObject(String path, Class<T> clazz) {
final String methodName = getMethodName();
logger.debug(EELFLoggerDelegate.debugLogger, "start {}->{}({}, {})", getMethodCallerName(), methodName, path, clazz);
@@ -211,80 +164,11 @@ public class RestMsoImplementation implements RestInterface {
return restObject;
}
- @Override
- public <T> void Delete(T t, Object r, String path, RestObject<T> restObject) {
-
- String methodName = "Delete";
- String url="";
- Response cres;
-
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + START_LOG);
-
- try {
- MultivaluedHashMap<String, Object> commonHeaders = initMsoClient();
-
- url = systemProperties.getProperty(MsoProperties.MSO_SERVER_URL) + path;
- loggingService.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url, r);
- cres = client.target(url)
- .request()
-
- .accept(APPLICATION_JSON)
- .headers(commonHeaders)
- //.entity(r)
- .build("DELETE", Entity.entity(r, MediaType.APPLICATION_JSON))
- .invoke();
- loggingService.logResponse(outgoingRequestsLogger, HttpMethod.DELETE, url, cres);
- int status = cres.getStatus();
- restObject.setStatusCode (status);
-
- if (status == 404) { // resource not found
- String msg = "Resource does not exist...: " + cres.getStatus();
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + msg);
- } else if (status == 200 || status == 204){
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + "Resource " + url + " deleted");
- } else if (status == 202) {
- String msg = "Delete in progress: " + status;
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + msg);
- }
- else {
- String msg = "Deleting Resource failed: " + status;
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + msg);
- }
-
- try {
- t = (T) cres.readEntity(t.getClass());
- restObject.set(t);
- }
- catch ( Exception e ) {
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + NO_RESPONSE_ENTITY_LOG
- + e.getMessage());
- throw e;
- }
-
- }
- catch (Exception e)
- {
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + WITH_URL_LOG +url+ EXCEPTION_LOG + e.toString());
- throw e;
- }
- }
-
public <T> RestObject<T> PostForObject(Object requestDetails, String path, Class<T> clazz) {
logger.debug(EELFLoggerDelegate.debugLogger, REST_MSG_TEMPLATE, getMethodCallerName(), getMethodName(), requestDetails, path, clazz);
return restCall(HttpMethod.POST, clazz, requestDetails, path);
}
- public <T> RestObject<T> DeleteForObject(Object requestDetails, String path, Class<T> clazz) {
- logger.debug(EELFLoggerDelegate.debugLogger, REST_MSG_TEMPLATE, getMethodCallerName(), getMethodName(), requestDetails, path, clazz);
- return restCall(HttpMethod.DELETE, clazz, requestDetails, path);
- }
-
- @Override
- public void Post(String t, Object r, String path, RestObject<String> restObject) {
- logger.debug(EELFLoggerDelegate.debugLogger, REST_MSG_TEMPLATE, getMethodCallerName(), getMethodName(), t.getClass(), r, path);
- restObject.copyFrom(restCall(HttpMethod.POST, String.class, r, path));
- }
-
public Invocation.Builder prepareClient(String path, String methodName) {
MultivaluedHashMap<String, Object> commonHeaders = initMsoClient();
@@ -320,7 +204,9 @@ public class RestMsoImplementation implements RestInterface {
final Invocation.Builder restBuilder = client.target(url)
.request()
.accept(APPLICATION_JSON)
- .headers(commonHeaders);
+ .headers(commonHeaders)
+ .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true)
+ ;
Invocation restInvocation = payload==null ?
restBuilder.build(httpMethod.name()) :
@@ -364,56 +250,4 @@ public class RestMsoImplementation implements RestInterface {
return restObject;
}
- @Override
- public <T> void Put(T t, org.onap.vid.changeManagement.RequestDetailsWrapper r, String path, RestObject<T> restObject) {
-
- String methodName = "Put";
- String url="";
-
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + START_LOG);
-
- try {
-
- MultivaluedHashMap<String, Object> commonHeaders = initMsoClient();
-
- url = systemProperties.getProperty(MsoProperties.MSO_SERVER_URL) + path;
- loggingService.logRequest(outgoingRequestsLogger, HttpMethod.PUT, url, r);
- // Change the content length
- final Response cres = client.target(url)
- .request()
- .accept(APPLICATION_JSON)
- .headers(commonHeaders)
- //.header("content-length", 201)
- .put(Entity.entity(r, MediaType.APPLICATION_JSON));
-
- loggingService.logResponse(outgoingRequestsLogger, HttpMethod.PUT, url, cres);
-
- try {
- t = (T) cres.readEntity(t.getClass());
- restObject.set(t);
- }
- catch ( Exception e ) {
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + NO_RESPONSE_ENTITY_LOG
- + e.getMessage());
- throw e;
- }
-
- int status = cres.getStatus();
- restObject.setStatusCode (status);
-
- if ( status >= 200 && status <= 299 ) {
- logger.info(EELFLoggerDelegate.errorLogger, "<== " + methodName + REST_API_SUCCESSFULL_LOG);
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + REST_API_SUCCESSFULL_LOG);
-
- } else {
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + WITH_STATUS +status+ URL_LOG +url);
- }
-
- } catch (Exception e)
- {
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + WITH_URL_LOG +url+ EXCEPTION_LOG + e.toString());
- throw e;
-
- }
- }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java
index b2ccde93b..5e19dad46 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java
@@ -20,6 +20,7 @@
*/
package org.onap.vid.mso.rest;
+import static org.onap.vid.logging.Headers.PARTNER_NAME;
import static org.onap.vid.utils.Logging.ONAP_REQUEST_ID_HEADER_KEY;
import com.google.common.collect.ImmutableMap;
@@ -38,11 +39,11 @@ import org.eclipse.jetty.util.security.Password;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.aai.HttpResponseWithRequestInfo;
-import org.onap.vid.aai.util.HttpsAuthClient;
import org.onap.vid.changeManagement.MsoRequestDetails;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
import org.onap.vid.changeManagement.WorkflowRequestDetail;
import org.onap.vid.client.SyncRestClient;
+import org.onap.vid.logging.Headers;
import org.onap.vid.model.RequestReferencesContainer;
import org.onap.vid.model.SOWorkflowList;
import org.onap.vid.mso.MsoInterface;
@@ -50,7 +51,6 @@ import org.onap.vid.mso.MsoProperties;
import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.MsoResponseWrapperInterface;
import org.onap.vid.mso.MsoUtil;
-import org.onap.vid.mso.RestMsoImplementation;
import org.onap.vid.mso.RestObject;
import org.onap.vid.utils.Logging;
import org.onap.vid.utils.SystemPropertiesWrapper;
@@ -60,27 +60,28 @@ import org.springframework.http.HttpMethod;
/**
* Created by pickjonathan on 21/06/2017.
*/
-public class MsoRestClientNew extends RestMsoImplementation implements MsoInterface {
+public class MsoRestClientNew implements MsoInterface {
/**
* The Constant dateFormat.
*/
public static final String X_FROM_APP_ID = "X-FromAppId";
- public static final String X_ONAP_PARTNER_NAME = "X-ONAP-PartnerName";
final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
private static final String START = " start";
private final SyncRestClient client;
private final String baseUrl;
+ private final SystemPropertiesWrapper systemProperties;
private final Map<String, String> commonHeaders;
+
/**
* The logger.
*/
EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoRestClientNew.class);
- public MsoRestClientNew(SyncRestClient client, String baseUrl, HttpsAuthClient authClient, SystemPropertiesWrapper systemPropertiesWrapper, Logging loggingService) {
- super(authClient,systemPropertiesWrapper, loggingService);
+ public MsoRestClientNew(SyncRestClient client, String baseUrl, SystemPropertiesWrapper systemPropertiesWrapper) {
this.client = client;
this.baseUrl = baseUrl;
+ this.systemProperties = systemPropertiesWrapper;
this.commonHeaders = initCommonHeaders();
}
@@ -482,14 +483,6 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf
return client.post(path, getHeaders(), requestDetailsWrapper, responseClass);
}
- @Override
- public <T> HttpResponse<T> post(String endpoint, RequestDetails requestDetails, Class<T> responseClass) {
- String path = baseUrl + endpoint;
-
- return client.post(path, getHeaders(), requestDetails, responseClass);
- }
-
-
public HttpResponse<SOWorkflowList> getWorkflowListByModelId(String endpoint){
String path = baseUrl + endpoint;
@@ -545,6 +538,7 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf
String requestIdValue = Logging.extractOrGenerateRequestId();
map.put(SystemProperties.ECOMP_REQUEST_ID, requestIdValue);
map.put(ONAP_REQUEST_ID_HEADER_KEY, requestIdValue);
+ map.put(Headers.INVOCATION_ID.getHeaderName(), Headers.INVOCATION_ID.getHeaderValue());
return map;
}
@@ -563,7 +557,7 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf
map.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
map.put(X_FROM_APP_ID, systemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME));
- map.put(X_ONAP_PARTNER_NAME, "VID");
+ map.put(PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue());
return ImmutableMap.copyOf(map);
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java
deleted file mode 100644
index 3a0d8fd8e..000000000
--- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * VID
- * ================================================================================
- * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.vid.mso.rest;
-
-import org.onap.vid.changeManagement.RequestDetailsWrapper;
-import org.onap.vid.mso.RestObject;
-import org.onap.vid.mso.RestObjectWithRequestInfo;
-
-/**
- * Created by pickjonathan on 26/06/2017.
- */
-public interface RestInterface {
-
- /**
- * Gets the.
- *
- * @param <T> the generic type
- * @param t the t
- * @param path the path
- * @param restObject the rest object
- * @param warpException
- * @throws Exception the exception
- */
- <T> RestObjectWithRequestInfo<T> Get(T t, String path, RestObject<T> restObject, boolean warpException);
-
- /**
- * Delete.
- *
- * @param <T> the generic type
- * @param t the t
- * @param r the r
- * @param path the path
- * @param restObject the rest object
- * @throws Exception the exception
- */
- <T> void Delete(T t, Object r, String path, RestObject<T> restObject);
-
- /**
- * Post.
- *
- * @param t the t
- * @param r the r
- * @param path the path
- * @param restObject the rest object
- * @throws Exception the exception
- */
- void Post(String t, Object r, String path, RestObject<String> restObject);
-
- /**
- * Put.
- *
- * @param <T> the generic type
- * @param t the t
- * @param r the r
- * @param path the path
- * @param restObject the rest object
- * @throws Exception the exception
- */
- <T> void Put(T t, RequestDetailsWrapper r, String path, RestObject<T> restObject);
-
- <T> RestObject<T> GetForObject(String path, Class<T> clazz);
-
-}
diff --git a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java
index 7384c97e2..a3343d36b 100644
--- a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java
+++ b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java
@@ -74,6 +74,7 @@ public enum Features implements Feature {
FLAG_PNP_INSTANTIATION,
FLAG_HANDLE_SO_WORKFLOWS,
FLAG_CREATE_ERROR_REPORTS,
+ FLAG_SHOW_ORCHESTRATION_TYPE,
FLAG_DISABLE_HOMING,
FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG,
FLAG_FLASH_MORE_ACTIONS_BUTTON_IN_OLD_VIEW_EDIT,
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
index b6404fa68..b64a233c7 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
@@ -75,7 +75,6 @@ import org.onap.vid.aai.model.RelationshipData;
import org.onap.vid.aai.model.RelationshipList;
import org.onap.vid.aai.model.Result;
import org.onap.vid.aai.model.ServiceRelationships;
-import org.onap.vid.aai.model.VnfResult;
import org.onap.vid.asdc.beans.Service;
import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.model.ServiceInstanceSearchResult;
@@ -137,7 +136,9 @@ public class AaiServiceImpl implements AaiService {
.setToscaModelURL(null)
.setLifecycleState(null)
.setArtifacts(null)
- .setResources(null).build();
+ .setResources(null)
+ .setOrchestrationType(modelVer.getOrchestrationType())
+ .build();
@@ -150,6 +151,10 @@ public class AaiServiceImpl implements AaiService {
return services;
}
+ private boolean hasData(AaiResponse<?> aaiResponse) {
+ return aaiResponse != null && aaiResponse.getT() != null;
+ }
+
private boolean validateModel(Model model){
if (model == null) {
return false;
@@ -388,24 +393,7 @@ public class AaiServiceImpl implements AaiService {
@Override
public AaiResponse<AaiGetVnfResponse> getVNFData(String globalSubscriberId, String serviceType) {
AaiResponse<AaiGetVnfResponse> response = aaiClient.getVNFData(globalSubscriberId, serviceType);
- return filterChangeManagementVNFCandidatesResponse(response);
- }
-
- protected AaiResponse<AaiGetVnfResponse> filterChangeManagementVNFCandidatesResponse(AaiResponse<AaiGetVnfResponse> response) {
-
- if (response != null && response.getT() != null) {
- List<VnfResult> filteredVnfs = response.getT().results.stream()
- .filter(result -> (
- result.nodeType.equalsIgnoreCase("generic-vnf") ||
- result.nodeType.equalsIgnoreCase("service-instance")))
- .collect(Collectors.toList());
-
- AaiGetVnfResponse aaiGetVnfResponse = new AaiGetVnfResponse();
- aaiGetVnfResponse.results = filteredVnfs;
- return new AaiResponse<>(aaiGetVnfResponse, response.getErrorMessage(), response.getHttpCode());
- }
-
- return new AaiResponse<>();
+ return hasData(response) ? response : new AaiResponse<>();
}
@Override
diff --git a/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties b/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties
index db2ff8e97..d4910bf25 100644
--- a/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties
+++ b/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties
@@ -36,3 +36,4 @@ FLAG_DISABLE_HOMING = true
FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH=false
FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG = false
FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE = false
+FLAG_SHOW_ORCHESTRATION_TYPE = false
diff --git a/vid-app-common/src/main/webapp/WEB-INF/conf/onap.features.properties b/vid-app-common/src/main/webapp/WEB-INF/conf/onap.features.properties
index d1ce91f44..709de9566 100644
--- a/vid-app-common/src/main/webapp/WEB-INF/conf/onap.features.properties
+++ b/vid-app-common/src/main/webapp/WEB-INF/conf/onap.features.properties
@@ -15,6 +15,7 @@ FLAG_1810_AAI_LOCAL_CACHE = true
FLAG_EXP_USE_DEFAULT_HOST_NAME_VERIFIER = false
FLAG_HANDLE_SO_WORKFLOWS = true
FLAG_CREATE_ERROR_REPORTS = true
+FLAG_SHOW_ORCHESTRATION_TYPE = false
# Modern UI (Drawing-Board; View/Edit)
# - - - - - - - - - - - - - - - - - -
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js b/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js
index f76d4786f..3575c382d 100755
--- a/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js
@@ -264,6 +264,7 @@ appDS2
FLAG_1908_RELEASE_TENANT_ISOLATION: "FLAG_1908_RELEASE_TENANT_ISOLATION",
FLAG_FLASH_REPLACE_VF_MODULE: "FLAG_FLASH_REPLACE_VF_MODULE",
FLAG_FLASH_MORE_ACTIONS_BUTTON_IN_OLD_VIEW_EDIT: "FLAG_FLASH_MORE_ACTIONS_BUTTON_IN_OLD_VIEW_EDIT",
+ FLAG_SHOW_ORCHESTRATION_TYPE: "FLAG_SHOW_ORCHESTRATION_TYPE",
}
};
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/controller/ServiceModelController.js b/vid-app-common/src/main/webapp/app/vid/scripts/controller/ServiceModelController.js
index 9cb905038..b29680f9d 100755
--- a/vid-app-common/src/main/webapp/app/vid/scripts/controller/ServiceModelController.js
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/controller/ServiceModelController.js
@@ -89,6 +89,10 @@
});
};
+ $scope.isShowOrchestrationType = function() {
+ return featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_SHOW_ORCHESTRATION_TYPE);
+ };
+
var wholeData=[];
$scope.filterDataWithHigherVersion = function(serviceData){
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js
index d966df8d9..9eed4c14d 100644
--- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js
@@ -541,7 +541,7 @@
});
};
- function isCompatibleVNFRole(vnf) {
+ function isCompatibleNFRole(vnf) {
return vnf.properties['nf-role'] === vm.changeManagement['vnfType'] || !vm.changeManagement['vnfType'];
@@ -549,7 +549,7 @@
function isValidVnf(vnf) {
- let result = isCompatibleVNFRole(vnf) && vnf.properties["model-invariant-id"]
+ let result = isCompatibleNFRole(vnf) && vnf.properties["model-invariant-id"]
&& vnf.properties["model-version-id"];
return result;
@@ -577,9 +577,9 @@
vm.vnfTypes = [];
vm.vnfTypesTemp = [];
vm.serviceInstances = [];
- vm.fromVNFVersions=[];
- vm.vnfNames =[];
- vm.changeManagement.vnfNames =[];
+ vm.fromVNFVersions = [];
+ vm.vnfNames = [];
+ vm.changeManagement.vnfNames = [];
var instances = vm.changeManagement.serviceType["service-instances"]["service-instance"];
// var promiseArrOfGetVnfs = preparePromiseArrOfGetVnfs(instances);
@@ -723,7 +723,7 @@
};
vm.loadVNFNames = function () {
- vm.changeManagement.vnfNames =[];
+ vm.changeManagement.vnfNames = [];
vm.vnfNames = [];
const vnfs = vm.changeManagement.fromVNFVersion ? vm.vnfs : [];
@@ -731,7 +731,7 @@
var selectedVersionNumber = getVersionNameForId(vm.changeManagement.fromVNFVersion);
- if (isCompatibleVNFRole(vnf) &&
+ if (isCompatibleNFRole(vnf) &&
selectedVersionNumber === getVersionNameForId(vnf.properties["model-version-id"])) {
var vServer = {};
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/view-models/serviceModels.htm b/vid-app-common/src/main/webapp/app/vid/scripts/view-models/serviceModels.htm
index 4570a0b08..06fc7f67b 100755
--- a/vid-app-common/src/main/webapp/app/vid/scripts/view-models/serviceModels.htm
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/view-models/serviceModels.htm
@@ -48,6 +48,7 @@
<tr>
<th att-table-header key="action">Action</th>
<th att-table-header key="uuid">UUID</th>
+ <th ng-if="isShowOrchestrationType()" att-table-header key="orchestrationType">Orchestration Type</th>
<th att-table-header key="invariantUUID">Invariant UUID</th>
<th att-table-header default-sort="A" key="name">Name</th>
<th att-table-header key="version">Version</th>
@@ -62,6 +63,7 @@
<tr class="sdcServiceModel" data-tests-id="Browse_SDC_Service_Models-uuid-{{service['uuid']}}">
<td class="deploy" att-table-body ><button class="deploy-service-class" type=button data-tests-id="deploy-{{service['uuid']}}" ng-click="deployService(service)" att-button btn-type="{{deployButtonType}}" size="small">Deploy</button></td>
<td class="uuid" att-table-body ng-bind="service['uuid']"></td>
+ <td ng-if="isShowOrchestrationType()" class="orchestrationType" att-table-body ng-bind="service['orchestrationType']"></td>
<td class="invariantUUID" att-table-body data-tests-id="Invariant-{{service['invariantUUID']}}" ng-bind="service['invariantUUID']"></td>
<td class="name" att-table-body ng-bind="service['name']"></td>
<td class="version" att-table-body ng-bind="service['version']"></td>
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java
index bf8a5a1bc..2076d83ef 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java
@@ -22,7 +22,6 @@ package org.onap.vid.aai.util;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
-import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static javax.ws.rs.core.Response.Status.OK;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -166,12 +165,12 @@ public class AAIRestInterfaceTest {
Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
// when
+ when(builder.build(any(), any())).thenReturn(invocation);
+ when(invocation.invoke()).thenReturn(response);
when(builder.post(Mockito.any(Entity.class))).thenReturn(response);
when(response.getStatusInfo()).thenReturn(OK);
Response finalResponse = testSubject.RestPost("", PATH, payload, false);
- // then
- verify(builder).post(entity);
Assert.assertEquals(response, finalResponse);
}
@@ -182,13 +181,13 @@ public class AAIRestInterfaceTest {
Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
// when
- when(builder.post(Mockito.any(Entity.class))).thenReturn(response);
+ when(builder.build(any(), any())).thenReturn(invocation);
+ when(invocation.invoke()).thenReturn(response);
when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
Response finalResponse = testSubject.RestPost("", PATH, payload, false);
// then
- verify(builder).post(entity);
Assert.assertEquals(response, finalResponse);
}
@@ -199,58 +198,15 @@ public class AAIRestInterfaceTest {
Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
// when
- when(builder.post(Mockito.any(Entity.class))).thenThrow(new RuntimeException());
+ when(builder.build(any(), any())).thenReturn(invocation);
+ when(invocation.invoke()).thenThrow(new RuntimeException());
Response finalResponse = testSubject.RestPost("", PATH, payload, false);
// then
- verify(builder).post(entity);
Assert.assertNull(finalResponse);
}
@Test
- public void shouldExecuteRestDeleteMethodWithResponse400() {
- // given
- // when
- when(builder.delete()).thenReturn(response);
- when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
- String reason = "Any reason";
- when(response.readEntity(String.class)).thenReturn(reason);
- when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
- boolean finalResponse = testSubject.Delete("", "", PATH);
-
- // then
- verify(builder).delete();
- Assert.assertFalse(finalResponse);
- }
-
- @Test
- public void shouldExecuteRestDeleteMethodWithResponse404() {
- // given
- // when
- when(builder.delete()).thenReturn(response);
- when(response.getStatusInfo()).thenReturn(NOT_FOUND);
- String reason = "Any reason";
- when(response.readEntity(String.class)).thenReturn(reason);
- when(response.getStatus()).thenReturn(NOT_FOUND.getStatusCode());
- boolean finalResponse = testSubject.Delete("", "", PATH);
-
- // then
- verify(builder).delete();
- Assert.assertFalse(finalResponse);
- }
-
- @Test
- public void shouldFailWhenRestDeleteExecuted() {
- // given
- // when
- when(builder.delete()).thenThrow(new RuntimeException());
- boolean finalResponse = testSubject.Delete("", "", PATH);
- // then
- verify(builder).delete();
- Assert.assertFalse(finalResponse);
- }
-
- @Test
public void shouldExecuteRestGetMethodWithResponse200() {
// given
// when
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java
deleted file mode 100644
index c0d3b962f..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * VID
- * ================================================================================
- * Copyright (C) 2018 - 2019 Nokia. All rights reserved.
- * ================================================================================
- * 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.vid.aai.util;
-
-import static javax.ws.rs.core.Response.Status.NO_CONTENT;
-import static javax.ws.rs.core.Response.Status.OK;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.UnsupportedEncodingException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Optional;
-import java.util.UUID;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.Response;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.onap.vid.aai.exceptions.InvalidPropertyException;
-import org.onap.vid.utils.Logging;
-import org.testng.Assert;
-
-@RunWith(Parameterized.class)
-public class ParametrizedAAIRestInterfaceTest {
-
- private static final String PATH = "path";
- private static final String HTTP_LOCALHOST = "http://localhost/";
- @Mock
- private Client client;
- @Mock
- private WebTarget webTarget;
- @Mock
- private Invocation.Builder builder;
- @Mock
- private ServletRequestHelper servletRequestHelper;
- @Mock
- private HttpsAuthClient httpsAuthClient;
- @Mock
- private HttpServletRequest httpServletRequest;
- @Mock
- private Response response;
- @Mock
- private SystemPropertyHelper systemPropertyHelper;
- @Mock
- private Logging loggingService;
-
- private AAIRestInterface testSubject;
- private Response.Status status;
-
- @Parameterized.Parameters
- public static Collection<Object> data() {
- return Arrays.asList(OK, NO_CONTENT);
- }
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- mockSystemProperties();
- testSubject = createTestSubject();
- when(client.target(HTTP_LOCALHOST+PATH)).thenReturn(webTarget);
- when(webTarget.request()).thenReturn(builder);
- when(builder.accept(Mockito.anyString())).thenReturn(builder);
- when(builder.header(Mockito.anyString(), Mockito.anyString())).thenReturn(builder);
- when(servletRequestHelper.extractOrGenerateRequestId()).thenReturn(UUID.randomUUID().toString());
- }
-
- public ParametrizedAAIRestInterfaceTest(Response.Status status) {
- this.status = status;
- }
-
- private AAIRestInterface createTestSubject() {
- return new AAIRestInterface(Optional.of(client), httpsAuthClient, servletRequestHelper, systemPropertyHelper, loggingService);
- }
-
- @Test
- public void testRestDeleteWithValidResponse() {
-
- // when
- when(builder.delete()).thenReturn(response);
- when(response.getStatusInfo()).thenReturn(status);
- boolean finalResponse = testSubject.Delete("", "", PATH);
-
- // then
- verify(builder).delete();
- Assert.assertTrue(finalResponse);
- }
-
- private void mockSystemProperties() throws UnsupportedEncodingException, InvalidPropertyException {
- when(systemPropertyHelper.getAAIServerUrl()).thenReturn(Optional.of(HTTP_LOCALHOST));
- when(systemPropertyHelper.getAAIUseClientCert()).thenReturn(Optional.of("cert"));
- when(systemPropertyHelper.getAAIVIDPasswd()).thenReturn(Optional.of("passwd"));
- when(systemPropertyHelper.getAAIVIDUsername()).thenReturn(Optional.of("user"));
- when(systemPropertyHelper.getEncodedCredentials()).thenReturn("someCredentials");
- when(systemPropertyHelper.getFullServicePath(Mockito.anyString())).thenReturn("http://localhost/path");
- }
-
-}
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientITTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientITTest.java
index fd946ebde..7cbf0805b 100644
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientITTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientITTest.java
@@ -24,10 +24,14 @@ import static com.xebialabs.restito.semantics.Action.ok;
import static com.xebialabs.restito.semantics.Action.stringContent;
import static org.apache.http.client.config.RequestConfig.custom;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.matchesPattern;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
+import static org.hamcrest.collection.IsMapContaining.hasEntry;
+import static org.hamcrest.collection.IsMapContaining.hasKey;
+import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.onap.vid.client.SyncRestClientInterface.HEADERS.X_ECOMP_INSTANCE_ID;
@@ -125,10 +129,12 @@ public class SdcRestClientITTest {
assertTrue(first.isPresent());
- assertThat(first.get().getHeaders().keySet(),
- hasItems(X_ECOMP_INSTANCE_ID.toLowerCase(), REQUEST_ID_HEADER_KEY.toLowerCase()));
- assertThat(first.get().getHeaders().get(REQUEST_ID_HEADER_KEY.toLowerCase()).get(0),
- matchesPattern(UUID_REGEX));
+ assertThat(first.get().getHeaders(),
+ allOf(
+ hasEntry(equalToIgnoringCase(REQUEST_ID_HEADER_KEY), contains(matchesPattern(UUID_REGEX))),
+ hasKey(equalToIgnoringCase(X_ECOMP_INSTANCE_ID)),
+ hasEntry(equalToIgnoringCase("x-onap-partnerName"), contains(equalTo("VID.VID")))
+ ));
}
private Service getExpectedService(String stringId) {
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerNewTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerNewTest.java
index 43edeebe9..03a6c40f3 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerNewTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerNewTest.java
@@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.Test;
import org.onap.vid.mso.MsoBusinessLogicImpl;
import org.onap.vid.mso.MsoInterface;
-import org.onap.vid.mso.rest.MsoRestClientNew;
+import org.onap.vid.mso.RestMsoImplementation;
import org.onap.vid.mso.rest.RequestDetails;
import org.onap.vid.mso.rest.RequestDetailsWrapper;
import org.onap.vid.services.CloudOwnerServiceImpl;
@@ -36,7 +36,7 @@ public class MsoControllerNewTest {
private MsoController createTestSubject() {
try {
- return new MsoController(new MsoBusinessLogicImpl(mock(MsoInterface.class)), mock(MsoRestClientNew.class),
+ return new MsoController(new MsoBusinessLogicImpl(mock(MsoInterface.class)), mock(RestMsoImplementation.class),
new CloudOwnerServiceImpl(null, null));
} catch (Exception e) {
return null;
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java
index 5aa6505d4..09f0fd357 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java
@@ -50,8 +50,8 @@ import org.onap.vid.model.RequestReferencesContainer;
import org.onap.vid.mso.MsoBusinessLogic;
import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.MsoResponseWrapper2;
+import org.onap.vid.mso.RestMsoImplementation;
import org.onap.vid.mso.RestObject;
-import org.onap.vid.mso.rest.MsoRestClientNew;
import org.onap.vid.mso.rest.Request;
import org.onap.vid.mso.rest.RequestDetails;
import org.onap.vid.mso.rest.RequestDetailsWrapper;
@@ -73,13 +73,13 @@ public class MsoControllerTest {
private MockMvc mockMvc;
private MsoBusinessLogic msoBusinessLogic;
private CloudOwnerService cloudService;
- private MsoRestClientNew msoRestClient;
+ private RestMsoImplementation msoRestClient;
@Before
public void setUp() {
msoBusinessLogic = mock(MsoBusinessLogic.class);
cloudService = mock(CloudOwnerService.class);
- msoRestClient = mock(MsoRestClientNew.class);
+ msoRestClient = mock(RestMsoImplementation.class);
MsoController msoController = new MsoController(msoBusinessLogic, msoRestClient, cloudService);
mockMvc = MockMvcBuilders.standaloneSetup(msoController).build();
diff --git a/vid-app-common/src/test/java/org/onap/vid/job/command/ResourceCommandTest.java b/vid-app-common/src/test/java/org/onap/vid/job/command/ResourceCommandTest.java
index 9501614b7..986f5d0f5 100644
--- a/vid-app-common/src/test/java/org/onap/vid/job/command/ResourceCommandTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/job/command/ResourceCommandTest.java
@@ -20,8 +20,45 @@
package org.onap.vid.job.command;
+import static java.util.Collections.emptyList;
+import static org.mockito.AdditionalAnswers.returnsFirstArg;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.RETURNS_MOCKS;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.onap.vid.job.command.ResourceCommandKt.ACTION_PHASE;
+import static org.onap.vid.job.command.ResourceCommandKt.INTERNAL_STATE;
+import static org.onap.vid.job.command.ResourceCommandTest.FakeResourceCreator.createGroup;
+import static org.onap.vid.job.command.ResourceCommandTest.FakeResourceCreator.createMember;
+import static org.onap.vid.job.command.ResourceCommandTest.FakeResourceCreator.createNetwork;
+import static org.onap.vid.job.command.ResourceCommandTest.FakeResourceCreator.createService;
+import static org.onap.vid.job.command.ResourceCommandTest.FakeResourceCreator.createVfModule;
+import static org.onap.vid.job.command.ResourceCommandTest.FakeResourceCreator.createVnf;
+import static org.onap.vid.model.Action.Create;
+import static org.onap.vid.model.Action.Delete;
+import static org.onap.vid.model.Action.None;
+import static org.onap.vid.model.Action.Resume;
+import static org.onap.vid.model.Action.values;
+import static org.onap.vid.utils.Logging.getMethodCallerName;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.ws.rs.ProcessingException;
+import kotlin.Pair;
import org.jetbrains.annotations.NotNull;
import org.onap.vid.exceptions.AbortingException;
import org.onap.vid.exceptions.GenericUncheckedException;
@@ -32,32 +69,19 @@ import org.onap.vid.job.JobsBrokerService;
import org.onap.vid.job.NextCommand;
import org.onap.vid.job.impl.JobSharedData;
import org.onap.vid.model.Action;
-import org.onap.vid.model.serviceInstantiation.*;
+import org.onap.vid.model.serviceInstantiation.BaseResource;
+import org.onap.vid.model.serviceInstantiation.InstanceGroup;
+import org.onap.vid.model.serviceInstantiation.InstanceGroupMember;
+import org.onap.vid.model.serviceInstantiation.Network;
+import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
+import org.onap.vid.model.serviceInstantiation.VfModule;
+import org.onap.vid.model.serviceInstantiation.Vnf;
import org.onap.vid.mso.RestMsoImplementation;
import org.onap.vid.mso.model.ModelInfo;
import org.springframework.http.HttpMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import javax.ws.rs.ProcessingException;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static java.util.Collections.emptyList;
-import static org.mockito.AdditionalAnswers.returnsFirstArg;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.*;
-import static org.onap.vid.job.command.ResourceCommandKt.ACTION_PHASE;
-import static org.onap.vid.job.command.ResourceCommandKt.INTERNAL_STATE;
-import static org.onap.vid.job.command.ResourceCommandTest.FakeResourceCreator.*;
-import static org.onap.vid.model.Action.*;
-import static org.onap.vid.utils.Logging.getMethodCallerName;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-
public class ResourceCommandTest {
public static class MockCommand extends ResourceCommand {
@@ -503,4 +527,30 @@ public class ResourceCommandTest {
assertEquals(expectedNextStatus, nextCommand.getStatus());
}
+ @DataProvider
+ public static Object[][] resourcePosition() {
+ return new Object[][]{
+ {1, 2, 3, ImmutableList.of(1,2,3)},
+ {null, 1, 100, ImmutableList.of(101,1,100)},
+ {null, null, null, ImmutableList.of(1,2,3)},
+ {1,2,2, ImmutableList.of(1,2,2)}
+ };
+ }
+
+ @Test(dataProvider = "resourcePosition")
+ public void sortChildren_sortAccordingToPosition(Integer firstPosition, Integer secondPosition, Integer thirdPosition, List<Integer> expectedPositions){
+ BaseResource mockedRequest1 = mock(BaseResource.class);
+ when(mockedRequest1.getPosition()).thenReturn(firstPosition);
+ BaseResource mockedRequest2 = mock(BaseResource.class);
+ when(mockedRequest2.getPosition()).thenReturn(secondPosition);
+ BaseResource mockedRequest3 = mock(BaseResource.class);
+ when(mockedRequest3.getPosition()).thenReturn(thirdPosition);
+
+ MockCommand underTest = new MockCommand(InternalState.CREATING_CHILDREN, Create, Job.JobStatus.IN_PROGRESS);
+ List<Pair<BaseResource, Integer>> sortedList = underTest.setPositionWhereIsMissing(ImmutableList.of(mockedRequest1, mockedRequest2, mockedRequest3));
+
+ assertEquals(sortedList.get(0).getSecond(),expectedPositions.get(0));
+ assertEquals(sortedList.get(1).getSecond(),expectedPositions.get(1));
+ assertEquals(sortedList.get(2).getSecond(),expectedPositions.get(2));
+ }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/job/command/ServiceInProgressStatusCommandTest.java b/vid-app-common/src/test/java/org/onap/vid/job/command/ServiceInProgressStatusCommandTest.java
index 787ff608d..992325049 100644
--- a/vid-app-common/src/test/java/org/onap/vid/job/command/ServiceInProgressStatusCommandTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/job/command/ServiceInProgressStatusCommandTest.java
@@ -143,9 +143,14 @@ public class ServiceInProgressStatusCommandTest {
UUID uuid = UUID.randomUUID();
String userId = "mockedUserID";
String testApi = "VNF_API";
+
+ // Create components setPosition in order to verify on the creation order on createChildJob
+ Network network = createNetwork(Create);
+ network.setPosition(0);
Vnf vnf1 = createVnf(emptyList(), Create);
+ vnf1.setPosition(1);
Vnf vnf2 = createVnf(emptyList(), Create);
- Network network = createNetwork(Create);
+ vnf2.setPosition(2);
ServiceInstantiation serviceInstantiation = createService(
ImmutableList.of(vnf1, vnf2),
ImmutableList.of(network),
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
index 558dc269f..83fff4f5d 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
@@ -1255,7 +1255,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
UUID workflow_UUID = new UUID(3,30);
String path = "/instanceManagement/v1/serviceInstances/"+serviceInstanceId+"/vnfs/"+vnfInstanceId+"/workflows/"+workflow_UUID;
- given(msoInterface.invokeWorkflow(eq(request), eq(path), MockitoHamcrest.argThat(allOf(hasEntry("X-RequestorID", "testRequester"),hasEntry("X-ONAP-PartnerName", "VID"))))).willReturn(okResponse);
+ given(msoInterface.invokeWorkflow(eq(request), eq(path), MockitoHamcrest.argThat(allOf(hasEntry("X-RequestorID", "testRequester"),hasEntry("X-ONAP-PartnerName", "VID.VID"))))).willReturn(okResponse);
// when
MsoResponseWrapper response = msoBusinessLogic.invokeVnfWorkflow(request, "testRequester", serviceInstanceId, vnfInstanceId, workflow_UUID);
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java
index e1b78740a..792435002 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java
@@ -37,13 +37,12 @@ import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
+import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.JerseyInvocation;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.onap.vid.aai.util.HttpClientMode;
import org.onap.vid.aai.util.HttpsAuthClient;
-import org.onap.vid.changeManagement.RequestDetailsWrapper;
-import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.mso.rest.RequestDetails;
import org.onap.vid.utils.Logging;
import org.onap.vid.utils.SystemPropertiesWrapper;
@@ -104,46 +103,6 @@ public class RestMsoImplementationTest {
assertThat(result).doesNotContainKey("notExistingKey");
}
- @Test
- public void shouldProperlyGetRestObjectWithRequestInfo() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
-
- prepareMocks(rawData, HttpStatus.ACCEPTED.value(),"");
-
- // when
- RestObjectWithRequestInfo<HttpRequest> response = restMsoImplementation.Get(httpRequest, path, restObject,false);
-
- // then
- assertThat(response.getRequestedUrl()).contains(path);
- assertThat(response.getRawData()).isEqualTo(rawData);
- assertThat(response.getHttpCode()).isEqualTo(HttpStatus.ACCEPTED.value());
- assertThat(response.getHttpMethod()).isEqualTo(HttpMethod.GET);
- }
-
- @Test( expectedExceptions = GenericUncheckedException.class)
- public void shouldThrowExceptionWhenGetRestObjectWithRequestInfoGetsWrongStatus() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
-
- prepareMocks("",HttpStatus.BAD_REQUEST.value(),"");
-
- // when
- restMsoImplementation.Get(httpRequest, "", restObject,false);
- }
-
- @Test( expectedExceptions = MsoTestException.class)
- public void shouldThrowExceptionWhenGetRestObjectWithRequestInfoGetsWrongParameters() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
-
- prepareMocks("",HttpStatus.ACCEPTED.value(),"");
- when(systemProperties.getProperty(MsoProperties.MSO_SERVER_URL)).thenReturn("SAMPLE_URL");
- when(mockClient.target("SAMPLE_URL")).thenThrow(new MsoTestException("test-target-exception"));
-
- // when
- restMsoImplementation.Get(httpRequest, "", restObject,false);
- }
@Test()
public void shouldProperlyGetRestObjectForObjectWithRequestInfoAndAcceptCode() {
@@ -171,79 +130,6 @@ public class RestMsoImplementationTest {
assertThat(response.getRaw()).isEqualTo(rawData);
}
- @Test()
- public void shouldProperlyDeleteRestObjectWithStatusHttpAccepted() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
-
- prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE");
-
- // when
- restMsoImplementation.Delete(httpRequest, "testObject", path, restObject);
-
- // then
- assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED.value());
- }
-
- @Test()
- public void shouldProperlyDeleteRestObjectWithStatusOK() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
-
- prepareMocks(rawData,HttpStatus.OK.value(),"DELETE");
-
- // when
- restMsoImplementation.Delete(httpRequest, "testObject", path, restObject);
-
- // then
- assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.OK.value());
- }
-
- @Test()
- public void shouldProperlyReturnFromDeleteWithStatusBadRequest() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
-
- prepareMocks(rawData,HttpStatus.BAD_REQUEST.value(),"DELETE");
-
- // when
- restMsoImplementation.Delete(httpRequest, "testObject", path, restObject);
-
- // then
- assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value());
- }
-
- @Test()
- public void shouldProperlyReturnFromDeleteWithStatusOtherThenAbove() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
- prepareMocks(rawData,HttpStatus.NOT_EXTENDED.value(),"DELETE");
-
- // when
- restMsoImplementation.Delete(httpRequest, "testObject", path, restObject);
-
- // then
- assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.NOT_EXTENDED.value());
- }
-
- @Test( expectedExceptions = MsoTestException.class)
- public void shouldThrowExceptionWhenCallsDeleteWithWrongParameters() {
- // given
- when(mockClient.target(any(String.class))).thenThrow(new MsoTestException("testDeleteException"));
-
- // when
- restMsoImplementation.Delete(httpRequest, "testObject", "", null);
- }
-
- @Test( expectedExceptions = NullPointerException.class)
- public void shouldThrowExceptionWhenCallsDeleteWithWrongObjectType() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
- prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE");
-
- // when
- restMsoImplementation.Delete(null, "testObject", path, restObject);
- }
@Test
public void shouldProperlyPostForObject() {
@@ -264,43 +150,6 @@ public class RestMsoImplementationTest {
}
@Test
- public void shouldProperlyDeleteForObject() {
- // given
- RequestDetails requestDetails = new RequestDetails();
-
- RestObject<HttpRequest> expectedResponse = new RestObject<>();
- expectedResponse.setStatusCode(HttpStatus.ACCEPTED.value());
- expectedResponse.setRaw(rawData);
-
- prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE");
-
- // when
- RestObject<HttpRequest> response = restMsoImplementation.DeleteForObject(requestDetails, path, HttpRequest.class);
-
- // then
- assertThat(response).isEqualToComparingFieldByField(expectedResponse);
- }
-
- @Test
- public void shouldProperlyPost() {
- // given
- RequestDetails requestDetails = new RequestDetails();
- RestObject<String> response = new RestObject<>();
-
- RestObject<String> expectedResponse = new RestObject<>();
- expectedResponse.setStatusCode(HttpStatus.ACCEPTED.value());
- expectedResponse.setRaw(rawData);
-
- prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"POST");
-
- // when
- restMsoImplementation.Post(rawData,requestDetails, path, response);
-
- // then
- assertThat(response).isEqualToComparingFieldByField(expectedResponse);
- }
-
- @Test
public void shouldProperlyPrepareClient() {
// given
String method = "POST";
@@ -339,70 +188,6 @@ public class RestMsoImplementationTest {
restMsoImplementation.restCall(HttpMethod.GET, String.class, null, "", Optional.empty());
}
- @Test
- public void shouldProperlyPutRestObjectWithProperParametersAndStatusAccepted() {
- // given
- String method = "PUT";
- prepareMocks(rawData,HttpStatus.ACCEPTED.value(),method);
-
- org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
- RestObject<String> response = new RestObject<>();
-
- RestObject<String> expectedResponse = new RestObject<>();
- expectedResponse.setStatusCode(HttpStatus.ACCEPTED.value());
- expectedResponse.set(rawData);
-
- // when
- restMsoImplementation.Put("testPutBody", requestDetailsWrapper , path, response);
-
- // then
- assertThat(response).isEqualToComparingFieldByField(expectedResponse);
- }
-
- @Test
- public void shouldProperlyPutRestObjectWithProperParametersAndStatusMultipleChoices() {
- // given
- String method = "PUT";
- prepareMocks(rawData,HttpStatus.MULTIPLE_CHOICES.value(),method);
-
- org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
- RestObject<String> response = new RestObject<>();
-
- RestObject<String> expectedResponse = new RestObject<>();
- expectedResponse.setStatusCode(HttpStatus.MULTIPLE_CHOICES.value());
- expectedResponse.set(rawData);
-
- // when
- restMsoImplementation.Put("testPutBody", requestDetailsWrapper , path, response);
-
- // then
- assertThat(response).isEqualToComparingFieldByField(expectedResponse);
- }
-
- @Test( expectedExceptions = MsoTestException.class)
- public void shouldThrowExceptionWhenCallsPutWithWrongParameters() {
- // given
- when(mockClient.target(any(String.class))).thenThrow(new MsoTestException("testDeleteException"));
- org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
-
- // when
- restMsoImplementation.Put(null, requestDetailsWrapper, "", null);
- }
-
- @Test( expectedExceptions = NullPointerException.class)
- public void shouldThrowExceptionWhenCallsPutWithWrongObjectType() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
- org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
-
- prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE");
-
- // when
- restMsoImplementation.Put(null, requestDetailsWrapper, path, restObject);
- }
-
-
-
private void prepareMocks(String rawData,int status,String httpMethod) {
when(mockClient.target(any(String.class))).thenReturn(webTarget);
@@ -411,6 +196,7 @@ public class RestMsoImplementationTest {
when(builder.accept(any(String.class))).thenReturn(builder);
when(builder.headers(any(MultivaluedMap.class))).thenReturn(builder);
+ when(builder.property(eq(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION), eq(true))).thenReturn(builder);
when(builder.get()).thenReturn(response);
when(builder.build( eq(httpMethod), any(Entity.class))).thenReturn(jerseyInvocation);
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
index 457007500..aaaa324e8 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
@@ -410,7 +410,7 @@ public class MsoRestClientNewTest {
String sourceId = "";
String endpoint = "";
final SyncRestClient client = mock(SyncRestClient.class);
- MsoRestClientNew testSubject = new MsoRestClientNew(client, "", null, new SystemPropertiesWrapper(), mock(Logging.class));
+ MsoRestClientNew testSubject = new MsoRestClientNew(client, "", new SystemPropertiesWrapper());
// setup
final HttpResponse<String> response = mock(HttpResponse.class);
@@ -474,10 +474,10 @@ public class MsoRestClientNewTest {
private MsoRestClientNew msoRestClient() {
return new MsoRestClientNew(new SyncRestClient(JOSHWORKS_JACKSON_OBJECT_MAPPER, mock(Logging.class)),
- baseUrl(), null, new SystemPropertiesWrapper(), mock(Logging.class));
+ baseUrl(), new SystemPropertiesWrapper());
}
private MsoRestClientNew createTestSubject() {
- return new MsoRestClientNew(null, "", null, new SystemPropertiesWrapper(), mock(Logging.class));
+ return new MsoRestClientNew(null, "", new SystemPropertiesWrapper());
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
index 5486becad..dd05a625e 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
@@ -99,7 +99,7 @@ public class MsoRestClientTest {
initMocks(this);
when(systemProperties.getProperty(MsoProperties.MSO_PASSWORD)).thenReturn("OBF:1ghz1kfx1j1w1m7w1i271e8q1eas1hzj1m4i1iyy1kch1gdz");
when(systemProperties.getProperty("app_display_name")).thenReturn("vid");
- restClient = new MsoRestClientNew(client,baseUrl,null,systemProperties,loggingService);
+ restClient = new MsoRestClientNew(client, baseUrl, systemProperties);
}
@Test
@@ -832,7 +832,7 @@ public class MsoRestClientTest {
Map<String,String> extraHeaders = new HashMap<>();
extraHeaders.put("X-ONAP-RequestID",requestId.toString());
- extraHeaders.put("X-ONAP-PartnerName","VID");
+ extraHeaders.put("X-ONAP-PartnerName","VID.VID");
extraHeaders.put("X-RequestorID","testRequester");
// when
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java
index ac82a6e53..123737f4f 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java
@@ -32,7 +32,7 @@ import static com.xebialabs.restito.semantics.Condition.post;
import static com.xebialabs.restito.semantics.Condition.uri;
import static com.xebialabs.restito.semantics.Condition.withHeader;
import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
-import static org.onap.vid.mso.rest.MsoRestClientNew.X_ONAP_PARTNER_NAME;
+import static org.onap.vid.logging.Headers.PARTNER_NAME;
import static org.onap.vid.utils.Logging.ONAP_REQUEST_ID_HEADER_KEY;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -235,7 +235,7 @@ class MsoRestClientTestUtil implements AutoCloseable {
withHeader(HttpHeaders.ACCEPT),
withHeader(HttpHeaders.CONTENT_TYPE),
withHeader(MsoRestClientNew.X_FROM_APP_ID),
- withHeader(X_ONAP_PARTNER_NAME, "VID"),
+ withHeader(PARTNER_NAME.getHeaderName(), "VID.VID"),
withHeader(SystemProperties.ECOMP_REQUEST_ID),
withHeader(ONAP_REQUEST_ID_HEADER_KEY)
);
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java
index ac05ea706..cfb9ee6ea 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java
@@ -20,16 +20,32 @@
package org.onap.vid.mso.rest;
+import static org.apache.commons.io.IOUtils.toInputStream;
+import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.matchesPattern;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
+import io.joshworks.restclient.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
@@ -38,6 +54,7 @@ import java.util.stream.Stream;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.core.MultivaluedMap;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.mockito.ArgumentCaptor;
@@ -47,13 +64,21 @@ import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.aai.util.AAIRestInterface;
+import org.onap.vid.aai.util.HttpsAuthClient;
import org.onap.vid.aai.util.ServletRequestHelper;
import org.onap.vid.aai.util.SystemPropertyHelper;
+import org.onap.vid.client.SyncRestClient;
import org.onap.vid.controller.filter.PromiseRequestIdFilter;
+import org.onap.vid.logging.Headers;
+import org.onap.vid.mso.MsoProperties;
+import org.onap.vid.mso.RestMsoImplementation;
import org.onap.vid.testUtils.TestUtils;
import org.onap.vid.utils.Logging;
+import org.onap.vid.utils.SystemPropertiesWrapper;
import org.onap.vid.utils.Unchecked;
+import org.springframework.http.HttpMethod;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -67,18 +92,29 @@ public class OutgoingRequestHeadersTest {
private static final PromiseRequestIdFilter promiseRequestIdFilter = new PromiseRequestIdFilter();
-// @InjectMocks
-// private RestMsoImplementation restMsoImplementation;
+ @InjectMocks
+ private RestMsoImplementation restMsoImplementation;
+
+ private MsoRestClientNew msoRestClientNew;
@Mock
private SystemPropertyHelper systemPropertyHelper;
@Mock
+ private SystemPropertiesWrapper systemPropertiesWrapper;
+
+ @Mock
+ private HttpsAuthClient httpsAuthClient;
+
+ @Mock
private ServletRequestHelper servletRequestHelper;
@Mock
private Logging loggingService;
+ @Mock
+ SyncRestClient syncRestClient;
+
@InjectMocks
private AAIRestInterface aaiRestInterface;
@@ -88,7 +124,12 @@ public class OutgoingRequestHeadersTest {
@BeforeClass
public void initMocks() {
MockitoAnnotations.initMocks(this);
- when(servletRequestHelper.extractOrGenerateRequestId()).thenAnswer(invocation -> UUID.randomUUID().toString());
+ String oneIncomingRequestId = UUID.randomUUID().toString();
+ when(servletRequestHelper.extractOrGenerateRequestId()).thenReturn(oneIncomingRequestId);
+ when(systemPropertiesWrapper.getProperty(MsoProperties.MSO_PASSWORD)).thenReturn("OBF:1vub1ua51uh81ugi1u9d1vuz");
+ when(systemPropertiesWrapper.getProperty(SystemProperties.APP_DISPLAY_NAME)).thenReturn("vid");
+ //the ctor of MsoRestClientNew require the above lines as preconditions
+ msoRestClientNew = new MsoRestClientNew(syncRestClient, "baseUrl",systemPropertiesWrapper);
}
@BeforeMethod
@@ -101,50 +142,110 @@ public class OutgoingRequestHeadersTest {
(HttpServletRequest) promiseRequestIdFilter.wrapIfNeeded(new MockHttpServletRequest())));
}
-// @DataProvider
-// public Object[][] msoMethods() {
-// return Stream.<ThrowingConsumer<RestMsoImplementation>>of(
-//
-// client -> client.Get(new Object(), "/any path", new RestObject<>(), false),
-// client -> client.GetForObject("/any path", Object.class),
-// client -> client.Post("", "some payload", "/any path", new RestObject<>()),
-// client -> client.PostForObject("some payload", "/any path", Object.class),
-// client -> client.Put(Object.class, new RequestDetailsWrapper(), "/any path", new RestObject<>())
-//
-// ).map(l -> ImmutableList.of(l).toArray()).collect(Collectors.toList()).toArray(new Object[][]{});
-// }
-//
-// @Test(dataProvider = "msoMethods")
-// public void mso(Consumer<RestMsoImplementation> f) throws Exception {
-// final TestUtils.JavaxRsClientMocks mocks = setAndGetMocksInsideRestImpl(restMsoImplementation);
-//
-// f.accept(restMsoImplementation);
-//
-// Invocation.Builder fakeBuilder = mocks.getFakeBuilder();
-// Object requestIdValue = verifyXEcompRequestIdHeaderWasAdded(fakeBuilder);
-// assertEquals(requestIdValue, captureHeaderKeyAndReturnItsValue(fakeBuilder, "X-ONAP-RequestID"));
-//
-// assertThat((String) captureHeaderKeyAndReturnItsValue(fakeBuilder, "Authorization"), startsWith("Basic "));
-// assertThat(captureHeaderKeyAndReturnItsValue(fakeBuilder, "X-ONAP-PartnerName"), equalTo("VID"));
-// }
-//
-// @Test
-// public void whenProvideMsoRestCallUserId_builderHasXRequestorIDHeader() throws Exception {
-//
-// final TestUtils.JavaxRsClientMocks mocks = setAndGetMocksInsideRestImpl(restMsoImplementation);
-// String randomUserName = randomAlphabetic(10);
-//
-// restMsoImplementation.restCall(HttpMethod.DELETE, String.class, null, "abc", Optional.of(randomUserName));
-// assertEquals(randomUserName, captureHeaderKeyAndReturnItsValue(mocks.getFakeBuilder(), "X-RequestorID"));
-// }
+ @DataProvider
+ public Object[][] msoMethods() {
+ return Stream.<ThrowingConsumer<RestMsoImplementation>>of(
+ client -> client.GetForObject("/any path", Object.class),
+ client -> client.restCall(HttpMethod.DELETE, Object.class, "some payload", "/any path", Optional.of("userId")),
+ client -> client.PostForObject("some payload", "/any path", Object.class)
+ ).map(l -> ImmutableList.of(l).toArray()).collect(Collectors.toList()).toArray(new Object[][]{});
+ }
+
+ @Test(dataProvider = "msoMethods")
+ public void mso(Consumer<RestMsoImplementation> f) throws Exception {
+ final TestUtils.JavaxRsClientMocks mocks = setAndGetMocksInsideRestImpl(restMsoImplementation);
+
+ f.accept(restMsoImplementation);
+ HeadersVerifier headersVerifier = new HeadersVerifier().verifyFirstCall(mocks.getFakeBuilder());
+
+ assertThat((String) captureHeaderKeyAndReturnItsValue(mocks.getFakeBuilder(), "Authorization"), startsWith("Basic "));
+
+ //verify requestId is same in next call but invocationId is different
+
+ //given
+ final TestUtils.JavaxRsClientMocks mocks2 = setAndGetMocksInsideRestImpl(restMsoImplementation);
+
+ //when
+ f.accept(restMsoImplementation);
+ //then
+ headersVerifier.verifySecondCall(mocks2.getFakeBuilder());
+ }
+
+
+
+ @Test
+ public void whenProvideMsoRestCallUserId_builderHasXRequestorIDHeader() throws Exception {
+
+ final TestUtils.JavaxRsClientMocks mocks = setAndGetMocksInsideRestImpl(restMsoImplementation);
+ String randomUserName = randomAlphabetic(10);
+
+ restMsoImplementation.restCall(HttpMethod.DELETE, String.class, null, "abc", Optional.of(randomUserName));
+ assertEquals(randomUserName, captureHeaderKeyAndReturnItsValue(mocks.getFakeBuilder(), "X-RequestorID"));
+ }
+
+ @DataProvider
+ public Object[][] msoRestClientNewMethods() {
+ return Stream.<ThrowingConsumer<MsoRestClientNew>>of(
+ client -> client.createInstance(new Object(), "/any path")
+ ).map(l -> ImmutableList.of(l).toArray()).collect(Collectors.toList()).toArray(new Object[][]{});
+ }
+
+ @Test(dataProvider = "msoRestClientNewMethods")
+ public void msoRestClientNewHeadersTest(Consumer<MsoRestClientNew> f) throws Exception {
+ Map[] captor = setMocksForMsoRestClientNew();
+
+ f.accept(msoRestClientNew);
+ Map headers = captor[0];
+
+ String ecompRequestId = assertRequestHeaderIsUUID(headers, "X-ECOMP-RequestID");
+ String onapRequestID = assertRequestHeaderIsUUID(headers, "X-ONAP-RequestID");
+ assertEquals(ecompRequestId, onapRequestID);
+
+
+ String invocationId1 = assertRequestHeaderIsUUID(headers, "X-InvocationID");
+ assertThat((String) headers.get("Authorization"), startsWith("Basic "));
+ assertThat(headers.get("X-ONAP-PartnerName"), is("VID.VID"));
+
+ //verify requestId is same in next call but invocationId is different
+
+ //given
+ captor = setMocksForMsoRestClientNew();
+
+ //when
+ f.accept(msoRestClientNew);
+ headers = captor[0];
+
+ //then
+ assertEquals(headers.get("X-ONAP-RequestID"), onapRequestID);
+ String invocationId2 = assertRequestHeaderIsUUID(headers, "X-InvocationID");
+ assertNotEquals(invocationId1, invocationId2);
+
+ }
+
+ private Map[] setMocksForMsoRestClientNew() {
+ reset(syncRestClient);
+ HttpResponse<String> httpResponse = mock(HttpResponse.class);
+ String expectedResponse = "myResponse";
+ when(httpResponse.getStatus()).thenReturn(202);
+ when(httpResponse.getBody()).thenReturn(expectedResponse);
+ when(httpResponse.getRawBody()).thenReturn(toInputStream(expectedResponse, StandardCharsets.UTF_8));
+ final Map[] headersCapture = new Map[1];
+ when(syncRestClient.post(anyString(), anyMap(), any(), eq(String.class))).thenAnswer(
+ invocation -> {
+ headersCapture[0] = (Map)invocation.getArguments()[1];
+ return httpResponse;
+ });
+
+ return headersCapture;
+ }
@DataProvider
public Object[][] aaiMethods() {
return Stream.<ThrowingConsumer<AAIRestInterface>>of(
client -> client.RestGet("from app id", "some transId", Unchecked.toURI("/any path"), false),
- client -> client.Delete("whatever source id", "some transId", "/any path"),
client -> client.RestPost("from app id", "/any path", "some payload", false),
+ client -> client.doRest("from app id", "some transId", Unchecked.toURI("/any path"), "somebody", HttpMethod.GET, false, true),
client -> client.RestPut("from app id", "/any path", "some payload", false, false)
).map(l -> ImmutableList.of(l).toArray()).collect(Collectors.toList()).toArray(new Object[][]{});
@@ -152,11 +253,21 @@ public class OutgoingRequestHeadersTest {
@Test(dataProvider = "aaiMethods")
public void aai(Consumer<AAIRestInterface> f) throws Exception {
+ //given
final TestUtils.JavaxRsClientMocks mocks = setAndGetMocksInsideRestImpl(aaiRestInterface);
+ //when
+ f.accept(aaiRestInterface);
+ //then
+ HeadersVerifier headersVerifier = new HeadersVerifier().verifyFirstCall(mocks.getFakeBuilder());
+ //verify requestId is same in next call but invocationId is different
+ //given
+ final TestUtils.JavaxRsClientMocks mocks2 = setAndGetMocksInsideRestImpl(aaiRestInterface);
+ //when
f.accept(aaiRestInterface);
+ //then
+ headersVerifier.verifySecondCall(mocks2.getFakeBuilder());
- verifyXEcompRequestIdHeaderWasAdded(mocks.getFakeBuilder());
}
// @Test(dataProvider = "schedulerMethods")
@@ -169,14 +280,32 @@ public class OutgoingRequestHeadersTest {
//
// }
- private Object verifyXEcompRequestIdHeaderWasAdded(Invocation.Builder fakeBuilder) {
+ private String verifyXEcompRequestIdHeaderWasAdded(Invocation.Builder fakeBuilder) {
final String requestIdHeader = "x-ecomp-requestid";
- final String uuidRegex = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
- Object requestId = captureHeaderKeyAndReturnItsValue(fakeBuilder, requestIdHeader);
+ return assertRequestHeaderIsUUID(fakeBuilder, requestIdHeader);
+ }
+
+ private String assertRequestHeaderIsUUID(Invocation.Builder fakeBuilder, String headerName) {
+ Object headerValue = captureHeaderKeyAndReturnItsValue(fakeBuilder, headerName);
+ return assertRequestHeaderIsUUID(headerName, headerValue);
+ }
+
+ private String assertRequestHeaderIsUUID(Map headers, String headerName) {
+ return assertRequestHeaderIsUUID(headerName, headers.get(headerName));
+ }
- assertThat("header '" + requestIdHeader + "' should be a uuid", requestId,
+ private String assertRequestHeaderIsUUID(String headerName, Object headerValue) {
+ final String uuidRegex = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
+ assertThat("header '" + headerName + "' should be a uuid", headerValue,
allOf(instanceOf(String.class), hasToString(matchesPattern(uuidRegex))));
- return requestId;
+ return (String)headerValue;
+ }
+
+ private void verifyXOnapPartnerNameHeaderWasAdded(Invocation.Builder fakeBuilder) {
+ assertThat(
+ captureHeaderKeyAndReturnItsValue(fakeBuilder, Headers.PARTNER_NAME.getHeaderName()),
+ is("VID.VID")
+ );
}
private Object captureHeaderKeyAndReturnItsValue(Invocation.Builder fakeBuilder, String headerName) {
@@ -187,22 +316,26 @@ public class OutgoingRequestHeadersTest {
// The 'verify()' will capture the request id. If no match -- AssertionError will
// catch for a second chance -- another 'verify()'.
try {
- ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
- Mockito.verify(fakeBuilder)
+ try {
+ ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
+ Mockito.verify(fakeBuilder)
.header(
- Matchers.argThat(s -> equalsIgnoreCase(s, headerName)),
- argumentCaptor.capture()
+ Matchers.argThat(s -> equalsIgnoreCase(s, headerName)),
+ argumentCaptor.capture()
);
- requestId = argumentCaptor.getValue();
+ requestId = argumentCaptor.getValue();
- } catch (AssertionError e) {
- Mockito.verify(fakeBuilder).headers(multivaluedMapArgumentCaptor.capture());
+ } catch (AssertionError e) {
+ Mockito.verify(fakeBuilder).headers(multivaluedMapArgumentCaptor.capture());
- final MultivaluedMap<String, Object> headersMap = multivaluedMapArgumentCaptor.getValue();
- final String thisRequestIdHeader = getFromSetCaseInsensitive(headersMap.keySet(), headerName);
+ final MultivaluedMap<String, Object> headersMap = multivaluedMapArgumentCaptor.getValue();
+ final String thisRequestIdHeader = getFromSetCaseInsensitive(headersMap.keySet(), headerName);
- assertThat(headersMap.keySet(), hasItem(thisRequestIdHeader));
- requestId = headersMap.getFirst(thisRequestIdHeader);
+ assertThat(headersMap.keySet(), hasItem(thisRequestIdHeader));
+ requestId = headersMap.getFirst(thisRequestIdHeader);
+ }
+ } catch (AssertionError e) {
+ throw new AssertionError("header not captured: " + headerName, e);
}
return requestId;
}
@@ -246,4 +379,26 @@ public class OutgoingRequestHeadersTest {
void acceptThrows(T t) throws Exception;
}
+ private class HeadersVerifier {
+
+ private String firstRequestId;
+ private String firstInvocationId;
+
+
+ HeadersVerifier verifyFirstCall(Builder fakeBuilder) {
+ firstRequestId = verifyXEcompRequestIdHeaderWasAdded(fakeBuilder);
+ assertEquals(firstRequestId, captureHeaderKeyAndReturnItsValue(fakeBuilder, "X-ONAP-RequestID"));
+ firstInvocationId = assertRequestHeaderIsUUID(fakeBuilder, "X-InvocationID");
+ verifyXOnapPartnerNameHeaderWasAdded(fakeBuilder);
+ return this;
+ }
+
+ void verifySecondCall(Builder fakeBuilder) {
+ String secondRequestId = verifyXEcompRequestIdHeaderWasAdded(fakeBuilder);
+ assertEquals(firstRequestId, secondRequestId);
+
+ Object secondInvocationId = assertRequestHeaderIsUUID(fakeBuilder, "X-InvocationID");
+ assertNotEquals(firstInvocationId, secondInvocationId);
+ }
+ }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
index 2eae1864f..9df99faa6 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
@@ -103,7 +103,6 @@ public class AaiServiceImplTest {
private static final String SUBSCRIBER_ID = "SUBSCRIBER_ID_EXPECTED";
private static final String STATUS_TEXT = "STATUS_TEXT";
private static final String GLOBAL_SUBSCRIBER_ID = "GLOBAL_SUBSCRIBER_ID";
- private static final String GLOBAL_SUBSCRIBER_ID_NULL_RESPONSE = "ID_NULL";
private static final String VNF_INSTANCE_ID_OK = "VNF_INSTANCE_ID_OK";
private static final String VNF_INSTANCE_ID_FAIL = "VNF_INSTANCE_ID_FAIL";
private static final String PARENT_NAME = "PARENT_NAME";
@@ -277,7 +276,7 @@ public class AaiServiceImplTest {
}
@Test
- public void shouldGetVNFDataWithoutFiltering() {
+ public void shouldGetVNFDataOfInstanceWithoutFiltering() {
when(aaiClient.getVNFData(anyString(), anyString(), anyString())).thenReturn(aaiResponse);
AaiResponse actualResponse = aaiService.getVNFData(anyString(), anyString(), anyString());
@@ -286,30 +285,26 @@ public class AaiServiceImplTest {
}
@Test
- public void shouldGetVNFDataWithFiltering() {
+ public void shouldGetVNFDataOfServiceWithoutFiltering() {
VnfResult vnfResult1 = createVnfResult("ID1", "generic-vnf");
VnfResult vnfResult2 = createVnfResult("ID2", "service-instance");
VnfResult vnfResult3 = createVnfResult("ID3", "anything-else");
- List<VnfResult> vnfResults = Arrays.asList(vnfResult1, vnfResult2, vnfResult3);
- AaiResponse<AaiGetVnfResponse> aaiResponseGetVnfResponse = createAaiResponseVnfResponse(vnfResults);
-
- vnfResults = Arrays.asList(vnfResult1, vnfResult2);
- AaiResponse<AaiGetVnfResponse> expectedResponseWithReturnedVnfs = createAaiResponseVnfResponse(vnfResults);
- AaiResponse expectedResponseWithoutReturnedVnfs = new AaiResponse();
+ AaiResponse<AaiGetVnfResponse> aaiResponseGetVnfResponse = createAaiResponseVnfResponse(
+ Arrays.asList(vnfResult1, vnfResult2, vnfResult3));
when(aaiClient.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE)).thenReturn(aaiResponseGetVnfResponse);
- when(aaiClient.getVNFData(GLOBAL_SUBSCRIBER_ID_NULL_RESPONSE, SERVICE_TYPE)).thenReturn(null);
- AaiResponse<AaiGetVnfResponse> actualResponseWithReturnedVnfs =
- aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE);
- AaiResponse<AaiGetVnfResponse> actualResponseWithoutReturnedVnfs =
- aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID_NULL_RESPONSE, SERVICE_TYPE);
+ assertThat(aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE))
+ .isEqualTo(aaiResponseGetVnfResponse);
+ }
+
+ @Test
+ public void shouldGetNonNullVNFDataOfServiceWhenNoResult() {
+ when(aaiClient.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE)).thenReturn(null);
- assertThat(actualResponseWithReturnedVnfs)
- .isEqualToComparingFieldByFieldRecursively(expectedResponseWithReturnedVnfs);
- assertThat(actualResponseWithoutReturnedVnfs)
- .isEqualToComparingFieldByField(expectedResponseWithoutReturnedVnfs);
+ assertThat(aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE))
+ .isEqualToComparingFieldByField(new AaiResponse());
}
@Test
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceTest.java
index 92a55f0b8..6aa67051e 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceTest.java
@@ -22,7 +22,6 @@ package org.onap.vid.services;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayWithSize;
-import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@@ -33,14 +32,11 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.vid.aai.AaiClientInterface;
-import org.onap.vid.aai.AaiGetVnfResponse;
import org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.model.AaiGetPnfResponse;
import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
@@ -50,7 +46,6 @@ import org.onap.vid.aai.model.Relationship;
import org.onap.vid.aai.model.RelationshipData;
import org.onap.vid.aai.model.RelationshipList;
import org.onap.vid.aai.model.ServiceRelationships;
-import org.onap.vid.aai.model.VnfResult;
import org.onap.vid.model.aaiTree.AAITreeNode;
import org.onap.vid.roles.Role;
import org.onap.vid.roles.RoleValidator;
@@ -211,20 +206,4 @@ public class AaiServiceTest {
assertThat(anyMatch, equalTo(expectedMatch));
}
- @Test
- public void testFilterChangeManagementVNFCandidatesResponse() {
- AaiGetVnfResponse aaiGetVnfResponse = new AaiGetVnfResponse();
- aaiGetVnfResponse.results = new ArrayList<>();
- Stream.of("genEric-vNf", "l3-interface-ipv6-address-list", "vserver", "pserver", "serviCe-inStance").forEach(
- nodeType->{
- VnfResult vnfResult = new VnfResult();
- vnfResult.nodeType=nodeType;
- aaiGetVnfResponse.results.add(vnfResult);
- }
- );
-
- AaiResponse<AaiGetVnfResponse> result = aaiService.filterChangeManagementVNFCandidatesResponse(new AaiResponse<>(aaiGetVnfResponse, "", 200));
- assertEquals(2, result.getT().results.size());
- assertThat(result.getT().results.stream().map(x->x.nodeType).collect(Collectors.toList()), containsInAnyOrder("genEric-vNf","serviCe-inStance"));
- }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/JobsBrokerServiceTest.java b/vid-app-common/src/test/java/org/onap/vid/services/JobsBrokerServiceTest.java
index 40546e967..20c9d1443 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/JobsBrokerServiceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/JobsBrokerServiceTest.java
@@ -21,8 +21,52 @@
package org.onap.vid.services;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.both;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.mockito.Mockito.when;
+import static org.onap.vid.job.Job.JobStatus.COMPLETED;
+import static org.onap.vid.job.Job.JobStatus.COMPLETED_WITH_ERRORS;
+import static org.onap.vid.job.Job.JobStatus.COMPLETED_WITH_NO_ACTION;
+import static org.onap.vid.job.Job.JobStatus.CREATING;
+import static org.onap.vid.job.Job.JobStatus.FAILED;
+import static org.onap.vid.job.Job.JobStatus.IN_PROGRESS;
+import static org.onap.vid.job.Job.JobStatus.PAUSE;
+import static org.onap.vid.job.Job.JobStatus.PENDING;
+import static org.onap.vid.job.Job.JobStatus.PENDING_RESOURCE;
+import static org.onap.vid.job.Job.JobStatus.RESOURCE_IN_PROGRESS;
+import static org.onap.vid.job.Job.JobStatus.STOPPED;
+import static org.onap.vid.testUtils.TestUtils.generateRandomAlphaNumeric;
+import static org.onap.vid.utils.Streams.not;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.lang.reflect.Method;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+import javax.inject.Inject;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
@@ -37,20 +81,21 @@ import org.mockito.MockitoAnnotations;
import org.onap.portalsdk.core.domain.support.DomainVo;
import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.vid.config.DataSourceConfig;
+import org.onap.vid.config.JobAdapterConfig;
import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.exceptions.OperationNotAllowedException;
import org.onap.vid.job.Job;
import org.onap.vid.job.JobAdapter;
+import org.onap.vid.job.JobAdapter.AsyncJobRequest;
import org.onap.vid.job.JobType;
import org.onap.vid.job.JobsBrokerService;
import org.onap.vid.job.command.JobCommandFactoryTest;
import org.onap.vid.job.impl.JobDaoImpl;
import org.onap.vid.job.impl.JobSchedulerInitializer;
+import org.onap.vid.job.impl.JobSharedData;
import org.onap.vid.job.impl.JobsBrokerServiceInDatabaseImpl;
-import org.onap.vid.services.VersionService;
import org.onap.vid.utils.DaoUtils;
-import org.onap.vid.config.DataSourceConfig;
-import org.onap.vid.config.JobAdapterConfig;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.Assert;
@@ -59,31 +104,6 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import javax.inject.Inject;
-import java.lang.reflect.Method;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.util.*;
-import java.util.concurrent.*;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-import java.util.stream.Stream;
-
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.stream.Collectors.toList;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.both;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.mockito.Mockito.when;
-import static org.onap.vid.job.Job.JobStatus.*;
-import static org.onap.vid.utils.Streams.not;
-import static org.onap.vid.testUtils.TestUtils.generateRandomAlphaNumeric;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-
@ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class, JobAdapterConfig.class})
public class JobsBrokerServiceTest extends AbstractTestNGSpringContextTests {
@@ -944,4 +964,40 @@ public class JobsBrokerServiceTest extends AbstractTestNGSpringContextTests {
broker.delete(new UUID(111, 111));
}
+ public static class MockAsyncRequest implements AsyncJobRequest {
+ public String value;
+
+ public MockAsyncRequest() {}
+
+ public MockAsyncRequest(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+ }
+
+ @Test
+ public void twoJobsWithSamePosition_bothJobsArePulled(){
+ UUID uuid = UUID.randomUUID();
+ int positionInBulk = RandomUtils.nextInt();
+ String userId = "userId";
+
+ Optional<Job> firstPulledJob = createAddAndPullJob(uuid, positionInBulk, userId, "first value");
+ Optional<Job> secondPulledJob = createAddAndPullJob(uuid, positionInBulk, userId, "second value");
+
+ MockAsyncRequest firstValue = (MockAsyncRequest) firstPulledJob.get().getSharedData().getRequest();
+ MockAsyncRequest secondValue = (MockAsyncRequest) secondPulledJob.get().getSharedData().getRequest();
+ assertThat(ImmutableList.of(firstValue.value, secondValue.value),
+ containsInAnyOrder("first value", "second value"));
+ }
+
+ private Optional<Job> createAddAndPullJob(UUID uuid, int positionInBulk, String userId, String s) {
+ JobDaoImpl job1 = createNewJob(positionInBulk, uuid, userId, CREATING, null,
+ LocalDateTime.now().minusSeconds(1), false);
+ job1.setSharedData(new JobSharedData(null, userId, new MockAsyncRequest(s), "testApi"));
+ broker.add(job1);
+ return broker.pull(CREATING, userId);
+ }
}