Skip to content

Commit

Permalink
current state of ABACUS extension
Browse files Browse the repository at this point in the history
  • Loading branch information
MarenHanke committed Jan 24, 2024
1 parent a6b6906 commit 218e8bb
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,10 @@ public Response storeGraph(@DefaultValue("unnamed") @QueryParam("name") String n
Check if user has a limit regarding number of graph or covers and throw an error if the limit is violated.
*/

if (userLimitsHandler.reachedGraphCountLimit(username)){
requestHandler.log(Level.WARNING, "user: " + username + " reached graph count limit.");
return requestHandler.writeError(Error.INTERNAL, "Graph count limit reached. Delete a graph before generating a new one, or contact administrator to adjust limits.");
}
//if (userLimitsHandler.reachedGraphCountLimit(username)){
// requestHandler.log(Level.WARNING, "user: " + username + " reached graph count limit.");
// return requestHandler.writeError(Error.INTERNAL, "Graph count limit reached. Delete a graph before generating a new one, or contact administrator to adjust limits.");
//}

File graphDir = new File("tmp" + File.separator + username);
if (!graphDir.exists()) {
Expand Down Expand Up @@ -915,16 +915,12 @@ public Response getMultiplexGraph(@DefaultValue("GRAPH_ML") @QueryParam("outputF
return requestHandler.writeError(Error.PARAMETER_INVALID,
"Specified graph output format does not exist.");
}
System.out.println("serviceclass: format");
System.out.println(format);
MultiplexGraph graph = database.getMultiplexGraph(username, graphIdStr);
System.out.println("serviceclass: graph.name");
System.out.println(graph.getName());
if (graph == null)
return requestHandler.writeError(Error.PARAMETER_INVALID,
"Graph does not exist: graph key " + graphIdStr);

generalLogger.getLogger().log(Level.INFO, "user " + username + ": get cover " + graphIdStr + " in format " + graphOutputFormatStr );
generalLogger.getLogger().log(Level.INFO, "user " + username + ": get multiplex graph " + graphIdStr + " in format " + graphOutputFormatStr );
return Response.ok(requestHandler.writeMultiplexGraph(graph, format)).build();
} catch (Exception e) {
requestHandler.log(Level.SEVERE, "", e);
Expand Down Expand Up @@ -952,7 +948,7 @@ public Response getMultiplexGraph(@DefaultValue("GRAPH_ML") @QueryParam("outputF
@ApiOperation(tags = {"delete"}, value = "Delete Graph", notes = "Deletes a graph.")
public Response deleteGraph(@PathParam("graphId") String graphIdStr) {
try {

System.out.println("ServiceClass: deleteGraph");
String username = ((UserAgent) Context.getCurrent().getMainAgent()).getLoginName();
try {
database.deleteGraph(username, graphIdStr, threadHandler); //done
Expand Down Expand Up @@ -990,18 +986,21 @@ public Response deleteGraph(@PathParam("graphId") String graphIdStr) {
@ApiOperation(tags = {"delete"}, value = "Delete Graph", notes = "Deletes a graph.")
public Response deleteMultiplexGraph(@PathParam("graphId") String graphIdStr) {
try {

System.out.println("ServiceClass: 1");
String username = ((UserAgent) Context.getCurrent().getMainAgent()).getLoginName();
try {
database.deleteMultiplexGraph(username, graphIdStr, threadHandler); //done

database.deleteMultiplexGraph(username, graphIdStr, threadHandler);
System.out.println("ServiceClass: 2");
} catch (Exception e) {
if(e.getMessage() != null) {
requestHandler.writeError(Error.INTERNAL, "Graph could not be deleted: " + e.getMessage());
System.out.println("ServiceClass: 3");
}
requestHandler.writeError(Error.INTERNAL, "Graph not found");
System.out.println("ServiceClass: 4");
}
generalLogger.getLogger().log(Level.INFO, "user " + username + ": delete graph " + graphIdStr);
System.out.println("ServiceClass: 5");
return Response.ok(requestHandler.writeConfirmationXml()).build();
} catch (Exception e) {
requestHandler.log(Level.SEVERE, "", e);
Expand Down Expand Up @@ -1046,10 +1045,10 @@ public Response createCover(@PathParam("graphId") String graphIdStr,
/*
Check if user has a limit regarding covers and throw an error if the limit is violated.
*/
if (userLimitsHandler.reachedCoverCountLimit(username)){
requestHandler.log(Level.WARNING, "user: " + username + " reached cover count limit.");
return requestHandler.writeError(Error.INTERNAL, "Cover count limit reached. Delete a cover before generating a new one, or contact administrator to adjust limits.");
}
//if (userLimitsHandler.reachedCoverCountLimit(username)){
// requestHandler.log(Level.WARNING, "user: " + username + " reached cover count limit.");
// return requestHandler.writeError(Error.INTERNAL, "Cover count limit reached. Delete a cover before generating a new one, or contact administrator to adjust limits.");
//}

CoverInputFormat format;
try {
Expand Down Expand Up @@ -2295,14 +2294,14 @@ public Response runGroundTruthBenchmark(@DefaultValue("unnamed") @QueryParam("co
/*
Check if user has a limit regarding number of graph or covers and throw an error if the limit is violated.
*/
if (userLimitsHandler.reachedGraphCountLimit(username)){
requestHandler.log(Level.WARNING, "user: " + username + " reached graph count limit.");
return requestHandler.writeError(Error.INTERNAL, "Graph count limit reached. Delete a graph before generating a new one, or contact administrator to adjust limits.");
}
if (userLimitsHandler.reachedCoverCountLimit(username)){
requestHandler.log(Level.WARNING, "user: " + username + " reached cover count limit.");
return requestHandler.writeError(Error.INTERNAL, "Cover count limit reached. Delete a cover before generating a new one, or contact administrator to adjust limits.");
}
//if (userLimitsHandler.reachedGraphCountLimit(username)){
// requestHandler.log(Level.WARNING, "user: " + username + " reached graph count limit.");
// return requestHandler.writeError(Error.INTERNAL, "Graph count limit reached. Delete a graph before generating a new one, or contact administrator to adjust limits.");
//}
//if (userLimitsHandler.reachedCoverCountLimit(username)){
// requestHandler.log(Level.WARNING, "user: " + username + " reached cover count limit.");
// return requestHandler.writeError(Error.INTERNAL, "Cover count limit reached. Delete a cover before generating a new one, or contact administrator to adjust limits.");
//}


GraphCreationType benchmarkType;
Expand Down Expand Up @@ -3327,12 +3326,33 @@ public Response getAlgorithmCompatibleGraphTypes(@PathParam("CoverCreationType")
@ApiOperation(tags = {"names"}, value = "Algorithms information", notes = "Returns all algorithm type names.")
public Response getAlgorithmNames() {
try {
System.out.println("ServiceClass: getAlgorithmNames: " + requestHandler.writeAlgorithmNames());
return Response.ok(requestHandler.writeAlgorithmNames()).build();
} catch (Exception e) {
requestHandler.log(Level.SEVERE, "", e);
return requestHandler.writeError(Error.INTERNAL, "Internal system error.");
}
}

/**
* Returns all algorithm type names.
*
* @return The types in a names xml. Or an error xml.
*/
@GET
@Path("multiplexalgorithms")
@Produces(MediaType.TEXT_XML)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success"),
@ApiResponse(code = 401, message = "Unauthorized") })
@ApiOperation(tags = {"names"}, value = "Algorithms information", notes = "Returns all algorithm type names.")
public Response getMultiplexAlgorithmNames() {
try {
return Response.ok(requestHandler.writeMultiplexAlgorithmNames()).build();
} catch (Exception e) {
requestHandler.log(Level.SEVERE, "", e);
return requestHandler.writeError(Error.INTERNAL, "Internal system error.");
}
}

/**
* Returns all centrality measure names.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,10 @@ public static CustomGraph load(String key, ArangoDatabase db, String transId) {
ArangoCollection collection = db.collection(collectionName);
DocumentReadOptions readOpt = new DocumentReadOptions().streamTransactionId(transId);
AqlQueryOptions queryOpt = new AqlQueryOptions().streamTransactionId(transId);
System.out.println("Graph load: collection: " + collection);
System.out.println("Graph load: key: " + key);
System.out.println("Graph load: BaseDocument.class: " + BaseDocument.class);
System.out.println("Graph load: readOpt: " + readOpt);
BaseDocument bd = collection.getDocument(key, BaseDocument.class, readOpt);

if (bd != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ public static MultiplexGraph load(String key, ArangoDatabase db, String transId)
MultiplexGraph graph = null;
ArangoCollection collection = db.collection(collectionName);
DocumentReadOptions readOpt = new DocumentReadOptions().streamTransactionId(transId);
AqlQueryOptions queryOpt = new AqlQueryOptions().streamTransactionId(transId);
//AqlQueryOptions queryOpt = new AqlQueryOptions().streamTransactionId(transId);
System.out.println("MultiplexGraph load: collection: " + collection);
System.out.println("MultiplexGraph load: key: " + key);
System.out.println("MultiplexGraph load: BaseDocument.class: " + BaseDocument.class);
System.out.println("MultiplexGraph load: readOpt: " + readOpt);
BaseDocument bd = collection.getDocument(key, BaseDocument.class, readOpt);

if (bd != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,6 @@ private MultiplexGraph getMultiplexGraph(String key) {
db.abortStreamTransaction(transId);
throw e;
}
System.out.println("Database getMultiplexGraph(key): graph.name");
System.out.println(graph.getName());
return graph;
}

Expand Down Expand Up @@ -435,7 +433,6 @@ public ArrayList<CustomGraphMeta> getGraphMetaDataEfficiently(String username, i
* @return the list of graphs
*/
public ArrayList<CustomGraphMeta> getMultiplexGraphMetaDataOfLayersEfficiently(String username, String key){
System.out.println("key in database:" + key);
String transId = getTransactionId(MultiplexGraph.class, false);
ObjectMapper objectMapper = new ObjectMapper(); // needed to instantiate CustomGraphMeta from JSON
ArrayList<CustomGraphMeta> customGraphMetas = new ArrayList<CustomGraphMeta>();
Expand Down Expand Up @@ -708,17 +705,16 @@ public void deleteMultiplexGraph(String username, String graphKey, ThreadHandler
threadHandler.interruptBenchmark(id);

List<Cover> coverList = getCovers(username, graphKey);
System.out.println("Database: 1 : coverlist : " + coverList);
for (Cover cover : coverList) {
try {
deleteCover(cover, threadHandler);
} catch (Exception e) {
throw e;
}
}

System.out.println("Database: 2 : coverlist : " + coverList);
try {
MultiplexGraph graph = getMultiplexGraph(username, graphKey);

String transId = this.getTransactionId(null, true);
DocumentReadOptions readOpt = new DocumentReadOptions().streamTransactionId(transId);
DocumentDeleteOptions deleteOpt = new DocumentDeleteOptions().streamTransactionId(transId);
Expand Down Expand Up @@ -1991,9 +1987,10 @@ else if(c == SimulationSeriesGroup.class){
}
else if(c == MultiplexGraph.class) {
collections = new String[] {collectionNames.get(0),collectionNames.get(1),collectionNames.get(2),collectionNames.get(3),collectionNames.get(4),collectionNames.get(13)};
System.out.println("Database: getTransactionId: " + collections);
}
else {
collections = collectionNames.subList(0, 13).toArray(new String[10]);
collections = collectionNames.subList(0, 14).toArray(new String[10]);
}
StreamTransactionEntity tx;
if(write) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import i5.las2peer.services.ocd.adapters.graphOutput.GraphOutputAdapterFactory;
import i5.las2peer.services.ocd.adapters.graphOutput.GraphOutputFormat;
import i5.las2peer.services.ocd.adapters.metaOutput.*;
import i5.las2peer.services.ocd.algorithms.ABACUSAlgorithm;
import i5.las2peer.services.ocd.centrality.data.CentralityMap;
import i5.las2peer.services.ocd.centrality.data.CentralityMeasureType;
import i5.las2peer.services.ocd.centrality.data.CentralityMeta;
Expand Down Expand Up @@ -680,8 +681,6 @@ public String writeMultiplexGraph(MultiplexGraph graph, GraphOutputFormat output
Writer writer = new StringWriter();
adapter.setWriter(writer);
adapter.writeGraph(graph);
System.out.println("Requesthandler: writeMultiplexGraph");
System.out.println(writer.toString());
return writer.toString();
}

Expand Down Expand Up @@ -880,6 +879,7 @@ public String writeAlgorithmNames() throws ParserConfigurationException {
Element namesElt = doc.createElement("Names");
for(CoverCreationType e : CoverCreationType.class.getEnumConstants()) {
if(e.correspondsAlgorithm()) {
System.out.println("requestHandler.writeAlgorithmNames()" + e.getDisplayName());
Element nameElt = doc.createElement("Name");
nameElt.appendChild(doc.createTextNode(e.name()));
nameElt.setAttribute("displayName", e.getDisplayName());
Expand All @@ -889,6 +889,29 @@ public String writeAlgorithmNames() throws ParserConfigurationException {
doc.appendChild(namesElt);
return writeDoc(doc);
}

/**
* Creates an XML document containing all ocd algorithm names.
* @return The document.
* @throws ParserConfigurationException if parsing failed
*/
public String writeMultiplexAlgorithmNames() throws ParserConfigurationException {
Document doc = getDocument();
Element namesElt = doc.createElement("Names");
for(CoverCreationType e : CoverCreationType.class.getEnumConstants()) {
if(e.correspondsAlgorithm()) {
if(e.getDisplayName() == "ABACUS Algorithm") {
System.out.println("requestHandler.writeMultiplexAlgorithmNames()" + e.getDisplayName());
Element nameElt = doc.createElement("Name");
nameElt.appendChild(doc.createTextNode(e.name()));
nameElt.setAttribute("displayName", e.getDisplayName());
namesElt.appendChild(nameElt);
}
}
}
doc.appendChild(namesElt);
return writeDoc(doc);
}

/**
* Creates an XML document containing all centrality measure names.
Expand Down
2 changes: 1 addition & 1 deletion time_seed.dat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21113101
21113242

0 comments on commit 218e8bb

Please sign in to comment.