diff options
Diffstat (limited to 'grpc')
3 files changed, 85 insertions, 14 deletions
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 9a818d7a..e32110de 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,9 @@ public class OpenInterfaceGrpcClient { private final ManagedChannel channel; private final OpenInterfaceGrpc.OpenInterfaceBlockingStub blockingStub; + //10 seconds + private int timeout = 60000; + public static class OpenInterfaceGrpcExecption extends Exception { private static final long serialVersionUID = -8755636432217894246L; @@ -64,6 +67,11 @@ public class OpenInterfaceGrpcClient { .build()); } + public OpenInterfaceGrpcClient(String host, int port, int timeout) { + this(host, port); + this.timeout = timeout; + + } OpenInterfaceGrpcClient(ManagedChannel channel) { this.channel = channel; blockingStub = OpenInterfaceGrpc.newBlockingStub(channel); @@ -78,7 +86,7 @@ public class OpenInterfaceGrpcClient { Output result = Output.newBuilder().build(); try { - result = blockingStub.withDeadlineAfter(10, TimeUnit.SECONDS).invoke(input); + result = blockingStub.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS).invoke(input); } catch (StatusRuntimeException e) { logger.warn("RPC failed: {0}", e.getStatus()); //Status{code=DEADLINE_EXCEEDED} @@ -93,7 +101,7 @@ public class OpenInterfaceGrpcClient { Result result = Result.newBuilder().setExitCode(1).build(); try { - result = blockingStub.withDeadlineAfter(10, TimeUnit.SECONDS).remoteCli(args); + result = blockingStub.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS).remoteCli(args); } catch (StatusRuntimeException e) { logger.warn("RPC failed: {0}", e.getStatus()); //Status{code=DEADLINE_EXCEEDED} 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 index fc0c2aac..724267e8 100644 --- 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 @@ -26,6 +26,51 @@ import org.open.infc.grpc.Output; import org.open.infc.grpc.Result; public class OpenRemoteCli { + + private String host; + private int port; + private int timeout; + private String requestId; + + public OpenRemoteCli(String host, int port, int timeout, String requestId) { + this.host = host; + this.port = port; + this.timeout = timeout; + this.requestId = requestId; + + } + + public Result run (List <String> args) throws Exception { + OpenInterfaceGrpcClient client = new OpenInterfaceGrpcClient( + host, port, timeout); + try { + Result result = client.remoteCli(Args.newBuilder().setRequestId(this.requestId).addAllArgs(args).build()); + return result; + } finally { + client.shutdown(); + } + } + + public Output invoke (String product, String profile, String action, Map <String, String> params) throws Exception { + OpenInterfaceGrpcClient client = new OpenInterfaceGrpcClient( + host, port, timeout); + try { + + Map <String, String> options = new HashMap<>(); + options.put("product", product); + if (profile != null && !profile.isEmpty()) + options.put("profile", profile); + params.put("format", "json"); + Input input = Input.newBuilder().setAction(action).setRequestId(requestId).putAllOptions(options).putAllParams(params).build(); + + Output output = client.invoke(input); + return output; + } finally { + client.shutdown(); + } + } + + //Absolute the static methods /** * Runs CLI remotely * @param host @@ -48,7 +93,7 @@ public class OpenRemoteCli { } } - /** + /** * Runs commands as remote procedure call :) * @param host * @param port 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 79d761d6..f34df89f 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 @@ -29,11 +29,13 @@ 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.input.OnapCommandParameter; +import org.onap.cli.fw.input.OnapCommandParameterType; import org.onap.cli.fw.output.OnapCommandResultType; import org.onap.cli.fw.registrar.OnapCommandRegistrar; import org.onap.cli.fw.store.OnapCommandExecutionStore; import org.onap.cli.fw.store.OnapCommandExecutionStore.ExecutionStoreContext; import org.onap.cli.main.OnapCli; +import org.onap.cli.main.utils.OnapCliArgsParser; import org.open.infc.grpc.Args; import org.open.infc.grpc.Input; import org.open.infc.grpc.OpenInterfaceGrpc; @@ -181,6 +183,24 @@ public class OpenInterfaceGrpcServer { if (params.contains(arg.getKey())) cmd.getParametersMap().get(arg.getKey()).setValue(arg.getValue()); } + + //fill values from the file, if needed + for (OnapCommandParameter param: cmd.getParameters()) { + if (param.getParameterType().equals(OnapCommandParameterType.JSON)) { + param.setValue(OnapCliArgsParser.readJsonStringFromUrl(param.getValue().toString(), param.getName())); + + } else if (param.getParameterType().equals(OnapCommandParameterType.TEXT)) { + param.setValue(OnapCliArgsParser.readTextStringFromUrl(param.getValue().toString(), param.getName())); + + } else if (param.getParameterType().equals(OnapCommandParameterType.BYTE)) { + param.setValue(OnapCliArgsParser.readBytesFromUrl(param.getValue().toString(), param.getName())); + + } else if (param.getParameterType().equals(OnapCommandParameterType.YAML)) { + param.setValue(OnapCliArgsParser.readYamlStringFromUrl(param.getValue().toString(), param.getName())); + + } + } + } else { cmd.getParametersMap().get(OnapCommandConstants.INFO_PRODUCT).setValue(product); @@ -194,7 +214,9 @@ public class OpenInterfaceGrpcServer { if (!cmd.isRpc()) { //Start the execution - if (req.getRequestId() != null) { + if (req.getRequestId() != null && !req.getRequestId().isEmpty()) { + if (!(cmd.getInfo().getProduct().equalsIgnoreCase("open-cli") && + cmd.getName().equalsIgnoreCase("execution-list"))) { String input = cmd.getArgsJson(true); executionStoreContext = OnapCommandExecutionStore.getStore().storeExectutionStart( req.getRequestId(), @@ -203,12 +225,16 @@ public class OpenInterfaceGrpcServer { cmd.getName(), profile, input); + } } } - + cmd.setExecutionContext(executionStoreContext); cmd.execute(); if (!cmd.isRpc()) { + //Track and/or persist the execution context + new OnapCli().handleTracking(cmd); + String printOut = cmd.getResult().print(); Builder reply = Output.newBuilder(); reply.putAttrs(OnapCommandConstants.ERROR, "{}"); @@ -226,15 +252,6 @@ public class OpenInterfaceGrpcServer { } output = reply.build(); - - if (req.getRequestId() != null) { - //complete the execution recording - OnapCommandExecutionStore.getStore().storeExectutionEnd( - executionStoreContext, - printOut, - null, - cmd.getResult().isPassed()); - } logger.info(output.toString()); } else { //Rpc command will set the output. @@ -254,6 +271,7 @@ public class OpenInterfaceGrpcServer { executionStoreContext, null, e.getMessage(), + cmd.getResult().getDebugInfo(), false); reply.putAddons("execution-id", executionStoreContext.getExecutionId()); } |