diff options
3 files changed, 38 insertions, 8 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java index 4097afe..557ba39 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -61,8 +61,8 @@ public class ClientController { return "queryForm"; } - @PostMapping("/query") - public String submitQuery(@ModelAttribute Query queryObject, Model model) { + @PostMapping("/installQuery") + public String installQuery(@ModelAttribute Query queryObject, Model model) { boolean success = true; try { @@ -76,7 +76,32 @@ public class ClientController { if (success) { model.addAttribute( "homeMessage", - "Query submitted successfully"); + "Query installed successfully"); + } else { + model.addAttribute( + "homeMessage", + "Query submission failed with a remote exception"); + } + + return "home"; + } + + @PostMapping("/uninstallQuery") + public String uninstallQuery(@ModelAttribute Query queryObject, Model model) { + boolean success = true; + + try { + this.api.uninstallQuery(queryObject.getName()); + } catch (Exception e) { + success = false; + System.err.println("Client exception:"); + e.printStackTrace(); + } + + if (success) { + model.addAttribute( + "homeMessage", + "Query uninstalled successfully"); } else { model.addAttribute( "homeMessage", diff --git a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/queryForm.html b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/queryForm.html index 08b4e89..f31ef6b 100644 --- a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/queryForm.html +++ b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/queryForm.html @@ -12,7 +12,7 @@ <div th:replace="fragments/navbar :: navbar"></div> <div id="installQueryForm"> <h2 class="display-7">Install query</h2> - <form action="#" th:action="@{/query}" th:object="${queryObject}" method="post"> + <form action="#" th:action="@{/installQuery}" th:object="${queryObject}" method="post"> <div class="form-group"> <label for="InstallQueryName1">Enter query name</label> <input type="text" class="form-control" id="InstallQueryName1" rows="3" th:field="*{name}"/> @@ -27,7 +27,7 @@ <div id="uninstallQueryForm"> <h2 class="display-7">Uninstall query</h2> - <form action="#" th:action="@{/query}" th:object="${queryObject}" method="post"> + <form action="#" th:action="@{/uninstallQuery}" th:object="${queryObject}" method="post"> <div class="form-group"> <label for="UninstallQueryName1">Enter query name</label> <input type="text" class="form-control" id="UninstallQueryName1" rows="3" th:field="*{name}"/> diff --git a/src/main/resources/pl/edu/mimuw/cloudatlas/fetcher/data_fetcher.py b/src/main/resources/pl/edu/mimuw/cloudatlas/fetcher/data_fetcher.py index 67b2eb4..d53ce05 100644 --- a/src/main/resources/pl/edu/mimuw/cloudatlas/fetcher/data_fetcher.py +++ b/src/main/resources/pl/edu/mimuw/cloudatlas/fetcher/data_fetcher.py @@ -64,9 +64,14 @@ def get_data(): kernel_ver = platform.release() logged_users = len(psutil.users()) - external_ip = urllib.request.urlopen('https://ident.me').read().decode('utf8') - hostname = socket.gethostbyaddr(external_ip) - dns_names = ([hostname[0]] + hostname[1])[:3] + try: + external_ip = urllib.request.urlopen('https://ident.me').read().decode('utf8') + hostname = socket.gethostbyaddr(external_ip) + dns_names = ([hostname[0]] + hostname[1])[:3] + except Exception as e: + pass + else: + dns_names = [] sys.stdout.write("[{},{},{},{},{},{},{},{},{},{},{},{}]\n".format( avg_load, |