diff options
33 files changed, 1210 insertions, 1687 deletions
@@ -1,7 +1,8 @@ -.idea/ -target/ -.settings/ -logs/* -.classpath -.project - +.idea/
+target/
+.settings/
+logs/*
+.classpath
+.project
+
+.checkstyle
diff --git a/config/application.properties b/config/application.properties index b9b8601..af0ffa0 100644 --- a/config/application.properties +++ b/config/application.properties @@ -36,8 +36,8 @@ serviceDecomposition.password=OBF:1u2a1toa1w8v1tok1u30 # Network Discovery Micro Service REST Client Configuration networkDiscoveryMicroService.host=10.147.112.148 -networkDiscoveryMicroService.port=8080 -networkDiscoveryMicroService.httpProtocol=http +networkDiscoveryMicroService.port=8443 +networkDiscoveryMicroService.httpProtocol=https networkDiscoveryMicroService.networkDiscoveryPath=/network-discovery/v1/network/resource # Wait for Network Discovery MicroService response in milliseconds networkDiscoveryMicroService.responseTimeOutInMilliseconds=60000 diff --git a/config/jolt/sdToModelContextSpec.json b/config/jolt/sdToModelContextSpec.json new file mode 100644 index 0000000..88201a7 --- /dev/null +++ b/config/jolt/sdToModelContextSpec.json @@ -0,0 +1,31 @@ +[ + // Use https://jolt-demo.appspot.com/#inception to develop/test + // any changes to this file + { + // This section converts the updated json from service-decompostion + // to org.onap.pomba.common.datatypes.ModelContext + "operation": "shift", + "spec": { + "service-instance-id": "service.uuid", + "generic-vnfs": { + "*": { + "vservers": { + "*": { + "vserver-id": "vnfList[&3].vfModuleList[0].vmList[&1].uuid" + } + }, + "l3-networks": { + "*": { + "network-id": "vnfList[&3].vfModuleList[0].networkList[&1].uuid" + } + }, + "vnfcs": { + "*": { + "vnfc-id": "vnfList[&3].vnfcList[&1].uuid" + } + } + } + } + } + } + ] diff --git a/config/jolt/sdToNdResourcesSpec.json b/config/jolt/sdToNdResourcesSpec.json new file mode 100644 index 0000000..c7d7496 --- /dev/null +++ b/config/jolt/sdToNdResourcesSpec.json @@ -0,0 +1,43 @@ +[
+ // Use https://jolt-demo.appspot.com/#inception to develop/test
+ // any changes to this file
+ {
+ // This section converts the updated json from service-decomposition
+ // to org.onap.pomba.contextbuilder.networkdiscovery.model.NdResources
+ "operation": "shift",
+ "spec": {
+ "generic-vnfs": {
+ "*": {
+ "vservers": {
+ "*": {
+ "vserver-id": {
+ "@": "tempResourceId",
+ "#vserver": "tempResourceType"
+
+ }
+ }},
+ "l3-networks": {
+ "*": {
+ "network-id": {
+ "@": "tempResourceId",
+ "#l3-network": "tempResourceType"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "operation": "shift",
+ "spec": {
+ "tempResourceType": {
+ "*": {
+ "@": "ndResources[&].resourceType",
+ "@(2,tempResourceId[&])": "ndResources[&].resourceId"
+ }
+ }
+ }
+ }
+
+]
diff --git a/config/networkdiscovery.spec b/config/networkdiscovery.spec deleted file mode 100644 index 8da7a87..0000000 --- a/config/networkdiscovery.spec +++ /dev/null @@ -1,67 +0,0 @@ -[ - // Use https://jolt-demo.appspot.com/#inception to develop/test - // any changes to this file - - { - // This sections adds nfNamingCode and dataQuality to the json - // fields returned from service-decomposition that we are - // interested in - "operation": "default", - "spec": { - "generic-vnfs[]": { - "*": { - "vf-modules": { - "vf-module[]": { - "*": {} - } - }, - "vservers[]": { - "*": { - "nfNamingCode": "vserver" - } - }, - "l3-networks[]": { - "*": { - "type": "l3-network" - } - }, - "vnfcList[]": { - "*": { - "type": "vnfc" - } - } - } - } - } - }, - { - // This section converts the updated json from service-decompostion - // to org.onap.pomba.common.datatypes.ModelContext - "operation": "shift", - "spec": { - "service-instance-id": "service.uuid", - "generic-vnfs": { - "*": { - "vservers": { - "*": { - "vserver-id": "vfList[&3].vfModuleList[0].vmList[&1].uuid", - "nfNamingCode": "vfList[&3].vfModuleList[0].vmList[&1].nfNamingCode" - } - }, - "l3-networks": { - "*": { - "network-id": "vfList[&3].vfModuleList[0].networkList[&1].uuid", - "type": "vfList[&3].vfModuleList[0].networkList[&1].type" - }, - "vnfcs": { - "*": { - "vnfc-id": "vfList[&2].vnfcList[&1].uuid", - "type": "vfList[&2].vfModuleList[0].type" - } - } - } - } - } - } - } - ] @@ -116,7 +116,7 @@ limitations under the License. <dependency> <groupId>org.onap.logging-analytics.pomba</groupId> <artifactId>pomba-audit-common</artifactId> - <version>1.3.1</version> + <version>1.4.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.google.guava</groupId> @@ -202,7 +202,7 @@ limitations under the License. <plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> - <version>0.19.1</version> + <version>0.28.0</version> <configuration> <verbose>true</verbose> <apiVersion>1.23</apiVersion> @@ -310,7 +310,7 @@ limitations under the License. <includes> <include>*.properties</include> <include>*.xml</include> - <include>*.spec</include> + <include>**/*.json</include> </includes> <filtering>false</filtering> </resource> diff --git a/src/main/docker/Dockerfile b/src/main/docker/Dockerfile index 9963da1..eb50570 100644 --- a/src/main/docker/Dockerfile +++ b/src/main/docker/Dockerfile @@ -5,6 +5,7 @@ ARG MICROSERVICE_HOME=/opt/app/ # Build up the deployment folder structure RUN mkdir -p $MICROSERVICE_HOME RUN mkdir -p $MICROSERVICE_HOME/config/ +RUN mkdir -p $MICROSERVICE_HOME/config/jolt/ RUN mkdir -p $MICROSERVICE_HOME/lib/ RUN mkdir -p $MICROSERVICE_HOME/bin/ @@ -16,4 +17,4 @@ RUN chmod 755 $MICROSERVICE_HOME/config/* RUN chmod 755 $MICROSERVICE_HOME/lib/* RUN chmod 755 $MICROSERVICE_HOME/bin/* -CMD ["/opt/app/bin/startService.sh"]
\ No newline at end of file +CMD ["/opt/app/bin/startService.sh"] diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/Application.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/Application.java index 9986266..397aabc 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/Application.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/Application.java @@ -15,6 +15,7 @@ * limitations under the License. * ============LICENSE_END===================================================== */ + package org.onap.pomba.contextbuilder.networkdiscovery; import org.springframework.boot.SpringApplication; @@ -38,7 +39,7 @@ public class Application extends SpringBootServletInitializer { return application.sources(Application.class); } - public static void main(String[] args) throws Exception { + public static void main(String[] args) { SpringApplication.run(Application.class, args); } diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/JerseyConfiguration.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/JerseyConfiguration.java index df7c8a8..7d97614 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/JerseyConfiguration.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/JerseyConfiguration.java @@ -15,10 +15,21 @@ * limitations under the License. * ============LICENSE_END===================================================== */ + package org.onap.pomba.contextbuilder.networkdiscovery; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.cert.X509Certificate; import java.util.logging.Logger; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; import javax.ws.rs.ApplicationPath; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @@ -30,15 +41,8 @@ import org.glassfish.jersey.servlet.ServletProperties; import org.onap.pomba.contextbuilder.networkdiscovery.service.rs.RestServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; - @Component @ApplicationPath("/") public class JerseyConfiguration extends ResourceConfig { @@ -52,18 +56,40 @@ public class JerseyConfiguration extends ResourceConfig { } @Bean - @Primary - public ObjectMapper objectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); - objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); - objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); - return objectMapper; + public Client jerseyClient() { + return ClientBuilder.newClient(new ClientConfig()); } @Bean - public Client jerseyClient() { - return ClientBuilder.newClient(new ClientConfig()); + public Client jerseySslClient() throws NoSuchAlgorithmException, KeyManagementException { + + ClientConfig clientConfig = new ClientConfig(); + TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return null; + } + + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } + + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + } }; + + SSLContext sc = SSLContext.getInstance("TLS"); + sc.init(null, trustAllCerts, new SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + + ClientBuilder.newClient(clientConfig); + + return ClientBuilder.newBuilder() + .sslContext(sc) + .hostnameVerifier(new HostnameVerifier() { + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }) + .withConfig(clientConfig).build(); } + } diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/NdctxbConfiguration.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/NdctxbConfiguration.java index 7781d1a..ed39de7 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/NdctxbConfiguration.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/NdctxbConfiguration.java @@ -18,31 +18,17 @@ package org.onap.pomba.contextbuilder.networkdiscovery; -import java.net.InetAddress; -import java.util.Arrays; import java.util.Base64; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.StreamSupport; import org.eclipse.jetty.util.security.Password; -import org.onap.pomba.contextbuilder.networkdiscovery.exception.DiscoveryException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; -import org.springframework.core.env.AbstractEnvironment; -import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.Environment; -import org.springframework.core.env.MutablePropertySources; import org.springframework.stereotype.Component; @Component public class NdctxbConfiguration { - private static Logger log = LoggerFactory.getLogger(NdctxbConfiguration.class); - private final String prefixResourceType = "networkDiscoveryCtxBuilder.resourceTypeMapping."; - private final String whiteSpace = "\\s"; // Network Discovery Context Builder Configuration values @@ -61,10 +47,6 @@ public class NdctxbConfiguration { @Value("${networkDiscoveryCtxBuilder.password:OBF:1u2a1toa1w8v1tok1u30}") private String networkDiscoveryCtxBuilderPassword; - @Value("${networkDiscoveryCtxBuilder.resourceList:vnfcs}") - private String networkDiscoveryCtxBuilderResourceList; - - // Service Decomposition Configuration values @Value("${serviceDecomposition.host:127.0.0.1}") @@ -111,9 +93,8 @@ public class NdctxbConfiguration { @Bean(name = "serviceDecompositionBaseUrl") public String getURL() { - String url = this.serviceDecompositionHttpProtocol + "://" + this.serviceDecompositionHost + ":" + return this.serviceDecompositionHttpProtocol + "://" + this.serviceDecompositionHost + ":" + this.serviceDecompositionPort + this.serviceDecompositionServiceInstancePath; - return url; } @Bean(name = "serviceDecompositionBasicAuthorization") @@ -130,38 +111,27 @@ public class NdctxbConfiguration { } @Bean(name = "networkDiscoveryCtxBuilderBaseUrl") - public String getNetworkDiscoveryCtxBuilderBaseUrl() throws DiscoveryException { - String url = null; - url = this.httpNetworkDiscoveryCtxBuilderProtocol + public String getNetworkDiscoveryCtxBuilderBaseUrl() { + return this.httpNetworkDiscoveryCtxBuilderProtocol + "://" + this.networkDiscoveryCtxBuilderServiceName + ":" + this.networkDiscoveryCtxBuilderPort; - return url; - } - - @Bean(name = "networkDiscoveryCtxBuilderResources") - public String getNetworkDiscoveryCtxBuilderResourcs() { - return this.networkDiscoveryCtxBuilderResourceList; } - @Bean(name = "networkDiscoveryMicroServiceBaseUrl") public String getNetworkDiscoveryURL() { - String url = this.httpNetworkDiscoveryMicroServiceProtocol + "://" + this.networkDiscoveryMicroServiceHost + ":" + return this.httpNetworkDiscoveryMicroServiceProtocol + "://" + this.networkDiscoveryMicroServiceHost + ":" + this.networkDiscoveryMicroServicePort + this.networkDiscoveryMicroServicePath; - return url; } @Bean(name = "networkDiscoveryResponseTimeOutInMilliseconds") public long getNdResponseTimeOutInMilliseconds() { - long timeoutV = Integer.parseUnsignedInt(this.networkDiscoveryResponseTimeOutInMilliseconds); - return timeoutV; + return Integer.parseUnsignedInt(this.networkDiscoveryResponseTimeOutInMilliseconds); } @Bean(name = "networkDiscoveryMicroServiceHostAndPort") public String getNetworkDiscoveryMicroServiceHostAndPort() { - String hostNPort = this.networkDiscoveryMicroServiceHost + ":" + this.networkDiscoveryMicroServicePort; - return hostNPort; + return this.networkDiscoveryMicroServiceHost + ":" + this.networkDiscoveryMicroServicePort; } @Bean(name = "networkDiscoveryMicroServiceBasicAuthorization") @@ -174,31 +144,4 @@ public class NdctxbConfiguration { @Autowired private Environment env; - // This method builds a map between Service Decomposition resource type and Network Discovery - // Context Builder resource type using dynamic mapping technique. - // It scans the contents of the configuration file "application.properties", - // searching for the string "networkDiscoveryCtxBuilder.resourceTypeMapping.", and if found, - // anything from the remaining string will be used as the key (Service Decomposition resource Type) - // to match to the value of assignment (network discovery context builder resource type). - // For example,"networkDiscoveryCtxBuilder.resourceTypeMapping.BBB = bbb", - // Service Decomposition resource type BBB matches to context builder resource type bbb - @Bean(name = "networkDiscoveryCtxBuilderResourceTypeMapping") - public Map<String, String> getResourceTypeMapping() { - Map<String, String> props = new HashMap<>(); - MutablePropertySources propSrcs = ((AbstractEnvironment) this.env).getPropertySources(); - StreamSupport.stream(propSrcs.spliterator(), false) - .filter(ps -> ps instanceof EnumerablePropertySource) - .map(ps -> ((EnumerablePropertySource<?>) ps).getPropertyNames()) - .flatMap(Arrays::<String>stream) - .forEach(propName -> { - if (propName.startsWith(prefixResourceType)) { - String myKey = propName.substring(prefixResourceType.length()).replaceAll(whiteSpace,""); - String myValue = this.env.getProperty(propName).replaceAll(whiteSpace, ""); - props.put( myKey , myValue); - } - }); - - log.info(props.toString()); - return props; - } } diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/WebConfiguration.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/WebConfiguration.java index ed779b8..e7a446e 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/WebConfiguration.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/WebConfiguration.java @@ -15,6 +15,7 @@ * limitations under the License. * ============LICENSE_END===================================================== */ + package org.onap.pomba.contextbuilder.networkdiscovery; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/exception/DiscoveryException.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/exception/DiscoveryException.java index 149efaa..0107672 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/exception/DiscoveryException.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/exception/DiscoveryException.java @@ -15,6 +15,7 @@ * limitations under the License. * ============LICENSE_END===================================================== */ + package org.onap.pomba.contextbuilder.networkdiscovery.exception; import javax.ws.rs.core.Response.Status; @@ -25,11 +26,11 @@ public class DiscoveryException extends Exception { private final Status httpStatus; - public DiscoveryException(String message) { - super(message); - this.httpStatus = matchErrorCode(message); - } - + /** + * Internal Exception class with HTTP status. + * @param message Exception message + * @param httpStatus The http status code + */ public DiscoveryException(String message, Status httpStatus) { super(message); if (httpStatus == null) { @@ -38,32 +39,8 @@ public class DiscoveryException extends Exception { this.httpStatus = httpStatus; } - public DiscoveryException(String message, Exception cause) { - super(message, cause); - this.httpStatus = matchErrorCode(cause.getMessage()); - } - public Status getHttpStatus() { return this.httpStatus; } - private Status matchErrorCode(String errorMessage) { - if(null == errorMessage) { - return Status.INTERNAL_SERVER_ERROR; - } - if (errorMessage.toLowerCase().contains("auth")) { - return Status.UNAUTHORIZED; - } - if ((errorMessage.toLowerCase().contains("missing"))) { - return Status.BAD_REQUEST; - } else { - for (Status st : Status.values()) { - - if (errorMessage.toLowerCase().contains(st.getReasonPhrase().toLowerCase())) { - return st; - } - } - } - return Status.INTERNAL_SERVER_ERROR; - } } diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/exception/ErrorMessage.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/exception/ErrorMessage.java index a1090e5..90a75d2 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/exception/ErrorMessage.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/exception/ErrorMessage.java @@ -15,10 +15,16 @@ * limitations under the License. * ============LICENSE_END===================================================== */ + package org.onap.pomba.contextbuilder.networkdiscovery.exception; public class ErrorMessage { public static final String CONTEXT_BUILDER_FAILED = "Context Builder Failed. "; public static final String INVALID_REQUEST_URL = "Invalid Request URL. "; public static final String MISSING_PARAMTER = "Missing Parameter: "; + + private ErrorMessage() { + throw new IllegalStateException("Utility class"); + } + } diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResource.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResource.java new file mode 100644 index 0000000..9f79849 --- /dev/null +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResource.java @@ -0,0 +1,54 @@ +/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextbuilder.networkdiscovery.model;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel(value = "NdResource")
+public class NdResource {
+
+ @Expose
+ @SerializedName("resourceId")
+ private String resourceId;
+ @Expose
+ @SerializedName("resourceType")
+ private String resourceType;
+
+ @ApiModelProperty(value = "UUID of Resource for Network Discovery")
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ }
+
+ @ApiModelProperty(value = "Type of Resource for Network Discovery")
+ public String getResourceType() {
+ return resourceType;
+ }
+
+ public void setResourceType(String resourceType) {
+ this.resourceType = resourceType;
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResources.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResources.java new file mode 100644 index 0000000..54e627d --- /dev/null +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResources.java @@ -0,0 +1,48 @@ +/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextbuilder.networkdiscovery.model;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.ArrayList;
+import java.util.List;
+
+@ApiModel(value = "NdResources")
+public class NdResources {
+
+ @Expose
+ @SerializedName("ndResources")
+ private List<NdResource> ndResources = new ArrayList<>();
+
+ @ApiModelProperty(value = "List of NdResource associated with the service instance")
+ public List<NdResource> getNdResources() {
+ return ndResources;
+ }
+
+ public void setNdResources(List<NdResource> ndResources) {
+ this.ndResources = ndResources;
+ }
+
+ public void addNdResource(NdResource ndResource) {
+ this.ndResources.add(ndResource);
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NetworkDiscoveryRspInfo.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NetworkDiscoveryRspInfo.java deleted file mode 100644 index b371631..0000000 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NetworkDiscoveryRspInfo.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * ============LICENSE_START=================================================== - * Copyright (c) 2018 Amdocs - * ============================================================================ - * 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.pomba.contextbuilder.networkdiscovery.model; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CountDownLatch; - -import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification; - -public class NetworkDiscoveryRspInfo { - - private String requestId; - private String resourceId; // e.g.: - // vserverId - private String resourceType; // e.g.: - // vserver - private CountDownLatch latchSignal; - - private List<NetworkDiscoveryNotification> networkDiscoveryNotificationList = Collections - .synchronizedList(new ArrayList<>()); - private List<String> relatedRequestIdList; - - public String getRequestId() { - return requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - - public String getResourceId() { - return resourceId; - } - - public void setResourceId(String resourceId) { - this.resourceId = resourceId; - } - - public CountDownLatch getLatchSignal() { - return latchSignal; - } - - public void setLatchSignal(CountDownLatch latchSignal) { - this.latchSignal = latchSignal; - } - - public List<NetworkDiscoveryNotification> getNetworkDiscoveryNotificationList() { - return this.networkDiscoveryNotificationList; - } - - public void setNetworkDiscoveryNotificationList(List<NetworkDiscoveryNotification> response) { - this.networkDiscoveryNotificationList = response; - } - - public List<String> getRelatedRequestIdList() { - return this.relatedRequestIdList; - } - - public void setRelatedRequestIdList(List<String> response) { - this.relatedRequestIdList = response; - } - - @Override - public String toString() { - return "networkDiscoveryRspInfo [requestId=" + this.requestId + ", resourceId=" + this.resourceId - + ", resourceType=" + this.resourceType + "]"; - } -} diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringService.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringService.java index 770f8a0..6b707ee 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringService.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringService.java @@ -15,13 +15,13 @@ * limitations under the License. * ============LICENSE_END===================================================== */ + package org.onap.pomba.contextbuilder.networkdiscovery.service; import javax.servlet.http.HttpServletRequest; import org.onap.pomba.common.datatypes.ModelContext; import org.onap.pomba.contextbuilder.networkdiscovery.exception.DiscoveryException; -import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification; public interface SpringService { @@ -31,6 +31,4 @@ public interface SpringService { public void validateBasicAuth(String authorization) throws DiscoveryException; - public void networkDiscoveryNotification(NetworkDiscoveryNotification notification, String authorization) - throws DiscoveryException; } diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java index d6010c4..2df082c 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java @@ -15,41 +15,42 @@ * limitations under the License. * ============LICENSE_END===================================================== */ + package org.onap.pomba.contextbuilder.networkdiscovery.service; import com.bazaarvoice.jolt.Chainr; import com.bazaarvoice.jolt.JsonUtils; import com.google.gson.Gson; + import java.net.InetAddress; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.locks.ReentrantLock; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.client.Client; import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.Response.Status.Family; + +import org.onap.aai.restclient.client.Headers; import org.onap.pomba.common.datatypes.Attribute; +import org.onap.pomba.common.datatypes.DataQuality; import org.onap.pomba.common.datatypes.ModelContext; import org.onap.pomba.common.datatypes.Network; -import org.onap.pomba.common.datatypes.VF; import org.onap.pomba.common.datatypes.VFModule; import org.onap.pomba.common.datatypes.VM; -import org.onap.pomba.common.datatypes.VNFC; +import org.onap.pomba.common.datatypes.VNF; import org.onap.pomba.contextbuilder.networkdiscovery.exception.DiscoveryException; -import org.onap.pomba.contextbuilder.networkdiscovery.model.NetworkDiscoveryRspInfo; +import org.onap.pomba.contextbuilder.networkdiscovery.model.NdResource; +import org.onap.pomba.contextbuilder.networkdiscovery.model.NdResources; import org.onap.pomba.contextbuilder.networkdiscovery.service.rs.RestService; import org.onap.pomba.contextbuilder.networkdiscovery.util.RestUtil; import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification; -import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryResponse; import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,51 +81,18 @@ public class SpringServiceImpl implements SpringService { public static final String MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_REQUEST_ID = "ChildRequestId"; public static final String MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_RESOURCE_TYPE = "ResourceType"; public static final String MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_RESOURCE_ID = "ResourceID"; - public static final String MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_CALL_BACK_URL = "CallbackUrl"; public static final String MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS = "Status"; - public static final String MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS_NO_MORE_CALL_BACK = "NoMoreCallBack"; - public static final String MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_WAIT_FOR_NOTIFICATION_TIME_OUT = "NotificationTimeOut"; - public static final String NETWORK_DISCOVERY_RSP_STATE_REQUEST_SENT = "RequestSent"; - public static final String NETWORK_DISCOVERY_RSP_STATE_RSP_ALL_RECEIVED = "AllRspReceived"; public static final String NETWORK_DISCOVERY_RSP_REQUESTID_SPLITTER = "___"; - public static final String NETWORK_DISCOVERY_CTX_BUILDER_NETWORK_DISCOVERY_NOTIFICATION_PATH = "/ndcontextbuilder/service/networkDiscoveryNotification"; public static final String NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_X_ONAP_PARTNER_NAME = "X-ONAP-PartnerName"; public static final String NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_X_ONAP_REQUEST_ID = "X-ONAP-RequestID"; public static final String NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_REQUEST_ID = "requestId"; public static final String NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_RESOURCE_TYPE = "resourceType"; public static final String NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_RESOURCE_ID = "resourceId"; - public static final String NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_NOTIFICATION_URL = "notificationURL"; - public static final String MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_APP = "NetworkDiscoveryMicroService_TO_NetworkDiscoveryContextBuilder"; - public static final String MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_MSG_NAME = "MsgName"; - public static final String MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_NETWORKDISCOVERYNOTIFICATION = "NetworkDiscoveryNotification"; - public static final String MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_REQUEST_ID = "RequestId"; - public static final String MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS = "Status"; - public static final String MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS_UNKNOWN_REQ = "EntryRemoved_dueTo_timeOut_or_error_or_neverExisit"; - public static final String MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS_SUCCESS = "SUCCESS"; private static UUID instanceUUID = UUID.randomUUID(); - private static Map<String, NetworkDiscoveryRspInfo> networkDiscoveryInfoList = new HashMap<>(); private static final AtomicLong uniqueSeq = new AtomicLong(); - private class NdResource { - - private String resourceType; - private String resourceId; - - public NdResource(String type, String id) { - this.resourceType = type; - this.resourceId = id; }; - - public String getResourceType() { - return this.resourceType; - } - public String getResourceId() { - return this.resourceId; - } - } - - @Autowired private String serviceDecompositionBaseUrl; @@ -141,142 +109,31 @@ public class SpringServiceImpl implements SpringService { private String networkDiscoveryMicroServiceBaseUrl; @Autowired - private String networkDiscoveryCtxBuilderBaseUrl; - - @Autowired - private long networkDiscoveryResponseTimeOutInMilliseconds; - - @Autowired private String networkDiscoveryMicroServiceHostAndPort; @Autowired private Client jerseyClient; - private static final ReentrantLock lock = new ReentrantLock(); + @Autowired + private Client jerseySslClient; @Override public ModelContext getContext(HttpServletRequest req, String partnerName, String authorization, String requestId, String serviceInstanceId, String modelVersionId, String modelInvariantId) throws DiscoveryException { String remoteAddress = req.getRemoteAddr() != null ? req.getRemoteAddr() : null; - initMDC(requestId, partnerName, serviceInstanceId, remoteAddress); - - try { - RestUtil.validateServiceInstanceId(serviceInstanceId); - RestUtil.validatePartnerName(partnerName); - validateBasicAuth(authorization); - ModelContext networkDiscoveryCtx = getServiceDeomposition(serviceInstanceId, partnerName, requestId); - - CountDownLatch latchSignal = createCountDownLatch(networkDiscoveryCtx); - - if (latchSignal == null) { - // Nothing to send - return networkDiscoveryCtx; - } - - List<String> sentRequestIdList = sendNetworkDiscoveryRequest(networkDiscoveryCtx, serviceInstanceId, requestId, - partnerName, latchSignal); - - int numOfMsgSent = sentRequestIdList.size(); - if ((numOfMsgSent > 0) && (latchSignal != null)) { - // The main task waits for four threads - if (false == latchSignal.await(networkDiscoveryResponseTimeOutInMilliseconds, TimeUnit.MILLISECONDS)) { - // When it comes here, it is due to time out. - log.info("Wait for Latch Signal time out " + serviceInstanceId); - } - return updateServiceDecompCtx(networkDiscoveryCtx, sentRequestIdList); - } else { - return networkDiscoveryCtx; - } - - } catch (Exception x) { - DiscoveryException exception = new DiscoveryException(x.getMessage(), x); - MDC.put(MDC_RESPONSE_CODE, String.valueOf(exception.getHttpStatus().getStatusCode())); - MDC.put(MDC_STATUS_CODE, "ERROR"); - log.error(x.getMessage()); - throw exception; - } finally { - MDC.clear(); - } - } - - private void initMDC(String requestId, String partnerName, String serviceInstanceId, String remoteAddress) { - MDC.clear(); - MDC.put(MDC_REQUEST_ID, requestId); - MDC.put(MDC_SERVICE_NAME, APP_NAME); - MDC.put(MDC_SERVICE_INSTANCE_ID, serviceInstanceId); - MDC.put(MDC_PARTNER_NAME, partnerName); - MDC.put(MDC_CLIENT_ADDRESS, remoteAddress); - MDC.put(MDC_START_TIME, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(new Date())); - MDC.put(MDC_INVOCATION_ID, UUID.randomUUID().toString()); - MDC.put(MDC_INSTANCE_UUID, instanceUUID.toString()); - - try { - MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName()); - } catch (Exception e) { - // If, for some reason we are unable to get the canonical host name, - // we - // just want to leave the field null. - log.info("Could not get canonical host name for " + MDC_SERVER_FQDN + ", leaving field null"); - } - } - - /** - * Given a service instance ID, GET the resources from Service Decompostion. - */ - private ModelContext getServiceDeomposition(String serviceInstanceId, String partnerName, String requestId) - throws DiscoveryException { - if (serviceInstanceId == null) { - return null; - } - - log.info("Querying Service Decomposition for service instance " + serviceInstanceId); - - String urlStr = getUrl(serviceInstanceId); - - try { - Response response = jerseyClient.target(urlStr).request() - .header("Accept", "application/json") - .header("Authorization", getSdBasicAuthorization()) - .header("X-ONAP-PartnerName", partnerName) - .header("X-ONAP-RequestID", requestId).get(); - - String reply = null; - if (response.getStatus() != 200) { - MDC.put(MDC_RESPONSE_CODE, String.valueOf(response.getStatus())); - MDC.put(MDC_STATUS_CODE, "ERROR"); - throw new DiscoveryException(response.getStatusInfo().toString(), - Response.Status.fromStatusCode(response.getStatus())); - } else { - MDC.put(MDC_RESPONSE_CODE, String.valueOf(response.getStatus())); - MDC.put(MDC_STATUS_CODE, "COMPLETE"); - reply = response.readEntity(String.class); - - log.info("GET Response from ServiceDecompositionMircoService GetContext for serviceInstanceId:" - + serviceInstanceId + ", message body: " + reply); - } - - List<Object> jsonSpec = JsonUtils.filepathToList("config/networkdiscovery.spec"); - Object jsonInput = JsonUtils.jsonToObject(reply); - Chainr chainr = Chainr.fromSpec(jsonSpec); - Object transObject = chainr.transform(jsonInput); - Gson gson = new Gson(); - return gson.fromJson(JsonUtils.toPrettyJsonString(transObject), ModelContext.class); - } catch (Exception x) { - throw new DiscoveryException(x.getMessage(), x); - } - } - - private String getUrl(String serviceInstanceId) throws DiscoveryException { - String url = serviceDecompositionBaseUrl + "?serviceInstanceId=" + serviceInstanceId; - return url; - } - - private String getSdBasicAuthorization() { - return serviceDecompositionBasicAuthorization; + initMdc(requestId, partnerName, serviceInstanceId, remoteAddress); + + RestUtil.validateServiceInstanceId(serviceInstanceId); + RestUtil.validatePartnerName(partnerName); + validateBasicAuth(authorization); + String sdReply = getServiceDeomposition(serviceInstanceId, partnerName, requestId); + ModelContext networkDiscoveryCtx = createModelContextFromSdResonse(sdReply); + NdResources ndResources = createNdResourcesFromSdResonse(sdReply); + sendNetworkDiscoveryRequest(networkDiscoveryCtx, ndResources, requestId, partnerName); + return networkDiscoveryCtx; } - /** * Validates the Basic authorization header as admin:admin. * @@ -288,115 +145,92 @@ public class SpringServiceImpl implements SpringService { if (!authorization.equals(networkDiscoveryCtxBuilderBasicAuthorization)) { throw new DiscoveryException("Authorization Failed", Status.UNAUTHORIZED); } - ; } else { throw new DiscoveryException( - "Missing Authorization: " + (authorization == null ? "null" : authorization.toString()), + "Missing Authorization: " + (authorization == null ? "null" : authorization), Status.UNAUTHORIZED); } } - @Override - public void networkDiscoveryNotification(NetworkDiscoveryNotification ndNotification, String authorization) + /** + * Given a service instance ID, GET the resources from Service Decomposition. + */ + private String getServiceDeomposition(String serviceInstanceId, String partnerName, String requestId) throws DiscoveryException { - String requestId = ndNotification.getRequestId(); - initMDC_MsgFrom_networkDiscoveryMicroService(requestId); - log.info("POST message payload:" + ndNotification.toString()); - String status = null; - - NetworkDiscoveryRspInfo myNetworkDiscoveryRspInfo; - lock.lock(); - try { - myNetworkDiscoveryRspInfo = networkDiscoveryInfoList.get(requestId); - if (myNetworkDiscoveryRspInfo == null) { - // The requestId is invalid. The corresponding request may - // already be discarded - // due to time out or error exception, or the request may never - // exist. - log.error("Unknown RequestId:" + requestId - + "! The corresponding request may already be discarded due to time out or error exception, or the request never exists."); - - status = MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS_UNKNOWN_REQ; - return; - } - - // Update networkDiscoveryInfo - status = MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS_SUCCESS; - myNetworkDiscoveryRspInfo.getNetworkDiscoveryNotificationList().add(ndNotification); - } finally { - lock.unlock(); + if (serviceInstanceId == null) { + return null; } + + String urlStr = serviceDecompositionBaseUrl + "?serviceInstanceId=" + serviceInstanceId; - MDC.put(MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, status); - CountDownLatch latch = myNetworkDiscoveryRspInfo.getLatchSignal(); - if (latch != null) { - latch.countDown(); - } + log.info("Querying Service Decomposition for service instance {} at url {}", serviceInstanceId, urlStr); - return; - } + Response response = jerseyClient.target(urlStr).request().header(Headers.ACCEPT, MediaType.APPLICATION_JSON) + .header(Headers.AUTHORIZATION, serviceDecompositionBasicAuthorization) + .header(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_X_ONAP_PARTNER_NAME, partnerName) + .header(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_X_ONAP_REQUEST_ID, requestId).get(); - private ModelContext updateServiceDecompCtx(ModelContext networkDiscoveryCtx, - List<String> sentRequestIdList) { - /* - * TO DO: We can't add network discovery data to networkDiscoveryCtx - * because the existing "v0" context aggregator context model doesn't - * support it. We will have to wait for the real "v1" context model - * which contains attributes, vservers and networks. - */ - - StringBuilder sbl = new StringBuilder(); - int idx = 0; - for (String reqId : sentRequestIdList) { - if (!(networkDiscoveryInfoList.containsKey(reqId))) { - continue; - } - idx++; - sbl.append("--[[Entry" + idx + "]]" + ", requestId:" + reqId); - lock.lock(); - NetworkDiscoveryRspInfo tNdRspInfo = networkDiscoveryInfoList.get(reqId); - - // ServiceDecompCtx is updated, we need to delete the existing entry - // in - // networkDiscoveryInfoList - networkDiscoveryInfoList.remove(reqId); - lock.unlock(); - - sbl.append(", Resource :" + tNdRspInfo.getResourceType()); - sbl.append(", ResourceId :" + tNdRspInfo.getResourceId()); - sbl.append(", RelatedRequestId :" + tNdRspInfo.getRelatedRequestIdList()); - for (NetworkDiscoveryNotification nt : tNdRspInfo.getNetworkDiscoveryNotificationList()) { - List <Resource> resourceList = nt.getResources(); - for (Resource resource : resourceList) { - updateServiceDecompCtx(networkDiscoveryCtx, resource); - } - sbl.append(" Notification :" + nt.toString()); - } + log.info( + "GET Response from ServiceDecompositionMircoService for serviceInstanceId: {}, status code {}", + serviceInstanceId, response.getStatusInfo().getStatusCode()); + + if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) { + MDC.put(MDC_RESPONSE_CODE, String.valueOf(response.getStatus())); + MDC.put(MDC_STATUS_CODE, "ERROR"); + throw new DiscoveryException( + "Error from Service Decomposition service: " + response.getStatusInfo().getReasonPhrase(), + Response.Status.fromStatusCode(response.getStatus())); } - String infoStr = sbl.toString(); + MDC.put(MDC_RESPONSE_CODE, String.valueOf(response.getStatus())); + MDC.put(MDC_STATUS_CODE, "COMPLETE"); + String reply = response.readEntity(String.class); + log.info( - "updateServiceDecompCtx_and_networkDiscoveryInfoList: All Notifications from NetworkDiscoveryMicroService: " - + infoStr); + "GET Response from ServiceDecompositionMircoService GetContext for serviceInstanceId: {}, message body: {}", + serviceInstanceId, reply); - return networkDiscoveryCtx; + return reply; } - private void updateServiceDecompCtx(ModelContext networkDiscoveryCtx, Resource resource) { - for (VF vf : networkDiscoveryCtx.getVfs()) { - for (VFModule vfModule : vf.getVfModules()) { + private void updateNetworkDiscoveryCtx(ModelContext networkDiscoveryCtx, Resource resource) { + // Future: try to replace this with a Jolt transformation. + for (VNF vnf : networkDiscoveryCtx.getVnfs()) { + for (VFModule vfModule : vnf.getVfModules()) { for (VM vm : vfModule.getVms()) { - if (vm.getUuid().equals(resource.getId())) { + if (vm.getUuid().equals(resource.getId()) && "vserver".equals(resource.getType())) { vm.setDataQuality(resource.getDataQuality()); if (null != resource.getAttributeList()) { - for (org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute ndattribute : resource.getAttributeList()) { + for (org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute ndattribute : resource + .getAttributeList()) { try { String ndattributeName = ndattribute.getName(); - if (ndattributeName.equals("name")) { + // Some Network Discovery attribute name do not exactly + // match the pomba-audit-common model Attribute Enums, + // so we have to do some custom mapping here: + switch (ndattributeName) { + case "id": + vm.setUuid(ndattribute.getValue()); + break; + case "name": vm.setName(ndattribute.getValue()); - } - else { + break; + case "inMaintenance": Attribute attribute = new Attribute(); + attribute.setName(Attribute.Name.lockedBoolean); + attribute.setValue(ndattribute.getValue()); + attribute.setDataQuality(ndattribute.getDataQuality()); + vm.addAttribute(attribute); + break; + case "hostname": + attribute = new Attribute(); + attribute.setName(Attribute.Name.hostName); + attribute.setValue(ndattribute.getValue()); + attribute.setDataQuality(ndattribute.getDataQuality()); + vm.addAttribute(attribute); + break; + default: + attribute = new Attribute(); attribute.setName(Attribute.Name.valueOf(ndattributeName)); attribute.setValue(ndattribute.getValue()); attribute.setDataQuality(ndattribute.getDataQuality()); @@ -404,31 +238,56 @@ public class SpringServiceImpl implements SpringService { } } catch (IllegalArgumentException ex) { // The attribute Name passed back from Network Discovery is not in our enum - log.info("Attribute Name: " + ndattribute.getName() + " for Resource:" + resource.getName() + " Id:" +resource.getId() + " is invalid"); + log.info("Attribute Name: {} for Resource: {} Id: {} is invalid", + ndattribute.getName(), resource.getName(), resource.getId()); } } } } } for (Network network : vfModule.getNetworks()) { - if (network.getUuid().equals(resource.getId())) { + if (network.getUuid().equals(resource.getId()) && "l3-network".equals(resource.getType())) { network.setDataQuality(resource.getDataQuality()); if (null != resource.getAttributeList()) { - for (org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute ndattribute : resource.getAttributeList()) { + for (org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute ndattribute : resource + .getAttributeList()) { try { String ndattributeName = ndattribute.getName(); - if (ndattributeName.equals("name")) { + // Some Network Discovery attribute name do not exactly + // match the pomba-audit-common model Attribute Enums, + // so we have to do some custom mapping here: + switch (ndattributeName) { + case "id": + network.setUuid(ndattribute.getValue()); + break; + case "name": network.setName(ndattribute.getValue()); - } - else { + break; + case "AdminState": Attribute attribute = new Attribute(); + attribute.setName(Attribute.Name.adminStatus); + attribute.setValue(ndattribute.getValue()); + attribute.setDataQuality(ndattribute.getDataQuality()); + network.addAttribute(attribute); + break; + case "sharedNetwork": + attribute = new Attribute(); + attribute.setName(Attribute.Name.sharedNetworkBoolean); + attribute.setValue(ndattribute.getValue()); + attribute.setDataQuality(ndattribute.getDataQuality()); + network.addAttribute(attribute); + break; + default: + attribute = new Attribute(); attribute.setName(Attribute.Name.valueOf(ndattributeName)); attribute.setValue(ndattribute.getValue()); + attribute.setDataQuality(ndattribute.getDataQuality()); network.addAttribute(attribute); } } catch (IllegalArgumentException ex) { // The attribute Name passed back from Network Discovery is not in our enum - log.info("Attribute Name: " + ndattribute.getName() + " for Resource:" + resource.getName() + " Id:" + resource.getId() + " is invalid"); + log.info("Attribute Name: {} for Resource: {} Id: {} is invalid", + ndattribute.getName(), resource.getName(), resource.getId()); } } } @@ -439,188 +298,105 @@ public class SpringServiceImpl implements SpringService { } } + private void updateNetworkDiscoveryCtxDataQuality(ModelContext networkDiscoveryCtx, String resourceId, + DataQuality dataQuality) { + for (VNF vnf : networkDiscoveryCtx.getVnfs()) { + for (VFModule vfModule : vnf.getVfModules()) { + for (VM vm : vfModule.getVms()) { + if (vm.getUuid().equals(resourceId)) { + vm.setDataQuality(dataQuality); + } + } + for (Network network : vfModule.getNetworks()) { + if (network.getUuid().equals(resourceId)) { + network.setDataQuality(dataQuality); + } + } - private CountDownLatch createCountDownLatch(ModelContext networkDiscoveryCtx) { - - // Obtain the possible total count of messages to NetworkDiscovery - // for CountDownLatch. - int latch_count = 0; - for (VF vf : networkDiscoveryCtx.getVfs()) { - latch_count += vf.getVnfcs().size(); - for (VFModule vfModule : vf.getVfModules()) { - latch_count += vfModule.getVms().size(); - latch_count += vfModule.getNetworks().size(); } } - if (latch_count > 0) { - // Let us create task that is going to - // wait for all threads before it starts - CountDownLatch latchSignal = new CountDownLatch(latch_count); - return latchSignal; - } - - return null; } /* Return list of requestIds sent to network-discovery microService. */ - private List<String> sendNetworkDiscoveryRequest(ModelContext networkDiscoveryCtx, String serviceInstanceId, String parent_requestId, - String partner_name, CountDownLatch latchSignal) throws DiscoveryException { - - List<String> relatedRequestIdList = new ArrayList<String>(); - List<NdResource> ndresourceList = new ArrayList<NdResource>(); - - for (VF vf : networkDiscoveryCtx.getVfs()) { - for (VNFC vnfc : vf.getVnfcs()) { - ndresourceList.add(new NdResource(vnfc.getType(), vnfc.getUuid())); - } - for (VFModule vfModule : vf.getVfModules()) { - for (VM vm : vfModule.getVms() ) { - ndresourceList.add(new NdResource(vm.getNfcNamingCode(), vm.getUuid())); - vm.setNfcNamingCode(null); - } - for (Network network : vfModule.getNetworks()) { - ndresourceList.add(new NdResource(network.getType(), network.getUuid())); + private void sendNetworkDiscoveryRequest(ModelContext networkDiscoveryCtx, NdResources ndResources, + String parentRequestId, String partnerName) throws DiscoveryException { + + for (NdResource ndResource : ndResources.getNdResources()) { + try { + // The old_requestId is inherited from ServiceDecomposition. + // Before we send a message to NetworkDiscoveryMicroService for each Resource, + // we need to generate a new request for identification, based on the old ID. + String requestId = parentRequestId + NETWORK_DISCOVERY_RSP_REQUESTID_SPLITTER + + uniqueSeq.incrementAndGet(); + + NetworkDiscoveryNotification nt = sendNetworkDiscoveryRequestToSpecificServer(partnerName, + parentRequestId, requestId, ndResource.getResourceId(), ndResource.getResourceType()); + + List<Resource> resourceList = nt.getResources(); + for (Resource resource1 : resourceList) { + updateNetworkDiscoveryCtx(networkDiscoveryCtx, resource1); } + } catch (Exception e) { + log.error("Error from Network Disovery Request - resourceId: {}, message: {}", + ndResource.getResourceId(), e.getMessage()); + DataQuality dataQuality = DataQuality.error("Error from Network Disovery Request: " + e.getMessage()); + updateNetworkDiscoveryCtxDataQuality(networkDiscoveryCtx, ndResource.getResourceId(), dataQuality); } } - for (NdResource resource : ndresourceList) { - - // The old_requestId is inherited from ServiceDecomposition. - // Before we send a - // message to NetworkDiscoveryMicroService for each Resource, we - // need to generate - // a new request for identification, based on the old ID. - String requestId = parent_requestId + NETWORK_DISCOVERY_RSP_REQUESTID_SPLITTER - + uniqueSeq.incrementAndGet(); - - if (true == sendNetworkDiscoveryRequestToSpecificServer(partner_name, parent_requestId, requestId, - resource.getResourceId(), resource.getResourceType(), latchSignal)) { - relatedRequestIdList.add(requestId); - } - } - - // Update networkDiscoveryInfoList - for (String t_rqId : relatedRequestIdList) { - if (networkDiscoveryInfoList.containsKey(t_rqId)) { - lock.lock(); - networkDiscoveryInfoList.get(t_rqId).setRelatedRequestIdList(relatedRequestIdList); - lock.unlock(); - } - } - - return relatedRequestIdList; } - // Return true when message is sent to network-discovery microService, - // otherwise, return false. - private boolean sendNetworkDiscoveryRequestToSpecificServer(String partner_name, String parent_requestId, - String requestId, String resourceId, String resourceType, CountDownLatch latchSignal) + private NetworkDiscoveryNotification sendNetworkDiscoveryRequestToSpecificServer(String partnerName, + String parentRequestId, String requestId, String resourceId, String resourceType) throws DiscoveryException { - String callbackUrlStr = getNetworkDiscoveryCtxBuilderCallBackUrl(); - String networkDiscoveryUrl = networkDiscoveryMicroServiceBaseUrl; - - NetworkDiscoveryRspInfo entryNS = new NetworkDiscoveryRspInfo(); - entryNS.setRequestId(requestId); - entryNS.setResourceId(resourceId); - entryNS.setResourceType(resourceType); - entryNS.setLatchSignal(latchSignal); - List<NetworkDiscoveryNotification> notfList = new ArrayList<>(); - List<String> reqList = new ArrayList<>(); - entryNS.setNetworkDiscoveryNotificationList(notfList); - entryNS.setRelatedRequestIdList(reqList); - - // Update networkDiscoveryInfoList before sending the message - // to NetworkDiscoveryMicroService, in case of race condition. - lock.lock(); - networkDiscoveryInfoList.put(requestId, entryNS); - lock.unlock(); - - // send message to Network Discovery API - NetworkDiscoveryResponse ndResponse = null; // Prepare MDC for logs - initMDC_sendTo_networkDiscoveryMicroService(networkDiscoveryUrl, requestId, resourceType, resourceId, - callbackUrlStr, partner_name); + initMdcSendToNetworkDiscoveryMicroService(networkDiscoveryMicroServiceBaseUrl, requestId, resourceType, + resourceId, partnerName); - try { - Response response = jerseyClient.target(networkDiscoveryUrl) - .queryParam(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_REQUEST_ID, requestId) - .queryParam(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_RESOURCE_TYPE, resourceType) - .queryParam(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_RESOURCE_ID, resourceId) - .queryParam(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_NOTIFICATION_URL, callbackUrlStr).request() - .header(HttpHeaders.CONTENT_TYPE, "application/json").header(HttpHeaders.ACCEPT, "application/json") - .header(HttpHeaders.AUTHORIZATION, getNetworkDiscoveryMircoServiceBasicAuthorization()) - .header(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_X_ONAP_PARTNER_NAME, partner_name) - .header(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_X_ONAP_REQUEST_ID, parent_requestId).get(); - - int responseCode = response.getStatus(); - String status = Response.Status.fromStatusCode(response.getStatus()) + ",code:" + response.getStatus(); - if ((responseCode < 200) || (responseCode >= 300)) { - latchSignal.countDown(); - safeRemoveEntry_from_networkDiscoveryInfoList(requestId); - MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, status); - throw new DiscoveryException(response.getStatusInfo().toString(), - Response.Status.fromStatusCode(response.getStatus())); - } else { - ndResponse = response.readEntity(NetworkDiscoveryResponse.class); - MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, status); - } - } catch (Exception e) { - latchSignal.countDown(); - safeRemoveEntry_from_networkDiscoveryInfoList(requestId); - MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, e.getMessage()); - throw new DiscoveryException(e.getMessage(), e); - } + log.info("Network Disvovery request for url {}, resourceId {}, resourceType {}", + networkDiscoveryMicroServiceBaseUrl, resourceId, resourceType); - if (true == ndResponse.getAckFinalIndicator()) { - // Perform count-down because there is no more notification coming - // for this requestId. - latchSignal.countDown(); - safeRemoveEntry_from_networkDiscoveryInfoList(requestId); - MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, - MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS_NO_MORE_CALL_BACK); - } + Response response = jerseySslClient.target(networkDiscoveryMicroServiceBaseUrl) + .queryParam(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_REQUEST_ID, requestId) + .queryParam(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_RESOURCE_TYPE, resourceType) + .queryParam(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_RESOURCE_ID, resourceId).request() + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON) + .header(HttpHeaders.AUTHORIZATION, networkDiscoveryMicroServiceBasicAuthorization) + .header(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_X_ONAP_PARTNER_NAME, partnerName) + .header(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_X_ONAP_REQUEST_ID, parentRequestId).get(); - log.info("Message sent. Response Payload:" + ndResponse); - return true; - } + String status = Response.Status.fromStatusCode(response.getStatus()) + ",code:" + response.getStatus(); - private void safeRemoveEntry_from_networkDiscoveryInfoList(String requestId) { - lock.lock(); - networkDiscoveryInfoList.remove(requestId); - lock.unlock(); - } + log.info("Network Disvovery response status code: {}", response.getStatus()); - private String getNetworkDiscoveryCtxBuilderCallBackUrl() { - String url = networkDiscoveryCtxBuilderBaseUrl - + NETWORK_DISCOVERY_CTX_BUILDER_NETWORK_DISCOVERY_NOTIFICATION_PATH; - return url; - } + MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, status); - private String getNetworkDiscoveryMircoServiceBasicAuthorization() { - return networkDiscoveryMicroServiceBasicAuthorization; + if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) { + throw new DiscoveryException( + "Error from Network Discovery service: " + response.getStatusInfo().getReasonPhrase(), + Response.Status.fromStatusCode(response.getStatus())); + } + + NetworkDiscoveryNotification ndResponse = response.readEntity(NetworkDiscoveryNotification.class); + log.info("Message sent. Response Payload: {}", ndResponse); + return ndResponse; } - private void initMDC_sendTo_networkDiscoveryMicroService(String networkDiscoveryUrl, String requestId, - String resourceType, String resourceId, String callbackUrlStr, String partner_name) { - String parentRequestId = MDC.get(MDC_REQUEST_ID); - String parentServiceInstanceId = MDC.get(MDC_SERVICE_INSTANCE_ID); - String parentPartnerName = MDC.get(MDC_PARTNER_NAME); + private void initMdc(String requestId, String partnerName, String serviceInstanceId, String remoteAddress) { MDC.clear(); - initMDC(parentRequestId, parentPartnerName, parentServiceInstanceId, networkDiscoveryMicroServiceHostAndPort); - - MDC.put(MDC_SERVICE_NAME, MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_APP); - MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_MSG_NAME, - MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_FINDBYRESOURCEIDANDTYPE); + MDC.put(MDC_REQUEST_ID, requestId); + MDC.put(MDC_SERVICE_NAME, APP_NAME); + MDC.put(MDC_SERVICE_INSTANCE_ID, serviceInstanceId); + MDC.put(MDC_PARTNER_NAME, partnerName); + MDC.put(MDC_CLIENT_ADDRESS, remoteAddress); MDC.put(MDC_START_TIME, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(new Date())); - MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_URL, networkDiscoveryUrl); - MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_REQUEST_ID, requestId); - MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_RESOURCE_TYPE, resourceType); - MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_RESOURCE_ID, resourceId); - MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_CALL_BACK_URL, callbackUrlStr); + MDC.put(MDC_INVOCATION_ID, UUID.randomUUID().toString()); + MDC.put(MDC_INSTANCE_UUID, instanceUUID.toString()); + try { - MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostAddress()); + MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName()); } catch (Exception e) { // If, for some reason we are unable to get the canonical host name, // we @@ -629,41 +405,51 @@ public class SpringServiceImpl implements SpringService { } } - private void initMDC_MsgFrom_networkDiscoveryMicroService(String requestId) { + private void initMdcSendToNetworkDiscoveryMicroService(String networkDiscoveryUrl, String requestId, + String resourceType, String resourceId, String partnerName) { String parentRequestId = MDC.get(MDC_REQUEST_ID); String parentServiceInstanceId = MDC.get(MDC_SERVICE_INSTANCE_ID); String parentPartnerName = MDC.get(MDC_PARTNER_NAME); MDC.clear(); - initMDC(parentRequestId, parentPartnerName, parentServiceInstanceId, networkDiscoveryMicroServiceHostAndPort); + initMdc(parentRequestId, parentPartnerName, parentServiceInstanceId, networkDiscoveryMicroServiceHostAndPort); - MDC.put(MDC_SERVICE_NAME, MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_APP); - MDC.put(MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_MSG_NAME, - MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_NETWORKDISCOVERYNOTIFICATION); + MDC.put(MDC_SERVICE_NAME, MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_APP); + MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_MSG_NAME, + MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_FINDBYRESOURCEIDANDTYPE); MDC.put(MDC_START_TIME, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(new Date())); - MDC.put(MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_REQUEST_ID, requestId); + MDC.put(MDC_PARTNER_NAME, partnerName); + MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_URL, networkDiscoveryUrl); + MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_REQUEST_ID, requestId); + MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_RESOURCE_TYPE, resourceType); + MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_RESOURCE_ID, resourceId); try { MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostAddress()); } catch (Exception e) { // If, for some reason we are unable to get the canonical host name, - // we - // just want to leave the field null. - log.info("Could not get canonical host name for " + MDC_SERVER_FQDN + ", leaving field null"); + // we just want to leave the field null. + log.info("Could not get canonical host name for {}, leaving field null", MDC_SERVER_FQDN); } } - protected static void updateNetworkDiscoveryInfoList(String requestId, NetworkDiscoveryRspInfo resp) { - lock.lock(); - networkDiscoveryInfoList.put(requestId, resp); - lock.unlock(); - return; + private ModelContext createModelContextFromSdResonse(String response) { + List<Object> jsonSpec = JsonUtils.filepathToList("config/jolt/sdToModelContextSpec.json"); + Object jsonInput = JsonUtils.jsonToObject(response); + Chainr chainr = Chainr.fromSpec(jsonSpec); + Object transObject = chainr.transform(jsonInput); + log.debug("Jolt transformed output: {}", JsonUtils.toJsonString(transObject)); + Gson gson = new Gson(); + return gson.fromJson(JsonUtils.toPrettyJsonString(transObject), ModelContext.class); } - protected static NetworkDiscoveryRspInfo getNetworkDiscoveryInfoList(String requestId) { - lock.lock(); - NetworkDiscoveryRspInfo returnInfo = networkDiscoveryInfoList.get(requestId); - lock.unlock(); - return returnInfo; + private NdResources createNdResourcesFromSdResonse(String response) { + List<Object> jsonSpec = JsonUtils.filepathToList("config/jolt/sdToNdResourcesSpec.json"); + Object jsonInput = JsonUtils.jsonToObject(response); + Chainr chainr = Chainr.fromSpec(jsonSpec); + Object transObject = chainr.transform(jsonInput); + log.debug("Jolt transformed output: {}", JsonUtils.toJsonString(transObject)); + Gson gson = new Gson(); + return gson.fromJson(JsonUtils.toPrettyJsonString(transObject), NdResources.class); } } diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/rs/RestService.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/rs/RestService.java index 67c65d9..9b17e47 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/rs/RestService.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/rs/RestService.java @@ -15,12 +15,12 @@ * limitations under the License. * ============LICENSE_END===================================================== */ + package org.onap.pomba.contextbuilder.networkdiscovery.service.rs; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; @@ -29,8 +29,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.onap.pomba.contextbuilder.networkdiscovery.exception.DiscoveryException; -import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification; -import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -50,20 +48,10 @@ public interface RestService { @ApiResponse(code = 404, message = "Service not available"), @ApiResponse(code = 500, message = "Unexpected Runtime error") }) public Response getContext(@Context HttpServletRequest req, @HeaderParam("Authorization") String authorization, - @HeaderParam("X-ONAP-PartnerName") String xpartnerName, @HeaderParam("X-ONAP-RequestID") String xRequestId, - @HeaderParam("X-FromAppId") String xFromAppId, @HeaderParam("X-TransactionId") String xTransactionId, + @HeaderParam("X-ONAP-PartnerName") String xpartnerName, @HeaderParam("X-ONAP-RequestID") String requestId, + @HeaderParam("X-FromAppId") String fromAppId, @HeaderParam("X-TransactionId") String transactionId, @QueryParam("serviceInstanceId") String serviceInstanceId, @QueryParam("modelVersionId") String modelVersionId, @QueryParam("modelInvariantId") String modelInvariantId) throws DiscoveryException; - @POST - @Path("/networkDiscoveryNotification") - @Produces(MediaType.TEXT_PLAIN) - @ApiOperation(value = "Send query request to Network Discovery", notes = "Retrieve information from primary data sources", response = NetworkDiscoveryResponse.class) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "Request has completed and no more information is forthcoming."), - @ApiResponse(code = 400, message = "Missing mandatory field in the request or HTTP header."), - @ApiResponse(code = 500, message = "Request failed due to internal error") }) - public Response networkDiscoveryNotification(NetworkDiscoveryNotification notification, - @HeaderParam("Authorization") String authorization) throws DiscoveryException; }
\ No newline at end of file diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/rs/RestServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/rs/RestServiceImpl.java index 7046c2d..67899ac 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/rs/RestServiceImpl.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/rs/RestServiceImpl.java @@ -15,8 +15,12 @@ * limitations under the License. * ============LICENSE_END===================================================== */ + package org.onap.pomba.contextbuilder.networkdiscovery.service.rs; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + import java.util.UUID; import javax.servlet.http.HttpServletRequest; @@ -27,15 +31,12 @@ import org.onap.pomba.common.datatypes.ModelContext; import org.onap.pomba.contextbuilder.networkdiscovery.exception.DiscoveryException; import org.onap.pomba.contextbuilder.networkdiscovery.exception.ErrorMessage; import org.onap.pomba.contextbuilder.networkdiscovery.service.SpringService; -import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - @Component public class RestServiceImpl implements RestService { private static Logger log = LoggerFactory.getLogger(RestService.class); @@ -46,27 +47,30 @@ public class RestServiceImpl implements RestService { private SpringService service; @Override - public Response getContext(HttpServletRequest req, String authorization, String partnerName, String requestId, String fromAppId, String transactionId, - String serviceInstanceId, String modelVersionId, String modelInvariantId) throws DiscoveryException { + public Response getContext(HttpServletRequest req, String authorization, String partnerName, String requestId, + String fromAppId, String transactionId, String serviceInstanceId, String modelVersionId, + String modelInvariantId) throws DiscoveryException { // Do some validation on Http headers and URL parameters - //The request ID in the header is not yet standardized to X-ONAP-RequestID. We would still support X-TransactionId until further notice. - if(requestId == null || requestId.isEmpty()) { - if(transactionId != null) { - requestId = transactionId; - } else { - requestId = UUID.randomUUID().toString(); - log.debug(HEADER_REQUEST_ID + " is missing; using newly generated value: " + requestId); - } - } + // The request ID in the header is not yet standardized to X-ONAP-RequestID. We + // would still support X-TransactionId until further notice. + if (requestId == null || requestId.isEmpty()) { + if (transactionId != null) { + requestId = transactionId; + } else { + requestId = UUID.randomUUID().toString(); + log.debug("{} is missing; using newly generated value: {}", HEADER_REQUEST_ID, requestId); + } + } - //The partner name in the header is not yet standardized to X-PartnerName. We would still support X-FromAppId until further notice. - if(partnerName == null || partnerName.isEmpty()) { - if(fromAppId != null) { - partnerName = fromAppId; - } - } + // The partner name in the header is not yet standardized to X-PartnerName. We + // would still support X-FromAppId until further notice. + if (partnerName == null || partnerName.isEmpty()) { + if (fromAppId != null) { + partnerName = fromAppId; + } + } try { ModelContext sdContext = service.getContext(req, partnerName, authorization, requestId, serviceInstanceId, @@ -79,33 +83,17 @@ public class RestServiceImpl implements RestService { return Response.ok().entity(gson.toJson(sdContext)).build(); } } catch (DiscoveryException x) { - log.error(ErrorMessage.CONTEXT_BUILDER_FAILED, x); + log.warn(ErrorMessage.CONTEXT_BUILDER_FAILED, x); return Response.status(x.getHttpStatus()).entity(x.getMessage()).build(); } catch (Exception x) { log.error(ErrorMessage.CONTEXT_BUILDER_FAILED, x); return Response.status(Status.INTERNAL_SERVER_ERROR).entity(x.getMessage()).build(); + + } finally { + MDC.clear(); } - } - - @Override - public Response networkDiscoveryNotification(NetworkDiscoveryNotification notification, String authorization) - throws DiscoveryException { - - try { - // The calling server (network discovery microService) - // doesn't check the response. - this.service.validateBasicAuth(authorization); - this.service.networkDiscoveryNotification(notification, authorization); - return Response.ok("Ack").build(); - - } catch (DiscoveryException x) { - log.error("context builder failed", x); - return Response.status(x.getHttpStatus()).entity(x.getMessage()).build(); - } catch (Exception x) { - log.error("context builder failed", x); - return Response.status(Status.INTERNAL_SERVER_ERROR).entity(x.getMessage()).build(); - } } + } diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/util/RestUtil.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/util/RestUtil.java index 94a5d5a..636e9ca 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/util/RestUtil.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/util/RestUtil.java @@ -15,6 +15,7 @@ * limitations under the License. * ============LICENSE_END===================================================== */ + package org.onap.pomba.contextbuilder.networkdiscovery.util; import javax.ws.rs.core.Response.Status; @@ -27,6 +28,10 @@ public class RestUtil { private static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; private static final String HEADER_PARTNER_NAME = "X-ONAP-PartnerName"; + private RestUtil() { + throw new IllegalStateException("Utility class"); + } + /** * Validates the URL parameter seriveInstanceId. * @@ -35,10 +40,11 @@ public class RestUtil { */ public static void validateServiceInstanceId(String serviceInstanceId) throws DiscoveryException { - if (serviceInstanceId == null || serviceInstanceId.trim().isEmpty()) + if (serviceInstanceId == null || serviceInstanceId.trim().isEmpty()) { throw new DiscoveryException( ErrorMessage.INVALID_REQUEST_URL + ErrorMessage.MISSING_PARAMTER + SERVICE_INSTANCE_ID, - Status.BAD_REQUEST); + Status.BAD_REQUEST); + } } /** @@ -50,7 +56,7 @@ public class RestUtil { public static void validatePartnerName(String partnerName) throws DiscoveryException { if ((partnerName == null) || partnerName.trim().isEmpty()) { - throw new DiscoveryException(ErrorMessage.MISSING_PARAMTER + HEADER_PARTNER_NAME, Status.BAD_REQUEST); + throw new DiscoveryException(ErrorMessage.MISSING_PARAMTER + HEADER_PARTNER_NAME, Status.BAD_REQUEST); } } diff --git a/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/NetworkDiscoveryRspInfoTest.java b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/NetworkDiscoveryRspInfoTest.java deleted file mode 100644 index af2ba01..0000000 --- a/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/NetworkDiscoveryRspInfoTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * ============LICENSE_START=================================================== - * Copyright (c) 2018 Amdocs - * ============================================================================ - * 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.pomba.contextbuilder.networkdiscovery.test; - -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CountDownLatch; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.pomba.contextbuilder.networkdiscovery.model.NetworkDiscoveryRspInfo; -import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -@RunWith(SpringJUnit4ClassRunner.class) -@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) -@WebAppConfiguration -@SpringBootTest -@TestPropertySource(properties = { "enricher.url=http://localhost:9505", "serviceDecomposition.host=localhost", - "networkDiscoveryMicroService.host=localhost", - "networkDiscoveryMicroService.responseTimeOutInMilliseconds=1000" }) -public class NetworkDiscoveryRspInfoTest { - NetworkDiscoveryRspInfo networkDiscoveryRspInfo = new NetworkDiscoveryRspInfo(); - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testGetRequestId() throws Exception { - String requestId = "2123"; - networkDiscoveryRspInfo.setRequestId(requestId); - assertEquals(requestId, networkDiscoveryRspInfo.getRequestId()); - } - - @Test - public void testGetResourceType() throws Exception { - String resourceType = "vserver"; - networkDiscoveryRspInfo.setResourceType(resourceType); - assertEquals(resourceType, networkDiscoveryRspInfo.getResourceType()); - } - - @Test - public void testGetResourceId() throws Exception { - String resourceId = "2123"; - networkDiscoveryRspInfo.setResourceId(resourceId); - assertEquals(resourceId, networkDiscoveryRspInfo.getResourceId()); - } - - @Test - public void testGetLatchSignal() throws Exception { - CountDownLatch latchSignal = new CountDownLatch(5); - networkDiscoveryRspInfo.setLatchSignal(latchSignal); - assertEquals(latchSignal, networkDiscoveryRspInfo.getLatchSignal()); - } - - @Test - public void testGetNetworkDiscoveryNotificationList() throws Exception { - NetworkDiscoveryNotification tmpNof = new NetworkDiscoveryNotification(); - List<NetworkDiscoveryNotification> myList = Arrays.asList(tmpNof); - - networkDiscoveryRspInfo.setNetworkDiscoveryNotificationList(myList); - networkDiscoveryRspInfo.toString(); - assertEquals(myList, networkDiscoveryRspInfo.getNetworkDiscoveryNotificationList()); - } - - @Test - public void testGetRelatedRequestIdList() throws Exception { - List<String> myList = Arrays.asList("myTest123"); - - networkDiscoveryRspInfo.setRelatedRequestIdList(myList); - assertEquals(myList, networkDiscoveryRspInfo.getRelatedRequestIdList()); - } -} diff --git a/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/jolt/TransformationTest.java b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/jolt/TransformationTest.java new file mode 100644 index 0000000..29a4a6f --- /dev/null +++ b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/jolt/TransformationTest.java @@ -0,0 +1,103 @@ +/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextbuilder.networkdiscovery.test.jolt;
+
+import com.bazaarvoice.jolt.Chainr;
+import com.bazaarvoice.jolt.JsonUtils;
+import com.google.gson.Gson;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.pomba.common.datatypes.ModelContext;
+import org.onap.pomba.contextbuilder.networkdiscovery.model.NdResources;
+
+public class TransformationTest {
+
+ private static final String CONFIG_JOLT_DIRECTORY = "config/jolt/";
+ private static final String TEST_RESOURCES = "src/test/resources/jolt/";
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+
+ @Test
+ public void testTransformNdResources() {
+
+ Object sourceObject = JsonUtils.filepathToObject(TEST_RESOURCES + "/serviceDecompResponse.json");
+ Object sourceObject1 = JsonUtils.jsonToObject(JsonUtils.toJsonString(sourceObject));
+
+ List<Object> chainrSpecJson = JsonUtils.filepathToList(CONFIG_JOLT_DIRECTORY + "sdToNdResourcesSpec.json");
+ Chainr chainr = Chainr.fromSpec(chainrSpecJson);
+ Object output = chainr.transform(sourceObject1);
+
+ String resultJson = JsonUtils.toJsonString(output);
+
+ System.err.println(resultJson);
+
+ // read the result into the NqQuery class:
+ Gson gson = new Gson();
+ NdResources ndQuery = gson.fromJson(resultJson, NdResources.class);
+
+ // convert ndQuery back to json:
+ String ndQueryToJson = gson.toJson(ndQuery);
+
+
+
+ // Compare with expected output:
+ Object expectedObject = JsonUtils.filepathToObject(TEST_RESOURCES + "serviceDecompToNdResources-expected.json");
+
+ Assert.assertEquals("Json transformation result does not match expected content",
+ JsonUtils.toPrettyJsonString(expectedObject),
+ JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(ndQueryToJson)));
+
+ }
+
+ @Test
+ public void testTransformModelContext() {
+
+ Object sourceObject = JsonUtils.filepathToObject(TEST_RESOURCES + "serviceDecompResponse.json");
+ Object sourceObject1 = JsonUtils.jsonToObject(JsonUtils.toJsonString(sourceObject));
+
+ List<Object> chainrSpecJson = JsonUtils.filepathToList(CONFIG_JOLT_DIRECTORY + "sdToModelContextSpec.json");
+ Chainr chainr = Chainr.fromSpec(chainrSpecJson);
+ Object output = chainr.transform(sourceObject1);
+
+ String resultJson = JsonUtils.toJsonString(output);
+
+ // read the result into the NqQuery class:
+ Gson gson = new Gson();
+ ModelContext ndQuery = gson.fromJson(resultJson, ModelContext.class);
+
+ // convert ndQuery back to json:
+ String ndQueryToJson = gson.toJson(ndQuery);
+
+ // Compare with expected output:
+ Object expectedObject = JsonUtils.filepathToObject(TEST_RESOURCES + "serviceDecompToModelContext-expected.json");
+
+ Assert.assertEquals("Json transformation result does not match expected content",
+ JsonUtils.toPrettyJsonString(expectedObject),
+ JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(ndQueryToJson)));
+
+ }
+
+}
diff --git a/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/unittest/service/NetworkDiscoveryContextBuilderTest.java b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/unittest/service/NetworkDiscoveryContextBuilderTest.java index 1705bde..c7475b0 100644 --- a/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/unittest/service/NetworkDiscoveryContextBuilderTest.java +++ b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/unittest/service/NetworkDiscoveryContextBuilderTest.java @@ -21,35 +21,29 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; -import com.github.jknack.handlebars.internal.Files; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.github.tomakehurst.wiremock.matching.UrlPattern; -import java.io.File; +import com.google.gson.Gson; + import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Base64; -import java.util.List; import java.util.UUID; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; + import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.pomba.common.datatypes.DataQuality; -import org.onap.pomba.contextbuilder.networkdiscovery.model.NetworkDiscoveryRspInfo; -import org.onap.pomba.contextbuilder.networkdiscovery.service.SpringServiceImpl; +import org.onap.pomba.common.datatypes.ModelContext; import org.onap.pomba.contextbuilder.networkdiscovery.service.rs.RestService; -import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute; -import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification; -import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Resource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; @@ -67,6 +61,7 @@ import org.springframework.test.context.web.WebAppConfiguration; @SpringBootTest @TestPropertySource(properties = {"serviceDecomposition.host=localhost", "serviceDecomposition.port=3333", "networkDiscoveryMicroService.host=localhost", "networkDiscoveryMicroService.port=9808", + "networkDiscoveryMicroService.httpProtocol=http", "networkDiscoveryMicroService.responseTimeOutInMilliseconds=1000"}) public class NetworkDiscoveryContextBuilderTest { @@ -75,12 +70,8 @@ public class NetworkDiscoveryContextBuilderTest { private String partnerName = "POMBA"; private String transactionId = UUID.randomUUID().toString(); private String serviceInstanceId = "c6456519-6acf-4adb-997c-3c363dd4caaf"; - private String requestId = "2131__1"; - private String resourceType = "vserver"; - private String resourceId = "25fb07ab-0478-465e-a021-6384ac299671"; HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); - NetworkDiscoveryNotification networkDiscoveryNotification = simulateNetworkDiscoveryNotification(); @Autowired Environment environment; @@ -137,12 +128,8 @@ public class NetworkDiscoveryContextBuilderTest { public void testVerifyServiceDecomposition() throws Exception { String urlStr = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId; - - File file = new File(ClassLoader.getSystemResource("SD_response.json").getFile()); - String sdResonse = Files.read(file); - - this.serviceDecompositionRule.stubFor(get(urlStr).willReturn(okJson(sdResonse))); - addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule); + addResponse(urlStr, "junit/serviceDecompositionResponse-1.json", serviceDecompositionRule); + addResponseAny("junit/networkDiscoveryResponseVserver-1.json", networkDiscoveryMicroServiceRule); Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, transactionId, null, null, serviceInstanceId, null, null); assertEquals(Status.OK.getStatusCode(), response.getStatus()); @@ -152,46 +139,73 @@ public class NetworkDiscoveryContextBuilderTest { public void testVerifyGetContext() throws Exception { String serviceDecompUrl = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId; - addResponse(serviceDecompUrl, "junit/serviceDecomposition-1.json", serviceDecompositionRule); - addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule); + addResponse(serviceDecompUrl, "junit/serviceDecompositionResponse-1.json", serviceDecompositionRule); + + String vserverPayload = readFully( + ClassLoader.getSystemResourceAsStream("junit/networkDiscoveryResponseVserver-1.json")); + networkDiscoveryMicroServiceRule.stubFor(WireMock + .any(WireMock.urlPathEqualTo("/network-discovery/v1/network/resource")) + .withQueryParam("resourceType", WireMock.equalTo("vserver")).willReturn(okJson(vserverPayload))); + + String l3networkPayload = readFully( + ClassLoader.getSystemResourceAsStream("junit/networkDiscoveryResponseL3Network.json")); + networkDiscoveryMicroServiceRule.stubFor(WireMock + .any(WireMock.urlPathEqualTo("/network-discovery/v1/network/resource")) + .withQueryParam("resourceType", WireMock.equalTo("l3-network")).willReturn(okJson(l3networkPayload))); Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, transactionId, null, null, serviceInstanceId, null, null); assertEquals(Status.OK.getStatusCode(), response.getStatus()); - } + System.out.println(response.getEntity()); + + Gson gson = new Gson(); + ModelContext modelContext = gson.fromJson((String) response.getEntity(), ModelContext.class); + assertTrue(modelContext.getVnfs().size() > 0); + assertTrue(modelContext.getVnfs().get(0).getVfModules().size() > 0); + assertTrue(modelContext.getVnfs().get(0).getVfModules().get(0).getVms().size() > 0); + + } + @Test - public void testUnauthorizedNetworkDiscoveryNotfi() throws Exception { - String networkDiscoveryCallBackUrl = "/network-discovery/service/networkDiscoveryNotification"; - addResponse(networkDiscoveryCallBackUrl, "junit/networkDiscovery-1.json", networkDiscoveryMicroServiceRule); + public void testVerifyGetContextNdResourceNotFound() throws Exception { - String badAuthorization = - "Basic " + Base64.getEncoder().encodeToString(("Test" + ":" + "Fake").getBytes(StandardCharsets.UTF_8)); - Response response = - this.restService.networkDiscoveryNotification(networkDiscoveryNotification, badAuthorization); + String serviceDecompUrl = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId; + addResponse(serviceDecompUrl, "junit/serviceDecompositionResponse-1.json", serviceDecompositionRule); + UrlPattern testPath = WireMock.anyUrl(); + networkDiscoveryMicroServiceRule.stubFor(get(testPath).willReturn(WireMock.notFound())); - assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus()); + Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, transactionId, + null, null, serviceInstanceId, null, null); + + assertEquals(Status.OK.getStatusCode(), response.getStatus()); + + Gson gson = new Gson(); + ModelContext modelContext = gson.fromJson((String)response.getEntity(), ModelContext.class); + assertTrue(modelContext.getVnfs().size() > 0); + assertTrue(modelContext.getVnfs().get(0).getVfModules().size() > 0); + assertTrue(modelContext.getVnfs().get(0).getVfModules().get(0).getVms().size() > 0); + } @Test - public void testNetworkDiscoveryNotfi() throws Exception { - NetworkDiscoveryInfoAccess networkDiscoveryInfoAccess = new NetworkDiscoveryInfoAccess(); - simulateNetworkDiscoveryInfoList(); - String networkDiscoveryCallBackUrl = "/network-discovery/service/networkDiscoveryNotification"; - addResponse(networkDiscoveryCallBackUrl, "junit/networkDiscovery-1.json", networkDiscoveryMicroServiceRule); - - Response response = this.restService.networkDiscoveryNotification(networkDiscoveryNotification, authorization); - NetworkDiscoveryRspInfo rsp = networkDiscoveryInfoAccess.getList(requestId); - assertEquals(Status.OK.getStatusCode(), response.getStatus()); - assertEquals(rsp.getNetworkDiscoveryNotificationList().size(), 1); + public void testVerifyGetContextSdResoureNofFound() throws Exception { + + UrlPattern testPath = WireMock.anyUrl(); + serviceDecompositionRule.stubFor(get(testPath).willReturn(WireMock.notFound())); + + Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, transactionId, + null, null, serviceInstanceId, null, null); + + assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); } @Test public void testVerifyNoPartnerNameWithFromAppId() throws Exception { String serviceDecompUrl = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId; - addResponse(serviceDecompUrl, "junit/serviceDecomposition-1.json", serviceDecompositionRule); - addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule); + addResponse(serviceDecompUrl, "junit/serviceDecompositionResponse-1.json", serviceDecompositionRule); + addResponseAny("junit/networkDiscoveryResponseVserver-1.json", networkDiscoveryMicroServiceRule); Response response = this.restService.getContext(httpServletRequest, authorization, null, transactionId, partnerName, null, serviceInstanceId, null, null); @@ -201,8 +215,8 @@ public class NetworkDiscoveryContextBuilderTest { @Test public void testVerifyNoRequestIdNoTransactionId() throws Exception { String serviceDecompUrl = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId; - addResponse(serviceDecompUrl, "junit/serviceDecomposition-1.json", serviceDecompositionRule); - addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule); + addResponse(serviceDecompUrl, "junit/serviceDecompositionResponse-1.json", serviceDecompositionRule); + addResponseAny("junit/networkDiscoveryResponseVserver-1.json", networkDiscoveryMicroServiceRule); Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, null, null, null, serviceInstanceId, null, null); @@ -212,8 +226,8 @@ public class NetworkDiscoveryContextBuilderTest { @Test public void testVerifyNoPartnerNameNoFromAppId() throws Exception { String serviceDecompUrl = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId; - addResponse(serviceDecompUrl, "junit/serviceDecomposition-1.json", serviceDecompositionRule); - addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule); + addResponse(serviceDecompUrl, "junit/serviceDecompositionResponse-1.json", serviceDecompositionRule); + addResponseAny("junit/networkDiscoveryResponseVserver-1.json", networkDiscoveryMicroServiceRule); Response response = this.restService.getContext(httpServletRequest, authorization, null, transactionId, null, null, serviceInstanceId, null, null); @@ -223,8 +237,8 @@ public class NetworkDiscoveryContextBuilderTest { @Test public void testVerifyNoRequestIdWithTransactionId() throws Exception { String serviceDecompUrl = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId; - addResponse(serviceDecompUrl, "junit/serviceDecomposition-1.json", serviceDecompositionRule); - addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule); + addResponse(serviceDecompUrl, "junit/serviceDecompositionResponse-1.json", serviceDecompositionRule); + addResponseAny("junit/networkDiscoveryResponseVserver-1.json", networkDiscoveryMicroServiceRule); Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, null, null, transactionId, serviceInstanceId, null, null); @@ -236,10 +250,10 @@ public class NetworkDiscoveryContextBuilderTest { thisMock.stubFor(get(path).willReturn(okJson(payload))); } - private void addResponse_any(String classpathResource, WireMockRule thisMock) throws IOException { + private void addResponseAny(String classpathResource, WireMockRule thisMock) throws IOException { String payload = readFully(ClassLoader.getSystemResourceAsStream(classpathResource)); - UrlPattern tPath = WireMock.anyUrl(); - thisMock.stubFor(get(tPath).willReturn(okJson(payload))); + UrlPattern testPath = WireMock.anyUrl(); + thisMock.stubFor(get(testPath).willReturn(okJson(payload))); } private String readFully(InputStream in) throws IOException { @@ -253,108 +267,4 @@ public class NetworkDiscoveryContextBuilderTest { } return content.toString(); } - - private NetworkDiscoveryNotification simulateNetworkDiscoveryNotification() { - Resource myResource = new Resource(); - myResource.setId("25fb07ab-0478-465e-a021-6384ac299671"); - myResource.setType("vserver"); - DataQuality dataQuality = new DataQuality(); - dataQuality.setStatus(DataQuality.Status.ok); - myResource.setDataQuality(dataQuality); - Attribute attribute = new Attribute(); - attribute.setName("vserver-id"); - attribute.setValue("25fb07ab-0478-465e-a021-6384ac299671"); - attribute.setDataQuality(dataQuality); - List<Attribute> attributeList = new ArrayList<>(); - attributeList.add(attribute); - - attribute.setName("power-state"); - attribute.setValue("1"); - attribute.setDataQuality(dataQuality); - attributeList.add(attribute); - - attribute.setName("vm-state"); - attribute.setValue("active"); - attribute.setDataQuality(dataQuality); - attributeList.add(attribute); - - attribute.setName("status"); - attribute.setValue("ACTIVE"); - attribute.setDataQuality(dataQuality); - attributeList.add(attribute); - - attribute.setName("host-status"); - attribute.setValue("UNKNOWN"); - attribute.setDataQuality(dataQuality); - attributeList.add(attribute); - - attribute.setName("updated"); - attribute.setValue("2017-11-20T04:26:13Z"); - attribute.setDataQuality(dataQuality); - attributeList.add(attribute); - - attribute.setName("disk-allocation-gb"); - attribute.setValue(".010"); - attribute.setDataQuality(dataQuality); - attributeList.add(attribute); - - attribute.setName("memory-usage-mb"); - attribute.setValue("null"); - attribute.setDataQuality(dataQuality); - attributeList.add(attribute); - - attribute.setName("cpu-util-percent"); - attribute.setValue(".048"); - attribute.setDataQuality(dataQuality); - attributeList.add(attribute); - - attribute.setName(".048"); - attribute.setValue("2018-07-26 01:37:07 +0000"); - attribute.setDataQuality(dataQuality); - attributeList.add(attribute); - myResource.setAttributeList(attributeList); - - NetworkDiscoveryNotification notification = new NetworkDiscoveryNotification(); - notification.setResources(Arrays.asList(myResource)); - notification.setAckFinalIndicator(true); - notification.setCode(200); - notification.setRequestId(requestId); - notification.setMessage("OK"); - - return notification; - } - - private void simulateNetworkDiscoveryInfoList() { - - String requestId2 = "2131__2"; - List<String> related_request_list = new ArrayList<>(); - related_request_list.add(requestId); - related_request_list.add(requestId2); - - NetworkDiscoveryRspInfo notif1 = new NetworkDiscoveryRspInfo(); - notif1.setRequestId(requestId); - notif1.setResourceType(resourceType); - notif1.setResourceId(resourceId); - notif1.setRelatedRequestIdList(related_request_list); - - NetworkDiscoveryInfoAccess networkDiscoveryInfoAccess = new NetworkDiscoveryInfoAccess(); - networkDiscoveryInfoAccess.updateList(requestId, notif1); - - NetworkDiscoveryRspInfo notif2 = new NetworkDiscoveryRspInfo(); - notif2.setRequestId(requestId2); - notif2.setResourceType(resourceType); - notif2.setResourceId(resourceId); - notif2.setRelatedRequestIdList(related_request_list); - networkDiscoveryInfoAccess.updateList(requestId2, notif2); - } - - private class NetworkDiscoveryInfoAccess extends SpringServiceImpl { - public void updateList(String requestId, NetworkDiscoveryRspInfo resp) { - super.updateNetworkDiscoveryInfoList(requestId, resp); - } - - public NetworkDiscoveryRspInfo getList(String requestId) { - return super.getNetworkDiscoveryInfoList(requestId); - } - } } diff --git a/src/test/resources/SD_response.json b/src/test/resources/SD_response.json deleted file mode 100644 index d4db960..0000000 --- a/src/test/resources/SD_response.json +++ /dev/null @@ -1,557 +0,0 @@ -{ - "relationship-list": { - "relationship": [ - { - "related-to": "generic-vnf", - "relationship-data": [ - { - "relationship-value": "6700c313-fbb7-4cf9-ac70-0293ec56df68", - "relationship-key": "generic-vnf.vnf-id" - } - ], - "related-link": "/aai/v13/network/generic-vnfs/generic-vnf/6700c313-fbb7-4cf9-ac70-0293ec56df68", - "related-to-property": [ - { - "property-key": "generic-vnf.vnf-name", - "property-value": "PacketGenerator-1" - } - ] - }, - { - "related-to": "generic-vnf", - "relationship-data": [ - { - "relationship-value": "6700c313-fbb7-4cf9-ac70-0293ec56df69", - "relationship-key": "generic-vnf.vnf-id" - } - ], - "related-link": "/aai/v13/network/generic-vnfs/generic-vnf/6700c313-fbb7-4cf9-ac70-0293ec56df69", - "related-to-property": [ - { - "property-key": "generic-vnf.vnf-name", - "property-value": "PacketGenerator-2" - } - ] - } - ] - }, - "model-version-id": "d3d6cf83-d03a-43cc-99ff-206d40bb9a72", - "service-instance-id": "c6456519-6acf-4adb-997c-3c363dd4caaf", - "resource-version": "1527637758480", - "generic-vnfs": [ - { - "nf-role": "", - "service-id": "8ea56b0d-459d-4668-b363-c9567432d8b7", - "relationship-list": { - "relationship": [ - { - "related-to": "service-instance", - "relationship-data": [ - { - "relationship-value": "Demonstration", - "relationship-key": "customer.global-customer-id" - }, - { - "relationship-value": "vFWCL", - "relationship-key": "service-subscription.service-type" - }, - { - "relationship-value": "c6456519-6acf-4adb-997c-3c363dd4caaf", - "relationship-key": "service-instance.service-instance-id" - } - ], - "related-link": "/aai/v11/business/customers/customer/Demonstration/service-subscriptions/service-subscription/vFWCL/service-instances/service-instance/c6456519-6acf-4adb-997c-3c363dd4caaf", - "related-to-property": [ - { - "property-key": "service-instance.service-instance-name", - "property-value": "Firewall1" - } - ] - }, - { - "related-to": "l3-network", - "relationship-data": [ - { - "relationship-value": "HNP1d77c-1094-41ec-b7f3-94bb30951870", - "relationship-key": "l3-network.network-id" - } - ], - "related-link": "/aai/v13/network/l3-networks/l3-network/HNP1d77c-1094-41ec-b7f3-94bb30951870", - "relationship-label": "org.onap.relationships.inventory.Uses", - "related-to-property": [ - { - "property-key": "l3-network.network-name", - "property-value": "HNPORTALOAM.OAM" - } - ] - }, - { - "related-to": "vserver", - "relationship-data": [ - { - "relationship-value": "CloudOwner", - "relationship-key": "cloud-region.cloud-owner" - }, - { - "relationship-value": "RegionOne", - "relationship-key": "cloud-region.cloud-region-id" - }, - { - "relationship-value": "b49b830686654191bb1e952a74b014ad", - "relationship-key": "tenant.tenant-id" - }, - { - "relationship-value": "25fb07ab-0478-465e-a021-6384ac299671", - "relationship-key": "vserver.vserver-id" - } - ], - "related-link": "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants/tenant/b49b830686654191bb1e952a74b014ad/vservers/vserver/25fb07ab-0478-465e-a021-6384ac299671" - }, - { - "related-to": "vserver", - "relationship-data": [ - { - "relationship-value": "CloudOwner", - "relationship-key": "cloud-region.cloud-owner" - }, - { - "relationship-value": "RegionOne", - "relationship-key": "cloud-region.cloud-region-id" - }, - { - "relationship-value": "b49b830686654191bb1e952a74b014ad", - "relationship-key": "tenant.tenant-id" - }, - { - "relationship-value": "25fb07ab-0478-465e-a021-6384ac299672", - "relationship-key": "vserver.vserver-id" - } - ], - "related-link": "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants/tenant/b49b830686654191bb1e952a74b014ad/vservers/vserver/25fb07ab-0478-465e-a021-6384ac299672" - } - ] - }, - "vnf-id": "6700c313-fbb7-4cf9-ac70-0293ec56df68", - "nf-type": "", - "l3-networks": [ - { - "network-role": "HNPORTALOAM.OAM", - "network-technology": "ovs", - "service-id": "V7611HNP-1222-48f1-8085-94aef0c6ef3d51870", - "network-id": "HNP1d77c-1222-41ec-b7f3-94bb30951870", - "neutron-network-id": "491c7cef-a3f4-4990-883e-b0af397466d0", - "is-external-network": false, - "is-bound-to-vpn": false, - "is-provider-network": false, - "network-type": "OVS_PROVIDER_VLAN", - "orchestration-status": "active", - "network-role-instance": 0, - "resource-version": "1526558298075", - "network-name": "HNPORTALOAM.OAM", - "is-shared-network": false - } - ], - "prov-status": "PREPROV", - "vnf-type": "vFW-vSINK-service/vPKG 0", - "orchestration-status": "Created", - "nf-naming-code": "", - "in-maint": false, - "nf-function": "", - "model-version-id": "a5565bf4-d55a-4964-8fbc-6a7674a2e676", - "vservers": [ - { - "relationship-list": { - "relationship": [ - { - "related-to": "generic-vnf", - "relationship-data": [ - { - "relationship-value": "8a9ddb25-2e79-449c-a40d-5011bac0da39", - "relationship-key": "generic-vnf.vnf-id" - } - ], - "related-link": "/aai/v11/network/generic-vnfs/generic-vnf/8a9ddb25-2e79-449c-a40d-5011bac0da39", - "related-to-property": [ - { - "property-key": "generic-vnf.vnf-name", - "property-value": "Firewall-1" - } - ] - }, - { - "related-to": "flavor", - "relationship-data": [ - { - "relationship-value": "CloudOwner", - "relationship-key": "cloud-region.cloud-owner" - }, - { - "relationship-value": "RegionOne", - "relationship-key": "cloud-region.cloud-region-id" - }, - { - "relationship-value": "764efb04-5a46-4806-a766-2bdd24559f39", - "relationship-key": "flavor.flavor-id" - } - ], - "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/flavors/flavor/764efb04-5a46-4806-a766-2bdd24559f39", - "related-to-property": [ - { - "property-key": "flavor.flavor-name", - "property-value": "m1.medium" - } - ] - }, - { - "related-to": "image", - "relationship-data": [ - { - "relationship-value": "CloudOwner", - "relationship-key": "cloud-region.cloud-owner" - }, - { - "relationship-value": "RegionOne", - "relationship-key": "cloud-region.cloud-region-id" - }, - { - "relationship-value": "42fd42f8-cf81-4f4c-a552-d4b124f83b0b", - "relationship-key": "image.image-id" - } - ], - "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/images/image/42fd42f8-cf81-4f4c-a552-d4b124f83b0b", - "related-to-property": [ - { - "property-key": "image.image-name", - "property-value": "unknown" - } - ] - } - ] - }, - "in-maint": false, - "resource-version": "1528481820321", - "vserver-name": "Firewall-0", - "prov-status": "ACTIVE", - "vserver-id": "25fb07ab-0478-465e-a021-6384ac299671", - "vserver-name2": "Firewall-0", - "vserver-selflink": "http://10.12.25.2:8774/v2.1/b49b830686654191bb1e952a74b014ad/servers/25fb07ab-0478-465e-a021-6384ac299671", - "is-closed-loop-disabled": false - }, - { - "relationship-list": { - "relationship": [ - { - "related-to": "generic-vnf", - "relationship-data": [ - { - "relationship-value": "8a9ddb25-2e79-449c-a40d-5011bac0da39", - "relationship-key": "generic-vnf.vnf-id" - } - ], - "related-link": "/aai/v11/network/generic-vnfs/generic-vnf/8a9ddb25-2e79-449c-a40d-5011bac0da39", - "related-to-property": [ - { - "property-key": "generic-vnf.vnf-name", - "property-value": "Firewall-1" - } - ] - }, - { - "related-to": "flavor", - "relationship-data": [ - { - "relationship-value": "CloudOwner", - "relationship-key": "cloud-region.cloud-owner" - }, - { - "relationship-value": "RegionOne", - "relationship-key": "cloud-region.cloud-region-id" - }, - { - "relationship-value": "764efb04-5a46-4806-a766-2bdd24559f39", - "relationship-key": "flavor.flavor-id" - } - ], - "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/flavors/flavor/764efb04-5a46-4806-a766-2bdd24559f39", - "related-to-property": [ - { - "property-key": "flavor.flavor-name", - "property-value": "m1.medium" - } - ] - }, - { - "related-to": "image", - "relationship-data": [ - { - "relationship-value": "CloudOwner", - "relationship-key": "cloud-region.cloud-owner" - }, - { - "relationship-value": "RegionOne", - "relationship-key": "cloud-region.cloud-region-id" - }, - { - "relationship-value": "42fd42f8-cf81-4f4c-a552-d4b124f83b0b", - "relationship-key": "image.image-id" - } - ], - "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/images/image/42fd42f8-cf81-4f4c-a552-d4b124f83b0b", - "related-to-property": [ - { - "property-key": "image.image-name", - "property-value": "unknown" - } - ] - } - ] - }, - "in-maint": false, - "resource-version": "1528481820321", - "vserver-name": "Firewall-0", - "prov-status": "ACTIVE", - "vserver-id": "25fb07ab-0478-465e-a021-6384ac299672", - "vserver-name2": "Firewall-0", - "vserver-selflink": "http://10.12.25.2:8774/v2.1/b49b830686654191bb1e952a74b014ad/servers/25fb07ab-0478-465e-a021-6384ac299672", - "is-closed-loop-disabled": false - } - ], - "resource-version": "1527638176989", - "model-customization-id": "4cc1e555-361f-4d69-ae21-9f371ea9f40c", - "vf-modules": { - "vf-module": [ - { - "vf-module-name": "vPacketGen-VNF-1128-3", - "model-version-id": "d6d4a002-a584-4640-bdce-a50e9bce552b", - "heat-stack-id": "vPacketGen-VNF-1128-3/df34f5d6-ed39-4184-b785-51c37cfa8ac2", - "resource-version": "1527641224058", - "model-customization-id": "49c8f521-e5ee-4095-bb87-4090166e49ab", - "is-base-vf-module": true, - "vf-module-id": "0f792076-f5b3-4251-9fcc-c4d5afae0eb1", - "module-index": 0, - "model-invariant-id": "2a8844a8-f5f7-46dd-a732-472c6972a28e", - "orchestration-status": "active" - } - ] - }, - "vserver": [ - { - "vserver-name": "Firewall-1", - "vserver-id": "25fb07ab-0478-465e-a021-6384ac299671", - "model-invariant-id": "0c5a20de-87ad-442c-9190-f38ab0a6bb7f" - } - ], - "model-invariant-id": "99f1fd3f-845c-48f5-a0ba-11fbde6ae557", - "vnf-name": "PacketGenerator-1", - "is-closed-loop-disabled": false - }, - { - "nf-role": "", - "service-id": "8ea56b0d-459d-4668-b363-c9567432d8b9", - "relationship-list": { - "relationship": [ - { - "related-to": "service-instance", - "relationship-data": [ - { - "relationship-value": "Demonstration", - "relationship-key": "customer.global-customer-id" - }, - { - "relationship-value": "vFWCL", - "relationship-key": "service-subscription.service-type" - }, - { - "relationship-value": "c6456519-6acf-4adb-997c-3c363dd4caaf", - "relationship-key": "service-instance.service-instance-id" - } - ], - "related-link": "/aai/v11/business/customers/customer/Demonstration/service-subscriptions/service-subscription/vFWCL/service-instances/service-instance/c6456519-6acf-4adb-997c-3c363dd4caaf", - "related-to-property": [ - { - "property-key": "service-instance.service-instance-name", - "property-value": "Firewall1" - } - ] - }, - { - "related-to": "l3-network", - "relationship-data": [ - { - "relationship-value": "HNP1d77c-1094-41ec-b7f3-94bb30951870", - "relationship-key": "l3-network.network-id" - } - ], - "related-link": "/aai/v13/network/l3-networks/l3-network/HNP1d77c-1094-41ec-b7f3-94bb30951871", - "relationship-label": "org.onap.relationships.inventory.Uses", - "related-to-property": [ - { - "property-key": "l3-network.network-name", - "property-value": "HNPORTALOAM.OAM" - } - ] - }, - { - "related-to": "vserver", - "relationship-data": [ - { - "relationship-value": "CloudOwner", - "relationship-key": "cloud-region.cloud-owner" - }, - { - "relationship-value": "RegionOne", - "relationship-key": "cloud-region.cloud-region-id" - }, - { - "relationship-value": "b49b830686654191bb1e952a74b014ad", - "relationship-key": "tenant.tenant-id" - }, - { - "relationship-value": "25fb07ab-0478-465e-a021-6384ac299671", - "relationship-key": "vserver.vserver-id" - } - ], - "related-link": "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants/tenant/b49b830686654191bb1e952a74b014ad/vservers/vserver/b494cd6e-b9f3-45e0-afe7-e1d1a5f5d74b" - } - ] - }, - "vnf-id": "6700c313-fbb7-4cf9-ac70-0293ec56df69", - "nf-type": "", - "l3-networks": [ - { - "network-role": "HNPORTALOAM.OAM", - "network-technology": "ovs", - "service-id": "V7611HNP-1222-48f1-8085-94aef0c6ef3d51870", - "network-id": "HNP1d77c-1222-41ec-b7f3-94bb30951870", - "neutron-network-id": "491c7cef-a3f4-4990-883e-b0af397466d0", - "is-external-network": false, - "is-bound-to-vpn": false, - "is-provider-network": false, - "network-type": "OVS_PROVIDER_VLAN", - "orchestration-status": "active", - "network-role-instance": 0, - "resource-version": "1526558298075", - "network-name": "HNPORTALOAM.OAM", - "is-shared-network": false - } - ], - "prov-status": "PREPROV", - "vnf-type": "vFW-vSINK-service/vPKG 0", - "orchestration-status": "Created", - "nf-naming-code": "", - "in-maint": false, - "nf-function": "", - "model-version-id": "a5565bf4-d55a-4964-8fbc-6a7674a2e676", - "vservers": [ - { - "relationship-list": { - "relationship": [ - { - "related-to": "generic-vnf", - "relationship-data": [ - { - "relationship-value": "8a9ddb25-2e79-449c-a40d-5011bac0da39", - "relationship-key": "generic-vnf.vnf-id" - } - ], - "related-link": "/aai/v11/network/generic-vnfs/generic-vnf/8a9ddb25-2e79-449c-a40d-5011bac0da39", - "related-to-property": [ - { - "property-key": "generic-vnf.vnf-name", - "property-value": "Firewall-1" - } - ] - }, - { - "related-to": "flavor", - "relationship-data": [ - { - "relationship-value": "CloudOwner", - "relationship-key": "cloud-region.cloud-owner" - }, - { - "relationship-value": "RegionOne", - "relationship-key": "cloud-region.cloud-region-id" - }, - { - "relationship-value": "764efb04-5a46-4806-a766-2bdd24559f39", - "relationship-key": "flavor.flavor-id" - } - ], - "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/flavors/flavor/764efb04-5a46-4806-a766-2bdd24559f39", - "related-to-property": [ - { - "property-key": "flavor.flavor-name", - "property-value": "m1.medium" - } - ] - }, - { - "related-to": "image", - "relationship-data": [ - { - "relationship-value": "CloudOwner", - "relationship-key": "cloud-region.cloud-owner" - }, - { - "relationship-value": "RegionOne", - "relationship-key": "cloud-region.cloud-region-id" - }, - { - "relationship-value": "42fd42f8-cf81-4f4c-a552-d4b124f83b0b", - "relationship-key": "image.image-id" - } - ], - "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/images/image/42fd42f8-cf81-4f4c-a552-d4b124f83b0b", - "related-to-property": [ - { - "property-key": "image.image-name", - "property-value": "unknown" - } - ] - } - ] - }, - "in-maint": false, - "resource-version": "1528481820321", - "vserver-name": "Firewall-0", - "prov-status": "ACTIVE", - "vserver-id": "b494cd6e-b9f3-45e0-afe7-e1d1a5f5d74b", - "vserver-name2": "Firewall-0", - "vserver-selflink": "http://10.12.25.2:8774/v2.1/b49b830686654191bb1e952a74b014ad/servers/25fb07ab-0478-465e-a021-6384ac299671", - "is-closed-loop-disabled": false - } - ], - "resource-version": "1527638176989", - "model-customization-id": "4cc1e555-361f-4d69-ae21-9f371ea9f40c", - "vf-modules": { - "vf-module": [ - { - "vf-module-name": "vPacketGen-VNF-1128-3", - "model-version-id": "d6d4a002-a584-4640-bdce-a50e9bce552b", - "heat-stack-id": "vPacketGen-VNF-1128-3/df34f5d6-ed39-4184-b785-51c37cfa8ac2", - "resource-version": "1527641224058", - "model-customization-id": "49c8f521-e5ee-4095-bb87-4090166e49ab", - "is-base-vf-module": true, - "vf-module-id": "0f792076-f5b3-4251-9fcc-c4d5afae0eb1", - "module-index": 0, - "model-invariant-id": "2a8844a8-f5f7-46dd-a732-472c6972a28e", - "orchestration-status": "active" - } - ] - }, - "vserver": [ - { - "vserver-name": "Firewall-1", - "vserver-id": "25fb07ab-0478-465e-a021-6384ac299672", - "model-invariant-id": "0c5a20de-87ad-442c-9190-f38ab0a6bb7f" - } - ], - "model-invariant-id": "99f1fd3f-845c-48f5-a0ba-11fbde6ae557", - "vnf-name": "PacketGenerator-2", - "is-closed-loop-disabled": false - } - ], - "model-invariant-id": "0c5a20de-87ad-442c-9190-f38ab0a6bb7f", - "service-instance-name": "Firewall1" -}
\ No newline at end of file diff --git a/src/test/resources/jolt/serviceDecompResponse.json b/src/test/resources/jolt/serviceDecompResponse.json new file mode 100644 index 0000000..2e2f38c --- /dev/null +++ b/src/test/resources/jolt/serviceDecompResponse.json @@ -0,0 +1,211 @@ +{
+ "model-version-id": "e2d52f32-a952-46f5-800c-c250903625d6",
+ "service-instance-id": "PombaDemoCust_001-SerivceInst-001",
+ "resource-version": "1545324562797",
+ "generic-vnfs": [
+ {
+ "nf-role": "",
+ "service-id": "8ea56b0d-459d-4668-b363-c9567432d8b7",
+ "vnf-id": "PombaDemoCust_001-VNF-id-001",
+ "nf-type": "",
+ "l3-networks": [
+ {
+ "network-role": "",
+ "network-technology": "",
+ "network-id": "2ea02809-7279-4b5e-931a-62b231615497",
+ "is-external-network": false,
+ "is-bound-to-vpn": false,
+ "is-provider-network": false,
+ "network-type": "",
+ "model-version-id": "pomba-demo-sdc-model-001-version001",
+ "resource-version": "1547484061985",
+ "model-customization-id": "3b822416-475d-4e1c-aac3-2544b0a0fdfc",
+ "network-name": "NET_1105",
+ "is-shared-network": true,
+ "model-invariant-id": "pomba-demo-sdc-model-001"
+ },
+ {
+ "network-role": "",
+ "network-technology": "",
+ "network-id": "01e8d84a-17a6-47b5-a167-6a45d1d56603",
+ "is-external-network": false,
+ "is-bound-to-vpn": false,
+ "is-provider-network": false,
+ "network-type": "",
+ "model-version-id": "pomba-demo-sdc-model-001-version001",
+ "resource-version": "1547484429696",
+ "model-customization-id": "3b822416-475d-4e1c-aac3-2544b0a0fdfc",
+ "network-name": "NET_1106",
+ "is-shared-network": true,
+ "model-invariant-id": "pomba-demo-sdc-model-001"
+ }
+ ],
+ "prov-status": "PREPROV",
+ "vnf-type": "vFW-vSINK-service/vFWvSINK 0",
+ "orchestration-status": "Created",
+ "nf-naming-code": "",
+ "in-maint": false,
+ "nf-function": "",
+ "model-version-id": "pomba-demo-sdc-model-001-version001",
+ "vservers": [
+ {
+ "in-maint": false,
+ "resource-version": "1545323228761",
+ "vserver-name": "Firewall-001",
+ "prov-status": "ACTIVE",
+ "vserver-id": "a6a609e3-967a-48bd-8ce5-41c7ff5c19b9",
+ "vserver-name2": "Firewall-001",
+ "vserver-selflink": "http://10.12.25.2:8774/v2.1/a6a609e3-967a-48bd-8ce5-41c7ff5c19b9/servers/a6a609e3-967a-48bd-8ce5-41c7ff5c19b9",
+ "is-closed-loop-disabled": false
+ }
+ ],
+ "resource-version": "1547828735448",
+ "model-customization-id": "3b822416-475d-4e1c-aac3-2544b0a0fdfc",
+ "vf-modules": {
+ "vf-module": [
+ {
+ "vf-module-name": "PombaDemoCust_001-VNF-id-001-VfModule001-name",
+ "model-version-id": "pomba-demo-sdc-model-001-version001",
+ "heat-stack-id": "HeatStackId-001",
+ "resource-version": "1547828735835",
+ "model-customization-id": "3b822416-475d-4e1c-aac3-2544b0a0fdfc",
+ "is-base-vf-module": true,
+ "vf-module-id": "PombaDemoCust_001-VNF-id-001-VfModule001",
+ "module-index": 0,
+ "model-invariant-id": "pomba-demo-sdc-model-001",
+ "orchestration-status": "Active",
+ "automated-assignment": true
+ }
+ ]
+ },
+ "model-invariant-id": "pomba-demo-sdc-model-001",
+ "vnf-name": "Firewall-1",
+ "is-closed-loop-disabled": false
+ },
+ {
+ "nf-role": "",
+ "service-id": "8ea56b0d-459d-4668-b363-c9567432d8b7",
+ "vnf-id": "PombaDemoCust_001-VNF-id-001-2",
+ "nf-type": "",
+ "l3-networks": [
+ {
+ "network-role": "",
+ "network-technology": "",
+ "network-id": "2ea02809-7279-4b5e-931a-62b231615497-1",
+ "is-external-network": false,
+ "is-bound-to-vpn": false,
+ "is-provider-network": false,
+ "network-type": "",
+ "model-version-id": "pomba-demo-sdc-model-001-version001",
+ "resource-version": "1547484061985",
+ "model-customization-id": "3b822416-475d-4e1c-aac3-2544b0a0fdfc",
+ "network-name": "NET_1105",
+ "is-shared-network": true,
+ "model-invariant-id": "pomba-demo-sdc-model-001"
+ },
+ {
+ "network-role": "",
+ "network-technology": "",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "service-instance",
+ "relationship-data": [
+ {
+ "relationship-value": "PombaDemoCust_001",
+ "relationship-key": "customer.global-customer-id"
+ },
+ {
+ "relationship-value": "SDN-ETHERNET-INTERNET",
+ "relationship-key": "service-subscription.service-type"
+ },
+ {
+ "relationship-value": "PombaDemoCust_001-SerivceInst-001",
+ "relationship-key": "service-instance.service-instance-id"
+ }
+ ],
+ "related-link": "/aai/v13/business/customers/customer/PombaDemoCust_001/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET/service-instances/service-instance/PombaDemoCust_001-SerivceInst-001",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf",
+ "related-to-property": [
+ {
+ "property-key": "service-instance.service-instance-name"
+ }
+ ]
+ },
+ {
+ "related-to": "generic-vnf",
+ "relationship-data": [
+ {
+ "relationship-value": "PombaDemoCust_001-VNF-id-001",
+ "relationship-key": "generic-vnf.vnf-id"
+ }
+ ],
+ "related-link": "/aai/v13/network/generic-vnfs/generic-vnf/PombaDemoCust_001-VNF-id-001",
+ "relationship-label": "org.onap.relationships.inventory.Uses",
+ "related-to-property": [
+ {
+ "property-key": "generic-vnf.vnf-name",
+ "property-value": "Firewall-1"
+ }
+ ]
+ },
+ {
+ "related-to": "generic-vnf",
+ "relationship-data": [
+ {
+ "relationship-value": "PombaDemoCust_001-VNF-id-001-2",
+ "relationship-key": "generic-vnf.vnf-id"
+ }
+ ],
+ "related-link": "/aai/v13/network/generic-vnfs/generic-vnf/PombaDemoCust_001-VNF-id-001-2",
+ "relationship-label": "org.onap.relationships.inventory.Uses",
+ "related-to-property": [
+ {
+ "property-key": "generic-vnf.vnf-name",
+ "property-value": "Firewall-2"
+ }
+ ]
+ }
+ ]
+ },
+ "network-id": "01e8d84a-17a6-47b5-a167-6a45d1d56603-1",
+ "is-external-network": false,
+ "is-bound-to-vpn": false,
+ "is-provider-network": false,
+ "network-type": "",
+ "model-version-id": "pomba-demo-sdc-model-001-version001",
+ "resource-version": "1547484429696",
+ "model-customization-id": "3b822416-475d-4e1c-aac3-2544b0a0fdfc",
+ "network-name": "NET_1106",
+ "is-shared-network": true,
+ "model-invariant-id": "pomba-demo-sdc-model-001"
+ }
+ ],
+ "prov-status": "PREPROV",
+ "vnf-type": "vFW-vSINK-service/vFWvSINK 0",
+ "orchestration-status": "Created",
+ "nf-naming-code": "",
+ "in-maint": false,
+ "nf-function": "",
+ "model-version-id": "pomba-demo-sdc-model-001-version001",
+ "vservers": [
+ {
+ "in-maint": true,
+ "resource-version": "1547822239190",
+ "vserver-name": "Firewall-001-2",
+ "prov-status": "UNKNOWN",
+ "vserver-id": "a6a609e3-967a-48bd-8ce5-41c7ff5c19b9-2",
+ "vserver-name2": "Firewall-001-2",
+ "vserver-selflink": "http://10.12.25.2:8774/v2.1/a6a609e3-967a-48bd-8ce5-41c7ff5c19b9/servers/a6a609e3-967a-48bd-8ce5-41c7ff5c19b9-2",
+ "is-closed-loop-disabled": false
+ }
+ ],
+ "resource-version": "1547822479098",
+ "model-customization-id": "3b822416-475d-4e1c-aac3-2544b0a0fdfc",
+ "model-invariant-id": "pomba-demo-sdc-model-001",
+ "vnf-name": "Firewall-2",
+ "is-closed-loop-disabled": false
+ }
+ ],
+ "model-invariant-id": "59dd4d63-8f21-406c-98c0-3b057bb86820"
+}
\ No newline at end of file diff --git a/src/test/resources/jolt/serviceDecompToModelContext-expected.json b/src/test/resources/jolt/serviceDecompToModelContext-expected.json new file mode 100644 index 0000000..31f1318 --- /dev/null +++ b/src/test/resources/jolt/serviceDecompToModelContext-expected.json @@ -0,0 +1,108 @@ +{
+ "service" : {
+ "uuid" : "PombaDemoCust_001-SerivceInst-001",
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ]
+ },
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "vnfList" : [ {
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "vfModuleList" : [ {
+ "maxInstances" : 0,
+ "minInstances" : 0,
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "vmList" : [ {
+ "uuid" : "a6a609e3-967a-48bd-8ce5-41c7ff5c19b9",
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "pServer" : {
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "pInterfaceList" : [ ],
+ "logicalLinkList" : [ ]
+ },
+ "lInterfaceList" : [ ]
+ } ],
+ "networkList" : [ {
+ "uuid" : "2ea02809-7279-4b5e-931a-62b231615497",
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "networkPolicyList" : [ ]
+ }, {
+ "uuid" : "01e8d84a-17a6-47b5-a167-6a45d1d56603",
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "networkPolicyList" : [ ]
+ } ]
+ } ],
+ "vnfcList" : [ ],
+ "networkList" : [ ]
+ }, {
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "vfModuleList" : [ {
+ "maxInstances" : 0,
+ "minInstances" : 0,
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "vmList" : [ {
+ "uuid" : "a6a609e3-967a-48bd-8ce5-41c7ff5c19b9-2",
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "pServer" : {
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "pInterfaceList" : [ ],
+ "logicalLinkList" : [ ]
+ },
+ "lInterfaceList" : [ ]
+ } ],
+ "networkList" : [ {
+ "uuid" : "2ea02809-7279-4b5e-931a-62b231615497-1",
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "networkPolicyList" : [ ]
+ }, {
+ "uuid" : "01e8d84a-17a6-47b5-a167-6a45d1d56603-1",
+ "dataQuality" : {
+ "status" : "ok"
+ },
+ "attributeList" : [ ],
+ "networkPolicyList" : [ ]
+ } ]
+ } ],
+ "vnfcList" : [ ],
+ "networkList" : [ ]
+ } ],
+ "pnfList" : [ ],
+ "networkList" : [ ]
+}
\ No newline at end of file diff --git a/src/test/resources/jolt/serviceDecompToNdResources-expected.json b/src/test/resources/jolt/serviceDecompToNdResources-expected.json new file mode 100644 index 0000000..1351350 --- /dev/null +++ b/src/test/resources/jolt/serviceDecompToNdResources-expected.json @@ -0,0 +1,21 @@ +{
+ "ndResources" : [ {
+ "resourceId" : "a6a609e3-967a-48bd-8ce5-41c7ff5c19b9",
+ "resourceType" : "vserver"
+ }, {
+ "resourceId" : "2ea02809-7279-4b5e-931a-62b231615497",
+ "resourceType" : "l3-network"
+ }, {
+ "resourceId" : "01e8d84a-17a6-47b5-a167-6a45d1d56603",
+ "resourceType" : "l3-network"
+ }, {
+ "resourceId" : "a6a609e3-967a-48bd-8ce5-41c7ff5c19b9-2",
+ "resourceType" : "vserver"
+ }, {
+ "resourceId" : "2ea02809-7279-4b5e-931a-62b231615497-1",
+ "resourceType" : "l3-network"
+ }, {
+ "resourceId" : "01e8d84a-17a6-47b5-a167-6a45d1d56603-1",
+ "resourceType" : "l3-network"
+ } ]
+}
\ No newline at end of file diff --git a/src/test/resources/junit/networkDiscovery-1.json b/src/test/resources/junit/networkDiscovery-1.json deleted file mode 100644 index 6dd844f..0000000 --- a/src/test/resources/junit/networkDiscovery-1.json +++ /dev/null @@ -1,83 +0,0 @@ -{ - "requestId": "2131_1", - "code": 200, - "message": "OK", - "ackFinalIndicator": true, - "resources": [{ - "id": "25fb07ab-0478-465e-a021-6384ac299671", - "type": "vserver", - "dataQuality": { - "status": "ok" - }, - "attributeList": [{ - "name": "vserver-id", - "value": "25fb07ab-0478-465e-a021-6384ac299671", - "dataQuality": { - "status": "ok" - } - }, - { - "name": "power-state", - "value": "1", - "dataQuality": { - "status": "ok" - } - }, - { - "name": "vm-state", - "value": "active", - "dataQuality": { - "status": "ok" - } - }, - { - "name": "status", - "value": "ACTIVE", - "dataQuality": { - "status": "ok" - } - }, - { - "name": "host-status", - "value": "UNKNOWN", - "dataQuality": { - "status": "ok" - } - }, - { - "name": "updated", - "value": "2017-11-20T04:26:13Z", - "dataQuality": { - "status": "ok" - } - }, - { - "name": "disk-allocation-gb", - "value": ".010", - "dataQuality": { - "status": "ok" - } - }, - { - "name": "memory-usage-mb", - "value": "null", - "dataQuality": { - "status": "ok" - } - }, - { - "name": "cpu-util-percent", - "value": ".048", - "dataQuality": { - "status": "ok" - } - }, - { - "name": "retrieval-timestamp", - "value": "2018-07-26 01:37:07 +0000", - "dataQuality": { - "status": "ok" - } - }] - }] -}
\ No newline at end of file diff --git a/src/test/resources/junit/networkDiscoveryResponse-1.json b/src/test/resources/junit/networkDiscoveryResponse-1.json deleted file mode 100644 index 12da468..0000000 --- a/src/test/resources/junit/networkDiscoveryResponse-1.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "requestId": "2131_1", - "code": 202, - "message": "Accepted", - "ackFinalIndicator": false -}
\ No newline at end of file diff --git a/src/test/resources/junit/networkDiscoveryResponseL3Network.json b/src/test/resources/junit/networkDiscoveryResponseL3Network.json new file mode 100644 index 0000000..e7087e2 --- /dev/null +++ b/src/test/resources/junit/networkDiscoveryResponseL3Network.json @@ -0,0 +1,83 @@ +{ + "requestId": "88001", + "code": 200, + "message": "OK", + "ackFinalIndicator": true, + "resources": [ + { + "id": "01e8d84a-17a6-47b5-a167-6a45d1d56603", + "name": null, + "type": "l3-network", + "dataQuality": { + "status": "ok", + "errorText": null + }, + "attributeList": [ + { + "name": "id", + "value": "01e8d84a-17a6-47b5-a167-6a45d1d56603", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "name", + "value": "NET_1106", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "AdminState", + "value": "true", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "sharedNetwork", + "value": "true", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "status", + "value": "ACTIVE", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "subnets", + "value": "089c9160-6f7a-4ae0-83b7-33536b4c6672", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "tenantId", + "value": "cbd5e07f58d84ea6b795aa9f5f207df0", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "host-status", + "value": "UNKNOWN", + "dataQuality": { + "status": "ok", + "errorText": null + } + } + ] + } + ] +}
\ No newline at end of file diff --git a/src/test/resources/junit/networkDiscoveryResponseVserver-1.json b/src/test/resources/junit/networkDiscoveryResponseVserver-1.json new file mode 100644 index 0000000..7861c71 --- /dev/null +++ b/src/test/resources/junit/networkDiscoveryResponseVserver-1.json @@ -0,0 +1,99 @@ +{ + "requestId": "2131_1", + "code": 200, + "message": "OK", + "ackFinalIndicator": true, + "resources": [ + { + "id": "25fb07ab-0478-465e-a021-6384ac299671", + "name": "vserver-name", + "type": "vserver", + "dataQuality": { + "status": "ok", + "errorText": null + }, + "attributeList": [ + { + "name": "id", + "value": "2c311eae-f542-4173-8a01-582922abd495", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "name", + "value": "norm-d2-k8s", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "hostname", + "value": "norm_bouygues", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "inMaintenance", + "value": "false", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "imageId", + "value": "c0022890-d91f-422c-91c5-3866edeae768", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "status", + "value": "ACTIVE", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "vmState", + "value": "active", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "tenantId", + "value": "15ad36d394e744838e947ca90609f805", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "hostId", + "value": "ea1660efbbedda164379afacdc622305c4b88cebfb84119472d286a8", + "dataQuality": { + "status": "ok", + "errorText": null + } + }, + { + "name": "hostStatus", + "value": "UNKNOWN", + "dataQuality": { + "status": "ok", + "errorText": null + } + } + ] + } + ] +}
\ No newline at end of file diff --git a/src/test/resources/junit/serviceDecomposition-1.json b/src/test/resources/junit/serviceDecompositionResponse-1.json index 10ebe4a..3303e26 100644 --- a/src/test/resources/junit/serviceDecomposition-1.json +++ b/src/test/resources/junit/serviceDecompositionResponse-1.json @@ -348,7 +348,7 @@ "network-role": "HNPORTALOAM.OAM", "network-technology": "ovs", "service-id": "V7611HNP-1222-48f1-8085-94aef0c6ef3d51870", - "network-id": "HNP1d77c-1222-41ec-b7f3-94bb30951870", + "network-id": "01e8d84a-17a6-47b5-a167-6a45d1d56603", "neutron-network-id": "491c7cef-a3f4-4990-883e-b0af397466d0", "is-external-network": false, "is-bound-to-vpn": false, |