From 037c33e49b202218261b474439def75d508717f4 Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Wed, 26 Jun 2024 14:12:55 +0200 Subject: Update Janusgraph to 0.5.0 in aai-common - 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 --- aai-core/pom.xml | 13 +- .../main/java/org/onap/aai/rest/db/HttpEntry.java | 187 ++------------------- .../java/org/onap/aai/rest/db/HttpEntryTest.java | 15 +- .../org/onap/logging/filter/base/MDCSetup.java | 22 ++- aai-parent/pom.xml | 8 +- aai-rest/pom.xml | 2 - aai-schema-ingest/.classpath | 57 ------- aai-schema-ingest/pom.xml | 1 + 8 files changed, 38 insertions(+), 267 deletions(-) delete mode 100644 aai-schema-ingest/.classpath diff --git a/aai-core/pom.xml b/aai-core/pom.xml index 30820d80..cd78bff2 100644 --- a/aai-core/pom.xml +++ b/aai-core/pom.xml @@ -197,6 +197,11 @@ limitations under the License. + + org.janusgraph + janusgraph-inmemory + test + com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider @@ -281,10 +286,6 @@ limitations under the License. xml-apis 1.4.01 - - com.beust - jcommander - org.json json @@ -313,10 +314,6 @@ limitations under the License. org.apache.activemq activemq-openwire-legacy - - com.opencsv - opencsv - org.freemarker freemarker diff --git a/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java b/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java index 7c652079..85c87667 100644 --- a/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java +++ b/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java @@ -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>> process(List 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 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 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 getPaginatedVertexListForAggregateFormat(List aggregateVertexList) throws AAIException { - List finalList = new Vector<>(); - if (this.isPaginated()) { - if (aggregateVertexList != null && !aggregateVertexList.isEmpty()) { - int listSize = aggregateVertexList.size(); - if (listSize == 1) { - List vertexList = (List) 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()); - for (int i = startIndex; i < endIndex; i++) { - ((ArrayList) finalList.get(0)) - .add(((ArrayList) 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 getPaginatedVertexList(List vertexList) throws AAIException { - List 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; - } } diff --git a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java index 0dcec24d..3bf991ec 100644 --- a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java +++ b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java @@ -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", "."); diff --git a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MDCSetup.java b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MDCSetup.java index 9b2503b7..1b48eb9b 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MDCSetup.java +++ b/aai-els-onap-logging/src/main/java/org/onap/logging/filter/base/MDCSetup.java @@ -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() { diff --git a/aai-parent/pom.xml b/aai-parent/pom.xml index 84b79a4a..e86f1012 100644 --- a/aai-parent/pom.xml +++ b/aai-parent/pom.xml @@ -62,8 +62,8 @@ limitations under the License. 2.0.0-oss 2.3.31 31.1-jre - 3.4.0 - 0.4.0 + 3.4.13 + 0.5.0 2.5.15 2.9.1 2.0.0.0 @@ -315,7 +315,7 @@ limitations under the License. org.janusgraph - janusgraph-cassandra + janusgraph-cql ${janusgraph.version} @@ -330,7 +330,7 @@ limitations under the License. org.janusgraph - janusgraph-cql + janusgraph-inmemory ${janusgraph.version} diff --git a/aai-rest/pom.xml b/aai-rest/pom.xml index a9dddc51..f4ed8dbd 100644 --- a/aai-rest/pom.xml +++ b/aai-rest/pom.xml @@ -37,8 +37,6 @@ https://nexus.onap.org - 1.5.21.RELEASE - 1.5.21.RELEASE 1.0.8.RELEASE diff --git a/aai-schema-ingest/.classpath b/aai-schema-ingest/.classpath deleted file mode 100644 index 5811926a..00000000 --- a/aai-schema-ingest/.classpath +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/aai-schema-ingest/pom.xml b/aai-schema-ingest/pom.xml index 4ee8226e..817e9f51 100644 --- a/aai-schema-ingest/pom.xml +++ b/aai-schema-ingest/pom.xml @@ -127,6 +127,7 @@ limitations under the License. org.springframework spring-test + test org.springframework.boot -- cgit 1.2.3-korg