diff options
Diffstat (limited to 'aai-traversal')
116 files changed, 10031 insertions, 2036 deletions
diff --git a/aai-traversal/.classpath b/aai-traversal/.classpath new file mode 100644 index 0000000..ff97a07 --- /dev/null +++ b/aai-traversal/.classpath @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" output="target/classes" path="src/main/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" output="target/test-classes" path="src/test/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/> + <classpathentry kind="output" path="target/classes"/> +</classpath> diff --git a/aai-traversal/pom.xml b/aai-traversal/pom.xml index 2d85bbb..9d9b14d 100644 --- a/aai-traversal/pom.xml +++ b/aai-traversal/pom.xml @@ -42,6 +42,8 @@ <maven.skip.tests>true</maven.skip.tests> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> + + <jopt.simple.version>4.9</jopt.simple.version> <!-- End of the jacoco plugin properties --> @@ -79,7 +81,7 @@ <antlr4.listener>true</antlr4.listener> <snapshot.file>${project.basedir}/snapshots/data.graphson</snapshot.file> - <jacoco.line.coverage.limit>0.67</jacoco.line.coverage.limit> + <jacoco.line.coverage.limit>0.61</jacoco.line.coverage.limit> <!-- Start of Default ONAP Schema Properties --> <schema.source.name>onap</schema.source.name> @@ -299,6 +301,11 @@ <artifactId>spring-boot-starter-parent</artifactId> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> --> <dependencies> + <dependency> + <groupId>net.sf.jopt-simple</groupId> + <artifactId>jopt-simple</artifactId> + <version>${jopt.simple.version}</version> + </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-core</artifactId> @@ -555,7 +562,11 @@ <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </exclusion> - </exclusions> + <exclusion> + <groupId>org.onap.aai</groupId> + <artifactId>aai-logging</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> diff --git a/aai-traversal/src/main/java/org/onap/aai/Profiles.java b/aai-traversal/src/main/java/org/onap/aai/Profiles.java index ea65b9a..25f51c3 100644 --- a/aai-traversal/src/main/java/org/onap/aai/Profiles.java +++ b/aai-traversal/src/main/java/org/onap/aai/Profiles.java @@ -25,7 +25,10 @@ public final class Profiles { public static final String DME2 = "dme2"; public static final String ONE_WAY_SSL = "one-way-ssl"; + // AAF Basic Auth public static final String AAF_AUTHENTICATION = "aaf-auth"; + // AAF Auth with Client Certs + public static final String AAF_CERT_AUTHENTICATION = "aaf-cert-auth"; public static final String TWO_WAY_SSL = "two-way-ssl"; private Profiles(){} diff --git a/aai-traversal/src/main/java/org/onap/aai/TraversalApp.java b/aai-traversal/src/main/java/org/onap/aai/TraversalApp.java index 4d8f4a8..64f99b9 100644 --- a/aai-traversal/src/main/java/org/onap/aai/TraversalApp.java +++ b/aai-traversal/src/main/java/org/onap/aai/TraversalApp.java @@ -19,35 +19,38 @@ */ package org.onap.aai; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.apache.commons.lang3.exception.ExceptionUtils; +import org.onap.aai.aailog.logs.AaiDebugLog; import org.onap.aai.config.PropertyPasswordConfiguration; import org.onap.aai.config.SpringContextAware; import org.onap.aai.dbmap.AAIGraph; import org.onap.aai.exceptions.AAIException; import org.onap.aai.logging.ErrorLogHelper; -import org.onap.aai.logging.LoggingContext; -import org.onap.aai.logging.LoggingContext.StatusCode; +import org.onap.aai.logging.LogFormatTools; import org.onap.aai.nodes.NodeIngestor; import org.onap.aai.util.AAIConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.core.env.Environment; -import org.slf4j.MDC; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; -import java.util.UUID; + import java.util.Map; -@SpringBootApplication +@SpringBootApplication(exclude = { + DataSourceAutoConfiguration.class, + DataSourceTransactionManagerAutoConfiguration.class, + HibernateJpaAutoConfiguration.class +}) // Component Scan provides a way to look for spring beans // It only searches beans in the following packages // Any method annotated with @Bean annotation or any class @@ -59,17 +62,17 @@ import java.util.Map; "org.onap.aai.tasks", "org.onap.aai.service", "org.onap.aai.rest", - "org.onap.aai.rest-client" -}) - -@EnableAutoConfiguration(exclude = { - DataSourceAutoConfiguration.class, - DataSourceTransactionManagerAutoConfiguration.class, - HibernateJpaAutoConfiguration.class + "org.onap.aai.aaf", + "org.onap.aai.aailog" }) public class TraversalApp { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(TraversalApp.class.getName()); + private static final Logger logger = LoggerFactory.getLogger(TraversalApp.class.getName()); + + private static AaiDebugLog debugLog = new AaiDebugLog(); + static { + debugLog.setupMDC(); + } private static final String APP_NAME = "aai-traversal"; private static Map<String,String> contextMap; @@ -92,26 +95,18 @@ public class TraversalApp { System.setProperty("org.onap.aai.serverStarted", "false"); setDefaultProps(); - LoggingContext.save(); - LoggingContext.component("init"); - LoggingContext.partnerName("NA"); - LoggingContext.targetEntity(APP_NAME); - LoggingContext.requestId(UUID.randomUUID().toString()); - LoggingContext.serviceName(APP_NAME); - LoggingContext.targetServiceName("contextInitialized"); - LoggingContext.statusCode(StatusCode.COMPLETE); contextMap = MDC.getCopyOfContextMap(); - logger.info("AAI Server initialization started..."); + logger.debug("AAI Server initialization started..."); // Setting this property to allow for encoded slash (/) in the path parameter // This is only needed for tomcat keeping this as temporary System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true"); - logger.info("Starting AAIGraph connections and the NodeInjestor"); + logger.debug("Starting AAIGraph connections and the NodeInjestor"); if(env.acceptsProfiles(Profiles.TWO_WAY_SSL) && env.acceptsProfiles(Profiles.ONE_WAY_SSL)){ - logger.warn("You have seriously misconfigured your application"); + logger.debug("You have seriously misconfigured your application"); } AAIConfig.init(); @@ -121,6 +116,9 @@ public class TraversalApp { @PreDestroy public void cleanup(){ + contextMap = MDC.getCopyOfContextMap(); + MDC.setContextMap (contextMap); + logger.debug("Traversal MicroService stopped"); logger.info("Shutting down both realtime and cached connections"); AAIGraph.getInstance().graphShutdown(); } @@ -129,14 +127,6 @@ public class TraversalApp { setDefaultProps(); - LoggingContext.save(); - LoggingContext.component("init"); - LoggingContext.partnerName("NA"); - LoggingContext.targetEntity(APP_NAME); - LoggingContext.requestId(UUID.randomUUID().toString()); - LoggingContext.serviceName(APP_NAME); - LoggingContext.targetServiceName("contextInitialized"); - LoggingContext.statusCode(StatusCode.COMPLETE); Environment env =null; AAIConfig.init(); @@ -149,12 +139,8 @@ public class TraversalApp { } catch(Exception ex){ AAIException aai = schemaServiceExceptionTranslator(ex); - LoggingContext.statusCode(LoggingContext.StatusCode.ERROR); - LoggingContext.responseCode(LoggingContext.DATA_ERROR); - logger.error("Problems starting Traversal "+aai.getMessage()); ErrorLogHelper.logException(aai); ErrorLogHelper.logError(aai.getCode(), ex.getMessage() + ", resolve and restart Traversal"); - //ErrorLogHelper.logError(aai.getCode(), aai.getMessage() + aai.getCause().toString()); throw aai; } @@ -166,8 +152,6 @@ public class TraversalApp { env.getProperty("server.port") ); - logger.info("Traversal MicroService Started"); - logger.error("Traversal MicroService Started"); logger.debug("Traversal MicroService Started"); System.out.println("Traversal Microservice Started"); } @@ -198,22 +182,24 @@ public class TraversalApp { } private static AAIException schemaServiceExceptionTranslator(Exception ex) { AAIException aai = null; - logger.info("Error Message is "+ ExceptionUtils.getRootCause(ex).toString() + " details - "+ExceptionUtils.getRootCause(ex).getMessage()); - if(ExceptionUtils.getRootCause(ex).getMessage().contains("NodeIngestor")){ - aai = new AAIException("AAI_3026","Error reading OXM from SchemaService - Investigate"); - } - else if(ExceptionUtils.getRootCause(ex).getMessage().contains("EdgeIngestor")){ - aai = new AAIException("AAI_3027","Error reading EdgeRules from SchemaService - Investigate"); - } - else if(ExceptionUtils.getRootCause(ex).getMessage().contains("stored-queries")){ - aai = new AAIException("AAI_3027","Error reading EdgeRules from SchemaService - Investigate"); - } - else if(ExceptionUtils.getRootCause(ex).getMessage().contains("Connection refused")){ - aai = new AAIException("AAI_3025","Error connecting to SchemaService - Investigate"); - } - else { - aai = new AAIException("AAI_3025","Error connecting to SchemaService - Please Investigate"); - } + logger.info("Error Message is {} details - {}", ExceptionUtils.getRootCause(ex).toString(), ExceptionUtils.getRootCause(ex).getMessage()); + if ( ExceptionUtils.getRootCause(ex) == null || ExceptionUtils.getRootCause(ex).getMessage() == null ) { + aai = new AAIException("AAI_3025","Error parsing exception - Please Investigate" + + LogFormatTools.getStackTop(ex)); + } else { + logger.info("Exception is " + ExceptionUtils.getRootCause(ex).getMessage() + "Root cause is"+ ExceptionUtils.getRootCause(ex).toString()); + if(ExceptionUtils.getRootCause(ex).getMessage().contains("NodeIngestor")){ + aai = new AAIException("AAI_3026","Error reading OXM from SchemaService - Investigate"); + } + else if(ExceptionUtils.getRootCause(ex).getMessage().contains("EdgeIngestor")){ + aai = new AAIException("AAI_3027","Error reading EdgeRules from SchemaService - Investigate"); + } + else if(ExceptionUtils.getRootCause(ex).getMessage().contains("Connection refused")){ + aai = new AAIException("AAI_3025","Error connecting to SchemaService - Investigate"); + }else { + aai = new AAIException("AAI_3025","Error connecting to SchemaService - Please Investigate"); + } + } return aai; } diff --git a/aai-traversal/src/main/java/org/onap/aai/aailog/logs/AaiDBTraversalMetricLog.java b/aai-traversal/src/main/java/org/onap/aai/aailog/logs/AaiDBTraversalMetricLog.java new file mode 100644 index 0000000..8afc58b --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/aailog/logs/AaiDBTraversalMetricLog.java @@ -0,0 +1,115 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.aai.aailog.logs; + +import org.onap.aai.util.AAIConstants; +import org.onap.logging.filter.base.Constants; +import org.onap.logging.filter.base.MDCSetup; +import org.onap.logging.filter.base.ONAPComponents; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.slf4j.*; +import org.springframework.beans.factory.annotation.Value; + +import java.net.URI; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Optional; + +public class AaiDBTraversalMetricLog extends MDCSetup { + + protected static final Logger logger = LoggerFactory.getLogger(AaiDBTraversalMetricLog.class); + private final String partnerName; + private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN"); + private static final String TARGET_ENTITY = ONAPComponents.AAI.toString() + ".DB"; + public AaiDBTraversalMetricLog(String subcomponent) { + partnerName = getPartnerName(subcomponent); + } + + + protected String getTargetServiceName(Optional<URI> uri) { + return (getServiceName(uri)); + } + + protected String getServiceName(Optional<URI> uri) { + String serviceName = Constants.DefaultValues.UNKNOWN; + if (uri.isPresent()) { + serviceName = uri.get().getPath(); + if (serviceName != null && (!serviceName.isEmpty())) { + serviceName = serviceName.replaceAll(",", "\\\\,"); + } + } + return serviceName; + } + + + protected String getTargetEntity(Optional<URI> uri) { + return TARGET_ENTITY; + } + + protected String getPartnerName(@Value(AAIConstants.AAI_TRAVERSAL_MS) String subcomponent ) { + StringBuilder sb = new StringBuilder(ONAPComponents.AAI.toString()).append(subcomponent); + return (sb.toString()); + } + + public void pre(Optional<URI> uri) { + try { + setupMDC(uri); + setLogTimestamp(); + logger.info(ONAPLogConstants.Markers.INVOKE, "Invoke"); + } catch (Exception e) { + logger.warn("Error in AaiDBMetricLog pre", e.getMessage()); + } + } + + public void post() { + try { + setLogTimestamp(); + setElapsedTimeInvokeTimestamp(); + setResponseStatusCode(200); + setResponseDescription(200); + MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, "200"); + logger.info(INVOKE_RETURN, "InvokeReturn"); + clearClientMDCs(); + } catch (Exception e) { + logger.warn("Error in AaiDBMetricLog post", e.getMessage()); + } + } + + protected void setupMDC(Optional<URI> uri) { + MDC.put("InvokeTimestamp", ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); + MDC.put("TargetServiceName", this.getTargetServiceName(uri)); + MDC.put("StatusCode", ONAPLogConstants.ResponseStatus.INPROGRESS.toString()); + this.setInvocationIdFromMDC(); + if (MDC.get("TargetEntity") == null) { + String targetEntity = this.getTargetEntity(uri); + if (targetEntity != null) { + MDC.put("TargetEntity", targetEntity); + } else { + MDC.put("TargetEntity", "Unknown-Target-Entity"); + } + } + if (MDC.get("ServiceName") == null) { + MDC.put("ServiceName", this.getServiceName(uri)); + } + this.setServerFQDN(); + } +} diff --git a/aai-traversal/src/main/java/org/onap/aai/config/DslConfiguration.java b/aai-traversal/src/main/java/org/onap/aai/config/DslConfiguration.java index 311dd99..d10d4ac 100644 --- a/aai-traversal/src/main/java/org/onap/aai/config/DslConfiguration.java +++ b/aai-traversal/src/main/java/org/onap/aai/config/DslConfiguration.java @@ -19,28 +19,35 @@ */ package org.onap.aai.config; +import org.antlr.v4.runtime.tree.ParseTreeListener; import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.introspection.LoaderFactory; -import org.onap.aai.rest.dsl.DslListener; import org.onap.aai.rest.dsl.DslQueryProcessor; +import org.onap.aai.rest.enums.QueryVersion; import org.onap.aai.setup.SchemaVersions; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; +import java.util.HashMap; +import java.util.Map; + @Configuration public class DslConfiguration { @Bean @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public DslListener dslListener(EdgeIngestor edgeIngestor, SchemaVersions schemaVersions, LoaderFactory loaderFactory){ - return new DslListener(edgeIngestor, schemaVersions, loaderFactory); + public Map<QueryVersion, ParseTreeListener> dslListeners(EdgeIngestor edgeIngestor, SchemaVersions schemaVersions, LoaderFactory loaderFactory){ + Map<QueryVersion, ParseTreeListener> dslListeners = new HashMap<>(); + dslListeners.put(QueryVersion.V1,new org.onap.aai.rest.dsl.v1.DslListener(edgeIngestor, schemaVersions, loaderFactory)); + dslListeners.put(QueryVersion.V2,new org.onap.aai.rest.dsl.v2.DslListener(edgeIngestor, schemaVersions, loaderFactory)); + return dslListeners; } @Bean @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public DslQueryProcessor dslQueryProcessor(DslListener dslListener){ - return new DslQueryProcessor(dslListener); + public DslQueryProcessor dslQueryProcessor(Map<QueryVersion, ParseTreeListener> dslListeners){ + return new DslQueryProcessor(dslListeners); } } diff --git a/aai-traversal/src/main/java/org/onap/aai/config/PropertyPasswordConfiguration.java b/aai-traversal/src/main/java/org/onap/aai/config/PropertyPasswordConfiguration.java index 0d2ff88..0a76d6d 100644 --- a/aai-traversal/src/main/java/org/onap/aai/config/PropertyPasswordConfiguration.java +++ b/aai-traversal/src/main/java/org/onap/aai/config/PropertyPasswordConfiguration.java @@ -29,7 +29,8 @@ import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.apache.commons.io.IOUtils; import org.springframework.context.ApplicationContextInitializer; @@ -40,7 +41,7 @@ public class PropertyPasswordConfiguration implements ApplicationContextInitiali private static final Pattern decodePasswordPattern = Pattern.compile("password\\((.*?)\\)"); private PasswordDecoder passwordDecoder = new JettyPasswordDecoder(); - private static final EELFLogger logger = EELFManager.getInstance().getLogger(PropertyPasswordConfiguration.class.getName()); + private static final Logger logger = LoggerFactory.getLogger(PropertyPasswordConfiguration.class.getName()); @Override public void initialize(ConfigurableApplicationContext applicationContext) { @@ -68,10 +69,10 @@ public class PropertyPasswordConfiguration implements ApplicationContextInitiali sslProps.put("server.ssl.key-store-password", keystorePassword); sslProps.put("schema.service.ssl.key-store-password", keystorePassword); } else { - logger.info("Not using AAF Certman password file"); + logger.debug("Not using AAF Certman password file"); } } catch (IOException e) { - logger.warn("Not using AAF Certman password file, e=" + e.getMessage()); + logger.debug("Not using AAF Certman password file, e=" + e.getMessage()); } finally { if (passwordStream != null) { try { @@ -95,10 +96,10 @@ public class PropertyPasswordConfiguration implements ApplicationContextInitiali sslProps.put("server.ssl.trust-store-password", truststorePassword); sslProps.put("schema.service.ssl.trust-store-password", truststorePassword); } else { - logger.info("Not using AAF Certman passphrases file"); + logger.debug("Not using AAF Certman passphrases file"); } } catch (IOException e) { - logger.warn("Not using AAF Certman passphrases file, e=" + e.getMessage()); + logger.debug("Not using AAF Certman passphrases file, e=" + e.getMessage()); } finally { if (passphrasesStream != null) { try { @@ -118,7 +119,7 @@ public class PropertyPasswordConfiguration implements ApplicationContextInitiali } if (!sslProps.isEmpty()) { - logger.info("Using AAF Certman files"); + logger.debug("Using AAF Certman files"); PropertySource<?> additionalProperties = new MapPropertySource("additionalProperties", sslProps); environment.getPropertySources().addFirst(additionalProperties); } diff --git a/aai-traversal/src/main/java/org/onap/aai/config/SearchConfiguration.java b/aai-traversal/src/main/java/org/onap/aai/config/SearchConfiguration.java index 0b8238b..b60a707 100644 --- a/aai-traversal/src/main/java/org/onap/aai/config/SearchConfiguration.java +++ b/aai-traversal/src/main/java/org/onap/aai/config/SearchConfiguration.java @@ -23,7 +23,7 @@ import org.onap.aai.dbgraphmap.SearchGraph; import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.introspection.LoaderFactory; -import org.onap.aai.rest.dsl.DslListener; +import org.onap.aai.rest.dsl.v1.DslListener; import org.onap.aai.rest.dsl.DslQueryProcessor; import org.onap.aai.rest.search.CQConfig; import org.onap.aai.rest.search.GremlinServerSingleton; diff --git a/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java b/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java index dc42120..f1ffb9f 100644 --- a/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java +++ b/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java @@ -19,7 +19,9 @@ */ package org.onap.aai.dbgraphgen; -import com.att.eelf.configuration.EELFLogger; +import org.onap.aai.logging.ErrorLogHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; @@ -58,7 +60,7 @@ import java.util.concurrent.TimeUnit; */ public class ModelBasedProcessing { - private EELFLogger LOGGER = EELFManager.getInstance().getLogger(ModelBasedProcessing.class); + private Logger LOGGER = LoggerFactory.getLogger(ModelBasedProcessing.class); private final int MAX_LEVELS = 50; // max depth allowed for our model - to protect against infinite loop problems private TransactionalGraphEngine engine; @@ -842,7 +844,8 @@ public class ModelBasedProcessing { } catch (Exception ex) { // Sometimes things have already been deleted by the time we get to them - just log it. - LOGGER.warn("Exception when trying to delete: " + thisGuyStr + ". msg = " + ex.getMessage() + LogFormatTools.getStackTop(ex)); + AAIException aaiException = new AAIException("AAI_6154", thisGuyStr + ". msg = " + ex.getMessage()); + ErrorLogHelper.logException(aaiException); } if( !gotVtxOK ){ @@ -853,7 +856,7 @@ public class ModelBasedProcessing { } else { if( resSet.getNewDataDelFlag() != null && resSet.getNewDataDelFlag().equals("T") ){ - LOGGER.info(">> will try to delete this one >> " + thisGuyStr); + LOGGER.debug(">> will try to delete this one >> " + thisGuyStr); try { Boolean requireResourceVersion = false; @@ -870,9 +873,10 @@ public class ModelBasedProcessing { throw ae; } else { + ErrorLogHelper.logException(ae); String errText = ae.getErrorObject().getErrorText(); String errDetail = ae.getMessage(); - LOGGER.warn("Exception when deleting " + thisGuyStr + ". ErrorCode = " + errorCode + + LOGGER.debug("Exception when deleting " + thisGuyStr + ". ErrorCode = " + errorCode + ", errorText = " + errText + ", details = " + errDetail); } } @@ -880,7 +884,8 @@ public class ModelBasedProcessing { // We'd expect to get a "node not found" here sometimes depending on the order that // the model has us finding / deleting nodes. // Ignore the exception - but log it so we can see what happened. - LOGGER.warn("Exception when deleting " + thisGuyStr + e.getMessage() + LogFormatTools.getStackTop(e)); + AAIException aaiException = new AAIException("AAI_6154", thisGuyStr + ". msg = " + e.getMessage()); + ErrorLogHelper.logException(aaiException); } // We can't depend on a thrown exception to tell us if a node was deleted since it may diff --git a/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java b/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java index a8f0153..d0e881d 100644 --- a/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java +++ b/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java @@ -19,24 +19,10 @@ */ package org.onap.aai.dbgraphmap; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilderException; -import javax.xml.bind.JAXBException; - +import com.google.common.base.CaseFormat; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import edu.emory.mathcs.backport.java.util.Collections; import org.apache.commons.lang3.StringUtils; import org.apache.tinkerpop.gremlin.process.traversal.P; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; @@ -52,42 +38,42 @@ import org.onap.aai.db.props.AAIProperties; import org.onap.aai.dbgen.PropertyLimitDesc; import org.onap.aai.dbgraphgen.ModelBasedProcessing; import org.onap.aai.dbgraphgen.ResultSet; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.edges.EdgeRule; import org.onap.aai.edges.EdgeRuleQuery; import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; import org.onap.aai.exceptions.AAIException; -import org.onap.aai.extensions.AAIExtensionMap; -import org.onap.aai.introspection.Introspector; -import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.LoaderFactory; -import org.onap.aai.introspection.ModelType; -import org.onap.aai.introspection.MoxyLoader; +import org.onap.aai.introspection.*; import org.onap.aai.introspection.exceptions.AAIUnknownObjectException; +import org.onap.aai.logging.ErrorLogHelper; import org.onap.aai.parsers.relationship.RelationshipToURI; import org.onap.aai.query.builder.QueryBuilder; +import org.onap.aai.rest.util.AAIExtensionMap; import org.onap.aai.schema.enums.ObjectMetadata; import org.onap.aai.schema.enums.PropertyMetadata; import org.onap.aai.serialization.db.DBSerializer; -import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.util.GenericQueryBuilder; import org.onap.aai.util.NodesQueryBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.google.common.base.CaseFormat; - -import edu.emory.mathcs.backport.java.util.Collections; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import org.onap.aai.util.GenericQueryBuilder; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilderException; +import javax.xml.bind.JAXBException; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** @@ -97,7 +83,7 @@ import org.onap.aai.util.GenericQueryBuilder; */ public class SearchGraph { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(SearchGraph.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SearchGraph.class); private LoaderFactory loaderFactory; @@ -145,11 +131,10 @@ public class SearchGraph { // for now query it directly without attempting to craft a valid URI if (genericQueryBuilder.getStartNodeType().equalsIgnoreCase("service-instance") && genericQueryBuilder.getStartNodeKeyParams().size() == 1) { - Introspector obj = - genericQueryBuilder.getLoader().introspectorFromName(genericQueryBuilder.getStartNodeType()); + genericQueryBuilder.getLoader().introspectorFromName(genericQueryBuilder.getStartNodeType()); // Build a hash with keys to uniquely identify the start Node - String keyName = null; - String keyValue = null; + String keyName; + String keyValue; QueryBuilder builder = genericQueryBuilder.getDbEngine().getQueryBuilder() .getVerticesByIndexedProperty(AAIProperties.NODE_TYPE, "service-instance"); @@ -185,7 +170,7 @@ public class SearchGraph { Vertex startNode = results.get(0); Collection<Vertex> ver = new HashSet<>(); - List<Vertex> queryResults = new ArrayList<>(); + List<Vertex> queryResults; GraphTraversalSource traversalSource = genericQueryBuilder.getDbEngine().asAdmin().getReadOnlyTraversalSource(); GraphTraversal<Vertex, Vertex> traversal; @@ -204,7 +189,8 @@ public class SearchGraph { if (queryResults.isEmpty()) { - LOGGER.warn("No nodes found - apipe was null/empty"); + AAIException aaiException = new AAIException("AAI_6114", "No nodes found - apipe was null/empty"); + ErrorLogHelper.logException(aaiException); } else { Introspector searchResults = createSearchResults(genericQueryBuilder.getLoader(), @@ -218,7 +204,7 @@ public class SearchGraph { result = searchResults.marshal(properties); response = Response.ok().entity(result).build(); - LOGGER.debug(ver.size() + " node(s) traversed, " + queryResults.size() + " found"); + LOGGER.debug("{} node(s) traversed, {} found", ver.size(), queryResults.size()); } success = true; } catch (AAIException e) { @@ -286,8 +272,7 @@ public class SearchGraph { Introspector target; - if (StringUtils.isBlank(nodesQuery.getTargetNodeType()) - || StringUtils.isBlank(nodesQuery.getTargetNodeType())) { + if (StringUtils.isBlank(nodesQuery.getTargetNodeType())) { throw new AAIException("AAI_6120", "null or empty target-node-type passed to the node query"); } @@ -300,13 +285,11 @@ public class SearchGraph { if (nodesQuery.getFilterParams().isEmpty() && nodesQuery.getEdgeFilterParams().isEmpty()) { // For now, it's ok to pass no filter params. We'll just return ALL the nodes of the requested type. - LOGGER.warn("No filters passed to the node query"); + LOGGER.debug("No filters passed to the node query"); } - StringBuilder queryStringForMsg = new StringBuilder(); GraphTraversal<Vertex, Vertex> traversal = nodesQuery.getDbEngine().asAdmin().getReadOnlyTraversalSource() .V().has(AAIProperties.NODE_TYPE, nodesQuery.getTargetNodeType()); - queryStringForMsg.append("has(\"aai-node-type\"," + nodesQuery.getTargetNodeType() + ")"); for (String filter : nodesQuery.getFilterParams()) { String[] pieces = filter.split(":"); @@ -322,13 +305,12 @@ public class SearchGraph { String value = "?"; if (pieces.length == 3) { value = pieces[2]; - } else if (pieces.length > 3) { + } else { // length > 3 // When a ipv6 address comes in as a value, it has colons in it which require us to // pull the "value" off the end of the filter differently int startPos4Value = propName.length() + filterType.length() + 3; value = filter.substring(startPos4Value); } - queryStringForMsg.append(".has(" + propName + "," + value + ")"); traversal.has(propName, value); } else if (filterType.equals(DOES_NOT_EQUAL)) { if (pieces.length < 3) { @@ -337,19 +319,16 @@ public class SearchGraph { String value = "?"; if (pieces.length == 3) { value = pieces[2]; - } else if (pieces.length > 3) { + } else { // length > 3 // When a ipv6 address comes in as a value, it has colons in it which require us to // pull the "value" off the end of the filter differently int startPos4Value = propName.length() + filterType.length() + 3; value = filter.substring(startPos4Value); } - queryStringForMsg.append(".hasNot(" + propName + "," + value + ")"); traversal.not(__.has(propName, value)); } else if (filterType.equals(EXISTS)) { - queryStringForMsg.append(".has(" + propName + ")"); traversal.has(propName); } else if (filterType.equals(DOES_NOT_EXIST)) { - queryStringForMsg.append(".hasNot(" + propName + ")"); traversal.hasNot(propName); } else { throw new AAIException("AAI_6120", "bad filterType passed: [" + filterType + "]"); @@ -400,7 +379,7 @@ public class SearchGraph { if (filterType.equals(DOES_NOT_EXIST)) { traversal.where(__.not(edgeSearch)); - } else if (filterType.equals(EXISTS)) { + } else { traversal.where(edgeSearch); } } @@ -521,7 +500,7 @@ public class SearchGraph { * @throws AAIException the AAI exception */ public Response runNamedQuery(String fromAppId, String transId, String queryParameters, - DBConnectionType connectionType, AAIExtensionMap aaiExtMap) throws JAXBException, AAIException { + AAIExtensionMap aaiExtMap) throws AAIException { Introspector inventoryItems; boolean success = true; @@ -531,7 +510,7 @@ public class SearchGraph { MoxyLoader loader = (MoxyLoader) loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); DynamicJAXBContext jaxbContext = loader.getJAXBContext(); - dbEngine = new JanusGraphDBEngine(QueryStyle.TRAVERSAL, connectionType, loader); + dbEngine = new JanusGraphDBEngine(QueryStyle.TRAVERSAL, loader); DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), dbEngine, ModelType.MOXY, fromAppId); ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); @@ -552,7 +531,7 @@ public class SearchGraph { if (modelAndNamedQuerySearch == null) { throw new AAIException("AAI_5105"); } - HashMap<String, Object> namedQueryLookupHash = new HashMap<String, Object>(); + Map<String, Object> namedQueryLookupHash = new HashMap<>(); DynamicEntity qp = modelAndNamedQuerySearch.get("queryParameters"); String namedQueryUuid = null; @@ -590,12 +569,12 @@ public class SearchGraph { List<Map<String, Object>> startNodeFilterHash = new ArrayList<>(); - mapInstanceFilters((DynamicEntity) modelAndNamedQuerySearch.get("instanceFilters"), startNodeFilterHash, + mapInstanceFilters(modelAndNamedQuerySearch.get("instanceFilters"), startNodeFilterHash, jaxbContext); Map<String, Object> secondaryFilterHash = new HashMap<>(); - mapSecondaryFilters((DynamicEntity) modelAndNamedQuerySearch.get("secondaryFilts"), secondaryFilterHash, + mapSecondaryFilters(modelAndNamedQuerySearch.get("secondaryFilts"), secondaryFilterHash, jaxbContext); List<ResultSet> resultSet = processor.queryByNamedQuery(transId, fromAppId, namedQueryUuid, @@ -641,8 +620,8 @@ public class SearchGraph { * @throws UnsupportedEncodingException the unsupported encoding exception */ public Response executeModelOperation(String fromAppId, String transId, String queryParameters, - DBConnectionType connectionType, boolean isDelete, AAIExtensionMap aaiExtMap) - throws JAXBException, AAIException, DynamicException, UnsupportedEncodingException { + boolean isDelete, AAIExtensionMap aaiExtMap) + throws AAIException, DynamicException { Response response; boolean success = true; TransactionalGraphEngine dbEngine = null; @@ -651,7 +630,7 @@ public class SearchGraph { MoxyLoader loader = (MoxyLoader) loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); DynamicJAXBContext jaxbContext = loader.getJAXBContext(); - dbEngine = new JanusGraphDBEngine(QueryStyle.TRAVERSAL, connectionType, loader); + dbEngine = new JanusGraphDBEngine(QueryStyle.TRAVERSAL, loader); DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), dbEngine, ModelType.MOXY, fromAppId); ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); @@ -674,12 +653,10 @@ public class SearchGraph { throw new AAIException("AAI_5105"); } - Map<String, Object> modelQueryLookupHash = new HashMap<>(); - String modelVersionId = null; String modelName = null; String modelInvariantId = null; - String modelVersion = null; + String modelVersion; String topNodeType = null; if (modelAndNamedQuerySearch.isSet("topNodeType")) { @@ -698,7 +675,7 @@ public class SearchGraph { DynamicEntity qp = modelAndNamedQuerySearch.get("queryParameters"); if (qp.isSet("model")) { - DynamicEntity model = (DynamicEntity) qp.get("model"); + DynamicEntity model = qp.get("model"); // on an old-style model object, the following 4 attrs were all present if (model.isSet("modelNameVersionId")) { @@ -723,7 +700,7 @@ public class SearchGraph { if (model.isSet("modelVers")) { // we know that this is new style, because modelVers was not an option // before v9 - DynamicEntity modelVers = (DynamicEntity) model.get("modelVers"); + DynamicEntity modelVers = model.get("modelVers"); if (modelVers.isSet("modelVer")) { List<DynamicEntity> modelVerList = modelVers.get("modelVer"); // if they send more than one, too bad, they get the first one @@ -752,8 +729,7 @@ public class SearchGraph { List<ResultSet> resultSet = processor.queryByModel(transId, fromAppId, modelVersionId, modelInvariantId, modelName, topNodeType, startNodeFilterHash, aaiExtMap.getApiVersion()); - Map<Object, String> objectToVertMap = new HashMap<>(); - List<Object> invItemList = unpackResultSet(resultSet, dbEngine, loader, serializer); + unpackResultSet(resultSet, dbEngine, loader, serializer); ResultSet rs = resultSet.get(0); diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/post/AAIResponseFilterPriority.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/post/AAIResponseFilterPriority.java index 146f847..ccf89fc 100644 --- a/aai-traversal/src/main/java/org/onap/aai/interceptors/post/AAIResponseFilterPriority.java +++ b/aai-traversal/src/main/java/org/onap/aai/interceptors/post/AAIResponseFilterPriority.java @@ -22,7 +22,7 @@ package org.onap.aai.interceptors.post; /** * Response Filter order is done reverse sorted * so in the following case the first response filter would be - * HEADER_MANIPULATION, RESPONSE_TRANS_LOGGING, RESET_LOGGING_CONTEXT, + * HEADER_MANIPULATION, RESPONSE_TRANS_LOGGING, * and INVALID_RESPONSE_STATUS */ public final class AAIResponseFilterPriority { @@ -31,8 +31,6 @@ public final class AAIResponseFilterPriority { public static final int INVALID_RESPONSE_STATUS = 1000; - public static final int RESET_LOGGING_CONTEXT = 2000; - public static final int RESPONSE_TRANS_LOGGING = 3000; public static final int HEADER_MANIPULATION = 4000; diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/post/ResetLoggingContext.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/post/ResetLoggingContext.java deleted file mode 100644 index baf28ad..0000000 --- a/aai-traversal/src/main/java/org/onap/aai/interceptors/post/ResetLoggingContext.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= - */ -package org.onap.aai.interceptors.post; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.aai.interceptors.AAIContainerFilter; -import org.onap.aai.logging.LoggingContext; -import org.onap.aai.logging.LoggingContext.StatusCode; -import org.springframework.beans.factory.annotation.Autowired; - -import javax.annotation.Priority; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerResponseContext; -import javax.ws.rs.container.ContainerResponseFilter; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.Response.StatusType; -import java.io.IOException; - -@Priority(AAIResponseFilterPriority.RESET_LOGGING_CONTEXT) -public class ResetLoggingContext extends AAIContainerFilter implements ContainerResponseFilter { - - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ResetLoggingContext.class); - - @Autowired - private HttpServletRequest httpServletRequest; - - @Override - public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) - throws IOException { - - this.cleanLoggingContext(responseContext); - - } - - private void cleanLoggingContext(ContainerResponseContext responseContext) { - //String url = httpServletRequest.getRequestURL().toString(); - boolean success = true; - String uri = httpServletRequest.getRequestURI(); - String queryString = httpServletRequest.getQueryString(); - - if(queryString != null && !queryString.isEmpty()){ - uri = uri + "?" + queryString; - } - // For now, we use the the HTTP status code, - // This may change, once the requirements for response codes are defined - - int httpStatusCode = responseContext.getStatus(); - if ( httpStatusCode < 100 || httpStatusCode > 599 ) { - httpStatusCode = Status.INTERNAL_SERVER_ERROR.getStatusCode(); - } - LoggingContext.responseCode(Integer.toString(httpStatusCode)); - - StatusType sType = responseContext.getStatusInfo(); - if ( sType != null ) { - Status.Family sFamily = sType.getFamily(); - if ( ! ( Status.Family.SUCCESSFUL.equals(sFamily) || - ( Status.NOT_FOUND.equals(Status.fromStatusCode(httpStatusCode)) ) ) ) { - success = false; - } - } - else { - if ( (httpStatusCode < 200 || httpStatusCode > 299) && ( ! ( Status.NOT_FOUND.equals(Status.fromStatusCode(httpStatusCode) ) ) ) ) { - success = false; - } - } - if (success) { - LoggingContext.statusCode(StatusCode.COMPLETE); - LOGGER.info(uri + " call succeeded"); - } - else { - LoggingContext.statusCode(StatusCode.ERROR); - LOGGER.error(uri + " call failed with responseCode=" + httpStatusCode); - } - LoggingContext.clear(); - - - } - -} diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/post/ResponseTransactionLogging.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/post/ResponseTransactionLogging.java index 547a7c8..51fe871 100644 --- a/aai-traversal/src/main/java/org/onap/aai/interceptors/post/ResponseTransactionLogging.java +++ b/aai-traversal/src/main/java/org/onap/aai/interceptors/post/ResponseTransactionLogging.java @@ -19,14 +19,14 @@ */ package org.onap.aai.interceptors.post; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import com.google.gson.JsonObject; import org.onap.aai.exceptions.AAIException; import org.onap.aai.interceptors.AAIContainerFilter; import org.onap.aai.interceptors.AAIHeaderProperties; import org.onap.aai.logging.ErrorLogHelper; import org.onap.aai.util.AAIConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import javax.annotation.Priority; @@ -34,14 +34,21 @@ import javax.servlet.http.HttpServletResponse; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; +import javax.ws.rs.core.PathSegment; import java.io.IOException; -import java.util.Objects; -import java.util.Optional; +import java.util.*; @Priority(AAIResponseFilterPriority.RESPONSE_TRANS_LOGGING) public class ResponseTransactionLogging extends AAIContainerFilter implements ContainerResponseFilter { - private static final EELFLogger TRANSACTION_LOGGER = EELFManager.getInstance().getLogger(ResponseTransactionLogging.class); + private static final Logger TRANSACTION_LOGGER = LoggerFactory.getLogger(ResponseTransactionLogging.class); + + private final static String QUERY_API_PATH_SEGMENT = "query"; + private final static String NODES_QUERY_API_PATH_SEGMENT = "nodes-query"; + private final static String GENERIC_QUERY_API_PATH_SEGMENT = "generic-query"; + private final static String DSL_API_PATH_SEGMENT = "dsl"; + private final static String RECENTS_API_PATH_SEGMENT = "recents"; + private final static Set<String> READ_ONLY_QUERIES = getReadOnlyQueries(); @Autowired private HttpServletResponse httpServletResponse; @@ -57,12 +64,13 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co private void transLogging(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { String logValue; - String getValue; + String isGetTransactionResponseLoggingEnabled; String postValue; - + try { + logValue = AAIConfig.get("aai.transaction.logging"); - getValue = AAIConfig.get("aai.transaction.logging.get"); + isGetTransactionResponseLoggingEnabled = AAIConfig.get("aai.transaction.logging.get"); postValue = AAIConfig.get("aai.transaction.logging.post"); } catch (AAIException e) { return; @@ -81,7 +89,6 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co String response = this.getResponseString(responseContext); if (!Boolean.parseBoolean(logValue)) { - } else if (!Boolean.parseBoolean(getValue) && "GET".equals(httpMethod)) { } else if (!Boolean.parseBoolean(postValue) && "POST".equals(httpMethod)) { } else { @@ -94,12 +101,33 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co logEntry.addProperty("resourceId", fullUri); logEntry.addProperty("resourceType", httpMethod); logEntry.addProperty("rqstBuf", Objects.toString(request, "")); - logEntry.addProperty("respBuf", Objects.toString(response, "")); - - try { - TRANSACTION_LOGGER.debug(logEntry.toString()); - } catch (Exception e) { - ErrorLogHelper.logError("AAI_4000", "Exception writing transaction log."); + + boolean recordResponse = true; + if (!Boolean.parseBoolean(isGetTransactionResponseLoggingEnabled) && "GET".equals(httpMethod)) { + recordResponse = false; + } + else { + /** + * Parse the uri path and see if it is a read-only query + * If it is, do not record the response in the logs + */ + + List<PathSegment> pathSegmentList = requestContext.getUriInfo().getPathSegments(); + for (PathSegment queryType : pathSegmentList) { + if (READ_ONLY_QUERIES.contains(queryType.toString())) { + recordResponse = false; + } + } + + if (recordResponse) { + logEntry.addProperty("respBuf", Objects.toString(response, "")); + } + + try { + TRANSACTION_LOGGER.debug(logEntry.toString()); + } catch (Exception e) { + ErrorLogHelper.logError("AAI_4000", "Exception writing transaction log."); + } } } @@ -120,4 +148,14 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co return response.toString(); } + private static Set<String> getReadOnlyQueries() { + Set<String> readOnlyQueries = new HashSet<String>(); + readOnlyQueries.add(NODES_QUERY_API_PATH_SEGMENT); + readOnlyQueries.add(GENERIC_QUERY_API_PATH_SEGMENT); + readOnlyQueries.add(RECENTS_API_PATH_SEGMENT); + readOnlyQueries.add(QUERY_API_PATH_SEGMENT); + readOnlyQueries.add(DSL_API_PATH_SEGMENT); + return readOnlyQueries; + } + } diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/AAIRequestFilterPriority.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/AAIRequestFilterPriority.java index c3d9d3b..4af96c5 100644 --- a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/AAIRequestFilterPriority.java +++ b/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/AAIRequestFilterPriority.java @@ -27,8 +27,6 @@ public final class AAIRequestFilterPriority { public static final int HEADER_VALIDATION = 2000; - public static final int SET_LOGGING_CONTEXT = 3000; - public static final int HTTP_HEADER = 4000; public static final int LATEST = 4250; diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/HeaderValidation.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/HeaderValidation.java index d6b6080..d70cb01 100644 --- a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/HeaderValidation.java +++ b/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/HeaderValidation.java @@ -23,6 +23,8 @@ import org.onap.aai.exceptions.AAIException; import org.onap.aai.interceptors.AAIContainerFilter; import org.onap.aai.interceptors.AAIHeaderProperties; import org.onap.aai.logging.ErrorLogHelper; +import org.onap.logging.filter.base.Constants; +import org.onap.logging.ref.slf4j.ONAPLogConstants; import javax.annotation.Priority; import javax.ws.rs.container.ContainerRequestContext; @@ -34,7 +36,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.UUID; @PreMatching @Priority(AAIRequestFilterPriority.HEADER_VALIDATION) @@ -44,36 +45,28 @@ public class HeaderValidation extends AAIContainerFilter implements ContainerReq public void filter(ContainerRequestContext requestContext) throws IOException { Optional<Response> oResp; - - String transId = requestContext.getHeaderString(AAIHeaderProperties.TRANSACTION_ID); - String fromAppId = requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID); List<MediaType> acceptHeaderValues = requestContext.getAcceptableMediaTypes(); + String fromAppId = getPartnerName(requestContext); oResp = this.validateHeaderValuePresence(fromAppId, "AAI_4009", acceptHeaderValues); if (oResp.isPresent()) { requestContext.abortWith(oResp.get()); return; } + String transId = getRequestId(requestContext); oResp = this.validateHeaderValuePresence(transId, "AAI_4010", acceptHeaderValues); if (oResp.isPresent()) { requestContext.abortWith(oResp.get()); return; } - - if (!this.isValidUUID(transId)) { - transId = UUID.randomUUID().toString(); - requestContext.getHeaders().get(AAIHeaderProperties.TRANSACTION_ID).clear(); - requestContext.getHeaders().add(AAIHeaderProperties.TRANSACTION_ID, transId); - } - } private Optional<Response> validateHeaderValuePresence(String value, String errorCode, List<MediaType> acceptHeaderValues) { Response response = null; AAIException aaie; - if (value == null) { + if (value == null || value.isEmpty()) { aaie = new AAIException(errorCode); return Optional.of(Response.status(aaie.getErrorObject().getHTTPResponseCode()) .entity(ErrorLogHelper.getRESTAPIErrorResponse(acceptHeaderValues, aaie, new ArrayList<>())) @@ -82,5 +75,52 @@ public class HeaderValidation extends AAIContainerFilter implements ContainerReq return Optional.ofNullable(response); } + public String getRequestId(ContainerRequestContext requestContext) { + String requestId = requestContext.getHeaderString(ONAPLogConstants.Headers.REQUEST_ID); + if (requestId == null || requestId.isEmpty()) { + requestId = requestContext.getHeaderString(Constants.HttpHeaders.HEADER_REQUEST_ID); + if (requestId == null || requestId.isEmpty()) { + requestId = requestContext.getHeaderString(Constants.HttpHeaders.TRANSACTION_ID); + if (requestId == null || requestId.isEmpty()) { + requestId = requestContext.getHeaderString(Constants.HttpHeaders.ECOMP_REQUEST_ID); + if (requestId == null || requestId.isEmpty()) { + return requestId; + } + } + } + } + if (requestContext.getHeaders().get(ONAPLogConstants.Headers.REQUEST_ID) != null) { + requestContext.getHeaders().get(ONAPLogConstants.Headers.REQUEST_ID).clear(); + } + if (requestContext.getHeaders().get(Constants.HttpHeaders.TRANSACTION_ID) != null) { + requestContext.getHeaders().get(Constants.HttpHeaders.TRANSACTION_ID).clear(); + } + if (requestContext.getHeaders().get(Constants.HttpHeaders.HEADER_REQUEST_ID) != null) { + requestContext.getHeaders().get(Constants.HttpHeaders.HEADER_REQUEST_ID).clear(); + } + if (requestContext.getHeaders().get(Constants.HttpHeaders.ECOMP_REQUEST_ID) != null) { + requestContext.getHeaders().get(Constants.HttpHeaders.ECOMP_REQUEST_ID).clear(); + } + requestContext.getHeaders().add(Constants.HttpHeaders.TRANSACTION_ID, requestId); + + return requestId; + } + public String getPartnerName(ContainerRequestContext requestContext) { + String partnerName = requestContext.getHeaderString(ONAPLogConstants.Headers.PARTNER_NAME); + if (partnerName == null || (partnerName.isEmpty())) { + partnerName = requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID); + if (partnerName == null || (partnerName.isEmpty())) { + return partnerName; + } + } + if (requestContext.getHeaders().get(ONAPLogConstants.Headers.PARTNER_NAME) != null) { + requestContext.getHeaders().get(ONAPLogConstants.Headers.PARTNER_NAME).clear(); + } + if (requestContext.getHeaders().get(AAIHeaderProperties.FROM_APP_ID) != null) { + requestContext.getHeaders().get(AAIHeaderProperties.FROM_APP_ID).clear(); + } + requestContext.getHeaders().add(AAIHeaderProperties.FROM_APP_ID, partnerName); + return partnerName; + } } diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java index 6c86f19..03cac8d 100644 --- a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java +++ b/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java @@ -37,6 +37,8 @@ import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.PreMatching; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.UriInfo; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -58,6 +60,8 @@ public class RequestTransactionLogging extends AAIContainerFilter implements Con private static final String CONTENT_TYPE = "Content-Type"; private static final String ACCEPT = "Accept"; private static final String TEXT_PLAIN = "text/plain"; + private static final String WILDCARD = "*/*"; + private static final String APPLICATION_JSON = "application/json"; @Override public void filter(ContainerRequestContext requestContext) throws IOException { @@ -83,8 +87,18 @@ public class RequestTransactionLogging extends AAIContainerFilter implements Con requestContext.getHeaders().putSingle(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - if(StringUtils.isEmpty(acceptType) || acceptType.contains(TEXT_PLAIN)){ - requestContext.getHeaders().putSingle(ACCEPT, DEFAULT_RESPONSE_TYPE); + if(WILDCARD.equals(acceptType) || StringUtils.isEmpty(acceptType) || acceptType.contains(TEXT_PLAIN)){ + UriInfo uriInfo = requestContext.getUriInfo(); + if(uriInfo != null){ + String path = uriInfo.getPath(); + if(path.endsWith("/dsl") || path.endsWith("/query") || path.contains("/recents/")){ + requestContext.getHeaders().putSingle(ACCEPT, APPLICATION_JSON); + } else { + requestContext.getHeaders().putSingle(ACCEPT, DEFAULT_RESPONSE_TYPE); + } + } else { + requestContext.getHeaders().putSingle(ACCEPT, DEFAULT_RESPONSE_TYPE); + } } } diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/SetLoggingContext.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/SetLoggingContext.java deleted file mode 100644 index 4b0f18a..0000000 --- a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/SetLoggingContext.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= - */ -package org.onap.aai.interceptors.pre; - -import org.onap.aai.interceptors.AAIContainerFilter; -import org.onap.aai.interceptors.AAIHeaderProperties; -import org.onap.aai.logging.LoggingContext; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; - -import javax.annotation.Priority; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerRequestFilter; -import javax.ws.rs.container.PreMatching; -import java.io.IOException; - -@PreMatching -@Priority(AAIRequestFilterPriority.SET_LOGGING_CONTEXT) -public class SetLoggingContext extends AAIContainerFilter implements ContainerRequestFilter { - - @Autowired - private Environment environment; - - @Autowired - private HttpServletRequest httpServletRequest; - - @Override - public void filter(ContainerRequestContext requestContext) throws IOException { - - String uri = httpServletRequest.getRequestURI(); - String queryString = httpServletRequest.getQueryString(); - - if(queryString != null && !queryString.isEmpty()){ - uri = uri + "?" + queryString; - } - - String httpMethod = requestContext.getMethod(); - String transId = requestContext.getHeaderString(AAIHeaderProperties.TRANSACTION_ID); - String fromAppId = requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID); - - LoggingContext.init(); - LoggingContext.requestId(transId); - LoggingContext.partnerName(fromAppId); - LoggingContext.targetEntity(environment.getProperty("spring.application.name")); - LoggingContext.component(fromAppId); - LoggingContext.serviceName(httpMethod + " " + uri); - LoggingContext.targetServiceName(httpMethod + " " + uri); - LoggingContext.statusCode(LoggingContext.StatusCode.COMPLETE); - } - -} diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/TwoWaySslAuthorization.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/TwoWaySslAuthorization.java index bc03082..58c7be6 100644 --- a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/TwoWaySslAuthorization.java +++ b/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/TwoWaySslAuthorization.java @@ -19,7 +19,7 @@ */ package org.onap.aai.interceptors.pre; -import org.onap.aai.auth.AAIAuthCore; +import org.onap.aai.aaf.auth.AAIAuthCore; import org.onap.aai.exceptions.AAIException; import org.onap.aai.interceptors.AAIContainerFilter; import org.onap.aai.interceptors.AAIHeaderProperties; diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/CQ2Gremlin.java b/aai-traversal/src/main/java/org/onap/aai/rest/CQ2Gremlin.java index dcf8418..d075f70 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/CQ2Gremlin.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/CQ2Gremlin.java @@ -19,23 +19,7 @@ */ package org.onap.aai.rest; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.ws.rs.Consumes; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - import org.onap.aai.config.SpringContextAware; -import org.onap.aai.dbmap.DBConnectionType; -import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.rest.db.HttpEntry; import org.onap.aai.rest.search.CustomQueryConfigDTO; @@ -50,6 +34,15 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.RequestBody; +import javax.ws.rs.Consumes; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.*; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + @Path("/cq2gremlin") public class CQ2Gremlin extends RESTAPI { @@ -86,8 +79,6 @@ public class CQ2Gremlin extends RESTAPI { protected Response processGremlinQuery(CustomQueryConfigDTO content, UriInfo info, HttpHeaders headers) { try{ - String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); - String realTime = headers.getRequestHeaders().getFirst("Real-Time"); LinkedHashMap <String, Object> params; CustomQueryDTO queryDTO = content.getQueryDTO(); String query = queryDTO.getQuery(); @@ -108,8 +99,7 @@ public class CQ2Gremlin extends RESTAPI { } SchemaVersions schemaVersions = SpringContextAware.getBean(SchemaVersions.class); - DBConnectionType type = this.determineConnectionType(sourceOfTruth, realTime); - traversalUriHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type); + traversalUriHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion()); traversalUriHttpEntry.setPaginationParameters("-1", "-1"); TransactionalGraphEngine dbEngine = traversalUriHttpEntry.getDbEngine(); diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/CQ2GremlinTest.java b/aai-traversal/src/main/java/org/onap/aai/rest/CQ2GremlinTest.java index 40538be..e3cfaca 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/CQ2GremlinTest.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/CQ2GremlinTest.java @@ -20,26 +20,8 @@ package org.onap.aai.rest; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -import javax.ws.rs.Consumes; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - +import com.beust.jcommander.internal.Lists; +import com.beust.jcommander.internal.Maps; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; @@ -47,7 +29,6 @@ import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; import org.onap.aai.config.SpringContextAware; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.LoaderFactory; @@ -61,21 +42,27 @@ import org.onap.aai.serialization.db.EdgeSerializer; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.RequestBody; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.beust.jcommander.internal.Lists; -import com.beust.jcommander.internal.Maps; +import javax.ws.rs.Consumes; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.*; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; @Path("/cq2gremlintest") public class CQ2GremlinTest extends RESTAPI { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(CQ2GremlinTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(CQ2GremlinTest.class); private HttpEntry traversalUriHttpEntry; @@ -110,8 +97,7 @@ public class CQ2GremlinTest extends RESTAPI { String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); String realTime = headers.getRequestHeaders().getFirst("Real-Time"); SchemaVersions schemaVersions = SpringContextAware.getBean(SchemaVersions.class); - DBConnectionType type = this.determineConnectionType(sourceOfTruth, realTime); - traversalUriHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type); + traversalUriHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion()); traversalUriHttpEntry.setPaginationParameters("-1", "-1"); return processC2UnitTest(content); } @@ -123,12 +109,12 @@ public class CQ2GremlinTest extends RESTAPI { gts = graph.traversal(); List<Vertex> expectedVertices = createGraph(content, graph); GremlinGroovyShell shell = new GremlinGroovyShell(); - loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v16")); + loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v19")); LinkedHashMap <String, Object> params = new LinkedHashMap<>(); //Adding parameters - content.getQueryRequiredProperties().forEach((K, V) -> {params.put(K, V);}); - content.getQueryOptionalProperties().forEach((K, V) -> {params.put(K, V);}); + content.getQueryRequiredProperties().forEach(params::put); + content.getQueryOptionalProperties().forEach(params::put); String query = new GroovyQueryBuilder().executeTraversal(dbEngine, content.getStoredQuery(), params); query = "g" + query; @@ -166,17 +152,17 @@ public class CQ2GremlinTest extends RESTAPI { private List<Vertex> createGraph(CustomQueryTestDTO content, Graph graph) { Map<String, Vertex> verticesMap = Maps.newLinkedHashMap(); //Creating all the Vertices - content.getVerticesDtos().stream().forEach(vertex -> { + content.getVerticesDtos().forEach(vertex -> { StringBuilder vertexIdentifier = new StringBuilder(); List<String> keyValues = Lists.newArrayList(); keyValues.add(T.id.toString()); keyValues.add(String.format("%02d", verticesMap.size() * 10)); AtomicInteger index = new AtomicInteger(0); - vertex.forEach((K, V) -> { + vertex.forEach((k, v) -> { if(index.get() == 1) - vertexIdentifier.append(V); - keyValues.add(K); - keyValues.add(V); + vertexIdentifier.append(k); + keyValues.add(k); + keyValues.add(v); index.incrementAndGet(); }); Vertex graphVertex = graph.addVertex(keyValues.toArray()); @@ -186,7 +172,7 @@ public class CQ2GremlinTest extends RESTAPI { GraphTraversalSource g = graph.traversal(); //Creating all the Edges - content.getEdgesDtos().stream().forEach(edge -> { + content.getEdgesDtos().forEach(edge -> { String fromId = edge.get("from-id"); String toId = edge.get("to-id"); boolean treeEdgeIdentifier = !"NONE".equalsIgnoreCase(edge.get("contains-other-v")); @@ -207,9 +193,7 @@ public class CQ2GremlinTest extends RESTAPI { List<Vertex> expectedVertices = Lists.newArrayList(); - content.getExpectedResultsDtos().getIds().stream().forEach(vertexId -> { - expectedVertices.add(verticesMap.get(vertexId)); - }); + content.getExpectedResultsDtos().getIds().forEach(vertexId -> expectedVertices.add(verticesMap.get(vertexId))); return expectedVertices; } @@ -218,8 +202,8 @@ public class CQ2GremlinTest extends RESTAPI { if(!startNodeVertex.isPresent()){ throw new IllegalArgumentException("start-node was not specified"); } - startNodeVertex.get().forEach((K, V) -> { - g.has(K, V); + startNodeVertex.get().forEach((k, v) -> { + g.has(k, v); }); } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/DslConsumer.java b/aai-traversal/src/main/java/org/onap/aai/rest/DslConsumer.java index 2d09636..6cb6565 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/DslConsumer.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/DslConsumer.java @@ -19,24 +19,20 @@ */ package org.onap.aai.rest; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.onap.aai.concurrent.AaiCallable; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.ModelType; -import org.onap.aai.logging.LoggingContext; -import org.onap.aai.logging.StopWatch; import org.onap.aai.rest.db.HttpEntry; import org.onap.aai.rest.dsl.DslQueryProcessor; +import org.onap.aai.rest.enums.QueryVersion; import org.onap.aai.rest.search.GenericQueryProcessor; import org.onap.aai.rest.search.GremlinServerSingleton; import org.onap.aai.rest.search.QueryProcessorType; import org.onap.aai.restcore.HttpMethod; -import org.onap.aai.restcore.RESTAPI; import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.Format; @@ -45,27 +41,29 @@ import org.onap.aai.serialization.queryformats.Formatter; import org.onap.aai.serialization.queryformats.SubGraphStyle; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.transforms.XmlFormatTransformer; import org.onap.aai.util.AAIConfig; import org.onap.aai.util.TraversalConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import javax.servlet.http.HttpServletRequest; import javax.ws.rs.*; import javax.ws.rs.core.*; import javax.ws.rs.core.Response.Status; import java.util.List; -import java.util.concurrent.TimeUnit; +import java.util.Map; +import java.util.Optional; @Path("{version: v[1-9][0-9]*|latest}/dsl") -public class DslConsumer extends RESTAPI { +public class DslConsumer extends TraversalConsumer { private HttpEntry traversalUriHttpEntry; private QueryProcessorType processorType = QueryProcessorType.LOCAL_GROOVY; - private static final String TARGET_ENTITY = "DB"; - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(DslConsumer.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DslConsumer.class); private DslQueryProcessor dslQueryProcessor; @@ -74,53 +72,74 @@ public class DslConsumer extends RESTAPI { private String basePath; private GremlinServerSingleton gremlinServerSingleton; + private final QueryVersion DEFAULT_VERSION = QueryVersion.V1; + private QueryVersion dslApiVersion = DEFAULT_VERSION; + + private XmlFormatTransformer xmlFormatTransformer; @Autowired public DslConsumer(HttpEntry traversalUriHttpEntry, DslQueryProcessor dslQueryProcessor, - SchemaVersions schemaVersions, GremlinServerSingleton gremlinServerSingleton, - @Value("${schema.uri.base.path}") String basePath) { + SchemaVersions schemaVersions, GremlinServerSingleton gremlinServerSingleton, + XmlFormatTransformer xmlFormatTransformer, + @Value("${schema.uri.base.path}") String basePath) { this.traversalUriHttpEntry = traversalUriHttpEntry; this.dslQueryProcessor = dslQueryProcessor; this.schemaVersions = schemaVersions; this.gremlinServerSingleton = gremlinServerSingleton; + this.xmlFormatTransformer = xmlFormatTransformer; this.basePath = basePath; } @PUT @Consumes({ MediaType.APPLICATION_JSON }) - @Produces({ MediaType.APPLICATION_JSON }) - public Response executeQuery(String content, @PathParam("version") String versionParam, - @PathParam("uri") @Encoded String uri, @DefaultValue("graphson") @QueryParam("format") String queryFormat, - @DefaultValue("no_op") @QueryParam("subgraph") String subgraph, @Context HttpHeaders headers, - @Context UriInfo info, @Context HttpServletRequest req, @DefaultValue("-1") @QueryParam("resultIndex") String resultIndex, @DefaultValue("-1") @QueryParam("resultSize") String resultSize) { + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public Response executeQuery(String content, + @PathParam("version") String versionParam, + @DefaultValue("graphson") @QueryParam("format") String queryFormat, + @DefaultValue("no_op") @QueryParam("subgraph") String subgraph, + @DefaultValue("all") @QueryParam("validate") String validate, + @Context HttpHeaders headers, + @Context UriInfo info, + @DefaultValue("-1") @QueryParam("resultIndex") String resultIndex, + @DefaultValue("-1") @QueryParam("resultSize") String resultSize) { return runner(TraversalConstants.AAI_TRAVERSAL_DSL_TIMEOUT_ENABLED, - TraversalConstants.AAI_TRAVERSAL_DSL_TIMEOUT_APP, TraversalConstants.AAI_TRAVERSAL_DSL_TIMEOUT_LIMIT, - headers, info, HttpMethod.PUT, new AaiCallable<Response>() { + TraversalConstants.AAI_TRAVERSAL_DSL_TIMEOUT_APP, + TraversalConstants.AAI_TRAVERSAL_DSL_TIMEOUT_LIMIT, + headers, + info, + HttpMethod.PUT, + new AaiCallable() { @Override - public Response process() { - return processExecuteQuery(content, versionParam, uri, queryFormat, subgraph, headers, info, - req, resultIndex, resultSize); + public Response process() throws Exception { + return (processExecuteQuery(content, versionParam, queryFormat, subgraph, validate, headers, info, + resultIndex, resultSize)); } - }); + } + ); } - public Response processExecuteQuery(String content, @PathParam("version") String versionParam, - @PathParam("uri") @Encoded String uri, @DefaultValue("graphson") @QueryParam("format") String queryFormat, - @DefaultValue("no_op") @QueryParam("subgraph") String subgraph, @Context HttpHeaders headers, - @Context UriInfo info, @Context HttpServletRequest req, @DefaultValue("-1") @QueryParam("resultIndex") String resultIndex, @DefaultValue("-1") @QueryParam("resultSize") String resultSize) { + public Response processExecuteQuery(String content, String versionParam, String queryFormat, String subgraph, + String validate, HttpHeaders headers, UriInfo info, String resultIndex, + String resultSize) { - String methodName = "executeDslQuery"; String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); String dslOverride = headers.getRequestHeaders().getFirst("X-DslOverride"); - String realTime = headers.getRequestHeaders().getFirst("Real-Time"); + + Optional<String> dslApiVersionHeader = Optional.ofNullable(headers.getRequestHeaders().getFirst("X-DslApiVersion")); + if (dslApiVersionHeader.isPresent()) { + try { + dslApiVersion = QueryVersion.valueOf(dslApiVersionHeader.get()); + } catch (IllegalArgumentException e) { + LOGGER.debug("Defaulting DSL Api Version to "+DEFAULT_VERSION); + } + } + Response response; SchemaVersion version = new SchemaVersion(versionParam); TransactionalGraphEngine dbEngine = null; try { - LoggingContext.save(); - DBConnectionType type = this.determineConnectionType(sourceOfTruth, realTime); - traversalUriHttpEntry.setHttpEntryProperties(version, type); + traversalUriHttpEntry.setHttpEntryProperties(version); traversalUriHttpEntry.setPaginationParameters(resultIndex, resultSize); dbEngine = traversalUriHttpEntry.getDbEngine(); JsonObject input = new JsonParser().parse(content).getAsJsonObject(); @@ -130,48 +149,83 @@ public class DslConsumer extends RESTAPI { dsl = dslElement.getAsString(); } - LoggingContext.targetEntity(TARGET_ENTITY); - LoggingContext.targetServiceName(methodName); - LoggingContext.startTime(); - StopWatch.conditionalStart(); boolean isDslOverride = dslOverride != null && !AAIConfig.get(TraversalConstants.DSL_OVERRIDE).equals("false") && dslOverride.equals(AAIConfig.get(TraversalConstants.DSL_OVERRIDE)); - if(isDslOverride) - dslQueryProcessor.setValidationFlag(false); - + if(isDslOverride) { + dslQueryProcessor.setStartNodeValidationFlag(false); + } + + dslQueryProcessor.setValidationRules(validate); + + Format format = Format.getFormat(queryFormat); + + if(isAggregate(format)){ + dslQueryProcessor.setAggregate(true); + } + + if(isHistory(format)){ + validateHistoryParams(format, info.getQueryParameters()); + } + + GraphTraversalSource traversalSource = getTraversalSource(dbEngine, format, info); + GenericQueryProcessor processor = new GenericQueryProcessor.Builder(dbEngine, gremlinServerSingleton) - .queryFrom(dsl, "dsl").queryProcessor(dslQueryProcessor).processWith(processorType).create(); - - String result = ""; + .queryFrom(dsl, "dsl").queryProcessor(dslQueryProcessor).version(dslApiVersion).processWith(processorType) + .format(format).uriParams(info.getQueryParameters()).traversalSource(isHistory(format), traversalSource).create(); + SubGraphStyle subGraphStyle = SubGraphStyle.valueOf(subgraph); List<Object> vertTemp = processor.execute(subGraphStyle); - List<Object> vertices = traversalUriHttpEntry.getPaginatedVertexList(vertTemp); + + List <Object> vertices; + if (isAggregate(format)){ + vertices = traversalUriHttpEntry.getPaginatedVertexListForAggregateFormat(vertTemp); + } else { + vertices = traversalUriHttpEntry.getPaginatedVertexList(vertTemp); + } + DBSerializer serializer = new DBSerializer(version, dbEngine, ModelType.MOXY, sourceOfTruth); - Format format = Format.getFormat(queryFormat); FormatFactory ff = new FormatFactory(traversalUriHttpEntry.getLoader(), serializer, schemaVersions, this.basePath); - - Formatter formater = ff.get(format, info.getQueryParameters()); - result = formater.output(vertices).toString(); - - double msecs = StopWatch.stopIfStarted(); - LoggingContext.elapsedTime((long) msecs, TimeUnit.MILLISECONDS); - LoggingContext.successStatusFields(); - LOGGER.info("Completed"); - + MultivaluedMap<String, String> mvm = new MultivaluedHashMap<>(); + mvm.putAll(info.getQueryParameters()); + if (isHistory(format)) { + mvm.putSingle("startTs", Long.toString(getStartTime(format, mvm))); + mvm.putSingle("endTs", Long.toString(getEndTime(mvm))); + } + Formatter formatter = ff.get(format, mvm); + + final Map<String, List<String>> propertiesMap = processor.getPropertiesMap(); + String result = ""; + if (propertiesMap != null && !propertiesMap.isEmpty()){ + result = formatter.output(vertices, propertiesMap).toString(); + } + else { + result = formatter.output(vertices).toString(); + } + + String acceptType = headers.getHeaderString("Accept"); + + if(acceptType == null){ + acceptType = MediaType.APPLICATION_JSON; + } + + if(MediaType.APPLICATION_XML_TYPE.isCompatible(MediaType.valueOf(acceptType))){ + result = xmlFormatTransformer.transform(result); + } + if(traversalUriHttpEntry.isPaginated()){ response = Response.status(Status.OK) - .type(MediaType.APPLICATION_JSON) + .type(acceptType) .header("total-results", traversalUriHttpEntry.getTotalVertices()) .header("total-pages", traversalUriHttpEntry.getTotalPaginationBuckets()) .entity(result) .build(); }else { response = Response.status(Status.OK) - .type(MediaType.APPLICATION_JSON) + .type(acceptType) .entity(result).build(); } @@ -181,8 +235,6 @@ public class DslConsumer extends RESTAPI { AAIException ex = new AAIException("AAI_4000", e); response = consumerExceptionResponseGenerator(headers, info, HttpMethod.PUT, ex); } finally { - LoggingContext.restoreIfPossible(); - LoggingContext.successStatusFields(); if (dbEngine != null) { dbEngine.rollback(); } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java b/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java index 633bc9c..d91e50d 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java @@ -19,38 +19,16 @@ */ package org.onap.aai.rest; -import java.net.URI; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.Encoded; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; - +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.onap.aai.concurrent.AaiCallable; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.ModelType; import org.onap.aai.logging.ErrorLogHelper; + import org.onap.aai.parsers.query.QueryParser; import org.onap.aai.rest.db.HttpEntry; import org.onap.aai.rest.search.CustomQueryConfig; @@ -58,7 +36,6 @@ import org.onap.aai.rest.search.GenericQueryProcessor; import org.onap.aai.rest.search.GremlinServerSingleton; import org.onap.aai.rest.search.QueryProcessorType; import org.onap.aai.restcore.HttpMethod; -import org.onap.aai.restcore.RESTAPI; import org.onap.aai.restcore.util.URITools; import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.engines.QueryStyle; @@ -67,33 +44,28 @@ import org.onap.aai.serialization.queryformats.Format; import org.onap.aai.serialization.queryformats.FormatFactory; import org.onap.aai.serialization.queryformats.Formatter; import org.onap.aai.serialization.queryformats.SubGraphStyle; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.aai.logging.LoggingContext; -import org.onap.aai.logging.StopWatch; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; -import org.onap.aai.util.AAIConstants; +import org.onap.aai.transforms.XmlFormatTransformer; import org.onap.aai.util.TraversalConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import javax.ws.rs.*; +import javax.ws.rs.core.*; +import javax.ws.rs.core.Response.Status; +import java.net.URI; +import java.util.*; +import java.util.stream.Collectors; + @Path("{version: v[1-9][0-9]*|latest}/query") -public class QueryConsumer extends RESTAPI { - - /** The introspector factory type. */ - private ModelType introspectorFactoryType = ModelType.MOXY; - +public class QueryConsumer extends TraversalConsumer { + private QueryProcessorType processorType = QueryProcessorType.LOCAL_GROOVY; - /** The query style. */ - private QueryStyle queryStyle = QueryStyle.TRAVERSAL; - - private static final String TARGET_ENTITY = "DB"; - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(QueryConsumer.class); + + private static final Logger LOGGER = LoggerFactory.getLogger(QueryConsumer.class); private HttpEntry traversalUriHttpEntry; @@ -104,23 +76,29 @@ public class QueryConsumer extends RESTAPI { private GremlinServerSingleton gremlinServerSingleton; + private XmlFormatTransformer xmlFormatTransformer; + @Autowired - public QueryConsumer( - HttpEntry traversalUriHttpEntry, - SchemaVersions schemaVersions, - GremlinServerSingleton gremlinServerSingleton, - @Value("${schema.uri.base.path}") String basePath - ){ + public QueryConsumer(HttpEntry traversalUriHttpEntry, SchemaVersions schemaVersions, + GremlinServerSingleton gremlinServerSingleton, XmlFormatTransformer xmlFormatTransformer, @Value("${schema.uri.base.path}") String basePath) { this.traversalUriHttpEntry = traversalUriHttpEntry; this.schemaVersions = schemaVersions; this.gremlinServerSingleton = gremlinServerSingleton; this.basePath = basePath; + this.xmlFormatTransformer = xmlFormatTransformer; } @PUT @Consumes({ MediaType.APPLICATION_JSON}) - @Produces({ MediaType.APPLICATION_JSON}) - public Response executeQuery(String content, @PathParam("version")String versionParam, @PathParam("uri") @Encoded String uri, @DefaultValue("graphson") @QueryParam("format") String queryFormat,@DefaultValue("no_op") @QueryParam("subgraph") String subgraph, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req, @DefaultValue("-1") @QueryParam("resultIndex") String resultIndex, @DefaultValue("-1") @QueryParam("resultSize") String resultSize){ + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public Response executeQuery(String content, + @PathParam("version") String versionParam, + @DefaultValue("graphson") @QueryParam("format") String queryFormat, + @DefaultValue("no_op") @QueryParam("subgraph") String subgraph, + @Context HttpHeaders headers, + @Context UriInfo info, + @DefaultValue("-1") @QueryParam("resultIndex") String resultIndex, + @DefaultValue("-1") @QueryParam("resultSize") String resultSize) { return runner(TraversalConstants.AAI_TRAVERSAL_TIMEOUT_ENABLED, TraversalConstants.AAI_TRAVERSAL_TIMEOUT_APP, TraversalConstants.AAI_TRAVERSAL_TIMEOUT_LIMIT, @@ -128,34 +106,33 @@ public class QueryConsumer extends RESTAPI { info, HttpMethod.GET, new AaiCallable<Response>() { - @Override - public Response process() { - return processExecuteQuery(content, versionParam, uri, queryFormat, subgraph, headers, info, req, resultIndex, resultSize); - } - } - ); + @Override + public Response process() { + return processExecuteQuery(content, versionParam, queryFormat, subgraph, headers, info, resultIndex, resultSize); + } + }); } - public Response processExecuteQuery(String content, @PathParam("version")String versionParam, @PathParam("uri") @Encoded String uri, @DefaultValue("graphson") @QueryParam("format") String queryFormat,@DefaultValue("no_op") @QueryParam("subgraph") String subgraph, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req, @DefaultValue("-1") @QueryParam("resultIndex") String resultIndex, @DefaultValue("-1") @QueryParam("resultSize") String resultSize) { - String methodName = "executeQuery"; + public Response processExecuteQuery(String content, String versionParam, String queryFormat, String subgraph, + HttpHeaders headers, UriInfo info, String resultIndex, + String resultSize) { + String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); - String realTime = headers.getRequestHeaders().getFirst("Real-Time"); String queryProcessor = headers.getRequestHeaders().getFirst("QueryProcessor"); QueryProcessorType processorType = this.processorType; - Response response = null; + Response response; TransactionalGraphEngine dbEngine = null; + try { - LoggingContext.save(); this.checkQueryParams(info.getQueryParameters()); Format format = Format.getFormat(queryFormat); if (queryProcessor != null) { processorType = QueryProcessorType.valueOf(queryProcessor); } SubGraphStyle subGraphStyle = SubGraphStyle.valueOf(subgraph); + JsonParser parser = new JsonParser(); - JsonObject input = parser.parse(content).getAsJsonObject(); - JsonElement startElement = input.get("start"); JsonElement queryElement = input.get("query"); JsonElement gremlinElement = input.get("gremlin"); @@ -164,8 +141,7 @@ public class QueryConsumer extends RESTAPI { String gremlin = ""; SchemaVersion version = new SchemaVersion(versionParam); - DBConnectionType type = this.determineConnectionType(sourceOfTruth, realTime); - traversalUriHttpEntry.setHttpEntryProperties(version, type); + traversalUriHttpEntry.setHttpEntryProperties(version); /* * Changes for Pagination */ @@ -196,76 +172,87 @@ public class QueryConsumer extends RESTAPI { List<String> missingRequiredQueryParameters = checkForMissingQueryParameters( customQueryConfig.getQueryRequiredProperties(), URITools.getQueryMap(queryURIObj)); if ( !missingRequiredQueryParameters.isEmpty() ) { - return( createMessageMissingQueryRequiredParameters( missingRequiredQueryParameters, headers, info, req)); + return( createMessageMissingQueryRequiredParameters( missingRequiredQueryParameters, headers)); } List<String> invalidQueryParameters = checkForInvalidQueryParameters( customQueryConfig, URITools.getQueryMap(queryURIObj)); if ( !invalidQueryParameters.isEmpty() ) { - return( createMessageInvalidQueryParameters( invalidQueryParameters, headers, info, req)); + return( createMessageInvalidQueryParameters( invalidQueryParameters, headers)); } } else if ( queryElement != null ) { - return( createMessageInvalidQuerySection( queryURI, headers, info, req)); + return (createMessageInvalidQuerySection(queryURI, headers)); } - - GenericQueryProcessor processor = null; - - LoggingContext.targetEntity(TARGET_ENTITY); - LoggingContext.targetServiceName(methodName); - LoggingContext.startTime(); - StopWatch.conditionalStart(); + GenericQueryProcessor processor; + + if(isHistory(format)){ + validateHistoryParams(format, info.getQueryParameters()); + } + GraphTraversalSource traversalSource = getTraversalSource(dbEngine, format, info); + QueryStyle queryStyle = getQueryStyle(format, traversalUriHttpEntry); if (!startURIs.isEmpty()) { Set<Vertex> vertexSet = new LinkedHashSet<>(); QueryParser uriQuery; List<Vertex> vertices; for (URI startUri : startURIs) { - uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(startUri, URITools.getQueryMap(startUri)); + uriQuery = dbEngine.getQueryBuilder(queryStyle, traversalSource).createQueryFromURI(startUri, URITools.getQueryMap(startUri)); vertices = uriQuery.getQueryBuilder().toList(); vertexSet.addAll(vertices); } - processor = new GenericQueryProcessor.Builder(dbEngine, gremlinServerSingleton) - .startFrom(vertexSet).queryFrom(queryURIObj) - .processWith(processorType).create(); + .startFrom(vertexSet).queryFrom(queryURIObj).format(format) + .processWith(processorType).traversalSource(isHistory(format), traversalSource).create(); } else if (!queryURI.equals("")){ processor = new GenericQueryProcessor.Builder(dbEngine, gremlinServerSingleton) .queryFrom(queryURIObj) - .processWith(processorType).create(); + .processWith(processorType).traversalSource(isHistory(format), traversalSource).create(); } else { processor = new GenericQueryProcessor.Builder(dbEngine, gremlinServerSingleton) .queryFrom(gremlin, "gremlin") - .processWith(processorType).create(); + .processWith(processorType).traversalSource(isHistory(format), traversalSource).create(); } - String result = ""; List<Object> vertTemp = processor.execute(subGraphStyle); List<Object> vertices = traversalUriHttpEntry.getPaginatedVertexList(vertTemp); - - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, sourceOfTruth); + + DBSerializer serializer = new DBSerializer(version, dbEngine, ModelType.MOXY, sourceOfTruth); FormatFactory ff = new FormatFactory(traversalUriHttpEntry.getLoader(), serializer, schemaVersions, this.basePath); - - Formatter formater = ff.get(format, info.getQueryParameters()); - - result = formater.output(vertices).toString(); - double msecs = StopWatch.stopIfStarted(); - LoggingContext.elapsedTime((long)msecs,TimeUnit.MILLISECONDS); - LoggingContext.successStatusFields(); - LOGGER.info ("Completed"); - + MultivaluedMap<String, String> mvm = new MultivaluedHashMap<>(); + mvm.putAll(info.getQueryParameters()); + if (isHistory(format)) { + mvm.putSingle("startTs", Long.toString(getStartTime(format, mvm))); + mvm.putSingle("endTs", Long.toString(getEndTime(mvm))); + } + Formatter formatter = ff.get(format, mvm); + + String result = formatter.output(vertices).toString(); + + //LOGGER.info ("Completed"); + + String acceptType = headers.getHeaderString("Accept"); + + if(acceptType == null){ + acceptType = MediaType.APPLICATION_JSON; + } + + if(MediaType.APPLICATION_XML_TYPE.isCompatible(MediaType.valueOf(acceptType))){ + result = xmlFormatTransformer.transform(result); + } + if(traversalUriHttpEntry.isPaginated()){ response = Response.status(Status.OK) - .type(MediaType.APPLICATION_JSON) + .type(acceptType) .header("total-results", traversalUriHttpEntry.getTotalVertices()) .header("total-pages", traversalUriHttpEntry.getTotalPaginationBuckets()) .entity(result) .build(); }else { response = Response.status(Status.OK) - .type(MediaType.APPLICATION_JSON) + .type(acceptType) .entity(result).build(); } } catch (AAIException e) { @@ -274,8 +261,6 @@ public class QueryConsumer extends RESTAPI { AAIException ex = new AAIException("AAI_4000", e); response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, ex); } finally { - LoggingContext.restoreIfPossible(); - LoggingContext.successStatusFields(); if (dbEngine != null) { dbEngine.rollback(); } @@ -289,7 +274,7 @@ public class QueryConsumer extends RESTAPI { if (params.containsKey("depth") && params.getFirst("depth").matches("\\d+")) { String depth = params.getFirst("depth"); - Integer i = Integer.parseInt(depth); + int i = Integer.parseInt(depth); if (i > 1) { throw new AAIException("AAI_3303"); } @@ -310,8 +295,6 @@ public class QueryConsumer extends RESTAPI { } private CustomQueryConfig getCustomQueryConfig(URI uriObj ) { - - CustomQueryConfig customQueryConfig; String path = uriObj.getPath(); String[] parts = path.split("/"); @@ -329,77 +312,61 @@ public class QueryConsumer extends RESTAPI { } - private Response createMessageMissingQueryRequiredParameters(List<String> missingRequiredQueryParams, HttpHeaders headers, UriInfo info, HttpServletRequest req) { + private Response createMessageMissingQueryRequiredParameters(List<String> missingRequiredQueryParams, HttpHeaders headers) { AAIException e = new AAIException("AAI_3013"); ArrayList<String> templateVars = new ArrayList<>(); + templateVars.add(missingRequiredQueryParams.toString()); - if (templateVars.isEmpty()) { - templateVars.add(missingRequiredQueryParams.toString()); - } - - Response response = Response + return Response .status(e.getErrorObject().getHTTPResponseCode()) .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars)).build(); - - return response; - } + } - private Response createMessageInvalidQuerySection(String invalidQuery, HttpHeaders headers, UriInfo info, HttpServletRequest req) { + private Response createMessageInvalidQuerySection(String invalidQuery, HttpHeaders headers) { AAIException e = new AAIException("AAI_3014"); ArrayList<String> templateVars = new ArrayList<>(); + templateVars.add(invalidQuery); - if (templateVars.isEmpty()) { - templateVars.add(invalidQuery); - } - - Response response = Response + return Response .status(e.getErrorObject().getHTTPResponseCode()) .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars)).build(); - - return response; - } + } - public List<String> checkForInvalidQueryParameters( CustomQueryConfig customQueryConfig, MultivaluedMap<String, String> queryParams) { + private List<String> checkForInvalidQueryParameters( CustomQueryConfig customQueryConfig, MultivaluedMap<String, String> queryParams) { - List<String> allParameters = new ArrayList<String>(); + List<String> allParameters = new ArrayList<>(); /* * Add potential Required and Optional to allParameters */ Optional.ofNullable(customQueryConfig.getQueryOptionalProperties()).ifPresent(allParameters::addAll); Optional.ofNullable(customQueryConfig.getQueryRequiredProperties()).ifPresent(allParameters::addAll); - if(queryParams.isEmpty()) + if(queryParams.isEmpty()) { return new ArrayList<>(); - List<String> invalidParameters = queryParams.keySet().stream() - .filter(param -> !allParameters.contains(param)) - .collect(Collectors.toList()); - - return invalidParameters; - + } + return queryParams.keySet().stream() + .filter(param -> !allParameters.contains(param)) + .collect(Collectors.toList()); } - private Response createMessageInvalidQueryParameters(List<String> invalidQueryParams, HttpHeaders headers, UriInfo info, HttpServletRequest req) { + private Response createMessageInvalidQueryParameters(List<String> invalidQueryParams, HttpHeaders headers) { AAIException e = new AAIException("AAI_3022"); ArrayList<String> templateVars = new ArrayList<>(); + templateVars.add(invalidQueryParams.toString()); - if (templateVars.isEmpty()) { - templateVars.add(invalidQueryParams.toString()); - } - - Response response = Response + return Response .status(e.getErrorObject().getHTTPResponseCode()) - .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, + .entity(ErrorLogHelper.getRESTAPIErrorResponse( + headers.getAcceptableMediaTypes(), + e, templateVars)).build(); - return response; - } - - + } } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/RecentAPIConsumer.java b/aai-traversal/src/main/java/org/onap/aai/rest/RecentAPIConsumer.java index 3154087..2e43e5b 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/RecentAPIConsumer.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/RecentAPIConsumer.java @@ -19,34 +19,12 @@ */ package org.onap.aai.rest; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; - import org.onap.aai.concurrent.AaiCallable; -import org.onap.aai.dbmap.DBConnectionType; - import org.onap.aai.exceptions.AAIException; -import org.onap.aai.introspection.Introspector; import org.onap.aai.introspection.ModelType; import org.onap.aai.introspection.exceptions.AAIUnknownObjectException; -import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.setup.SchemaVersions; + import org.onap.aai.rest.db.HttpEntry; -import org.onap.aai.rest.dsl.DslQueryProcessor; import org.onap.aai.rest.search.GenericQueryProcessor; import org.onap.aai.rest.search.GremlinServerSingleton; import org.onap.aai.rest.search.QueryProcessorType; @@ -58,16 +36,22 @@ import org.onap.aai.serialization.queryformats.Format; import org.onap.aai.serialization.queryformats.FormatFactory; import org.onap.aai.serialization.queryformats.Formatter; import org.onap.aai.serialization.queryformats.SubGraphStyle; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.aai.logging.LoggingContext; -import org.onap.aai.logging.StopWatch; - +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.transforms.XmlFormatTransformer; import org.onap.aai.util.AAIConstants; import org.onap.aai.util.TraversalConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import javax.ws.rs.*; +import javax.ws.rs.core.*; +import javax.ws.rs.core.Response.Status; +import java.util.List; +import java.util.concurrent.TimeUnit; + @Path("/recents/{version: v[1-9][0-9]*|latest}") public class RecentAPIConsumer extends RESTAPI { @@ -77,39 +61,38 @@ public class RecentAPIConsumer extends RESTAPI { private QueryProcessorType processorType = QueryProcessorType.LOCAL_GROOVY; /** The query style. */ - private static final String TARGET_ENTITY = "DB"; - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(RecentAPIConsumer.class); + private static final Logger LOGGER = LoggerFactory.getLogger(RecentAPIConsumer.class); private HttpEntry traversalUriHttpEntry; - private DslQueryProcessor dslQueryProcessor; - private SchemaVersions schemaVersions; private String basePath; private GremlinServerSingleton gremlinServerSingleton; + private XmlFormatTransformer xmlFormatTransformer; + @Autowired public RecentAPIConsumer( HttpEntry traversalUriHttpEntry, - DslQueryProcessor dslQueryProcessor, SchemaVersions schemaVersions, GremlinServerSingleton gremlinServerSingleton, + XmlFormatTransformer xmlFormatTransformer, @Value("${schema.uri.base.path}") String basePath ){ this.traversalUriHttpEntry = traversalUriHttpEntry; - this.dslQueryProcessor = dslQueryProcessor; this.schemaVersions = schemaVersions; this.gremlinServerSingleton = gremlinServerSingleton; + this.xmlFormatTransformer = xmlFormatTransformer; this.basePath = basePath; } @GET @Path("/{nodeType: .+}") @Consumes({ MediaType.APPLICATION_JSON }) - @Produces({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response getRecentData(String content, @PathParam("version") String versionParam, @PathParam("nodeType") String nodeType, @Context HttpHeaders headers, @Context UriInfo info) { @@ -126,15 +109,12 @@ public class RecentAPIConsumer extends RESTAPI { public Response processRecentData(String content, @PathParam("version") String versionParam, @PathParam("nodeType") String nodeType, @Context UriInfo info, @Context HttpHeaders headers) { - String methodName = "processRecentData"; String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); - String realTime = headers.getRequestHeaders().getFirst("Real-Time"); String queryProcessor = headers.getRequestHeaders().getFirst("QueryProcessor"); QueryProcessorType processorType = this.processorType; - Response response = null; + Response response; TransactionalGraphEngine dbEngine = null; try { - LoggingContext.save(); if (queryProcessor != null) { processorType = QueryProcessorType.valueOf(queryProcessor); @@ -143,8 +123,7 @@ public class RecentAPIConsumer extends RESTAPI { SchemaVersion version = new SchemaVersion(versionParam); this.checkVersion(version); - DBConnectionType type = this.determineConnectionType(sourceOfTruth, realTime); - traversalUriHttpEntry.setHttpEntryProperties(version, type); + traversalUriHttpEntry.setHttpEntryProperties(version); dbEngine = traversalUriHttpEntry.getDbEngine(); /* @@ -156,10 +135,7 @@ public class RecentAPIConsumer extends RESTAPI { GenericQueryProcessor processor = null; - LoggingContext.targetEntity(TARGET_ENTITY); - LoggingContext.targetServiceName(methodName); - LoggingContext.startTime(); - StopWatch.conditionalStart(); + processor = new GenericQueryProcessor.Builder(dbEngine, gremlinServerSingleton).queryFrom(nodeType, "nodeQuery") .uriParams(info.getQueryParameters()) @@ -179,12 +155,19 @@ public class RecentAPIConsumer extends RESTAPI { result = formater.output(vertices).toString(); - double msecs = StopWatch.stopIfStarted(); - LoggingContext.elapsedTime((long) msecs, TimeUnit.MILLISECONDS); - LoggingContext.successStatusFields(); - LOGGER.info("Completed"); + //LOGGER.info("Completed"); + + String acceptType = headers.getHeaderString("Accept"); + + if(acceptType == null){ + acceptType = MediaType.APPLICATION_JSON; + } + + if(MediaType.APPLICATION_XML_TYPE.isCompatible(MediaType.valueOf(acceptType))){ + result = xmlFormatTransformer.transform(result); + } - response = Response.status(Status.OK).type(MediaType.APPLICATION_JSON).entity(result).build(); + response = Response.status(Status.OK).type(acceptType).entity(result).build(); } catch (AAIException e) { response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, e); @@ -193,8 +176,6 @@ public class RecentAPIConsumer extends RESTAPI { response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, ex); } finally { - LoggingContext.restoreIfPossible(); - LoggingContext.successStatusFields(); if (dbEngine != null) { dbEngine.rollback(); } @@ -212,7 +193,7 @@ public class RecentAPIConsumer extends RESTAPI { public void checkNodeType(String nodeType) throws AAIException { try { - Introspector target = traversalUriHttpEntry.getLoader().introspectorFromName(nodeType); + traversalUriHttpEntry.getLoader().introspectorFromName(nodeType); } catch (AAIUnknownObjectException e) { throw new AAIException("AAI_6115", "Unrecognized nodeType [" + nodeType + "] passed to recents query."); } @@ -224,7 +205,7 @@ public class RecentAPIConsumer extends RESTAPI { if (params != null && params.containsKey("hours") && params.getFirst("hours").matches("-?\\d+")) { isHoursParameter = true; - Long hours = 0L; + long hours; try{ hours = Long.parseLong(params.getFirst("hours")); } @@ -238,7 +219,7 @@ public class RecentAPIConsumer extends RESTAPI { if (params != null && params.containsKey("date-time") && params.getFirst("date-time").matches("-?\\d+")) { isDateTimeParameter = true; Long minStartTime = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(AAIConstants.HISTORY_MAX_HOURS); - Long startTime = 0L; + Long startTime; try{ startTime = Long.parseLong(params.getFirst("date-time")); } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/TraversalConsumer.java b/aai-traversal/src/main/java/org/onap/aai/rest/TraversalConsumer.java new file mode 100644 index 0000000..4aa0888 --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/rest/TraversalConsumer.java @@ -0,0 +1,232 @@ +/** + * ============LICENSE_START================================================== + * org.onap.aai + * =========================================================================== + * Copyright © 2017-2020 AT&T Intellectual Property. 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==================================================== + */ +package org.onap.aai.rest; + +import org.apache.tinkerpop.gremlin.process.traversal.P; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy; +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.db.props.AAIProperties; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.rest.db.HttpEntry; +import org.onap.aai.restcore.RESTAPI; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; +import org.onap.aai.serialization.queryformats.Format; + +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.UriInfo; +import java.util.concurrent.TimeUnit; + +public abstract class TraversalConsumer extends RESTAPI { + + private static final String HISTORICAL_FORMAT = "state,lifecycle"; + private final boolean historyEnabled; + private final int historyTruncateWindow; + private final long currentTime = System.currentTimeMillis(); + private Long startTime = null; + private Long endTime = null; + private Long furthestInThePast = null; + + public TraversalConsumer() { + this.historyTruncateWindow = Integer.parseInt( + SpringContextAware.getApplicationContext().getEnvironment().getProperty("history.truncate.window.days", "365")); + this.historyEnabled = Boolean.parseBoolean( + SpringContextAware.getApplicationContext().getEnvironment().getProperty("history.enabled", "false")); + } + + public boolean isHistory(Format queryFormat) { + return isHistoryEnabled() && HISTORICAL_FORMAT.contains(queryFormat.toString()); + } + + public boolean isAggregate(Format queryFormat) { + return Format.aggregate.equals(queryFormat); + } + + public boolean isHistoryEnabled() { + return historyEnabled; + } + + protected SubgraphStrategy getSubgraphStrategy(long startTs, long endTs, Format format) { + + if (Format.state.equals(format)) { + return getStateSubgraphStrategy(startTs); + } else if (Format.lifecycle.equals(format)) { + return getLifeCycleSubgraphStrategy(startTs, endTs); + } else { + return SubgraphStrategy.build() + .vertices(__.has(AAIProperties.START_TS, P.gte(startTs))) + .vertexProperties(__.has(AAIProperties.START_TS, P.gte(startTs))) + .edges(__.has(AAIProperties.START_TS, P.gte(startTs))).create(); + } + } + + private SubgraphStrategy getLifeCycleSubgraphStrategy(long startTs, long endTs) { + return SubgraphStrategy.build() + .vertices( + __.not( + __.or( + __.and( + __.has(AAIProperties.START_TS, P.gt(startTs)), + __.has(AAIProperties.START_TS, P.gt(endTs)) + ), + __.and( + __.has(AAIProperties.END_TS).has(AAIProperties.END_TS, P.lt(startTs)), + __.has(AAIProperties.END_TS).has(AAIProperties.END_TS, P.lt(endTs)) + ) + ) + ) + ).vertexProperties( + __.not( + __.or( + __.and( + __.has(AAIProperties.START_TS, P.gt(startTs)), + __.has(AAIProperties.START_TS, P.gt(endTs)) + ), + __.and( + __.has(AAIProperties.END_TS).has(AAIProperties.END_TS, P.lt(startTs)), + __.has(AAIProperties.END_TS).has(AAIProperties.END_TS, P.lt(endTs)) + ) + ) + ) + ).edges( + __.not( + __.or( + __.and( + __.has(AAIProperties.START_TS, P.gt(startTs)), + __.has(AAIProperties.START_TS, P.gt(endTs)) + ), + __.and( + __.has(AAIProperties.END_TS).has(AAIProperties.END_TS, P.lt(startTs)), + __.has(AAIProperties.END_TS).has(AAIProperties.END_TS, P.lt(endTs)) + ) + ) + ) + ).create(); + } + + private SubgraphStrategy getStateSubgraphStrategy(long startTs) { + return SubgraphStrategy.build() + .vertices( + __.and(__.has(AAIProperties.START_TS, P.lte(startTs)), + __.or(__.hasNot(AAIProperties.END_TS), __.has(AAIProperties.END_TS, P.gt(startTs)))) + ).vertexProperties( + __.and(__.has(AAIProperties.START_TS, P.lte(startTs)), + __.or(__.hasNot(AAIProperties.END_TS), __.has(AAIProperties.END_TS, P.gt(startTs)))) + ).edges( + __.and(__.has(AAIProperties.START_TS, P.lte(startTs)), + __.or(__.hasNot(AAIProperties.END_TS), __.has(AAIProperties.END_TS, P.gt(startTs)))) + ).create(); + } + + + + protected GraphTraversalSource getTraversalSource(TransactionalGraphEngine dbEngine, Format format, UriInfo info) throws AAIException { + if (isHistory(format)) { + long startTime = this.getStartTime(format, info.getQueryParameters()); + long endTime = this.getEndTime(info.getQueryParameters()); + return dbEngine.asAdmin().getTraversalSource().withStrategies(getSubgraphStrategy(startTime, endTime, format)); + } + return dbEngine.asAdmin().getTraversalSource(); + } + + protected void validateHistoryParams(Format format, MultivaluedMap<String, String> params) throws AAIException { + getStartTime(format, params); + getEndTime(params); + } + + /** + * If a request comes in for information prior to our truncation timeframe, throw an error. + * In the changes api, we never return change timestamps prior to the truncation timeframe. + * In the lifecycle api, we should treat a call with no timestamp as a lifecycle since call with a timestamp of the truncation time + * in the lifecycle api, we should return an error if the timestamp provided is prior to the truncation time + * In the state api, we should return an error if the timestamp provided is prior to the truncation time + * @param params + * @return + */ + protected long getStartTime(Format format, MultivaluedMap<String, String> params) throws AAIException { + + if (startTime != null) { + return startTime; + } + + String startTs = params.getFirst("startTs") ; + + if (Format.state.equals(format)) { + if (startTs == null || startTs.isEmpty() || "-1".equals(startTs) || "now".equals(startTs)) { + startTime = currentTime; + } else { + startTime = Long.valueOf(startTs); + verifyTimeAgainstTruncationTime(startTime); + } + } else if (Format.lifecycle.equals(format)) { + if("now".equals(startTs)) { + startTime = currentTime; + } else if (startTs == null || startTs.isEmpty()|| "-1".equals(startTs)) { + startTime = getFurthestInThePast(); + } else { + startTime = Long.valueOf(startTs); + verifyTimeAgainstTruncationTime(startTime); + } + } + + return startTime; + + } + + private void verifyTimeAgainstTruncationTime(long timestamp) throws AAIException { + if (timestamp < getFurthestInThePast()) { + throw new AAIException("AAI_4019"); + } + } + + protected long getEndTime(MultivaluedMap<String, String> params) throws AAIException { + if (endTime != null) { + return endTime; + } + + String endTs = params.getFirst("endTs") ; + + if (endTs == null || endTs.isEmpty() || "-1".equals(endTs) || "now".equals(endTs)) { + endTime = currentTime; + } else { + endTime = Long.valueOf(endTs); + verifyTimeAgainstTruncationTime(endTime); + } + + return endTime; + } + + protected Long getFurthestInThePast() { + if (furthestInThePast == null) { + furthestInThePast = currentTime - TimeUnit.DAYS.toMillis(historyTruncateWindow); + } + return furthestInThePast; + } + + protected QueryStyle getQueryStyle(Format format, HttpEntry traversalUriHttpEntry) { + if (isHistory(format)) { + return QueryStyle.HISTORY_TRAVERSAL; + } + return traversalUriHttpEntry.getQueryStyle(); + } + +} diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslContext.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslContext.java index 9ffa69b..cf7f51d 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslContext.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslContext.java @@ -19,13 +19,13 @@ */ package org.onap.aai.rest.dsl; +import org.antlr.v4.runtime.ParserRuleContext; + import java.util.ArrayList; import java.util.Deque; import java.util.LinkedList; import java.util.List; -import org.antlr.v4.runtime.ParserRuleContext; - public class DslContext { private ParserRuleContext ctx; @@ -33,7 +33,7 @@ public class DslContext { private boolean validationFlag = true; private boolean isStartNode = false; private String startNode = ""; - private List<String> startNodeKeys = new ArrayList<String>(); + private List<String> startNodeKeys = new ArrayList<>(); private String currentNode; private String previousNode; @@ -45,13 +45,13 @@ public class DslContext { private String whereStartNode = ""; - private Deque<String> unionStartNodes = new LinkedList<String>(); + private Deque<String> unionStartNodes = new LinkedList<>(); /* * Limit Queries have to be applied in the end - so i have to set this in * context */ - StringBuilder limitQuery = new StringBuilder(); + public StringBuilder limitQuery = new StringBuilder(); public ParserRuleContext getCtx() { return ctx; diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryBuilder.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryBuilder.java index 6817cf7..3d324ad 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryBuilder.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryBuilder.java @@ -19,21 +19,26 @@ */ package org.onap.aai.rest.dsl; -import com.google.common.base.Joiner; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.edges.EdgeRule; import org.onap.aai.edges.EdgeRuleQuery; +import org.onap.aai.edges.enums.AAIDirection; import org.onap.aai.edges.enums.EdgeType; import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; import org.onap.aai.introspection.Introspector; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.exceptions.AAIUnknownObjectException; import org.onap.aai.schema.enums.PropertyMetadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.StringUtils; import java.util.List; import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; public class DslQueryBuilder { @@ -43,6 +48,8 @@ public class DslQueryBuilder { private StringBuilder query; private StringBuilder queryException; + private static final Logger LOGGER = LoggerFactory.getLogger(DslQueryBuilder.class); + public DslQueryBuilder(EdgeIngestor edgeIngestor, Loader loader) { this.edgeRules = edgeIngestor; this.loader = loader; @@ -74,6 +81,19 @@ public class DslQueryBuilder { /* * DSL always dedupes the results */ + public DslQueryBuilder end(long selectCounter) { + if(selectCounter <= 0) { + return this.end(); + } else { + String selectStep = "step" + selectCounter; + query.append(".as('").append(selectStep).append("')").append(".as('stepMain')" + + ".select('").append(selectStep).append("')").append(".store('x')").append(".select('stepMain').fold().dedup()"); + } + return this; + } + + + public DslQueryBuilder end() { query.append(".cap('x').unfold().dedup()"); return this; @@ -85,6 +105,21 @@ public class DslQueryBuilder { } public DslQueryBuilder edgeQuery(List<String> edgeLabels, String aNode, String bNode) { + EdgeRuleQuery.Builder baseQ = new EdgeRuleQuery.Builder(aNode, bNode); + return edgeQueryWithBuilder(edgeLabels, aNode, bNode, baseQ); + } + + public DslQueryBuilder edgeQuery(Edge edge, String aNode, String bNode) { + List<String> edgeLabels = edge.getLabels().stream().map(edgeLabel -> StringUtils.quote(edgeLabel.getLabel())).collect(Collectors.toList()); + EdgeRuleQuery.Builder baseQ = new EdgeRuleQuery.Builder(aNode, bNode); + + if((AAIDirection.valueOf(edge.getDirection().name())) != AAIDirection.BOTH) { + baseQ = baseQ.direction(AAIDirection.valueOf(edge.getDirection().name())); + } + return edgeQueryWithBuilder(edgeLabels, aNode, bNode, baseQ); + } + + private DslQueryBuilder edgeQueryWithBuilder(List<String> edgeLabels, String aNode, String bNode, EdgeRuleQuery.Builder edgeBuilder) { //TODO : change this for fuzzy search. String edgeType = ""; @@ -94,48 +129,42 @@ public class DslQueryBuilder { if (!edgeLabels.isEmpty()) { edgeTraversalClause = ".createEdgeTraversalWithLabels("; - edgeLabelsClause = String.join("", ", new ArrayList<>(Arrays.asList(", Joiner.on(",").join(edgeLabels), "))"); + edgeLabelsClause = String.join("", ", new ArrayList<>(Arrays.asList(", String.join(",", edgeLabels), "))"); } + LOGGER.debug("EdgeLabels Clause: {}", edgeLabelsClause); - EdgeRuleQuery.Builder baseQ = new EdgeRuleQuery.Builder(aNode, bNode); Multimap<String, EdgeRule> rules = ArrayListMultimap.create(); try { - //TODO chnage this - ugly if (edgeLabels.isEmpty()) { - rules.putAll(edgeRules.getRules(baseQ.build())); + rules.putAll(edgeRules.getRules(edgeBuilder.build())); } else { - edgeLabels.stream().forEach(label -> { + edgeLabels.forEach(label -> { try { - rules.putAll(edgeRules.getRules(baseQ.label(label).build())); + rules.putAll(edgeRules.getRules(edgeBuilder.label(label).build())); } catch (EdgeRuleNotFoundException e) { - queryException.append("AAI_6120" + "No EdgeRule found for passed nodeTypes: " + aNode - + ", " + bNode + label); - + queryException.append("Exception while finding the edge rule between the nodeTypes: ").append(aNode).append(", ").append(bNode).append(label); } }); } } catch (EdgeRuleNotFoundException e) { if (!edgeLabels.isEmpty()) { - queryException.append("AAI_6120" + "No EdgeRule found for passed nodeTypes: " + aNode - + ", " + bNode + edgeLabels.stream().toString()); + queryException.append("- No EdgeRule found for passed nodeTypes: ").append(aNode).append(", ").append(bNode).append(edgeLabels.stream().toString()); } else { - queryException.append("AAI_6120" + "No EdgeRule found for passed nodeTypes: " + aNode - + ", " + bNode); + queryException.append("- No EdgeRule found for passed nodeTypes: ").append(aNode).append(", ").append(bNode); } return this; } if (rules.isEmpty() || rules.keys().isEmpty()) { - queryException.append("AAI_6120" + "No EdgeRule found for passed nodeTypes: " + aNode - + ", " + bNode); + queryException.append("- No EdgeRule found for passed nodeTypes: ").append(aNode).append(", ").append(bNode); } else { if (edgeLabels.isEmpty()) { - if (edgeRules.hasRule(baseQ.edgeType(EdgeType.TREE).build())) { + if (edgeRules.hasRule(edgeBuilder.edgeType(EdgeType.TREE).build())) { edgeType = "EdgeType.TREE" + ","; } - if (edgeRules.hasRule(baseQ.edgeType(EdgeType.COUSIN).build())) { + if (edgeRules.hasRule(edgeBuilder.edgeType(EdgeType.COUSIN).build())) { if (edgeType.isEmpty()) { edgeType = "EdgeType.COUSIN" + ","; } else { @@ -152,13 +181,19 @@ public class DslQueryBuilder { } - public DslQueryBuilder where() { + public DslQueryBuilder where(boolean isNot) { query.append(".where("); + if(isNot){ + query.append("builder.newInstance().not("); + } return this; } - public DslQueryBuilder endWhere() { + public DslQueryBuilder endWhere(boolean isNot) { query.append(")"); + if(isNot){ + query.append(")"); + } return this; } @@ -168,12 +203,14 @@ public class DslQueryBuilder { } public DslQueryBuilder filter(boolean isNot, String node, String key, List<String> values) { - return this.filterPropertyStart(isNot).filterPropertyKeys(node, key, values).filterPropertyEnd(); + return this.filterPropertyStart(isNot,values).filterPropertyKeys(node, key, values).filterPropertyEnd(); } - public DslQueryBuilder filterPropertyStart(boolean isNot) { + public DslQueryBuilder filterPropertyStart(boolean isNot, List<String> values) { if (isNot) { query.append(".getVerticesExcludeByProperty("); + } else if(values!= null && !values.isEmpty() && Boolean.parseBoolean(values.get(0))) { + query.append(".getVerticesByBooleanProperty("); } else { query.append(".getVerticesByProperty("); } @@ -188,46 +225,63 @@ public class DslQueryBuilder { public DslQueryBuilder validateFilter(String node, List<String> keys) { try { Introspector obj = loader.introspectorFromName(node); + if (keys.isEmpty()) { - queryException.append("No keys sent. Valid keys for " + node + " are " - + String.join(",", obj.getIndexedProperties())); + queryException.append("No keys sent. Valid keys for ") + .append(node) + .append(" are ") + .append(String.join(",", obj.getIndexedProperties())); return this; } - boolean notIndexed = keys.stream() - .filter(prop -> obj.getIndexedProperties().contains(prop)).collect(Collectors.toList()).isEmpty(); - - if (notIndexed) { - queryException.append("Non indexed keys sent. Valid keys for " + node + " " - + String.join(",", obj.getIndexedProperties())); - } } catch (AAIUnknownObjectException e) { - queryException.append("Unknown Object being referenced by the query" + node); + queryException.append("Unknown Object being referenced by the query").append(node); } return this; } + public DslQueryBuilder select(boolean isNot, long selectCounter, List<String> keys) { + /* + * TODO : isNot should look at the vertex properties and include everything except the notKeys + */ + + Pattern p = Pattern.compile("aai-node-type"); + Matcher m = p.matcher(query); + int count = 0; + while (m.find()){ + count++; + } + + if (selectCounter == count || keys == null) { + String selectStep = "step" + selectCounter; +// String keysArray = String.join(",", keys); + query.append(".as('").append(selectStep).append("')") + .append(".as('stepMain').select('").append(selectStep).append("')"); + } + return this; + } + public DslQueryBuilder filterPropertyKeys(String node, String key, List<String> values) { try { Introspector obj = loader.introspectorFromName(node); - - Optional<String> alias = obj.getPropertyMetadata(key, PropertyMetadata.DB_ALIAS); + Optional<String> alias = obj.getPropertyMetadata(key.replace("'",""), PropertyMetadata.DB_ALIAS); if (alias.isPresent()) { - key = alias.get(); + key = StringUtils.quote(alias.get()); } + query.append(key); if (!values.isEmpty()) { if (values.size() > 1) { String valuesArray = String.join(",", values); - query.append(",").append(" new ArrayList<>(Arrays.asList(" + valuesArray + "))"); + query.append(",").append(" new ArrayList<>(Arrays.asList(").append(valuesArray).append("))"); } else { query.append(",").append(values.get(0)); } } } catch (AAIUnknownObjectException e) { - queryException.append("Unknown Object being referenced by the query" + node); + queryException.append("Unknown Object being referenced by the query").append(node); } return this; } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryProcessor.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryProcessor.java index a3978fd..14663e1 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryProcessor.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryProcessor.java @@ -19,86 +19,151 @@ */ package org.onap.aai.rest.dsl; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.*; import org.antlr.v4.runtime.misc.ParseCancellationException; import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.ParseTreeListener; import org.antlr.v4.runtime.tree.ParseTreeWalker; -import org.onap.aai.AAIDslLexer; -import org.onap.aai.AAIDslParser; import org.onap.aai.exceptions.AAIException; +import org.onap.aai.rest.dsl.v2.DslListener; +import org.onap.aai.rest.dsl.validation.DslValidator; +import org.onap.aai.rest.enums.QueryVersion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; import java.nio.charset.StandardCharsets; - +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * The Class DslQueryProcessor. */ public class DslQueryProcessor { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(DslQueryProcessor.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DslQueryProcessor.class); + + private Map<QueryVersion, ParseTreeListener> dslListeners; + private boolean startNodeValidationFlag = true; + private String validationRules = ""; + private String packageName = "org.onap.aai.dsl."; + private static final String LEXER = "AAIDslLexer"; + private static final String PARSER = "AAIDslParser"; + private static final String EOF_TOKEN = "<EOF>"; - private DslListener dslListener; - private boolean validationFlag = true; + private boolean isAggregate = false; @Autowired - public DslQueryProcessor(DslListener dslListener) { - this.dslListener = dslListener; + public DslQueryProcessor(Map<QueryVersion, ParseTreeListener> dslListeners) { + this.dslListeners = dslListeners; } - public String parseAaiQuery(String aaiQuery) throws AAIException { + public Map<String, Object> parseAaiQuery(QueryVersion version, String aaiQuery) throws AAIException { + Map<String, Object> resultMap = new HashMap<>(); try { // Create a input stream that reads our string InputStream stream = new ByteArrayInputStream(aaiQuery.getBytes(StandardCharsets.UTF_8)); - // Create a lexer from the input CharStream - AAIDslLexer lexer = new AAIDslLexer(CharStreams.fromStream(stream, StandardCharsets.UTF_8)); + packageName = packageName + version.toString().toLowerCase() + "."; + + Class<?> lexerClass = Class.forName(packageName + LEXER); + Class<?> parserClass = Class.forName(packageName + PARSER); + + Lexer lexer = (Lexer)lexerClass.getConstructor(CharStream.class).newInstance(CharStreams.fromStream(stream, StandardCharsets.UTF_8)); lexer.removeErrorListeners(); lexer.addErrorListener(new AAIDslErrorListener()); - - // Get a list of tokens pulled from the lexer CommonTokenStream tokens = new CommonTokenStream(lexer); // Parser that feeds off of the tokens buffer - AAIDslParser parser = new AAIDslParser(tokens); - parser.removeErrorListeners(); // remove ConsoleErrorListener + Parser parser = (Parser)parserClass.getConstructor(TokenStream.class).newInstance(tokens); + parser.removeErrorListeners(); parser.addErrorListener(new AAIDslErrorListener()); + ParseTreeListener dslListener = dslListeners.get(version); + dslListener.getClass().getMethod("setValidationFlag", boolean.class).invoke(dslListener, isStartNodeValidationFlag()); + dslListener.getClass().getMethod("setAggregateFlag", boolean.class).invoke(dslListener,isAggregate()); - dslListener.setValidationFlag(isValidationFlag()); - // Specify our entry point - ParseTree ptree = parser.aaiquery(); - LOGGER.info("QUERY-interim" + ptree.toStringTree(parser)); + if(!getValidationRules().isEmpty() && !"none".equals(getValidationRules())) { + DslValidator validator = new DslValidator.Builder() + .create(); + dslListener.getClass().getMethod("setQueryValidator", DslValidator.class, String.class).invoke(dslListener, validator, getValidationRules()); + } + // Specify our entry point + ParseTree ptree = (ParseTree)parserClass.getMethod("aaiquery").invoke(parser); + + // Check if there is no EOF token at the end of the parsed aaiQuery + // If none, DSL query may have not been parsed correctly and omitted part of the query out. If so error out. + // If it wasn't expecting a opening parens after a closing bracket for union, it will drop the proceeding part of the query. + Token eofToken = tokens.get(tokens.size() - 1); + if (eofToken != null && !eofToken.getText().equals(EOF_TOKEN)) { + if (eofToken.getText().equals("(")) { + throw new AAIException("AAI_6153", "DSL Syntax Error while processing the query: DSL Query could not be parsed correctly. Please check your syntax."); + } + } + + if (LOGGER.isInfoEnabled()) { + LOGGER.info("QUERY-interim {}", ptree.toStringTree(parser)); + } // Walk it and attach our listener ParseTreeWalker walker = new ParseTreeWalker(); + walker.walk(dslListener, ptree); - LOGGER.info("Final QUERY" + dslListener.getQuery()); - - /* - * TODO - Visitor patternQueryDslVisitor visitor = new - * QueryDslVisitor(); String query = visitor.visit(ptree); - * - */ - return dslListener.getQuery(); - } catch(ParseCancellationException e){ - throw new AAIException("AAI_6149", "DSL Syntax Error while processing the query :" + e.getMessage()); - } catch(AAIException e) { - throw new AAIException("AAI_6149", "DSL Syntax Error while processing the query :" + e.getMessage()); + String query = (String) dslListener.getClass().getMethod("getQuery").invoke(dslListener); + resultMap.put("query", query); + if (version.equals(QueryVersion.V2)){ + Map<String, List<String>> selectKeys= ((DslListener)dslListener).getSelectKeys(); + if (selectKeys != null && !selectKeys.isEmpty()){ + resultMap.put("propertiesMap", selectKeys); + } + } + LOGGER.info("Final QUERY {}", query); + return resultMap; + }catch(InvocationTargetException e){ + if (e.getTargetException() instanceof ParseCancellationException) { + throw new AAIException("AAI_6153", "DSL Syntax Error while processing the query :" + e.getTargetException().getMessage()); + } else if (e.getTargetException() instanceof AAIException) { + AAIException ex = (AAIException)e.getTargetException(); + throw new AAIException((ex.getCode().isEmpty() ? "AAI_6149":ex.getCode()), "DSL Error while processing the query :" + ex.getMessage()); + } else { + throw new AAIException("AAI_6152","Exception while processing DSL query"); + } + + } catch(ParseCancellationException e) { + throw new AAIException("AAI_6153", "DSL Syntax Error while processing the query: " + e.getMessage()); + } catch (Exception e) { - throw new AAIException("AAI_6149","Error while processing the query :" + e.getMessage()); + throw new AAIException("AAI_6152","Error while processing the query: " + e.getMessage()); + } } - public boolean isValidationFlag() { - return validationFlag; + + public boolean isStartNodeValidationFlag() { + return startNodeValidationFlag; + } + + public void setStartNodeValidationFlag(boolean startNodeValidationFlag) { + this.startNodeValidationFlag = startNodeValidationFlag; + } + + public boolean isAggregate() { + return isAggregate; + } + + public void setAggregate(boolean aggregate) { + this.isAggregate = aggregate; + } + + public String getValidationRules() { + return validationRules; } - public void setValidationFlag(boolean validationFlag) { - this.validationFlag = validationFlag; + public void setValidationRules(String validationRules) { + this.validationRules = validationRules; } } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/Edge.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/Edge.java new file mode 100644 index 0000000..c3be5dc --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/Edge.java @@ -0,0 +1,59 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.dsl; + +import org.onap.aai.rest.enums.EdgeDirection; + +import java.util.List; +import java.util.stream.Collectors; + +public class Edge { + + private List<EdgeLabel> labels; + private EdgeDirection direction; + + public Edge (EdgeDirection direction, List<EdgeLabel> labels) { + this.labels = labels; + this.direction = direction; + } + + public List<EdgeLabel> getLabels() { + return labels; + } + + public void setLabels(List<EdgeLabel> labels) { + this.labels = labels; + } + + public EdgeDirection getDirection() { + return direction; + } + + public void setDirection(EdgeDirection direction) { + this.direction = direction; + } + + @Override + public String toString() { + return String.format("labels: %s, direction: %s ", + labels.stream().map(EdgeLabel::getLabel).collect(Collectors.joining(",")), + this.getDirection().name()); + } +}
\ No newline at end of file diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/EdgeLabel.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/EdgeLabel.java new file mode 100644 index 0000000..703adaf --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/EdgeLabel.java @@ -0,0 +1,48 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.dsl; + +public class EdgeLabel { + + private String label; + private boolean isExactMatch; + + public EdgeLabel (String label, boolean isExactMatch) { + this.isExactMatch = isExactMatch; + this.label = label; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public boolean isExactMatch() { + return isExactMatch; + } + + public void setExactMatch(boolean isExactMatch) { + this.isExactMatch = isExactMatch; + } + +}
\ No newline at end of file diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslListener.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/v1/DslListener.java index 8fd23cc..4bb093e 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslListener.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/v1/DslListener.java @@ -17,25 +17,26 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.rest.dsl; +package org.onap.aai.rest.dsl.v1; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import com.google.common.collect.Lists; -import org.onap.aai.AAIDslBaseListener; -import org.onap.aai.AAIDslParser; +import org.onap.aai.dsl.v1.AAIDslBaseListener; +import org.onap.aai.dsl.v1.AAIDslParser; import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; +import org.onap.aai.logging.ErrorLogHelper; +import org.onap.aai.rest.dsl.DslQueryBuilder; +import org.onap.aai.rest.dsl.validation.DslValidator; +import org.onap.aai.rest.dsl.validation.DslValidatorRule; import org.onap.aai.setup.SchemaVersions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import java.util.ArrayList; -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -44,17 +45,29 @@ import java.util.stream.Stream; */ public class DslListener extends AAIDslBaseListener { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(DslListener.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DslListener.class); - boolean validationFlag = false; - EdgeIngestor edgeIngestor; - Loader loader; + private boolean validationFlag = false; + private EdgeIngestor edgeIngestor; + private Loader loader; + private Optional<DslValidator> queryValidator = Optional.empty(); + private boolean hasReturnValue = false; + + private String validationRules = "none"; private Deque<DslQueryBuilder> dslQueryBuilders = new LinkedList<>(); private Deque<String> traversedNodes = new LinkedList<>(); private Deque<List<String>> returnedNodes = new LinkedList<>(); - List<String> traversedEdgeLabels = new LinkedList<>(); + private List<String> traversedEdgeLabels = new LinkedList<>(); + + private boolean isAggregate = false; + + /* + * Additional datastructures to store all nodeCount & looped edges + */ + private int nodeCount = 0; + private List<String> traversedEdges = new LinkedList<>(); /** * Instantiates a new DslListener. @@ -70,12 +83,20 @@ public class DslListener extends AAIDslBaseListener { } public String getQuery() throws AAIException { - //TODO Change the exception reporting if (!getException().isEmpty()) { - LOGGER.error("Exception in the DSL Query" + getException()); - throw new AAIException("AAI_6149", getException()); + AAIException aaiException = new AAIException("AAI_6149", getException()); + ErrorLogHelper.logException(aaiException); + throw aaiException; } + DslValidatorRule ruleValidator = new DslValidatorRule.Builder() + .loop(getValidationRules() , traversedEdges) + .nodeCount(getValidationRules(), nodeCount).build(); + if(queryValidator.isPresent() && !queryValidator.get().validate(ruleValidator)){ + AAIException aaiException = new AAIException("AAI_6151", "Validation error " + queryValidator.get().getErrorMessage() ); + ErrorLogHelper.logException(aaiException); + throw aaiException; + } return this.compile(); } @@ -85,7 +106,8 @@ public class DslListener extends AAIDslBaseListener { } public String getException() { - return builder().getQueryException().toString(); + List<String> exceptions = dslQueryBuilders.stream().map(dslQb -> dslQb.getQueryException().toString()).collect(Collectors.toList()); + return String.join("", Lists.reverse(exceptions)); } @Override @@ -94,6 +116,13 @@ public class DslListener extends AAIDslBaseListener { } @Override + public void exitAaiquery(AAIDslParser.AaiqueryContext ctx) { + if (!hasReturnValue) { + throw new RuntimeException(new AAIException("AAI_6149", "No nodes marked for output")); + } + } + + @Override public void enterStartStatement(AAIDslParser.StartStatementContext ctx) { builder().start(); } @@ -124,7 +153,6 @@ public class DslListener extends AAIDslBaseListener { if(!ctx.traversal().isEmpty()) { count += ctx.traversal().size() ; } - //TODO so ugly String resultNode = traversedNodes.peekFirst(); if (!traversedNodes.isEmpty()) { @@ -147,6 +175,7 @@ public class DslListener extends AAIDslBaseListener { if (!traversedNodes.isEmpty()) { builder().edgeQuery(traversedEdgeLabels, traversedNodes.peekFirst(), ctx.label().getText()); + traversedEdges.add(traversedNodes.peekFirst() + ctx.label().getText()); } else { builder().nodeQuery(ctx.label().getText()); } @@ -164,15 +193,17 @@ public class DslListener extends AAIDslBaseListener { if (ctx.filter() != null) { allKeys = ctx.filter().propertyFilter().stream().flatMap( pf -> pf.key().stream()).map( - e -> e.getText().replaceAll("\'", "")).collect(Collectors.toList()); + e -> e.getText().replaceFirst("\'", "").substring(0, e.getText().length() - 2)).collect(Collectors.toList()); } builder().validateFilter(ctx.label().getText(), allKeys); } if (ctx.store() != null) { builder().store(); + hasReturnValue = true; } traversedEdgeLabels = new ArrayList<>(); + nodeCount++; } @@ -187,12 +218,17 @@ public class DslListener extends AAIDslBaseListener { String resultNode = returnedNodes.pop().get(0); traversedNodes.addFirst(resultNode); builder().endUnion(); + if (ctx.store() != null) { + builder().store(); + hasReturnValue = true; + } } @Override public void enterWhereFilter(AAIDslParser.WhereFilterContext ctx) { + boolean isNot = ctx.not() != null && !ctx.not().isEmpty(); returnedNodes.addFirst(new ArrayList<>()); - builder().where(); + builder().where(isNot); } @Override @@ -200,15 +236,8 @@ public class DslListener extends AAIDslBaseListener { if(!returnedNodes.isEmpty()) { returnedNodes.pop(); } - builder().endWhere(); - } - - @Override - public void enterTraversal(AAIDslParser.TraversalContext ctx) { - } - - @Override - public void enterEdge(AAIDslParser.EdgeContext ctx) { + boolean isNot = ctx.not() != null && !ctx.not().isEmpty(); + builder().endWhere(isNot); } @Override @@ -218,11 +247,6 @@ public class DslListener extends AAIDslBaseListener { } @Override - public void enterFilter(AAIDslParser.FilterContext ctx) { - - } - - @Override public void enterPropertyFilter(AAIDslParser.PropertyFilterContext ctx) { List<AAIDslParser.KeyContext> valueList = ctx.key(); @@ -231,17 +255,26 @@ public class DslListener extends AAIDslBaseListener { boolean isNot = ctx.not() != null && !ctx.not().isEmpty(); List<AAIDslParser.NumContext> numberValues = ctx.num(); + List<AAIDslParser.BoolContext> booleanValues = ctx.bool(); + /* * Add all String values */ List<String> values = valueList.stream().filter(value -> !filterKey.equals(value.getText())) - .map(value -> "'" + value.getText().replace("'", "") + "'").collect(Collectors.toList()); + .map(value -> value.getText()).collect(Collectors.toList()); + /* * Add all numeric values */ values.addAll(numberValues.stream().filter(value -> !filterKey.equals(value.getText())) .map(value -> value.getText()).collect(Collectors.toList())); + /* + * Add all boolean values + */ + values.addAll(booleanValues.stream().filter(value -> !filterKey.equals(value.getText())) + .map(value -> value.getText().toLowerCase()).collect(Collectors.toList())); + builder().filter(isNot, traversedNodes.peekFirst(), filterKey, values); } @@ -254,4 +287,20 @@ public class DslListener extends AAIDslBaseListener { this.validationFlag = validationFlag; } + public void setQueryValidator(DslValidator queryValidator, String validationRules) { + this.queryValidator = Optional.of(queryValidator); + this.validationRules = validationRules; + } + public String getValidationRules() { + return validationRules; + } + + public void setAggregateFlag(boolean isAggregate) { + this.isAggregate = isAggregate; + } + + public boolean isAggregate(){ + return this.isAggregate; + } + } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/v2/DslListener.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/v2/DslListener.java new file mode 100644 index 0000000..8f9f145 --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/v2/DslListener.java @@ -0,0 +1,353 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.dsl.v2; + +import com.google.common.collect.Lists; +import org.onap.aai.dsl.v2.AAIDslBaseListener; +import org.onap.aai.dsl.v2.AAIDslParser; +import org.onap.aai.edges.EdgeIngestor; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.logging.ErrorLogHelper; +import org.onap.aai.rest.dsl.DslQueryBuilder; +import org.onap.aai.rest.dsl.Edge; +import org.onap.aai.rest.dsl.EdgeLabel; +import org.onap.aai.rest.dsl.validation.DslValidator; +import org.onap.aai.rest.dsl.validation.DslValidatorRule; +import org.onap.aai.rest.enums.EdgeDirection; +import org.onap.aai.setup.SchemaVersions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * The Class DslListener. + */ +public class DslListener extends AAIDslBaseListener { + + private static final Logger LOGGER = LoggerFactory.getLogger(DslListener.class.getName()); + + private boolean validationFlag = false; + private EdgeIngestor edgeIngestor; + private Loader loader; + private Optional<DslValidator> queryValidator = Optional.empty(); + private boolean hasReturnValue = false; + + private String validationRules = "none"; + + private Deque<DslQueryBuilder> dslQueryBuilders = new LinkedList<>(); + private Deque<String> traversedNodes = new LinkedList<>(); + private Deque<List<String>> returnedNodes = new LinkedList<>(); + + private Deque<Edge> traversedEdges = new ArrayDeque<>(); + private long selectCounter = 0; + + /* + * Additional datastructures to store all nodeCount & looped edges + */ + int nodeCount = 0; + private List<String> traversedEdgesOld = new LinkedList<>(); + + private Map<String, List<String>> selectKeys = new HashMap<String, List<String>>(); + private boolean isAggregate; + + public Map<String, List<String>> getSelectKeys() { + return selectKeys; + } + + public void setSelectKeys(String nodeType, List<String> properties) { + this.selectKeys.put(nodeType, properties); + } + + /** + * Instantiates a new DslListener. + */ + @Autowired + public DslListener(EdgeIngestor edgeIngestor, SchemaVersions schemaVersions, LoaderFactory loaderFactory) { + this.loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); + this.edgeIngestor = edgeIngestor; + } + + public DslQueryBuilder builder() { + return dslQueryBuilders.peekFirst(); + } + + public String getQuery() throws AAIException { + //TODO Change the exception reporting + if (!getException().isEmpty()) { + AAIException aaiException = new AAIException("AAI_6149", getException()); + ErrorLogHelper.logException(aaiException); + throw aaiException; + } + + DslValidatorRule ruleValidator = new DslValidatorRule.Builder() + .loop(getValidationRules() , traversedEdgesOld) + .nodeCount(getValidationRules(), nodeCount).build(); + if(queryValidator.isPresent() && !queryValidator.get().validate(ruleValidator)){ + AAIException aaiException = new AAIException("AAI_6151", "Validation error " + queryValidator.get().getErrorMessage() ); + ErrorLogHelper.logException(aaiException); + throw aaiException; + } + return this.compile(); + } + + public String compile() { + List<String> queries = dslQueryBuilders.stream().map(dslQb -> dslQb.getQuery().toString()).collect(Collectors.toList()); + return String.join("", Lists.reverse(queries)); + } + + public String getException() { + List<String> exceptions = dslQueryBuilders.stream().map(dslQb -> dslQb.getQueryException().toString()).collect(Collectors.toList()); + return String.join("", Lists.reverse(exceptions)); + } + + @Override + public void enterAaiquery(AAIDslParser.AaiqueryContext ctx) { + dslQueryBuilders.push(new DslQueryBuilder(edgeIngestor, loader)); + } + + @Override + public void exitAaiquery(AAIDslParser.AaiqueryContext ctx) { + if (!hasReturnValue) { + throw new RuntimeException(new AAIException("AAI_6149", "No nodes marked for output")); + } + } + + @Override + public void enterStartStatement(AAIDslParser.StartStatementContext ctx) { + builder().start(); + } + + @Override + public void exitStartStatement(AAIDslParser.StartStatementContext ctx) { + builder().end(selectCounter); + if (!traversedNodes.isEmpty()) { + traversedNodes.removeFirst(); + } + + } + + @Override + public void exitLimit(AAIDslParser.LimitContext ctx) { + builder().limit(ctx.num().getText()); + } + + @Override + public void enterNestedStatement(AAIDslParser.NestedStatementContext ctx) { + dslQueryBuilders.addFirst(new DslQueryBuilder(edgeIngestor, loader)); + builder().startInstance(); + } + + @Override + public void exitNestedStatement(AAIDslParser.NestedStatementContext ctx) { + int count = 1; + if(!ctx.traversal().isEmpty()) { + count = ctx.traversal().size() ; + } + String resultNode = traversedNodes.peekFirst(); + + if (!traversedNodes.isEmpty()) { + Stream<Integer> integers = Stream.iterate(0, i -> i + 1); + integers.limit(count) + .forEach(i -> traversedNodes.removeFirst()); + } + List<String> resultNodes = returnedNodes.pop(); + resultNodes.add(resultNode); + returnedNodes.addFirst(resultNodes); + } + + @Override + public void enterComma(AAIDslParser.CommaContext ctx) { + builder().comma(); + } + + @Override + public void enterVertex(AAIDslParser.VertexContext ctx) { + + if (!traversedEdges.isEmpty() && !traversedNodes.isEmpty()) { + builder().edgeQuery(traversedEdges.peekFirst(), traversedNodes.peekFirst(), ctx.label().getText()); + traversedEdgesOld.add(traversedNodes.peekFirst() + ctx.label().getText()); + } else { + builder().nodeQuery(ctx.label().getText()); + } + + traversedNodes.addFirst(ctx.label().getText()); + } + + @Override + public void exitVertex(AAIDslParser.VertexContext ctx) { + + /*TODO dont use context */ + if (ctx.getParent() instanceof AAIDslParser.StartStatementContext && isValidationFlag()) { + List<String> allKeys = new ArrayList<>(); + + if (ctx.filter() != null) { + allKeys = ctx.filter().propertyFilter().stream().flatMap( + pf -> pf.key().stream()).map( + e -> e.getText().replaceAll("\'", "")).collect(Collectors.toList()); + } + builder().validateFilter(ctx.label().getText(), allKeys); + } + if (ctx.store() != null) { + if (isAggregate() && (selectCounter == nodeCount) && (nodeCount < traversedNodes.size())) { + builder().select(false, selectCounter++, null); + } + builder().store(); + hasReturnValue = true; + } + nodeCount++; + } + + + @Override + public void enterUnionVertex(AAIDslParser.UnionVertexContext ctx) { + returnedNodes.addFirst(new ArrayList<>()); + builder().union(); + } + + @Override + public void exitUnionVertex(AAIDslParser.UnionVertexContext ctx) { + String resultNode = returnedNodes.pop().get(0); + traversedNodes.addFirst(resultNode); + builder().endUnion(); + if (ctx.store() != null) { + builder().store(); + hasReturnValue = true; + } + } + + @Override + public void enterWhereFilter(AAIDslParser.WhereFilterContext ctx) { + boolean isNot = ctx.not() != null && !ctx.not().isEmpty(); + returnedNodes.addFirst(new ArrayList<>()); + builder().where(isNot); + } + + @Override + public void exitWhereFilter(AAIDslParser.WhereFilterContext ctx) { + if(!returnedNodes.isEmpty()) { + returnedNodes.pop(); + } + boolean isNot = ctx.not() != null && !ctx.not().isEmpty(); + builder().endWhere(isNot); + } + + @Override + public void enterEdge(AAIDslParser.EdgeContext ctx) { + List<EdgeLabel> labels = new ArrayList<>(); + + if(ctx.edgeFilter() != null) { + labels.addAll(ctx.edgeFilter().key().stream().map( + e -> new EdgeLabel(removeSingleQuotes(e.getText()), true)) + .collect(Collectors.toList())); + } + EdgeDirection direction = EdgeDirection.BOTH; + if(ctx.DIRTRAVERSE() != null){ + direction = EdgeDirection.fromValue(ctx.DIRTRAVERSE().getText()); + } + traversedEdges.addFirst(new Edge(direction, labels)); + } + + protected String removeSingleQuotes(String value) { + return value.replaceFirst("^'(.*)'$", "$1"); + } + + @Override + public void enterPropertyFilter(AAIDslParser.PropertyFilterContext ctx) { + + List<AAIDslParser.KeyContext> valueList = ctx.key(); + String filterKey = valueList.get(0).getText(); + + boolean isNot = ctx.not() != null && !ctx.not().isEmpty(); + List<AAIDslParser.NumContext> numberValues = ctx.num(); + + List<AAIDslParser.BoolContext> booleanValues = ctx.bool(); + + /* + * Add all String values + */ + List<String> values = valueList.stream().filter(value -> !filterKey.equals(value.getText())) + .map(value -> "'" + value.getText().replace("'", "") + "'").collect(Collectors.toList()); + /* + * Add all numeric values + */ + values.addAll(numberValues.stream().filter(value -> !filterKey.equals(value.getText())) + .map(value -> value.getText()).collect(Collectors.toList())); + + /* + * Add all boolean values + */ + values.addAll(booleanValues.stream().filter(value -> !filterKey.equals(value.getText())) + .map(value -> value.getText().toLowerCase()).collect(Collectors.toList())); + + builder().filter(isNot, traversedNodes.peekFirst(), filterKey, values); + + } + + @Override + public void enterSelectFilter(AAIDslParser.SelectFilterContext ctx) { + + List<AAIDslParser.KeyContext> keyList = ctx.key(); + + boolean isNot = ctx.not() != null && !ctx.not().isEmpty(); + + /* + * Add all String values + */ + List<String> allKeys = keyList.stream().map(keyValue -> "'" + keyValue.getText().replace("'", "") + "'").collect(Collectors.toList()); + if (allKeys != null && !allKeys.isEmpty()){ + setSelectKeys(traversedNodes.getFirst(), allKeys); + } + if (isAggregate() && (traversedNodes.size() == nodeCount)) { + builder().select(isNot, selectCounter++, allKeys); + } + } + + public boolean isValidationFlag() { + return validationFlag; + } + + public void setValidationFlag(boolean validationFlag) { + this.validationFlag = validationFlag; + } + + public void setAggregateFlag(boolean isAggregate) { + this.isAggregate = isAggregate; + } + + public boolean isAggregate(){ + return this.isAggregate; + } + + public void setQueryValidator(DslValidator queryValidator, String validationRules) { + this.queryValidator = Optional.of(queryValidator); + this.validationRules = validationRules; + } + public String getValidationRules() { + return validationRules; + } + +} diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslQueryValidator.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslQueryValidator.java new file mode 100644 index 0000000..53f2c72 --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslQueryValidator.java @@ -0,0 +1,62 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2018-2019 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.dsl.validation; + +import org.onap.aai.util.AAIConfig; +import org.onap.aai.util.TraversalConstants; + +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +public class DslQueryValidator extends DslValidator { + + protected DslQueryValidator(Builder builder) { + super(builder); + } + + public boolean validate(DslValidatorRule dslValidatorRule) { + + return validateLoop(dslValidatorRule.isValidateLoop(), dslValidatorRule.getEdges()) && validateNodeCount(dslValidatorRule.isValidateNodeCount(), dslValidatorRule.getNodeCount()); + } + + private boolean validateLoop(boolean isValidateLoop, List<String> edges) { + if (isValidateLoop) { + Set<String> uniqueEdges = new LinkedHashSet<>(edges); + + if (uniqueEdges.size() < (edges.size() / 2)) { + this.errorMessage.append("Loop Validation failed"); + return false; + } + } + return true; + } + + private boolean validateNodeCount(boolean isValidateNodeCount, int nodeCount) { + String maxNodeString = AAIConfig.get("aai.dsl.max.nodecount", TraversalConstants.DSL_MAX_NODE_COUNT); + int maxNodeCount = Integer.parseInt(maxNodeString); + if (isValidateNodeCount && nodeCount > maxNodeCount) { + this.errorMessage.append("NodeCount Validation failed"); + return false; + } + return true; + } + +} diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslSchemaValidator.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslSchemaValidator.java new file mode 100644 index 0000000..54a2feb --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslSchemaValidator.java @@ -0,0 +1,32 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2018-2019 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.dsl.validation; + +public class DslSchemaValidator extends DslValidator { + + protected DslSchemaValidator(Builder builder) { + super(builder); + } + + public boolean validate(DslValidatorRule dslValidatorRule) { + return true; + } + +} diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslValidator.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslValidator.java new file mode 100644 index 0000000..128f8a8 --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslValidator.java @@ -0,0 +1,58 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2018-2019 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.dsl.validation; + +import org.onap.aai.exceptions.AAIException; + +public abstract class DslValidator { + protected StringBuilder errorMessage = new StringBuilder(""); + + + protected DslValidator(DslValidator.Builder builder) { + + } + + public abstract boolean validate(DslValidatorRule dslValidatorRule) throws AAIException; + + public String getErrorMessage() { + return errorMessage.toString(); + } + + public static class Builder { + + boolean isSchemaValidation = false; + + public Builder schema() { + this.setSchemaValidation(true); + return this; + } + + private void setSchemaValidation(boolean schemaValidation) { + isSchemaValidation = schemaValidation; + } + + public DslValidator create() { + if (isSchemaValidation) { + return new DslSchemaValidator(this); + } + return new DslQueryValidator(this); + } + } +} diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslValidatorRule.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslValidatorRule.java new file mode 100644 index 0000000..54d45bd --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/validation/DslValidatorRule.java @@ -0,0 +1,141 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2018-2019 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.dsl.validation; + +import java.util.LinkedList; +import java.util.List; + +public class DslValidatorRule { + + private static final String LOOP_RULE = "loop"; + private static final String NODECOUNT_RULE = "nodeCount"; + private static final String ALL_RULE = "all"; + + private String query; + private boolean validateLoop; + private boolean validateNodeCount; + private int nodeCount; + private List<String> edges; + + protected DslValidatorRule(DslValidatorRule.Builder builder) { + query = builder.query; + validateLoop = builder.validateLoop; + validateNodeCount = builder.validateNodeCount; + nodeCount = builder.nodeCount; + edges = builder.getEdges(); + } + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + public boolean isValidateLoop() { + return validateLoop; + } + + public void setValidateLoop(boolean validateLoop) { + this.validateLoop = validateLoop; + } + + public boolean isValidateNodeCount() { + return validateNodeCount; + } + + public void setValidateNodeCount(boolean validateNodeCount) { + this.validateNodeCount = validateNodeCount; + } + + public int getNodeCount() { + return nodeCount; + } + + public void setNodeCount(int nodeCount) { + this.nodeCount = nodeCount; + } + + public List<String> getEdges() { + return edges; + } + + public void setEdges(List<String> edges) { + this.edges = edges; + } + + public static class Builder { + + //todo optional + String query = ""; + boolean validateLoop = false; + boolean validateNodeCount = false; + int nodeCount = 0; + List<String> edges = new LinkedList<>(); + + public List<String> getEdges() { + return edges; + } + + public void setEdges(List<String> edges) { + this.edges = edges; + } + + public Builder query(String query) { + this.setQuery(query); + return this; + } + + public Builder loop(String validateLoop, List<String> edges) { + if (validateLoop.contains(LOOP_RULE) || validateLoop.contains(ALL_RULE)) { + this.setValidateLoop(true); + this.setEdges(edges); + } + + return this; + } + + public Builder nodeCount(String validateNodeCount, int nodeCount) { + if (validateNodeCount.contains(NODECOUNT_RULE) || validateNodeCount.contains(ALL_RULE)) { + this.setValidateNodeCount(true); + this.nodeCount = nodeCount; + } + return this; + } + + private void setQuery(String query) { + this.query = query; + } + + private void setValidateLoop(boolean validateLoop) { + this.validateLoop = validateLoop; + } + + private void setValidateNodeCount(boolean validateNodeCount) { + this.validateNodeCount = validateNodeCount; + } + + public DslValidatorRule build() { + + return new DslValidatorRule(this); + } + } +} diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/enums/EdgeDirection.java b/aai-traversal/src/main/java/org/onap/aai/rest/enums/EdgeDirection.java new file mode 100644 index 0000000..61f35ac --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/rest/enums/EdgeDirection.java @@ -0,0 +1,48 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.enums; + +public enum EdgeDirection { + OUT(">>"), + IN("<<"), + BOTH(">"); + + + private final String value; + + private EdgeDirection(String value) { + this.value = value; + } + + + public static EdgeDirection fromValue(String value) { + + for (EdgeDirection d : values()) { + if (d.value.equals(value)) { + return d; + } + } + return BOTH; + } + @Override + public String toString() { + return value; + } +}
\ No newline at end of file diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/enums/QueryVersion.java b/aai-traversal/src/main/java/org/onap/aai/rest/enums/QueryVersion.java new file mode 100644 index 0000000..0e30f28 --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/rest/enums/QueryVersion.java @@ -0,0 +1,25 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.enums; + +public enum QueryVersion { + V1, + V2; +}
\ No newline at end of file diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java index 56b748c..8e62900 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java @@ -19,10 +19,12 @@ */ package org.onap.aai.rest.search; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.apache.tinkerpop.gremlin.process.traversal.P; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; @@ -30,9 +32,12 @@ import org.javatuples.Pair; import org.onap.aai.exceptions.AAIException; import org.onap.aai.query.builder.MissingOptionalParameter; import org.onap.aai.rest.dsl.DslQueryProcessor; +import org.onap.aai.rest.enums.QueryVersion; import org.onap.aai.restcore.search.GroovyQueryBuilder; import org.onap.aai.restcore.util.URITools; +import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.TransactionalGraphEngine; +import org.onap.aai.serialization.queryformats.Format; import org.onap.aai.serialization.queryformats.SubGraphStyle; import javax.ws.rs.core.MultivaluedHashMap; @@ -45,7 +50,7 @@ import java.util.regex.Pattern; public abstract class GenericQueryProcessor { - private static EELFLogger LOGGER = EELFManager.getInstance().getLogger(GenericQueryProcessor.class); + private static Logger LOGGER = LoggerFactory.getLogger(GenericQueryProcessor.class); protected final Optional<URI> uri; protected final MultivaluedMap<String, String> queryParams; @@ -57,11 +62,27 @@ public abstract class GenericQueryProcessor { protected GroovyQueryBuilder groovyQueryBuilder = new GroovyQueryBuilder(); protected final boolean isGremlin; protected Optional<DslQueryProcessor> dslQueryProcessorOptional; + + public Map<String, List<String>> getPropertiesMap() { + return propertiesList; + } + + public void setPropertiesMap(Map<String, List<String>> propertiesMap) { + this.propertiesList = propertiesMap; + } + + private Map<String, List<String>> propertiesList; /* dsl parameters to store dsl query and to check + * if this is a DSL request */ protected Optional<String> dsl; protected final boolean isDsl ; + protected boolean isHistory; + protected GraphTraversalSource traversalSource; + protected QueryStyle style; + protected QueryVersion dslApiVersion; + protected Format format; protected GenericQueryProcessor(Builder builder) { this.uri = builder.getUri(); @@ -73,16 +94,23 @@ public abstract class GenericQueryProcessor { this.isDsl = builder.isDsl(); this.gremlinServerSingleton = builder.getGremlinServerSingleton(); this.dslQueryProcessorOptional = builder.getDslQueryProcessor(); + this.dslApiVersion = builder.getDslApiVersion(); if (uri.isPresent()) { queryParams = URITools.getQueryMap(uri.get()); + } else if (builder.getUriParams() != null) { + queryParams = builder.getUriParams(); } else { queryParams = new MultivaluedHashMap<>(); } + this.traversalSource = builder.getTraversalSource(); + this.style = builder.getStyle(); + this.isHistory = builder.isHistory(); + this.format = builder.getFormat(); } - protected abstract GraphTraversal<?,?> runQuery(String query, Map<String, Object> params); - + protected abstract GraphTraversal<?,?> runQuery(String query, Map<String, Object> params, GraphTraversalSource traversalSource); + protected List<Object> processSubGraph(SubGraphStyle style, GraphTraversal<?,?> g) { final List<Object> resultVertices = new Vector<>(); g.store("y"); @@ -106,18 +134,45 @@ public abstract class GenericQueryProcessor { Pair<String, Map<String, Object>> tuple = this.createQuery(); String query = tuple.getValue0(); + if (queryParams.containsKey("as-tree")) { + if (queryParams.getFirst("as-tree").equalsIgnoreCase("true")) { + if (this.isDsl) { // If dsl query and as-tree parameter is true, remove "end" concatenation and append tree. + query = removeDslQueryEnd(query); + } + query = query.concat(".tree()"); // Otherwise, normal gremlin query will just append tree + } + } Map<String, Object> params = tuple.getValue1(); if (query.equals("") && (vertices.isPresent() && vertices.get().isEmpty())) { //nothing to do, just exit return new ArrayList<>(); } - GraphTraversal<?,?> g = this.runQuery(query, params); + GraphTraversal<?,?> g = this.runQuery(query, params, traversalSource); resultVertices = this.processSubGraph(style, g); return resultVertices; } + + private String removeDslQueryEnd(String query) { + String end = ".cap('x').unfold().dedup()"; + if (query.length() <= end.length()) { + return query; + } + if (query.contains(end)) { + int startIndex = query.length() - end.length(); + for (int i = 0; startIndex - i >= 0; i++) { // remove tailing instance + startIndex = query.length() - end.length() - i; + int lastIndex = query.length() - i; + if (query.substring(startIndex, lastIndex).equals(end)) { + query = query.substring(0, startIndex) + query.substring(lastIndex); + break; + } + } + } + return query; + } protected Pair<String, Map<String, Object>> createQuery() throws AAIException { Map<String, Object> params = new HashMap<>(); @@ -128,8 +183,15 @@ public abstract class GenericQueryProcessor { }else if (this.isDsl) { String dslUserQuery = dsl.get(); if(dslQueryProcessorOptional.isPresent()){ - String dslQuery = dslQueryProcessorOptional.get().parseAaiQuery(dslUserQuery); - query = groovyQueryBuilder.executeTraversal(dbEngine, dslQuery, params); + Map<String, Object>resultMap = dslQueryProcessorOptional.get().parseAaiQuery(dslApiVersion, dslUserQuery); + String dslQuery = resultMap.get("query").toString(); + Object propMap = resultMap.get("propertiesMap"); + if (propMap instanceof Map) { + Map<String, List<String>> newPropMap = new HashMap<String, List<String>>(); + newPropMap = (Map<String, List<String>>)propMap; + setPropertiesMap(newPropMap); + } + query = groovyQueryBuilder.executeTraversal(dbEngine, dslQuery, params, style, traversalSource); String startPrefix = "g.V()"; query = startPrefix + query; } @@ -178,7 +240,7 @@ public abstract class GenericQueryProcessor { if (query == null) { query = ""; } else { - query = groovyQueryBuilder.executeTraversal(dbEngine, query, params); + query = groovyQueryBuilder.executeTraversal(dbEngine, query, params, style, traversalSource); } String startPrefix = "g.V(startVertexes)"; @@ -227,7 +289,14 @@ public abstract class GenericQueryProcessor { private GremlinServerSingleton gremlinServerSingleton; private Optional<String> nodeType = Optional.empty(); private boolean isNodeTypeQuery = false; - protected MultivaluedMap<String, String> uriParams; + protected MultivaluedMap<String, String> uriParams; + protected GraphTraversalSource traversalSource; + protected boolean isHistory = false; + protected QueryVersion dslApiVersion; + protected Format format; + + + protected QueryStyle style = QueryStyle.GREMLIN_TRAVERSAL; public Builder(TransactionalGraphEngine dbEngine, GremlinServerSingleton gremlinServerSingleton) { this.dbEngine = dbEngine; @@ -272,11 +341,31 @@ public abstract class GenericQueryProcessor { return this; } + public Builder format(Format format) { + this.format = format; + return this; + } + + public Builder traversalSource(boolean isHistory, GraphTraversalSource source) { + this.traversalSource = source; + this.isHistory = isHistory; + if(this.isHistory){ + this.style = QueryStyle.HISTORY_GREMLIN_TRAVERSAL; + } + + return this; + } + public Builder queryProcessor(DslQueryProcessor dslQueryProcessor){ this.dslQueryProcessor = dslQueryProcessor; return this; } + public Builder version(QueryVersion version){ + this.dslApiVersion = version; + return this; + } + public Optional<DslQueryProcessor> getDslQueryProcessor(){ return Optional.ofNullable(this.dslQueryProcessor); } @@ -288,6 +377,8 @@ public abstract class GenericQueryProcessor { return uri; } + public MultivaluedMap<String, String> getUriParams() { return uriParams; } + public Optional<String> getGremlin() { return gremlin; } @@ -330,6 +421,40 @@ public abstract class GenericQueryProcessor { } return new GroovyShellImpl(this); } + + public GraphTraversalSource getTraversalSource() { + return traversalSource; + } + + public void setTraversalSource(GraphTraversalSource traversalSource) { + this.traversalSource = traversalSource; + } + + public boolean isHistory() { + return isHistory; + } + + public void setHistory(boolean history) { + isHistory = history; + } + + public QueryStyle getStyle() { + return style; + } + + public void setStyle(QueryStyle style) { + this.style = style; + } + + public QueryVersion getDslApiVersion() { + return dslApiVersion; + } + + public void setDslApiVersion(QueryVersion dslApiVersion) { + this.dslApiVersion = dslApiVersion; + } + + public Format getFormat(){ return this.format; } } } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java index 9ae3dec..e30f13f 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java @@ -21,8 +21,8 @@ package org.onap.aai.rest.search; import org.onap.aai.logging.LogFormatTools; import org.onap.aai.util.AAIConstants; -import org.onap.aai.util.FileWatcher; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.apache.tinkerpop.gremlin.driver.Cluster; import org.springframework.beans.factory.annotation.Autowired; @@ -43,7 +43,7 @@ import java.util.TimerTask; public class GremlinServerSingleton { - private static EELFLogger logger = EELFManager.getInstance().getLogger(GremlinServerSingleton.class); + private static Logger logger = LoggerFactory.getLogger(GremlinServerSingleton.class); private boolean timerSet; private Timer timer; diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/GroovyShellImpl.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/GroovyShellImpl.java index 712d7f0..340c525 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/GroovyShellImpl.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/GroovyShellImpl.java @@ -23,7 +23,13 @@ import java.util.Map; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.onap.aai.aailog.logs.AaiDBTraversalMetricLog; import org.onap.aai.restcore.search.GremlinGroovyShell; +import org.onap.aai.restcore.util.URITools; +import org.onap.aai.util.AAIConstants; + +import javax.ws.rs.core.MultivaluedHashMap; public class GroovyShellImpl extends GenericQueryProcessor { @@ -32,13 +38,17 @@ public class GroovyShellImpl extends GenericQueryProcessor { } @Override - protected GraphTraversal<?,?> runQuery(String query, Map<String, Object> params) { + protected GraphTraversal<?,?> runQuery(String query, Map<String, Object> params, GraphTraversalSource traversalSource) { - params.put("g", this.dbEngine.asAdmin().getTraversalSource()); - + AaiDBTraversalMetricLog metricLog = new AaiDBTraversalMetricLog (AAIConstants.AAI_TRAVERSAL_MS); + metricLog.pre(uri); + + params.put("g", traversalSource); GremlinGroovyShell shell = new GremlinGroovyShell(); - - return shell.executeTraversal(query, params); + GraphTraversal<?,?> graphTraversal = shell.executeTraversal(query, params); + + metricLog.post(); + return graphTraversal; } } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/LocalCQConfig.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/LocalCQConfig.java index bcd4c4e..52957d4 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/LocalCQConfig.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/LocalCQConfig.java @@ -19,11 +19,14 @@ */ package org.onap.aai.rest.search; -import com.att.eelf.configuration.EELFLogger; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.logging.ErrorLogHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; +import org.onap.aai.aaf.auth.FileWatcher; import org.onap.aai.logging.LogFormatTools; import org.onap.aai.util.AAIConstants; -import org.onap.aai.util.FileWatcher; import org.springframework.beans.factory.annotation.Value; import javax.annotation.PostConstruct; @@ -37,7 +40,7 @@ import java.util.Timer; import java.util.TimerTask; public class LocalCQConfig extends CQConfig { - private static EELFLogger logger = EELFManager.getInstance().getLogger(LocalCQConfig.class); + private static Logger logger = LoggerFactory.getLogger(LocalCQConfig.class); @Value("${schema.queries.location}") private String storedQueriesLocation; @@ -56,7 +59,9 @@ public class LocalCQConfig extends CQConfig { queryConfig = new GetCustomQueryConfig(customQueryConfigJson); } catch (IOException e) { - logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); + AAIException aaiException = new AAIException("AAI_4002", e); + ErrorLogHelper.logException(aaiException); + //logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); } TimerTask task = new FileWatcher(new File(storedQueriesLocation)) { @@ -69,7 +74,9 @@ public class LocalCQConfig extends CQConfig { queryConfig = new GetCustomQueryConfig(customQueryConfigJson); } catch (IOException e) { - logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); + AAIException aaiException = new AAIException("AAI_4002", e); + ErrorLogHelper.logException(aaiException); + //logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); } } }; diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProvider.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProvider.java index 4102c52..e590964 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProvider.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProvider.java @@ -19,22 +19,21 @@ */ package org.onap.aai.rest.search; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.onap.aai.aailog.logs.AaiDBTraversalMetricLog; +import org.onap.aai.concurrent.AaiCallable; import org.onap.aai.dbgraphmap.SearchGraph; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; -import org.onap.aai.extensions.AAIExtensionMap; import org.onap.aai.logging.ErrorLogHelper; -import org.onap.aai.logging.LoggingContext; -import org.onap.aai.logging.StopWatch; + +import org.onap.aai.rest.util.AAIExtensionMap; import org.onap.aai.restcore.HttpMethod; import org.onap.aai.restcore.RESTAPI; import org.onap.aai.setup.SchemaVersions; import org.onap.aai.util.AAIConstants; import org.onap.aai.util.TraversalConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.onap.aai.concurrent.AaiCallable; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.POST; @@ -43,8 +42,9 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.*; import javax.ws.rs.core.Response.Status; +import java.net.URI; import java.util.ArrayList; -import java.util.concurrent.TimeUnit; +import java.util.Optional; /** * Implements the search subdomain in the REST API. All API calls must include @@ -54,15 +54,13 @@ import java.util.concurrent.TimeUnit; @Path("/search") public class ModelAndNamedQueryRestProvider extends RESTAPI { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ModelAndNamedQueryRestProvider.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ModelAndNamedQueryRestProvider.class); public static final String NAMED_QUERY = "/named-query"; public static final String MODEL_QUERY = "/model"; - public static final String TARGET_ENTITY = "DB"; - private SearchGraph searchGraph; private SchemaVersions schemaVersions; @@ -107,19 +105,12 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI { public Response processNamedQueryResponse(@Context HttpHeaders headers, @Context HttpServletRequest req, String queryParameters) { - String methodName = "getNamedQueryResponse"; AAIException ex = null; - Response response = null; - String fromAppId = null; - String transId = null; - double dbTimeMsecs = 0; - String rqstTm = genDate(); - ArrayList<String> templateVars = new ArrayList<String>(); + Response response; + String fromAppId; + String transId; + ArrayList<String> templateVars = new ArrayList<String>(); try { - LoggingContext.save(); - LoggingContext.targetEntity(TARGET_ENTITY); - LoggingContext.targetServiceName(methodName); - fromAppId = getFromAppId(headers); transId = getTransId(headers); @@ -127,29 +118,25 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI { aaiExtMap.setHttpHeaders(headers); aaiExtMap.setServletRequest(req); aaiExtMap.setApiVersion(schemaVersions.getDefaultVersion().toString()); - String realTime = headers.getRequestHeaders().getFirst("Real-Time"); - //only consider header value for search - DBConnectionType type = this.determineConnectionType("force-cache", realTime); - - LoggingContext.startTime(); - StopWatch.conditionalStart(); - - response = searchGraph.runNamedQuery(fromAppId, transId, queryParameters, type, aaiExtMap); - - dbTimeMsecs += StopWatch.stopIfStarted(); - LoggingContext.elapsedTime((long)dbTimeMsecs,TimeUnit.MILLISECONDS); - LoggingContext.successStatusFields(); - - - LOGGER.info ("Completed"); - - LoggingContext.restoreIfPossible(); - LoggingContext.successStatusFields(); - - String respTm = genDate(); + //only consider header value for search + + + AaiDBTraversalMetricLog metricLog = new AaiDBTraversalMetricLog (AAIConstants.AAI_TRAVERSAL_MS); + String uriString = req.getRequestURI(); + Optional<URI> o; + if (uriString != null) { + o = Optional.of(new URI(uriString)); + } + else { + o = Optional.empty(); + } + metricLog.pre(o); + + response = searchGraph.runNamedQuery(fromAppId, transId, queryParameters, aaiExtMap); + metricLog.post(); + //LOGGER.info ("Completed"); } catch (AAIException e) { - LoggingContext.restoreIfPossible(); // send error response ex = e; templateVars.add("POST Search"); @@ -159,7 +146,6 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI { .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars)) .build(); } catch (Exception e) { - LoggingContext.restoreIfPossible(); // send error response ex = new AAIException("AAI_4000", e); templateVars.add("POST Search"); @@ -214,20 +200,13 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI { @Context HttpServletRequest req, String inboundPayload, @QueryParam("action") String action) { - String methodName = "getModelQueryResponse"; AAIException ex = null; - Response response = null; - String fromAppId = null; - String transId = null; - double dbTimeMsecs = 0; - - String rqstTm = genDate(); - ArrayList<String> templateVars = new ArrayList<String>(); + Response response; + String fromAppId; + String transId; + + ArrayList<String> templateVars = new ArrayList<>(); try { - LoggingContext.save(); - LoggingContext.targetEntity(TARGET_ENTITY); - LoggingContext.targetServiceName(methodName); - fromAppId = getFromAppId(headers); transId = getTransId(headers); @@ -238,30 +217,28 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI { aaiExtMap.setFromAppId(fromAppId); aaiExtMap.setTransId(transId); - String realTime = headers.getRequestHeaders().getFirst("Real-Time"); - //only consider header value for search - DBConnectionType type = this.determineConnectionType("force-cache", realTime); - - LoggingContext.startTime(); - StopWatch.conditionalStart(); - + //only consider header value for search + + + AaiDBTraversalMetricLog metricLog = new AaiDBTraversalMetricLog (AAIConstants.AAI_TRAVERSAL_MS); + String uriString = req.getRequestURI(); + Optional<URI> o; + if (uriString != null) { + o = Optional.of(new URI(uriString)); + } + else { + o = Optional.empty(); + } + metricLog.pre(o); if (action != null && action.equalsIgnoreCase("DELETE")) { - response = searchGraph.executeModelOperation(fromAppId, transId, inboundPayload, type, true, aaiExtMap); + response = searchGraph.executeModelOperation(fromAppId, transId, inboundPayload, true, aaiExtMap); } else { - response = searchGraph.executeModelOperation(fromAppId, transId, inboundPayload, type, false, aaiExtMap); + response = searchGraph.executeModelOperation(fromAppId, transId, inboundPayload, false, aaiExtMap); } - dbTimeMsecs += StopWatch.stopIfStarted(); - LoggingContext.elapsedTime((long)dbTimeMsecs,TimeUnit.MILLISECONDS); - LoggingContext.successStatusFields(); - - LOGGER.info ("Completed"); - - LoggingContext.restoreIfPossible(); - LoggingContext.successStatusFields(); - String respTm = genDate(); - + metricLog.post(); + //LOGGER.info ("Completed"); + } catch (AAIException e) { - LoggingContext.restoreIfPossible(); // send error response ex = e; templateVars.add("POST Search"); @@ -271,7 +248,6 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI { .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars)) .build(); } catch (Exception e) { - LoggingContext.restoreIfPossible(); // send error response ex = new AAIException("AAI_4000", e); templateVars.add("POST Search"); diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/NodeQueryProcessor.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/NodeQueryProcessor.java index 6421f67..61f370b 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/NodeQueryProcessor.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/NodeQueryProcessor.java @@ -19,7 +19,8 @@ */ package org.onap.aai.rest.search; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit; @@ -41,7 +42,7 @@ import javax.ws.rs.core.MultivaluedMap; public class NodeQueryProcessor extends GroovyShellImpl { - private static EELFLogger LOGGER = EELFManager.getInstance().getLogger(NodeQueryProcessor.class); + private static Logger LOGGER = LoggerFactory.getLogger(NodeQueryProcessor.class); protected String nodeType; private MultivaluedMap<String, String> nodeQueryParams = new MultivaluedHashMap<String, String>(); @@ -106,7 +107,7 @@ public class NodeQueryProcessor extends GroovyShellImpl { // nothing to do, just exit return new ArrayList<>(); } - GraphTraversal<?, ?> g = this.runQuery(query, params); + GraphTraversal<?, ?> g = this.runQuery(query, params, dbEngine.asAdmin().getTraversalSource()); resultVertices.addAll(g.toList()); diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/SchemaServiceCQConfig.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/SchemaServiceCQConfig.java index 6e55246..ea1b62f 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/SchemaServiceCQConfig.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/SchemaServiceCQConfig.java @@ -19,12 +19,13 @@ */ package org.onap.aai.rest.search; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.onap.aai.restclient.RestClient; -import org.onap.aai.restclient.RestClientFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.ResponseEntity; import javax.annotation.PostConstruct; @@ -33,14 +34,15 @@ import java.util.Map; public class SchemaServiceCQConfig extends CQConfig { - private static EELFLogger logger = EELFManager.getInstance().getLogger(SchemaServiceCQConfig.class); + private static Logger logger = LoggerFactory.getLogger(SchemaServiceCQConfig.class); private static final String SCHEMA_SERVICE = "schema-service"; @Value("${schema.service.custom.queries.endpoint}") private String customQueriesUri; + @Qualifier("restClient") @Autowired - private RestClientFactory restClientFactory; + private RestClient restClient; @PostConstruct public void initialize() { @@ -55,8 +57,6 @@ public class SchemaServiceCQConfig extends CQConfig { logger.info("Calling the SchemaService to retrieve stored queries"); String content = ""; Map<String, String> headersMap = new HashMap<>(); - RestClient restClient = restClientFactory - .getRestClient(SCHEMA_SERVICE); ResponseEntity<String> schemaResponse = restClient.getGetRequest(content, customQueriesUri, headersMap); queryConfig = new GetCustomQueryConfig(schemaResponse.getBody()); diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java index 8c97c0a..75a19c9 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java @@ -19,48 +19,41 @@ */ package org.onap.aai.rest.search; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; +import org.onap.aai.aailog.logs.AaiDBTraversalMetricLog; +import org.onap.aai.concurrent.AaiCallable; import org.onap.aai.dbgraphmap.SearchGraph; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; import org.onap.aai.logging.ErrorLogHelper; -import org.onap.aai.logging.LoggingContext; -import org.onap.aai.logging.StopWatch; import org.onap.aai.restcore.HttpMethod; import org.onap.aai.restcore.RESTAPI; import org.onap.aai.serialization.db.DBSerializer; -import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.util.AAIConstants; import org.onap.aai.util.GenericQueryBuilder; import org.onap.aai.util.NodesQueryBuilder; import org.onap.aai.util.TraversalConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.onap.aai.concurrent.AaiCallable; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.springframework.beans.factory.annotation.Value; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.*; +import javax.ws.rs.core.*; +import javax.ws.rs.core.Response.Status; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + /** * Implements the search subdomain in the REST API. All API calls must include X-FromAppId and * X-TransactionId in the header. @@ -68,14 +61,12 @@ import org.springframework.beans.factory.annotation.Value; @Path("/{version: v[1-9][0-9]*|latest}/search") public class SearchProvider extends RESTAPI { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(SearchProvider.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SearchProvider.class); public static final String GENERIC_QUERY = "/generic-query"; public static final String NODES_QUERY = "/nodes-query"; - public static final String TARGET_ENTITY = "DB"; - private SearchGraph searchGraph; private LoaderFactory loaderFactory; @@ -130,51 +121,37 @@ public class SearchProvider extends RESTAPI { @QueryParam("include") final List<String> includeNodeTypes, @QueryParam("depth") final int depth, @PathParam("version") String versionParam) { - String methodName = "getGenericQueryResponse"; AAIException ex = null; - Response searchResult = null; - String fromAppId = null; - String transId = null; - String rqstTm = genDate(); - ArrayList<String> templateVars = new ArrayList<String>(); - double dbTimeMsecs = 0; + Response searchResult; + String fromAppId; + ArrayList<String> templateVars = new ArrayList<>(); try { - LoggingContext.save(); - LoggingContext.targetEntity(TARGET_ENTITY); - LoggingContext.targetServiceName(methodName); fromAppId = getFromAppId(headers); - transId = getTransId(headers); - String realTime = headers.getRequestHeaders().getFirst("Real-Time"); + getTransId(headers); // only consider header value for search - DBConnectionType type = this.determineConnectionType("force-cache", realTime); final SchemaVersion version = new SchemaVersion(versionParam); final ModelType factoryType = ModelType.MOXY; Loader loader = loaderFactory.createLoaderForVersion(factoryType, version); - TransactionalGraphEngine dbEngine = new JanusGraphDBEngine(QueryStyle.TRAVERSAL, type, loader); + TransactionalGraphEngine dbEngine = new JanusGraphDBEngine(QueryStyle.TRAVERSAL, loader); DBSerializer dbSerializer = new DBSerializer(version, dbEngine, factoryType, fromAppId); UrlBuilder urlBuilder = new UrlBuilder(version, dbSerializer, schemaVersions, this.basePath); - LoggingContext.startTime(); - StopWatch.conditionalStart(); + + AaiDBTraversalMetricLog metricLog = new AaiDBTraversalMetricLog (AAIConstants.AAI_TRAVERSAL_MS); + metricLog.pre(Optional.of(new URI(req.getRequestURI()))); + searchResult = searchGraph .runGenericQuery(new GenericQueryBuilder().setHeaders(headers).setStartNodeType(startNodeType) .setStartNodeKeyParams(startNodeKeyParams).setIncludeNodeTypes(includeNodeTypes) .setDepth(depth).setDbEngine(dbEngine).setLoader(loader).setUrlBuilder(urlBuilder)); - dbTimeMsecs += StopWatch.stopIfStarted(); - - LoggingContext.successStatusFields(); - LoggingContext.elapsedTime((long) dbTimeMsecs, TimeUnit.MILLISECONDS); - LOGGER.info("Completed"); - LoggingContext.restoreIfPossible(); - LoggingContext.successStatusFields(); + metricLog.post(); - String respTm = genDate(); + //LOGGER.info("Completed"); } catch (AAIException e) { - LoggingContext.restoreIfPossible(); // send error response ex = e; templateVars.add("GET Search"); @@ -183,7 +160,6 @@ public class SearchProvider extends RESTAPI { .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars)) .build(); } catch (Exception e) { - LoggingContext.restoreIfPossible(); // send error response ex = new AAIException("AAI_4000", e); templateVars.add("GET Search"); @@ -239,50 +215,37 @@ public class SearchProvider extends RESTAPI { @QueryParam("search-node-type") final String searchNodeType, @QueryParam("edge-filter") final List<String> edgeFilterList, @QueryParam("filter") final List<String> filterList, @PathParam("version") String versionParam) { - String methodName = "getNodesQueryResponse"; + AAIException ex = null; - Response searchResult = null; - String fromAppId = null; - String transId = null; - String rqstTm = genDate(); - ArrayList<String> templateVars = new ArrayList<String>(); - double dbTimeMsecs = 0; + Response searchResult; + String fromAppId; + ArrayList<String> templateVars = new ArrayList<>(); try { - LoggingContext.save(); - LoggingContext.targetEntity(TARGET_ENTITY); - LoggingContext.targetServiceName(methodName); fromAppId = getFromAppId(headers); - transId = getTransId(headers); + getTransId(headers); String realTime = headers.getRequestHeaders().getFirst("Real-Time"); // only consider header value for search - DBConnectionType type = this.determineConnectionType("force-cache", realTime); final SchemaVersion version = new SchemaVersion(versionParam); final ModelType factoryType = ModelType.MOXY; Loader loader = loaderFactory.createLoaderForVersion(factoryType, version); - TransactionalGraphEngine dbEngine = new JanusGraphDBEngine(QueryStyle.TRAVERSAL, type, loader); + TransactionalGraphEngine dbEngine = new JanusGraphDBEngine(QueryStyle.TRAVERSAL, loader); DBSerializer dbSerializer = new DBSerializer(version, dbEngine, factoryType, fromAppId); UrlBuilder urlBuilder = new UrlBuilder(version, dbSerializer, schemaVersions, this.basePath); - LoggingContext.startTime(); - StopWatch.conditionalStart(); + + AaiDBTraversalMetricLog metricLog = new AaiDBTraversalMetricLog (AAIConstants.AAI_TRAVERSAL_MS); + metricLog.pre(Optional.of(new URI(req.getRequestURI()))); searchResult = searchGraph.runNodesQuery(new NodesQueryBuilder().setHeaders(headers) .setTargetNodeType(searchNodeType).setEdgeFilterParams(edgeFilterList).setFilterParams(filterList) .setDbEngine(dbEngine).setLoader(loader).setUrlBuilder(urlBuilder)); - dbTimeMsecs += StopWatch.stopIfStarted(); - LoggingContext.elapsedTime((long) dbTimeMsecs, TimeUnit.MILLISECONDS); - LoggingContext.successStatusFields(); - LOGGER.info("Completed"); - - LoggingContext.restoreIfPossible(); - LoggingContext.successStatusFields(); + metricLog.post(); + //LOGGER.info("Completed"); - String respTm = genDate(); } catch (AAIException e) { - LoggingContext.restoreIfPossible(); // send error response ex = e; templateVars.add("GET Search"); @@ -291,7 +254,6 @@ public class SearchProvider extends RESTAPI { .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars)) .build(); } catch (Exception e) { - LoggingContext.restoreIfPossible(); // send error response ex = new AAIException("AAI_4000", e); templateVars.add("GET Search"); diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/util/AAIExtensionMap.java b/aai-traversal/src/main/java/org/onap/aai/rest/util/AAIExtensionMap.java new file mode 100644 index 0000000..0aa70e3 --- /dev/null +++ b/aai-traversal/src/main/java/org/onap/aai/rest/util/AAIExtensionMap.java @@ -0,0 +1,826 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.aai.rest.util; + +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; +import org.onap.aai.domain.responseMessage.AAIResponseMessages; +import org.onap.aai.introspection.Loader; +import org.onap.aai.rest.db.DBRequest; +import org.onap.aai.rest.db.HttpEntry; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.UriInfo; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; + +public class AAIExtensionMap { + // ======================================================================= + // Attribute | Type + // ======================================================================= + // message | java.lang.String (RW) + // ---------------------------------------------------------------------- + // templateVars | java.lang.ArrayList<String> (RW) + // ----------------------------------------------------------------------- + // preExtException | java.lang.Exception (RW) + // ----------------------------------------------------------------------- + // preExtErrorCallback | java.lang.reflect.Method (RW) + // ----------------------------------------------------------------------- + // postExtException | java.lang.Exception (RW) + // ----------------------------------------------------------------------- + // postExtErrorCallback | java.lang.reflect.Method (RW) + // ----------------------------------------------------------------------- + // servletRequest | javax.servlet.http.HttpServletRequest (RO) + // ----------------------------------------------------------------------- + // headers | javax.ws.rs.core.HttpHeaders (RO) + // ----------------------------------------------------------------------- + // objFromRequestType | String (ex. ?org.onap.aai.domain.yang.Vce?) (RO) + // ----------------------------------------------------------------------- + // objFromRequest | $TYPE {ObjFromRequestType) (RO) + // ----------------------------------------------------------------------- + // preExtFailOnError | java.lang.Boolean (RW) + // ----------------------------------------------------------------------- + // postExtFailOnError | java.lang.Boolean (RW) + // ----------------------------------------------------------------------- + // preExtSkipErrorCallback | java.lang.Boolean (RW) + // ----------------------------------------------------------------------- + // postExtSkipErrorCallback | java.lang.Boolean (RW) + // ----------------------------------------------------------------------- + // graph | org.janusgraph.core.JanusGraph (RW) + // ----------------------------------------------------------------------- + // objectFromResponse | Object + // ----------------------------------------------------------------------- + // precheckAddedList | java.util.HashMap + // ----------------------------------------------------------------------- + // precheckResponseMessages | org.onap.aai.extensions.AAIResponseMessages + // ======================================================================= + + private String message; + private ArrayList<String> templateVars; + private Exception preExtException; + private Exception postExtException; + private Method preExtErrorCallback; + private Method postExtErrorCallback; + private HttpServletRequest servletRequest; + private HttpHeaders httpHeaders; + private String objectFromRequestType; + private Object objectFromRequest; + private boolean preExtFailOnError = true; + private boolean postExtFailOnError = true; + private boolean preExtSkipErrorCallback = true; + private boolean postExtSkipErrorCallback = true; + private String fromAppId; + private String transId; + private Graph graph; + private Object objectFromResponse; + private HashMap<String, Object> lookupHashMap; + private HashMap<String, ArrayList<String>> precheckAddedList; + private AAIResponseMessages precheckResponseMessages; + private HashMap<String, Object> topology; + private HashMap<String, Vertex> vertexCache; + private String baseObject; + private String namespace; + private String fullResourceName; + private String topObjectFullResourceName; + private String uri; + private String notificationUri; + private String apiVersion; + private long startTime; + private long checkpointTime; + private DynamicJAXBContext jaxbContext; + private String objectFromResponseType; + private String eventAction; + private TransactionalGraphEngine dbEngine; + private Loader loader; + private UriInfo uriInfo; + private DBRequest dbRequest; + private HttpEntry httpEntry; + + /** + * Sets the message. + * + * @param _message the new message + */ + public void setMessage(String _message) { + this.message = _message; + } + + /** + * Sets the template vars. + * + * @param _templateVars the new template vars + */ + public void setTemplateVars(ArrayList<String> _templateVars) { + this.templateVars = _templateVars; + } + + /** + * Sets the pre ext exception. + * + * @param _exception the new pre ext exception + */ + public void setPreExtException(Exception _exception) { + this.preExtException = _exception; + } + + /** + * Sets the pre ext error callback. + * + * @param _errorCallback the new pre ext error callback + */ + public void setPreExtErrorCallback(Method _errorCallback) { + this.preExtErrorCallback = _errorCallback; + } + + /** + * Sets the post ext exception. + * + * @param _exception the new post ext exception + */ + public void setPostExtException(Exception _exception) { + this.postExtException = _exception; + } + + /** + * Sets the post ext error callback. + * + * @param _errorCallback the new post ext error callback + */ + public void setPostExtErrorCallback(Method _errorCallback) { + this.postExtErrorCallback = _errorCallback; + } + + /** + * Sets the servlet request. + * + * @param _httpServletRequest the new servlet request + */ + public void setServletRequest(HttpServletRequest _httpServletRequest) { + this.servletRequest = _httpServletRequest; + } + + /** + * Sets the http headers. + * + * @param _httpHeaders the new http headers + */ + public void setHttpHeaders(HttpHeaders _httpHeaders) { + this.httpHeaders = _httpHeaders; + } + + /** + * Sets the object from request type. + * + * @param _objectFromRequestType the new object from request type + */ + public void setObjectFromRequestType(String _objectFromRequestType) { + this.objectFromRequestType = _objectFromRequestType; + } + + /** + * Sets the object from request. + * + * @param _objectFromRequest the new object from request + */ + public void setObjectFromRequest(Object _objectFromRequest) { + this.objectFromRequest = _objectFromRequest; + } + + /** + * Sets the object from response type. + * + * @param resourceClassName the new object from response type + */ + public void setObjectFromResponseType(String resourceClassName) { + // TODO Auto-generated method stub + this.objectFromResponseType = resourceClassName; + } + + /** + * Gets the object from response type. + * + * @return the object from response type + */ + public String getObjectFromResponseType() { + // TODO Auto-generated method stub + return this.objectFromResponseType; + } + + /** + * Sets the pre ext fail on error. + * + * @param _failOnError the new pre ext fail on error + */ + public void setPreExtFailOnError(boolean _failOnError) { + this.preExtFailOnError = _failOnError; + } + + /** + * Sets the post ext fail on error. + * + * @param _failOnError the new post ext fail on error + */ + public void setPostExtFailOnError(boolean _failOnError) { + this.postExtFailOnError = _failOnError; + } + + /** + * Gets the message. + * + * @return the message + */ + public String getMessage() { + return this.message; + } + + /** + * Gets the template vars. + * + * @return the template vars + */ + public ArrayList<String> getTemplateVars() { + if (this.templateVars == null) { + this.templateVars = new ArrayList<String>(); + } + return this.templateVars; + } + + /** + * Gets the pre ext exception. + * + * @return the pre ext exception + */ + public Exception getPreExtException() { + return this.preExtException; + } + + /** + * Gets the pre ext error callback. + * + * @return the pre ext error callback + */ + public Method getPreExtErrorCallback() { + return this.preExtErrorCallback; + } + + /** + * Gets the post ext exception. + * + * @return the post ext exception + */ + public Exception getPostExtException() { + return this.postExtException; + } + + /** + * Gets the post ext error callback. + * + * @return the post ext error callback + */ + public Method getPostExtErrorCallback() { + return this.postExtErrorCallback; + } + + /** + * Gets the http servlet request. + * + * @return the http servlet request + */ + public HttpServletRequest getHttpServletRequest() { + return this.servletRequest; + } + + /** + * Gets the http headers. + * + * @return the http headers + */ + public HttpHeaders getHttpHeaders() { + return this.httpHeaders; + } + + /** + * Gets the object from request type. + * + * @return the object from request type + */ + public String getObjectFromRequestType() { + return this.objectFromRequestType; + } + + /** + * Gets the object from request. + * + * @return the object from request + */ + public Object getObjectFromRequest() { + return this.objectFromRequest; + } + + /** + * Gets the pre ext fail on error. + * + * @return the pre ext fail on error + */ + public boolean getPreExtFailOnError() { + return this.preExtFailOnError; + } + + /** + * Gets the post ext fail on error. + * + * @return the post ext fail on error + */ + public boolean getPostExtFailOnError() { + return this.postExtFailOnError; + } + + /** + * Gets the from app id. + * + * @return the from app id + */ + public String getFromAppId() { + return this.fromAppId; + } + + /** + * Sets the from app id. + * + * @param fromAppId the new from app id + */ + public void setFromAppId(String fromAppId) { + this.fromAppId = fromAppId; + } + + /** + * Gets the trans id. + * + * @return the trans id + */ + public String getTransId() { + return this.transId; + } + + /** + * Sets the trans id. + * + * @param transId the new trans id + */ + public void setTransId(String transId) { + this.transId = transId; + } + + /** + * Gets the pre ext skip error callback. + * + * @return the pre ext skip error callback + */ + public boolean getPreExtSkipErrorCallback() { + return preExtSkipErrorCallback; + } + + /** + * Sets the pre ext skip error callback. + * + * @param preExtSkipErrorCallback the new pre ext skip error callback + */ + public void setPreExtSkipErrorCallback(boolean preExtSkipErrorCallback) { + this.preExtSkipErrorCallback = preExtSkipErrorCallback; + } + + /** + * Gets the post ext skip error callback. + * + * @return the post ext skip error callback + */ + public boolean getPostExtSkipErrorCallback() { + return postExtSkipErrorCallback; + } + + /** + * Sets the post ext skip error callback. + * + * @param postExtSkipErrorCallback the new post ext skip error callback + */ + public void setPostExtSkipErrorCallback(boolean postExtSkipErrorCallback) { + this.postExtSkipErrorCallback = postExtSkipErrorCallback; + } + + /** + * Gets the graph. + * + * @return the graph + */ + public Graph getGraph() { + return graph; + } + + /** + * Sets the graph. + * + * @param graph the new graph + */ + public void setGraph(Graph graph) { + this.graph = graph; + } + + /** + * Gets the object from response. + * + * @return the object from response + */ + public Object getObjectFromResponse() { + return objectFromResponse; + } + + /** + * Sets the object from response. + * + * @param objectFromResponse the new object from response + */ + public void setObjectFromResponse(Object objectFromResponse) { + this.objectFromResponse = objectFromResponse; + } + + /** + * Gets the lookup hash map. + * + * @return the lookup hash map + */ + public HashMap<String, Object> getLookupHashMap() { + if (this.lookupHashMap == null) { + this.lookupHashMap = new HashMap<String, Object>(); + } + return this.lookupHashMap; + } + + /** + * Sets the lookup hash map. + * + * @param lookupHashMap the lookup hash map + */ + public void setLookupHashMap(HashMap<String, Object> lookupHashMap) { + this.lookupHashMap = lookupHashMap; + } + + /** + * Gets the precheck added list. + * + * @return the precheck added list + */ + public HashMap<String, ArrayList<String>> getPrecheckAddedList() { + if (this.precheckAddedList == null) { + this.precheckAddedList = new HashMap<String, ArrayList<String>>(); + } + return precheckAddedList; + } + + /** + * Sets the precheck added list. + * + * @param precheckAddedList the precheck added list + */ + public void setPrecheckAddedList(HashMap<String, ArrayList<String>> precheckAddedList) { + this.precheckAddedList = precheckAddedList; + } + + /** + * Gets the precheck response messages. + * + * @return the precheck response messages + */ + public AAIResponseMessages getPrecheckResponseMessages() { + if (this.precheckResponseMessages == null) { + this.precheckResponseMessages = new AAIResponseMessages(); + } + return precheckResponseMessages; + } + + /** + * Sets the precheck response messages. + * + * @param precheckResponseData the new precheck response messages + */ + public void setPrecheckResponseMessages(AAIResponseMessages precheckResponseData) { + this.precheckResponseMessages = precheckResponseData; + } + + /** + * Gets the topology. + * + * @return the topology + */ + public HashMap<String, Object> getTopology() { + if (this.topology == null) { + this.topology = new HashMap<String, Object>(); + } + return topology; + } + + /** + * Gets the vertex cache. + * + * @return the vertex cache + */ + public HashMap<String, Vertex> getVertexCache() { + if (this.vertexCache == null) { + this.vertexCache = new HashMap<String, Vertex>(); + } + return vertexCache; + } + + /** + * Gets the base object. + * + * @return the base object + */ + public String getBaseObject() { + return baseObject; + } + + /** + * Sets the base object. + * + * @param baseObject the new base object + */ + public void setBaseObject(String baseObject) { + this.baseObject = baseObject; + } + + /** + * Gets the namespace. + * + * @return the namespace + */ + public String getNamespace() { + return namespace; + } + + /** + * Sets the namespace. + * + * @param namespace the new namespace + */ + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + /** + * Gets the full resource name. + * + * @return the full resource name + */ + public String getFullResourceName() { + return fullResourceName; + } + + /** + * Sets the full resource name. + * + * @param fullResourceName the new full resource name + */ + public void setFullResourceName(String fullResourceName) { + this.fullResourceName = fullResourceName; + } + + /** + * Gets the top object full resource name. + * + * @return the top object full resource name + */ + public String getTopObjectFullResourceName() { + return topObjectFullResourceName; + } + + /** + * Sets the top object full resource name. + * + * @param topObjectFullResourceName the new top object full resource name + */ + public void setTopObjectFullResourceName(String topObjectFullResourceName) { + this.topObjectFullResourceName = topObjectFullResourceName; + } + + /** + * Gets the uri. + * + * @return the uri + */ + public String getUri() { + return uri; + } + + /** + * Sets the uri. + * + * @param uri the new uri + */ + public void setUri(String uri) { + this.uri = uri; + } + + /** + * Gets the api version. + * + * @return the api version + */ + public String getApiVersion() { + return apiVersion; + } + + /** + * Sets the api version. + * + * @param apiVersion the new api version + */ + public void setApiVersion(String apiVersion) { + this.apiVersion = apiVersion; + } + + /** + * Sets the notification uri. + * + * @param uri the new notification uri + */ + public void setNotificationUri(String uri) { + this.notificationUri = uri; + + } + + /** + * Gets the notification uri. + * + * @return the notification uri + */ + public String getNotificationUri() { + return this.notificationUri; + + } + + /** + * Gets the start time. + * + * @return the start time + */ + public long getStartTime() { + return startTime; + } + + /** + * Sets the start time. + * + * @param startTime the new start time + */ + public void setStartTime(long startTime) { + this.startTime = startTime; + } + + /** + * Gets the checkpoint time. + * + * @return the checkpoint time + */ + public long getCheckpointTime() { + return checkpointTime; + } + + /** + * Sets the checkpoint time. + * + * @param checkpointTime the new checkpoint time + */ + public void setCheckpointTime(long checkpointTime) { + this.checkpointTime = checkpointTime; + } + + /** + * Gets the jaxb context. + * + * @return the jaxb context + */ + public DynamicJAXBContext getJaxbContext() { + return jaxbContext; + } + + /** + * Sets the jaxb context. + * + * @param jaxbContext the new jaxb context + */ + public void setJaxbContext(DynamicJAXBContext jaxbContext) { + this.jaxbContext = jaxbContext; + } + + /** + * Sets the event action. + * + * @param eventAction the new event action + */ + public void setEventAction(String eventAction) { + this.eventAction = eventAction; + } + + /** + * Gets the event action. + * + * @return the event action + */ + public String getEventAction() { + return this.eventAction; + } + + /** + * Gets the transactional graph engine. + * + * @return the transactional graph engine + */ + public TransactionalGraphEngine getTransactionalGraphEngine() { + return this.dbEngine; + + } + + /** + * Sets the transactional graph engine. + * + * @param dbEngine the new transactional graph engine + */ + public void setTransactionalGraphEngine(TransactionalGraphEngine dbEngine) { + this.dbEngine = dbEngine; + + } + + /** + * Gets the loader. + * + * @return the loader + */ + public Loader getLoader() { + return loader; + } + + /** + * Sets the loader. + * + * @param loader the new loader + */ + public void setLoader(Loader loader) { + this.loader = loader; + } + + /** + * Gets the uri info. + * + * @return the uri info + */ + public UriInfo getUriInfo() { + return uriInfo; + } + + /** + * Sets the uri info. + * + * @param uriInfo the new uri info + */ + public void setUriInfo(UriInfo uriInfo) { + this.uriInfo = uriInfo; + } + + public DBRequest getDbRequest() { + return dbRequest; + } + + public void setDbRequest(DBRequest dbRequest) { + this.dbRequest = dbRequest; + } + + public HttpEntry getHttpEntry() { + return httpEntry; + } + + public void setHttpEntry(HttpEntry httpEntry) { + this.httpEntry = httpEntry; + } +} diff --git a/aai-traversal/src/main/java/org/onap/aai/service/AuthorizationService.java b/aai-traversal/src/main/java/org/onap/aai/service/AuthorizationService.java index 2bb2794..c0fa93e 100644 --- a/aai-traversal/src/main/java/org/onap/aai/service/AuthorizationService.java +++ b/aai-traversal/src/main/java/org/onap/aai/service/AuthorizationService.java @@ -19,7 +19,8 @@ */ package org.onap.aai.service; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.eclipse.jetty.util.security.Password; import org.onap.aai.Profiles; @@ -41,7 +42,7 @@ import java.util.stream.Stream; @Profile(Profiles.ONE_WAY_SSL) public class AuthorizationService { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(AuthorizationService.class); + private static final Logger logger = LoggerFactory.getLogger(AuthorizationService.class); private final Map<String, String> authorizedUsers = new HashMap<>(); @@ -72,7 +73,7 @@ public class AuthorizationService { String[] usernamePasswordArray = usernamePassword.split(":"); if(usernamePasswordArray == null || usernamePasswordArray.length != 3){ - throw new RuntimeException("Not a valid entry for the realm.properties entry: " + usernamePassword); + throw new RuntimeException("This username / pwd is not a valid entry in realm.properties"); } String username = usernamePasswordArray[0]; diff --git a/aai-traversal/src/main/java/org/onap/aai/transforms/MapTraverser.java b/aai-traversal/src/main/java/org/onap/aai/transforms/MapTraverser.java index 36c453a..9091998 100644 --- a/aai-traversal/src/main/java/org/onap/aai/transforms/MapTraverser.java +++ b/aai-traversal/src/main/java/org/onap/aai/transforms/MapTraverser.java @@ -19,13 +19,14 @@ */ package org.onap.aai.transforms; + +import joptsimple.internal.Objects; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.collections.MapUtils; - public class MapTraverser { private Converter converter; @@ -36,9 +37,8 @@ public class MapTraverser { public Map<String, Object> convertKeys(Map<String, Object> map){ - if (MapUtils.isEmpty(map)) { - throw new NullPointerException("map cannot be null"); - } + Objects.ensureNotNull(map); + Map<String, Object> modifiedMap = new HashMap<String, Object>(); convertKeys(map, modifiedMap); diff --git a/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java b/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java index 503cf6c..4a80f58 100644 --- a/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java +++ b/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java @@ -26,7 +26,8 @@ import java.util.List; import java.util.Map.Entry; import java.util.UUID; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.apache.commons.io.FileUtils; import org.onap.aai.config.SpringContextAware; @@ -41,7 +42,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext public class MakeNamedQuery { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(MakeNamedQuery.class.getName()); + private static final Logger logger = LoggerFactory.getLogger(MakeNamedQuery.class.getName()); public static void main(String[] args) throws Exception { String _apiVersion = AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP); diff --git a/aai-traversal/src/main/java/org/onap/aai/util/TraversalConstants.java b/aai-traversal/src/main/java/org/onap/aai/util/TraversalConstants.java index 4b5ebfe..fdeefe1 100644 --- a/aai-traversal/src/main/java/org/onap/aai/util/TraversalConstants.java +++ b/aai-traversal/src/main/java/org/onap/aai/util/TraversalConstants.java @@ -31,7 +31,8 @@ public final class TraversalConstants { public static final String AAI_TRAVERSAL_DSL_TIMEOUT_APP = "aai.traversal.dsl.timeout.appspecific"; public static final String DSL_NOVALIDATION_CLIENTS = "aai.traversal.dsl.novalidation.clients"; public static final String DSL_OVERRIDE = "aai.dsl.override"; - + public static final String DSL_MAX_NODE_COUNT = "15"; + public static final long HISTORY_MAX_HOURS = 192; private TraversalConstants() { diff --git a/aai-traversal/src/main/java/org/onap/aai/web/JerseyConfiguration.java b/aai-traversal/src/main/java/org/onap/aai/web/JerseyConfiguration.java index ab3c9fd..e6cf080 100644 --- a/aai-traversal/src/main/java/org/onap/aai/web/JerseyConfiguration.java +++ b/aai-traversal/src/main/java/org/onap/aai/web/JerseyConfiguration.java @@ -19,131 +19,131 @@ */ package org.onap.aai.web; +import jersey.repackaged.com.google.common.collect.Sets; import org.glassfish.jersey.filter.LoggingFilter; import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.servlet.ServletProperties; -import org.onap.aai.rest.CQ2Gremlin; -import org.onap.aai.rest.CQ2GremlinTest; -import org.onap.aai.rest.DslConsumer; -import org.onap.aai.rest.QueryConsumer; -import org.onap.aai.rest.RecentAPIConsumer; +import org.onap.aai.aailog.logs.AaiDebugLog; +import org.onap.aai.rest.*; import org.onap.aai.rest.search.ModelAndNamedQueryRestProvider; import org.onap.aai.rest.search.SearchProvider; import org.onap.aai.rest.util.EchoResponse; -import org.reflections.Reflections; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; import javax.annotation.Priority; -import javax.ws.rs.container.ContainerRequestFilter; -import javax.ws.rs.container.ContainerResponseFilter; - -import java.util.List; +import java.lang.reflect.AnnotatedElement; +import java.util.Collection; +import java.util.Comparator; import java.util.Set; import java.util.logging.Logger; -import java.util.stream.Collectors; -@Component -public class JerseyConfiguration extends ResourceConfig { +import static java.lang.Boolean.parseBoolean; +import static java.util.Comparator.comparingInt; - private static final Logger log = Logger.getLogger(JerseyConfiguration.class.getName()); +@Configuration +public class JerseyConfiguration { - private Environment env; + private static final Logger log = Logger.getLogger(JerseyConfiguration.class.getName()); + private static final org.slf4j.Logger logger = LoggerFactory.getLogger(JerseyConfiguration.class.getName()); - @Autowired - public JerseyConfiguration(Environment env) { - - this.env = env; - - register(SearchProvider.class); - register(ModelAndNamedQueryRestProvider.class); - register(QueryConsumer.class); - register(RecentAPIConsumer.class); - register(DslConsumer.class); - register(EchoResponse.class); - register(CQ2Gremlin.class); - register(CQ2GremlinTest.class); - - //Request Filters - registerFiltersForRequests(); - // Response Filters - registerFiltersForResponses(); - - property(ServletProperties.FILTER_FORWARD_ON_404, true); - - // Following registers the request headers and response headers - // If the LoggingFilter second argument is set to true, it will print response value as well - if ("true".equalsIgnoreCase(env.getProperty("aai.request.logging.enabled"))) { - register(new LoggingFilter(log, false)); - } + private static AaiDebugLog debugLog = new AaiDebugLog(); + static { + debugLog.setupMDC(); } - public void registerFiltersForRequests() { + private static final String LOGGING_ENABLED_PROPERTY = "aai.request.logging.enabled"; + private static final boolean ENABLE_RESPONSE_LOGGING = false; + + private final Environment environment; - // Find all the classes within the interceptors package - Reflections reflections = new Reflections("org.onap.aai.interceptors"); - // Filter them based on the clazz that was passed in - Set<Class<? extends ContainerRequestFilter>> filters = reflections.getSubTypesOf(ContainerRequestFilter.class); + @Autowired + public JerseyConfiguration(Environment environment) { + this.environment = environment; + } + @Bean + public ResourceConfig resourceConfig() { + ResourceConfig resourceConfig = new ResourceConfig(); + + Set<Class<?>> classes = Sets.newHashSet( + SearchProvider.class, + ModelAndNamedQueryRestProvider.class, + QueryConsumer.class, + RecentAPIConsumer.class, + DslConsumer.class, + EchoResponse.class, + CQ2Gremlin.class, + CQ2GremlinTest.class + ); + Set<Class<?>> filterClasses = Sets.newHashSet( + org.onap.aai.aailog.filter.AaiAuditLogContainerFilter.class, + org.onap.aai.interceptors.pre.RequestTransactionLogging.class, + org.onap.aai.interceptors.pre.HeaderValidation.class, + org.onap.aai.interceptors.pre.HttpHeaderInterceptor.class, + org.onap.aai.interceptors.pre.OneWaySslAuthorization.class, + org.onap.aai.interceptors.pre.VersionLatestInterceptor.class, + org.onap.aai.interceptors.pre.RetiredInterceptor.class, + org.onap.aai.interceptors.pre.VersionInterceptor.class, + org.onap.aai.interceptors.pre.RequestHeaderManipulation.class, + org.onap.aai.interceptors.pre.RequestModification.class, + org.onap.aai.interceptors.post.InvalidResponseStatus.class, + org.onap.aai.interceptors.post.ResponseTransactionLogging.class, + org.onap.aai.interceptors.post.ResponseHeaderManipulation.class + ); + if (isLoggingEnabled()) { + logRequests(resourceConfig); + } + resourceConfig.registerClasses(classes); + logger.debug("REGISTERED CLASSES " + classes.toString()); + + throwIfPriorityAnnotationAbsent(filterClasses); + filterClasses.stream() + .filter(this::isEnabledByActiveProfiles) + .sorted(priorityComparator()) + .forEach(resourceConfig::register); + + filterClasses.stream() + .filter(this::isEnabledByActiveProfiles) + .sorted(priorityComparator()) + .forEach(s -> logger.debug("REGISTERED FILTERS " + s.getName())); + return resourceConfig; + } - // Check to ensure that each of the filter has the @Priority annotation and if not throw exception - for (Class filterClass : filters) { - if (filterClass.getAnnotation(Priority.class) == null) { - throw new RuntimeException("Container filter " + filterClass.getName() + " does not have @Priority annotation"); + private <T> void throwIfPriorityAnnotationAbsent(Collection<Class<? extends T>> classes) { + for (Class clazz : classes) { + if (!clazz.isAnnotationPresent(Priority.class)) { + logger.debug("throwIfPriorityAnnotationAbsent: missing filter priority for : " + clazz.getName()); + throw new MissingFilterPriorityException(clazz); } } + } - // Turn the set back into a list - List<Class<? extends ContainerRequestFilter>> filtersList = filters - .stream() - .filter(f -> { - if (f.isAnnotationPresent(Profile.class) - && !env.acceptsProfiles(f.getAnnotation(Profile.class).value())) { - return false; - } - return true; - }) - .collect(Collectors.toList()); - - // Sort them by their priority levels value - filtersList.sort((c1, c2) -> Integer.valueOf(c1.getAnnotation(Priority.class).value()).compareTo(c2.getAnnotation(Priority.class).value())); - - // Then register this to the jersey application - filtersList.forEach(this::register); + private <T> Comparator<Class<? extends T>> priorityComparator() { + return comparingInt(clazz -> clazz.getAnnotation(Priority.class).value()); } - public void registerFiltersForResponses() { + private void logRequests(ResourceConfig resourceConfig) { + resourceConfig.register(new LoggingFilter(log, ENABLE_RESPONSE_LOGGING)); + } - // Find all the classes within the interceptors package - Reflections reflections = new Reflections("org.onap.aai.interceptors"); - // Filter them based on the clazz that was passed in - Set<Class<? extends ContainerResponseFilter>> filters = reflections.getSubTypesOf(ContainerResponseFilter.class); + private boolean isLoggingEnabled() { + return parseBoolean(environment.getProperty(LOGGING_ENABLED_PROPERTY)); + } + private boolean isEnabledByActiveProfiles(AnnotatedElement annotatedElement) { + boolean result = !annotatedElement.isAnnotationPresent(Profile.class) || + environment.acceptsProfiles(annotatedElement.getAnnotation(Profile.class).value()); + logger.debug("isEnabledByActiveProfiles: annotatedElement: " + annotatedElement.toString() + " result=" + result); + return result; + } - // Check to ensure that each of the filter has the @Priority annotation and if not throw exception - for (Class filterClass : filters) { - if (filterClass.getAnnotation(Priority.class) == null) { - throw new RuntimeException("Container filter " + filterClass.getName() + " does not have @Priority annotation"); - } + private class MissingFilterPriorityException extends RuntimeException { + private MissingFilterPriorityException(Class<?> clazz) { + super("Container filter " + clazz.getName() + " does not have @Priority annotation"); } - - // Turn the set back into a list - List<Class<? extends ContainerResponseFilter>> filtersList = filters.stream() - .filter(f -> { - if (f.isAnnotationPresent(Profile.class) - && !env.acceptsProfiles(f.getAnnotation(Profile.class).value())) { - return false; - } - return true; - }) - .collect(Collectors.toList()); - - // Sort them by their priority levels value - filtersList.sort((c1, c2) -> Integer.valueOf(c1.getAnnotation(Priority.class).value()).compareTo(c2.getAnnotation(Priority.class).value())); - - // Then register this to the jersey application - filtersList.forEach(this::register); } -} +}
\ No newline at end of file diff --git a/aai-traversal/src/main/resources/aaf/onap/aai b/aai-traversal/src/main/resources/aaf/onap/aai Binary files differnew file mode 100644 index 0000000..093c773 --- /dev/null +++ b/aai-traversal/src/main/resources/aaf/onap/aai diff --git a/aai-traversal/src/main/resources/aaf/onap/org.onap.aai.keyfile b/aai-traversal/src/main/resources/aaf/onap/org.onap.aai.keyfile new file mode 100644 index 0000000..3416d4a --- /dev/null +++ b/aai-traversal/src/main/resources/aaf/onap/org.onap.aai.keyfile @@ -0,0 +1,27 @@ +2otP92kNFHdexroZxvgYY7ffslFiwCD3CiVYMIfUF2edqZK7972NwkvE_mbaBo6jh8lByLIqrWAf +jyzoiVsvQ_kCa0cS1xaRLpcxv3bx1b7o3hGPBqpd6vmSG4y2JLzNlCBZWuTJz827wr8p_fWrYuUm +4L1WoaEe8W5PRnXjl4hDqbJBAlEoRIBXugUDt_7O5wgx2Rl3HVoOczZtf0RzONZ1F0BmKf3QlAUe +moSbARitYRgIPt5sLbT7qPyoEpGDhQ1XBowR744-wsjBc-14yO62Ajp5xWKTp15uWn3_HHuw1SAf +GWSBRGlSlEVkXQqi9Hw5jDttKVzHX1ckwR0SQOirbtHPHplxPX3WKjKhSdSeMzw6LOAHIQYRMKBT +74oGnULAfPtV7TaGwOKriT3P49CoPdt9On89-LGyCZSxDWKH0K-rgB6I2_hPT2Uzr3jmXiMa-sfh +iMvyQ7ABBVx0OFsUuNb5mcU2O6dWiQreL5RerrloV_X3ZtnNjxENXKjQ5KBR1A5ISPjFFK-kf4Rb +p6FSII8LcsiqgdWuZ4GX_C6x8HX4A-vD0x3Uc9CfoXY-k23cNIy-R-W-oB-P2OgdWDNgZ7VaOLNt +3L-NwWpNblfYvs93cNmkbVAwCZ3r0OP7RFeuON84TRaynK_Fh2S3rypRyJcUmM1pvpZqJ5_-umSW +hUs1OqkdLv3xjlVzzK-3nMr0q3Zcyp4XdyLYtcX5I3Xqk9ZcsyAT7ghmHhV8KjUjue7OcfAWg0m7 +RJLGq6VC8HeK4HEMa4lF677Qh7DRufghIDEmQSIDfGA790WGSA8HqcOvAL4hURCHyCWiPa5i8ksX +xX4HyqF8PCVCLJ_ZhzcuIlc0jStAexWbJU_vcyX7XgUaHCkF-M-zv1FP6Z3DHBMD2QqSWjmyNCCk +8sIuwzs62P_j2o9jG33kssedCrUWOwZancU107-5H0Zw-UWvtCqUfmRZ7TsEbWY7lk_SKfLfAN5q +ncOQgU_VxDXUFDST4LN_WVECRafK3UtwWomxWSji25Lbf6NVni3ok-yLMDZR-wrE-54jLPES9j0i +5N0xrk9CfsvGUpUZ1_XQcgaxI6m27DtCCJXb5ywenPBiUIJCMCTq88CqNZxGpju2i4BJcUH2hUHe +GKhO8pgslwhtEVot9EDwdzSrJkWFCfb6ud4zMxrqdi7-mLWMOydg6lhpEFEX5wu2BLIujGsZlEGE +_K9jGfBypjXuJCKDZIuPfEnf_7idjKis_JcFB7x4Hx2HHDcBjlWWFZN_VIEnPkQSyZEC26RTFP3k +zkY3GwUfA36a4XW2pu3gE9wz-W6fkONfzOZ6YiyCm_dRFUVuGSdJG02Hh5iXYlMOGJltPzWH2jVf +S-QTOmXQTKSOheXoJO6O-9uQbsRf-kq-6w1pvIOp4ms35w4_0Xj0Xr2a9y-L9PdBZvrUsa-jxsZU +LyA-YY4Ej6QwDBDTD2MGjF1E5_ekYgjoNlltM9rJjofruM4ym0n7LPHC7YXXQSEFOZYeTKi6wUDw +hQ1DoWHgu4PQ2lexada8sxQdConbPe2iW16h-PrO5D12E4XbT00fqaMlBmjQwzdNRdCC2NRPIQ5W +nwaO8dZ9yjxsjT7ZVHb9-DRblb3XDocponzxVXqUGtJAie4WXQnerX0ApTWGaHEr5y56JJVS_3LP +bKrbXBXcs4jTUX4ECXRrOs8JQDQNysXhvTPCu0XUxNZpjx6KLxDs93k2OcESHjl5J6n6OKKJqqoN +JEyFO5LGXpnmUJbn0-CaHHPRI1mHwEu4brY8wDZd9A0PD1KGXDoCHMfEk1lGblQdyOcVrXZ6uSBk +Z6zHDnwSCHO1mPYqtelJQehZoFuPSv9PIgKLxs_qJOtZFnXII5YO1mGXgiIBWBjUFDR5HG4ENS6y +J4MCF-JLMp-PVMAkOaCIQRRDpRnMm_fT1sc_P562Diu_pcdt-r55pMFQYGoGfjRmxQBKk0-SsdnP +mlZIiis9DfQEN0q3QQdNRYBJD7tmhUwhAPZdLgXqJA8sZf8UyFQhhpsky79NT343YL9smUlF
\ No newline at end of file diff --git a/aai-traversal/src/main/resources/aaf/onap/org.onap.aai.p12 b/aai-traversal/src/main/resources/aaf/onap/org.onap.aai.p12 Binary files differnew file mode 100644 index 0000000..023e2ea --- /dev/null +++ b/aai-traversal/src/main/resources/aaf/onap/org.onap.aai.p12 diff --git a/aai-traversal/src/main/resources/aaf/onap/org.onap.aai.props b/aai-traversal/src/main/resources/aaf/onap/org.onap.aai.props new file mode 100644 index 0000000..279c776 --- /dev/null +++ b/aai-traversal/src/main/resources/aaf/onap/org.onap.aai.props @@ -0,0 +1,13 @@ +############################################################ +# Properties Generated by AT&T Certificate Manager +# @copyright 2016, AT&T +############################################################ +cadi_x509_issuers=CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US +cadi_keyfile=aai-traversal/src/main/resources/aaf/org.onap.aai.keyfile +cadi_keystore=aai-traversal/src/main/resources/aaf/org.onap.aai.p12 +cadi_keystore_password=enc:383RDJRFA6yQz9AOxUxC1iIg3xTJXityw05MswnpnEtelRQy2D4r5INQjrea7GTV +#cadi_key_password=enc:<KEY PASSWORD (optional if the same as KEYSTORE PASSWORD)> +cadi_alias=aai@aai.onap.org +cadi_truststore=aai-traversal/src/main/resources/aaf/truststoreONAPall.jks +cadi_truststore_password=enc:s77wlnZFoQ08NhnU3OSeWO6uKgRwC6sAK-wTvVubNz2 +cadi_loglevel=INFO
\ No newline at end of file diff --git a/aai-traversal/src/main/resources/aaf/onap/org.osaaf.location.props b/aai-traversal/src/main/resources/aaf/onap/org.osaaf.location.props new file mode 100644 index 0000000..73a3a1e --- /dev/null +++ b/aai-traversal/src/main/resources/aaf/onap/org.osaaf.location.props @@ -0,0 +1,26 @@ +## +## org.osaaf.location.props +## +## Localized Machine Information +## +# Almeda California ? +cadi_latitude=37.78187 +cadi_longitude=-122.26147 + +# Locate URL (which AAF Env) +#aaf_locate_url=https://aaf-onap-beijing-test.osaaf.org +#aaf_locate_url=https://aaf-onap-test.osaaf.org + +aaf_locate_url=https://aaf-onap-test.osaaf.org:8095 + +# AAF URL +aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:2.0 + +# AAF Environment Designation +aaf_env=DEV + +# OAuth2 Endpoints +aaf_oauth2_token_url=https://AAF_LOCATE_URL/AAF_NS.token:2.0/token +aaf_oauth2_introspect_url=https://AAF_LOCATE_URL/AAF_NS.introspect:2.0/introspect + + diff --git a/aai-traversal/src/main/resources/aaf/onap/truststoreONAPall.jks b/aai-traversal/src/main/resources/aaf/onap/truststoreONAPall.jks Binary files differnew file mode 100644 index 0000000..2da1dcc --- /dev/null +++ b/aai-traversal/src/main/resources/aaf/onap/truststoreONAPall.jks diff --git a/aai-traversal/src/main/resources/antlr4/org/onap/aai/AAIDsl.g4 b/aai-traversal/src/main/resources/antlr4/org/onap/aai/AAIDsl.g4 index 78162f5..3ba370c 100644 --- a/aai-traversal/src/main/resources/antlr4/org/onap/aai/AAIDsl.g4 +++ b/aai-traversal/src/main/resources/antlr4/org/onap/aai/AAIDsl.g4 @@ -13,11 +13,12 @@ vertex: label store? (filter)?; traversal: (edge (vertex|unionVertex)); filter: (propertyFilter)* whereFilter?; -propertyFilter: (not? '(' key (',' (key | num))* ')'); +propertyFilter: (not? '(' key (',' (key | num | bool))* ')'); +bool: BOOL; whereFilter: (not? '(' edge nestedStatement ')' ); -unionVertex: '[' ( (edgeFilter)* nestedStatement ( comma ( (edgeFilter)* nestedStatement))*) ']'; +unionVertex: '[' ( (edgeFilter)* nestedStatement ( comma ( (edgeFilter)* nestedStatement))*) ']' store?; comma: ','; edge: TRAVERSE (edgeFilter)*; @@ -31,11 +32,13 @@ key: KEY; store: STORE; not: NOT; +BOOL: 'true'|'TRUE'|'false'|'FALSE'; LIMIT: 'LIMIT'|'limit'; NUM: (DIGIT)+; /*NODE: (ID | NUM )+;*/ -KEY : '\'' ( ~['\r\n] )*? '\''; +fragment ESCAPED_QUOTE : '\\' '\''; +KEY : '\'' (ESCAPED_QUOTE | ~[\r\n] )*? '\''; AND: [&]; diff --git a/aai-traversal/src/main/resources/antlr4/org/onap/aai/dsl/v1/AAIDsl.g4 b/aai-traversal/src/main/resources/antlr4/org/onap/aai/dsl/v1/AAIDsl.g4 new file mode 100644 index 0000000..3ba370c --- /dev/null +++ b/aai-traversal/src/main/resources/antlr4/org/onap/aai/dsl/v1/AAIDsl.g4 @@ -0,0 +1,65 @@ +/** + * Define a parser grammar called AAIDsl + */ +grammar AAIDsl; + +aaiquery: startStatement limit?; + +startStatement: (vertex ) (traversal)* ; +nestedStatement: (vertex|unionVertex ) (traversal)* ; + +vertex: label store? (filter)?; + +traversal: (edge (vertex|unionVertex)); + +filter: (propertyFilter)* whereFilter?; +propertyFilter: (not? '(' key (',' (key | num | bool))* ')'); +bool: BOOL; + +whereFilter: (not? '(' edge nestedStatement ')' ); + +unionVertex: '[' ( (edgeFilter)* nestedStatement ( comma ( (edgeFilter)* nestedStatement))*) ']' store?; + +comma: ','; +edge: TRAVERSE (edgeFilter)*; +edgeFilter: '(' key (',' key )* ')'; + +num: NUM; +limit: LIMIT num; +label: (ID | NUM )+; +key: KEY; + +store: STORE; +not: NOT; + +BOOL: 'true'|'TRUE'|'false'|'FALSE'; +LIMIT: 'LIMIT'|'limit'; +NUM: (DIGIT)+; + +/*NODE: (ID | NUM )+;*/ +fragment ESCAPED_QUOTE : '\\' '\''; +KEY : '\'' (ESCAPED_QUOTE | ~[\r\n] )*? '\''; + +AND: [&]; + +STORE: [*]; + +OR: [|]; + +TRAVERSE: [>] ; + +EQUAL: [=]; + +NOT: [!]; + +fragment LOWERCASE : [a-z] ; +fragment UPPERCASE : [A-Z] ; +fragment DIGIT : [0-9] ; +fragment ESC : '\\' . ; +fragment ID_SPECIALS: [-:_]; + +ID + : ( LOWERCASE | UPPERCASE | DIGIT | ID_SPECIALS) + ; + +WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines diff --git a/aai-traversal/src/main/resources/antlr4/org/onap/aai/dsl/v2/AAIDsl.g4 b/aai-traversal/src/main/resources/antlr4/org/onap/aai/dsl/v2/AAIDsl.g4 new file mode 100644 index 0000000..453c0fe --- /dev/null +++ b/aai-traversal/src/main/resources/antlr4/org/onap/aai/dsl/v2/AAIDsl.g4 @@ -0,0 +1,69 @@ +/** + * Define a parser grammar called AAIDsl + */ +grammar AAIDsl; + +aaiquery: startStatement limit?; + +startStatement: (vertex ) (traversal)* ; +nestedStatement: (traversal)+ ; + +vertex: label store? (filter)?; + +//traversal: ( vertex|unionVertex edge); +traversal: (edge* (vertex|unionVertex)); + +filter: (selectFilter)* (propertyFilter)* whereFilter?; +propertyFilter: (not? '(' key (',' (key | num | bool))* ')'); +selectFilter: (not? '{' key (',' key)* '}'); +bool: BOOL; + +whereFilter: (not? '(' nestedStatement ')' ); + +unionVertex: '[' ( nestedStatement ( comma (nestedStatement))*) ']' store?; + +comma: ','; +edge: ( TRAVERSE|DIRTRAVERSE) (edgeFilter)?; + +edgeFilter: '(' key (',' key )* ')'; + +num: NUM; +limit: LIMIT num; +label: (ID | NUM )+; +key: KEY; + +store: STORE | selectFilter; +not: NOT; + +BOOL: 'true'|'TRUE'|'false'|'FALSE'; +LIMIT: 'LIMIT'|'limit'; +NUM: (DIGIT)+; + +/*NODE: (ID | NUM )+;*/ +fragment ESCAPED_QUOTE : '\\' '\''; +KEY : '\'' (ESCAPED_QUOTE | ~[\r\n] )*? '\''; + +AND: [&]; + +STORE: [*]; + +OR: [|]; +DIRTRAVERSE: '>>' | '<<' ; + +TRAVERSE: '>' ; + +EQUAL: [=]; + +NOT: [!]; + +fragment LOWERCASE : [a-z] ; +fragment UPPERCASE : [A-Z] ; +fragment DIGIT : [0-9] ; +fragment ESC : '\\' . ; +fragment ID_SPECIALS: [-:_]; + +ID + : ( LOWERCASE | UPPERCASE | DIGIT | ID_SPECIALS) + ; + +WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines diff --git a/aai-traversal/src/main/resources/application.properties b/aai-traversal/src/main/resources/application.properties index f44bed4..48fdd46 100644 --- a/aai-traversal/src/main/resources/application.properties +++ b/aai-traversal/src/main/resources/application.properties @@ -46,7 +46,7 @@ server.ssl.key-store-password=password(OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0) server.ssl.trust-store=${server.certs.location}${server.truststore.name} server.ssl.trust-store-password=password(OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0) -schema.version.list=v10,v11,v12,v13,v14,v15,v16 +schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17,v18,v19 # Specifies which component should the oxm be looking at schema.source.name=onap # End of Internal Specific Properties @@ -83,7 +83,7 @@ schema.version.namespace.change.start=v12 # Specifies from which version should the client start seeing the edge label in payload schema.version.edge.label.start=v12 # Specifies the version that the application should default to -schema.version.api.default=v16 +schema.version.api.default=v19 schema.translator.list=config schema.service.base.url=https://localhost:8452/aai/schema-service/v1/ @@ -98,3 +98,9 @@ schema.service.ssl.trust-store=${server.certs.location}${server.truststore.name} schema.service.ssl.key-store-password=password(OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0) schema.service.ssl.trust-store-password=password(OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0) schema.service.versions.override=false + +# Location of the cadi properties file should be specified here +aaf.cadi.file=${server.local.startpath}/cadi.properties + +history.enabled=false; +history.truncate.window.days=365 diff --git a/aai-traversal/src/main/resources/etc/appprops/aaiconfig.properties b/aai-traversal/src/main/resources/etc/appprops/aaiconfig.properties index b94c3b1..79eb709 100644 --- a/aai-traversal/src/main/resources/etc/appprops/aaiconfig.properties +++ b/aai-traversal/src/main/resources/etc/appprops/aaiconfig.properties @@ -31,23 +31,23 @@ aai.transaction.logging.get=true aai.transaction.logging.post=true aai.server.url.base=https://localhost:8443/aai/ -aai.server.url=https://localhost:8443/aai/v16/ +aai.server.url=https://localhost:8443/aai/v19/ aai.global.callback.url=https://localhost:8443/aai/ -aai.notification.current.version=v16 +aai.notification.current.version=v19 aai.notificationEvent.default.status=UNPROCESSED aai.notificationEvent.default.eventType=AAI-EVENT aai.notificationEvent.default.domain=devINT1 aai.notificationEvent.default.sourceName=aai aai.notificationEvent.default.sequenceNumber=0 aai.notificationEvent.default.severity=NORMAL -aai.notificationEvent.default.version=v16 +aai.notificationEvent.default.version=v19 # This one lets us enable/disable resource-version checking on updates/deletes aai.resourceversion.enableflag=true # This will specify how deep the stack trace should be logged aai.logging.maxStackTraceEntries=10 -aai.default.api.version=v16 +aai.default.api.version=v19 # Used by Model-processing code aai.model.query.resultset.maxcount=50 @@ -71,6 +71,8 @@ aai.realtime.clients=SDNC,SO,MSO #DSL Override property - when running on dev uncomment and use the value #aai.dsl.override=D5D0158NMWN14NYBA0H5F2S2L5JYD07RXJ4P1FB aai.dsl.override=false +aai.dsl.max.nodecount=15 + # Threshold for margin of error (in ms) for resources_with_sot format to derive the most recent http method performed aai.resource.formatter.threshold=10 diff --git a/aai-traversal/src/main/resources/etc/appprops/error.properties b/aai-traversal/src/main/resources/etc/appprops/error.properties index 1ef789e..52de6ac 100644 --- a/aai-traversal/src/main/resources/etc/appprops/error.properties +++ b/aai-traversal/src/main/resources/etc/appprops/error.properties @@ -3,187 +3,195 @@ #Key=Disposition:Category:Severity:Error Code:HTTP ResponseCode:RESTError Code:Error Message #------------------------------------------------------------------------------- ---------- # testing code, please don't change unless error utility source code changes -AAI_TESTING=5:2:WARN:0000:400:0001:Error code for testing +AAI_TESTING=5:2:WARN:0000:400:0001:Error code for testing:0 # General success -AAI_0000=0:0:INFO:0000:200:0000:Success +AAI_0000=0:0:INFO:0000:200:0000:Success:0 # health check success -AAI_0001=0:0:INFO:0001:200:0001:Success X-FromAppId=%1 X-TransactionId=%2 -AAI_0002=0:0:INFO:0002:200:0001:Successful health check +AAI_0001=0:0:INFO:0001:200:0001:Success X-FromAppId=%1 X-TransactionId=%2 :0 +AAI_0002=0:0:INFO:0002:200:0001:Successful health check:0 # Success with additional info -AAI_0003=0:3:INFO:0003:202:0003:Success with additional info performing %1 on %2. Added %3 with key %4 -AAI_0004=0:3:INFO:0004:202:0003:Added prerequisite object to db +AAI_0003=0:3:INFO:0003:202:0003:Success with additional info performing %1 on %2. Added %3 with key %4:0 +AAI_0004=0:3:INFO:0004:202:0003:Added prerequisite object to db:0 #--- aairest: 3000-3299 # svc errors -AAI_3000=5:2:INFO:3000:400:3000:Invalid input performing %1 on %2 -AAI_3001=5:6:INFO:3001:404:3001:Resource not found for %1 using id %2 -AAI_3002=5:1:WARN:3002:400:3002:Error writing output performing %1 on %2 -AAI_3003=5:1:WARN:3003:400:3003:Failed to make edge to missing target node of type %3 with keys %4 performing %1 on %2 -AAI_3005=5:6:WARN:3005:404:3001:Node cannot be directly accessed for read, must be accessed via ancestor(s) -AAI_3006=5:6:WARN:3006:404:3001:Node cannot be directly accessed for write, must be accessed via ancestor(s) -AAI_3007=5:6:INFO:3007:410:3007:This version (%1) of the API is retired, please migrate to %2 -AAI_3008=5:6:WARN:3008:400:3008:URI is not encoded in UTF-8 -AAI_3009=5:6:WARN:3009:400:3002:Malformed URL -AAI_3010=5:6:WARN:3010:400:3002:Cannot write via this URL -AAI_3011=5:6:WARN:3011:400:3000:Unknown XML namespace used in payload -AAI_3012=5:6:WARN:3012:400:3012:Unrecognized AAI function -AAI_3013=5:6:WARN:3013:400:3013:Query payload missing required parameters %1 -AAI_3014=5:6:WARN:3014:400:3014:Query payload is invalid %1 -AAI_3018=5:6:WARN:3018:400:3018:Query URI missing required parameters -AAI_3019=5:6:WARN:3019:400:3019:Query URI sending conflicting parameters -AAI_3020=5:6:WARN:3020:400:3020:Query URI parameters outside bounds -AAI_3021=5:6:WARN:3021:400:3021:Invalid parameters to Recents API -AAI_3022=5:6:WARN:3022:400:3022:Query payload includes extra/unrecognized parameters %1 -AAI_3025=5:4:FATAL:3025:500:3025:Error connecting to Schema Service -AAI_3026=5:4:FATAL:3026:500:3026:Error reading OXM from Schema Service -AAI_3027=5:4:FATAL:3026:500:3026:Error reading EdgeRules from Schema Service -AAI_3028=5:4:FATAL:3026:500:3026:Error reading stored-queries from Schema Service +AAI_3000=5:2:INFO:3000:400:3000:Invalid input performing %1 on %2:300 +AAI_3001=5:6:INFO:3001:404:3001:Resource not found for %1 using id %2:300 +AAI_3002=5:1:WARN:3002:400:3002:Error writing output performing %1 on %2:300 +AAI_3003=5:1:WARN:3003:400:3003:Failed to make edge to missing target node of type %3 with keys %4 performing %1 on %2:400 +AAI_3005=5:6:WARN:3005:404:3001:Node cannot be directly accessed for read, must be accessed via ancestor(s):100 +AAI_3006=5:6:WARN:3006:404:3001:Node cannot be directly accessed for write, must be accessed via ancestor(s)100 +AAI_3007=5:6:INFO:3007:410:3007:This version (%1) of the API is retired, please migrate to %2:500 +AAI_3008=5:6:WARN:3008:400:3008:URI is not encoded in UTF-8:300 +AAI_3009=5:6:WARN:3009:400:3002:Malformed URL:300 +AAI_3010=5:6:WARN:3010:400:3002:Cannot write via this URL:100 +AAI_3011=5:6:WARN:3011:400:3000:Unknown XML namespace used in payload:300 +AAI_3012=5:6:WARN:3012:400:3012:Unrecognized AAI function:300 +AAI_3013=5:6:WARN:3013:400:3013:Query payload missing required parameters %1:300 +AAI_3014=5:6:WARN:3014:400:3014:Query payload is invalid %1:300 +AAI_3016=5:6:INFO:3007:400:3016:Request uri is not valid, please check the version %1:500 +AAI_3017=5:6:INFO:3007:400:3016:Request uri is not valid, please check the uri %1:500 +AAI_3018=5:6:WARN:3018:400:3018:Query URI missing required parameters:300 +AAI_3019=5:6:WARN:3019:400:3019:Query URI sending conflicting parameters:300 +AAI_3020=5:6:WARN:3020:400:3020:Query URI parameters outside bounds:300 +AAI_3021=5:6:WARN:3021:400:3021:Invalid parameters to Recents API:300 +AAI_3022=5:6:WARN:3022:400:3022:Query payload includes extra/unrecognized parameters %1:300 +AAI_3025=5:4:FATAL:3025:500:3025:Error connecting to Schema Service:400 +AAI_3026=5:4:FATAL:3026:500:3026:Error reading OXM from Schema Service:400 +AAI_3027=5:4:FATAL:3026:500:3026:Error reading EdgeRules from Schema Service:400 +AAI_3028=5:4:FATAL:3026:500:3026:Error reading stored-queries from Schema Service:400 # pol errors -AAI_3100=5:1:WARN:3100:400:3100:Unsupported operation %1 -AAI_3101=5:1:WARN:3101:403:3101:Attempt by client %1 to execute API %2 -AAI_3102=5:1:WARN:3102:400:3102:Error parsing input performing %1 on %2 -AAI_3300=5:1:WARN:3300:403:3300:Unauthorized -AAI_3301=5:1:WARN:3301:401:3301:Stale credentials -AAI_3302=5:1:WARN:3302:401:3301:Not authenticated -AAI_3303=5:1:WARN:3303:403:3300:Too many objects would be returned by this request, please refine your request and retry +AAI_3100=5:1:WARN:3100:400:3100:Unsupported operation %1:300 +AAI_3101=5:1:WARN:3101:403:3101:Attempt by client %1 to execute API %2:100 +AAI_3102=5:1:WARN:3102:400:3102:Error parsing input performing %1 on %2:300 +AAI_3300=5:1:WARN:3300:403:3300:Unauthorized:100 +AAI_3301=5:1:WARN:3301:401:3301:Stale credentials:100 +AAI_3302=5:1:WARN:3302:401:3301:Not authenticated:100 +AAI_3303=5:1:WARN:3303:403:3300:Too many objects would be returned by this request, please refine your request and retry:500 #--- aaigen: 4000-4099 -AAI_4000=5:4:ERROR:4000:500:3002:Internal Error -AAI_4001=5:4:FATAL:4001:500:3002:Configuration file not found -AAI_4002=5:4:FATAL:4002:500:3002:Error reading Configuration file -AAI_4003=5:4:ERROR:4003:500:3002:Error writing to log file -AAI_4004=5:4:FATAL:4004:500:3002:Error reading/parsing the error properties file -AAI_4005=5:4:FATAL:4005:500:3002:Missing or invalid configuration parameter -AAI_4006=5:4:FATAL:4006:500:3002:Unexpected error in service -AAI_4007=5:4:WARN:4007:500:3102:Input parsing error -AAI_4008=5:4:ERROR:4008:500:3002:Output parsing error -AAI_4009=4:0:WARN:4009:400:3000:Invalid X-FromAppId in header -AAI_4010=4:0:WARN:4010:400:3000:Invalid X-TransactionId in header -AAI_4011=5:4:ERROR:4011:500:3002:Missing data for REST error response -AAI_4014=4:0:WARN:4014:400:3000:Invalid Accept header -AAI_4015=4:0:WARN:4015:400:3000:You must provide at least one indexed property -AAI_4016=4:0:WARN:4016:400:3000:The depth parameter must be a number or the string "all" -AAI_4017=5:2:INFO:4017:400:3000:Could not set property -AAI_4018=5:2:WARN:4018:400:3000:Unable to convert the string to integer +AAI_4000=5:4:ERROR:4000:500:3002:Internal Error:500 +AAI_4001=5:4:FATAL:4001:500:3002:Configuration file not found:500 +AAI_4002=5:4:FATAL:4002:500:3002:Error reading Configuration file:500 +AAI_4003=5:4:ERROR:4003:500:3002:Error writing to log file:500 +AAI_4004=5:4:FATAL:4004:500:3002:Error reading/parsing the error properties file:500 +AAI_4005=5:4:FATAL:4005:500:3002:Missing or invalid configuration parameter:500 +AAI_4006=5:4:FATAL:4006:500:3002:Unexpected error in service:500 +AAI_4007=5:4:WARN:4007:500:3102:Input parsing error:500 +AAI_4008=5:4:ERROR:4008:500:3002:Output parsing error:500 +AAI_4009=4:0:WARN:4009:400:3000:Invalid X-FromAppId in header:300 +AAI_4010=4:0:WARN:4010:400:3000:Invalid X-TransactionId in header:300 +AAI_4011=5:4:ERROR:4011:500:3002:Missing data for REST error response:500 +AAI_4014=4:0:WARN:4014:400:3000:Invalid Accept header:300 +AAI_4015=4:0:WARN:4015:400:3000:You must provide at least one indexed property:400 +AAI_4016=4:0:WARN:4016:400:3000:The depth parameter must be a number or the string "all":300 +AAI_4017=5:2:INFO:4017:400:3000:Could not set property:300 +AAI_4018=5:2:WARN:4018:400:3000:Unable to convert the string to integer:300 +AAI_4019=5:4:ERROR:4018:400:3000:Invalid start time sent to history formats:300 + #--- aaidbmap: 5102-5199 -AAI_5102=5:4:FATAL:5102:500:3002:Graph database is null after open -AAI_5105=5:4:ERROR:5105:500:3002:Unexpected error reading/updating database -AAI_5106=5:4:WARN:5106:404:3001:Node not found -AAI_5107=5:2:WARN:5107:400:3000:Required information missing -AAI_5108=5:2:WARN:5108:200:0:Unexpected information in request being ignored +AAI_5102=5:4:FATAL:5102:500:3002:Graph database is null after open:400 +AAI_5105=5:4:ERROR:5105:500:3002:Unexpected error reading/updating database:300 +AAI_5106=5:4:WARN:5106:404:3001:Node not found:300 +AAI_5107=5:2:WARN:5107:400:3000:Required information missing:300 +AAI_5108=5:2:WARN:5108:200:0:Unexpected information in request being ignored:300 #--- aaidbgen: 6101-6199 -AAI_6101=5:4:ERROR:6101:500:3002:null JanusGraph object passed -AAI_6102=5:4:WARN:6102:400:3000:Passed-in property is not valid for this nodeType -AAI_6103=5:4:WARN:6103:400:3000:Required Node-property not found in input data -AAI_6104=5:4:WARN:6104:400:3000:Required Node-property was passed with no data -AAI_6105=5:4:WARN:6105:400:3000:Node-Key-Property not defined in DbMaps -AAI_6106=5:4:WARN:6106:400:3000:Passed-in property is not valid for this edgeType -AAI_6107=5:4:WARN:6107:400:3000:Required Edge-property not found in input data -AAI_6108=5:4:WARN:6108:400:3000:Required Edge-property was passed with no data -AAI_6109=5:4:WARN:6109:400:3000:Bad dependent Node value -AAI_6110=5:4:ERROR:6110:400:3100:Node cannot be deleted -AAI_6111=5:4:WARN:6111:400:3000:JSON processing error -AAI_6112=5:4:ERROR:6112:400:3000:More than one node found by getUniqueNode() -AAI_6114=5:4:INFO:6114:404:3001:Node Not Found -AAI_6115=5:4:ERROR:6115:400:3000:Unrecognized NodeType -AAI_6116=5:4:ERROR:6116:400:3000:Unrecognized Property -AAI_6117=5:4:ERROR:6117:400:3000:Uniqueness constraint violated -AAI_6118=5:4:WARN:6118:400:3000:Required Field not passed. -AAI_6120=5:4:WARN:6120:400:3000:Bad Parameter Passed -AAI_6121=5:4:ERROR:6121:400:3000:Problem with internal AAI reference data -AAI_6122=5:4:ERROR:6122:400:3000:Data Set not complete in DB for this request -AAI_6123=5:4:ERROR:6123:500:3000:Bad Data found by DataGrooming Tool - Investigate -AAI_6124=5:4:ERROR:6124:500:3000:File read/write error -AAI_6125=5:4:WARN:6125:500:3000:Problem Pulling Data Set -AAI_6126=5:4:ERROR:6126:400:3000:Edge cannot be deleted -AAI_6127=5:4:INFO:6127:404:3001:Edge Not Found -AAI_6128=5:4:INFO:6128:500:3000:Unexpected error -AAI_6129=5:4:INFO:6129:404:3003:Error making edge to target node -AAI_6130=5:4:WARN:6130:412:3000:Precondition Required -AAI_6131=5:4:WARN:6131:412:3000:Precondition Failed -AAI_6132=5:4:WARN:6132:400:3000:Bad Model Definition -AAI_6133=5:4:WARN:6133:400:3000:Bad Named Query Definition -AAI_6134=5:4:ERROR:6134:500:6134:Could not persist transaction to storage back end. Exhausted retry amount -AAI_6135=5:4:WARN:6135:412:3000:Resource version specified on create -AAI_6136=5:4:ERROR:6136:400:3000:Object cannot hold multiple items -AAI_6137=5:4:ERROR:6137:400:3000:Cannot perform writes on multiple vertices -AAI_6138=5:4:ERROR:6138:400:3000:Cannot delete multiple vertices -AAI_6139=5:4:ERROR:6139:404:3000:Attempted to add edge to vertex that does not exist -AAI_6140=5:4:ERROR:6140:400:3000:Edge multiplicity violated -AAI_6141=5:4:WARN:6141:400:3000:Please Refine Query -AAI_6142=5:4:INFO:6142:400:3000:Retrying transaction -AAI_6143=5:4:INFO:6143:400:3000:Ghost vertex found -AAI_6144=5:4:WARN:6144:400:3000:Cycle found in graph -AAI_6145=5:4:ERROR:6145:400:3000:Cannot create a nested/containment edge via relationship -AAI_6146=5:4:ERROR:6146:400:3000:Ambiguous identity map found, use a URI instead -AAI_6147=5:4:ERROR:6147:400:3000:Payload Limit Reached, reduce payload -AAI_6148=5:4:INFO:6148:404:3001:Node Not Found. Start URI returned no vertexes, please check the start URI -AAI_6149=5:4:INFO:6149:404:6149:DSL Query Error -AAI_6150=5:4:INFO:6150:404:6150:Pagination Error +AAI_6101=5:4:ERROR:6101:500:3002:null JanusGraph object passed:400 +AAI_6102=5:4:WARN:6102:400:3000:Passed-in property is not valid for this nodeType:400 +AAI_6103=5:4:WARN:6103:400:3000:Required Node-property not found in input data:400 +AAI_6104=5:4:WARN:6104:400:3000:Required Node-property was passed with no data:400 +AAI_6105=5:4:WARN:6105:400:3000:Node-Key-Property not defined in DbMaps:400 +AAI_6106=5:4:WARN:6106:400:3000:Passed-in property is not valid for this edgeType:400 +AAI_6107=5:4:WARN:6107:400:3000:Required Edge-property not found in input data:400 +AAI_6108=5:4:WARN:6108:400:3000:Required Edge-property was passed with no data:400 +AAI_6109=5:4:WARN:6109:400:3000:Bad dependent Node value:400 +AAI_6110=5:4:ERROR:6110:400:3100:Node cannot be deleted:500 +AAI_6111=5:4:WARN:6111:400:3000:JSON processing error:300 +AAI_6112=5:4:ERROR:6112:400:3000:More than one node found by getUniqueNode():400 +AAI_6114=5:4:WARN:6114:404:3001:Node Not Found:300 +AAI_6115=5:4:ERROR:6115:400:3000:Unrecognized NodeType:400 +AAI_6116=5:4:ERROR:6116:400:3000:Unrecognized Property:400 +AAI_6117=5:4:ERROR:6117:400:3000:Uniqueness constraint violated:400 +AAI_6118=5:4:WARN:6118:400:3000:Required Field not passed.:400 +AAI_6120=5:4:WARN:6120:400:3000:Bad Parameter Passed:300 +AAI_6121=5:4:ERROR:6121:400:3000:Problem with internal AAI reference data:400 +AAI_6122=5:4:ERROR:6122:400:3000:Data Set not complete in DB for this request:400 +AAI_6123=5:4:ERROR:6123:500:3000:Bad Data found by DataGrooming Tool - Investigate:300 +AAI_6124=5:4:ERROR:6124:500:3000:File read/write error:500 +AAI_6125=5:4:WARN:6125:500:3000:Problem Pulling Data Set:500 +AAI_6126=5:4:ERROR:6126:400:3000:Edge cannot be deleted:400 +AAI_6127=5:4:INFO:6127:404:3001:Edge Not Found:400 +AAI_6128=5:4:INFO:6128:500:3000:Unexpected error:900 +AAI_6129=5:4:INFO:6129:404:3003:Error making edge to target node:400 +AAI_6130=5:4:WARN:6130:412:3000:Precondition Required:300 +AAI_6131=5:4:WARN:6131:412:3000:Precondition Failed:300 +AAI_6132=5:4:WARN:6132:400:3000:Bad Model Definition:500 +AAI_6133=5:4:WARN:6133:400:3000:Bad Named Query Definition:500 +AAI_6134=5:4:ERROR:6134:500:6134:Could not persist transaction to storage back end. Exhausted retry amount:500 +AAI_6135=5:4:WARN:6135:412:3000:Resource version specified on create:300 +AAI_6136=5:4:ERROR:6136:400:3000:Object cannot hold multiple items:400 +AAI_6137=5:4:ERROR:6137:400:3000:Cannot perform writes on multiple vertices:400 +AAI_6138=5:4:ERROR:6138:400:3000:Cannot delete multiple vertices:400 +AAI_6139=5:4:ERROR:6139:404:3000:Attempted to add edge to vertex that does not exist:400 +AAI_6140=5:4:ERROR:6140:400:3000:Edge multiplicity violated:400 +AAI_6141=5:4:WARN:6141:400:3000:Please Refine Query:400 +AAI_6142=5:4:INFO:6142:400:3000:Retrying transaction:900 +AAI_6143=5:4:INFO:6143:400:3000:Ghost vertex found:400 +AAI_6144=5:4:WARN:6144:400:3000:Cycle found in graph:400 +AAI_6145=5:4:ERROR:6145:400:3000:Cannot create a nested/containment edge via relationship:400 +AAI_6146=5:4:ERROR:6146:400:3000:Ambiguous identity map found, use a URI instead:300 +AAI_6147=5:4:ERROR:6147:400:3000:Payload Limit Reached, reduce payload:300 +AAI_6148=5:4:INFO:6148:404:3001:Node Not Found. Start URI returned no vertexes, please check the start URI:400 +AAI_6149=5:4:INFO:6149:400:6149:DSL Query/Schema Error:400 +AAI_6150=5:4:INFO:6150:404:6150:Pagination Error:500 +AAI_6151=5:4:INFO:6151:400:6151:DSL Validation Error:500 +AAI_6152=5:4:INFO:6152:400:6152:DSL Generic Error:900 +AAI_6153=5:4:INFO:6153:400:6153:DSL Syntax Error:300 +AAI_6154=5:4:WARN:6134:500:3000:Delete Error:300 #--- aaicsvp: 7101-7199 -AAI_7101=5:4:ERROR:7101:500:3002:Unexpected error in CSV file processing -AAI_7102=5:4:ERROR:7102:500:3002:Error in cleanup temporary directory -#AAI_7103=4:2:ERROR:7103:500:3002:Unsupported user -AAI_7104=5:4:ERROR:7104:500:3002:Failed to create directory -AAI_7105=5:4:ERROR:7105:500:3002:Temporary directory exists -AAI_7106=5:4:ERROR:7106:500:3002:Cannot delete -AAI_7107=5:4:ERROR:7107:500:3002:Input file does not exist -AAI_7108=5:4:ERROR:7108:500:3002:Output file does not exist -AAI_7109=5:4:ERROR:7109:500:3002:Error closing file -AAI_7110=5:4:ERROR:7110:500:3002:Error loading/reading properties file -AAI_7111=5:4:ERROR:7111:500:3002:Error executing shell script -AAI_7112=5:4:ERROR:7112:500:3002:Error creating output file -AAI_7113=5:4:ERROR:7113:500:3002:Trailer record error -AAI_7114=5:4:ERROR:7114:500:3002:Input file error -AAI_7115=5:4:ERROR:7115:500:3002:Unexpected error -AAI_7116=5:4:ERROR:7116:500:3002:Request error -AAI_7117=5:4:ERROR:7117:500:3002:Error in get http client object -AAI_7118=5:4:ERROR:7118:500:3002:Script Error -AAI_7119=5:4:ERROR:7119:500:3002:Unknown host +AAI_7101=5:4:ERROR:7101:500:3002:Unexpected error in CSV file processing:900 +AAI_7102=5:4:ERROR:7102:500:3002:Error in cleanup temporary directory:500 +#AAI_7103=4:2:ERROR:7103:500:3002:Unsupported user:100 +AAI_7104=5:4:ERROR:7104:500:3002:Failed to create directory:500 +AAI_7105=5:4:ERROR:7105:500:3002:Temporary directory exists:500 +AAI_7106=5:4:ERROR:7106:500:3002:Cannot delete:500 +AAI_7107=5:4:ERROR:7107:500:3002:Input file does not exist:500 +AAI_7108=5:4:ERROR:7108:500:3002:Output file does not exist:500 +AAI_7109=5:4:ERROR:7109:500:3002:Error closing file:500 +AAI_7110=5:4:ERROR:7110:500:3002:Error loading/reading properties file:500 +AAI_7111=5:4:ERROR:7111:500:3002:Error executing shell script:900 +AAI_7112=5:4:ERROR:7112:500:3002:Error creating output file:500 +AAI_7113=5:4:ERROR:7113:500:3002:Trailer record error:300 +AAI_7114=5:4:ERROR:7114:500:3002:Input file error:300 +AAI_7115=5:4:ERROR:7115:500:3002:Unexpected error:900 +AAI_7116=5:4:ERROR:7116:500:3002:Request error:900 +AAI_7117=5:4:ERROR:7117:500:3002:Error in get http client object:500 +AAI_7118=5:4:ERROR:7118:500:3002:Script Error:900 +AAI_7119=5:4:ERROR:7119:500:3002:Unknown host:900 #--- aaisdnc: 7201-7299 -AAI_7202=5:4:ERROR:7202:500:3002:Error getting connection to odl -AAI_7203=5:4:ERROR:7203:500:3002:Unexpected error calling DataChangeNotification API -AAI_7204=5:4:ERROR:7204:500:3002:Error returned by DataChangeNotification API -#AAI_7206=5:4:ERROR:7206:500:3002:Invalid data returned from ODL +AAI_7202=5:4:ERROR:7202:500:3002:Error getting connection to odl:200 +AAI_7203=5:4:ERROR:7203:500:3002:Unexpected error calling DataChangeNotification API:900 +AAI_7204=5:4:ERROR:7204:500:3002:Error returned by DataChangeNotification API:200 +#AAI_7206=5:4:ERROR:7206:500:3002:Invalid data returned from ODL:300 #--- NotificationEvent, using UEB space -AAI_7350=5:4:ERROR:7305:500:3002:Notification event creation failed +AAI_7304=4:5:ERROR:7304:500:3002:Error reaching DMaaP to send event:200 +AAI_7350=5:4:ERROR:7305:500:3002:Notification event creation failed:500 #--- aairestctlr: 7401-7499 -AAI_7401=5:4:ERROR:7401:500:3002:Error connecting to AAI REST API -AAI_7402=5:4:ERROR:7402:500:3002:Unexpected error -AAI_7403=5:4:WARN:7403:400:3001:Request error -AAI_7404=5:4:INFO:7404:404:3001:Node not found -AAI_7405=5:4:WARN:7405:200:0:UUID not formatted correctly, generating UUID -AAI_7406=5:4:ERROR:7406:400:7406:Request Timed Out +AAI_7401=5:4:ERROR:7401:500:3002:Error connecting to AAI REST API:200 +AAI_7402=5:4:ERROR:7402:500:3002:Unexpected error:900 +AAI_7403=5:4:WARN:7403:400:3001:Request error:900 +AAI_7404=5:4:INFO:7404:404:3001:Node not found:300 +AAI_7405=5:4:WARN:7405:200:0:UUID not formatted correctly, generating UUID:300 +AAI_7406=5:4:ERROR:7406:400:7406:Request Timed Out:200 #--- aaicsiovals: 7501-7599 -#AAI_7501=5:4:WARN:7501:500:3002:Error getting connection to CSI-OVALS -AAI_7502=5:4:WARN:7502:500:3002:Bad parameter when trying to build request for CSI-OVALS -AAI_7503=5:4:WARN:7503:500:3002:Error returned by CSI-OVALS +#AAI_7501=5:4:WARN:7501:500:3002:Error getting connection to CSI-OVALS:200 +AAI_7502=5:4:WARN:7502:500:3002:Bad parameter when trying to build request for CSI-OVALS:300 +AAI_7503=5:4:WARN:7503:500:3002:Error returned by CSI-OVALS:500 #--- aaiauth: 9101-9199 -AAI_9101=5:0:WARN:9101:403:3300:User is not authorized to perform function +AAI_9101=5:0:WARN:9101:403:3300:User is not authorized to perform function:100 #AAI_9102=5:0:WARN:9102:401:3301:Refresh credentials from source #AAI_9103=5:0:WARN:9103:403:3300:User not found #AAI_9104=5:0:WARN:9104:401:3302:Authentication error #AAI_9105=5:0:WARN:9105:403:3300:Authorization error #AAI_9106=5:0:WARN:9106:403:3300:Invalid AppId #AAI_9107=5:0:WARN:9107:403:3300:No Username in Request -AAI_9107=5:0:WARN:9107:403:3300:SSL is not provided in request, please contact admin +AAI_9107=5:0:WARN:9107:403:3300:SSL is not provided in request, please contact admin:100 #--- aaiinstar: 9201-9299 #AAI_9201=5:4:ERROR:9201:500:3002:Unable to send notification -AAI_9202=5:4:ERROR:9202:500:3002:Unable to start a thread +AAI_9202=5:4:ERROR:9202:500:3002:Unable to start a thread:500 #--- GRM DME2: 9501-9599 -AAI_9501=5:4:WARN:9501:500:3002:Unable to register with GRM retrying -AAI_9502=5:4:ERROR:9502:500:3002:Unable to register with GRM after exhausting all retries -AAI_9503=5:4:WARN:9503:500:3002:Unable to successfully unpublish with GRM, recommend manual cleanup but not necessary - +AAI_9501=5:4:WARN:9501:500:3002:Unable to register with GRM retrying:200 +AAI_9502=5:4:ERROR:9502:500:3002:Unable to register with GRM after exhausting all retries:200 +AAI_9503=5:4:WARN:9503:500:3002:Unable to successfully unpublish with GRM, recommend manual cleanup but not necessary:200 diff --git a/aai-traversal/src/main/resources/etc/appprops/janusgraph-cached.properties b/aai-traversal/src/main/resources/etc/appprops/janusgraph-cached.properties index d032dd0..8b0dcff 100644 --- a/aai-traversal/src/main/resources/etc/appprops/janusgraph-cached.properties +++ b/aai-traversal/src/main/resources/etc/appprops/janusgraph-cached.properties @@ -18,6 +18,7 @@ # ============LICENSE_END========================================================= query.fast-property=true +query.smart-limit=false # the following parameters are not reloaded automatically and require a manual bounce storage.backend=inmemory storage.hostname=localhost diff --git a/aai-traversal/src/main/resources/etc/appprops/janusgraph-realtime.properties b/aai-traversal/src/main/resources/etc/appprops/janusgraph-realtime.properties index b55897c..9c7843a 100644 --- a/aai-traversal/src/main/resources/etc/appprops/janusgraph-realtime.properties +++ b/aai-traversal/src/main/resources/etc/appprops/janusgraph-realtime.properties @@ -18,6 +18,7 @@ # ============LICENSE_END========================================================= query.fast-property=true +query.smart-limit=false # the following parameters are not reloaded automatically and require a manual bounce storage.backend=inmemory storage.hostname=localhost diff --git a/aai-traversal/src/main/resources/logback.xml b/aai-traversal/src/main/resources/logback.xml index 3a6dae4..c6fe5c7 100644 --- a/aai-traversal/src/main/resources/logback.xml +++ b/aai-traversal/src/main/resources/logback.xml @@ -31,16 +31,32 @@ <property name="AJSC_HOME" value="${AJSC_HOME:-.}" /> <jmxConfigurator /> <property name="logDirectory" value="${AJSC_HOME}/logs" /> - <property name="eelfLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%X{serviceName}|%X{partnerName}|%X{statusCode}|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> - <property name="eelfAuditLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%X{serviceName}|%X{partnerName}|%X{statusCode}|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n|\r\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> - <property name="eelfMetricLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%X{serviceName}|%X{partnerName}|%X{targetEntity}|%X{targetServiceName}|%X{statusCode}|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{targetVirtualEntity}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> - <!-- <property name="eelfErrorLogPattern" value="%ecompStartTime|%X{requestId}|%-10t|%X{serviceName}|%X{partnerName}|%X{targetEntity}|%X{targetServiceName}|%ecompErrorCategory|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n|\r\n', '^'}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> --> - <property name="eelfErrorLogPattern" value="%ecompStartTime|%X{requestId}|%-10t|%X{serviceName}|%X{partnerName}|%X{targetEntity}|%X{targetServiceName}|%ecompErrorCategory|%ecompResponseCode|%ecompResponseDescription|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> - <property name="eelfTransLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%X{serviceName}|%X{partnerName}|%X{statusCode}|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{partnerName}:%m%n"/> - - <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> - <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /> - <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" /> + <!-- Old patterns + <property name="eelfLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%ecompServiceName|%X{partnerName}|%ecompStatusCode|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> + <property name="eelfAuditLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%ecompServiceName|%X{partnerName}|%ecompStatusCode|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n|\r\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> + <property name="eelfMetricLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%ecompServiceName|%X{partnerName}|%X{targetEntity}|%X{targetServiceName}|%ecompStatusCode|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{targetVirtualEntity}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> + <property name="eelfErrorLogPattern" value="%ecompStartTime|%X{requestId}|%-10t|%ecompServiceName|%X{partnerName}|%X{targetEntity}|%X{targetServiceName}|%ecompErrorCategory|%ecompResponseCode|%ecompResponseDescription|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> + <property name="eelfTransLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%ecompServiceName|%X{partnerName}|%ecompStatusCode|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{partnerName}:%m%n"/> + --> + <property name="p_tim" value="%d{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX", UTC}"/> + <property name="p_lvl" value="%level"/> + <property name="p_log" value="%logger"/> + <property name="p_mdc" value="%replace(%replace(%replace(%mdc){'\t','\\\\t'}){'\n', '\\\\n'}){'\\|', '!'}"/> + <property name="p_msg" value="%replace(%replace(%replace(%msg){'\t','\\\\t'}){'\n', '\\\\n'}){'\\|', '!'}"/> + <property name="p_exc" value="%replace(%replace(%rootException){'\t', '\\\\t'}){'\n','\\\\n'}"/> + <property name="p_mak" value="%replace(%replace(%marker){'\t', '\\\\t'}){'\n','\\\\n'}"/> + <property name="p_thr" value="%thread"/> + <property name="pattern" value="%nopexception${p_tim}\t${p_thr}\t${p_lvl}\t${p_log}\t${p_mdc}\t${p_msg}\t${p_exc}\t${p_mak}\t%n"/> + <!-- Patterns from onap demo --> + <property name="errorPattern" value="%X{LogTimestamp}|%X{RequestID}|%thread|%replace(%X{ServiceName}){'\\|', '!'}|%X{PartnerName}|%X{TargetEntity}|%replace(%X{TargetServiceName}){'\\|', '!'}|%.-5level|%X{ErrorCode}|%X{ErrorDesc}|${p_msg}%n" /> + <property name="debugPattern" value="%X{LogTimestamp}|%X{RequestID}|${p_msg}\t${p_mdc}\t${p_exc}\t${p_mak}\t|^%n" /> + <property name="auditPattern" value="%X{EntryTimestamp}|%X{LogTimestamp}|%X{RequestID}|%X{ServiceInstanceID}|%thread||%replace(%X{ServiceName}){'\\|', '!'}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDesc}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}||||${p_mak}|${p_mdc}|||${p_msg}%n" /> + <property name="metricPattern" value="%X{InvokeTimestamp}|%X{LogTimestamp}|%X{RequestID}|%X{ServiceInstanceID}|%thread||%replace(%X{ServiceName}){'\\|', '!'}|%X{PartnerName}|%X{TargetEntity}|%replace(%X{TargetServiceName}){'\\|', '!'}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDesc}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}||||%X{TargetVirtualEntity}|${p_mak}|${p_mdc}|||${p_msg}%n" /> + + <property name="transLogPattern" value="%X{LogTimestamp}|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{RequestID}|%X{ServiceInstanceID}|%-10t|%X{ServerFQDN}|%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%replace(%replace(%X{ResponseDesc}){'\\|', '!'}){'\r|\n', '^'}|%X{InstanceUUID}|%level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{clientIpAddress}||%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{PartnerName}:%m%n"/> + <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> + <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /> + <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" /> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern> @@ -53,6 +69,8 @@ <file>${logDirectory}/rest/sane.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${logDirectory}/rest/sane.log.%d{yyyy-MM-dd}</fileNamePattern> + <maxHistory>14</maxHistory> + <cleanHistoryOnStart>true</cleanHistoryOnStart> </rollingPolicy> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} - %msg%n @@ -65,82 +83,82 @@ <includeCallerData>true</includeCallerData> <appender-ref ref="SANE" /> </appender> - - <appender name="METRIC" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <filter class="ch.qos.logback.classic.filter.LevelFilter"> - <level>INFO</level> - <onMatch>ACCEPT</onMatch> - <onMismatch>DENY</onMismatch> - </filter> + <appender name="METRIC" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logDirectory}/rest/metrics.log</file> - <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> - <fileNamePattern>${logDirectory}/rest/metrics.log.%d{yyyy-MM-dd} - </fileNamePattern> + <rollingPolicy + class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${logDirectory}/rest/metrics.log.%d{yyyy-MM-dd}</fileNamePattern> + <maxHistory>14</maxHistory> + <cleanHistoryOnStart>true</cleanHistoryOnStart> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfMetricLogPattern}</pattern> + <encoder> + <pattern>${metricPattern}</pattern> </encoder> </appender> + <appender name="asyncMETRIC" class="ch.qos.logback.classic.AsyncAppender"> <queueSize>1000</queueSize> <includeCallerData>true</includeCallerData> - <appender-ref ref="METRIC" /> + <appender-ref ref="METRIC"/> </appender> <appender name="DEBUG" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <file>${logDirectory}/rest/debug.log</file> - <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> - <fileNamePattern>${logDirectory}/rest/debug.log.%d{yyyy-MM-dd} - </fileNamePattern> + <rollingPolicy + class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${logDirectory}/rest/debug.log.%d{yyyy-MM-dd}</fileNamePattern> + <maxHistory>14</maxHistory> + <cleanHistoryOnStart>true</cleanHistoryOnStart> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfLogPattern}</pattern> + <encoder> + <pattern>${debugPattern}</pattern> </encoder> </appender> <appender name="asyncDEBUG" class="ch.qos.logback.classic.AsyncAppender"> <queueSize>1000</queueSize> - <includeCallerData>true</includeCallerData> <appender-ref ref="DEBUG" /> + <includeCallerData>true</includeCallerData> </appender> - <appender name="ERROR" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/rest/error.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${logDirectory}/rest/error.log.%d{yyyy-MM-dd}</fileNamePattern> + <maxHistory>14</maxHistory> + <cleanHistoryOnStart>true</cleanHistoryOnStart> + </rollingPolicy> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>WARN</level> </filter> - <file>${logDirectory}/rest/error.log</file> - <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> - <fileNamePattern>${logDirectory}/rest/error.log.%d{yyyy-MM-dd} - </fileNamePattern> - </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfErrorLogPattern}</pattern> + <encoder> + <pattern>${errorPattern}</pattern> </encoder> </appender> <appender name="asyncERROR" class="ch.qos.logback.classic.AsyncAppender"> <queueSize>1000</queueSize> - <includeCallerData>true</includeCallerData> - <appender-ref ref="ERROR" /> + <appender-ref ref="ERROR"/> </appender> <appender name="AUDIT" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logDirectory}/rest/audit.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${logDirectory}/rest/audit.log.%d{yyyy-MM-dd} </fileNamePattern> + <maxHistory>14</maxHistory> + <cleanHistoryOnStart>true</cleanHistoryOnStart> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfAuditLogPattern}</pattern> + <encoder> + <pattern>${auditPattern}</pattern> </encoder> </appender> @@ -151,7 +169,7 @@ </appender> <appender name="translog" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> @@ -161,12 +179,14 @@ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${logDirectory}/rest/translog.log.%d{yyyy-MM-dd} </fileNamePattern> + <maxHistory>14</maxHistory> + <cleanHistoryOnStart>true</cleanHistoryOnStart> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfTransLogPattern}</pattern> + <encoder> + <pattern>${transLogPattern}</pattern> </encoder> </appender> - + <appender name="asynctranslog" class="ch.qos.logback.classic.AsyncAppender"> <queueSize>1000</queueSize> <includeCallerData>true</includeCallerData> @@ -174,7 +194,7 @@ </appender> <appender name="dmaapAAIEventConsumer" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>WARN</level> </filter> @@ -183,13 +203,14 @@ <fileNamePattern>${logDirectory}/dmaapAAIEventConsumer/error.log.%d{yyyy-MM-dd} </fileNamePattern> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfLogPattern}</pattern> + <encoder> + <pattern>${errorPattern}</pattern> </encoder> + </appender> <appender name="dmaapAAIEventConsumerDebug" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> @@ -199,13 +220,33 @@ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${logDirectory}/dmaapAAIEventConsumer/debug.log.%d{yyyy-MM-dd} </fileNamePattern> + <maxHistory>14</maxHistory> + <cleanHistoryOnStart>true</cleanHistoryOnStart> + </rollingPolicy> + <encoder> + <pattern>${debugPattern}</pattern> + </encoder> + </appender> + <appender name="dmaapAAIEventConsumerInfo" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <filter class="ch.qos.logback.classic.filter.LevelFilter"> + <level>INFO</level> + <onMatch>ACCEPT</onMatch> + <onMismatch>DENY</onMismatch> + </filter> + <File>${logDirectory}/dmaapAAIEventConsumer/dmaap-transaction.log</File> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${logDirectory}/dmaapAAIEventConsumer/dmaap-transaction.log.%d{yyyy-MM-dd} + </fileNamePattern> + <maxHistory>14</maxHistory> + <cleanHistoryOnStart>true</cleanHistoryOnStart> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfLogPattern}</pattern> + <encoder> + <pattern>${auditPattern}</pattern> </encoder> </appender> <appender name="dmaapAAIEventConsumerMetric" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>INFO</level> <onMatch>ACCEPT</onMatch> @@ -215,13 +256,15 @@ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${logDirectory}/dmaapAAIEventConsumer/metrics.log.%d{yyyy-MM-dd} </fileNamePattern> + <maxHistory>14</maxHistory> + <cleanHistoryOnStart>true</cleanHistoryOnStart> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfMetricLogPattern}</pattern> + <encoder> + <pattern>${metricPattern}</pattern> </encoder> </appender> <appender name="external" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>WARN</level> </filter> @@ -229,161 +272,90 @@ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${logDirectory}/external/external.log.%d{yyyy-MM-dd} </fileNamePattern> + <maxHistory>14</maxHistory> + <cleanHistoryOnStart>true</cleanHistoryOnStart> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfLogPattern}</pattern> + <encoder> + <pattern>${debugPattern}</pattern> </encoder> </appender> - <logger name="org.onap.aai" level="DEBUG" additivity="false"> - <appender-ref ref="asyncDEBUG" /> - <appender-ref ref="asyncERROR" /> - <appender-ref ref="asyncMETRIC" /> - <appender-ref ref="asyncSANE" /> - </logger> + <appender name="auth" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> + <level>DEBUG</level> + </filter> + <file>${logDirectory}/auth/auth.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${logDirectory}/auth/auth.log.%d{yyyy-MM-dd} + </fileNamePattern> + <maxHistory>14</maxHistory> + <cleanHistoryOnStart>true</cleanHistoryOnStart> + </rollingPolicy> + <encoder> + <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}[%thread] %-5level %logger{1024} - %msg%n</pattern> + </encoder> + </appender> + <appender name="asyncAUTH" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>1000</queueSize> + <includeCallerData>true</includeCallerData> + <appender-ref ref="auth" /> + </appender> + <!-- logback internals logging --> + + <logger name="ch.qos.logback.classic" level="WARN" /> + <logger name="ch.qos.logback.core" level="WARN" /> + <logger name="com.att.aft.dme2" level="WARN" /> + <logger name="com.jayway.jsonpath" level="WARN" /> + + <logger name="org.apache" level="OFF" /> + <logger name="org.apache.commons" level="WARN" /> + <logger name="org.apache.zookeeper" level="OFF" /> + <logger name="org.codehaus.groovy" level="WARN" /> + <logger name="org.eclipse.jetty" level="WARN" /> <!-- Spring related loggers --> <logger name="org.springframework" level="WARN" /> <logger name="org.springframework.beans" level="WARN" /> <logger name="org.springframework.web" level="WARN" /> - <logger name="com.blog.spring.jms" level="WARN" /> - <logger name="com.jayway.jsonpath" level="WARN" /> - - <!-- AJSC Services (bootstrap services) --> - <logger name="ajsc" level="WARN" /> - <logger name="ajsc.RouteMgmtService" level="WARN" /> - <logger name="ajsc.ComputeService" level="WARN" /> - <logger name="ajsc.VandelayService" level="WARN" /> - <logger name="ajsc.FilePersistenceService" level="WARN" /> - <logger name="ajsc.UserDefinedJarService" level="WARN" /> - <logger name="ajsc.UserDefinedBeansDefService" level="WARN" /> - <logger name="ajsc.LoggingConfigurationService" level="WARN" /> - - <!-- AJSC related loggers (DME2 Registration, csi logging, restlet, servlet - logging) --> - <logger name="org.codehaus.groovy" level="WARN" /> - <logger name="com.att.scamper" level="WARN" /> - <logger name="ajsc.utils" level="WARN" /> - <logger name="ajsc.utils.DME2Helper" level="WARN" /> - <logger name="ajsc.filters" level="WARN" /> - <logger name="ajsc.beans.interceptors" level="WARN" /> - <logger name="ajsc.restlet" level="WARN" /> - <logger name="ajsc.servlet" level="WARN" /> - <logger name="com.att.ajsc" level="WARN" /> - <logger name="com.att.ajsc.csi.logging" level="WARN" /> - <logger name="com.att.ajsc.filemonitor" level="WARN" /> - <logger name="com.netflix.loadbalancer" level="WARN" /> - - <logger name="org.apache.zookeeper" level="WARN" /> - - <!-- Other Loggers that may help troubleshoot --> - <logger name="net.sf" level="WARN" /> - <logger name="org.apache.commons.httpclient" level="WARN" /> - <logger name="org.apache.commons" level="WARN" /> - <logger name="org.apache.coyote" level="WARN" /> - <logger name="org.apache.jasper" level="WARN" /> - <logger name="org.onap.aaf" level="DEBUG" /> - - <!-- Camel Related Loggers (including restlet/servlet/jaxrs/cxf logging. - May aid in troubleshooting) --> - <logger name="org.apache.camel" level="WARN" /> - <logger name="org.apache.cxf" level="WARN" /> - <logger name="org.apache.camel.processor.interceptor" level="WARN" /> - <logger name="org.apache.cxf.jaxrs.interceptor" level="WARN" /> - <logger name="org.apache.cxf.service" level="WARN" /> - <logger name="org.restlet" level="WARN" /> - <logger name="org.apache.camel.component.restlet" level="WARN" /> - - <logger name="org.hibernate.validator" level="WARN" /> - <logger name="org.hibernate" level="WARN" /> - <logger name="org.hibernate.ejb" level="OFF" /> - - <!-- logback internals logging --> - <logger name="ch.qos.logback.classic" level="WARN" /> - <logger name="ch.qos.logback.core" level="WARN" /> + <logger name="org.janusgraph" level="WARN" /> + <logger name="org.zookeeper" level="OFF" /> - <logger name="org.eclipse.jetty" level="WARN" /> - <!-- logback jms appenders & loggers definition starts here --> - <appender name="auditLogs" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <filter class="ch.qos.logback.classic.filter.ThresholdFilter" /> - <file>${logDirectory}/perf-audit/Audit-${lrmRVer}-${lrmRO}-${Pid}.log - </file> - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${logDirectory}/perf-audit/Audit-${lrmRVer}-${lrmRO}-${Pid}.%i.log.zip - </fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>9</maxIndex> - </rollingPolicy> - <triggeringPolicy - class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>5MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>"%d [%thread] %-5level %logger{1024} - %msg%n"</pattern> - </encoder> - </appender> - <appender name="perfLogs" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <filter class="ch.qos.logback.classic.filter.ThresholdFilter" /> - <file>${logDirectory}/perf-audit/Perform-${lrmRVer}-${lrmRO}-${Pid}.log - </file> - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${logDirectory}/perf-audit/Perform-${lrmRVer}-${lrmRO}-${Pid}.%i.log.zip - </fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>9</maxIndex> - </rollingPolicy> - <triggeringPolicy - class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>5MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>"%d [%thread] %-5level %logger{1024} - %msg%n"</pattern> - </encoder> - </appender> - <logger name="AuditRecord" level="INFO" additivity="false"> - <appender-ref ref="auditLogs" /> - </logger> - <logger name="AuditRecord_DirectCall" level="INFO" additivity="false"> - <appender-ref ref="auditLogs" /> + <logger name="org.onap.aai" level="DEBUG" additivity="false"> + <appender-ref ref="asyncDEBUG" /> + <appender-ref ref="asyncSANE" /> </logger> - <logger name="PerfTrackerRecord" level="INFO" additivity="false"> - <appender-ref ref="perfLogs" /> + <logger name="org.onap.aai.aaf" level="DEBUG" additivity="false"> + <appender-ref ref="asyncAUTH" /> </logger> - <!-- logback jms appenders & loggers definition ends here --> - - <logger name="org.onap.aai.interceptors.post" level="DEBUG" - additivity="false"> + <logger name="org.onap.logging.filter.base.AbstractAuditLogFilter" level="INFO"> + <appender-ref ref="asyncAUDIT"/> + </logger> + <logger name="org.onap.aai.aailog.logs.AaiScheduledTaskAuditLog" level="INFO"> + <appender-ref ref="asyncAUDIT"/> + </logger> + <logger name="org.onap.aai.aailog.logs.AaiDBTraversalMetricLog" level="INFO"> + <appender-ref ref="asyncMETRIC"/> + </logger> + <logger name="org.onap.aai.aailog.logs.AaiDmaapMetricLog" level="INFO"> + <appender-ref ref="dmaapAAIEventConsumerMetric"/> + </logger> + <logger name="org.onap.aai.logging.ErrorLogHelper" level="WARN"> + <appender-ref ref="asyncERROR"/> + </logger> + <logger name="org.onap.aai.interceptors.post" level="DEBUG" additivity="false"> <appender-ref ref="asynctranslog" /> </logger> - - <logger name="org.onap.aai.interceptors.pre.SetLoggingContext" level="DEBUG"> - <appender-ref ref="asyncAUDIT"/> - </logger> - - <logger name="org.onap.aai.interceptors.post.ResetLoggingContext" level="DEBUG"> - <appender-ref ref="asyncAUDIT"/> + <logger name="org.onap.aai.web.JerseyConfiguration" level="DEBUG" additivity="false"> + <appender-ref ref="asyncDEBUG" /> </logger> - <logger name="org.onap.aai.dmaap" level="DEBUG" additivity="false"> <appender-ref ref="dmaapAAIEventConsumer" /> <appender-ref ref="dmaapAAIEventConsumerDebug" /> - <appender-ref ref="dmaapAAIEventConsumerMetric" /> </logger> - <logger name="org.apache" level="WARN" /> - <logger name="org.zookeeper" level="WARN" /> - <logger name="org.janusgraph" level="WARN" /> - <logger name="com.att.aft.dme2" level="WARN" /> - - <!-- ============================================================================ --> - <!-- General EELF logger --> - <!-- ============================================================================ --> - <logger name="com.att.eelf" level="WARN" additivity="false"> - <appender-ref ref="asyncDEBUG" /> - <appender-ref ref="asyncERROR" /> - <appender-ref ref="asyncMETRIC" /> + <logger name="com.att.nsa.mr" level="INFO" > + <appender-ref ref="dmaapAAIEventConsumerInfo" /> </logger> <root level="DEBUG"> diff --git a/aai-traversal/src/main/resources/schema/onap/query/stored-queries.json b/aai-traversal/src/main/resources/schema/onap/query/stored-queries.json index edbeff8..327a0b5 100644 --- a/aai-traversal/src/main/resources/schema/onap/query/stored-queries.json +++ b/aai-traversal/src/main/resources/schema/onap/query/stored-queries.json @@ -59,7 +59,7 @@ }, "stored-query":"builder.createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'pnf').getVerticesByProperty('equip-vendor', equipVendor).getVerticesByProperty('equip-model', equipModel).store('x').cap('x').unfold().dedup()" } - },{ + },{ "pnf-fromModel-byRegion":{ "query":{ "required-properties":["equipVendor","equipModel","cloudRegionId"] @@ -95,13 +95,6 @@ "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'logical-link').where(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'logical-link', 'l-interface').getVerticesByProperty('interface-id', interfaceId).store('x')).union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'logical-link', 'l-interface').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vserver').createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'logical-link', 'generic-vnf').store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'pnf').store('x')).cap('x').unfold().dedup()" } },{ - "pserver-fromConfigurationFilterInterfaceId":{ - "query":{ - "required-properties":["interfaceId"] - }, - "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'logical-link').where(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'logical-link', 'l-interface').getVerticesByProperty('interface-id', interfaceId).store('x')).union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'logical-link', 'l-interface').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vserver').createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'logical-link', 'generic-vnf').store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'pnf').store('x')).cap('x').unfold().dedup()" - } - },{ "cloudRegion-fromCountry":{ "stored-query":"builder.createEdgeTraversal(EdgeType.COUSIN, 'complex', 'cloud-region').store('x').cap('x').unfold().dedup()" } @@ -261,19 +254,19 @@ "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'service-instance', 'service-subscription').store('x').createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'customer').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'forwarding-path').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'forwarding-path', 'configuration').store('x').createEdgeTraversal(EdgeType.TREE, 'configuration', 'evc').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'forwarding-path', 'forwarder').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'forwarder', 'configuration').store('x').createEdgeTraversal(EdgeType.TREE, 'configuration', 'forwarder-evc').store('x').createEdgeTraversal(EdgeType.TREE, 'forwarder-evc', 'vlan-mapping').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'forwarder', 'p-interface').store('x').createEdgeTraversal(EdgeType.TREE, 'p-interface', 'pnf').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'forwarder', 'lag-interface').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'lag-interface', 'pnf').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'lag-interface', 'logical-link').getVerticesByProperty('link-type', 'LAG').store('x'))))).cap('x').unfold().dedup()" } },{ - "count-vnf-byVnfType":{ + "count-vnf-byVnfType":{ "stored-query":"builder.getVerticesByProperty('aai-node-type', 'generic-vnf').groupCount().by('vnf-type').store('x').unfold()" - } + } },{ - "pservers-withNoComplex":{ + "pservers-withNoComplex":{ "stored-query":"builder.getVerticesByProperty('aai-node-type', 'pserver').where(builder.newInstance().not(builder.newInstance().both().getVerticesByProperty('aai-node-type', 'complex'))).store('x').unfold()" - } + } },{ "gfp-vserver-data":{ "stored-query":"builder.createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv4-address-list').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv6-address-list').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').store('x')).cap('x').unfold().dedup()" } },{ - "gfp-vnf-data":{ + "gfp-vnf-data":{ "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'l-interface').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv4-address-list').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv6-address-list').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv4-address-list').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv6-address-list').store('x'))),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'lag-interface').createEdgeTraversal(EdgeType.TREE, 'lag-interface', 'l-interface').store('x').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv4-address-list').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv6-address-list').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vnf-image').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'network-profile').store('x')).cap('x').unfold().dedup()" } },{ @@ -284,7 +277,7 @@ }, "stored-query":"builder.createEdgeTraversal(edgeType, startingNodeType, relatedToNodeType).store('x').cap('x').unfold().dedup()" } - },{ + },{ "gfp-vserver":{ "stored-query":"builder.where(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant'))" } @@ -299,39 +292,10 @@ }, "stored-query":"builder.where(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vnfc', 'vserver').createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').getVerticesByProperty('network-name',networkName)).createEdgeTraversal(EdgeType.COUSIN, 'vnfc', 'vserver').store('x').createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').getVerticesByProperty('network-name',networkName).store('x').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l-interface').store('x').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').store('x').cap('x').unfold().dedup()" } - },{ - "containment-path":{ - "stored-query":"builder.until(builder.newInstance().not(builder.newInstance().getParentEdge())).repeat(builder.newInstance().getParentVertex()).path()" - } - }, - { - "getSvcSubscriberModelInfo":{ - "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'service-instance', 'service-subscription').store('x'),builder.newInstance().createPrivateEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'model-ver').store('x')).cap('x').unfold().dedup()" - } - }, - { - "vnf-vserver-fromCustomer":{ - "stored-query":"builder.createEdgeTraversal(EdgeType.TREE, 'customer', 'service-subscription').createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'service-instance').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').cap('x').unfold().dedup()" - } - }, - { - "getCustomerVPNBondingServiceDetails":{ - "stored-query":"builder.union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'customer').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'service-instance').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'configuration').getVerticesByProperty('configuration-type', 'VLAN-NETWORK-RECEPTOR').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'generic-vnf').store('x').createEdgeTraversalWithLabels(EdgeType.COUSIN, 'generic-vnf', 'instance-group', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.MemberOf'))).store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'l3-network').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l3-network', 'subnet').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'subnet', 'l3-interface-ipv6-address-list').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'subnet', 'l3-interface-ipv4-address-list').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'vpn-binding').store('x').createEdgeTraversal(EdgeType.TREE, 'vpn-binding', 'route-target').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'l-interface').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l-interface').store('x'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'configuration').getVerticesByProperty('configuration-type', 'VRF ENTRY').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'vpn-binding').store('x').createEdgeTraversal(EdgeType.TREE, 'vpn-binding', 'route-target').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'pnf').getVerticesByProperty('nf-role','D2IPE').store('x')))).cap('x').unfold().dedup()" - } - }, - { - "vnf-summary-fromVnf": { - "stored-query": "builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'platform').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'line-of-business').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'owning-entity').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'project').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').store('x')).cap('x').unfold().dedup()" - } - }, - { - "getComplexAndPservers":{ - "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'complex','pserver').store('x').cap('x').unfold().dedup()" - } - },{ - "cloud-region-and-source-FromConfiguration":{ - "stored-query":"builder.createEdgeTraversal(EdgeType.COUSIN, 'configuration','logical-link').createEdgeTraversalWithLabels(EdgeType.COUSIN, 'logical-link', 'l-interface',new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.Source'))).createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vserver').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'vf-module').createEdgeTraversal(EdgeType.TREE, 'vf-module', 'generic-vnf').store('x')).cap('x').unfold().dedup()" - } + },{ + "vnfs-vlans-fromServiceInstance":{ + "stored-query":"builder.createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'configuration').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'generic-vnf').store('x'), builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'l-interface').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').store('x')).cap('x').unfold().dedup()" + } },{ "getClfiRoadmTailSummary":{ "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN,'logical-link', 'p-interface').store('x').createEdgeTraversal(EdgeType.TREE,'p-interface', 'pnf').store('x'), builder.newInstance().createEdgeTraversal(EdgeType.COUSIN,'logical-link', 'logical-link').createEdgeTraversal(EdgeType.COUSIN,'logical-link', 'service-instance').store('x').createEdgeTraversal(EdgeType.TREE,'service-instance', 'service-subscription').store('x').createEdgeTraversal(EdgeType.TREE,'service-subscription', 'customer').store('x')).cap('x').unfold().dedup()" @@ -341,10 +305,22 @@ "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.TREE,'pnf', 'p-interface').store('x').createEdgeTraversal(EdgeType.COUSIN,'p-interface', 'logical-link').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN,'logical-link', 'p-interface').store('x').createEdgeTraversal(EdgeType.TREE,'p-interface', 'pnf').store('x'), builder.newInstance().createEdgeTraversal(EdgeType.COUSIN,'logical-link', 'logical-link').createEdgeTraversal(EdgeType.COUSIN,'logical-link', 'service-instance').store('x').createEdgeTraversal(EdgeType.TREE,'service-instance', 'service-subscription').store('x').createEdgeTraversal(EdgeType.TREE,'service-subscription', 'customer').store('x')).cap('x').unfold().dedup()" } },{ + "topology-summary-fromCloudRegion":{ + "stored-query": "builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'cloud-region', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'vserver').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').store('x'), builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'vnfc').store('x'), builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'generic-vnf').store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vnfc').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'cloud-region', 'pserver').store('x')).cap('x').unfold().dedup()" + } + }, { "vservers-fromPserver-tree": { "stored-query": "builder.createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'vserver').tree()" } - },{ + },{ + "cloud-region-and-source-FromConfiguration":{ + "stored-query":"builder.createEdgeTraversal(EdgeType.COUSIN, 'configuration','logical-link').createEdgeTraversalWithLabels(EdgeType.COUSIN, 'logical-link', 'l-interface',new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.Source'))).createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vserver').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'vf-module').createEdgeTraversal(EdgeType.TREE, 'vf-module', 'generic-vnf').store('x')).cap('x').unfold().dedup()" + } + },{ + "destination-FromConfiguration":{ + "stored-query":"builder.createEdgeTraversal(EdgeType.COUSIN, 'configuration','logical-link').union(builder.newInstance().createEdgeTraversalWithLabels(EdgeType.COUSIN, 'logical-link', 'l-interface', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.Destination'))).createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vserver').createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'vf-module').createEdgeTraversal(EdgeType.TREE, 'vf-module', 'generic-vnf').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'logical-link', 'generic-vnf').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'pnf').store('x')).cap('x').unfold().dedup()" + } + },{ "topology-summary-fromTenant":{ "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'tenant', 'vserver').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'generic-vnf').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').store('x'))).cap('x').unfold().dedup()" } @@ -352,11 +328,7 @@ "vfModule-fromServiceInstance":{ "stored-query":"builder.createEdgeTraversal(EdgeType.COUSIN, 'service-instance','generic-vnf').createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'vf-module').store('x').cap('x').unfold().dedup()" } - },{ - "topology-summary-fromCloudRegion":{ - "stored-query": "builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'cloud-region', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'vserver').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').store('x'), builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'vnfc').store('x'), builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'generic-vnf').store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vnfc').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'cloud-region', 'pserver').store('x')).cap('x').unfold().dedup()" - } - }, { + },{ "getComplexByPnfName":{ "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN,'pnf', 'complex').store('x').cap('x').unfold().dedup()" } @@ -375,41 +347,43 @@ "network-collection-ByServiceInstance":{ "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'collection').store('x').createEdgeTraversal(EdgeType.COUSIN, 'collection', 'instance-group').store('x').createEdgeTraversal(EdgeType.COUSIN, 'instance-group', 'l3-network').store('x').cap('x').unfold().dedup()" } - },{ - "getServiceTopology":{ - "stored-query":"builder.union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'l-interface').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv6-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv6-address-list'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv6-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv6-address-list'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'complex'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'allotted-resource').createEdgeTraversal(EdgeType.TREE, 'allotted-resource', 'service-instance').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'l-interface').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv6-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv6-address-list'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv6-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv6-address-list')))))).tree()"} - }, - { - "getL3networkCloudRegionByNetworkRole": { - "stored-query": "builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'generic-vnf').store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x').cap('x').unfold().dedup()" - } },{ - "getNetworks": { - "query":{ - "required-properties":["networkRole","cloudRegionId"] - }, - "stored-query": "builder.createEdgeTraversal(EdgeType.COUSIN, 'owning-entity','service-instance').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'l3-network').getVerticesByProperty('network-role', networkRole).where(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'cloud-region').getVerticesByProperty('cloud-region-id', cloudRegionId)).store('x').cap('x').unfold().dedup()" - } - },{ + "containment-path":{ + "stored-query":"builder.until(builder.newInstance().not(builder.newInstance().getParentEdge())).repeat(builder.newInstance().getParentVertex()).path()" + } + },{ + "getSvcSubscriberModelInfo":{ + "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'service-instance', 'service-subscription').store('x'),builder.newInstance().createPrivateEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'model-ver').store('x')).cap('x').unfold().dedup()" + } + }, + { "getLogicalLinkByCloudRegionId": { "stored-query": "builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region', 'logical-link').store('x').cap('x').unfold().dedup()" } - },{ - "getPinterfacePhysicalLinkBySvcInstId":{ + },{ + "getPinterfacePhysicalLinkBySvcInstId":{ "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN,'service-instance', 'generic-vnf').store('x').createEdgeTraversal(EdgeType.COUSIN,'generic-vnf', 'vserver').store('x').createEdgeTraversal(EdgeType.COUSIN,'vserver', 'pserver').store('x').createEdgeTraversal(EdgeType.TREE,'pserver', 'p-interface').store('x').createEdgeTraversal(EdgeType.COUSIN,'p-interface', 'physical-link').store('x').cap('x').unfold().dedup()" - } - },{ - "getNetworksByServiceInstance": { - "stored-query": "builder.createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'l3-network').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'vlan-tag').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'l3-network').store('x').createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'vlan-tag').store('x')).cap('x').unfold().dedup()" - } - }, - { - "topology-detail-fromVnf":{ + } + },{ + "topology-detail-fromVnf":{ "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'vnfc').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x').createEdgeTraversal(EdgeType.TREE, 'cloud-region', 'availability-zone').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'image').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'flavor').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').store('x').createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'complex').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface','l3-interface-ipv4-address-list').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv6-address-list').store('x'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'vf-module').createEdgeTraversal(EdgeType.COUSIN, 'vf-module', 'volume-group').store('x')).cap('x').unfold().dedup()"} },{ "vnf-to-service-instance":{ "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').store('x').cap('x').unfold().dedup()"} - },{ + },{ + "getServiceTopology":{ + "stored-query":"builder.union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'l-interface').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv6-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv6-address-list'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv6-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv6-address-list'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'complex'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'allotted-resource').createEdgeTraversal(EdgeType.TREE, 'allotted-resource', 'service-instance').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'l-interface').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv6-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv6-address-list'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l3-interface-ipv6-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv4-address-list'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vlan', 'l3-interface-ipv6-address-list')))))).tree()"} + }, + { + "getL3networkCloudRegionByNetworkRole": { + "stored-query": "builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'generic-vnf').store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x').cap('x').unfold().dedup()" + } + },{ + "getDHVLogicalLink": { + "stored-query": "builder.createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'l-interface').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').createEdgeTraversal(EdgeType.COUSIN, 'vlan', 'logical-link').tree()" + } + }, + { "pserver-fromHostnameFirstToken": { "query":{ "required-properties":["hostnameFirstToken","sourcesOfTruth"] @@ -417,7 +391,7 @@ "stored-query": "builder.getVerticesStartsWithProperty('hostname', hostnameFirstToken).getVerticesByProperty('source-of-truth', new ArrayList<>(Arrays.asList(sourcesOfTruth)))" } }, - { + { "pserver-fromFqdnFirstToken": { "query":{ "required-properties":["fqdnFirstToken","sourcesOfTruth"] @@ -425,26 +399,12 @@ "stored-query": "builder.getVerticesStartsWithProperty('fqdn', fqdnFirstToken).getVerticesByProperty('source-of-truth', new ArrayList<>(Arrays.asList(sourcesOfTruth)))" } }, - { + { "cloud-regions-by-generic-vnf-HG-pairs": { - "stored-query": "builder.createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'service-instance').as('a').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'allotted-resource').createEdgeTraversal(EdgeType.TREE, 'allotted-resource', 'service-instance').createEdgeTraversal(EdgeType.TREE, 'service-instance', 'service-subscription').getVerticesByProperty('service-type', 'HNGATEWAY').createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'service-instance').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').getVerticesByProperty('vnf-type', 'HG').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').as('b').select('a','b').by('aai-uri')" + "stored-query": "builder.createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'service-instance').as('a').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'allotted-resource').createEdgeTraversal(EdgeType.TREE, 'allotted-resource', 'service-instance').createEdgeTraversal(EdgeType.TREE, 'service-instance', 'service-subscription').getVerticesByProperty('service-type', 'HNGATEWAY').createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'service-instance').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').getVerticesByProperty('vnf-type', 'HG').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').as('b').select('a','b').by('aai-uri')" } }, { - "getDHVLogicalLink": { - "stored-query": "builder.createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'l-interface').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').createEdgeTraversal(EdgeType.COUSIN, 'vlan', 'logical-link').tree()" - } - }, - { - "destination-FromConfiguration":{ - "stored-query":"builder.createEdgeTraversal(EdgeType.COUSIN, 'configuration','logical-link').union(builder.newInstance().createEdgeTraversalWithLabels(EdgeType.COUSIN, 'logical-link', 'l-interface', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.Destination'))).createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vserver').createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'vf-module').createEdgeTraversal(EdgeType.TREE, 'vf-module', 'generic-vnf').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'logical-link', 'generic-vnf').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'pnf').store('x')).cap('x').unfold().dedup()" - } - },{ - "fabric-information-fromVnf":{ - "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'sriov-vf').createEdgeTraversal(EdgeType.COUSIN, 'sriov-vf', 'sriov-pf').createEdgeTraversal(EdgeType.TREE, 'sriov-pf', 'p-interface').store('x').createEdgeTraversal(EdgeType.TREE, 'p-interface', 'pserver').store('x'), builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'vnfc').store('x').createEdgeTraversal(EdgeType.TREE, 'vnfc', 'cp').createEdgeTraversal(EdgeType.COUSIN, 'cp', 'vlan-tag').store('x')).cap('x').unfold().dedup()" - } - }, - { "getLinterface-fromNewvce": { "query":{ "required-properties":["interfaceRole1","interfaceRole2"] @@ -460,18 +420,135 @@ "stored-query": "builder.union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vnfc', 'cp').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'cp', 'vlan-tag').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'cp', 'l3-network').getVerticesByBooleanProperty('is-provider-network', isProviderNetwork).store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vnfc', 'vserver').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').store('x'))).cap('x').unfold().dedup()" } }, - { - "vnf-to-esr-system-info":{ - "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x').createEdgeTraversal(EdgeType.TREE, 'cloud-region', 'esr-system-info').store('x').cap('x').unfold().dedup()" + { + "getNetworks": { + "query":{ + "required-properties":["networkRole","cloudRegionId"] + }, + "stored-query": "builder.createEdgeTraversal(EdgeType.COUSIN, 'owning-entity','service-instance').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'l3-network').getVerticesByProperty('network-role', networkRole).where(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'cloud-region').getVerticesByProperty('cloud-region-id', cloudRegionId)).store('x').cap('x').unfold().dedup()" + } + },{ + "getTenantInfoAtSvcSubscription": { + "stored-query": "builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'service-subscription', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region', 'complex').store('x').cap('x').unfold().dedup()" + } + }, + { + "fabric-information-fromVnf":{ + "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'sriov-vf').createEdgeTraversal(EdgeType.COUSIN, 'sriov-vf', 'sriov-pf').createEdgeTraversal(EdgeType.TREE, 'sriov-pf', 'p-interface').store('x').createEdgeTraversal(EdgeType.TREE, 'p-interface', 'pserver').store('x'), builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'vnfc').store('x').createEdgeTraversal(EdgeType.TREE, 'vnfc', 'cp').createEdgeTraversal(EdgeType.COUSIN, 'cp', 'vlan-tag').store('x')).cap('x').unfold().dedup()" + } + }, + { + "getNetworksByServiceInstance": { + "stored-query": "builder.createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'l3-network').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'vlan-tag').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'l3-network').store('x').createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'vlan-tag').store('x')).cap('x').unfold().dedup()" + } + }, + { + "ips-networks-fromVnf": { + "stored-query": "builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vnfc').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vnfc','vip-ipv4-address-list').store('x').createEdgeTraversal(EdgeType.COUSIN, 'vip-ipv4-address-list', 'subnet').store('x').createEdgeTraversal(EdgeType.TREE, 'subnet', 'l3-network').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vnfc', 'vip-ipv6-address-list').store('x').createEdgeTraversal(EdgeType.COUSIN, 'vip-ipv6-address-list', 'subnet').store('x').createEdgeTraversal(EdgeType.TREE, 'subnet', 'l3-network').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vnfc', 'l3-interface-ipv4-address-list').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-interface-ipv4-address-list', 'l3-network').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-interface-ipv4-address-list', 'subnet').store('x').createEdgeTraversal(EdgeType.TREE, 'subnet', 'l3-network').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vnfc', 'l3-interface-ipv6-address-list').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-interface-ipv6-address-list', 'l3-network').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-interface-ipv6-address-list', 'subnet').store('x').createEdgeTraversal(EdgeType.TREE, 'subnet', 'l3-network').store('x'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').createEdgeTraversal(EdgeType.COUSIN, 'vserver','pserver').store('x').createEdgeTraversal(EdgeType.COUSIN, 'pserver','complex').store('x')).cap('x').unfold().dedup()" + } + }, + { + "vnf-vserver-fromCustomer":{ + "stored-query":"builder.createEdgeTraversal(EdgeType.TREE, 'customer', 'service-subscription').createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'service-instance').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').cap('x').unfold().dedup()" + } + }, + { + "getCustomerVPNBondingServiceDetails":{ + "stored-query":"builder.union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'customer').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'service-instance').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'configuration').getVerticesByProperty('configuration-type', 'VLAN-NETWORK-RECEPTOR').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'generic-vnf').store('x').createEdgeTraversalWithLabels(EdgeType.COUSIN, 'generic-vnf', 'instance-group', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.MemberOf'))).store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'l3-network').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l3-network', 'subnet').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'subnet', 'l3-interface-ipv6-address-list').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'subnet', 'l3-interface-ipv4-address-list').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'vpn-binding').store('x').createEdgeTraversal(EdgeType.TREE, 'vpn-binding', 'route-target').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'l-interface').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l-interface').store('x'))),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'configuration').getVerticesByProperty('configuration-type', 'VRF ENTRY').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'vpn-binding').store('x').createEdgeTraversal(EdgeType.TREE, 'vpn-binding', 'route-target').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'pnf').getVerticesByProperty('nf-role','D2IPE').store('x')))).cap('x').unfold().dedup()" + } + }, + { + "getServiceInstanceVnfVfModuleModels":{ + "stored-query":"builder.store('x').union(builder.newInstance().createPrivateEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'model-ver').store('x').createEdgeTraversal(EdgeType.TREE, 'model-ver', 'model').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').store('x').union(builder.newInstance().createPrivateEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'model-ver').store('x').createEdgeTraversal(EdgeType.TREE, 'model-ver', 'model').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'vf-module').store('x').createPrivateEdgeTraversal(EdgeType.COUSIN, 'vf-module', 'model-ver').store('x').createEdgeTraversal(EdgeType.TREE, 'model-ver', 'model').store('x'))).cap('x').unfold().dedup()" + } + }, + { + "closed-loop":{ + "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'generic-vnf').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'vf-module').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x')).cap('x').unfold().dedup()" + } + }, + { + "getVserverDetail":{ + "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'generic-vnf').store('x').union(builder.newInstance().createPrivateEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'model-ver').store('x').createEdgeTraversal(EdgeType.TREE, 'model-ver', 'model').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'vf-module').store('x').createPrivateEdgeTraversal(EdgeType.COUSIN, 'vf-module', 'model-ver').store('x').createEdgeTraversal(EdgeType.TREE, 'model-ver', 'model').store('x'), builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x').createPrivateEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'model-ver').store('x').createEdgeTraversal(EdgeType.TREE, 'model-ver', 'model').store('x'))).cap('x').unfold().dedup()" + } + }, + { + "getTenantInfoAtSvcInstance":{ + "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region', 'complex').store('x').cap('x').unfold().dedup()" + } + }, + { + "getServiceInstanceSummary":{ + "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'l3-network').createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'cloud-region').store('x'), builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'service-instance', 'service-subscription').store('x').createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'customer').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x')).cap('x').unfold().dedup()" } }, { + "vnf-to-esr-system-info":{ + "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x').createEdgeTraversal(EdgeType.TREE, 'cloud-region', 'esr-system-info').store('x').cap('x').unfold().dedup()" + } + }, + { + "getComplexAndPservers":{ + "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'complex','pserver').store('x').cap('x').unfold().dedup()" + } + }, + { + "getWlBundleId":{ + "stored-query":"builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'lag-link', 'logical-link').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN,'logical-link', 'service-instance').store('x').createEdgeTraversal(EdgeType.TREE, 'service-instance', 'service-subscription').store('x').createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'customer').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN,'logical-link', 'logical-link').store('x')).cap('x').unfold().dedup()" + } + }, + { + "getVnfVlanByCircuitId": { + "stored-query": "builder.store('x').createEdgeTraversal(EdgeType.COUSIN, 'logical-link', 'vlan').store('x').createEdgeTraversal(EdgeType.TREE, 'vlan', 'l-interface').store('x').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'generic-vnf').store('x').cap('x').unfold().dedup()" + } + }, + { + "getVNFVpnBondingServiceDetails":{ + "stored-query":"builder.union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'l-interface').store('x').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'l-interface').store('x').createEdgeTraversal(EdgeType.TREE, 'l-interface', 'vlan').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'configuration').getVerticesByProperty('configuration-type', 'VLAN-NETWORK-RECEPTOR').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'configuration').getVerticesByProperty('configuration-type', 'VRF-ENTRY').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'service-instance').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'configuration', 'l3-network').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'l3-network', 'subnet').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'subnet', 'l3-interface-ipv6-address-list').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'subnet', 'l3-interface-ipv4-address-list').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'l3-network', 'vpn-binding').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vpn-binding', 'customer').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vpn-binding', 'route-target').store('x'))))).cap('x').unfold().dedup()" + } + }, + { "genericVnfs-fromPserver":{ "query":{ "optional-properties":["vnfType","nfFunction","nfRole","nfNamingCode"] }, "stored-query":"builder.union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'generic-vnf'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'vserver').createEdgeTraversal('vserver','generic-vnf')).getVerticesByProperty('vnf-type',vnfType).getVerticesByProperty('nf-function',nfFunction).getVerticesByProperty('nf-role',nfRole).getVerticesByProperty('nf-naming-code',nfNamingCode).store('x').cap('x').unfold().dedup()" } + }, + { + "getComponentList1":{ + "stored-query":"builder.union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'l3-network').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'volume-group').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'vf-module').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vf-module', 'l3-network').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vf-module', 'vserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vf-module', 'volume-group').store('x')))).cap('x').unfold().dedup()" + } + }, + { + "getComponentList2":{ + "stored-query":"builder.union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'configuration').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'l3-network').store('x').createEdgeTraversal(EdgeType.TREE, 'l3-network', 'subnet').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'volume-group').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'vf-module').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vf-module', 'l3-network').store('x').createEdgeTraversal(EdgeType.TREE, 'l3-network', 'subnet').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN,'vf-module','vserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN,'vf-module','volume-group').store('x')))).cap('x').unfold().dedup()" + } + }, + { + "getComponentList3":{ + "stored-query":"builder.union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'l3-network').store('x').createEdgeTraversal(EdgeType.TREE, 'l3-network', 'subnet').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'volume-group').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'vf-module').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vf-module', 'l3-network').store('x').createEdgeTraversal(EdgeType.TREE, 'l3-network', 'subnet').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vf-module', 'vserver').createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vf-module', 'volume-group').store('x')))).cap('x').unfold().dedup()" + } + }, + { + "vnf-summary-fromVnf": { + "stored-query": "builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'platform').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'line-of-business').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'owning-entity').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'project').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').store('x')).cap('x').unfold().dedup()" + } + }, + { + "vnf-summary-fromVserver": { + "stored-query": "builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'generic-vnf').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'platform').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'line-of-business').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'owning-entity').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'project').store('x')))).cap('x').unfold().dedup()" + } + }, + { + "vnf-summary-fromPserver": { + "stored-query": "builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'generic-vnf').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'vserver').store('x').createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'generic-vnf').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'platform').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'line-of-business').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'owning-entity').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'project').store('x')))).cap('x').unfold().dedup()" + } + }, + { + "closed-loop":{ + "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'generic-vnf').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x').createEdgeTraversal(EdgeType.COUSIN, 'service-instance', 'generic-vnf').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'generic-vnf', 'vf-module').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').store('x').createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x')).cap('x').unfold().dedup()" + } } ] } diff --git a/aai-traversal/src/test/java/org/onap/aai/AAIGremlinQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/AAIGremlinQueryTest.java index 7f5b1d8..6d2d5ff 100644 --- a/aai-traversal/src/test/java/org/onap/aai/AAIGremlinQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/AAIGremlinQueryTest.java @@ -21,12 +21,16 @@ package org.onap.aai; import com.jayway.jsonpath.JsonPath; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; import org.janusgraph.core.JanusGraphTransaction; import org.junit.*; import org.onap.aai.config.PropertyPasswordConfiguration; import org.onap.aai.dbmap.AAIGraph; import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.queryformats.Format; import org.onap.aai.util.AAIConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; @@ -38,14 +42,12 @@ import org.springframework.test.context.junit4.rules.SpringClassRule; import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.web.client.RestTemplate; -import java.util.Base64; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.fail; /** @@ -68,6 +70,8 @@ public class AAIGremlinQueryTest { @ClassRule public static final SpringClassRule springClassRule = new SpringClassRule(); + private static final Logger logger = LoggerFactory.getLogger(AAIGremlinQueryTest.class); + @Rule public final SpringMethodRule springMethodRule = new SpringMethodRule(); @@ -158,16 +162,88 @@ public class AAIGremlinQueryTest { String result = JsonPath.read(responseEntity.getBody().toString(), "$.results[0].result"); assertThat(result, is("1")); + + } + + @Test + public void testPserverCountUsingGremlinReturnsJsonWhenAcceptIsMissing() throws Exception { + + headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("Accept", ""); + headers.add("Real-Time", "true"); + headers.add("X-FromAppId", "JUNIT"); + headers.add("X-TransactionId", "JUNIT"); + Map<String, String> gremlinQueryMap = new HashMap<>(); + gremlinQueryMap.put("gremlin-query", "g.V().has('hostname', 'test-pserver').count()"); + + String payload = PayloadUtil.getTemplatePayload("gremlin-query.json", gremlinQueryMap); + + ResponseEntity responseEntity = null; + + String endpoint = "/aai/v11/query?format=console"; + + httpEntity = new HttpEntity(payload, headers); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK)); + + String result = JsonPath.read(responseEntity.getBody().toString(), "$.results[0].result"); + assertThat(result, is("1")); } @Test + public void testPserverGremlinFormatsWithXmlResponse() throws Exception { + + Map<String, String> gremlinQueryMap = new HashMap<>(); + gremlinQueryMap.put("gremlin-query", "g.V().has('hostname', 'test-pserver')"); + + String payload = PayloadUtil.getTemplatePayload("gremlin-query.json", gremlinQueryMap); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); + httpEntity = new HttpEntity(payload, headers); + String endpoint = "/aai/v11/query?format=count"; + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK)); + assertThat(responseEntity.getBody().toString(), containsString("<results><result><pserver>1</pserver></result></results>")); + + gremlinQueryMap.put("gremlin-query", "g.V().has('hostname', 'test-pserver')"); + payload = PayloadUtil.getTemplatePayload("gremlin-query.json", gremlinQueryMap); + httpEntity = new HttpEntity(payload, headers); + + Format[] formats = new Format[]{ + Format.graphson, + Format.pathed, + Format.id, + Format.resource, + Format.simple, + Format.resource_and_url, + Format.console, + Format.raw, + Format.count + }; + + for(Format format : formats){ + + endpoint = "/aai/v11/query?format=" + format.toString(); + + logger.debug("Current endpoint being executed {}", endpoint); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK)); + + String responseBody = responseEntity.getBody().toString(); + logger.debug("Response from the gremlin query: {}", responseBody); + assertThat(responseBody, containsString("<results><result>")); + assertThat(responseBody, is(not(containsString("<result><result>")))); + } + } + @Test public void testPserverCountUsingDsl() throws Exception { Map<String, String> dslQuerymap = new HashMap<>(); dslQuerymap.put("dsl-query", "pserver*('hostname', 'test-pserver')"); String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQuerymap); - ResponseEntity responseEntity = null; + ResponseEntity responseEntity; String endpoint = "/aai/v11/dsl?format=console"; @@ -179,6 +255,50 @@ public class AAIGremlinQueryTest { assertThat(result, containsString("v[")); } + @Test + public void testPserverDslFormatsWithXmlResponse() throws Exception { + + Map<String, String> dslQuerymap = new HashMap<>(); + dslQuerymap.put("dsl-query", "pserver*('hostname', 'test-pserver')"); + + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQuerymap); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); + httpEntity = new HttpEntity(payload, headers); + String endpoint = "/aai/v11/dsl?format=count"; + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK)); + assertThat(responseEntity.getBody().toString(), containsString("<results><result><pserver>1</pserver></result></results>")); + + httpEntity = new HttpEntity(payload, headers); + + Format[] formats = new Format[]{ + Format.graphson, + Format.pathed, + Format.id, + Format.resource, + Format.simple, + Format.resource_and_url, + Format.console, + Format.raw, + Format.count + }; + + for(Format format : formats){ + + endpoint = "/aai/v11/dsl?format=" + format.toString(); + + logger.debug("Current endpoint being executed {}", endpoint); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK)); + + String responseBody = responseEntity.getBody().toString(); + logger.debug("Response from the dsl query: {}", responseBody); + assertThat(responseBody, containsString("<results><result>")); + assertThat(responseBody, is(not(containsString("<result><result>")))); + } + } + @After public void tearDown() { @@ -191,7 +311,7 @@ public class AAIGremlinQueryTest { g.V().has("source-of-truth", "JUNIT") .toList() - .forEach(v -> v.remove()); + .forEach(Vertex::remove); } catch(Exception ex){ success = false; diff --git a/aai-traversal/src/test/java/org/onap/aai/AAISetup.java b/aai-traversal/src/test/java/org/onap/aai/AAISetup.java index d43cde9..a13384a 100644 --- a/aai-traversal/src/test/java/org/onap/aai/AAISetup.java +++ b/aai-traversal/src/test/java/org/onap/aai/AAISetup.java @@ -61,6 +61,7 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule; RestBeanConfig.class, SearchConfiguration.class, DslConfiguration.class, + XmlFormatTransformerConfiguration.class, GremlinServerSingleton.class }) @TestPropertySource(properties = { diff --git a/aai-traversal/src/test/java/org/onap/aai/HttpTestUtil.java b/aai-traversal/src/test/java/org/onap/aai/HttpTestUtil.java index cfe15a1..f12c8c3 100644 --- a/aai-traversal/src/test/java/org/onap/aai/HttpTestUtil.java +++ b/aai-traversal/src/test/java/org/onap/aai/HttpTestUtil.java @@ -19,12 +19,9 @@ */ package org.onap.aai; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.javatuples.Pair; import org.mockito.Mockito; import org.onap.aai.config.SpringContextAware; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Introspector; import org.onap.aai.introspection.Loader; @@ -37,12 +34,15 @@ import org.onap.aai.restcore.RESTAPI; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.ws.rs.core.*; -import javax.xml.validation.Schema; import java.io.UnsupportedEncodingException; import java.net.URI; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.doReturn; @@ -50,7 +50,7 @@ import static org.mockito.Mockito.when; public class HttpTestUtil extends RESTAPI { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(HttpTestUtil.class); + private static final Logger logger = LoggerFactory.getLogger(HttpTestUtil.class); protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); @@ -116,7 +116,7 @@ public class HttpTestUtil extends RESTAPI { SchemaVersion version = null; - if(arr != null && arr.length > 1){ + if(arr.length > 1){ if(arr[0].matches("^v\\d+")){ version = new SchemaVersion(arr[0]); uri = uri.replaceAll("^v\\d+", ""); @@ -128,10 +128,8 @@ public class HttpTestUtil extends RESTAPI { } Mockito.when(uriInfo.getPath()).thenReturn(uri); - DBConnectionType type = DBConnectionType.REALTIME; HttpEntry resourceHttpEntry = SpringContextAware.getBean("traversalHttpEntry", HttpEntry.class); - resourceHttpEntry.setHttpEntryProperties(version, type); - // HttpEntry httpEntry = new HttpEntry(version, ModelType.MOXY, QueryStyle.TRAVERSAL, type); + resourceHttpEntry.setHttpEntryProperties(version); Loader loader = resourceHttpEntry.getLoader(); dbEngine = resourceHttpEntry.getDbEngine(); @@ -210,7 +208,7 @@ public class HttpTestUtil extends RESTAPI { SchemaVersion version = null; - if(arr != null && arr.length > 1){ + if(arr.length > 1){ if(arr[0].matches("^v\\d+")){ version = new SchemaVersion(arr[0]); uri = uri.replaceAll("^v\\d+", ""); @@ -221,11 +219,8 @@ public class HttpTestUtil extends RESTAPI { version = schemaVersions.getDefaultVersion(); } - DBConnectionType type = DBConnectionType.REALTIME; - - //HttpEntry httpEntry = new HttpEntry(version, ModelType.MOXY, QueryStyle.TRAVERSAL, type); HttpEntry resourceHttpEntry = SpringContextAware.getBean("traversalHttpEntry", HttpEntry.class); - resourceHttpEntry.setHttpEntryProperties(version, type); + resourceHttpEntry.setHttpEntryProperties(version); Loader loader = resourceHttpEntry.getLoader(); dbEngine = resourceHttpEntry.getDbEngine(); @@ -295,7 +290,7 @@ public class HttpTestUtil extends RESTAPI { SchemaVersion version = null; - if(arr != null && arr.length > 1){ + if(arr.length > 1){ if(arr[0].matches("^v\\d+")){ version = new SchemaVersion(arr[0]); if(!uri.contains("relationship-list/relationship")){ @@ -309,10 +304,8 @@ public class HttpTestUtil extends RESTAPI { } Mockito.when(uriInfo.getPath()).thenReturn(uri); - DBConnectionType type = DBConnectionType.REALTIME; HttpEntry resourceHttpEntry = SpringContextAware.getBean("traversalHttpEntry", HttpEntry.class); - resourceHttpEntry.setHttpEntryProperties(version, type); - // HttpEntry httpEntry = new HttpEntry(version, ModelType.MOXY, QueryStyle.TRAVERSAL, type); + resourceHttpEntry.setHttpEntryProperties(version); Loader loader = resourceHttpEntry.getLoader(); dbEngine = resourceHttpEntry.getDbEngine(); diff --git a/aai-traversal/src/test/java/org/onap/aai/QueryParameterTest.java b/aai-traversal/src/test/java/org/onap/aai/QueryParameterTest.java index 76a1277..7703df9 100644 --- a/aai-traversal/src/test/java/org/onap/aai/QueryParameterTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/QueryParameterTest.java @@ -19,7 +19,8 @@ */ package org.onap.aai; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.junit.Before; import org.junit.Test; @@ -49,7 +50,7 @@ import static org.junit.Assert.assertThat; @Import(TraversalTestConfiguration.class) public class QueryParameterTest { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(QueryParameterTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(QueryParameterTest.class); private HttpTestUtil httpTestUtil; diff --git a/aai-traversal/src/test/java/org/onap/aai/TraversalTestConfiguration.java b/aai-traversal/src/test/java/org/onap/aai/TraversalTestConfiguration.java index 552feb6..32ab70e 100644 --- a/aai-traversal/src/test/java/org/onap/aai/TraversalTestConfiguration.java +++ b/aai-traversal/src/test/java/org/onap/aai/TraversalTestConfiguration.java @@ -19,7 +19,8 @@ */ package org.onap.aai; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.HttpClients; @@ -46,7 +47,7 @@ import java.security.KeyStore; @TestConfiguration public class TraversalTestConfiguration { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(TraversalTestConfiguration.class); + private static final Logger logger = LoggerFactory.getLogger(TraversalTestConfiguration.class); @Autowired private Environment env; diff --git a/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java b/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java index 1f05785..80f6d34 100644 --- a/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java @@ -19,11 +19,8 @@ */ package org.onap.aai.dbgraphgen; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.T; @@ -35,28 +32,27 @@ import org.junit.Test; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.aai.AAISetup; -import org.onap.aai.db.props.AAIProperties; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.ModelType; import org.onap.aai.parsers.exceptions.AAIIdentityMapParseException; import org.onap.aai.serialization.db.DBSerializer; -import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.TransactionalGraphEngine; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; import org.onap.aai.setup.SchemaVersion; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class ModelBasedProcessingTest extends AAISetup{ private SchemaVersion version; private static final ModelType introspectorFactoryType = ModelType.MOXY; private static final QueryStyle queryStyle = QueryStyle.TRAVERSAL; - private static final DBConnectionType type = DBConnectionType.REALTIME; - + private static final String TRANSACTION_ID = "transaction-1"; private static final String FROM_APP_ID = "JUNIT"; private static final String API_VERSION = "1.0"; @@ -104,9 +100,8 @@ public class ModelBasedProcessingTest extends AAISetup{ public void init() throws AAIException { MockitoAnnotations.initMocks(this); version = schemaVersions.getDefaultVersion(); - //rules = EdgeRules.getInstance(); loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version); - TransactionalGraphEngine newDbEngine = new JanusGraphDBEngine(queryStyle, type, loader); + TransactionalGraphEngine newDbEngine = new JanusGraphDBEngine(queryStyle, loader); dbEngine = Mockito.spy(newDbEngine); serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); admin = Mockito.spy(dbEngine.asAdmin()); @@ -408,8 +403,7 @@ public class ModelBasedProcessingTest extends AAISetup{ strList.add("1"); strList.add("2"); strList.add("3"); - String listString = strList.toString(); - return listString; + return strList.toString(); } @Test @@ -876,12 +870,9 @@ public class ModelBasedProcessingTest extends AAISetup{ Vertex modelV = serviceGraph.addVertex(T.label, "model", T.id, "66", AAI_NODE_TYPE, "model", "model-invariant-id", "model-invariant-id-1", "model-type", "widget"); Vertex modelVerV = serviceGraph.addVertex(T.label, MODEL_VESION_NODE_VALUE, T.id, "67", AAI_NODE_TYPE, MODEL_VESION_NODE_VALUE, MODEL_VERSION_ID_KEY, MODEL_VERSION_ID_VALUE,MODEL_NAME_ID_KEY, MODEL_NAME_ID_VALUE, "model-version", "model-version-1"); - //Vertex modelElementV = graph.addVertex(T.label, "model-element", T.id, "68", AAI_NODE_TYPE, "model-element"); GraphTraversalSource gts = serviceGraph.traversal(); edgeSer.addTreeEdge(gts, modelV, modelVerV); - //rules4Service.addTreeEdge(gts, modelElementV, modelVerV); - //rules4Service.addEdge(gts, modelElementV, modelVerV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); diff --git a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphNamedQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphNamedQueryTest.java index 243fc6e..7839496 100644 --- a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphNamedQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphNamedQueryTest.java @@ -21,23 +21,18 @@ package org.onap.aai.dbgraphmap; import com.google.gson.JsonObject; import com.google.gson.JsonParser; - import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; +import org.onap.aai.AAISetup; import org.onap.aai.HttpTestUtil; import org.onap.aai.PayloadUtil; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; -import org.onap.aai.extensions.AAIExtensionMap; -import org.onap.aai.introspection.*; -import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.rest.util.AAIExtensionMap; import org.onap.aai.util.AAIConstants; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.*; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -48,8 +43,8 @@ import java.util.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; -import org.onap.aai.AAISetup; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class SearchGraphNamedQueryTest extends AAISetup{ @@ -92,6 +87,7 @@ public class SearchGraphNamedQueryTest extends AAISetup{ File dir = new File(widgetPath); File[] files = dir.listFiles(); + assert files != null; for ( File file : files) { try { Path path = Paths.get(widgetPath + AAIConstants.AAI_FILESEP + file.getName()); @@ -114,6 +110,7 @@ public class SearchGraphNamedQueryTest extends AAISetup{ File dir = new File(namedQueryPath); File[] files = dir.listFiles(); + assert files != null; for ( File file : files) { try { Path path = Paths.get(namedQueryPath + AAIConstants.AAI_FILESEP + file.getName()); @@ -160,8 +157,8 @@ public class SearchGraphNamedQueryTest extends AAISetup{ when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); - when(httpHeaders.getRequestHeader("X-FromAppId")).thenReturn(Arrays.asList("JUNIT")); - when(httpHeaders.getRequestHeader("X-TransactionId")).thenReturn(Arrays.asList("JUNIT")); + when(httpHeaders.getRequestHeader("X-FromAppId")).thenReturn(Collections.singletonList("JUNIT")); + when(httpHeaders.getRequestHeader("X-TransactionId")).thenReturn(Collections.singletonList("JUNIT")); when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); @@ -201,10 +198,10 @@ public class SearchGraphNamedQueryTest extends AAISetup{ aaiExtMap.setServletRequest(request); - response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, DBConnectionType.REALTIME, aaiExtMap); + response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, aaiExtMap); System.out.println("response was\n" + response.getEntity().toString()); assertEquals("Expected success from query", 200, response.getStatus()); - boolean hasLinkName = response.getEntity().toString().indexOf(linkName) > 0 ? true : false; + boolean hasLinkName = response.getEntity().toString().indexOf(linkName) > 0; assertTrue("Response contains linkName", hasLinkName ); } @@ -235,9 +232,9 @@ public class SearchGraphNamedQueryTest extends AAISetup{ aaiExtMap.setServletRequest(request); - response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, DBConnectionType.REALTIME, aaiExtMap); + response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, aaiExtMap); assertEquals("Expected success from query", 200, response.getStatus()); - boolean hasModelName = response.getEntity().toString().indexOf("junit-model-name") > 0 ? true : false; + boolean hasModelName = response.getEntity().toString().indexOf("junit-model-name") > 0; assertTrue("Response contains modelName from model-ver", hasModelName ); } @@ -316,9 +313,9 @@ public class SearchGraphNamedQueryTest extends AAISetup{ aaiExtMap.setServletRequest(request); - response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, DBConnectionType.REALTIME, aaiExtMap); + response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, aaiExtMap); assertEquals("Expected success from query", 200, response.getStatus()); - boolean hasModelName = response.getEntity().toString().indexOf("example-model-name-val-closed-loop") > 0 ? true : false; + boolean hasModelName = response.getEntity().toString().indexOf("example-model-name-val-closed-loop") > 0; assertTrue("Response contains modelName from model-ver", hasModelName ); } @@ -382,9 +379,9 @@ public class SearchGraphNamedQueryTest extends AAISetup{ aaiExtMap.setServletRequest(request); - response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, DBConnectionType.REALTIME, aaiExtMap); + response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, aaiExtMap); assertEquals("Expected success from query", 200, response.getStatus()); - boolean hasModelName = response.getEntity().toString().indexOf("example-model-name-val-component-list") > 0 ? true : false; + boolean hasModelName = response.getEntity().toString().indexOf("example-model-name-val-component-list") > 0; assertTrue("Response contains modelName from model-ver", hasModelName ); } }
\ No newline at end of file diff --git a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java index 94a89a9..2b4ec18 100644 --- a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java @@ -19,32 +19,29 @@ */ package org.onap.aai.dbgraphmap; -import org.janusgraph.core.JanusGraph; -import org.janusgraph.graphdb.types.system.EmptyVertex; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.eclipse.persistence.dynamic.DynamicEntity; +import org.janusgraph.graphdb.types.system.EmptyVertex; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.onap.aai.AAISetup; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; -import org.onap.aai.extensions.AAIExtensionMap; -import org.onap.aai.introspection.*; +import org.onap.aai.introspection.Introspector; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.ModelType; import org.onap.aai.parsers.relationship.RelationshipToURI; +import org.onap.aai.rest.util.AAIExtensionMap; import org.onap.aai.serialization.db.DBSerializer; -import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.util.GenericQueryBuilder; import org.onap.aai.util.NodesQueryBuilder; - import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.*; import java.net.URI; @@ -52,7 +49,8 @@ import java.util.*; import java.util.stream.Stream; import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class SearchGraphTest extends AAISetup{ @@ -65,7 +63,6 @@ public class SearchGraphTest extends AAISetup{ private SchemaVersion version; private final static ModelType introspectorFactoryType = ModelType.MOXY; private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; - private final static DBConnectionType type = DBConnectionType.REALTIME; static { VALID_HTTP_STATUS_CODES.add(200); @@ -85,11 +82,7 @@ public class SearchGraphTest extends AAISetup{ private List<MediaType> outputMediaTypes; private Loader loader; - private JanusGraph graph; - - private Graph tx; - private GraphTraversalSource g; private TransactionalGraphEngine dbEngine; @Before @@ -116,8 +109,8 @@ public class SearchGraphTest extends AAISetup{ when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); - when(httpHeaders.getRequestHeader("X-FromAppId")).thenReturn(Arrays.asList("JUNIT")); - when(httpHeaders.getRequestHeader("X-TransactionId")).thenReturn(Arrays.asList("JUNIT")); + when(httpHeaders.getRequestHeader("X-FromAppId")).thenReturn(Collections.singletonList("JUNIT")); + when(httpHeaders.getRequestHeader("X-TransactionId")).thenReturn(Collections.singletonList("JUNIT")); when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); @@ -130,7 +123,7 @@ public class SearchGraphTest extends AAISetup{ when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new JanusGraphDBEngine(queryStyle, type, loader); + dbEngine = new JanusGraphDBEngine(queryStyle, loader); } @Test(expected = AAIException.class) @@ -187,9 +180,6 @@ public class SearchGraphTest extends AAISetup{ @Test(expected = AAIException.class) public void testRunGenericQueryFailWhenInvalidRelationshipList2() throws AAIException { - List<String> keys = new ArrayList<>(); - keys.add("cloud-region.cloud-owner:test-aic"); - List<String> includeStrings = new ArrayList<>(); includeStrings.add("cloud-region"); @@ -207,9 +197,6 @@ public class SearchGraphTest extends AAISetup{ List<String> keys = new ArrayList<>(); keys.add("cloud-region.cloud-owner:test-aic"); - List<String> includeStrings = new ArrayList<>(); - includeStrings.add("cloud-region"); - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); UrlBuilder urlBuilder = new UrlBuilder(version, serializer, schemaVersions, basePath); Response response = searchGraph.runGenericQuery(new GenericQueryBuilder().setHeaders(httpHeaders) @@ -218,43 +205,21 @@ public class SearchGraphTest extends AAISetup{ System.out.println(response); } - - /*@Test(expected = NullPointerException.class) - public void createSearchResults() throws AAIException { - - List<Vertex> keys = new ArrayList<>(); - Vertex vertex=new EmptyVertex(); - keys.add(vertex); - - - - List<String> includeStrings = new ArrayList<>(); - includeStrings.add("cloud-region"); - - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); - Introspector response = searchGraph.createSearchResults(loader, urlBuilder, keys); - System.out.println(response); - }*/ @Test public void createSearchResults1() throws Exception { List<Vertex> keys = new ArrayList<>(); Vertex vertex=new EmptyVertex(); keys.add(vertex); - DBSerializer ds=mock(DBSerializer.class); UrlBuilder urlBuilder=mock(UrlBuilder.class); when(urlBuilder.pathed(vertex)).thenReturn("cloud-region"); Stream<Vertex> stream=mock(Stream.class); when(stream.isParallel()).thenReturn(true); - List<String> includeStrings = new ArrayList<>(); - includeStrings.add("cloud-region"); + RelationshipToURI relationshipToURI=mock(RelationshipToURI.class); URI uri =new URI(""); when(relationshipToURI.getUri()).thenReturn(uri); - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - // UrlBuilder urlBuilder = new UrlBuilder(version, serializer); Introspector response = searchGraph.createSearchResults(loader, urlBuilder, keys); System.out.println(response); } @@ -262,13 +227,6 @@ public class SearchGraphTest extends AAISetup{ public void executeModelOperationTest() throws Exception{ Vertex vertex=new EmptyVertex(); vertex.property("model-name"); - Map<String,Object> mapObj=new HashMap<String,Object>(); - mapObj.put("modle-version",vertex); - List<Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<>(); - startNodeFilterArrayOfHashes.add(mapObj); - List<org.onap.aai.dbgraphgen.ResultSet> resultSet=new ArrayList<org.onap.aai.dbgraphgen.ResultSet>(); - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - // ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); AAIExtensionMap map=mock(AAIExtensionMap.class); HttpServletRequest servletRequest=mock(HttpServletRequest.class); @@ -277,12 +235,7 @@ public class SearchGraphTest extends AAISetup{ DynamicEntity modelAndNamedQuerySearch=mock(DynamicEntity.class); when(modelAndNamedQuerySearch.isSet("topNodeType")).thenReturn(true); - -/* when(processor.queryByModel("9999","model-ver","model-version-id", - "model-inv-id","modelname","aai", - startNodeFilterArrayOfHashes,"aai-ver")).thenReturn(resultSet);*/ - - searchGraph.executeModelOperation("","","",type,true, + searchGraph.executeModelOperation("","","",true, map); } @@ -290,13 +243,6 @@ public class SearchGraphTest extends AAISetup{ public void executeModelOperationXMLTest() throws Exception{ Vertex vertex=new EmptyVertex(); vertex.property("model-name"); - Map<String,Object> mapObj=new HashMap<String,Object>(); - mapObj.put("modle-version",vertex); - List<Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<>(); - startNodeFilterArrayOfHashes.add(mapObj); - List<org.onap.aai.dbgraphgen.ResultSet> resultSet=new ArrayList<org.onap.aai.dbgraphgen.ResultSet>(); - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - // ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); AAIExtensionMap map=mock(AAIExtensionMap.class); HttpServletRequest servletRequest=mock(HttpServletRequest.class); @@ -305,19 +251,16 @@ public class SearchGraphTest extends AAISetup{ DynamicEntity modelAndNamedQuerySearch=mock(DynamicEntity.class); when(modelAndNamedQuerySearch.isSet("queryParameters")).thenReturn(true); -/* when(processor.queryByModel("9999","model-ver","model-version-id", - "model-inv-id","modelname","aai", - startNodeFilterArrayOfHashes,"aai-ver")).thenReturn(resultSet);*/ - searchGraph.executeModelOperation("","","",type,true, + searchGraph.executeModelOperation("","","",true, map); } @Test public void runNodesQueryTest() throws AAIException{ UrlBuilder urlBuilder=mock(UrlBuilder.class); - List<String> filter=new ArrayList<String>(); + List<String> filter=new ArrayList<>(); filter.add("model:EQUALS:DOES-NOT-EXIST:AAI"); - List<String> edgeFilter=new ArrayList<String>(); + List<String> edgeFilter=new ArrayList<>(); edgeFilter.add("model:DOES-NOT-EXIST:DOES-NOT-EXIST:AAI"); Response response= searchGraph.runNodesQuery(new NodesQueryBuilder().setHeaders(httpHeaders).setTargetNodeType("model-ver").setEdgeFilterParams(edgeFilter) .setFilterParams(filter).setDbEngine(dbEngine).setLoader(loader).setUrlBuilder(urlBuilder)); @@ -341,7 +284,7 @@ public class SearchGraphTest extends AAISetup{ UrlBuilder urlBuilder=mock(UrlBuilder.class); List<String> filter=new ArrayList<String>(); filter.add("model:DOES-NOT-EQUAL:DOES-NOT-EXIST"); - List<String> edgeFilter=new ArrayList<String>(); + List<String> edgeFilter=new ArrayList<>(); searchGraph.runNodesQuery(new NodesQueryBuilder().setHeaders(httpHeaders).setTargetNodeType("model-ver").setEdgeFilterParams(edgeFilter) .setFilterParams(filter).setDbEngine(dbEngine).setLoader(loader).setUrlBuilder(urlBuilder)); } @@ -349,9 +292,9 @@ public class SearchGraphTest extends AAISetup{ @Test public void runNodesQueryTestGreaterThan3() throws AAIException{ UrlBuilder urlBuilder=mock(UrlBuilder.class); - List<String> filter=new ArrayList<String>(); + List<String> filter=new ArrayList<>(); filter.add("model:DOES-NOT-EQUAL:DOES-NOT-EXIST:AAI"); - List<String> edgeFilter=new ArrayList<String>(); + List<String> edgeFilter=new ArrayList<>(); searchGraph.runNodesQuery(new NodesQueryBuilder().setHeaders(httpHeaders).setTargetNodeType("model-ver").setEdgeFilterParams(edgeFilter) .setFilterParams(filter).setDbEngine(dbEngine).setLoader(loader).setUrlBuilder(urlBuilder)); } @@ -359,9 +302,9 @@ public class SearchGraphTest extends AAISetup{ @Test public void runNodesQueryTestGreaterThanExists() throws AAIException{ UrlBuilder urlBuilder=mock(UrlBuilder.class); - List<String> filter=new ArrayList<String>(); + List<String> filter=new ArrayList<>(); filter.add("model:EXISTS:DOES-NOT-EXIST:AAI"); - List<String> edgeFilter=new ArrayList<String>(); + List<String> edgeFilter=new ArrayList<>(); searchGraph.runNodesQuery(new NodesQueryBuilder().setHeaders(httpHeaders).setTargetNodeType("model-ver").setEdgeFilterParams(edgeFilter) .setFilterParams(filter).setDbEngine(dbEngine).setLoader(loader).setUrlBuilder(urlBuilder)); } @@ -369,9 +312,9 @@ public class SearchGraphTest extends AAISetup{ @Test(expected = AAIException.class) public void runNodesQueryTestGreaterThanDoesNotExists() throws AAIException{ UrlBuilder urlBuilder=mock(UrlBuilder.class); - List<String> filter=new ArrayList<String>(); + List<String> filter=new ArrayList<>(); filter.add("model:DOES_NOT_EXIST:DOES-NOT-EXIST:AAI"); - List<String> edgeFilter=new ArrayList<String>(); + List<String> edgeFilter=new ArrayList<>(); searchGraph.runNodesQuery(new NodesQueryBuilder().setHeaders(httpHeaders).setTargetNodeType("model-ver").setEdgeFilterParams(edgeFilter) .setFilterParams(filter).setDbEngine(dbEngine).setLoader(loader).setUrlBuilder(urlBuilder)); } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java index b767dbb..b82d751 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java @@ -19,10 +19,9 @@ */ package org.onap.aai.rest; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; import org.apache.tinkerpop.gremlin.process.traversal.P; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; import org.janusgraph.core.JanusGraph; import org.janusgraph.core.JanusGraphTransaction; import org.junit.*; @@ -47,12 +46,12 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.web.client.RestTemplate; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.Collections; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TraversalApp.class) @TestPropertySource(locations = "classpath:application-test.properties") -@ContextConfiguration(initializers = PropertyPasswordConfiguration.class) @Import(TraversalTestConfiguration.class) public abstract class AbstractSpringRestTest { @@ -96,7 +95,7 @@ public abstract class AbstractSpringRestTest { headers.add("Real-Time", "true"); headers.add("X-FromAppId", "JUNIT"); headers.add("X-TransactionId", "JUNIT"); - String authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes("UTF-8")); + String authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes(StandardCharsets.UTF_8)); headers.add("Authorization", "Basic " + authorization); httpEntity = new HttpEntity(headers); baseUrl = "http://localhost:" + randomPort; @@ -120,8 +119,7 @@ public abstract class AbstractSpringRestTest { GraphTraversalSource g = transaction.traversal(); g.V().has("source-of-truth", P.within("JUNIT", "AAI-EXTENSIONS")) .toList() - .stream() - .forEach(v -> v.remove()); + .forEach(Vertex::remove); } catch(Exception ex){ success = false; } finally { diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java index e4576ae..7918eb3 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java @@ -19,43 +19,32 @@ */ package org.onap.aai.rest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.junit.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.janusgraph.core.JanusGraphTransaction; -import org.junit.Before; import org.junit.Test; +import org.junit.Ignore; +import org.onap.aai.HttpTestUtil; import org.onap.aai.PayloadUtil; import org.onap.aai.dbmap.AAIGraph; import org.onap.aai.util.AAIConfig; import org.onap.aai.util.TraversalConstants; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.util.UriComponentsBuilder; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.jayway.jsonpath.JsonPath; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.*; + +import java.util.*; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.*; public class DslConsumerTest extends AbstractSpringRestTest { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(DslConsumerTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DslConsumerTest.class); @Override public void createTestGraph() { @@ -65,7 +54,7 @@ public class DslConsumerTest extends AbstractSpringRestTest { GraphTraversalSource g = transaction.traversal(); g.addV().property("aai-node-type", "pserver").property("hostname", "test-pserver-dsl") .property("in-maint", false).property("source-of-truth", "JUNIT") - .property("aai-uri", "/cloud-infrastructure/pservers/pserver/test-pserver").next(); + .property("aai-uri", "/cloud-infrastructure/pservers/pserver/test-pserver-dsl").next(); } catch (Exception ex) { success = false; } finally { @@ -85,13 +74,71 @@ public class DslConsumerTest extends AbstractSpringRestTest { Map<String, String> dslQueryMap = new HashMap<>(); dslQueryMap.put("dsl-query", "pserver*('hostname','test-pserver-dsl')"); String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + headers.add("X-Dsl-Version", "V1"); httpEntity = new HttpEntity(payload, headers); ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); System.out.println(responseEntity.getBody()); assertNotNull("Response from /aai/v14/dsl is not null", responseEntity); - assertEquals("Expected the response to be 500", HttpStatus.OK, responseEntity.getStatusCode()); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); + httpEntity = new HttpEntity(payload, headers); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, + String.class); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + assertNotNull("Response from /aai/v14/dsl is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + + // Make sure that there are no two result <result><result> + assertThat(responseEntity.getBody().toString(), is(not(containsString("<result><result>")))); + assertThat(responseEntity.getBody().toString(), is(containsString("<results><result>"))); + } + + @Test + public void testDslQueryV2() throws Exception { + + String endpoint = "/aai/v14/dsl?format=console"; + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver*('hostname','test-pserver-dsl') > complex*"); + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + headers.add("X-Dsl-Version", "V2"); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, + String.class); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + assertNotNull("Response from /aai/v14/dsl is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); + httpEntity = new HttpEntity(payload, headers); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, + String.class); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + assertNotNull("Response from /aai/v14/dsl is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + + // Make sure that there are no two result <result><result> + assertThat(responseEntity.getBody().toString(), is(not(containsString("<result><result>")))); + assertThat(responseEntity.getBody().toString(), is(containsString("<results><result>"))); + } + + @Test + public void testDslQueryV2Aggregate() throws Exception { + String endpoint = "/aai/v17/dsl?format=aggregate"; + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver*('hostname','test-pserver-dsl')"); + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + System.out.println("Payload" + payload); + headers.add("X-Dsl-Version", "V2"); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, + String.class); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + System.out.println(responseEntity.getBody()); + assertNotNull("Response from /aai/v17/dsl is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); } @Test @@ -107,10 +154,10 @@ public class DslConsumerTest extends AbstractSpringRestTest { httpEntity = new HttpEntity(payload, headers); responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); - assertEquals("Expected the response to be 404", HttpStatus.NOT_FOUND, + assertEquals("Expected the response to be 404", HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); } - + @Test public void testDslQueryOverride() throws Exception { Map<String, String> dslQuerymap = new HashMap<>(); @@ -125,8 +172,198 @@ public class DslConsumerTest extends AbstractSpringRestTest { headers.add("X-DslOverride", AAIConfig.get(TraversalConstants.DSL_OVERRIDE)); httpEntity = new HttpEntity(payload, headers); responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); - assertEquals("Expected the response to be 404", HttpStatus.NOT_FOUND, + assertEquals("Expected the response to be 404", HttpStatus.BAD_REQUEST, + responseEntity.getStatusCode()); + } + + + @Test + public void testSelectedPropertiesNotRequiredOnDSLStartNode() throws Exception { + Map<String, String> dslQuerymap = new HashMap<>(); + dslQuerymap.put("dsl-query", "pserver*('equip-model','abc')"); + + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQuerymap); + + String endpoint = "/aai/v11/dsl?format=console"; + + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + + assertEquals("Expected the response to be " + HttpStatus.OK, HttpStatus.OK, + responseEntity.getStatusCode()); + } + + @Test + public void testAPropertyIsRequiredOnDSLStartNode() throws Exception { + Map<String, String> dslQuerymap = new HashMap<>(); + dslQuerymap.put("dsl-query", "pserver*"); + + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQuerymap); + + String endpoint = "/aai/v11/dsl?format=console"; + + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + + assertEquals("Expected the response to be " + HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); } + + @Test + public void testDslQueryProcessingV2_WithSimpleFormat_WithAsTreeQueryParameter() throws Exception { + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver{'hostname', 'ptnii-equip-name', 'in-maint'}('hostname','test-pserver-dsl')"); + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + String endpoint = "/aai/v16/dsl?format=simple&depth=0&nodesOnly=true&as-tree=true"; + + // Add header with V2 to use the {} feature as a part of dsl query + headers.add("X-DslApiVersion","V2"); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + String responseString = responseEntity.getBody().toString(); + + // Extract the properties array from the response and compare in assert statements + JsonParser jsonParser = new JsonParser(); + JsonObject results = jsonParser.parse(responseString).getAsJsonObject(); + JsonArray resultsArray = results.get("results").getAsJsonArray(); + JsonObject resultsValue = resultsArray.get(0).getAsJsonObject(); + JsonObject properties = resultsValue.get("properties").getAsJsonObject(); + assertEquals(2, properties.size()); + assertTrue(properties.get("hostname").toString().equals("\"test-pserver-dsl\"")); + assertTrue(properties.get("in-maint").toString().equals("false")); + headers.remove("X-DslApiVersion"); + } + + @Test + public void testDslQueryProcessingV2_WithSimpleFormat_WithoutAsTreeQueryParameter() throws Exception { + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver{'hostname', 'ptnii-equip-name', 'in-maint'}('hostname','test-pserver-dsl')"); + + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + String endpoint = "/aai/v16/dsl?format=simple&depth=0&nodesOnly=true"; + + // Add header with V2 to use the {} feature as a part of dsl query + headers.add("X-DslApiVersion","V2"); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + String responseString = responseEntity.getBody().toString(); + // Extract the properties array from the response and compare in assert statements + JsonParser jsonParser = new JsonParser(); + JsonObject results = jsonParser.parse(responseString).getAsJsonObject(); + JsonArray resultsArray = results.get("results").getAsJsonArray(); + JsonObject resultsValue = resultsArray.get(0).getAsJsonObject(); + JsonObject properties = resultsValue.get("properties").getAsJsonObject(); + assertEquals(2, properties.size()); + assertTrue(properties.get("hostname").toString().equals("\"test-pserver-dsl\"")); + assertTrue(properties.get("in-maint").toString().equals("false")); + headers.remove("X-DslApiVersion"); + } + + @Test + public void testDslQueryProcessingV2_WithResourceFormat_WithAsTreeQueryParameter() throws Exception { + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver{'hostname', 'ptnii-equip-name', 'in-maint'}('hostname','test-pserver-dsl')"); + + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + String endpoint = "/aai/v16/dsl?format=resource&depth=0&nodesOnly=true&as-tree=true"; + + // Add header with V2 to use the {} feature as a part of dsl query + headers.add("X-DslApiVersion","V2"); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + String responseString = responseEntity.getBody().toString(); + + // Extract the properties array from the response and compare in assert statements + JsonParser jsonParser = new JsonParser(); + JsonObject results = jsonParser.parse(responseString).getAsJsonObject(); + JsonArray resultsArray = results.get("results").getAsJsonArray(); + JsonObject resultsValue = resultsArray.get(0).getAsJsonObject(); + JsonObject properties = resultsValue.get("pserver").getAsJsonObject(); + assertEquals(2, properties.size()); + assertTrue(properties.get("hostname").toString().equals("\"test-pserver-dsl\"")); + assertTrue(properties.get("in-maint").toString().equals("false")); + headers.remove("X-DslApiVersion"); + } + + @Ignore + @Test + public void testDslQueryProcessingV2_WithResourceFormat_WithoutAsTreeQueryParameter() throws Exception { + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver{'hostname', 'ptnii-equip-name', 'in-maint'}('hostname','test-pserver-dsl')"); + + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + String endpoint = "/aai/v16/dsl?format=resource&depth=0&nodesOnly=true"; + + // Add header with V2 to use the {} feature as a part of dsl query + headers.add("X-DslApiVersion","V2"); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + String responseString = responseEntity.getBody().toString(); + + // Extract the properties array from the response and compare in assert statements + JsonParser jsonParser = new JsonParser(); + JsonObject results = jsonParser.parse(responseString).getAsJsonObject(); + JsonArray resultsArray = results.get("results").getAsJsonArray(); + JsonObject resultsValue = resultsArray.get(0).getAsJsonObject(); + JsonObject properties = resultsValue.get("pserver").getAsJsonObject(); + assertEquals(2, properties.size()); + assertTrue(properties.get("hostname").toString().equals("\"test-pserver-dsl\"")); + assertTrue(properties.get("in-maint").toString().equals("false")); + headers.remove("X-DslApiVersion"); + } + + @Test + public void testDslQueryProcessingV2_WithResourceAndUrlFormat_WithAsTreeQueryParameter() throws Exception { + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver{'hostname', 'ptnii-equip-name', 'in-maint'}('hostname','test-pserver-dsl')"); + + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + String endpoint = "/aai/v16/dsl?format=resource_and_url&depth=0&nodesOnly=true&as-tree=true"; + + // Add header with V2 to use the {} feature as a part of dsl query + headers.add("X-DslApiVersion","V2"); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + String responseString = responseEntity.getBody().toString(); + + // Extract the properties array from the response and compare in assert statements + JsonParser jsonParser = new JsonParser(); + JsonObject results = jsonParser.parse(responseString).getAsJsonObject(); + JsonArray resultsArray = results.get("results").getAsJsonArray(); + JsonObject resultsValue = resultsArray.get(0).getAsJsonObject(); + JsonObject properties = resultsValue.get("pserver").getAsJsonObject(); + assertEquals(2, properties.size()); + assertTrue(properties.get("hostname").toString().equals("\"test-pserver-dsl\"")); + assertTrue(properties.get("in-maint").toString().equals("false")); + headers.remove("X-DslApiVersion"); + } + + @Ignore + @Test + public void testDslQueryProcessingV2_WithResourceAndUrlFormat_WithoutAsTreeQueryParameter() throws Exception { + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver{'hostname', 'ptnii-equip-name', 'in-maint'}('hostname','test-pserver-dsl')"); + + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + String endpoint = "/aai/v16/dsl?format=resource_and_url&depth=0&nodesOnly=true"; + + // Add header with V2 to use the {} feature as a part of dsl query + headers.add("X-DslApiVersion","V2"); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + String responseString = responseEntity.getBody().toString(); + + // Extract the properties array from the response and compare in assert statements + JsonParser jsonParser = new JsonParser(); + JsonObject results = jsonParser.parse(responseString).getAsJsonObject(); + JsonArray resultsArray = results.get("results").getAsJsonArray(); + JsonObject resultsValue = resultsArray.get(0).getAsJsonObject(); + JsonObject properties = resultsValue.get("pserver").getAsJsonObject(); + assertEquals(2, properties.size()); + assertTrue(properties.get("hostname").toString().equals("\"test-pserver-dsl\"")); + assertTrue(properties.get("in-maint").toString().equals("false")); + headers.remove("X-DslApiVersion"); + } + } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java index 7a6f101..c965407 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java @@ -19,7 +19,10 @@ */ package org.onap.aai.rest; -import com.att.eelf.configuration.EELFLogger; +import org.onap.aai.config.PropertyPasswordConfiguration; +import org.onap.aai.transforms.XmlFormatTransformer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import com.jayway.jsonpath.JsonPath; import org.janusgraph.core.JanusGraph; @@ -34,6 +37,7 @@ import org.onap.aai.HttpTestUtil; import org.onap.aai.PayloadUtil; import org.onap.aai.dbmap.AAIGraph; import org.onap.aai.setup.SchemaVersion; +import org.springframework.test.context.ContextConfiguration; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.*; @@ -47,9 +51,10 @@ import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +@ContextConfiguration(initializers = PropertyPasswordConfiguration.class) public class GfpVserverDataStoredQueryTest extends AAISetup{ - private static final EELFLogger logger = EELFManager.getInstance().getLogger(GfpVserverDataStoredQueryTest.class); + private static final Logger logger = LoggerFactory.getLogger(GfpVserverDataStoredQueryTest.class); protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); @@ -102,7 +107,7 @@ public class GfpVserverDataStoredQueryTest extends AAISetup{ assertEquals("Expecting the cloud region to be created", 201, response.getStatus()); logger.info("Successfully created the cloud region with linterface"); - queryConsumer = new QueryConsumer(traversalUriHttpEntry, schemaVersions, gremlinServerSingleton, basePath); + queryConsumer = new QueryConsumer(traversalUriHttpEntry, schemaVersions, gremlinServerSingleton, new XmlFormatTransformer(), basePath); httpHeaders = mock(HttpHeaders.class); @@ -164,12 +169,10 @@ public class GfpVserverDataStoredQueryTest extends AAISetup{ Response response = queryConsumer.executeQuery( payload, version.toString(), - query, "resource_and_url", "" + "no_op", httpHeaders, uriInfo, - httpServletRequest, "-1", "-1" ); @@ -203,12 +206,10 @@ public class GfpVserverDataStoredQueryTest extends AAISetup{ Response response = queryConsumer.executeQuery( payload, version.toString(), - query, "resource_and_url", "" + "no_op", httpHeaders, uriInfo, - httpServletRequest, "-1", "-1" ); @@ -243,12 +244,10 @@ public class GfpVserverDataStoredQueryTest extends AAISetup{ Response response = queryConsumer.executeQuery( payload, version.toString(), - query, "resource_and_url", "" + "no_op", httpHeaders, uriInfo, - httpServletRequest, "-1", "-1" ); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/QueryConsumerTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/QueryConsumerTest.java index b894985..cf81b47 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/QueryConsumerTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/QueryConsumerTest.java @@ -42,8 +42,8 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestTemplate; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.UnsupportedEncodingException; import java.util.Base64; @@ -56,8 +56,7 @@ import javax.ws.rs.core.Response; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TraversalApp.class) @@ -66,7 +65,7 @@ import static org.junit.Assert.fail; @Import(TraversalTestConfiguration.class) public class QueryConsumerTest { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(QueryConsumerTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(QueryConsumerTest.class); private HttpTestUtil httpTestUtil; private String pserverUri; @@ -123,7 +122,7 @@ public class QueryConsumerTest { Response response = httpTestUtil.doPut(complexUri, complexPayload); } - //@Test +// @Test public void testRequiredAGood() throws Exception { String endpoint = "/aai/v14/query?format=pathed"; Map<String, String> cloudRegionMap = new HashMap<>(); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/RecentApiTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/RecentApiTest.java index 43ac7c2..10ff7b9 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/RecentApiTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/RecentApiTest.java @@ -19,22 +19,45 @@ */ package org.onap.aai.rest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.janusgraph.core.JanusGraphTransaction; import org.junit.Test; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; +import org.onap.aai.dbmap.AAIGraph; +import org.springframework.http.*; import org.springframework.web.util.UriComponentsBuilder; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; +import java.util.Collections; + +import static org.junit.Assert.*; + public class RecentApiTest extends AbstractSpringRestTest { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(RecentApiTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(RecentApiTest.class); + + @Override + public void createTestGraph() { + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + boolean success = true; + try { + GraphTraversalSource g = transaction.traversal(); + g.addV().property("aai-node-type", "pserver").property("hostname", "test-pserver-recents") + .property("in-maint", false).property("source-of-truth", "JUNIT") + .property("aai-uri", "/cloud-infrastructure/pservers/pserver/test-pserver-recents").next(); + } catch (Exception ex) { + success = false; + } finally { + if (success) { + transaction.commit(); + } else { + transaction.rollback(); + fail("Unable to setup the graph"); + } + } + } @Test public void testRecentsQuery() { @@ -44,10 +67,28 @@ public class RecentApiTest extends AbstractSpringRestTest { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl + endpoint).queryParam("hours", "190"); ResponseEntity responseEntity = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, httpEntity, String.class); - LOGGER.debug("Response for PUT request with uri {} : {}", builder.toUriString(), responseEntity.getBody()); - assertNotNull("Response from /aai/recents/v14/pserver is null", responseEntity); - assertEquals("Expected the response to be 400", HttpStatus.OK, responseEntity.getStatusCode()); + LOGGER.debug("Response for GET request with uri {} : {}", builder.toUriString(), responseEntity.getBody()); + assertNotNull("Response from /aai/recents/v14/pserver is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + + // Check different application xml headers for accept + headers.set("Accept", "application/xml"); + httpEntity = new HttpEntity(headers); + + responseEntity = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, httpEntity, + String.class); + LOGGER.debug("Response for GET request with uri {} : {}", builder.toUriString(), responseEntity.getBody()); + assertNotNull("Response from /aai/recents/v14/pserver is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + + headers.set("Accept", "application/xml; charset=UTF-8"); + httpEntity = new HttpEntity(headers); + responseEntity = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, httpEntity, + String.class); + LOGGER.debug("Response for GET request with uri {} : {}", builder.toUriString(), responseEntity.getBody()); + assertNotNull("Response from /aai/recents/v14/pserver is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); } @Test diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/SearchProviderRestTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/SearchProviderRestTest.java index d53fa56..6980753 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/SearchProviderRestTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/SearchProviderRestTest.java @@ -19,7 +19,8 @@ */ package org.onap.aai.rest; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.junit.Test; import org.springframework.http.*; @@ -34,7 +35,7 @@ import static org.junit.Assert.assertNotNull; public class SearchProviderRestTest extends AbstractSpringRestTest { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(SearchProviderRestTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SearchProviderRestTest.class); @Test public void testNodesQueryInvalidData() { diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslContextTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslContextTest.java index de81104..e85e250 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslContextTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslContextTest.java @@ -20,20 +20,127 @@ package org.onap.aai.rest.dsl; -import static org.junit.Assert.assertNull; - +import org.antlr.v4.runtime.ParserRuleContext; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import java.util.Deque; +import java.util.List; + +import static org.junit.Assert.*; + public class DslContextTest { DslContext dslContext; @Before - public void setUp() - { + public void setUp() { + dslContext= new DslContext(); + dslContext.setCtx(null); + } + + @Test + public void testGetCtx() { + assertNull(dslContext.getCtx()); + } + + @Test + public void testSetUnionStart() { + dslContext.setUnionStart(true); + } + + @Test + public void testGetLimitQuery() { + assertNotNull(dslContext.getLimitQuery()); + } + + @Test + public void testSetLimitQuery() { + StringBuilder builder = new StringBuilder(); + builder.append("abc"); + dslContext.setLimitQuery(builder); + dslContext.setStartNodeFlag(true); + dslContext.setUnionStart(true); + dslContext.setUnionStartNodes(null); + assertNotNull(dslContext); + } + + @Test + public void testIsStartNode() { + Assert.assertFalse(dslContext.isStartNode()); + } + + @Test + public void testGetStartNode() { + dslContext.setStartNode("xyz"); + Assert.assertEquals(dslContext.getStartNode(), "xyz"); + } + + @Test + public void testGetStartNodeKeys() { + Assert.assertNotNull(dslContext.getStartNodeKeys()); + } + + @Test + public void testGetCurrentNode() { + dslContext.setCurrentNode("blah"); + Assert.assertEquals(dslContext.getCurrentNode(), "blah"); } - + + @Test + public void testGetPreviousNode() { + dslContext.setPreviousNode("blah"); + Assert.assertEquals(dslContext.getPreviousNode(), "blah"); + } + + @Test + public void testisTraversal() { + dslContext.setTraversal(false); + Assert.assertFalse(dslContext.isTraversal()); + } + + @Test + public void testGetWhereQuery() { + dslContext.setWhereQuery(true); + Assert.assertTrue(dslContext.isWhereQuery()); + } + + @Test + public void testIsUnionQuery() { + dslContext.setUnionQuery(true); + Assert.assertTrue(dslContext.isUnionQuery()); + } + + @Test + public void testIsUnionStart() { + dslContext.setUnionStart(true); + Assert.assertTrue(dslContext.isUnionStart()); + } + + @Test + public void testUnionStart() throws Exception { + assertNotNull(dslContext.getUnionStartNodes()); + } + + @Test + public void testGetWhereStartNode() { + dslContext.setWhereStartNode("blah"); + Assert.assertEquals(dslContext.getWhereStartNode(), "blah"); + } + + @Test + public void testIsValidationFlag() { + Assert.assertTrue(dslContext.isValidationFlag()); + } + + @Test + public void testSetValidationFlag() + { + dslContext.setValidationFlag(true); + Assert.assertTrue(dslContext.isValidationFlag()); + } + @Test public void testUnionStartNodes() { diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslQueryProcessorTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslQueryProcessorV1Test.java index 340f8f8..9d36ac7 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslQueryProcessorTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslQueryProcessorV1Test.java @@ -19,29 +19,125 @@ */ package org.onap.aai.rest.dsl; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.onap.aai.AAISetup; import org.onap.aai.exceptions.AAIException; +import org.onap.aai.rest.enums.QueryVersion; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * The Class DslMain. */ -public class DslQueryProcessorTest extends AAISetup { +public class DslQueryProcessorV1Test extends AAISetup { @Rule public ExpectedException expectedEx = ExpectedException.none(); @Test + public void dbAliasTest() throws AAIException { + String aaiQuery = "logical-link* ('model-invariant-id','invid')"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'logical-link').getVerticesByProperty('model-invariant-id-local','invid')" + + ".store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void apostropheTest() throws AAIException { + String aaiQuery = "logical-link*('link-id','dsl\\'link')"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'logical-link').getVerticesByProperty('link-id','dsl\\'link')" + + ".store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void parseCancellationExceptionTest() throws AAIException { + boolean thrown = false; + String aaiQuery = "logical-link*('link-id','dsl\\'link)"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'logical-link').getVerticesByProperty('link-id','dsl\\'link')" + + ".store('x').cap('x').unfold().dedup()"; + + try { + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1, aaiQuery).get("query").toString(); + } catch (AAIException e) { + thrown = true; + } + assertTrue(thrown); + } + + @Test + public void cloudRegionFromVnf() throws AAIException { + String aaiQuery = "generic-vnf*('vnf-name','xyz') > [ vnfc* > vserver* > [pserver*, tenant* > cloud-region*], "+ + "vserver* > [pserver*, tenant* > cloud-region*] ]"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-name','xyz').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vnfc').store('x')." + +"createEdgeTraversal(EdgeType.COUSIN, 'vnfc','vserver').store('x').union(builder.newInstance().createEdgeTraversal" + +"(EdgeType.COUSIN, 'vserver','pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver','tenant')" + +".store('x').createEdgeTraversal(EdgeType.TREE, 'tenant','cloud-region').store('x')),builder.newInstance().createEdgeTraversal" + +"(EdgeType.COUSIN, 'generic-vnf','vserver').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver'" + +",'pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver','tenant').store('x').createEdgeTraversal" + +"(EdgeType.TREE, 'tenant','cloud-region').store('x'))).cap('x').unfold().dedup()"; + + + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void cloudRegionSites() throws AAIException { + String aaiQuery = "cloud-region*('cloud-owner','xyz') > complex*"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner'" + +",'xyz').store('x').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','complex').store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void pserverWithNoComplexTest() throws AAIException { + String aaiQuery = "pserver*('hostname','xyz')!(> complex)"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'pserver').getVerticesByProperty('hostname','xyz').where(builder.newInstance().not(" + +"builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver','complex'))).store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void pserverWhereNotTest() throws AAIException { + String aaiQuery = "pserver('hostname','xyz')>vserver*!(> vnfc > configuration))"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'pserver').getVerticesByProperty('hostname','xyz').createEdgeTraversal" + + "(EdgeType.COUSIN, 'pserver','vserver').where(builder.newInstance().not(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN,"+ + " 'vserver','vnfc').createEdgeTraversal(EdgeType.COUSIN, 'vnfc','configuration'))).store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test public void singleNode1() throws AAIException { String aaiQuery = "cloud-region* !('cloud-owner','coid')"; String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner','coid')" + ".store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -52,7 +148,7 @@ public class DslQueryProcessorTest extends AAISetup { String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner','coid')" + ".store('x').cap('x').unfold().dedup().limit(10)"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -62,7 +158,7 @@ public class DslQueryProcessorTest extends AAISetup { String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner','coidhello:?_-)(!@#$%^&*+={}[]|/.<,')" + ".store('x').cap('x').unfold().dedup().limit(10)"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -75,7 +171,7 @@ public class DslQueryProcessorTest extends AAISetup { expectedEx.expect(org.onap.aai.exceptions.AAIException.class); expectedEx.expectMessage("DSL Syntax Error while processing the query"); - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); } @Test @@ -88,7 +184,7 @@ public class DslQueryProcessorTest extends AAISetup { expectedEx.expect(org.onap.aai.exceptions.AAIException.class); expectedEx.expectMessage("DSL Syntax Error while processing the query"); - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); } @Test @@ -98,7 +194,7 @@ public class DslQueryProcessorTest extends AAISetup { String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner','coid')" + ".getVerticesByProperty('cloud-region-id','cr id').store('x').cap('x').unfold().dedup().limit(10)"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -115,7 +211,7 @@ public class DslQueryProcessorTest extends AAISetup { + ".getVerticesByProperty('cloud-region-id','One'))" + ".createEdgeTraversal(EdgeType.TREE, 'generic-vnf','entitlement').store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -129,7 +225,7 @@ public class DslQueryProcessorTest extends AAISetup { + ".getVerticesByProperty('cloud-region-id','One'))" + ".createEdgeTraversalWithLabels( 'generic-vnf','service-instance', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.ComposedOf'))).store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -137,7 +233,7 @@ public class DslQueryProcessorTest extends AAISetup { public void complex_az_fromComplexTest() throws AAIException { String aaiQuery = "cloud-region('cloud-owner','coid')('cloud-region-id','crid') > [ availability-zone* , complex*]"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region')" + ".getVerticesByProperty('cloud-owner','coid').getVerticesByProperty('cloud-region-id','crid')" + ".union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'cloud-region','availability-zone').store('x')" @@ -150,7 +246,7 @@ public class DslQueryProcessorTest extends AAISetup { public void complex_az_fromComplexTestWithLabels() throws AAIException { String aaiQuery = "cloud-region('cloud-owner','coid')('cloud-region-id','crid') > [ ('org.onap.relationships.inventory.BelongsTo')availability-zone* , ('org.onap.relationships.inventory.LocatedIn')complex*]"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region')" + ".getVerticesByProperty('cloud-owner','coid').getVerticesByProperty('cloud-region-id','crid')" + ".union(builder.newInstance().createEdgeTraversalWithLabels( 'cloud-region','availability-zone', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.BelongsTo'))).store('x')" @@ -165,7 +261,7 @@ public class DslQueryProcessorTest extends AAISetup { String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'complex').getVerticesByProperty('data-center-code','data-center-code-name')" + ".createEdgeTraversal(EdgeType.COUSIN, 'complex','cloud-region').store('x').cap('x').unfold().dedup()"; String aaiQuery = "complex('data-center-code','data-center-code-name') > cloud-region*"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(builderQuery, query); } @@ -177,7 +273,7 @@ public class DslQueryProcessorTest extends AAISetup { + ".createEdgeTraversal(EdgeType.COUSIN, 'complex','cloud-region').getVerticesByProperty('cloud-region-version','crv')" + ".store('x').cap('x').unfold().dedup()"; String aaiQuery = "complex('data-center-code','data-center-code-name') > cloud-region*('cloud-region-version','crv')"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(builderQuery, query); } @@ -192,7 +288,7 @@ public class DslQueryProcessorTest extends AAISetup { + ".store('x').cap('x').unfold().dedup()"; String aaiQuery = "image('application-vendor','F5') > vserver (> generic-vnf('vnf-name','ZALL1MMSC03')) > tenant > cloud-region*"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(builderQuery, query); } @@ -206,7 +302,7 @@ public class DslQueryProcessorTest extends AAISetup { + ".store('x').cap('x').unfold().dedup()"; String aaiQuery = "image('application-vendor','vendor') > vserver(> generic-vnf('nf-type', 'nfType') ) > tenant > cloud-region*"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(builderQuery, query); } @@ -223,7 +319,7 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "generic-vnf('vnf-id','vnfId') > vnfc* > vserver* > tenant* > cloud-region*"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(builderQuery, query); } @@ -237,7 +333,7 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "cloud-region*('cloud-owner','co') > complex*"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(builderQuery, query); } @@ -256,7 +352,7 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "generic-vnf*('vnf-id','vnfId') > [ pserver* > complex*, " + " vserver > pserver* > complex* " + "]"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(builderQuery, query); } @@ -273,7 +369,7 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "generic-vnf*('vnf-id','vnfId') > [ pserver* , " + " vserver > pserver* ] > complex*"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(builderQuery, query); } @@ -294,7 +390,7 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "customer('global-customer-id', 'a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb') > service-subscription('service-subscription-id', 'Nimbus') " + " > service-instance('service-instance-id','sid') > generic-vnf* " + " > [ vnfc* , vserver*, pserver* , pnf* ]"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(builderQuery, query); } @@ -308,7 +404,7 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "generic-vnf*('vnf-id','vnfId') (> [ pserver('hostname','hostname1'), " + " vserver > pserver('hostname','hostname1')])"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(builderQuery, query); } @@ -318,7 +414,7 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "cloud-region* ('cloud-owner')"; String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner').store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -327,7 +423,7 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "cloud-region* ('cloud-owner','cloud-owner1','cloud-owner2')"; String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner', new ArrayList<>(Arrays.asList('cloud-owner1','cloud-owner2'))).store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -336,7 +432,7 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "cloud-region* !('cloud-owner','cloud-owner1','cloud-owner2')"; String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner', new ArrayList<>(Arrays.asList('cloud-owner1','cloud-owner2'))).store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -345,7 +441,7 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "cloud-region* !('cloud-owner',' ',' null ')"; String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner', new ArrayList<>(Arrays.asList(' ',' null '))).store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -353,7 +449,7 @@ public class DslQueryProcessorTest extends AAISetup { public void hasPropertyIntegerTest() throws AAIException { String aaiQuery = "cloud-region('cloud-owner', 'att-nc')('cloud-region-id', 'MTN61a') > vlan-tag*('vlan-id-inner', 20)"; String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner','att-nc').getVerticesByProperty('cloud-region-id','MTN61a').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','vlan-tag').getVerticesByProperty('vlan-id-inner',20).store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -363,7 +459,7 @@ public class DslQueryProcessorTest extends AAISetup { String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'vserver').getVerticesByProperty('vserver-id','abc').createEdgeTraversal(EdgeType.TREE, 'vserver','logical-link').store('x').createEdgeTraversal('logical-link','l-interface').store('x')cap('x').unfold().dedup()"; expectedEx.expect(org.onap.aai.exceptions.AAIException.class); expectedEx.expectMessage("No EdgeRule found for passed nodeTypes: vserver, logical-link"); - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -371,7 +467,7 @@ public class DslQueryProcessorTest extends AAISetup { public void multipleEdgeRuleTest() throws AAIException { String aaiQuery = "vserver('vserver-id','abc') > l-interface* > lag-interface*"; String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'vserver').getVerticesByProperty('vserver-id','abc').createEdgeTraversal(EdgeType.TREE, 'vserver','l-interface').store('x').createEdgeTraversal( 'l-interface','lag-interface').store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -379,7 +475,7 @@ public class DslQueryProcessorTest extends AAISetup { public void multipleEdgeRuleTestWithLabels() throws AAIException { String aaiQuery = "vserver('vserver-id','abc') > l-interface* > ('org.onap.relationships.inventory.BelongsTo') lag-interface*"; String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'vserver').getVerticesByProperty('vserver-id','abc').createEdgeTraversal(EdgeType.TREE, 'vserver','l-interface').store('x').createEdgeTraversalWithLabels( 'l-interface','lag-interface', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.BelongsTo'))).store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -388,7 +484,7 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "cloud-region* !('cloud-owner')"; String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner').store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -402,7 +498,7 @@ public class DslQueryProcessorTest extends AAISetup { ".createEdgeTraversal(EdgeType.COUSIN, 'vserver','pserver').getVerticesByProperty('hostname','hostname1'),builder.newInstance()." + "createEdgeTraversal(EdgeType.COUSIN, 'vserver','pserver').getVerticesByProperty('hostname','hostname1'))))).store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vserver').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -416,7 +512,7 @@ public class DslQueryProcessorTest extends AAISetup { ".createEdgeTraversalWithLabels( 'vserver','pserver', new ArrayList<>(Arrays.asList('tosca.relationships.HostedOn'))).getVerticesByProperty('hostname','hostname1'),builder.newInstance()." + "createEdgeTraversalWithLabels( 'vserver','pserver', new ArrayList<>(Arrays.asList('tosca.relationships.HostedOn'))).getVerticesByProperty('hostname','hostname1'))))).store('x').createEdgeTraversalWithLabels( 'generic-vnf','allotted-resource', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.PartOf'))).cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -446,9 +542,38 @@ public class DslQueryProcessorTest extends AAISetup { String aaiQuery = "generic-vnf*('vnf-id','vnfId') > [ pserver* , " + " vserver > pserver* ] > complex* > [ availability-zone > cloud-region*, cloud-region*, " + " ctag-pool* > [ availability-zone* > complex* , generic-vnf* > availability-zone* > complex*, vpls-pe* > complex*] > cloud-region*] > tenant* " ; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(builderQuery, query); } + @Test + public void booleanPropertyValuesTest() throws AAIException { + String aaiQuery = "cloud-region ('cloud-owner','cloud-owner1') > zone*('in-maint',true)"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner','cloud-owner1').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','zone').getVerticesByBooleanProperty('in-maint',true).store('x').cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void upperCaseBooleanPropertyValuesTest() throws AAIException { + String aaiQuery = "cloud-region ('cloud-owner','cloud-owner1') > zone*('in-maint',TRUE)"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner','cloud-owner1').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','zone').getVerticesByBooleanProperty('in-maint',true).store('x').cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void booleanPropertyTest() throws AAIException { + String aaiQuery = "cloud-region ('cloud-owner','cloud-owner1') > zone*('in-maint')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner','cloud-owner1').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','zone').getVerticesByProperty('in-maint').store('x').cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test(expected = AAIException.class) + public void filterOnUnion_vserverFromTentantFromCloudRegion_BadRequest() throws AAIException { + String aaiQuery = "cloud-region('cloud-owner', 'test-aic')>[tenant*('tenant-id', 'tenant1'), tenant*('tenant-id', 'tenant2')]('tenant-name', 'tenant1')>[vserver*]"; + dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + } } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslQueryProcessorV2Test.java b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslQueryProcessorV2Test.java new file mode 100644 index 0000000..85da551 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslQueryProcessorV2Test.java @@ -0,0 +1,591 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.dsl; + +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.aai.AAISetup; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.rest.enums.QueryVersion; + +import static org.junit.Assert.assertEquals; + +/** + * The Class DslMain. + */ +public class DslQueryProcessorV2Test extends AAISetup { + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public void dbAliasTest() throws AAIException { + String aaiQuery = "logical-link* ('model-invariant-id','invid')"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'logical-link').getVerticesByProperty('model-invariant-id-local','invid')" + + ".store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void cloudRegionFromVnf() throws AAIException { + String aaiQuery = "generic-vnf*('vnf-name','xyz') [> vnfc* > vserver* [>pserver*, > tenant* > cloud-region*], "+ + "> vserver* [> pserver*, >tenant* > cloud-region*] ]"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-name','xyz').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vnfc').store('x')." + +"createEdgeTraversal(EdgeType.COUSIN, 'vnfc','vserver').store('x').union(builder.newInstance().createEdgeTraversal" + +"(EdgeType.COUSIN, 'vserver','pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver','tenant')" + +".store('x').createEdgeTraversal(EdgeType.TREE, 'tenant','cloud-region').store('x')),builder.newInstance().createEdgeTraversal" + +"(EdgeType.COUSIN, 'generic-vnf','vserver').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver'" + +",'pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver','tenant').store('x').createEdgeTraversal" + +"(EdgeType.TREE, 'tenant','cloud-region').store('x'))).cap('x').unfold().dedup()"; + + + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void cloudRegionFromVnfWithDirection() throws AAIException { + String aaiQuery = "generic-vnf*('vnf-name','xyz') [>> vnfc* >> vserver* [>>pserver*, >> tenant* >> cloud-region*], "+ + ">> vserver* [>> pserver*, >>tenant* >> cloud-region*] ]"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-name','xyz').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vnfc').store('x')." + +"createEdgeTraversal(EdgeType.COUSIN, 'vnfc','vserver').store('x').union(builder.newInstance().createEdgeTraversal" + +"(EdgeType.COUSIN, 'vserver','pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver','tenant')" + +".store('x').createEdgeTraversal(EdgeType.TREE, 'tenant','cloud-region').store('x')),builder.newInstance().createEdgeTraversal" + +"(EdgeType.COUSIN, 'generic-vnf','vserver').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver'" + +",'pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver','tenant').store('x').createEdgeTraversal" + +"(EdgeType.TREE, 'tenant','cloud-region').store('x'))).cap('x').unfold().dedup()"; + + + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + @Test + public void cloudRegionSites() throws AAIException { + String aaiQuery = "cloud-region*('cloud-owner','xyz') > complex*"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner'" + +",'xyz').store('x').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','complex').store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void pserverWithNoComplexTest() throws AAIException { + String aaiQuery = "pserver*('hostname','xyz')!(> complex)"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'pserver').getVerticesByProperty('hostname','xyz').where(builder.newInstance().not(" + +"builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver','complex'))).store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void pserverWhereNotTest() throws AAIException { + String aaiQuery = "pserver('hostname','xyz')>vserver*!(> vnfc > configuration))"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'pserver').getVerticesByProperty('hostname','xyz').createEdgeTraversal" + + "(EdgeType.COUSIN, 'pserver','vserver').where(builder.newInstance().not(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN,"+ + " 'vserver','vnfc').createEdgeTraversal(EdgeType.COUSIN, 'vnfc','configuration'))).store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void singleNode1() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner','coid')"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner','coid')" + + ".store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void singleNodeLimit() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner','coid') LIMIT 10"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner','coid')" + + ".store('x').cap('x').unfold().dedup().limit(10)"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void specialCharacterTest() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner','coidhello:?_-)(!@#$%^&*+={}[]|/.<,') LIMIT 10"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner','coidhello:?_-)(!@#$%^&*+={}[]|/.<,')" + + ".store('x').cap('x').unfold().dedup().limit(10)"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void singleNodeLimitBlah() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner','coid') LIMIT blah"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner','coid')" + + ".getVerticesByProperty('cloud-region-id','cr id').store('x').cap('x').unfold().dedup().limit(10)"; + + expectedEx.expect(AAIException.class); + expectedEx.expectMessage("DSL Syntax Error while processing the query"); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + } + + @Test + public void singleNodeLimitNull() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner','coid') LIMIT "; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner','coid')" + + ".getVerticesByProperty('cloud-region-id','cr id').store('x').cap('x').unfold().dedup().limit(10)"; + + expectedEx.expect(AAIException.class); + expectedEx.expectMessage("DSL Syntax Error while processing the query"); + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + } + + @Test + public void cloudRegion1Test() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner','coid')('cloud-region-id','cr id') LIMIT 10"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner','coid')" + + ".getVerticesByProperty('cloud-region-id','cr id').store('x').cap('x').unfold().dedup().limit(10)"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void cloudRegion_entitlementTest() throws AAIException { + + /* + A store within a where makes no sense + */ + String aaiQuery = "generic-vnf('vnf-id','vnfId') ( > vserver > tenant > cloud-region('cloud-region-id','One')) > entitlement*"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-id','vnfId').where(" + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vserver').createEdgeTraversal(EdgeType.TREE, 'vserver','tenant').createEdgeTraversal(EdgeType.TREE, 'tenant','cloud-region')" + + ".getVerticesByProperty('cloud-region-id','One'))" + + ".createEdgeTraversal(EdgeType.TREE, 'generic-vnf','entitlement').store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void cloudRegion_entitlementTestWithLabels() throws AAIException { + + String aaiQuery = "generic-vnf('vnf-id','vnfId') (> ('tosca.relationships.HostedOn') vserver > ('org.onap.relationships.inventory.BelongsTo') tenant > ('org.onap.relationships.inventory.BelongsTo') cloud-region('cloud-region-id','One')) > ('org.onap.relationships.inventory.ComposedOf')service-instance*"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-id','vnfId').where(" + + "builder.newInstance().createEdgeTraversalWithLabels( 'generic-vnf','vserver', new ArrayList<>(Arrays.asList('tosca.relationships.HostedOn'))).createEdgeTraversalWithLabels( 'vserver','tenant', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.BelongsTo'))).createEdgeTraversalWithLabels( 'tenant','cloud-region', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.BelongsTo')))" + + ".getVerticesByProperty('cloud-region-id','One'))" + + ".createEdgeTraversalWithLabels( 'generic-vnf','service-instance', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.ComposedOf'))).store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void complex_az_fromComplexTest() throws AAIException { + + String aaiQuery = "cloud-region('cloud-owner','coid')('cloud-region-id','crid') [> availability-zone* ,> complex*]"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region')" + + ".getVerticesByProperty('cloud-owner','coid').getVerticesByProperty('cloud-region-id','crid')" + + ".union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'cloud-region','availability-zone').store('x')" + + ",builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','complex').store('x')).cap('x').unfold().dedup()"; + + assertEquals(dslQuery, query); + } + + @Test + public void complex_az_fromComplexTestWithLabels() throws AAIException { + + String aaiQuery = "cloud-region('cloud-owner','coid')('cloud-region-id','crid') [> ('org.onap.relationships.inventory.BelongsTo')availability-zone* ,> ('org.onap.relationships.inventory.LocatedIn')complex*]"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region')" + + ".getVerticesByProperty('cloud-owner','coid').getVerticesByProperty('cloud-region-id','crid')" + + ".union(builder.newInstance().createEdgeTraversalWithLabels( 'cloud-region','availability-zone', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.BelongsTo'))).store('x')" + + ",builder.newInstance().createEdgeTraversalWithLabels( 'cloud-region','complex', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.LocatedIn'))).store('x')).cap('x').unfold().dedup()"; + + assertEquals(dslQuery, query); + } + + @Test + public void cloudRegion_fromComplex1Test() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'complex').getVerticesByProperty('data-center-code','data-center-code-name')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'complex','cloud-region').store('x').cap('x').unfold().dedup()"; + String aaiQuery = "complex('data-center-code','data-center-code-name') > cloud-region*"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + + assertEquals(builderQuery, query); + } + + @Test + public void cloudRegion_fromComplex2Test() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'complex').getVerticesByProperty('data-center-code','data-center-code-name')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'complex','cloud-region').getVerticesByProperty('cloud-region-version','crv')" + + ".store('x').cap('x').unfold().dedup()"; + String aaiQuery = "complex('data-center-code','data-center-code-name') > cloud-region*('cloud-region-version','crv')"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + + assertEquals(builderQuery, query); + } + + @Test + public void cloudRegion_fromNfTypeTest() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'image').getVerticesByProperty('application-vendor','F5')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'image','vserver')" + + ".where(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver','generic-vnf').getVerticesByProperty('vnf-name','ZALL1MMSC03'))" + + ".createEdgeTraversal(EdgeType.TREE, 'vserver','tenant').createEdgeTraversal(EdgeType.TREE, 'tenant','cloud-region')" + + ".store('x').cap('x').unfold().dedup()"; + + String aaiQuery = "image('application-vendor','F5') > vserver (> generic-vnf('vnf-name','ZALL1MMSC03')) > tenant > cloud-region*"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(builderQuery, query); + } + + @Test + public void cloudRegion_fromNfTypeVendorVersionTest() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'image').getVerticesByProperty('application-vendor','vendor')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'image','vserver').where(" + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vserver','generic-vnf').getVerticesByProperty('nf-type','nfType')" + + ").createEdgeTraversal(EdgeType.TREE, 'vserver','tenant').createEdgeTraversal(EdgeType.TREE, 'tenant','cloud-region')" + + ".store('x').cap('x').unfold().dedup()"; + + String aaiQuery = "image('application-vendor','vendor') > vserver(> generic-vnf('nf-type', 'nfType') ) > tenant > cloud-region*"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + + assertEquals(builderQuery, query); + } + + @Test + public void cloud_region_fromVnfTest() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-id','vnfId')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vnfc').store('x')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'vnfc','vserver').store('x')" + + ".createEdgeTraversal(EdgeType.TREE, 'vserver','tenant').store('x')" + + ".createEdgeTraversal(EdgeType.TREE, 'tenant','cloud-region').store('x')" + + ".cap('x').unfold().dedup()"; + + String aaiQuery = "generic-vnf('vnf-id','vnfId') > vnfc* > vserver* > tenant* > cloud-region*"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + + assertEquals(builderQuery, query); + } + + @Test + public void cloud_region_sitesTest() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region')." + + "getVerticesByProperty('cloud-owner','co').store('x').createEdgeTraversal(EdgeType.COUSIN, " + + "'cloud-region','complex').store('x').cap('x').unfold().dedup()"; + + String aaiQuery = "cloud-region*('cloud-owner','co') > complex*"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + + assertEquals(builderQuery, query); + } + + @Test + public void complex_fromVnf2Test() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-id','vnfId').store('x').union(" + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','pserver').store('x')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'pserver','complex').store('x')," + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vserver')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'vserver','pserver').store('x')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'pserver','complex').store('x')" + + ").cap('x').unfold().dedup()"; + + String aaiQuery = "generic-vnf*('vnf-id','vnfId') [ > pserver* > complex*, " + + " >vserver > pserver* > complex* " + "]"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + + assertEquals(builderQuery, query); + } + + @Test + public void complex_fromVnfTest2() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-id','vnfId').store('x').union(" + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','pserver').store('x')," + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vserver')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'vserver','pserver').store('x'))" + + ".createEdgeTraversal(EdgeType.COUSIN, 'pserver','complex').store('x')" + + ".cap('x').unfold().dedup()"; + + String aaiQuery = "generic-vnf*('vnf-id','vnfId') [> pserver* , " + + " > vserver > pserver* ] > complex*"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + + assertEquals(builderQuery, query); + } + + @Test + public void fn_topology1Test() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'customer')" + + ".getVerticesByProperty('global-customer-id','a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb')" + + ".createEdgeTraversal(EdgeType.TREE, 'customer','service-subscription').getVerticesByProperty('service-subscription-id','Nimbus')" + + ".createEdgeTraversal(EdgeType.TREE, 'service-subscription','service-instance').getVerticesByProperty('service-instance-id','sid')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'service-instance','generic-vnf').store('x')" + + ".union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vnfc').store('x')," + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vserver').store('x')," + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','pserver').store('x')," + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','pnf').store('x')).cap('x').unfold().dedup()"; + + String aaiQuery = "customer('global-customer-id', 'a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb') > service-subscription('service-subscription-id', 'Nimbus') " + + " > service-instance('service-instance-id','sid') > generic-vnf* " + + " [> vnfc* ,> vserver*,> pserver* ,> pnf* ]"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + + assertEquals(builderQuery, query); + } + + @Test + public void vnf_Dsl() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-id','vnfId').where(builder.newInstance().union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','pserver')" + + ".getVerticesByProperty('hostname','hostname1'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vserver')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'vserver','pserver').getVerticesByProperty('hostname','hostname1'))).store('x').cap('x').unfold().dedup()"; + + String aaiQuery = "generic-vnf*('vnf-id','vnfId') ( [> pserver('hostname','hostname1'), " + + " > vserver > pserver('hostname','hostname1')])"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + + assertEquals(builderQuery, query); + } + + @Test + public void hasPropertyTest() throws AAIException { + String aaiQuery = "cloud-region* ('cloud-owner')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner').store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void hasPropertyValuesTest() throws AAIException { + String aaiQuery = "cloud-region* ('cloud-owner','cloud-owner1','cloud-owner2')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner', new ArrayList<>(Arrays.asList('cloud-owner1','cloud-owner2'))).store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void hasNotPropertyValuesTest() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner','cloud-owner1','cloud-owner2')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner', new ArrayList<>(Arrays.asList('cloud-owner1','cloud-owner2'))).store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void hasNotPropertyNullValuesTest() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner',' ',' null ')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner', new ArrayList<>(Arrays.asList(' ',' null '))).store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void hasPropertyIntegerTest() throws AAIException { + String aaiQuery = "cloud-region('cloud-owner', 'att-nc')('cloud-region-id', 'MTN61a') > vlan-tag*('vlan-id-inner', 20)"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner','att-nc').getVerticesByProperty('cloud-region-id','MTN61a').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','vlan-tag').getVerticesByProperty('vlan-id-inner',20).store('x').cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void directionalityTest() throws AAIException { + String aaiQuery = "cloud-region('cloud-region-id','abc') >> complex* >> l3-network*"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-region-id','abc').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','complex').store('x').createEdgeTraversal(EdgeType.COUSIN, 'complex','l3-network').store('x').cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void enterSelectFilterTest() throws AAIException { + String aaiQuery = "cloud-region*('cloud-region-id','whp3a'){'cloud-region-id'}"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-region-id','whp3a').store('x').cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2, aaiQuery).get("query").toString(); + assertEquals(query, dslQuery); + } + + + @Test + public void returnSpecificPropsAndAllForDifferentVertices() throws AAIException { + String aaiQuery = "cloud-region{'cloud-owner'}('cloud-region-id','new-r111egion-111111') > [ l3-network*, vlan-tag*]"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-region-id','new-r111egion-111111').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','l3-network').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','vlan-tag').store('x')).cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2, aaiQuery).get("query").toString(); + assertEquals(query, dslQuery); + } + + @Test + public void groupingAttributesTestForAggregate() throws AAIException { + String aaiQuery = "cloud-region{'cloud-owner'}('cloud-owner','att-nc')('cloud-region-id','wah2a') > vip-ipv6-address-list > [subnet{'subnet-name'}, instance-group{'id'}]"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner','att-nc').getVerticesByProperty('cloud-region-id','wah2a').store('x').createEdgeTraversal(EdgeType.TREE, 'cloud-region','vip-ipv6-address-list').union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vip-ipv6-address-list','subnet').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'vip-ipv6-address-list','instance-group').store('x')).cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2, aaiQuery).get("query").toString(); + assertEquals(query, dslQuery); + } + + @Test + public void multipleEdgeRuleTest() throws AAIException { + String aaiQuery = "vserver('vserver-id','abc') > l-interface* > lag-interface*"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'vserver').getVerticesByProperty('vserver-id','abc').createEdgeTraversal(EdgeType.TREE, 'vserver','l-interface').store('x').createEdgeTraversal( 'l-interface','lag-interface').store('x').cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void multipleEdgeRuleTestWithLabels() throws AAIException { + String aaiQuery = "vserver('vserver-id','abc') > l-interface* > ('org.onap.relationships.inventory.BelongsTo') lag-interface*"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'vserver').getVerticesByProperty('vserver-id','abc').createEdgeTraversal(EdgeType.TREE, 'vserver','l-interface').store('x').createEdgeTraversalWithLabels( 'l-interface','lag-interface', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.BelongsTo'))).store('x').cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void hasNotPropertyTest() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner').store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void overlyNestedQueryTest() throws AAIException { + //String aaiQuery = "generic-vnf*('vnf-id','vnfId') (> [ pserver('hostname','hostname1'), vserver (> [ pserver('hostname','hostname1'), pserver('hostname','hostname1')])]) > vserver"; + String aaiQuery = "generic-vnf*('vnf-id','vnfId') ( [> pserver('hostname','hostname1'), > vserver ( [> pserver('hostname','hostname1'), > pserver('hostname','hostname1')])]) > vserver"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-id','vnfId').where(builder.newInstance().union" + + "(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','pserver').getVerticesByProperty('hostname','hostname1')," + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vserver').where(builder.newInstance().union(builder.newInstance()" + + ".createEdgeTraversal(EdgeType.COUSIN, 'vserver','pserver').getVerticesByProperty('hostname','hostname1'),builder.newInstance()." + + "createEdgeTraversal(EdgeType.COUSIN, 'vserver','pserver').getVerticesByProperty('hostname','hostname1'))))).store('x').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vserver').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void overlyNestedQueryTestWithLabels() throws AAIException { + String aaiQuery = "generic-vnf*('vnf-id','vnfId') ( [> ('tosca.relationships.HostedOn')pserver('hostname','hostname1'),> ('tosca.relationships.HostedOn')vserver ( [> ('tosca.relationships.HostedOn')pserver('hostname','hostname1'),> ('tosca.relationships.HostedOn')pserver('hostname','hostname1')])]) > ('org.onap.relationships.inventory.PartOf')allotted-resource"; + + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-id','vnfId').where(builder.newInstance().union" + + "(builder.newInstance().createEdgeTraversalWithLabels( 'generic-vnf','pserver', new ArrayList<>(Arrays.asList('tosca.relationships.HostedOn'))).getVerticesByProperty('hostname','hostname1')," + + "builder.newInstance().createEdgeTraversalWithLabels( 'generic-vnf','vserver', new ArrayList<>(Arrays.asList('tosca.relationships.HostedOn'))).where(builder.newInstance().union(builder.newInstance()" + + ".createEdgeTraversalWithLabels( 'vserver','pserver', new ArrayList<>(Arrays.asList('tosca.relationships.HostedOn'))).getVerticesByProperty('hostname','hostname1'),builder.newInstance()." + + "createEdgeTraversalWithLabels( 'vserver','pserver', new ArrayList<>(Arrays.asList('tosca.relationships.HostedOn'))).getVerticesByProperty('hostname','hostname1'))))).store('x').createEdgeTraversalWithLabels( 'generic-vnf','allotted-resource', new ArrayList<>(Arrays.asList('org.onap.relationships.inventory.PartOf'))).cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void nestedUnionQueryTest() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-id','vnfId').store('x').union(" + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','pserver').store('x')," + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vserver')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'vserver','pserver').store('x'))" + + ".createEdgeTraversal(EdgeType.COUSIN, 'pserver','complex').store('x')" + + ".union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'complex','availability-zone')" + + ".createEdgeTraversal(EdgeType.TREE, 'availability-zone','cloud-region').store('x')," + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'complex','cloud-region').store('x')," + + "builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'complex','ctag-pool').store('x').union(" + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'ctag-pool','availability-zone').store('x')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'availability-zone','complex').store('x')," + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'ctag-pool','generic-vnf').store('x')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','availability-zone').store('x')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'availability-zone','complex').store('x')," + + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'ctag-pool','vpls-pe').store('x')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'vpls-pe','complex').store('x'))" + + ".createEdgeTraversal(EdgeType.COUSIN, 'complex','cloud-region').store('x'))" + + ".createEdgeTraversal(EdgeType.TREE, 'cloud-region','tenant').store('x')" + + ".cap('x').unfold().dedup()"; + + String aaiQuery = "generic-vnf*('vnf-id','vnfId') [> pserver* , " + + " > vserver > pserver* ] > complex* [> availability-zone > cloud-region*,> cloud-region*, " + + " > ctag-pool* [ > availability-zone* > complex* , > generic-vnf* > availability-zone* > complex*,> vpls-pe* > complex*] > cloud-region*] > tenant* " ; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + + assertEquals(builderQuery, query); + } + + @Test + public void booleanPropertyValuesTest() throws AAIException { + String aaiQuery = "cloud-region ('cloud-owner','cloud-owner1') > zone*('in-maint',true)"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner','cloud-owner1').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','zone').getVerticesByBooleanProperty('in-maint',true).store('x').cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void upperCaseBooleanPropertyValuesTest() throws AAIException { + String aaiQuery = "cloud-region ('cloud-owner','cloud-owner1') > zone*('in-maint',TRUE)"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner','cloud-owner1').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','zone').getVerticesByBooleanProperty('in-maint',true).store('x').cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test + public void booleanPropertyTest() throws AAIException { + String aaiQuery = "cloud-region ('cloud-owner','cloud-owner1') > zone*('in-maint')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner','cloud-owner1').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','zone').getVerticesByProperty('in-maint').store('x').cap('x').unfold().dedup()"; + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + assertEquals(dslQuery, query); + } + + @Test(expected = AAIException.class) + public void filterOnUnion_vserverFromTentantFromCloudRegion_BadRequest() throws AAIException { + String aaiQuery = "cloud-region('cloud-owner', 'test-aic')>[tenant*('tenant-id', 'tenant1'), tenant*('tenant-id', 'tenant2')]('tenant-name', 'tenant1')>[vserver*]"; + dslQueryProcessor.parseAaiQuery(QueryVersion.V2,aaiQuery).get("query").toString(); + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/dsl/EdgeLabelTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/EdgeLabelTest.java new file mode 100644 index 0000000..9664342 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/EdgeLabelTest.java @@ -0,0 +1,62 @@ +/** + * ============LICENSE_START================================================== + * org.onap.aai + * =========================================================================== + * Copyright © 2017-2020 AT&T Intellectual Property. 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==================================================== + */ +package org.onap.aai.rest.dsl; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class EdgeLabelTest { + + private static EdgeLabel edgeLabel; + private static EdgeLabel edgeLabel1; + + @Before + public void setUp() throws Exception { + edgeLabel = new EdgeLabel("label", true); + edgeLabel1 = new EdgeLabel("org.onap.relationships.inventory.Uses", false); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void getLabel() { + assertEquals(edgeLabel.getLabel(), "label"); + } + + @Test + public void setLabel() { + edgeLabel1.setLabel("org.onap.relationships.inventory.Uses"); + } + + @Test + public void isExactMatch() { + assertFalse(edgeLabel1.isExactMatch()); + } + + @Test + public void setExactMatch() { + edgeLabel1.setExactMatch(false); + } +}
\ No newline at end of file diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/dsl/EdgeTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/EdgeTest.java new file mode 100644 index 0000000..4378085 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/EdgeTest.java @@ -0,0 +1,79 @@ +/** + * ============LICENSE_START================================================== + * org.onap.aai + * =========================================================================== + * Copyright © 2017-2020 AT&T Intellectual Property. 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==================================================== + */ +package org.onap.aai.rest.dsl; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.rest.enums.EdgeDirection; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +public class EdgeTest { + + Edge edge; + Edge edge2; + @Before + public void setUp() throws Exception { + EdgeDirection dir = EdgeDirection.OUT; + EdgeDirection both = EdgeDirection.BOTH; + EdgeLabel label = new EdgeLabel("org.onap.relationships.inventory.Uses", true); + List<EdgeLabel> labelList = new ArrayList<EdgeLabel>(); + edge = new Edge(dir, labelList); + edge2 = new Edge(both, labelList); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void getLabels() { + assertNotNull(edge.getLabels()); + } + + @Test + public void setLabels() { + EdgeLabel label = new EdgeLabel("org.onap.relationships.inventory.Uses", true); + List<EdgeLabel> labelList = new ArrayList<EdgeLabel>(); + labelList.add(label); + edge.setLabels(labelList); + } + + @Test + public void getDirection() { + assertEquals(edge2.getDirection(), EdgeDirection.BOTH); + assertEquals(edge.getDirection(), EdgeDirection.OUT); + } + + @Test + public void setDirection() { + edge.setDirection(EdgeDirection.OUT); + } + + @Test + public void testToString() { + assertNotNull(edge.getDirection().toString()); + assertNotNull(edge.toString()); + } +}
\ No newline at end of file diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/dsl/ProdDslTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/ProdDslTest.java index 822643e..e8fee37 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/dsl/ProdDslTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/ProdDslTest.java @@ -22,6 +22,7 @@ package org.onap.aai.rest.dsl; import org.junit.Test; import org.onap.aai.AAISetup; import org.onap.aai.exceptions.AAIException; +import org.onap.aai.rest.enums.QueryVersion; import static org.junit.Assert.assertEquals; @@ -37,7 +38,7 @@ public class ProdDslTest extends AAISetup { + ".getVerticesByProperty('cloud-region-id','value').createEdgeTraversal(EdgeType.COUSIN, 'cloud-region','vlan-tag')" + ".getVerticesByProperty('vlan-id-outer','value').store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -49,7 +50,7 @@ public class ProdDslTest extends AAISetup { + ".createEdgeTraversal(EdgeType.TREE, 'pserver','p-interface')" + ".createEdgeTraversal(EdgeType.TREE, 'p-interface','sriov-pf').getVerticesByProperty('pf-pci-id','0000:ee:00.0').store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -61,7 +62,7 @@ public class ProdDslTest extends AAISetup { + ".createEdgeTraversal(EdgeType.TREE, 'l-interface','sriov-vf')" + ".createEdgeTraversal(EdgeType.COUSIN, 'sriov-vf','sriov-pf').store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -75,7 +76,7 @@ public class ProdDslTest extends AAISetup { + ".createEdgeTraversal( 'l-interface','lag-interface').getVerticesByProperty('interface-name','bond1')" + ".createEdgeTraversal(EdgeType.COUSIN, 'lag-interface','p-interface').createEdgeTraversal(EdgeType.TREE, 'p-interface','sriov-pf').store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } @@ -88,7 +89,7 @@ public class ProdDslTest extends AAISetup { + ".createEdgeTraversal(EdgeType.COUSIN, 'pserver','vserver').getVerticesByProperty('vserver-name','value')" + ".createEdgeTraversal(EdgeType.TREE, 'vserver','l-interface').createEdgeTraversal(EdgeType.COUSIN, 'l-interface','cp').createEdgeTraversal(EdgeType.COUSIN, 'cp','vlan-tag').store('x').cap('x').unfold().dedup()"; - String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(QueryVersion.V1,aaiQuery).get("query").toString(); assertEquals(dslQuery, query); } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/history/AbstractSpringHistoryRestTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/history/AbstractSpringHistoryRestTest.java new file mode 100644 index 0000000..f671135 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/history/AbstractSpringHistoryRestTest.java @@ -0,0 +1,138 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.history; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; +import org.junit.*; +import org.onap.aai.TraversalApp; +import org.onap.aai.TraversalTestConfiguration; +import org.onap.aai.config.PropertyPasswordConfiguration; +import org.onap.aai.dbmap.AAIGraph; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.util.AAIConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.rules.SpringClassRule; +import org.springframework.test.context.junit4.rules.SpringMethodRule; +import org.springframework.web.client.RestTemplate; + +import java.io.UnsupportedEncodingException; +import java.util.Base64; +import java.util.Collections; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TraversalApp.class) +@TestPropertySource( + locations = "classpath:application-test.properties", + properties = { + "history.enabled=true", + "history.truncate.window.days = " + Integer.MAX_VALUE + } +) +@ContextConfiguration(initializers = PropertyPasswordConfiguration.class) +@Import(TraversalTestConfiguration.class) +public abstract class AbstractSpringHistoryRestTest { + + @ClassRule + public static final SpringClassRule springClassRule = new SpringClassRule(); + + @Rule + public final SpringMethodRule springMethodRule = new SpringMethodRule(); + + @Autowired + protected RestTemplate restTemplate; + + @Autowired + protected NodeIngestor nodeIngestor; + + @LocalServerPort + protected int randomPort; + + protected HttpEntity httpEntity; + + protected String baseUrl; + protected HttpHeaders headers ; + + @BeforeClass + public static void setupConfig() throws AAIException { + System.setProperty("AJSC_HOME", "./"); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/"); + } + + @Before + public void setup() throws AAIException, UnsupportedEncodingException { + + AAIConfig.init(); + AAIGraph.getInstance(); + + createTestGraph(); + headers = new HttpHeaders(); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add("Real-Time", "true"); + headers.add("X-FromAppId", "JUNIT"); + headers.add("X-TransactionId", "JUNIT"); + String authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes("UTF-8")); + headers.add("Authorization", "Basic " + authorization); + httpEntity = new HttpEntity(headers); + baseUrl = "http://localhost:" + randomPort; + } + + /* + * Inheritors please override this one + */ + public void createTestGraph(){ + + } + + @After + public void tearDown(){ + + JanusGraph janusGraph = AAIGraph.getInstance().getGraph(); + JanusGraphTransaction transaction = janusGraph.newTransaction(); + + boolean success = true; + + try { + GraphTraversalSource g = transaction.traversal(); + g.V().toList() + .forEach(Vertex::remove); + } catch(Exception ex){ + success = false; + } finally { + if(success){ + transaction.commit(); + } else { + transaction.rollback(); + } + } + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/history/CQAllChildernFromPnfStateTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/history/CQAllChildernFromPnfStateTest.java new file mode 100644 index 0000000..7cf8138 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/history/CQAllChildernFromPnfStateTest.java @@ -0,0 +1,246 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.history; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.janusgraph.core.JanusGraphTransaction; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.aai.db.props.AAIProperties; +import org.onap.aai.dbmap.AAIGraph; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +@Ignore("The state format requires the history schema to be loaded. " + + "Because aaigraph is a singleton its very complicated to have 2 different schemas loaded for testing. " + + "This needs to be addressed.") +public class CQAllChildernFromPnfStateTest extends AbstractSpringHistoryRestTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(CQAllChildernFromPnfStateTest.class); + + @Override + public void createTestGraph() { + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + boolean success = true; + try { + GraphTraversalSource g = transaction.traversal(); + + Vertex pnf1 = g.addV() + .property(AAIProperties.NODE_TYPE, "pnf", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.AAI_URI, "/network/pnfs/pnf/pnf-1", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.RESOURCE_VERSION, "100", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.START_TS, 100L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("pnf-name", "pnf-1", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("in-maint", false, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("pnf-id", "pnf-1-id", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .next(); + + Vertex pint1 = g.addV() + .property(AAIProperties.NODE_TYPE, "p-interface", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.AAI_URI, "/network/pnfs/pnf/pnf-1/p-interfaces/p-interface/pint-1", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.RESOURCE_VERSION, "100", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.START_TS, 100L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("interface-name", "pint-1", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .next(); + + Vertex lint1 = g.addV() + .property(AAIProperties.NODE_TYPE, "l-interface", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.AAI_URI, "/network/pnfs/pnf/pnf-1/p-interfaces/p-interface/pint-1/l-interfaces/l-interface/lint-1", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.RESOURCE_VERSION, "100", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.START_TS, 100L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("interface-name", "lint-1", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .next(); + + pint1.addEdge("tosca.relationships.network.BindsTo", pnf1, + "start-ts", 100L, + "private", false, + "aai-uuid", "e713ce2c-62d5-4555-a481-95619cb158aa", + "prevent-delete", "NONE", + "delete-other-v", "IN", + "source-of-truth", "JUNIT-EDGE-C", + "start-tx-id", "JUNIT-EDGE-C", + "contains-other-v", "IN"); + + lint1.addEdge("tosca.relationships.network.BindsTo", pint1, + "start-ts", 100L, + "private", false, + "aai-uuid", "e713ce2c-62d5-4555-a481-95619cb158ab", + "prevent-delete", "NONE", + "delete-other-v", "IN", + "source-of-truth", "JUNIT-EDGE-C", + "start-tx-id", "JUNIT-EDGE-C", + "contains-other-v", "IN"); + + } catch (Exception ex) { + success = false; + } finally { + if (success) { + transaction.commit(); + } else { + transaction.rollback(); + fail("Unable to setup the graph"); + } + } + } + + private JsonArray executeCustomQuery(String endpoint, String queryName, String... startUris) throws Exception { + JsonObject payload = new JsonObject(); + JsonArray start = new JsonArray(); + Arrays.stream(startUris).forEach(start::add); + payload.add("start", start); + payload.addProperty("query", "query/" + queryName); + httpEntity = new HttpEntity(payload.toString(), headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + JsonArray results = new JsonParser().parse(responseEntity.getBody().toString()).getAsJsonObject().getAsJsonArray("results"); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + return results; + } + + private JsonArray executeGremlin(String endpoint, String query) throws Exception { + JsonObject payload = new JsonObject(); + payload.addProperty("gremlin", query); + httpEntity = new HttpEntity(payload.toString(), headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + JsonArray results = new JsonParser().parse(responseEntity.getBody().toString()).getAsJsonObject().getAsJsonArray("results"); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + return results; + } + + private void verifyResultUris(JsonArray results, String... uris) { + Set<String> expected = new HashSet<>(Arrays.asList(uris)); + final Set<String> actualEquipType = new HashSet<>(); + for (JsonElement result : results) { + actualEquipType.add(result.getAsJsonObject().get("uri").getAsString()); + } + assertThat("Verify results uri's", actualEquipType, is(expected)); + } + + + @Test + public void pnfChildrenQueryTest() throws Exception { + JsonArray results = executeCustomQuery("/aai/v14/query?format=state", "allchildren-fromPnf", "/network/pnfs/pnf/pnf-1"); + verifyResultUris(results, "/network/pnfs/pnf/pnf-1", "/network/pnfs/pnf/pnf-1/p-interfaces/p-interface/pint-1", "/network/pnfs/pnf/pnf-1/p-interfaces/p-interface/pint-1/l-interfaces/l-interface/lint-1"); + } + + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryLifecycleEdgeTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryLifecycleEdgeTest.java new file mode 100644 index 0000000..5b2c8da --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryLifecycleEdgeTest.java @@ -0,0 +1,476 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.history; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.janusgraph.core.JanusGraphTransaction; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.aai.PayloadUtil; +import org.onap.aai.db.props.AAIProperties; +import org.onap.aai.dbmap.AAIGraph; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.*; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +@Ignore("The lifecycle format requires the history schema to be loaded. " + + "Because aaigraph is a singleton its very complicated to have 2 different schemas loaded for testing. " + + "This needs to be addressed.") +public class DslConsumerHistoryLifecycleEdgeTest extends AbstractSpringHistoryRestTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(DslConsumerHistoryLifecycleEdgeTest.class); + + @Override + public void createTestGraph() { + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + boolean success = true; + try { + GraphTraversalSource g = transaction.traversal(); + + Vertex pserver = g.addV().property(AAIProperties.NODE_TYPE, "pserver", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.RESOURCE_VERSION, "100", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property("hostname", "test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property("in-maint", false, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property("equip-type", "ps-type", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.START_TS, 100L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .next(); + Vertex complex = g.addV().property(AAIProperties.NODE_TYPE, "complex", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/complexes/complex/test-complex-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.RESOURCE_VERSION, "100", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property("physical-location-id", "test-complex-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property("street", "200 S. Laurel Ave", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property("city", "Middletown", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property("state", "NJ", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property("zip", "11111", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.START_TS, 100L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C" , + AAIProperties.START_TS, 100L + ) + .next(); + + pserver.addEdge("org.onap.relationships.inventory.LocatedIn", + complex, + "start-ts", 100, + "private", false, + "aai-uuid", "edge1", + "end-source-of-truth", "JUNIT-E-D-1", + "end-tx-id", "JUNIT-E-D-1", + "end-ts", 300, + "prevent-delete", "IN", + "delete-other-v", "NONE", + "source-of-truth", "JUNIT-E-C-1", + "start-tx-id", "JUNIT-E-C-1", + "contains-other-v", "NONE" + ); + pserver.addEdge("org.onap.relationships.inventory.LocatedIn", + complex, + "start-ts", 500, + "private", false, + "aai-uuid", "edge2", + "end-source-of-truth", "JUNIT-E-D-2", + "end-tx-id", "JUNIT-E-D-2", + "end-ts", 700, + "prevent-delete", "IN", + "delete-other-v", "NONE", + "source-of-truth", "JUNIT-E-C-2", + "start-tx-id", "JUNIT-E-C-2", + "contains-other-v", "NONE" + ); + pserver.addEdge("org.onap.relationships.inventory.LocatedIn", + complex, + "start-ts", 900, + "private", false, + "aai-uuid", "edge3", + "end-source-of-truth", "JUNIT-E-D-3", + "end-tx-id", "JUNIT-E-D-3", + "end-ts", 1100, + "prevent-delete", "IN", + "delete-other-v", "NONE", + "source-of-truth", "JUNIT-E-C-3", + "start-tx-id", "JUNIT-E-C-3", + "contains-other-v", "NONE" + ); + pserver.addEdge("org.onap.relationships.inventory.LocatedIn", + complex, + "start-ts", 1300, + "private", false, + "aai-uuid", "edge3", + "prevent-delete", "IN", + "delete-other-v", "NONE", + "source-of-truth", "JUNIT-E-C-3", + "start-tx-id", "JUNIT-E-C-3", + "contains-other-v", "NONE" + ); + } catch (Exception ex) { + success = false; + } finally { + if (success) { + transaction.commit(); + } else { + transaction.rollback(); + fail("Unable to setup the graph"); + } + } + } + + private JsonArray getResultsForPserverLookupByHostname(String endpoint) throws Exception { + return getResultsForPserverLookupByHostnameAndAnother(endpoint, ""); + } + + private JsonArray getResultsForPserverLookupByHostnameAndAnother(String endpoint, String additionalFilterInParen) throws Exception { + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver*('hostname','test-pserver-dsl')" + additionalFilterInParen); + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + JsonArray results = new JsonParser().parse(responseEntity.getBody().toString()).getAsJsonObject().getAsJsonArray("results"); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + + assertNotNull("Response from /aai/v14/dsl is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + return results; + } + + + private void verifyEquipTypeValues(JsonArray results, String... expectedEquipTypes) { + List<String> expected = Arrays.asList(expectedEquipTypes); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("value") && !property.getAsJsonObject().get("value").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("value").getAsString()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type in lifecycle", actualEquipType, is(expected)); + } + + private void verifyEquipTypeSoTs(JsonArray results, String... expectedSTOs) { + List<String> expected = Arrays.asList(expectedSTOs); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("sot") && !property.getAsJsonObject().get("sot").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("sot").getAsString()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type SoTs in lifecycle", actualEquipType, is(expected)); + } + + private void verifyEquipTypeTxId(JsonArray results, String... expectedSTOs) { + List<String> expected = Arrays.asList(expectedSTOs); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("tx-id") && !property.getAsJsonObject().get("tx-id").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("tx-id").getAsString()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type tx-ids in lifecycle", actualEquipType, is(expected)); + } + + private void verifyEquipTypeTimestamps(JsonArray results, Long... expectedSTOs) { + List<Long> expected = Arrays.asList(expectedSTOs); + final List<Long> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("timestamp") && !property.getAsJsonObject().get("timestamp").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("timestamp").getAsLong()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type timestamps in lifecycle", actualEquipType, is(expected)); + } + + private void verifyNodeTimestamps(JsonArray results, Long... nodeTimestamps) { + List<Long> expected = Arrays.asList(nodeTimestamps); + final List<Long> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + result.getAsJsonObject().get("node-actions").getAsJsonArray().forEach(jsonElement -> + actualEquipType.add(jsonElement.getAsJsonObject().get("timestamp").getAsLong())); + } + assertThat("Verify node-changes timestamps in lifecycle", actualEquipType, is(expected)); + } + + private void verifyRelatedToCreatedTimestamps(JsonArray results, Long... edgeCreatedTimestamps) { + List<Long> expected = Arrays.asList(edgeCreatedTimestamps); + final List<Long> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + result.getAsJsonObject().get("related-to").getAsJsonArray().forEach(jsonElement -> { + if (jsonElement.getAsJsonObject().has("timestamp")) { + actualEquipType.add(jsonElement.getAsJsonObject().get("timestamp").getAsLong()); + } + }); + } + assertThat("Verify related-to createdtimestamps in lifecycle", actualEquipType, is(expected)); + } + + private void verifyRelatedToCreatedDeletedTimestamps(JsonArray results, Long... edgeDeletedTimestamps) { + List<Long> expected = Arrays.asList(edgeDeletedTimestamps); + final List<Long> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + result.getAsJsonObject().get("related-to").getAsJsonArray().forEach(jsonElement -> { + if (jsonElement.getAsJsonObject().has("end-timestamp")) { + actualEquipType.add(jsonElement.getAsJsonObject().get("end-timestamp").getAsLong()); + } + }); + } + assertThat("Verify related-to createdtimestamps in lifecycle", actualEquipType, is(expected)); + } + + private void verifyRelatedToCount(JsonArray results, int expectedSize) { + int actualSize = 0; + for (JsonElement result : results) { + actualSize += result.getAsJsonObject().get("related-to").getAsJsonArray().size(); + } + assertEquals("Verify related-to count", actualSize, expectedSize); + } + + private void verifyRelatedToTxId(JsonArray results) { + final Set<JsonObject> withTxId = new HashSet<>(); + int count = 0; + for (JsonElement result : results) { + count += result.getAsJsonObject().get("related-to").getAsJsonArray().size(); + result.getAsJsonObject().get("related-to").getAsJsonArray().forEach(jsonElement -> { + if (jsonElement.getAsJsonObject().has("tx-id")) { + withTxId.add(jsonElement.getAsJsonObject()); + } + if (jsonElement.getAsJsonObject().has("end-tx-id")) { + withTxId.add(jsonElement.getAsJsonObject()); + } + }); + } + assertEquals("Verify no related-to has end-tx-id in state", count, withTxId.size()); + } + + + @Test + public void lifecycleQueryStartTsBeforeCreationTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-C"); + verifyEquipTypeTimestamps(results, 100L); + verifyNodeTimestamps(results, 100L); + verifyRelatedToCreatedTimestamps(results, 100L, 500L, 900L, 1300L); + verifyRelatedToCreatedDeletedTimestamps(results, 300L, 700L, 1100L); + verifyRelatedToCount(results, 4); + verifyRelatedToTxId(results); + } + + + + @Test + public void lifecycleQueryStartTsBeforeSecondEdgeCreationTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=400"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results); + verifyEquipTypeSoTs(results); + verifyEquipTypeTxId(results); + verifyEquipTypeTimestamps(results); + verifyNodeTimestamps(results); + verifyRelatedToCreatedTimestamps(results, 500L, 900L, 1300L); + verifyRelatedToCreatedDeletedTimestamps(results, 700L, 1100L); + verifyRelatedToCount(results, 3); + verifyRelatedToTxId(results); + } + + @Test + public void lifecycleQueryStartTsAtSecondEdgeDeletionTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=700"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results); + verifyEquipTypeSoTs(results); + verifyEquipTypeTxId(results); + verifyEquipTypeTimestamps(results); + verifyNodeTimestamps(results); + verifyRelatedToCreatedTimestamps(results, 900L, 1300L); + verifyRelatedToCreatedDeletedTimestamps(results, 700L, 1100L); + verifyRelatedToCount(results, 3); + verifyRelatedToTxId(results); + } + + @Test + public void lifecycleQueryStartTsAfterSecondEdgeDeletionTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=800"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results); + verifyEquipTypeSoTs(results); + verifyEquipTypeTxId(results); + verifyEquipTypeTimestamps(results); + verifyNodeTimestamps(results); + verifyRelatedToCreatedTimestamps(results, 900L, 1300L); + verifyRelatedToCreatedDeletedTimestamps(results, 1100L); + verifyRelatedToCount(results, 2); + verifyRelatedToTxId(results); + } + + @Test + public void lifecycleQueryStartTsAtLastEdgeActionTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=1300"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results); + verifyEquipTypeSoTs(results); + verifyEquipTypeTxId(results); + verifyEquipTypeTimestamps(results); + verifyNodeTimestamps(results); + verifyRelatedToCreatedTimestamps(results, 1300L); + verifyRelatedToCreatedDeletedTimestamps(results); + verifyRelatedToCount(results, 1); + verifyRelatedToTxId(results); + } + + @Test + public void lifecycleQueryStartTsAfterLastEdgeActionTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=1400"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 0, results.size()); + + verifyEquipTypeValues(results); + verifyEquipTypeSoTs(results); + verifyEquipTypeTxId(results); + verifyEquipTypeTimestamps(results); + verifyNodeTimestamps(results); + verifyRelatedToCreatedTimestamps(results); + verifyRelatedToCreatedDeletedTimestamps(results); + verifyRelatedToCount(results, 0); + verifyRelatedToTxId(results); + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryLifecycleNodeDeletedThenRecreatedTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryLifecycleNodeDeletedThenRecreatedTest.java new file mode 100644 index 0000000..25e9e84 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryLifecycleNodeDeletedThenRecreatedTest.java @@ -0,0 +1,744 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.history; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.janusgraph.core.JanusGraphTransaction; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.aai.PayloadUtil; +import org.onap.aai.db.props.AAIProperties; +import org.onap.aai.dbmap.AAIGraph; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.*; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +@Ignore("The lifecycle format requires the history schema to be loaded. " + + "Because aaigraph is a singleton its very complicated to have 2 different schemas loaded for testing. " + + "This needs to be addressed.") +public class DslConsumerHistoryLifecycleNodeDeletedThenRecreatedTest extends AbstractSpringHistoryRestTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(DslConsumerHistoryLifecycleNodeDeletedThenRecreatedTest.class); + + @Override + public void createTestGraph() { + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + boolean success = true; + try { + GraphTraversalSource g = transaction.traversal(); + /* + Pserver + - created pserver @ time 100 + - equip-type = first-ps-type + - update equip-type @ 500 + - equip-type = first-ps-type-update + - deleted pserver @ time 1000 + */ + g.addV().property(AAIProperties.NODE_TYPE, "pserver", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.RESOURCE_VERSION, "100", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U", + AAIProperties.END_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 500L + ) + .property(AAIProperties.RESOURCE_VERSION, "500", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U", + AAIProperties.START_TX_ID, "JUNIT-U", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 500L, + AAIProperties.END_TS, 1000L + ) + .property("hostname", "test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property("in-maint", false, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property("equip-type", "first-ps-type", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U", + AAIProperties.END_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 500L + ) + .property("equip-type", "first-ps-type-update", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U", + AAIProperties.START_TX_ID, "JUNIT-U", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 500L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-D", + AAIProperties.START_TX_ID, "JUNIT-D", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.START_TS, 100L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.END_TS, 1000L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-D", + AAIProperties.START_TX_ID, "JUNIT-D", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 1000L, + AAIProperties.END_TS, 1000L + ) + .next(); + + /* + Pserver + - created pserver @ time 10000 + - equip-type = second-ps-type + - delete equip-type @ 13000 + - recreate equip-type @ 15000 + - equip-type = second-ps-type-recreated + - update equip-type @ 17000 + - equip-type = second-ps-type-update + - delete equip-type @ 20000 + */ + g.addV().property(AAIProperties.NODE_TYPE, "pserver", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 10000L + ) + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 10000L + ) + .property(AAIProperties.RESOURCE_VERSION, "10000", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U-1", + AAIProperties.END_TX_ID, "JUNIT-U-1", + AAIProperties.START_TS, 10000L, + AAIProperties.END_TS, 13000L + ) + .property(AAIProperties.RESOURCE_VERSION, "13000", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U-1", + AAIProperties.START_TX_ID, "JUNIT-U-1", + AAIProperties.END_SOT, "JUNIT-U-2", + AAIProperties.END_TX_ID, "JUNIT-U-2", + AAIProperties.START_TS, 13000L, + AAIProperties.END_TS, 15000L + ) + .property(AAIProperties.RESOURCE_VERSION, "15000", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U-2", + AAIProperties.START_TX_ID, "JUNIT-U-2", + AAIProperties.END_SOT, "JUNIT-U-3", + AAIProperties.END_TX_ID, "JUNIT-U-3", + AAIProperties.START_TS, 15000L, + AAIProperties.END_TS, 17000L + ) + .property(AAIProperties.RESOURCE_VERSION, "17000", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U-3", + AAIProperties.START_TX_ID, "JUNIT-U-3", + AAIProperties.END_SOT, "JUNIT-U-4", + AAIProperties.END_TX_ID, "JUNIT-U-4", + AAIProperties.START_TS, 17000L, + AAIProperties.END_TS, 20000L + ) + .property(AAIProperties.RESOURCE_VERSION, "20000", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U-4", + AAIProperties.START_TX_ID, "JUNIT-U-4", + AAIProperties.START_TS, 20000L + ) + .property("hostname", "test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 10000L + ) + .property("in-maint", true, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 10000L + ) + .property("equip-type", "second-ps-type", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U-1", + AAIProperties.END_TX_ID, "JUNIT-U-1", + AAIProperties.START_TS, 10000L, + AAIProperties.END_TS, 13000L + ) + .property("equip-type", "second-ps-type-recreated", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U-2", + AAIProperties.START_TX_ID, "JUNIT-U-2", + AAIProperties.END_SOT, "JUNIT-U-3", + AAIProperties.END_TX_ID, "JUNIT-U-3", + AAIProperties.START_TS, 15000L, + AAIProperties.END_TS, 17000L + ) + .property("equip-type", "second-ps-type-update", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U-3", + AAIProperties.START_TX_ID, "JUNIT-U-3", + AAIProperties.START_TS, 17000L, + AAIProperties.END_SOT, "JUNIT-U-4", + AAIProperties.END_TX_ID, "JUNIT-U-4", + AAIProperties.END_TS, 20000L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 10000L + ) + .property(AAIProperties.START_TS, 10000L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 10000L + ) + .next(); + } catch (Exception ex) { + success = false; + } finally { + if (success) { + transaction.commit(); + } else { + transaction.rollback(); + fail("Unable to setup the graph"); + } + } + } + + private JsonArray getResultsForPserverLookupByHostname(String endpoint) throws Exception { + return getResultsForPserverLookupByHostnameAndAnother(endpoint, ""); + } + + private JsonArray getResultsForPserverLookupByHostnameAndAnother(String endpoint, String additionalFilterInParen) throws Exception { + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver*('hostname','test-pserver-dsl')" + additionalFilterInParen); + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + JsonArray results = new JsonParser().parse(responseEntity.getBody().toString()).getAsJsonObject().getAsJsonArray("results"); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + + assertNotNull("Response from /aai/v14/dsl is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + return results; + } + + + private void verifyEquipTypeValues(JsonArray results, String... expectedEquipTypes) { + List<String> expected = Arrays.asList(expectedEquipTypes); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("value") && !property.getAsJsonObject().get("value").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("value").getAsString()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type in lifecycle", actualEquipType, is(expected)); + } + + private void verifyEquipTypeSoTs(JsonArray results, String... expectedSTOs) { + List<String> expected = Arrays.asList(expectedSTOs); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("sot") && !property.getAsJsonObject().get("sot").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("sot").getAsString()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type SoTs in lifecycle", actualEquipType, is(expected)); + } + + private void verifyEquipTypeTxId(JsonArray results, String... expectedSTOs) { + List<String> expected = Arrays.asList(expectedSTOs); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("tx-id") && !property.getAsJsonObject().get("tx-id").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("tx-id").getAsString()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type tx-ids in lifecycle", actualEquipType, is(expected)); + } + + private void verifyEquipTypeTimestamps(JsonArray results, Long... expectedSTOs) { + List<Long> expected = Arrays.asList(expectedSTOs); + final List<Long> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("timestamp") && !property.getAsJsonObject().get("timestamp").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("timestamp").getAsLong()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type timestamps in lifecycle", actualEquipType, is(expected)); + } + + private void verifyNodeTimestamps(JsonArray results, Long... nodeTimestamps) { + List<Long> expected = Arrays.asList(nodeTimestamps); + final List<Long> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + result.getAsJsonObject().get("node-actions").getAsJsonArray().forEach(jsonElement -> + actualEquipType.add(jsonElement.getAsJsonObject().get("timestamp").getAsLong())); + } + assertThat("Verify node-changes timestamps in lifecycle", actualEquipType, is(expected)); + } + + private void verifyNodeSot(JsonArray results, String... nodeSots) { + List<String> expected = Arrays.asList(nodeSots); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + result.getAsJsonObject().get("node-actions").getAsJsonArray().forEach(jsonElement -> + actualEquipType.add(jsonElement.getAsJsonObject().get("sot").getAsString())); + } + assertThat("Verify node-changes sot in lifecycle", actualEquipType, is(expected)); + } + + + @Test + public void lifecycleQueryNoStartOrEndTsTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type", "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L, 100L); + verifyNodeTimestamps(results, 10000L, 1000L, 100L); + + + String equipType = "first-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 500L, 100L); + verifyNodeTimestamps(results, 1000L, 100L); + + equipType = "second-ps-type-recreated"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L); + verifyNodeTimestamps(results, 10000L); + } + + + + @Test + public void lifecycleQueryStartTsBeforeCreationTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type", "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L, 100L); + verifyNodeTimestamps(results, 10000L, 1000L, 100L); + + + String equipType = "first-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 500L, 100L); + verifyNodeTimestamps(results, 1000L, 100L); + + equipType = "second-ps-type-recreated"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L); + verifyNodeTimestamps(results, 10000L); + } + + @Test + public void lifecycleQueryStartTsAtCreationTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=100"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type", "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L, 100L); + verifyNodeTimestamps(results, 10000L, 1000L, 100L); + } + + @Test + public void lifecycleQueryStartTsAfterCreationTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=300"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type", "first-ps-type-update"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L); + verifyNodeTimestamps(results, 10000L, 1000L); + } + + @Test + public void lifecycleQueryStartTsAtFirstUpdateTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=500"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type", "first-ps-type-update"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L); + verifyNodeTimestamps(results, 10000L, 1000L); + } + + @Test + public void lifecycleQueryStartTsAfterFirstUpdateTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=700"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L); + verifyNodeTimestamps(results, 10000L, 1000L); + } + + @Test + public void lifecycleQueryStartTsAtFirstDeleteTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=1000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L); + verifyNodeTimestamps(results, 10000L, 1000L); + } + + @Test + public void lifecycleQueryStartTsAfterFirstDeleteTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=5000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L); + verifyNodeTimestamps(results, 10000L); + } + + @Test + public void lifecycleQueryStartTsAtSecondCreateTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=10000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L); + verifyNodeTimestamps(results, 10000L); + } + + @Test + public void lifecycleQueryStartTsAfterSecondCreateTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=12000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L); + verifyNodeTimestamps(results); + } + + @Test + public void lifecycleQueryStartTsAtEquipTypeFirstDeleteOnSecondPsTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=13000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L); + verifyNodeTimestamps(results); + } + + @Test + public void lifecycleQueryStartTsAfterEquipTypeFirstDeleteOnSecondPsTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=14000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L); + verifyNodeTimestamps(results); + } + + @Test + public void lifecycleQueryStartTsAtEquipTypeRecreateOnSecondPsTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=15000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L); + verifyNodeTimestamps(results); + } + + @Test + public void lifecycleQueryStartTsAfterEquipTypeRecreateOnSecondPsTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=16000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3"); + verifyEquipTypeTimestamps(results, 20000L, 17000L); + verifyNodeTimestamps(results); + } + + @Test + public void lifecycleQueryStartTsAtEquipTypeUpdateOnSecondPsTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=17000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3"); + verifyEquipTypeTimestamps(results, 20000L, 17000L); + verifyNodeTimestamps(results); + } + + @Test + public void lifecycleQueryStartTsAfterEquipTypeUpdateOnSecondPsTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=19000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, new String[] {null}); + verifyEquipTypeSoTs(results, "JUNIT-U-4"); + verifyEquipTypeTxId(results, "JUNIT-U-4"); + verifyEquipTypeTimestamps(results, 20000L); + verifyNodeTimestamps(results); + } + + @Test + public void lifecycleQueryStartTsOnEquipTypeSecondDeleteOnSecondPsTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=20000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, new String[] {null}); + verifyEquipTypeSoTs(results, "JUNIT-U-4"); + verifyEquipTypeTxId(results, "JUNIT-U-4"); + verifyEquipTypeTimestamps(results, 20000L); + verifyNodeTimestamps(results); + } + + @Test + public void lifecycleQueryStartTsAfterEquipTypeSecondDeleteOnSecondPsTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=22000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 0, results.size()); + + verifyEquipTypeValues(results); + verifyEquipTypeSoTs(results); + verifyEquipTypeTxId(results); + verifyEquipTypeTimestamps(results); + verifyNodeTimestamps(results); + } + + @Test + public void lifecycleQueryStartTsBeforeCreationEndTimeAfterEquipTypeSecondDeleteOnSecondPsTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50&endTs=22000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type", "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L, 100L); + verifyNodeTimestamps(results, 10000L, 1000L, 100L); + } + + @Test + public void lifecycleQueryStartTsBeforeCreationEndTimeAtEquipTypeSecondDeleteOnSecondPsTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50&endTs=20000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, null, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type", "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-4", "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 20000L, 17000L, 15000L, 13000L, 10000L, 500L, 100L); + verifyNodeTimestamps(results, 10000L, 1000L, 100L); + } + + @Test + public void lifecycleQueryStartTsBeforeCreationEndTimeBeforeEquipTypeSecondDeleteOnSecondPsTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50&endTs=19000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "second-ps-type-update", "second-ps-type-recreated", null, "second-ps-type", "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U-3", "JUNIT-U-2", "JUNIT-U-1", "JUNIT-C", "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 17000L, 15000L, 13000L, 10000L, 500L, 100L); + verifyNodeTimestamps(results, 10000L, 1000L, 100L); + } + + @Test + public void lifecycleQueryStartTsBeforeCreationEndTimeBeforeSecondPsCreateTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50&endTs=9000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 500L, 100L); + verifyNodeTimestamps(results, 1000L, 100L); + } + + @Test + public void verifyNodeActionsWithNoTimeRangeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + verifyNodeTimestamps(results, 10000L, 1000L, 100L); + verifyNodeSot(results, "JUNIT-C", "JUNIT-D", "JUNIT-C"); + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryLifecycleSingleNodeTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryLifecycleSingleNodeTest.java new file mode 100644 index 0000000..e59573d --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryLifecycleSingleNodeTest.java @@ -0,0 +1,467 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.history; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.janusgraph.core.JanusGraphTransaction; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.aai.PayloadUtil; +import org.onap.aai.db.props.AAIProperties; +import org.onap.aai.dbmap.AAIGraph; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.*; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +@Ignore("The lifecycle format requires the history schema to be loaded. " + + "Because aaigraph is a singleton its very complicated to have 2 different schemas loaded for testing. " + + "This needs to be addressed.") +public class DslConsumerHistoryLifecycleSingleNodeTest extends AbstractSpringHistoryRestTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(DslConsumerHistoryLifecycleSingleNodeTest.class); + + @Override + public void createTestGraph() { + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + boolean success = true; + try { + GraphTraversalSource g = transaction.traversal(); + /* + Pserver + - created pserver @ time 100 + - equip-type = first-ps-type + - update equip-type @ 500 + - equip-type = first-ps-type-update + - deleted pserver @ time 1000 + */ + g.addV().property(AAIProperties.NODE_TYPE, "pserver", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.RESOURCE_VERSION, "100", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U", + AAIProperties.END_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 500L + ) + .property(AAIProperties.RESOURCE_VERSION, "500", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U", + AAIProperties.START_TX_ID, "JUNIT-U", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 500L, + AAIProperties.END_TS, 1000L + ) + .property("hostname", "test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property("in-maint", false, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property("equip-type", "first-ps-type", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U", + AAIProperties.END_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 500L + ) + .property("equip-type", "first-ps-type-update", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U", + AAIProperties.START_TX_ID, "JUNIT-U", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 500L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-D", + AAIProperties.START_TX_ID, "JUNIT-D", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.START_TS, 100L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.END_TS, 1000L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-D", + AAIProperties.START_TX_ID, "JUNIT-D", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 1000L, + AAIProperties.END_TS, 1000L + ) + .next(); + + } catch (Exception ex) { + success = false; + } finally { + if (success) { + transaction.commit(); + } else { + transaction.rollback(); + fail("Unable to setup the graph"); + } + } + } + + private JsonArray getResultsForPserverLookupByHostname(String endpoint) throws Exception { + return getResultsForPserverLookupByHostnameAndAnother(endpoint, ""); + } + + private JsonArray getResultsForPserverLookupByHostnameAndAnother(String endpoint, String additionalFilterInParen) throws Exception { + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver*('hostname','test-pserver-dsl')" + additionalFilterInParen); + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + JsonArray results = new JsonParser().parse(responseEntity.getBody().toString()).getAsJsonObject().getAsJsonArray("results"); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + + assertNotNull("Response from /aai/v14/dsl is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + return results; + } + + + private void verifyEquipTypeValues(JsonArray results, String... expectedEquipTypes) { + List<String> expected = Arrays.asList(expectedEquipTypes); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("value") && !property.getAsJsonObject().get("value").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("value").getAsString()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type in lifecycle", actualEquipType, is(expected)); + } + + private void verifyEquipTypeSoTs(JsonArray results, String... expectedSTOs) { + List<String> expected = Arrays.asList(expectedSTOs); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("sot") && !property.getAsJsonObject().get("sot").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("sot").getAsString()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type SoTs in lifecycle", actualEquipType, is(expected)); + } + + private void verifyEquipTypeTxId(JsonArray results, String... expectedSTOs) { + List<String> expected = Arrays.asList(expectedSTOs); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("tx-id") && !property.getAsJsonObject().get("tx-id").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("tx-id").getAsString()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type tx-ids in lifecycle", actualEquipType, is(expected)); + } + + private void verifyEquipTypeTimestamps(JsonArray results, Long... expectedSTOs) { + List<Long> expected = Arrays.asList(expectedSTOs); + final List<Long> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("timestamp") && !property.getAsJsonObject().get("timestamp").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("timestamp").getAsLong()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type timestamps in lifecycle", actualEquipType, is(expected)); + } + + private void verifyNodeTimestamps(JsonArray results, Long... nodeTimestamps) { + List<Long> expected = Arrays.asList(nodeTimestamps); + final List<Long> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + result.getAsJsonObject().get("node-actions").getAsJsonArray().forEach(jsonElement -> + actualEquipType.add(jsonElement.getAsJsonObject().get("timestamp").getAsLong())); + } + assertThat("Verify node-changes timestamps in lifecycle", actualEquipType, is(expected)); + } + + + @Test + public void lifecycleQueryNoStartOrEndTsTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 500L, 100L); + verifyNodeTimestamps(results, 1000L, 100L); + + + String equipType = "first-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 500L, 100L); + verifyNodeTimestamps(results, 1000L, 100L); + + equipType = "other-ps-type-recreated"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + } + + + + @Test + public void lifecycleQueryStartTsBeforeCreationTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=50"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 500L, 100L); + verifyNodeTimestamps(results, 1000L, 100L); + + + String equipType = "first-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 500L, 100L); + verifyNodeTimestamps(results, 1000L, 100L); + + equipType = "other-ps-type-recreated"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + } + + @Test + public void lifecycleQueryStartTsAtCreationTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=100"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 500L, 100L); + verifyNodeTimestamps(results, 1000L, 100L); + + + String equipType = "first-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + verifyEquipTypeValues(results, "first-ps-type-update", "first-ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTxId(results, "JUNIT-U", "JUNIT-C"); + verifyEquipTypeTimestamps(results, 500L, 100L); + verifyNodeTimestamps(results, 1000L, 100L); + + equipType = "other-ps-type-recreated"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + } + + @Test + public void lifecycleQueryStartTsAfterCreationTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=300"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "first-ps-type-update"); + verifyEquipTypeSoTs(results, "JUNIT-U"); + verifyEquipTypeTxId(results, "JUNIT-U"); + verifyEquipTypeTimestamps(results, 500L); + verifyNodeTimestamps(results, 1000L); + + + String equipType = "first-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + verifyEquipTypeValues(results, "first-ps-type-update"); + verifyEquipTypeSoTs(results, "JUNIT-U"); + verifyEquipTypeTxId(results, "JUNIT-U"); + verifyEquipTypeTimestamps(results, 500L); + verifyNodeTimestamps(results, 1000L); + + equipType = "other-ps-type-recreated"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + } + + @Test + public void lifecycleQueryStartTsAtUpdateTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=500"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "first-ps-type-update"); + verifyEquipTypeSoTs(results, "JUNIT-U"); + verifyEquipTypeTxId(results, "JUNIT-U"); + verifyEquipTypeTimestamps(results, 500L); + verifyNodeTimestamps(results, 1000L); + + + String equipType = "first-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + verifyEquipTypeValues(results, "first-ps-type-update"); + verifyEquipTypeSoTs(results, "JUNIT-U"); + verifyEquipTypeTxId(results, "JUNIT-U"); + verifyEquipTypeTimestamps(results, 500L); + verifyNodeTimestamps(results, 1000L); + + equipType = "other-ps-type-recreated"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + } + + @Test + public void lifecycleQueryStartTsAfterUpdateTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=700"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results); + verifyEquipTypeSoTs(results); + verifyEquipTypeTxId(results); + verifyEquipTypeTimestamps(results); + verifyNodeTimestamps(results, 1000L); + + + String equipType = "first-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "other-ps-type-recreated"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + } + + @Test + public void lifecycleQueryStartTsAtDeleteTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=1000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + assertEquals("properties size should be 0", results.get(0).getAsJsonObject().get("properties").getAsJsonArray().size(), 0); + + String equipType = "first-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + } + + @Test + public void lifecycleQueryStartTsAfterDeleteTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=lifecycle&startTs=5000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 0, results.size()); + + String equipType = "first-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "other-ps-type-recreated"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryStateEdgeTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryStateEdgeTest.java new file mode 100644 index 0000000..4e122dc --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryStateEdgeTest.java @@ -0,0 +1,476 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.history; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.janusgraph.core.JanusGraphTransaction; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.aai.PayloadUtil; +import org.onap.aai.db.props.AAIProperties; +import org.onap.aai.dbmap.AAIGraph; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.*; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +@Ignore("The state format requires the history schema to be loaded. " + + "Because aaigraph is a singleton its very complicated to have 2 different schemas loaded for testing. " + + "This needs to be addressed.") +public class DslConsumerHistoryStateEdgeTest extends AbstractSpringHistoryRestTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(DslConsumerHistoryStateEdgeTest.class); + + @Override + public void createTestGraph() { + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + boolean success = true; + try { + GraphTraversalSource g = transaction.traversal(); + + Vertex pserver = g.addV().property(AAIProperties.NODE_TYPE, "pserver", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.RESOURCE_VERSION, "100", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("hostname", "test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("in-maint", false, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("equip-type", "ps-type", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.START_TS, 100L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .next(); + Vertex complex = g.addV().property(AAIProperties.NODE_TYPE, "complex", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/complexes/complex/test-complex-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.RESOURCE_VERSION, "100", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("physical-location-id", "test-complex-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("street", "200 S. Laurel Ave", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("city", "Middletown", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("state", "NJ", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property("zip", "11111", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .property(AAIProperties.START_TS, 100L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 100L + ) + .next(); + + pserver.addEdge("org.onap.relationships.inventory.LocatedIn", + complex, + "start-ts", 100, + "private", false, + "aai-uuid", "edge1", + "end-source-of-truth", "JUNIT-E-D-1", + "end-tx-id", "JUNIT-E-D-1", + "end-ts", 300, + "prevent-delete", "IN", + "delete-other-v", "NONE", + "source-of-truth", "JUNIT-E-C-1", + "start-tx-id", "JUNIT-E-C-1", + "contains-other-v", "NONE" + ); + pserver.addEdge("org.onap.relationships.inventory.LocatedIn", + complex, + "start-ts", 500, + "private", false, + "aai-uuid", "edge2", + "end-source-of-truth", "JUNIT-E-D-2", + "end-tx-id", "JUNIT-E-D-2", + "end-ts", 700, + "prevent-delete", "IN", + "delete-other-v", "NONE", + "source-of-truth", "JUNIT-E-C-2", + "start-tx-id", "JUNIT-E-C-2", + "contains-other-v", "NONE" + ); + pserver.addEdge("org.onap.relationships.inventory.LocatedIn", + complex, + "start-ts", 900, + "private", false, + "aai-uuid", "edge3", + "end-source-of-truth", "JUNIT-E-D-3", + "end-tx-id", "JUNIT-E-D-3", + "end-ts", 1100, + "prevent-delete", "IN", + "delete-other-v", "NONE", + "source-of-truth", "JUNIT-E-C-3", + "start-tx-id", "JUNIT-E-C-3", + "contains-other-v", "NONE" + ); + pserver.addEdge("org.onap.relationships.inventory.LocatedIn", + complex, + "start-ts", 1300, + "private", false, + "aai-uuid", "edge3", + "prevent-delete", "IN", + "delete-other-v", "NONE", + "source-of-truth", "JUNIT-E-C-3", + "start-tx-id", "JUNIT-E-C-3", + "contains-other-v", "NONE" + ); + } catch (Exception ex) { + success = false; + } finally { + if (success) { + transaction.commit(); + } else { + transaction.rollback(); + fail("Unable to setup the graph"); + } + } + } + + private JsonArray getResultsForPserverLookupByHostname(String endpoint) throws Exception { + return getResultsForPserverLookupByHostnameAndAnother(endpoint, ""); + } + + private JsonArray getResultsForPserverLookupByHostnameAndAnother(String endpoint, String additionalFilterInParen) throws Exception { + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver*('hostname','test-pserver-dsl')" + additionalFilterInParen); + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + JsonArray results = new JsonParser().parse(responseEntity.getBody().toString()).getAsJsonObject().getAsJsonArray("results"); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + + assertNotNull("Response from /aai/v14/dsl is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + return results; + } + + + private void verifyEquipTypeValues(JsonArray results, String... expectedEquipTypes) { + List<String> expected = Arrays.asList(expectedEquipTypes); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + assertFalse("State format properties should not have end timestamps", + property.getAsJsonObject().has("end-timestamp")); + if (property.getAsJsonObject().has("value") && !property.getAsJsonObject().get("value").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("value").getAsString()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type in state", actualEquipType, is(expected)); + } + + private void verifyEquipTypeSoTs(JsonArray results, String... expectedSTOs) { + List<String> expected = Arrays.asList(expectedSTOs); + final List<String> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("sot") && !property.getAsJsonObject().get("sot").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("sot").getAsString()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type SoTs in state", actualEquipType, is(expected)); + } + + private void verifyEquipTypeTimestamps(JsonArray results, Long... expectedSTOs) { + List<Long> expected = Arrays.asList(expectedSTOs); + final List<Long> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + if (property.getAsJsonObject().has("timestamp") && !property.getAsJsonObject().get("timestamp").isJsonNull()) { + actualEquipType.add(property.getAsJsonObject().get("timestamp").getAsLong()); + } else { + actualEquipType.add(null); + } + } + } + } + assertThat("Verify equip-type timestamps in state", actualEquipType, is(expected)); + } + + private void verifyRelatedToCreatedTimestamps(JsonArray results, Long... edgeCreatedTimestamps) { + List<Long> expected = Arrays.asList(edgeCreatedTimestamps); + final List<Long> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + result.getAsJsonObject().get("related-to").getAsJsonArray().forEach(jsonElement -> + actualEquipType.add(jsonElement.getAsJsonObject().get("timestamp").getAsLong())); + } + assertThat("Verify related-to createdtimestamps in state", actualEquipType, is(expected)); + } + + private void verifyRelatedToCreatedDeletedTimestamps(JsonArray results, Long... edgeDeletedTimestamps) { + List<Long> expected = Arrays.asList(edgeDeletedTimestamps); + final List<Long> actualEquipType = new ArrayList<>(); + for (JsonElement result : results) { + result.getAsJsonObject().get("related-to").getAsJsonArray().forEach(jsonElement -> { + if (jsonElement.getAsJsonObject().has("end-timestamp")) { + actualEquipType.add(jsonElement.getAsJsonObject().get("end-timestamp").getAsLong()); + } + }); + } + assertThat("Verify related-to created timestamps in state", actualEquipType, is(expected)); + } + + private void verifyRelatedToCount(JsonArray results, int expectedSize) { + int actualSize = 0; + for (JsonElement result : results) { + actualSize += result.getAsJsonObject().get("related-to").getAsJsonArray().size(); + } + assertEquals("Verify related-to count", actualSize, expectedSize); + } + + private void verifyAllPropsTxIds(JsonArray results) { + final Set<String> propMissingCreatedTxId = new HashSet<>(); + final Set<String> propContainingEndTxId = new HashSet<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (!property.getAsJsonObject().has("tx-id")) { + propMissingCreatedTxId.add(property.getAsJsonObject().get("key").getAsString()); + } + if (property.getAsJsonObject().has("end-tx-id")) { + propContainingEndTxId.add(property.getAsJsonObject().get("key").getAsString()); + } + } + } + + assertThat("Verify no prop is missing tx-id in state", propMissingCreatedTxId, is(Collections.EMPTY_SET)); + assertThat("Verify no prop has end-tx-id in state", propContainingEndTxId, is(Collections.EMPTY_SET)); + } + + private void verifyRelatedToCreatedTxId(JsonArray results) { + final Set<JsonObject> edgeMissingCreatedTxId = new HashSet<>(); + final Set<JsonObject> edgeContainingEndTxId = new HashSet<>(); + for (JsonElement result : results) { + result.getAsJsonObject().get("related-to").getAsJsonArray().forEach(jsonElement -> { + if (!jsonElement.getAsJsonObject().has("tx-id")) { + edgeMissingCreatedTxId.add(jsonElement.getAsJsonObject()); + } + if (jsonElement.getAsJsonObject().has("end-tx-id")) { + edgeContainingEndTxId.add(jsonElement.getAsJsonObject()); + } + }); + } + assertThat("Verify no related-to is missing tx-id in state", edgeMissingCreatedTxId, is(Collections.EMPTY_SET)); + assertThat("Verify no related-to has end-tx-id in state", edgeContainingEndTxId, is(Collections.EMPTY_SET)); + } + + @Test + public void stateQueryStartTsBeforeCreationTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=50"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 0, results.size()); + + verifyEquipTypeValues(results); + verifyEquipTypeSoTs(results); + verifyEquipTypeTimestamps(results); + verifyRelatedToCreatedTimestamps(results); + verifyRelatedToCreatedDeletedTimestamps(results); + verifyRelatedToCount(results, 0); + verifyAllPropsTxIds(results); + verifyRelatedToCreatedTxId(results); + } + + + + @Test + public void stateQueryStartTsBeforeSecondEdgeCreationTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=400"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-C"); + verifyEquipTypeTimestamps(results, 100L); + verifyRelatedToCreatedTimestamps(results); + verifyRelatedToCreatedDeletedTimestamps(results); + verifyRelatedToCount(results, 0); + verifyAllPropsTxIds(results); + verifyRelatedToCreatedTxId(results); + } + + @Test + public void stateQueryStartTsAfterSecondEdgeCreationTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=600"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-C"); + verifyEquipTypeTimestamps(results, 100L); + verifyRelatedToCreatedTimestamps(results, 500L); + verifyRelatedToCreatedDeletedTimestamps(results); + verifyRelatedToCount(results, 1); + verifyAllPropsTxIds(results); + verifyRelatedToCreatedTxId(results); + } + + @Test + public void stateQueryStartTsAtSecondEdgeDeletionTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=700"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-C"); + verifyEquipTypeTimestamps(results, 100L); + verifyRelatedToCreatedTimestamps(results); + verifyRelatedToCreatedDeletedTimestamps(results); + verifyRelatedToCount(results, 0); + verifyAllPropsTxIds(results); + verifyRelatedToCreatedTxId(results); + } + + @Test + public void stateQueryStartTsAfterSecondEdgeDeletionTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=800"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-C"); + verifyEquipTypeTimestamps(results, 100L); + verifyRelatedToCreatedTimestamps(results); + verifyRelatedToCreatedDeletedTimestamps(results); + verifyRelatedToCount(results, 0); + verifyAllPropsTxIds(results); + verifyRelatedToCreatedTxId(results); + } + + @Test + public void stateQueryStartTsAtLastEdgeActionTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=1300"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-C"); + verifyEquipTypeTimestamps(results, 100L); + verifyRelatedToCreatedTimestamps(results, 1300L); + verifyRelatedToCreatedDeletedTimestamps(results); + verifyRelatedToCount(results, 1); + verifyAllPropsTxIds(results); + verifyRelatedToCreatedTxId(results); + } + + @Test + public void stateQueryStartTsAfterLastEdgeActionTimeTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=1400"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals("Result size", 1, results.size()); + + verifyEquipTypeValues(results, "ps-type"); + verifyEquipTypeSoTs(results, "JUNIT-C"); + verifyEquipTypeTimestamps(results, 100L); + verifyRelatedToCreatedTimestamps(results, 1300L); + verifyRelatedToCreatedDeletedTimestamps(results); + verifyRelatedToCount(results, 1); + verifyAllPropsTxIds(results); + verifyRelatedToCreatedTxId(results); + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryStateTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryStateTest.java new file mode 100644 index 0000000..bb9584e --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/history/DslConsumerHistoryStateTest.java @@ -0,0 +1,770 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.history; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.janusgraph.core.JanusGraphTransaction; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.aai.PayloadUtil; +import org.onap.aai.db.props.AAIProperties; +import org.onap.aai.dbmap.AAIGraph; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.*; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +@Ignore("The state format requires the history schema to be loaded. " + + "Because aaigraph is a singleton its very complicated to have 2 different schemas loaded for testing. " + + "This needs to be addressed.") +public class DslConsumerHistoryStateTest extends AbstractSpringHistoryRestTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(DslConsumerHistoryStateTest.class); + + @Override + public void createTestGraph() { + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + boolean success = true; + try { + GraphTraversalSource g = transaction.traversal(); + /* + Pserver + - created @ time 100 + - update in-maint/equip-type @ 500 + - deleted @ time 1000 + */ + g.addV().property(AAIProperties.NODE_TYPE, "pserver", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.RESOURCE_VERSION, "100", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U", + AAIProperties.END_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 500L + ) + .property(AAIProperties.RESOURCE_VERSION, "500", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U", + AAIProperties.START_TX_ID, "JUNIT-U", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 500L, + AAIProperties.END_TS, 1000L + ) + .property("hostname", "test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property("in-maint", false, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U", + AAIProperties.END_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 500L + ) + .property("in-maint", true, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U", + AAIProperties.START_TX_ID, "JUNIT-U", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 500L, + AAIProperties.END_TS, 1000L + ) + .property("equip-type", "first-ps-type", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U", + AAIProperties.END_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 500L + ) + .property("equip-type", "first-ps-type-update", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U", + AAIProperties.START_TX_ID, "JUNIT-U", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 500L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-D", + AAIProperties.START_TX_ID, "JUNIT-D", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.START_TS, 100L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 100L, + AAIProperties.END_TS, 1000L + ) + .property(AAIProperties.END_TS, 1000L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-D", + AAIProperties.START_TX_ID, "JUNIT-D", + AAIProperties.END_SOT, "JUNIT-D", + AAIProperties.END_TX_ID, "JUNIT-D", + AAIProperties.START_TS, 1000L, + AAIProperties.END_TS, 1000L + ) + .next(); + + /* + Pserver + - created @ time 10000 + - update in-maint/equip-type @ 15000 + */ + g.addV().property(AAIProperties.NODE_TYPE, "pserver", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 10000L + ) + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 10000L + ) + .property(AAIProperties.RESOURCE_VERSION, "10000", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U", + AAIProperties.END_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 10000L, + AAIProperties.END_TS, 15000L + ) + .property(AAIProperties.RESOURCE_VERSION, "15000", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U", + AAIProperties.START_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 15000 + ) + .property("hostname", "test-pserver-dsl", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 10000L + ) + .property("in-maint", true, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U", + AAIProperties.END_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 10000L, + AAIProperties.END_TS, 15000L + ) + .property("in-maint", false, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U", + AAIProperties.START_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 15000L + ) + .property("equip-type", "second-ps-type", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.END_SOT, "JUNIT-U", + AAIProperties.END_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 10000L, + AAIProperties.END_TS, 15000L + ) + .property("equip-type", "second-ps-type-update", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-U", + AAIProperties.START_TX_ID, "JUNIT-U", + AAIProperties.START_TS, 15000L + ) + .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 10000L + ) + .property(AAIProperties.START_TS, 10000L, + AAIProperties.SOURCE_OF_TRUTH, "JUNIT-C", + AAIProperties.START_TX_ID, "JUNIT-C", + AAIProperties.START_TS, 10000L + ) + .next(); + } catch (Exception ex) { + success = false; + } finally { + if (success) { + transaction.commit(); + } else { + transaction.rollback(); + fail("Unable to setup the graph"); + } + } + } + + private JsonArray getResultsForPserverLookupByHostname(String endpoint) throws Exception { + return getResultsForPserverLookupByHostnameAndAnother(endpoint, ""); + } + + private JsonArray getResultsForPserverLookupByHostnameAndAnother(String endpoint, String additionalFilterInParen) throws Exception { + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver*('hostname','test-pserver-dsl')" + additionalFilterInParen); + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + JsonArray results = new JsonParser().parse(responseEntity.getBody().toString()).getAsJsonObject().getAsJsonArray("results"); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + + assertNotNull("Response from /aai/v14/dsl is not null", responseEntity); + assertEquals("Expected the response to be 200", HttpStatus.OK, responseEntity.getStatusCode()); + return results; + } + + private void verifyEquipTypeValues(JsonArray results, String... equipType) { + Set<String> expectedEquipTypes = new HashSet<>(Arrays.asList(equipType)); + final Set<String> actualEquipType = new HashSet<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + assertFalse("State format properties should not have end timestamps", + property.getAsJsonObject().has("end-timestamp")); + if (property.getAsJsonObject().get("key").getAsString().equals("equip-type")) { + actualEquipType.add(property.getAsJsonObject().get("value").getAsString()); + } + } + } + assertThat("Verify equip-type in state", actualEquipType, is(expectedEquipTypes)); + } + + + private void verifyAllPropsTxIds(JsonArray results) { + final Set<String> propMissingCreatedTxId = new HashSet<>(); + final Set<String> propContainingEndTxId = new HashSet<>(); + for (JsonElement result : results) { + for (JsonElement property : result.getAsJsonObject().get("properties").getAsJsonArray()) { + if (!property.getAsJsonObject().has("tx-id")) { + propMissingCreatedTxId.add(property.getAsJsonObject().get("key").getAsString()); + } + if (property.getAsJsonObject().has("end-tx-id")) { + propContainingEndTxId.add(property.getAsJsonObject().get("key").getAsString()); + } + } + } + + assertThat("Verify no prop is missing tx-id in state", propMissingCreatedTxId, is(Collections.EMPTY_SET)); + assertThat("Verify no prop has end-tx-id in state", propContainingEndTxId, is(Collections.EMPTY_SET)); + } + + @Test + public void stateQueryBeforeCreationTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=50"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(0, results.size()); + } + + @Test + public void stateQueryAtCreationTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=100"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "first-ps-type"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryAfterCreationTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=200"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "first-ps-type"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryAtUpdateTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=500"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "first-ps-type-update"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryAfterUpdateTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=700"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "first-ps-type-update"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryAtDeletionTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=1000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(0, results.size()); + } + + @Test + public void stateQueryAfterDeletionTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=2000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(0, results.size()); + } + + // WITH endTs=startTs + @Test + public void stateQueryBeforeCreationWithEndTsTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=50&endTs=50"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(0, results.size()); + } + + @Test + public void stateQueryAtCreationTimeWithEndTsTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=100&endTs=100"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "first-ps-type"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryAfterCreationTimeWithEndTsTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=200&endTs=200"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "first-ps-type"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryAtUpdateTimeWithEndTsTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=500&endTs=500"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "first-ps-type-update"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryAfterUpdateTimeWithEndTsTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=700&endTs=700"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "first-ps-type-update"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryAtDeletionTimeWithEndTsTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=1000&endTs=1000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(0, results.size()); + } + + @Test + public void stateQueryAfterDeletionTimeWithEndTsTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=2000&endTs=2000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(0, results.size()); + } + + // Second pserver + + @Test + public void stateQueryBeforeSecondCreationTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=9000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(0, results.size()); + } + + @Test + public void stateQueryAtSecondCreationTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=10000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "second-ps-type"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryAfterSecondCreationTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=12000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "second-ps-type"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryAtUpdateAfterSecondCreationTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=15000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "second-ps-type-update"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryAfterUpdateAfterSecondCreationTimeTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state&startTs=17000"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "second-ps-type-update"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryNoTimestampTest() throws Exception { + String endpoint = "/aai/v14/dsl?format=state"; + JsonArray results = getResultsForPserverLookupByHostname(endpoint); + assertEquals(1, results.size()); + verifyEquipTypeValues(results, "second-ps-type-update"); + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryNoTimestampWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + + verifyEquipTypeValues(results, equipType); + + verifyAllPropsTxIds(results); + } + + @Test + public void stateQueryTimestampBeforeFirstCreateWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=50"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + } + + @Test + public void stateQueryTimestampAtFirstCreateWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=100"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + + verifyEquipTypeValues(results, equipType); + + verifyAllPropsTxIds(results); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + } + + @Test + public void stateQueryTimestampAfterFirstCreateWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=200"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + + verifyEquipTypeValues(results, equipType); + + verifyAllPropsTxIds(results); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + } + + @Test + public void stateQueryTimestampAtFirstUpdateWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=500"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + + verifyEquipTypeValues(results, equipType); + + verifyAllPropsTxIds(results); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + } + + @Test + public void stateQueryTimestampAfterFirstUpdateWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=700"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + + verifyEquipTypeValues(results, equipType); + + verifyAllPropsTxIds(results); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + } + + @Test + public void stateQueryTimestampAtFirstDeleteWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=1000"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + } + + @Test + public void stateQueryTimestampAfterFirstDeleteWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=5000"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + } + + @Test + public void stateQueryTimestampAtSecondCreateWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=10000"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + + verifyEquipTypeValues(results, equipType); + + verifyAllPropsTxIds(results); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + } + + @Test + public void stateQueryTimestampAfterSecondCreateWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=12000"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + + verifyEquipTypeValues(results, equipType); + + verifyAllPropsTxIds(results); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + } + + @Test + public void stateQueryTimestampAtSecondUpdateWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=15000"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + + verifyEquipTypeValues(results, equipType); + + verifyAllPropsTxIds(results); + + } + + @Test + public void stateQueryTimestampAfterSecondUpdateWithEquipTypeFilterTest() throws Exception { + + String endpoint = "/aai/v14/dsl?format=state&startTs=15000"; + String equipType = "first-ps-type"; + JsonArray results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "first-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 0, results.size()); + + equipType = "second-ps-type-update"; + results = getResultsForPserverLookupByHostnameAndAnother(endpoint, "('equip-type','" + equipType + "')"); + assertEquals("Filter equip-type on " + equipType, 1, results.size()); + + verifyEquipTypeValues(results, equipType); + + verifyAllPropsTxIds(results); + + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/retired/RetiredConsumerSpringTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/retired/RetiredConsumerSpringTest.java index 6664465..46e4a35 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/retired/RetiredConsumerSpringTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/retired/RetiredConsumerSpringTest.java @@ -19,7 +19,8 @@ */ package org.onap.aai.rest.retired; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.junit.Test; import org.onap.aai.rest.AbstractSpringRestTest; @@ -34,7 +35,7 @@ import static org.junit.Assert.assertEquals; public class RetiredConsumerSpringTest extends AbstractSpringRestTest { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(RetiredConsumerSpringTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(RetiredConsumerSpringTest.class); private Map<String, HttpStatus> httpStatusMap; diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/ClosedLoopQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/ClosedLoopQueryTest.java new file mode 100644 index 0000000..821836a --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/ClosedLoopQueryTest.java @@ -0,0 +1,103 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class ClosedLoopQueryTest extends QueryTest { + public ClosedLoopQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "1", "aai-node-type", "vserver", "vserver-id", "vserver-id-1","vserver-name","vserver-name-1"); + Vertex gnvf = graph.addVertex(T.label, "generic-vnf", T.id, "2", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1"); + + Vertex serviceInstance = graph.addVertex(T.label, "service-instance", T.id, "3", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1"); + Vertex vfModule = graph.addVertex(T.label, "vf-module", T.id, "4", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-1"); + + Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "5", "aai-node-type", "tenant", "tenant-id", "tenantid01", "tenant-name", "tenantName01"); + Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "6", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-1", "cloud-region-owner", "cloud-owner-name-1"); + + + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "7", "aai-node-type", "vserver", "vserver-id", "vserver-id-2","vserver-name","vserver-name-1"); + Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "8", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-2"); + + Vertex serviceInstance1 = graph.addVertex(T.label, "service-instance", T.id, "9", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-2"); + Vertex vfModule1 = graph.addVertex(T.label, "vf-module", T.id, "10", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-2"); + + Vertex tenant1 = graph.addVertex(T.label, "tenant", T.id, "11", "aai-node-type", "tenant", "tenant-id", "tenantid01", "tenant-name", "tenantName02"); + Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "12", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-2", "cloud-region-owner", "cloud-owner-name-1"); + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, vserver, gnvf); + rules.addEdge(g, gnvf, serviceInstance); + rules.addTreeEdge(g, gnvf, vfModule); + rules.addTreeEdge(g, vserver,tenant); + rules.addTreeEdge(g, tenant,cloudregion); + + //Not expected in result + rules.addEdge(g, vserver1, gnvf1); + rules.addEdge(g, gnvf1, serviceInstance1); + rules.addTreeEdge(g, gnvf1, vfModule1); + rules.addTreeEdge(g, vserver1,tenant1); + rules.addTreeEdge(g, tenant1,cloudregion1); + //Not expected in result + + expectedResult.add(vserver); + expectedResult.add(gnvf); + expectedResult.add(serviceInstance); + expectedResult.add(vfModule); + expectedResult.add(tenant); + expectedResult.add(cloudregion); + + } + + @Override + protected String getQueryName() { + return "closed-loop"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "vserver").has("vserver-id", "vserver-id-1"); + + } + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetServiceInstanceSummaryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetServiceInstanceSummaryTest.java new file mode 100644 index 0000000..1fba932 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetServiceInstanceSummaryTest.java @@ -0,0 +1,104 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; + +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class GetServiceInstanceSummaryTest extends QueryTest { + + public GetServiceInstanceSummaryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + @Test + public void run() { + super.run(); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //set up test graph + Vertex serviceinstance = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", "serviceinstanceid0"); + Vertex l3network = graph.addVertex(T.label, "l3-network", T.id, "2", "aai-node-type", "l3-network", "network-id", "networkid0"); + Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "3", "aai-node-type", "cloud-region", "cloud-region-id", "regionid0", "cloud-owner", "cloudOwnername0"); + Vertex servicesub = graph.addVertex(T.label, "service-subscription", T.id, "4", "aai-node-type", "service-subscription", "service-type", "servicetype0"); + Vertex customer = graph.addVertex(T.label, "customer", T.id, "5", "aai-node-type", "customer", "customer-id", "customerid0"); + Vertex genericvnf = graph.addVertex(T.label, "generic-vnf", T.id, "6", "aai-node-type", "generic-vnf", "vnf-id", "vnfid0"); + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "7", "aai-node-type", "vserver", "vserver-id", "vserverid0"); + Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "8", "aai-node-type", "tenant", "tenant-id", "tenantid0", "tenant-name", "tenantName0"); + Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "9", "aai-node-type", "cloud-region", "cloud-region-id", "regionid0", "cloud-owner", "cloudOwnername0"); + + Vertex serviceinstance1 = graph.addVertex(T.label, "service-instance", T.id, "10", "aai-node-type", "service-instance", "service-instance-id", "serviceinstanceid1"); + Vertex l3network1 = graph.addVertex(T.label, "l3-network", T.id, "11", "aai-node-type", "l3-network", "network-id", "networkid0"); + Vertex cloudregion2 = graph.addVertex(T.label, "cloud-region", T.id, "12", "aai-node-type", "cloud-region", "cloud-region-id", "regionid0", "cloud-owner", "cloudOwnername0"); + Vertex servicesub1 = graph.addVertex(T.label, "service-subscription", T.id, "13", "aai-node-type", "service-subscription", "service-type", "servicetype0"); + Vertex customer1 = graph.addVertex(T.label, "customer", T.id, "14", "aai-node-type", "customer", "customer-id", "customerid0"); + Vertex genericvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "15", "aai-node-type", "generic-vnf", "vnf-id", "vnfid0"); + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "16", "aai-node-type", "vserver", "vserver-id", "vserverid0"); + Vertex tenant1 = graph.addVertex(T.label, "tenant", T.id, "17", "aai-node-type", "tenant", "tenant-id", "tenantid0", "tenant-name", "tenantName0"); + Vertex cloudregion3 = graph.addVertex(T.label, "cloud-region", T.id, "18", "aai-node-type", "cloud-region", "cloud-region-id", "regionid0", "cloud-owner", "cloudOwnername0"); + GraphTraversalSource g = graph.traversal(); + + rules.addEdge(g, serviceinstance, l3network); + rules.addEdge(g, l3network, cloudregion); + rules.addTreeEdge(g, serviceinstance, servicesub); + rules.addTreeEdge(g, servicesub, customer); + rules.addEdge(g, serviceinstance, genericvnf); + rules.addEdge(g, genericvnf, vserver); + rules.addTreeEdge(g, vserver, tenant); + rules.addTreeEdge(g, tenant, cloudregion1); + + rules.addEdge(g, serviceinstance1, l3network1);//false + rules.addEdge(g, l3network1, cloudregion2);//false + rules.addTreeEdge(g, serviceinstance1, servicesub1);//false + rules.addTreeEdge(g, servicesub1, customer1);//false + rules.addEdge(g, serviceinstance1, genericvnf1);//false + rules.addEdge(g, genericvnf1, vserver1);//false + rules.addTreeEdge(g, vserver1, tenant1);//false + rules.addTreeEdge(g, tenant1, cloudregion3);//false + + expectedResult.add(serviceinstance); + expectedResult.add(cloudregion); + expectedResult.add(cloudregion1); + expectedResult.add(servicesub); + expectedResult.add(customer); + } + @Override + protected String getQueryName() { + return "getServiceInstanceSummary"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "service-instance").has("service-instance-id", "serviceinstanceid0"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetServiceInstanceVnfVfModuleModelsTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetServiceInstanceVnfVfModuleModelsTest.java new file mode 100644 index 0000000..64abbae --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetServiceInstanceVnfVfModuleModelsTest.java @@ -0,0 +1,111 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.search; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException; +import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +public class GetServiceInstanceVnfVfModuleModelsTest extends QueryTest { + + public GetServiceInstanceVnfVfModuleModelsTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + @Test + public void run() { + super.run(); + } + + + + @Override + protected void createGraph() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException { + + Vertex serviceInstance = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1"); + Vertex modelver = graph.addVertex(T.label, "model-ver", T.id, "2", "aai-node-type", "model-ver","model-ver-id", "model-ver-id-1"); + Vertex genericvnf = graph.addVertex(T.label, "generic-vnf", T.id, "3", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1"); + Vertex modelver1 = graph.addVertex(T.label, "model-ver", T.id, "4", "aai-node-type", "model-ver","model-ver-id", "model-ver-id-1"); + Vertex model = graph.addVertex(T.label, "model", T.id, "5", "aai-node-type", "model","model-id", "model-id-1"); + Vertex vfmodule = graph.addVertex(T.label, "vf-module", T.id, "6", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-1"); + Vertex modelver2 = graph.addVertex(T.label, "model-ver", T.id, "7", "aai-node-type", "model-ver","model-ver-id", "model-ver-id-2"); + Vertex model1 = graph.addVertex(T.label, "model", T.id, "8", "aai-node-type", "model","model-id", "model-id-2"); + + Vertex serviceInstance1 = graph.addVertex(T.label, "service-instance", T.id, "9", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-2", "service-instance-name", "service-instance-name-2"); + Vertex l3network = graph.addVertex(T.label, "l3-network", T.id, "10", "aai-node-type", "l3-network","l3-network-id", "l3-network-id-1"); + Vertex genericvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "11", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-2"); + Vertex complex = graph.addVertex(T.label, "complex", T.id, "12", "aai-node-type", "complex","complex-id", "complex-1"); + Vertex vfmodule1 = graph.addVertex(T.label, "vf-module", T.id, "13", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-2"); + Vertex l3network1 = graph.addVertex(T.label, "l3-network", T.id, "14", "aai-node-type", "l3-network","l3-network-id", "l3-network-id-2"); + + Vertex model2 = graph.addVertex(T.label, "model", T.id, "15", "aai-node-type", "model","model-id", "model-id-3"); + + + GraphTraversalSource g = graph.traversal(); + rules.addPrivateEdge(g, serviceInstance, modelver,null); + rules.addTreeEdge(g, modelver, model2); + rules.addEdge(g, serviceInstance, genericvnf); + rules.addPrivateEdge(g, genericvnf, modelver1,null); + rules.addTreeEdge(g, modelver1, model); + rules.addTreeEdge(g, genericvnf, vfmodule); + rules.addPrivateEdge(g, vfmodule, modelver2,null); + rules.addTreeEdge(g, modelver2, model1); + + rules.addEdge(g, serviceInstance1, l3network);//not expected in result + rules.addEdge(g, serviceInstance1, genericvnf1);//not expected in result + rules.addEdge(g, genericvnf1, complex);//not expected in result + rules.addTreeEdge(g, genericvnf1, vfmodule1);//not expected in result + rules.addEdge(g, vfmodule1, l3network1);//not expected in result + + + expectedResult.add(serviceInstance); + expectedResult.add(modelver); + expectedResult.add(model2); + expectedResult.add(genericvnf); + expectedResult.add(modelver1); + expectedResult.add(model); + expectedResult.add(vfmodule); + expectedResult.add(modelver2); + expectedResult.add(model1); + + + } + + + @Override + protected String getQueryName() { + return "getServiceInstanceVnfVfModuleModels"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "service-instance").has("service-instance-id", "service-instance-id-1"); + } + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetTenantInfoAtSvcInstanceQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetTenantInfoAtSvcInstanceQueryTest.java new file mode 100644 index 0000000..71e2f18 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetTenantInfoAtSvcInstanceQueryTest.java @@ -0,0 +1,101 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class GetTenantInfoAtSvcInstanceQueryTest extends QueryTest { + public GetTenantInfoAtSvcInstanceQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + Vertex serviceInstance = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1"); + Vertex gnvf = graph.addVertex(T.label, "generic-vnf", T.id, "2", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1"); + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vserver-id-1","vserver-name","vserver-name-1"); + Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "4", "aai-node-type", "tenant", "tenant-id", "tenantid01", "tenant-name", "tenantName01"); + Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "5", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-1", "cloud-region-owner", "cloud-owner-name-1"); + Vertex complex = graph.addVertex(T.label, "complex", T.id, "6", "aai-node-type", "complex", "complex-id", "complex-1"); + + Vertex serviceInstance1 = graph.addVertex(T.label, "service-instance", T.id, "7", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-2"); + Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "8", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-2"); + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "9", "aai-node-type", "vserver", "vserver-id", "vserver-id-2","vserver-name","vserver-name-2"); + Vertex tenant1 = graph.addVertex(T.label, "tenant", T.id, "10", "aai-node-type", "tenant", "tenant-id", "tenantid02", "tenant-name", "tenantName02"); + Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "11", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-2", "cloud-region-owner", "cloud-owner-name-2"); + Vertex complex1 = graph.addVertex(T.label, "complex", T.id, "12", "aai-node-type", "complex", "complex-id", "complex-2"); + + + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, serviceInstance, gnvf); + rules.addEdge(g, gnvf, vserver); + rules.addTreeEdge(g, vserver,tenant); + rules.addTreeEdge(g, tenant,cloudregion); + rules.addEdge(g, cloudregion, complex); + + //Not expected in result + rules.addEdge(g, serviceInstance1, gnvf1); + rules.addEdge(g, gnvf1, vserver1); + rules.addTreeEdge(g, vserver1,tenant1); + rules.addTreeEdge(g, tenant1,cloudregion1); + rules.addEdge(g, cloudregion1, complex1); + //Not expected in result + + expectedResult.add(serviceInstance); + expectedResult.add(gnvf); + expectedResult.add(vserver); + expectedResult.add(tenant); + expectedResult.add(cloudregion); + expectedResult.add(complex); + + + } + + @Override + protected String getQueryName() { + return "getTenantInfoAtSvcInstance"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "service-instance").has("service-instance-id", "service-instance-id-1"); + + } + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetTenantInfoAtSvcSubscriptionTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetTenantInfoAtSvcSubscriptionTest.java new file mode 100644 index 0000000..8ceab5e --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetTenantInfoAtSvcSubscriptionTest.java @@ -0,0 +1,89 @@ +package org.onap.aai.rest.search; +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ + +import java.util.Map; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + + +public class GetTenantInfoAtSvcSubscriptionTest extends QueryTest{ + + public GetTenantInfoAtSvcSubscriptionTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void test() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + Vertex servicesubscription = graph.addVertex(T.label, "service-subscription",T.id, "0", "aai-node-type", "service-subscription", "service-type", "service-type-0"); + Vertex tenant = graph.addVertex(T.label, "tenant",T.id, "1", "aai-node-type", "tenant", "tenant-id", "tenant-id-0", "tenant-name", "tenant-name-0"); + Vertex cloudregion = graph.addVertex(T.label, "cloud-region",T.id, "2", "aai-node-type", "cloud-region", "cloud-owner", "cloud-owner-0", "cloud-region-id", "cloud-region-id-0"); + Vertex complex = graph.addVertex(T.label, "complex",T.id, "3", "aai-node-type", "complex", "physical-location-id", "physical-location-id-0", "physical-location-type", + "physical-location-type-0", "street1", "street1-0", "city", "city-0", "postal-code", "postal-code-0", "country", "country-0", "region", "region-0"); + Vertex servicesubscription1 = graph.addVertex(T.label, "service-subscription",T.id, "5", "aai-node-type", "service-subscription", "service-type", "service-type-1"); + Vertex tenant1 = graph.addVertex(T.label, "tenant",T.id, "6", "aai-node-type", "tenant", "tenant-id", "tenant-id-1", "tenant-name", "tenant-name-1"); + Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region",T.id, "7", "aai-node-type", "cloud-region", "cloud-owner", "cloud-owner-1", "cloud-region-id", "cloud-region-id-1"); + Vertex complex1 = graph.addVertex(T.label, "complex",T.id, "8", "aai-node-type", "complex", "physical-location-id", "physical-location-id-1", "physical-location-type", + "physical-location-type-1", "street1", "street1-1", "city", "city-1", "postal-code", "postal-code-1", "country", "country-1", "region", "region-1"); + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, servicesubscription, tenant); + rules.addTreeEdge(g, tenant, cloudregion); + rules.addEdge(g, cloudregion, complex); + + rules.addEdge(g, servicesubscription1, tenant1); + rules.addTreeEdge(g, tenant1, cloudregion1); + rules.addEdge(g, cloudregion1, complex1); + + + expectedResult.add(servicesubscription); + expectedResult.add(tenant); + expectedResult.add(cloudregion); + expectedResult.add(complex); + } + + @Override + protected String getQueryName() { + return "getTenantInfoAtSvcSubscription"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "service-subscription").has("service-type", "service-type-0"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetVnfVlanByCircuitIdTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetVnfVlanByCircuitIdTest.java new file mode 100644 index 0000000..74e4875 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetVnfVlanByCircuitIdTest.java @@ -0,0 +1,89 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; + +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class GetVnfVlanByCircuitIdTest extends QueryTest { + public GetVnfVlanByCircuitIdTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + //Set up the test graph + Vertex logicallink1 = graph.addVertex(T.label, "logical-link", T.id, "1", "aai-node-type", "logical-link", "link-name", "linkName1", "link-type", "linkType1", "circuit-id", "circuitId1"); + Vertex logicallink2 = graph.addVertex(T.label, "logical-link", T.id, "2", "aai-node-type", "logical-link", "link-name", "linkName2", "link-type", "linkType2", "circuit-id", "circuitId2"); + + Vertex vlan1 = graph.addVertex(T.label, "vlan", T.id, "3", "aai-node-type", "vlan", "vlan-interface", "vlanInterface1"); + Vertex vlan2 = graph.addVertex(T.label, "vlan", T.id, "4", "aai-node-type", "vlan", "vlan-interface", "vlanInterface2"); + + Vertex linterface1 = graph.addVertex(T.label, "l-interface", T.id, "5", "aai-node-type", "l-interface", "interface-name", "interfaceName1"); + Vertex linterface2 = graph.addVertex(T.label, "l-interface", T.id, "6", "aai-node-type", "l-interface", "interface-name", "interfaceName2"); + + Vertex genericvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "7", "aai-node-type", "generic-vnf", "vnf-id", "vnfId1", "vnf-type", "vnfType1"); + Vertex genericvnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "8", "aai-node-type", "generic-vnf", "vnf-id", "vnfId2", "vnf-type", "vnfType2"); + + GraphTraversalSource g = graph.traversal(); + + rules.addEdge(g, logicallink1, vlan1); + rules.addTreeEdge(g, vlan1, linterface1); + rules.addTreeEdge(g, linterface1, genericvnf1); + + rules.addEdge(g, logicallink2, vlan2);//false + rules.addTreeEdge(g, vlan2, linterface2);//false + rules.addTreeEdge(g, linterface2, genericvnf2);//false + + expectedResult.add(logicallink1); + expectedResult.add(vlan1); + expectedResult.add(linterface1); + expectedResult.add(genericvnf1); + + } + + @Override + protected String getQueryName() { + return "getVnfVlanByCircuitId"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("link-name","linkName1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + params.put("circuit-id","circuitId1"); + } +}
\ No newline at end of file diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetVserverDetailTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetVserverDetailTest.java new file mode 100644 index 0000000..094439b --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetVserverDetailTest.java @@ -0,0 +1,122 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException; +import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class GetVserverDetailTest extends QueryTest { + public GetVserverDetailTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + @Test + public void run() { + super.run(); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException { + //set up test graph + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vserverid0"); + Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "1", "aai-node-type", "cloud-region", "cloud-region-id", "regionid0", "cloud-owner", "cloudOwnername0"); + Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "2", "aai-node-type", "tenant", "tenant-id", "tenantid0", "tenant-name", "tenantName0"); + Vertex genericvnf = graph.addVertex(T.label, "generic-vnf", T.id, "4", "aai-node-type", "generic-vnf", "vnf-id", "vnfid0"); + Vertex vfmodule = graph.addVertex(T.label, "vf-module", T.id, "5", "aai-node-type", "vf-module", "vf-module-id", "vfmoduleid0"); + Vertex serviceinstance = graph.addVertex(T.label, "service-instance", T.id, "6", "aai-node-type", "service-instance", "service-intsance-id", "serviceinstanceid0"); + Vertex modelver0 = graph.addVertex(T.label, "model-ver", T.id, "7", "aai-node-type", "model-ver", "model-version-id", "modelversionid0"); + Vertex modelver1 = graph.addVertex(T.label, "model-ver", T.id, "8", "aai-node-type", "model-ver", "model-version-id", "modelversionid1"); + Vertex modelver2 = graph.addVertex(T.label, "model-ver", T.id, "9", "aai-node-type", "model-ver", "model-version-id", "modelversionid2"); + Vertex model0 = graph.addVertex(T.label, "model", T.id, "10", "aai-node-type", "model", "model-invariant-id", "modelinvariantid0"); + Vertex model1 = graph.addVertex(T.label, "model", T.id, "11", "aai-node-type", "model", "model-invariant-id", "modelinvariantid1"); + Vertex model2 = graph.addVertex(T.label, "model", T.id, "12", "aai-node-type", "model", "model-invariant-id", "modelinvariantid2"); + + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "13", "aai-node-type", "vserver", "vserver-id", "vserverid1"); + Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "14", "aai-node-type", "cloud-region", "cloud-region-id", "regionid0", "cloud-owner", "cloudOwnername0"); + Vertex tenant1 = graph.addVertex(T.label, "tenant", T.id, "15", "aai-node-type", "tenant", "tenant-id", "tenantid0", "tenant-name", "tenantName0"); + Vertex genericvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "16", "aai-node-type", "generic-vnf", "vnf-id", "vnfid0"); + Vertex vfmodule1 = graph.addVertex(T.label, "vf-module", T.id, "17", "aai-node-type", "vf-module", "vf-module-id", "vfmoduleid0"); + Vertex serviceinstance1 = graph.addVertex(T.label, "service-instance", T.id, "18", "aai-node-type", "service-instance", "service-intsance-id", "serviceinstanceid0"); + Vertex modelver3 = graph.addVertex(T.label, "model-ver", T.id, "19", "aai-node-type", "model-ver", "model-version-id", "modelversionid0"); + Vertex modelver4 = graph.addVertex(T.label, "model-ver", T.id, "20", "aai-node-type", "model-ver", "model-version-id", "modelversionid1"); + Vertex modelver5 = graph.addVertex(T.label, "model-ver", T.id, "21", "aai-node-type", "model-ver", "model-version-id", "modelversionid2"); + Vertex model3 = graph.addVertex(T.label, "model", T.id, "22", "aai-node-type", "model", "model-invariant-id", "modelinvariantid0"); + Vertex model4 = graph.addVertex(T.label, "model", T.id, "23", "aai-node-type", "model", "model-invariant-id", "modelinvariantid1"); + Vertex model5 = graph.addVertex(T.label, "model", T.id, "24", "aai-node-type", "model", "model-invariant-id", "modelinvariantid2"); + GraphTraversalSource g = graph.traversal(); + + rules.addTreeEdge(g, vserver, tenant); + rules.addTreeEdge(g, tenant, cloudregion); + rules.addEdge(g, vserver, genericvnf); + rules.addPrivateEdge(g, genericvnf, modelver0, null); + rules.addTreeEdge(g, modelver0, model0); + rules.addTreeEdge(g, genericvnf, vfmodule); + rules.addPrivateEdge(g, vfmodule, modelver1, null); + rules.addTreeEdge(g, modelver1, model1); + rules.addEdge(g, genericvnf, serviceinstance); + rules.addPrivateEdge(g, serviceinstance, modelver2, null); + rules.addTreeEdge(g, modelver2, model2); + + rules.addTreeEdge(g, vserver1, tenant1);//false + rules.addTreeEdge(g, tenant1, cloudregion1);//false + rules.addEdge(g, vserver1, genericvnf1);//false + rules.addPrivateEdge(g, genericvnf1, modelver3, null);//false + rules.addTreeEdge(g, modelver3, model3);//false + rules.addTreeEdge(g, genericvnf1, vfmodule1);//false + rules.addPrivateEdge(g, vfmodule1, modelver4, null);//false + rules.addTreeEdge(g, modelver4, model4);//false + rules.addEdge(g, genericvnf1, serviceinstance1); + rules.addPrivateEdge(g, serviceinstance1, modelver5, null);//false + rules.addTreeEdge(g, modelver5, model5);//false + + expectedResult.add(vserver); + expectedResult.add(tenant); + expectedResult.add(cloudregion); + expectedResult.add(genericvnf); + expectedResult.add(modelver0); + expectedResult.add(model0); + expectedResult.add(vfmodule); + expectedResult.add(modelver1); + expectedResult.add(model1); + expectedResult.add(serviceinstance); + expectedResult.add(modelver2); + expectedResult.add(model2); + } + @Override + protected String getQueryName() { + return "getVserverDetail"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "vserver").has("vserver-id", "vserverid0"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } +}
\ No newline at end of file diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetWlBundleIdQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetWlBundleIdQueryTest.java new file mode 100644 index 0000000..2831315 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetWlBundleIdQueryTest.java @@ -0,0 +1,100 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class GetWlBundleIdQueryTest extends QueryTest { + public GetWlBundleIdQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + + Vertex lagLink = graph.addVertex(T.label, "lag-link", T.id, "1", "aai-node-type", "lag-link", "lag-link-id", "lag-link-id-1","link-name", "link-name-1"); + Vertex logicalLink = graph.addVertex(T.label, "logical-link", T.id, "2", "aai-node-type", "logical-link", "logical-link-id", "logical-link-id-1"); + Vertex serviceInstance = graph.addVertex(T.label, "service-instance", T.id, "3", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1"); + Vertex serviceSubcription = graph.addVertex(T.label, "service-subscription", T.id, "4", "aai-node-type", "service-subscription", "service-subscription-id", "service-subscription-id-1"); + Vertex customer = graph.addVertex(T.label, "customer", T.id, "5", "aai-node-type", "customer", "customer-id", "customer-id-1"); + Vertex logicalLink1 = graph.addVertex(T.label, "logical-link", T.id, "6", "aai-node-type", "logical-link", "logical-link-id", "logical-link-id-2"); + + Vertex lagLink1 = graph.addVertex(T.label, "lag-link", T.id, "7", "aai-node-type", "lag-link", "lag-link-id", "lag-link-id-2","link-name", "link-name-2"); + Vertex logicalLink2 = graph.addVertex(T.label, "logical-link", T.id, "8", "aai-node-type", "logical-link", "logical-link-id", "logical-link-id-3"); + Vertex serviceInstance1 = graph.addVertex(T.label, "service-instance", T.id, "9", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-2"); + Vertex serviceSubcription1 = graph.addVertex(T.label, "service-subscription", T.id, "10", "aai-node-type", "service-subscription", "service-subscription-id", "service-subscription-id-2"); + Vertex customer1 = graph.addVertex(T.label, "customer", T.id, "11", "aai-node-type", "customer", "customer-id", "customer-id-2"); + Vertex logicalLink3 = graph.addVertex(T.label, "logical-link", T.id, "12", "aai-node-type", "logical-link", "logical-link-id", "logical-link-id-4"); + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, lagLink, logicalLink); + rules.addEdge(g, logicalLink, serviceInstance); + rules.addTreeEdge(g, serviceInstance,serviceSubcription); + rules.addTreeEdge(g, serviceSubcription,customer); + rules.addEdge(g, logicalLink, logicalLink1); + + //Not expected in result + rules.addEdge(g, lagLink1, logicalLink2); + rules.addEdge(g, logicalLink2, serviceInstance1); + rules.addTreeEdge(g, serviceInstance1,serviceSubcription1); + rules.addTreeEdge(g, serviceSubcription1,customer1); + rules.addEdge(g, logicalLink2, logicalLink3); + //Not expected in result + + expectedResult.add(lagLink); + expectedResult.add(logicalLink); + expectedResult.add(serviceInstance); + expectedResult.add(serviceSubcription); + expectedResult.add(customer); + expectedResult.add(logicalLink1); + + + } + + @Override + protected String getQueryName() { + return "getWlBundleId"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "lag-link").has("link-name", "link-name-1"); + + } + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java index 97045df..b489a83 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java @@ -26,7 +26,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.onap.aai.AAISetup; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.ModelType; import org.onap.aai.serialization.engines.JanusGraphDBEngine; @@ -54,9 +53,7 @@ public class GroovyShellImplTest extends AAISetup{ private final static ModelType introspectorFactoryType = ModelType.MOXY; private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; - private final static DBConnectionType type = DBConnectionType.REALTIME; - static { VALID_HTTP_STATUS_CODES.add(200); VALID_HTTP_STATUS_CODES.add(201); @@ -117,7 +114,6 @@ public class GroovyShellImplTest extends AAISetup{ loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version); dbEngine = new JanusGraphDBEngine( queryStyle, - type, loader); GenericQueryProcessor.Builder builder = new GenericQueryProcessor.Builder(dbEngine, gremlinServerSingleton); builder.queryFrom(URI.create("te")); @@ -134,7 +130,7 @@ public class GroovyShellImplTest extends AAISetup{ GraphTraversal<Vertex, Vertex> g = Mockito.mock(GraphTraversal.class); g.has("cloud-region-id", "cloud-region-id-1"); Map<String, Object> params = new HashMap<>(); - groovyShellImpl.runQuery("vnfs-fromServiceInstance", params); + groovyShellImpl.runQuery("vnfs-fromServiceInstance", params, dbEngine.asAdmin().getTraversalSource()); } } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/IpsNetworksFromVnfTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/IpsNetworksFromVnfTest.java new file mode 100644 index 0000000..cab4ad0 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/IpsNetworksFromVnfTest.java @@ -0,0 +1,200 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. 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========================================================= + */ +package org.onap.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.junit.Ignore; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class IpsNetworksFromVnfTest extends QueryTest { + + public IpsNetworksFromVnfTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Ignore + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + Vertex genericVnf = graph.addVertex(T.label, "generic-vnf",T.id, "0", "aai-node-type", "generic-vnf", "generic-vnf-id", "serviceinstanceid0"); + Vertex vnfc = graph.addVertex(T.label, "vnfc",T.id, "1", "aai-node-type", "vnfc","vnfc-id", "vnfcId1"); + Vertex cp = graph.addVertex(T.label, "cp",T.id, "30", "aai-node-type", "cp","cp-id", "cpId1"); + Vertex vipIpv4AddressList = graph.addVertex(T.label, "vip-ipv4-address-list",T.id, "2", "aai-node-type", "vip-ipv4-address-list","vip-ipv4-address-list-id", "vip-ipv4-address-listId2"); + Vertex vipIpv6AddressList = graph.addVertex(T.label, "vip-ipv6-address-list",T.id, "3", "aai-node-type", "vip-ipv6-address-list","vip-ipv6-address-list-id", "vip-ipv6-address-listId3"); + + + Vertex subnetIpv4 = graph.addVertex(T.label, "subnet",T.id, "7", "aai-node-type", "subnet","subnet-id", "subnetId7"); + Vertex l3Network1Ipv4 = graph.addVertex(T.label, "l3-network",T.id, "8", "aai-node-type", "l3-network","l3-network-id", "l3-networkId8"); + + Vertex subnetIpv6 = graph.addVertex(T.label, "subnet",T.id, "10", "aai-node-type", "subnet","subnet-id", "subnetId10"); + Vertex l3Network1Ipv6 = graph.addVertex(T.label, "l3-network",T.id, "11", "aai-node-type", "l3-network","l3-network-id", "l3-networkId11"); + + Vertex vserver = graph.addVertex(T.label, "vserver",T.id, "18", "aai-node-type", "vserver","vserver-id", "vserverId18"); + Vertex linterface = graph.addVertex(T.label, "l-interface",T.id, "19", "aai-node-type", "l-interface","l-interface-id", "l-interfaceId19"); + Vertex pserver = graph.addVertex(T.label, "pserver",T.id, "20", "aai-node-type", "pserver","pserver-id", "pserverId20"); + + + Vertex l3NetworklintIpv4 = graph.addVertex(T.label, "l3-network",T.id, "21", "aai-node-type", "l3-network","l3-network-id", "l3-networkId21"); + Vertex subnetlintIpv4 = graph.addVertex(T.label, "subnet",T.id, "22", "aai-node-type", "subnet","subnet-id", "subnetId22"); + Vertex l3Network1lintIpv4 = graph.addVertex(T.label, "l3-network",T.id, "23", "aai-node-type", "l3-network","l3-network-id", "l3-networkId23"); + + Vertex l3NetworklintIpv6 = graph.addVertex(T.label, "l3-network",T.id, "24", "aai-node-type", "l3-network","l3-network-id", "l3-networkId24"); + Vertex subnetlintIpv6 = graph.addVertex(T.label, "subnet",T.id, "25", "aai-node-type", "subnet","subnet-id", "subnetId25"); + Vertex l3Network1lintIpv6 = graph.addVertex(T.label, "l3-network",T.id, "26", "aai-node-type", "l3-network","l3-network-id", "l3-networkId26"); + + + Vertex l3InterfaceIpv4AddressListLint = graph.addVertex(T.label, "l3-interface-ipv4-address-list",T.id, "27", "aai-node-type", "l3-interface-ipv4-address-list","l3-interface-ipv4-address-list-id", "l3-interface-ipv4-address-listId27"); + Vertex l3InterfaceIpv6AddressListlInt = graph.addVertex(T.label, "l3-interface-ipv6-address-list",T.id, "28", "aai-node-type", "l3-interface-ipv6-address-list","l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-listId28"); + + + Vertex complex = graph.addVertex(T.label, "complex",T.id, "29", "aai-node-type", "complex","complex-id", "complexId29"); + + + + Vertex genericVnf1 = graph.addVertex(T.label, "generic-vnf",T.id, "31", "aai-node-type", "generic-vnf", "generic-vnf-id", "serviceinstanceid1"); + Vertex vnfc1 = graph.addVertex(T.label, "vnfc",T.id, "32", "aai-node-type", "vnfc","vnfc-id", "vnfcId2"); + Vertex cp1 = graph.addVertex(T.label, "cp",T.id, "33", "aai-node-type", "cp","cp-id", "cpId3"); + Vertex vipIpv4AddressList1 = graph.addVertex(T.label, "vip-ipv4-address-list",T.id, "34", "aai-node-type", "vip-ipv4-address-list","vip-ipv4-address-list-id", "vip-ipv4-address-listId4"); + Vertex vipIpv6AddressList1 = graph.addVertex(T.label, "vip-ipv6-address-list",T.id, "35", "aai-node-type", "vip-ipv6-address-list","vip-ipv6-address-list-id", "vip-ipv6-address-listId5"); + Vertex subnetIpv41 = graph.addVertex(T.label, "subnet",T.id, "36", "aai-node-type", "subnet","subnet-id", "subnetId6"); + Vertex l3Network1Ipv41 = graph.addVertex(T.label, "l3-network",T.id, "37", "aai-node-type", "l3-network","l3-network-id", "l3-networkId7"); + Vertex subnetIpv61 = graph.addVertex(T.label, "subnet",T.id, "38", "aai-node-type", "subnet","subnet-id", "subnetId8"); + Vertex l3Network1Ipv61 = graph.addVertex(T.label, "l3-network",T.id, "39", "aai-node-type", "l3-network","l3-network-id", "l3-networkId9"); + Vertex vserver1 = graph.addVertex(T.label, "vserver",T.id, "40", "aai-node-type", "vserver","vserver-id", "vserverId10"); + Vertex linterface1 = graph.addVertex(T.label, "l-interface",T.id, "41", "aai-node-type", "l-interface","l-interface-id", "l-interfaceId11"); + Vertex pserver1 = graph.addVertex(T.label, "pserver",T.id, "42", "aai-node-type", "pserver","pserver-id", "pserverId12"); + Vertex l3NetworklintIpv41 = graph.addVertex(T.label, "l3-network",T.id, "43", "aai-node-type", "l3-network","l3-network-id", "l3-networkId13"); + Vertex subnetlintIpv41 = graph.addVertex(T.label, "subnet",T.id, "44", "aai-node-type", "subnet","subnet-id", "subnetId14"); + Vertex l3Network1lintIpv41 = graph.addVertex(T.label, "l3-network",T.id, "45", "aai-node-type", "l3-network","l3-network-id", "l3-networkId15"); + Vertex l3NetworklintIpv61 = graph.addVertex(T.label, "l3-network",T.id, "46", "aai-node-type", "l3-network","l3-network-id", "l3-networkId16"); + Vertex subnetlintIpv61 = graph.addVertex(T.label, "subnet",T.id, "47", "aai-node-type", "subnet","subnet-id", "subnetId17"); + Vertex l3Network1lintIpv61 = graph.addVertex(T.label, "l3-network",T.id, "48", "aai-node-type", "l3-network","l3-network-id", "l3-networkId18"); + Vertex l3InterfaceIpv4AddressListLint1 = graph.addVertex(T.label, "l3-interface-ipv4-address-list",T.id, "49", "aai-node-type", "l3-interface-ipv4-address-list","l3-interface-ipv4-address-list-id", "l3-interface-ipv4-address-listId19"); + Vertex l3InterfaceIpv6AddressListlInt1 = graph.addVertex(T.label, "l3-interface-ipv6-address-list",T.id, "50", "aai-node-type", "l3-interface-ipv6-address-list","l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-listId20"); + Vertex complex1 = graph.addVertex(T.label, "complex",T.id, "51", "aai-node-type", "complex","complex-id", "complexId21"); + + + GraphTraversalSource g = graph.traversal(); + + rules.addEdge(g, genericVnf,vnfc); + rules.addTreeEdge(g, vnfc,cp); + rules.addEdge(g, cp,vipIpv4AddressList); + rules.addEdge(g, cp,vipIpv6AddressList); + + rules.addEdge(g, vipIpv4AddressList,subnetIpv4); + rules.addTreeEdge(g, subnetIpv4,l3Network1Ipv4); + + rules.addEdge(g, vipIpv6AddressList,subnetIpv6); + rules.addTreeEdge(g, subnetIpv6,l3Network1Ipv6); + + rules.addEdge(g, genericVnf,vserver); + rules.addEdge(g, vserver,pserver); + + rules.addTreeEdge(g, cp,l3InterfaceIpv4AddressListLint); + rules.addTreeEdge(g, cp,l3InterfaceIpv6AddressListlInt); + + rules.addEdge(g, l3InterfaceIpv4AddressListLint,l3NetworklintIpv4); + rules.addEdge(g, l3InterfaceIpv4AddressListLint,subnetlintIpv4); + rules.addTreeEdge(g, subnetlintIpv4,l3Network1lintIpv4); + + rules.addEdge(g, l3InterfaceIpv6AddressListlInt,l3NetworklintIpv6); + rules.addEdge(g, l3InterfaceIpv6AddressListlInt,subnetlintIpv6); + rules.addTreeEdge(g, subnetlintIpv6,l3Network1lintIpv6); + + rules.addEdge(g, pserver,complex); + + //false + rules.addEdge(g, genericVnf1,vnfc1); + rules.addTreeEdge(g, vnfc1,cp1); + rules.addEdge(g, cp1,vipIpv4AddressList1); + rules.addEdge(g, cp1,vipIpv6AddressList1); + rules.addEdge(g, vipIpv4AddressList1,subnetIpv41); + rules.addTreeEdge(g, subnetIpv41,l3Network1Ipv41); + rules.addEdge(g, vipIpv6AddressList1,subnetIpv61); + rules.addTreeEdge(g, subnetIpv61,l3Network1Ipv61); + rules.addEdge(g, genericVnf1,vserver1); + rules.addEdge(g, vserver1,pserver1); + rules.addTreeEdge(g, cp1,l3InterfaceIpv4AddressListLint1); + rules.addTreeEdge(g, cp1,l3InterfaceIpv6AddressListlInt1); + rules.addEdge(g, l3InterfaceIpv4AddressListLint1,l3NetworklintIpv41); + rules.addEdge(g, l3InterfaceIpv4AddressListLint1,subnetlintIpv41); + rules.addTreeEdge(g, subnetlintIpv41,l3Network1lintIpv41); + rules.addEdge(g, l3InterfaceIpv6AddressListlInt1,l3NetworklintIpv61); + rules.addEdge(g, l3InterfaceIpv6AddressListlInt1,subnetlintIpv61); + rules.addTreeEdge(g, subnetlintIpv61,l3Network1lintIpv61); + rules.addEdge(g, pserver1,complex1); + //false + + expectedResult.add(genericVnf); + expectedResult.add(vnfc); + expectedResult.add(vipIpv4AddressList); + expectedResult.add(vipIpv6AddressList); + + expectedResult.add(subnetIpv4); + expectedResult.add(l3Network1Ipv4); + + expectedResult.add(subnetIpv6); + expectedResult.add(l3Network1Ipv6); + + expectedResult.add(l3InterfaceIpv4AddressListLint); + expectedResult.add(l3InterfaceIpv6AddressListlInt); + + expectedResult.add(l3NetworklintIpv4); + expectedResult.add(subnetlintIpv4); + expectedResult.add(l3Network1lintIpv4); + + expectedResult.add(l3NetworklintIpv6); + expectedResult.add(subnetlintIpv6); + expectedResult.add(l3Network1lintIpv6); + + expectedResult.add(vserver); + expectedResult.add(pserver); + expectedResult.add(complex); + + } + + @Override + protected String getQueryName() { + return "ips-networks-fromVnf"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "generic-vnf").has("generic-vnf-id", "serviceinstanceid0"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java index 1fc8bbd..b4a3dcd 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java @@ -19,23 +19,16 @@ */ package org.onap.aai.rest.search; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; import org.onap.aai.AAISetup; -import org.onap.aai.dbmap.DBConnectionType; -import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.ModelType; -import org.onap.aai.serialization.db.DBSerializer; -import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.JanusGraphDBEngine; -import org.onap.aai.serialization.engines.TransactionalGraphEngine; -import org.onap.aai.serialization.queryformats.utils.UrlBuilder; import org.onap.aai.setup.SchemaVersion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.*; @@ -57,11 +50,6 @@ public class ModelAndNamedQueryRestProviderTest extends AAISetup{ private SchemaVersion version; private static final ModelType introspectorFactoryType = ModelType.MOXY; - private static final QueryStyle queryStyle = QueryStyle.TRAVERSAL; - private static final DBConnectionType type = DBConnectionType.REALTIME; - - private Loader loader; - private TransactionalGraphEngine dbEngine; static { VALID_HTTP_STATUS_CODES.add(200); @@ -82,7 +70,7 @@ public class ModelAndNamedQueryRestProviderTest extends AAISetup{ private List<MediaType> outputMediaTypes; - private static final EELFLogger logger = EELFManager.getInstance().getLogger(ModelAndNamedQueryRestProviderTest.class.getName()); + private static final Logger logger = LoggerFactory.getLogger(ModelAndNamedQueryRestProviderTest.class.getName()); @Before public void setup(){ @@ -112,8 +100,8 @@ public class ModelAndNamedQueryRestProviderTest extends AAISetup{ when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); - when(httpHeaders.getRequestHeader("X-FromAppId")).thenReturn(Arrays.asList("JUNIT")); - when(httpHeaders.getRequestHeader("X-TransactionId")).thenReturn(Arrays.asList("JUNIT")); + when(httpHeaders.getRequestHeader("X-FromAppId")).thenReturn(Collections.singletonList("JUNIT")); + when(httpHeaders.getRequestHeader("X-TransactionId")).thenReturn(Collections.singletonList("JUNIT")); when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); @@ -125,11 +113,6 @@ public class ModelAndNamedQueryRestProviderTest extends AAISetup{ Mockito.doReturn(null).when(queryParameters).remove(anyObject()); when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); - loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new JanusGraphDBEngine( - queryStyle, - type, - loader); } @Test @@ -224,7 +207,6 @@ public class ModelAndNamedQueryRestProviderTest extends AAISetup{ String message = String.format("Unable to find the %s in src/test/resources", filename); assertNotNull(message, inputStream); - String resource = IOUtils.toString(inputStream); - return resource; + return IOUtils.toString(inputStream); } } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/OnapQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/OnapQueryTest.java index d92b902..138892c 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/OnapQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/OnapQueryTest.java @@ -19,7 +19,8 @@ */ package org.onap.aai.rest.search; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; @@ -93,7 +94,7 @@ public abstract class OnapQueryTest { @Rule public final SpringMethodRule springMethodRule = new SpringMethodRule(); - protected EELFLogger logger; + protected Logger logger; protected Graph graph; protected GremlinGroovyShell shell; @Mock protected TransactionalGraphEngine dbEngine; @@ -144,7 +145,7 @@ public abstract class OnapQueryTest { public void setUp() throws AAIException, NoEdgeRuleFoundException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException { System.setProperty("AJSC_HOME", "."); System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); - logger = EELFManager.getInstance().getLogger(getClass()); + logger = LoggerFactory.getLogger(getClass()); MockitoAnnotations.initMocks(this); graph = TinkerGraph.open(); gts = graph.traversal(); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryTest.java index 005b5e7..f96d4c5 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryTest.java @@ -19,7 +19,8 @@ */ package org.onap.aai.rest.search; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; @@ -93,7 +94,7 @@ public abstract class QueryTest { @Rule public final SpringMethodRule springMethodRule = new SpringMethodRule(); - protected EELFLogger logger; + protected Logger logger; protected Graph graph; protected GremlinGroovyShell shell; @Mock protected TransactionalGraphEngine dbEngine; @@ -144,7 +145,7 @@ public abstract class QueryTest { public void setUp() throws AAIException, NoEdgeRuleFoundException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException { System.setProperty("AJSC_HOME", "."); System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); - logger = EELFManager.getInstance().getLogger(getClass()); + logger = LoggerFactory.getLogger(getClass()); MockitoAnnotations.initMocks(this); graph = TinkerGraph.open(); gts = graph.traversal(); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java index b69f992..4332536 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java @@ -19,28 +19,23 @@ */ package org.onap.aai.rest.search; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; import org.onap.aai.AAISetup; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.ModelType; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.JanusGraphDBEngine; -import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.setup.SchemaVersion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.ws.rs.core.*; import java.util.*; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -54,10 +49,8 @@ public class SearchProviderTest extends AAISetup{ private SchemaVersion version; private static final ModelType introspectorFactoryType = ModelType.MOXY; private static final QueryStyle queryStyle = QueryStyle.TRAVERSAL; - private static final DBConnectionType type = DBConnectionType.REALTIME; private Loader loader; - private TransactionalGraphEngine dbEngine; static { VALID_HTTP_STATUS_CODES.add(200); @@ -78,7 +71,7 @@ public class SearchProviderTest extends AAISetup{ private List<MediaType> outputMediaTypes; - private static final EELFLogger logger = EELFManager.getInstance().getLogger(SearchProviderTest.class.getName()); + private static final Logger logger = LoggerFactory.getLogger(SearchProviderTest.class.getName()); @Before public void setup(){ @@ -108,8 +101,8 @@ public class SearchProviderTest extends AAISetup{ when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); - when(httpHeaders.getRequestHeader("X-FromAppId")).thenReturn(Arrays.asList("JUNIT")); - when(httpHeaders.getRequestHeader("X-TransactionId")).thenReturn(Arrays.asList("JUNIT")); + when(httpHeaders.getRequestHeader("X-FromAppId")).thenReturn(Collections.singletonList("JUNIT")); + when(httpHeaders.getRequestHeader("X-TransactionId")).thenReturn(Collections.singletonList("JUNIT")); when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); @@ -122,10 +115,6 @@ public class SearchProviderTest extends AAISetup{ when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new JanusGraphDBEngine( - queryStyle, - type, - loader); } @Test diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java index d6ad59a..934d3fa 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java @@ -29,12 +29,10 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.onap.aai.AAISetup; -import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.ModelType; import org.onap.aai.serialization.db.DBSerializer; - import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.QueryStyle; @@ -96,7 +94,6 @@ public class SimpleFormatTest extends AAISetup{ Loader loader = loaderFactory.createLoaderForVersion(factoryType, schemaVersions.getRelatedLinkVersion()); dbEngine = spy(new JanusGraphDBEngine( QueryStyle.TRAVERSAL, - DBConnectionType.CACHED, loader)); when(dbEngine.tx()).thenReturn(graph); @@ -114,7 +111,7 @@ public class SimpleFormatTest extends AAISetup{ System.out.println(dbEngine.tx()); assertNotNull(graph.traversal()); JsonObject json = _simpleFormat.createPropertiesObject(vfmodule).get(); - json.entrySet().stream().forEach((System.out::println)); + json.entrySet().forEach((System.out::println)); assertTrue(json.has("model-invariant-id")); } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologyFromSubscriberNameAndServiceTypeTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologyFromSubscriberNameAndServiceTypeTest.java index 6cec307..7164dba 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologyFromSubscriberNameAndServiceTypeTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologyFromSubscriberNameAndServiceTypeTest.java @@ -26,7 +26,8 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSo import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import com.google.common.base.CaseFormat; import org.junit.Test; @@ -35,7 +36,7 @@ import org.onap.aai.exceptions.AAIException; import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; public class TopologyFromSubscriberNameAndServiceTypeTest extends QueryTest { - private static final EELFLogger LOGGER = EELFManager.getInstance() + private static final Logger LOGGER = LoggerFactory .getLogger(TopologyFromSubscriberNameAndServiceTypeTest.class); public TopologyFromSubscriberNameAndServiceTypeTest() throws AAIException, NoEdgeRuleFoundException { diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java index 9b10070..a07dfa6 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java @@ -19,7 +19,8 @@ */ package org.onap.aai.rest.util; -import com.att.eelf.configuration.EELFLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.eelf.configuration.EELFManager; import org.junit.Before; import org.junit.Test; @@ -59,7 +60,7 @@ public class EchoResponseTest { private List<MediaType> outputMediaTypes; - private static final EELFLogger logger = EELFManager.getInstance().getLogger(EchoResponseTest.class.getName()); + private static final Logger logger = LoggerFactory.getLogger(EchoResponseTest.class.getName()); @Before public void setup(){ diff --git a/aai-traversal/src/test/resources/application-onap-test.properties b/aai-traversal/src/test/resources/application-onap-test.properties index 48a0b60..c8e9f6a 100644 --- a/aai-traversal/src/test/resources/application-onap-test.properties +++ b/aai-traversal/src/test/resources/application-onap-test.properties @@ -57,7 +57,7 @@ schema.ingest.file=${server.local.startpath}/application-test.properties # Schema Version Related Attributes schema.uri.base.path=/aai # Lists all of the versions in the schema -schema.version.list=v10,v11,v12,v13,v14,v15,v16 +schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17,v18,v19 # Specifies from which version should the depth parameter to default to zero schema.version.depth.start=v10 # Specifies from which version should the related link be displayed in response payload @@ -70,5 +70,5 @@ schema.version.namespace.change.start=v12 # Specifies from which version should the client start seeing the edge label in payload schema.version.edge.label.start=v12 # Specifies the version that the application should default to -schema.version.api.default=v16 +schema.version.api.default=v19 schema.translator.list=config
\ No newline at end of file diff --git a/aai-traversal/src/test/resources/application-test.properties b/aai-traversal/src/test/resources/application-test.properties index 7e244bb..eae212b 100644 --- a/aai-traversal/src/test/resources/application-test.properties +++ b/aai-traversal/src/test/resources/application-test.properties @@ -48,7 +48,6 @@ dmaap.ribbon.listOfServers=localhost:3904 schema.configuration.location=N/A # Choose if the oxm schema is onap or other system schema.source.name=onap ->>>>>>> release/1902 # Location of where the oxm files are schema.nodes.location=${server.local.startpath}/schema/${schema.source.name}/oxm/ # Location of where the dbedgerules files are @@ -61,7 +60,7 @@ schema.ingest.file=${server.local.startpath}/application-test.properties # Schema Version Related Attributes schema.uri.base.path=/aai # Lists all of the versions in the schema -schema.version.list=v10,v11,v12,v13,v14,v15,v16 +schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17,v18,v19 # Specifies from which version should the depth parameter to default to zero schema.version.depth.start=v10 # Specifies from which version should the related link be displayed in response payload @@ -74,6 +73,6 @@ schema.version.namespace.change.start=v12 # Specifies from which version should the client start seeing the edge label in payload schema.version.edge.label.start=v12 # Specifies the version that the application should default to -schema.version.api.default=v16 +schema.version.api.default=v19 schema.translator.list=config diff --git a/aai-traversal/src/test/resources/logback.xml b/aai-traversal/src/test/resources/logback.xml index f8a5925..4b969b1 100644 --- a/aai-traversal/src/test/resources/logback.xml +++ b/aai-traversal/src/test/resources/logback.xml @@ -31,16 +31,32 @@ <property name="AJSC_HOME" value="${AJSC_HOME:-.}" /> <jmxConfigurator /> <property name="logDirectory" value="${AJSC_HOME}/logs" /> - <property name="eelfLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%X{serviceName}|%X{partnerName}|%X{statusCode}|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> - <property name="eelfAuditLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%X{serviceName}|%X{partnerName}|%X{statusCode}|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n|\r\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> - <property name="eelfMetricLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%X{serviceName}|%X{partnerName}|%X{targetEntity}|%X{targetServiceName}|%X{statusCode}|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{targetVirtualEntity}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> - <!-- <property name="eelfErrorLogPattern" value="%ecompStartTime|%X{requestId}|%-10t|%X{serviceName}|%X{partnerName}|%X{targetEntity}|%X{targetServiceName}|%ecompErrorCategory|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n|\r\n', '^'}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> --> - <property name="eelfErrorLogPattern" value="%ecompStartTime|%X{requestId}|%-10t|%X{serviceName}|%X{partnerName}|%X{targetEntity}|%X{targetServiceName}|%ecompErrorCategory|%ecompResponseCode|%ecompResponseDescription|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> - <property name="eelfTransLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%X{serviceName}|%X{partnerName}|%X{statusCode}|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{partnerName}:%m%n"/> - - <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> - <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /> - <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" /> + <!-- Old patterns + <property name="eelfLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%ecompServiceName|%X{partnerName}|%ecompStatusCode|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> + <property name="eelfAuditLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%ecompServiceName|%X{partnerName}|%ecompStatusCode|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n|\r\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> + <property name="eelfMetricLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%ecompServiceName|%X{partnerName}|%X{targetEntity}|%X{targetServiceName}|%ecompStatusCode|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{targetVirtualEntity}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> + <property name="eelfErrorLogPattern" value="%ecompStartTime|%X{requestId}|%-10t|%ecompServiceName|%X{partnerName}|%X{targetEntity}|%X{targetServiceName}|%ecompErrorCategory|%ecompResponseCode|%ecompResponseDescription|co=%X{component}:%replace(%replace(%m){'\\|', '!'}){'\r|\n', '^'}%n"/> + <property name="eelfTransLogPattern" value="%ecompStartTime|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{requestId}|%X{serviceInstanceId}|%-10t|%X{serverName}|%ecompServiceName|%X{partnerName}|%ecompStatusCode|%X{responseCode}|%replace(%replace(%X{responseDescription}){'\\|', '!'}){'\r|\n', '^'}|%X{instanceUUID}|%level|%X{severity}|%X{serverIpAddress}|%ecompElapsedTime|%X{server}|%X{clientIpAddress}|%eelfClassOfCaller|%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{partnerName}:%m%n"/> + --> + <property name="p_tim" value="%d{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX", UTC}"/> + <property name="p_lvl" value="%level"/> + <property name="p_log" value="%logger"/> + <property name="p_mdc" value="%replace(%replace(%mdc){'\t','\\\\t'}){'\n', '\\\\n'}"/> + <property name="p_msg" value="%replace(%replace(%replace(%msg){'\t','\\\\t'}){'\n', '\\\\n'}){'\\|', '!'}"/> + <property name="p_exc" value="%replace(%replace(%rootException){'\t', '\\\\t'}){'\n','\\\\n'}"/> + <property name="p_mak" value="%replace(%replace(%marker){'\t', '\\\\t'}){'\n','\\\\n'}"/> + <property name="p_thr" value="%thread"/> + <property name="pattern" value="%nopexception${p_tim}\t${p_thr}\t${p_lvl}\t${p_log}\t${p_mdc}\t${p_msg}\t${p_exc}\t${p_mak}\t%n"/> + <!-- Patterns from onap demo --> + <property name="errorPattern" value="%X{LogTimestamp}|%X{RequestID}|%thread|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%.-5level|%X{ErrorCode}|%X{ErrorDesc}|${p_msg}%n" /> + <property name="debugPattern" value="%X{LogTimestamp}|%X{RequestID}|${p_msg}\t${p_mdc}\t${p_exc}\t${p_mak}\t|^%n" /> + + <property name="auditPattern" value="%X{EntryTimestamp}|%X{LogTimestamp}|%X{RequestID}|%X{ServiceInstanceID}|%thread||%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDesc}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}||||${p_mak}|${p_mdc}|||${p_msg}%n" /> + <property name="metricPattern" value="%X{InvokeTimestamp}|%X{LogTimestamp}|%X{RequestID}|%X{ServiceInstanceID}|%thread||%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDesc}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}||||%X{TargetVirtualEntity}|${p_mak}|${p_mdc}|||${p_msg}%n" /> + <property name="transLogPattern" value="%X{LogTimestamp}|%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}|%X{RequestID}|%X{ServiceInstanceID}|%-10t|%X{ServerFQDN}|%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%replace(%replace(%X{ResponseDesc}){'\\|', '!'}){'\r|\n', '^'}|%X{InstanceUUID}|%level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{clientIpAddress}||%X{unused}|%X{processKey}|%X{customField1}|%X{customField2}|%X{customField3}|%X{customField4}|co=%X{PartnerName}:%m%n"/> + <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> + <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /> + <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" /> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern> @@ -65,82 +81,74 @@ <includeCallerData>true</includeCallerData> <appender-ref ref="SANE" /> </appender> - - <appender name="METRIC" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <filter class="ch.qos.logback.classic.filter.LevelFilter"> - <level>INFO</level> - <onMatch>ACCEPT</onMatch> - <onMismatch>DENY</onMismatch> - </filter> + <appender name="METRIC" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logDirectory}/rest/metrics.log</file> - <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> - <fileNamePattern>${logDirectory}/rest/metrics.log.%d{yyyy-MM-dd} - </fileNamePattern> + <rollingPolicy + class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${logDirectory}/rest/metrics.log.%d{yyyy-MM-dd}</fileNamePattern> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfMetricLogPattern}</pattern> + <encoder> + <pattern>${metricPattern}</pattern> </encoder> </appender> + <appender name="asyncMETRIC" class="ch.qos.logback.classic.AsyncAppender"> <queueSize>1000</queueSize> <includeCallerData>true</includeCallerData> - <appender-ref ref="METRIC" /> + <appender-ref ref="METRIC"/> </appender> <appender name="DEBUG" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <file>${logDirectory}/rest/debug.log</file> - <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> - <fileNamePattern>${logDirectory}/rest/debug.log.%d{yyyy-MM-dd} - </fileNamePattern> + <rollingPolicy + class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${logDirectory}/rest/debug.log.%d{yyyy-MM-dd}</fileNamePattern> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfLogPattern}</pattern> + <encoder> + <pattern>${debugPattern}</pattern> </encoder> </appender> <appender name="asyncDEBUG" class="ch.qos.logback.classic.AsyncAppender"> <queueSize>1000</queueSize> - <includeCallerData>true</includeCallerData> <appender-ref ref="DEBUG" /> + <includeCallerData>true</includeCallerData> </appender> - <appender name="ERROR" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/rest/error.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${logDirectory}/rest/error.log.%d{yyyy-MM-dd}</fileNamePattern> + </rollingPolicy> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>WARN</level> </filter> - <file>${logDirectory}/rest/error.log</file> - <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> - <fileNamePattern>${logDirectory}/rest/error.log.%d{yyyy-MM-dd} - </fileNamePattern> - </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfErrorLogPattern}</pattern> + <encoder> + <pattern>${errorPattern}</pattern> </encoder> </appender> <appender name="asyncERROR" class="ch.qos.logback.classic.AsyncAppender"> <queueSize>1000</queueSize> - <includeCallerData>true</includeCallerData> - <appender-ref ref="ERROR" /> + <appender-ref ref="ERROR"/> </appender> <appender name="AUDIT" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logDirectory}/rest/audit.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${logDirectory}/rest/audit.log.%d{yyyy-MM-dd} </fileNamePattern> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfAuditLogPattern}</pattern> + <encoder> + <pattern>${auditPattern}</pattern> </encoder> </appender> @@ -151,7 +159,7 @@ </appender> <appender name="translog" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> @@ -162,11 +170,11 @@ <fileNamePattern>${logDirectory}/rest/translog.log.%d{yyyy-MM-dd} </fileNamePattern> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfTransLogPattern}</pattern> + <encoder> + <pattern>${transLogPattern}</pattern> </encoder> </appender> - + <appender name="asynctranslog" class="ch.qos.logback.classic.AsyncAppender"> <queueSize>1000</queueSize> <includeCallerData>true</includeCallerData> @@ -174,7 +182,7 @@ </appender> <appender name="dmaapAAIEventConsumer" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>WARN</level> </filter> @@ -183,13 +191,14 @@ <fileNamePattern>${logDirectory}/dmaapAAIEventConsumer/error.log.%d{yyyy-MM-dd} </fileNamePattern> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfLogPattern}</pattern> + <encoder> + <pattern>${errorPattern}</pattern> </encoder> + </appender> <appender name="dmaapAAIEventConsumerDebug" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> @@ -200,12 +209,28 @@ <fileNamePattern>${logDirectory}/dmaapAAIEventConsumer/debug.log.%d{yyyy-MM-dd} </fileNamePattern> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfLogPattern}</pattern> + <encoder> + <pattern>${debugPattern}</pattern> + </encoder> + </appender> + <appender name="dmaapAAIEventConsumerInfo" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <filter class="ch.qos.logback.classic.filter.LevelFilter"> + <level>INFO</level> + <onMatch>ACCEPT</onMatch> + <onMismatch>DENY</onMismatch> + </filter> + <File>${logDirectory}/dmaapAAIEventConsumer/dmaap-transaction.log</File> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${logDirectory}/dmaapAAIEventConsumer/dmaap-transaction.log.%d{yyyy-MM-dd} + </fileNamePattern> + </rollingPolicy> + <encoder> + <pattern>${auditPattern}</pattern> </encoder> </appender> <appender name="dmaapAAIEventConsumerMetric" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>INFO</level> <onMatch>ACCEPT</onMatch> @@ -216,12 +241,12 @@ <fileNamePattern>${logDirectory}/dmaapAAIEventConsumer/metrics.log.%d{yyyy-MM-dd} </fileNamePattern> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfMetricLogPattern}</pattern> + <encoder> + <pattern>${metricPattern}</pattern> </encoder> </appender> <appender name="external" - class="ch.qos.logback.core.rolling.RollingFileAppender"> + class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>WARN</level> </filter> @@ -230,151 +255,88 @@ <fileNamePattern>${logDirectory}/external/external.log.%d{yyyy-MM-dd} </fileNamePattern> </rollingPolicy> - <encoder class="org.onap.aai.logging.EcompEncoder"> - <pattern>${eelfLogPattern}</pattern> + <encoder> + <pattern>${debugPattern}</pattern> </encoder> </appender> - <logger name="org.onap.aai" level="DEBUG" additivity="true"> - <appender-ref ref="asyncDEBUG" /> - <appender-ref ref="asyncERROR" /> - <appender-ref ref="asyncMETRIC" /> - <appender-ref ref="asyncSANE" /> - </logger> + <appender name="auth" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> + <level>DEBUG</level> + </filter> + <file>${logDirectory}/auth/auth.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${logDirectory}/auth/auth.log.%d{yyyy-MM-dd} + </fileNamePattern> + </rollingPolicy> + <encoder> + <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ, UTC}[%thread] %-5level %logger{1024} - %msg%n</pattern> + </encoder> + </appender> + <appender name="asyncAUTH" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>1000</queueSize> + <includeCallerData>true</includeCallerData> + <appender-ref ref="auth" /> + </appender> + <!-- logback internals logging --> + + <logger name="ch.qos.logback.classic" level="WARN" /> + <logger name="ch.qos.logback.core" level="WARN" /> + <logger name="com.att.aft.dme2" level="WARN" /> + <logger name="com.jayway.jsonpath" level="WARN" /> + + <logger name="org.apache" level="OFF" /> + <logger name="org.apache.commons" level="WARN" /> + <logger name="org.apache.zookeeper" level="OFF" /> + <logger name="org.codehaus.groovy" level="WARN" /> + <logger name="org.eclipse.jetty" level="WARN" /> <!-- Spring related loggers --> <logger name="org.springframework" level="WARN" /> <logger name="org.springframework.beans" level="WARN" /> <logger name="org.springframework.web" level="WARN" /> - <logger name="com.blog.spring.jms" level="WARN" /> - <logger name="com.jayway.jsonpath" level="WARN" /> - - <!-- AJSC Services (bootstrap services) --> - <logger name="ajsc" level="WARN" /> - <logger name="ajsc.RouteMgmtService" level="WARN" /> - <logger name="ajsc.ComputeService" level="WARN" /> - <logger name="ajsc.VandelayService" level="WARN" /> - <logger name="ajsc.FilePersistenceService" level="WARN" /> - <logger name="ajsc.UserDefinedJarService" level="WARN" /> - <logger name="ajsc.UserDefinedBeansDefService" level="WARN" /> - <logger name="ajsc.LoggingConfigurationService" level="WARN" /> - - <!-- AJSC related loggers (DME2 Registration, csi logging, restlet, servlet - logging) --> - <logger name="org.codehaus.groovy" level="WARN" /> - <logger name="com.att.scamper" level="WARN" /> - <logger name="ajsc.utils" level="WARN" /> - <logger name="ajsc.utils.DME2Helper" level="WARN" /> - <logger name="ajsc.filters" level="WARN" /> - <logger name="ajsc.beans.interceptors" level="WARN" /> - <logger name="ajsc.restlet" level="WARN" /> - <logger name="ajsc.servlet" level="WARN" /> - <logger name="com.att.ajsc" level="WARN" /> - <logger name="com.att.ajsc.csi.logging" level="WARN" /> - <logger name="com.att.ajsc.filemonitor" level="WARN" /> - <logger name="com.netflix.loadbalancer" level="WARN" /> - - <logger name="org.apache.zookeeper" level="WARN" /> - - <!-- Other Loggers that may help troubleshoot --> - <logger name="net.sf" level="WARN" /> - <logger name="org.apache.commons.httpclient" level="WARN" /> - <logger name="org.apache.commons" level="WARN" /> - <logger name="org.apache.coyote" level="WARN" /> - <logger name="org.apache.jasper" level="WARN" /> - - <!-- Camel Related Loggers (including restlet/servlet/jaxrs/cxf logging. - May aid in troubleshooting) --> - <logger name="org.apache.camel" level="WARN" /> - <logger name="org.apache.cxf" level="WARN" /> - <logger name="org.apache.camel.processor.interceptor" level="WARN" /> - <logger name="org.apache.cxf.jaxrs.interceptor" level="WARN" /> - <logger name="org.apache.cxf.service" level="WARN" /> - <logger name="org.restlet" level="WARN" /> - <logger name="org.apache.camel.component.restlet" level="WARN" /> - - <logger name="org.hibernate.validator" level="WARN" /> - <logger name="org.hibernate" level="WARN" /> - <logger name="org.hibernate.ejb" level="OFF" /> - - <!-- logback internals logging --> - <logger name="ch.qos.logback.classic" level="WARN" /> - <logger name="ch.qos.logback.core" level="WARN" /> + <logger name="org.janusgraph" level="WARN" /> + <logger name="org.zookeeper" level="OFF" /> - <logger name="org.eclipse.jetty" level="WARN" /> - <!-- logback jms appenders & loggers definition starts here --> - <appender name="auditLogs" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <filter class="ch.qos.logback.classic.filter.ThresholdFilter" /> - <file>${logDirectory}/perf-audit/Audit-${lrmRVer}-${lrmRO}-${Pid}.log - </file> - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${logDirectory}/perf-audit/Audit-${lrmRVer}-${lrmRO}-${Pid}.%i.log.zip - </fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>9</maxIndex> - </rollingPolicy> - <triggeringPolicy - class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>5MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>"%d [%thread] %-5level %logger{1024} - %msg%n"</pattern> - </encoder> - </appender> - <appender name="perfLogs" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <filter class="ch.qos.logback.classic.filter.ThresholdFilter" /> - <file>${logDirectory}/perf-audit/Perform-${lrmRVer}-${lrmRO}-${Pid}.log - </file> - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${logDirectory}/perf-audit/Perform-${lrmRVer}-${lrmRO}-${Pid}.%i.log.zip - </fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>9</maxIndex> - </rollingPolicy> - <triggeringPolicy - class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>5MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>"%d [%thread] %-5level %logger{1024} - %msg%n"</pattern> - </encoder> - </appender> - <logger name="AuditRecord" level="INFO" additivity="false"> - <appender-ref ref="auditLogs" /> - </logger> - <logger name="AuditRecord_DirectCall" level="INFO" additivity="false"> - <appender-ref ref="auditLogs" /> - </logger> - <logger name="PerfTrackerRecord" level="INFO" additivity="false"> - <appender-ref ref="perfLogs" /> + <logger name="org.onap.aai" level="DEBUG" additivity="false"> + <appender-ref ref="asyncDEBUG" /> + <appender-ref ref="asyncSANE" /> + <appender-ref ref="STDOUT" /> </logger> - <!-- logback jms appenders & loggers definition ends here --> - - <logger name="org.onap.aai.interceptors.post" level="DEBUG" - additivity="false"> - <appender-ref ref="asynctranslog" /> + <logger name="org.onap.aai.aaf.auth" level="DEBUG" additivity="false"> + <appender-ref ref="asyncAUTH" /> </logger> - - <logger name="org.onap.aai.interceptors.pre.SetLoggingContext" level="DEBUG"> + <logger name="org.onap.aai.aailog.logs.AaiScheduledTaskAuditLog" level="INFO"> <appender-ref ref="asyncAUDIT"/> </logger> - - <logger name="org.onap.aai.interceptors.post.ResetLoggingContext" level="DEBUG"> + <logger name="org.onap.logging.filter.base.AbstractAuditLogFilter" level="INFO"> <appender-ref ref="asyncAUDIT"/> </logger> + <logger name="org.onap.aai.aailog.logs.AaiDBMetricLog" level="INFO"> + <appender-ref ref="asyncMETRIC"/> + </logger> + <logger name="org.onap.logging.filter.base.AbstractMetricLogFilter" level="INFO"> + <appender-ref ref="asyncMETRIC"/> + </logger> + <logger name="org.onap.aai.aailog.logs.AaiDmaapMetricLog" level="INFO"> + <appender-ref ref="dmaapAAIEventConsumerMetric"/> + </logger> + <logger name="org.onap.aai.logging.ErrorLogHelper" level="WARN"> + <appender-ref ref="asyncERROR"/> + </logger> + <logger name="org.onap.aai.interceptors.post" level="DEBUG" additivity="false"> + <appender-ref ref="asynctranslog" /> + </logger> <logger name="org.onap.aai.dmaap" level="DEBUG" additivity="false"> <appender-ref ref="dmaapAAIEventConsumer" /> <appender-ref ref="dmaapAAIEventConsumerDebug" /> - <appender-ref ref="dmaapAAIEventConsumerMetric" /> </logger> - <logger name="org.apache" level="WARN" /> - <logger name="org.zookeeper" level="WARN" /> - <logger name="org.janusgraph" level="WARN" /> - <logger name="com.att.aft.dme2" level="WARN" /> + <logger name="com.att.nsa.mr" level="INFO" > + <appender-ref ref="dmaapAAIEventConsumerInfo" /> + </logger> <!-- ============================================================================ --> <!-- General EELF logger --> diff --git a/aai-traversal/src/test/resources/schema-ingest.properties b/aai-traversal/src/test/resources/schema-ingest.properties index 9371645..363c5a1 100644 --- a/aai-traversal/src/test/resources/schema-ingest.properties +++ b/aai-traversal/src/test/resources/schema-ingest.properties @@ -2,9 +2,9 @@ schema.configuration.location=N/A schema.nodes.location=src/main/resources/etc/oxm/ schema.edges.location=src/main/resources/etc/dbedgerules/ -schema.version.list=v10,v11,v12,v13,v14,v15,v16 +schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17,v18,v19 schema.version.depth.start=v10 schema.version.related.link.start=v10 schema.version.app.root.start=v11 schema.version.edge.label.start=v12 -schema.version.api.default=v16 +schema.version.api.default=v19 |