public void afterTest() { cluster.truncate(keyspace.getKeyspaceName(), "Super1"); }
/** * Wrapped call to keyspace.createClock * To Specify a clock for a group of operations, use {@link AbstractTemplateUpdater} instead * @return */ public long getClock() { return keyspace.createClock(); }
/** * @return the keyspace */ public Keyspace getKeyspace() { if (keyspace != null) { return keyspace; } keyspace = HFactory.createKeyspace(getValue(KEYSPACE_PROP).getString(), getCluster()); keyspace.setConsistencyLevelPolicy(new JPAConsistencyPolicy()); return keyspace; }
public AbstractLockManager(Cluster cluster, Keyspace keyspace, HLockManagerConfigurator lockManagerConfigurator) { if (cluster == null) throw new RuntimeException("Cluster cannot be null for LockManager"); this.cluster = cluster; this.lockManagerConfigurator = lockManagerConfigurator; if (lockManagerConfigurator == null) { this.lockManagerConfigurator = new HLockManagerConfigurator(); } if (keyspace == null) { this.keyspace = HFactory.createKeyspace(this.lockManagerConfigurator.getKeyspaceName(), cluster); } else { this.keyspace = keyspace; // Set the Keyspace name in order to keep the info consistent this.lockManagerConfigurator.setKeyspaceName(keyspace.getKeyspaceName()); } }
/** * @deprecated does the same thing as getClock() will be removed in a future release * @return */ public long getEffectiveClock() { return keyspace.createClock(); }
private void checkCreateLockSchema() { KeyspaceDefinition keyspaceDef = cluster.describeKeyspace(keyspace.getKeyspaceName()); if (keyspaceDef == null) { ColumnFamilyDefinition cfDef = createColumnFamilyDefinition(); KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(keyspace.getKeyspaceName(), ThriftKsDef.DEF_STRATEGY_CLASS, lockManagerConfigurator.getReplicationFactor(), Arrays.asList(cfDef)); log.info("Creating Keyspace and Column Family for LockManager with name (KSPS/CF): (" + newKeyspace.getName() + " / " + cfDef.getName()); cluster.addKeyspace(newKeyspace, true); } else { log.info("Keyspace for LockManager already exists. Skipping creation."); // The Keyspace exists but we don't know anything about the CF yet. if (!doesLockCFExist(keyspaceDef)) { // create it ColumnFamilyDefinition cfDef = createColumnFamilyDefinition(); log.info("Creating Column Family for LockManager with name: " + cfDef.getName()); cluster.addColumnFamily(cfDef, true); } else { log.info("Column Family for LockManager already exists. Skipping creation."); } } }
/** * Insert multiple values */ public <K> void insertMulti(Map<K, String> keyValues, Serializer<K> keySerializer) { Mutator<K> m = createMutator(keyspace, keySerializer); for (Map.Entry<K, String> keyValue: keyValues.entrySet()) { m.addInsertion(keyValue.getKey(), CF_NAME, createColumn(COLUMN_NAME, keyValue.getValue(), keyspace.createClock(), serializer, serializer)); } m.execute(); }
@After public void after() { cluster.truncate(keyspace.getKeyspaceName(), columnFamily); }
/** * Insert multiple values for a given columnName */ public void insertMulti(String columnName, Map<String, String> keyValues) { Mutator<String> m = createMutator(keyspace, serializer); for (Map.Entry<String, String> keyValue: keyValues.entrySet()) { m.addInsertion(keyValue.getKey(), columnFamilyName, createColumn(columnName, keyValue.getValue(), keyspace.createClock(), serializer, serializer)); } m.execute(); }
private ColumnFamilyDefinition createColumnFamilyDefinition() { ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspace.getKeyspaceName(), lockManagerConfigurator.getLockManagerCF(), ComparatorType.UTF8TYPE); cfDef.setKeyValidationClass(ComparatorType.UTF8TYPE.getClassName()); cfDef.setRowCacheSize(lockManagerConfigurator.isRowsCacheEnabled() ? 10000 : 0); cfDef.setGcGraceSeconds(Ints.saturatedCast(TimeUnit.MILLISECONDS.toSeconds(lockManagerConfigurator.getLocksTTLInMillis()))); return cfDef; }
private HColumn<String, String> createColumnForLock(String name, String value) { return createColumn(name, value, keyspace.createClock(), colTtl, StringSerializer.get(), StringSerializer.get()); }
@Test public void getObjectInstance() throws Exception { Reference resource = new Reference("CassandraClientFactory"); resource.add(new StringRefAddr("hosts", cassandraUrl)); resource.add(new StringRefAddr("clusterName", clusterName)); resource.add(new StringRefAddr("keyspace", "Keyspace1")); resource.add(new StringRefAddr("autoDiscoverHosts", "true")); Name jndiName = mock(Name.class); Context context = new InitialContext(); Hashtable<String, String> environment = new Hashtable<String, String>(); Keyspace keyspace = (Keyspace) factory.getObjectInstance(resource, jndiName, context, environment); assertNotNull(keyspace); assertEquals("Keyspace1",keyspace.getKeyspaceName()); } }
private void deleteLock(HLock lock) { // cancel the heartbeat task if it exists Future<Void> heartbeat = ((HLockImpl) lock).getHeartbeat(); if (heartbeat != null) { heartbeat.cancel(false); } Mutator<String> mutator = createMutator(keyspace, StringSerializer.get()); mutator.addDeletion(lock.getPath(), lockManagerConfigurator.getLockManagerCF(), lock.getLockId(), StringSerializer.get(), keyspace.createClock()); mutator.execute(); }
@Test public void testInitWithDefaults() { KeyspaceDefinition keyspaceDef = cluster.describeKeyspace(lm.getKeyspace().getKeyspaceName()); assertNotNull(keyspaceDef); assertTrue(verifyCFCreation(keyspaceDef.getCfDefs())); }
/** * Wrapped call to keyspace.createClock * To Specify a clock for a group of operations, use {@link AbstractTemplateUpdater} instead * @return */ public long getClock() { return keyspace.createClock(); }
@Test public void testFilter() { cluster.truncate(keyspace.getKeyspaceName(), CF);
/** * @deprecated does the same thing as getClock() will be removed in a future release * @return */ public long getEffectiveClock() { return keyspace.createClock(); }
private static KeyspaceDefinition getKeyspaceDefinition(Cluster cluster, Keyspace keyspaceName) { return cluster.describeKeyspace(keyspaceName.getKeyspaceName()); }
/** * Wrapped call to keyspace.createClock * To Specify a clock for a group of operations, use {@link AbstractTemplateUpdater} instead * @return */ public long getClock() { return keyspace.createClock(); }
private static KeyspaceDefinition getKeyspaceDefinition(Cluster cluster, Keyspace keyspaceName) { return cluster.describeKeyspace(keyspaceName.getKeyspaceName()); }