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
* 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]
* 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) {
tm.close();
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()) {
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"));
}
public BasicDBObject setGenericMoveProperties(MyFile resource, String filename, String dir,
String name, BasicDBObject f) {
f.append("filename", filename).append("type", "file").append("name", name).append("dir", dir);
return f;
public DBObject setGenericMoveProperties(MyFile resource, String filename, String dir,
String name, DBObject sourcePathMetaCollection) {
sourcePathMetaCollection.put("filename", filename);
sourcePathMetaCollection.put("type", "file");
sourcePathMetaCollection.put("name", name);
sourcePathMetaCollection.put("dir", dir);
return sourcePathMetaCollection;
}
@ -778,10 +781,10 @@ public class MongoIOManager {
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);
BasicDBObject query = new BasicDBObject();
BasicDBObject obj=null;
DBObject obj=null;
query.put( "filename" ,source);
DBCursor cursor=fileCollection.find(query);
if(cursor != null && !cursor.hasNext()){
@ -790,7 +793,7 @@ public class MongoIOManager {
cursor=fileCollection.find(query);
}
if(cursor.hasNext()){
obj=(BasicDBObject) cursor.next();
obj=(DBObject) cursor.next();
String path=(String)obj.get("filename");
logger.debug("path found "+path);
}
@ -1064,8 +1067,8 @@ public class MongoIOManager {
public void close() {
// if(mongo!=null)
// mongo.close();
logger.info(" no close()");
logger.info("Mongo has been closed");
logger.debug(" try to close backend but the close operation is not implemented");
// logger.info("Mongo has been closed");
// mongo=null;
// gfs=null;
// db=null;

View File

@ -26,6 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoException;
import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSDBFile;
@ -44,7 +45,7 @@ public class MongoOperationManager extends TransportManager{
// private MongoClient mongo;
private MongoIOManager mongoPrimaryInstance;
private MongoIOManager mongoSecondaryInstance;
// private MemoryType memoryType;
private MemoryType memoryType;
protected static String[] dbNames;
@ -58,6 +59,7 @@ public class MongoOperationManager extends TransportManager{
logger.debug("init storage backend with "+memoryType+" memory");
try {
this.memoryType=memoryType;
super.memoryType=memoryType;
MongoOperationManager.dbNames=dbNames;
logger.debug("check mongo configuration");
if (dbNames!=null){
@ -457,7 +459,7 @@ public class MongoOperationManager extends TransportManager{
*/
private void updateMetaObject(String remoteIdentifier, String propertyField, String propertyValue)
throws UnknownHostException {
BasicDBObject remoteMetaCollectionObject;
DBObject remoteMetaCollectionObject;
logger.debug("find object...");
remoteMetaCollectionObject = mongoPrimaryInstance.findMetaCollectionObject(remoteIdentifier);
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.debug("MOVE OPERATION operation defined: "+resource.getOperationDefinition().getOperation());
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
if(sourcePathMetaCollection != null){
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();
if(op == null){
op=resource.getOperationDefinition().getOperation();
@ -188,14 +188,23 @@ public class MoveOperator extends Move {
String address=null;
try {
address=InetAddress.getLocalHost().getCanonicalHostName().toString();
f.put("callerIP", address);
sourcePathMetaCollection.put("callerIP", address);
} catch (UnknownHostException e) { }
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);
else
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);
return f;
if(from == null) {
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);
}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;
}
}