Added cache for FilterValues

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@142672 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-02-17 11:20:56 +00:00
parent c701df8aef
commit 5903aa2d4c
12 changed files with 283 additions and 115 deletions

View File

@ -25,6 +25,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.ContextData;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.exception.SessionExpiredException;
import com.allen_sauer.gwt.log.client.Log;
@ -1125,7 +1126,7 @@ public class ActiveFiltersPanel extends SimpleContainer {
AccountingManagerServiceAsync.INSTANCE.getFilterValues(
requestFilterValue,
new AsyncCallback<ArrayList<FilterValue>>() {
new AsyncCallback<FilterValuesResponse>() {
@Override
public void onFailure(Throwable caught) {
@ -1143,11 +1144,11 @@ public class ActiveFiltersPanel extends SimpleContainer {
}
@Override
public void onSuccess(ArrayList<FilterValue> result) {
public void onSuccess(FilterValuesResponse result) {
Log.debug("FilterValues: " + result);
accountingMonitor.hide();
ArrayList<String> values = new ArrayList<String>();
for (FilterValue fv : result) {
for (FilterValue fv : result.getFilterValues()) {
values.add(fv.getValue());
}
if (cancelValue) {

View File

@ -5,8 +5,8 @@ import java.util.ArrayList;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.Context;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException;
@ -90,7 +90,7 @@ public interface AccountingManagerService extends RemoteService {
* @return
* @throws ServiceException
*/
public ArrayList<FilterValue> getFilterValues(
public FilterValuesResponse getFilterValues(
FilterValuesRequest filterValuesRequest) throws ServiceException;
/**

View File

@ -8,8 +8,8 @@ import java.util.ArrayList;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.Context;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.session.UserInfo;
@ -78,14 +78,8 @@ public interface AccountingManagerServiceAsync {
void getFilterKeys(AccountingType accountingType,
AsyncCallback<ArrayList<FilterKey>> callback);
/**
*
* @param filterValuesRequest
* request values available
* @param callback
*/
void getFilterValues(FilterValuesRequest filterValuesRequest,
AsyncCallback<ArrayList<FilterValue>> callback);
AsyncCallback<FilterValuesResponse> callback);
/**
*

View File

@ -97,7 +97,7 @@ public class AccountingClientCallable implements Callable<TaskStatus> {
+ "_" + taskRequest.getSeriesRequest().toString());
accountingCache.put(key, seriesResponse);
accountingCache.putSeries(key, seriesResponse);
AccountingStateData accountingStateData = new AccountingStateData(
taskRequest.getAccountingType(),

View File

@ -25,8 +25,8 @@ import org.gcube.portlets.admin.accountingmanager.shared.Constants;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.Context;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException;
@ -144,7 +144,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
logger.debug("Accounting Cache retrieved in Servlet: "
+ accountingCache);
SeriesResponse seriesResponse = accountingCache.get(key);
SeriesResponse seriesResponse = accountingCache.getSeries(key);
if (seriesResponse == null) {
logger.info("Accounting no data in Cache retrieved, call Service");
@ -303,21 +303,49 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
* {@inheritDoc}
*/
@Override
public ArrayList<FilterValue> getFilterValues(
public FilterValuesResponse getFilterValues(
FilterValuesRequest filterValuesRequest) throws ServiceException {
try {
SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
AccountingCallerInterface accountingCaller;
if (Constants.DEBUG_MODE) {
accountingCaller = new AccountingCallerTester();
String key = new String(serviceCredentials.getScope() + "_"
+ filterValuesRequest.toString());
logger.info("Search Accounting filter values in Cache with key: "
+ key);
ServletContext sc = getServletContext();
AccountingCache accountingCache = (AccountingCache) sc
.getAttribute(SessionConstants.ACCOUNTING_CACHE);
logger.debug("Accounting Cache retrieved in Servlet: "
+ accountingCache);
FilterValuesResponse filterValuesResponse = accountingCache
.getFilterValues(key);
if (filterValuesResponse == null
|| filterValuesResponse.getFilterValues() == null
|| filterValuesResponse.getFilterValues().isEmpty()) {
AccountingCallerInterface accountingCaller;
if (Constants.DEBUG_MODE) {
accountingCaller = new AccountingCallerTester();
} else {
accountingCaller = new AccountingCaller();
}
filterValuesResponse = accountingCaller
.getFilterValues(filterValuesRequest);
if (filterValuesResponse.getFilterValues() != null
&& !filterValuesResponse.getFilterValues().isEmpty()) {
accountingCache.putFilterValues(key, filterValuesResponse);
}
logger.info("Accounting no filter values in Cache retrieved, call Service");
} else {
accountingCaller = new AccountingCaller();
logger.info("Accounting use filter values in Cache");
}
ArrayList<FilterValue> filterValues = accountingCaller
.getFilterValues(filterValuesRequest);
return filterValues;
return filterValuesResponse;
} catch (ServiceException e) {
e.printStackTrace();
@ -366,17 +394,18 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
logger.debug("isRootScope()");
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
if (Constants.DEBUG_MODE) {
logger.debug("RootScope: "+true);
logger.debug("RootScope: " + true);
return true;
}
}
LiferayGroupManager groupManagement = new LiferayGroupManager();
Boolean isRoot = groupManagement.isRootVO(groupManagement
.getGroupIdFromInfrastructureScope(serviceCredentials.getScope()));
.getGroupIdFromInfrastructureScope(serviceCredentials
.getScope()));
logger.debug("RootScope: "+isRoot);
logger.debug("RootScope: " + isRoot);
return isRoot;
} catch (ServiceException e) {

View File

@ -20,8 +20,8 @@ import org.gcube.portlets.admin.accountingmanager.server.amservice.query.Account
import org.gcube.portlets.admin.accountingmanager.server.amservice.query.AccountingQueryTop;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException;
@ -35,7 +35,8 @@ import org.slf4j.LoggerFactory;
*
*/
public class AccountingCaller implements AccountingCallerInterface {
private static Logger logger = LoggerFactory.getLogger(AccountingCaller.class);
private static Logger logger = LoggerFactory
.getLogger(AccountingCaller.class);
public AccountingCaller() {
super();
@ -43,27 +44,25 @@ public class AccountingCaller implements AccountingCallerInterface {
public ArrayList<FilterKey> getFilterKeys(AccountingType accountingType)
throws ServiceException {
AccountingCommandGetFilterKeys accountingCommand=new AccountingCommandGetFilterKeys(accountingType);
AccountingCommandGetFilterKeys accountingCommand = new AccountingCommandGetFilterKeys(
accountingType);
return accountingCommand.execute();
}
public ArrayList<FilterValue> getFilterValues(
FilterValuesRequest filterValuesRequest)
throws ServiceException {
AccountingCommandGetFilterValues accountingCommand=new AccountingCommandGetFilterValues(filterValuesRequest);
return accountingCommand.execute();
public FilterValuesResponse getFilterValues(
FilterValuesRequest filterValuesRequest) throws ServiceException {
AccountingCommandGetFilterValues accountingCommand = new AccountingCommandGetFilterValues(
filterValuesRequest);
return accountingCommand.execute();
}
public SeriesResponse getSeries(AccountingType accountingType,
SeriesRequest seriesRequest)
throws ServiceException {
SeriesRequest seriesRequest) throws ServiceException {
try {
logger.debug("getSeries(): [AccountingType=" + accountingType
+ " , seriesRequest=" + seriesRequest + "]");
AccountingQueryBuilder queryBuilder = getAccountQueryBuilder(
accountingType, seriesRequest);
@ -82,15 +81,18 @@ public class AccountingCaller implements AccountingCallerInterface {
switch (query.getChartType()) {
case Basic:
AccountingQueryBasic accountingQueryBasic = (AccountingQueryBasic) query;
AccountingCommandBasic accountingCommandBasic=new AccountingCommandBasic(accountingQueryBasic,accountingType);
AccountingCommandBasic accountingCommandBasic = new AccountingCommandBasic(
accountingQueryBasic, accountingType);
return accountingCommandBasic.execute();
case Top:
AccountingQueryTop accountingQueryTop = (AccountingQueryTop) query;
AccountingCommandTop accountingCommandTop=new AccountingCommandTop(accountingQueryTop,accountingType);
AccountingCommandTop accountingCommandTop = new AccountingCommandTop(
accountingQueryTop, accountingType);
return accountingCommandTop.execute();
case Context:
AccountingQueryContext accountingQueryContext = (AccountingQueryContext) query;
AccountingCommandContext accountingCommandContext=new AccountingCommandContext(accountingQueryContext,accountingType);
AccountingCommandContext accountingCommandContext = new AccountingCommandContext(
accountingQueryContext, accountingType);
return accountingCommandContext.execute();
default:
throw new ServiceException(
@ -99,19 +101,17 @@ public class AccountingCaller implements AccountingCallerInterface {
}
} catch (Throwable e) {
logger.error("Error in GetSeries(): " + e.getLocalizedMessage(),e);
logger.error("Error in GetSeries(): " + e.getLocalizedMessage(), e);
throw new ServiceException("No data available!");
}
}
private AccountingQueryBuilder getAccountQueryBuilder(
AccountingType accountingType, SeriesRequest seriesRequest)
throws ServiceException {
if (accountingType == null) {
throw new ServiceException(
"Error accounting type is null");
throw new ServiceException("Error accounting type is null");
}
logger.debug("StartCalendar: "
@ -131,12 +131,9 @@ public class AccountingCaller implements AccountingCallerInterface {
case TASK:
return new AccountingQuery4Task(seriesRequest);
default:
throw new ServiceException(
"Error request type is unknow!");
throw new ServiceException("Error request type is unknow!");
}
}
}

View File

@ -4,8 +4,8 @@ import java.util.ArrayList;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException;
@ -21,7 +21,7 @@ public interface AccountingCallerInterface {
public ArrayList<FilterKey> getFilterKeys(AccountingType accountingType)
throws ServiceException;
public ArrayList<FilterValue> getFilterValues(
public FilterValuesResponse getFilterValues(
FilterValuesRequest filterValuesRequest)
throws ServiceException;

View File

@ -16,6 +16,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.Context;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
@ -93,18 +94,22 @@ public class AccountingCallerTester implements AccountingCallerInterface {
}
}
public ArrayList<FilterValue> getFilterValues(
public FilterValuesResponse getFilterValues(
FilterValuesRequest filterValuesRequest) throws ServiceException {
try {
logger.debug("getFilterValue(): [FilterValueRequest="
+ filterValuesRequest + "]");
FilterValuesResponse filterValuesResponse=null;
if (filterValuesRequest == null
|| filterValuesRequest.getAccountingType() == null
|| filterValuesRequest.getFilterKey() == null) {
return new ArrayList<FilterValue>();
filterValuesResponse = new FilterValuesResponse(
new ArrayList<FilterValue>());
return filterValuesResponse;
}
ArrayList<FilterValue> filteValues = new ArrayList<FilterValue>();
ArrayList<FilterValue> filterValues = new ArrayList<FilterValue>();
List<String> values;
String[] vals = { "giancarlo.panichi", "gianpaolo.coro" };
@ -125,11 +130,13 @@ public class AccountingCallerTester implements AccountingCallerInterface {
}
for (String value : values) {
if (value != null && !value.isEmpty()) {
filteValues.add(new FilterValue(value));
filterValues.add(new FilterValue(value));
}
}
return filteValues;
filterValuesResponse = new FilterValuesResponse(
filterValues);
return filterValuesResponse;
} catch (Throwable e) {
logger.error("Error in getFilterValues(): "
+ e.getLocalizedMessage());

View File

@ -14,6 +14,7 @@ import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.config.units.MemoryUnit;
import org.ehcache.expiry.Expirations;
import org.ehcache.jsr107.Eh107Configuration;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException;
import org.slf4j.Logger;
@ -32,8 +33,10 @@ public class AccountingCache implements Serializable {
.getLogger(AccountingCache.class);
private static final String ACCOUNTING_SERIES_CACHE = "AccountingSeriesCache";
private static final String ACCOUNTING_FILTER_VALUES_CACHE = "AccountingFilterValuesCache";
private CacheManager cacheManager;
private CacheConfiguration<String, SeriesResponse> cacheConfiguration;
private CacheConfiguration<String, SeriesResponse> cacheSeriesConfiguration;
private CacheConfiguration<String, FilterValuesResponse> cacheFilterValuesConfiguration;
// private MBeanServer mBeanServer;
@ -46,16 +49,16 @@ public class AccountingCache implements Serializable {
cacheManager = cachingProvider.getCacheManager();
logger.info("AccountingCache URI: " + cacheManager.getURI());
ResourcePoolsBuilder builder = ResourcePoolsBuilder
ResourcePoolsBuilder builderSeries = ResourcePoolsBuilder
.newResourcePoolsBuilder().heap(60L, MemoryUnit.MB)
.offheap(240L, MemoryUnit.MB);
// .disk(500L, MemoryUnit.KB)
// .withSizeOfMaxObjectSize(1L, MemoryUnit.KB)
cacheConfiguration = CacheConfigurationBuilder
cacheSeriesConfiguration = CacheConfigurationBuilder
.newCacheConfigurationBuilder(String.class,
SeriesResponse.class, builder)
SeriesResponse.class, builderSeries)
.withExpiry(
Expirations
.timeToLiveExpiration(org.ehcache.expiry.Duration
@ -71,6 +74,22 @@ public class AccountingCache implements Serializable {
* .build(true);
*/
ResourcePoolsBuilder builderFilterValues = ResourcePoolsBuilder
.newResourcePoolsBuilder().heap(10L, MemoryUnit.MB)
.offheap(30L, MemoryUnit.MB);
// .disk(500L, MemoryUnit.KB)
// .withSizeOfMaxObjectSize(1L, MemoryUnit.KB)
cacheFilterValuesConfiguration = CacheConfigurationBuilder
.newCacheConfigurationBuilder(String.class,
FilterValuesResponse.class, builderFilterValues)
.withExpiry(
Expirations
.timeToLiveExpiration(org.ehcache.expiry.Duration
.of(30L, TimeUnit.MINUTES)))
.withSizeOfMaxObjectSize(4L, MemoryUnit.MB).build();
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e);
@ -78,15 +97,16 @@ public class AccountingCache implements Serializable {
}
}
private Cache<String, SeriesResponse> initCache() throws ServiceException {
private Cache<String, SeriesResponse> initCacheSeries()
throws ServiceException {
try {
String cacheName = ACCOUNTING_SERIES_CACHE;
String cacheSeriesName = ACCOUNTING_SERIES_CACHE;
// create the cache
Cache<String, SeriesResponse> cache = cacheManager.getCache(
cacheName, String.class, SeriesResponse.class);
Cache<String, SeriesResponse> cacheSeries = cacheManager.getCache(
cacheSeriesName, String.class, SeriesResponse.class);
if (cache == null) {
if (cacheSeries == null) {
/*
* MutableConfiguration<String, SeriesResponse> config = new
* MutableConfiguration<String, SeriesResponse>()
@ -98,10 +118,13 @@ public class AccountingCache implements Serializable {
* cache = cacheManager.createCache(cacheName, config);
*/
cache = cacheManager.createCache(cacheName, Eh107Configuration
.fromEhcacheCacheConfiguration(cacheConfiguration));
cacheManager.enableManagement(cacheName, true);
cacheManager.enableStatistics(cacheName, true);
cacheSeries = cacheManager
.createCache(
cacheSeriesName,
Eh107Configuration
.fromEhcacheCacheConfiguration(cacheSeriesConfiguration));
cacheManager.enableManagement(cacheSeriesName, true);
cacheManager.enableStatistics(cacheSeriesName, true);
/*
* ObjectName objectName = new
@ -115,7 +138,7 @@ public class AccountingCache implements Serializable {
}
return cache;
return cacheSeries;
} catch (Exception e) {
logger.error(e.getLocalizedMessage(), e);
@ -125,18 +148,89 @@ public class AccountingCache implements Serializable {
}
public void put(String key, SeriesResponse value) throws ServiceException {
private Cache<String, FilterValuesResponse> initCacheFilterValues()
throws ServiceException {
try {
String cacheFilterValuesName = ACCOUNTING_FILTER_VALUES_CACHE;
// create the cache
Cache<String, FilterValuesResponse> cacheFilterValues = cacheManager
.getCache(cacheFilterValuesName, String.class,
FilterValuesResponse.class);
if (cacheFilterValues == null) {
cacheFilterValues = cacheManager
.createCache(
cacheFilterValuesName,
Eh107Configuration
.fromEhcacheCacheConfiguration(cacheFilterValuesConfiguration));
cacheManager.enableManagement(cacheFilterValuesName, true);
cacheManager.enableStatistics(cacheFilterValuesName, true);
}
return cacheFilterValues;
} catch (Exception e) {
logger.error(e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
public void putSeries(String key, SeriesResponse value)
throws ServiceException {
logger.debug("Cache put: [" + key + ", " + value + "]");
Cache<String, SeriesResponse> cache = initCache();
cache.put(key, value);
Cache<String, SeriesResponse> cacheSeries = initCacheSeries();
cacheSeries.put(key, value);
logger.debug("Cached: [" + key + ", " + value + "]");
}
/**
*
* @param key
* @return
* @throws ServiceException
*/
public SeriesResponse getSeries(String key) throws ServiceException {
logger.debug("Cache get: [" + key + "]");
Cache<String, SeriesResponse> cacheSeries = initCacheSeries();
SeriesResponse value = cacheSeries.get(key);
logger.debug("Cached value: [" + key + ", " + value + "]");
return value;
}
/**
*
* @param key
* @param value
* @throws ServiceException
*/
public void putFilterValues(String key, FilterValuesResponse value)
throws ServiceException {
logger.debug("Cache put: [" + key + ", " + value + "]");
Cache<String, FilterValuesResponse> cacheFilterValues = initCacheFilterValues();
cacheFilterValues.put(key, value);
logger.debug("Cached: [" + key + ", " + value + "]");
}
public SeriesResponse get(String key) throws ServiceException {
/**
*
* @param key
* @return
* @throws ServiceException
*/
public FilterValuesResponse getFilterValues(String key) throws ServiceException {
logger.debug("Cache get: [" + key + "]");
Cache<String, SeriesResponse> cache = initCache();
SeriesResponse value = cache.get(key);
Cache<String, FilterValuesResponse> cacheFilterValues = initCacheFilterValues();
FilterValuesResponse value = cacheFilterValues.get(key);
logger.debug("Cached value: [" + key + ", " + value + "]");
return value;
}

View File

@ -19,6 +19,7 @@ import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
import org.gcube.portlets.admin.accountingmanager.server.amservice.PeriodModeMap;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -30,7 +31,7 @@ import org.slf4j.LoggerFactory;
*
*/
public class AccountingCommandGetFilterValues implements
AccountingCommand<ArrayList<FilterValue>> {
AccountingCommand<FilterValuesResponse> {
private static final Logger logger = LoggerFactory
.getLogger(AccountingCommandGetFilterValues.class);
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMMMM dd");
@ -43,31 +44,31 @@ public class AccountingCommandGetFilterValues implements
}
@Override
public ArrayList<FilterValue> execute()
throws ServiceException {
public FilterValuesResponse execute() throws ServiceException {
try {
logger.debug("getFilterValue(): [FilterValueRequest="
+ filterValuesRequest + "]");
FilterValuesResponse filterValuesResponse = null;
if (filterValuesRequest == null
|| filterValuesRequest.getAccountingType() == null
|| filterValuesRequest.getFilterKey() == null) {
return new ArrayList<FilterValue>();
filterValuesResponse = new FilterValuesResponse(
new ArrayList<FilterValue>());
return filterValuesResponse;
}
ArrayList<FilterValue> filteValues = new ArrayList<FilterValue>();
ArrayList<FilterValue> filterValues = new ArrayList<FilterValue>();
Set<NumberedFilter> values;
AccountingPersistenceQuery apq = AccountingPersistenceQueryFactory
.getInstance();
Calendar startCalendar = GregorianCalendar
.getInstance(TemporalConstraint.DEFAULT_TIME_ZONE);
try {
startCalendar.setTime(sdf.parse(filterValuesRequest.getAccountingPeriod()
.getStartDate()));
startCalendar.setTime(sdf.parse(filterValuesRequest
.getAccountingPeriod().getStartDate()));
} catch (ParseException e) {
e.printStackTrace();
throw new ServiceException("Start Date not valid!");
@ -76,8 +77,8 @@ public class AccountingCommandGetFilterValues implements
Calendar endCalendar = GregorianCalendar
.getInstance(TemporalConstraint.DEFAULT_TIME_ZONE);
try {
endCalendar.setTime(sdf.parse(filterValuesRequest.getAccountingPeriod()
.getEndDate()));
endCalendar.setTime(sdf.parse(filterValuesRequest
.getAccountingPeriod().getEndDate()));
} catch (ParseException e) {
e.printStackTrace();
throw new ServiceException("End Date not valid!");
@ -89,49 +90,54 @@ public class AccountingCommandGetFilterValues implements
endCalendar.set(GregorianCalendar.MILLISECOND, 999);
TemporalConstraint tc = new TemporalConstraint(
startCalendar.getTimeInMillis(), endCalendar.getTimeInMillis(),
PeriodModeMap.getMode(filterValuesRequest.getAccountingPeriod()
.getPeriod()));
startCalendar.getTimeInMillis(),
endCalendar.getTimeInMillis(),
PeriodModeMap.getMode(filterValuesRequest
.getAccountingPeriod().getPeriod()));
List<Filter> filters = new ArrayList<>();
switch (filterValuesRequest.getAccountingType()) {
case JOB:
values = apq.getFilterValues(
AggregatedJobUsageRecord.class, tc, filters, filterValuesRequest.getFilterKey().getKey());
values = apq.getFilterValues(AggregatedJobUsageRecord.class,
tc, filters, filterValuesRequest.getFilterKey()
.getKey());
break;
case PORTLET:
// values = rrq.getPossibleValuesForKey(
// AggregatedPortletUsageRecord.class, filterValuesRequest
// .getFilterKey().getKey());
return filteValues;
filterValuesResponse = new FilterValuesResponse(filterValues);
return filterValuesResponse;
case SERVICE:
values = apq.getFilterValues(
AggregatedServiceUsageRecord.class, tc, filters, filterValuesRequest.getFilterKey().getKey());
AggregatedServiceUsageRecord.class, tc, filters,
filterValuesRequest.getFilterKey().getKey());
break;
case STORAGE:
values = apq.getFilterValues(
AggregatedStorageUsageRecord.class, tc, filters, filterValuesRequest.getFilterKey().getKey());
AggregatedStorageUsageRecord.class, tc, filters,
filterValuesRequest.getFilterKey().getKey());
break;
case TASK:
// values = rrq.getPossibleValuesForKey(
// AggregatedTaskUsageRecord.class, filterValuesRequest
// .getFilterKey().getKey());
return filteValues;
filterValuesResponse = new FilterValuesResponse(filterValues);
return filterValuesResponse;
default:
return filteValues;
filterValuesResponse = new FilterValuesResponse(filterValues);
return filterValuesResponse;
}
for (NumberedFilter value : values) {
if (value != null) {
filteValues.add(new FilterValue(value.getValue()));
filterValues.add(new FilterValue(value.getValue()));
}
}
return filteValues;
filterValuesResponse = new FilterValuesResponse(filterValues);
return filterValuesResponse;
} catch (Throwable e) {
logger.error("Error in AccountingCommandGetFilterValues(): "
+ e.getLocalizedMessage());

View File

@ -0,0 +1,40 @@
package org.gcube.portlets.admin.accountingmanager.shared.data;
import java.io.Serializable;
import java.util.ArrayList;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class FilterValuesResponse implements Serializable {
private static final long serialVersionUID = 5446974602912986860L;
private ArrayList<FilterValue> filterValues;
public FilterValuesResponse() {
super();
}
public FilterValuesResponse(ArrayList<FilterValue> filterValues) {
super();
this.filterValues = filterValues;
}
public ArrayList<FilterValue> getFilterValues() {
return filterValues;
}
public void setFilterValues(ArrayList<FilterValue> filterValues) {
this.filterValues = filterValues;
}
@Override
public String toString() {
return "FilterValuesResponse [filterValues=" + filterValues + "]";
}
}

View File

@ -30,7 +30,7 @@ public class TestAccountingManangerCache extends TestCase {
AccountingCache accountingCache = new AccountingCache();
SeriesResponse s = new SeriesResponse();
for (int i = 0; i < 1000000; i++) {
accountingCache.put("key" + i, s);
accountingCache.putSeries("key" + i, s);
}
Thread.sleep(180000);