Search in sources :

Example 1 with CouchbaseEnvironment

use of com.couchbase.client.java.env.CouchbaseEnvironment in project incubator-gobblin by apache.

the class CouchbaseTestServer method testServer.

@Test
public static void testServer() throws InterruptedException, IOException {
    CouchbaseTestServer couchbaseTestServer = new CouchbaseTestServer(TestUtils.findFreePort());
    couchbaseTestServer.start();
    int port = couchbaseTestServer.getPort();
    int serverPort = couchbaseTestServer.getServerPort();
    try {
        CouchbaseEnvironment cbEnv = DefaultCouchbaseEnvironment.builder().bootstrapHttpEnabled(true).bootstrapHttpDirectPort(port).bootstrapCarrierDirectPort(serverPort).connectTimeout(TimeUnit.SECONDS.toMillis(15)).bootstrapCarrierEnabled(true).build();
        CouchbaseCluster cbCluster = CouchbaseCluster.create(cbEnv, "localhost");
        Bucket bucket = cbCluster.openBucket("default", "");
        try {
            JsonObject content = JsonObject.empty().put("name", "Michael");
            JsonDocument doc = JsonDocument.create("docId", content);
            JsonDocument inserted = bucket.insert(doc);
        } catch (Exception e) {
            Assert.fail("Should not throw exception on insert", e);
        }
    } finally {
        couchbaseTestServer.stop();
    }
}
Also used : Bucket(com.couchbase.client.java.Bucket) CouchbaseCluster(com.couchbase.client.java.CouchbaseCluster) JsonObject(com.couchbase.client.java.document.json.JsonObject) CouchbaseEnvironment(com.couchbase.client.java.env.CouchbaseEnvironment) DefaultCouchbaseEnvironment(com.couchbase.client.java.env.DefaultCouchbaseEnvironment) JsonDocument(com.couchbase.client.java.document.JsonDocument) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 2 with CouchbaseEnvironment

use of com.couchbase.client.java.env.CouchbaseEnvironment in project components by Talend.

the class CouchbaseInputTestIT method populateBucket.

private void populateBucket() {
    CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().socketConnectTimeout(60000).connectTimeout(60000).keepAliveInterval(60000).build();
    CouchbaseCluster cluster = CouchbaseCluster.create(env, bootstrapNodes);
    Bucket bucket = cluster.openBucket(bucketName, password);
    assertTrue(bucket.bucketManager().flush());
    JsonDocument document = JsonDocument.create("foo", JsonObject.create().put("bar", 42));
    bucket.upsert(document, PersistTo.MASTER);
    bucket.close();
    cluster.disconnect();
}
Also used : Bucket(com.couchbase.client.java.Bucket) CouchbaseCluster(com.couchbase.client.java.CouchbaseCluster) CouchbaseEnvironment(com.couchbase.client.java.env.CouchbaseEnvironment) DefaultCouchbaseEnvironment(com.couchbase.client.java.env.DefaultCouchbaseEnvironment) JsonDocument(com.couchbase.client.java.document.JsonDocument)

Example 3 with CouchbaseEnvironment

use of com.couchbase.client.java.env.CouchbaseEnvironment in project tutorials by eugenp.

the class ClusterServiceImpl method init.

@PostConstruct
private void init() {
    CouchbaseEnvironment env = DefaultCouchbaseEnvironment.create();
    cluster = CouchbaseCluster.create(env, "localhost");
}
Also used : DefaultCouchbaseEnvironment(com.couchbase.client.java.env.DefaultCouchbaseEnvironment) CouchbaseEnvironment(com.couchbase.client.java.env.CouchbaseEnvironment) PostConstruct(javax.annotation.PostConstruct)

Example 4 with CouchbaseEnvironment

use of com.couchbase.client.java.env.CouchbaseEnvironment in project samza by apache.

the class CouchbaseBucketRegistry method openCluster.

/**
 * Helper method to open a cluster given cluster nodes and environment configurations.
 */
