diff options
Diffstat (limited to 'sparkybe-onap-service/src/main/java')
14 files changed, 316 insertions, 322 deletions
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessor.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessor.java index 5c4e160..fb0280e 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessor.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessor.java @@ -22,7 +22,6 @@ package org.onap.aai.sparky.viewandinspect; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.apache.camel.Exchange; import org.onap.aai.cl.api.Logger; @@ -31,7 +30,6 @@ import org.onap.aai.restclient.client.OperationResult; import org.onap.aai.sparky.logging.AaiUiMsgs; import org.onap.aai.sparky.logging.util.ServletUtils; import org.onap.aai.sparky.viewandinspect.entity.QueryRequest; -import org.onap.aai.sparky.viewandinspect.services.VisualizationService; import org.restlet.data.Status; public class SchemaVisualizationProcessor { @@ -42,7 +40,7 @@ public class SchemaVisualizationProcessor { private VisualizationService visualizationService; - public SchemaVisualizationProcessor()throws Exception{} + public SchemaVisualizationProcessor() throws Exception{} protected String generateJsonErrorResponse(String message) { return String.format("{ \"errorMessage\" : %s }", message); @@ -68,7 +66,7 @@ public class SchemaVisualizationProcessor { if (hashId != null) { - operationResult = this.getVisualizationService().buildVisualizationUsingGenericQuery(hashId); + operationResult = this.getVisualizationService().buildVisualization(hashId); if (operationResult.getResultCode() != Status.SUCCESS_OK.getCode()) { exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, operationResult.getResultCode()); diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContext.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/VisualizationContext.java index 1641aa3..0d2f8aa 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContext.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/VisualizationContext.java @@ -18,13 +18,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.sparky.viewandinspect.services; +package org.onap.aai.sparky.viewandinspect; import java.util.concurrent.ConcurrentHashMap; import org.onap.aai.sparky.sync.entity.SearchableEntity; import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode; -import org.onap.aai.sparky.viewandinspect.entity.InlineMessage; import org.onap.aai.sparky.viewandinspect.entity.QueryParams; @@ -36,16 +35,10 @@ public interface VisualizationContext { * @param skeletonNode the skeleton node * @param queryParams the query params */ - void processSelfLinks(SearchableEntity searchtargetEntity, QueryParams queryParams); + public void processSelfLinks(SearchableEntity searchtargetEntity, QueryParams queryParams); - ConcurrentHashMap<String, ActiveInventoryNode> getNodeCache(); - - InlineMessage getInlineMessage(); + public ConcurrentHashMap<String, ActiveInventoryNode> getNodeCache(); - int getNumFailedLinkResolve(); - - int getNumSuccessfulLinkResolveFromCache(); - - int getNumSuccessfulLinkResolveFromFromServer(); + public long getContextId(); } diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/VisualizationContextBuilder.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/VisualizationContextBuilder.java new file mode 100644 index 0000000..6286fde --- /dev/null +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/VisualizationContextBuilder.java @@ -0,0 +1,9 @@ +package org.onap.aai.sparky.viewandinspect; + +public interface VisualizationContextBuilder { + + public VisualizationContext getVisualizationContext() throws Exception; + + public void shutdown(); + +} diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationService.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/VisualizationService.java index 7693885..7a090b0 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationService.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/VisualizationService.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.sparky.viewandinspect.services; +package org.onap.aai.sparky.viewandinspect; import org.onap.aai.restclient.client.OperationResult; @@ -33,7 +33,7 @@ public interface VisualizationService { * @return the query request */ - QueryRequest analyzeQueryRequestBody(String queryRequestJson); + public QueryRequest analyzeQueryRequestBody(String queryRequestJson); /** * Builds the visualization using generic query. @@ -41,8 +41,8 @@ public interface VisualizationService { * @param queryRequest the query request * @return the operation result */ - OperationResult buildVisualizationUsingGenericQuery(QueryRequest queryRequest); - - void shutdown(); + public OperationResult buildVisualization(QueryRequest queryRequest); + + public void shutdown(); } diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java index b0834ca..acca775 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java @@ -47,16 +47,12 @@ public class VisualizationConfigs { private ArrayList<String> shallowEntities; - private boolean gizmoEnabled; - private SparkyResourceLoader resourceLoader; /** * Instantiates a new visualization config. */ - public VisualizationConfigs() { - this.gizmoEnabled = false; - } + public VisualizationConfigs() {} public ArrayList<String> getShallowEntities() { return shallowEntities; @@ -135,14 +131,6 @@ public class VisualizationConfigs { this.numOfThreadsToFetchNodeIntegrity = numOfThreadsToFetchNodeIntegrity; } - public boolean isGizmoEnabled() { - return gizmoEnabled; - } - - public void setGizmoEnabled(boolean gizmoEnabled) { - this.gizmoEnabled = gizmoEnabled; - } - public SparkyResourceLoader getResourceLoader() { return resourceLoader; } @@ -152,19 +140,22 @@ public class VisualizationConfigs { } @Override - public String toString() { - return "VisualizationConfigs [maxSelfLinkTraversalDepth=" + maxSelfLinkTraversalDepth - + ", visualizationDebugEnabled=" + visualizationDebugEnabled + ", " - + (aaiEntityNodeDescriptors != null ? "aaiEntityNodeDescriptors=" + aaiEntityNodeDescriptors + ", " - : "") - + (generalNodeClassName != null ? "generalNodeClassName=" + generalNodeClassName + ", " : "") - + (searchNodeClassName != null ? "searchNodeClassName=" + searchNodeClassName + ", " : "") - + (selectedSearchedNodeClassName != null - ? "selectedSearchedNodeClassName=" + selectedSearchedNodeClassName + ", " : "") - + "numOfThreadsToFetchNodeIntegrity=" + numOfThreadsToFetchNodeIntegrity - + ", makeAllNeighborsBidirectional=" + makeAllNeighborsBidirectional + ", " - + (shallowEntities != null ? "shallowEntities=" + shallowEntities + ", " : "") + "gizmoEnabled=" - + gizmoEnabled + "]"; - } + public String toString() { + return "VisualizationConfigs [maxSelfLinkTraversalDepth=" + maxSelfLinkTraversalDepth + + ", visualizationDebugEnabled=" + visualizationDebugEnabled + ", " + + (aaiEntityNodeDescriptors != null + ? "aaiEntityNodeDescriptors=" + aaiEntityNodeDescriptors + ", " : "") + + (generalNodeClassName != null ? "generalNodeClassName=" + generalNodeClassName + ", " + : "") + + (searchNodeClassName != null ? "searchNodeClassName=" + searchNodeClassName + ", " : "") + + (selectedSearchedNodeClassName != null + ? "selectedSearchedNodeClassName=" + selectedSearchedNodeClassName + ", " : "") + + "numOfThreadsToFetchNodeIntegrity=" + numOfThreadsToFetchNodeIntegrity + + ", makeAllNeighborsBidirectional=" + makeAllNeighborsBidirectional + ", " + + (shallowEntities != null ? "shallowEntities=" + shallowEntities + ", " : "") + + (resourceLoader != null ? "resourceLoader=" + resourceLoader : "") + "]"; + } + + } diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseGizmoVisualizationContext.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/context/BaseGizmoVisualizationContext.java index 11a771b..f058c48 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseGizmoVisualizationContext.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/context/BaseGizmoVisualizationContext.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.sparky.viewandinspect.services; +package org.onap.aai.sparky.viewandinspect.context; import static java.util.concurrent.CompletableFuture.supplyAsync; @@ -38,13 +38,13 @@ import org.onap.aai.sparky.dal.GizmoAdapter; import org.onap.aai.sparky.logging.AaiUiMsgs; import org.onap.aai.sparky.sync.entity.SearchableEntity; import org.onap.aai.sparky.util.NodeUtils; +import org.onap.aai.sparky.viewandinspect.VisualizationContext; import org.onap.aai.sparky.viewandinspect.config.SparkyConstants; import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode; import org.onap.aai.sparky.viewandinspect.entity.GizmoEntity; import org.onap.aai.sparky.viewandinspect.entity.GizmoRelationshipEntity; import org.onap.aai.sparky.viewandinspect.entity.GizmoRelationshipHint; -import org.onap.aai.sparky.viewandinspect.entity.InlineMessage; import org.onap.aai.sparky.viewandinspect.entity.NodeProcessingTransaction; import org.onap.aai.sparky.viewandinspect.entity.QueryParams; import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingAction; @@ -65,36 +65,35 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { private static final Logger LOG = LoggerFactory.getInstance().getLogger(BaseGizmoVisualizationContext.class); - private final GizmoAdapter gizmoAdapter; + protected final GizmoAdapter gizmoAdapter; - private AtomicInteger numLinksDiscovered; - private AtomicInteger numSuccessfulLinkResolveFromCache; - private AtomicInteger numSuccessfulLinkResolveFromFromServer; - private AtomicInteger numFailedLinkResolve; - private AtomicInteger aaiWorkOnHand; + protected AtomicInteger numLinksDiscovered; + protected AtomicInteger numSuccessfulLinkResolveFromCache; + protected AtomicInteger numSuccessfulLinkResolveFromFromServer; + protected AtomicInteger numFailedLinkResolve; + protected AtomicInteger aaiWorkOnHand; - private VisualizationConfigs visualizationConfigs; + protected VisualizationConfigs visualizationConfigs; - private AtomicInteger totalLinksRetrieved; + protected AtomicInteger totalLinksRetrieved; - private final long contextId; - private final String contextIdStr; - private long lastProcessStatesSummaryLogInMs = -1; + protected final long contextId; + protected final String contextIdStr; + protected long lastProcessStatesSummaryLogInMs = -1; - private ObjectMapper mapper; - private InlineMessage inlineMessage = null; + protected ObjectMapper mapper; - private ExecutorService graphExecutorService; - private OxmEntityLookup oxmEntityLookup; - private boolean rootNodeFound; + protected ExecutorService graphExecutorService; + protected OxmEntityLookup oxmEntityLookup; + protected boolean rootNodeFound; /* * The node cache is intended to be a flat structure indexed by a primary key to avoid needlessly * re-requesting the same self-links over-and-over again, to speed up the overall render time and * more importantly to reduce the network cost of determining information we already have. */ - private ConcurrentHashMap<String, ActiveInventoryNode> nodeCache; + protected ConcurrentHashMap<String, ActiveInventoryNode> nodeCache; /** * Instantiates a new self link node collector. @@ -148,7 +147,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { * * @param nodeId the node id */ - private void processSelfLinkResponse(String nodeId) { + protected void processSelfLinkResponse(String nodeId) { if (nodeId == null) { LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, @@ -288,7 +287,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { * * @param nodeId the node id */ - private void performSelfLinkResolve(String nodeId) { + protected void performSelfLinkResolve(String nodeId) { if (nodeId == null) { LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, @@ -456,7 +455,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { * @param queryParams the query params * @return true, if successful */ - private void findAndMarkRootNode(QueryParams queryParams) { + protected void findAndMarkRootNode(QueryParams queryParams) { if (isRootNodeFound()) { return; @@ -511,7 +510,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { dumpThrottledWorkOnHandLog(false); } - private void dumpThrottledWorkOnHandLog(boolean override) { + protected void dumpThrottledWorkOnHandLog(boolean override) { if ((lastProcessStatesSummaryLogInMs < 0) || ((System.currentTimeMillis() > (lastProcessStatesSummaryLogInMs + 5000))) || override) { @@ -572,7 +571,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { * * @param rootNodeDiscovered the root node discovered */ - private void processCurrentNodeStates(QueryParams queryParams) { + protected void processCurrentNodeStates(QueryParams queryParams) { /* * Force an evaluation of node depths before determining if we should limit state-based * traversal or processing. @@ -635,14 +634,6 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { return numFailedLinkResolve.get(); } - public InlineMessage getInlineMessage() { - return inlineMessage; - } - - public void setInlineMessage(InlineMessage inlineMessage) { - this.inlineMessage = inlineMessage; - } - public ConcurrentHashMap<String, ActiveInventoryNode> getNodeCache() { return nodeCache; } @@ -654,7 +645,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { * * @param nodeId the node id */ - private void processInitialState(String nodeId) { + protected void processInitialState(String nodeId) { if (nodeId == null) { LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_INITIAL_STATE, "Node id is null"); @@ -713,7 +704,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { * @param skeletonNode the skeleton node * @param queryParams the query params */ - private void processSearchableEntity(SearchableEntity searchTargetEntity, + protected void processSearchableEntity(SearchableEntity searchTargetEntity, QueryParams queryParams) { if (searchTargetEntity == null) { @@ -741,7 +732,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { nodeCache.putIfAbsent(newNode.getNodeId(), newNode); } - private int getTotalWorkOnHand() { + protected int getTotalWorkOnHand() { int numNodesWithPendingStates = 0; @@ -781,7 +772,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { * * @return true, if successful */ - private void processOutstandingWork(QueryParams queryParams) { + protected void processOutstandingWork(QueryParams queryParams) { while (getTotalWorkOnHand() > 0) { @@ -852,7 +843,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { /** * Verify outbound neighbors. */ - private void verifyOutboundNeighbors() { + protected void verifyOutboundNeighbors() { for (ActiveInventoryNode srcNode : nodeCache.values()) { @@ -879,7 +870,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { /** * Evaluate node depths. */ - private void evaluateNodeDepths() { + protected void evaluateNodeDepths() { int numChanged = -1; int numAttempts = 0; @@ -954,7 +945,7 @@ public class BaseGizmoVisualizationContext implements VisualizationContext { */ - private String getEntityTypePrimaryKeyName(String entityType) { + protected String getEntityTypePrimaryKeyName(String entityType) { if (entityType == null) { LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE, diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/context/BaseGizmoVisualizationContextBuilder.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/context/BaseGizmoVisualizationContextBuilder.java new file mode 100644 index 0000000..a0f0fd5 --- /dev/null +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/context/BaseGizmoVisualizationContextBuilder.java @@ -0,0 +1,71 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.sparky.viewandinspect.context; + +import java.security.SecureRandom; +import java.util.concurrent.ExecutorService; + +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; +import org.onap.aai.sparky.config.oxm.OxmEntityLookup; +import org.onap.aai.sparky.dal.GizmoAdapter; +import org.onap.aai.sparky.util.NodeUtils; +import org.onap.aai.sparky.viewandinspect.VisualizationContext; +import org.onap.aai.sparky.viewandinspect.VisualizationContextBuilder; +import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; + +public class BaseGizmoVisualizationContextBuilder implements VisualizationContextBuilder { + + private static final Logger LOG = + LoggerFactory.getInstance().getLogger(BaseGizmoVisualizationContextBuilder.class); + + private SecureRandom secureRandom = new SecureRandom(); + private GizmoAdapter gizmoAdapter; + private final ExecutorService executorService; + private VisualizationConfigs visualizationConfig; + private OxmEntityLookup oxmEntityLookup; + + + public BaseGizmoVisualizationContextBuilder(GizmoAdapter gizmoAdapter, int numWorkers, + VisualizationConfigs visualizationConfig, OxmEntityLookup oxmEntityLookup) { + this.gizmoAdapter = gizmoAdapter; + this.executorService = NodeUtils.createNamedExecutor("SLNC-WORKER", numWorkers, LOG); + this.visualizationConfig = visualizationConfig; + this.oxmEntityLookup = oxmEntityLookup; + } + + @Override + public VisualizationContext getVisualizationContext() throws Exception { + + return new BaseGizmoVisualizationContext(secureRandom.nextLong(), this.gizmoAdapter, + executorService, visualizationConfig, oxmEntityLookup); + + } + + @Override + public void shutdown() { + if (executorService != null) { + executorService.shutdown(); + } + + } + +}
\ No newline at end of file diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContext.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/context/BaseVisualizationContext.java index 0cbd52e..18c6647 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContext.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/context/BaseVisualizationContext.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.sparky.viewandinspect.services; +package org.onap.aai.sparky.viewandinspect.context; import static java.util.concurrent.CompletableFuture.supplyAsync; @@ -43,10 +43,10 @@ import org.onap.aai.sparky.dal.ActiveInventoryAdapter; import org.onap.aai.sparky.logging.AaiUiMsgs; import org.onap.aai.sparky.sync.entity.SearchableEntity; import org.onap.aai.sparky.util.NodeUtils; +import org.onap.aai.sparky.viewandinspect.VisualizationContext; import org.onap.aai.sparky.viewandinspect.config.SparkyConstants; import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode; -import org.onap.aai.sparky.viewandinspect.entity.InlineMessage; import org.onap.aai.sparky.viewandinspect.entity.NodeProcessingTransaction; import org.onap.aai.sparky.viewandinspect.entity.QueryParams; import org.onap.aai.sparky.viewandinspect.entity.Relationship; @@ -68,42 +68,41 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy; */ public class BaseVisualizationContext implements VisualizationContext { - private static final int MAX_DEPTH_EVALUATION_ATTEMPTS = 100; - private static final String DEPTH_ALL_MODIFIER = "?depth=all"; - private static final String NODES_ONLY_MODIFIER = "?nodes-only"; - private static final String SERVICE_INSTANCE = "service-instance"; + protected static final int MAX_DEPTH_EVALUATION_ATTEMPTS = 100; + protected static final String DEPTH_ALL_MODIFIER = "?depth=all"; + protected static final String NODES_ONLY_MODIFIER = "?nodes-only"; + protected static final String SERVICE_INSTANCE = "service-instance"; private static final Logger LOG = LoggerFactory.getInstance().getLogger( BaseVisualizationContext.class); - private final ActiveInventoryAdapter aaiAdapter; - - private int maxSelfLinkTraversalDepth; - private AtomicInteger numLinksDiscovered; - private AtomicInteger numSuccessfulLinkResolveFromCache; - private AtomicInteger numSuccessfulLinkResolveFromFromServer; - private AtomicInteger numFailedLinkResolve; - private AtomicInteger aaiWorkOnHand; + protected final ActiveInventoryAdapter aaiAdapter; + + protected int maxSelfLinkTraversalDepth; + protected AtomicInteger numLinksDiscovered; + protected AtomicInteger numSuccessfulLinkResolveFromCache; + protected AtomicInteger numSuccessfulLinkResolveFromFromServer; + protected AtomicInteger numFailedLinkResolve; + protected AtomicInteger aaiWorkOnHand; - private VisualizationConfigs visualizationConfigs; + protected VisualizationConfigs visualizationConfigs; - private AtomicInteger totalLinksRetrieved; + protected AtomicInteger totalLinksRetrieved; - private final long contextId; - private final String contextIdStr; + protected final long contextId; + protected final String contextIdStr; - private ObjectMapper mapper; - private InlineMessage inlineMessage = null; + protected ObjectMapper mapper; - private ExecutorService aaiExecutorService; - private OxmEntityLookup oxmEntityLookup; - private boolean rootNodeFound; + protected ExecutorService aaiExecutorService; + protected OxmEntityLookup oxmEntityLookup; + protected boolean rootNodeFound; /* * The node cache is intended to be a flat structure indexed by a primary key to avoid needlessly * re-requesting the same self-links over-and-over again, to speed up the overall render time and * more importantly to reduce the network cost of determining information we already have. */ - private ConcurrentHashMap<String, ActiveInventoryNode> nodeCache; + protected ConcurrentHashMap<String, ActiveInventoryNode> nodeCache; /** * Instantiates a new self link node collector. @@ -471,7 +470,7 @@ public class BaseVisualizationContext implements VisualizationContext { * * @param nodeId the node id */ - private void processSelfLinkResponse(String nodeId) { + protected void processSelfLinkResponse(String nodeId) { if (nodeId == null) { LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, "Cannot process self link" @@ -605,7 +604,7 @@ public class BaseVisualizationContext implements VisualizationContext { } - private void handleNodeValue(ActiveInventoryNode ain, String fieldName, String key, String value) { + protected void handleNodeValue(ActiveInventoryNode ain, String fieldName, String key, String value) { if (oxmEntityLookup.getEntityDescriptors().get(fieldName) == null) { /* @@ -623,7 +622,7 @@ public class BaseVisualizationContext implements VisualizationContext { * * @param nodeId the node id */ - private void performSelfLinkResolve(String nodeId) { + protected void performSelfLinkResolve(String nodeId) { if (nodeId == null) { LOG.error(AaiUiMsgs.SELF_LINK_PROCESSING_ERROR, "Resolve of self-link" @@ -744,7 +743,7 @@ public class BaseVisualizationContext implements VisualizationContext { * * @param nodeId the node id */ - private void processNeighbors(String nodeId) { + protected void processNeighbors(String nodeId) { if (nodeId == null) { LOG.error(AaiUiMsgs.SELF_LINK_PROCESS_NEIGHBORS_ERROR, "Failed to process" @@ -795,7 +794,7 @@ public class BaseVisualizationContext implements VisualizationContext { * @param queryParams the query params * @return true, if successful */ - private void findAndMarkRootNode(QueryParams queryParams) { + protected void findAndMarkRootNode(QueryParams queryParams) { if (isRootNodeFound()) { return; @@ -817,7 +816,7 @@ public class BaseVisualizationContext implements VisualizationContext { * Process current node states. * */ - private void processCurrentNodeStates(QueryParams queryParams) { + protected void processCurrentNodeStates(QueryParams queryParams) { /* * Force an evaluation of node depths before determining if we should limit state-based * traversal or processing. @@ -896,7 +895,7 @@ public class BaseVisualizationContext implements VisualizationContext { * @param attributeGroup the attribute group * @return true, if successful */ - private boolean addComplexGroupToNode(ActiveInventoryNode targetNode, JsonNode attributeGroup) { + protected boolean addComplexGroupToNode(ActiveInventoryNode targetNode, JsonNode attributeGroup) { if (attributeGroup == null) { targetNode.changeState(NodeProcessingState.ERROR, @@ -986,14 +985,6 @@ public class BaseVisualizationContext implements VisualizationContext { return numFailedLinkResolve.get(); } - public InlineMessage getInlineMessage() { - return inlineMessage; - } - - public void setInlineMessage(InlineMessage inlineMessage) { - this.inlineMessage = inlineMessage; - } - public void setMaxSelfLinkTraversalDepth(int depth) { this.maxSelfLinkTraversalDepth = depth; } @@ -1014,7 +1005,7 @@ public class BaseVisualizationContext implements VisualizationContext { * @param pkeyNames the pkey names * @return the relationship primary key values */ - private String getRelationshipPrimaryKeyValues(Relationship r, String entityType, + protected String getRelationshipPrimaryKeyValues(Relationship r, String entityType, List<String> pkeyNames) { StringBuilder sb = new StringBuilder(64); @@ -1066,7 +1057,7 @@ public class BaseVisualizationContext implements VisualizationContext { * @param keyName the key name * @return the string */ - private String extractKeyValueFromRelationData(Relationship r, String keyName) { + protected String extractKeyValueFromRelationData(Relationship r, String keyName) { RelationshipData[] rdList = r.getRelationshipData(); @@ -1086,7 +1077,7 @@ public class BaseVisualizationContext implements VisualizationContext { * @param ain the ain * @return true, if successful */ - private boolean addNodeQueryParams(ActiveInventoryNode ain) { + protected boolean addNodeQueryParams(ActiveInventoryNode ain) { if (ain == null) { LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE_NODE_ID, "ActiveInventoryNode is null"); @@ -1158,7 +1149,7 @@ public class BaseVisualizationContext implements VisualizationContext { * @param relationshipList the relationship list * @return true, if successful */ - private boolean addSelfLinkRelationshipChildren(ActiveInventoryNode processingNode, + protected boolean addSelfLinkRelationshipChildren(ActiveInventoryNode processingNode, RelationshipList relationshipList) { if (relationshipList == null) { @@ -1171,7 +1162,6 @@ public class BaseVisualizationContext implements VisualizationContext { Relationship[] relationshipArray = relationshipList.getRelationshipList(); OxmEntityDescriptor descriptor = null; - String repairedSelfLink = null; if (relationshipArray != null) { @@ -1254,7 +1244,7 @@ public class BaseVisualizationContext implements VisualizationContext { * * @param nodeId the node id */ - private void processInitialState(String nodeId) { + protected void processInitialState(String nodeId) { if (nodeId == null) { LOG.error(AaiUiMsgs.FAILED_TO_PROCESS_INITIAL_STATE, "Node id is null"); @@ -1313,7 +1303,7 @@ public class BaseVisualizationContext implements VisualizationContext { * @param skeletonNode the skeleton node * @param queryParams the query params */ - private void processSearchableEntity(SearchableEntity searchTargetEntity, QueryParams queryParams) { + protected void processSearchableEntity(SearchableEntity searchTargetEntity, QueryParams queryParams) { if (searchTargetEntity == null) { return; @@ -1361,7 +1351,7 @@ public class BaseVisualizationContext implements VisualizationContext { nodeCache.putIfAbsent(newNode.getNodeId(), newNode); } - private int getTotalWorkOnHand() { + protected int getTotalWorkOnHand() { int numNodesWithPendingStates = 0; @@ -1419,7 +1409,7 @@ public class BaseVisualizationContext implements VisualizationContext { * * @return true, if successful */ - private void processOutstandingWork(QueryParams queryParams) { + protected void processOutstandingWork(QueryParams queryParams) { while (getTotalWorkOnHand() > 0) { @@ -1484,7 +1474,7 @@ public class BaseVisualizationContext implements VisualizationContext { /** * Verify outbound neighbors. */ - private void verifyOutboundNeighbors() { + protected void verifyOutboundNeighbors() { for (ActiveInventoryNode srcNode : nodeCache.values()) { @@ -1511,7 +1501,7 @@ public class BaseVisualizationContext implements VisualizationContext { /** * Evaluate node depths. */ - private void evaluateNodeDepths() { + protected void evaluateNodeDepths() { int numChanged = -1; int numAttempts = 0; @@ -1586,7 +1576,7 @@ public class BaseVisualizationContext implements VisualizationContext { */ - private String getEntityTypePrimaryKeyName(String entityType) { + protected String getEntityTypePrimaryKeyName(String entityType) { if (entityType == null) { LOG.error(AaiUiMsgs.FAILED_TO_DETERMINE, "node primary key" diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/context/BaseVisualizationContextBuilder.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/context/BaseVisualizationContextBuilder.java new file mode 100644 index 0000000..7ffc9d0 --- /dev/null +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/context/BaseVisualizationContextBuilder.java @@ -0,0 +1,70 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.sparky.viewandinspect.context; + +import java.security.SecureRandom; +import java.util.concurrent.ExecutorService; + +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; +import org.onap.aai.sparky.config.oxm.OxmEntityLookup; +import org.onap.aai.sparky.dal.ActiveInventoryAdapter; +import org.onap.aai.sparky.util.NodeUtils; +import org.onap.aai.sparky.viewandinspect.VisualizationContext; +import org.onap.aai.sparky.viewandinspect.VisualizationContextBuilder; +import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; + +public class BaseVisualizationContextBuilder implements VisualizationContextBuilder { + + private static final Logger LOG = + LoggerFactory.getInstance().getLogger(BaseVisualizationContextBuilder.class); + + private SecureRandom secureRandom = new SecureRandom(); + private ActiveInventoryAdapter aaiAdapter; + private final ExecutorService executorService; + private VisualizationConfigs visualizationConfig; + private OxmEntityLookup oxmEntityLookup; + + + public BaseVisualizationContextBuilder(ActiveInventoryAdapter aaiAdapter, int numWorkers, + VisualizationConfigs visualizationConfig, OxmEntityLookup oxmEntityLookup) { + this.aaiAdapter = aaiAdapter; + this.executorService = NodeUtils.createNamedExecutor("SLNC-WORKER", numWorkers, LOG); + this.visualizationConfig = visualizationConfig; + this.oxmEntityLookup = oxmEntityLookup; + } + + @Override + public VisualizationContext getVisualizationContext() throws Exception { + return new BaseVisualizationContext(secureRandom.nextLong(), this.aaiAdapter, executorService, + visualizationConfig, oxmEntityLookup); + + } + + @Override + public void shutdown() { + if (executorService != null) { + executorService.shutdown(); + } + + } + +}
\ No newline at end of file diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutput.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutput.java index 9599726..ea63065 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutput.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutput.java @@ -31,7 +31,6 @@ public class D3VisualizationOutput { public GraphMeta graphMeta; public List<SparkyGraphNode> nodes; public List<SparkyGraphLink> links; - public InlineMessage inlineMessage; /** * Instantiates a new d 3 visualization output. @@ -39,7 +38,6 @@ public class D3VisualizationOutput { public D3VisualizationOutput() { nodes = new ArrayList<SparkyGraphNode>(); links = new ArrayList<SparkyGraphLink>(); - inlineMessage = null; } public GraphMeta getGraphMeta() { @@ -77,13 +75,4 @@ public class D3VisualizationOutput { this.links.addAll(links); } - public InlineMessage getInlineMessage() { - return inlineMessage; - } - - public void setInlineMessage(InlineMessage inlineMessage) { - this.inlineMessage = inlineMessage; - } - - } diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphMeta.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphMeta.java index b827e74..0ccefdb 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphMeta.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/GraphMeta.java @@ -34,12 +34,8 @@ public class GraphMeta { private int numLinks; private long renderTimeInMs; - - private int numLinksResolvedSuccessfullyFromCache; - - private int numLinksResolvedSuccessfullyFromServer; - - private int numLinkResolveFailed; + + private int numNodeWithProcessingErrors; private EntityTypeAggregation entitySummary; @@ -67,31 +63,6 @@ public class GraphMeta { this.aaiEntityNodeDescriptors = aaiEntityNodeDefinitions; } - public int getNumLinksResolvedSuccessfullyFromCache() { - return numLinksResolvedSuccessfullyFromCache; - } - - public void setNumLinksResolvedSuccessfullyFromCache(int numLinksResolvedSuccessfullyFromCache) { - this.numLinksResolvedSuccessfullyFromCache = numLinksResolvedSuccessfullyFromCache; - } - - public int getNumLinksResolvedSuccessfullyFromServer() { - return numLinksResolvedSuccessfullyFromServer; - } - - public void setNumLinksResolvedSuccessfullyFromServer( - int numLinksResolvedSuccessfullyFromServer) { - this.numLinksResolvedSuccessfullyFromServer = numLinksResolvedSuccessfullyFromServer; - } - - public int getNumLinkResolveFailed() { - return numLinkResolveFailed; - } - - public void setNumLinkResolveFailed(int numLinkResolveFailed) { - this.numLinkResolveFailed = numLinkResolveFailed; - } - public int getNumNodes() { return numNodes; } @@ -116,6 +87,14 @@ public class GraphMeta { this.renderTimeInMs = renderTimeInMs; } + public int getNumNodeWithProcessingErrors() { + return numNodeWithProcessingErrors; + } + + public void setNumNodeWithProcessingErrors(int numNodeWithProcessingErrors) { + this.numNodeWithProcessingErrors = numNodeWithProcessingErrors; + } + /** * Peg counter. * @@ -125,19 +104,12 @@ public class GraphMeta { entitySummary.pegCounter(counterName); } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ @Override public String toString() { - return "GraphMeta [" - + (aaiEntityNodeDescriptors != null - ? "aaiEntityNodeDescriptors=" + aaiEntityNodeDescriptors + ", " : "") - + "numNodes=" + numNodes + ", numLinks=" + numLinks + ", renderTimeInMs=" + renderTimeInMs - + ", numLinksResolvedSuccessfullyFromCache=" + numLinksResolvedSuccessfullyFromCache - + ", numLinksResolvedSuccessfullyFromServer=" + numLinksResolvedSuccessfullyFromServer - + ", numLinkResolveFailed=" + numLinkResolveFailed + ", " - + (entitySummary != null ? "entitySummary=" + entitySummary : "") + "]"; + return "GraphMeta [aaiEntityNodeDescriptors=" + aaiEntityNodeDescriptors + ", numNodes=" + + numNodes + ", numLinks=" + numLinks + ", renderTimeInMs=" + renderTimeInMs + + ", numNodeWithProcessingErrors=" + numNodeWithProcessingErrors + ", entitySummary=" + + entitySummary + "]"; } } diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/InlineMessage.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/InlineMessage.java deleted file mode 100644 index 5ddc20f..0000000 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/InlineMessage.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sparky.viewandinspect.entity; - -/** - * The Class InlineMessage. - */ -public class InlineMessage { - - private String level; - private String message; - - /** - * Instantiates a new inline message. - * - * @param level the level - * @param message the message - */ - public InlineMessage(String level, String message) { - this.level = level; - this.message = message; - } - - public String getLevel() { - return level; - } - - public void setLevel(String level) { - this.level = level; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return level + " : " + message; - } - -} diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java index 17c9072..992e531 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java @@ -21,20 +21,14 @@ package org.onap.aai.sparky.viewandinspect.services; import java.io.IOException; -import java.security.SecureRandom; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; import javax.servlet.ServletException; import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.restclient.client.OperationResult; -import org.onap.aai.sparky.config.oxm.OxmEntityLookup; -import org.onap.aai.sparky.config.oxm.OxmModelLoader; -import org.onap.aai.sparky.dal.ActiveInventoryAdapter; -import org.onap.aai.sparky.dal.GizmoAdapter; import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig; import org.onap.aai.sparky.logging.AaiUiMsgs; import org.onap.aai.sparky.search.SearchServiceAdapter; @@ -42,6 +36,9 @@ import org.onap.aai.sparky.subscription.config.SubscriptionConfig; import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig; import org.onap.aai.sparky.sync.entity.SearchableEntity; import org.onap.aai.sparky.util.NodeUtils; +import org.onap.aai.sparky.viewandinspect.VisualizationContext; +import org.onap.aai.sparky.viewandinspect.VisualizationContextBuilder; +import org.onap.aai.sparky.viewandinspect.VisualizationService; import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode; import org.onap.aai.sparky.viewandinspect.entity.D3VisualizationOutput; @@ -60,43 +57,30 @@ public class BaseVisualizationService implements VisualizationService { private static final Logger LOG = LoggerFactory.getInstance().getLogger(BaseVisualizationService.class); - private ObjectMapper mapper = new ObjectMapper(); + protected ObjectMapper mapper = new ObjectMapper(); - private final ActiveInventoryAdapter aaiAdapter; - private final GizmoAdapter gizmoAdapter; - private final SearchServiceAdapter searchServiceAdapter; - private final ExecutorService aaiExecutorService; + protected final SearchServiceAdapter searchServiceAdapter; - private ConcurrentHashMap<Long, VisualizationContext> contextMap; - private final SecureRandom secureRandom; - - private VisualizationConfigs visualizationConfigs; - private SubscriptionConfig subConfig; - private RestEndpointConfig endpointConfig; - private ElasticSearchSchemaConfig schemaEConfig; - private OxmEntityLookup oxmEntityLookup; + protected ConcurrentHashMap<Long, VisualizationContext> contextMap; + + protected VisualizationConfigs visualizationConfigs; + protected SubscriptionConfig subConfig; + protected RestEndpointConfig endpointConfig; + protected ElasticSearchSchemaConfig schemaEConfig; + + protected VisualizationContextBuilder contextBuilder; - public BaseVisualizationService(OxmModelLoader loader, VisualizationConfigs visualizationConfigs, - ActiveInventoryAdapter aaiAdapter, GizmoAdapter gizmoAdapter, SearchServiceAdapter searchServiceAdapter, - RestEndpointConfig endpointConfig, ElasticSearchSchemaConfig schemaConfig, - int numActiveInventoryWorkers, OxmEntityLookup oxmEntityLookup, SubscriptionConfig subscriptionConfig) - throws Exception { + public BaseVisualizationService(VisualizationContextBuilder contextBuilder, + VisualizationConfigs visualizationConfigs, SearchServiceAdapter searchServiceAdapter, + RestEndpointConfig endpointConfig, ElasticSearchSchemaConfig schemaConfig, + SubscriptionConfig subscriptionConfig) throws Exception { this.visualizationConfigs = visualizationConfigs; this.endpointConfig = endpointConfig; this.schemaEConfig = schemaConfig; - this.oxmEntityLookup = oxmEntityLookup; this.subConfig = subscriptionConfig; + this.contextBuilder = contextBuilder; - - secureRandom = new SecureRandom(); - - /* - * Fix constructor with properly wired in properties - */ - - this.aaiAdapter = aaiAdapter; - this.gizmoAdapter = gizmoAdapter; this.searchServiceAdapter = searchServiceAdapter; this.mapper = new ObjectMapper(); @@ -104,9 +88,6 @@ public class BaseVisualizationService implements VisualizationService { this.contextMap = new ConcurrentHashMap<Long, VisualizationContext>(); - this.aaiExecutorService = NodeUtils.createNamedExecutor("SLNC-WORKER", - numActiveInventoryWorkers, LOG); - } /** @@ -144,12 +125,12 @@ public class BaseVisualizationService implements VisualizationService { * @param method the method * @param opStartTimeInMs the op start time in ms */ - private void logOptime(String method, long opStartTimeInMs) { + protected void logOptime(String method, long opStartTimeInMs) { LOG.info(AaiUiMsgs.OPERATION_TIME, method, String.valueOf(System.currentTimeMillis() - opStartTimeInMs)); } - private SearchableEntity extractSearchableEntityFromElasticEntity(OperationResult operationResult) { + protected SearchableEntity extractSearchableEntityFromElasticEntity(OperationResult operationResult) { if (operationResult == null || !operationResult.wasSuccessful()) { // error, return empty collection return null; @@ -190,7 +171,8 @@ public class BaseVisualizationService implements VisualizationService { * @param queryRequest the query request * @return the operation result */ - public OperationResult buildVisualizationUsingGenericQuery(QueryRequest queryRequest) { + @Override + public OperationResult buildVisualization(QueryRequest queryRequest) { OperationResult returnValue = new OperationResult(); OperationResult dataCollectionResult; @@ -263,7 +245,7 @@ public class BaseVisualizationService implements VisualizationService { * @throws ServletException the servlet exception * @throws */ - private String getVisualizationOutputBasedonGenericQuery(SearchableEntity searchtargetEntity, + protected String getVisualizationOutputBasedonGenericQuery(SearchableEntity searchtargetEntity, QueryParams queryParams, QueryRequest request) throws ServletException { long opStartTimeInMs = System.currentTimeMillis(); @@ -277,17 +259,12 @@ public class BaseVisualizationService implements VisualizationService { } VisualizationContext visContext = null; - long contextId = secureRandom.nextLong(); + try { - if ( visualizationConfigs.isGizmoEnabled()) { - visContext = new BaseGizmoVisualizationContext(contextId, this.gizmoAdapter, aaiExecutorService, - this.visualizationConfigs, oxmEntityLookup); - } else { - visContext = new BaseVisualizationContext(contextId, this.aaiAdapter, aaiExecutorService, - this.visualizationConfigs, oxmEntityLookup); - } - - contextMap.putIfAbsent(contextId, visContext); + + visContext = contextBuilder.getVisualizationContext(); + contextMap.putIfAbsent(visContext.getContextId(), visContext); + } catch (Exception e1) { LOG.error(AaiUiMsgs.EXCEPTION_CAUGHT, "While building Visualization Context, " + e1.getLocalizedMessage()); @@ -297,7 +274,7 @@ public class BaseVisualizationService implements VisualizationService { long startTimeInMs = System.currentTimeMillis(); visContext.processSelfLinks(searchtargetEntity, queryParams); - contextMap.remove(contextId); + contextMap.remove(visContext.getContextId()); logOptime("collectSelfLinkNodes()", startTimeInMs); @@ -323,7 +300,9 @@ public class BaseVisualizationService implements VisualizationService { LOG.debug(AaiUiMsgs.DEBUG_GENERIC, sb.toString()); } - transformer.buildFlatNodeArrayFromGraphCollection(cachedNodeMap); + GraphMeta graphMeta = new GraphMeta(); + + transformer.buildFlatNodeArrayFromGraphCollection(cachedNodeMap, graphMeta); transformer.buildLinksFromGraphCollection(cachedNodeMap); /* @@ -333,20 +312,12 @@ public class BaseVisualizationService implements VisualizationService { */ transformer.addSearchTargetAttributesToRootNode(); - - GraphMeta graphMeta = new GraphMeta(); D3VisualizationOutput output = getD3VisualizationOutput(opStartTimeInMs, transformer, graphMeta); String jsonResponse = null; if (output != null) { - output.setInlineMessage(visContext.getInlineMessage()); - output.getGraphMeta().setNumLinkResolveFailed(visContext.getNumFailedLinkResolve()); - output.getGraphMeta().setNumLinksResolvedSuccessfullyFromCache( - visContext.getNumSuccessfulLinkResolveFromCache()); - output.getGraphMeta().setNumLinksResolvedSuccessfullyFromServer( - visContext.getNumSuccessfulLinkResolveFromFromServer()); try { jsonResponse = transformer.convertVisualizationOutputToJson(output); @@ -365,7 +336,8 @@ public class BaseVisualizationService implements VisualizationService { } - private D3VisualizationOutput getD3VisualizationOutput(long opStartTimeInMs, VisualizationTransformer transformer, GraphMeta graphMeta) throws ServletException { + protected D3VisualizationOutput getD3VisualizationOutput(long opStartTimeInMs, + VisualizationTransformer transformer, GraphMeta graphMeta) throws ServletException { D3VisualizationOutput output = null; try { output = transformer @@ -378,7 +350,7 @@ public class BaseVisualizationService implements VisualizationService { return output; } - private JsonNode extractSearchServiceContent(JsonNode returnedData){ + protected JsonNode extractSearchServiceContent(JsonNode returnedData){ JsonNode searchResults = returnedData.get("searchResult"); JsonNode searchHits = searchResults.get("hits"); @@ -388,8 +360,11 @@ public class BaseVisualizationService implements VisualizationService { return content; } + @Override public void shutdown() { - aaiExecutorService.shutdown(); + if ( contextBuilder != null ) { + contextBuilder.shutdown(); + } } } diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java index 7fcacfe..2d70b92 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java @@ -33,7 +33,6 @@ import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.sparky.config.SparkyResourceLoader; import org.onap.aai.sparky.logging.AaiUiMsgs; import org.onap.aai.sparky.subscription.config.SubscriptionConfig; -import org.onap.aai.sparky.util.ConfigHelper; import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode; import org.onap.aai.sparky.viewandinspect.entity.D3VisualizationOutput; @@ -41,6 +40,7 @@ import org.onap.aai.sparky.viewandinspect.entity.GraphMeta; import org.onap.aai.sparky.viewandinspect.entity.NodeDebug; import org.onap.aai.sparky.viewandinspect.entity.SparkyGraphLink; import org.onap.aai.sparky.viewandinspect.entity.SparkyGraphNode; +import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingState; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -263,13 +263,17 @@ public class VisualizationTransformer { * Builds the flat node array from graph collection. * * @param nodeMap the node map + * @param graphMeta information + stats about the graph */ /* * Recursive function to walk multi-graph nodes and children to build a folded resource target * graph. */ - public void buildFlatNodeArrayFromGraphCollection(Map<String, ActiveInventoryNode> nodeMap) { + public void buildFlatNodeArrayFromGraphCollection(Map<String, ActiveInventoryNode> nodeMap, + GraphMeta graphMeta) { + int numNodesWithErrors = 0; + for (ActiveInventoryNode n : nodeMap.values()) { if (n.getNodeDepth() <= this.visualizationConfigs.getMaxSelfLinkTraversalDepth()) { @@ -277,6 +281,10 @@ public class VisualizationTransformer { SparkyGraphNode jsonNode = new SparkyGraphNode(n, this.visualizationConfigs, this.subConfig); jsonNode.getNodeMeta().setClassName(this.visualizationConfigs.getGeneralNodeClassName()); + + if (n.getState() == NodeProcessingState.ERROR) { + numNodesWithErrors++; + } if (this.visualizationConfigs.isVisualizationDebugEnabled()) { @@ -296,6 +304,9 @@ public class VisualizationTransformer { } } } + + graphMeta.setNumNodeWithProcessingErrors(numNodesWithErrors); + } } |