diff options
Diffstat (limited to 'grpc')
-rw-r--r-- | grpc/grpc-client/pom.xml | 2 | ||||
-rw-r--r-- | grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java | 31 | ||||
-rw-r--r-- | grpc/grpc-server/pom.xml | 4 | ||||
-rw-r--r-- | grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java | 5 | ||||
-rw-r--r-- | grpc/grpc-stub/pom.xml | 2 | ||||
-rw-r--r-- | grpc/pom.xml | 4 |
6 files changed, 37 insertions, 11 deletions
diff --git a/grpc/grpc-client/pom.xml b/grpc/grpc-client/pom.xml index 15e4f5b0..a8763857 100644 --- a/grpc/grpc-client/pom.xml +++ b/grpc/grpc-client/pom.xml @@ -18,7 +18,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>oclip-grpc</artifactId> - <version>1.0.2</version> + <version>1.0.3</version> </parent> <artifactId>oclip-grpc-client</artifactId> <name>oclip/grpc/client</name> 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 index 2d9d32fc..9a818d7a 100644 --- 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 @@ -37,6 +37,25 @@ public class OpenInterfaceGrpcClient { private final ManagedChannel channel; private final OpenInterfaceGrpc.OpenInterfaceBlockingStub blockingStub; + public static class OpenInterfaceGrpcExecption extends Exception { + private static final long serialVersionUID = -8755636432217894246L; + + private int errorCode = -1; + + public OpenInterfaceGrpcExecption(int errorCode, String message) { + super(message); + this.errorCode = errorCode; + } + } + + public static class OpenInterfaceGrpcTimeoutExecption extends OpenInterfaceGrpcExecption { + private static int errorCode = 1; + + public OpenInterfaceGrpcTimeoutExecption(String message) { + super(errorCode, message); + } + } + 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 @@ -54,27 +73,31 @@ public class OpenInterfaceGrpcClient { channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); } - public Output invoke(Input input) { + public Output invoke(Input input) throws OpenInterfaceGrpcTimeoutExecption { logger.info("Input " + input.toString()); Output result = Output.newBuilder().build(); try { - result = blockingStub.invoke(input); + result = blockingStub.withDeadlineAfter(10, TimeUnit.SECONDS).invoke(input); } catch (StatusRuntimeException e) { logger.warn("RPC failed: {0}", e.getStatus()); + //Status{code=DEADLINE_EXCEEDED} + throw new OpenInterfaceGrpcTimeoutExecption(e.getMessage()); } logger.info("Output: " + result.toString()); return result; } - public Result remoteCli(Args args) { + public Result remoteCli(Args args) throws OpenInterfaceGrpcTimeoutExecption { logger.info(args.toString()); Result result = Result.newBuilder().setExitCode(1).build(); try { - result = blockingStub.remoteCli(args); + result = blockingStub.withDeadlineAfter(10, TimeUnit.SECONDS).remoteCli(args); } catch (StatusRuntimeException e) { logger.warn("RPC failed: {0}", e.getStatus()); + //Status{code=DEADLINE_EXCEEDED} + throw new OpenInterfaceGrpcTimeoutExecption(e.getMessage()); } logger.info("Result: " + result.toString()); diff --git a/grpc/grpc-server/pom.xml b/grpc/grpc-server/pom.xml index a91cb884..e4d1a288 100644 --- a/grpc/grpc-server/pom.xml +++ b/grpc/grpc-server/pom.xml @@ -18,7 +18,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>oclip-grpc</artifactId> - <version>1.0.2</version> + <version>1.0.3</version> </parent> <artifactId>oclip-grpc-server</artifactId> <name>oclip/grpc/server</name> @@ -32,7 +32,7 @@ <dependency> <groupId>org.onap.cli</groupId> <artifactId>cli-main</artifactId> - <version>2.0.5</version> + <version>2.0.6</version> </dependency> </dependencies> <build> 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 index 45a64084..afbd7682 100644 --- 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 @@ -208,7 +208,10 @@ public class OpenInterfaceGrpcServer { Builder reply = Output.newBuilder(); reply.setSuccess(true); reply.putAttrs(OnapCommandConstants.ERROR, "{}"); - reply.putAddons("execution-id", executionStoreContext.getExecutionId()); + + if (executionStoreContext != null) + reply.putAddons("execution-id", executionStoreContext.getExecutionId()); + try { reply.putAttrs(OnapCommandConstants.RESULTS, new ObjectMapper().readTree(printOut).toString()); } catch (IOException e) { diff --git a/grpc/grpc-stub/pom.xml b/grpc/grpc-stub/pom.xml index 00e34391..1fecb3aa 100644 --- a/grpc/grpc-stub/pom.xml +++ b/grpc/grpc-stub/pom.xml @@ -18,7 +18,7 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>oclip-grpc</artifactId> - <version>1.0.2</version> + <version>1.0.3</version> </parent> <artifactId>oclip-grpc-stub</artifactId> <name>oclip/grpc/stub</name> diff --git a/grpc/pom.xml b/grpc/pom.xml index 32104a63..4924ac72 100644 --- a/grpc/pom.xml +++ b/grpc/pom.xml @@ -18,9 +18,9 @@ <parent> <groupId>org.onap.cli</groupId> <artifactId>cli</artifactId> - <version>2.0.5</version> + <version>2.0.6</version> </parent> - <version>1.0.2</version> + <version>1.0.3</version> <artifactId>oclip-grpc</artifactId> <packaging>pom</packaging> <name>oclip/grpc</name> |