2 * Copyright 2018 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.open.infc.grpc.client;
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.logging.Logger;
24 import org.open.infc.grpc.Args;
25 import org.open.infc.grpc.Result;
27 public class OpenRemoteCli {
28 public static final String OCLIP_GRPC_SERVER = "http://localhost:50051";
29 public static final String OCLIP_GRPC_SERVER_ENV = "OCLIP_SERVER";
31 public static Result run (String[] args) throws Exception {
32 String oclipHome = System.getenv(OCLIP_GRPC_SERVER_ENV);
34 if (oclipHome == null) {
35 oclipHome = OCLIP_GRPC_SERVER;
38 if (System.getenv("OPEN_CLI_DEBUG") == null) {
39 Logger globalLogger = Logger.getLogger(OpenInterfaceGrpcClient.class.getName());
40 globalLogger.setLevel(java.util.logging.Level.OFF);
42 System.out.println(OCLIP_GRPC_SERVER_ENV + "=" + oclipHome);
45 if (args.length <= 2 || !args[0].equals("-P")) {
46 System.out.println("Usage: oclip -P <product-name> <command-name> <command-arguments");
47 System.out.println("NOTE: Set environment variable " + OCLIP_GRPC_SERVER_ENV + " to OCLIP gRPC server. By default its " + OCLIP_GRPC_SERVER);
51 List<String> argList = new ArrayList<>();
53 for (String arg: args) {
61 String product = argList.remove(0);
63 URL oclipUrl = new URL(oclipHome);
64 OpenInterfaceGrpcClient client = new OpenInterfaceGrpcClient(
65 oclipUrl.getHost(), oclipUrl.getPort());
68 Result result = client.remoteCli(Args.newBuilder().addAllArgs(argList).setProduct(product).build());
76 public static void main(String[] args) throws Exception {
79 Result result = OpenRemoteCli.run(args);
80 System.out.println(result.getOutput());
81 exitCode = result.getExitCode();
83 System.exit(exitCode);