spring-projects / spring-projects/spring-boot

Add support for customized Cassandra keyspace creations

Open
#15,821 23 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

Using the Cluster bean from CassandraAutoConfiguration makes it quite difficult to provide a custom keyspace creation (e.g. via CreateKeyspaceSpecification).

While CassandraClusterFactoryBean#setKeyspaceCreations provides support for custom keyspace creations I couldn't find anything similar when the cluster is created via the auto-configuration.

Trying to find a workaround that doesn't duplicate existing auto-configuration code led to this ugly custom configuration...

@Configuration
@Import(CassandraDataAutoConfiguration.class)
@EnableConfigurationProperties(CassandraProperties.class)
public class CassandraCustomConfiguration {

    @Bean
    Cluster cluster(CassandraProperties properties, ObjectProvider<ClusterBuilderCustomizer> builderCustomizers) {
        CassandraAutoConfiguration cassandraAutoConfiguration = new CassandraAutoConfiguration(properties, builderCustomizers);
        Cluster cluster = cassandraAutoConfiguration.cassandraCluster();
        createKeyspace(cluster, getSimpleKeyspaceCreation());
        return cluster;
    }

    private CreateKeyspaceSpecification getSimpleKeyspaceCreation() {
        return CreateKeyspaceSpecification.createKeyspace("foo").ifNotExists(); // simplified sample
    }

    private void createKeyspace(Cluster cluster, CreateKeyspaceSpecification keyspaceCreation) {
        try (Session session = cluster.connect()) {
            CqlTemplate template = new CqlTemplate(session);
            template.execute(CreateKeyspaceCqlGenerator.toCql(keyspaceCreation));
        }
    }
}

It would be nice if the auto-configuration would provide support for keyspace creations.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading CassandraAutoConfiguration and CassandraClusterFactoryBean#setKeyspaceCreations, then trace how CreateKeyspaceSpecification is handled in the supplied custom configuration. Determine how auto-configuration could expose custom keyspace creations without duplicating its existing setup. Done means applications can provide custom keyspace creations through the auto-configured Cassandra cluster.

Written by the indexing model from the issue text.

Assessment

Tech stack
cassandra, java, spring-boot
Domain
backend, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.