Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Working on cassandra updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Mar 21, 2024
1 parent b3698dd commit 8881f48
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 132 deletions.
23 changes: 1 addition & 22 deletions entitydb-app/files/entitydb.properties
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -149,4 +128,4 @@ metrics.influxdb.password=

# General configuration options.
mask.entity.acl=false
populate.test.data=true
populate.test.data=true
22 changes: 1 addition & 21 deletions entitydb-app/files/run.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions entitydb-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,6 @@
<groupId>ai.philterd.entitydb</groupId>
<artifactId>entitydb-api</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ContextClosingListener implements ApplicationListener<ContextClosed
private AuditLogger auditLogger;

@Override
public void onApplicationEvent(ContextClosedEvent arg0) {
public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {

// Gracefully stop things.
queueConsumer.shutdown();
Expand Down
5 changes: 0 additions & 5 deletions entitydb-data-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.entitymanager.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
Expand Down
24 changes: 13 additions & 11 deletions entitydb-entity-store/entitydb-entity-store-cassandra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<artifactId>entitydb-entity-store-cassandra</artifactId>
<name>entitydb-entity-store-cassandra</name>
<dependencies>
<dependency>
<groupId>ai.philterd.entitydb</groupId>
<artifactId>entitydb-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
Expand All @@ -41,17 +46,21 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>${cassandra.datastax.version}</version>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
<version>4.17.0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>${cassandra.datastax.version}</version>
<version>3.11.5</version>
</dependency>
<dependency>
<groupId>ai.philterd.entitydb</groupId>
Expand Down Expand Up @@ -97,13 +106,6 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ai.philterd.entitydb</groupId>
<artifactId>entitydb-model</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ai.philterd.entitydb</groupId>
<artifactId>entitydb-testing</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -86,7 +87,7 @@ public class CassandraEntityStore implements EntityStore<CassandraStoredEntity>

private final String host;
private final String keySpace;
private final Session session;
private final CqlSession session;

/**
* Creates a Cassandra entity store.
Expand All @@ -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();

}

Expand All @@ -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;

Expand All @@ -135,27 +136,29 @@ public String getStatus() {
public List<CassandraStoredEntity> 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)
.where(eq("indexed", Long.valueOf(0)))
//.and(eq("visible", Long.valueOf(1)))
.limit(limit);

final ResultSet resultSet = session.execute(select);
final ResultSet resultSet = session.execute(simpleStatement);

final List<CassandraStoredEntity> cassandraStoredEntities = new LinkedList<CassandraStoredEntity>();

final Iterator<Row> iterator = resultSet.iterator();

while(iterator.hasNext()) {

Row row = iterator.next();
final Row row = iterator.next();

CassandraStoredEntity cassandraStoredEntity = rowToEntity(row);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,10 +42,10 @@ public class CassandraEntityStoreTest extends AbstractEntityStoreTest<CassandraS
public CassandraCQLUnit embeddedCassandra = new CassandraCQLUnit(new ClassPathCQLDataSet("entitydb.cql", KEYSPACE), null, 120000, 120000);

@Override
public EntityStore<CassandraStoredEntity> getEntityStore() throws EntityStoreException {
public EntityStore<CassandraStoredEntity> 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;

Expand Down
11 changes: 0 additions & 11 deletions entitydb-search/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
<groupId>ai.philterd.entitydb</groupId>
<artifactId>entitydb-model</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand All @@ -76,11 +70,6 @@
<artifactId>jest</artifactId>
<version>${jest.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
Expand Down
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@
<antlr.version>4.13.1</antlr.version>
<aspectjweaver.version>1.9.21.2</aspectjweaver.version>
<aws.sdk.version>1.12.683</aws.sdk.version>
<cassandra.version>3.7</cassandra.version>
<cassandra.datastax.version>3.1.0</cassandra.datastax.version>
<cassandra.unit.version>3.0.0.1</cassandra.unit.version>
<cassandra.version>4.1.4</cassandra.version>
<cassandra.unit.version>4.3.1.0</cassandra.unit.version>
<commons.cli.version>1.6.0</commons.cli.version>
<commons.codec.version>1.16.1</commons.codec.version>
<commons.collections.version>4.4</commons.collections.version>
Expand Down

0 comments on commit 8881f48

Please sign in to comment.