From 48647e7a77f72477cdb24efe3184bf4c457e8534 Mon Sep 17 00:00:00 2001 From: "giancarlo.panichi" Date: Wed, 16 Nov 2016 16:08:51 +0000 Subject: [PATCH] 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 --- pom.xml | 5 +- .../client/filters/ActiveFiltersPanel.java | 38 +++++++---- .../client/filters/FiltersPanel.java | 6 +- .../server/AccountingManagerServiceImpl.java | 6 +- .../accountingmanager/server/SessionUtil.java | 20 +++--- .../amservice/AccountingCallerTester.java | 12 +++- .../amservice/cache/AccountingCache.java | 65 +++++++++---------- .../accountingmanager/shared/Constants.java | 4 +- .../TestAccountingManangerCache.java | 2 +- 9 files changed, 88 insertions(+), 70 deletions(-) diff --git a/pom.xml b/pom.xml index 20621fa..fc6483e 100644 --- a/pom.xml +++ b/pom.xml @@ -197,16 +197,19 @@ compile + org.gcube.portal custom-portal-handler - org.gcube.applicationsupportlayer aslcore + + org.gcube.dvos usermanagement-core diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java index b560f48..aeb797a 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java @@ -38,6 +38,7 @@ import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.event.shared.EventBus; import com.google.gwt.safehtml.shared.SafeHtml; 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.ui.HasValue; import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign; @@ -239,7 +240,7 @@ public class ActiveFiltersPanel extends SimpleContainer { gridFilter.getView().setStripeRows(true); gridFilter.getView().setColumnLines(true); gridFilter.getView().setAutoFill(true); - gridFilter.setBorders(false); + gridFilter.setBorders(true); gridFilter.setColumnReordering(false); gridFilter.getView().setAutoExpandColumn(valueColumn); gridFilter.getView().setSortingEnabled(false); @@ -423,11 +424,23 @@ public class ActiveFiltersPanel extends SimpleContainer { ContextDataProperties propsContextData = GWT .create(ContextDataProperties.class); + IdentityValueProvider identity = new IdentityValueProvider(); + smContext = new CheckBoxSelectionModel(identity); + ColumnConfig labelCol = new ColumnConfig( propsContextData.label(), 356, "Scope"); - IdentityValueProvider identity = new IdentityValueProvider(); - smContext = new CheckBoxSelectionModel(identity); + labelCol.setCell(new AbstractCell() { + + @Override + public void render(Context context, String value, SafeHtmlBuilder sb) { + sb.appendHtmlConstant("" + + SafeHtmlUtils.htmlEscape(value) + ""); + + } + + }); List> lContext = new ArrayList>(); lContext.add(smContext.getColumn()); @@ -440,15 +453,15 @@ public class ActiveFiltersPanel extends SimpleContainer { gridContext = new Grid(storeContext, cmContextData); sm.setSelectionMode(SelectionMode.MULTI); + gridContext.setHeight("130px"); gridContext.setSelectionModel(smContext); gridContext.getView().setStripeRows(true); gridContext.getView().setColumnLines(true); gridContext.getView().setAutoFill(true); - gridContext.setBorders(false); + gridContext.setBorders(true); gridContext.setColumnReordering(false); gridContext.getView().setAutoExpandColumn(labelCol); gridContext.getView().setSortingEnabled(true); - // / @@ -538,6 +551,7 @@ public class ActiveFiltersPanel extends SimpleContainer { vlc.add(gridFilter, new VerticalLayoutData(1, 1, new Margins(0))); FieldSet fieldSet = new FieldSet(); + fieldSet.setHeight("360px"); fieldSet.setHeadingHtml("Active Filters"); fieldSet.setCollapsible(false); fieldSet.add(vlc); @@ -804,18 +818,17 @@ public class ActiveFiltersPanel extends SimpleContainer { forceLayout(); } - - private void reconfigureContext(){ + + private void reconfigureContext() { if (accountingStateData.getAvailableContext() != null && accountingStateData.getAvailableContext().getContexts() != null && !accountingStateData.getAvailableContext().getContexts() - .isEmpty()){ + .isEmpty()) { repopulatesContexts(); } else { resetContexts(); } } - private void resetContexts() { storeContext.clear(); @@ -825,8 +838,8 @@ public class ActiveFiltersPanel extends SimpleContainer { } private void repopulatesContexts() { - ArrayList contexts = accountingStateData - .getAvailableContext().getContexts(); + ArrayList contexts = accountingStateData.getAvailableContext() + .getContexts(); ArrayList ctx = new ArrayList(); for (String context : contexts) { ContextData contextData = new ContextData(context); @@ -1135,7 +1148,6 @@ public class ActiveFiltersPanel extends SimpleContainer { }); } - private void updateComboChartType(ChartType chartType) { if (chartType == null) { return; @@ -1190,7 +1202,7 @@ public class ActiveFiltersPanel extends SimpleContainer { storeFilter.commitChanges(); seq = 0; forceLayout(); - break; + break; default: break; diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/FiltersPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/FiltersPanel.java index 6512942..40fb0f1 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/FiltersPanel.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/FiltersPanel.java @@ -77,9 +77,9 @@ public class FiltersPanel extends FramedPanel { VerticalLayoutContainer vlc = new VerticalLayoutContainer(); vlc.setScrollMode(ScrollMode.AUTO); vlc.add(accountPeriodPanel, new VerticalLayoutData(1, -1, new Margins( - 4, 0, 2, 4))); - vlc.add(activeFiltersPanel, new VerticalLayoutData(1, 1, new Margins(4, - 0, 2, 4))); + 2, 0, 1, 2))); + vlc.add(activeFiltersPanel, new VerticalLayoutData(1, -1, new Margins(2, + 0, 1, 2))); vlc.add(hBox, new VerticalLayoutData(1, -1, new Margins(0))); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java index 4426ce8..0ddef0e 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImpl.java @@ -145,11 +145,11 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet String token = SessionUtil.getToken(aslSession); logger.debug("UserToken: " + token); - String key = new String(accountingType.name() + "_" + String key = new String(aslSession.getScope()+"_"+accountingType.name() + "_" + seriesRequest.toString()); 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) { logger.info("Accounting no data in Cache retrieved, call Service"); @@ -161,7 +161,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet } seriesResponse = accountingCaller.getSeries(accountingType, seriesRequest); - accountingCache.put(aslSession.getScope(), key, seriesResponse); + accountingCache.put(key, seriesResponse); } else { logger.info("Accounting use data in Cache"); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java index 632623d..0f62103 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/SessionUtil.java @@ -11,7 +11,6 @@ import javax.servlet.http.HttpSession; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; 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.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.shared.Constants; @@ -39,7 +38,7 @@ public class SessionUtil { throws ServiceException { String username = (String) httpSession .getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); - ASLSession aslSession; + ASLSession portalContext; if (username == null) { if (Constants.DEBUG_MODE) { logger.info("no user found in session, use test user"); @@ -50,24 +49,24 @@ public class SessionUtil { httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username); - aslSession = SessionManager.getInstance().getASLSession( + portalContext = SessionManager.getInstance().getASLSession( httpSession.getId(), username); - aslSession.setScope(scope); + portalContext.setScope(scope); } else { logger.info("No user found in session"); throw new SessionExpiredException("Session Expired!"); } } else { - aslSession = SessionManager.getInstance().getASLSession( + portalContext = SessionManager.getInstance().getASLSession( httpSession.getId(), username); } - logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " " - + aslSession.getScope()); + logger.info("SessionUtil: aslSession " + portalContext.getUsername() + + " " + portalContext.getScope()); - return aslSession; + return portalContext; } public static String getToken(ASLSession aslSession) @@ -118,9 +117,12 @@ public class SessionUtil { try { logger.info("Current context is " + aslSession.getScope()); ArrayList contexts = new ArrayList<>(); - + if (Constants.DEBUG_MODE) { contexts.add(aslSession.getScope()); + for(int i=0; i<50 ; i++){ + contexts.add(aslSession.getScope()+i); + } } else { contexts.add(aslSession.getScope()); GroupManager gm = new LiferayGroupManager(); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerTester.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerTester.java index 7ac208c..126fd0e 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerTester.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/AccountingCallerTester.java @@ -71,11 +71,17 @@ public class AccountingCallerTester implements AccountingCallerInterface { return new ArrayList(); } ArrayList filterKeys = new ArrayList(); + FilterKey key = new FilterKey("ConsumerId"); - FilterKey key1 = new FilterKey("ClassName"); - 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); return filterKeys; diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/cache/AccountingCache.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/cache/AccountingCache.java index 6cac16d..84003d6 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/cache/AccountingCache.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/cache/AccountingCache.java @@ -13,6 +13,7 @@ import org.ehcache.config.builders.CacheConfigurationBuilder; import org.ehcache.config.builders.ResourcePoolsBuilder; import org.ehcache.config.units.MemoryUnit; import org.ehcache.expiry.Expirations; +import org.ehcache.expiry.Expiry; import org.ehcache.jsr107.Eh107Configuration; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException; @@ -35,7 +36,7 @@ public class AccountingCache implements Serializable { private CacheManager cacheManager; private CacheConfiguration cacheConfiguration; - //private MBeanServer mBeanServer; + // private MBeanServer mBeanServer; public AccountingCache() throws ServiceException { super(); @@ -47,10 +48,10 @@ public class AccountingCache implements Serializable { logger.info("AccountingCache URI: " + cacheManager.getURI()); ResourcePoolsBuilder builder = ResourcePoolsBuilder - .newResourcePoolsBuilder().heap(2L, MemoryUnit.KB); - //.offheap(1L, MemoryUnit.MB); - - //.disk(500L, MemoryUnit.KB) + .newResourcePoolsBuilder().heap(240L, MemoryUnit.MB); + // .offheap(1L, MemoryUnit.MB); + + // .disk(500L, MemoryUnit.KB) // .withSizeOfMaxObjectSize(1L, MemoryUnit.KB) cacheConfiguration = CacheConfigurationBuilder @@ -60,13 +61,10 @@ public class AccountingCache implements Serializable { Expirations .timeToLiveExpiration(org.ehcache.expiry.Duration .of(30L, TimeUnit.MINUTES))) - .build(); + .withSizeOfMaxObjectSize(80L, MemoryUnit.MB).build(); + + // mBeanServer = ManagementFactory.getPlatformMBeanServer(); - - - //mBeanServer = ManagementFactory.getPlatformMBeanServer(); - - /* * PersistentCacheManager myCacheManager = * CacheManagerBuilder.newCacheManagerBuilder() @@ -81,10 +79,9 @@ public class AccountingCache implements Serializable { } } - private Cache initCache(String scope) - throws ServiceException { + private Cache initCache() throws ServiceException { try { - String cacheName = ACCOUNTING_CACHE + scope; + String cacheName = ACCOUNTING_CACHE; // create the cache Cache cache = cacheManager.getCache( @@ -106,16 +103,17 @@ public class AccountingCache implements Serializable { .fromEhcacheCacheConfiguration(cacheConfiguration)); cacheManager.enableManagement(cacheName, true); cacheManager.enableStatistics(cacheName, true); - - - /*ObjectName objectName = new ObjectName("javax.cache:type=CacheStatistics" - + " , CacheManager=" + (cache.getCacheManager().getURI().toString()) - + " , Cache=" + cache.getName()); - - mBeanServer.registerMBean(cache, objectName); - */ - - + + /* + * ObjectName objectName = new + * ObjectName("javax.cache:type=CacheStatistics" + + * " , CacheManager=" + + * (cache.getCacheManager().getURI().toString()) + " , Cache=" + + * cache.getName()); + * + * mBeanServer.registerMBean(cache, objectName); + */ + } return cache; @@ -128,25 +126,22 @@ public class AccountingCache implements Serializable { } - public void put(String scope, String key, SeriesResponse value) - throws ServiceException { - logger.debug("Cache put: [" + scope + ", " + key + ", " + value + "]"); - Cache cache = initCache(scope); + public void put(String key, SeriesResponse value) throws ServiceException { + logger.debug("Cache put: [" + key + ", " + value + "]"); + Cache cache = initCache(); cache.put(key, value); - logger.debug("Cached: [" + scope + ", " + key + ", " + value + "]"); + logger.debug("Cached: [" + key + ", " + value + "]"); } - public SeriesResponse get(String scope, String key) throws ServiceException { - logger.debug("Cache get: [" + scope + ", " + key + "]"); - Cache cache = initCache(scope); + public SeriesResponse get(String key) throws ServiceException { + logger.debug("Cache get: [" + key + "]"); + Cache cache = initCache(); SeriesResponse value = cache.get(key); - logger.debug("Cached value: [" + scope + ", " + value + "]"); + logger.debug("Cached value: [" + key + ", " + value + "]"); return value; } - - @Override public void finalize() throws Throwable { logger.debug("Release the cache resources"); diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/Constants.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/Constants.java index f70b567..a46dd1f 100644 --- a/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/Constants.java +++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/Constants.java @@ -18,8 +18,8 @@ public class Constants { public static final String AM_LANG = "AMLang"; public static final String DEFAULT_USER = "giancarlo.panichi"; 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_TOKEN = // "16e65d4f-11e0-4e4a-84b9-351688fccc12-98187548"; diff --git a/src/test/java/org/gcube/portlets/admin/accountingmanager/TestAccountingManangerCache.java b/src/test/java/org/gcube/portlets/admin/accountingmanager/TestAccountingManangerCache.java index e0b4884..2e4ce85 100644 --- a/src/test/java/org/gcube/portlets/admin/accountingmanager/TestAccountingManangerCache.java +++ b/src/test/java/org/gcube/portlets/admin/accountingmanager/TestAccountingManangerCache.java @@ -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("scope", "key" + i, s); + accountingCache.put("key" + i, s); } Thread.sleep(180000);