Added utility
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@178416 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8ec41a6d80
commit
bf4229014c
|
@ -0,0 +1,80 @@
|
||||||
|
package org.gcube.phd;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
|
||||||
|
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||||
|
import org.gcube.common.resources.gcore.GenericResource;
|
||||||
|
import org.gcube.common.resources.gcore.HostingNode;
|
||||||
|
import org.gcube.common.resources.gcore.Resource;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
import org.gcube.common.resources.gcore.Software;
|
||||||
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
||||||
|
|
||||||
|
public class ContextStatistic {
|
||||||
|
|
||||||
|
private ScopeBean scopeBean;
|
||||||
|
|
||||||
|
public ScopeBean getScopeBean() {
|
||||||
|
return scopeBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Class<? extends Resource>, Set<ResourceInfo<? extends Resource>>> resourceMap;
|
||||||
|
private Map<Class<? extends Resource>, SummaryStatistics> statisticsMap;
|
||||||
|
|
||||||
|
public ContextStatistic(ScopeBean scopeBean) {
|
||||||
|
this.scopeBean = scopeBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <R extends Resource> void analizeInstances(Class<R> clz) throws Exception {
|
||||||
|
Set<ResourceInfo<? extends Resource>> resources = resourceMap.get(clz);
|
||||||
|
|
||||||
|
DiscoveryClient<R> client = ICFactory.clientFor(clz);
|
||||||
|
SimpleQuery query = ICFactory.queryFor(clz);
|
||||||
|
List<R> instances = client.submit(query);
|
||||||
|
for(R r : instances) {
|
||||||
|
ResourceInfo<R> resourceInfo = new ResourceInfo<R>(r);
|
||||||
|
resources.add(resourceInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Class<? extends Resource>, Set<ResourceInfo<? extends Resource>>> getAllResources() throws Exception {
|
||||||
|
if(resourceMap ==null) {
|
||||||
|
resourceMap = new HashMap<>();
|
||||||
|
List<Class<? extends Resource>> classes = new ArrayList<>();
|
||||||
|
classes.add(GCoreEndpoint.class);
|
||||||
|
classes.add(HostingNode.class);
|
||||||
|
classes.add(ServiceEndpoint.class);
|
||||||
|
classes.add(GenericResource.class);
|
||||||
|
classes.add(Software.class);
|
||||||
|
|
||||||
|
for(Class<? extends Resource> clz : classes) {
|
||||||
|
analizeInstances(clz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resourceMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Class<? extends Resource>, SummaryStatistics> getStatistcs() throws Exception {
|
||||||
|
if(statisticsMap==null) {
|
||||||
|
statisticsMap = new HashMap<>();
|
||||||
|
getAllResources();
|
||||||
|
for(Class<? extends Resource> clz : resourceMap.keySet()) {
|
||||||
|
SummaryStatistics summaryStatistics = new SummaryStatistics();
|
||||||
|
Set<ResourceInfo<? extends Resource>> resources = resourceMap.get(clz);
|
||||||
|
for(ResourceInfo<? extends Resource> resourceInfo : resources) {
|
||||||
|
summaryStatistics.addValue(resourceInfo.getSize());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return statisticsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.gcube.phd;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
|
import org.gcube.common.resources.gcore.Resource;
|
||||||
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
|
|
||||||
|
public class ResourceInfo<R extends Resource> {
|
||||||
|
|
||||||
|
private R r;
|
||||||
|
private String unmarshalledResource;
|
||||||
|
private Integer size;
|
||||||
|
|
||||||
|
public ResourceInfo(R r) {
|
||||||
|
this.r = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getUnmarshalledResource() {
|
||||||
|
if(unmarshalledResource==null) {
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
Resources.marshal(r, stringWriter);
|
||||||
|
unmarshalledResource = stringWriter.toString();
|
||||||
|
}
|
||||||
|
return unmarshalledResource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() throws UnsupportedEncodingException {
|
||||||
|
if(size==null) {
|
||||||
|
String unmarshalledR = getUnmarshalledResource();
|
||||||
|
final byte[] grUTF8Bytes = unmarshalledR.getBytes("UTF-8");
|
||||||
|
size = grUTF8Bytes.length;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.phd;
|
package org.gcube.phd.oldclasses;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.phd;
|
package org.gcube.phd.oldclasses;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.phd;
|
package org.gcube.phd.oldclasses;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public class StatisticsAggregator extends ContextElaborator {
|
||||||
private Map<Type,Integer> contextCount;
|
private Map<Type,Integer> contextCount;
|
||||||
|
|
||||||
// <resourcetype,<id,size>>
|
// <resourcetype,<id,size>>
|
||||||
private Map<String,Map<String,Integer>> globalMap;
|
private Map<String,Map<String,Integer>> infrastructuresResourcesMap;
|
||||||
|
|
||||||
// <VOcontext,<resourcetype,<id,size>>
|
// <VOcontext,<resourcetype,<id,size>>
|
||||||
private Map<String,Map<String,Map<String,Integer>>> voContextMap;
|
private Map<String,Map<String,Map<String,Integer>>> voContextMap;
|
||||||
|
@ -52,7 +52,7 @@ public class StatisticsAggregator extends ContextElaborator {
|
||||||
|
|
||||||
public StatisticsAggregator() {
|
public StatisticsAggregator() {
|
||||||
contextCount = new HashMap<>();
|
contextCount = new HashMap<>();
|
||||||
globalMap = new HashMap<>();
|
infrastructuresResourcesMap = new HashMap<>();
|
||||||
voContextMap = new HashMap<>();
|
voContextMap = new HashMap<>();
|
||||||
directory = new File("/home/lucafrosini/Desktop/GlobalStatistics");
|
directory = new File("/home/lucafrosini/Desktop/GlobalStatistics");
|
||||||
if(!directory.exists()) {
|
if(!directory.exists()) {
|
||||||
|
@ -86,12 +86,12 @@ public class StatisticsAggregator extends ContextElaborator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public <R extends Resource> void analizeInstances(Class<R> clz) throws Exception {
|
public <R extends Resource> void analizeInstances(Class<R> clz) throws Exception {
|
||||||
Map<String,Integer> resourcesGlobalMap = globalMap.get(clz.getSimpleName());
|
Map<String,Integer> resourcesGlobalMap = infrastructuresResourcesMap.get(clz.getSimpleName());
|
||||||
Map<String,Integer> resourcesPerContextMap = null;
|
Map<String,Integer> resourcesPerVOMap = null;
|
||||||
Type type = currentScopeBean.type();
|
Type type = currentScopeBean.type();
|
||||||
|
|
||||||
if(type != Type.INFRASTRUCTURE) {
|
if(type != Type.INFRASTRUCTURE) {
|
||||||
resourcesPerContextMap = getVOContextMap().get(clz.getSimpleName());
|
resourcesPerVOMap = getVOContextMap().get(clz.getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscoveryClient<R> client = ICFactory.clientFor(clz);
|
DiscoveryClient<R> client = ICFactory.clientFor(clz);
|
||||||
|
@ -101,8 +101,8 @@ public class StatisticsAggregator extends ContextElaborator {
|
||||||
String id = r.id();
|
String id = r.id();
|
||||||
int resourceSize = getResourceSize(r);
|
int resourceSize = getResourceSize(r);
|
||||||
if(type != Type.INFRASTRUCTURE) {
|
if(type != Type.INFRASTRUCTURE) {
|
||||||
if(!resourcesPerContextMap.containsKey(id)) {
|
if(!resourcesPerVOMap.containsKey(id)) {
|
||||||
resourcesPerContextMap.put(id, resourceSize);
|
resourcesPerVOMap.put(id, resourceSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ public class StatisticsAggregator extends ContextElaborator {
|
||||||
|
|
||||||
for(Class<? extends Resource> clz : classes) {
|
for(Class<? extends Resource> clz : classes) {
|
||||||
Map<String,Integer> resourcesGlobalMap = new HashMap<>();
|
Map<String,Integer> resourcesGlobalMap = new HashMap<>();
|
||||||
globalMap.put(clz.getSimpleName(), resourcesGlobalMap);
|
infrastructuresResourcesMap.put(clz.getSimpleName(), resourcesGlobalMap);
|
||||||
|
|
||||||
if(currentScopeBean.type() != Type.INFRASTRUCTURE) {
|
if(currentScopeBean.type() != Type.INFRASTRUCTURE) {
|
||||||
Map<String,Map<String,Integer>> contextMap = getVOContextMap();
|
Map<String,Map<String,Integer>> contextMap = getVOContextMap();
|
||||||
|
@ -252,7 +252,7 @@ public class StatisticsAggregator extends ContextElaborator {
|
||||||
stringBuffer.append("Whole Infrastructure Statistics");
|
stringBuffer.append("Whole Infrastructure Statistics");
|
||||||
printLineToFile(stringBuffer.toString(), statisticsFile);
|
printLineToFile(stringBuffer.toString(), statisticsFile);
|
||||||
addHeader();
|
addHeader();
|
||||||
getStatistcsFromMap(globalMap);
|
getStatistcsFromMap(infrastructuresResourcesMap);
|
||||||
printLineToFile("", statisticsFile);
|
printLineToFile("", statisticsFile);
|
||||||
printLineToFile("", statisticsFile);
|
printLineToFile("", statisticsFile);
|
||||||
printLineToFile("", statisticsFile);
|
printLineToFile("", statisticsFile);
|
Loading…
Reference in New Issue