diff --git a/distro/CHANGELOG b/distro/CHANGELOG new file mode 100644 index 0000000..e8b0225 --- /dev/null +++ b/distro/CHANGELOG @@ -0,0 +1,3 @@ +v. 1.0.0 (04-05-2012) + * First release + diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..cdb5851 --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1,7 @@ +gCube System - License +------------------------------------------------------------ + +The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl). +The software and documentation is provided by its authors/distributors "as is" and no expressed or +implied warranty is given for its use, quality or fitness for a particular case. + diff --git a/distro/MAINTAINERS b/distro/MAINTAINERS new file mode 100644 index 0000000..05abbd7 --- /dev/null +++ b/distro/MAINTAINERS @@ -0,0 +1 @@ +* Roberto Cirillo (roberto.cirillo@isti.cnr.it), CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..8ac1421 Binary files /dev/null and b/distro/README differ diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..5180e2e --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,7 @@ + + + + First Release + + + diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..21d8c88 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,42 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + INSTALL + MAINTAINERS + changelog.xml + + 755 + true + + + + + ${distroDirectory}/profile.xml + / + true + + + target/${build.finalName}.jar + /${artifactId} + + + ${distroDirectory}/svnpath.txt + /${artifactId} + true + + + \ No newline at end of file diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..83f8c3d --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,25 @@ + + + + Service + + ${description} + ContentManagement + ${artifactId} + 1.0.0 + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + ${build.finalName}.jar + + + + + diff --git a/distro/svnpath.txt b/distro/svnpath.txt new file mode 100644 index 0000000..edacb04 --- /dev/null +++ b/distro/svnpath.txt @@ -0,0 +1 @@ +${scm.url} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8fe59b9..1df81c7 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ org.gcube.contentmanagement storage-manager-trigger - 0.0.1-SNAPSHOT + 1.0.0-SNAPSHOT scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/${project.artifactId} scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/${project.artifactId} @@ -23,41 +23,11 @@ mongo-java-driver [2.6.2,) - - - - - org.slf4j slf4j-log4j12 1.6.4 - - - - - - - - - - - - - - - - - - - - - - - - - junit junit @@ -102,6 +72,14 @@ org.apache.maven.plugins maven-assembly-plugin + + + org.gcube.contentmanager.storageserver.startup.Startup + + + + jar-with-dependencies + ${distroDirectory}/descriptor.xml diff --git a/src/main/java/org/gcube/contentmanager/storageserver/accounting/Report.java b/src/main/java/org/gcube/contentmanager/storageserver/accounting/Report.java index 5182701..dbd759c 100644 --- a/src/main/java/org/gcube/contentmanager/storageserver/accounting/Report.java +++ b/src/main/java/org/gcube/contentmanager/storageserver/accounting/Report.java @@ -20,7 +20,7 @@ public interface Report { * Set end time of operation and other specific properties * @return */ - public void ultimate(String owner, String uri, String operation, String size, String filePath, String id); + public void ultimate(String owner, String operation, String size, String filePath, String id, String callerIP, String lastAccess); /** * send report 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 944abcb..0761e0b 100644 --- a/src/main/java/org/gcube/contentmanager/storageserver/accounting/ReportAccountingImpl.java +++ b/src/main/java/org/gcube/contentmanager/storageserver/accounting/ReportAccountingImpl.java @@ -36,27 +36,21 @@ import org.slf4j.LoggerFactory; e.printStackTrace(); } this.ur = new RawUsageRecord(); - //generic properties + // generic properties ur.setResourceType("storage-usage"); if(consumerId!=null) ur.setConsumerId(consumerId); -// ur.setResourceOwner("paolo.fabriani"); + // ur.setResourceOwner("paolo.fabriani"); if(resourceScope !=null) ur.setResourceScope(resourceScope); -//set creation time - if(creationTime == null){ - Calendar createTime = new GregorianCalendar(); - ur.setCreateTime(createTime.getTime()); - }else{ - 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(); - } + //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(); ur.setCreateTime(date); } - } @Override @@ -66,17 +60,20 @@ import org.slf4j.LoggerFactory; } @Override - public void ultimate(String owner, String uri, String operation, String size, String filePath, String id) { - logger.info("set accounting properties: owner "+owner+" uri: "+uri+" operation: "+operation+" size: "+size+ " remotePath: "+filePath+" id: "+id); + 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 if(owner != null) ur.setResourceOwner(owner); - if(uri != null) ur.setResourceSpecificProperty("objectURI", uri); +// 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); - setEndTime(); + ur.setResourceSpecificProperty("dataCount", "1"); + ur.setResourceSpecificProperty("callerIP", "etics.eng.it"); +// setEndTime(); + ur.setResourceSpecificProperty("lastAccess", lastAccess); } @Override public void send() { diff --git a/src/main/java/org/gcube/contentmanager/storageserver/parse/JsonParser.java b/src/main/java/org/gcube/contentmanager/storageserver/parse/JsonParser.java index 034802e..4139044 100644 --- a/src/main/java/org/gcube/contentmanager/storageserver/parse/JsonParser.java +++ b/src/main/java/org/gcube/contentmanager/storageserver/parse/JsonParser.java @@ -24,7 +24,21 @@ public class JsonParser extends Thread{ private CubbyHole c; private int number; private Report report; - private String previousInsert; +// object fields + private String op; + private String filename; + private String type; + private String name; + private String owner; + private String creationTime; + private String lastAccess; + private String lastOperation; + private String lastUser; + private int linkCount; + private String delete; + private String id; + private String callerIp; +// private String previousInsert; public JsonParser(CubbyHole c, int number){ this.c=c; this.number=number; @@ -44,107 +58,103 @@ public class JsonParser extends Thread{ while(true){ DBObject x=c.get(); logger.info("Consumer #" + this.number + " got: " + x); + op = (String) x.get("op"); // retrieve object fields DBObject obj=(DBObject)x.get("o"); - String op=(String) x.get("op"); - String filename=(String) obj.get("filename"); - String type=(String) obj.get("type"); - String name=(String) obj.get("name"); - String owner=(String) obj.get("owner"); - String creationTime=(String) obj.get("creationTime"); - String lastAccess=null; -// logger.info("obj.get(lastAccess) "+obj.get("lastAccess")); - if(obj.get("lastAccess") != null) lastAccess=(String)obj.get("lastAccess"); -// logger.info("last Access field: "+lastAccess); - String lastOperation=null; -// logger.info("obj.get(lastAccess) "+obj.get("lastOperation")); - if(obj.get("lastOperation") != null) lastOperation=(String)obj.get("lastOperation"); -// logger.info("last OPERATION field: "+lastOperation); - String lastUser=null; -// logger.info("obj.get(lastUser) "+obj.get("lastUser")); - if(obj.get("lastUser") != null) lastUser=(String)obj.get("lastUser"); - int linkCount=0; -// logger.info("obj.get(lastUser) "+obj.get("lastUser")); - if(obj.get("linkCount") != null) linkCount=(int)obj.get("linkCount"); -// logger.info("last USER field: "+lastUser); - String delete=null; -// logger.info("obj.get(OnDeleting) "+obj.get("onDeleting")); - if(obj.get("onDeleting") != null) delete=(String)obj.get("onDeleting"); -// logger.info("delete field: "+delete); - ObjectId objectId=(ObjectId)obj.get("_id"); - String id = objectId.toString(); + 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+ " id: "+id+" lastOperation "+lastOperation+" lastUser: "+lastUser+" lastAccess: "+lastAccess); if(((length >0) && ((filename!=null) || (linkCount > 0)))){ - //call to the accounting library + String scope=null; if(filename!=null) 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); } 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; } // operation=mappingOperationField(op, id, delete, lastAccess); -// report(op, filename, owner, creationTime, delete, id, length,scope, operation); + //call to the accounting library + report( filename, owner, creationTime, id, length, scope, lastOperation, callerIp, lastAccess, lastUser); logger.info(" operation accounted "+lastOperation); - logger.info("\n[accountingCall] operation: "+lastOperation+"\n\t name: "+name+"\n\t type: "+type+"\n\t path: "+filename+"\n\t length: "+length+"\n\t owner: "+owner+"\n\t cretionTime: "+creationTime+"\n\t id: "+id+"\n\t scope: "+scope+"\n\t lastOperation "+lastOperation+"\n\t lastUser: "+lastUser+"\n\t lastAccess: "+lastAccess); -// }else if(op.equals("i")){ -// previousInsert=id; + logger.info("\n[accountingCall] operation: "+lastOperation+"\n\t name: "+name+"\n\t type: "+type+"\n\t path: "+filename+"\n\t length: "+length+"\n\t owner: "+owner+"\n\t cretionTime: "+creationTime+"\n\t id: "+id+"\n\t scope: "+scope+"\n\t lastOperation "+lastOperation+"\n\t lastUser: "+lastUser+"\n\t lastAccess: "+lastAccess+"\n\t callerIp: "+callerIp); }else{ logger.info("operation is not accounted"); } } } - private void report(String op, String filename, String owner, - String creationTime, String delete, String id, long length, - String scope, String operation) { - report.init(owner, scope, creationTime); -// report.timeUpdate(); - report.ultimate(owner, null, operation, length+"", filename, id); + private void retrieveObjectFields(DBObject obj) { + filename = (String) obj.get("filename"); + type = (String) obj.get("type"); + name = (String) obj.get("name"); + owner = (String) obj.get("owner"); + creationTime = (String) obj.get("creationTime"); + lastAccess = null; + if(obj.get("lastAccess") != null) lastAccess=(String)obj.get("lastAccess"); + callerIp = null; + if(obj.get("callerIP") != null) callerIp=(String)obj.get("callerIP"); + lastOperation = null; + if(obj.get("lastOperation") != null) lastOperation=(String)obj.get("lastOperation"); + lastUser = null; + if(obj.get("lastUser") != null) lastUser=(String)obj.get("lastUser"); + linkCount = 0; + if(obj.get("linkCount") != null) linkCount=(int)obj.get("linkCount"); + delete = null; + if(obj.get("onDeleting") != null) delete=(String)obj.get("onDeleting"); + ObjectId objectId=(ObjectId)obj.get("_id"); + id = objectId.toString(); + } + + private void report(String filename, String owner, + String creationTime, String id, long length, + String scope, String operation, String callerIP, String lastAccess, String lastUser) { + report.init(lastUser, scope, creationTime); +// report.timeUpdate(); + report.ultimate(owner, operation, length+"", filename, id, callerIP, lastAccess); report.send(); } - private String mappingOperationField(String op, String id, String onDeleting, String lastRead) throws ParseException { - logger.info("delete field: "+onDeleting); - if(op.equals("u")){ - if((onDeleting != null) && (onDeleting.equals("true"))){ - logger.info("found delete field"); - return "DELETE"; - }else if(lastRead !=null){ - SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy 'at' hh:mm:ss z"); - Date dateLastRead = sdf.parse(lastRead); -// Calendar calendarLastRead = Calendar.getInstance(); -// calendarLastRead.setTime(dateLastRead); -// calendarLastRead.set(Calendar.MINUTE, -5); - Calendar now=Calendar.getInstance(); - logger.info("now: "+sdf.format(now.getTime())); - now.add(Calendar.MINUTE, MINUTE_DECREMENT); -// logger.info("now decreased -5 min: "+sdf.format(dateNow)); -// logger.info("lastRead is "+sdf.format(dateLastRead)+" now,5 min decreased is"+sdf.format(dateNow)); - logger.info("now decreased -5 min: "+sdf.format(now.getTime())); - logger.info("lastRead is "+sdf.format(dateLastRead)+" now,5 min decreased is"+sdf.format(now.getTime())); - if(now.getTime().compareTo(dateLastRead) < 0){ - logger.info("It is a read"); - return "READ"; - }else{ - logger.info("It isn't a read"); - return "UPDATE"; - } - - }else - return "UPDATE"; - }else if(op.equals("i")){ - return "INSERT"; - }else if(op.equals("d")){ - return "DELETE"; - } - return op; - } +// private String mappingOperationField(String op, String id, String onDeleting, String lastRead) throws ParseException { +// logger.info("delete field: "+onDeleting); +// if(op.equals("u")){ +// if((onDeleting != null) && (onDeleting.equals("true"))){ +// logger.info("found delete field"); +// return "DELETE"; +// }else if(lastRead !=null){ +// SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy 'at' hh:mm:ss z"); +// Date dateLastRead = sdf.parse(lastRead); +// Calendar now=Calendar.getInstance(); +// logger.info("now: "+sdf.format(now.getTime())); +// now.add(Calendar.MINUTE, MINUTE_DECREMENT); +// logger.info("now decreased -5 min: "+sdf.format(now.getTime())); +// logger.info("lastRead is "+sdf.format(dateLastRead)+" now,5 min decreased is"+sdf.format(now.getTime())); +// if(now.getTime().compareTo(dateLastRead) < 0){ +// logger.info("It is a read"); +// return "READ"; +// }else{ +// logger.info("It isn't a read"); +// return "UPDATE"; +// } +// +// }else +// return "UPDATE"; +// }else if(op.equals("i")){ +// return "INSERT"; +// }else if(op.equals("d")){ +// return "DELETE"; +// } +// return op; +// } private String retrieveScopeFromRemoteFilePath(String filename) { String[] split=filename.split("/");