refs #166: Create accouting-analytics library
https://support.d4science.org/issues/166 Implementing Library git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics@117126 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7e296b7faa
commit
05895bb488
10
.classpath
10
.classpath
|
@ -6,22 +6,12 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -42,6 +42,11 @@
|
|||
<artifactId>accounting-lib</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
|
|
@ -3,18 +3,21 @@
|
|||
*/
|
||||
package org.gcube.accounting.analytics;
|
||||
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public interface Info {
|
||||
|
||||
public long getData();
|
||||
public long getDate();
|
||||
|
||||
public Number getInfo();
|
||||
|
||||
/*
|
||||
public String getUnity(); // Number of Occurrences, Kb,
|
||||
|
||||
public String getUnityDescription(); // Total Kb accumulated, Single Operation Kb
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -3,25 +3,58 @@
|
|||
*/
|
||||
package org.gcube.accounting.analytics;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||
import org.reflections.Reflections;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*/
|
||||
public class ResourceRecordQuery {
|
||||
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ResourceRecordQuery.class);
|
||||
|
||||
protected static Map<Class<? extends SingleUsageRecord>, Set<String>> resourceRecords = null;
|
||||
|
||||
public static Map<Class<? extends SingleUsageRecord>, Set<String>> getResourceRecordsTypes() {
|
||||
if(resourceRecords==null){
|
||||
resourceRecords = new HashMap<Class<? extends SingleUsageRecord>, Set<String>>();
|
||||
Package usageRecordPackage = ServiceUsageRecord.class.getPackage();
|
||||
Reflections reflections = new Reflections(usageRecordPackage.getName());
|
||||
Set<Class<? extends SingleUsageRecord>> resourceRecordsTypes = reflections.getSubTypesOf(SingleUsageRecord.class);
|
||||
for(Class<? extends SingleUsageRecord> resourceRecordsType : resourceRecordsTypes){
|
||||
try {
|
||||
SingleUsageRecord singleUsageRecord = resourceRecordsType.newInstance();
|
||||
resourceRecords.put(resourceRecordsType, singleUsageRecord.getRequiredFields());
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
logger.error(String.format("Unable to correctly istantiate %s", resourceRecordsType.getSimpleName()), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return resourceRecords;
|
||||
}
|
||||
|
||||
|
||||
protected AccountingPersistenceQuery accountingPersistenceQuery;
|
||||
|
||||
protected ResourceRecordQuery(AccountingPersistenceQuery accountingPersistenceQuery){
|
||||
this.accountingPersistenceQuery = accountingPersistenceQuery;
|
||||
}
|
||||
|
||||
public List<Info> getInfo(Class<? extends UsageRecord> usageRecordType,
|
||||
public List<Info> getInfo(Class<? extends SingleUsageRecord> usageRecordType,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters) throws Exception{
|
||||
return accountingPersistenceQuery.query(usageRecordType, temporalConstraint, filters);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.List;
|
|||
import org.gcube.accounting.analytics.Filter;
|
||||
import org.gcube.accounting.analytics.Info;
|
||||
import org.gcube.accounting.analytics.TemporalConstraint;
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
|
@ -18,10 +18,10 @@ public abstract class AccountingPersistenceQuery {
|
|||
|
||||
protected abstract void prepareConnection(AccountingPersistenceQueryConfiguration configuration) throws Exception;
|
||||
|
||||
protected abstract List<Info> reallyQuery(Class<? extends UsageRecord> usageRecordType,
|
||||
protected abstract List<Info> reallyQuery(Class<? extends SingleUsageRecord> usageRecordType,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters) throws Exception;
|
||||
|
||||
public List<Info> query(Class<? extends UsageRecord> usageRecordType,
|
||||
public List<Info> query(Class<? extends SingleUsageRecord> usageRecordType,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters) throws Exception{
|
||||
return reallyQuery(usageRecordType, temporalConstraint, filters);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.analytics;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.accounting.datamodel.SingleUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*/
|
||||
public class ResourceRecordQueryTest {
|
||||
|
||||
public class TestUsageRecord extends BasicUsageRecord implements SingleUsageRecord {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
*/
|
||||
private static final long serialVersionUID = 1939161386352514727L;
|
||||
|
||||
}
|
||||
|
||||
public static Set<Class<? extends SingleUsageRecord>> getExpectedResourceRecordsTypes(){
|
||||
Set<Class<? extends SingleUsageRecord>> expected = new HashSet<Class<? extends SingleUsageRecord>>();
|
||||
expected.add(ServiceUsageRecord.class);
|
||||
expected.add(StorageUsageRecord.class);
|
||||
expected.add(JobUsageRecord.class);
|
||||
expected.add(TaskUsageRecord.class);
|
||||
expected.add(PortletUsageRecord.class);
|
||||
return expected;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResourceRecordsTypes(){
|
||||
Set<Class<? extends SingleUsageRecord>> expected = getExpectedResourceRecordsTypes();
|
||||
Set<Class<? extends SingleUsageRecord>> found = ResourceRecordQuery.getResourceRecordsTypes().keySet();
|
||||
Assert.assertTrue(expected.containsAll(found));
|
||||
Assert.assertTrue(found.containsAll(expected));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetResourceRecordsTypesWithFakeClass(){
|
||||
Set<Class<? extends SingleUsageRecord>> expected = getExpectedResourceRecordsTypes();
|
||||
expected.add(TestUsageRecord.class);
|
||||
Set<Class<? extends SingleUsageRecord>> found = ResourceRecordQuery.getResourceRecordsTypes().keySet();
|
||||
Assert.assertTrue(expected.containsAll(found));
|
||||
Assert.assertFalse(found.containsAll(expected));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
64Z<34>/U<><55>C<><43>ߘ
|
|
@ -0,0 +1 @@
|
|||
64Z<34>/U<><55>C<><43>ߘ
|
|
@ -0,0 +1 @@
|
|||
64Z<34>/U<><55>C<><43>ߘ
|
|
@ -0,0 +1,16 @@
|
|||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<logger name="org.gcube" level="TRACE" />
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
Loading…
Reference in New Issue