diff options
author | subhash kumar singh <subhash.kumar.singh@huawei.com> | 2018-09-05 07:24:38 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-05 07:24:38 +0000 |
commit | f040ecf089eac94a4efc90316175ccc0529bbfd2 (patch) | |
tree | 32dcd3bc996f6cdb5cda18752c360d79a1e26efb /grpc | |
parent | 5a295e30a8cbd0b39144328e23f6b1be37e526c3 (diff) | |
parent | d6230a718e176f02bc91314a0cd96a49820498fb (diff) |
Merge changes Ic75c7eca,Ic0b547f7,I932b1ceb,I26c99032,Ifaeeb8f4, ...
* changes:
OCLIP: Change the order of classpath
OCLIP: Fix the correct type of OCS command
VTP: Add schema-list command
OCLIP: Fix OCLIP registrar to log register events
OCLIP: Fix json print format
VTP: Enable grpc part of deployment
VTP: grpc client impl
VTP: grpc server impl
VTP: grpc stub model
VTP: grpc client
VTP: grpc server
VTP: grpc stub
VTP: Add grpc
Diffstat (limited to 'grpc')
-rw-r--r-- | grpc/grpc-client/pom.xml | 53 | ||||
-rw-r--r-- | grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java | 83 | ||||
-rw-r--r-- | grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenRemoteCli.java | 86 | ||||
-rw-r--r-- | grpc/grpc-client/src/main/resources/log4j.properties | 32 | ||||
-rw-r--r-- | grpc/grpc-server/pom.xml | 58 | ||||
-rw-r--r-- | grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java | 156 | ||||
-rw-r--r-- | grpc/grpc-server/src/main/resources/log4j.properties | 32 | ||||
-rw-r--r-- | grpc/grpc-server/src/main/resources/oclip-grpc-server.properties | 15 | ||||
-rw-r--r-- | grpc/grpc-stub/pom.xml | 34 | ||||
-rw-r--r-- | grpc/grpc-stub/src/main/proto/oclip.proto | 53 | ||||
-rw-r--r-- | grpc/pom.xml | 169 |
11 files changed, 771 insertions, 0 deletions
diff --git a/grpc/grpc-client/pom.xml b/grpc/grpc-client/pom.xml new file mode 100644 index 00000000..93d2b361 --- /dev/null +++ b/grpc/grpc-client/pom.xml @@ -0,0 +1,53 @@ +<!-- + Copyright 2018 Huawei Technologies Co., Ltd. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<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> + <parent> + <groupId>org.onap.cli</groupId> + <artifactId>oclip-grpc</artifactId> + <version>1.0.0</version> + </parent> + <artifactId>oclip-grpc-client</artifactId> + <name>oclip/grpc/client</name> + <packaging>jar</packaging> + <dependencies> + <dependency> + <groupId>org.onap.cli</groupId> + <artifactId>oclip-grpc-stub</artifactId> + <version>1.0.0</version> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifest> + <addClasspath>true</addClasspath> + <mainClass>org.onap.cli.grpc.client.OpenRemoteCli</mainClass> + </manifest> + </archive> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java b/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java new file mode 100644 index 00000000..e61f54f6 --- /dev/null +++ b/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java @@ -0,0 +1,83 @@ +/* + * Copyright 2018 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.open.infc.grpc.client; + +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.open.infc.grpc.Args; +import org.open.infc.grpc.Input; +import org.open.infc.grpc.OpenInterfaceGrpc; +import org.open.infc.grpc.Output; +import org.open.infc.grpc.Result; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import io.grpc.StatusRuntimeException; + +public class OpenInterfaceGrpcClient { + private static final Logger logger = Logger.getLogger(OpenInterfaceGrpcClient.class.getName()); + + private final ManagedChannel channel; + private final OpenInterfaceGrpc.OpenInterfaceBlockingStub blockingStub; + + public OpenInterfaceGrpcClient(String host, int port) { + this(ManagedChannelBuilder.forAddress(host, port) + // Channels are secure by default (via SSL/TLS). For the example we disable TLS to avoid + // needing certificates. + .usePlaintext(true) + .build()); + } + + OpenInterfaceGrpcClient(ManagedChannel channel) { + this.channel = channel; + blockingStub = OpenInterfaceGrpc.newBlockingStub(channel); + } + + public void shutdown() throws InterruptedException { + channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + + public Output invoke(Input input) { + logger.info("Input " + input.toString()); + + Output result = Output.newBuilder().build(); + try { + result = blockingStub.invoke(input); + } catch (StatusRuntimeException e) { + logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus()); + } + logger.info("Output: " + result.toString()); + return result; + } + + public Result remoteCli(Args args) { + logger.info(args.toString()); + + Result result = Result.newBuilder().setExitCode(1).build(); + try { + result = blockingStub.remoteCli(args); + } catch (StatusRuntimeException e) { + logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus()); + } + + logger.info("Result: " + result.toString()); + return result; + } +} diff --git a/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenRemoteCli.java b/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenRemoteCli.java new file mode 100644 index 00000000..7d02c141 --- /dev/null +++ b/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenRemoteCli.java @@ -0,0 +1,86 @@ +/* + * Copyright 2018 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.open.infc.grpc.client; + +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +import org.open.infc.grpc.Args; +import org.open.infc.grpc.Result; + +public class OpenRemoteCli { + public static final String OCLIP_GRPC_SERVER = "http://localhost:50051"; + public static final String OCLIP_GRPC_SERVER_ENV = "OCLIP_SERVER"; + + public static Result run (String[] args) throws Exception { + String oclipHome = System.getenv(OCLIP_GRPC_SERVER_ENV); + + if (oclipHome == null) { + oclipHome = OCLIP_GRPC_SERVER; + } + + if (System.getenv("OPEN_CLI_DEBUG") == null) { + Logger globalLogger = Logger.getLogger(OpenInterfaceGrpcClient.class.getName()); + globalLogger.setLevel(java.util.logging.Level.OFF); + } else { + System.out.println(OCLIP_GRPC_SERVER_ENV + "=" + oclipHome); + } + + if (args.length <= 2 || !args[0].equals("-P")) { + System.out.println("Usage: oclip -P <product-name> <command-name> <command-arguments"); + System.out.println("NOTE: Set environment variable " + OCLIP_GRPC_SERVER_ENV + " to OCLIP gRPC server. By default its " + OCLIP_GRPC_SERVER); + System.exit(0); + } + + List<String> argList = new ArrayList<>(); + + for (String arg: args) { + argList.add(arg); + } + + //-P + argList.remove(0); + + //<product-name> + String product = argList.remove(0); + + URL oclipUrl = new URL(oclipHome); + OpenInterfaceGrpcClient client = new OpenInterfaceGrpcClient( + oclipUrl.getHost(), oclipUrl.getPort()); + + try { + Result result = client.remoteCli(Args.newBuilder().addAllArgs(argList).setProduct(product).build()); + return result; + } finally { + client.shutdown(); + } + } + + + public static void main(String[] args) throws Exception { + int exitCode = 1; + try { + Result result = OpenRemoteCli.run(args); + System.out.println(result.getOutput()); + exitCode = result.getExitCode(); + } finally { + System.exit(exitCode); + } + } +} diff --git a/grpc/grpc-client/src/main/resources/log4j.properties b/grpc/grpc-client/src/main/resources/log4j.properties new file mode 100644 index 00000000..778641ed --- /dev/null +++ b/grpc/grpc-client/src/main/resources/log4j.properties @@ -0,0 +1,32 @@ +# Copyright 2018 Huawei Technologies Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +log4j.rootLogger=ERROR, file + +log4j.logger.org.onap.cli=DEBUG, file +log4j.logger.org.open.infc=DEBUG, file + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Redirect log messages to a log file, support file rolling. +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=${OPEN_CLI_HOME}/logs/open-cli.log +log4j.appender.file.MaxFileSize=5MB +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/grpc/grpc-server/pom.xml b/grpc/grpc-server/pom.xml new file mode 100644 index 00000000..412c5c90 --- /dev/null +++ b/grpc/grpc-server/pom.xml @@ -0,0 +1,58 @@ +<!-- + Copyright 2018 Huawei Technologies Co., Ltd. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<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> + <parent> + <groupId>org.onap.cli</groupId> + <artifactId>oclip-grpc</artifactId> + <version>1.0.0</version> + </parent> + <artifactId>oclip-grpc-server</artifactId> + <name>oclip/grpc/server</name> + <packaging>jar</packaging> + <dependencies> + <dependency> + <groupId>org.onap.cli</groupId> + <artifactId>oclip-grpc-stub</artifactId> + <version>1.0.0</version> + </dependency> + <dependency> + <groupId>org.onap.cli</groupId> + <artifactId>cli-main</artifactId> + <version>2.0.2</version> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifest> + <addClasspath>true</addClasspath> + <mainClass>org.onap.cli.grpc.server.OpenInterfaceGrpcServer</mainClass> + </manifest> + </archive> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java new file mode 100644 index 00000000..0f389f31 --- /dev/null +++ b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java @@ -0,0 +1,156 @@ +/* + * Copyright 2018 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.open.infc.grpc.server; + +import java.io.IOException; +import java.util.Map.Entry; +import java.util.logging.Logger; + +import org.onap.cli.fw.cmd.OnapCommand; +import org.onap.cli.fw.conf.OnapCommandConfig; +import org.onap.cli.fw.conf.OnapCommandConstants; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.output.OnapCommandResultType; +import org.onap.cli.fw.registrar.OnapCommandRegistrar; +import org.onap.cli.main.OnapCli; +import org.open.infc.grpc.Args; +import org.open.infc.grpc.Input; +import org.open.infc.grpc.OpenInterfaceGrpc; +import org.open.infc.grpc.Output; +import org.open.infc.grpc.Output.Builder; +import org.open.infc.grpc.Result; + +import io.grpc.Server; +import io.grpc.ServerBuilder; +import io.grpc.stub.StreamObserver; + +public class OpenInterfaceGrpcServer { + + private static final Logger logger = Logger.getLogger(OpenInterfaceGrpcServer.class.getName()); + + private static final String CONF_FILE = "oclip-grpc-server.properties"; + private static final String CONF_SERVER_PORT = "oclip.grpc_server_port"; + + static { + OnapCommandConfig.addProperties(CONF_FILE); + } + private Server server; + + private void start() throws IOException { + /* The port on which the server should run */ + int port = Integer.parseInt(OnapCommandConfig.getPropertyValue(CONF_SERVER_PORT)); + server = ServerBuilder.forPort(port) + .addService(new OpenInterfaceGrpcImpl()) + .build() + .start(); + logger.info("Server started, listening on " + port); + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + // Use stderr here since the logger may have been reset by its JVM shutdown hook. + System.err.println("*** shutting down gRPC server since JVM is shutting down"); + OpenInterfaceGrpcServer.this.stop(); + System.err.println("*** server shut down"); + } + }); + } + + private void stop() { + if (server != null) { + server.shutdown(); + } + } + + /** + * Await termination on the main thread since the grpc library uses daemon threads. + */ + private void blockUntilShutdown() throws InterruptedException { + if (server != null) { + server.awaitTermination(); + } + } + + /** + * Main launches the server from the command line. + */ + public static void main(String[] args) throws IOException, InterruptedException { + final OpenInterfaceGrpcServer server = new OpenInterfaceGrpcServer(); + server.start(); + server.blockUntilShutdown(); + } + + static class OpenRemoteCli extends OnapCli { + private String outputs = ""; + public OpenRemoteCli(String product, String[] args) { + super(product, args); + } + + public void print(String msg) { + outputs += msg + "\n"; + } + + public String getResult() { + return outputs; + } + } + + static class OpenInterfaceGrpcImpl extends OpenInterfaceGrpc.OpenInterfaceImplBase { + + @Override + public void invoke(Input req, StreamObserver<Output> responseObserver) { + Builder reply = Output.newBuilder(); + logger.info(req.toString()); + + String product = req.getOptionsMap().get(OnapCommandConstants.OPEN_CLI_PRODUCT_NAME); + String format = req.getOptionsMap().getOrDefault(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_FORMAT, OnapCommandResultType.JSON.name().toLowerCase()); + String command = req.getAction(); + + try { + OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get(command, product); + cmd.getParametersMap().get(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_FORMAT).setValue(format); + for (Entry<String, String> arg: req.getParams().entrySet()) { + cmd.getParametersMap().get(arg.getKey()).setValue(arg.getValue()); + } + cmd.execute(); + + reply.putAttrs(OnapCommandConstants.RESULTS, cmd.getResult().print()); + reply.setSuccess(true); + reply.putAttrs(OnapCommandConstants.ERROR, "{}"); + } catch (OnapCommandException e) { + logger.info(e.getMessage()); + reply.putAttrs(OnapCommandConstants.RESULTS, "{}"); + reply.setSuccess(false); + reply.putAttrs(OnapCommandConstants.ERROR, e.toJsonString()); + } + + responseObserver.onNext(reply.build()); + responseObserver.onCompleted(); + } + + @Override + public void remoteCli(Args req, StreamObserver<Result> responseObserver) { + logger.info(req.toString()); + + OpenRemoteCli cli = new OpenRemoteCli(req.getProduct(), req.getArgsList().toArray(new String [] {})); + cli.handle(); + + Result reply = Result.newBuilder().setExitCode(cli.getExitCode()).setOutput(cli.getResult()).build(); + responseObserver.onNext(reply); + responseObserver.onCompleted(); + } + } +} diff --git a/grpc/grpc-server/src/main/resources/log4j.properties b/grpc/grpc-server/src/main/resources/log4j.properties new file mode 100644 index 00000000..29a491cd --- /dev/null +++ b/grpc/grpc-server/src/main/resources/log4j.properties @@ -0,0 +1,32 @@ +# Copyright 2018 Huawei Technologies Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +log4j.rootLogger=ERROR, file + +log4j.logger.org.onap.cli=DEBUG, file, stdout +log4j.logger.org.open.infc=DEBUG, file, stdout + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Redirect log messages to a log file, support file rolling. +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=${OPEN_CLI_HOME}/logs/open-cli.log +log4j.appender.file.MaxFileSize=5MB +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/grpc/grpc-server/src/main/resources/oclip-grpc-server.properties b/grpc/grpc-server/src/main/resources/oclip-grpc-server.properties new file mode 100644 index 00000000..972fdebb --- /dev/null +++ b/grpc/grpc-server/src/main/resources/oclip-grpc-server.properties @@ -0,0 +1,15 @@ +# Copyright 2018 Huawei Technologies Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +oclip.grpc_server_port=50051
\ No newline at end of file diff --git a/grpc/grpc-stub/pom.xml b/grpc/grpc-stub/pom.xml new file mode 100644 index 00000000..9e13c8ec --- /dev/null +++ b/grpc/grpc-stub/pom.xml @@ -0,0 +1,34 @@ +<!-- + Copyright 2018 Huawei Technologies Co., Ltd. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<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> + <parent> + <groupId>org.onap.cli</groupId> + <artifactId>oclip-grpc</artifactId> + <version>1.0.0</version> + </parent> + <artifactId>oclip-grpc-stub</artifactId> + <name>oclip/grpc/stub</name> + <packaging>jar</packaging> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/grpc/grpc-stub/src/main/proto/oclip.proto b/grpc/grpc-stub/src/main/proto/oclip.proto new file mode 100644 index 00000000..03224823 --- /dev/null +++ b/grpc/grpc-stub/src/main/proto/oclip.proto @@ -0,0 +1,53 @@ +// Copyright 2018 Huawei Technologies Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + syntax = "proto3"; + +option java_package = "org.open.infc.grpc"; +option java_multiple_files = true; +option java_outer_classname = "Oclip"; + +package oclip; + +service OpenInterface { + rpc invoke(Input) returns (Output) {} + rpc remoteCli(Args) returns (Result) {} +} + +//Used for java rpc +message Input { + string requestId = 1; + string action = 2; + map<string, string> params = 3; + map<string, string> options = 4; +} + +message Output { + bool success = 1; + map<string, string> attrs = 2; + + //if backend wants to report back some info like response header + map<string, string> addons = 3; +} + +//Used for remote CLI +message Args{ + repeated string args = 1; + string product = 2; +} + +message Result { + int32 exitCode = 1; + string output = 2; +}
\ No newline at end of file diff --git a/grpc/pom.xml b/grpc/pom.xml new file mode 100644 index 00000000..187aa03d --- /dev/null +++ b/grpc/pom.xml @@ -0,0 +1,169 @@ +<!-- + Copyright 2018 Huawei Technologies Co., Ltd. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> +<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> + <parent> + <groupId>org.onap.cli</groupId> + <artifactId>cli</artifactId> + <version>2.0.2</version> + <relativePath>..</relativePath> + </parent> + <version>1.0.0</version> + <artifactId>oclip-grpc</artifactId> + <packaging>pom</packaging> + <name>oclip/grpc</name> + <modules> + <module>grpc-stub</module> + <module>grpc-server</module> + <module>grpc-client</module> + </modules> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <grpc.version>1.8.0</grpc.version> + </properties> + <dependencies> + <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>io.grpc</groupId> + <artifactId>grpc-testing</artifactId> + <version>${grpc.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.api.grpc</groupId> + <artifactId>proto-google-common-protos</artifactId> + <version>0.1.9</version> + </dependency> + </dependencies> + <build> + <extensions> + <extension> + <groupId>kr.motd.maven</groupId> + <artifactId>os-maven-plugin</artifactId> + <version>1.5.0.Final</version> + </extension> + </extensions> + <plugins> + <plugin> + <groupId>org.xolstice.maven.plugins</groupId> + <artifactId>protobuf-maven-plugin</artifactId> + <version>0.5.0</version> + <configuration> + <protocArtifact>com.google.protobuf:protoc:3.4.0: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> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <version>1.4.1</version> + <executions> + <execution> + <id>enforce</id> + <goals> + <goal>enforce</goal> + </goals> + <configuration> + <rules> + <requireUpperBoundDeps/> + </rules> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>copy-artifact</id> + <phase>package</phase> + <goals> + <goal>copy</goal> + <goal>copy-dependencies</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>${project.groupId}</groupId> + <artifactId>${project.artifactId}</artifactId> + <version>${project.version}</version> + <type>${project.packaging}</type> + </artifactItem> + </artifactItems> + <outputDirectory>${project.build.directory}/lib</outputDirectory> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>false</overWriteSnapshots> + <overWriteIfNewer>true</overWriteIfNewer> + <excludeArtifactIds>junit,jmockit</excludeArtifactIds> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>copy-artifact</id> + <phase>package</phase> + <goals> + <goal>copy</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>${project.groupId}</groupId> + <artifactId>${project.artifactId}</artifactId> + <version>${project.version}</version> + <type>${project.packaging}</type> + </artifactItem> + </artifactItems> + <outputDirectory>../../grpc/target/lib</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </pluginManagement> + </build> +</project>
\ No newline at end of file |