Commit 64b85b83 authored by Ali Saeed's avatar Ali Saeed

final project

parent 35652575
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="Proxy" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17 (2)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
2024-02-01 09:27:13,553 INFO Proxy.SearchServlet [http-nio-8081-exec-2] New search request for: ali zein ahmad
2024-02-01 09:27:23,052 DEBUG Proxy.SearchProxy [http-nio-8081-exec-2-EventThread] Successfully connected to Zookeeper
2024-02-01 09:27:26,254 INFO Proxy.SearchProxy [http-nio-8081-exec-2] Results is:
2024-02-01 09:27:26,258 INFO Proxy.SearchProxy [http-nio-8081-exec-2] Document name: Text.txt , Score: 0.0764850866344497
2024-02-01 09:27:26,259 INFO Proxy.SearchProxy [http-nio-8081-exec-2] Document name: Text1.txt , Score: 0.036819081438915165
2024-02-01 09:27:26,260 INFO Proxy.SearchProxy [http-nio-8081-exec-2] Document name: Text2.txt , Score: 0.05055251456143959
2024-02-01 09:27:37,019 INFO Proxy.SearchServlet [http-nio-8081-exec-4] New search request for: ali zein ahmad while process run
2024-02-01 09:27:46,498 DEBUG Proxy.SearchProxy [http-nio-8081-exec-4-EventThread] Successfully connected to Zookeeper
2024-02-01 09:27:47,164 INFO Proxy.SearchProxy [http-nio-8081-exec-4] Results is:
2024-02-01 09:27:47,165 INFO Proxy.SearchProxy [http-nio-8081-exec-4] Document name: Text.txt , Score: 0.08992716747839483
2024-02-01 09:27:47,165 INFO Proxy.SearchProxy [http-nio-8081-exec-4] Document name: Text1.txt , Score: 0.05122654808892545
2024-02-01 09:27:47,166 INFO Proxy.SearchProxy [http-nio-8081-exec-4] Document name: Text2.txt , Score: 0.05055251456143959
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.anubhav</groupId>
<artifactId>grpc</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<lognet.grpc.version>4.7.1</lognet.grpc.version>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.10</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.10</version>
</dependency>
<dependency>
<groupId>io.github.lognet</groupId>
<artifactId>grpc-spring-boot-starter</artifactId>
<version>${lognet.grpc.version}</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>10.1.15</version>
</dependency>
<dependency>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
<version>0.0.20131108.vaadin1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.17.3:exe:windows-x86_64</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.41.0:exe:windows-x86_64</pluginArtifact>
<protoSourceRoot>src/main/proto</protoSourceRoot>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>TomcatServer</server>
<path>/searchServlet</path>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>SearchServlet</servlet-name>
<servlet-class>Proxy.SearchServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SearchServlet</servlet-name>
<url-pattern>/searchServlet</url-pattern>
</servlet-mapping>
</web-app>
\ No newline at end of file
package Proxy;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
public class SearchProxy implements Watcher{
private static final Logger logger = LoggerFactory.getLogger(SearchProxy.class);
private static final String address = "192.168.181.136:2181";
private static final String coordinatorAddress = "";
private static final String COORDINATOR_ZNODE = "/cordinator";
private static final int SESSION_TIMEOUT = 3000; //dead client
private static final int DEFAULT_PORT = 8080;
private static String CURRENT_COORDINATOR = "";
private static String CURRENT_COORDINATOR_FULL_PATH = "";
private ZooKeeper zooKeeper;
public String getCurrentCoordinator() {
return CURRENT_COORDINATOR;
}
public void setCurrentCoordinator(String currentCoordinator) {
CURRENT_COORDINATOR = currentCoordinator;
}
public static String getCurrentCoordinatorFullPath() {
return CURRENT_COORDINATOR_FULL_PATH;
}
public static void setCurrentCoordinatorFullPath(String currentCoordinatorFullPath) {
CURRENT_COORDINATOR_FULL_PATH = currentCoordinatorFullPath;
}
public ZooKeeper getZooKeeper() {
return zooKeeper;
}
public void setZooKeeper(ZooKeeper zooKeeper) {
this.zooKeeper = zooKeeper;
}
public Map<String,Double> searchOnCoordinator(String searchQuery) throws InterruptedException, IOException {
ManagedChannel channel = ManagedChannelBuilder.forAddress(CURRENT_COORDINATOR, 6565).usePlaintext().build();
SearchServiceGrpc.SearchServiceBlockingStub searchServiceBlockingStub = SearchServiceGrpc.newBlockingStub(channel);
SearchResponse searchResponse = searchServiceBlockingStub.search(Proxy.SearchRequest.newBuilder().setQuery(searchQuery).build());
Proxy.SearchResult searchResult = searchResponse.getSearchResult();
Map<String,Double> response = searchResult.getResultsMap();
if(response.isEmpty() || response == null){
logger.warn("No results, maybe cluster does not have workers !!");
response = null;
}
else {
logger.info("Results is:");
for (Map.Entry<String, Double> entry : response.entrySet())
{
String documentName = entry.getKey();
Double score = entry.getValue();
logger.info("Document name: "+ documentName+ " , Score: "+score);
}
}
return response;
}
public ZooKeeper connectToZookeeper() throws IOException {
this.zooKeeper = new ZooKeeper(address, SESSION_TIMEOUT, this);
return zooKeeper;
}
public void run() throws InterruptedException {
synchronized (zooKeeper) {
zooKeeper.wait();
}
}
public void close() throws InterruptedException {
this.zooKeeper.close();
}
@Override
public void process(WatchedEvent watchedEvent) {
switch (watchedEvent.getType()) {
case None:
if (watchedEvent.getState() == Watcher.Event.KeeperState.SyncConnected) {
logger.debug("Successfully connected to Zookeeper");
} else if (watchedEvent.getState() == Watcher.Event.KeeperState.Disconnected) {
synchronized (zooKeeper) {
logger.debug("Disconnected from Zookeeper");
zooKeeper.notifyAll();
}
} else if (watchedEvent.getState() == Watcher.Event.KeeperState.Closed) {
logger.debug("Closed Successfully");
}
break;
case NodeDeleted:
System.out.println("change");
if(watchedEvent.getPath().equals(CURRENT_COORDINATOR_FULL_PATH)){
getCoordinatorAddress();
}
break;
}
}
public void getCoordinatorAddress(){
try {
Thread.sleep(10000);
List<String> children = zooKeeper.getChildren(COORDINATOR_ZNODE, false);
if(children.size() == 1){
String coordinatorZnode = children.get(0);
CURRENT_COORDINATOR_FULL_PATH = COORDINATOR_ZNODE + "/" + coordinatorZnode;
Stat stat = zooKeeper.exists(CURRENT_COORDINATOR_FULL_PATH, this);
if (stat == null) {
System.out.println("Coordinator not found !");
logger.warn("Coordinator not found !");
}else {
byte[] addressBytes = zooKeeper.getData(CURRENT_COORDINATOR_FULL_PATH, false, stat);
String address = new String(addressBytes);
CURRENT_COORDINATOR = address;
System.out.println("full path: "+ CURRENT_COORDINATOR_FULL_PATH+" , address: "+ CURRENT_COORDINATOR);
}
} else if (children.size() > 1) {
System.out.println("there are more than coordinator !!");
logger.warn("there are more than coordinator !!");
}else {
System.out.println("coordinator not available !!");
logger.warn("coordinator not available !!");
}
} catch (KeeperException e) {
throw new RuntimeException("Coordinator is down !!! ");
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
\ No newline at end of file
package Proxy;
import Proxy.SearchProxy;
import com.google.gson.Gson;
import org.apache.zookeeper.ZooKeeper;
import org.json.JSONException;
import org.json.JSONObject;
import Proxy.SearchProxy;
import com.google.gson.Gson;
import org.apache.zookeeper.ZooKeeper;
import org.json.JSONException;
import org.json.JSONObject;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
public class SearchServlet extends HttpServlet {
private SearchProxy searchProxy = new SearchProxy();
private static final Logger logger = LoggerFactory.getLogger(SearchServlet.class);
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Read the JSON data from the request
StringBuilder jsonStringBuilder = new StringBuilder();
String line;
BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null) {
jsonStringBuilder.append(line);
}
String jsonString = jsonStringBuilder.toString();
// Parse the JSON data
String searchQuery = ""; // Default value
try {
JSONObject jsonObject = new JSONObject(jsonString);
searchQuery = jsonObject.getString("query");
logger.info("New search request for: "+searchQuery);
} catch (JSONException e) {
e.printStackTrace();
}
// Perform your logic to generate the response
Map<String, Double> searchResults = null;
try {
searchResults = performSearch(searchQuery);
if(searchResults.isEmpty() || searchResults == null){
logger.info("no results, maybe does not exist workers !!");
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// Convert the search results to a JSON string
String jsonResponse = new Gson().toJson(searchResults);
// Set CORS headers
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
response.setHeader("Access-Control-Allow-Headers", "Content-Type");
// Send the JSON response back to the client
response.setContentType("application/json");
response.getWriter().write(jsonResponse);
}
private Map<String, Double> performSearch(String query) throws IOException, InterruptedException {
Map<String,Double> response = new HashMap<>();
ZooKeeper zooKeeper = searchProxy.connectToZookeeper();
searchProxy.setZooKeeper(zooKeeper);
searchProxy.getCoordinatorAddress();
if(!searchProxy.getCurrentCoordinator().isEmpty() && !searchProxy.getCurrentCoordinator().equals("")){
response = searchProxy.searchOnCoordinator(query);
}
return response;
}
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
response.setHeader("Access-Control-Allow-Headers", "Content-Type");
response.setStatus(HttpServletResponse.SC_OK);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Forward the request to the index.html file
RequestDispatcher dispatcher = request.getRequestDispatcher("wepapp/index.html");
dispatcher.forward(request, response);
}
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Welcome to My Application</title>
</head>
<body>
<h1>Welcome to My Application</h1>
<p>This is the default page of my application.</p>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to My Web Application</title>
</head>
<body>
<h1>Welcome!</h1>
<p>This is the homepage of my web application.</p>
</body>
</html>
\ No newline at end of file
syntax = "proto3";
option java_multiple_files = true;
option java_package = "Proxy";
message SearchResult {
map<string, double> results = 1;
}
message SearchRequest {
string query = 1;
}
message SearchResponse {
SearchResult searchResult = 1;
}
service SearchService {
rpc Search(SearchRequest) returns (SearchResponse);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="HOME_LOG" value="D:\\DS_Project\\Proxy\\logs\\proxy.log"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${HOME_LOG}</file>
<append>true</append>
<immediateFlush>true</immediateFlush>
<encoder>
<pattern>%d %p %c{1.} [%t] %m%n</pattern>
</encoder>
</appender>
<logger name="Proxy" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
<root level="error">
<appender-ref ref="FILE"/>
</root>
</configuration>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to My Application</title>
</head>
<body>
<h1>Welcome to My Application</h1>
<p>This is the default page of my application.</p>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to My Web Application</title>
</head>
<body>
<h1>Welcome!</h1>
<p>This is the homepage of my web application.</p>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="HOME_LOG" value="D:\\DS_Project\\Proxy\\logs\\proxy.log"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${HOME_LOG}</file>
<append>true</append>
<immediateFlush>true</immediateFlush>
<encoder>
<pattern>%d %p %c{1.} [%t] %m%n</pattern>
</encoder>
</appender>
<logger name="Proxy" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
<root level="error">
<appender-ref ref="FILE"/>
</root>
</configuration>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: search.proto
package Proxy;
public final class Search {
private Search() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
static final com.google.protobuf.Descriptors.Descriptor
internal_static_SearchResult_descriptor;
static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SearchResult_fieldAccessorTable;
static final com.google.protobuf.Descriptors.Descriptor
internal_static_SearchResult_ResultsEntry_descriptor;
static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SearchResult_ResultsEntry_fieldAccessorTable;
static final com.google.protobuf.Descriptors.Descriptor
internal_static_SearchRequest_descriptor;
static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SearchRequest_fieldAccessorTable;
static final com.google.protobuf.Descriptors.Descriptor
internal_static_SearchResponse_descriptor;
static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SearchResponse_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n\014search.proto\"k\n\014SearchResult\022+\n\007result" +
"s\030\001 \003(\0132\032.SearchResult.ResultsEntry\032.\n\014R" +
"esultsEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\001:" +
"\0028\001\"\036\n\rSearchRequest\022\r\n\005query\030\001 \001(\t\"5\n\016S" +
"earchResponse\022#\n\014searchResult\030\001 \001(\0132\r.Se" +
"archResult2:\n\rSearchService\022)\n\006Search\022\016." +
"SearchRequest\032\017.SearchResponseB\t\n\005ProxyP" +
"\001b\006proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SearchResult_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SearchResult_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SearchResult_descriptor,
new java.lang.String[] { "Results", });
internal_static_SearchResult_ResultsEntry_descriptor =
internal_static_SearchResult_descriptor.getNestedTypes().get(0);
internal_static_SearchResult_ResultsEntry_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SearchResult_ResultsEntry_descriptor,
new java.lang.String[] { "Key", "Value", });
internal_static_SearchRequest_descriptor =
getDescriptor().getMessageTypes().get(1);
internal_static_SearchRequest_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SearchRequest_descriptor,
new java.lang.String[] { "Query", });
internal_static_SearchResponse_descriptor =
getDescriptor().getMessageTypes().get(2);
internal_static_SearchResponse_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SearchResponse_descriptor,
new java.lang.String[] { "SearchResult", });
}
// @@protoc_insertion_point(outer_class_scope)
}
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: search.proto
package Proxy;
public interface SearchRequestOrBuilder extends
// @@protoc_insertion_point(interface_extends:SearchRequest)
com.google.protobuf.MessageOrBuilder {
/**
* <code>string query = 1;</code>
* @return The query.
*/
java.lang.String getQuery();
/**
* <code>string query = 1;</code>
* @return The bytes for query.
*/
com.google.protobuf.ByteString
getQueryBytes();
}
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: search.proto
package Proxy;
public interface SearchResponseOrBuilder extends
// @@protoc_insertion_point(interface_extends:SearchResponse)
com.google.protobuf.MessageOrBuilder {
/**
* <code>.SearchResult searchResult = 1;</code>
* @return Whether the searchResult field is set.
*/
boolean hasSearchResult();
/**
* <code>.SearchResult searchResult = 1;</code>
* @return The searchResult.
*/
Proxy.SearchResult getSearchResult();
/**
* <code>.SearchResult searchResult = 1;</code>
*/
Proxy.SearchResultOrBuilder getSearchResultOrBuilder();
}
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: search.proto
package Proxy;
public interface SearchResultOrBuilder extends
// @@protoc_insertion_point(interface_extends:SearchResult)
com.google.protobuf.MessageOrBuilder {
/**
* <code>map&lt;string, double&gt; results = 1;</code>
*/
int getResultsCount();
/**
* <code>map&lt;string, double&gt; results = 1;</code>
*/
boolean containsResults(
java.lang.String key);
/**
* Use {@link #getResultsMap()} instead.
*/
@java.lang.Deprecated
java.util.Map<java.lang.String, java.lang.Double>
getResults();
/**
* <code>map&lt;string, double&gt; results = 1;</code>
*/
java.util.Map<java.lang.String, java.lang.Double>
getResultsMap();
/**
* <code>map&lt;string, double&gt; results = 1;</code>
*/
double getResultsOrDefault(
java.lang.String key,
double defaultValue);
/**
* <code>map&lt;string, double&gt; results = 1;</code>
*/
double getResultsOrThrow(
java.lang.String key);
}
syntax = "proto3";
option java_multiple_files = true;
option java_package = "Proxy";
message SearchResult {
map<string, double> results = 1;
}
message SearchRequest {
string query = 1;
}
message SearchResponse {
SearchResult searchResult = 1;
}
service SearchService {
rpc Search(SearchRequest) returns (SearchResponse);
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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