From 1ea03343f7fa6e765d202d959c166836860ce7a4 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Wed, 8 Jul 2020 23:52:51 +0200 Subject: [PATCH] WIP: minimal grpc example --- pom.xml | 681 ++++++++++-------- src/main/java/caosdb/server/CaosDBServer.java | 87 +-- src/main/java/caosdb/server/GRPCServer.java | 14 + .../server/grpc/EntityTransactionImpl.java | 19 + src/main/proto/EntityService.proto | 13 + 5 files changed, 452 insertions(+), 362 deletions(-) create mode 100644 src/main/java/caosdb/server/GRPCServer.java create mode 100644 src/main/java/caosdb/server/grpc/EntityTransactionImpl.java create mode 100644 src/main/proto/EntityService.proto diff --git a/pom.xml b/pom.xml index c8f79b3d..00e5919b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,321 +1,364 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- - * ** header v3.0 - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2018 Research Group Biomedical Physics, - * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header ---> -<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>bmp.ds.mpg.de</groupId> - <artifactId>caosdb-server</artifactId> - <version>0.1-SNAPSHOT</version> - <packaging>jar</packaging> - <name>CaosDB Server</name> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.build.testSourceDirectory>src/test/java</project.build.testSourceDirectory> - </properties> - <repositories> - <repository> - <id>maven-central</id> - <url>http://central.maven.org/maven2/</url> - <name>Maven Central</name> - </repository> - <repository> - <id>maven-restlet</id> - <name>Public online Restlet repository</name> - <url>http://maven.restlet.com</url> - </repository> - <repository> - <id>local-maven-repo</id> - <url>file:///${project.basedir}/.m2-local</url> - </repository> - </repositories> - <dependencies> - <dependency> - <groupId>de.timmfitschen</groupId> - <artifactId>easy-units</artifactId> - <version>0.0.1-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.shiro</groupId> - <artifactId>shiro-core</artifactId> - <version>1.4.1</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.12</version> - <scope>test</scope> - </dependency> - <dependency> - <!-- preventing parallel execution of some test classes --> - <groupId>com.github.stephenc.jcip</groupId> - <artifactId>jcip-annotations</artifactId> - <version>1.0-1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.jdom</groupId> - <artifactId>jdom2</artifactId> - <version>2.0.6</version> - </dependency> - <dependency> - <groupId>org.restlet.jse</groupId> - <artifactId>org.restlet</artifactId> - <version>2.3.12</version> - </dependency> - <dependency> - <groupId>org.restlet.jse</groupId> - <artifactId>org.restlet.ext.fileupload</artifactId> - <version>2.3.12</version> - </dependency> - <dependency> - <groupId>mysql</groupId> - <artifactId>mysql-connector-java</artifactId> - <version>6.0.6</version> - </dependency> - <dependency> - <groupId>org.xerial</groupId> - <artifactId>sqlite-jdbc</artifactId> - <version>3.16.1</version> - </dependency> - <dependency> - <groupId>net.snaq</groupId> - <artifactId>dbpool</artifactId> - <version>7.0.1</version> - </dependency> - <dependency> - <groupId>org.reflections</groupId> - <artifactId>reflections</artifactId> - <version>0.9.11</version> - </dependency> - <dependency> - <groupId>com.googlecode.lanterna</groupId> - <artifactId>lanterna</artifactId> - <version>2.1.9</version> - </dependency> - <dependency> - <groupId>org.antlr</groupId> - <artifactId>antlr4</artifactId> - <version>4.8-1</version> - </dependency> - <dependency> - <groupId>org.restlet.jse</groupId> - <artifactId>org.restlet.ext.jetty</artifactId> - <version>2.3.12</version> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-math</artifactId> - <version>2.2</version> - </dependency> - <dependency> - <groupId>commons-codec</groupId> - <artifactId>commons-codec</artifactId> - <version>1.12</version> - </dependency> - <dependency> - <groupId>com.sun.mail</groupId> - <artifactId>javax.mail</artifactId> - <version>1.6.0-rc1</version> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-jcs-core</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.kohsuke</groupId> - <artifactId>libpam4j</artifactId> - <version>1.8</version> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-util-ajax</artifactId> - <version>9.2.14.v20151106</version> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j-impl</artifactId> - <version>2.11.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.7.21</version> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-api</artifactId> - <version>2.11.1</version> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-core</artifactId> - <version>2.11.1</version> - </dependency> - </dependencies> - <build> - <sourceDirectory>${basedir}/src/main/java</sourceDirectory> - <scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory> - <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory> - <outputDirectory>${basedir}/target/classes</outputDirectory> - <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>2.4.3</version> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <finalName>${project.artifactId}-${project.version}-jar-with-dependencies</finalName> - <transformers> - <transformer implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer"></transformer> - <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> - <mainClass>caosdb.server.CaosDBServer</mainClass> - </transformer> - </transformers> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>com.github.edwgiz</groupId> - <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId> - <version>2.8.1</version> - </dependency> - </dependencies> - </plugin> - <plugin> - <groupId>org.antlr</groupId> - <artifactId>antlr4-maven-plugin</artifactId> - <version>4.8-1</version> - <configuration> - <sourceDirectory>${basedir}/src/main/java</sourceDirectory> - </configuration> - <executions> - <execution> - <goals> - <goal>antlr4</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.8.1</version> - <configuration> - <source>11</source> - <target>11</target> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>3.0.0-M3</version> - <configuration> - <includes> - <include>**/*.java</include> - </includes> - <systemPropertyVariables> - <caosdb.debug>true</caosdb.debug> - <log4j2.debug>true</log4j2.debug> - </systemPropertyVariables> - <reuseForks>false</reuseForks> - <!-- Start 0.5 JVMs per CPU core - Higher numbers *seem* to lead to higher failure rates... :-/ --> - <forkCount>0.5C</forkCount> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>1.6.0</version> - <executions> - <execution> - <id>run</id> - <goals> - <goal>java</goal> - </goals> - <configuration> - <mainClass>caosdb.server.CaosDBServer</mainClass> - <arguments> - <argument>silent</argument> - </arguments> - </configuration> - </execution> - <execution> - <id>run-debug</id> - <goals> - <goal>java</goal> - </goals> - <configuration> - <mainClass>caosdb.server.CaosDBServer</mainClass> - <arguments> - <argument>silent</argument> - </arguments> - <systemProperties> - <systemProperty> - <key>caosdb.debug</key> - <value>true</value> - </systemProperty> - </systemProperties> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>com.coveo</groupId> - <artifactId>fmt-maven-plugin</artifactId> - <version>2.5.1</version> - <configuration> - <skip> - <!-- Set skip to `true` to prevent auto-formatting while coding. --> - false - </skip> - </configuration> - <executions> - <execution> - <goals> - <goal>format</goal> - </goals> - </execution> - </executions> - </plugin> - <!-- Remove easy-units from classpath generation because of https://github.com/jdee-emacs/jdee/issues/125 - (no sources inside easy-units) --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <configuration> - <excludeArtifactIds>easy-units</excludeArtifactIds> - </configuration> - </plugin> - </plugins> - </build> - <url>bmp.ds.mpg.de</url> +<!-- * ** header v3.0 * This file is a part of the CaosDB Project. * * Copyright + (C) 2018 Research Group Biomedical Physics, * Max-Planck-Institute for Dynamics + and Self-Organization Göttingen * * This program is free software: you can + redistribute it and/or modify * it under the terms of the GNU Affero General + Public License as * published by the Free Software Foundation, either version + 3 of the * License, or (at your option) any later version. * * This program + is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; + without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the * GNU Affero General Public License for more details. * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. * + * ** end header --> +<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>bmp.ds.mpg.de</groupId> + <artifactId>caosdb-server</artifactId> + <version>0.1-SNAPSHOT</version> + <packaging>jar</packaging> + <name>CaosDB Server</name> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.build.testSourceDirectory>src/test/java</project.build.testSourceDirectory> + <protobuf.version>3.12.3</protobuf.version> + <grpc.version>1.30.2</grpc.version> + </properties> + <repositories> + <repository> + <id>maven-central</id> + <url>http://central.maven.org/maven2/</url> + <name>Maven Central</name> + </repository> + <repository> + <id>maven-restlet</id> + <name>Public online Restlet repository</name> + <url>http://maven.restlet.com</url> + </repository> + <repository> + <id>local-maven-repo</id> + <url>file:///${project.basedir}/.m2-local</url> + </repository> + </repositories> + <dependencies> + <dependency> + <groupId>de.timmfitschen</groupId> + <artifactId>easy-units</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.shiro</groupId> + <artifactId>shiro-core</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + <dependency> + <!-- preventing parallel execution of some test classes --> + <groupId>com.github.stephenc.jcip</groupId> + <artifactId>jcip-annotations</artifactId> + <version>1.0-1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jdom</groupId> + <artifactId>jdom2</artifactId> + <version>2.0.6</version> + </dependency> + <dependency> + <groupId>org.restlet.jse</groupId> + <artifactId>org.restlet</artifactId> + <version>2.3.12</version> + </dependency> + <dependency> + <groupId>org.restlet.jse</groupId> + <artifactId>org.restlet.ext.fileupload</artifactId> + <version>2.3.12</version> + </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>6.0.6</version> + </dependency> + <dependency> + <groupId>org.xerial</groupId> + <artifactId>sqlite-jdbc</artifactId> + <version>3.16.1</version> + </dependency> + <dependency> + <groupId>net.snaq</groupId> + <artifactId>dbpool</artifactId> + <version>7.0.1</version> + </dependency> + <dependency> + <groupId>org.reflections</groupId> + <artifactId>reflections</artifactId> + <version>0.9.11</version> + </dependency> + <dependency> + <groupId>com.googlecode.lanterna</groupId> + <artifactId>lanterna</artifactId> + <version>2.1.9</version> + </dependency> + <dependency> + <groupId>org.antlr</groupId> + <artifactId>antlr4</artifactId> + <version>4.8-1</version> + </dependency> + <dependency> + <groupId>org.restlet.jse</groupId> + <artifactId>org.restlet.ext.jetty</artifactId> + <version>2.3.12</version> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-math</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + <version>1.12</version> + </dependency> + <dependency> + <groupId>com.sun.mail</groupId> + <artifactId>javax.mail</artifactId> + <version>1.6.0-rc1</version> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-jcs-core</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.kohsuke</groupId> + <artifactId>libpam4j</artifactId> + <version>1.8</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-util-ajax</artifactId> + <version>9.2.14.v20151106</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <version>2.11.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.7.21</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <version>2.11.1</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.11.1</version> + </dependency> + <dependency> + <groupId>io.grpc</groupId> + <artifactId>grpc-netty</artifactId> + <version>${grpc.version}</version> + </dependency> + <dependency> + <groupId>io.grpc</groupId> + <artifactId>grpc-protobuf</artifactId> + <version>${grpc.version}</version> + </dependency> + <dependency> + <groupId>io.grpc</groupId> + <artifactId>grpc-stub</artifactId> + <version>${grpc.version}</version> + </dependency> + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + <version>1.3.2</version> + </dependency> + </dependencies> + <build> + <extensions> + <extension> + <groupId>kr.motd.maven</groupId> + <artifactId>os-maven-plugin</artifactId> + <version>1.6.2</version> + </extension> + </extensions> + <sourceDirectory>${basedir}/src/main/java</sourceDirectory> + <scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory> + <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory> + <outputDirectory>${basedir}/target/classes</outputDirectory> + <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>2.4.3</version> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <finalName>${project.artifactId}-${project.version}-jar-with-dependencies</finalName> + <transformers> + <transformer + implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer"></transformer> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <mainClass>caosdb.server.CaosDBServer</mainClass> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>com.github.edwgiz</groupId> + <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId> + <version>2.8.1</version> + </dependency> + </dependencies> + </plugin> + <plugin> + <groupId>org.antlr</groupId> + <artifactId>antlr4-maven-plugin</artifactId> + <version>4.8-1</version> + <configuration> + <sourceDirectory>${basedir}/src/main/java</sourceDirectory> + </configuration> + <executions> + <execution> + <goals> + <goal>antlr4</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>3.0.0-M3</version> + <configuration> + <includes> + <include>**/*.java</include> + </includes> + <systemPropertyVariables> + <caosdb.debug>true</caosdb.debug> + <log4j2.debug>true</log4j2.debug> + </systemPropertyVariables> + <reuseForks>false</reuseForks> + <!-- Start 0.5 JVMs per CPU core Higher numbers *seem* to lead to higher + failure rates... :-/ --> + <forkCount>0.5C</forkCount> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>1.6.0</version> + <executions> + <execution> + <id>run</id> + <goals> + <goal>java</goal> + </goals> + <configuration> + <mainClass>caosdb.server.CaosDBServer</mainClass> + <arguments> + <argument>silent</argument> + </arguments> + </configuration> + </execution> + <execution> + <id>run-debug</id> + <goals> + <goal>java</goal> + </goals> + <configuration> + <mainClass>caosdb.server.CaosDBServer</mainClass> + <arguments> + <argument>silent</argument> + </arguments> + <systemProperties> + <systemProperty> + <key>caosdb.debug</key> + <value>true</value> + </systemProperty> + </systemProperties> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>com.coveo</groupId> + <artifactId>fmt-maven-plugin</artifactId> + <version>2.5.1</version> + <configuration> + <skip> + <!-- Set skip to `true` to prevent auto-formatting while coding. --> + false + </skip> + </configuration> + <executions> + <execution> + <goals> + <goal>format</goal> + </goals> + </execution> + </executions> + </plugin> + <!-- Remove easy-units from classpath generation because of https://github.com/jdee-emacs/jdee/issues/125 + (no sources inside easy-units) --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <configuration> + <excludeArtifactIds>easy-units</excludeArtifactIds> + </configuration> + </plugin> + <plugin> + <groupId>org.xolstice.maven.plugins</groupId> + <artifactId>protobuf-maven-plugin</artifactId> + <version>0.6.1</version> + <configuration> + <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact> + <pluginId>grpc-java</pluginId> + <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact> + </configuration> + <executions> + <execution> + <goals> + <goal>compile</goal> + <goal>compile-custom</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + + </build> + <url>bmp.ds.mpg.de</url> </project> diff --git a/src/main/java/caosdb/server/CaosDBServer.java b/src/main/java/caosdb/server/CaosDBServer.java index 34bfe3e2..2beabb78 100644 --- a/src/main/java/caosdb/server/CaosDBServer.java +++ b/src/main/java/caosdb/server/CaosDBServer.java @@ -19,6 +19,49 @@ */ package caosdb.server; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Properties; +import java.util.TimeZone; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.config.Ini; +import org.apache.shiro.config.Ini.Section; +import org.apache.shiro.config.IniSecurityManagerFactory; +import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.subject.Subject; +import org.apache.shiro.util.Factory; +import org.apache.shiro.util.ThreadContext; +import org.restlet.Application; +import org.restlet.Component; +import org.restlet.Context; +import org.restlet.Request; +import org.restlet.Response; +import org.restlet.Restlet; +import org.restlet.Server; +import org.restlet.data.CookieSetting; +import org.restlet.data.Parameter; +import org.restlet.data.Protocol; +import org.restlet.data.Reference; +import org.restlet.data.ServerInfo; +import org.restlet.data.Status; +import org.restlet.engine.Engine; +import org.restlet.routing.Route; +import org.restlet.routing.Router; +import org.restlet.routing.Template; +import org.restlet.routing.TemplateRoute; +import org.restlet.routing.Variable; +import org.restlet.util.Series; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import caosdb.server.accessControl.AnonymousRealm; import caosdb.server.accessControl.AuthenticationUtils; import caosdb.server.accessControl.CaosDBAuthorizingRealm; @@ -64,49 +107,6 @@ import caosdb.server.utils.FileUtils; import caosdb.server.utils.Initialization; import caosdb.server.utils.NullPrintStream; import caosdb.server.utils.Utils; -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.time.ZoneId; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Properties; -import java.util.TimeZone; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.config.Ini; -import org.apache.shiro.config.Ini.Section; -import org.apache.shiro.config.IniSecurityManagerFactory; -import org.apache.shiro.mgt.SecurityManager; -import org.apache.shiro.subject.Subject; -import org.apache.shiro.util.Factory; -import org.apache.shiro.util.ThreadContext; -import org.restlet.Application; -import org.restlet.Component; -import org.restlet.Context; -import org.restlet.Request; -import org.restlet.Response; -import org.restlet.Restlet; -import org.restlet.Server; -import org.restlet.data.CookieSetting; -import org.restlet.data.Parameter; -import org.restlet.data.Protocol; -import org.restlet.data.Reference; -import org.restlet.data.ServerInfo; -import org.restlet.data.Status; -import org.restlet.engine.Engine; -import org.restlet.routing.Route; -import org.restlet.routing.Router; -import org.restlet.routing.Template; -import org.restlet.routing.TemplateRoute; -import org.restlet.routing.Variable; -import org.restlet.util.Series; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class CaosDBServer extends Application { @@ -344,6 +344,7 @@ public class CaosDBServer extends Application { init.release(); + GRPCServer.startServer(8080); if (INSECURE) { runHTTPServer(port_http, initialConnections, maxTotalConnections); } else { diff --git a/src/main/java/caosdb/server/GRPCServer.java b/src/main/java/caosdb/server/GRPCServer.java new file mode 100644 index 00000000..55050592 --- /dev/null +++ b/src/main/java/caosdb/server/GRPCServer.java @@ -0,0 +1,14 @@ +package caosdb.server; + +import java.io.IOException; +import caosdb.server.grpc.EntityTransactionImpl; +import io.grpc.Server; +import io.grpc.ServerBuilder; + +public class GRPCServer { + + public static void startServer(int port) throws IOException, InterruptedException { + Server server = ServerBuilder.forPort(port).addService(new EntityTransactionImpl()).build(); + server.start(); + } +} diff --git a/src/main/java/caosdb/server/grpc/EntityTransactionImpl.java b/src/main/java/caosdb/server/grpc/EntityTransactionImpl.java new file mode 100644 index 00000000..70f5b0c5 --- /dev/null +++ b/src/main/java/caosdb/server/grpc/EntityTransactionImpl.java @@ -0,0 +1,19 @@ +package caosdb.server.grpc; + +import caosdb.grpc.Entity; +import caosdb.grpc.EntityTransactionServiceGrpc.EntityTransactionServiceImplBase; +import io.grpc.stub.StreamObserver; + +public class EntityTransactionImpl extends EntityTransactionServiceImplBase { + + @Override + public void retrieve(Entity request, StreamObserver<Entity> responseObserver) { + Entity response = Entity.newBuilder(request) + .setName("EntityName") + .setDescription("EntityDescription") + .build(); + + responseObserver.onNext(response); + responseObserver.onCompleted(); + } +} diff --git a/src/main/proto/EntityService.proto b/src/main/proto/EntityService.proto new file mode 100644 index 00000000..259fae6b --- /dev/null +++ b/src/main/proto/EntityService.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +option java_multiple_files = true; +package caosdb.grpc; + +message Entity { + string eid = 1; + string name = 2; + string description = 3; +} + +service EntityTransactionService { + rpc retrieve(Entity) returns (Entity); +} -- GitLab