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:
parent
5c36e9ae2a
commit
48647e7a77
5
pom.xml
5
pom.xml
|
@ -197,16 +197,19 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- GCube 4.2 -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>custom-portal-handler</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.applicationsupportlayer</groupId>
|
||||
<artifactId>aslcore</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency> <groupId>org.gcube.common.portal</groupId> <artifactId>portal-manager</artifactId>
|
||||
<scope>provided</scope> </dependency> -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.dvos</groupId>
|
||||
<artifactId>usermanagement-core</artifactId>
|
||||
|
|
|
@ -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<ContextData> identity = new IdentityValueProvider<ContextData>();
|
||||
smContext = new CheckBoxSelectionModel<ContextData>(identity);
|
||||
|
||||
ColumnConfig<ContextData, String> labelCol = new ColumnConfig<ContextData, String>(
|
||||
propsContextData.label(), 356, "Scope");
|
||||
|
||||
IdentityValueProvider<ContextData> identity = new IdentityValueProvider<ContextData>();
|
||||
smContext = new CheckBoxSelectionModel<ContextData>(identity);
|
||||
labelCol.setCell(new AbstractCell<String>() {
|
||||
|
||||
@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, ?>>();
|
||||
lContext.add(smContext.getColumn());
|
||||
|
@ -440,15 +453,15 @@ public class ActiveFiltersPanel extends SimpleContainer {
|
|||
gridContext = new Grid<ContextData>(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("<b>Active Filters</b>");
|
||||
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<String> contexts = accountingStateData
|
||||
.getAvailableContext().getContexts();
|
||||
ArrayList<String> contexts = accountingStateData.getAvailableContext()
|
||||
.getContexts();
|
||||
ArrayList<ContextData> ctx = new ArrayList<ContextData>();
|
||||
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;
|
||||
|
||||
|
|
|
@ -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)));
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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<String> 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();
|
||||
|
|
|
@ -71,11 +71,17 @@ public class AccountingCallerTester implements AccountingCallerInterface {
|
|||
return new ArrayList<FilterKey>();
|
||||
}
|
||||
ArrayList<FilterKey> filterKeys = new ArrayList<FilterKey>();
|
||||
|
||||
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;
|
||||
|
|
|
@ -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<String, SeriesResponse> 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<String, SeriesResponse> initCache(String scope)
|
||||
throws ServiceException {
|
||||
private Cache<String, SeriesResponse> initCache() throws ServiceException {
|
||||
try {
|
||||
String cacheName = ACCOUNTING_CACHE + scope;
|
||||
String cacheName = ACCOUNTING_CACHE;
|
||||
|
||||
// create the cache
|
||||
Cache<String, SeriesResponse> 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<String, SeriesResponse> cache = initCache(scope);
|
||||
public void put(String key, SeriesResponse value) throws ServiceException {
|
||||
logger.debug("Cache put: [" + key + ", " + value + "]");
|
||||
Cache<String, SeriesResponse> 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<String, SeriesResponse> cache = initCache(scope);
|
||||
public SeriesResponse get(String key) throws ServiceException {
|
||||
logger.debug("Cache get: [" + key + "]");
|
||||
Cache<String, SeriesResponse> 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");
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue