From eca94fd6da746173dff547b2b4a5d364772443b2 Mon Sep 17 00:00:00 2001 From: "roberto.cirillo" Date: Tue, 6 May 2014 08:12:38 +0000 Subject: [PATCH] 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 --- .../accounting/ReportAccountingImpl.java | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/gcube/contentmanager/storageserver/accounting/ReportAccountingImpl.java b/src/main/java/org/gcube/contentmanager/storageserver/accounting/ReportAccountingImpl.java index 8a3b706..d68fb2f 100644 --- a/src/main/java/org/gcube/contentmanager/storageserver/accounting/ReportAccountingImpl.java +++ b/src/main/java/org/gcube/contentmanager/storageserver/accounting/ReportAccountingImpl.java @@ -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