create distro folder

update metadata fields
enabled accounting call
added callerIp field

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/storage-manager-trigger@93968 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
roberto.cirillo 2014-04-01 09:20:28 +00:00
parent 3bd6b11c1e
commit eff8bd680c
12 changed files with 198 additions and 127 deletions

3
distro/CHANGELOG Normal file
View File

@ -0,0 +1,3 @@
v. 1.0.0 (04-05-2012)
* First release

7
distro/LICENSE Normal file
View File

@ -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.

1
distro/MAINTAINERS Normal file
View File

@ -0,0 +1 @@
* Roberto Cirillo (roberto.cirillo@isti.cnr.it), CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"

BIN
distro/README Normal file

Binary file not shown.

7
distro/changelog.xml Normal file
View File

@ -0,0 +1,7 @@
<ReleaseNotes>
<ReleaseNotes>
<Changeset component="org.gcube.content-management.storage-manager-trigger.1-0-0" date="2014-03-31">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>
</ReleaseNotes>

42
distro/descriptor.xml Normal file
View File

@ -0,0 +1,42 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>INSTALL</include>
<include>MAINTAINERS</include>
<include>changelog.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>${distroDirectory}/profile.xml</source>
<outputDirectory>/</outputDirectory>
<filtered>true</filtered>
</file>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
<file>
<source>${distroDirectory}/svnpath.txt</source>
<outputDirectory>/${artifactId}</outputDirectory>
<filtered>true</filtered>
</file>
</files>
</assembly>

25
distro/profile.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID />
<Type>Service</Type>
<Profile>
<Description>${description}</Description>
<Class>ContentManagement</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

1
distro/svnpath.txt Normal file
View File

@ -0,0 +1 @@
${scm.url}

40
pom.xml
View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-trigger</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/${project.artifactId}</connection>
<developerConnection>scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/${project.artifactId}</developerConnection>
@ -23,41 +23,11 @@
<artifactId>mongo-java-driver</artifactId>
<version>[2.6.2,)</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.slf4j</groupId> -->
<!-- <artifactId>slf4j-nop</artifactId> -->
<!-- <version>1.6.4</version> -->
<!-- </dependency> -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.gcube.resources</groupId> -->
<!-- <artifactId>common-gcore-resources</artifactId> -->
<!-- <version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.core</groupId> -->
<!-- <artifactId>common-gcore-stubs</artifactId> -->
<!-- <version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.resources.discovery</groupId> -->
<!-- <artifactId>ic-client</artifactId> -->
<!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.core</groupId> -->
<!-- <artifactId>common-encryption</artifactId> -->
<!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.core</groupId> -->
<!-- <artifactId>common-scope-maps</artifactId> -->
<!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
<!-- </dependency> -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -102,6 +72,14 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.gcube.contentmanager.storageserver.startup.Startup</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>

View File

@ -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

View File

@ -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() {

View File

@ -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("/");