aboutsummaryrefslogtreecommitdiffstats
path: root/grpc/grpc-client
diff options
context:
space:
mode:
authorItohan Ukponmwan <itohan.ukponmwan@intel.com>2019-08-05 16:30:20 +0000
committerGerrit Code Review <gerrit@onap.org>2019-08-05 16:30:20 +0000
commit55f55f93890a2c4745ee89505cc889f54ba3c3dd (patch)
tree5eb804de9b3907b38621a3f5d8169ae3f6a64c21 /grpc/grpc-client
parentd53b78f51ed1a37f13163fe0ffd77ebd1c7f6f6f (diff)
parentb9d85a33892c99949aff8e3471eb0fdc039d44aa (diff)
Merge changes I816a1dbb,Ice38da57,I1217d391,I07d22e81,I0ddcdc1c, ...
* changes: Add integration support Update framework Add vf model add artifact command Add service model artifact add command Add VF model checkout command Add VF checkin command Add sdc service resource property set Add sdc consumer-show command Add sdc consumer create command Add ID output in service-model commands Update open-cli.properties Update the sample command OCS YAML Add product into service and schema list Update the version format Update the README Set SNAPSHOT versioning clean-up stale onap profiles Ignore python build artifacts from git
Diffstat (limited to 'grpc/grpc-client')
-rw-r--r--grpc/grpc-client/pom.xml2
-rw-r--r--grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java12
-rw-r--r--grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenRemoteCli.java47
3 files changed, 57 insertions, 4 deletions
diff --git a/grpc/grpc-client/pom.xml b/grpc/grpc-client/pom.xml
index 813e8e72..3b7ad6d5 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>3.0.0</version>
+ <version>4.0.0-SNAPSHOT</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 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