aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorNorm Traxler <normant@amdocs.com>2019-01-21 21:03:59 +0000
committerNorm Traxler <normant@amdocs.com>2019-01-22 14:23:19 +0000
commit5c07f0088fd71e30bfd8dc92b870f604b4297420 (patch)
tree8f4fca51f25c591888b6dad00c6b94ee0db6a1ce /src/main
parentcdad28821c2ac6834e284aae72f10ad2d0529147 (diff)
NetworkDiscCtxBuilder error handling
Issue-ID: LOG-938 Change-Id: I20e8592efe5f1ca8960f228041303c8d25628018 Signed-off-by: Norm Traxler <normant@amdocs.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/docker/Dockerfile3
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/Application.java1
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/JerseyConfiguration.java20
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/NdctxbConfiguration.java49
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/WebConfiguration.java1
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/exception/DiscoveryException.java35
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/exception/ErrorMessage.java1
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdQuery.java45
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResource.java5
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResources.java4
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResourcesList.java45
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NetworkDiscoveryRspInfo.java93
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringService.java1
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java358
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/rs/RestService.java5
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/rs/RestServiceImpl.java45
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/util/RestUtil.java8
17 files changed, 244 insertions, 475 deletions
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 f5e8247..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;
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 2bec9ad..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,18 +15,15 @@
* limitations under the License.
* ============LICENSE_END=====================================================
*/
+
package org.onap.pomba.contextbuilder.networkdiscovery;
-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;
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;
@@ -36,6 +33,7 @@ import javax.net.ssl.X509TrustManager;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
+
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.server.ResourceConfig;
@@ -43,7 +41,6 @@ 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;
@Component
@@ -59,17 +56,6 @@ 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;
- }
-
- @Bean
public Client jerseyClient() {
return ClientBuilder.newClient(new ClientConfig());
}
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 f123e62..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,29 +18,17 @@
package org.onap.pomba.contextbuilder.networkdiscovery;
-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.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 static final String PREFIX_RESOURCE_TYPE = "networkDiscoveryCtxBuilder.resourceTypeMapping.";
- private static final String WHITE_SPACE = "\\s";
// Network Discovery Context Builder Configuration values
@@ -59,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}")
@@ -134,12 +118,6 @@ public class NdctxbConfiguration {
+ this.networkDiscoveryCtxBuilderPort;
}
- @Bean(name = "networkDiscoveryCtxBuilderResources")
- public String getNetworkDiscoveryCtxBuilderResourcs() {
- return this.networkDiscoveryCtxBuilderResourceList;
- }
-
-
@Bean(name = "networkDiscoveryMicroServiceBaseUrl")
public String getNetworkDiscoveryURL() {
return this.httpNetworkDiscoveryMicroServiceProtocol + "://" + this.networkDiscoveryMicroServiceHost + ":"
@@ -166,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(PREFIX_RESOURCE_TYPE)) {
- String myKey = propName.substring(PREFIX_RESOURCE_TYPE.length()).replaceAll(WHITE_SPACE,"");
- String myValue = this.env.getProperty(propName).replaceAll(WHITE_SPACE, "");
- 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 7bf9e96..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,6 +15,7 @@
* limitations under the License.
* ============LICENSE_END=====================================================
*/
+
package org.onap.pomba.contextbuilder.networkdiscovery.exception;
public class ErrorMessage {
diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdQuery.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdQuery.java
deleted file mode 100644
index f40af2b..0000000
--- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdQuery.java
+++ /dev/null
@@ -1,45 +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 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="NdQuery")
-public class NdQuery {
-
- @Expose
- @SerializedName("ndQuery")
- private List<NdResourcesList> ndQuery = new ArrayList<>();
-
- @ApiModelProperty(value = "List of NdResource associated with the service instance")
- public List<NdResourcesList> getNdQuery() {
- return ndQuery;
- }
- public void setNdQuery(List<NdResourcesList> ndQuery) {
- this.ndQuery = ndQuery;
- }
- public void addNdQuery(NdResourcesList ndResourcesList) {
- this.ndQuery.add(ndResourcesList);
- }
-}
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
index a4575b6..9f79849 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResource.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResource.java
@@ -23,7 +23,7 @@ import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
-@ApiModel(value="NdResource")
+@ApiModel(value = "NdResource")
public class NdResource {
@Expose
@@ -37,13 +37,16 @@ public class NdResource {
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
index a1592fc..54e627d 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResources.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResources.java
@@ -25,7 +25,7 @@ import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
-@ApiModel(value="NdResources")
+@ApiModel(value = "NdResources")
public class NdResources {
@Expose
@@ -36,9 +36,11 @@ public class NdResources {
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/NdResourcesList.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResourcesList.java
deleted file mode 100644
index c7e397f..0000000
--- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResourcesList.java
+++ /dev/null
@@ -1,45 +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 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="NdResourcesList")
-public class NdResourcesList {
-
- @Expose
- @SerializedName("ndResourcesList")
- private List<NdResources> ndResourcesList = new ArrayList<>();
-
- @ApiModelProperty(value = "List of NdResources associated with the service instance")
- public List<NdResources> getNdResources() {
- return ndResourcesList;
- }
- public void setNdResources(List<NdResources> ndResourcesList) {
- this.ndResourcesList = ndResourcesList;
- }
- public void addNdResource(NdResources ndResources) {
- this.ndResourcesList.add(ndResources);
- }
-}
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 4a8c50c..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,6 +15,7 @@
* limitations under the License.
* ============LICENSE_END=====================================================
*/
+
package org.onap.pomba.contextbuilder.networkdiscovery.service;
import javax.servlet.http.HttpServletRequest;
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 b6c1d12..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,6 +15,7 @@
* limitations under the License.
* ============LICENSE_END=====================================================
*/
+
package org.onap.pomba.contextbuilder.networkdiscovery.service;
import com.bazaarvoice.jolt.Chainr;
@@ -38,16 +39,15 @@ 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.VFModule;
import org.onap.pomba.common.datatypes.VM;
import org.onap.pomba.common.datatypes.VNF;
import org.onap.pomba.contextbuilder.networkdiscovery.exception.DiscoveryException;
-import org.onap.pomba.contextbuilder.networkdiscovery.model.NdQuery;
import org.onap.pomba.contextbuilder.networkdiscovery.model.NdResource;
import org.onap.pomba.contextbuilder.networkdiscovery.model.NdResources;
-import org.onap.pomba.contextbuilder.networkdiscovery.model.NdResourcesList;
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;
@@ -122,47 +122,33 @@ public class SpringServiceImpl implements SpringService {
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);
- String sdReply = getServiceDeomposition(serviceInstanceId, partnerName, requestId);
- ModelContext networkDiscoveryCtx = createModelContextFromSdResonse(sdReply);
- NdQuery ndQuery = createNdQueryFromSdResonse(sdReply);
- sendNetworkDiscoveryRequest(networkDiscoveryCtx, ndQuery, requestId, partnerName);
- 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();
- }
+ 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;
}
- 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");
+ /**
+ * Validates the Basic authorization header as admin:admin.
+ *
+ * @throws DiscoveryException
+ * if there is missing parameter
+ */
+ public void validateBasicAuth(String authorization) throws DiscoveryException {
+ if (authorization != null && !authorization.trim().isEmpty() && authorization.startsWith("Basic")) {
+ if (!authorization.equals(networkDiscoveryCtxBuilderBasicAuthorization)) {
+ throw new DiscoveryException("Authorization Failed", Status.UNAUTHORIZED);
+ }
+ } else {
+ throw new DiscoveryException(
+ "Missing Authorization: " + (authorization == null ? "null" : authorization),
+ Status.UNAUTHORIZED);
}
}
@@ -174,77 +160,49 @@ public class SpringServiceImpl implements SpringService {
if (serviceInstanceId == null) {
return null;
}
+
+ String urlStr = serviceDecompositionBaseUrl + "?serviceInstanceId=" + serviceInstanceId;
- log.info("Querying Service Decomposition for service instance {}", serviceInstanceId);
-
- String urlStr = getUrl(serviceInstanceId);
-
- log.info("Querying Service Decomposition for url {}", urlStr);
+ log.info("Querying Service Decomposition for service instance {} at url {}", serviceInstanceId, urlStr);
+ 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();
- try {
- Response response = jerseyClient.target(urlStr).request()
- .header(Headers.ACCEPT, MediaType.APPLICATION_JSON)
- .header(Headers.AUTHORIZATION, getSdBasicAuthorization())
- .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();
-
- String reply = null;
- if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) {
- 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: {}, message body: {}",
- serviceInstanceId, reply);
- }
+ log.info(
+ "GET Response from ServiceDecompositionMircoService for serviceInstanceId: {}, status code {}",
+ serviceInstanceId, response.getStatusInfo().getStatusCode());
- return reply;
- } catch (Exception x) {
- throw new DiscoveryException(x.getMessage(), x);
+ 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()));
}
- }
- private String getUrl(String serviceInstanceId) {
- return serviceDecompositionBaseUrl + "?serviceInstanceId=" + serviceInstanceId;
- }
+ MDC.put(MDC_RESPONSE_CODE, String.valueOf(response.getStatus()));
+ MDC.put(MDC_STATUS_CODE, "COMPLETE");
+ String reply = response.readEntity(String.class);
- private String getSdBasicAuthorization() {
- return serviceDecompositionBasicAuthorization;
- }
+ log.info(
+ "GET Response from ServiceDecompositionMircoService GetContext for serviceInstanceId: {}, message body: {}",
+ serviceInstanceId, reply);
- /**
- * Validates the Basic authorization header as admin:admin.
- *
- * @throws DiscoveryException
- * if there is missing parameter
- */
- public void validateBasicAuth(String authorization) throws DiscoveryException {
- if (authorization != null && !authorization.trim().isEmpty() && authorization.startsWith("Basic")) {
- if (!authorization.equals(networkDiscoveryCtxBuilderBasicAuthorization)) {
- throw new DiscoveryException("Authorization Failed", Status.UNAUTHORIZED);
- }
- } else {
- throw new DiscoveryException(
- "Missing Authorization: " + (authorization == null ? "null" : authorization),
- Status.UNAUTHORIZED);
- }
+ return reply;
}
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();
// Some Network Discovery attribute name do not exactly
@@ -270,41 +228,66 @@ public class SpringServiceImpl implements SpringService {
attribute.setValue(ndattribute.getValue());
attribute.setDataQuality(ndattribute.getDataQuality());
vm.addAttribute(attribute);
- break;
+ break;
default:
attribute = new Attribute();
attribute.setName(Attribute.Name.valueOf(ndattributeName));
attribute.setValue(ndattribute.getValue());
attribute.setDataQuality(ndattribute.getDataQuality());
- vm.addAttribute(attribute);
+ vm.addAttribute(attribute);
}
} catch (IllegalArgumentException ex) {
// The attribute Name passed back from Network Discovery is not in our enum
- log.info("Attribute Name: {} for Resource: {} Id: {} is invalid", ndattribute.getName(), resource.getName(), resource.getId());
+ 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: {} for Resource: {} Id: {} is invalid", ndattribute.getName(), resource.getName(), resource.getId());
+ log.info("Attribute Name: {} for Resource: {} Id: {} is invalid",
+ ndattribute.getName(), resource.getName(), resource.getId());
}
}
}
@@ -315,72 +298,111 @@ 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);
+ }
+ }
+
+ }
+ }
+ }
/* Return list of requestIds sent to network-discovery microService. */
- private void sendNetworkDiscoveryRequest(ModelContext networkDiscoveryCtx,
- NdQuery ndQuery,
- String parentRequestId,
- String partnerName) throws DiscoveryException {
- for (NdResourcesList ndResourcesList : ndQuery.getNdQuery()) {
- for (NdResources ndResources : ndResourcesList.getNdResources()) {
- for (NdResource ndResource : ndResources.getNdResources()) {
- // 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);
- }
+ 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);
}
}
}
- private NetworkDiscoveryNotification sendNetworkDiscoveryRequestToSpecificServer(String partnerName, String parentRequestId,
- String requestId, String resourceId, String resourceType)
+ private NetworkDiscoveryNotification sendNetworkDiscoveryRequestToSpecificServer(String partnerName,
+ String parentRequestId, String requestId, String resourceId, String resourceType)
throws DiscoveryException {
- String networkDiscoveryUrl = networkDiscoveryMicroServiceBaseUrl;
// Prepare MDC for logs
- initMdcSendToNetworkDiscoveryMicroService(networkDiscoveryUrl, requestId, resourceType, resourceId,
- partnerName);
+ initMdcSendToNetworkDiscoveryMicroService(networkDiscoveryMicroServiceBaseUrl, requestId, resourceType,
+ resourceId, partnerName);
- try {
- Response response = jerseySslClient.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)
- .request()
- .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
- .header(HttpHeaders.AUTHORIZATION, getNetworkDiscoveryMircoServiceBasicAuthorization())
- .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();
-
- String status = Response.Status.fromStatusCode(response.getStatus()) + ",code:" + response.getStatus();
-
- if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) {
- MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, status);
- throw new DiscoveryException(response.getStatusInfo().toString(),
- Response.Status.fromStatusCode(response.getStatus()));
- } else {
- MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, status);
- NetworkDiscoveryNotification ndResponse = response.readEntity(NetworkDiscoveryNotification.class);
- log.info("Message sent. Response Payload: {}", ndResponse);
- return ndResponse;
- }
- } catch (Exception e) {
- 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);
+
+ 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();
+
+ String status = Response.Status.fromStatusCode(response.getStatus()) + ",code:" + response.getStatus();
+
+ log.info("Network Disvovery response status code: {}", response.getStatus());
+
+ MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, status);
+
+ 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 String getNetworkDiscoveryMircoServiceBasicAuthorization() {
- return networkDiscoveryMicroServiceBasicAuthorization;
+
+ 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");
+ }
}
private void initMdcSendToNetworkDiscoveryMicroService(String networkDiscoveryUrl, String requestId,
@@ -390,7 +412,7 @@ public class SpringServiceImpl implements SpringService {
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_TO_NETWORK_DISCOVERY_MICRO_SERVICE_APP);
MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_MSG_NAME,
@@ -410,30 +432,24 @@ public class SpringServiceImpl implements SpringService {
}
}
-
private ModelContext createModelContextFromSdResonse(String response) {
- List<Object> jsonSpec = JsonUtils.filepathToList("config/networkdiscovery.spec");
+ 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);
-
}
- private NdQuery createNdQueryFromSdResonse(String response) {
- List<Object> jsonSpec = JsonUtils.filepathToList("config/ndQuery.spec");
+ 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);
- Gson gson = new Gson();
-
- log.info("Jolt transformed output: {}", JsonUtils.toJsonString(transObject));
-
-
- return gson.fromJson(JsonUtils.toPrettyJsonString(transObject), NdQuery.class);
-
+ 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 55fe2d2..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,6 +15,7 @@
* limitations under the License.
* ============LICENSE_END=====================================================
*/
+
package org.onap.pomba.contextbuilder.networkdiscovery.service.rs;
import javax.servlet.http.HttpServletRequest;
@@ -47,8 +48,8 @@ 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;
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 53adbc4..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,6 +15,7 @@
* limitations under the License.
* ============LICENSE_END=====================================================
*/
+
package org.onap.pomba.contextbuilder.networkdiscovery.service.rs;
import com.google.gson.Gson;
@@ -32,6 +33,7 @@ import org.onap.pomba.contextbuilder.networkdiscovery.exception.ErrorMessage;
import org.onap.pomba.contextbuilder.networkdiscovery.service.SpringService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -45,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("{} is missing; using newly generated value: {}", HEADER_REQUEST_ID, 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,
@@ -78,13 +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();
}
+
}
}
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 fe10949..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;
@@ -39,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);
+ }
}
/**
@@ -54,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);
}
}