import (
"broker/pkg/handlers"
"broker/pkg/util"
- "github.com/sirupsen/logrus"
"os"
+
+ "github.com/sirupsen/logrus"
)
// Variables to be defined in deployment file
var (
- logFile = os.Getenv("LOGFILE_PATH")
- loggerLevel = os.Getenv("LOGGER_LEVEL")
+ logFile = os.Getenv("LOGFILE_PATH")
+ loggerLevel = os.Getenv("LOGGER_LEVEL")
applcmAddress = os.Getenv("ADDRESS")
)
-
func main() {
// Prepare logger
file, err := os.Create(logFile)
import (
context "context"
+ reflect "reflect"
+ sync "sync"
+
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
- reflect "reflect"
- sync "sync"
)
const (
import (
"broker/pkg/handlers/model"
+ "os"
+
"github.com/jinzhu/gorm"
"github.com/sirupsen/logrus"
- "os"
)
// DB name
usrpswd := os.Getenv("MYSQL_USER") + ":" + os.Getenv("MYSQL_PASSWORD")
host := "@tcp(" + "dbhost" + ":3306)/"
- db, err := gorm.Open("mysql", usrpswd + host)
+ db, err := gorm.Open("mysql", usrpswd+host)
if err != nil {
adapter.logger.Fatalf("Database connect error", err.Error())
}
adapter.logger.Infof("Get App Instance Info %s", key)
var appInstanceInfo model.AppInstanceInfo
returnVal := adapter.db.First(&appInstanceInfo, "id=?", key).Error
- if returnVal != nil {
+ if returnVal != nil {
return
}
adapter.logger.Infof("Get App Package Info: %s", key)
var appPkgInfo model.AppPackageInfo
err := adapter.db.First(&appPkgInfo, "id=?", key).Error
- if err != nil {
+ if err != nil {
return
}
return appPkgInfo
import (
"broker/pkg/plugin"
"context"
- "github.com/sirupsen/logrus"
"time"
+
+ "github.com/sirupsen/logrus"
)
const (
- chunkSize = 1024
- rootCertificate = ""
+ chunkSize = 1024
+ rootCertificate = ""
)
// Plugin adapter which decides a specific client based on plugin info
// TODO PluginInfo to have other information about plugins to find the client and implementation to handle accordingly.
type PluginAdapter struct {
pluginInfo string
- logger *logrus.Logger
+ logger *logrus.Logger
}
// Constructor of PluginAdapter
package handlers
import (
- "github.com/gorilla/mux"
- "github.com/sirupsen/logrus"
"net/http"
"os"
+
+ "github.com/gorilla/mux"
+ "github.com/sirupsen/logrus"
)
// URLS
const (
- CreateAppInstance = "/ealtedge/mepm/app_lcm/v1/app_instances"
- InstantiateAppInstance = "/ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}/instantiate"
- QueryAppInstanceInfo = "/ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}"
- QueryAppLcmOperationStatus = "/ealtedge/mepm/app_lcm/v1/app_lcm_op_occs"
- TerminateAppIns = "/ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}/terminate"
- DeleteAppInstanceIdentifier = "/ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}"
- OnboardPackage = "/ealtedge/mepm/app_pkgm/v1/app_packages"
- QueryOnboardPackage = "/ealtedge/mepm/app_pkgm/v1/app_packages/{appPkgId}"
+ CreateAppInstance = "/ealtedge/mepm/app_lcm/v1/app_instances"
+ InstantiateAppInstance = "/ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}/instantiate"
+ QueryAppInstanceInfo = "/ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}"
+ QueryAppLcmOperationStatus = "/ealtedge/mepm/app_lcm/v1/app_lcm_op_occs"
+ TerminateAppIns = "/ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}/terminate"
+ DeleteAppInstanceIdentifier = "/ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}"
+ OnboardPackage = "/ealtedge/mepm/app_pkgm/v1/app_packages"
+ QueryOnboardPackage = "/ealtedge/mepm/app_pkgm/v1/app_packages/{appPkgId}"
)
var (
- PackageFolderPath = os.Getenv("PACKAGE_PATH")
+ PackageFolderPath = os.Getenv("PACKAGE_PATH")
PackageArtifactPath = os.Getenv("PACKAGE_ARTIFACT_PATH")
)
"bytes"
"encoding/json"
"fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "path/filepath"
+ "strings"
+
"github.com/buger/jsonparser"
"github.com/ghodss/yaml"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
- "io"
- "io/ioutil"
- "net/http"
- "os"
- "path/filepath"
- "strings"
)
// Handler of REST APIs
type HandlerImpl struct {
- logger *logrus.Logger
- dbAdapter *dbAdapter.DbAdapter
+ logger *logrus.Logger
+ dbAdapter *dbAdapter.DbAdapter
}
// Creates handler implementation
import (
"broker/internal/lcmservice"
+ "io"
+ "os"
+
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
_ "google.golang.org/grpc/encoding/gzip"
- "io"
- "os"
)
// GRPC client to different GRPC supported plugins
file, err := os.Open(deployArtifact)
if err != nil {
c.logger.Errorf("failed to open package file: %s. Err: %s", deployArtifact, err.Error())
- return "","Failure", err
+ return "", "Failure", err
}
defer file.Close()
if err != nil {
c.logger.Errorf("failed to upload stream: %s. Err: %s", deployArtifact, err.Error())
- return "","Failure", err
+ return "", "Failure", err
}
defer stream.CloseSend()
req := &lcmservice.InstantiateRequest{
Data: &lcmservice.InstantiateRequest_HostIp{
- HostIp: hostIP,
+ HostIp: hostIP,
},
}
err = stream.Send(req)
if err != nil {
c.logger.Errorf("failed to send metadata information: ", deployArtifact)
- return "","Failure", err
+ return "", "Failure", err
}
// Allocate a buffer with `chunkSize` as the capacity
continue
}
c.logger.Errorf("errored while copying from file to buf: ", err)
- return "","Failure", err
+ return "", "Failure", err
}
- req := &lcmservice.InstantiateRequest {
- Data: &lcmservice.InstantiateRequest_Package {
+ req := &lcmservice.InstantiateRequest{
+ Data: &lcmservice.InstantiateRequest_Package{
Package: buf[:n],
},
}
if err != nil {
c.logger.Errorf("failed to send chunk via stream: ", err)
- return "","Failure", err
+ return "", "Failure", err
}
}
res, err := stream.CloseAndRecv()
if err != nil {
c.logger.Errorf("failed to receive upstream status response: ", err)
- return "","Failure", err
+ return "", "Failure", err
}
c.logger.Infof("Instantiation Completed with workloadId %s and status", res.GetWorkloadId(), res.GetStatus())
return res.GetWorkloadId(), res.GetStatus(), err
func (c *ClientGRPC) Query(ctx context.Context, hostIP string, workloadId string) (status string, error error) {
req := &lcmservice.QueryRequest{
- HostIp: hostIP,
+ HostIp: hostIP,
WorkloadId: workloadId,
}
resp, err := c.client.Query(ctx, req)
func (c *ClientGRPC) Terminate(ctx context.Context, hostIP string, workloadId string) (status string, error error) {
req := &lcmservice.TerminateRequest{
- HostIp: hostIP,
+ HostIp: hostIP,
WorkloadId: workloadId,
}
resp, err := c.client.Terminate(ctx, req)
if c.conn != nil {
c.conn.Close()
}
-}
\ No newline at end of file
+}
package util
import (
- "github.com/sirupsen/logrus"
"os"
+
+ "github.com/sirupsen/logrus"
)
func GetLogger(logFile string, loggerLevel logrus.Level, file *os.File) *logrus.Logger {
logger.SetLevel(loggerLevel)
logger.Infof("logger created")
return logger
-}
\ No newline at end of file
+}
+++ /dev/null
-module applcm
-
-go 1.14
package main
import (
- "github.com/sirupsen/logrus"
"k8shelm/pkg/plugin"
"os"
"strconv"
+
+ "github.com/sirupsen/logrus"
)
// Variables to be defined in deployment file
var (
- serverPort = os.Getenv("HELM_PLUGIN_PORT")
- logFile = os.Getenv("LOGFILE_PATH")
+ serverPort = os.Getenv("HELM_PLUGIN_PORT")
+ logFile = os.Getenv("LOGFILE_PATH")
loggerLevel = os.Getenv("LOGGER_LEVEL")
certificate = os.Getenv("CERTIFICATE_PATH")
- key = os.Getenv("KEY_PATH")
+ key = os.Getenv("KEY_PATH")
)
func main() {
// Create GRPC server
sp, err := strconv.Atoi(serverPort)
- serverConfig := plugin.ServerGRPCConfig{Certificate: certificate, Port:sp, Key:key, Logger:logger}
+ serverConfig := plugin.ServerGRPCConfig{Certificate: certificate, Port: sp, Key: key, Logger: logger}
server := plugin.NewServerGRPC(serverConfig)
// Start listening
import (
context "context"
+ reflect "reflect"
+ sync "sync"
+
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
- reflect "reflect"
- sync "sync"
)
const (
import (
"bytes"
"context"
+ "io"
+ "k8shelm/internal/lcmservice"
+ "net"
+ "os"
+ "strconv"
+
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
_ "google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/status"
- "io"
- "k8shelm/internal/lcmservice"
- "net"
- "os"
- "strconv"
)
// GRPC server
// Create HELM Client
hc, err := NewHelmClient(req.GetHostIp(), s.logger)
if os.IsNotExist(err) {
- return nil, s.logError(status.Errorf(codes.InvalidArgument, "Kubeconfig corresponding to given Edge can't be found. " +
+ return nil, s.logError(status.Errorf(codes.InvalidArgument, "Kubeconfig corresponding to given Edge can't be found. "+
"Err: %s", err))
}
// Query Chart
r, err := hc.queryChart(req.GetWorkloadId())
- if (err != nil) {
+ if err != nil {
return nil, s.logError(status.Errorf(codes.NotFound, "Chart not found for workloadId: %s. Err: %s",
req.GetWorkloadId(), err))
}
// Create HELM client
hc, err := NewHelmClient(req.GetHostIp(), s.logger)
if os.IsNotExist(err) {
- return nil, s.logError(status.Errorf(codes.InvalidArgument, "Kubeconfig corresponding to given Edge can't be found. " +
+ return nil, s.logError(status.Errorf(codes.InvalidArgument, "Kubeconfig corresponding to given Edge can't be found. "+
"Err: %s", err))
}
// Uninstall chart
err = hc.uninstallChart(req.GetWorkloadId())
- if (err != nil) {
+ if err != nil {
resp = &lcmservice.TerminateResponse{
Status: "Failure",
}
s.logger.Infof("Recieved instantiate request")
// Host validation
- if (hostIP == "") {
+ if hostIP == "" {
return s.logError(status.Errorf(codes.InvalidArgument, "HostIP & WorkloadId can't be null", err))
}
// Create HELM client
hc, err := NewHelmClient(req.GetHostIp(), s.logger)
if os.IsNotExist(err) {
- return s.logError(status.Errorf(codes.InvalidArgument, "Kubeconfig corresponding to edge can't be found. " +
+ return s.logError(status.Errorf(codes.InvalidArgument, "Kubeconfig corresponding to edge can't be found. "+
"Err: %s", err))
}
var res lcmservice.InstantiateResponse
res.WorkloadId = relName
- if (err != nil) {
+ if err != nil {
res.Status = "Failure"
s.logger.Infof("Instantiation Failed")
} else {
s.logger.Errorf("Error Information: ", err)
}
return err
-}
\ No newline at end of file
+}
import (
"bytes"
"fmt"
+ "os"
+
"github.com/sirupsen/logrus"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/kube"
- "os"
)
// Variables to be defined in deployment file
var (
- chartPath = os.Getenv("CHART_PATH")
- kubeconfigPath = os.Getenv("KUBECONFIG_DIR_PATH")
+ chartPath = os.Getenv("CHART_PATH")
+ kubeconfigPath = os.Getenv("KUBECONFIG_DIR_PATH")
releaseNamespace = os.Getenv("RELEASE_NAMESPACE")
)
-
// Helm client
type HelmClient struct {
- hostIP string
+ hostIP string
kubeconfig string
- logger *logrus.Logger
+ logger *logrus.Logger
}
// Constructor of helm client for a given host IP
if exists {
return &HelmClient{hostIP: hostIP, kubeconfig: kubeconfigPath + hostIP, logger: logger}, nil
} else {
- logger.Errorf("No file exist with name: %s. Err: %s", kubeconfigPath + hostIP)
+ logger.Errorf("No file exist with name: %s. Err: %s", kubeconfigPath+hostIP)
return nil, err
}
}
// Create temporary file to hold helm chart
file, err := os.Create(chartPath + "temp.tar.gz")
if err != nil {
- hc.logger.Errorf("Unable to create file: %s. Err: %s", chartPath + "temp.tar.gz", err)
+ hc.logger.Errorf("Unable to create file: %s. Err: %s", chartPath+"temp.tar.gz", err)
return "", err
}
defer os.Remove(chartPath + "temp.tar.gz")
// Write input bytes to temp file
_, err = helmPkg.WriteTo(file)
if err != nil {
- hc.logger.Errorf("Unable to write to file: %s. Err: %s", chartPath + "temp.tar.gz", err)
+ hc.logger.Errorf("Unable to write to file: %s. Err: %s", chartPath+"temp.tar.gz", err)
return "", err
}
// Load the file to chart
chart, err := loader.Load(chartPath + "temp.tar.gz")
if err != nil {
- hc.logger.Errorf("Unable to load chart from file: %s. Err: %s", chartPath + "temp.tar.gz", err)
+ hc.logger.Errorf("Unable to load chart from file: %s. Err: %s", chartPath+"temp.tar.gz", err)
return "", err
}
}
// Un-Install a given helm chart
-func (hc *HelmClient) uninstallChart(relName string) (error) {
+func (hc *HelmClient) uninstallChart(relName string) error {
// Prepare action config and uninstall chart
actionConfig := new(action.Configuration)
if err := actionConfig.Init(kube.GetConfig(hc.kubeconfig, "", releaseNamespace), releaseNamespace,
}
ui := action.NewUninstall(actionConfig)
- res, err := ui.Run(relName);
+ res, err := ui.Run(relName)
if err != nil {
hc.logger.Errorf("Unable to uninstall chart with release name: %s. Err: %s", relName, err)
return err
}
// Query a given chart
-func (hc *HelmClient) queryChart(relName string) (string, error) {
+func (hc *HelmClient) queryChart(relName string) (string, error) {
actionConfig := new(action.Configuration)
if err := actionConfig.Init(kube.GetConfig(hc.kubeconfig, "", releaseNamespace), releaseNamespace,
os.Getenv("HELM_DRIVER"), func(format string, v ...interface{}) {
return false, err
}
return !info.IsDir(), nil
-}
\ No newline at end of file
+}
package plugin
import (
- "github.com/sirupsen/logrus"
"os"
+
+ "github.com/sirupsen/logrus"
)
func GetLogger(logFile string, loggerLevel logrus.Level, file *os.File) *logrus.Logger {
logger.SetLevel(loggerLevel)
logger.Infof("logger created")
return logger
-}
\ No newline at end of file
+}
name: my-db
volumes:
- name: my-db
- persistentVolumeClaim:
- claimName: my-db
+ hostPath:
+ # data folder needs to be created in host machine
+ path: /data
+
# dbhost service
---
apiVersion: v1