git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib-couchbase@146355 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9b664f88a7
commit
8f67991a34
2
pom.xml
2
pom.xml
|
@ -8,7 +8,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.data.publishing</groupId>
|
<groupId>org.gcube.data.publishing</groupId>
|
||||||
<artifactId>document-store-lib-couchbase</artifactId>
|
<artifactId>document-store-lib-couchbase</artifactId>
|
||||||
<version>1.3.0-SNAPSHOT</version>
|
<version>1.3.1-SNAPSHOT</version>
|
||||||
<name>Document Store CouchBase Connector</name>
|
<name>Document Store CouchBase Connector</name>
|
||||||
<description>Document Store Connector for CouchBase</description>
|
<description>Document Store Connector for CouchBase</description>
|
||||||
|
|
||||||
|
|
|
@ -125,16 +125,35 @@ public class PersistenceCouchBase extends PersistenceBackend {
|
||||||
//Bucket bucket = connectionMap.get(recordType);
|
//Bucket bucket = connectionMap.get(recordType);
|
||||||
Bucket bucket = null;
|
Bucket bucket = null;
|
||||||
synchronized (Connections.connectionsMap) {
|
synchronized (Connections.connectionsMap) {
|
||||||
|
/*
|
||||||
|
String bucketNamesValue=bucketNames.get(recordType);
|
||||||
|
logger.trace("bucketNamesValue:{}",bucketNamesValue);
|
||||||
|
|
||||||
|
Map<Nodes, Connection>conMap=Connections.connectionsMap;
|
||||||
|
logger.trace("conMap:{}",conMap.toString());
|
||||||
|
|
||||||
|
logger.debug("nodes:{}",nodes.toString());
|
||||||
|
Map<String,Bucket> mapStringBucket=conMap.get(nodes).getBucketsMap();
|
||||||
|
|
||||||
|
logger.trace("mapStringBucket:{}",mapStringBucket.toString());
|
||||||
|
bucket =mapStringBucket.get(bucketNamesValue);
|
||||||
|
*/
|
||||||
|
//Old code
|
||||||
bucket =Connections.connectionsMap.get(nodes).getBucketsMap().get(bucketNames.get(recordType));
|
bucket =Connections.connectionsMap.get(nodes).getBucketsMap().get(bucketNames.get(recordType));
|
||||||
|
try {
|
||||||
//logger.debug("PersistenceCouchBase getBucketConnection recordType:{}, bucket name:{}",recordType,bucketNames.get(recordType));
|
//logger.debug("PersistenceCouchBase getBucketConnection recordType:{}, bucket name:{}",recordType,bucketNames.get(recordType));
|
||||||
if(bucket == null){
|
if(bucket == null){
|
||||||
//bucket = cluster.openBucket(recordType, password);
|
//bucket = cluster.openBucket(recordType, password);
|
||||||
bucket = Connections.connectionsMap.get(nodes).getCluster().openBucket(bucketNames.get(recordType), password);
|
bucket = Connections.connectionsMap.get(nodes).getCluster().openBucket(bucketNames.get(recordType), password);
|
||||||
logger.trace("PersistenceCouchBase getBucketConnection bucket close, open:{}",bucket.toString() );
|
logger.trace("PersistenceCouchBase getBucketConnection bucket close, open:{}",bucket.toString() );
|
||||||
//connectionMap.put(recordType, bucket);
|
//connectionMap.put(recordType, bucket);
|
||||||
Connections.connectionsMap.get(nodes).getBucketsMap().put(bucketNames.get(recordType), bucket);
|
Connections.connectionsMap.get(nodes).getBucketsMap().put(bucketNames.get(recordType), bucket);
|
||||||
logger.trace("PersistenceCouchBase getBucketConnection connectionMap:{}",Connections.connectionsMap.get(nodes).getBucketsMap());
|
logger.trace("PersistenceCouchBase getBucketConnection connectionMap:{}",Connections.connectionsMap.get(nodes).getBucketsMap());
|
||||||
}
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
logger.error("getBucketConnection connection error", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return bucket;
|
return bucket;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +184,7 @@ public class PersistenceCouchBase extends PersistenceBackend {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void reallyAccount(Record record) throws Exception {
|
protected void reallyAccount(Record record) throws Exception {
|
||||||
JsonNode node = PersistenceCouchBase.usageRecordToJsonNode(record);
|
JsonNode node = PersistenceCouchBase.usageRecordToJsonNode(record);
|
||||||
JsonObject jsonObject = JsonObject.fromJson(node.toString());
|
JsonObject jsonObject = JsonObject.fromJson(node.toString());
|
||||||
//get a bucket association
|
//get a bucket association
|
||||||
|
@ -178,32 +197,36 @@ public class PersistenceCouchBase extends PersistenceBackend {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void close() throws Exception {
|
public void close() throws Exception {
|
||||||
logger.debug("PersistenceCouchBase close" );
|
logger.trace("PersistenceCouchBase close" );
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void closeAndClean() throws Exception {
|
protected void closeAndClean() throws Exception {
|
||||||
synchronized (Connections.connectionsMap) {
|
synchronized (Connections.connectionsMap) {
|
||||||
for (Map.Entry<String, Bucket> entry : Connections.connectionsMap.get(nodes).getBucketsMap().entrySet())
|
try {
|
||||||
{
|
for (Map.Entry<String, Bucket> entry : Connections.connectionsMap.get(nodes).getBucketsMap().entrySet())
|
||||||
Boolean closed = entry.getValue().close();
|
{
|
||||||
if (!closed){
|
Boolean closed = entry.getValue().close();
|
||||||
logger.warn("bucket not close :{}",entry.getKey());
|
if (!closed){
|
||||||
|
logger.warn("bucket not close :{}",entry.getKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
Boolean clusterClosed= Connections.connectionsMap.get(nodes).getCluster().disconnect();
|
||||||
Boolean clusterClosed= Connections.connectionsMap.get(nodes).getCluster().disconnect();
|
if (!clusterClosed){
|
||||||
if (!clusterClosed){
|
logger.warn("cluster not disconnect");
|
||||||
logger.warn("cluster not disconnect");
|
}
|
||||||
}
|
Connections.connectionsMap.remove(nodes);
|
||||||
Connections.connectionsMap.remove(nodes);
|
logger.trace("PersistenceCouchBase disconnect" );
|
||||||
logger.trace("PersistenceCouchBase disconnect" );
|
} catch(Exception e) {
|
||||||
|
logger.error("closeAndClean error with close and clean", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void closeConnection() throws Exception {
|
protected void closeConnection() throws Exception {
|
||||||
|
logger.trace("PersistenceCouchBase closeConnection" );
|
||||||
logger.debug("PersistenceCouchBase closeConnection" );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue