Added phd test

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@177269 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2019-02-26 09:55:09 +00:00
parent f046b1a6b7
commit 71eef30d2a
1 changed files with 132 additions and 0 deletions

View File

@ -0,0 +1,132 @@
package org.gcube.phd;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.HostingNode;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.common.resources.gcore.Resources;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
import org.gcube.informationsystem.utils.ISMapper;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.icclient.ICFactory;
import org.gcube.testutility.ScopedTest;
import org.junit.Test;
public class Statistics extends ScopedTest {
private File directory;
private void printLineToFile(String line, File file) throws IOException {
synchronized (file) {
try (FileWriter fw = new FileWriter(file, true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw)) {
out.println(line);
out.flush();
} catch (IOException e) {
throw e;
}
}
}
protected String getUnmarshalledResource(Resource gr) {
StringWriter stringWriter = new StringWriter();
Resources.marshal(gr, stringWriter);
return stringWriter.toString();
}
private void addToCSV(UUID uuid, Resource gr, org.gcube.informationsystem.model.reference.entities.Resource r, File statisticsFile, boolean addHeader) throws IOException {
StringBuffer stringBuffer = new StringBuffer();
if(addHeader) {
stringBuffer.append(gr.getClass().getSimpleName());
stringBuffer.append("(byte size)");
stringBuffer.append(",");
stringBuffer.append(r.getClass().getSimpleName());
stringBuffer.append("(byte size)");
printLineToFile(stringBuffer.toString(), statisticsFile);
stringBuffer = new StringBuffer();
}
String unmarshalledGR = getUnmarshalledResource(gr);
File xmlFile = new File(directory, uuid.toString()+".xml");
printLineToFile(unmarshalledGR, xmlFile);
final byte[] grUTF8Bytes = unmarshalledGR.getBytes("UTF-8");
stringBuffer.append(grUTF8Bytes.length);
stringBuffer.append(",");
String unmarshalledR = ISMapper.marshal(r);
File jsonFile = new File(directory, uuid.toString()+".json");
printLineToFile(unmarshalledR, jsonFile);
final byte[] rUTF8Bytes = unmarshalledR.getBytes("UTF-8");
stringBuffer.append(rUTF8Bytes.length);
printLineToFile(stringBuffer.toString(), statisticsFile);
}
@Test
public void test() throws Exception {
ScopedTest.setContext(GCUBE);
boolean first = true;
directory = new File("/home/lucafrosini/Dropbox/Dottorato/Review Tesi");
File eServicesFile = new File(directory, "EService.csv");
File hostingNodeFile = new File(directory, "HostingNode.csv");
List<UUID> serviceIDs = new ArrayList<>();
// Data Tansfer Service
serviceIDs.add(UUID.fromString("d33619ab-4084-492f-800c-a2197a610132"));
// Smart Executor Service
serviceIDs.add(UUID.fromString("f7b0030a-4608-4560-bb6e-c1f33a7ad9f6"));
// Web Hosting Node Service (WHNMAnager)
serviceIDs.add(UUID.fromString("3aa75ba7-27d0-49a2-8ffc-356eb012d305"));
DiscoveryClient<GCoreEndpoint> client = ICFactory.clientFor(GCoreEndpoint.class);
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
for(UUID uuid : serviceIDs){
SimpleQuery query = ICFactory.queryFor(GCoreEndpoint.class);
query.addCondition(String.format("$resource/ID/text() eq '%1s'", uuid.toString()));
List<GCoreEndpoint> gces = client.submit(query);
GCoreEndpoint gCoreEndpoint = gces.get(0);
EService eService = resourceRegistryClient.getInstance(EService.class, uuid);
addToCSV(uuid, gCoreEndpoint, eService, eServicesFile, first);
first= false;
}
UUID hostingNodeUUID = UUID.fromString("e81b39b6-0ee4-49cd-805f-ac133544b6fe");
DiscoveryClient<HostingNode> hnClient = ICFactory.clientFor(HostingNode.class);
SimpleQuery query = ICFactory.queryFor(HostingNode.class);
query.addCondition(String.format("$resource/ID/text() eq '%1s'", hostingNodeUUID.toString()));
List<HostingNode> hostingNodes = hnClient.submit(query);
HostingNode hostingNode = hostingNodes.get(0);
org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode hn =
resourceRegistryClient.getInstance(org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode.class, hostingNodeUUID);
addToCSV(hostingNodeUUID, hostingNode, hn, hostingNodeFile, true);
}
}