git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib-couchbase@130584 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0eef919051
commit
b8e565734c
|
@ -31,7 +31,7 @@ public class PersistenceCouchBase extends PersistenceBackend {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory
|
private static final Logger logger = LoggerFactory
|
||||||
.getLogger(PersistenceCouchBase.class);
|
.getLogger(PersistenceCouchBase.class);
|
||||||
|
|
||||||
public static final String URL_PROPERTY_KEY = "URL";
|
public static final String URL_PROPERTY_KEY = "URL";
|
||||||
//public static final String USERNAME_PROPERTY_KEY = "username";
|
//public static final String USERNAME_PROPERTY_KEY = "username";
|
||||||
public static final String PASSWORD_PROPERTY_KEY = "password";
|
public static final String PASSWORD_PROPERTY_KEY = "password";
|
||||||
|
@ -54,11 +54,13 @@ public class PersistenceCouchBase extends PersistenceBackend {
|
||||||
public static final String BUCKET_TASK_TYPE="TaskUsageRecord";
|
public static final String BUCKET_TASK_TYPE="TaskUsageRecord";
|
||||||
|
|
||||||
|
|
||||||
|
//public static final Integer TIMEOUT_BUCKET=90;
|
||||||
|
|
||||||
/* The environment configuration */
|
/* The environment configuration */
|
||||||
protected static final CouchbaseEnvironment ENV =
|
protected static final CouchbaseEnvironment ENV =
|
||||||
DefaultCouchbaseEnvironment.builder()
|
DefaultCouchbaseEnvironment.builder()
|
||||||
.connectTimeout(8 * 1000) // 8 Seconds in milliseconds
|
.connectTimeout(90 * 1000) // 90 Seconds in milliseconds
|
||||||
.keepAliveInterval(3600 * 1000) // 3600 Seconds in milliseconds
|
.keepAliveInterval(3600 * 1000) // 3600 Seconds in milliseconds
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
protected Cluster cluster;
|
protected Cluster cluster;
|
||||||
|
@ -96,7 +98,7 @@ public class PersistenceCouchBase extends PersistenceBackend {
|
||||||
String password = configuration.getProperty(PASSWORD_PROPERTY_KEY);
|
String password = configuration.getProperty(PASSWORD_PROPERTY_KEY);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
cluster = CouchbaseCluster.create(ENV, url);
|
cluster = CouchbaseCluster.create(ENV, url);
|
||||||
|
|
||||||
bucketNameStorage = configuration.getProperty(BUCKET_STORAGE_NAME_PROPERTY_KEY);
|
bucketNameStorage = configuration.getProperty(BUCKET_STORAGE_NAME_PROPERTY_KEY);
|
||||||
|
@ -107,37 +109,41 @@ public class PersistenceCouchBase extends PersistenceBackend {
|
||||||
|
|
||||||
connectionMap = new HashMap<String, Bucket>();
|
connectionMap = new HashMap<String, Bucket>();
|
||||||
|
|
||||||
bucketStorage = cluster.openBucket(bucketNameStorage, password);
|
//bucketStorage = cluster.openBucket(bucketNameStorage, password);
|
||||||
|
bucketStorage = cluster.openBucket( bucketNameStorage,password);
|
||||||
connectionMap.put(BUCKET_STORAGE_TYPE, bucketStorage);
|
connectionMap.put(BUCKET_STORAGE_TYPE, bucketStorage);
|
||||||
|
|
||||||
bucketService = cluster.openBucket(bucketNameService, password);
|
//bucketService = cluster.openBucket(bucketNameService, password);
|
||||||
|
bucketService = cluster.openBucket( bucketNameService,password);
|
||||||
connectionMap.put(BUCKET_SERVICE_TYPE, bucketService);
|
connectionMap.put(BUCKET_SERVICE_TYPE, bucketService);
|
||||||
|
|
||||||
bucketJob= cluster.openBucket(bucketNameJob, password);
|
//bucketJob= cluster.openBucket(bucketNameJob, password);
|
||||||
|
bucketJob = cluster.openBucket( bucketNameJob,password);
|
||||||
connectionMap.put(BUCKET_JOB_TYPE, bucketJob);
|
connectionMap.put(BUCKET_JOB_TYPE, bucketJob);
|
||||||
|
|
||||||
bucketPortlet= cluster.openBucket(bucketNamePortlet, password);
|
//bucketPortlet= cluster.openBucket(bucketNamePortlet, password);
|
||||||
|
bucketPortlet = cluster.openBucket( bucketNamePortlet,password);
|
||||||
connectionMap.put(BUCKET_PORTLET_TYPE, bucketPortlet);
|
connectionMap.put(BUCKET_PORTLET_TYPE, bucketPortlet);
|
||||||
|
|
||||||
bucketTask= cluster.openBucket(bucketNameTask, password);
|
//bucketTask= cluster.openBucket(bucketNameTask, password);
|
||||||
|
bucketTask = cluster.openBucket( bucketNameTask,password);
|
||||||
connectionMap.put(BUCKET_TASK_TYPE, bucketTask);
|
connectionMap.put(BUCKET_TASK_TYPE, bucketTask);
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.trace("Bucket connection error");
|
logger.error("Bucket connection error");
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JsonDocument createItem(JsonObject jsonObject, String id,String recordType) throws Exception {
|
protected JsonDocument createItem(JsonObject jsonObject, String id,String recordType) throws Exception {
|
||||||
|
logger.debug("insert a new record"+id);
|
||||||
JsonDocument doc = JsonDocument.create(id, jsonObject);
|
JsonDocument doc = JsonDocument.create(id, jsonObject);
|
||||||
|
|
||||||
return connectionMap.get(recordType).upsert(doc);
|
return connectionMap.get(recordType).upsert(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonNode usageRecordToJsonNode(Record record) throws Exception {
|
public static JsonNode usageRecordToJsonNode(Record record) throws Exception {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
|
||||||
JsonNode node = mapper.valueToTree(record.getResourceProperties());
|
JsonNode node = mapper.valueToTree(record.getResourceProperties());
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue