Search in sources :

Example 11 with Keyspace

use of com.netflix.astyanax.Keyspace in project coprhd-controller by CoprHD.

the class DbClientImpl method removeObject.

public void removeObject(Class<? extends DataObject> clazz, DataObject... object) {
    tracer.newTracer("write");
    List<DataObject> allObjects = Arrays.asList(object);
    Keyspace ks = getKeyspace(clazz);
    DataObjectType doType = null;
    RemovedColumnsList removedList = new RemovedColumnsList();
    for (DataObject dataObject : allObjects) {
        _log.debug("Try to remove data object {}", dataObject.getId());
        checkGeoVersionForMutation(dataObject);
        doType = TypeMap.getDoType(dataObject.getClass());
        // delete all the index columns for this object first
        if (doType == null) {
            throw new IllegalArgumentException();
        }
        Row<String, CompositeColumnName> row = queryRowWithAllColumns(ks, dataObject.getId(), doType.getCF());
        if (row != null) {
            Iterator<Column<CompositeColumnName>> it = row.getColumns().iterator();
            String key = row.getKey();
            while (it.hasNext()) {
                Column<CompositeColumnName> column = it.next();
                removedList.add(key, column);
            }
        }
    }
    if (!removedList.isEmpty()) {
        boolean retryFailedWriteWithLocalQuorum = shouldRetryFailedWriteWithLocalQuorum(clazz);
        RowMutator mutator = new RowMutator(ks, retryFailedWriteWithLocalQuorum);
        _indexCleaner.removeColumnAndIndex(mutator, doType, removedList);
    }
}
Also used : PropertyListDataObject(com.emc.storageos.db.client.model.PropertyListDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) Column(com.netflix.astyanax.model.Column) Keyspace(com.netflix.astyanax.Keyspace)

Example 12 with Keyspace

use of com.netflix.astyanax.Keyspace in project coprhd-controller by CoprHD.

the class InternalDbClientImpl method countTimeSeries.

public int countTimeSeries(String cfName, Calendar startTime, Calendar endTime) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd/HH");
    String startTimeStr = dateFormat.format(startTime.getTime());
    String endTimeStr = dateFormat.format(endTime.getTime());
    int recordCount = 0;
    try {
        Keyspace keyspace = getLocalKeyspace();
        ColumnFamily<String, String> cf = new ColumnFamily<String, String>(cfName, StringSerializer.get(), StringSerializer.get());
        List<String> keys = genTimeSeriesKeys(startTime, endTime);
        for (String key : keys) {
            recordCount += keyspace.prepareQuery(cf).getKey(key).getCount().execute().getResult();
        }
        System.out.println(String.format("Column Family %s's record count between %s and %s is: %s", cfName, startTimeStr, endTimeStr, recordCount));
        return recordCount;
    } catch (ConnectionException e) {
        System.err.println(String.format("Exception=%s", e));
        throw DatabaseException.retryables.connectionFailed(e);
    }
}
Also used : Keyspace(com.netflix.astyanax.Keyspace) SimpleDateFormat(java.text.SimpleDateFormat) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) ColumnFamily(com.netflix.astyanax.model.ColumnFamily)

Example 13 with Keyspace

use of com.netflix.astyanax.Keyspace in project janusgraph by JanusGraph.

the class AstyanaxStoreManager method clearStorage.

