2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.sparky.viewandinspect.context;
23 import static java.util.concurrent.CompletableFuture.supplyAsync;
25 import java.io.IOException;
26 import java.util.List;
28 import java.util.concurrent.ConcurrentHashMap;
29 import java.util.concurrent.ExecutorService;
30 import java.util.concurrent.atomic.AtomicInteger;
32 import org.onap.aai.cl.api.Logger;
33 import org.onap.aai.cl.eelf.LoggerFactory;
34 import org.onap.aai.restclient.client.OperationResult;
35 import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
36 import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
37 import org.onap.aai.sparky.dal.GizmoAdapter;
38 import org.onap.aai.sparky.logging.AaiUiMsgs;
39 import org.onap.aai.sparky.sync.entity.SearchableEntity;
40 import org.onap.aai.sparky.util.NodeUtils;
41 import org.onap.aai.sparky.viewandinspect.VisualizationContext;
42 import org.onap.aai.sparky.viewandinspect.config.SparkyConstants;
43 import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs;
44 import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode;
45 import org.onap.aai.sparky.viewandinspect.entity.GizmoEntity;
46 import org.onap.aai.sparky.viewandinspect.entity.GizmoRelationshipEntity;
47 import org.onap.aai.sparky.viewandinspect.entity.GizmoRelationshipHint;
48 import org.onap.aai.sparky.viewandinspect.entity.NodeProcessingTransaction;
49 import org.onap.aai.sparky.viewandinspect.entity.QueryParams;
50 import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingAction;
51 import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingState;
52 import org.onap.aai.sparky.viewandinspect.task.PerformGizmoNodeSelfLinkProcessingTask;
54 import com.fasterxml.jackson.annotation.JsonInclude.Include;
55 import com.fasterxml.jackson.databind.ObjectMapper;
56 import com.fasterxml.jackson.databind.PropertyNamingStrategy;
59 * The Class SelfLinkNodeCollector.
61 public class BaseGizmoVisualizationContext implements VisualizationContext {
63 private static final int MAX_DEPTH_EVALUATION_ATTEMPTS = 100;
65 private static final Logger LOG =
66 LoggerFactory.getInstance().getLogger(BaseGizmoVisualizationContext.class);
68 protected final GizmoAdapter gizmoAdapter;
70 protected AtomicInteger numLinksDiscovered;
71 protected AtomicInteger numSuccessfulLinkResolveFromCache;
72 protected AtomicInteger numSuccessfulLinkResolveFromFromServer;
73 protected AtomicInteger numFailedLinkResolve;
74 protected AtomicInteger aaiWorkOnHand;
76 protected VisualizationConfigs visualizationConfigs;
78 protected AtomicInteger totalLinksRetrieved;
80 protected final long contextId;
81 protected final String contextIdStr;
82 protected long lastProcessStatesSummaryLogInMs = -1;
85 protected ObjectMapper mapper;
87 protected ExecutorService graphExecutorService;
88 protected OxmEntityLookup oxmEntityLookup;
89 protected boolean rootNodeFound;
92 * The node cache is intended to be a flat structure indexed by a primary key to avoid needlessly
93 * re-requesting the same self-links over-and-over again, to speed up the overall render time and
94 * more importantly to reduce the network cost of determining information we already have.
96 protected ConcurrentHashMap<String, ActiveInventoryNode> nodeCache;
99 * Instantiates a new self link node collector.
101 * @param loader the loader
102 * @throws Exception the exception
104 public BaseGizmoVisualizationContext(long contextId, GizmoAdapter gizmoAdapter,
105 ExecutorService graphExecutorService, VisualizationConfigs visualizationConfigs,
106 OxmEntityLookup oxmEntityLookup) throws Exception {
108 this.contextId = contextId;
109 this.contextIdStr = "[Context-Id=" + contextId + "]";
110 this.gizmoAdapter = gizmoAdapter;
111 this.graphExecutorService = graphExecutorService;
112 this.visualizationConfigs = visualizationConfigs;
113 this.oxmEntityLookup = oxmEntityLookup;
115 this.nodeCache = new ConcurrentHashMap<String, ActiveInventoryNode>();
116 this.numLinksDiscovered = new AtomicInteger(0);
117 this.totalLinksRetrieved = new AtomicInteger(0);
118 this.numSuccessfulLinkResolveFromCache = new AtomicInteger(0);
119 this.numSuccessfulLinkResolveFromFromServer = new AtomicInteger(0);
120 this.numFailedLinkResolve = new AtomicInteger(0);
121 this.aaiWorkOnHand = new AtomicInteger(0);
123 this.mapper = new ObjectMapper();
124 mapper.setSerializationInclusion(Include.NON_EMPTY);
125 mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.KebabCaseStrategy());
126 this.rootNodeFound = false;
129 protected boolean isRootNodeFound() {
130 return rootNodeFound;
133 protected void setRootNodeFound(boolean rootNodeFound) {
134 this.rootNodeFound = rootNodeFound;
137 public long getContextId() {
141 public GizmoAdapter getGizmoAdapter() {
146 * Process self link response.
148 * @param nodeId the node id
150 protected void processSelfLinkResponse(String nodeId) {
152 if (nodeId == null) {
153 LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
154 "Cannot process self link" + " response because nodeId is null");
158 ActiveInventoryNode ain = nodeCache.get(nodeId);
161 LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
162 "Cannot process self link response" + " because can't find node for id = " + nodeId);
166 GizmoEntity gizmoEntity = null;
169 gizmoEntity = mapper.readValue(ain.getOpResult().getResult(), GizmoEntity.class);
170 } catch (Exception exc) {
171 LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR, "Failed to marshal json"
172 + " response str into JsonNode with error, " + exc.getLocalizedMessage());
173 ain.changeState(NodeProcessingState.ERROR,
174 NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_ERROR);
178 if (gizmoEntity == null) {
180 LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR,
181 "Failed to parse json node str." + " Parse resulted a null value.");
182 ain.changeState(NodeProcessingState.ERROR,
183 NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_ERROR);
188 * Now that we have the gizmo entity we can populate the AIN node with it, as well as the
192 ain.setEntityType(gizmoEntity.getType());
194 ain.setPrimaryKeyName(getEntityTypePrimaryKeyName(gizmoEntity.getType()));
196 OxmEntityDescriptor descriptor = oxmEntityLookup.getEntityDescriptors().get(gizmoEntity.getType());
198 if (descriptor != null) {
199 ain.setPrimaryKeyValue(getPrimaryKeyValues(gizmoEntity.getProperties(),
200 descriptor.getPrimaryKeyAttributeNames()));
202 LOG.error(AaiUiMsgs.ERROR_GENERIC, "Could not determine oxm descriptor for entity type = " + gizmoEntity.getType());
205 gizmoEntity.getProperties().forEach((key, value) -> {
206 ain.getProperties().put(key, value);
209 // add edit attributes link
210 if (ain.getSelfLink() != null) {
211 ain.addProperty(SparkyConstants.URI_ATTR_NAME, ain.getSelfLink());
215 * Only discover neighbors if our depth is less than the Max-Traversal-Depth
218 if (ain.getNodeDepth() < this.visualizationConfigs.getMaxSelfLinkTraversalDepth()) {
221 * I think the next thing to do is:
223 * 1. Calculate the source / target node id 2. Add the nodeId to the incoming / outgoing links
224 * collection 3. Add the node to the node cache for processing
227 String resourceLink = null;
228 String relationshipNodeId = null;
229 ActiveInventoryNode relationshipNode = null;
231 for (GizmoRelationshipHint inRelationship : gizmoEntity.getIn()) {
233 if (inRelationship.getSource() != null) {
235 resourceLink = NodeUtils.extractRawGizmoPathWithoutVersion(inRelationship.getSource());
236 relationshipNodeId = NodeUtils.generateUniqueShaDigest(resourceLink);
238 if (!nodeCache.containsKey(relationshipNodeId)) {
240 relationshipNode = new ActiveInventoryNode(visualizationConfigs, oxmEntityLookup);
241 relationshipNode.setNodeId(relationshipNodeId);
242 relationshipNode.setSelfLink(resourceLink);
243 relationshipNode.changeState(NodeProcessingState.SELF_LINK_UNRESOLVED,
244 NodeProcessingAction.NEW_NODE_PROCESSED);
246 ain.addInboundNeighbor(relationshipNodeId);
248 addNode(relationshipNode);
255 for (GizmoRelationshipHint outRelationship : gizmoEntity.getOut()) {
257 if (outRelationship.getTarget() != null) {
259 resourceLink = NodeUtils.extractRawGizmoPathWithoutVersion(outRelationship.getTarget());
260 relationshipNodeId = NodeUtils.generateUniqueShaDigest(resourceLink);
262 if (!nodeCache.containsKey(relationshipNodeId)) {
264 relationshipNode = new ActiveInventoryNode(visualizationConfigs, oxmEntityLookup);
265 relationshipNode.setNodeId(relationshipNodeId);
266 relationshipNode.setSelfLink(resourceLink);
267 relationshipNode.changeState(NodeProcessingState.SELF_LINK_UNRESOLVED,
268 NodeProcessingAction.NEW_NODE_PROCESSED);
270 ain.addOutboundNeighbor(relationshipNodeId);
272 addNode(relationshipNode);
280 ain.changeState(NodeProcessingState.READY, NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_OK);
285 * Perform self link resolve.
287 * @param nodeId the node id
289 protected void performSelfLinkResolve(String nodeId) {
291 if (nodeId == null) {
292 LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
293 "Resolve of self-link" + " has been skipped because provided nodeId is null");
297 ActiveInventoryNode ain = nodeCache.get(nodeId);
300 LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, "Failed to find node with id, " + nodeId
301 + ", from node cache. Resolve self-link method has been skipped.");
305 if (!ain.isSelfLinkPendingResolve()) {
307 ain.setSelfLinkPendingResolve(true);
309 // kick off async self-link resolution
311 if (LOG.isDebugEnabled()) {
312 LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
313 "About to process node in SELF_LINK_UNPROCESSED State, link = " + ain.getSelfLink());
316 numLinksDiscovered.incrementAndGet();
319 * If the current node is the search target, we want to see everything the node has to offer
320 * from the self-link and not filter it to a single node.
323 NodeProcessingTransaction txn = new NodeProcessingTransaction();
324 txn.setProcessingNode(ain);
325 txn.setRequestParameters(null);
326 aaiWorkOnHand.incrementAndGet();
327 supplyAsync(new PerformGizmoNodeSelfLinkProcessingTask(txn, null, gizmoAdapter),
328 graphExecutorService).whenComplete((nodeTxn, error) -> {
333 * an error processing the self link should probably result in the node processing
334 * state shifting to ERROR
337 nodeTxn.getProcessingNode().setSelflinkRetrievalFailure(true);
339 nodeTxn.getProcessingNode().changeState(NodeProcessingState.ERROR,
340 NodeProcessingAction.SELF_LINK_RESOLVE_ERROR);
342 nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
346 totalLinksRetrieved.incrementAndGet();
348 OperationResult opResult = nodeTxn.getOpResult();
350 if (opResult != null && opResult.wasSuccessful()) {
352 if (!opResult.wasSuccessful()) {
353 numFailedLinkResolve.incrementAndGet();
356 if (opResult.isFromCache()) {
357 numSuccessfulLinkResolveFromCache.incrementAndGet();
359 numSuccessfulLinkResolveFromFromServer.incrementAndGet();
363 nodeTxn.getProcessingNode().setOpResult(opResult);
364 nodeTxn.getProcessingNode().changeState(
365 NodeProcessingState.SELF_LINK_RESPONSE_UNPROCESSED,
366 NodeProcessingAction.SELF_LINK_RESOLVE_OK);
368 nodeTxn.getProcessingNode().setSelfLinkProcessed(true);
369 nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
372 LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
373 "Self Link retrieval for link," + txn.getSelfLinkWithModifiers()
374 + ", failed with error code," + nodeTxn.getOpResult().getResultCode()
375 + ", and message," + nodeTxn.getOpResult().getResult());
377 nodeTxn.getProcessingNode().setSelflinkRetrievalFailure(true);
378 nodeTxn.getProcessingNode().setSelfLinkProcessed(true);
380 nodeTxn.getProcessingNode().changeState(NodeProcessingState.ERROR,
381 NodeProcessingAction.SELF_LINK_RESOLVE_ERROR);
383 nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
388 aaiWorkOnHand.decrementAndGet();
396 public GizmoRelationshipEntity getGizmoRelationshipEntity(String gizmoJsonResponse) {
398 GizmoRelationshipEntity gizmoRelationship = null;
400 gizmoRelationship = mapper.readValue(gizmoJsonResponse, GizmoRelationshipEntity.class);
401 } catch (IOException exc) {
402 LOG.error(AaiUiMsgs.ERROR_GENERIC, "Failed to map json to GizmoRelationshipEntity. Error: " + exc.getMessage());
405 return gizmoRelationship;
409 public String getPrimaryKeyValues(Map<String, String> properties, List<String> pkeyNames) {
411 StringBuilder sb = new StringBuilder(64);
413 if (pkeyNames.size() > 0) {
414 String primaryKey = properties.get(pkeyNames.get(0));
415 if (primaryKey != null) {
416 sb.append(primaryKey);
418 // this should be a fatal error because unless we can
419 // successfully retrieve all the expected keys we'll end up
420 // with a garbage node
421 LOG.error(AaiUiMsgs.EXTRACTION_ERROR, "ERROR: Failed to extract" + " keyName, "
422 + pkeyNames.get(0) + ", from properties , " + properties);
426 for (int i = 1; i < pkeyNames.size(); i++) {
428 String kv = properties.get(pkeyNames.get(i));
430 sb.append("/").append(kv);
432 // this should be a fatal error because unless we can
433 // successfully retrieve all the expected keys we'll end up
434 // with a garbage node
435 LOG.error(AaiUiMsgs.EXTRACTION_ERROR, "ERROR: failed to extract keyName, "
436 + pkeyNames.get(i) + ", from properties, " + properties);
441 return sb.toString();
452 * Find and mark root node.
454 * @param queryParams the query params
455 * @return true, if successful
457 protected void findAndMarkRootNode(QueryParams queryParams) {
459 if (isRootNodeFound()) {
463 for (ActiveInventoryNode cacheNode : nodeCache.values()) {
465 if (queryParams.getSearchTargetNodeId().equals(cacheNode.getNodeId())) {
466 cacheNode.setNodeDepth(0);
467 cacheNode.setRootNode(true);
468 LOG.info(AaiUiMsgs.ROOT_NODE_DISCOVERED, queryParams.getSearchTargetNodeId());
469 setRootNodeFound(true);
475 public void addNode(ActiveInventoryNode node) {
481 nodeCache.putIfAbsent(node.getNodeId(), node);
484 public VisualizationConfigs getVisualizationConfigs() {
485 return visualizationConfigs;
488 public void setVisualizationConfigs(VisualizationConfigs visualizationConfigs) {
489 this.visualizationConfigs = visualizationConfigs;
492 public OxmEntityLookup getOxmEntityLookup() {
493 return oxmEntityLookup;
496 public void setOxmEntityLookup(OxmEntityLookup oxmEntityLookup) {
497 this.oxmEntityLookup = oxmEntityLookup;
500 public ObjectMapper getMapper() {
504 public void setMapper(ObjectMapper mapper) {
505 this.mapper = mapper;
508 private void dumpThrottledWorkOnHandLog() {
509 dumpThrottledWorkOnHandLog(false);
512 protected void dumpThrottledWorkOnHandLog(boolean override) {
514 if ((lastProcessStatesSummaryLogInMs < 0)
515 || ((System.currentTimeMillis() > (lastProcessStatesSummaryLogInMs + 5000))) || override) {
517 lastProcessStatesSummaryLogInMs = System.currentTimeMillis();
522 int numSelfLinkUnresolved = 0;
523 int numSelfLinkResponseUnprocessed = 0;
525 for (ActiveInventoryNode cacheNode : nodeCache.values()) {
527 switch (cacheNode.getState()) {
543 case SELF_LINK_UNRESOLVED: {
544 numSelfLinkUnresolved++;
548 case SELF_LINK_RESPONSE_UNPROCESSED: {
549 numSelfLinkResponseUnprocessed++;
559 LOG.info(AaiUiMsgs.INFO_GENERIC,
561 "ProcessCurrentStates for ContextId=%s, [PendingTxns=%d, numInit=%d, numSelfLinkUnresolved=%d, numSelfLinkResponseUnProcessed=%d, numReady=%d, numError=%d]",
562 contextIdStr, aaiWorkOnHand.get(), numInit, numSelfLinkUnresolved, numSelfLinkResponseUnprocessed,
563 numReady, numError));
569 * Process current node states.
571 * @param rootNodeDiscovered the root node discovered
573 protected void processCurrentNodeStates(QueryParams queryParams) {
575 * Force an evaluation of node depths before determining if we should limit state-based
576 * traversal or processing.
579 findAndMarkRootNode(queryParams);
581 verifyOutboundNeighbors();
583 for (ActiveInventoryNode cacheNode : nodeCache.values()) {
585 if (LOG.isDebugEnabled()) {
586 LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "processCurrentNodeState(), nid = "
587 + cacheNode.getNodeId() + " , nodeDepth = " + cacheNode.getNodeDepth());
590 switch (cacheNode.getState()) {
593 processInitialState(cacheNode.getNodeId());
602 case SELF_LINK_UNRESOLVED: {
603 performSelfLinkResolve(cacheNode.getNodeId());
607 case SELF_LINK_RESPONSE_UNPROCESSED: {
608 processSelfLinkResponse(cacheNode.getNodeId());
618 dumpThrottledWorkOnHandLog();
624 public int getNumSuccessfulLinkResolveFromCache() {
625 return numSuccessfulLinkResolveFromCache.get();
628 public int getNumSuccessfulLinkResolveFromFromServer() {
629 return numSuccessfulLinkResolveFromFromServer.get();
632 public int getNumFailedLinkResolve() {
633 return numFailedLinkResolve.get();
636 public ConcurrentHashMap<String, ActiveInventoryNode> getNodeCache() {
643 * Process initial state.
645 * @param nodeId the node id
647 protected void processInitialState(String nodeId) {
649 if (nodeId == null) {
650 LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_INITIAL_STATE, "Node id is null");
654 ActiveInventoryNode cachedNode = nodeCache.get(nodeId);
656 if (cachedNode == null) {
657 LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_INITIAL_STATE,
658 "Node cannot be" + " found for nodeId, " + nodeId);
662 if (cachedNode.getSelfLink() == null) {
664 if (cachedNode.getNodeId() == null) {
667 * if the self link is null at the INIT state, which could be valid if this node is a
668 * complex attribute group which didn't originate from a self-link, but in that situation
669 * both the node id and node key should already be set.
672 cachedNode.changeState(NodeProcessingState.ERROR, NodeProcessingAction.NODE_IDENTITY_ERROR);
676 if (cachedNode.getNodeId() != null) {
679 * This should be the success path branch if the self-link is not set
682 cachedNode.changeState(NodeProcessingState.SELF_LINK_RESPONSE_UNPROCESSED,
683 NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_OK);
689 if (cachedNode.hasResolvedSelfLink()) {
690 LOG.error(AaiUiMsgs.INVALID_RESOLVE_STATE_DURING_INIT);
691 cachedNode.changeState(NodeProcessingState.ERROR,
692 NodeProcessingAction.UNEXPECTED_STATE_TRANSITION);
694 cachedNode.changeState(NodeProcessingState.SELF_LINK_UNRESOLVED,
695 NodeProcessingAction.SELF_LINK_SET);
701 * Process skeleton node.
703 * @param skeletonNode the skeleton node
704 * @param queryParams the query params
706 protected void processSearchableEntity(SearchableEntity searchTargetEntity,
707 QueryParams queryParams) {
709 if (searchTargetEntity == null) {
713 if (searchTargetEntity.getId() == null) {
714 LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_SKELETON_NODE, "Failed to process skeleton"
715 + " node because nodeId is null for node, " + searchTargetEntity.getLink());
719 ActiveInventoryNode newNode =
720 new ActiveInventoryNode(this.visualizationConfigs, oxmEntityLookup);
722 newNode.setNodeId(searchTargetEntity.getId());
724 newNode.setNodeDepth(0);
725 newNode.setRootNode(true);
726 LOG.info(AaiUiMsgs.ROOT_NODE_DISCOVERED, queryParams.getSearchTargetNodeId());
727 setRootNodeFound(true);
729 newNode.setSelfLink(searchTargetEntity.getLink());
731 nodeCache.putIfAbsent(newNode.getNodeId(), newNode);
734 protected int getTotalWorkOnHand() {
736 int numNodesWithPendingStates = 0;
738 if (isRootNodeFound()) {
739 evaluateNodeDepths();
742 for (ActiveInventoryNode n : nodeCache.values()) {
744 switch (n.getState()) {
748 // do nothing, these are our normal
756 * for all other states, there is work to be done
758 numNodesWithPendingStates++;
765 return (aaiWorkOnHand.get() + numNodesWithPendingStates);
770 * Checks for out standing work.
772 * @return true, if successful
774 protected void processOutstandingWork(QueryParams queryParams) {
776 while (getTotalWorkOnHand() > 0) {
779 * Force an evaluation of node depths before determining if we should limit state-based
780 * traversal or processing.
783 processCurrentNodeStates(queryParams);
787 } catch (InterruptedException exc) {
788 LOG.error(AaiUiMsgs.PROCESSING_LOOP_INTERUPTED, exc.getMessage());
789 Thread.currentThread().interrupt();
795 dumpThrottledWorkOnHandLog(true);
803 * org.onap.aai.sparky.viewandinspect.services.VisualizationContext#processSelfLinks(org.onap.aai.
804 * sparky.sync.entity.SearchableEntity, org.onap.aai.sparky.viewandinspect.entity.QueryParams)
807 public void processSelfLinks(SearchableEntity searchtargetEntity, QueryParams queryParams) {
812 if (searchtargetEntity == null) {
813 LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
814 contextIdStr + " - Failed to" + " processSelfLinks, searchtargetEntity is null");
818 long startTimeInMs = System.currentTimeMillis();
820 processSearchableEntity(searchtargetEntity, queryParams);
823 * This method is blocking until we decouple it with a CountDownLatch await condition, and
824 * make the internal graph processing more event-y.
827 processOutstandingWork(queryParams);
829 long totalResolveTime = (System.currentTimeMillis() - startTimeInMs);
831 long opTime = System.currentTimeMillis() - startTimeInMs;
833 LOG.info(AaiUiMsgs.ALL_TRANSACTIONS_RESOLVED, String.valueOf(totalResolveTime),
834 String.valueOf(totalLinksRetrieved.get()), String.valueOf(opTime));
836 } catch (Exception exc) {
837 LOG.error(AaiUiMsgs.VISUALIZATION_OUTPUT_ERROR, exc.getMessage());
843 * Verify outbound neighbors.
845 protected void verifyOutboundNeighbors() {
847 for (ActiveInventoryNode srcNode : nodeCache.values()) {
849 for (String targetNodeId : srcNode.getOutboundNeighbors()) {
851 ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
853 if (targetNode != null && srcNode.getNodeId() != null) {
855 targetNode.addInboundNeighbor(srcNode.getNodeId());
857 if (this.visualizationConfigs.makeAllNeighborsBidirectional()) {
858 targetNode.addOutboundNeighbor(srcNode.getNodeId());
870 * Evaluate node depths.
872 protected void evaluateNodeDepths() {
877 while (numChanged != 0) {
882 for (ActiveInventoryNode srcNode : nodeCache.values()) {
884 if (srcNode.getState() == NodeProcessingState.INIT) {
887 * this maybe the only state that we don't want to to process the node depth on, because
888 * typically it won't have any valid fields set, and it may remain in a partial state
889 * until we have processed the self-link.
896 for (String targetNodeId : srcNode.getOutboundNeighbors()) {
897 ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
899 if (targetNode != null) {
901 if (targetNode.changeDepth(srcNode.getNodeDepth() + 1)) {
907 for (String targetNodeId : srcNode.getInboundNeighbors()) {
908 ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
910 if (targetNode != null) {
912 if (targetNode.changeDepth(srcNode.getNodeDepth() + 1)) {
919 if (numAttempts >= MAX_DEPTH_EVALUATION_ATTEMPTS) {
920 LOG.info(AaiUiMsgs.MAX_EVALUATION_ATTEMPTS_EXCEEDED);
926 if (LOG.isDebugEnabled()) {
927 if (numAttempts > 0) {
928 LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
929 "Evaluate node depths completed in " + numAttempts + " attempts");
931 LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
932 "Evaluate node depths completed in 0 attempts because all nodes at correct depth");
940 * Gets the entity type primary key name.
942 * @param entityType the entity type
943 * @return the entity type primary key name
947 protected String getEntityTypePrimaryKeyName(String entityType) {
949 if (entityType == null) {
950 LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE,
951 "node primary key" + " name because entity type is null");
955 OxmEntityDescriptor descriptor = oxmEntityLookup.getEntityDescriptors().get(entityType);
957 if (descriptor == null) {
958 LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE,
959 "oxm entity" + " descriptor for entityType = " + entityType);
963 List<String> pkeyNames = descriptor.getPrimaryKeyAttributeNames();
965 if (pkeyNames == null || pkeyNames.size() == 0) {
966 LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE,
967 "node primary" + " key because descriptor primary key names is empty");
971 return NodeUtils.concatArray(pkeyNames, "/");