From a5af445acaf16660c28f6012be15c17915efc874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 20 Nov 2019 11:38:26 +0100 Subject: Add api call to client query installation --- .../pl/edu/mimuw/cloudatlas/client/Client.java | 11 ++------- .../mimuw/cloudatlas/client/ClientController.java | 28 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java index 96fe14f..5e71754 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java @@ -1,5 +1,6 @@ package pl.edu.mimuw.cloudatlas.client; +import org.springframework.context.annotation.Bean; import pl.edu.mimuw.cloudatlas.api.Api; import java.rmi.registry.LocateRegistry; @@ -29,14 +30,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Client { public static void main(String[] args) { - try { - Registry registry = LocateRegistry.getRegistry("localhost"); - Api api = (Api) registry.lookup("Api"); - - SpringApplication.run(Client.class, args); - } catch (Exception e) { - System.err.println("Client exception:"); - e.printStackTrace(); - } + SpringApplication.run(Client.class, args); } } 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 62f77ee..f6b1524 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -1,8 +1,16 @@ package pl.edu.mimuw.cloudatlas.client; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.stereotype.Controller; +import pl.edu.mimuw.cloudatlas.api.Api; + +import javax.annotation.PostConstruct; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; /* should enable reading attribute values stored by the agent @@ -17,6 +25,17 @@ plotting the attributes with numeric values as real-time graphs. @Controller public class ClientController { + private Api api; + + ClientController() { + try { + Registry registry = LocateRegistry.getRegistry("localhost"); + this.api = (Api) registry.lookup("Api"); + } catch (Exception e) { + System.err.println("Client exception:"); + e.printStackTrace(); + } + } @GetMapping("/") public String homePage(Model model) { @@ -31,7 +50,14 @@ public class ClientController { } @PostMapping("/query") - public String submitQuery(@ModelAttribute Query queryObject, Model model) { + public String submitQuery(@ModelAttribute Query queryObject, Model model) { + try { + this.api.installQuery(queryObject.getName(), queryObject.getValue()); + } catch (Exception e) { + System.err.println("Client exception:"); + e.printStackTrace(); + } + model.addAttribute("homeMessage", "Query submitted successfully"); return "home"; } -- cgit v1.2.3 From 5160a9622c22463a383271e5b00f7b46d6959bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 20 Nov 2019 11:43:09 +0100 Subject: Cleanup Client file --- .../pl/edu/mimuw/cloudatlas/client/Client.java | 24 ---------------------- 1 file changed, 24 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java index 5e71754..b63e4fd 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java @@ -1,32 +1,8 @@ package pl.edu.mimuw.cloudatlas.client; -import org.springframework.context.annotation.Bean; -import pl.edu.mimuw.cloudatlas.api.Api; - -import java.rmi.registry.LocateRegistry; -import java.rmi.RemoteException; -import java.rmi.registry.Registry; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -/** - * Main class for a client. - * - * Set the following properties on the command line: - * - *
- * -Djava.rmi.server.useCodebaseOnly=false - *
- * -Djava.rmi.server.codebase=file:/path/to/compiled/classes/ - *
- * -Djava.security.policy=client.policy - *
- * - * NOTE: MAKE SURE YOU HAVE THE TRAILING / ON THE CODEBASE PATH - */ - -// https://github.com/rm5248/Java-RMI-Example/ - @SpringBootApplication public class Client { public static void main(String[] args) { -- cgit v1.2.3 From 3b82c72f0de30db176df3a1bc5323e0fd9bb0a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 20 Nov 2019 11:43:50 +0100 Subject: Cleanup unused imports from client controller --- src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas') 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 f6b1524..ea39a3d 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -1,14 +1,10 @@ package pl.edu.mimuw.cloudatlas.client; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.stereotype.Controller; import pl.edu.mimuw.cloudatlas.api.Api; -import javax.annotation.PostConstruct; -import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; -- cgit v1.2.3 From 4693b0a6ac7bcb408eef3aac67d1052082ce9ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 20 Nov 2019 14:20:39 +0100 Subject: Add exception message to query submission --- .../pl/edu/mimuw/cloudatlas/client/ClientController.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas') 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 ea39a3d..bdc71df 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -47,14 +47,26 @@ public class ClientController { @PostMapping("/query") public String submitQuery(@ModelAttribute Query queryObject, Model model) { + boolean success = true; + try { this.api.installQuery(queryObject.getName(), queryObject.getValue()); } catch (Exception e) { + success = false; System.err.println("Client exception:"); e.printStackTrace(); } - model.addAttribute("homeMessage", "Query submitted successfully"); + if (success) { + model.addAttribute( + "homeMessage", + "Query submitted successfully"); + } else { + model.addAttribute( + "homeMessage", + "Query submission failed with a remote exception"); + } + return "home"; } -- cgit v1.2.3 From f7bc805b5e63269107ba87e8d2d3007737cb379e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 20 Nov 2019 16:18:27 +0100 Subject: Extend client data model to read contact jsons --- .../edu/mimuw/cloudatlas/client/ContactsString.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/client/ContactsString.java (limited to 'src/main/java/pl/edu/mimuw/cloudatlas') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/ContactsString.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/ContactsString.java new file mode 100644 index 0000000..7cdd82e --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ContactsString.java @@ -0,0 +1,20 @@ +package pl.edu.mimuw.cloudatlas.client; + +public class ContactsString { + private String string; + + public String getString() { + return string; + } + + public void setString(String string) { + this.string = string; + } + + @Override + public String toString() { + return "ContactString{" + + "string='" + string + '\'' + + '}'; + } +} -- cgit v1.2.3 From 906996114a16ef5d7576de7f48ea22fd1f680b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 20 Nov 2019 16:19:25 +0100 Subject: Add contact submission backend --- .../mimuw/cloudatlas/client/ClientController.java | 44 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas') 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 bdc71df..31d1c06 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -1,12 +1,21 @@ package pl.edu.mimuw.cloudatlas.client; +import com.google.gson.Gson; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.stereotype.Controller; import pl.edu.mimuw.cloudatlas.api.Api; +import pl.edu.mimuw.cloudatlas.model.PathName; +import pl.edu.mimuw.cloudatlas.model.ValueContact; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; /* should enable reading attribute values stored by the agent @@ -72,12 +81,43 @@ public class ClientController { @GetMapping("/contacts") public String contactPage(Model model) { + model.addAttribute("contactsObject" , new ContactsString()); return "contactsForm"; } @PostMapping("/contacts") - public String contactPage(@ModelAttribute String contactsObject, Model model) { - model.addAttribute("homeMessage", "Contact list submitted successfully"); + public String contactPage(@ModelAttribute ContactsString contactsObject, Model model) { + boolean success = true; + Gson gson = new Gson(); + Map contactStrings = gson.fromJson(contactsObject.getString(), Map.class); + Set contactObjects = new HashSet(); + ArrayList cAddr; + byte[] inetArray = new byte[4]; + + try { + for (Map.Entry cursor : contactStrings.entrySet()) { + cAddr = cursor.getValue(); // gson always reads numerical values as doubles + for (int i = 0; i < 4; i++) { + inetArray[i] = (byte) cAddr.get(i).doubleValue(); + } + contactObjects.add(new ValueContact( + new PathName(cursor.getKey()), + InetAddress.getByAddress(inetArray)) + ); + } + this.api.setFallbackContacts(contactObjects); + } catch (Exception e) { + success = false; + System.err.println("Client exception:"); + e.printStackTrace(); + } + + if (success) { + model.addAttribute("homeMessage", "Contact list submitted successfully"); + } else { + model.addAttribute("homeMessage", "Contact list submission failed"); + } + return "home"; } -- cgit v1.2.3 From 5a44701aecd6531b3cb6403d359b6c8f6cd89a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 20 Nov 2019 16:20:40 +0100 Subject: Fix pathname serialization --- src/main/java/pl/edu/mimuw/cloudatlas/model/PathName.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/PathName.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/PathName.java index 7f3a9ac..e56b62a 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/PathName.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/PathName.java @@ -24,6 +24,7 @@ package pl.edu.mimuw.cloudatlas.model; +import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -33,7 +34,7 @@ import java.util.List; /** * Represent a fully qualified name of a zone, also known as a global name or a path name. Objects of this class are immutable. */ -public class PathName { +public class PathName implements Serializable { /** * Object representing the name of the root zone (/). */ -- cgit v1.2.3