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.
21 "github.com/sirupsen/logrus"
30 // Plugin adapter which decides a specific client based on plugin info
31 // TODO PluginInfo to have other information about plugins to find the client and implementation to handle accordingly.
32 type PluginAdapter struct {
37 // Constructor of PluginAdapter
38 func NewPluginAdapter(pluginInfo string, logger *logrus.Logger) *PluginAdapter {
39 return &PluginAdapter{pluginInfo: pluginInfo, logger: logger}
42 // Instantiate application
43 func (c *PluginAdapter) Instantiate(pluginInfo string, host string, deployArtifact string) (workloadId string, error error) {
44 c.logger.Info("Instantation started")
45 clientConfig := plugin.ClientGRPCConfig{Address: pluginInfo, ChunkSize: chunkSize, RootCertificate: rootCertificate}
46 var client, err = plugin.NewClientGRPC(clientConfig)
48 c.logger.Errorf("failed to create client: %v", err)
52 ctx, cancel := context.WithTimeout(context.Background(), 50*time.Second)
56 workloadId, status, err := client.Instantiate(ctx, deployArtifact, host)
58 c.logger.Errorf("server failed to respond %s", err.Error())
61 c.logger.Info("Instantiation success with workloadId %s, status: %s ", workloadId, status)
62 return workloadId, nil
66 func (c *PluginAdapter) Query(pluginInfo string, host string, workloadId string) (status string, error error) {
67 c.logger.Info("Query started")
68 clientConfig := plugin.ClientGRPCConfig{Address: pluginInfo, ChunkSize: chunkSize, RootCertificate: rootCertificate}
69 var client, err = plugin.NewClientGRPC(clientConfig)
71 c.logger.Errorf("failed to create client: %v", err)
75 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
79 status, err = client.Query(ctx, host, workloadId)
81 c.logger.Errorf("failed to query: %v", err)
84 c.logger.Info("query status: ", status)
88 // Terminate application
89 func (c *PluginAdapter) Terminate(pluginInfo string, host string, workloadId string) (status string, error error) {
90 c.logger.Info("Terminate started")
91 clientConfig := plugin.ClientGRPCConfig{Address: pluginInfo, ChunkSize: chunkSize, RootCertificate: rootCertificate}
92 var client, err = plugin.NewClientGRPC(clientConfig)
94 c.logger.Errorf("failed to create client: %v", err)
98 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
102 status, err = client.Terminate(ctx, host, workloadId)
105 c.logger.Errorf("failed to instantiate: %v", err)
106 return "Failure", err
109 c.logger.Info("termination success with status: ", status)