relaxed filter on caller ip: not equals but contains

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/storage-manager-trigger@100630 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
roberto.cirillo 2014-10-13 10:24:19 +00:00
parent 5ba9d3ce48
commit e818f29879
1 changed files with 3 additions and 71 deletions

View File

@ -113,10 +113,10 @@ public class JsonParser extends Thread{
}else if((lastOperation==null) || (lastUser==null)){
logger.warn("lastOperation: "+lastOperation+" lastUser: "+lastUser+". These values cannot be null. Skip next ");
}
// if the lastoperation is download and the caller is a dts host then it isn't a real user but it is a workspace accounting record
// if the lastoperation is download and the caller contains a dts host then it isn't a real user but it is a workspace accounting record
if(lastOperation != null && lastOperation.equalsIgnoreCase("DOWNLOAD")){
for(String host: dtsHosts){
if(host.equalsIgnoreCase(callerIp))
if(host.contains(callerIp))
lastUser="workspace.accounting";
}
}
@ -175,75 +175,7 @@ public class JsonParser extends Thread{
e1.printStackTrace();
}
report.init();
// DBObject x=null;
MongoDB mongo=null;
try{
// x=c.get();
logger.info("Consumer #" + this.number + " got: " + x);
op = (String) x.get("op");
// retrieve object fields
DBObject obj=(DBObject)x.get("o");
retrieveObjectFields(obj);
long length=-1;
if(obj.get("length")!=null) length=(long)obj.get("length");
logger.info("[recordCheck] operation: "+op+" name: "+name+" type: "+type+" path: "+filename+" length: "+length+" owner: "+owner+"\n\t cretionTime: "+creationTime+ " lastOperation "+lastOperation+" lastUser: "+lastUser+" lastAccess: "+lastAccess);
if(((length >0) && (((filename!=null) && (filename.contains("/"))) || (linkCount > 0)))){
//convert from byte to kb
length=length/1024;
String scope=null;
if((filename!=null)&& (filename.contains("/")))
scope=retrieveScopeFromRemoteFilePath(filename);
else{
// field added on storage manager library for retrieve scope. Used only if it is a link delete
String pathString=(String)obj.get("onScope");
scope=retrieveScopeFromRemoteFilePath(pathString);
}
boolean validScope=ValidationUtils.validationScope(scope);
if(validScope){
if(delete!=null){
lastOperation="DELETE";
}else if ((lastOperation != null) && (op != null) && (lastOperation.equalsIgnoreCase("LINK")) && (op.equalsIgnoreCase("u"))){
// it is an update on a link object this operation doesn't be accounted
logger.info("update on link object is not accounted. Skip next ");
// continue;
}else if((lastOperation==null) || (lastUser==null)){
logger.warn("lastOperation: "+lastOperation+" lastUser: "+lastUser+". These values cannot be null. Skip next ");
}
logger.debug(" current operation "+lastOperation);
StorageStatusRecord ssr=null;
if(isNeedSSReport(lastOperation)){
try{
mongo=new MongoDB(server, user, password);
if(lastOperation.equalsIgnoreCase("COPY")){
ssr=mongo.update(lastUser, length, 1, lastOperation);
}else{
ssr=mongo.update(owner, length, 1, lastOperation);
}
mongo.close();
}catch(Exception e){
logger.error("Problem in updating storage status record: "+e.getMessage());
}
}
try{
//call to the accounting library
report( filename, owner, creationTime, length, scope, lastOperation, callerIp, lastAccess, lastUser, ssr.getVolume()+"", ssr.getCount()+"");
}catch(Exception e){
logger.error("Problem sending accounting report. Exception message: "+e.getMessage());
}
}else{
logger.info("operation is not accounted: invalid scope: "+scope);
}
}else{
logger.info("operation is not accounted");
}
}catch(Exception e){
e.printStackTrace();
logger.error("ERROR Processing record: "+x+" Exception throws: "+e.getStackTrace());
logger.info("skip to next record ");
if(mongo!=null)
mongo.close();
}
run();
}
private void retrieveObjectFields(DBObject obj) {