update reportAccounting implementation. Now only one istance is used
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/storage-manager-trigger@94856 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
eff8bd680c
commit
317c8482e6
5
pom.xml
5
pom.xml
|
@ -39,6 +39,11 @@
|
|||
<artifactId>common-accounting-lib</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -4,7 +4,7 @@ log4j.appender.A1.File=log.txt
|
|||
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
|
||||
# ***** Max file size is set to 100KB
|
||||
log4j.appender.A1.MaxFileSize=100MB
|
||||
log4j.appender.A1.MaxFileSize=10MB
|
||||
# ***** Keep one backup file
|
||||
log4j.appender.A1.MaxBackupIndex=1
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.gcube.contentmanager.storageserver.accounting;
|
||||
|
||||
public interface Report {
|
||||
|
||||
public void init();
|
||||
/**
|
||||
* Set generic properties of report
|
||||
* @param resourceType
|
||||
|
@ -9,7 +11,7 @@ public interface Report {
|
|||
* @param resourceScope
|
||||
* @return
|
||||
*/
|
||||
public void init(String consumerId, String resourceScope, String creationTime);
|
||||
public void start(String consumerId, String resourceScope, String creationTime);
|
||||
/**
|
||||
* set start time of the operation
|
||||
* @return
|
||||
|
|
|
@ -21,9 +21,24 @@ import org.slf4j.LoggerFactory;
|
|||
final Logger logger = LoggerFactory.getLogger(ReportAccountingImpl.class);
|
||||
public RawUsageRecord ur;
|
||||
public ResourceAccounting raFactory;
|
||||
|
||||
|
||||
@Override
|
||||
public void init(String consumerId, String resourceScope, String creationTime) {
|
||||
public void init(){
|
||||
raFactory = null;
|
||||
try {
|
||||
raFactory = ResourceAccountingFactory.getResourceAccountingInstance();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(String consumerId, String resourceScope, String creationTime) {
|
||||
logger.info("set accounting properties: consumerId "+consumerId+" scope: "+resourceScope+ " creationTime "+creationTime);
|
||||
raFactory = null;
|
||||
try {
|
||||
|
|
|
@ -52,6 +52,7 @@ public class JsonParser extends Thread{
|
|||
|
||||
private void init() throws ReportException{
|
||||
report=new ReportFactory().getReport(ReportConfig.ACCOUNTING_TYPE);
|
||||
report.init();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
@ -75,6 +76,7 @@ public class JsonParser extends Thread{
|
|||
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"))){
|
||||
|
@ -118,7 +120,7 @@ public class JsonParser extends Thread{
|
|||
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.start(lastUser, scope, creationTime);
|
||||
// report.timeUpdate();
|
||||
report.ultimate(owner, operation, length+"", filename, id, callerIP, lastAccess);
|
||||
report.send();
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.gcube.contentmanager.storageserver.parse.utiils;
|
||||
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
|
||||
public class ValidationUtils {
|
||||
|
||||
public static boolean validationScope(String scope){
|
||||
ScopeBean scopeBean=new ScopeBean(scope);
|
||||
System.out.println("scope type "+scopeBean.type());
|
||||
if((scopeBean.is(Type.INFRASTRUCTURE)) || (scopeBean.is(Type.VO)) || (scopeBean.is(Type.VRE)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package org.gcube.contentmanager.storageserver.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.contentmanager.storageserver.parse.utiils.ValidationUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ValidationScopeTest {
|
||||
|
||||
private String scope="/pinco/pallino";
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertTrue(ValidationUtils.validationScope(scope));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue