From 7f7ad7cd481ae07b26752b92a9b00af805f39179 Mon Sep 17 00:00:00 2001 From: sofiakarb Date: Tue, 10 Dec 2019 13:39:41 +0200 Subject: [PATCH 01/11] fix variable. fix way of deleting pathologies when node is down --- .../async/handler/HttpAsyncMiningQueryHandler.java | 11 +++++++++-- .../Docker-Ansible/scripts/add_worker.sh | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java index 794336473..3353882e2 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java @@ -439,7 +439,7 @@ private HashMap getAlgoParameters(HttpRequest request) throws IO } private boolean nodesRunning(List nodesToBeChecked, String pathology) throws Exception { - + Gson gson = new Gson(); //Check if IP's gotten from Consul[Key-Value store] exist in Exareme's Registry List notContainerProxy = new ArrayList<>(); ContainerProxy[] containerProxy = ArtRegistryLocator.getArtRegistryProxy().getContainers(); //get IP's from Exareme's Registry @@ -468,7 +468,14 @@ private boolean nodesRunning(List nodesToBeChecked, String pathology) th log.info("It seems that node[" + name + "," + ip + "] you are trying to check is not part of Exareme's registry. Deleting it from Consul...."); //Delete datasets and IP of the node - deleteFromConsul(System.getenv("DATA") + "/" + name); + String pathologyKey = searchConsul(System.getenv("DATA") + "/" + name + "?keys"); + String[] pathologyKeyArray = gson.fromJson(pathologyKey, String[].class); + for( String p: pathologyKeyArray){ + System.out.println("hereeeeee: "+p); + deleteFromConsul(p); + } + + //deleteFromConsul(System.getenv("DATA") + "/" + name); //TODO get the pathologies and DELETE those deleteFromConsul(System.getenv("EXAREME_ACTIVE_WORKERS_PATH") + "/" + name); //Get datasets exist in other nodes for showing appropriate message to user diff --git a/Federated-Deployment/Docker-Ansible/scripts/add_worker.sh b/Federated-Deployment/Docker-Ansible/scripts/add_worker.sh index 26b5a27f3..332e4a903 100755 --- a/Federated-Deployment/Docker-Ansible/scripts/add_worker.sh +++ b/Federated-Deployment/Docker-Ansible/scripts/add_worker.sh @@ -111,7 +111,7 @@ while IFS= read -r line || [[ -n "$line" ]]; do continue else #workerN exists below [workers] tag workerExist=1 #TODO check if [workerX_X_X_X] exists as tag? - echo -e "\nWorker with IP: \"workerIP\" already exists under [workers] tag." + echo -e "\nWorker with IP: \"${workerIP}\" already exists under [workers] tag." break fi if [[ -z "$line1" ]]; then From 226698974fbacd9856cf2bbaf92f2ac7a6d4c8c2 Mon Sep 17 00:00:00 2001 From: sofiakarb Date: Tue, 10 Dec 2019 13:50:45 +0200 Subject: [PATCH 02/11] add comments --- .../async/handler/HttpAsyncMiningQueryHandler.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java index 3353882e2..b8dbc1af6 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java @@ -467,15 +467,13 @@ private boolean nodesRunning(List nodesToBeChecked, String pathology) th String name = names.get(ip); log.info("It seems that node[" + name + "," + ip + "] you are trying to check is not part of Exareme's registry. Deleting it from Consul...."); - //Delete datasets and IP of the node + //Delete pathologies and IP of the node String pathologyKey = searchConsul(System.getenv("DATA") + "/" + name + "?keys"); String[] pathologyKeyArray = gson.fromJson(pathologyKey, String[].class); - for( String p: pathologyKeyArray){ - System.out.println("hereeeeee: "+p); - deleteFromConsul(p); + for( String p: pathologyKeyArray) { + deleteFromConsul(p); //Delete every pathology for node with name $name } - - //deleteFromConsul(System.getenv("DATA") + "/" + name); //TODO get the pathologies and DELETE those + //Delete IP of active_worker with name $name deleteFromConsul(System.getenv("EXAREME_ACTIVE_WORKERS_PATH") + "/" + name); //Get datasets exist in other nodes for showing appropriate message to user From cc00e80eedb958bb0313b79f100d517ac62683b4 Mon Sep 17 00:00:00 2001 From: sofiakarb Date: Wed, 8 Jan 2020 18:19:16 +0200 Subject: [PATCH 03/11] check why while does not work.. --- .../worker/art/remote/RmiObjectProxy.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java b/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java index 87e99bdef..9357f6558 100644 --- a/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java +++ b/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java @@ -102,12 +102,14 @@ public T getRemoteObject() throws RemoteException { } } //Search if the Exareme's node IP exist in Exareme's registry - for (ContainerProxy containerProxy : ArtRegistryLocator.getArtRegistryProxy().getContainers()) { - log.debug("Container: " + containerProxy.getEntityName().getIP() + " : " + - containerProxy.getEntityName().getName()); - if (containerProxy.getEntityName().getIP().equals(regEntityName.getIP())) { + //for (ContainerProxy containerProxy : ArtRegistryLocator.getArtRegistryProxy().getContainers()) { + // log.debug("Container: " + containerProxy.getEntityName().getIP() + " : " + + // containerProxy.getEntityName().getName()); + // System.out.println("HERE: "+containerProxy.getEntityName().getIP()); + System.out.println("and here: "+regEntityName.getIP()); + // if (containerProxy.getEntityName().getIP().equals(regEntityName.getIP())) { //If exists, remove it from Exareme's registry - ArtRegistryLocator.getArtRegistryProxy().removeContainer(containerProxy.getEntityName()); + // ArtRegistryLocator.getArtRegistryProxy().removeContainer(containerProxy.getEntityName()); log.info("Worker node:[" + name + "," + regEntityName.getIP() + "]" + " removed successfully from Exareme's registry"); //If exist in Consul[Key-Value store], delete infos regarding that Exareme node from there @@ -120,9 +122,9 @@ public T getRemoteObject() throws RemoteException { throw new RemoteException("Can not contact Consul Key value Store"); } } - break; - } - } + //break; + //} + //} } throw new RemoteException("There was an error with worker "+ "[" + name + "," + regEntityName.getIP() + "]."); } From 463b7c7d74fa7b26b49173c7ca8c347af384f319 Mon Sep 17 00:00:00 2001 From: sofiakarb Date: Fri, 10 Jan 2020 21:58:54 +0200 Subject: [PATCH 04/11] Fixes for failed COntainer --- .../worker/art/remote/RmiObjectProxy.java | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java b/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java index 9357f6558..a334d7a06 100644 --- a/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java +++ b/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Objects; +import java.util.concurrent.Semaphore; /** * University of Athens / @@ -78,6 +79,8 @@ public synchronized T connect() throws RemoteException { public T getRemoteObject() throws RemoteException { String name = null; Iterator> entries; + Gson gson = new Gson(); + Semaphore semaphore = new Semaphore(1); if (isConnected == false) { try { @@ -87,46 +90,44 @@ public T getRemoteObject() throws RemoteException { //Get the Exareme's node name that is not responding HashMap names = null; try { + semaphore.acquire(); names = getNamesOfActiveNodes(); + for (Map.Entry entry : names.entrySet()) { + System.out.println("ActiveNodes from Consul key-value store: " + entry.getKey() + " = " + entry.getValue()); + } } catch (IOException e) { e.printStackTrace(); } + catch (InterruptedException e) { + e.printStackTrace(); + } if(names != null) { entries = names.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entry = entries.next(); if (Objects.equals(entry.getKey(), regEntityName.getIP())) { + System.out.println(entry.getKey()+"="+regEntityName.getIP()); name = entry.getValue(); + System.out.println("Found node with name: "+name+" that seems to be done.."); + + try { + String pathologyKey = searchConsul(System.getenv("DATA") + "/" + name + "?keys"); + String[] pathologyKeyArray = gson.fromJson(pathologyKey, String[].class); + for( String p: pathologyKeyArray) { + deleteFromConsul(p); //Delete every pathology for node with name $name + } + deleteFromConsul(System.getenv("EXAREME_ACTIVE_WORKERS_PATH") + "/" + name); + log.info("Worker node:[" + name + "," + regEntityName.getIP() + "]" + " removed from Consul key-value store"); + } catch (IOException E) { + throw new RemoteException("Can not contact Consul Key value Store"); + } break; } } - //Search if the Exareme's node IP exist in Exareme's registry - //for (ContainerProxy containerProxy : ArtRegistryLocator.getArtRegistryProxy().getContainers()) { - // log.debug("Container: " + containerProxy.getEntityName().getIP() + " : " + - // containerProxy.getEntityName().getName()); - // System.out.println("HERE: "+containerProxy.getEntityName().getIP()); - System.out.println("and here: "+regEntityName.getIP()); - // if (containerProxy.getEntityName().getIP().equals(regEntityName.getIP())) { - //If exists, remove it from Exareme's registry - // ArtRegistryLocator.getArtRegistryProxy().removeContainer(containerProxy.getEntityName()); - log.info("Worker node:[" + name + "," + regEntityName.getIP() + "]" + " removed successfully from Exareme's registry"); - - //If exist in Consul[Key-Value store], delete infos regarding that Exareme node from there - if (name != null) { - try { - deleteFromConsul(System.getenv("DATA") + "/" + name); - deleteFromConsul(System.getenv("EXAREME_ACTIVE_WORKERS_PATH") + "/" + name); - log.info("Worker node:[" + name + "," + regEntityName.getIP() + "]" + " removed from Consul key-value store"); - } catch (IOException E) { - throw new RemoteException("Can not contact Consul Key value Store"); - } - } - //break; - //} - //} } - throw new RemoteException("There was an error with worker "+ "[" + name + "," + regEntityName.getIP() + "]."); + semaphore.release(); + throw new RemoteException("There was an error with worker "+ "["+ regEntityName.getIP() + "]."); } } return remoteObject; @@ -235,3 +236,4 @@ public RetryPolicy getRetryPolicy() throws RemoteException { return RetryPolicyFactory.defaultRetryPolicy(); } } + From 2309fa72fd78767ac2716ed6e327545c459fbde3 Mon Sep 17 00:00:00 2001 From: sofiakarb Date: Fri, 10 Jan 2020 22:49:25 +0200 Subject: [PATCH 05/11] minor changes --- .../worker/art/remote/RmiObjectProxy.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java b/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java index a334d7a06..4b08c09a5 100644 --- a/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java +++ b/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java @@ -5,8 +5,6 @@ import com.google.gson.Gson; import madgik.exareme.common.art.entity.EntityName; -import madgik.exareme.worker.art.container.ContainerProxy; -import madgik.exareme.worker.art.registry.ArtRegistryLocator; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; @@ -90,15 +88,12 @@ public T getRemoteObject() throws RemoteException { //Get the Exareme's node name that is not responding HashMap names = null; try { - semaphore.acquire(); + semaphore.acquire(); names = getNamesOfActiveNodes(); for (Map.Entry entry : names.entrySet()) { - System.out.println("ActiveNodes from Consul key-value store: " + entry.getKey() + " = " + entry.getValue()); + log.debug("ActiveNodes from Consul key-value store: " + entry.getKey() + " = " + entry.getValue()); } - } catch (IOException e) { - e.printStackTrace(); - } - catch (InterruptedException e) { + } catch (IOException | InterruptedException e) { e.printStackTrace(); } @@ -107,9 +102,8 @@ public T getRemoteObject() throws RemoteException { while (entries.hasNext()) { Map.Entry entry = entries.next(); if (Objects.equals(entry.getKey(), regEntityName.getIP())) { - System.out.println(entry.getKey()+"="+regEntityName.getIP()); name = entry.getValue(); - System.out.println("Found node with name: "+name+" that seems to be done.."); + log.info("Found node with name: "+name+" that seems to be down.."); try { String pathologyKey = searchConsul(System.getenv("DATA") + "/" + name + "?keys"); @@ -126,7 +120,7 @@ public T getRemoteObject() throws RemoteException { } } } - semaphore.release(); + semaphore.release(); throw new RemoteException("There was an error with worker "+ "["+ regEntityName.getIP() + "]."); } } From 8cd5086cf4ae25bcbb263a952cba14ba0c0f34aa Mon Sep 17 00:00:00 2001 From: sofiakarb Date: Mon, 20 Jan 2020 13:47:11 +0200 Subject: [PATCH 06/11] Can not connect to Consul --- .../handler/HttpAsyncMiningQueryHandler.java | 93 ++++++++++++------- 1 file changed, 59 insertions(+), 34 deletions(-) diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java index ad34c43e4..1feef96c0 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java @@ -139,7 +139,21 @@ private void handleInternal(HttpRequest request, HttpResponse response, HttpCont HashMap nodeDatasets = null; List nodesToBeChecked; if (pathology != null) { - nodeDatasets = getDatasetsFromConsul(pathology); + try { + nodeDatasets = getDatasetsFromConsul(pathology); + } + catch (Exception e){ + log.error(e.getMessage()); + System.out.println(Arrays.toString(e.getStackTrace())); + String data = e.getMessage(); + String type = user_error; //type could be error, user_error, warning regarding the error occured along the process + String result = defaultOutputFormat(data, type); + BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(result.getBytes())); + response.setStatusCode(HttpStatus.SC_BAD_REQUEST); + response.setEntity(entity); + return; + } if (userDatasets == null) nodesToBeChecked = allNodesIPs(); //LIST_VARIABLES Algorithm else @@ -245,7 +259,7 @@ private void handleInternal(HttpRequest request, HttpResponse response, HttpCont entity.setContent(new ByteArrayInputStream(result.getBytes())); response.setStatusCode(HttpStatus.SC_BAD_REQUEST); response.setEntity(entity); - } catch (PathologyException | DatasetsException e) { + } catch (PathologyException | DatasetsException | IOException e) { log.error(e.getMessage()); String data = e.getMessage(); String type = user_error; //type could be error, user_error, warning regarding the error occured along the process @@ -254,7 +268,8 @@ private void handleInternal(HttpRequest request, HttpResponse response, HttpCont entity.setContent(new ByteArrayInputStream(result.getBytes())); response.setStatusCode(HttpStatus.SC_BAD_REQUEST); response.setEntity(entity); - } catch (Exception e) { + } + catch (Exception e) { log.error(e); String data = e.getMessage(); String type = error; //type could be error, user_error, warning regarding the error occured along the process @@ -266,12 +281,17 @@ private void handleInternal(HttpRequest request, HttpResponse response, HttpCont } } - private HashMap getDatasetsFromConsul(String pathology) throws IOException, PathologyException { + private HashMap getDatasetsFromConsul(String pathology) throws Exception { Gson gson = new Gson(); HashMap nodeDatasets = new HashMap<>(); List pathologyNodes = new ArrayList(); - String masterKey = searchConsul(System.getenv("EXAREME_MASTER_PATH") + "/?keys"); + String masterKey; + try { + masterKey = searchConsul(System.getenv("EXAREME_MASTER_PATH") + "/?keys"); + } catch (IOException e) { + throw new Exception(e.getMessage()); + } String[] masterKeysArray = gson.fromJson(masterKey, String[].class); String masterName = masterKeysArray[0].replace(System.getenv("EXAREME_MASTER_PATH") + "/", ""); @@ -318,7 +338,7 @@ private HashMap getDatasetsFromConsul(String pathology) throws return nodeDatasets; } - private HashMap getNamesOfActiveNodes() throws IOException { + private HashMap getNamesOfActiveNodes() throws Exception { Gson gson = new Gson(); HashMap nodeNames = new HashMap<>(); String masterKey = searchConsul(System.getenv("EXAREME_MASTER_PATH") + "/?keys"); @@ -520,7 +540,7 @@ private List allNodesIPs() throws RemoteException { } //Consul[Key-Value store] consists of information like IP's of Exareme nodes, Datasets existing at each node. - private String searchConsul(String query) throws IOException { + private String searchConsul(String query) throws IOException,ServerException { String result = null; CloseableHttpClient httpclient = HttpClients.createDefault(); String consulURL = System.getenv("CONSULURL"); @@ -528,39 +548,43 @@ private String searchConsul(String query) throws IOException { if (!consulURL.startsWith("http://")) { consulURL = "http://" + consulURL; } - try { - HttpGet httpGet; - httpGet = new HttpGet(consulURL + "/v1/kv/" + query); - log.debug("Running: " + httpGet.getURI()); - CloseableHttpResponse response = null; - if (httpGet.toString().contains(System.getenv("EXAREME_MASTER_PATH") + "/") || httpGet.toString().contains(System.getenv("DATA") + "/")) { //if we can not contact : http://exareme-keystore:8500/v1/kv/master* or http://exareme-keystore:8500/v1/kv/datasets* - try { //then throw exception - response = httpclient.execute(httpGet); - if (response.getStatusLine().getStatusCode() != 200) { - throw new ServerException("Cannot contact consul", new Exception(EntityUtils.toString(response.getEntity()))); + + HttpGet httpGet; + httpGet = new HttpGet(consulURL + "/v1/kv/" + query); + log.debug("Running: " + httpGet.getURI()); + CloseableHttpResponse response = null; + if (httpGet.toString().contains(System.getenv("EXAREME_MASTER_PATH") + "/") || httpGet.toString().contains(System.getenv("DATA") + "/")) { //if we can not contact : http://exareme-keystore:8500/v1/kv/master* or http://exareme-keystore:8500/v1/kv/datasets* + log.debug(httpGet.toString()); + try { //then throw exception + log.debug("trying to execute connection"); + response = httpclient.execute(httpGet); + } catch (Exception e) { + log.debug("caught an error:"+e.getMessage()); + response.close(); + throw new IOException(e.getMessage()); + } + result = EntityUtils.toString(response.getEntity()); + if (result == null ) { + throw new IOException("Can not contact consul"); + } + log.debug(response.getStatusLine().getStatusCode()); + } + if (httpGet.toString().contains(System.getenv("EXAREME_ACTIVE_WORKERS_PATH") + "/")) { //if we can not contact : http://exareme-keystore:8500/v1/kv/active_workers* + //then maybe there are no workers running + try { + response = httpclient.execute(httpGet); + if (response.getStatusLine().getStatusCode() != 200) { + if (httpGet.toString().contains("?keys")) + log.debug("No workers running. Continue with master"); } else { result = EntityUtils.toString(response.getEntity()); } - } finally { - response.close(); } - } - if (httpGet.toString().contains(System.getenv("EXAREME_ACTIVE_WORKERS_PATH") + "/")) { //if we can not contact : http://exareme-keystore:8500/v1/kv/active_workers* - try { //then maybe there are no workers running - response = httpclient.execute(httpGet); - if (response.getStatusLine().getStatusCode() != 200) { - if (httpGet.toString().contains("?keys")) - log.debug("No workers running. Continue with master"); - } else { - result = EntityUtils.toString(response.getEntity()); - } - } finally { + finally { response.close(); } - } - } finally { - return result; } + return result; } //Some times infos regarding Exareme nodes exist in Consul-Key-Value store], but the nodes are not part of Exareme's registry. We delete the infos from Consul[Key-Value store] @@ -578,6 +602,7 @@ private void deleteFromConsul(String query) throws IOException { //curl -X DELETE $CONSULURL/v1/kv/$1/$NODE_NAME log.debug("Running: " + httpDelete.getURI()); + CloseableHttpResponse response = null; if (httpDelete.toString().contains(System.getenv("EXAREME_ACTIVE_WORKERS_PATH") + "/") || httpDelete.toString().contains(System.getenv("DATA") + "/")) { //if we can not contact : http://exareme-keystore:8500/v1/kv/master* or http://exareme-keystore:8500/v1/kv/datasets* try { //then throw exception @@ -594,4 +619,4 @@ private void deleteFromConsul(String query) throws IOException { private String defaultOutputFormat(String data, String type) { return "{\"result\" : [{\"data\":" + "\"" + data + "\",\"type\":" + "\"" + type + "\"}]}"; } -} \ No newline at end of file +} From 587cc8c83ca838ddffd31b42aa76d065d7317898 Mon Sep 17 00:00:00 2001 From: sofiakarb Date: Mon, 20 Jan 2020 15:42:28 +0200 Subject: [PATCH 07/11] release sem always. Consul key-value may be down, inform --- .../handler/HttpAsyncMiningQueryHandler.java | 59 +++++++++---------- .../worker/art/remote/RmiObjectProxy.java | 9 ++- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java index 1feef96c0..e974cfc05 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java @@ -2,6 +2,7 @@ import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; +import com.jcraft.jsch.IO; import madgik.exareme.common.consts.HBPConstants; import madgik.exareme.master.client.AdpDBClient; import madgik.exareme.master.client.AdpDBClientFactory; @@ -141,18 +142,15 @@ private void handleInternal(HttpRequest request, HttpResponse response, HttpCont if (pathology != null) { try { nodeDatasets = getDatasetsFromConsul(pathology); - } - catch (Exception e){ - log.error(e.getMessage()); - System.out.println(Arrays.toString(e.getStackTrace())); - String data = e.getMessage(); - String type = user_error; //type could be error, user_error, warning regarding the error occured along the process + } catch (Exception e){ + String data = "Can not contact Consul key value Store.Please inform your system admin."; + String type = error; //type could be error, user_error, warning regarding the error occured along the process String result = defaultOutputFormat(data, type); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(result.getBytes())); response.setStatusCode(HttpStatus.SC_BAD_REQUEST); response.setEntity(entity); - return; + return; } if (userDatasets == null) nodesToBeChecked = allNodesIPs(); //LIST_VARIABLES Algorithm @@ -281,17 +279,12 @@ private void handleInternal(HttpRequest request, HttpResponse response, HttpCont } } - private HashMap getDatasetsFromConsul(String pathology) throws Exception { + private HashMap getDatasetsFromConsul(String pathology) throws IOException,PathologyException { Gson gson = new Gson(); HashMap nodeDatasets = new HashMap<>(); List pathologyNodes = new ArrayList(); - String masterKey; - try { - masterKey = searchConsul(System.getenv("EXAREME_MASTER_PATH") + "/?keys"); - } catch (IOException e) { - throw new Exception(e.getMessage()); - } + String masterKey = searchConsul(System.getenv("EXAREME_MASTER_PATH") + "/?keys"); String[] masterKeysArray = gson.fromJson(masterKey, String[].class); String masterName = masterKeysArray[0].replace(System.getenv("EXAREME_MASTER_PATH") + "/", ""); @@ -461,10 +454,11 @@ private boolean nodesRunning(List nodesToBeChecked, String pathology) th List notContainerProxy = new ArrayList<>(); ContainerProxy[] containerProxy = ArtRegistryLocator.getArtRegistryProxy().getContainers(); //get IP's from Exareme's Registry for (String IP : nodesToBeChecked) { + log.debug("Node to be checked: "+IP); boolean flag = false; for (ContainerProxy containers : containerProxy) { - log.debug("Container in registry: " + containers.getEntityName().getIP()); if (containers.getEntityName().getIP().contains(IP)) { //If IP exists in Exareme's Registry + log.debug("Container in registry: " + containers.getEntityName().getIP()); flag = true; break; } @@ -487,14 +481,19 @@ private boolean nodesRunning(List nodesToBeChecked, String pathology) th //Delete pathologies and IP of the node String pathologyKey = searchConsul(System.getenv("DATA") + "/" + name + "?keys"); String[] pathologyKeyArray = gson.fromJson(pathologyKey, String[].class); - for( String p: pathologyKeyArray) { + for (String p : pathologyKeyArray) { deleteFromConsul(p); //Delete every pathology for node with name $name } //Delete IP of active_worker with name $name deleteFromConsul(System.getenv("EXAREME_ACTIVE_WORKERS_PATH") + "/" + name); //Get datasets exist in other nodes for showing appropriate message to user - HashMap nodeDatasets = getDatasetsFromConsul(pathology); + HashMap nodeDatasets; + try { + nodeDatasets = getDatasetsFromConsul(pathology); + } catch (Exception e) { + throw new Exception("Can not contact Consul key value store. Please inform your system admin."); + } for (Map.Entry entry : nodeDatasets.entrySet()) { String[] getDatasets = entry.getValue(); for (String data : getDatasets) { @@ -540,7 +539,7 @@ private List allNodesIPs() throws RemoteException { } //Consul[Key-Value store] consists of information like IP's of Exareme nodes, Datasets existing at each node. - private String searchConsul(String query) throws IOException,ServerException { + private String searchConsul(String query) throws IOException { String result = null; CloseableHttpClient httpclient = HttpClients.createDefault(); String consulURL = System.getenv("CONSULURL"); @@ -554,20 +553,14 @@ private String searchConsul(String query) throws IOException,ServerException { log.debug("Running: " + httpGet.getURI()); CloseableHttpResponse response = null; if (httpGet.toString().contains(System.getenv("EXAREME_MASTER_PATH") + "/") || httpGet.toString().contains(System.getenv("DATA") + "/")) { //if we can not contact : http://exareme-keystore:8500/v1/kv/master* or http://exareme-keystore:8500/v1/kv/datasets* - log.debug(httpGet.toString()); - try { //then throw exception - log.debug("trying to execute connection"); + try { //then throw exception response = httpclient.execute(httpGet); } catch (Exception e) { - log.debug("caught an error:"+e.getMessage()); - response.close(); - throw new IOException(e.getMessage()); + log.error("Caught an error:"+e.getMessage()); + response.close(); + throw new IOException(e.getMessage()); } - result = EntityUtils.toString(response.getEntity()); - if (result == null ) { - throw new IOException("Can not contact consul"); - } - log.debug(response.getStatusLine().getStatusCode()); + result = EntityUtils.toString(response.getEntity()); } if (httpGet.toString().contains(System.getenv("EXAREME_ACTIVE_WORKERS_PATH") + "/")) { //if we can not contact : http://exareme-keystore:8500/v1/kv/active_workers* //then maybe there are no workers running @@ -580,11 +573,13 @@ private String searchConsul(String query) throws IOException,ServerException { result = EntityUtils.toString(response.getEntity()); } } - finally { - response.close(); + catch (Exception e){ + log.debug("Caught an error:"+e.getMessage()); + response.close(); + throw new IOException(e.getMessage()); } } - return result; + return result; } //Some times infos regarding Exareme nodes exist in Consul-Key-Value store], but the nodes are not part of Exareme's registry. We delete the infos from Consul[Key-Value store] diff --git a/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java b/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java index 4b08c09a5..a0b674ce3 100644 --- a/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java +++ b/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/remote/RmiObjectProxy.java @@ -88,7 +88,7 @@ public T getRemoteObject() throws RemoteException { //Get the Exareme's node name that is not responding HashMap names = null; try { - semaphore.acquire(); + semaphore.acquire(); names = getNamesOfActiveNodes(); for (Map.Entry entry : names.entrySet()) { log.debug("ActiveNodes from Consul key-value store: " + entry.getKey() + " = " + entry.getValue()); @@ -120,9 +120,14 @@ public T getRemoteObject() throws RemoteException { } } } - semaphore.release(); throw new RemoteException("There was an error with worker "+ "["+ regEntityName.getIP() + "]."); } + finally { + boolean acquired = semaphore.tryAcquire(); + if (!acquired) { + semaphore.release(); + } + } } return remoteObject; } From 068f8bbd0f21d6f8033d98faca1f679b1ab5f704 Mon Sep 17 00:00:00 2001 From: sofiakarb Date: Mon, 20 Jan 2020 17:27:16 +0200 Subject: [PATCH 08/11] PathologyException before Exception --- .../handler/HttpAsyncMiningQueryHandler.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java index e974cfc05..21547f433 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java @@ -142,7 +142,18 @@ private void handleInternal(HttpRequest request, HttpResponse response, HttpCont if (pathology != null) { try { nodeDatasets = getDatasetsFromConsul(pathology); - } catch (Exception e){ + } + catch (PathologyException e) { + log.error(e.getMessage()); + String data = e.getMessage(); + String type = user_error; //type could be error, user_error, warning regarding the error occured along the process + String result = defaultOutputFormat(data, type); + BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(result.getBytes())); + response.setStatusCode(HttpStatus.SC_BAD_REQUEST); + response.setEntity(entity); + } + catch (Exception e){ String data = "Can not contact Consul key value Store.Please inform your system admin."; String type = error; //type could be error, user_error, warning regarding the error occured along the process String result = defaultOutputFormat(data, type); @@ -257,7 +268,7 @@ private void handleInternal(HttpRequest request, HttpResponse response, HttpCont entity.setContent(new ByteArrayInputStream(result.getBytes())); response.setStatusCode(HttpStatus.SC_BAD_REQUEST); response.setEntity(entity); - } catch (PathologyException | DatasetsException | IOException e) { + } catch (DatasetsException | IOException e) { log.error(e.getMessage()); String data = e.getMessage(); String type = user_error; //type could be error, user_error, warning regarding the error occured along the process @@ -573,11 +584,11 @@ private String searchConsul(String query) throws IOException { result = EntityUtils.toString(response.getEntity()); } } - catch (Exception e){ + catch (Exception e){ log.debug("Caught an error:"+e.getMessage()); response.close(); throw new IOException(e.getMessage()); - } + } } return result; } From 4d4defad242c3cdf2d72497193a312dde3922059 Mon Sep 17 00:00:00 2001 From: sofiakarb Date: Mon, 20 Jan 2020 17:38:28 +0200 Subject: [PATCH 09/11] update --- .../gateway/async/handler/HttpAsyncMiningQueryHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java index 21547f433..0dd3c843d 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java @@ -152,6 +152,7 @@ private void handleInternal(HttpRequest request, HttpResponse response, HttpCont entity.setContent(new ByteArrayInputStream(result.getBytes())); response.setStatusCode(HttpStatus.SC_BAD_REQUEST); response.setEntity(entity); + return; } catch (Exception e){ String data = "Can not contact Consul key value Store.Please inform your system admin."; From d1f9b95122685239073a6e195482f363c4cf813a Mon Sep 17 00:00:00 2001 From: sofiakarb Date: Mon, 20 Jan 2020 18:10:09 +0200 Subject: [PATCH 10/11] nodesRunning exception --- .../async/handler/HttpAsyncMiningQueryHandler.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java index 0dd3c843d..9f32270ee 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java @@ -269,7 +269,7 @@ private void handleInternal(HttpRequest request, HttpResponse response, HttpCont entity.setContent(new ByteArrayInputStream(result.getBytes())); response.setStatusCode(HttpStatus.SC_BAD_REQUEST); response.setEntity(entity); - } catch (DatasetsException | IOException e) { + } catch (PathologyException | DatasetsException | IOException e) { log.error(e.getMessage()); String data = e.getMessage(); String type = user_error; //type could be error, user_error, warning regarding the error occured along the process @@ -503,7 +503,11 @@ private boolean nodesRunning(List nodesToBeChecked, String pathology) th HashMap nodeDatasets; try { nodeDatasets = getDatasetsFromConsul(pathology); - } catch (Exception e) { + } + catch (PathologyException e) { + throw new PathologyException(e.getMessage()); + } + catch (Exception e) { throw new Exception("Can not contact Consul key value store. Please inform your system admin."); } for (Map.Entry entry : nodeDatasets.entrySet()) { @@ -571,7 +575,7 @@ private String searchConsul(String query) throws IOException { log.error("Caught an error:"+e.getMessage()); response.close(); throw new IOException(e.getMessage()); - } + } result = EntityUtils.toString(response.getEntity()); } if (httpGet.toString().contains(System.getenv("EXAREME_ACTIVE_WORKERS_PATH") + "/")) { //if we can not contact : http://exareme-keystore:8500/v1/kv/active_workers* From b7e3018959f6732e959cad2c7d1facd4f82b7d65 Mon Sep 17 00:00:00 2001 From: sofiakarb Date: Tue, 28 Jan 2020 14:16:39 +0200 Subject: [PATCH 11/11] Change error to user --- .../async/handler/HttpAsyncMiningQueryHandler.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java index 9f32270ee..d9af64835 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HttpAsyncMiningQueryHandler.java @@ -155,7 +155,7 @@ private void handleInternal(HttpRequest request, HttpResponse response, HttpCont return; } catch (Exception e){ - String data = "Can not contact Consul key value Store.Please inform your system admin."; + String data = "An error has occurred.Please inform your system admin."; String type = error; //type could be error, user_error, warning regarding the error occured along the process String result = defaultOutputFormat(data, type); BasicHttpEntity entity = new BasicHttpEntity(); @@ -508,7 +508,7 @@ private boolean nodesRunning(List nodesToBeChecked, String pathology) th throw new PathologyException(e.getMessage()); } catch (Exception e) { - throw new Exception("Can not contact Consul key value store. Please inform your system admin."); + throw new Exception("An error has occurred.Please inform your system admin."); } for (Map.Entry entry : nodeDatasets.entrySet()) { String[] getDatasets = entry.getValue(); @@ -572,9 +572,7 @@ private String searchConsul(String query) throws IOException { try { //then throw exception response = httpclient.execute(httpGet); } catch (Exception e) { - log.error("Caught an error:"+e.getMessage()); response.close(); - throw new IOException(e.getMessage()); } result = EntityUtils.toString(response.getEntity()); } @@ -590,9 +588,7 @@ private String searchConsul(String query) throws IOException { } } catch (Exception e){ - log.debug("Caught an error:"+e.getMessage()); response.close(); - throw new IOException(e.getMessage()); } } return result;