convert BasicDBObject to DBObject the return type used for metadata collections

This commit is contained in:
Roberto Cirillo 2021-05-13 15:24:32 +02:00
parent 88fe3747f6
commit 60b9ebaa93
5 changed files with 37 additions and 21 deletions

View File

@ -2,7 +2,8 @@
## [v2.12.1-SNAPSHOT ## [v2.12.1-SNAPSHOT
* add check on transport layer instance: if the memory type is not the same, a new transportLayer is instatiated * add check on transport layer instance: if the memory type is not the same, a new transportLayer is instatiated
* amove memoryType var from super class TransportManager * move memoryType var from super class TransportManager
* convert BasicDBObject to DBObject the return type used for metadata collections
## [v2.12.0-SNAPSHOT] ## [v2.12.0-SNAPSHOT]
* One pool for every operation: static Operation class; no mongo close operation * One pool for every operation: static Operation class; no mongo close operation

View File

@ -29,7 +29,8 @@ public class SetMetaInfo extends Operation {
} catch (Exception e) { } catch (Exception e) {
tm.close(); tm.close();
e.printStackTrace(); e.printStackTrace();
throw new RemoteBackendException(" Error in SetMetaInfo operation ", e.getCause()); } logger.error("Problem setting file property", e);
throw new RemoteBackendException(" Error in SetMetaInfo operation ", e); }
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(" PATH " + bucket); logger.debug(" PATH " + bucket);
} }

View File

@ -547,10 +547,13 @@ public class MongoIOManager {
destinationFile.put("creationTime", DateUtils.now("dd MM yyyy 'at' hh:mm:ss z")); destinationFile.put("creationTime", DateUtils.now("dd MM yyyy 'at' hh:mm:ss z"));
} }
public BasicDBObject setGenericMoveProperties(MyFile resource, String filename, String dir, public DBObject setGenericMoveProperties(MyFile resource, String filename, String dir,
String name, BasicDBObject f) { String name, DBObject sourcePathMetaCollection) {
f.append("filename", filename).append("type", "file").append("name", name).append("dir", dir); sourcePathMetaCollection.put("filename", filename);
return f; sourcePathMetaCollection.put("type", "file");
sourcePathMetaCollection.put("name", name);
sourcePathMetaCollection.put("dir", dir);
return sourcePathMetaCollection;
} }
@ -778,10 +781,10 @@ public class MongoIOManager {
return list; return list;
} }
public BasicDBObject findMetaCollectionObject(String source) throws UnknownHostException { public DBObject findMetaCollectionObject(String source) throws UnknownHostException {
DBCollection fileCollection=getConnectionDB(dbName, false).getCollection(Costants.DEFAULT_META_COLLECTION); DBCollection fileCollection=getConnectionDB(dbName, false).getCollection(Costants.DEFAULT_META_COLLECTION);
BasicDBObject query = new BasicDBObject(); BasicDBObject query = new BasicDBObject();
BasicDBObject obj=null; DBObject obj=null;
query.put( "filename" ,source); query.put( "filename" ,source);
DBCursor cursor=fileCollection.find(query); DBCursor cursor=fileCollection.find(query);
if(cursor != null && !cursor.hasNext()){ if(cursor != null && !cursor.hasNext()){
@ -790,7 +793,7 @@ public class MongoIOManager {
cursor=fileCollection.find(query); cursor=fileCollection.find(query);
} }
if(cursor.hasNext()){ if(cursor.hasNext()){
obj=(BasicDBObject) cursor.next(); obj=(DBObject) cursor.next();
String path=(String)obj.get("filename"); String path=(String)obj.get("filename");
logger.debug("path found "+path); logger.debug("path found "+path);
} }
@ -1064,8 +1067,8 @@ public class MongoIOManager {
public void close() { public void close() {
// if(mongo!=null) // if(mongo!=null)
// mongo.close(); // mongo.close();
logger.info(" no close()"); logger.debug(" try to close backend but the close operation is not implemented");
logger.info("Mongo has been closed"); // logger.info("Mongo has been closed");
// mongo=null; // mongo=null;
// gfs=null; // gfs=null;
// db=null; // db=null;

View File

@ -26,6 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.mongodb.BasicDBObject; import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection; import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoException; import com.mongodb.MongoException;
import com.mongodb.gridfs.GridFS; import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSDBFile; import com.mongodb.gridfs.GridFSDBFile;
@ -44,7 +45,7 @@ public class MongoOperationManager extends TransportManager{
// private MongoClient mongo; // private MongoClient mongo;
private MongoIOManager mongoPrimaryInstance; private MongoIOManager mongoPrimaryInstance;
private MongoIOManager mongoSecondaryInstance; private MongoIOManager mongoSecondaryInstance;
// private MemoryType memoryType; private MemoryType memoryType;
protected static String[] dbNames; protected static String[] dbNames;
@ -58,6 +59,7 @@ public class MongoOperationManager extends TransportManager{
logger.debug("init storage backend with "+memoryType+" memory"); logger.debug("init storage backend with "+memoryType+" memory");
try { try {
this.memoryType=memoryType; this.memoryType=memoryType;
super.memoryType=memoryType;
MongoOperationManager.dbNames=dbNames; MongoOperationManager.dbNames=dbNames;
logger.debug("check mongo configuration"); logger.debug("check mongo configuration");
if (dbNames!=null){ if (dbNames!=null){
@ -457,7 +459,7 @@ public class MongoOperationManager extends TransportManager{
*/ */
private void updateMetaObject(String remoteIdentifier, String propertyField, String propertyValue) private void updateMetaObject(String remoteIdentifier, String propertyField, String propertyValue)
throws UnknownHostException { throws UnknownHostException {
BasicDBObject remoteMetaCollectionObject; DBObject remoteMetaCollectionObject;
logger.debug("find object..."); logger.debug("find object...");
remoteMetaCollectionObject = mongoPrimaryInstance.findMetaCollectionObject(remoteIdentifier); remoteMetaCollectionObject = mongoPrimaryInstance.findMetaCollectionObject(remoteIdentifier);
if(remoteMetaCollectionObject!=null){ if(remoteMetaCollectionObject!=null){

View File

@ -65,7 +65,7 @@ public class MoveOperator extends Move {
logger.info("move operation on Mongo backend, parameters: source path: "+source+" destination path: "+destination); logger.info("move operation on Mongo backend, parameters: source path: "+source+" destination path: "+destination);
logger.debug("MOVE OPERATION operation defined: "+resource.getOperationDefinition().getOperation()); logger.debug("MOVE OPERATION operation defined: "+resource.getOperationDefinition().getOperation());
if((source != null) && (!source.isEmpty()) && (destination != null) && (!destination.isEmpty())){ if((source != null) && (!source.isEmpty()) && (destination != null) && (!destination.isEmpty())){
BasicDBObject sourcePathMetaCollection = mongoPrimaryInstance.findMetaCollectionObject(source); DBObject sourcePathMetaCollection = mongoPrimaryInstance.findMetaCollectionObject(source);
//check if the file exist in the destination path, if it exist then it will be deleted //check if the file exist in the destination path, if it exist then it will be deleted
if(sourcePathMetaCollection != null){ if(sourcePathMetaCollection != null){
sourceId=sourcePathMetaCollection.get("_id").toString(); sourceId=sourcePathMetaCollection.get("_id").toString();
@ -175,7 +175,7 @@ public class MoveOperator extends Move {
} }
private BasicDBObject setCommonFields(BasicDBObject f, MyFile resource, OPERATION op) { private DBObject setCommonFields(DBObject sourcePathMetaCollection, MyFile resource, OPERATION op) {
String owner=resource.getOwner(); String owner=resource.getOwner();
if(op == null){ if(op == null){
op=resource.getOperationDefinition().getOperation(); op=resource.getOperationDefinition().getOperation();
@ -188,14 +188,23 @@ public class MoveOperator extends Move {
String address=null; String address=null;
try { try {
address=InetAddress.getLocalHost().getCanonicalHostName().toString(); address=InetAddress.getLocalHost().getCanonicalHostName().toString();
f.put("callerIP", address); sourcePathMetaCollection.put("callerIP", address);
} catch (UnknownHostException e) { } } catch (UnknownHostException e) { }
if(from == null) if(from == null) {
f.append("lastAccess", DateUtils.now("dd MM yyyy 'at' hh:mm:ss z")).append("lastUser", owner).append("lastOperation", op.toString()).append("callerIP", address); sourcePathMetaCollection.put("lastAccess", DateUtils.now("dd MM yyyy 'at' hh:mm:ss z"));
else sourcePathMetaCollection.put("lastUser", owner);
f.append("lastAccess", DateUtils.now("dd MM yyyy 'at' hh:mm:ss z")).append("lastUser", owner).append("lastOperation", op.toString()).append("callerIP", address).append("from", from); sourcePathMetaCollection.put("lastOperation", op.toString());
return f; sourcePathMetaCollection.put("callerIP", address);
}else {
sourcePathMetaCollection.put("lastAccess", DateUtils.now("dd MM yyyy 'at' hh:mm:ss z"));
sourcePathMetaCollection.put("lastUser", owner);
sourcePathMetaCollection.put("lastOperation", op.toString());
sourcePathMetaCollection.put("callerIP", address);
sourcePathMetaCollection.put("from", from);
}
return sourcePathMetaCollection;
} }
} }