me.prettyprint.hector.api.Cluster Java Examples

The following examples show how to use me.prettyprint.hector.api.Cluster. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThresholdsDao.java    From oneops with Apache License 2.0 6 votes vote down vote up
/**
 * Bean post init method. The following configuration is used
 * for initializing the ThresholdsDao cassandra cluster,
 * <p>
 * <ul>
 * <li>Active clients per node - 4</li>
 * <li>Cassandra Thrift timeout - 600 sec</li>
 * </ul>
 */
public void init() {
    logger.info("Initializing Monitor Thresholds Dao...");

    Cluster cluster = cb.getCluster(clusterName, 4, timeout);
    logger.info("Connected to cluster : " + clusterName);

    SchemaBuilder.createSchema(cluster, keyspaceName);
    ConfigurableConsistencyLevel cl = new ConfigurableConsistencyLevel();
    cl.setDefaultWriteConsistencyLevel(HConsistencyLevel.ONE);
    cl.setDefaultReadConsistencyLevel(HConsistencyLevel.ONE);

    keyspace = HFactory.createKeyspace(keyspaceName, cluster, cl);
    thresholdMutator = HFactory.createMutator(keyspace, longSerializer);
    manifestMapMutator = HFactory.createMutator(keyspace, longSerializer);
    realizedAsMutator = HFactory.createMutator(keyspace, longSerializer);
}
 
Example #2
Source File: OpsCiStateDao.java    From oneops with Apache License 2.0 5 votes vote down vote up
/**
 * Bean post init method. The following configuration is used
 * for initializing the OpsCiStateDao cassandra cluster,
 * <p/>
 * <ul>
 * <li>Active clients per node - 4</li>
 * <li>Cassandra Thrift timeout - 5 sec </li>
 * </ul>
 */
public void init() {
    logger.info("Initializing OpsCiState Dao...");
    Cluster cluster = cb.getCluster(clusterName, 4, 5 * 1000);
    logger.info("Connected to cluster : " + clusterName);

    SchemaBuilder.createSchema(cluster, keyspaceName);
    ConfigurableConsistencyLevel cl = new ConfigurableConsistencyLevel();
    HConsistencyLevel wrCL = System.getProperty("com.sensor.cistates.cl","LOCAL_QUORUM").equals("ONE") ? HConsistencyLevel.ONE :HConsistencyLevel.LOCAL_QUORUM;
    cl.setDefaultWriteConsistencyLevel(wrCL);
    cl.setDefaultReadConsistencyLevel(HConsistencyLevel.ONE);
    keyspace = createKeyspace(keyspaceName, cluster, cl);
    ciStateHistMutator = HFactory.createMutator(keyspace, longSerializer);
    componentStateMutator = HFactory.createMutator(keyspace, longSerializer);
}
 
