Commit 886d3322 authored by mohammad.salama's avatar mohammad.salama

Web and GRPC Working - No Web Client as html

parent e854fc87
......@@ -9,40 +9,20 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="b8bcd35c-99f3-44c8-a866-59f81c3c8bd0" name="Changes" comment="">
<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$/src/main/java/GRPCConnection/AddressProxy.java" 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$/src/main/java/GRPCConnection/GRPCClient/GRPCClient.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/GRPCConnection/GRPCClient/GRPCClient.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/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/Coordinator.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/Coordinator.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/ServiceRegistry.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/ServiceRegistry.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/SearchWebApp/WebClient/Aggregator.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/SearchWebApp/WebClient/Application.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/SearchWebApp/WebClient/WebClient.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/SearchWebApp/WebServer/WebServer.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/generalTesting/test.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/generalTesting/test.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/testTransmitting/MyClass.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/testTransmitting/Receiver.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/testTransmitting/Sender.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/GRPCConnection/GRPCClient/GRPCClient$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/GRPCConnection/GRPCClient/GRPCClient.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/GRPCConnection/GRPCClient/GRPCClient.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/WebSide/WebClient.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/WebSide/WebClient.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/WebSide/WebServer$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/WebSide/WebServer.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/WebSide/WebServer.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/Coordinator$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/Coordinator$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/Coordinator.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/Coordinator.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/ServiceRegistry$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/ServiceRegistry$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/ServiceRegistry.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/ServiceRegistry.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/SearchWebApp/WebClient/Aggregator.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/SearchWebApp/WebClient/Application.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/SearchWebApp/WebClient/WebClient.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/SearchWebApp/WebServer/WebServer$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/SearchWebApp/WebServer/WebServer.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/generalTesting/test.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/generalTesting/test.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/testTransmitting/MyClass.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/testTransmitting/Receiver.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/org/AutoHealerAndClusterSearch/testTransmitting/Sender.class" beforeDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -192,23 +172,22 @@
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Working as Strings, no json, problem in coordinator address" />
<option name="LAST_COMMIT_MESSAGE" value="Working as Strings, no json, problem in coordinator address" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/WebSide/WebClient.java</url>
<line>27</line>
<option name="timeStamp" value="11" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/WebSide/WebClient.java</url>
<line>32</line>
<option name="timeStamp" value="20" />
<url>file://$PROJECT_DIR$/src/main/java/WebSide/WebServer.java</url>
<line>85</line>
<option name="timeStamp" value="22" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/org/AutoHealerAndClusterSearch/AutoHealerAndClusterSearch/ServiceRegistry.java</url>
<line>74</line>
<option name="timeStamp" value="21" />
<url>file://$PROJECT_DIR$/src/main/java/GRPCConnection/GRPCClient/GRPCClient.java</url>
<line>37</line>
<option name="timeStamp" value="24" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
......
This diff is collapsed.
package GRPCConnection;
import org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Application;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
public class AddressProxy implements Watcher
{
private static final String address = "192.168.184.10:2181";
private static final int SESSION_TIMEOUT = 3000; //dead client
private static final String COORDINATOR_ZNODE_PATH = "/coordinator_node";
private ZooKeeper zooKeeper;
private String IP;
private final Logger logger = LoggerFactory.getLogger(AddressProxy.class);
public static AddressProxy start() throws IOException, InterruptedException {
AddressProxy addressProxy = new AddressProxy();
ZooKeeper zooKeeper = addressProxy.connectToZookeeper();
//addressProxy.run();
//addressProxy.close();
return addressProxy;
}
private synchronized void updateAddress() throws InterruptedException, KeeperException
{
List<String> temp = zooKeeper.getChildren(COORDINATOR_ZNODE_PATH , this);
if (temp.isEmpty()) return;
String node = temp.get(0);
node = COORDINATOR_ZNODE_PATH + "/" + node;
Stat stat = zooKeeper.exists(node , false);
IP = new String(zooKeeper.getData(node , false , stat));
IP = IP.split(":")[0];
}
public String getAddress() throws InterruptedException, KeeperException
{
if (IP==null)
{
updateAddress();
}
return IP;
}
@Override
public void process(WatchedEvent watchedEvent) {
switch (watchedEvent.getType())
{
case NodeChildrenChanged ->
{
try {
updateAddress();
} catch (InterruptedException | KeeperException e)
{
logger.error("Error Updating Coordinator address in Proxy");
throw new RuntimeException(e);
}
}
}
}
public ZooKeeper connectToZookeeper() throws IOException
{
this.zooKeeper = new ZooKeeper(address, SESSION_TIMEOUT, this);
return zooKeeper;
}
public void run() throws InterruptedException {
synchronized (zooKeeper) {
zooKeeper.wait();
}
}
private void close() throws InterruptedException {
this.zooKeeper.close();
}
}
......@@ -2,6 +2,7 @@ package GRPCConnection.GRPCClient;
import GRPCConnection.AddressProxy;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.AutoHealerAndClusterSearch.AutoHealerAndClusterSearch.Coordinator;
......@@ -13,6 +14,7 @@ import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.checkerframework.checker.units.qual.A;
import java.io.IOException;
import java.util.List;
......@@ -23,14 +25,11 @@ import java.util.List;
* */
public class GRPCClient
{
private String COORDINATOR_ADDRESS;
public List<String> search(String query) throws InterruptedException, KeeperException
public List<String> search(String query , String ip) throws InterruptedException, KeeperException
{
COORDINATOR_ADDRESS = Coordinator.getIP();
ManagedChannel channel = ManagedChannelBuilder.
forAddress("localhost" , 6565).
forAddress(ip, 6565).
usePlaintext().build();
SearchServiceGrpc.SearchServiceBlockingStub stub = SearchServiceGrpc.newBlockingStub(channel);
......
package WebSide;
import GRPCConnection.AddressProxy;
import GRPCConnection.GRPCClient.GRPCClient;
import com.google.gson.Gson;
import com.sun.net.httpserver.Headers;
......@@ -10,6 +11,7 @@ import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.*;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
......@@ -22,6 +24,7 @@ public class WebServer
{
private final String Search_EndPoint = "/search";
private GRPCClient grpcClient;
private AddressProxy addressProxy;
private static final Logger logger = LoggerFactory.getLogger(WebServer.class);
private final int port;
private HttpServer server;
......@@ -30,6 +33,7 @@ public class WebServer
{
this.port = port;
grpcClient = new GRPCClient();
addressProxy = AddressProxy.start();
}
public static void main(String[] args) throws IOException, InterruptedException {
int serverPort = 5566;
......@@ -78,7 +82,8 @@ public class WebServer
List<String> files = new ArrayList<>();
try
{
files = grpcClient.search(query);
String o = addressProxy.getAddress();
files = grpcClient.search(query , o);
}
catch (InterruptedException | KeeperException e)
{
......
......@@ -19,7 +19,6 @@ import java.util.stream.Stream;
public class Coordinator
{
private static String ipAdress;
private static String FILES_DIRECTORY = System.getProperty("user.dir") + "/SearchFiles/";;
private static final Logger logger = LoggerFactory.getLogger(Coordinator.class);
......@@ -43,12 +42,6 @@ public class Coordinator
return answer;
}
public static String getIP()
{
ipAdress = ServiceRegistry.getCoordinatorAddress();
return ipAdress;
}
private static SearchQueryResponse sendRequestToNode(SearchQueryRequest searchQueryRequest, String ipAddress)
{
SearchQueryResponse searchQueryResponse = null;
......
......@@ -19,12 +19,10 @@ public class ServiceRegistry implements Watcher
private static final String COORDINATOR_ZNODE_PATH = "/coordinator_node";
private final Logger logger = LoggerFactory.getLogger(ServiceRegistry.class);
private final ZooKeeper zooKeeper;
private Coordinator coordinator = null;
private TransientWorker transientWorker = null;
private String currentZnode = null;
private static List<String> allServiceAddresses = null;
private static String Coordinator_Address;
public ServiceRegistry(ZooKeeper zooKeeper)
{
......@@ -72,16 +70,10 @@ public class ServiceRegistry implements Watcher
this.currentZnode = zooKeeper.create(COORDINATOR_ZNODE_PATH + "/coordinator_", metadata.getBytes(),
ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
logger.info("Registered to be Coordinator and I am Master !");
Coordinator_Address = metadata.split(":")[0];
GRPCServiceStart.start();
/*Thread thread = new Thread(()-> new Runnable() {
@Override
public void run() {
//Coordinator coordinator = new Coordinator();
GRPCServiceStart.start();
}
});
thread.start();*/
}
public void registerForUpdates() {
try
{
......@@ -141,10 +133,7 @@ public class ServiceRegistry implements Watcher
{
return allServiceAddresses;
}
public static String getCoordinatorAddress()
{
return Coordinator_Address;
}
@Override
public void process(WatchedEvent watchedEvent)
......
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