Java Code Examples for com.netflix.astyanax.connectionpool.exceptions.ConnectionException#printStackTrace()

The following examples show how to use com.netflix.astyanax.connectionpool.exceptions.ConnectionException#printStackTrace() . 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: MetaDaoImpl.java    From staash with Apache License 2.0 6 votes vote down vote up
@Override
public void writeMetaEntity(Entity entity) {
    // TODO Auto-generated method stub
    Keyspace ks = kscp.acquireKeyspace("meta");
    ks.prepareMutationBatch();
    MutationBatch m;
    OperationResult<Void> result;
    m = ks.prepareMutationBatch();
    m.withRow(dbcf, entity.getRowKey()).putColumn(entity.getName(), entity.getPayLoad(), null);
    try {
        result = m.execute();
        if (entity instanceof PaasTableEntity) {
            String schemaName = ((PaasTableEntity)entity).getSchemaName();
            Keyspace schemaks = kscp.acquireKeyspace(schemaName);
            ColumnFamily<String, String> cf = ColumnFamily.newColumnFamily(entity.getName(), StringSerializer.get(), StringSerializer.get());
            schemaks.createColumnFamily(cf, null);
        }
        int i = 0;
    } catch (ConnectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
Example 2
Source File: AstyanaxMetaDaoImpl.java    From staash with Apache License 2.0 5 votes vote down vote up
public Map<String, JsonObject> runQuery(String key, String col) {
	OperationResult<CqlStatementResult> rs;
	Map<String, JsonObject> resultMap = new HashMap<String, JsonObject>();
	try {
		String queryStr = "";
		if (col != null && !col.equals("*")) {
			queryStr = "select column1, value from "+MetaConstants.META_KEY_SPACE + "." + MetaConstants.META_COLUMN_FAMILY +" where key='"
					+ key + "' and column1='" + col + "';";
		} else {
			queryStr = "select column1, value from "+MetaConstants.META_KEY_SPACE + "." + MetaConstants.META_COLUMN_FAMILY +" where key='"
					+ key + "';";
		}
		rs = keyspace.prepareCqlStatement().withCql(queryStr).execute();
		for (Row<String, String> row : rs.getResult().getRows(METACF)) {

			ColumnList<String> columns = row.getColumns();

			String key1 = columns.getStringValue("column1", null);
			String val1 = columns.getStringValue("value", null);
			resultMap.put(key1, new JsonObject(val1));
		}
	} catch (ConnectionException e) {
		e.printStackTrace();
		throw new RuntimeException(e.getMessage());
	}

	return resultMap;
}
 
Example 3
Source File: AstyanaxThriftDataTableResource.java    From staash with Apache License 2.0 5 votes vote down vote up
@Override
public QueryResult listRows(String cursor, Integer rowLimit, Integer columnLimit) throws PaasException {
    try {
        invariant();
        
        // Execute the query
        Partitioner partitioner = keyspace.getPartitioner();
        Rows<ByteBuffer, ByteBuffer> result = keyspace
            .prepareQuery(columnFamily)
            .getKeyRange(null,  null, cursor != null ? cursor : partitioner.getMinToken(),  partitioner.getMaxToken(),  rowLimit)
            .execute()
            .getResult();
        
        // Convert raw data into a simple sparse tree
        SchemalessRows.Builder builder = SchemalessRows.builder();
        for (Row<ByteBuffer, ByteBuffer> row : result) { 
            Map<String, String> columns = Maps.newHashMap();
            for (Column<ByteBuffer> column : row.getColumns()) {
                columns.put(serializers.columnAsString(column.getRawName()), serializers.valueAsString(column.getRawName(), column.getByteBufferValue()));
            }
            builder.addRow(serializers.keyAsString(row.getKey()), columns);
        }
        
        QueryResult dr = new QueryResult();
        dr.setSrows(builder.build());
        
        if (!result.isEmpty()) {
            dr.setCursor(partitioner.getTokenForKey(Iterables.getLast(result).getKey()));
        }
        return dr;
    } catch (ConnectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
 
Example 4
Source File: DefaultKeyspaceClientProvider.java    From staash with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized Keyspace acquireKeyspace(String schemaName) {
    schemaName = schemaName.toLowerCase();
    
    Preconditions.checkNotNull(schemaName, "Invalid schema name 'null'");
    
    KeyspaceContextHolder holder = contextMap.get(schemaName);
    if (holder == null) {
        LOG.info("Creating schema for '{}'", new Object[]{schemaName});
        
        String clusterName   = configuration.getString(String.format(CLUSTER_NAME_FORMAT,   schemaName));
        String keyspaceName  = configuration.getString(String.format(KEYSPACE_NAME__FORMAT, schemaName));
        String discoveryType = configuration.getString(String.format(DISCOVERY_TYPE_FORMAT, schemaName));
        if (clusterName==null || clusterName.equals("")) clusterName   = configuration.getString(String.format(CLUSTER_NAME_FORMAT,   "configuration"));
        if (keyspaceName == null || keyspaceName.equals("")) keyspaceName = schemaName;
        if (discoveryType==null || discoveryType.equals("")) discoveryType = configuration.getString(String.format(DISCOVERY_TYPE_FORMAT, "configuration"));
        Preconditions.checkNotNull(clusterName,   "Missing cluster name for schema " + schemaName + " " + String.format(CLUSTER_NAME_FORMAT,schemaName));
        Preconditions.checkNotNull(keyspaceName,  "Missing cluster name for schema " + schemaName + " " + String.format(KEYSPACE_NAME__FORMAT,schemaName));
        Preconditions.checkNotNull(discoveryType, "Missing cluster name for schema " + schemaName + " " + String.format(DISCOVERY_TYPE_FORMAT,schemaName));
        
        HostSupplierProvider hostSupplierProvider = hostSupplierProviders.get(discoveryType);
        Preconditions.checkNotNull(hostSupplierProvider, 
                String.format("Unknown host supplier provider '%s' for schema '%s'", discoveryType, schemaName));
        
        AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
            .forCluster(clusterName)
            .forKeyspace(keyspaceName)
            .withAstyanaxConfiguration(configurationProvider.get(schemaName))
            .withConnectionPoolConfiguration(cpProvider.get(schemaName))
            .withConnectionPoolMonitor(monitorProvider.get(schemaName))
            .withHostSupplier(hostSupplierProvider.getSupplier(clusterName))
            .buildKeyspace(ThriftFamilyFactory.getInstance());
        context.start();
        try {
            context.getClient().createKeyspace(defaultKsOptions);
        } catch (ConnectionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        holder = new KeyspaceContextHolder(context);
        contextMap.put(schemaName, holder);
        holder.start();
    }
    holder.addRef();
    
    return holder.getKeyspace();
}