Example #3
Source File: UsergridSystemMonitor.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * Must be instantiated with a build number and a cluster to be of any use. Properties can be null. Threshold
 * property must be a form compatible with {@link TimeUtils#millisFromDuration(String)}
 */
public UsergridSystemMonitor( String buildNumber, Cluster cluster, Properties properties ) {
    this.buildNumber = buildNumber;
    this.cluster = cluster;
    if ( properties != null ) {
        timerLogThreshold = TimeUtils.millisFromDuration( properties.getProperty( LOG_THRESHOLD_PROPERTY, "15s" ) );
    }
}
 
Example #4
Source File: BackplaneConfiguration.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void initialize() {
    String cassandraHosts = env.getProperty("ea.cassandra.hosts","localhost:9160");
    CassandraHostConfigurator hostConfigurator = new CassandraHostConfigurator(cassandraHosts);
    hostConfigurator.setAutoDiscoverHosts(false);
    hostConfigurator.setMaxActive(env.getProperty("ea.cassandra.maxActive",Integer.class,Runtime.getRuntime().availableProcessors() * 3));
    hostConfigurator.setRetryDownedHosts(true);
    hostConfigurator.setRetryDownedHostsDelayInSeconds(env.getProperty("ea.cassandra.retryDownedHostsDelayInSeconds",Integer.class,1));
    hostConfigurator.setMaxWaitTimeWhenExhausted(2000L);
    String cassandraClusterName = env.getProperty("ea.cassandra.cluster","ElasticActorsCluster");
    // it seems that there are issues with the CassandraHostRetryService and retrying downed hosts
    // if we don't let the HFactory manage the cluster then CassandraHostRetryService doesn't try to
    // be smart about finding out if a host was removed from the ring and so it will keep on retrying
    // all configured hosts (and ultimately fail-back when the host comes back online)
    // the default is TRUE, which will let HFactory manage the cluster
    Boolean manageClusterThroughHFactory = env.getProperty("ea.cassandra.hfactory.manageCluster", Boolean.class, Boolean.TRUE);
    Cluster cluster;
    if(manageClusterThroughHFactory) {
        cluster = HFactory.getOrCreateCluster(cassandraClusterName, hostConfigurator);
    } else {
        cluster = new ThriftCluster(cassandraClusterName, hostConfigurator, null);
    }
    String cassandraKeyspaceName = env.getProperty("ea.cassandra.keyspace","ElasticActors");
    Keyspace keyspace = HFactory.createKeyspace(cassandraKeyspaceName,cluster);
    persistentActorsColumnFamilyTemplate =
        new ThriftColumnFamilyTemplate<>(keyspace,"PersistentActors", CompositeSerializer.get(),StringSerializer.get());
    scheduledMessagesColumnFamilyTemplate =
        new ThriftColumnFamilyTemplate<>(keyspace,"ScheduledMessages",CompositeSerializer.get(), CompositeSerializer.get());
    actorSystemEventListenersColumnFamilyTemplate =
            new ThriftColumnFamilyTemplate<>(keyspace,"ActorSystemEventListeners", CompositeSerializer.get(),StringSerializer.get());
    // return
    // @TODO: make this configurable and use the ColumnSliceIterator
    scheduledMessagesColumnFamilyTemplate.setCount(Integer.MAX_VALUE);
    actorSystemEventListenersColumnFamilyTemplate.setCount(Integer.MAX_VALUE);
}
 
Example #5
Source File: DAOManager.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Informs the {@link DAOManager} that a DAO was closed. Shuts down the given cluster if all DAOs are closed.
 * 
 * @param cluster the cluster to shutdown if necessary.
 */
public synchronized void daoWasClosed(final Cluster cluster) {
	_daoCount--;

	if (_daoCount == 0) {
		HFactory.shutdownCluster(cluster);
	}
}
 
Example #6
Source File: Cassandra12xQuadIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public void clear() {
	super.clear();

	final Cluster cluster = _dataAccessLayerFactory.getCluster();
	final String keyspaceName = _dataAccessLayerFactory.getKeyspaceName();
	cluster.truncate(keyspaceName, OC_PS);
	cluster.truncate(keyspaceName, SC_OP);
	cluster.truncate(keyspaceName, SPC_O);	
}
 
Example #7
Source File: Cassandra12xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public void clear() {
	final Cluster cluster = _dataAccessLayerFactory.getCluster();
	final String keyspaceName = _dataAccessLayerFactory.getKeyspaceName();
	cluster.truncate(keyspaceName, S_POC);
	cluster.truncate(keyspaceName, O_SPC);
	cluster.truncate(keyspaceName, PO_SC);
	cluster.truncate(keyspaceName, RN_SP_O);
	cluster.truncate(keyspaceName, RN_PO_S);
	cluster.truncate(keyspaceName, RDT_PO_S);		
	cluster.truncate(keyspaceName, RDT_SP_O);		
}
 
Example #8
Source File: ClusterBootstrap.java    From oneops with Apache License 2.0 5 votes vote down vote up
/**
 * Create a hector cluster instance for an existing Cassandra cluster with the given configuration.
 * Default values for {@code CassandraHostConfigurator} are configured in properties.
 *
 * @param clusterName         cluster name. This is an identifying string for the cluster.
 *                            Clusters will be created on demand per each unique clusterName
 * @param activeClients       The maximum number of active clients to allowkey.
 * @param thriftSocketTimeout Cassandra Thrift Socket Timeout (in milliseconds)
 * @return cluster object
 * @see <a href="https://github.com/hector-client/hector/wiki/User-Guide#finer-grained-configuration">Hector config</a>
 */
public Cluster getCluster(String clusterName, int activeClients, int thriftSocketTimeout) {
    logger.info("Bootstrapping hector cluster client for " + clusterName);
    CassandraHostConfigurator config = new CassandraHostConfigurator();
    String hostStr = collectionToCommaDelimitedString(resolveHosts(clusterHosts,
            getProp("host_resolve", Boolean.class, true),
            getProp("host_ipv4", Boolean.class, true)));
    config.setHosts(hostStr);
    config.setPort(clusterPort);
    config.setUseThriftFramedTransport(getProp("thrift", Boolean.class, true));
    config.setUseSocketKeepalive(getProp("keep_alive", Boolean.class, true));
    config.setCassandraThriftSocketTimeout(thriftSocketTimeout);
    config.setMaxActive(activeClients);
    config.setExhaustedPolicy(ExhaustedPolicy.valueOf(getProp("exhausted_policy", String.class, WHEN_EXHAUSTED_GROW.toString())));
    config.setMaxWaitTimeWhenExhausted(getProp("exhausted_waittime", Integer.class, -1));
    config.setUseHostTimeoutTracker(getProp("ht_tracker", Boolean.class, true));
    config.setHostTimeoutCounter(getProp("ht_count", Integer.class, 3));
    config.setRetryDownedHosts(getProp("retry_hosts", Boolean.class, true));
    config.setRetryDownedHostsDelayInSeconds(getProp("retry_hosts_delay", Integer.class, 60));
    boolean autoDiscovery = getProp("auto_discovery", Boolean.class, false);
    config.setAutoDiscoverHosts(autoDiscovery);
    if (autoDiscovery) {
        config.setRunAutoDiscoveryAtStartup(true);
        config.setAutoDiscoveryDelayInSeconds(60);
    }

    logger.info(config.toString());
    Cluster cluster = HFactory.createCluster(clusterName, config);
    logger.info("Known pool hosts for " + clusterName + " cluster is " + cluster.getKnownPoolHosts(true));
    if (cluster.getKnownPoolHosts(true).size() == 0) {
    	logger.error("shutdown due to empty cluster.getKnownPoolHosts - hector doesnt throw java.net.ConnectException: Connection refused");
    }
    return cluster;
}
 
Example #9
Source File: OpsEventDao.java    From oneops with Apache License 2.0 5 votes vote down vote up
/**
 * Bean post init method. The following configuration is used
 * for initializing the OpsEventDao cassandra cluster,
 * <p>
 * <ul>
 * <li>Active clients per node - 4</li>
 * <li>Cassandra Thrift timeout - 5 sec </li>
 * </ul>
 */
public void init() {
    logger.info("Initializing OpsEvent Dao...");
    Cluster cluster = cb.getCluster(clusterName, 4, 5 * 1000);
    logger.info("Connected to cluster : " + clusterName);

    SchemaBuilder.createSchema(cluster, keyspaceName);
    ConfigurableConsistencyLevel cl = new ConfigurableConsistencyLevel();
    cl.setDefaultWriteConsistencyLevel(HConsistencyLevel.ONE);
    cl.setDefaultReadConsistencyLevel(HConsistencyLevel.ONE);
    keyspace = createKeyspace(keyspaceName, cluster, cl);
    eventMutator = HFactory.createMutator(keyspace, bytesSerializer);
    ciMutator = HFactory.createMutator(keyspace, longSerializer);
    orphanCloseMutator = HFactory.createMutator(keyspace, longSerializer);
}
 
Example #10
Source File: SchemaBuilder.java    From oneops with Apache License 2.0 4 votes vote down vote up
public static void addCiStateHistCF(Cluster cluster, String keyspaceName) {
	ColumnFamilyDefinition cfCiStateHistDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			CI_STATE_HIST_CF, 
               ComparatorType.LONGTYPE);
	cluster.addColumnFamily(cfCiStateHistDef);
}
 
