merge from trunk
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/storage-manager-trigger@169797 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
cb875b1021
commit
2cce222fd8
|
@ -108,7 +108,7 @@ public class UserAccountingConsumer extends Thread{
|
|||
record.setLastOperation("DELETE");
|
||||
}else if ((record.getLastOperation() != null) && (op != null) && (record.getLastOperation().equalsIgnoreCase("LINK")) && (op.equalsIgnoreCase("u"))){ //add check on operation
|
||||
// it is an update on a link object this operation doesn't be accounted
|
||||
logger.info("[recordCheck] update on link object is not accounted. Skip next ");
|
||||
logger.debug("[recordCheck] update on link object is not accounted. Skip next ");
|
||||
continue;
|
||||
}else if((record.getLastOperation()==null) || (record.getLastUser()==null)){
|
||||
logger.warn("lastOperation: "+record.getLastOperation()+" lastUser: "+record.getLastUser()+". These values cannot be null. Skip next ");
|
||||
|
@ -141,10 +141,11 @@ public class UserAccountingConsumer extends Thread{
|
|||
record.setOwner(record.getLastUser());
|
||||
ssr=new StorageStatusObject(record.getOwner(), record.getLength(), 1);
|
||||
ssr=mongo.updateUserVolume(ssr, record.getLastOperation());
|
||||
mongo.close();
|
||||
// mongo.close();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
mongo.close();
|
||||
logger.error("[recordCheck] Problem in updating storage status record: "+e.getMessage());
|
||||
logger.error("[recordCheck] Problem when updating storage status record: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
try{
|
||||
|
@ -159,10 +160,10 @@ public class UserAccountingConsumer extends Thread{
|
|||
logger.error("[recordCheck] Problem sending accounting report. Exception message: "+e.getMessage());
|
||||
}
|
||||
}else{
|
||||
logger.info("[recordCheck] operation "+record.getLastOperation()+" is not accounted: invalid scope: "+scope);
|
||||
logger.warn("[recordCheck] operation "+record.getLastOperation()+" is not accounted: invalid scope: "+scope);
|
||||
}
|
||||
}else{
|
||||
logger.info("operation "+record.getLastOperation()+" is not accounted");
|
||||
logger.debug("operation "+record.getLastOperation()+" is not accounted");
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
|
|
|
@ -102,7 +102,7 @@ public class MongoDB {
|
|||
|
||||
public StorageStatusObject getSSRecord(String consumer){
|
||||
StorageStatusObject record=ssOperationManager.getSSRecord(consumer);
|
||||
close();
|
||||
// close();
|
||||
return record;
|
||||
}
|
||||
|
||||
|
@ -144,65 +144,6 @@ public class MongoDB {
|
|||
return db;
|
||||
}
|
||||
|
||||
|
||||
// private DB getDB() {
|
||||
// if(db != null){
|
||||
// // check if the old server is primary
|
||||
// try{
|
||||
// DB db = mongo.getDB(ACCOUNTING_DB);
|
||||
// }catch(Exception e ){
|
||||
// logger.warn("the server now is not a primary ");
|
||||
// db=null;
|
||||
// }
|
||||
// }
|
||||
// if(db==null){
|
||||
// List<ServerAddress> srvList=new ArrayList<ServerAddress>();
|
||||
// for(String srv : server){
|
||||
// srvList.add(new ServerAddress(srv));
|
||||
// }
|
||||
// int i=-1;
|
||||
// for(String srv : server){
|
||||
// try {
|
||||
// i++;
|
||||
// ssCollection=null;
|
||||
// if(mongo!=null)
|
||||
// mongo.close();
|
||||
//// MongoOptions options=new MongoOptions();
|
||||
////// options.autoConnectRetry=true;
|
||||
//// options.socketKeepAlive=true;
|
||||
//// options.maxWaitTime=240000;
|
||||
//// options.connectionsPerHost=35;
|
||||
// MongoClientOptions options=MongoClientOptions.builder().connectionsPerHost(10).socketTimeout(60000).connectTimeout(30000).build();
|
||||
//// mongo = new Mongo(srv, options);
|
||||
// if(((pwd != null) && (pwd.length() >0)) && ((user != null) && (user.length() > 0))){
|
||||
// MongoCredential credential = MongoCredential.createMongoCRCredential(user, ACCOUNTING_DB, pwd.toCharArray());
|
||||
// mongo = new MongoClient(srvList, Arrays.asList(credential), options);
|
||||
// }else{
|
||||
// mongo = new MongoClient(srvList, options);
|
||||
// }
|
||||
// logger.debug("Istantiate MongoDB with options: "+mongo.getMongoOptions());
|
||||
// db = mongo.getDB(ACCOUNTING_DB);
|
||||
// // check on user and password for non authenticate mode
|
||||
//// if(user==null) user="";
|
||||
//// if(pwd==null) pwd="";
|
||||
//// boolean auth = db.authenticate(user, pwd.toCharArray());
|
||||
//// if(auth) logger.debug("mongo is in authenticate mode");
|
||||
//// else logger.debug("mongo is not in authenticate mode");
|
||||
// if(ssCollection == null)
|
||||
// ssCollection=db.getCollection(collectionSSName);
|
||||
// ssCollection.findOne();
|
||||
// String firstServer = server[0];
|
||||
// server[0] = srv;
|
||||
// server[i]=firstServer;
|
||||
// break;
|
||||
// } catch (Exception e) {
|
||||
// logger.warn("server "+srv+" is not a primary retry ");
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return db;
|
||||
// }
|
||||
|
||||
public DBCollection getStorageStatusCollection() {
|
||||
if(ssCollection==null)
|
||||
|
@ -220,8 +161,8 @@ public class MongoDB {
|
|||
|
||||
|
||||
public void close(){
|
||||
if(mongo!=null)
|
||||
mongo.close();
|
||||
// if(mongo!=null)
|
||||
// mongo.close();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,35 +19,39 @@ public class StorageStatusOperationManager {
|
|||
}
|
||||
|
||||
public void putSSRecord(String consumer, long volume, int count){
|
||||
logger.debug("put ss record method");
|
||||
BasicDBObject doc = new BasicDBObject("consumer", consumer)
|
||||
.append("volume", volume)
|
||||
.append("count", count);
|
||||
getSsCollection().insert(doc);
|
||||
DBCollection collection=getSsCollection();
|
||||
logger.info("put ss record ["+ consumer+" "+volume+" "+count+" ] in collection: "+collection);
|
||||
collection.insert(doc);
|
||||
}
|
||||
|
||||
public StorageStatusObject updateUser(StorageStatusObject ssRecord, String lastOperation){
|
||||
StorageStatusObject oldSsr=getSSRecord(ssRecord.getConsumer());
|
||||
|
||||
String consumer= ssRecord.getConsumer();
|
||||
logger.debug("check counts and volume for user "+consumer);
|
||||
StorageStatusObject oldSsr=getSSRecord(consumer);
|
||||
if(oldSsr != null){
|
||||
|
||||
logger.debug("user already present");
|
||||
int partialCount=oldSsr.getCount();
|
||||
logger.info(ssRecord.getConsumer()+" count found on db "+partialCount);
|
||||
logger.info(consumer+" count found on db "+partialCount);
|
||||
int count = countCalculation(ssRecord.getCount(), partialCount, lastOperation);
|
||||
ssRecord.setCount(count);
|
||||
|
||||
long partialVolume=oldSsr.getVolume();
|
||||
logger.info(ssRecord.getConsumer()+" volume found on db "+partialVolume);
|
||||
logger.info(consumer+" volume found on db "+partialVolume);
|
||||
long volume = volumeCalculation(ssRecord.getVolume(), partialVolume, lastOperation);
|
||||
ssRecord.setVolume(volume);
|
||||
|
||||
final BasicDBObject query = new BasicDBObject("consumer", ssRecord.getConsumer());
|
||||
final BasicDBObject query = new BasicDBObject("consumer", consumer);
|
||||
// Creating BasicDBObjectBuilder object without arguments
|
||||
DBObject documentBuilder = BasicDBObjectBuilder.start().add("volume", volume).add("count", count).get();
|
||||
// get the dbobject from builder and Inserting document
|
||||
getSsCollection().update(query,new BasicDBObject("$set", documentBuilder), true, false);
|
||||
// close();
|
||||
}else{
|
||||
putSSRecord(ssRecord.getConsumer(), ssRecord.getVolume(), ssRecord.getCount());
|
||||
logger.debug("user not present on db");
|
||||
putSSRecord(consumer, ssRecord.getVolume(), ssRecord.getCount());
|
||||
}
|
||||
return ssRecord;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue