diff options
Diffstat (limited to 'src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java')
-rw-r--r-- | src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java | 365 |
1 files changed, 61 insertions, 304 deletions
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 58d13b7..933d2ab 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 @@ -20,23 +20,24 @@ 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.ModelContext; import org.onap.pomba.common.datatypes.Network; @@ -45,11 +46,9 @@ 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.contextbuilder.networkdiscovery.exception.DiscoveryException; -import org.onap.pomba.contextbuilder.networkdiscovery.model.NetworkDiscoveryRspInfo; 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,31 +79,16 @@ 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 { @@ -114,11 +98,13 @@ public class SpringServiceImpl implements SpringService { public NdResource(String type, String id) { this.resourceType = type; - this.resourceId = id; }; + this.resourceId = id; + } public String getResourceType() { return this.resourceType; } + public String getResourceId() { return this.resourceId; } @@ -141,12 +127,6 @@ public class SpringServiceImpl implements SpringService { private String networkDiscoveryMicroServiceBaseUrl; @Autowired - private String networkDiscoveryCtxBuilderBaseUrl; - - @Autowired - private long networkDiscoveryResponseTimeOutInMilliseconds; - - @Autowired private String networkDiscoveryMicroServiceHostAndPort; @Autowired @@ -155,8 +135,6 @@ public class SpringServiceImpl implements SpringService { @Autowired private Client jerseySslClient; - private static final ReentrantLock lock = new ReentrantLock(); - @Override public ModelContext getContext(HttpServletRequest req, String partnerName, String authorization, String requestId, String serviceInstanceId, String modelVersionId, String modelInvariantId) throws DiscoveryException { @@ -170,27 +148,8 @@ public class SpringServiceImpl implements SpringService { 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; - } + sendNetworkDiscoveryRequest(networkDiscoveryCtx, requestId, partnerName); + return networkDiscoveryCtx; } catch (Exception x) { DiscoveryException exception = new DiscoveryException(x.getMessage(), x); @@ -225,7 +184,7 @@ public class SpringServiceImpl implements SpringService { } /** - * Given a service instance ID, GET the resources from Service Decompostion. + * Given a service instance ID, GET the resources from Service Decomposition. */ private ModelContext getServiceDeomposition(String serviceInstanceId, String partnerName, String requestId) throws DiscoveryException { @@ -233,19 +192,22 @@ public class SpringServiceImpl implements SpringService { return null; } - log.info("Querying Service Decomposition for service instance " + serviceInstanceId); + log.info("Querying Service Decomposition for service instance {}", serviceInstanceId); String urlStr = getUrl(serviceInstanceId); + + log.info("Querying Service Decomposition for url {}", urlStr); + 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(); + .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.getStatus() != 200) { + 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(), @@ -255,8 +217,9 @@ public class SpringServiceImpl implements SpringService { MDC.put(MDC_STATUS_CODE, "COMPLETE"); reply = response.readEntity(String.class); - log.info("GET Response from ServiceDecompositionMircoService GetContext for serviceInstanceId:" - + serviceInstanceId + ", message body: " + reply); + log.info( + "GET Response from ServiceDecompositionMircoService GetContext for serviceInstanceId: {}, message body: {}", + serviceInstanceId, reply); } List<Object> jsonSpec = JsonUtils.filepathToList("config/networkdiscovery.spec"); @@ -270,16 +233,14 @@ public class SpringServiceImpl implements SpringService { } } - private String getUrl(String serviceInstanceId) throws DiscoveryException { - String url = serviceDecompositionBaseUrl + "?serviceInstanceId=" + serviceInstanceId; - return url; + private String getUrl(String serviceInstanceId) { + return serviceDecompositionBaseUrl + "?serviceInstanceId=" + serviceInstanceId; } private String getSdBasicAuthorization() { return serviceDecompositionBasicAuthorization; } - /** * Validates the Basic authorization header as admin:admin. * @@ -291,100 +252,13 @@ 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) - 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(); - } - - MDC.put(MDC_FROM_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, status); - CountDownLatch latch = myNetworkDiscoveryRspInfo.getLatchSignal(); - if (latch != null) { - latch.countDown(); - } - - return; - } - - 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()); - } - } - - String infoStr = sbl.toString(); - log.info( - "updateServiceDecompCtx_and_networkDiscoveryInfoList: All Notifications from NetworkDiscoveryMicroService: " - + infoStr); - - return networkDiscoveryCtx; - } - private void updateServiceDecompCtx(ModelContext networkDiscoveryCtx, Resource resource) { for (VF vf : networkDiscoveryCtx.getVfs()) { for (VFModule vfModule : vf.getVfModules()) { @@ -407,7 +281,7 @@ 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()); } } } @@ -431,7 +305,7 @@ 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()); } } } @@ -443,34 +317,12 @@ public class SpringServiceImpl implements SpringService { } - 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 { + private List<String> sendNetworkDiscoveryRequest(ModelContext networkDiscoveryCtx, String parentRequestId, + String partnerName) throws DiscoveryException { - List<String> relatedRequestIdList = new ArrayList<String>(); - List<NdResource> ndresourceList = new ArrayList<NdResource>(); + List<String> relatedRequestIdList = new ArrayList<>(); + List<NdResource> ndresourceList = new ArrayList<>(); for (VF vf : networkDiscoveryCtx.getVfs()) { for (VNFC vnfc : vf.getVnfcs()) { @@ -486,126 +338,69 @@ public class SpringServiceImpl implements SpringService { } } } + 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); - } - } + // 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, resource.getResourceId(), resource.getResourceType()); - // Update networkDiscoveryInfoList - for (String t_rqId : relatedRequestIdList) { - if (networkDiscoveryInfoList.containsKey(t_rqId)) { - lock.lock(); - networkDiscoveryInfoList.get(t_rqId).setRelatedRequestIdList(relatedRequestIdList); - lock.unlock(); + List<Resource> resourceList = nt.getResources(); + for (Resource resource1 : resourceList) { + updateServiceDecompCtx(networkDiscoveryCtx, resource1); } } - 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(networkDiscoveryUrl, 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) - .queryParam(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_NOTIFICATION_URL, callbackUrlStr).request() - .header(HttpHeaders.CONTENT_TYPE, "application/json").header(HttpHeaders.ACCEPT, "application/json") + .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, partner_name) - .header(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_X_ONAP_REQUEST_ID, parent_requestId).get(); + .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(); - 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); + + 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 { - ndResponse = response.readEntity(NetworkDiscoveryResponse.class); 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) { - latchSignal.countDown(); - safeRemoveEntry_from_networkDiscoveryInfoList(requestId); MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, e.getMessage()); throw new DiscoveryException(e.getMessage(), e); } - - 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); - } - - log.info("Message sent. Response Payload:" + ndResponse); - return true; - } - - private void safeRemoveEntry_from_networkDiscoveryInfoList(String requestId) { - lock.lock(); - networkDiscoveryInfoList.remove(requestId); - lock.unlock(); - } - - private String getNetworkDiscoveryCtxBuilderCallBackUrl() { - String url = networkDiscoveryCtxBuilderBaseUrl - + NETWORK_DISCOVERY_CTX_BUILDER_NETWORK_DISCOVERY_NOTIFICATION_PATH; - return url; } private String getNetworkDiscoveryMircoServiceBasicAuthorization() { return networkDiscoveryMicroServiceBasicAuthorization; } - private void initMDC_sendTo_networkDiscoveryMicroService(String networkDiscoveryUrl, String requestId, - String resourceType, String resourceId, String callbackUrlStr, String partner_name) { + 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); @@ -617,56 +412,18 @@ public class SpringServiceImpl implements SpringService { 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_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); - MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_CALL_BACK_URL, callbackUrlStr); - 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"); - } - } - - private void initMDC_MsgFrom_networkDiscoveryMicroService(String requestId) { - 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); - - 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_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); 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; - } - - protected static NetworkDiscoveryRspInfo getNetworkDiscoveryInfoList(String requestId) { - lock.lock(); - NetworkDiscoveryRspInfo returnInfo = networkDiscoveryInfoList.get(requestId); - lock.unlock(); - return returnInfo; - } - } |