Example usage for org.apache.cassandra.config Config Config

List of usage examples for org.apache.cassandra.config Config Config

Introduction

In this page you can find the example usage for org.apache.cassandra.config Config Config.

Prototype

Config

Source Link

Usage

From source file:org.wildfly.extension.cassandra.ClusterAdd.java

License:Apache License

private static Config createServiceConfig(final OperationContext context, PathAddress address,
        ModelNode fullModel) throws OperationFailedException {

    final ExpressionResolver expressionResolver = new ExpressionResolver() {
        @Override/*from  ww w.j  av  a  2 s  . c o m*/
        public ModelNode resolveExpressions(ModelNode node) throws OperationFailedException {
            return context.resolveExpressions(node);
        }
    };

    // create the actual cassandra config singleton
    final Config cassandraConfig = new Config();
    cassandraConfig.cluster_name = address.getLastElement().getValue();
    cassandraConfig.num_tokens = ClusterDefinition.NUM_TOKENS.resolveModelAttribute(context, fullModel).asInt();
    cassandraConfig.hinted_handoff_enabled = ClusterDefinition.HINTED_HANDOFF_ENABLED
            .resolveModelAttribute(context, fullModel).asString();

    cassandraConfig.authenticator = ClusterDefinition.AUTHENTICATOR.resolveModelAttribute(context, fullModel)
            .asString();
    cassandraConfig.authorizer = ClusterDefinition.AUTHORIZER.resolveModelAttribute(context, fullModel)
            .asString();
    cassandraConfig.partitioner = ClusterDefinition.PARTIONER.resolveModelAttribute(context, fullModel)
            .asString();

    // The cassandra config is a real brainfuck
    LinkedHashMap providerConfig = new LinkedHashMap();
    providerConfig.put("class_name",
            ClusterDefinition.SEED_PROVIDER.resolveModelAttribute(context, fullModel).asString());
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("seeds",
            ClusterDefinition.SEEDS.resolveModelAttribute(expressionResolver, fullModel).asString());
    ArrayList wrapper = new ArrayList();
    wrapper.add(params);
    providerConfig.put("parameters", wrapper);

    SeedProviderDef providerDef = new SeedProviderDef(providerConfig);
    cassandraConfig.seed_provider = providerDef;

    cassandraConfig.listen_address = ClusterDefinition.LISTEN_ADDRESS
            .resolveModelAttribute(expressionResolver, fullModel).asString();
    cassandraConfig.broadcast_address = ClusterDefinition.BROADCAST_ADDRESS
            .resolveModelAttribute(expressionResolver, fullModel).asString();

    cassandraConfig.start_native_transport = ClusterDefinition.START_NATIVE_TRANSPORT
            .resolveModelAttribute(context, fullModel).asBoolean();
    cassandraConfig.start_rpc = ClusterDefinition.START_RPC.resolveModelAttribute(context, fullModel)
            .asBoolean();

    cassandraConfig.native_transport_port = ClusterDefinition.NATIVE_TRANSPORT_PORT
            .resolveModelAttribute(context, fullModel).asInt();
    cassandraConfig.rpc_port = ClusterDefinition.RPC_PORT.resolveModelAttribute(context, fullModel).asInt();

    cassandraConfig.internode_authenticator = ClusterDefinition.INTERNODE_AUTHENTICATOR
            .resolveModelAttribute(context, fullModel).asString();

    if (fullModel.hasDefined(CassandraModel.DATA_FILE_DIR))
        cassandraConfig.data_file_directories = new String[] {
                ClusterDefinition.DATA_FILE_DIR.resolveModelAttribute(context, fullModel).asString() };

    if (fullModel.hasDefined(CassandraModel.SAVED_CACHES_DIR))
        cassandraConfig.saved_caches_directory = ClusterDefinition.SAVED_CACHES_DIR
                .resolveModelAttribute(context, fullModel).asString();

    if (fullModel.hasDefined(CassandraModel.COMMIT_LOG_DIR))
        cassandraConfig.commitlog_directory = ClusterDefinition.COMMIT_LOG_DIR
                .resolveModelAttribute(context, fullModel).asString();

    cassandraConfig.commitlog_sync = Config.CommitLogSync
            .valueOf(ClusterDefinition.COMMIT_LOG_SYNC.resolveModelAttribute(context, fullModel).asString());
    cassandraConfig.commitlog_sync_period_in_ms = ClusterDefinition.COMMIT_LOG_SYNC_PERIOD
            .resolveModelAttribute(context, fullModel).asInt();

    cassandraConfig.endpoint_snitch = ClusterDefinition.ENDPOINT_SNITCH
            .resolveModelAttribute(context, fullModel).asString();
    cassandraConfig.request_scheduler = ClusterDefinition.REQUEST_SCHEDULER
            .resolveModelAttribute(context, fullModel).asString();

    // TODO: encryption options
    //cassandraConfig.server_encryption_options =
    //cassandraConfig.client_encryption_options =

    // TODO: ring delay configuration (cassandra.ring_delay_ms)

    return cassandraConfig;

}