Example #11
Source File: ClusterBootstrapTest.java    From oneops with Apache License 2.0 4 votes vote down vote up
@Test(enabled=false)
public void testGetCluster() throws Exception {
    assertNotNull(cb);
    Cluster c = (cb.getCluster("test_cluster"));
    assertNotNull(c);
}
 
Example #12
Source File: SchemaBuilder.java    From oneops with Apache License 2.0 4 votes vote down vote up
private static void createFreshSchema(Cluster cluster, String keyspaceName) {
	ColumnFamilyDefinition cfThresholdsDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			THRESHOLDS_CF, 
               ComparatorType.BYTESTYPE);
	cfThresholdsDef.setColumnType(ColumnType.SUPER);
	cfThresholdsDef.setSubComparatorType(ComparatorType.BYTESTYPE);
	
	ColumnFamilyDefinition cfManifestMapDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			MANIFESTMAP_CF, 
               ComparatorType.BYTESTYPE);

	ColumnFamilyDefinition cfRealizedAsMapDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			REALIZED_AS_CF, 
               ComparatorType.LONGTYPE);
	
	ColumnFamilyDefinition cfOpsDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			OPS_EVENTS_CF, 
               ComparatorType.LONGTYPE);

	ColumnFamilyDefinition cfCiStateHistDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			CI_STATE_HIST_CF, 
               ComparatorType.LONGTYPE);

	ColumnFamilyDefinition cfCiOpenEventsDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			CI_OPEN_EVENTS_CF, 
               ComparatorType.BYTESTYPE);
	cfCiOpenEventsDef.setColumnType(ColumnType.SUPER);
	cfCiOpenEventsDef.setSubComparatorType(ComparatorType.BYTESTYPE);

	ColumnFamilyDefinition cfComponentStateDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			COMPONENT_STATE_CF, 
               ComparatorType.BYTESTYPE);
	cfComponentStateDef.setColumnType(ColumnType.STANDARD);
	cfComponentStateDef.setDefaultValidationClass(ComparatorType.COUNTERTYPE.getClassName());
	cfComponentStateDef.setKeyValidationClass(ComparatorType.LONGTYPE.getClassName());
	
	ColumnFamilyDefinition cfOrphanEventsDef = HFactory.createColumnFamilyDefinition(keyspaceName,
			ORPHAN_CLOSE_EVENTS_CF, 
			ComparatorType.LONGTYPE);
	cfOrphanEventsDef.setColumnType(ColumnType.SUPER);
	cfOrphanEventsDef.setSubComparatorType(ComparatorType.BYTESTYPE);

	KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(keyspaceName,                 
	              ThriftKsDef.DEF_STRATEGY_CLASS,  
	              1,
	              Arrays.asList(cfThresholdsDef,cfManifestMapDef, cfRealizedAsMapDef, cfOpsDef, cfCiStateHistDef, cfCiOpenEventsDef, cfComponentStateDef));
	//Add the schema to the cluster.
	//"true" as the second param means that Hector will block until all nodes see the change.
	cluster.addKeyspace(newKeyspace, true);
	logger.info("Added keyspace " + keyspaceName);
}
 
