Unified Cassandra Utility Module#164
Conversation
- 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.
…database operations
…lasses for error handling
…il` to `org.sunbird.logging.LoggerUtil` across multiple files
…handling in DAO classes
…andraConnectionMngrFactory in DBUtil
|
There was a problem hiding this comment.
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) andcore/sunbird-platform-common(logging + common keys/exceptions). - Refactored service/actor/SDK code to use
org.sunbird.logging.LoggerUtiland the new Cassandra APIs (notablyRequestContext-based context passing). - Removed legacy
cassandra-utilsmodule 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.propertiesnow 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.propertiesvia theuserNameandpasswordfields, 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.
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-simple</artifactId> | ||
| <version>${slf4j.version}</version> | ||
| <scope>runtime</scope> |
There was a problem hiding this comment.
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.
| if (params != null) | ||
| this.edata.put("params", new ArrayList<Map<String, Object>>(){{add(params);}}); | ||
| setEventMap(requestContext, msg); |
There was a problem hiding this comment.
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.
| this.eventMap.putAll(new HashMap<String, Object>() {{ | ||
| put("eid", eid); | ||
| put("ets", System.currentTimeMillis()); | ||
| put("ver", ver); | ||
| put("mid", "LOG:" + UUID.randomUUID().toString()); |
There was a problem hiding this comment.
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.
| logDebug(requestContext, formatLogMessage("Executing async CQL query: {}", select.getQueryString())); | ||
| ResultSetFuture future = session.executeAsync(select); | ||
| Futures.addCallback(future, callback, Executors.newFixedThreadPool(1)); | ||
|
|
There was a problem hiding this comment.
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.
| cassandraOperation.deleteRecord(KEY_SPACE_NAME, NOTIFICATION_TEMPLATE, compositeKey, getRequestContext(reqContext)); | ||
| Response response = new Response(); | ||
| response.put("response", "SUCCESS"); | ||
| return response; |
There was a problem hiding this comment.
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.
| 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)); |
| keyspace, | ||
| table, | ||
| selectMap != null ? selectMap.size() : 0, | ||
| updateMap != null ? updateMap.size() : 0)); |
There was a problem hiding this comment.
This check is useless. updateMap cannot be null at this check, since it is guarded by ... != ....
| if (requestContext instanceof RequestContext) { | ||
| info((RequestContext) requestContext, message, null, null); | ||
| } else if (requestContext instanceof Map) { | ||
| if (requestContext != null) { |
There was a problem hiding this comment.
This check is useless. requestContext cannot be null at this check, since it is guarded by ...instanceof....
|
|
||
| } finally { | ||
| // Log query execution time | ||
| if (batchStatement != null && batchStatement.size() > 0) { |
There was a problem hiding this comment.
This check is useless. batchStatement cannot be null at this check, since new BatchStatement(...) always is non-null.
|
|
||
| } finally { | ||
| // Log query execution time | ||
| if (batchStatement != null && batchStatement.size() > 0) { |
There was a problem hiding this comment.
This check is useless. batchStatement cannot be null at this check, since new BatchStatement(...) always is non-null.
|
|
||
| } finally { | ||
| // Log query execution time | ||
| if (batchStatement != null && batchStatement.size() > 0) { |
There was a problem hiding this comment.
This check is useless. batchStatement cannot be null at this check, since new BatchStatement(...) always is non-null.




Summary
Re-architected and rewrote the Cassandra utility layer into a single, unified
core/sunbird-cassandra-utilsmodule. This new implementation consolidates disparate Cassandra handling logic from across all microservices into one central library.Key Changes
core/sunbird-cassandra-utilsas the single source of truth for all Cassandra operations.CassandraOperationImpl,CassandraDACImpl) to be generic and reusable across the entire platform.cassandra-utilsmodule and refactored all dependent services (Actors, DAOs) to use the new unified implementation.Impact
Eliminates code duplication across microservices, enforces a standardized database access pattern, and simplifies future maintenance and upgrades.