bugFix on building accounting record

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/storage-manager-trigger@95337 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
roberto.cirillo 2014-05-06 08:12:38 +00:00
parent 3febcf534f
commit eca94fd6da
1 changed files with 20 additions and 26 deletions

View File

@ -40,16 +40,7 @@ import org.slf4j.LoggerFactory;
@Override
public void start(String consumerId, String resourceScope, String creationTime) {
logger.info("set accounting properties: consumerId "+consumerId+" scope: "+resourceScope+ " creationTime "+creationTime);
raFactory = null;
try {
raFactory = ResourceAccountingFactory.getResourceAccountingInstance();
}
catch (IOException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
if(raFactory==null) init();
this.ur = new RawUsageRecord();
// generic properties
ur.setResourceType("storage-usage");
@ -57,43 +48,46 @@ import org.slf4j.LoggerFactory;
// ur.setResourceOwner("paolo.fabriani");
if(resourceScope !=null) ur.setResourceScope(resourceScope);
//set creation time
SimpleDateFormat formatter = new SimpleDateFormat("dd MM yyyy 'at' hh:mm:ss z");
Date date=null;
try {
date = formatter.parse(creationTime);
} catch (ParseException e) {
logger.error("Error in parsing date: "+e.getMessage());
e.printStackTrace();
if(creationTime!=null){
SimpleDateFormat formatter = new SimpleDateFormat("dd MM yyyy 'at' hh:mm:ss z");
Date date=null;
try {
date = formatter.parse(creationTime);
} catch (ParseException e) {
logger.error("Error in parsing date: "+creationTime+" exc msg: "+e.getMessage());
}
ur.setCreateTime(date);
}
}
@Override
public void timeUpdate() {
// setIpAddress();
setStartTime();
}
@Override
public void ultimate(String owner, String operation, String size, String filePath, String id, String callerIP, String lastAccess) {
logger.info("set accounting properties: owner "+owner+" operation: "+operation+" size: "+size+ " remotePath: "+filePath+" id: "+id);
//specific properties TODO
logger.info("set accounting properties: owner "+owner+" operation: "+operation+" size: "+size+ " remotePath: "+filePath+" id: "+id+"callerIP "+callerIP+" lastAccess"+lastAccess);
if(ur==null) this.ur = new RawUsageRecord();
//specific properties
if(owner != null) ur.setResourceOwner(owner);
// if(uri != null) ur.setResourceSpecificProperty("objectURI", uri);
if (operation!=null) ur.setResourceSpecificProperty("operationType",operation);
ur.setResourceSpecificProperty("dataType","STORAGE");
if(size!= null) ur.setResourceSpecificProperty("dataVolume", size);
if(filePath != null) ur.setResourceSpecificProperty("remotePath", filePath);
if(id!= null) ur.setResourceSpecificProperty("id", id);
if(callerIP!=null) ur.setResourceSpecificProperty("callerIP", "etics.eng.it");
if(lastAccess!=null)ur.setResourceSpecificProperty("lastAccess", lastAccess);
// set static properties
ur.setResourceSpecificProperty("dataType","STORAGE");
ur.setResourceSpecificProperty("dataCount", "1");
ur.setResourceSpecificProperty("callerIP", "etics.eng.it");
// setEndTime();
ur.setResourceSpecificProperty("lastAccess", lastAccess);
}
@Override
public void send() {
logger.info("report sending...");
raFactory.sendAccountingMessage(ur);
if(raFactory!=null)
raFactory.sendAccountingMessage(ur);
else
logger.error("Problem on building accounting record: Factory Object is null ");
}
@Deprecated