Updated support for Context

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@134254 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-11-16 16:08:51 +00:00
parent 5c36e9ae2a
commit 48647e7a77
9 changed files with 88 additions and 70 deletions

View File

@ -197,16 +197,19 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- GCube 4.2 -->
<dependency> <dependency>
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId> <artifactId>custom-portal-handler</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.applicationsupportlayer</groupId> <groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId> <artifactId>aslcore</artifactId>
</dependency> </dependency>
<!-- <dependency> <groupId>org.gcube.common.portal</groupId> <artifactId>portal-manager</artifactId>
<scope>provided</scope> </dependency> -->
<dependency> <dependency>
<groupId>org.gcube.dvos</groupId> <groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId> <artifactId>usermanagement-core</artifactId>

View File

@ -38,6 +38,7 @@ import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.EventBus; import com.google.gwt.event.shared.EventBus;
import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasValue; import com.google.gwt.user.client.ui.HasValue;
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign; import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
@ -239,7 +240,7 @@ public class ActiveFiltersPanel extends SimpleContainer {
gridFilter.getView().setStripeRows(true); gridFilter.getView().setStripeRows(true);
gridFilter.getView().setColumnLines(true); gridFilter.getView().setColumnLines(true);
gridFilter.getView().setAutoFill(true); gridFilter.getView().setAutoFill(true);
gridFilter.setBorders(false); gridFilter.setBorders(true);
gridFilter.setColumnReordering(false); gridFilter.setColumnReordering(false);
gridFilter.getView().setAutoExpandColumn(valueColumn); gridFilter.getView().setAutoExpandColumn(valueColumn);
gridFilter.getView().setSortingEnabled(false); gridFilter.getView().setSortingEnabled(false);
@ -423,11 +424,23 @@ public class ActiveFiltersPanel extends SimpleContainer {
ContextDataProperties propsContextData = GWT ContextDataProperties propsContextData = GWT
.create(ContextDataProperties.class); .create(ContextDataProperties.class);
IdentityValueProvider<ContextData> identity = new IdentityValueProvider<ContextData>();
smContext = new CheckBoxSelectionModel<ContextData>(identity);
ColumnConfig<ContextData, String> labelCol = new ColumnConfig<ContextData, String>( ColumnConfig<ContextData, String> labelCol = new ColumnConfig<ContextData, String>(
propsContextData.label(), 356, "Scope"); propsContextData.label(), 356, "Scope");
IdentityValueProvider<ContextData> identity = new IdentityValueProvider<ContextData>(); labelCol.setCell(new AbstractCell<String>() {
smContext = new CheckBoxSelectionModel<ContextData>(identity);
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<span title='"
+ SafeHtmlUtils.htmlEscape(value) + "'>"
+ SafeHtmlUtils.htmlEscape(value) + "</span>");
}
});
List<ColumnConfig<ContextData, ?>> lContext = new ArrayList<ColumnConfig<ContextData, ?>>(); List<ColumnConfig<ContextData, ?>> lContext = new ArrayList<ColumnConfig<ContextData, ?>>();
lContext.add(smContext.getColumn()); lContext.add(smContext.getColumn());
@ -440,15 +453,15 @@ public class ActiveFiltersPanel extends SimpleContainer {
gridContext = new Grid<ContextData>(storeContext, cmContextData); gridContext = new Grid<ContextData>(storeContext, cmContextData);
sm.setSelectionMode(SelectionMode.MULTI); sm.setSelectionMode(SelectionMode.MULTI);
gridContext.setHeight("130px");
gridContext.setSelectionModel(smContext); gridContext.setSelectionModel(smContext);
gridContext.getView().setStripeRows(true); gridContext.getView().setStripeRows(true);
gridContext.getView().setColumnLines(true); gridContext.getView().setColumnLines(true);
gridContext.getView().setAutoFill(true); gridContext.getView().setAutoFill(true);
gridContext.setBorders(false); gridContext.setBorders(true);
gridContext.setColumnReordering(false); gridContext.setColumnReordering(false);
gridContext.getView().setAutoExpandColumn(labelCol); gridContext.getView().setAutoExpandColumn(labelCol);
gridContext.getView().setSortingEnabled(true); gridContext.getView().setSortingEnabled(true);
// / // /
@ -538,6 +551,7 @@ public class ActiveFiltersPanel extends SimpleContainer {
vlc.add(gridFilter, new VerticalLayoutData(1, 1, new Margins(0))); vlc.add(gridFilter, new VerticalLayoutData(1, 1, new Margins(0)));
FieldSet fieldSet = new FieldSet(); FieldSet fieldSet = new FieldSet();
fieldSet.setHeight("360px");
fieldSet.setHeadingHtml("<b>Active Filters</b>"); fieldSet.setHeadingHtml("<b>Active Filters</b>");
fieldSet.setCollapsible(false); fieldSet.setCollapsible(false);
fieldSet.add(vlc); fieldSet.add(vlc);
@ -804,18 +818,17 @@ public class ActiveFiltersPanel extends SimpleContainer {
forceLayout(); forceLayout();
} }
private void reconfigureContext(){ private void reconfigureContext() {
if (accountingStateData.getAvailableContext() != null if (accountingStateData.getAvailableContext() != null
&& accountingStateData.getAvailableContext().getContexts() != null && accountingStateData.getAvailableContext().getContexts() != null
&& !accountingStateData.getAvailableContext().getContexts() && !accountingStateData.getAvailableContext().getContexts()
.isEmpty()){ .isEmpty()) {
repopulatesContexts(); repopulatesContexts();
} else { } else {
resetContexts(); resetContexts();
} }
} }
private void resetContexts() { private void resetContexts() {
storeContext.clear(); storeContext.clear();
@ -825,8 +838,8 @@ public class ActiveFiltersPanel extends SimpleContainer {
} }
private void repopulatesContexts() { private void repopulatesContexts() {
ArrayList<String> contexts = accountingStateData ArrayList<String> contexts = accountingStateData.getAvailableContext()
.getAvailableContext().getContexts(); .getContexts();
ArrayList<ContextData> ctx = new ArrayList<ContextData>(); ArrayList<ContextData> ctx = new ArrayList<ContextData>();
for (String context : contexts) { for (String context : contexts) {
ContextData contextData = new ContextData(context); ContextData contextData = new ContextData(context);
@ -1135,7 +1148,6 @@ public class ActiveFiltersPanel extends SimpleContainer {
}); });
} }
private void updateComboChartType(ChartType chartType) { private void updateComboChartType(ChartType chartType) {
if (chartType == null) { if (chartType == null) {
return; return;
@ -1190,7 +1202,7 @@ public class ActiveFiltersPanel extends SimpleContainer {
storeFilter.commitChanges(); storeFilter.commitChanges();
seq = 0; seq = 0;
forceLayout(); forceLayout();
break; break;
default: default:
break; break;

View File

@ -77,9 +77,9 @@ public class FiltersPanel extends FramedPanel {
VerticalLayoutContainer vlc = new VerticalLayoutContainer(); VerticalLayoutContainer vlc = new VerticalLayoutContainer();
vlc.setScrollMode(ScrollMode.AUTO); vlc.setScrollMode(ScrollMode.AUTO);
vlc.add(accountPeriodPanel, new VerticalLayoutData(1, -1, new Margins( vlc.add(accountPeriodPanel, new VerticalLayoutData(1, -1, new Margins(
4, 0, 2, 4))); 2, 0, 1, 2)));
vlc.add(activeFiltersPanel, new VerticalLayoutData(1, 1, new Margins(4, vlc.add(activeFiltersPanel, new VerticalLayoutData(1, -1, new Margins(2,
0, 2, 4))); 0, 1, 2)));
vlc.add(hBox, new VerticalLayoutData(1, -1, new Margins(0))); vlc.add(hBox, new VerticalLayoutData(1, -1, new Margins(0)));

View File

@ -145,11 +145,11 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
String token = SessionUtil.getToken(aslSession); String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token); logger.debug("UserToken: " + token);
String key = new String(accountingType.name() + "_" String key = new String(aslSession.getScope()+"_"+accountingType.name() + "_"
+ seriesRequest.toString()); + seriesRequest.toString());
logger.info("Search Accounting data in Cache with key: "+key); logger.info("Search Accounting data in Cache with key: "+key);
SeriesResponse seriesResponse = accountingCache.get(aslSession.getScope(), key); SeriesResponse seriesResponse = accountingCache.get(key);
if (seriesResponse == null) { if (seriesResponse == null) {
logger.info("Accounting no data in Cache retrieved, call Service"); logger.info("Accounting no data in Cache retrieved, call Service");
@ -161,7 +161,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
} }
seriesResponse = accountingCaller.getSeries(accountingType, seriesResponse = accountingCaller.getSeries(accountingType,
seriesRequest); seriesRequest);
accountingCache.put(aslSession.getScope(), key, seriesResponse); accountingCache.put(key, seriesResponse);
} else { } else {
logger.info("Accounting use data in Cache"); logger.info("Accounting use data in Cache");

View File

@ -11,7 +11,6 @@ import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager; import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.admin.accountingmanager.server.amservice.cache.AccountingCache;
import org.gcube.portlets.admin.accountingmanager.server.state.AccountingState; import org.gcube.portlets.admin.accountingmanager.server.state.AccountingState;
import org.gcube.portlets.admin.accountingmanager.server.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.server.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.shared.Constants; import org.gcube.portlets.admin.accountingmanager.shared.Constants;
@ -39,7 +38,7 @@ public class SessionUtil {
throws ServiceException { throws ServiceException {
String username = (String) httpSession String username = (String) httpSession
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); .getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
ASLSession aslSession; ASLSession portalContext;
if (username == null) { if (username == null) {
if (Constants.DEBUG_MODE) { if (Constants.DEBUG_MODE) {
logger.info("no user found in session, use test user"); logger.info("no user found in session, use test user");
@ -50,24 +49,24 @@ public class SessionUtil {
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE,
username); username);
aslSession = SessionManager.getInstance().getASLSession( portalContext = SessionManager.getInstance().getASLSession(
httpSession.getId(), username); httpSession.getId(), username);
aslSession.setScope(scope); portalContext.setScope(scope);
} else { } else {
logger.info("No user found in session"); logger.info("No user found in session");
throw new SessionExpiredException("Session Expired!"); throw new SessionExpiredException("Session Expired!");
} }
} else { } else {
aslSession = SessionManager.getInstance().getASLSession( portalContext = SessionManager.getInstance().getASLSession(
httpSession.getId(), username); httpSession.getId(), username);
} }
logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " " logger.info("SessionUtil: aslSession " + portalContext.getUsername()
+ aslSession.getScope()); + " " + portalContext.getScope());
return aslSession; return portalContext;
} }
public static String getToken(ASLSession aslSession) public static String getToken(ASLSession aslSession)
@ -118,9 +117,12 @@ public class SessionUtil {
try { try {
logger.info("Current context is " + aslSession.getScope()); logger.info("Current context is " + aslSession.getScope());
ArrayList<String> contexts = new ArrayList<>(); ArrayList<String> contexts = new ArrayList<>();
if (Constants.DEBUG_MODE) { if (Constants.DEBUG_MODE) {
contexts.add(aslSession.getScope()); contexts.add(aslSession.getScope());
for(int i=0; i<50 ; i++){
contexts.add(aslSession.getScope()+i);
}
} else { } else {
contexts.add(aslSession.getScope()); contexts.add(aslSession.getScope());
GroupManager gm = new LiferayGroupManager(); GroupManager gm = new LiferayGroupManager();

View File

@ -71,11 +71,17 @@ public class AccountingCallerTester implements AccountingCallerInterface {
return new ArrayList<FilterKey>(); return new ArrayList<FilterKey>();
} }
ArrayList<FilterKey> filterKeys = new ArrayList<FilterKey>(); ArrayList<FilterKey> filterKeys = new ArrayList<FilterKey>();
FilterKey key = new FilterKey("ConsumerId"); FilterKey key = new FilterKey("ConsumerId");
FilterKey key1 = new FilterKey("ClassName");
filterKeys.add(key); filterKeys.add(key);
filterKeys.add(key1);
key = new FilterKey("ClassName");
filterKeys.add(key);
for (int i = 0; i < 20; i++) {
key = new FilterKey("ServiceClass" + i);
filterKeys.add(key);
}
logger.debug("List FilterKeys:" + filterKeys); logger.debug("List FilterKeys:" + filterKeys);
return filterKeys; return filterKeys;

View File

@ -13,6 +13,7 @@ import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder; import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.config.units.MemoryUnit; import org.ehcache.config.units.MemoryUnit;
import org.ehcache.expiry.Expirations; import org.ehcache.expiry.Expirations;
import org.ehcache.expiry.Expiry;
import org.ehcache.jsr107.Eh107Configuration; import org.ehcache.jsr107.Eh107Configuration;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException;
@ -35,7 +36,7 @@ public class AccountingCache implements Serializable {
private CacheManager cacheManager; private CacheManager cacheManager;
private CacheConfiguration<String, SeriesResponse> cacheConfiguration; private CacheConfiguration<String, SeriesResponse> cacheConfiguration;
//private MBeanServer mBeanServer; // private MBeanServer mBeanServer;
public AccountingCache() throws ServiceException { public AccountingCache() throws ServiceException {
super(); super();
@ -47,10 +48,10 @@ public class AccountingCache implements Serializable {
logger.info("AccountingCache URI: " + cacheManager.getURI()); logger.info("AccountingCache URI: " + cacheManager.getURI());
ResourcePoolsBuilder builder = ResourcePoolsBuilder ResourcePoolsBuilder builder = ResourcePoolsBuilder
.newResourcePoolsBuilder().heap(2L, MemoryUnit.KB); .newResourcePoolsBuilder().heap(240L, MemoryUnit.MB);
//.offheap(1L, MemoryUnit.MB); // .offheap(1L, MemoryUnit.MB);
//.disk(500L, MemoryUnit.KB) // .disk(500L, MemoryUnit.KB)
// .withSizeOfMaxObjectSize(1L, MemoryUnit.KB) // .withSizeOfMaxObjectSize(1L, MemoryUnit.KB)
cacheConfiguration = CacheConfigurationBuilder cacheConfiguration = CacheConfigurationBuilder
@ -60,13 +61,10 @@ public class AccountingCache implements Serializable {
Expirations Expirations
.timeToLiveExpiration(org.ehcache.expiry.Duration .timeToLiveExpiration(org.ehcache.expiry.Duration
.of(30L, TimeUnit.MINUTES))) .of(30L, TimeUnit.MINUTES)))
.build(); .withSizeOfMaxObjectSize(80L, MemoryUnit.MB).build();
// mBeanServer = ManagementFactory.getPlatformMBeanServer();
//mBeanServer = ManagementFactory.getPlatformMBeanServer();
/* /*
* PersistentCacheManager myCacheManager = * PersistentCacheManager myCacheManager =
* CacheManagerBuilder.newCacheManagerBuilder() * CacheManagerBuilder.newCacheManagerBuilder()
@ -81,10 +79,9 @@ public class AccountingCache implements Serializable {
} }
} }
private Cache<String, SeriesResponse> initCache(String scope) private Cache<String, SeriesResponse> initCache() throws ServiceException {
throws ServiceException {
try { try {
String cacheName = ACCOUNTING_CACHE + scope; String cacheName = ACCOUNTING_CACHE;
// create the cache // create the cache
Cache<String, SeriesResponse> cache = cacheManager.getCache( Cache<String, SeriesResponse> cache = cacheManager.getCache(
@ -106,16 +103,17 @@ public class AccountingCache implements Serializable {
.fromEhcacheCacheConfiguration(cacheConfiguration)); .fromEhcacheCacheConfiguration(cacheConfiguration));
cacheManager.enableManagement(cacheName, true); cacheManager.enableManagement(cacheName, true);
cacheManager.enableStatistics(cacheName, true); cacheManager.enableStatistics(cacheName, true);
/*
/*ObjectName objectName = new ObjectName("javax.cache:type=CacheStatistics" * ObjectName objectName = new
+ " , CacheManager=" + (cache.getCacheManager().getURI().toString()) * ObjectName("javax.cache:type=CacheStatistics" +
+ " , Cache=" + cache.getName()); * " , CacheManager=" +
* (cache.getCacheManager().getURI().toString()) + " , Cache=" +
mBeanServer.registerMBean(cache, objectName); * cache.getName());
*/ *
* mBeanServer.registerMBean(cache, objectName);
*/
} }
return cache; return cache;
@ -128,25 +126,22 @@ public class AccountingCache implements Serializable {
} }
public void put(String scope, String key, SeriesResponse value) public void put(String key, SeriesResponse value) throws ServiceException {
throws ServiceException { logger.debug("Cache put: [" + key + ", " + value + "]");
logger.debug("Cache put: [" + scope + ", " + key + ", " + value + "]"); Cache<String, SeriesResponse> cache = initCache();
Cache<String, SeriesResponse> cache = initCache(scope);
cache.put(key, value); cache.put(key, value);
logger.debug("Cached: [" + scope + ", " + key + ", " + value + "]"); logger.debug("Cached: [" + key + ", " + value + "]");
} }
public SeriesResponse get(String scope, String key) throws ServiceException { public SeriesResponse get(String key) throws ServiceException {
logger.debug("Cache get: [" + scope + ", " + key + "]"); logger.debug("Cache get: [" + key + "]");
Cache<String, SeriesResponse> cache = initCache(scope); Cache<String, SeriesResponse> cache = initCache();
SeriesResponse value = cache.get(key); SeriesResponse value = cache.get(key);
logger.debug("Cached value: [" + scope + ", " + value + "]"); logger.debug("Cached value: [" + key + ", " + value + "]");
return value; return value;
} }
@Override @Override
public void finalize() throws Throwable { public void finalize() throws Throwable {
logger.debug("Release the cache resources"); logger.debug("Release the cache resources");

View File

@ -18,8 +18,8 @@ public class Constants {
public static final String AM_LANG = "AMLang"; public static final String AM_LANG = "AMLang";
public static final String DEFAULT_USER = "giancarlo.panichi"; public static final String DEFAULT_USER = "giancarlo.panichi";
public final static String DEFAULT_SCOPE = "/gcube/devNext/NextNext"; public final static String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
public final static String DEFAULT_TOKEN = "6af6eaff-35bd-4405-b747-f63246d0212a-98187548"; public final static String DEFAULT_TOKEN = "ae1208f0-210d-47c9-9b24-d3f2dfcce05f-98187548";
// public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE"; // public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE";
// public final static String DEFAULT_TOKEN = // public final static String DEFAULT_TOKEN =
// "16e65d4f-11e0-4e4a-84b9-351688fccc12-98187548"; // "16e65d4f-11e0-4e4a-84b9-351688fccc12-98187548";

View File

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