mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-28 09:56:22 +02:00
Fixing more Cassandra consistency issues (#488)
* Fixing more Cassandra work * Fix tests
This commit is contained in:
parent
ccaec88a72
commit
85e669c763
23 changed files with 196 additions and 208 deletions
|
|
@ -21,12 +21,12 @@ from strawberry.tools import create_type
|
|||
from .... schema import ObjectsQueryRequest, ObjectsQueryResponse, GraphQLError
|
||||
from .... schema import Error, RowSchema, Field as SchemaField
|
||||
from .... base import FlowProcessor, ConsumerSpec, ProducerSpec
|
||||
from .... base.cassandra_config import add_cassandra_args, resolve_cassandra_config
|
||||
|
||||
# Module logger
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
default_ident = "objects-query"
|
||||
default_graph_host = 'localhost'
|
||||
|
||||
# GraphQL filter input types
|
||||
@strawberry.input
|
||||
|
|
@ -68,10 +68,22 @@ class Processor(FlowProcessor):
|
|||
|
||||
id = params.get("id", default_ident)
|
||||
|
||||
# Cassandra connection parameters
|
||||
self.graph_host = params.get("graph_host", default_graph_host)
|
||||
self.graph_username = params.get("graph_username", None)
|
||||
self.graph_password = params.get("graph_password", None)
|
||||
# Get Cassandra parameters
|
||||
cassandra_host = params.get("cassandra_host")
|
||||
cassandra_username = params.get("cassandra_username")
|
||||
cassandra_password = params.get("cassandra_password")
|
||||
|
||||
# Resolve configuration with environment variable fallback
|
||||
hosts, username, password = resolve_cassandra_config(
|
||||
host=cassandra_host,
|
||||
username=cassandra_username,
|
||||
password=cassandra_password
|
||||
)
|
||||
|
||||
# Store resolved configuration with proper names
|
||||
self.cassandra_host = hosts # Store as list
|
||||
self.cassandra_username = username
|
||||
self.cassandra_password = password
|
||||
|
||||
# Config key for schemas
|
||||
self.config_key = params.get("config_type", "schema")
|
||||
|
|
@ -124,20 +136,20 @@ class Processor(FlowProcessor):
|
|||
return
|
||||
|
||||
try:
|
||||
if self.graph_username and self.graph_password:
|
||||
if self.cassandra_username and self.cassandra_password:
|
||||
auth_provider = PlainTextAuthProvider(
|
||||
username=self.graph_username,
|
||||
password=self.graph_password
|
||||
username=self.cassandra_username,
|
||||
password=self.cassandra_password
|
||||
)
|
||||
self.cluster = Cluster(
|
||||
contact_points=[self.graph_host],
|
||||
contact_points=self.cassandra_host,
|
||||
auth_provider=auth_provider
|
||||
)
|
||||
else:
|
||||
self.cluster = Cluster(contact_points=[self.graph_host])
|
||||
self.cluster = Cluster(contact_points=self.cassandra_host)
|
||||
|
||||
self.session = self.cluster.connect()
|
||||
logger.info(f"Connected to Cassandra cluster at {self.graph_host}")
|
||||
logger.info(f"Connected to Cassandra cluster at {self.cassandra_host}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to connect to Cassandra: {e}", exc_info=True)
|
||||
|
|
@ -712,24 +724,7 @@ class Processor(FlowProcessor):
|
|||
"""Add command-line arguments"""
|
||||
|
||||
FlowProcessor.add_args(parser)
|
||||
|
||||
parser.add_argument(
|
||||
'-g', '--graph-host',
|
||||
default=default_graph_host,
|
||||
help=f'Cassandra host (default: {default_graph_host})'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--graph-username',
|
||||
default=None,
|
||||
help='Cassandra username'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--graph-password',
|
||||
default=None,
|
||||
help='Cassandra password'
|
||||
)
|
||||
add_cassandra_args(parser)
|
||||
|
||||
parser.add_argument(
|
||||
'--config-type',
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@ class Processor(TriplesQueryService):
|
|||
|
||||
def __init__(self, **params):
|
||||
|
||||
# Use new parameter names, fall back to old for compatibility
|
||||
cassandra_host = params.get("cassandra_host", params.get("graph_host"))
|
||||
cassandra_username = params.get("cassandra_username", params.get("graph_username"))
|
||||
cassandra_password = params.get("cassandra_password", params.get("graph_password"))
|
||||
# Get Cassandra parameters
|
||||
cassandra_host = params.get("cassandra_host")
|
||||
cassandra_username = params.get("cassandra_username")
|
||||
cassandra_password = params.get("cassandra_password")
|
||||
|
||||
# Resolve configuration with environment variable fallback
|
||||
hosts, username, password = resolve_cassandra_config(
|
||||
|
|
@ -41,9 +41,9 @@ class Processor(TriplesQueryService):
|
|||
}
|
||||
)
|
||||
|
||||
self.graph_host = hosts
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.cassandra_host = hosts
|
||||
self.cassandra_username = username
|
||||
self.cassandra_password = password
|
||||
self.table = None
|
||||
|
||||
def create_value(self, ent):
|
||||
|
|
@ -59,15 +59,15 @@ class Processor(TriplesQueryService):
|
|||
table = (query.user, query.collection)
|
||||
|
||||
if table != self.table:
|
||||
if self.username and self.password:
|
||||
if self.cassandra_username and self.cassandra_password:
|
||||
self.tg = TrustGraph(
|
||||
hosts=self.graph_host,
|
||||
hosts=self.cassandra_host,
|
||||
keyspace=query.user, table=query.collection,
|
||||
username=self.username, password=self.password
|
||||
username=self.cassandra_username, password=self.cassandra_password
|
||||
)
|
||||
else:
|
||||
self.tg = TrustGraph(
|
||||
hosts=self.graph_host,
|
||||
hosts=self.cassandra_host,
|
||||
keyspace=query.user, table=query.collection,
|
||||
)
|
||||
self.table = table
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue