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 exc.printStackTrace();
172 LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR, "Failed to marshal json"
173 + " response str into JsonNode with error, " + exc.getLocalizedMessage());
174 ain.changeState(NodeProcessingState.ERROR,
175 NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_ERROR);
179 if (gizmoEntity == null) {
181 LOG.error(AaiUiMsgs.SELF_LINK_JSON_PARSE_ERROR,
182 "Failed to parse json node str." + " Parse resulted a null value.");
183 ain.changeState(NodeProcessingState.ERROR,
184 NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_ERROR);
189 * Now that we have the gizmo entity we can populate the AIN node with it, as well as the
193 ain.setEntityType(gizmoEntity.getType());
195 ain.setPrimaryKeyName(getEntityTypePrimaryKeyName(gizmoEntity.getType()));
197 OxmEntityDescriptor descriptor = oxmEntityLookup.getEntityDescriptors().get(gizmoEntity.getType());
199 if (descriptor != null) {
200 ain.setPrimaryKeyValue(getPrimaryKeyValues(gizmoEntity.getProperties(),
201 descriptor.getPrimaryKeyAttributeNames()));
203 LOG.error(AaiUiMsgs.ERROR_GENERIC, "Could not determine oxm descriptor for entity type = " + gizmoEntity.getType());
206 gizmoEntity.getProperties().forEach((key, value) -> {
207 ain.getProperties().put(key, value);
210 // add edit attributes link
211 if (ain.getSelfLink() != null) {
212 ain.addProperty(SparkyConstants.URI_ATTR_NAME, ain.getSelfLink());
216 * Only discover neighbors if our depth is less than the Max-Traversal-Depth
219 if (ain.getNodeDepth() < this.visualizationConfigs.getMaxSelfLinkTraversalDepth()) {
222 * I think the next thing to do is:
224 * 1. Calculate the source / target node id 2. Add the nodeId to the incoming / outgoing links
225 * collection 3. Add the node to the node cache for processing
228 String resourceLink = null;
229 String relationshipNodeId = null;
230 ActiveInventoryNode relationshipNode = null;
232 for (GizmoRelationshipHint inRelationship : gizmoEntity.getIn()) {
234 if (inRelationship.getSource() != null) {
236 resourceLink = NodeUtils.extractRawGizmoPathWithoutVersion(inRelationship.getSource());
237 relationshipNodeId = NodeUtils.generateUniqueShaDigest(resourceLink);
239 if (!nodeCache.containsKey(relationshipNodeId)) {
241 relationshipNode = new ActiveInventoryNode(visualizationConfigs, oxmEntityLookup);
242 relationshipNode.setNodeId(relationshipNodeId);
243 relationshipNode.setSelfLink(resourceLink);
244 relationshipNode.changeState(NodeProcessingState.SELF_LINK_UNRESOLVED,
245 NodeProcessingAction.NEW_NODE_PROCESSED);
247 ain.addInboundNeighbor(relationshipNodeId);
249 addNode(relationshipNode);
256 for (GizmoRelationshipHint outRelationship : gizmoEntity.getOut()) {
258 if (outRelationship.getTarget() != null) {
260 resourceLink = NodeUtils.extractRawGizmoPathWithoutVersion(outRelationship.getTarget());
261 relationshipNodeId = NodeUtils.generateUniqueShaDigest(resourceLink);
263 if (!nodeCache.containsKey(relationshipNodeId)) {
265 relationshipNode = new ActiveInventoryNode(visualizationConfigs, oxmEntityLookup);
266 relationshipNode.setNodeId(relationshipNodeId);
267 relationshipNode.setSelfLink(resourceLink);
268 relationshipNode.changeState(NodeProcessingState.SELF_LINK_UNRESOLVED,
269 NodeProcessingAction.NEW_NODE_PROCESSED);
271 ain.addOutboundNeighbor(relationshipNodeId);
273 addNode(relationshipNode);
281 ain.changeState(NodeProcessingState.READY, NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_OK);
286 * Perform self link resolve.
288 * @param nodeId the node id
290 protected void performSelfLinkResolve(String nodeId) {
292 if (nodeId == null) {
293 LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
294 "Resolve of self-link" + " has been skipped because provided nodeId is null");
298 ActiveInventoryNode ain = nodeCache.get(nodeId);
301 LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, "Failed to find node with id, " + nodeId
302 + ", from node cache. Resolve self-link method has been skipped.");
306 if (!ain.isSelfLinkPendingResolve()) {
308 ain.setSelfLinkPendingResolve(true);
310 // kick off async self-link resolution
312 if (LOG.isDebugEnabled()) {
313 LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
314 "About to process node in SELF_LINK_UNPROCESSED State, link = " + ain.getSelfLink());
317 numLinksDiscovered.incrementAndGet();
320 * If the current node is the search target, we want to see everything the node has to offer
321 * from the self-link and not filter it to a single node.
324 NodeProcessingTransaction txn = new NodeProcessingTransaction();
325 txn.setProcessingNode(ain);
326 txn.setRequestParameters(null);
327 aaiWorkOnHand.incrementAndGet();
328 supplyAsync(new PerformGizmoNodeSelfLinkProcessingTask(txn, null, gizmoAdapter),
329 graphExecutorService).whenComplete((nodeTxn, error) -> {
334 * an error processing the self link should probably result in the node processing
335 * state shifting to ERROR
338 nodeTxn.getProcessingNode().setSelflinkRetrievalFailure(true);
340 nodeTxn.getProcessingNode().changeState(NodeProcessingState.ERROR,
341 NodeProcessingAction.SELF_LINK_RESOLVE_ERROR);
343 nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
347 totalLinksRetrieved.incrementAndGet();
349 OperationResult opResult = nodeTxn.getOpResult();
351 if (opResult != null && opResult.wasSuccessful()) {
353 if (!opResult.wasSuccessful()) {
354 numFailedLinkResolve.incrementAndGet();
357 if (opResult.isFromCache()) {
358 numSuccessfulLinkResolveFromCache.incrementAndGet();
360 numSuccessfulLinkResolveFromFromServer.incrementAndGet();
364 nodeTxn.getProcessingNode().setOpResult(opResult);
365 nodeTxn.getProcessingNode().changeState(
366 NodeProcessingState.SELF_LINK_RESPONSE_UNPROCESSED,
367 NodeProcessingAction.SELF_LINK_RESOLVE_OK);
369 nodeTxn.getProcessingNode().setSelfLinkProcessed(true);
370 nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
373 LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
374 "Self Link retrieval for link," + txn.getSelfLinkWithModifiers()
375 + ", failed with error code," + nodeTxn.getOpResult().getResultCode()
376 + ", and message," + nodeTxn.getOpResult().getResult());
378 nodeTxn.getProcessingNode().setSelflinkRetrievalFailure(true);
379 nodeTxn.getProcessingNode().setSelfLinkProcessed(true);
381 nodeTxn.getProcessingNode().changeState(NodeProcessingState.ERROR,
382 NodeProcessingAction.SELF_LINK_RESOLVE_ERROR);
384 nodeTxn.getProcessingNode().setSelfLinkPendingResolve(false);
389 aaiWorkOnHand.decrementAndGet();
397 public GizmoRelationshipEntity getGizmoRelationshipEntity(String gizmoJsonResponse) {
399 GizmoRelationshipEntity gizmoRelationship = null;
401 gizmoRelationship = mapper.readValue(gizmoJsonResponse, GizmoRelationshipEntity.class);
402 } catch (IOException exc) {
403 LOG.error(AaiUiMsgs.ERROR_GENERIC, "Failed to map json to GizmoRelationshipEntity. Error: " + exc.getMessage());
406 return gizmoRelationship;
410 public String getPrimaryKeyValues(Map<String, String> properties, List<String> pkeyNames) {
412 StringBuilder sb = new StringBuilder(64);
414 if (pkeyNames.size() > 0) {
415 String primaryKey = properties.get(pkeyNames.get(0));
416 if (primaryKey != null) {
417 sb.append(primaryKey);
419 // this should be a fatal error because unless we can
420 // successfully retrieve all the expected keys we'll end up
421 // with a garbage node
422 LOG.error(AaiUiMsgs.EXTRACTION_ERROR, "ERROR: Failed to extract" + " keyName, "
423 + pkeyNames.get(0) + ", from properties , " + properties);
427 for (int i = 1; i < pkeyNames.size(); i++) {
429 String kv = properties.get(pkeyNames.get(i));
431 sb.append("/").append(kv);
433 // this should be a fatal error because unless we can
434 // successfully retrieve all the expected keys we'll end up
435 // with a garbage node
436 LOG.error(AaiUiMsgs.EXTRACTION_ERROR, "ERROR: failed to extract keyName, "
437 + pkeyNames.get(i) + ", from properties, " + properties);
442 return sb.toString();
453 * Find and mark root node.
455 * @param queryParams the query params
456 * @return true, if successful
458 protected void findAndMarkRootNode(QueryParams queryParams) {
460 if (isRootNodeFound()) {
464 for (ActiveInventoryNode cacheNode : nodeCache.values()) {
466 if (queryParams.getSearchTargetNodeId().equals(cacheNode.getNodeId())) {
467 cacheNode.setNodeDepth(0);
468 cacheNode.setRootNode(true);
469 LOG.info(AaiUiMsgs.ROOT_NODE_DISCOVERED, queryParams.getSearchTargetNodeId());
470 setRootNodeFound(true);
476 public void addNode(ActiveInventoryNode node) {
482 nodeCache.putIfAbsent(node.getNodeId(), node);
485 public VisualizationConfigs getVisualizationConfigs() {
486 return visualizationConfigs;
489 public void setVisualizationConfigs(VisualizationConfigs visualizationConfigs) {
490 this.visualizationConfigs = visualizationConfigs;
493 public OxmEntityLookup getOxmEntityLookup() {
494 return oxmEntityLookup;
497 public void setOxmEntityLookup(OxmEntityLookup oxmEntityLookup) {
498 this.oxmEntityLookup = oxmEntityLookup;
501 public ObjectMapper getMapper() {
505 public void setMapper(ObjectMapper mapper) {
506 this.mapper = mapper;
509 private void dumpThrottledWorkOnHandLog() {
510 dumpThrottledWorkOnHandLog(false);
513 protected void dumpThrottledWorkOnHandLog(boolean override) {
515 if ((lastProcessStatesSummaryLogInMs < 0)
516 || ((System.currentTimeMillis() > (lastProcessStatesSummaryLogInMs + 5000))) || override) {
518 lastProcessStatesSummaryLogInMs = System.currentTimeMillis();
523 int numSelfLinkUnresolved = 0;
524 int numSelfLinkResponseUnprocessed = 0;
526 for (ActiveInventoryNode cacheNode : nodeCache.values()) {
528 switch (cacheNode.getState()) {
544 case SELF_LINK_UNRESOLVED: {
545 numSelfLinkUnresolved++;
549 case SELF_LINK_RESPONSE_UNPROCESSED: {
550 numSelfLinkResponseUnprocessed++;
560 LOG.info(AaiUiMsgs.INFO_GENERIC,
562 "ProcessCurrentStates for ContextId=%s, [PendingTxns=%d, numInit=%d, numSelfLinkUnresolved=%d, numSelfLinkResponseUnProcessed=%d, numReady=%d, numError=%d]",
563 contextIdStr, aaiWorkOnHand.get(), numInit, numSelfLinkUnresolved, numSelfLinkResponseUnprocessed,
564 numReady, numError));
570 * Process current node states.
572 * @param rootNodeDiscovered the root node discovered
574 protected void processCurrentNodeStates(QueryParams queryParams) {
576 * Force an evaluation of node depths before determining if we should limit state-based
577 * traversal or processing.
580 findAndMarkRootNode(queryParams);
582 verifyOutboundNeighbors();
584 for (ActiveInventoryNode cacheNode : nodeCache.values()) {
586 if (LOG.isDebugEnabled()) {
587 LOG.debug(AaiUiMsgs.DEBUG_GENERIC, "processCurrentNodeState(), nid = "
588 + cacheNode.getNodeId() + " , nodeDepth = " + cacheNode.getNodeDepth());
591 switch (cacheNode.getState()) {
594 processInitialState(cacheNode.getNodeId());
603 case SELF_LINK_UNRESOLVED: {
604 performSelfLinkResolve(cacheNode.getNodeId());
608 case SELF_LINK_RESPONSE_UNPROCESSED: {
609 processSelfLinkResponse(cacheNode.getNodeId());
619 dumpThrottledWorkOnHandLog();
625 public int getNumSuccessfulLinkResolveFromCache() {
626 return numSuccessfulLinkResolveFromCache.get();
629 public int getNumSuccessfulLinkResolveFromFromServer() {
630 return numSuccessfulLinkResolveFromFromServer.get();
633 public int getNumFailedLinkResolve() {
634 return numFailedLinkResolve.get();
637 public ConcurrentHashMap<String, ActiveInventoryNode> getNodeCache() {
644 * Process initial state.
646 * @param nodeId the node id
648 protected void processInitialState(String nodeId) {
650 if (nodeId == null) {
651 LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_INITIAL_STATE, "Node id is null");
655 ActiveInventoryNode cachedNode = nodeCache.get(nodeId);
657 if (cachedNode == null) {
658 LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_INITIAL_STATE,
659 "Node cannot be" + " found for nodeId, " + nodeId);
663 if (cachedNode.getSelfLink() == null) {
665 if (cachedNode.getNodeId() == null) {
668 * if the self link is null at the INIT state, which could be valid if this node is a
669 * complex attribute group which didn't originate from a self-link, but in that situation
670 * both the node id and node key should already be set.
673 cachedNode.changeState(NodeProcessingState.ERROR, NodeProcessingAction.NODE_IDENTITY_ERROR);
677 if (cachedNode.getNodeId() != null) {
680 * This should be the success path branch if the self-link is not set
683 cachedNode.changeState(NodeProcessingState.SELF_LINK_RESPONSE_UNPROCESSED,
684 NodeProcessingAction.SELF_LINK_RESPONSE_PARSE_OK);
690 if (cachedNode.hasResolvedSelfLink()) {
691 LOG.error(AaiUiMsgs.INVALID_RESOLVE_STATE_DURING_INIT);
692 cachedNode.changeState(NodeProcessingState.ERROR,
693 NodeProcessingAction.UNEXPECTED_STATE_TRANSITION);
695 cachedNode.changeState(NodeProcessingState.SELF_LINK_UNRESOLVED,
696 NodeProcessingAction.SELF_LINK_SET);
702 * Process skeleton node.
704 * @param skeletonNode the skeleton node
705 * @param queryParams the query params
707 protected void processSearchableEntity(SearchableEntity searchTargetEntity,
708 QueryParams queryParams) {
710 if (searchTargetEntity == null) {
714 if (searchTargetEntity.getId() == null) {
715 LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_SKELETON_NODE, "Failed to process skeleton"
716 + " node because nodeId is null for node, " + searchTargetEntity.getLink());
720 ActiveInventoryNode newNode =
721 new ActiveInventoryNode(this.visualizationConfigs, oxmEntityLookup);
723 newNode.setNodeId(searchTargetEntity.getId());
725 newNode.setNodeDepth(0);
726 newNode.setRootNode(true);
727 LOG.info(AaiUiMsgs.ROOT_NODE_DISCOVERED, queryParams.getSearchTargetNodeId());
728 setRootNodeFound(true);
730 newNode.setSelfLink(searchTargetEntity.getLink());
732 nodeCache.putIfAbsent(newNode.getNodeId(), newNode);
735 protected int getTotalWorkOnHand() {
737 int numNodesWithPendingStates = 0;
739 if (isRootNodeFound()) {
740 evaluateNodeDepths();
743 for (ActiveInventoryNode n : nodeCache.values()) {
745 switch (n.getState()) {
749 // do nothing, these are our normal
757 * for all other states, there is work to be done
759 numNodesWithPendingStates++;
766 return (aaiWorkOnHand.get() + numNodesWithPendingStates);
771 * Checks for out standing work.
773 * @return true, if successful
775 protected void processOutstandingWork(QueryParams queryParams) {
777 while (getTotalWorkOnHand() > 0) {
780 * Force an evaluation of node depths before determining if we should limit state-based
781 * traversal or processing.
784 processCurrentNodeStates(queryParams);
788 } catch (InterruptedException exc) {
789 LOG.error(AaiUiMsgs.PROCESSING_LOOP_INTERUPTED, exc.getMessage());
790 Thread.currentThread().interrupt();
796 dumpThrottledWorkOnHandLog(true);
804 * org.onap.aai.sparky.viewandinspect.services.VisualizationContext#processSelfLinks(org.onap.aai.
805 * sparky.sync.entity.SearchableEntity, org.onap.aai.sparky.viewandinspect.entity.QueryParams)
808 public void processSelfLinks(SearchableEntity searchtargetEntity, QueryParams queryParams) {
813 if (searchtargetEntity == null) {
814 LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR,
815 contextIdStr + " - Failed to" + " processSelfLinks, searchtargetEntity is null");
819 long startTimeInMs = System.currentTimeMillis();
821 processSearchableEntity(searchtargetEntity, queryParams);
824 * This method is blocking until we decouple it with a CountDownLatch await condition, and
825 * make the internal graph processing more event-y.
828 processOutstandingWork(queryParams);
830 long totalResolveTime = (System.currentTimeMillis() - startTimeInMs);
832 long opTime = System.currentTimeMillis() - startTimeInMs;
834 LOG.info(AaiUiMsgs.ALL_TRANSACTIONS_RESOLVED, String.valueOf(totalResolveTime),
835 String.valueOf(totalLinksRetrieved.get()), String.valueOf(opTime));
837 } catch (Exception exc) {
838 LOG.error(AaiUiMsgs.VISUALIZATION_OUTPUT_ERROR, exc.getMessage());
844 * Verify outbound neighbors.
846 protected void verifyOutboundNeighbors() {
848 for (ActiveInventoryNode srcNode : nodeCache.values()) {
850 for (String targetNodeId : srcNode.getOutboundNeighbors()) {
852 ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
854 if (targetNode != null && srcNode.getNodeId() != null) {
856 targetNode.addInboundNeighbor(srcNode.getNodeId());
858 if (this.visualizationConfigs.makeAllNeighborsBidirectional()) {
859 targetNode.addOutboundNeighbor(srcNode.getNodeId());
871 * Evaluate node depths.
873 protected void evaluateNodeDepths() {
878 while (numChanged != 0) {
883 for (ActiveInventoryNode srcNode : nodeCache.values()) {
885 if (srcNode.getState() == NodeProcessingState.INIT) {
888 * this maybe the only state that we don't want to to process the node depth on, because
889 * typically it won't have any valid fields set, and it may remain in a partial state
890 * until we have processed the self-link.
897 for (String targetNodeId : srcNode.getOutboundNeighbors()) {
898 ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
900 if (targetNode != null) {
902 if (targetNode.changeDepth(srcNode.getNodeDepth() + 1)) {
908 for (String targetNodeId : srcNode.getInboundNeighbors()) {
909 ActiveInventoryNode targetNode = nodeCache.get(targetNodeId);
911 if (targetNode != null) {
913 if (targetNode.changeDepth(srcNode.getNodeDepth() + 1)) {
920 if (numAttempts >= MAX_DEPTH_EVALUATION_ATTEMPTS) {
921 LOG.info(AaiUiMsgs.MAX_EVALUATION_ATTEMPTS_EXCEEDED);
927 if (LOG.isDebugEnabled()) {
928 if (numAttempts > 0) {
929 LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
930 "Evaluate node depths completed in " + numAttempts + " attempts");
932 LOG.debug(AaiUiMsgs.DEBUG_GENERIC,
933 "Evaluate node depths completed in 0 attempts because all nodes at correct depth");
941 * Gets the entity type primary key name.
943 * @param entityType the entity type
944 * @return the entity type primary key name
948 protected String getEntityTypePrimaryKeyName(String entityType) {
950 if (entityType == null) {
951 LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE,
952 "node primary key" + " name because entity type is null");
956 OxmEntityDescriptor descriptor = oxmEntityLookup.getEntityDescriptors().get(entityType);
958 if (descriptor == null) {
959 LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE,
960 "oxm entity" + " descriptor for entityType = " + entityType);
964 List<String> pkeyNames = descriptor.getPrimaryKeyAttributeNames();
966 if (pkeyNames == null || pkeyNames.size() == 0) {
967 LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE,
968 "node primary" + " key because descriptor primary key names is empty");
972 return NodeUtils.concatArray(pkeyNames, "/");