Example #13
Source File: SchemaBuilder.java    From oneops with Apache License 2.0 4 votes vote down vote up
public static void createSchema(Cluster cluster, String keyspaceName) {
	
	KeyspaceDefinition keyspaceDef = cluster.describeKeyspace(keyspaceName);
	
	if (keyspaceDef == null) {
		createFreshSchema(cluster, keyspaceName);
		return;
	}
	
	List<ColumnFamilyDefinition> existingCFs = keyspaceDef.getCfDefs();
	
	Set<String> existingCFNames = new HashSet<String>();
	for (ColumnFamilyDefinition existingCF : existingCFs) {
		existingCFNames.add(existingCF.getName());
	}
	
	if (!existingCFNames.contains(THRESHOLDS_CF)) {
		ColumnFamilyDefinition cfThresholdsDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
				THRESHOLDS_CF, 
                ComparatorType.BYTESTYPE);
		cfThresholdsDef.setColumnType(ColumnType.SUPER);
		cfThresholdsDef.setSubComparatorType(ComparatorType.BYTESTYPE);
		cluster.addColumnFamily(cfThresholdsDef,true);
		logger.info("Added column family " + THRESHOLDS_CF);
	}

	if (!existingCFNames.contains(MANIFESTMAP_CF)) {
		ColumnFamilyDefinition cfManifestMapDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
				MANIFESTMAP_CF, 
                ComparatorType.BYTESTYPE);
		cluster.addColumnFamily(cfManifestMapDef,true);
		logger.info("Added column family " + MANIFESTMAP_CF);
	}

	if (!existingCFNames.contains(REALIZED_AS_CF)) {
		ColumnFamilyDefinition cfRealizedAsMapDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
				REALIZED_AS_CF, 
                ComparatorType.LONGTYPE);
		cluster.addColumnFamily(cfRealizedAsMapDef,true);
		logger.info("Added column family " + REALIZED_AS_CF);
	}
	
	
	if (!existingCFNames.contains(OPS_EVENTS_CF)) {
		ColumnFamilyDefinition cfOpsDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
				OPS_EVENTS_CF, 
                ComparatorType.LONGTYPE);
		cluster.addColumnFamily(cfOpsDef,true);
		logger.info("Added column family " + OPS_EVENTS_CF);
	}
	
	if (!existingCFNames.contains(ORPHAN_CLOSE_EVENTS_CF)) {
		ColumnFamilyDefinition cfResetOpsDef = HFactory.createColumnFamilyDefinition(keyspaceName,
				ORPHAN_CLOSE_EVENTS_CF, 
				ComparatorType.LONGTYPE);
		cfResetOpsDef.setColumnType(ColumnType.SUPER);
		cfResetOpsDef.setSubComparatorType(ComparatorType.BYTESTYPE);
		cluster.addColumnFamily(cfResetOpsDef,true);
		logger.info("Added column family " + ORPHAN_CLOSE_EVENTS_CF);
	}

	if (!existingCFNames.contains(CI_STATE_HIST_CF)) {
		ColumnFamilyDefinition cfCiStateHistDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
				CI_STATE_HIST_CF, 
                ComparatorType.LONGTYPE);
		cluster.addColumnFamily(cfCiStateHistDef,true);
		logger.info("Added column family " + CI_STATE_HIST_CF);
	}
	
	if (!existingCFNames.contains(CI_OPEN_EVENTS_CF)) {
		ColumnFamilyDefinition cfCiOpenEventsDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
				CI_OPEN_EVENTS_CF, 
                ComparatorType.BYTESTYPE);
		cfCiOpenEventsDef.setColumnType(ColumnType.SUPER);
		cfCiOpenEventsDef.setSubComparatorType(ComparatorType.BYTESTYPE);
		cluster.addColumnFamily(cfCiOpenEventsDef,true);
		logger.info("Added column family " + CI_OPEN_EVENTS_CF);
	}

	if (!existingCFNames.contains(COMPONENT_STATE_CF)) {
		ColumnFamilyDefinition cfComponentStateDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
				COMPONENT_STATE_CF, 
                ComparatorType.BYTESTYPE);
		cfComponentStateDef.setColumnType(ColumnType.STANDARD);
		cfComponentStateDef.setDefaultValidationClass(ComparatorType.COUNTERTYPE.getClassName());
		cfComponentStateDef.setKeyValidationClass(ComparatorType.LONGTYPE.getClassName());
		cluster.addColumnFamily(cfComponentStateDef,true);
		logger.info("Added column family " + COMPONENT_STATE_CF);
	}

}
 
Example #14
Source File: DefaultCassandraArchivaManager.java    From archiva with Apache License 2.0 4 votes vote down vote up
@Override
public Cluster getCluster()
{
    return cluster;
}
 
Example #15
Source File: ClusterBootstrap.java    From oneops with Apache License 2.0 2 votes vote down vote up
/**
 * Create a hector cluster instance for an existing Cassandra cluster with default active clients & thrift timeout.
 *
 * @param clusterName cluster name. This is an identifying string for the cluster.
 *                    Clusters will be created on demand per each unique clusterName
 *                    key.
 * @return cluster object
 * @see <a href="https://github.com/hector-client/hector/wiki/User-Guide#finer-grained-configuration">Hector config</a>
 */
public Cluster getCluster(String clusterName) {
    return getCluster(clusterName, getProp("active_clients", Integer.class, 6), getProp("timeout", Integer.class, 60 * 1000));
}
 
Example #16
Source File: CumulusDataAccessLayerFactory.java    From cumulusrdf with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the cluster currently in use.
 * 
 * @return the cluster currently in use.
 */
public Cluster getCluster() {
	return _cluster;
}
 
Example #17
Source File: CassandraArchivaManager.java    From archiva with Apache License 2.0 votes vote down vote up
Cluster getCluster();