Commit 055a5de6 authored by Ali Fahs's avatar Ali Fahs
Browse files

Improving the RM Gateway to enable hostnames retrieval

parent f73803f6
......@@ -34,7 +34,7 @@ public class PAResourceManagerGateway {
private RMRestInterface rmRestInterface;
static final int MAX_CONNECTION_RETRIES = 10;
static final int MAX_CONNECTION_RETRIES = 2;
static final int INTERVAL = 10000;
......@@ -48,7 +48,7 @@ public class PAResourceManagerGateway {
* @return List of deployed nodes names
* @throws InterruptedException In case the process is interrupted
*/
public List<String> getAsyncDeployedNodesInformation(String nodeSource) throws InterruptedException {
public List<String> getAsyncDeployedNodesInformation(String nodeSource, String option) throws InterruptedException {
ExecutorService executorService = Executors.newSingleThreadExecutor();
Callable<List<String>> callable = () -> {
......@@ -60,14 +60,19 @@ public class PAResourceManagerGateway {
while (!gotResponse && retries <= MAX_CONNECTION_RETRIES) {
try {
Thread.sleep(INTERVAL);
deployedNodes = getDeployedNodesInformation(nodeSource);
deployedNodes = getDeployedNodesInformation(nodeSource, option);
if (!deployedNodes.isEmpty()) {
gotResponse = true;
} else {
retries++;
}
} catch (Exception e) {
retries++;
if(e.getClass().getSimpleName().equals("IllegalArgumentException")) {
throw e;
}
else {
retries++;
}
}
}
if (gotResponse) {
......@@ -86,6 +91,11 @@ public class PAResourceManagerGateway {
}
executorService.shutdown();
return deployedNodes;
/* TODO
* This method throws an error if a node source is deployed with no nodes attached.
* The better approach should be returning an empty list instead of connectTimeoutException.
*/
}
......@@ -135,24 +145,43 @@ public class PAResourceManagerGateway {
/**
* Get deployed nodes names
* @param nodeSource The name of the node source
* @param option needed (either "hostname" or "name")
* @return List of deployed nodes names
* @throws NotConnectedException In case the user is not connected
* @throws PermissionRestException In case the user does not have valid permissions
* @throws IllegalArgumentException if the option passed was not supported
*/
private List<String> getDeployedNodesInformation(String nodeSource) throws NotConnectedException, PermissionRestException {
private List<String> getDeployedNodesInformation(String nodeSource, String option) throws IllegalArgumentException, NotConnectedException, PermissionRestException {
reconnectIfDisconnected();
List<String> deployedNodes = new ArrayList<>();
RMStateFull rmState = getFullMonitoring();
String nodeInfo= "none";
LOGGER.debug("Searching for deployed nodes information ...");
for (RMNodeEvent rmNodeEvent : rmState.getNodesEvents()) {
if (rmNodeEvent.getNodeSource().equals(nodeSource)) {
String nodeUrl = rmNodeEvent.getNodeUrl();
deployedNodes.add(nodeUrl.substring(nodeUrl.lastIndexOf('/') + 1));
if (option.equals("name")) {
nodeInfo = rmNodeEvent.getNodeUrl();
}
if (option.equals("hostname")) {
nodeInfo = rmNodeEvent.getHostName();
}
if (nodeInfo.equals("none")) {
LOGGER.error("A wrong option was passed and the nodeInfo was now changed");
throw new IllegalArgumentException("The option passed \"" + option+ "\" is not found!");
}
else {
deployedNodes.add(nodeInfo.substring(nodeInfo.lastIndexOf('/') + 1));
}
}
}
LOGGER.info(deployedNodes.size() + " nodes found!");
return deployedNodes;
/* TODO
* This method can be improved to including all RMNodeEvent variables.
* For now, all what we need are the name and Hostname, but later it can include other variables.
*/
}
private RMStateFull getFullMonitoring() throws NotConnectedException, PermissionRestException {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment