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@117085 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-07-08 13:24:32 +00:00
parent a051f970f3
commit 63bc734999
9 changed files with 226 additions and 0 deletions

View File

@ -31,6 +31,7 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>

View File

@ -0,0 +1,12 @@
/**
*
*/
package org.gcube.accounting.analytics;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class Filter {
}

View File

@ -0,0 +1,20 @@
/**
*
*/
package org.gcube.accounting.analytics;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public interface Info {
public long getData();
public Number getInfo();
public String getUnity(); // Number of Occurrences, Kb,
public String getUnityDescription(); // Total Kb accumulated, Single Operation Kb
}

View File

@ -0,0 +1,27 @@
/**
*
*/
package org.gcube.accounting.analytics;
import java.util.List;
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
import org.gcube.accounting.datamodel.UsageRecord;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public class ResourceRecordQuery {
protected AccountingPersistenceQuery accountingPersistenceQuery;
protected ResourceRecordQuery(AccountingPersistenceQuery accountingPersistenceQuery){
this.accountingPersistenceQuery = accountingPersistenceQuery;
}
public List<Info> getInfo(Class<? extends UsageRecord> usageRecordType,
TemporalConstraint temporalConstraint, List<Filter> filters){
return null;
}
}

View File

@ -0,0 +1,78 @@
/**
*
*/
package org.gcube.accounting.analytics;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
import org.gcube.accounting.analytics.exception.NoAvailableScopeException;
import org.gcube.accounting.analytics.exception.NoUsableAccountingPersistenceQueryFound;
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
import org.gcube.common.scope.api.ScopeProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public abstract class ResourceRecordQueryFactory {
private static Logger logger = LoggerFactory.getLogger(ResourceRecordQueryFactory.class);
private static Map<String, ResourceRecordQuery> resourceRecordQueries;
static {
resourceRecordQueries = new HashMap<String, ResourceRecordQuery>();
}
public synchronized static ResourceRecordQuery getInstance() throws NoAvailableScopeException, NoUsableAccountingPersistenceQueryFound {
String scope = ScopeProvider.instance.get();
if(scope==null){
new NoAvailableScopeException();
}
ResourceRecordQuery resourceRecordQuery = resourceRecordQueries.get(scope);
if(resourceRecordQuery==null){
try {
ServiceLoader<AccountingPersistenceQuery> serviceLoader = ServiceLoader.load(AccountingPersistenceQuery.class);
for (AccountingPersistenceQuery found : serviceLoader) {
try {
String foundClassName = found.getClass().getSimpleName();
logger.debug("Testing {}", foundClassName);
//AccountingPersistenceQueryConfiguration configuration = AccountingPersistenceQueryConfiguration.getConfiguration(foundClassName);
//found.prepareConnection(configuration);
resourceRecordQuery = new ResourceRecordQuery(found);
break;
} catch (Exception e) {
logger.debug(String.format("%s not initialized correctly. It will not be used", found.getClass().getSimpleName()));
}
}
} catch(Exception e){
throw new NoUsableAccountingPersistenceQueryFound();
}
if(resourceRecordQuery==null){
throw new NoUsableAccountingPersistenceQueryFound();
}
resourceRecordQueries.put(scope, resourceRecordQuery);
}
return resourceRecordQuery;
}
protected ResourceRecordQueryFactory(){
}
}

View File

@ -0,0 +1,12 @@
/**
*
*/
package org.gcube.accounting.analytics;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public interface TemporalConstraint {
}

View File

@ -0,0 +1,32 @@
/**
*
*/
package org.gcube.accounting.analytics.exception;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class NoAvailableScopeException extends Exception {
/**
* Generated serial Version UID
*/
private static final long serialVersionUID = -327144230654860518L;
public NoAvailableScopeException() {
super();
}
public NoAvailableScopeException(String message) {
super(message);
}
public NoAvailableScopeException(Throwable cause) {
super(cause);
}
public NoAvailableScopeException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -0,0 +1,32 @@
/**
*
*/
package org.gcube.accounting.analytics.exception;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class NoUsableAccountingPersistenceQueryFound extends Exception {
/**
* Generated serial Version UID
*/
private static final long serialVersionUID = -327144230654860518L;
public NoUsableAccountingPersistenceQueryFound() {
super();
}
public NoUsableAccountingPersistenceQueryFound(String message) {
super(message);
}
public NoUsableAccountingPersistenceQueryFound(Throwable cause) {
super(cause);
}
public NoUsableAccountingPersistenceQueryFound(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -0,0 +1,12 @@
/**
*
*/
package org.gcube.accounting.analytics.persistence;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class AccountingPersistenceQuery {
}