Commit 13fe80b7 authored by mohammad.salama's avatar mohammad.salama

Web Interface added - All working

parent 0f68e317
...@@ -10,11 +10,13 @@ ...@@ -10,11 +10,13 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b8bcd35c-99f3-44c8-a866-59f81c3c8bd0" name="Changes" comment="Working as Strings, no json, problem in coordinator address"> <list default="true" id="b8bcd35c-99f3-44c8-a866-59f81c3c8bd0" name="Changes" comment="Working as Strings, no json, problem in coordinator address">
<change afterPath="$PROJECT_DIR$/index.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/logs/app.log" beforeDir="false" afterPath="$PROJECT_DIR$/logs/app.log" afterDir="false" /> <change beforePath="$PROJECT_DIR$/logs/app.log" beforeDir="false" afterPath="$PROJECT_DIR$/logs/app.log" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/WebSide/ClientApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/WebSide/ClientApplication.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/WebSide/ClientApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/WebSide/ClientApplication.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/WebSide/WebClient.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/WebSide/WebClient.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/WebSide/WebServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/WebSide/WebServer.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/WebSide/WebServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/WebSide/WebServer.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/WebSide/ClientApplication.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/WebSide/ClientApplication.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/WebSide/WebServer.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/WebSide/WebServer.class" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -49,26 +51,27 @@ ...@@ -49,26 +51,27 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;ToolWindowRun.ShowToolbar&quot;: &quot;false&quot;, "ToolWindowRun.ShowToolbar": "false",
&quot;jdk.selected.JAVA_MODULE&quot;: &quot;17 (2)&quot;, "jdk.selected.JAVA_MODULE": "17 (2)",
&quot;last_opened_file_path&quot;: &quot;D:/HIAST/FIY/FS/Distributed Systems/Lab/4/HomeWork&quot;, "last_opened_file_path": "D:/HIAST/FIY/FS/Distributed Systems/Lab/8/Distributed-Search",
&quot;project.structure.last.edited&quot;: &quot;Artifacts&quot;, "project.structure.last.edited": "Artifacts",
&quot;project.structure.proportion&quot;: &quot;0.15&quot;, "project.structure.proportion": "0.15",
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;, "project.structure.side.proportion": "0.2",
&quot;settings.editor.selected.configurable&quot;: &quot;reference.settings.project.maven.repository.indices&quot; "settings.editor.selected.configurable": "reference.settings.project.maven.repository.indices"
} }
}</component> }]]></component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search" />
<recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\src\main\java\WebSide" />
<recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\src\main\java" /> <recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\src\main\java" />
<recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\src\main\java\GRPC" /> <recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\src\main\java\GRPC" />
<recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\src\main\java\GRPC\GRPCConnection" /> <recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\src\main\java\GRPC\GRPCConnection" />
<recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\src\main\java\SearchWebApp\WebClient" />
</key> </key>
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
<recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\src\main\proto" /> <recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\src\main\proto" />
...@@ -85,7 +88,7 @@ ...@@ -85,7 +88,7 @@
<command value="mvn clean install" /> <command value="mvn clean install" />
</option> </option>
</component> </component>
<component name="RunManager" selected="Application.WebClient"> <component name="RunManager" selected="Application.WebServer">
<configuration name="Node1" type="Application" factoryName="Application"> <configuration name="Node1" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application" /> <option name="MAIN_CLASS_NAME" value="org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application" />
<module name="Distributed-Search" /> <module name="Distributed-Search" />
......
...@@ -2,8 +2,5 @@ Run Nodes first. ...@@ -2,8 +2,5 @@ Run Nodes first.
then Run WebServer then Run WebServer
then WebClient then open browser to localhost:5566/
and see the wonders !!
configured in run settings. \ No newline at end of file
no jars due to development.
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Search Page</title>
<script>
function search() {
var query = document.getElementById('searchInput').value;
fetch('/search', {
method: 'POST',
body: JSON.stringify({ query: query }),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
var results = document.getElementById('results');
results.innerHTML = '';
data.files.forEach(file => {
var listItem = document.createElement('li');
listItem.textContent = file;
results.appendChild(listItem);
});
})
.catch(error => console.error('Error:', error));
}
</script>
</head>
<body>
<h1>Search Page</h1>
<input type="text" id="searchInput" style="padding:10px ; width:500px">
<button onclick="search()" style="padding:10px ; width:150px">Search</button>
<ul id="results"></ul>
</body>
</html>
\ No newline at end of file
...@@ -1167,3 +1167,39 @@ java.lang.NullPointerException: Cannot invoke "java.util.List.isEmpty()" because ...@@ -1167,3 +1167,39 @@ java.lang.NullPointerException: Cannot invoke "java.util.List.isEmpty()" because
2024-02-01 14:26:21,329 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1 2024-02-01 14:26:21,329 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:28:46,493 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1 2024-02-01 14:28:46,493 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:29:03,769 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1 2024-02-01 14:29:03,769 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:43:21,112 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-02-01 14:43:21,131 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000265
2024-02-01 14:43:21,135 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-02-01 14:43:21,138 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-02-01 14:43:21,141 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-02-01 14:43:21,663 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application [main] Starting Application using Java 17.0.5 on M-Salameh with PID 6220 (D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\target\classes started by M_Salameh in D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search)
2024-02-01 14:43:21,663 DEBUG org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application [main] Running with Spring Boot v2.6.8, Spring v5.3.20
2024-02-01 14:43:21,664 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application [main] No active profile set, falling back to 1 default profile: "default"
2024-02-01 14:43:22,915 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application [main] Started Application in 1.63 seconds (JVM running for 5.764)
2024-02-01 14:43:30,498 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-02-01 14:43:30,519 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000266
2024-02-01 14:43:30,523 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-02-01 14:43:30,530 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-02-01 14:43:30,538 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 66
2024-02-01 14:43:30,545 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.ServiceRegistry [main-EventThread] The cluster addresses are: [127.0.0.1:66]
2024-02-01 14:51:11,204 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:51:26,813 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:51:28,879 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:51:30,606 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:51:35,925 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:52:48,325 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:53:44,164 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:54:22,307 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:55:30,477 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 14:59:19,391 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 15:01:00,405 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-02-01 15:02:44,860 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-02-01 15:02:44,879 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000267
2024-02-01 15:02:44,882 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-02-01 15:02:44,884 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-02-01 15:02:44,887 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-02-01 15:02:45,405 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application [main] Starting Application using Java 17.0.5 on M-Salameh with PID 15432 (D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search\target\classes started by M_Salameh in D:\HIAST\FIY\FS\Distributed Systems\Lab\8\Distributed-Search)
2024-02-01 15:02:45,406 DEBUG org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application [main] Running with Spring Boot v2.6.8, Spring v5.3.20
2024-02-01 15:02:45,406 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application [main] No active profile set, falling back to 1 default profile: "default"
2024-02-01 15:02:46,594 INFO org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application [main] Started Application in 1.55 seconds (JVM running for 5.526)
2024-02-01 15:04:27,710 WARN org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Coordinator [grpc-default-executor-0] No Nodes Are Working , Search Cannot Be Done
...@@ -17,6 +17,7 @@ public class ClientApplication ...@@ -17,6 +17,7 @@ public class ClientApplication
WebClient webClient = new WebClient(); WebClient webClient = new WebClient();
JsonObject ans = webClient.sendQuery(SearchEngine , query); JsonObject ans = webClient.sendQuery(SearchEngine , query);
String[] kk = ans.toString().split(","); String[] kk = ans.toString().split(",");
for (String k : kk) for (String k : kk)
{ {
System.out.println(k); System.out.println(k);
......
...@@ -14,9 +14,11 @@ import org.slf4j.Logger; ...@@ -14,9 +14,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.awt.*; import java.awt.*;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -65,13 +67,16 @@ public class WebServer ...@@ -65,13 +67,16 @@ public class WebServer
HttpContext searchContext = server.createContext(Search_EndPoint); HttpContext searchContext = server.createContext(Search_EndPoint);
searchContext.setHandler(this::handleSearchRequest); searchContext.setHandler(this::handleSearchRequest);
HttpContext htmlContext = server.createContext("/");
htmlContext.setHandler(this::handleHtmlRequest);
server.setExecutor(Executors.newFixedThreadPool(8)); server.setExecutor(Executors.newFixedThreadPool(8));
server.start(); server.start();
} }
private void handleSearchRequest(HttpExchange exchange) throws IOException { private void handleSearchRequest(HttpExchange exchange) throws IOException
{
logger.info("Search Request at " + System.nanoTime()); logger.info("Search Request at " + System.nanoTime());
if (!exchange.getRequestMethod().equalsIgnoreCase("post")) { if (!exchange.getRequestMethod().equalsIgnoreCase("post")) {
exchange.close(); exchange.close();
...@@ -81,6 +86,8 @@ public class WebServer ...@@ -81,6 +86,8 @@ public class WebServer
byte[] requestBytes = exchange.getRequestBody().readAllBytes(); byte[] requestBytes = exchange.getRequestBody().readAllBytes();
String query = new String(requestBytes); String query = new String(requestBytes);
query = extractQuery(query);
//System.out.println(query);
List<String> files = new ArrayList<>(); List<String> files = new ArrayList<>();
try try
{ {
...@@ -122,4 +129,25 @@ public class WebServer ...@@ -122,4 +129,25 @@ public class WebServer
exchange.close(); exchange.close();
} }
private String extractQuery(String query)
{
query = query.split(":")[1];
query = query.replace("\"" , "");
query = query.replace("}" , "");
return query;
}
private void handleHtmlRequest(HttpExchange exchange) throws IOException {
String filePath = "index.html";
File file = new File(filePath);
byte[] fileBytes = Files.readAllBytes(file.toPath());
exchange.getResponseHeaders().set("Content-Type", "text/html");
exchange.sendResponseHeaders(200, fileBytes.length);
OutputStream outputStream = exchange.getResponseBody();
outputStream.write(fileBytes);
outputStream.flush();
outputStream.close();
exchange.close();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment