Search in sources :

Example 11 with DriverException

use of com.datastax.driver.core.exceptions.DriverException in project apex-malhar by apache.

the class CassandraStore method buildCluster.

/**
 * Creates a cluster object.
 */
public void buildCluster() {
    try {
        if (protocolVersion != null && protocolVersion.length() != 0) {
            ProtocolVersion version = getCassandraProtocolVersion();
            cluster = Cluster.builder().addContactPoint(node).withCredentials(userName, password).withProtocolVersion(version).build();
        } else {
            cluster = Cluster.builder().addContactPoint(node).withCredentials(userName, password).build();
        }
    } catch (DriverException ex) {
        throw new RuntimeException("closing database resource", ex);
    } catch (Throwable t) {
        DTThrowable.rethrow(t);
    }
}
Also used : DTThrowable(com.datatorrent.netlet.util.DTThrowable) DriverException(com.datastax.driver.core.exceptions.DriverException) ProtocolVersion(com.datastax.driver.core.ProtocolVersion)

Example 12 with DriverException

use of com.datastax.driver.core.exceptions.DriverException in project metacat by Netflix.

the class CassandraConnectorDatabaseService method listViewNames.

/**
 * {@inheritDoc}
 */
@Override
public List<QualifiedName> listViewNames(@Nonnull @NonNull final ConnectorRequestContext context, @Nonnull @NonNull final QualifiedName databaseName) {
    final String catalogName = databaseName.getCatalogName();
    final String keyspace = databaseName.getDatabaseName();
    log.debug("Attempting to get materialized view names for keyspace {} due to request {}", keyspace, context);
    try {
        final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
        if (keyspaceMetadata == null) {
            throw new DatabaseNotFoundException(databaseName);
        }
        final ImmutableList.Builder<QualifiedName> viewsBuilder = ImmutableList.builder();
        for (final MaterializedViewMetadata view : keyspaceMetadata.getMaterializedViews()) {
            viewsBuilder.add(QualifiedName.ofView(catalogName, keyspace, view.getBaseTable().getName(), view.getName()));
        }
        final List<QualifiedName> views = viewsBuilder.build();
        log.debug("Successfully found {} views for keyspace {} due to request {}", views.size(), keyspace, context);
        return views;
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, databaseName);
    }
}
Also used : MaterializedViewMetadata(com.datastax.driver.core.MaterializedViewMetadata) ImmutableList(com.google.common.collect.ImmutableList) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) QualifiedName(com.netflix.metacat.common.QualifiedName) DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 13 with DriverException

use of com.datastax.driver.core.exceptions.DriverException in project metacat by Netflix.

the class CassandraConnectorDatabaseService method listNames.

/**
 * {@inheritDoc}
 */
@Override
public List<QualifiedName> listNames(@Nonnull @NonNull final ConnectorRequestContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    log.debug("Attempting to list keyspaces for request {}", context);
    try {
        final List<QualifiedName> names = Lists.newArrayList();
        for (final KeyspaceMetadata keyspace : this.getCluster().getMetadata().getKeyspaces()) {
            final String keyspaceName = keyspace.getName();
            if (prefix != null && !keyspaceName.startsWith(prefix.getDatabaseName())) {
                continue;
            }
            names.add(QualifiedName.ofDatabase(name.getCatalogName(), keyspaceName));
        }
        if (sort != null) {
            // We can only really sort by the database name at this level so ignore SortBy field
            final Comparator<QualifiedName> comparator = Comparator.comparing(QualifiedName::getDatabaseName);
            ConnectorUtils.sort(names, sort, comparator);
        }
        final List<QualifiedName> results = ConnectorUtils.paginate(names, pageable);
        log.debug("Finished listing keyspaces for request {}", context);
        return results;
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, name);
    }
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 14 with DriverException

use of com.datastax.driver.core.exceptions.DriverException in project metacat by Netflix.

the class CassandraConnectorDatabaseService method get.

/**
 * {@inheritDoc}
 */
@Override
public DatabaseInfo get(@Nonnull @NonNull final ConnectorRequestContext context, @Nonnull @NonNull final QualifiedName name) {
    final String keyspace = name.getDatabaseName();
    log.debug("Attempting to get keyspace metadata for keyspace {} for request {}", keyspace, context);
    try {
        final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
        if (keyspaceMetadata == null) {
            throw new DatabaseNotFoundException(name);
        }
        log.debug("Successfully found the keyspace metadata for {} for request {}", name, context);
        return DatabaseInfo.builder().name(name).build();
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, name);
    }
}
Also used : DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 15 with DriverException

use of com.datastax.driver.core.exceptions.DriverException in project metacat by Netflix.

the class CassandraConnectorTableService method exists.

/**
 * {@inheritDoc}
 */
@Override
public boolean exists(@Nonnull @NonNull final ConnectorRequestContext context, @Nonnull @NonNull final QualifiedName name) {
    final String keyspace = name.getDatabaseName();
    final String table = name.getTableName();
    log.debug("Checking if Cassandra table {}.{} exists for request {}", keyspace, table, context);
    try {
        final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
        if (keyspaceMetadata == null) {
            return false;
        }
        final boolean exists = keyspaceMetadata.getTable(table) != null;
        log.debug("Cassandra table {}.{} {} for request {}", keyspace, table, exists ? "exists" : "doesn't exist", context);
        return exists;
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, name);
    }
}
Also used : DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Aggregations

DriverException (com.datastax.driver.core.exceptions.DriverException)18 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)14 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)10 TableMetadata (com.datastax.driver.core.TableMetadata)6 QualifiedName (com.netflix.metacat.common.QualifiedName)6 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)4 BoundStatement (com.datastax.driver.core.BoundStatement)3 MaterializedViewMetadata (com.datastax.driver.core.MaterializedViewMetadata)2 ImmutableList (com.google.common.collect.ImmutableList)2 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)2 ProtocolVersion (com.datastax.driver.core.ProtocolVersion)1 ResultSet (com.datastax.driver.core.ResultSet)1 DTThrowable (com.datatorrent.netlet.util.DTThrowable)1