From 8881f4893dde5932e42bc7191efbde3e9dd1d6d3 Mon Sep 17 00:00:00 2001 From: jzonthemtn Date: Thu, 21 Mar 2024 18:09:11 -0400 Subject: [PATCH] Working on cassandra updates. --- entitydb-app/files/entitydb.properties | 23 +---- entitydb-app/files/run.sh | 22 +---- entitydb-app/pom.xml | 10 -- .../lifecycle/ContextClosingListener.java | 2 +- entitydb-data-store/pom.xml | 5 - .../entitydb-entity-store-cassandra/pom.xml | 24 ++--- .../cassandra/CassandraEntityStore.java | 93 ++++++++++--------- .../cassandra/CassandraEntityStoreTest.java | 7 +- entitydb-search/pom.xml | 11 --- pom.xml | 5 +- 10 files changed, 70 insertions(+), 132 deletions(-) diff --git a/entitydb-app/files/entitydb.properties b/entitydb-app/files/entitydb.properties index 8be0a57..3f74d34 100644 --- a/entitydb-app/files/entitydb.properties +++ b/entitydb-app/files/entitydb.properties @@ -1,24 +1,3 @@ -# -# Copyright 2024 Philterd, LLC -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# - # EntityDB configuration. # EntityDB's stack consists of several applications which can be configured in this file. @@ -149,4 +128,4 @@ metrics.influxdb.password= # General configuration options. mask.entity.acl=false -populate.test.data=true \ No newline at end of file +populate.test.data=true diff --git a/entitydb-app/files/run.sh b/entitydb-app/files/run.sh index 43c7d55..b85de5a 100644 --- a/entitydb-app/files/run.sh +++ b/entitydb-app/files/run.sh @@ -1,23 +1,3 @@ -#!/bin/sh -# -# Copyright 2024 Philterd, LLC -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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. -# +#!/bin/bash -e java -jar entitydb.jar diff --git a/entitydb-app/pom.xml b/entitydb-app/pom.xml index cb873d3..ddcefda 100644 --- a/entitydb-app/pom.xml +++ b/entitydb-app/pom.xml @@ -192,16 +192,6 @@ ai.philterd.entitydb entitydb-api ${project.version} - - - org.slf4j - log4j-over-slf4j - - - ch.qos.logback - logback-core - - org.springframework.boot diff --git a/entitydb-app/src/main/java/ai/philterd/entitydb/lifecycle/ContextClosingListener.java b/entitydb-app/src/main/java/ai/philterd/entitydb/lifecycle/ContextClosingListener.java index 9ec294a..ec1a1e1 100644 --- a/entitydb-app/src/main/java/ai/philterd/entitydb/lifecycle/ContextClosingListener.java +++ b/entitydb-app/src/main/java/ai/philterd/entitydb/lifecycle/ContextClosingListener.java @@ -42,7 +42,7 @@ public class ContextClosingListener implements ApplicationListenerjakarta.persistence-api 3.1.0 - - org.hibernate - hibernate-entitymanager - ${hibernate.entitymanager.version} - org.hibernate hibernate-core diff --git a/entitydb-entity-store/entitydb-entity-store-cassandra/pom.xml b/entitydb-entity-store/entitydb-entity-store-cassandra/pom.xml index 9b0f02a..d6115c4 100644 --- a/entitydb-entity-store/entitydb-entity-store-cassandra/pom.xml +++ b/entitydb-entity-store/entitydb-entity-store-cassandra/pom.xml @@ -32,6 +32,11 @@ entitydb-entity-store-cassandra entitydb-entity-store-cassandra + + ai.philterd.entitydb + entitydb-model + ${project.version} + org.apache.cassandra cassandra-all @@ -41,17 +46,21 @@ commons-codec commons-codec + + ch.qos.logback + logback + - com.datastax.cassandra - cassandra-driver-core - ${cassandra.datastax.version} + com.datastax.oss + java-driver-core + 4.17.0 com.datastax.cassandra cassandra-driver-mapping - ${cassandra.datastax.version} + 3.11.5 ai.philterd.entitydb @@ -97,13 +106,6 @@ ${junit.version} test - - ai.philterd.entitydb - entitydb-model - ${project.version} - test-jar - test - ai.philterd.entitydb entitydb-testing diff --git a/entitydb-entity-store/entitydb-entity-store-cassandra/src/main/java/ai/philterd/entitydb/entitystore/cassandra/CassandraEntityStore.java b/entitydb-entity-store/entitydb-entity-store-cassandra/src/main/java/ai/philterd/entitydb/entitystore/cassandra/CassandraEntityStore.java index a9b2519..aa5d094 100644 --- a/entitydb-entity-store/entitydb-entity-store-cassandra/src/main/java/ai/philterd/entitydb/entitystore/cassandra/CassandraEntityStore.java +++ b/entitydb-entity-store/entitydb-entity-store-cassandra/src/main/java/ai/philterd/entitydb/entitystore/cassandra/CassandraEntityStore.java @@ -20,15 +20,34 @@ */ package ai.philterd.entitydb.entitystore.cassandra; -import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker; -import static com.datastax.driver.core.querybuilder.QueryBuilder.contains; -import static com.datastax.driver.core.querybuilder.QueryBuilder.containsKey; -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; -import static com.datastax.driver.core.querybuilder.QueryBuilder.gte; -import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; -import static com.datastax.driver.core.querybuilder.QueryBuilder.lte; -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; -import static com.datastax.driver.core.querybuilder.QueryBuilder.set; +import ai.philterd.entitydb.entitystore.cassandra.model.CassandraStoredEntity; +import ai.philterd.entitydb.model.entity.Entity; +import ai.philterd.entitydb.model.entitystore.EntityIdGenerator; +import ai.philterd.entitydb.model.entitystore.EntityStore; +import ai.philterd.entitydb.model.entitystore.QueryResult; +import ai.philterd.entitydb.model.eql.EntityMetadataFilter; +import ai.philterd.entitydb.model.eql.EntityQuery; +import ai.philterd.entitydb.model.exceptions.EntityStoreException; +import ai.philterd.entitydb.model.exceptions.MalformedAclException; +import ai.philterd.entitydb.model.exceptions.NonexistantEntityException; +import ai.philterd.entitydb.model.search.IndexedEntity; +import com.datastax.driver.core.BatchStatement; +import com.datastax.driver.core.BoundStatement; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.PreparedStatement; +import com.datastax.driver.core.QueryOptions; +import com.datastax.driver.core.Statement; +import com.datastax.driver.core.querybuilder.QueryBuilder; +import com.datastax.driver.core.querybuilder.Select; +import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.CqlSession; +import com.datastax.oss.driver.api.core.cql.ResultSet; +import com.datastax.oss.driver.api.core.cql.Row; +import com.datastax.oss.driver.api.core.cql.SimpleStatement; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collection; import java.util.Date; @@ -40,33 +59,15 @@ import java.util.Set; import java.util.UUID; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.datastax.driver.core.BatchStatement; -import com.datastax.driver.core.BoundStatement; -import com.datastax.driver.core.Cluster; -import com.datastax.driver.core.PreparedStatement; -import com.datastax.driver.core.QueryOptions; -import com.datastax.driver.core.ResultSet; -import com.datastax.driver.core.Row; -import com.datastax.driver.core.Session; -import com.datastax.driver.core.Statement; -import com.datastax.driver.core.querybuilder.QueryBuilder; -import com.datastax.driver.core.querybuilder.Select; -import ai.philterd.entitydb.model.entity.Entity; -import ai.philterd.entitydb.entitystore.cassandra.model.CassandraStoredEntity; -import ai.philterd.entitydb.model.eql.EntityMetadataFilter; -import ai.philterd.entitydb.model.eql.EntityQuery; -import ai.philterd.entitydb.model.entitystore.EntityIdGenerator; -import ai.philterd.entitydb.model.entitystore.EntityStore; -import ai.philterd.entitydb.model.entitystore.QueryResult; -import ai.philterd.entitydb.model.exceptions.EntityStoreException; -import ai.philterd.entitydb.model.exceptions.MalformedAclException; -import ai.philterd.entitydb.model.exceptions.NonexistantEntityException; -import ai.philterd.entitydb.model.search.IndexedEntity; +import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker; +import static com.datastax.driver.core.querybuilder.QueryBuilder.contains; +import static com.datastax.driver.core.querybuilder.QueryBuilder.containsKey; +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; +import static com.datastax.driver.core.querybuilder.QueryBuilder.gte; +import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; +import static com.datastax.driver.core.querybuilder.QueryBuilder.lte; +import static com.datastax.driver.core.querybuilder.QueryBuilder.select; +import static com.datastax.driver.core.querybuilder.QueryBuilder.set; /** * Implementation of {@link EntityStore} that uses a Cassandra database. @@ -86,7 +87,7 @@ public class CassandraEntityStore implements EntityStore private final String host; private final String keySpace; - private final Session session; + private final CqlSession session; /** * Creates a Cassandra entity store. @@ -103,9 +104,9 @@ public CassandraEntityStore(String host, int port, String keySpace) { .addContactPoint(host) .withPort(port) .withQueryOptions(new QueryOptions().setFetchSize(DEFAULT_PAGE_SIZE)) - .build(); - - this.session = cluster.connect(keySpace); + .build(); + + this.session = CqlSession.builder().build(); } @@ -114,9 +115,9 @@ public CassandraEntityStore(String host, int port, String keySpace) { * @param session The pre-existing Cassandra session. * @param keySpace The Cassandra keyspace. */ - public CassandraEntityStore(Session session, String keySpace) { + public CassandraEntityStore(CqlSession session, String keySpace) { - this.host = session.getCluster().getClusterName(); + this.host = session.getContext().getSessionName(); this.keySpace = keySpace; this.session = session; @@ -135,11 +136,13 @@ public String getStatus() { public List getNonIndexedEntities(int limit) { // We can NOT allow filtering here because this query WILL be run. - // The "indexed" column is indexed but we can only use one index. + // The "indexed" column is indexed, but we can only use one index. // Because of being restricted to a single index, the "visible" // column is checked on each returned entity and not in the query. // That's why the "visible" condition is commented out in the below query. + final SimpleStatement simpleStatement = SimpleStatement.newInstance("SELECT * FROM my_table WHERE id = 1").setKeyspace(CqlIdentifier.fromCql("my_keyspace")); + final Select select = QueryBuilder.select() .all() .from(keySpace, TABLE_NAME) @@ -147,7 +150,7 @@ public List getNonIndexedEntities(int limit) { //.and(eq("visible", Long.valueOf(1))) .limit(limit); - final ResultSet resultSet = session.execute(select); + final ResultSet resultSet = session.execute(simpleStatement); final List cassandraStoredEntities = new LinkedList(); @@ -155,7 +158,7 @@ public List getNonIndexedEntities(int limit) { while(iterator.hasNext()) { - Row row = iterator.next(); + final Row row = iterator.next(); CassandraStoredEntity cassandraStoredEntity = rowToEntity(row); diff --git a/entitydb-entity-store/entitydb-entity-store-cassandra/src/test/java/ai/philterd/test/entitydb/entitystore/cassandra/CassandraEntityStoreTest.java b/entitydb-entity-store/entitydb-entity-store-cassandra/src/test/java/ai/philterd/test/entitydb/entitystore/cassandra/CassandraEntityStoreTest.java index bfd425e..0866859 100644 --- a/entitydb-entity-store/entitydb-entity-store-cassandra/src/test/java/ai/philterd/test/entitydb/entitystore/cassandra/CassandraEntityStoreTest.java +++ b/entitydb-entity-store/entitydb-entity-store-cassandra/src/test/java/ai/philterd/test/entitydb/entitystore/cassandra/CassandraEntityStoreTest.java @@ -20,6 +20,7 @@ */ package ai.philterd.test.entitydb.entitystore.cassandra; +import com.datastax.oss.driver.api.core.CqlSession; import org.cassandraunit.CassandraCQLUnit; import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; import org.junit.Ignore; @@ -41,10 +42,10 @@ public class CassandraEntityStoreTest extends AbstractEntityStoreTest getEntityStore() throws EntityStoreException { + public EntityStore getEntityStore() { - Session session = embeddedCassandra.getSession(); - CassandraEntityStore cassandraEntityStore = new CassandraEntityStore(session, KEYSPACE); + final CqlSession session = embeddedCassandra.getSession(); + final CassandraEntityStore cassandraEntityStore = new CassandraEntityStore(session, KEYSPACE); return cassandraEntityStore; diff --git a/entitydb-search/pom.xml b/entitydb-search/pom.xml index d0c9f3f..280005c 100644 --- a/entitydb-search/pom.xml +++ b/entitydb-search/pom.xml @@ -44,12 +44,6 @@ ai.philterd.entitydb entitydb-model ${project.version} - - - commons-logging - commons-logging - - org.apache.commons @@ -76,11 +70,6 @@ jest ${jest.version} - - commons-logging - commons-logging - 1.2 - org.apache.logging.log4j log4j-core diff --git a/pom.xml b/pom.xml index a503c05..5ee191e 100644 --- a/pom.xml +++ b/pom.xml @@ -56,9 +56,8 @@ 4.13.1 1.9.21.2 1.12.683 - 3.7 - 3.1.0 - 3.0.0.1 + 4.1.4 + 4.3.1.0 1.6.0 1.16.1 4.4