diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7a5faf4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 The Naval Postgraduate School + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/webapp/WEB-INF/classes/1 b/webapp/WEB-INF/classes/1 new file mode 100644 index 0000000..e3d57ed --- /dev/null +++ b/webapp/WEB-INF/classes/1 @@ -0,0 +1,13 @@ + + +DiDAP Job Monitor + + +

+

DiDAP Job Monitor

+ + + diff --git a/webapp/WEB-INF/classes/HelloWorld.class b/webapp/WEB-INF/classes/HelloWorld.class new file mode 100644 index 0000000..37d7c28 Binary files /dev/null and b/webapp/WEB-INF/classes/HelloWorld.class differ diff --git a/webapp/WEB-INF/classes/HelloWorld.java b/webapp/WEB-INF/classes/HelloWorld.java new file mode 100644 index 0000000..24467db --- /dev/null +++ b/webapp/WEB-INF/classes/HelloWorld.java @@ -0,0 +1,40 @@ +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ResourceBundle; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class HelloWorld extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException + { + response.setContentType("text/html"); + response.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + + out.println(""); + out.println(""); + out.println(""); + + String title = "Hello, World!"; + + out.println("" + title + ""); + out.println(""); + out.println(""); + + out.println("

" + title + "

"); + out.println(""); + out.println(""); + } +} + + + diff --git a/webapp/WEB-INF/classes/MetadataTableCreation.class b/webapp/WEB-INF/classes/MetadataTableCreation.class new file mode 100644 index 0000000..cb2e054 Binary files /dev/null and b/webapp/WEB-INF/classes/MetadataTableCreation.class differ diff --git a/webapp/WEB-INF/classes/MetadataTableCreation.java b/webapp/WEB-INF/classes/MetadataTableCreation.java new file mode 100644 index 0000000..b9da928 --- /dev/null +++ b/webapp/WEB-INF/classes/MetadataTableCreation.java @@ -0,0 +1,136 @@ +import java.io.IOException; +import java.io.PrintWriter; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ResourceBundle; +import java.util.Arrays; + +import java.sql.SQLException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.DriverManager; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class MetadataTableCreation extends HttpServlet { + private Connection conn; + private Statement stmt; + private boolean connEstablished = false; + private PrintWriter out; + + public void DBinit() { + if (!connEstablished) { + try { + // Register driver and create driver instance + String driverName = "com.cloudera.hive.jdbc4.HS1Driver"; + Class.forName(driverName); + } catch (ClassNotFoundException e) { + e.printStackTrace(out); + System.exit(1); + } + + try { + // Establish connection + String url = "jdbc:hive://localhost:10000/metadata"; + conn = DriverManager.getConnection(url, "", ""); + out.println("Connected to Database!"); + + // Create statement + stmt = conn.createStatement(); + connEstablished = true; + } catch (SQLException e) { + e.printStackTrace(out); + System.exit(1); + } + } + } + + public void createTable(String tableName) { + if (connEstablished) { + try { + String query = ""; + // create hive table statement + query = "CREATE EXTERNAL TABLE IF NOT EXISTS " + tableName + + " (filePath STRING, dateStamp INT,navTime STRING,FathTime STRING,latitude DOUBLE,longitude DOUBLE,waterDepth FLOAT,towfishDepth FLOAT)" + + "ROW FORMAT DELIMITED" + + "FIELDS TERMINATED BY ','" + + "STORED AS TEXTFILE" + + "LOCATION '/user/cloudera/successfulOutput_fullScript'"; + out.println("Your query:" + query); + stmt.executeQuery(query); // executeUpdate + } catch (SQLException e) { + e.printStackTrace(); + out.println("Query Failed!!"); + } + } + } + + public void DBExecuteQuery(String query) { + if (connEstablished) { + try { + out.println("Running: " + query); + stmt.execute(query); + out.println("Finished!"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + public void DBfinish() { + if (connEstablished) { + out.println("Connection Closed."); + try { + stmt.close(); + conn.close(); + connEstablished = false; + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + @Override + public void doGet(HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException + { + response.setContentType("text/html"); + response.setCharacterEncoding("UTF-8"); + out = response.getWriter(); + + out.println(""); + out.println(""); + out.println(""); + + String title = "Metadata Table Creation"; + + out.println("" + title + ""); + out.println(""); + + out.println(""); + + out.println("

" + title + " Status:

\n"); + out.println("Metadata Table Data Being Loaded from HDFS:"); + + // Create DB Connection + DBinit(); + + // Create Actual Table + //createTable("florida"); + + // Display HDFS Data + String query = "LOAD DATA INPATH '/user/cloudera/successfulOutput_fullScript/part-m-00000' OVERWRITE INTO TABLE florida"; + DBExecuteQuery(query); + + out.println(""); + out.println(""); + + // Close DB Connection + DBfinish(); + } +} diff --git a/webapp/WEB-INF/classes/MstiffExtraction.class b/webapp/WEB-INF/classes/MstiffExtraction.class new file mode 100644 index 0000000..c1d27cf Binary files /dev/null and b/webapp/WEB-INF/classes/MstiffExtraction.class differ diff --git a/webapp/WEB-INF/classes/MstiffExtraction.java b/webapp/WEB-INF/classes/MstiffExtraction.java new file mode 100644 index 0000000..94218dd --- /dev/null +++ b/webapp/WEB-INF/classes/MstiffExtraction.java @@ -0,0 +1,58 @@ +import java.io.IOException; +import java.io.PrintWriter; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ResourceBundle; +import java.util.Arrays; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class MstiffExtraction extends HttpServlet { + + @Override + public void doGet(HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException + { + response.setContentType("text/html"); + response.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + + out.println(""); + out.println(""); + out.println(""); + + String title = "MSTIFF Extraction"; + + out.println("" + title + ""); + out.println(""); + out.println(""); + + out.println("

" + title + " Job Status:

\n"); + + String[] command = {"/bin/bash", "/usr/share/tomcat/webapps/didap/WEB-INF/scripts/mstiff.sh"}; + ProcessBuilder p = new ProcessBuilder(command); + Process p2 = p.start(); + try { + p2.waitFor(); + } catch (InterruptedException e) { + e.printStackTrace(); + System.out.println("Did not execute in hadoop!"); + } + + BufferedReader br = new BufferedReader(new InputStreamReader(p2.getInputStream())); + String line; + + out.println("Output of running " + Arrays.toString(command) + " is: "); + while ((line = br.readLine()) != null) { + out.println(line + "\n"); + } + + out.println(""); + out.println(""); + } +} + diff --git a/webapp/WEB-INF/scripts/1 b/webapp/WEB-INF/scripts/1 new file mode 100644 index 0000000..9157cae --- /dev/null +++ b/webapp/WEB-INF/scripts/1 @@ -0,0 +1,23 @@ +#!/bin/bash + +su cloudera < + + HelloWorld + HelloWorld + + + MetadataTableCreation + MetadataTableCreation + + + MSTIFF_Extraction + MstiffExtraction + + + HelloWorld + /HelloWorld + + + MetadataTableCreation + /MetadataTableCreation + + + MSTIFF_Extraction + /MSTIFF_Extraction + + diff --git a/webapp/WEB-INF/web.xml~ b/webapp/WEB-INF/web.xml~ new file mode 100644 index 0000000..9db7f9c --- /dev/null +++ b/webapp/WEB-INF/web.xml~ @@ -0,0 +1,26 @@ + + + HelloWorld + HelloWorld + + + MetadataTableCreation + MetadataTableCreation + + + MSTIFF_Extraction + MstiffExtraction + + + HelloWorld + /HelloWorld + + + MetadataTableCreation + /MetadataTableCreation + + + MSTIFF_Extraction + /MSTIFF_Extraction + + diff --git a/webapp/WEB-INF/web_my.xml b/webapp/WEB-INF/web_my.xml new file mode 100644 index 0000000..3069058 --- /dev/null +++ b/webapp/WEB-INF/web_my.xml @@ -0,0 +1,18 @@ + + + HelloWorld + HelloWorld + + + MSTIFF_Extraction + MstiffExtraction + + + HelloWorld + /HelloWorld + + + MSTIFF_Extraction + /MSTIFF_Extraction + + diff --git a/webapp/index.html b/webapp/index.html new file mode 100644 index 0000000..894a95f --- /dev/null +++ b/webapp/index.html @@ -0,0 +1,13 @@ + + +DiDAP Job Monitor + + +

+

DiDAP Job Monitor

+ + + diff --git a/webapp/index.html~ b/webapp/index.html~ new file mode 100644 index 0000000..894a95f --- /dev/null +++ b/webapp/index.html~ @@ -0,0 +1,13 @@ + + +DiDAP Job Monitor + + +

+

DiDAP Job Monitor

+ + +