Skip to content

Unified Cassandra Utility Module#164

Merged
pallakartheekreddy merged 23 commits intodevelopfrom
cassandra_utils
Jan 28, 2026
Merged

Unified Cassandra Utility Module#164
pallakartheekreddy merged 23 commits intodevelopfrom
cassandra_utils

Conversation

@chethann007
Copy link
Contributor

Summary

Re-architected and rewrote the Cassandra utility layer into a single, unified core/sunbird-cassandra-utils module. This new implementation consolidates disparate Cassandra handling logic from across all microservices into one central library.

Key Changes

  • New Core Module: Created core/sunbird-cassandra-utils as the single source of truth for all Cassandra operations.
  • Code Rewrite: Completely rewrote Cassandra utility classes (CassandraOperationImpl, CassandraDACImpl) to be generic and reusable across the entire platform.
  • Cleanup: Removed the legacy cassandra-utils module and refactored all dependent services (Actors, DAOs) to use the new unified implementation.
  • Enhanced Observability: Built-in standard INFO-level logging for all database interactions (keyspace, table, query details) to improve debuggability.

Impact

Eliminates code duplication across microservices, enforces a standardized database access pattern, and simplifies future maintenance and upgrades.

- Remove the deprecated Cassandra utility files from the root `cassandra-utils`.
- These have been superseded by the core/sunbird-cassandra-utils module, which serves as the central library for Cassandra operations.
…il` to `org.sunbird.logging.LoggerUtil` across multiple files
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
10.9% Duplication on New Code (required ≤ 3%)
B Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR consolidates Cassandra access into a new unified core/sunbird-cassandra-utils module, removes the legacy cassandra-utils module, and updates services to use the new shared Cassandra + logging utilities.

Changes:

  • Introduced new core libraries: core/sunbird-cassandra-utils (Cassandra operations + connection management) and core/sunbird-platform-common (logging + common keys/exceptions).
  • Refactored service/actor/SDK code to use org.sunbird.logging.LoggerUtil and the new Cassandra APIs (notably RequestContext-based context passing).
  • Removed legacy cassandra-utils module and updated Maven reactor/module dependencies accordingly.

Reviewed changes

Copilot reviewed 100 out of 101 changed files in this pull request and generated 39 comments.

Show a summary per file
File Description
service/test/validators/TemplateActionUpdateRequestValidatorTest.java Updated LoggerUtil import to new shared logging package.
service/app/validators/TemplateUpdateRequestValidator.java Updated LoggerUtil import to new shared logging package.
service/app/validators/TemplateRequestValidator.java Updated LoggerUtil import to new shared logging package.
service/app/validators/TemplateActionUpdateRequestValidator.java Updated LoggerUtil import to new shared logging package.
service/app/validators/RequestValidator.java Updated LoggerUtil import to new shared logging package.
service/app/utils/module/SignalHandler.java Updated LoggerUtil import to new shared logging package.
service/app/utils/module/OnRequestHandler.java Updated LoggerUtil import to new shared logging package.
service/app/utils/ValidationUtil.java Updated LoggerUtil import to new shared logging package.
service/app/utils/RequestMapper.java Updated LoggerUtil import to new shared logging package.
service/app/utils/PrintEntryExitLog.java Updated LoggerUtil import to new shared logging package.
service/app/utils/ApplicationStart.java Updated LoggerUtil import to new shared logging package.
service/app/controllers/notification/NotificationTemplateController.java Updated LoggerUtil import to new shared logging package.
service/app/controllers/notification/NotificationController.java Updated LoggerUtil import to new shared logging package.
service/app/controllers/health/HealthController.java Updated LoggerUtil import to new shared logging package.
service/app/controllers/BaseController.java Updated LoggerUtil import to new shared logging package.
sb-utils/src/main/java/org/sunbird/utils/PropertiesCache.java Migrated to new LoggerUtil API shape (context-first).
sb-utils/src/main/java/org/sunbird/utils/HttpClientUtil.java Updated LoggerUtil import to new shared logging package.
sb-utils/src/main/java/org.sunbird/request/LoggerUtil.java Removed legacy LoggerUtil implementation from sb-utils.
sb-utils/src/main/java/org.sunbird/auth/verifier/KeyManager.java Updated LoggerUtil import to new shared logging package.
sb-utils/src/main/java/org.sunbird/auth/verifier/AccessTokenValidator.java Updated LoggerUtil import to new shared logging package.
sb-utils/pom.xml Added dependency on sunbird-platform-common for shared logging.
sb-telemetry-utils/pom.xml Reworked module POM to be standalone (groupId/version/properties).
sb-common/src/main/java/org/sunbird/common/request/RequestContext.java Extended RequestContext with fields needed for structured logging.
sb-common/pom.xml Reworked module POM to be standalone (groupId/version/properties).
pom.xml Updated Maven reactor modules to include new core modules and remove legacy cassandra-utils.
notification-sdk/src/main/java/org/sunbird/notification/utils/Util.java Updated LoggerUtil import + updated call signature to include context argument.
notification-sdk/src/main/java/org/sunbird/notification/utils/JsonUtil.java Updated LoggerUtil import to new shared logging package.
notification-sdk/src/main/java/org/sunbird/notification/sms/providerimpl/Msg91SmsProviderImpl.java Updated LoggerUtil import to new shared logging package.
notification-sdk/src/main/java/org/sunbird/notification/fcm/providerImpl/FCMNotificationServiceImpl.java Updated LoggerUtil import to new shared logging package.
notification-sdk/src/main/java/org/sunbird/notification/fcm/providerImpl/FCMHttpNotificationServiceImpl.java Updated LoggerUtil import to new shared logging package.
notification-sdk/src/main/java/org/sunbird/notification/fcm/provider/NotificationFactory.java Updated LoggerUtil import to new shared logging package.
notification-sdk/src/main/java/org/sunbird/notification/email/service/impl/SmtpEMailServiceImpl.java Updated LoggerUtil import to new shared logging package.
notification-sdk/src/main/java/org/sunbird/notification/email/Email.java Updated LoggerUtil import to new shared logging package.
core/sunbird-platform-common/src/main/java/org/sunbird/logging/LoggerUtil.java Added new structured logging utility with RequestContext + telemetry integration.
core/sunbird-platform-common/src/main/java/org/sunbird/logging/CustomLogFormat.java Added structured log event builder for consistent JSON log shape.
core/sunbird-platform-common/src/main/java/org/sunbird/keys/JsonKey.java Added shared platform constants used across modules.
core/sunbird-platform-common/src/main/java/org/sunbird/exception/ResponseMessage.java Added shared response message constants.
core/sunbird-platform-common/src/main/java/org/sunbird/exception/ResponseCode.java Added shared response code enum (HTTP + domain codes).
core/sunbird-platform-common/src/main/java/org/sunbird/exception/ProjectCommonException.java Added shared exception type for platform-wide error handling.
core/sunbird-platform-common/pom.xml Introduced new platform-common module build/deps.
core/sunbird-cassandra-utils/src/main/resources/cassandratablecolumn.properties Added consolidated Cassandra column↔property mapping.
core/sunbird-cassandra-utils/src/main/resources/cassandra.config.properties Updated Cassandra config defaults and annotations.
core/sunbird-cassandra-utils/src/main/java/org/sunbird/helper/ServiceFactory.java Added singleton factory for CassandraOperation.
core/sunbird-cassandra-utils/src/main/java/org/sunbird/helper/CassandraConnectionMngrFactory.java Added singleton factory for CassandraConnectionManager.
core/sunbird-cassandra-utils/src/main/java/org/sunbird/helper/CassandraConnectionManagerImpl.java Added Cassandra cluster/session manager implementation.
core/sunbird-cassandra-utils/src/main/java/org/sunbird/helper/CassandraConnectionManager.java Added Cassandra connection manager interface.
core/sunbird-cassandra-utils/src/main/java/org/sunbird/common/Constants.java Added shared constants for cassandra-utils module.
core/sunbird-cassandra-utils/src/main/java/org/sunbird/common/CassandraUtil.java Added unified Cassandra query/response helper utilities.
core/sunbird-cassandra-utils/src/main/java/org/sunbird/common/CassandraPropertyReader.java Added unified property reader for mapping + config.
core/sunbird-cassandra-utils/src/main/java/org/sunbird/cassandraimpl/CassandraDACImpl.java Added rewritten Cassandra DAC implementation (including async ops).
core/sunbird-cassandra-utils/src/main/java/org/sunbird/cassandraannotation/PartitioningKey.java Updated annotation docs.
core/sunbird-cassandra-utils/src/main/java/org/sunbird/cassandraannotation/ClusteringKey.java Updated annotation docs.
core/sunbird-cassandra-utils/pom.xml Introduced new cassandra-utils module build/deps.
cassandra-utils/src/test/resources/cassandra.cql Removed legacy cassandra-utils test resources.
cassandra-utils/src/test/java/org/sunbird/cassandraimpl/CassandraOperationImplTest.java Removed legacy cassandra-utils tests.
cassandra-utils/src/test/java/org/sunbird/cassandra/ConnectionManagerTest.java Removed legacy cassandra-utils tests.
cassandra-utils/src/test/java/org/sunbird/cassandra/CassandraTest.java Removed legacy cassandra-utils tests.
cassandra-utils/src/test/java/org/sunbird/cassandra/CassandraStandaloneTest.java Removed legacy cassandra-utils tests.
cassandra-utils/src/main/java/org/sunbird/utils/ServiceFactory.java Removed legacy cassandra-utils ServiceFactory.
cassandra-utils/src/main/java/org/sunbird/utils/CassandraPropertyReader.java Removed legacy cassandra-utils property reader.
cassandra-utils/src/main/java/org/sunbird/utils/CassandraConnectionMngrFactory.java Removed legacy cassandra-utils connection factory.
cassandra-utils/src/main/java/org/sunbird/utils/CassandraConnectionManagerImpl.java Removed legacy cassandra-utils connection manager.
cassandra-utils/src/main/java/org/sunbird/utils/CassandraConnectionManager.java Removed legacy cassandra-utils interface.
cassandra-utils/src/main/java/org/sunbird/common/Constants.java Removed legacy cassandra-utils constants.
cassandra-utils/src/main/java/org/sunbird/common/CassandraUtil.java Removed legacy cassandra-utils util class.
cassandra-utils/src/main/java/org/sunbird/cassandraimpl/CassandraDACImpl.java Removed legacy cassandra-utils DAC implementation.
cassandra-utils/src/main/java/org/sunbird/cassandra/CassandraOperation.java Removed legacy cassandra-utils API interface.
cassandra-utils/pom.xml Removed legacy cassandra-utils Maven module.
all-actors/src/test/java/org/sunbird/notification/actor/UpdateNotificationActorTest.java Updated ServiceFactory import + mocks for RequestContext-based methods.
all-actors/src/test/java/org/sunbird/notification/actor/ReadNotificationActorTest.java Updated ServiceFactory import + mocks for RequestContext-based methods.
all-actors/src/test/java/org/sunbird/notification/actor/NotificationTemplateActorTest.java Updated ServiceFactory import + adjusted mocks for new CassandraOperation signatures.
all-actors/src/test/java/org/sunbird/notification/actor/DeleteNotificationActorTest.java Updated ServiceFactory import + mocks for RequestContext-based methods.
all-actors/src/test/java/org/sunbird/notification/actor/CreateNotificationActorTest.java Updated ServiceFactory import + mocks for RequestContext-based methods.
all-actors/src/main/java/org/sunbird/util/kafka/KafkaClient.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/util/SystemConfigUtil.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/util/DataHash.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/util/DBUtil.java Updated Cassandra connection imports to new helper package.
all-actors/src/main/java/org/sunbird/util/ConfigUtil.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/service/UserServiceImpl.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/service/TemplateServiceImpl.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/service/NotificationServiceImpl.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/notification/handler/PhoneNotificationHandler.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/notification/handler/FeedNotificationHandler.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/notification/handler/EmailNotificationHandler.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/notification/handler/DeviceNotificationHandler.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/notification/dispatcher/impl/FCMNotificationDispatcher.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/notification/dispatcher/NotificationRouter.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/notification/actor/UpdateNotificationActor.java Updated LoggerUtil usage to RequestContext-based API.
all-actors/src/main/java/org/sunbird/notification/actor/ReadNotificationActor.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/notification/actor/NotificationTemplateActor.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/notification/actor/NotificationActor.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/notification/actor/DeleteNotificationActor.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/notification/actor/CreateNotificationActor.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/dao/TemplateDaoImpl.java Updated DAO to use new ServiceFactory + RequestContext conversion + updated CassandraOperation signatures.
all-actors/src/main/java/org/sunbird/dao/NotificationDaoImpl.java Updated DAO to use new ServiceFactory + RequestContext conversion + updated CassandraOperation signatures.
all-actors/src/main/java/org/sunbird/NotificationRequestMapper.java Updated LoggerUtil import to new shared logging package.
all-actors/src/main/java/org/sunbird/BaseActor.java Updated LoggerUtil import to new shared logging package.
all-actors/pom.xml Switched dependency from legacy cassandra-utils to new sunbird-cassandra-utils.
Comments suppressed due to low confidence (2)

core/sunbird-cassandra-utils/src/main/resources/cassandra.config.properties:21

  • cassandra.config.properties now includes a concrete default password (password=cassandra). Keeping real/default credentials in-repo is risky and can lead to insecure deployments. Prefer leaving this blank/placeholder and require credentials via environment variables or secret management.
    core/sunbird-cassandra-utils/src/main/resources/cassandra.config.properties:20
  • The Cassandra connection credentials are hardcoded in cassandra.config.properties via the userName and password fields, exposing real database secrets in source control. Anyone with access to this file (including in built artifacts or logs) can reuse these static credentials to connect to the Cassandra cluster, potentially gaining full access to stored data if the same values are used in shared or production environments. Move these values to a secure secret management mechanism or environment-specific configuration and replace them with strong, unique credentials that are not committed to the repo.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +71 to +75
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reusable library but declares slf4j-simple as a runtime dependency, which can cause SLF4J binding conflicts in consuming applications. Prefer removing the binding (keep only slf4j-api) and let the application choose the logging backend.

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +20
if (params != null)
this.edata.put("params", new ArrayList<Map<String, Object>>(){{add(params);}});
setEventMap(requestContext, msg);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new ArrayList<>() {{ ... }} is double-brace initialization, which creates an extra anonymous class and can retain references unexpectedly. Prefer constructing the list normally (or using Collections.singletonList(...)) to avoid the hidden allocation.

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +38
this.eventMap.putAll(new HashMap<String, Object>() {{
put("eid", eid);
put("ets", System.currentTimeMillis());
put("ver", ver);
put("mid", "LOG:" + UUID.randomUUID().toString());
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double-brace new HashMap<>() {{ ... }} initializer creates an anonymous class and adds allocations in a hot path (logging). Build the map explicitly to avoid extra classes and reduce GC pressure.

Copilot uses AI. Check for mistakes.
Comment on lines +166 to +169
logDebug(requestContext, formatLogMessage("Executing async CQL query: {}", select.getQueryString()));
ResultSetFuture future = session.executeAsync(select);
Futures.addCallback(future, callback, Executors.newFixedThreadPool(1));

Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Futures.addCallback(..., Executors.newFixedThreadPool(1)) creates a new thread pool on every call and never shuts it down, which can leak threads and degrade performance. Reuse a shared executor (static/singleton) or use a direct executor where appropriate.

Copilot uses AI. Check for mistakes.
Comment on lines +70 to +73
cassandraOperation.deleteRecord(KEY_SPACE_NAME, NOTIFICATION_TEMPLATE, compositeKey, getRequestContext(reqContext));
Response response = new Response();
response.put("response", "SUCCESS");
return response;
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleteTemplate constructs a new Response with hard-coded keys/values after calling deleteRecord(...). Prefer using existing constants (e.g., the shared response key and SUCCESS value) so callers see a consistent response shape across DAOs.

Suggested change
cassandraOperation.deleteRecord(KEY_SPACE_NAME, NOTIFICATION_TEMPLATE, compositeKey, getRequestContext(reqContext));
Response response = new Response();
response.put("response", "SUCCESS");
return response;
return cassandraOperation.deleteRecord(
KEY_SPACE_NAME,
NOTIFICATION_TEMPLATE,
compositeKey,
getRequestContext(reqContext));

Copilot uses AI. Check for mistakes.
keyspace,
table,
selectMap != null ? selectMap.size() : 0,
updateMap != null ? updateMap.size() : 0));
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is useless. updateMap cannot be null at this check, since it is guarded by ... != ....

Copilot uses AI. Check for mistakes.
if (requestContext instanceof RequestContext) {
info((RequestContext) requestContext, message, null, null);
} else if (requestContext instanceof Map) {
if (requestContext != null) {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is useless. requestContext cannot be null at this check, since it is guarded by ...instanceof....

Copilot uses AI. Check for mistakes.

} finally {
// Log query execution time
if (batchStatement != null && batchStatement.size() > 0) {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is useless. batchStatement cannot be null at this check, since new BatchStatement(...) always is non-null.

Copilot uses AI. Check for mistakes.

} finally {
// Log query execution time
if (batchStatement != null && batchStatement.size() > 0) {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is useless. batchStatement cannot be null at this check, since new BatchStatement(...) always is non-null.

Copilot uses AI. Check for mistakes.

} finally {
// Log query execution time
if (batchStatement != null && batchStatement.size() > 0) {
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is useless. batchStatement cannot be null at this check, since new BatchStatement(...) always is non-null.

Copilot uses AI. Check for mistakes.
@pallakartheekreddy pallakartheekreddy merged commit 047cdd2 into develop Jan 28, 2026
7 of 9 checks passed
@pallakartheekreddy pallakartheekreddy deleted the cassandra_utils branch January 28, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants