Alessandro Pieve 2016-07-20 12:18:10 +00:00
parent 0eef919051
commit b8e565734c
1 changed files with 19 additions and 13 deletions

View File

@ -31,7 +31,7 @@ public class PersistenceCouchBase extends PersistenceBackend {
private static final Logger logger = LoggerFactory
.getLogger(PersistenceCouchBase.class);
public static final String URL_PROPERTY_KEY = "URL";
//public static final String USERNAME_PROPERTY_KEY = "username";
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 Integer TIMEOUT_BUCKET=90;
/* The environment configuration */
protected static final CouchbaseEnvironment ENV =
DefaultCouchbaseEnvironment.builder()
.connectTimeout(8 * 1000) // 8 Seconds in milliseconds
.keepAliveInterval(3600 * 1000) // 3600 Seconds in milliseconds
.connectTimeout(90 * 1000) // 90 Seconds in milliseconds
.keepAliveInterval(3600 * 1000) // 3600 Seconds in milliseconds
.build();
protected Cluster cluster;
@ -96,7 +98,7 @@ public class PersistenceCouchBase extends PersistenceBackend {
String password = configuration.getProperty(PASSWORD_PROPERTY_KEY);
try {
cluster = CouchbaseCluster.create(ENV, url);
bucketNameStorage = configuration.getProperty(BUCKET_STORAGE_NAME_PROPERTY_KEY);
@ -107,37 +109,41 @@ public class PersistenceCouchBase extends PersistenceBackend {
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);
bucketService = cluster.openBucket(bucketNameService, password);
//bucketService = cluster.openBucket(bucketNameService, password);
bucketService = cluster.openBucket( bucketNameService,password);
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);
bucketPortlet= cluster.openBucket(bucketNamePortlet, password);
//bucketPortlet= cluster.openBucket(bucketNamePortlet, password);
bucketPortlet = cluster.openBucket( bucketNamePortlet,password);
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);
} 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 {
logger.debug("insert a new record"+id);
JsonDocument doc = JsonDocument.create(id, jsonObject);
return connectionMap.get(recordType).upsert(doc);
}
public static JsonNode usageRecordToJsonNode(Record record) throws Exception {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.valueToTree(record.getResourceProperties());
return node;
}