private Cluster openCluster(List<String> clusterNodes, CouchbaseEnvironmentConfigs configs) {
    DefaultCouchbaseEnvironment.Builder envBuilder = new DefaultCouchbaseEnvironment.Builder();
    if (configs.sslEnabled != null) {
        envBuilder.sslEnabled(configs.sslEnabled);
    }
    if (configs.certAuthEnabled != null) {
        envBuilder.certAuthEnabled(configs.certAuthEnabled);
    }
    if (configs.sslKeystoreFile != null) {
        envBuilder.sslKeystoreFile(configs.sslKeystoreFile);
    }
    if (configs.sslKeystorePassword != null) {
        envBuilder.sslKeystorePassword(configs.sslKeystorePassword);
    }
    if (configs.sslTruststoreFile != null) {
        envBuilder.sslTruststoreFile(configs.sslTruststoreFile);
    }
    if (configs.sslTruststorePassword != null) {
        envBuilder.sslTruststorePassword(configs.sslTruststorePassword);
    }
    if (configs.bootstrapCarrierDirectPort != null) {
        envBuilder.bootstrapCarrierDirectPort(configs.bootstrapCarrierDirectPort);
    }
    if (configs.bootstrapCarrierSslPort != null) {
        envBuilder.bootstrapCarrierSslPort(configs.bootstrapCarrierSslPort);
    }
    if (configs.bootstrapHttpDirectPort != null) {
        envBuilder.bootstrapHttpDirectPort(configs.bootstrapHttpDirectPort);
    }
    if (configs.bootstrapHttpSslPort != null) {
        envBuilder.bootstrapHttpSslPort(configs.bootstrapHttpSslPort);
    }
    CouchbaseEnvironment env = envBuilder.build();
    Cluster cluster = CouchbaseCluster.create(env, clusterNodes);
    if (configs.sslEnabled != null && configs.sslEnabled) {
        cluster.authenticate(CertAuthenticator.INSTANCE);
    } else if (configs.username != null) {
        cluster.authenticate(configs.username, configs.password);
    } else {
        LOGGER.warn("No authentication is enabled for cluster: {}. This is not recommended except for test cases.", clusterNodes);
    }
    return cluster;
}
Also used : DefaultCouchbaseEnvironment(com.couchbase.client.java.env.DefaultCouchbaseEnvironment) CouchbaseCluster(com.couchbase.client.java.CouchbaseCluster) Cluster(com.couchbase.client.java.Cluster) DefaultCouchbaseEnvironment(com.couchbase.client.java.env.DefaultCouchbaseEnvironment) CouchbaseEnvironment(com.couchbase.client.java.env.CouchbaseEnvironment)

Example 5 with CouchbaseEnvironment

use of com.couchbase.client.java.env.CouchbaseEnvironment in project teiid by teiid.

the class CouchbaseManagedConnectionFactory method createConnectionFactory.

@SuppressWarnings("serial")
@Override
public BasicConnectionFactory<CouchbaseConnectionImpl> createConnectionFactory() throws ResourceException {
    final CouchbaseEnvironment environment = DefaultCouchbaseEnvironment.builder().managementTimeout(managementTimeout).queryTimeout(queryTimeout).viewTimeout(viewTimeout).kvTimeout(kvTimeout).searchTimeout(searchTimeout).connectTimeout(connectTimeout).dnsSrvEnabled(dnsSrvEnabled).build();
    if (this.connectionString == null) {
        // $NON-NLS-1$
        throw new InvalidPropertyException(UTIL.getString("no_server"));
    }
    if (this.keyspace == null) {
        // $NON-NLS-1$
        throw new InvalidPropertyException(UTIL.getString("no_keyspace"));
    }
    if (this.namespace == null) {
        // $NON-NLS-1$
        throw new InvalidPropertyException(UTIL.getString("no_namespace"));
    }
    final ScanConsistency consistency = ScanConsistency.valueOf(scanConsistency);
    TimeUnit unit = TimeUnit.MILLISECONDS;
    if (this.timeUnit != null) {
        try {
            unit = TimeUnit.valueOf(timeUnit);
        } catch (IllegalArgumentException e) {
            // $NON-NLS-1$
            throw new InvalidPropertyException(UTIL.getString("invalid_timeUnit", timeUnit));
        }
    }
    final TimeUnit timeoutUnit = unit;
    return new BasicConnectionFactory<CouchbaseConnectionImpl>() {

        @Override
        public CouchbaseConnectionImpl getConnection() throws ResourceException {
            return new CouchbaseConnectionImpl(environment, connectionString, keyspace, password, timeoutUnit, namespace, consistency);
        }
    };
}
Also used : BasicConnectionFactory(org.teiid.resource.spi.BasicConnectionFactory) InvalidPropertyException(javax.resource.spi.InvalidPropertyException) ScanConsistency(com.couchbase.client.java.query.consistency.ScanConsistency) TimeUnit(java.util.concurrent.TimeUnit) DefaultCouchbaseEnvironment(com.couchbase.client.java.env.DefaultCouchbaseEnvironment) CouchbaseEnvironment(com.couchbase.client.java.env.CouchbaseEnvironment)

Aggregations

CouchbaseEnvironment (com.couchbase.client.java.env.CouchbaseEnvironment)7 DefaultCouchbaseEnvironment (com.couchbase.client.java.env.DefaultCouchbaseEnvironment)6 CouchbaseCluster (com.couchbase.client.java.CouchbaseCluster)3 Bucket (com.couchbase.client.java.Bucket)2 JsonDocument (com.couchbase.client.java.document.JsonDocument)2 PostConstruct (javax.annotation.PostConstruct)2 Cluster (com.couchbase.client.java.Cluster)1 JsonObject (com.couchbase.client.java.document.json.JsonObject)1 ScanConsistency (com.couchbase.client.java.query.consistency.ScanConsistency)1 Config (com.typesafe.config.Config)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 TimeUnit (java.util.concurrent.TimeUnit)1 InvalidPropertyException (javax.resource.spi.InvalidPropertyException)1 State (org.apache.gobblin.configuration.State)1 AsyncDataWriter (org.apache.gobblin.writer.AsyncDataWriter)1 BasicConnectionFactory (org.teiid.resource.spi.BasicConnectionFactory)1 Test (org.testng.annotations.Test)1