Package me.prettyprint.hector.api

Examples of me.prettyprint.hector.api.Cluster


    public boolean deleteColumnFamily(String keyspaceName, String columnFamilyName) throws CassandraServerManagementException {

        validateKeyspace(keyspaceName);
        validateCF(columnFamilyName);
        try {
            Cluster cluster = getCluster(null);
            cluster.dropColumnFamily(keyspaceName.trim(), columnFamilyName.trim());
        } catch (HectorException e) {
            throw new CassandraServerManagementException("Error removing a column family with the name :" +
                    columnFamilyName, e, log);
        }
        return true;
View Full Code Here


     * @return A list of keyspace names
     * @throws CassandraServerManagementException
     *          for errors during accessing keyspaces
     */
    private String[] getKeyspaces(ClusterInformation clusterInformation) throws CassandraServerManagementException {
        Cluster cluster = getCluster(clusterInformation);
        List<String> keyspaceNames = new ArrayList<String>();
        for (KeyspaceDefinition keyspaceDefinition : cluster.describeKeyspaces()) {
            String name = keyspaceDefinition.getName();
            if (name != null && !"".equals(name)) {
                keyspaceNames.add(name);
            }
        }
View Full Code Here

     *          for errors during accessing a hector cluster
     */
    private Cluster getCluster(ClusterInformation clusterInformation) throws CassandraServerManagementException {
        DataAccessService dataAccessService =
                CassandraAdminComponentManager.getInstance().getDataAccessService();
        Cluster cluster;
        if (clusterInformation != null) {
            cluster = dataAccessService.getCluster(clusterInformation);
        } else {
            cluster = dataAccessService.getClusterForCurrentUser();
        }
View Full Code Here

    private void addOrUpdateKeyspace(boolean isAdd,
                                     String keyspaceName,
                                     int replicationFactor,
                                     String replicationStrategy) throws CassandraServerManagementException {

        Cluster cluster = getCluster(null);
        try {
            KeyspaceDefinition definition =
                    HFactory.createKeyspaceDefinition(keyspaceName.trim(), replicationStrategy, replicationFactor, null);
            if (isAdd) {
                cluster.addKeyspace(definition);
            } else {
                cluster.updateKeyspace(definition);
            }
        } catch (HectorException e) {
            throw new CassandraServerManagementException("Error " + (isAdd ? "adding" : "updating") + " a keyspace" +
                    " with name :" + keyspaceName, e, log);
        }
View Full Code Here

                familyDefinition.addColumnDefinition(columnDefinition);
            }
        }

        try {
            Cluster cluster = getCluster(null);
            if (isAdd) {
                cluster.addColumnFamily(new ThriftCfDef(familyDefinition));
            } else {
                cluster.updateColumnFamily(new ThriftCfDef(familyDefinition));
            }
        } catch (HectorException e) {
            throw new CassandraServerManagementException("Error " + (isAdd ? "adding" : "updating ") + " a column family with" +
                    " the name :" + columnFamilyName, e, log);
        }
View Full Code Here

        }
    }

    private KeyspaceDefinition getKeyspaceDefinition(String keyspace) throws CassandraServerManagementException {
        validateKeyspace(keyspace);
        Cluster cluster = getCluster(null);
        KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace(keyspace.trim());
        if (keyspaceDefinition == null) {
            throw new CassandraServerManagementException("Cannot find a keyspace for : " + keyspace, log);
        }
        return keyspaceDefinition;
    }
View Full Code Here

*/
public class ReadColumn {

    public static void main(String arg[]) {

        Cluster cluster = ExampleHelper.createCluster("test", "test123");
        Keyspace keyspace = HFactory.createKeyspace("TestKeyspace", cluster);
        ColumnQuery<String, String, String> columnQuery =
                HFactory.createStringColumnQuery(keyspace);
        columnQuery.setColumnFamily("CFone").setKey("keyone").setName("name");
        QueryResult<HColumn<String, String>> result = columnQuery.execute();
View Full Code Here

    private static Cluster retrieveCassandraCluster(String clusterName, String connectionUrl,
        Map<String, String> credentials) {

        CassandraHostConfigurator hostConfigurator = new CassandraHostConfigurator(connectionUrl);
        hostConfigurator.setRetryDownedHosts(false);
        Cluster cluster = HFactory.createCluster(clusterName, hostConfigurator, credentials);
        return cluster;
    }
View Full Code Here

        return createOrReplaceKeyspace(keyspaceName, ImmutableList.<ColumnFamilyDefinition>of());
    }

    public static Keyspace createOrReplaceKeyspace(String keyspaceName, List<ColumnFamilyDefinition> columnFamilyDefinitions)
    {
        Cluster cluster = getOrCreateCluster();

        KeyspaceDefinition keyspaceDefinition = HFactory.createKeyspaceDefinition(
                keyspaceName,
                StrategyModel.SIMPLE_STRATEGY.value(),
                1,
                columnFamilyDefinitions);

        if (cluster.describeKeyspace(keyspaceName) != null) {
            cluster.dropKeyspace(keyspaceName, true);
        }
        cluster.addKeyspace(keyspaceDefinition, true);
        return HFactory.createKeyspace(keyspaceName, cluster);
    }
View Full Code Here

        @Override
        public void evaluate() throws Throwable { // one clean instance by test to avoid side effects
            EmbeddedCassandraServerHelper.startEmbeddedCassandra();
            EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
            try {
                final Cluster cluster = HFactory.getOrCreateCluster("TestCluster", DatabaseDescriptor.getRpcAddress().getHostName() + ":" + DatabaseDescriptor.getRpcPort());

                for (final Field f : instance.getClass().getDeclaredFields()) {
                    final CassandraTestInject annotation = f.getAnnotation(CassandraTestInject.class);
                    if (annotation != null) {
                        if (Cluster.class.equals(f.getType())) {
View Full Code Here

TOP

Related Classes of me.prettyprint.hector.api.Cluster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.