Skip to content

Commit

Permalink
Merge pull request #68 from rwth-acis/release/v0.8.4
Browse files Browse the repository at this point in the history
Release v1.0.0
  • Loading branch information
AlexanderNeumann authored Nov 20, 2020
2 parents b9fdd35 + 83bdede commit 16378b7
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 49 deletions.
4 changes: 2 additions & 2 deletions bundle/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<property environment="env"/>

<property name="ivy.organisation" value="i5"/>
<property name="ivy.revision" value="0.8"/>
<property name="ivy.build.number" value="3"/>
<property name="ivy.revision" value="1.0"/>
<property name="ivy.build.number" value="0"/>
<property name="ivy.deliver.revision" value="${ivy.revision}"/>
<property name="ivy.pom.version" value="${ivy.revision}"/>

Expand Down
4 changes: 2 additions & 2 deletions core/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<property environment="env"/>

<property name="ivy.organisation" value="i5"/>
<property name="ivy.revision" value="0.8"/>
<property name="ivy.build.number" value="3"/>
<property name="ivy.revision" value="1.0"/>
<property name="ivy.build.number" value="0"/>
<property name="ivy.deliver.revision" value="${ivy.revision}"/>
<property name="ivy.pom.version" value="${ivy.revision}"/>

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/i5/las2peer/p2p/MessageResultListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ public boolean isTimedOut() {
public long getAgeMs() {
return new Date().getTime() - startedAt;
}

public long getTimeoutTime() {
return timeoutMs;
}

/**
* was their any exception during sending or processing the corresponding message
Expand Down
66 changes: 55 additions & 11 deletions core/src/main/java/i5/las2peer/p2p/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public enum NodeStatus {
*/
private Timer tidyUpTimer;

/**
* Runtime to get performance information (RAM)
*/
private Runtime runtime;

/**
* status of this node
*/
Expand Down Expand Up @@ -191,7 +196,7 @@ public enum NodeStatus {
*/
private L2pLogger serviceLogger;
private static final String SERVICE_LOGFILE = "service.log";

/**
* maps names and emails to UserAgents
*/
Expand Down Expand Up @@ -251,7 +256,7 @@ public Node(ClassManager classManager, boolean standardObserver, boolean monitor
initStandardLogfile();
initServiceLogfile();
}

if (monitoringObserver) {
addObserver(new MonitoringObserver(50, this));
}
Expand All @@ -267,6 +272,8 @@ public Node(ClassManager classManager, boolean standardObserver, boolean monitor

userManager = new UserAgentManager(this);
aliasManager = new ServiceAliasManager(this);

this.runtime = Runtime.getRuntime();
}

/**
Expand All @@ -276,7 +283,7 @@ private void initStandardLogfile() {
L2pLogger logger = L2pLogger.getInstance(this.getClass());
addObserver(logger);
}

/**
* Creates an additional observer for the log-file for custom mesages
*/
Expand All @@ -286,9 +293,8 @@ private void initServiceLogfile() {
serviceLogger.setLogfilePrefix(SERVICE_LOGFILE);
addObserver(serviceLogger);
} catch (IOException e) {
System.err.println("Fatal Error! Can't use logging prefix '"
+ SERVICE_LOGFILE
+ "'! File logging is disabled!");
System.err.println(
"Fatal Error! Can't use logging prefix '" + SERVICE_LOGFILE + "'! File logging is disabled!");
}
}

Expand Down Expand Up @@ -409,8 +415,7 @@ public void observerNotice(MonitoringEvent event, Object sourceNode, String sour
String sourceNodeRepresentation = getNodeRepresentation(sourceNode);
String destinationNodeRepresentation = getNodeRepresentation(destinationNode);
for (NodeObserver ob : observers) {
if (ob == serviceLogger
&& (Math.abs(event.getCode()) < 7500 || Math.abs(event.getCode()) >= 7600)) {
if (ob == serviceLogger && (Math.abs(event.getCode()) < 7500 || Math.abs(event.getCode()) >= 7600)) {
// custom logger shall only log service messages
continue;
}
Expand Down Expand Up @@ -526,7 +531,7 @@ public NodeInformation getNodeInformation() throws CryptoException {
}

result.setNodeHandle(getNodeId());
//logger.info("retrieving node info: \n" + result.toXmlString());
// logger.info("retrieving node info: \n" + result.toXmlString());
return result;
}

Expand Down Expand Up @@ -1515,6 +1520,29 @@ public void registerAnswerListener(long messageId, MessageResultListener listene
return;
}
htAnswerListeners.put(messageId, listener);
// Thread to check whether a listener reaches timeout and needs to be removed from the table
new Thread() {
public void run(){
long listenerId = messageId;
long sleepTime = listener.getTimeoutTime();
while(!htAnswerListeners.get(listenerId).checkTimeOut()) {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("Thread interupted because of "+e );
e.printStackTrace();
}
if(htAnswerListeners.get(listenerId) == null) {
this.interrupt();
break;
}
}
if(!this.isInterrupted()) {
htAnswerListeners.remove(listenerId);
}
}
}.start();
}

/**
Expand All @@ -1536,9 +1564,12 @@ public boolean handoverAnswer(Message answer) {
System.out.println("Did not find corresponding observer!");
return false;
}

listener.collectAnswer(answer);

// Remove listener from list if no more messages are expected
if(listener.getNumberOfExpectedResults() == listener.getNumberOfResults()) {
htAnswerListeners.remove(answer.getResponseToId());
}
return true;
}

Expand Down Expand Up @@ -1718,6 +1749,19 @@ public void setCpuLoadThreshold(double cpuLoadThreshold) {
this.cpuLoadThreshold = cpuLoadThreshold;
}

/**
* Gets the approximate RAM load of the JVM the Node is running on.
*
* @return the total amount of memory currently available for current and future objects, measured in bytes.
*/
public long getNodeRAMLoad() {
return runtime.totalMemory();
}

public long getNodeFreeRAMLoad() {
return runtime.freeMemory();
}

// Tidy up Timer

/**
Expand Down
4 changes: 2 additions & 2 deletions restmapper/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<property environment="env"/>

<property name="ivy.organisation" value="i5"/>
<property name="ivy.revision" value="0.8"/>
<property name="ivy.build.number" value="3"/>
<property name="ivy.revision" value="1.0"/>
<property name="ivy.build.number" value="0"/>
<property name="ivy.deliver.revision" value="${ivy.revision}"/>
<property name="ivy.pom.version" value="${ivy.revision}"/>

Expand Down
4 changes: 2 additions & 2 deletions webconnector/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<property environment="env"/>

<property name="ivy.organisation" value="i5"/>
<property name="ivy.revision" value="0.8"/>
<property name="ivy.build.number" value="3"/>
<property name="ivy.revision" value="1.0"/>
<property name="ivy.build.number" value="0"/>
<property name="ivy.deliver.revision" value="${ivy.revision}"/>
<property name="ivy.pom.version" value="${ivy.revision}"/>

Expand Down
5 changes: 5 additions & 0 deletions webconnector/frontend/src/view-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class StatusView extends PolymerElement {
<!-- NODE STATUS -->
<strong>Uptime</strong>: [[_status.uptime]] <br />
<strong>CPU Load</strong>: [[_status.cpuLoad]]% <br />
<strong>RAM Usage</strong>: <meter value="[[_status.ramLoad]]" min="0" max="[[_status.maxRamLoad]]"></meter> [[_status.ramLoadStr]] of [[_status.maxRamLoadStr]] used <br />
<strong>Local Storage</strong>: <meter value="[[_status.storageSize]]" min="0" max="[[_status.maxStorageSize]]"></meter> [[_status.storageSizeStr]] of [[_status.maxStorageSizeStr]] used <br />
<strong>Node ID</strong>: [[_status.nodeId]] <br />
</div>
Expand Down Expand Up @@ -166,6 +167,10 @@ class StatusView extends PolymerElement {
nodeDescription: "...",
nodeId: "...",
cpuLoad: "...",
ramLoad: 0,
maxRamLoad: 1,
ramLoadStr: "...",
maxRamLoadStr: "...",
storageSize: 0,
maxStorageSize: 1,
storageSizeStr: "...",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import java.util.Collection;
import java.util.Date;

import javax.ws.rs.*;
import javax.ws.rs.GET;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
Expand All @@ -36,8 +40,7 @@
import i5.las2peer.security.ServiceAgentImpl;
import i5.las2peer.serialization.SerializationException;
import i5.las2peer.tools.CryptoException;
import i5.las2peer.tools.L2pNodeLauncher;

import i5.las2peer.tools.L2pNodeLauncher;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import rice.pastry.NodeHandle;
Expand All @@ -56,12 +59,9 @@ public class DefaultHandler {
public DefaultHandler(WebConnector connector) {
this.connector = connector;
node = connector.getL2pNode();
if ( node instanceof EthereumNode )
{
if (node instanceof EthereumNode) {
ethNode = (EthereumNode) node;
}
else
{
} else {
ethNode = null;
}
}
Expand All @@ -70,14 +70,11 @@ public DefaultHandler(WebConnector connector) {
@Path("/check-eth")
@Produces(MediaType.APPLICATION_JSON)
public Response checkEth() throws NotFoundException {
if ( node instanceof EthereumNode )
{
if (node instanceof EthereumNode) {
JSONObject json = new JSONObject();
json.put("msg", "found eth");
return Response.ok(json.toJSONString(), MediaType.APPLICATION_JSON).build();
}
else
{
} else {
throw new NotFoundException("Node does not use registry.");
}
}
Expand Down Expand Up @@ -121,6 +118,10 @@ public String getNodeStatus(@Context UriInfo uriInfo) {
JSONObject response = new JSONObject();
response.put("nodeId", node.getNodeId().toString());
response.put("cpuLoad", getCPULoad(node));
response.put("ramLoad", getRamLoad(node) - getFreeRamLoad(node));
response.put("maxRamLoad", getRamLoad(node));
response.put("ramLoadStr", humanReadableByteCount(getRamLoad(node) - getFreeRamLoad(node), true));
response.put("maxRamLoadStr", humanReadableByteCount(getRamLoad(node), true));
long localStorageSize = -1;
long maxLocalStorageSize = -1;
if (node instanceof PastryNodeImpl) {
Expand All @@ -135,27 +136,25 @@ public String getNodeStatus(@Context UriInfo uriInfo) {
// should never happen O.o
e.printStackTrace();
}
if ( nodeInfo != null )
{
if (nodeInfo != null) {
String nodeAdminName = nodeInfo.getAdminName();
String nodeAdminEmail = nodeInfo.getAdminEmail();
String nodeOrganization = nodeInfo.getOrganization();
String nodeDescription = nodeInfo.getDescription();
if (nodeAdminName != null && nodeAdminName.length() > 0)
response.put("nodeAdminName", nodeAdminName);
if (nodeAdminEmail != null && nodeAdminEmail.length() > 0)
{
if (nodeAdminEmail != null && nodeAdminEmail.length() > 0) {
response.put("nodeAdminEmail", nodeAdminEmail);
if ( ethNode != null )
if (ethNode != null)
response.put("nodeAdminReputation", ethNode.getAgentReputation(nodeAdminName, nodeAdminEmail));
}

if (nodeOrganization != null && nodeOrganization.length() > 0)
response.put("nodeOrganization", nodeOrganization);
if (nodeDescription != null && nodeDescription.length() > 0)
response.put("nodeDescription", nodeDescription);
}

response.put("storageSize", localStorageSize);
response.put("storageSizeStr", humanReadableByteCount(localStorageSize, true));
response.put("maxStorageSize", maxLocalStorageSize);
Expand All @@ -169,15 +168,22 @@ public String getNodeStatus(@Context UriInfo uriInfo) {
@GET
@Path("/getOtherNodesInfo")
@Produces(MediaType.APPLICATION_JSON)
public String handleGetOtherNodeInfo()
{
public String handleGetOtherNodeInfo() {
return getOtherNodeInfos(node).toJSONString();
}

private int getCPULoad(Node node) {
return (int) (node.getNodeCpuLoad() * 100);
}

private long getRamLoad(Node node) {
return node.getNodeRAMLoad();
}

private long getFreeRamLoad(Node node) {
return node.getNodeFreeRAMLoad();
}

// Source: http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
private static String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
Expand Down Expand Up @@ -241,7 +247,7 @@ private JSONArray getOtherNodes(Node node) {
private JSONArray getOtherNodeInfos(Node node) {
JSONArray result = new JSONArray();

if (!( node instanceof PastryNodeImpl )) {
if (!(node instanceof PastryNodeImpl)) {
return result;
}
Collection<NodeHandle> knownNodes = ((PastryNodeImpl) node).getPastryNode().getLeafSet().getUniqueSet();
Expand All @@ -250,14 +256,11 @@ private JSONArray getOtherNodeInfos(Node node) {
String nodeID = nodeHandle.toString();
try {
NodeInformation nodeInfo = node.getNodeInformation(nodeHandle);
if ( nodeInfo.getAdminName() != null && nodeInfo.getAdminName().length() > 2 &&
nodeInfo.getAdminEmail() != null && nodeInfo.getAdminEmail().length() > 2
)
{
if (nodeInfo.getAdminName() != null && nodeInfo.getAdminName().length() > 2
&& nodeInfo.getAdminEmail() != null && nodeInfo.getAdminEmail().length() > 2) {
if (ethNode != null) {
nodeJSON.put("nodeAdminReputation",
ethNode.getAgentReputation(nodeInfo.getAdminName(), nodeInfo.getAdminEmail())
);
nodeJSON.put("nodeAdminReputation",
ethNode.getAgentReputation(nodeInfo.getAdminName(), nodeInfo.getAdminEmail()));
}
}
nodeJSON.put("nodeID", nodeID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public void testGetNodeStatus() {
JSONObject result = (JSONObject) new JSONParser(JSONParser.DEFAULT_PERMISSIVE_MODE).parse(bytes);
Assert.assertEquals(nodes.get(0).getNodeId().toString(), result.getAsString("nodeId"));
Assert.assertNotNull(result.get("cpuLoad"));
Assert.assertNotNull(result.get("ramLoad"));
Assert.assertNotNull(result.get("ramLoadStr"));
Assert.assertNotNull(result.get("maxRamLoad"));
Assert.assertNotNull(result.get("maxRamLoadStr"));
Assert.assertNotNull(result.get("storageSize"));
Assert.assertNotNull(result.get("storageSizeStr"));
Assert.assertNotNull(result.get("maxStorageSize"));
Expand Down

0 comments on commit 16378b7

Please sign in to comment.