2 * Copyright 2020 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.
26 func Instantiate(pluginInfo string, host string, deployArtifact string) (workloadId string, error error) {
27 logger := log.New(os.Stdout, "broker ", log.LstdFlags|log.Lshortfile)
28 clientConfig := plugin.ClientGRPCConfig{Address: pluginInfo, ChunkSize: 1024, RootCertificate: ""}
29 var client, err = plugin.NewClientGRPC(clientConfig)
31 logger.Fatalf("failed to create client: %v", err)
34 log.Printf("pluginInfo: ", pluginInfo)
35 log.Printf("host: ", host)
36 log.Printf("deployArtifact: ", deployArtifact)
37 ctx, cancel := context.WithTimeout(context.Background(), 50*time.Second)
41 workloadId, status, err := client.Instantiate(ctx, deployArtifact, host)
43 logger.Println("server failed to respond %s", err.Error())
45 logger.Println(workloadId, status)
46 return workloadId, nil
51 func Query(pluginInfo string, host string, workloadId string) (status string, error error) {
52 logger := log.New(os.Stdout, "broker ", log.LstdFlags|log.Lshortfile)
53 clientConfig := plugin.ClientGRPCConfig{Address: pluginInfo, ChunkSize: 1024, RootCertificate: ""}
54 var client, err = plugin.NewClientGRPC(clientConfig)
56 logger.Fatalf("failed to create client: %v", err)
59 log.Printf("pluginInfo: ", pluginInfo)
60 log.Printf("host: ", host)
61 log.Printf("workloadId: ", workloadId)
62 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
66 stats := client.Query(ctx, host, workloadId)
68 logger.Fatalf("failed to instantiate: %v", err)
71 logger.Println("query status: ", stats)
75 func Terminate(pluginInfo string, host string, workloadId string) (status string, error error) {
76 logger := log.New(os.Stdout, "broker ", log.LstdFlags|log.Lshortfile)
77 clientConfig := plugin.ClientGRPCConfig{Address: pluginInfo, ChunkSize: 1024, RootCertificate: ""}
78 var client, err = plugin.NewClientGRPC(clientConfig)
80 logger.Fatalf("failed to create client: %v", err)
83 log.Printf("pluginInfo: ", pluginInfo)
84 log.Printf("host: ", host)
85 log.Printf("workloadId: ", workloadId)
86 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
90 ts := client.Terminate(ctx, host, workloadId)
92 logger.Fatalf("failed to instantiate: %v", err)
96 logger.Println("termination status: ", ts)