Update Janusgraph to 0.5.0 in aai-common 30/138330/3
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Wed, 26 Jun 2024 12:12:55 +0000 (14:12 +0200)
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 28 Jun 2024 14:14:12 +0000 (16:14 +0200)
- update tinkerpop to 3.4.13
- update janusgraph to 0.5.0
- restore the total-pages header that was accidentally removed in the last pagination commit
- remove stateful pagination logic from HttpEntry

Issue-ID: AAI-3900
Change-Id: I5fac397ece75136673b8dc3866e10ff15dfdcee3
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
aai-core/pom.xml
aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MDCSetup.java
aai-parent/pom.xml
aai-rest/pom.xml
aai-schema-ingest/.classpath [deleted file]
aai-schema-ingest/pom.xml

index 30820d8..cd78bff 100644 (file)
@@ -197,6 +197,11 @@ limitations under the License.
                                </exclusion>
                        </exclusions>
                </dependency>
+               <dependency>
+                       <groupId>org.janusgraph</groupId>
+                       <artifactId>janusgraph-inmemory</artifactId>
+                       <scope>test</scope>
+               </dependency>
                <dependency>
                        <groupId>com.fasterxml.jackson.jaxrs</groupId>
                        <artifactId>jackson-jaxrs-json-provider</artifactId>
@@ -281,10 +286,6 @@ limitations under the License.
                        <artifactId>xml-apis</artifactId>
                        <version>1.4.01</version>
                </dependency>
-               <dependency>
-                       <groupId>com.beust</groupId>
-                       <artifactId>jcommander</artifactId>
-               </dependency>
                <dependency>
                        <groupId>org.json</groupId>
                        <artifactId>json</artifactId>
@@ -313,10 +314,6 @@ limitations under the License.
                        <groupId>org.apache.activemq</groupId>
                        <artifactId>activemq-openwire-legacy</artifactId>
                </dependency>
-               <dependency>
-                       <groupId>com.opencsv</groupId>
-                       <artifactId>opencsv</artifactId>
-               </dependency>
                <dependency>
                        <groupId>org.freemarker</groupId>
                        <artifactId>freemarker</artifactId>
