diff options
Diffstat (limited to 'sparkybe-onap-service/src')
23 files changed, 635 insertions, 426 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); + } } diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationContextTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationContextTest.java index 5c027da..d58bf42 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationContextTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationContextTest.java @@ -1,5 +1,295 @@ package org.onap.aai.sparky.viewandinspect; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.InputStream; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutorService; + +import javax.inject.Inject; + +import org.eclipse.persistence.jaxb.JAXBContextProperties; +import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; +import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory; +import org.hamcrest.Matcher; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; +import org.onap.aai.cl.mdc.MdcContext; +import org.onap.aai.restclient.client.OperationResult; +import org.onap.aai.sparky.config.oxm.OxmEntityLookup; +import org.onap.aai.sparky.dal.ActiveInventoryAdapter; +import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig; +import org.onap.aai.sparky.sync.entity.SearchableEntity; +import org.onap.aai.sparky.util.NodeUtils; +import org.onap.aai.sparky.util.StringCollectionContainsMatcher; +import org.onap.aai.sparky.util.TestResourceLoader; +import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; +import org.onap.aai.sparky.viewandinspect.context.BaseVisualizationContext; +import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode; +import org.onap.aai.sparky.viewandinspect.entity.QueryParams; +import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingState; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + + + +@RunWith(SpringJUnit4ClassRunner.class) +@TestPropertySource(properties = { +"schemaIngestPropLoc = src/test/resources/oxm-reader/schema-ingest-single-oxm.properties" }) +@ContextConfiguration(locations = { "classpath:oxm-reader/oxm-reader-bean.xml" }) + + public class BaseVisualizationContextTest { -} + private static SecureRandom secureRandom = new SecureRandom(); + private static Logger LOG = + LoggerFactory.getInstance().getLogger(BaseVisualizationContextTest.class); + + private BaseVisualizationContext baseVisualizationContext; + private ExecutorService aaiExecutorService; + private VisualizationConfigs visualizationConfig; + + private ActiveInventoryAdapter aaiAdapter; + private RestEndpointConfig aaiRestEndPointConfig; + + @Inject + private OxmEntityLookup oxmEntityLookup; + + @Before + public void init() throws Exception { + + aaiExecutorService = NodeUtils.createNamedExecutor("SLNC-WORKER", 5, LOG); + visualizationConfig = new VisualizationConfigs(); + + ArrayList<String> shallowEntities = new ArrayList<String>(); + shallowEntities.add("cloud-region"); + + visualizationConfig.setShallowEntities(shallowEntities); + visualizationConfig.setMaxSelfLinkTraversalDepth(2); + + + aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class); + + aaiRestEndPointConfig = new RestEndpointConfig(); + aaiRestEndPointConfig.setNumRequestRetries(5); + + Mockito.when(aaiAdapter.getEndpointConfig()).thenReturn(aaiRestEndPointConfig); + + MdcContext.initialize("" + secureRandom.nextLong(), "AAI-UI", "", "partner-name", + "localhost:4242"); + + // all our resources are prefixed already, so the repairSelfLink shouldn't do anything to the link + Mockito.when(aaiAdapter.repairSelfLink(Matchers.contains(""))).thenReturn(""); + + + } + + private Matcher<List<String>> listContainsValue(String expectedValue) { + return new StringCollectionContainsMatcher(expectedValue); + } + + + @Test + public void validateBasicConstruction() throws Exception { + + long contextId = secureRandom.nextLong(); + + baseVisualizationContext = new BaseVisualizationContext(contextId, aaiAdapter, + aaiExecutorService, visualizationConfig, oxmEntityLookup); + + assertEquals(contextId, baseVisualizationContext.getContextId()); + + } + + @Test + public void validateSmallGraphAssembly() throws Exception { + + /** + * We have a tiny graph that we will validate assembly of: + * + * <li>customer -> tenant + * <li>customer -> service-subscription + * <li>service-subscription -> service-instance-1 + * <li>service-subscription -> service-instance-2 + * + * At the end of this success path, we should have 5 nodes in the node cache. Once we have this + * flow we can experiment with error paths involving resource download failures to ensure graph + * nodes are in the correct state and that expected nodes are successfully represented in the + * cache. + */ + + long contextId = secureRandom.nextLong(); + + baseVisualizationContext = new BaseVisualizationContext(contextId, aaiAdapter, + aaiExecutorService, visualizationConfig, oxmEntityLookup); + + SearchableEntity searchableEntity = new SearchableEntity(); + String customerSelfLink = + "https://server.proxy:8443/aai/v11/business/customers/customer/customer-4"; + String customerNodeId = NodeUtils.generateUniqueShaDigest(customerSelfLink); + + searchableEntity.setId(customerNodeId); + searchableEntity.setEntityType("customer"); + searchableEntity.setEntityPrimaryKeyValue("customer-4"); + searchableEntity.setLink(customerSelfLink); + + QueryParams queryParams = new QueryParams(); + queryParams.setSearchTargetNodeId(customerNodeId); + queryParams.setSearchTargetPrimaryKeyValues("customer-4"); + + // aai customer resource dip + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("customer-4"), + Mockito.anyString(), Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader + .getTestResourceDataJson("/sync/aai/aai-resources/customer/customer-4.json"))); + + // aai tenant resource dip + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries(Matchers.contains("tenant/tenant-1"), + Mockito.anyString(), Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader + .getTestResourceDataJson("/sync/aai/aai-resources/tenant/tenant-1.json"))); + + // generic-queries for service-subscription + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-subscription"), + Matchers.argThat( + listContainsValue("service-subscription.service-type:service-subscription-2")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-subscription-2"); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-subscription-2"), Mockito.anyString(), + Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-subscription/service-subscription-2.json"))); + + // generic-queries for service-instance-1 + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-id:service-instance-54")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-id/service-instance-54"); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-id/service-instance-54"), + Mockito.anyString(), Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance/service-instance-54.json"))); + + // generic-queries for service-instance-2 + + Mockito + .when(aaiAdapter.getGenericQueryForSelfLink(Matchers.contains("service-instance"), + Matchers.argThat(listContainsValue("service-instance-id:service-instance-55")))) + .thenReturn( + "https://server.proxy:8443/aai/v11/search/generic-query/service-instance-id/service-instance-55"); + + Mockito + .when(aaiAdapter.queryActiveInventoryWithRetries( + Matchers.contains("generic-query/service-instance-id/service-instance-55"), + Mockito.anyString(), Mockito.anyInt())) + .thenReturn(new OperationResult(200, TestResourceLoader.getTestResourceDataJson( + "/sync/aai/aai-traversal/generic-query/service-instance/service-instance-55.json"))); + + + + // start the test + + baseVisualizationContext.processSelfLinks(searchableEntity, queryParams); + + /* + * validation can be in the form of validating nodes + relationships from the node cache + * baseVisualizationContext.getNodeCache(); + */ + + Map<String, ActiveInventoryNode> nodeCache = baseVisualizationContext.getNodeCache(); + + assertEquals(5, nodeCache.size()); + assertNotNull(nodeCache.get(customerNodeId)); + assertEquals("customer", nodeCache.get(customerNodeId).getEntityType()); + + // verify node collection nodes + + ActiveInventoryNode customerNode = + nodeCache.get("da4101ad19b3c380a1c12ffeda8ab390e1489fb4a22a392c9a1939db63c3dec5"); + ActiveInventoryNode ssNode = + nodeCache.get("f4ceaf19459993c4fc9438a7579dd20d786109f4455e38682c579045b7ae615e"); + ActiveInventoryNode tenantNode = + nodeCache.get("4735439b29e446b339535668238076e4b392eaa3eec218936e12f735179bc55e"); + ActiveInventoryNode s1 = + nodeCache.get("f975ab453b142197af5d0173e0a9cf2aa22d10502f8ad655c8d17de81b066e8f"); + ActiveInventoryNode s2 = + nodeCache.get("de77ef8f76dd6f19662b163527ff839891b9596cac655e3143fdd7ad39e2e4e3"); + + assertNotNull(customerNode); + assertNotNull(ssNode); + assertNotNull(tenantNode); + assertNotNull(s1); + assertNotNull(s2); + + // verify node depths + + assertEquals(0, customerNode.getNodeDepth()); + assertEquals(1, ssNode.getNodeDepth()); + + /* + * I think there is a bug in the way the node depth is represented due to the enforcement of + * bidirectional links being disabled. We may have to circle back to this behavior at some point + * and re-verify that the behavior works properly. + */ + + assertEquals(2, tenantNode.getNodeDepth()); + assertEquals(2, s1.getNodeDepth()); + assertEquals(2, s2.getNodeDepth()); + + // verify node states + + assertEquals(NodeProcessingState.READY, customerNode.getState()); + assertEquals(NodeProcessingState.READY, ssNode.getState()); + + /* + * these nodes have a NEIGHBORS_UNPROCESSED state because the max traversal depth was hit before + * processing all the nested relationships. I think what we should look at is advancing the + * state to READY if in fact there are no relationships to process, which I think could be the + * case sometimes. + */ + assertEquals(NodeProcessingState.NEIGHBORS_UNPROCESSED, tenantNode.getState()); + assertEquals(NodeProcessingState.NEIGHBORS_UNPROCESSED, s1.getState()); + assertEquals(NodeProcessingState.NEIGHBORS_UNPROCESSED, s2.getState()); + + } + + protected DynamicJAXBContext createVersionedOxm() { + Map<String, Object> properties = new HashMap<>(); + ClassLoader classLoader = null; + InputStream iStream = classLoader.getResourceAsStream("example/resources/eclipselink/eclipselink-oxm.xml"); + + properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, iStream); + try{ + return DynamicJAXBContextFactory.createContextFromOXM(this.getClass().getClassLoader(), properties); + } catch (Exception e) { + return null; + } + } + + +}
\ No newline at end of file diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationServiceTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationServiceTest.java index eeacde1..9be0fe2 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationServiceTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationServiceTest.java @@ -5,15 +5,11 @@ import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -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.search.SearchServiceAdapter; import org.onap.aai.sparky.subscription.config.SubscriptionConfig; import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig; -import org.onap.aai.sparky.util.OxmModelAndProcessorHelper; import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; import org.onap.aai.sparky.viewandinspect.entity.QueryRequest; import org.onap.aai.sparky.viewandinspect.services.BaseVisualizationService; @@ -26,50 +22,49 @@ public class BaseVisualizationServiceTest { private SubscriptionConfig subConfig; private RestEndpointConfig endpointEConfig; private ElasticSearchSchemaConfig schemaEConfig; - private OxmEntityLookup oxmEntityLookup; - private GizmoAdapter mockGizmoAdapter; - + private VisualizationContextBuilder contextBuilder; + private BaseVisualizationService baseVisService; - + @Before public void init() throws Exception { this.mockAaiAdapter = Mockito.mock(ActiveInventoryAdapter.class); - this.mockAaiAdapter = Mockito.mock(ActiveInventoryAdapter.class); this.mocksearchServiceAdapter = Mockito.mock(SearchServiceAdapter.class); - this.mockGizmoAdapter = Mockito.mock(GizmoAdapter.class); this.visualizationConfigs = new VisualizationConfigs(); this.subConfig = new SubscriptionConfig(); this.endpointEConfig = new RestEndpointConfig(); this.schemaEConfig = new ElasticSearchSchemaConfig(); - this.oxmEntityLookup = OxmModelAndProcessorHelper.getInstance().getOxmEntityLookup(); - - OxmModelLoader modelLoader = OxmModelAndProcessorHelper.getInstance().getModelLoader(); - - this.baseVisService = new BaseVisualizationService(modelLoader, visualizationConfigs, - mockAaiAdapter, mockGizmoAdapter, mocksearchServiceAdapter, endpointEConfig, schemaEConfig, 1, - oxmEntityLookup, subConfig); + + this.contextBuilder = Mockito.mock(VisualizationContextBuilder.class); + + this.baseVisService = new BaseVisualizationService(contextBuilder, visualizationConfigs, + mocksearchServiceAdapter, endpointEConfig, schemaEConfig, subConfig); } - + @Test public void testAnalyzeQueryRequestBody() { - QueryRequest validResquest = baseVisService.analyzeQueryRequestBody(SchemaVisualizationTestDataBuilder.getQueryRequest()); + QueryRequest validResquest = baseVisService + .analyzeQueryRequestBody(SchemaVisualizationTestDataBuilder.getQueryRequest()); assertEquals(SchemaVisualizationTestDataBuilder.ROOT_NODE_HASH_ID, validResquest.getHashId()); - - QueryRequest nullRequest = baseVisService.analyzeQueryRequestBody("This String should make the request return null eh!"); + + QueryRequest nullRequest = baseVisService + .analyzeQueryRequestBody("This String should make the request return null eh!"); assertEquals(null, nullRequest); } - + @Test public void testBuildVisualizationUsingGenericQuery() { - + initializeMocksForBuildVisualizationUsingGenericQueryTest(); - - QueryRequest rootNodeQuery = baseVisService.analyzeQueryRequestBody(SchemaVisualizationTestDataBuilder.getQueryRequest()); - + + QueryRequest rootNodeQuery = baseVisService + .analyzeQueryRequestBody(SchemaVisualizationTestDataBuilder.getQueryRequest()); + } - + private void initializeMocksForBuildVisualizationUsingGenericQueryTest() { - Mockito.when(mockAaiAdapter.queryActiveInventoryWithRetries(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt())).thenReturn(null); + Mockito.when(mockAaiAdapter.queryActiveInventoryWithRetries(Mockito.anyString(), + Mockito.anyString(), Mockito.anyInt())).thenReturn(null); } - + } diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessorTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessorTest.java index 83e3ee0..edb6d4c 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessorTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/SchemaVisualizationProcessorTest.java @@ -16,7 +16,6 @@ import org.junit.Test; import org.mockito.Mockito; import org.onap.aai.sparky.util.HttpServletHelper; import org.onap.aai.sparky.viewandinspect.entity.QueryRequest; -import org.onap.aai.sparky.viewandinspect.services.VisualizationService; import org.onap.aai.sparky.viewandinspect.util.SchemaVisualizationTestDataBuilder; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -65,7 +64,7 @@ public class SchemaVisualizationProcessorTest { QueryRequest queryBody = nonEmptyMapper.readValue(queryRequest, QueryRequest.class); Mockito.when(mockVisualizationService.analyzeQueryRequestBody(Mockito.anyString())).thenReturn(queryBody); - Mockito.when(mockVisualizationService.buildVisualizationUsingGenericQuery(Mockito.anyObject())).thenReturn(SchemaVisualizationTestDataBuilder.getSchemaVisResult()); + Mockito.when(mockVisualizationService.buildVisualization(Mockito.anyObject())).thenReturn(SchemaVisualizationTestDataBuilder.getSchemaVisResult()); schemaVisProcessor.setVisualizationService(mockVisualizationService); schemaVisProcessor.processVisualizationRequest(exchange); diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigTest.java index dfa4b27..dbbd38d 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigTest.java @@ -29,8 +29,6 @@ public class VisualizationConfigTest { visualConfig.setShallowEntities(shallowEntities); assertNotNull(visualConfig.getShallowEntities()); - visualConfig.setGizmoEnabled(true); - assertTrue(visualConfig.isGizmoEnabled()); visualConfig.setMakeAllNeighborsBidirectional(true); assertTrue(visualConfig.makeAllNeighborsBidirectional()); visualConfig.setSelectedSearchedNodeClassName("selectedsearchedNodeClass"); diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutputTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutputTest.java index e1b9931..4afdc7d 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutputTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/entity/D3VisualizationOutputTest.java @@ -1,20 +1,15 @@ package org.onap.aai.sparky.viewandinspect.entity; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import java.util.ArrayList; import org.junit.Before; import org.junit.Test; -import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; public class D3VisualizationOutputTest { private D3VisualizationOutput d3visualization; - private InlineMessage inlineMessage; private GraphMeta graphMeta; private ArrayList<SparkyGraphNode> nodes; private ArrayList<SparkyGraphLink> links; @@ -26,15 +21,13 @@ public class D3VisualizationOutputTest { nodes = new ArrayList<SparkyGraphNode>(); links = new ArrayList<SparkyGraphLink>(); graphMeta = new GraphMeta(); - inlineMessage = new InlineMessage("level-1","Violation"); + } @Test public void updateValues() { - d3visualization.setInlineMessage(inlineMessage); - assertNotNull(d3visualization.getInlineMessage()); d3visualization.addLinks(links); d3visualization.addNodes(nodes); d3visualization.setGraphMeta(graphMeta); diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/entity/GraphMetaTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/entity/GraphMetaTest.java index bd4e454..e60f634 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/entity/GraphMetaTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/entity/GraphMetaTest.java @@ -4,7 +4,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; - import org.junit.Before; import org.junit.Test; import org.onap.aai.sparky.viewandinspect.EntityTypeAggregation; @@ -36,12 +35,6 @@ public class GraphMetaTest { graphMeta.setAaiEntityNodeDescriptors(aaiEntityNodeDescriptors); assertNotNull(graphMeta.getAaiEntityNodeDescriptors()); - graphMeta.setNumLinksResolvedSuccessfullyFromCache(3); - assertEquals(3,graphMeta.getNumLinksResolvedSuccessfullyFromCache()); - graphMeta.setNumLinksResolvedSuccessfullyFromServer(25); - assertEquals(25,graphMeta.getNumLinksResolvedSuccessfullyFromServer()); - graphMeta.setNumLinkResolveFailed(3); - assertEquals(3,graphMeta.getNumLinkResolveFailed()); graphMeta.setNumNodes(25); assertEquals(25,graphMeta.getNumNodes()); graphMeta.setNumLinks(3); diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/entity/InlineMessageTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/entity/InlineMessageTest.java deleted file mode 100644 index eebc821..0000000 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/entity/InlineMessageTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * ============LICENSE_START=================================================== - * SPARKY (AAI UI service) - * ============================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * All rights reserved. - * ============================================================================ - * 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===================================================== - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - */ - -package org.onap.aai.sparky.viewandinspect.entity; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Before; -import org.junit.Test; -import org.onap.aai.sparky.viewandinspect.entity.InlineMessage; - -public class InlineMessageTest { - - private InlineMessage inlineMsg; - - @Before - public void init() throws Exception { - inlineMsg = new InlineMessage("InlineMessage1","InlineMessage2"); - - } - - @Test - public void successfulInitializationAndUpdate() { - - inlineMsg.setLevel("Level-1"); - assertNotNull(inlineMsg.getLevel()); - inlineMsg.setMessage("InlineMessage3"); - assertNotNull(inlineMsg.getMessage()); - assertNotNull(inlineMsg.toString()); - } - - -} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseGizmoVisualizationContextTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseGizmoVisualizationContextTest.java index 94050be..79b71bc 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseGizmoVisualizationContextTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseGizmoVisualizationContextTest.java @@ -20,6 +20,7 @@ import org.onap.aai.sparky.dal.GizmoAdapter; import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig; import org.onap.aai.sparky.util.NodeUtils; import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; +import org.onap.aai.sparky.viewandinspect.context.BaseGizmoVisualizationContext; public class BaseGizmoVisualizationContextTest { diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContextTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContextTest.java index 1934207..394bfe4 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContextTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContextTest.java @@ -34,6 +34,7 @@ import org.onap.aai.sparky.util.NodeUtils; import org.onap.aai.sparky.util.StringCollectionContainsMatcher; import org.onap.aai.sparky.util.TestResourceLoader; import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; +import org.onap.aai.sparky.viewandinspect.context.BaseVisualizationContext; import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode; import org.onap.aai.sparky.viewandinspect.entity.QueryParams; import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingState; |