@Override
public void clearStorage() throws BackendException {
    try {
        Cluster cluster = clusterContext.getClient();
        Keyspace ks = cluster.getKeyspace(keySpaceName);
        // everything up, so first invocation would always fail as Keyspace doesn't yet exist.
        if (ks == null)
            return;
        if (this.storageConfig.get(GraphDatabaseConfiguration.DROP_ON_CLEAR)) {
            ks.dropKeyspace();
        } else {
            final KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace(keySpaceName);
            if (keyspaceDefinition == null) {
                return;
            }
            for (final ColumnFamilyDefinition cf : keyspaceDefinition.getColumnFamilyList()) {
                ks.truncateColumnFamily(new ColumnFamily<>(cf.getName(), null, null));
            }
        }
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) ColumnFamilyDefinition(com.netflix.astyanax.ddl.ColumnFamilyDefinition) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Keyspace(com.netflix.astyanax.Keyspace) Cluster(com.netflix.astyanax.Cluster) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 14 with Keyspace

use of com.netflix.astyanax.Keyspace in project zuul by Netflix.

the class StartServer method initCassandra.

void initCassandra() throws Exception {
    if (cassandraEnabled.get()) {
        LOG.info("Getting AstyanaxContext");
        Keyspace keyspace = CassandraHelper.getInstance().getZuulCassKeyspace();
        LOG.info("Initializing Cassandra ZuulFilterDAO");
        ZuulFilterDAO dao = new ZuulFilterDAOCassandra(keyspace);
        LOG.info("Starting ZuulFilter Poller");
        ZuulFilterPoller.start(dao);
    }
}
Also used : ZuulFilterDAO(com.netflix.zuul.scriptManager.ZuulFilterDAO) Keyspace(com.netflix.astyanax.Keyspace) ZuulFilterDAOCassandra(com.netflix.zuul.scriptManager.ZuulFilterDAOCassandra)

Example 15 with Keyspace

use of com.netflix.astyanax.Keyspace in project zuul by Netflix.

the class CassandraHelper method getZuulCassKeyspace.

/**
     * @return the Keyspace for the Zuul Cassandra cluster which stores filters
     * @throws Exception
     */
public Keyspace getZuulCassKeyspace() throws Exception {
    if (zuulCassKeyspace != null)
        return zuulCassKeyspace;
    try {
        setAstynaxConfiguration(ConfigurationManager.getConfigInstance());
        AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder().forKeyspace(DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_CASSANDRA_KEYSPACE, "zuul_scripts").get()).withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)).withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("cass_connection_pool").setPort(DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_PORT, 7102).get()).setMaxConnsPerHost(DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_MAXCONNECTIONSPERHOST, 1).get()).setSeeds(DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_CASSANDRA_HOST, "").get() + ":" + DynamicPropertyFactory.getInstance().getIntProperty(ZUUL_CASSANDRA_PORT, 7102).get())).withConnectionPoolMonitor(new CountingConnectionPoolMonitor()).buildKeyspace(ThriftFamilyFactory.getInstance());
        context.start();
        zuulCassKeyspace = context.getClient();
        return zuulCassKeyspace;
    } catch (Exception e) {
        LOG.error("Exception occurred when initializing Cassandra keyspace: " + e);
        throw e;
    }
}
Also used : Keyspace(com.netflix.astyanax.Keyspace) ConnectionPoolConfigurationImpl(com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl) AstyanaxContext(com.netflix.astyanax.AstyanaxContext) AstyanaxConfigurationImpl(com.netflix.astyanax.impl.AstyanaxConfigurationImpl) CountingConnectionPoolMonitor(com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor)

Aggregations

Keyspace (com.netflix.astyanax.Keyspace)29 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)8 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)8 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)8 Test (org.junit.Test)7 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)6 CheckResult (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult)6 Column (com.netflix.astyanax.model.Column)6 Row (com.netflix.astyanax.model.Row)6 TimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName)5 Rows (com.netflix.astyanax.model.Rows)5 IndexAndCf (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf)4 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)4 FileShare (com.emc.storageos.db.client.model.FileShare)4 Order (com.emc.storageos.db.client.model.uimodels.Order)4 CompositeIndexColumnName (com.emc.storageos.db.client.impl.CompositeIndexColumnName)3 DataObject (com.emc.storageos.db.client.model.DataObject)3 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 KeyspaceDefinition (com.netflix.astyanax.ddl.KeyspaceDefinition)3 URI (java.net.URI)3