Skip to content
Snippets Groups Projects
Commit d410f5d5 authored by Elisa Giglio's avatar Elisa Giglio
Browse files

install

parent 8713a624
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ public class InstallHandler implements HttpHandler {
HttpsExchange he = (HttpsExchange) hex;
String requestMethod = he.getRequestMethod();
// System.out.println(requestMethod);
if (requestMethod.compareToIgnoreCase("options") == 0) {
Helper.sendCors(he, 200);
......@@ -45,6 +46,7 @@ public class InstallHandler implements HttpHandler {
JSONObject j = null;
try {
j = new JSONObject(body);
String dm = j.getString("domain");
Dominio d = DBC.getDom(dm);
if (d != null) {
......@@ -93,11 +95,13 @@ public class InstallHandler implements HttpHandler {
}
JSONArray arrServ = j.getJSONArray("services");// array con solo il nome dei servizi da installare
// System.out.println("arrServ = "+arrServ);
ArrayList<String> moduleHosts = new ArrayList<String>();
for (int i = 0; i < arrServ.length(); i++) {
String modul = arrServ.getString(i);
String modul = arrServ.getString(i).replace("gpio","bbgpio").replace("arduino","AinDout_Arduino1wifi");
moduleHosts.addAll(DBC.insertService(domain, modul));
}
// System.out.println("riga 105 moduleHost = " + moduleHosts);
// divido gli host in base al loro module
HashMap<String, ArrayList<String>> hostsMap = new HashMap<String, ArrayList<String>>();
for (String mh : moduleHosts) {
......@@ -112,13 +116,17 @@ public class InstallHandler implements HttpHandler {
hostsMap.put(module, hostsList);
}
hostsList.add(host);
// System.out.println("riga 120 modulo = "+ module + " host = "+ host);
}
// imposta correttamente l'array dei servizi
JSONArray arrServiziFinale = new JSONArray();
for (int i = 0; i < arrServ.length(); i++) {
JSONObject row = new JSONObject();
String mod = arrServ.getString(i);
String mod = arrServ.getString(i).replace("gpio","bbgpio").replace("arduino","AinDout_Arduino1wifi");
// System.out.println("mod = "+mod + " indice = "+i);
ArrayList<String> ho = hostsMap.get(mod);
// System.out.println(" riga 131 ho = "+ho);
for (String h : ho) {
row.put("host", h.replace("BB1","luci"));
row.put("service", mod);
......@@ -126,10 +134,13 @@ public class InstallHandler implements HttpHandler {
arrServiziFinale.put(row);
}
}
// System.out.println("riga 137 arrServiziFinale = "+arrServiziFinale);
j.put("services", arrServiziFinale);
} catch (SQLException | JSONException e) {
e.printStackTrace();
} catch ( Exception e2) {
e2.printStackTrace();
}
// ora bisogna fare la chiamata al CloudApp, non prima!
// effettuo chiamata a CloudAppManager
......@@ -143,6 +154,7 @@ public class InstallHandler implements HttpHandler {
HttpURLConnection con = Helper.sendMessageToCloudapp("install", j.toString());
int status = con.getResponseCode();
// FIXME serve avere anche il content?
// String cloudappResponse = Helper.getResponseFromConnection(con);
con.disconnect();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment