summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/datatype/PserverInstance.java3
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/datatype/Vserver.java4
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringService.java3
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java5
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java6
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java18
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java181
7 files changed, 131 insertions, 89 deletions
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/PserverInstance.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/PserverInstance.java
index 5ca73c5..8ec0f6b 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/PserverInstance.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/PserverInstance.java
@@ -23,9 +23,6 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
-
-import javax.validation.Valid;
-
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/Vserver.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/Vserver.java
index 948aaa7..9bf67d9 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/Vserver.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/Vserver.java
@@ -21,11 +21,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
-
import java.util.List;
-
-import javax.validation.Valid;
-
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringService.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringService.java
index c59a24e..77f9145 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringService.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringService.java
@@ -18,10 +18,11 @@
package org.onap.pomba.contextbuilder.aai.service;
+import javax.servlet.http.HttpServletRequest;
import org.onap.pomba.common.datatypes.ModelContext;
import org.onap.pomba.contextbuilder.aai.exception.AuditException;
public interface SpringService {
- public ModelContext getContext(String serviceInstanceId, String transactionId) throws AuditException;
+ public ModelContext getContext(HttpServletRequest req, String serviceInstanceId, String requestId, String partnerName) throws AuditException;
}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java
index 216ee3e..cba4aa9 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java
@@ -17,6 +17,7 @@
*/
package org.onap.pomba.contextbuilder.aai.service;
+import javax.servlet.http.HttpServletRequest;
import org.onap.aai.restclient.client.RestClient;
import org.onap.pomba.common.datatypes.ModelContext;
import org.onap.pomba.contextbuilder.aai.common.LogMessages;
@@ -45,7 +46,7 @@ public class SpringServiceImpl implements SpringService {
// needed for instantiation
}
- public ModelContext getContext(String serviceInstanceId, String tranId) throws AuditException {
+ public ModelContext getContext(HttpServletRequest req, String serviceInstanceId, String requestId, String partnerName) throws AuditException {
String url = "serviceInstanceId=" + serviceInstanceId;
log.info(LogMessages.AAI_CONTEXT_BUILDER_URL, url);
@@ -54,7 +55,7 @@ public class SpringServiceImpl implements SpringService {
// Retrieve the service instance information from AAI
try {
- context= RestUtil.retrieveAAIModelData(aaiClient, aaiBaseUrl, aaiPathToSearchNodeQuery, tranId, serviceInstanceId, aaiBasicAuthorization);
+ context= RestUtil.retrieveAAIModelData(aaiClient, aaiBaseUrl, aaiPathToSearchNodeQuery, req, requestId, partnerName, serviceInstanceId, aaiBasicAuthorization);
} catch (AuditException ae) {
throw ae;
} catch (Exception e) {
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java
index b30b76d..6d28c90 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java
@@ -22,6 +22,7 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
+import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
@@ -54,9 +55,10 @@ public interface RestService {
@ApiResponse(code = 500, message = "Unexpected Runtime error")
})
public Response getContext(@Context HttpHeaders headers,
+ @Context HttpServletRequest req,
@HeaderParam(HttpHeaders.AUTHORIZATION) @ApiParam(hidden=true) String authorization,
- @HeaderParam(org.onap.pomba.contextbuilder.aai.util.RestUtil.FROM_APP_ID) @ApiParam(required=true) String xFromAppId,
- @HeaderParam(org.onap.pomba.contextbuilder.aai.util.RestUtil.TRANSACTION_ID) String xTransactionId,
+ @HeaderParam(org.onap.pomba.contextbuilder.aai.util.RestUtil.FROM_APP_ID) @ApiParam(required=true) String xPartnerName,
+ @HeaderParam(org.onap.pomba.contextbuilder.aai.util.RestUtil.TRANSACTION_ID) String xRequestId,
@QueryParam("serviceInstanceId") @ApiParam(required=true) String serviceInstanceId
);
} \ No newline at end of file
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java
index 19e81df..f5653f2 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java
@@ -20,6 +20,8 @@ package org.onap.pomba.contextbuilder.aai.service.rs;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import java.util.UUID;
+import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -31,7 +33,6 @@ import org.onap.pomba.contextbuilder.aai.util.RestUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.UUID;
import org.springframework.stereotype.Component;
@Component
@@ -47,9 +48,10 @@ public class RestServiceImpl implements RestService {
@Override
public Response getContext(HttpHeaders headers,
+ HttpServletRequest req,
String authorization,
- String fromAppId,
- String transactionId,
+ String partnerName,
+ String requestId,
String serviceInstanceId) {
String url = "serviceInstanceId=" + serviceInstanceId;
@@ -57,9 +59,9 @@ public class RestServiceImpl implements RestService {
log.debug(LogMessages.AAI_CONTEXT_BUILDER_URL, url);
}
- if (transactionId == null || transactionId.isEmpty()) {
- transactionId = UUID.randomUUID().toString();
- log.info(String.format("%s is missing; using newly generated value: %s", org.onap.pomba.contextbuilder.aai.util.RestUtil.TRANSACTION_ID, transactionId));
+ if (requestId == null || requestId.isEmpty()) {
+ requestId = UUID.randomUUID().toString();
+ log.info(String.format("%s is missing; using newly generated value: %s", org.onap.pomba.contextbuilder.aai.util.RestUtil.TRANSACTION_ID, requestId));
}
Response response = null;
@@ -74,9 +76,9 @@ public class RestServiceImpl implements RestService {
RestUtil.validateServiceInstanceId(serviceInstanceId);
// Keep the same transaction id for logging purpose
- transactionId= RestUtil.extractTranIdHeader(headers);
+ requestId= RestUtil.extractRequestIdHeader(headers);
- aaiContext = service.getContext(serviceInstanceId,transactionId);
+ aaiContext = service.getContext(req, serviceInstanceId, requestId, partnerName);
if (aaiContext==null) {
// Return empty JSON
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java b/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java
index 581ef32..928153b 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java
@@ -15,8 +15,13 @@ package org.onap.pomba.contextbuilder.aai.util;
+import com.bazaarvoice.jolt.JsonUtils;
+import java.net.InetAddress;
+import java.text.MessageFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -24,6 +29,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
+import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
@@ -35,14 +41,26 @@ import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.restclient.client.RestClient;
import org.onap.pomba.common.datatypes.Attribute;
import org.onap.pomba.common.datatypes.DataQuality;
+import org.onap.pomba.common.datatypes.LInterface;
+import org.onap.pomba.common.datatypes.LogicalLink;
import org.onap.pomba.common.datatypes.ModelContext;
+import org.onap.pomba.common.datatypes.Network;
+import org.onap.pomba.common.datatypes.PInterface;
+import org.onap.pomba.common.datatypes.PNF;
+import org.onap.pomba.common.datatypes.Pserver;
import org.onap.pomba.common.datatypes.Service;
-import org.onap.pomba.common.datatypes.VNF;
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.common.datatypes.VNFC;
-import org.onap.pomba.common.datatypes.Network;
import org.onap.pomba.contextbuilder.aai.common.LogMessages;
+import org.onap.pomba.contextbuilder.aai.datatype.L3networkInstance;
+import org.onap.pomba.contextbuilder.aai.datatype.LInterfaceInstance;
+import org.onap.pomba.contextbuilder.aai.datatype.LogicalLinkInstance;
+import org.onap.pomba.contextbuilder.aai.datatype.PInterfaceInstance;
+import org.onap.pomba.contextbuilder.aai.datatype.PInterfaceInstanceList;
+import org.onap.pomba.contextbuilder.aai.datatype.PnfInstance;
+import org.onap.pomba.contextbuilder.aai.datatype.PserverInstance;
import org.onap.pomba.contextbuilder.aai.datatype.Relationship;
import org.onap.pomba.contextbuilder.aai.datatype.RelationshipList;
import org.onap.pomba.contextbuilder.aai.datatype.ServiceInstance;
@@ -50,24 +68,11 @@ import org.onap.pomba.contextbuilder.aai.datatype.VfModule;
import org.onap.pomba.contextbuilder.aai.datatype.VnfInstance;
import org.onap.pomba.contextbuilder.aai.datatype.VnfcInstance;
import org.onap.pomba.contextbuilder.aai.datatype.Vserver;
-import org.onap.pomba.contextbuilder.aai.datatype.PserverInstance;
-import org.onap.pomba.contextbuilder.aai.datatype.PInterfaceInstance;
-import org.onap.pomba.contextbuilder.aai.datatype.L3networkInstance;
-import org.onap.pomba.contextbuilder.aai.datatype.LInterfaceInstance;
-import org.onap.pomba.contextbuilder.aai.datatype.LogicalLinkInstance;
import org.onap.pomba.contextbuilder.aai.exception.AuditError;
import org.onap.pomba.contextbuilder.aai.exception.AuditException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.onap.pomba.contextbuilder.aai.datatype.PnfInstance;
-import org.onap.pomba.contextbuilder.aai.datatype.PInterfaceInstanceList;
-import org.onap.pomba.common.datatypes.PNF;
-import org.onap.pomba.common.datatypes.PInterface;
-import com.bazaarvoice.jolt.JsonUtils;
-import org.onap.pomba.common.datatypes.Pserver;
-import org.onap.pomba.common.datatypes.LInterface;
-import org.onap.pomba.common.datatypes.LogicalLink;
-import java.text.MessageFormat;
+import org.slf4j.MDC;
public class RestUtil {
@@ -85,6 +90,20 @@ public class RestUtil {
private static final String APP_NAME = "aaiCtxBuilder";
+ private static final String MDC_REQUEST_ID = "RequestId";
+ private static final String MDC_SERVER_FQDN = "ServerFQDN";
+ private static final String MDC_SERVICE_NAME = "ServiceName";
+ private static final String MDC_PARTNER_NAME = "PartnerName";
+ private static final String MDC_START_TIME = "StartTime";
+ private static final String MDC_SERVICE_INSTANCE_ID = "ServiceInstanceId";
+ private static final String MDC_INVOCATION_ID = "InvocationID";
+ private static final String MDC_CLIENT_ADDRESS = "ClientAddress";
+ private static final String MDC_STATUS_CODE = "StatusCode";
+ private static final String MDC_RESPONSE_CODE = "ResponseCode";
+ private static final String MDC_INSTANCE_ID = "InstanceId";
+
+ private static UUID instanceId = UUID.randomUUID();
+
// Service Catalog - "related-to"
private static final String CATALOG_GENERIC_VNF = "generic-vnf";
private static final String CATALOG_VNFC = "vnfc";
@@ -97,8 +116,6 @@ public class RestUtil {
private static final String VF_MODULES = "vf-modules";
private static final String VF_MODULE = "vf-module";
-
-
// Relationship Json Path
private static final String RELATIONSHIP_LIST = "relationship-list";
private static final String RELATIONSHIP = "relationship";
@@ -187,7 +204,7 @@ public class RestUtil {
public static void validateHeader(HttpHeaders headers) throws AuditException {
String fromAppId = null;
- String transactionId = null;
+ String requestId = null;
fromAppId = headers.getRequestHeaders().getFirst(FROM_APP_ID);
if ((fromAppId == null) || fromAppId.trim().isEmpty()) {
@@ -195,24 +212,24 @@ public class RestUtil {
throw new AuditException(AuditError.MISSING_HEADER_PARAMETER + FROM_APP_ID, Status.BAD_REQUEST);
}
- transactionId = headers.getRequestHeaders().getFirst(TRANSACTION_ID);
- if ((transactionId == null) || transactionId.trim().isEmpty()) {
- transactionId = UUID.randomUUID().toString();
- log.info(LogMessages.HEADER_MESSAGE, TRANSACTION_ID, transactionId);
+ requestId = headers.getRequestHeaders().getFirst(TRANSACTION_ID);
+ if ((requestId == null) || requestId.trim().isEmpty()) {
+ requestId = UUID.randomUUID().toString();
+ log.info(LogMessages.HEADER_MESSAGE, TRANSACTION_ID, requestId);
}
}
/*
* The purpose is to keep same transaction Id from north bound interface to south bound interface
*/
- public static String extractTranIdHeader(HttpHeaders headers) {
- String transactionId = null;
- transactionId = headers.getRequestHeaders().getFirst(TRANSACTION_ID);
- if ((transactionId == null) || transactionId.trim().isEmpty()) {
- transactionId = UUID.randomUUID().toString();
- log.info(LogMessages.HEADER_MESSAGE, TRANSACTION_ID, transactionId);
+ public static String extractRequestIdHeader(HttpHeaders headers) {
+ String requestId = null;
+ requestId = headers.getRequestHeaders().getFirst(TRANSACTION_ID);
+ if ((requestId == null) || requestId.trim().isEmpty()) {
+ requestId = UUID.randomUUID().toString();
+ log.info(LogMessages.HEADER_MESSAGE, TRANSACTION_ID, requestId);
}
- return transactionId;
+ return requestId;
}
/*
@@ -220,7 +237,8 @@ public class RestUtil {
*
*/
public static ModelContext retrieveAAIModelData(RestClient aaiClient, String baseURL, String aaiPathToSearchNodeQuery,
- String transactionId, String serviceInstanceId, String aaiBasicAuthorization) throws AuditException {
+ HttpServletRequest req, String requestId, String partnerName, String serviceInstanceId, String aaiBasicAuthorization) throws AuditException {
+ initMdc(requestId, partnerName, serviceInstanceId, req.getRemoteAddr());
String serviceInstancePayload = null;
String genericVNFPayload = null;
@@ -238,7 +256,7 @@ public class RestUtil {
// Response from service instance API call
serviceInstancePayload =
- getResource(aaiClient, url, aaiBasicAuthorization, transactionId, MediaType.valueOf(MediaType.APPLICATION_JSON));
+ getResource(aaiClient, url, aaiBasicAuthorization, requestId, MediaType.valueOf(MediaType.APPLICATION_JSON));
// Handle the case if the service instance is not found in AAI
if (isEmptyJson(serviceInstancePayload)) {
@@ -259,7 +277,7 @@ public class RestUtil {
String genericVNFURL = baseURL + genericVNFLink + DEPTH;
// Response from generic VNF API call
genericVNFPayload =
- getResource(aaiClient, genericVNFURL, aaiBasicAuthorization, transactionId, MediaType.valueOf(MediaType.APPLICATION_JSON));
+ getResource(aaiClient, genericVNFURL, aaiBasicAuthorization, requestId, MediaType.valueOf(MediaType.APPLICATION_JSON));
if (isEmptyJson(genericVNFPayload)) {
log.info(LogMessages.NOT_FOUND, "GenericVNF with url ", genericVNFLink);
@@ -274,34 +292,34 @@ public class RestUtil {
List<LInterfaceInstance> lInterfaceInstList_aai = vnfInstance.getLInterfaceInstanceList().getLInterfaceList();
for (LInterfaceInstance lInterfaceInst_aai : lInterfaceInstList_aai) {
lInterfaceInst_aai.setLogicalLinkInstanceList(obtainLogicalLinkInfoFromAai ( aaiClient, baseURL,
- transactionId, aaiBasicAuthorization, lInterfaceInst_aai.getRelationshipList()));
+ requestId, aaiBasicAuthorization, lInterfaceInst_aai.getRelationshipList()));
}
}
vnfLst.add(vnfInstance);
// Update VModule with l3-network list from aai, if any.
- buildVModuleWithL3NetworkInfo (vnfInstance, aaiClient, baseURL, transactionId, aaiBasicAuthorization);
+ buildVModuleWithL3NetworkInfo (vnfInstance, aaiClient, baseURL, requestId, aaiBasicAuthorization);
// Build the vnf_vnfc relationship map
- buildVnfcMap(vnfcMap, genericVNFPayload, aaiClient, baseURL, transactionId, aaiBasicAuthorization );
+ buildVnfcMap(vnfcMap, genericVNFPayload, aaiClient, baseURL, requestId, aaiBasicAuthorization );
// Build vnf_vfmodule_vserver relationship map
- buildVfmoduleVserverMap(vnfVfmoduleVserverMap, genericVNFPayload, aaiClient, baseURL, transactionId, aaiBasicAuthorization);
+ buildVfmoduleVserverMap(vnfVfmoduleVserverMap, genericVNFPayload, aaiClient, baseURL, requestId, aaiBasicAuthorization);
// Build the vnf_l3_network relationship map
- buildVnfWithL3networkInfo(l3networkMapInVnf, genericVNFPayload, aaiClient, baseURL, transactionId, aaiBasicAuthorization );
+ buildVnfWithL3networkInfo(l3networkMapInVnf, genericVNFPayload, aaiClient, baseURL, requestId, aaiBasicAuthorization );
}
}
//Obtain PNF (Physical Network Function)
- List<PnfInstance> pnfLst = retrieveAAIModelData_PNF (aaiClient, baseURL, transactionId, serviceInstanceId, aaiBasicAuthorization, serviceInstancePayload) ;
+ List<PnfInstance> pnfLst = retrieveAAIModelData_PNF (aaiClient, baseURL, requestId, serviceInstanceId, aaiBasicAuthorization, serviceInstancePayload) ;
//Obtain l3-network on service level
- List<L3networkInstance> l3networkLstInService = retrieveAaiModelDataL3NetworkInServiceLevel (aaiClient, baseURL, transactionId, aaiBasicAuthorization, serviceInstancePayload) ;
+ List<L3networkInstance> l3networkLstInService = retrieveAaiModelDataL3NetworkInServiceLevel (aaiClient, baseURL, requestId, aaiBasicAuthorization, serviceInstancePayload) ;
//Obtain logical-link on service level
List<LogicalLinkInstance> logicalLinkInstanceLstInService = obtainLogicalLinkInfoFromAai ( aaiClient, baseURL,
- transactionId, aaiBasicAuthorization, ServiceInstance.fromJson(serviceInstancePayload).getRelationshipList());
+ requestId, aaiBasicAuthorization, ServiceInstance.fromJson(serviceInstancePayload).getRelationshipList());
// Transform to common model and return
return transform(ServiceInstance.fromJson(serviceInstancePayload), vnfLst, vnfcMap, l3networkMapInVnf, vnfVfmoduleVserverMap, pnfLst, l3networkLstInService, logicalLinkInstanceLstInService);
@@ -309,7 +327,7 @@ public class RestUtil {
private static void buildVModuleWithL3NetworkInfo (VnfInstance vnfInstance,
RestClient aaiClient, String baseURL,
- String transactionId, String aaiBasicAuthorization
+ String requestId, String aaiBasicAuthorization
) throws AuditException {
if ((vnfInstance != null ) && (vnfInstance.getVfModules()) != null) {
@@ -329,7 +347,7 @@ public class RestUtil {
}
if (!(relatedLinkList.isEmpty())) {
- List<L3networkInstance> l3nwInsLst = queryAaiForL3networkInfo (aaiClient,baseURL,transactionId,aaiBasicAuthorization,relatedLinkList);
+ List<L3networkInstance> l3nwInsLst = queryAaiForL3networkInfo (aaiClient,baseURL,requestId,aaiBasicAuthorization,relatedLinkList);
if ((l3nwInsLst != null) && (!l3nwInsLst.isEmpty())) {
t_vfModule.setL3NetworkList(l3nwInsLst);
@@ -342,7 +360,7 @@ public class RestUtil {
}
private static List<PnfInstance> retrieveAAIModelData_PNF(RestClient aaiClient, String baseURL,
- String transactionId, String serviceInstanceId, String aaiBasicAuthorization, String serviceInstancePayload) throws AuditException {
+ String requestId, String serviceInstanceId, String aaiBasicAuthorization, String serviceInstancePayload) throws AuditException {
List<String> genericPNFLinkLst = extractRelatedLink(serviceInstancePayload, CATALOG_PNF);
log.info(LogMessages.NUMBER_OF_API_CALLS, "PNF", genericPNFLinkLst.size());
@@ -360,7 +378,7 @@ public class RestUtil {
String genericPNFURL = baseURL + genericPNFLink + DEPTH;
// Response from generic PNF API call
genericPNFPayload =
- getResource(aaiClient, genericPNFURL, aaiBasicAuthorization, transactionId, MediaType.valueOf(MediaType.APPLICATION_JSON));
+ getResource(aaiClient, genericPNFURL, aaiBasicAuthorization, requestId, MediaType.valueOf(MediaType.APPLICATION_JSON));
if (isEmptyJson(genericPNFPayload)) {
log.info(LogMessages.NOT_FOUND, "GenericPNF with url ", genericPNFLink);
@@ -376,7 +394,7 @@ public class RestUtil {
List<PInterfaceInstance> pInterfaceInstList_aai = pnfInstance.getPInterfaceInstanceList().getPInterfaceList();
for (PInterfaceInstance pInterfaceInst_aai : pInterfaceInstList_aai) {
pInterfaceInst_aai.setLogicalLinkInstanceList(obtainLogicalLinkInfoFromAai ( aaiClient, baseURL,
- transactionId, aaiBasicAuthorization, pInterfaceInst_aai.getRelationshipList()));
+ requestId, aaiBasicAuthorization, pInterfaceInst_aai.getRelationshipList()));
//Obtain L-Interface level logical-link
if ((pInterfaceInst_aai.getLInterfaceInstanceList() != null)
@@ -384,7 +402,7 @@ public class RestUtil {
List<LInterfaceInstance> lInterfaceInstList_aai = pInterfaceInst_aai.getLInterfaceInstanceList().getLInterfaceList();
for (LInterfaceInstance lInterfaceInst_aai : lInterfaceInstList_aai) {
lInterfaceInst_aai.setLogicalLinkInstanceList(obtainLogicalLinkInfoFromAai ( aaiClient, baseURL,
- transactionId, aaiBasicAuthorization, lInterfaceInst_aai.getRelationshipList()));
+ requestId, aaiBasicAuthorization, lInterfaceInst_aai.getRelationshipList()));
}
}
}
@@ -396,7 +414,7 @@ public class RestUtil {
}
private static List<LogicalLinkInstance> obtainLogicalLinkInfoFromAai(RestClient aaiClient, String baseURL,
- String transactionId, String aaiBasicAuthorization, RelationshipList logicalLinkRelateionShipList) throws AuditException {
+ String requestId, String aaiBasicAuthorization, RelationshipList logicalLinkRelateionShipList) throws AuditException {
if (logicalLinkRelateionShipList == null) {
return null;
}
@@ -416,7 +434,7 @@ public class RestUtil {
}
if (!(relatedLinkList.isEmpty())) {
- List<LogicalLinkInstance> logicalLinkInsLst = queryAaiForLogicalLinkData (aaiClient,baseURL,transactionId,aaiBasicAuthorization,relatedLinkList);
+ List<LogicalLinkInstance> logicalLinkInsLst = queryAaiForLogicalLinkData (aaiClient,baseURL,requestId,aaiBasicAuthorization,relatedLinkList);
if ((logicalLinkInsLst != null) && (!logicalLinkInsLst.isEmpty())) {
@@ -428,7 +446,7 @@ public class RestUtil {
}
private static List<LogicalLinkInstance> queryAaiForLogicalLinkData(RestClient aaiClient, String baseURL,
- String transactionId, String aaiBasicAuthorization, List<String> genericRelatedLinkLst) throws AuditException {
+ String requestId, String aaiBasicAuthorization, List<String> genericRelatedLinkLst) throws AuditException {
if ( genericRelatedLinkLst.isEmpty()) {
return null;
}
@@ -443,7 +461,7 @@ public class RestUtil {
String genericURL = baseURL + genericRelatedLink;
// Response from generic l3-network API call
genericDataPayload =
- getResource(aaiClient, genericURL, aaiBasicAuthorization, transactionId, MediaType.valueOf(MediaType.APPLICATION_JSON));
+ getResource(aaiClient, genericURL, aaiBasicAuthorization, requestId, MediaType.valueOf(MediaType.APPLICATION_JSON));
if (isEmptyJson(genericDataPayload)) {
log.info(LogMessages.NOT_FOUND, " url ", genericRelatedLink);
@@ -460,7 +478,7 @@ public class RestUtil {
}
private static List<L3networkInstance> queryAaiForL3networkInfo(RestClient aaiClient, String baseURL,
- String transactionId, String aaiBasicAuthorization, List<String> genericL3networkLinkLst) throws AuditException {
+ String requestId, String aaiBasicAuthorization, List<String> genericL3networkLinkLst) throws AuditException {
if ( genericL3networkLinkLst.isEmpty()) {
return null;
}
@@ -475,7 +493,7 @@ public class RestUtil {
String genericL3NetworkURL = baseURL + genericNetworkLink + DEPTH;
// Response from generic l3-network API call
genericL3networkPayload =
- getResource(aaiClient, genericL3NetworkURL, aaiBasicAuthorization, transactionId, MediaType.valueOf(MediaType.APPLICATION_JSON));
+ getResource(aaiClient, genericL3NetworkURL, aaiBasicAuthorization, requestId, MediaType.valueOf(MediaType.APPLICATION_JSON));
if (isEmptyJson(genericL3networkPayload)) {
log.info(LogMessages.NOT_FOUND, "GenericPNF with url ", genericNetworkLink);
@@ -491,18 +509,18 @@ public class RestUtil {
}
private static List<L3networkInstance> retrieveAaiModelDataL3NetworkInServiceLevel(RestClient aaiClient, String baseURL,
- String transactionId, String aaiBasicAuthorization, String relationShipPayload) throws AuditException {
+ String requestId, String aaiBasicAuthorization, String relationShipPayload) throws AuditException {
List<String> genericL3networkLinkLst = extractRelatedLink(relationShipPayload, CATALOG_L3_NETWORK);
- return (queryAaiForL3networkInfo (aaiClient,baseURL,transactionId,aaiBasicAuthorization,genericL3networkLinkLst) ) ;
+ return (queryAaiForL3networkInfo (aaiClient,baseURL,requestId,aaiBasicAuthorization,genericL3networkLinkLst) ) ;
}
/*
* The map is to track the relationship of vnf-id with multiple vnfc relationship
*/
private static Map<String, List<VnfcInstance>> buildVnfcMap(Map<String, List<VnfcInstance>> vnfcMap, String genericVNFPayload, RestClient aaiClient, String baseURL,
- String transactionId, String aaiBasicAuthorization) throws AuditException {
+ String requestId, String aaiBasicAuthorization) throws AuditException {
String vnfcPayload = null;
@@ -513,7 +531,7 @@ public class RestUtil {
List<VnfcInstance> vnfcLst = new ArrayList<>();
for (String vnfcLink : vnfcLinkLst) {
String vnfcURL = baseURL + vnfcLink;
- vnfcPayload = getResource(aaiClient, vnfcURL, aaiBasicAuthorization, transactionId,
+ vnfcPayload = getResource(aaiClient, vnfcURL, aaiBasicAuthorization, requestId,
MediaType.valueOf(MediaType.APPLICATION_JSON));
if (isEmptyJson(vnfcPayload)) {
@@ -538,9 +556,9 @@ public class RestUtil {
* The map is to track the relationship of vnf-id with multiple l3-network relationship at vnf level
*/
private static Map<String, List<L3networkInstance>> buildVnfWithL3networkInfo(Map<String, List<L3networkInstance>> l3networkMap_in_vnf, String genericVNFPayload, RestClient aaiClient, String baseURL,
- String transactionId, String aaiBasicAuthorization) throws AuditException {
+ String requestId, String aaiBasicAuthorization) throws AuditException {
- List<L3networkInstance> l3NwLst = retrieveAaiModelDataL3NetworkInServiceLevel (aaiClient, baseURL, transactionId, aaiBasicAuthorization, genericVNFPayload) ;
+ List<L3networkInstance> l3NwLst = retrieveAaiModelDataL3NetworkInServiceLevel (aaiClient, baseURL, requestId, aaiBasicAuthorization, genericVNFPayload) ;
if ((l3NwLst != null ) && (!l3NwLst.isEmpty())) {
// Assume the vnf-id is unique as a key
@@ -558,7 +576,7 @@ public class RestUtil {
*
* The Map<String, Map<String, List<Vserver>>> key: vnf-id
*/
- private static Map<String, Map<String, List<Vserver>>> buildVfmoduleVserverMap(Map<String, Map<String, List<Vserver>>> vnf_vfmodule_vserver_Map, String genericVNFPayload, RestClient aaiClient, String baseURL, String transactionId, String aaiBasicAuthorization) throws AuditException {
+ private static Map<String, Map<String, List<Vserver>>> buildVfmoduleVserverMap(Map<String, Map<String, List<Vserver>>> vnf_vfmodule_vserver_Map, String genericVNFPayload, RestClient aaiClient, String baseURL, String requestId, String aaiBasicAuthorization) throws AuditException {
Map<String, List<Vserver>> vServerMap = new HashMap<>();
@@ -577,7 +595,7 @@ public class RestUtil {
List<Vserver> vserverLst = new ArrayList<>();
for (String vserverLink : vserverLinkLst) {
String vserverURL = baseURL + vserverLink + DEPTH;
- vserverPayload = getResource(aaiClient, vserverURL, aaiBasicAuthorization, transactionId,
+ vserverPayload = getResource(aaiClient, vserverURL, aaiBasicAuthorization, requestId,
MediaType.valueOf(MediaType.APPLICATION_XML));
if (isEmptyJson(vserverPayload)) {
@@ -587,7 +605,7 @@ public class RestUtil {
Vserver vserver = Vserver.fromJson(vserverPayload);
// add pserver if any
- List<PserverInstance> pserverInstanceLst = getPserverInfoFromAai(vserverPayload, aaiClient, baseURL, transactionId, aaiBasicAuthorization);
+ List<PserverInstance> pserverInstanceLst = getPserverInfoFromAai(vserverPayload, aaiClient, baseURL, requestId, aaiBasicAuthorization);
if ((pserverInstanceLst != null) && (!pserverInstanceLst.isEmpty())) {
vserver.setPserverInstanceList(pserverInstanceLst);
}
@@ -598,7 +616,7 @@ public class RestUtil {
List<LInterfaceInstance> lInterfaceInstList_aai = vserver.getLInterfaceInstanceList().getLInterfaceList();
for (LInterfaceInstance lInterfaceInst_aai : lInterfaceInstList_aai) {
lInterfaceInst_aai.setLogicalLinkInstanceList(obtainLogicalLinkInfoFromAai ( aaiClient, baseURL,
- transactionId, aaiBasicAuthorization, lInterfaceInst_aai.getRelationshipList()));
+ requestId, aaiBasicAuthorization, lInterfaceInst_aai.getRelationshipList()));
}
}
@@ -618,7 +636,7 @@ public class RestUtil {
return vnf_vfmodule_vserver_Map;
}
- private static List<PserverInstance> getPserverInfoFromAai (String vserverPayload, RestClient aaiClient, String baseURL, String transactionId, String aaiBasicAuthorization) throws AuditException {
+ private static List<PserverInstance> getPserverInfoFromAai (String vserverPayload, RestClient aaiClient, String baseURL, String requestId, String aaiBasicAuthorization) throws AuditException {
if (vserverPayload == null) {
//already reported.
return null;
@@ -634,7 +652,7 @@ public class RestUtil {
pserverLst = new ArrayList<>();
for (String pserverRelatedLink : pserverRelatedLinkList) {
String pserverURL = baseURL + pserverRelatedLink + DEPTH;;
- String pserverPayload = getResource(aaiClient, pserverURL, aaiBasicAuthorization, transactionId,
+ String pserverPayload = getResource(aaiClient, pserverURL, aaiBasicAuthorization, requestId,
MediaType.valueOf(MediaType.APPLICATION_XML));
if (isEmptyJson(pserverPayload)) {
@@ -651,13 +669,13 @@ public class RestUtil {
for (PInterfaceInstance pInterfaceInst_aai : pInterfaceInstList_aai) {
//Obtain P-Interface level logical-link
pInterfaceInst_aai.setLogicalLinkInstanceList(obtainLogicalLinkInfoFromAai ( aaiClient, baseURL,
- transactionId, aaiBasicAuthorization, pInterfaceInst_aai.getRelationshipList()));
+ requestId, aaiBasicAuthorization, pInterfaceInst_aai.getRelationshipList()));
List<LInterfaceInstance> lInterfaceInstList_aai = pInterfaceInst_aai.getLInterfaceInstanceList().getLInterfaceList();
for (LInterfaceInstance lInterfaceInst_aai : lInterfaceInstList_aai) {
//Obtain L-Interface level logical-link
lInterfaceInst_aai.setLogicalLinkInstanceList(obtainLogicalLinkInfoFromAai ( aaiClient, baseURL,
- transactionId, aaiBasicAuthorization, lInterfaceInst_aai.getRelationshipList()));
+ requestId, aaiBasicAuthorization, lInterfaceInst_aai.getRelationshipList()));
}
}
@@ -1913,9 +1931,9 @@ public class RestUtil {
return vServerRelatedLinkMap;
}
- private static Map<String, List<String>> buildHeaders(String aaiBasicAuthorization, String transactionId) {
+ private static Map<String, List<String>> buildHeaders(String aaiBasicAuthorization, String requestId) {
MultivaluedHashMap<String, String> headers = new MultivaluedHashMap<>();
- headers.put(TRANSACTION_ID, Collections.singletonList(transactionId));
+ headers.put(TRANSACTION_ID, Collections.singletonList(requestId));
headers.put(FROM_APP_ID, Collections.singletonList(APP_NAME));
headers.put(AUTHORIZATION, Collections.singletonList(aaiBasicAuthorization));
return headers;
@@ -1926,14 +1944,18 @@ public class RestUtil {
throws AuditException {
OperationResult result = client.get(url, buildHeaders(aaiBasicAuthorization, transId), MediaType.valueOf(MediaType.APPLICATION_JSON));
+ MDC.put(MDC_RESPONSE_CODE, String.valueOf(result.getResultCode()));
if (result.getResultCode() == 200) {
+ MDC.put(MDC_STATUS_CODE, "COMPLETE");
return result.getResult();
} else if (result.getResultCode() == 404) {
// Resource not found, generate empty JSON format
+ MDC.put(MDC_STATUS_CODE, "ERROR");
log.info(LogMessages.RESOURCE_NOT_FOUND, url, "return empty Json format");
return new JSONObject().toString();
} else {
+ MDC.put(MDC_STATUS_CODE, "ERROR");
throw new AuditException(AuditError.INTERNAL_SERVER_ERROR + " with " + result.getFailureCause());
}
}
@@ -1950,4 +1972,25 @@ public class RestUtil {
return true;
}
+
+ private static 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_ID, instanceId.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");
+ }
+ }
}