summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xepsdk-app-onap/pom.xml4
-rwxr-xr-xvid-app-common/pom.xml6
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java102
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java51
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSPropertySupplier.java47
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/exceptions/InvalidAAIResponseException.java25
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java70
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java10
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiService.java24
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java43
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java323
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java39
-rw-r--r--vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js4
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java198
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java86
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java40
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java24
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java43
18 files changed, 970 insertions, 169 deletions
diff --git a/epsdk-app-onap/pom.xml b/epsdk-app-onap/pom.xml
index 9b0136f0c..85731d1b9 100755
--- a/epsdk-app-onap/pom.xml
+++ b/epsdk-app-onap/pom.xml
@@ -319,6 +319,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>com.lowagie</groupId>
+ <artifactId>itext</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
diff --git a/vid-app-common/pom.xml b/vid-app-common/pom.xml
index 479510368..72f50ac47 100755
--- a/vid-app-common/pom.xml
+++ b/vid-app-common/pom.xml
@@ -341,6 +341,12 @@
<groupId>org.onap.portal.sdk</groupId>
<artifactId>epsdk-analytics</artifactId>
<version>${epsdk.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.lowagie</groupId>
+ <artifactId>itext</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.onap.portal.sdk</groupId>
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java
new file mode 100644
index 000000000..4f98bd37c
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java
@@ -0,0 +1,102 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2018 Nokia 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.aai;
+
+import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.ACCEPT;
+import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.CONTENT_TYPE;
+import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.FROM_APP_ID_HEADER;
+import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.REQUEST_ID;
+import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.TRANSACTION_ID_HEADER;
+
+import io.joshworks.restclient.http.HttpResponse;
+import io.vavr.collection.HashMap;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.Collections;
+import java.util.Map;
+import javax.ws.rs.core.MediaType;
+import lombok.val;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.vid.aai.model.AaiNodeQueryResponse;
+import org.onap.vid.aai.model.ResourceType;
+import org.onap.vid.aai.util.AAIProperties;
+import org.onap.vid.client.SyncRestClientInterface;
+import org.onap.vid.model.SubscriberList;
+
+public class AaiOverTLSClient implements AaiOverTLSClientInterface {
+
+ private final AaiOverTLSPropertySupplier propertySupplier;
+ private SyncRestClientInterface syncRestClient;
+ private boolean useClientCert;
+ private static String CALLER_APP_ID = "VidAaiController";
+ private String urlBase;
+
+ public AaiOverTLSClient(SyncRestClientInterface syncRestClient, AaiOverTLSPropertySupplier propertySupplier) {
+ this(syncRestClient, propertySupplier, SystemProperties.getProperty(AAIProperties.AAI_SERVER_URL));
+ }
+
+ AaiOverTLSClient(SyncRestClientInterface syncRestClient, AaiOverTLSPropertySupplier propertySupplier, String baseUrl) {
+ this.syncRestClient = syncRestClient;
+ this.propertySupplier = propertySupplier;
+ this.urlBase = baseUrl;
+ }
+
+ @Override
+ public void setUseClientCert(boolean useClientCert) {
+ this.useClientCert = useClientCert;
+ }
+
+ @Override
+ public HttpResponse<AaiNodeQueryResponse> searchNodeTypeByName(String name, ResourceType type) {
+ val uri = urlBase + String.format(URIS.NODE_TYPE_BY_NAME, type.getAaiFormat(), type.getNameFilter(), name);
+ return syncRestClient.get(uri, getRequestHeaders(), Collections.emptyMap(), AaiNodeQueryResponse.class);
+ }
+
+ @Override
+ public HttpResponse<SubscriberList> getAllSubscribers() {
+ val uri = urlBase + String.format(URIS.SUBSCRIBERS, 0);
+ return syncRestClient.get(uri, getRequestHeaders(), Collections.emptyMap(), SubscriberList.class);
+ }
+
+ private Map<String, String> getRequestHeaders() {
+ val result = HashMap.of(
+ TRANSACTION_ID_HEADER, propertySupplier.getRandomUUID(),
+ FROM_APP_ID_HEADER, CALLER_APP_ID,
+ CONTENT_TYPE, MediaType.APPLICATION_JSON,
+ REQUEST_ID, propertySupplier.getRequestId(),
+ ACCEPT, MediaType.APPLICATION_JSON)
+ .toJavaMap();
+ result.putAll(getAuthorizationHeader());
+ return result;
+ }
+
+ private Map<String, String> getAuthorizationHeader() {
+ if (!useClientCert) {
+ val vidUsername = propertySupplier.getUsername();
+ val vidPassword = propertySupplier.getPassword();
+ val encoded = Base64.getEncoder()
+ .encodeToString((vidUsername + ":" + vidPassword).getBytes(StandardCharsets.UTF_8));
+ return HashMap.of("Authorization", "Basic " + encoded).toJavaMap();
+ }
+ return HashMap.<String, String>empty().toJavaMap();
+ }
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java
new file mode 100644
index 000000000..ad43746ca
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2018 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;
+
+import io.joshworks.restclient.http.HttpResponse;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.vid.aai.model.AaiNodeQueryResponse;
+import org.onap.vid.aai.model.ResourceType;
+import org.onap.vid.model.SubscriberList;
+
+public interface AaiOverTLSClientInterface {
+
+ class URIS {
+
+ static final String SUBSCRIBERS = "business/customers?subscriber-type=INFRA&depth=%s";
+ static final String NODE_TYPE_BY_NAME = "search/nodes-query?search-node-type=%s&filter=%s:EQUALS:%s";
+ }
+
+ class HEADERS {
+ static final String TRANSACTION_ID_HEADER = "X-TransactionId";
+ static final String FROM_APP_ID_HEADER = "X-FromAppId";
+ static final String CONTENT_TYPE = "Content-Type";
+ static final String REQUEST_ID = SystemProperties.ECOMP_REQUEST_ID;
+ static final String ACCEPT = "Accept";
+ }
+
+ void setUseClientCert(boolean useClientCert);
+
+ HttpResponse<AaiNodeQueryResponse> searchNodeTypeByName(String name, ResourceType type);
+
+ HttpResponse<SubscriberList> getAllSubscribers();
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSPropertySupplier.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSPropertySupplier.java
new file mode 100644
index 000000000..33b44b159
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSPropertySupplier.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2018 Nokia 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.aai;
+
+import java.util.UUID;
+import org.eclipse.jetty.util.security.Password;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.vid.aai.util.AAIProperties;
+import org.onap.vid.utils.Logging;
+
+public class AaiOverTLSPropertySupplier {
+
+ public String getUsername() {
+ return SystemProperties.getProperty(AAIProperties.AAI_VID_USERNAME);
+ }
+
+ public String getPassword() {
+ return Password.deobfuscate(SystemProperties.getProperty(AAIProperties.AAI_VID_PASSWD_X));
+ }
+
+ public String getRequestId() {
+ return Logging.extractOrGenerateRequestId();
+ }
+
+ public String getRandomUUID(){
+ return UUID.randomUUID().toString();
+ }
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/exceptions/InvalidAAIResponseException.java b/vid-app-common/src/main/java/org/onap/vid/aai/exceptions/InvalidAAIResponseException.java
index f80cae504..0e403697b 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/exceptions/InvalidAAIResponseException.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/exceptions/InvalidAAIResponseException.java
@@ -1,3 +1,24 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 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.exceptions;
import org.onap.vid.aai.AaiResponse;
@@ -10,4 +31,8 @@ public class InvalidAAIResponseException extends GenericUncheckedException {
public InvalidAAIResponseException(AaiResponse aaiResponse) {
super(String.format("errorCode: %d, raw: %s", aaiResponse.getHttpCode(), aaiResponse.getErrorMessage()));
}
+
+ public InvalidAAIResponseException(int statusCode, String message) {
+ super(String.format("errorCode: %d, raw: %s", statusCode, message));
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java b/vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java
index 0f4b536a1..56dce9ac7 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java
@@ -21,9 +21,14 @@
package org.onap.vid.controllers;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import io.joshworks.restclient.http.mapper.ObjectMapper;
+import java.io.IOException;
import org.onap.vid.aai.AaiClient;
import org.onap.vid.aai.AaiClientInterface;
+import org.onap.vid.aai.AaiOverTLSClient;
+import org.onap.vid.aai.AaiOverTLSClientInterface;
+import org.onap.vid.aai.AaiOverTLSPropertySupplier;
import org.onap.vid.aai.AaiResponseTranslator;
import org.onap.vid.aai.PombaClientImpl;
import org.onap.vid.aai.PombaClientInterface;
@@ -48,7 +53,6 @@ import org.onap.vid.services.VidService;
import org.onap.vid.services.VidServiceImpl;
import org.onap.vid.scheduler.SchedulerRestInterface;
import org.onap.vid.scheduler.SchedulerRestInterfaceIfc;
-import org.onap.vid.services.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -66,8 +70,8 @@ public class WebConfig {
* @return the object mapper
*/
@Bean
- public ObjectMapper getObjectMapper() {
- return new ObjectMapper();
+ public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
+ return new com.fasterxml.jackson.databind.ObjectMapper();
}
@@ -161,4 +165,62 @@ public class WebConfig {
public SchedulerRestInterfaceIfc getSchedulerRestInterface(){
return new SchedulerRestInterface();
}
+
+ @Bean(name = "aaiClientForFasterXmlMapping")
+ public AaiOverTLSClientInterface getAaiClientForFasterXmlMapping(){
+ ObjectMapper objectMapper = new ObjectMapper() {
+
+ com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
+
+ @Override
+ public <T> T readValue(String s, Class<T> aClass) {
+ try {
+ return om.readValue(s, aClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public String writeValue(Object o) {
+ try {
+ return om.writeValueAsString(o);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+
+ return new AaiOverTLSClient(new SyncRestClient(objectMapper), new AaiOverTLSPropertySupplier());
+ }
+
+
+ @Bean(name = "aaiClientForCodehausMapping")
+ public AaiOverTLSClientInterface getAaiClientForCodehausMapping() {
+
+ ObjectMapper objectMapper = new ObjectMapper() {
+
+ org.codehaus.jackson.map.ObjectMapper om = new org.codehaus.jackson.map.ObjectMapper();
+
+ @Override
+ public <T> T readValue(String s, Class<T> aClass) {
+ try {
+ return om.readValue(s, aClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public String writeValue(Object o) {
+ try {
+ return om.writeValueAsString(o);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+
+ return new AaiOverTLSClient(new SyncRestClient(objectMapper), new AaiOverTLSPropertySupplier());
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java
index 5c1ee9e89..b83f751fe 100644
--- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java
@@ -2,7 +2,8 @@
* ============LICENSE_START=======================================================
* VID
* ================================================================================
- * Modifications Copyright 2018 Nokia
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 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.
@@ -22,6 +23,7 @@ package org.onap.vid.roles;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import io.joshworks.restclient.http.HttpResponse;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.web.support.UserUtils;
import org.onap.vid.aai.AaiResponse;
@@ -58,8 +60,8 @@ public class RoleProvider {
public void init() {
LOG.debug(EELFLoggerDelegate.debugLogger, "Role provider => init method started");
- AaiResponse<SubscriberList> subscribersResponse = aaiService.getFullSubscriberList();
- subscribers = subscribersResponse.getT();
+ HttpResponse<SubscriberList> subscribersResponse = aaiService.getFullSubscriberList();
+ subscribers = subscribersResponse.getBody();
LOG.debug(EELFLoggerDelegate.debugLogger, "Role provider => init method finished");
}
@@ -69,7 +71,7 @@ public class RoleProvider {
LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + "Entering to get user role for user " + UserUtils.getUserId(request));
List<Role> roleList = new ArrayList<>();
-
+
Map roles = UserUtils.getRoles(request);
for (Object role : roles.keySet()) {
org.onap.portalsdk.core.domain.Role sdkRol = (org.onap.portalsdk.core.domain.Role) roles.get(role);
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java
index f3e0bfdab..d2ee32cbc 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java
@@ -1,5 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 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.services;
+import io.joshworks.restclient.http.HttpResponse;
import org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.AaiResponseTranslator;
import org.onap.vid.aai.SubscriberFilteredResults;
@@ -28,7 +50,7 @@ public interface AaiService {
AaiResponse getServiceInstanceSearchResults(String subscriberId, String instanceIdentifier, RoleValidator roleProvider, List<String> owningEntities, List<String> projects);
- AaiResponse<SubscriberList> getFullSubscriberList();
+ HttpResponse<SubscriberList> getFullSubscriberList();
AaiResponse getServices(RoleValidator roleValidator);
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 4de2cc740..c5bee2448 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
@@ -1,5 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 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.services;
+import io.joshworks.restclient.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.codehaus.jackson.JsonNode;
import org.onap.vid.aai.*;
@@ -30,6 +52,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
+import org.springframework.beans.factory.annotation.Qualifier;
/**
* Created by Oren on 7/4/17.
@@ -45,6 +68,10 @@ public class AaiServiceImpl implements AaiService {
private AaiClientInterface aaiClient;
@Autowired
+ @Qualifier("aaiClientForCodehausMapping")
+ private AaiOverTLSClientInterface aaiOverTLSClient;
+
+ @Autowired
private AaiResponseTranslator aaiResponseTranslator;
private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AaiServiceImpl.class);
@@ -162,11 +189,13 @@ public class AaiServiceImpl implements AaiService {
@Override
public SubscriberFilteredResults getFullSubscriberList(RoleValidator roleValidator) {
- AaiResponse<SubscriberList> subscriberResponse = aaiClient.getAllSubscribers();
-
- return new SubscriberFilteredResults(roleValidator, subscriberResponse.getT(),
- subscriberResponse.getErrorMessage(),
- subscriberResponse.getHttpCode());
+ HttpResponse<SubscriberList> allSubscribers = aaiOverTLSClient.getAllSubscribers();
+ return new SubscriberFilteredResults(
+ roleValidator,
+ allSubscribers.getBody(),
+ allSubscribers.getStatusText(),
+ allSubscribers.getStatus()
+ );
}
@Override
@@ -175,8 +204,8 @@ public class AaiServiceImpl implements AaiService {
}
@Override
- public AaiResponse<SubscriberList> getFullSubscriberList() {
- return aaiClient.getAllSubscribers();
+ public HttpResponse<SubscriberList> getFullSubscriberList() {
+ return aaiOverTLSClient.getAllSubscribers();
}
@Override
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
index 7259301a8..df8e92d66 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
@@ -1,10 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 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.services;
import com.google.common.collect.ImmutableMap;
+import io.joshworks.restclient.http.HttpResponse;
+import java.io.IOException;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.SessionFactory;
import org.onap.vid.aai.AaiClientInterface;
+import org.onap.vid.aai.AaiOverTLSClientInterface;
import org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.exceptions.InvalidAAIResponseException;
import org.onap.vid.aai.model.AaiNodeQueryResponse;
@@ -35,6 +60,7 @@ import org.onap.vid.utils.DaoUtils;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.service.DataAccessService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
@@ -50,7 +76,7 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
private static final int MAX_RETRIES_GETTING_COUNTER = 100;
private static final int MAX_RETRIES_GETTING_FREE_NAME_FROM_AAI = 10000;
- public static final String NAME_FOR_CHECK_AAI_STATUS = "NAME_FOR_CHECK_AAI_STATUS";
+ private static final String NAME_FOR_CHECK_AAI_STATUS = "NAME_FOR_CHECK_AAI_STATUS";
private final DataAccessService dataAccessService;
@@ -60,60 +86,62 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
private SessionFactory sessionFactory;
- private AaiClientInterface aaiClient;
+ private AaiOverTLSClientInterface aaiOverTLSClient;
private int maxRetriesGettingFreeNameFromAai = MAX_RETRIES_GETTING_FREE_NAME_FROM_AAI;
- private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AsyncInstantiationBusinessLogicImpl.class);
+ private static final EELFLoggerDelegate logger = EELFLoggerDelegate
+ .getLogger(AsyncInstantiationBusinessLogicImpl.class);
private Map<String, JobStatus> msoStateToJobStatusMap = ImmutableMap.<String, JobStatus>builder()
- .put("inprogress", JobStatus.IN_PROGRESS)
- .put("failed", JobStatus.FAILED)
- .put("pause", JobStatus.PAUSE)
- .put("paused", JobStatus.PAUSE)
- .put("complete", JobStatus.COMPLETED)
- .put("pending", JobStatus.IN_PROGRESS)
- .put("pendingmanualtask", JobStatus.PAUSE)
- .put("unlocked", JobStatus.IN_PROGRESS)
- .build();
+ .put("inprogress", JobStatus.IN_PROGRESS)
+ .put("failed", JobStatus.FAILED)
+ .put("pause", JobStatus.PAUSE)
+ .put("paused", JobStatus.PAUSE)
+ .put("complete", JobStatus.COMPLETED)
+ .put("pending", JobStatus.IN_PROGRESS)
+ .put("pendingmanualtask", JobStatus.PAUSE)
+ .put("unlocked", JobStatus.IN_PROGRESS)
+ .build();
@Autowired
public AsyncInstantiationBusinessLogicImpl(DataAccessService dataAccessService,
- JobAdapter jobAdapter,
- JobsBrokerService jobService,
- SessionFactory sessionFactory,
- AaiClientInterface aaiClient) {
+ JobAdapter jobAdapter,
+ JobsBrokerService jobService,
+ SessionFactory sessionFactory,
+ @Qualifier("aaiClientForFasterXmlMapping") AaiOverTLSClientInterface aaiOverTLSClient) {
this.dataAccessService = dataAccessService;
this.jobAdapter = jobAdapter;
this.jobService = jobService;
this.sessionFactory = sessionFactory;
- this.aaiClient = aaiClient;
+ this.aaiOverTLSClient = aaiOverTLSClient;
}
@Override
public List<ServiceInfo> getAllServicesInfo() {
- return dataAccessService.getList(ServiceInfo.class, filterByCreationDateAndNotDeleted(), orderByCreatedDateAndStatus(), null);
+ return dataAccessService
+ .getList(ServiceInfo.class, filterByCreationDateAndNotDeleted(), orderByCreatedDateAndStatus(), null);
}
private String filterByCreationDateAndNotDeleted() {
LocalDateTime minus3Months = LocalDateTime.now().minusMonths(3);
Timestamp filterDate = Timestamp.valueOf(minus3Months);
return " where" +
- " hidden = false" +
- " and deleted_at is null" + // don't fetch deleted
- " and created >= '" + filterDate + "' ";
+ " hidden = false" +
+ " and deleted_at is null" + // don't fetch deleted
+ " and created >= '" + filterDate + "' ";
}
private String orderByCreatedDateAndStatus() {
return " createdBulkDate DESC ,\n" +
- " (CASE jobStatus\n" +
- " WHEN 'COMPLETED' THEN 0\n" +
- " WHEN 'FAILED' THEN 0\n" +
- " WHEN 'IN_PROGRESS' THEN 1\n" +
- " WHEN 'PAUSE' THEN 2\n" +
- " WHEN 'PENDING' THEN 3\n" +
- " WHEN 'STOPPED' THEN 3 END),\n" +
- " statusModifiedDate ";
+ " (CASE jobStatus\n" +
+ " WHEN 'COMPLETED' THEN 0\n" +
+ " WHEN 'FAILED' THEN 0\n" +
+ " WHEN 'IN_PROGRESS' THEN 1\n" +
+ " WHEN 'PAUSE' THEN 2\n" +
+ " WHEN 'PENDING' THEN 3\n" +
+ " WHEN 'STOPPED' THEN 3 END),\n" +
+ " statusModifiedDate ";
}
@Override
@@ -125,77 +153,87 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
for (int i = 0; i < bulkSize; i++) {
Job job = jobAdapter.createJob(JobType.ServiceInstantiation, request, templateId, userId, i);
UUID jobId = jobService.add(job);
- auditVidStatus(jobId,job.getStatus());
+ auditVidStatus(jobId, job.getStatus());
uuids.add(jobId);
- dataAccessService.saveDomainObject(createServiceInfo(userId, request, jobId, templateId, createdBulkDate), DaoUtils.getPropsMap());
+ dataAccessService.saveDomainObject(createServiceInfo(userId, request, jobId, templateId, createdBulkDate),
+ DaoUtils.getPropsMap());
}
return uuids;
}
- private ServiceInfo createServiceInfo(String userId, ServiceInstantiation serviceInstantiation, UUID jobId, UUID templateId, Date createdBulkDate) {
+ private ServiceInfo createServiceInfo(String userId, ServiceInstantiation serviceInstantiation, UUID jobId,
+ UUID templateId, Date createdBulkDate) {
return new ServiceInfo(
- userId, Job.JobStatus.PENDING, serviceInstantiation.isPause(), jobId, templateId,
- serviceInstantiation.getOwningEntityId(),
- serviceInstantiation.getOwningEntityName(),
- serviceInstantiation.getProjectName(),
- serviceInstantiation.getAicZoneId(),
- serviceInstantiation.getAicZoneName(),
- serviceInstantiation.getTenantId(),
- serviceInstantiation.getTenantName(),
- serviceInstantiation.getLcpCloudRegionId(),
- null,
- serviceInstantiation.getSubscriptionServiceType(),
- serviceInstantiation.getSubscriberName(),
- null,
- serviceInstantiation.getInstanceName(),
- serviceInstantiation.getModelInfo().getModelInvariantId(),
- serviceInstantiation.getModelInfo().getModelName(),
- serviceInstantiation.getModelInfo().getModelVersion(),
- createdBulkDate
+ userId, Job.JobStatus.PENDING, serviceInstantiation.isPause(), jobId, templateId,
+ serviceInstantiation.getOwningEntityId(),
+ serviceInstantiation.getOwningEntityName(),
+ serviceInstantiation.getProjectName(),
+ serviceInstantiation.getAicZoneId(),
+ serviceInstantiation.getAicZoneName(),
+ serviceInstantiation.getTenantId(),
+ serviceInstantiation.getTenantName(),
+ serviceInstantiation.getLcpCloudRegionId(),
+ null,
+ serviceInstantiation.getSubscriptionServiceType(),
+ serviceInstantiation.getSubscriberName(),
+ null,
+ serviceInstantiation.getInstanceName(),
+ serviceInstantiation.getModelInfo().getModelInvariantId(),
+ serviceInstantiation.getModelInfo().getModelName(),
+ serviceInstantiation.getModelInfo().getModelVersion(),
+ createdBulkDate
);
}
@Override
- public RequestDetailsWrapper<ServiceInstantiationRequestDetails> generateServiceInstantiationRequest(UUID jobId, ServiceInstantiation payload, String userId) {
+ public RequestDetailsWrapper<ServiceInstantiationRequestDetails> generateServiceInstantiationRequest(UUID jobId,
+ ServiceInstantiation payload, String userId) {
- ServiceInstantiationRequestDetails.ServiceInstantiationOwningEntity owningEntity = new ServiceInstantiationRequestDetails.ServiceInstantiationOwningEntity(payload.getOwningEntityId(), payload.getOwningEntityName());
+ ServiceInstantiationRequestDetails.ServiceInstantiationOwningEntity owningEntity = new ServiceInstantiationRequestDetails.ServiceInstantiationOwningEntity(
+ payload.getOwningEntityId(), payload.getOwningEntityName());
SubscriberInfo subscriberInfo = new SubscriberInfo();
subscriberInfo.setGlobalSubscriberId(payload.getGlobalSubscriberId());
String serviceInstanceName = null;
- if(payload.isUserProvidedNaming()) {
+ if (payload.isUserProvidedNaming()) {
serviceInstanceName = getUniqueName(payload.getInstanceName(), ResourceType.SERVICE_INSTANCE);
String finalServiceInstanceName = serviceInstanceName;
updateServiceInfo(jobId, x -> x.setServiceInstanceName(finalServiceInstanceName));
}
ServiceInstantiationRequestDetails.RequestInfo requestInfo = new ServiceInstantiationRequestDetails.RequestInfo(
- serviceInstanceName,
- payload.getProductFamilyId(),
- "VID",
- payload.isRollbackOnFailure(),
- userId);
+ serviceInstanceName,
+ payload.getProductFamilyId(),
+ "VID",
+ payload.isRollbackOnFailure(),
+ userId);
List<ServiceInstantiationRequestDetails.ServiceInstantiationService> serviceInstantiationService = new LinkedList<>();
- List<Map<String, String>> unFilteredInstanceParams = payload.getInstanceParams() != null ? payload.getInstanceParams() : new LinkedList<>();
+ List<Map<String, String>> unFilteredInstanceParams =
+ payload.getInstanceParams() != null ? payload.getInstanceParams() : new LinkedList<>();
List<Map<String, String>> filteredInstanceParams = removeUnNeededParams(unFilteredInstanceParams);
ServiceInstantiationRequestDetails.ServiceInstantiationService serviceInstantiationService1 = new ServiceInstantiationRequestDetails.ServiceInstantiationService(
- payload.getModelInfo(),
- serviceInstanceName,
- filteredInstanceParams,
- createServiceInstantiationVnfList(payload)
+ payload.getModelInfo(),
+ serviceInstanceName,
+ filteredInstanceParams,
+ createServiceInstantiationVnfList(payload)
);
serviceInstantiationService.add(serviceInstantiationService1);
- ServiceInstantiationRequestDetails.RequestParameters requestParameters = new ServiceInstantiationRequestDetails.RequestParameters(payload.getSubscriptionServiceType(), false, serviceInstantiationService);
+ ServiceInstantiationRequestDetails.RequestParameters requestParameters = new ServiceInstantiationRequestDetails.RequestParameters(
+ payload.getSubscriptionServiceType(), false, serviceInstantiationService);
- ServiceInstantiationRequestDetails.Project project = payload.getProjectName() != null ? new ServiceInstantiationRequestDetails.Project(payload.getProjectName()) : null;
+ ServiceInstantiationRequestDetails.Project project =
+ payload.getProjectName() != null ? new ServiceInstantiationRequestDetails.Project(payload.getProjectName())
+ : null;
- ServiceInstantiationRequestDetails requestDetails = new ServiceInstantiationRequestDetails(payload.getModelInfo(), owningEntity, subscriberInfo,
- project, requestInfo, requestParameters);
+ ServiceInstantiationRequestDetails requestDetails = new ServiceInstantiationRequestDetails(
+ payload.getModelInfo(), owningEntity, subscriberInfo,
+ project, requestInfo, requestParameters);
- RequestDetailsWrapper<ServiceInstantiationRequestDetails> requestDetailsWrapper = new RequestDetailsWrapper(requestDetails);
+ RequestDetailsWrapper<ServiceInstantiationRequestDetails> requestDetailsWrapper = new RequestDetailsWrapper(
+ requestDetails);
debugRequestDetails(requestDetailsWrapper, logger);
return requestDetailsWrapper;
}
@@ -204,10 +242,11 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
List<String> keysToRemove = new ArrayList<>();
if (instanceParams != null && !instanceParams.isEmpty()) {
for (String key : instanceParams.get(0).keySet()) {
- for (String paramToIgnore : PARAMS_TO_IGNORE)
+ for (String paramToIgnore : PARAMS_TO_IGNORE) {
if ((key.equalsIgnoreCase(paramToIgnore))) {
keysToRemove.add(key);
}
+ }
}
for (String key : keysToRemove) {
instanceParams.get(0).remove(key);
@@ -220,7 +259,8 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
return instanceParams;
}
- private ServiceInstantiationRequestDetails.ServiceInstantiationVnfList createServiceInstantiationVnfList(ServiceInstantiation payload) {
+ private ServiceInstantiationRequestDetails.ServiceInstantiationVnfList createServiceInstantiationVnfList(
+ ServiceInstantiation payload) {
CloudConfiguration cloudConfiguration = new CloudConfiguration();
cloudConfiguration.setTenantId(payload.getTenantId());
cloudConfiguration.setLcpCloudRegionId(payload.getLcpCloudRegionId());
@@ -230,16 +270,17 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
for (Vnf vnf : vnfs.values()) {
Map<String, Map<String, VfModule>> vfModules = vnf.getVfModules();
List<VfModule> convertedUnFilteredVfModules = convertVfModuleMapToList(vfModules);
- List<VfModule> filteredVfModules = filterInstanceParamsFromVfModuleAndUniqueNames(convertedUnFilteredVfModules, vnf.isUserProvidedNaming());
+ List<VfModule> filteredVfModules = filterInstanceParamsFromVfModuleAndUniqueNames(
+ convertedUnFilteredVfModules, vnf.isUserProvidedNaming());
ServiceInstantiationRequestDetails.ServiceInstantiationVnf serviceInstantiationVnf = new ServiceInstantiationRequestDetails.ServiceInstantiationVnf(
- vnf.getModelInfo(),
- cloudConfiguration,
- vnf.getPlatformName(),
- vnf.getLineOfBusiness(),
- payload.getProductFamilyId(),
- removeUnNeededParams(vnf.getInstanceParams()),
- filteredVfModules,
- vnf.isUserProvidedNaming() ? getUniqueName(vnf.getInstanceName(), ResourceType.GENERIC_VNF) : null
+ vnf.getModelInfo(),
+ cloudConfiguration,
+ vnf.getPlatformName(),
+ vnf.getLineOfBusiness(),
+ payload.getProductFamilyId(),
+ removeUnNeededParams(vnf.getInstanceParams()),
+ filteredVfModules,
+ vnf.isUserProvidedNaming() ? getUniqueName(vnf.getInstanceName(), ResourceType.GENERIC_VNF) : null
);
vnfList.add(serviceInstantiationVnf);
}
@@ -251,27 +292,29 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
return vfModules.values().stream().flatMap(vfModule -> vfModule.values().stream()).collect(Collectors.toList());
}
- private List<VfModule> filterInstanceParamsFromVfModuleAndUniqueNames(List<VfModule> unFilteredVfModules, boolean isUserProvidedNaming) {
+ private List<VfModule> filterInstanceParamsFromVfModuleAndUniqueNames(List<VfModule> unFilteredVfModules,
+ boolean isUserProvidedNaming) {
return unFilteredVfModules.stream().map(vfModule ->
- new VfModule(
- vfModule.getModelInfo(),
- getUniqueNameIfNeeded(isUserProvidedNaming, vfModule.getInstanceName(), ResourceType.VF_MODULE),
- getUniqueNameIfNeeded(isUserProvidedNaming, vfModule.getVolumeGroupInstanceName(), ResourceType.VOLUME_GROUP),
- removeUnNeededParams(vfModule.getInstanceParams())))
- .collect(Collectors.toList());
+ new VfModule(
+ vfModule.getModelInfo(),
+ getUniqueNameIfNeeded(isUserProvidedNaming, vfModule.getInstanceName(), ResourceType.VF_MODULE),
+ getUniqueNameIfNeeded(isUserProvidedNaming, vfModule.getVolumeGroupInstanceName(),
+ ResourceType.VOLUME_GROUP),
+ removeUnNeededParams(vfModule.getInstanceParams())))
+ .collect(Collectors.toList());
}
private String getUniqueNameIfNeeded(boolean isUserProvidedNaming, String name, ResourceType resourceType) {
return isUserProvidedNaming && !StringUtils.isEmpty(name) ?
- getUniqueName(name, resourceType) : null;
+ getUniqueName(name, resourceType) : null;
}
@Override
public String getServiceInstantiationPath(ServiceInstantiation serviceInstantiationRequest) {
//in case pause flag is true - use assign , else - use create.
return MsoBusinessLogicImpl.validateEndpointPath(
- serviceInstantiationRequest.isPause() ?
- "mso.restapi.serviceInstanceAssign" : "mso.restapi.serviceInstanceCreate"
+ serviceInstantiationRequest.isPause() ?
+ "mso.restapi.serviceInstanceAssign" : "mso.restapi.serviceInstanceCreate"
);
}
@@ -290,7 +333,7 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
@Override
public ServiceInfo updateServiceInfoAndAuditStatus(UUID jobUuid, JobStatus jobStatus) {
- auditVidStatus(jobUuid,jobStatus);
+ auditVidStatus(jobUuid, jobStatus);
return updateServiceInfo(jobUuid, x -> setServiceInfoStatus(x, jobStatus));
}
@@ -300,9 +343,12 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
}
public ServiceInfo getServiceInfoByJobId(UUID jobUUID) {
- List<ServiceInfo> serviceInfoList = dataAccessService.getList(ServiceInfo.class, String.format(" where jobId = '%s' ", jobUUID), null, null);
+ List<ServiceInfo> serviceInfoList = dataAccessService
+ .getList(ServiceInfo.class, String.format(" where jobId = '%s' ", jobUUID), null, null);
if (serviceInfoList.size() != 1) {
- throw new GenericUncheckedException("Failed to retrieve job with uuid " + jobUUID + " from ServiceInfo table. Instances found: " + serviceInfoList.size());
+ throw new GenericUncheckedException(
+ "Failed to retrieve job with uuid " + jobUUID + " from ServiceInfo table. Instances found: "
+ + serviceInfoList.size());
}
return serviceInfoList.get(0);
}
@@ -310,43 +356,46 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
public List<JobAuditStatus> getAuditStatuses(UUID jobUUID, JobAuditStatus.SourceStatus source) {
return dataAccessService.getList(
JobAuditStatus.class,
- String.format(" where SOURCE = '%s' and JOB_ID = '%s'",source, jobUUID),
+ String.format(" where SOURCE = '%s' and JOB_ID = '%s'", source, jobUUID),
" CREATED_DATE ", null);
}
- private JobAuditStatus getLatestAuditStatus(UUID jobUUID, JobAuditStatus.SourceStatus source){
- List<JobAuditStatus> list = getAuditStatuses(jobUUID,source);
- return !list.isEmpty() ? list.get(list.size()-1) : null;
+ private JobAuditStatus getLatestAuditStatus(UUID jobUUID, JobAuditStatus.SourceStatus source) {
+ List<JobAuditStatus> list = getAuditStatuses(jobUUID, source);
+ return !list.isEmpty() ? list.get(list.size() - 1) : null;
}
@Override
- public void auditVidStatus(UUID jobUUID, JobStatus jobStatus){
+ public void auditVidStatus(UUID jobUUID, JobStatus jobStatus) {
JobAuditStatus vidStatus = new JobAuditStatus(jobUUID, jobStatus.toString(), JobAuditStatus.SourceStatus.VID);
auditStatus(vidStatus);
}
@Override
- public void auditMsoStatus(UUID jobUUID, AsyncRequestStatus.Request msoRequestStatus){
- auditMsoStatus(jobUUID, msoRequestStatus.requestStatus.getRequestState(), msoRequestStatus.requestId, msoRequestStatus.requestStatus.getStatusMessage());
+ public void auditMsoStatus(UUID jobUUID, AsyncRequestStatus.Request msoRequestStatus) {
+ auditMsoStatus(jobUUID, msoRequestStatus.requestStatus.getRequestState(), msoRequestStatus.requestId,
+ msoRequestStatus.requestStatus.getStatusMessage());
}
@Override
- public void auditMsoStatus(UUID jobUUID, String jobStatus, String requestId, String additionalInfo){
+ public void auditMsoStatus(UUID jobUUID, String jobStatus, String requestId, String additionalInfo) {
JobAuditStatus msoStatus = new JobAuditStatus(jobUUID, jobStatus, JobAuditStatus.SourceStatus.MSO,
- requestId != null ? UUID.fromString(requestId) : null,
- additionalInfo);
+ requestId != null ? UUID.fromString(requestId) : null,
+ additionalInfo);
auditStatus(msoStatus);
}
- private void auditStatus(JobAuditStatus jobAuditStatus){
- JobAuditStatus latestStatus = getLatestAuditStatus(jobAuditStatus.getJobId(),jobAuditStatus.getSource());
- if (latestStatus == null || !latestStatus.equals(jobAuditStatus))
+ private void auditStatus(JobAuditStatus jobAuditStatus) {
+ JobAuditStatus latestStatus = getLatestAuditStatus(jobAuditStatus.getJobId(), jobAuditStatus.getSource());
+ if (latestStatus == null || !latestStatus.equals(jobAuditStatus)) {
dataAccessService.saveDomainObject(jobAuditStatus, DaoUtils.getPropsMap());
+ }
}
public Job.JobStatus calcStatus(AsyncRequestStatus asyncRequestStatus) {
- String msoRequestState = asyncRequestStatus.request.requestStatus.getRequestState().toLowerCase().replaceAll("[^a-z]+", "");
+ String msoRequestState = asyncRequestStatus.request.requestStatus.getRequestState().toLowerCase()
+ .replaceAll("[^a-z]+", "");
JobStatus jobStatus = msoStateToJobStatusMap.get(msoRequestState);
return (jobStatus != null ? jobStatus : JobStatus.IN_PROGRESS);
}
@@ -355,11 +404,11 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
public void handleFailedInstantiation(UUID jobUUID) {
ServiceInfo serviceInfo = updateServiceInfoAndAuditStatus(jobUUID, JobStatus.FAILED);
List<ServiceInfo> serviceInfoList = dataAccessService.getList(
- ServiceInfo.class,
- String.format(" where templateId = '%s' and jobStatus = '%s'",
- serviceInfo.getTemplateId(),
- JobStatus.PENDING),
- null, null);
+ ServiceInfo.class,
+ String.format(" where templateId = '%s' and jobStatus = '%s'",
+ serviceInfo.getTemplateId(),
+ JobStatus.PENDING),
+ null, null);
serviceInfoList.forEach(si -> updateServiceInfoAndAuditStatus(si.getJobId(), JobStatus.STOPPED));
}
@@ -374,9 +423,9 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
public void hideServiceInfo(UUID jobUUID) {
ServiceInfo serviceInfo = getServiceInfoByJobId(jobUUID);
if (!serviceInfo.getJobStatus().isFinal()) {
- String message = String.format( "jobId %s: Service status does not allow hide service, status = %s",
- serviceInfo.getJobId(),
- serviceInfo.getJobStatus());
+ String message = String.format("jobId %s: Service status does not allow hide service, status = %s",
+ serviceInfo.getJobId(),
+ serviceInfo.getJobStatus());
logger.error(EELFLoggerDelegate.errorLogger, message);
throw new OperationNotAllowedException(message);
}
@@ -387,31 +436,29 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
@Override
public int
-
getCounterForName(String name) {
String hqlSelectNC = "from NameCounter where name = :name";
String hqlUpdateCounter = "update NameCounter set counter = :newCounter " +
- "where name= :name " +
- "and counter= :prevCounter";
+ "where name= :name " +
+ "and counter= :prevCounter";
Integer counter = null;
GenericUncheckedException lastException = null;
- for (int i = 0; i< MAX_RETRIES_GETTING_COUNTER && counter==null; i++) {
+ for (int i = 0; i < MAX_RETRIES_GETTING_COUNTER && counter == null; i++) {
try {
counter = calcCounter(name, hqlSelectNC, hqlUpdateCounter);
- }
- catch (GenericUncheckedException exception) {
+ } catch (GenericUncheckedException exception) {
lastException = exception; //do nothing, we will try again in the loop
}
}
- if (counter!=null) {
+ if (counter != null) {
return counter;
}
- throw lastException!=null ? new DbFailureUncheckedException(lastException) :
- new DbFailureUncheckedException("Failed to get counter for "+name+" due to unknown error");
+ throw lastException != null ? new DbFailureUncheckedException(lastException) :
+ new DbFailureUncheckedException("Failed to get counter for " + name + " due to unknown error");
}
@@ -419,14 +466,14 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
Integer counter;
counter = DaoUtils.tryWithSessionAndTransaction(sessionFactory, session -> {
NameCounter nameCounter = (NameCounter) session.createQuery(hqlSelectNC)
- .setText("name", name)
- .uniqueResult();
+ .setText("name", name)
+ .uniqueResult();
if (nameCounter != null) {
int updatedRows = session.createQuery(hqlUpdateCounter)
- .setText("name", nameCounter.getName())
- .setInteger("prevCounter", nameCounter.getCounter())
- .setInteger("newCounter", nameCounter.getCounter() + 1)
- .executeUpdate();
+ .setText("name", nameCounter.getName())
+ .setInteger("prevCounter", nameCounter.getCounter())
+ .setInteger("newCounter", nameCounter.getCounter() + 1)
+ .executeUpdate();
if (updatedRows == 1) {
return nameCounter.getCounter() + 1;
}
@@ -459,7 +506,7 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
//Prevents unnecessary increasing of the counter while AAI doesn't response
isNameFreeInAai(NAME_FOR_CHECK_AAI_STATUS, resourceType);
- for (int i=0; i<getMaxRetriesGettingFreeNameFromAai(); i++) {
+ for (int i = 0; i < getMaxRetriesGettingFreeNameFromAai(); i++) {
int counter = getCounterForName(name);
String newName = formatNameAndCounter(name, counter);
if (isNameFreeInAai(newName, resourceType)) {
@@ -467,7 +514,7 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
}
}
- throw new MaxRetriesException("find unused name for "+name, getMaxRetriesGettingFreeNameFromAai());
+ throw new MaxRetriesException("find unused name for " + name, getMaxRetriesGettingFreeNameFromAai());
}
//the method is protected so we can call it in the UT
@@ -476,11 +523,17 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
}
private boolean isNameFreeInAai(String name, ResourceType resourceType) throws InvalidAAIResponseException {
- AaiResponse<AaiNodeQueryResponse> aaiResponse = aaiClient.searchNodeTypeByName(name, resourceType);
- if (aaiResponse.getHttpCode() > 399 || aaiResponse.getT() == null) {
- throw new InvalidAAIResponseException(aaiResponse);
+ HttpResponse<AaiNodeQueryResponse> aaiResponse = aaiOverTLSClient
+ .searchNodeTypeByName(name, resourceType);
+ if (aaiResponse.getStatus() > 399 || aaiResponse.getBody() == null) {
+ try {
+ String message = IOUtils.toString(aaiResponse.getRawBody(), "UTF-8");
+ throw new InvalidAAIResponseException(aaiResponse.getStatus(), message);
+ } catch (IOException e) {
+ throw new InvalidAAIResponseException(aaiResponse.getStatus(), aaiResponse.getStatusText());
+ }
}
- return CollectionUtils.isEmpty(aaiResponse.getT().resultData);
+ return CollectionUtils.isEmpty(aaiResponse.getBody().resultData);
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java
index 635cb4855..500f5ac7f 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java
@@ -1,7 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 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.services;
+import io.joshworks.restclient.http.HttpResponse;
import jline.internal.Log;
import org.onap.vid.aai.AaiClientInterface;
+import org.onap.vid.aai.AaiOverTLSClientInterface;
import org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.ServiceSubscription;
import org.onap.vid.aai.Services;
@@ -9,6 +32,7 @@ import org.onap.vid.model.ModelConstants;
import org.onap.vid.model.Subscriber;
import org.onap.vid.model.SubscriberList;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@@ -17,9 +41,14 @@ import java.util.HashMap;
public class RoleGenaratorServiceImpl implements RoleGeneratorService {
public static final String ROLE_ID_COLUMN = "ROLE_ID";
+
@Autowired
AaiClientInterface client;
+ @Autowired
+ @Qualifier("aaiClientForCodehausMapping")
+ AaiOverTLSClientInterface aaiOverTLSClient;
+
public static final String DB_NAME = "vid_portal";
public static final String TBL_NAME = "fn_role";
public static final String TEMP_DELIMITER ="***";
@@ -30,11 +59,11 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService {
String query = "USE " + DB_NAME + ";\r\n" +
"SET SQL_SAFE_UPDATES = 0;\r\n";
try {
- AaiResponse<SubscriberList> subscribers = client.getAllSubscribers();
+ HttpResponse<SubscriberList> allSubscribers = aaiOverTLSClient.getAllSubscribers();
if (firstRun) {
- query += replaceRolesToTempDelimiter("subscriber",buildSubscribersValuesForMappingsTable(subscribers.getT()));
+ query += replaceRolesToTempDelimiter("subscriber",buildSubscribersValuesForMappingsTable(allSubscribers.getBody()));
}
- query += addAvailableRolesCombination(firstRun, subscribers);
+ query += addAvailableRolesCombination(firstRun, allSubscribers.getBody());
}
catch (Exception e) {
@@ -43,10 +72,10 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService {
return query;
}
- private String addAvailableRolesCombination(Boolean firstRun, AaiResponse<SubscriberList> subscribers) {
+ private String addAvailableRolesCombination(Boolean firstRun, SubscriberList subscribers) {
String query, availableRoles="";
HashMap<String,String> servicesNames = new HashMap<String,String>();
- for (Subscriber subscriber: subscribers.getT().customer) {
+ for (Subscriber subscriber: subscribers.customer) {
AaiResponse<Services> subscriberResponse = client.getSubscriberData(subscriber.globalCustomerId);
for(ServiceSubscription service: subscriberResponse.getT().serviceSubscriptions.serviceSubscription) {
servicesNames.put(service.serviceType,"");
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 6029ed2d7..c6c9edf6e 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
@@ -94,14 +94,14 @@
_.forEach(newVNFName.vfModules, function (mdl, key) {
mdl.scale = false; //defaults to not scale unless user changes it
- if(mdl.properties && mdl.properties.max_vf_module_instances) {
+ if(mdl.properties && mdl.properties.maxCountInstances) {
//how many vf modules of the same customizationId belong to that vnf instance
mdl.currentCount = _.filter(vm.vfModules, function(item){
return modulesAaiIds.indexOf(item.id) > -1 && item.properties["model-customization-id"] === mdl.customizationUuid;
}).length;
- mdl.scalable = mdl.properties.max_vf_module_instances.value - mdl.currentCount > 0;
+ mdl.scalable = mdl.properties.maxCountInstances - mdl.currentCount > 0;
}else{
mdl.scalable = false;
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java
new file mode 100644
index 000000000..7ae8ac832
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java
@@ -0,0 +1,198 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2018 Nokia 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.aai;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.xebialabs.restito.semantics.Action;
+import io.joshworks.restclient.http.HttpResponse;
+import io.joshworks.restclient.http.mapper.ObjectMapper;
+import java.io.IOException;
+import org.assertj.core.api.Assertions;
+import org.glassfish.grizzly.http.util.HttpStatus;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.vid.aai.model.AaiNodeQueryResponse;
+import org.onap.vid.aai.model.ResourceType;
+import org.onap.vid.client.SyncRestClient;
+import org.onap.vid.model.SubscriberList;
+import org.onap.vid.testUtils.StubServerUtil;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AaiOverTLSClientServerTest {
+
+ @Mock
+ private AaiOverTLSPropertySupplier propertySupplier;
+
+ private static StubServerUtil serverUtil;
+
+ private String searchNodesQueryResponsePayload =
+ "{\n"
+ + "\"result-data\": [\n"
+ + " {\n"
+ + "\"resource-type\": \"generic-vnf\",\n"
+ + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/6eac8e69-c98d-4ac5-ab90-69fe0cabda76\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"resource-type\": \"generic-vnf\",\n"
+ + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/e3766bc5-40a7-4dbe-9d4a-1d8c8f284913\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"resource-type\": \"generic-vnf\",\n"
+ + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/6aa153ee-6637-4b49-beb5-a5e756e00393\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"resource-type\": \"generic-vnf\",\n"
+ + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/5a981c30-de25-4ea9-98fa-ed398f13ea41\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"resource-type\": \"generic-vnf\",\n"
+ + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/b0ef2271-8ac0-4268-b9a5-09cb50c20c85\"\n"
+ + "}\n"
+ + "],\n"
+ + "}";
+
+ private String subscribersResponsePayload =
+ "{\n"
+ + "\"customer\": [\n"
+ + " {\n"
+ + "\"global-customer-id\": \"DemoCust_752df078-d8e9-4731-abf6-8ae7348075bb\",\n"
+ + "\"subscriber-name\": \"DemoCust_752df078-d8e9-4731-abf6-8ae7348075bb\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536158347585\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"global-customer-id\": \"DemoCust_62bf43a3-4888-4c82-ae98-3ebc3d782761\",\n"
+ + "\"subscriber-name\": \"DemoCust_62bf43a3-4888-4c82-ae98-3ebc3d782761\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536240894581\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"global-customer-id\": \"DemoCust_e84256d6-ef3e-4a28-9741-9987019c3a8f\",\n"
+ + "\"subscriber-name\": \"DemoCust_e84256d6-ef3e-4a28-9741-9987019c3a8f\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536330956393\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"global-customer-id\": \"ETE_Customer_377bb124-2638-4025-a315-cdae04f52bce\",\n"
+ + "\"subscriber-name\": \"ETE_Customer_377bb124-2638-4025-a315-cdae04f52bce\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536088625538\"\n"
+ + "}\n"
+ + "],\n"
+ + "}";
+
+ @BeforeClass
+ public static void setUpClass(){
+ serverUtil = new StubServerUtil();
+ serverUtil.runServer();
+ }
+
+ @AfterClass
+ public static void tearDown(){
+ serverUtil.stopServer();
+ }
+
+ @Test
+ public void shouldSearchNodeTypeByName() throws IOException, ParseException {
+ ObjectMapper objectMapper = getFasterXmlObjectMapper();
+ AaiOverTLSClient aaiOverTLSClient = new AaiOverTLSClient(new SyncRestClient(objectMapper), propertySupplier, serverUtil.constructTargetUrl("http", ""));
+
+ serverUtil.prepareGetCall("/search/nodes-query", new JSONParser().parse(searchNodesQueryResponsePayload), Action.status(HttpStatus.OK_200));
+
+ HttpResponse<AaiNodeQueryResponse> aaiNodeQueryResponseHttpResponse = aaiOverTLSClient
+ .searchNodeTypeByName("any", ResourceType.GENERIC_VNF);
+
+ AaiNodeQueryResponse body = aaiNodeQueryResponseHttpResponse.getBody();
+ Assertions.assertThat(body.resultData.size()).isEqualTo(5);
+ Assertions.assertThat(aaiNodeQueryResponseHttpResponse.getStatus()).isEqualTo(200);
+ }
+
+ @Test
+ public void shouldGetSubscribers() throws ParseException, JsonProcessingException {
+ ObjectMapper objectMapper = getCodehausObjectMapper();
+ AaiOverTLSClient aaiOverTLSClient = new AaiOverTLSClient(new SyncRestClient(objectMapper), propertySupplier, serverUtil.constructTargetUrl("http", ""));
+
+ serverUtil.prepareGetCall("/business/customers", new JSONParser().parse(subscribersResponsePayload), Action.status(HttpStatus.OK_200));
+
+ HttpResponse<SubscriberList> allSubscribers = aaiOverTLSClient.getAllSubscribers();
+
+ SubscriberList subscriberList = allSubscribers.getBody();
+ Assertions.assertThat(subscriberList.customer.size()).isEqualTo(4);
+ Assertions.assertThat(allSubscribers.getStatus()).isEqualTo(200);
+ }
+
+ private ObjectMapper getCodehausObjectMapper() {
+ return new ObjectMapper() {
+
+ org.codehaus.jackson.map.ObjectMapper om = new org.codehaus.jackson.map.ObjectMapper();
+
+ @Override
+ public <T> T readValue(String s, Class<T> aClass) {
+ try {
+ return om.readValue(s, aClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public String writeValue(Object o) {
+ try {
+ return om.writeValueAsString(o);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ }
+
+ private ObjectMapper getFasterXmlObjectMapper() {
+ return new ObjectMapper() {
+
+ com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
+
+ @Override
+ public <T> T readValue(String s, Class<T> aClass) {
+ try {
+ return om.readValue(s, aClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public String writeValue(Object o) {
+ try {
+ return om.writeValueAsString(o);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ }
+
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java
new file mode 100644
index 000000000..4e0e70e89
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2018 Nokia 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.aai;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.vid.aai.model.AaiNodeQueryResponse;
+import org.onap.vid.aai.model.ResourceType;
+import org.onap.vid.client.SyncRestClient;
+import org.onap.vid.model.SubscriberList;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AaiOverTLSClientTest {
+
+ private static final String SEARCH_NODES_QUERY_SEARCH_NODE_TYPE = "search/nodes-query?search-node-type=generic-vnf&filter=vnf-name:EQUALS:name";
+ private static final String SUBSCRIBERS = "business/customers?subscriber-type=INFRA&depth=0";
+ private AaiOverTLSClient aaiRestClient;
+
+ @Mock
+ private SyncRestClient syncRestClient;
+ @Mock
+ private AaiOverTLSPropertySupplier propertySupplier;
+
+ @Before
+ public void setUp() {
+ aaiRestClient = new AaiOverTLSClient(syncRestClient, propertySupplier);
+ }
+
+ @Test
+ public void testSearchNodeTypeByName() {
+ mockPropertyReader();
+
+ aaiRestClient.searchNodeTypeByName("name", ResourceType.GENERIC_VNF);
+ Mockito.verify(syncRestClient).get(Matchers.contains(SEARCH_NODES_QUERY_SEARCH_NODE_TYPE),
+ Matchers.eq(getHeaders()), Matchers.eq(Collections.emptyMap()), Matchers.eq(AaiNodeQueryResponse.class));
+ }
+
+ @Test
+ public void testGetAllSubscribers(){
+ mockPropertyReader();
+
+ aaiRestClient.getAllSubscribers();
+ Mockito.verify(syncRestClient).get(Matchers.contains(SUBSCRIBERS),
+ Matchers.eq(getHeaders()), Matchers.eq(Collections.emptyMap()), Matchers.eq(SubscriberList.class));
+ }
+
+ private void mockPropertyReader() {
+ Mockito.when(propertySupplier.getPassword()).thenReturn("Pass");
+ Mockito.when(propertySupplier.getUsername()).thenReturn("User");
+ Mockito.when(propertySupplier.getRequestId()).thenReturn("1");
+ Mockito.when(propertySupplier.getRandomUUID()).thenReturn("2");
+ }
+
+ private Map<String,String> getHeaders(){
+ return ImmutableMap.<String, String>builder().put("Authorization", "Basic VXNlcjpQYXNz").
+ put("X-FromAppId", "VidAaiController").put("Accept", "application/json").put("X-ECOMP-RequestID", "1").
+ put("X-TransactionId", "2").put("Content-Type", "application/json").build();
+ }
+
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java b/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
index 56ac28d2e..c1ac6a219 100644
--- a/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
+++ b/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
@@ -21,13 +21,19 @@
package org.onap.vid.config;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
import org.hibernate.SessionFactory;
import org.mockito.Mockito;
import org.onap.portalsdk.core.service.DataAccessService;
-import org.onap.vid.aai.AaiClientInterface;
+import org.onap.vid.aai.AaiOverTLSClient;
+import org.onap.vid.aai.AaiOverTLSClientInterface;
+import org.onap.vid.aai.AaiOverTLSPropertySupplier;
import org.onap.vid.aai.util.HttpsAuthClient;
import org.onap.vid.aai.util.SSLContextProvider;
import org.onap.vid.aai.util.SystemPropertyHelper;
+import org.onap.vid.client.SyncRestClient;
import org.onap.vid.job.JobAdapter;
import org.onap.vid.job.JobsBrokerService;
import org.onap.vid.job.command.InProgressStatusCommand;
@@ -84,12 +90,40 @@ public class JobCommandsConfigWithMockedMso {
}
@Bean
+ public AaiOverTLSClientInterface AaiOverTLSClient(){
+ io.joshworks.restclient.http.mapper.ObjectMapper objectMapper = new io.joshworks.restclient.http.mapper.ObjectMapper() {
+
+ ObjectMapper om = new ObjectMapper();
+
+ @Override
+ public <T> T readValue(String s, Class<T> aClass) {
+ try {
+ return om.readValue(s, aClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public String writeValue(Object o) {
+ try {
+ return om.writeValueAsString(o);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+
+ return new AaiOverTLSClient(new SyncRestClient(objectMapper), new AaiOverTLSPropertySupplier());
+ }
+
+ @Bean
public AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic(DataAccessService dataAccessService,
JobAdapter jobAdapter,
JobsBrokerService jobsBrokerService,
SessionFactory sessionFactory,
- AaiClientInterface aaiClient) {
- return new AsyncInstantiationBusinessLogicImpl(dataAccessService, jobAdapter, jobsBrokerService, sessionFactory, aaiClient);
+ AaiOverTLSClientInterface aaiOverTLSClientInterface) {
+ return new AsyncInstantiationBusinessLogicImpl(dataAccessService, jobAdapter, jobsBrokerService, sessionFactory, aaiOverTLSClientInterface);
}
@Bean
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 ae6c2ccca..70a454a75 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
@@ -1,5 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 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.services;
+import io.joshworks.restclient.http.HttpResponse;
import java.util.Collection;
import java.util.List;
@@ -55,7 +77,7 @@ public class AaiServiceImplTest {
@Test
public void testGetFullSubscriberList_1() throws Exception {
AaiServiceImpl testSubject;
- AaiResponse<SubscriberList> result;
+ HttpResponse<SubscriberList> result;
// default test
try {
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
index c3d01283d..7ad49a968 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
@@ -1,8 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 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.services;
import com.google.common.collect.ImmutableMap;
+import io.joshworks.restclient.http.HttpResponse;
+import java.io.UnsupportedEncodingException;
import jersey.repackaged.com.google.common.collect.ImmutableList;
-import org.onap.vid.aai.AaiClientInterface;
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.message.BasicStatusLine;
+import org.onap.vid.aai.AaiOverTLSClientInterface;
import org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.model.AaiNodeQueryResponse;
import org.onap.vid.aai.model.ResourceType;
@@ -13,8 +41,6 @@ import org.onap.vid.model.serviceInstantiation.VfModule;
import org.onap.vid.model.serviceInstantiation.Vnf;
import org.onap.vid.mso.RestObject;
import org.onap.vid.mso.rest.AsyncRequestStatus;
-import org.onap.vid.services.AsyncInstantiationBusinessLogic;
-import org.onap.vid.services.AsyncInstantiationBusinessLogicTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.togglz.core.manager.FeatureManager;
@@ -48,7 +74,7 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests
protected FeatureManager featureManager;
@Inject
- protected AaiClientInterface aaiClient;
+ protected AaiOverTLSClientInterface aaiClient;
public ServiceInstantiation generateMockServiceInstantiationPayload(boolean isPause, Map<String, Vnf> vnfs, int bulkSize, boolean isUserProvidedNaming, String projectName, boolean rollbackOnFailure) {
ModelInfo modelInfo = createModelInfo();
@@ -174,12 +200,15 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests
return restObject;
}
- protected void mockAaiClientAnyNameFree() {
+ protected void mockAaiClientAnyNameFree() throws UnsupportedEncodingException {
when(aaiClient.searchNodeTypeByName(any(), any())).thenReturn(aaiNodeQueryResponseNameFree());
}
- protected AaiResponse<AaiNodeQueryResponse> aaiNodeQueryResponseNameFree() {
- return new AaiResponse<>(new AaiNodeQueryResponse(null),"", 200);
+ protected HttpResponse<AaiNodeQueryResponse> aaiNodeQueryResponseNameFree() throws UnsupportedEncodingException {
+ org.apache.http.HttpResponse response = new DefaultHttpResponseFactory().newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null), null);
+ response.setEntity(new StringEntity(""));
+
+ return HttpResponse.fallback(new AaiNodeQueryResponse(null));
}
protected AaiResponse<AaiNodeQueryResponse> aaiNodeQueryBadResponse() {