index 7c65207..85c8766 100644 (file)
@@ -95,11 +95,6 @@ public class HttpEntry {
 
     private boolean processSingle = true;
 
-    private int paginationBucket = -1;
-    private int paginationIndex = -1;
-    private int totalVertices = 0;
-    private int totalPaginationBuckets = 0;
-
     @Autowired
     private NodeIngestor nodeIngestor;
 
@@ -178,132 +173,26 @@ public class HttpEntry {
         return this;
     }
 
-    /**
-     * Gets the introspector factory type.
-     *
-     * @return the introspector factory type
-     */
     public ModelType getIntrospectorFactoryType() {
         return introspectorFactoryType;
     }
 
-    /**
-     * Gets the query style.
-     *
-     * @return the query style
-     */
     public QueryStyle getQueryStyle() {
         return queryStyle;
     }
 
-    /**
-     * Gets the version.
-     *
-     * @return the version
-     */
     public SchemaVersion getVersion() {
         return version;
     }
 
-    /**
-     * Gets the loader.
-     *
-     * @return the loader
-     */
     public Loader getLoader() {
         return loader;
     }
 
-    /**
-     * Gets the db engine.
-     *
-     * @return the db engine
-     */
     public TransactionalGraphEngine getDbEngine() {
         return dbEngine;
     }
 
-    /**
-     * Checks the pagination bucket and pagination index variables to determine whether or not the user
-     * requested paginated results
-     *
-     * @return a boolean true/false of whether the user requested paginated results
-     */
-    public boolean isPaginated() {
-        return this.paginationBucket > -1 && this.paginationIndex > -1;
-    }
-
-    /**
-     * Returns the pagination size
-     *
-     * @return integer of the size of results to be returned when paginated
-     */
-    public int getPaginationBucket() {
-        return this.paginationBucket;
-    }
-
-    /**
-     * Setter for the pagination bucket variable which stores in this object the size of results to return
-     *
-     * @param pb
-     */
-    public void setPaginationBucket(int pb) {
-        this.paginationBucket = pb;
-    }
-
-    /**
-     * Getter to return the pagination index requested by the user when requesting paginated results
-     *
-     * @return
-     */
-    public int getPaginationIndex() {
-        return this.paginationIndex;
-    }
-
-    /**
-     * Sets the pagination index that was passed in by the user, to determine which index or results to retrieve when
-     * paginated
-     *
-     * @param pi
-     */
-    public void setPaginationIndex(int pi) {
-        if (pi == 0) {
-            pi = 1;
-        }
-        this.paginationIndex = pi;
-    }
-
-    /**
-     * Sets the total vertices variables and calculates the amount of pages based on size and total vertices
-     *
-     * @param totalVertices
-     * @param paginationBucketSize
-     */
-    public void setTotalsForPaging(int totalVertices, int paginationBucketSize) {
-        this.totalVertices = totalVertices;
-        // set total number of buckets equal to full pages
-        this.totalPaginationBuckets = totalVertices / paginationBucketSize;
-        // conditionally add a page for the remainder
-        if (totalVertices % paginationBucketSize > 0) {
-            this.totalPaginationBuckets++;
-        }
-    }
-
-    /**
-     * @return the total amount of pages
-     */
-    public int getTotalPaginationBuckets() {
-        return this.totalPaginationBuckets;
-    }
-
-    /**
-     *
-     * @return the total number of vertices when paginated
-     */
-    public int getTotalVertices() {
-        return this.totalVertices;
-    }
-
     public Pair<Boolean, List<Pair<URI, Response>>> process(List<DBRequest> requests, String sourceOfTruth) throws AAIException {
         return this.process(requests, sourceOfTruth, true);
     }
@@ -679,8 +568,10 @@ public class HttpEntry {
                     ) {
                         String myvertid = v.id().toString();
                         if (paginationResult != null && paginationResult.getTotalCount() != null) {
+                            long totalPages = getTotalPages(queryOptions, paginationResult);
                             response = Response.status(status).header("vertex-id", myvertid)
                                     .header("total-results", paginationResult.getTotalCount())
+                                    .header("total-pages", totalPages)
                                     .entity(result)
                                     .type(outputMediaType).build();
                         } else {
@@ -741,6 +632,17 @@ public class HttpEntry {
         return Pair.with(success, responses);
     }
 
+    private long getTotalPages(QueryOptions queryOptions, PaginationResult<Vertex> paginationResult) {
+        long totalCount = paginationResult.getTotalCount();
+        int pageSize = queryOptions.getPageable().getPageSize();
+        long totalPages = totalCount / pageSize;
+        // conditionally add a page for the remainder
+        if (totalCount % pageSize > 0) {
+            totalPages++;
+        }
+        return totalPages;
+    }
+
     private List<Vertex> executeQuery(QueryParser query, QueryOptions queryOptions) {
         return (queryOptions != null && queryOptions.getSort() != null)
             ? query.getQueryBuilder().sort(queryOptions.getSort()).toList()
@@ -1122,67 +1024,4 @@ public class HttpEntry {
             }
         }
     }
-
-    public void setPaginationParameters(String resultIndex, String resultSize) {
-        if (resultIndex != null && !"-1".equals(resultIndex) && resultSize != null && !"-1".equals(resultSize)) {
-            this.setPaginationIndex(Integer.parseInt(resultIndex));
-            this.setPaginationBucket(Integer.parseInt(resultSize));
-        }
-    }
-
-    @Deprecated
-    public List<Object> getPaginatedVertexListForAggregateFormat(List<Object> aggregateVertexList) throws AAIException {
-        List<Object> finalList = new Vector<>();
-        if (this.isPaginated()) {
-            if (aggregateVertexList != null && !aggregateVertexList.isEmpty()) {
-                int listSize = aggregateVertexList.size();
-                if (listSize == 1) {
-                    List<Object> vertexList = (List<Object>) aggregateVertexList.get(0);
-                    this.setTotalsForPaging(vertexList.size(), this.getPaginationBucket());
-                    int startIndex = (this.getPaginationIndex() - 1) * this.getPaginationBucket();
-                    int endIndex =
-                            Math.min((this.getPaginationBucket() * this.getPaginationIndex()), vertexList.size());
-                    if (startIndex > endIndex) {
-                        throw new AAIException("AAI_6150",
-                                " ResultIndex is not appropriate for the result set, Needs to be <= " + endIndex);
-                    }
-                    finalList.add(new ArrayList<Object>());
-                    for (int i = startIndex; i < endIndex; i++) {
-                        ((ArrayList<Object>) finalList.get(0))
-                                .add(((ArrayList<Object>) aggregateVertexList.get(0)).get(i));
-                    }
-                    return finalList;
-                }
-            }
-        }
-        // If the list size is greater than 1 or if pagination is not needed, return the original list.
-        return aggregateVertexList;
-    }
-
-    /**
-     * This method is used to paginate the vertex list based on the pagination index and bucket size
-     *
-     * @deprecated
-     * This method is no longer supported. Use {@link #process(List, String, Set, boolean, QueryOptions)} instead.
-     * @param vertexList
-     * @return
-     * @throws AAIException
-     */
-    @Deprecated
-    public List<Object> getPaginatedVertexList(List<Object> vertexList) throws AAIException {
-        List<Object> vertices;
-        if (this.isPaginated()) {
-            this.setTotalsForPaging(vertexList.size(), this.getPaginationBucket());
-            int startIndex = (this.getPaginationIndex() - 1) * this.getPaginationBucket();
-            int endIndex = Math.min((this.getPaginationBucket() * this.getPaginationIndex()), vertexList.size());
-            if (startIndex > endIndex) {
-                throw new AAIException("AAI_6150",
-                        " ResultIndex is not appropriate for the result set, Needs to be <= " + endIndex);
-            }
-            vertices = vertexList.subList(startIndex, endIndex);
-        } else {
-            vertices = vertexList;
-        }
-        return vertices;
-    }
 }
index 0dcec24..3bf991e 100644 (file)
@@ -319,8 +319,10 @@ public class HttpEntryTest extends AAISetup {
         Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, queryOptions);
         JSONObject actualResponseBody = new JSONObject(response.getEntity().toString());
         String totalCount = response.getHeaderString("total-results");
+        String totalPages = response.getHeaderString("total-pages");
 
         assertEquals(2, Integer.parseInt(totalCount));
+        assertEquals(2, Integer.parseInt(totalPages));
         assertEquals(1, actualResponseBody.getJSONArray("pserver").length());
         assertEquals("Expected the pservers to be returned", 200, response.getStatus());
         verify(validationService, times(1)).validate(any());
@@ -985,19 +987,6 @@ public class HttpEntryTest extends AAISetup {
         return responsesTuple.getValue1().get(0).getValue1();
     }
 
-    @Test
-    public void testSetGetPaginationMethods() {
-        traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
-        traversalHttpEntry.setPaginationBucket(10);
-        traversalHttpEntry.setPaginationIndex(1);
-        traversalHttpEntry.setTotalsForPaging(101, traversalHttpEntry.getPaginationBucket());
-        assertEquals("Expected the pagination bucket size to be 10", 10, traversalHttpEntry.getPaginationBucket());
-        assertEquals("Expected the total number of pagination buckets to be 11", 11,
-                traversalHttpEntry.getTotalPaginationBuckets());
-        assertEquals("Expected the pagination index to be 1", 1, traversalHttpEntry.getPaginationIndex());
-        assertEquals("Expected the total amount of vertices to be 101", 101, traversalHttpEntry.getTotalVertices());
-    }
-
     @Test
     public void setDepthTest() throws AAIException {
         System.setProperty("AJSC_HOME", ".");
index 9b2503b..1b48eb9 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
@@ -168,13 +168,17 @@ public class MDCSetup {
     }
 
     public void setElapsedTime() {
-        DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
-        ZonedDateTime entryTimestamp =
-                ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP), timeFormatter);
-        ZonedDateTime endTimestamp = ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter);
-
-        MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME,
-                Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp)));
+        String entryTimestampString = MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP);
+        String elapsedTime = "elapsedTimeIsNotAvailable";
+        if(entryTimestampString != null) {
+            DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
+            ZonedDateTime entryTimestamp =
+                    ZonedDateTime.parse(entryTimestampString, timeFormatter);
+            String logTimestamp = MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP);
+            ZonedDateTime endTimestamp = ZonedDateTime.parse(logTimestamp, timeFormatter);
+            elapsedTime = Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp));
+        }
+        MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, elapsedTime);
     }
 
     public void setElapsedTimeInvokeTimestamp() {
index 84b79a4..e86f101 100644 (file)
@@ -62,8 +62,8 @@ limitations under the License.
     <eelf.core.version>2.0.0-oss</eelf.core.version>
     <freemarker.version>2.3.31</freemarker.version>
     <google.guava.version>31.1-jre</google.guava.version>
-    <gremlin.version>3.4.0</gremlin.version>
-    <janusgraph.version>0.4.0</janusgraph.version>
+    <gremlin.version>3.4.13</gremlin.version>
+    <janusgraph.version>0.5.0</janusgraph.version>
     <groovy.version>2.5.15</groovy.version>
     <gson.version>2.9.1</gson.version>
     <hamcrest.junit.version>2.0.0.0</hamcrest.junit.version>
@@ -315,7 +315,7 @@ limitations under the License.
 
       <dependency>
         <groupId>org.janusgraph</groupId>
-        <artifactId>janusgraph-cassandra</artifactId>
+        <artifactId>janusgraph-cql</artifactId>
         <version>${janusgraph.version}</version>
       </dependency>
 
@@ -330,7 +330,7 @@ limitations under the License.
 
       <dependency>
         <groupId>org.janusgraph</groupId>
-        <artifactId>janusgraph-cql</artifactId>
+        <artifactId>janusgraph-inmemory</artifactId>
         <version>${janusgraph.version}</version>
       </dependency>
 
index a9dddc5..f4ed8db 100644 (file)
@@ -37,8 +37,6 @@
 
     <properties>
         <onap.nexus.url>https://nexus.onap.org</onap.nexus.url>
-        <spring.boot.starter.web.version>1.5.21.RELEASE</spring.boot.starter.web.version>
-        <spring.boot.starter.parent.version>1.5.21.RELEASE</spring.boot.starter.parent.version>
         <spring.security.version>1.0.8.RELEASE</spring.security.version>
     </properties>
 
diff --git a/aai-schema-ingest/.classpath b/aai-schema-ingest/.classpath
deleted file mode 100644 (file)
index 5811926..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-<?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"/>
-                       <attribute name="test" value="true"/>
-               </attributes>
-       </classpathentry>
-       <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
-               <attributes>
-                       <attribute name="maven.pomderived" value="true"/>
-                       <attribute name="test" value="true"/>
-                       <attribute name="optional" 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"/>
-                       <attribute name="optional" value="true"/>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="target/generated-sources/annotations">
-               <attributes>
-                       <attribute name="optional" value="true"/>
-                       <attribute name="maven.pomderived" value="true"/>
-                       <attribute name="ignore_optional_problems" value="true"/>
-                       <attribute name="m2e-apt" value="true"/>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
-               <attributes>
-                       <attribute name="optional" value="true"/>
-                       <attribute name="maven.pomderived" value="true"/>
-                       <attribute name="ignore_optional_problems" value="true"/>
-                       <attribute name="m2e-apt" value="true"/>
-                       <attribute name="test" value="true"/>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="output" path="target/classes"/>
-</classpath>
index 4ee8226..817e9f5 100644 (file)
@@ -127,6 +127,7 @@ limitations under the License.
                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-test</artifactId>
+                       <scope>test</scope>
                </dependency>
                <dependency>
                        <groupId>org.springframework.boot</groupId>