import (
"ealt/cmd/common"
+ model "ealt/cmd/model"
"encoding/json"
"fmt"
"log"
//Onboard Command
//ealtedge/mepm/app_pkgm/v1/app_packages/
//read the file from the system.
- URIString = common.AppmUri
+ URIString = common.AppmUriCreate
var packageName string
var body []byte
body = jsonEmptyBodyFormat()
packageName = strings.TrimSpace(valueArgs[0])
HttpMultiPartPostRequestBuilder(URIString, body, packageName)
- fmt.Println(packageName)
case "NewAppDeleteCommand":
//The Delete Application Package URI
var body []byte
URIString = common.AppmUri + strings.TrimSpace(valueArgs[0])
body = jsonEmptyBodyFormat()
- fmt.Println(URIString)
HttpDeleteRequestBuilder(URIString, body)
- fmt.Println(URIString)
-
case "NewApplcmCreateCommand":
//appLCM application Creation URI
//ealtedge/mepm/app_lcm/v1/app_instances
var body []byte
- URIString = common.ApplcmUri
- body, err := json.Marshal(map[string]string{
- "appDId": strings.TrimSpace(valueArgs[0]),
- "appInstancename": strings.TrimSpace(valueArgs[1]),
- "appInstanceDescriptor": strings.TrimSpace(valueArgs[2]),
- })
+ URIString = common.ApplcmUriCreate
+ //Assigning the AppLcm Create Command Line Flags to the Json Paylod.
+ payload := model.CreateApplicationReq{AppDID: strings.TrimSpace(valueArgs[0]),
+ AppInstancename: strings.TrimSpace(valueArgs[1]),
+ AppInstanceDescriptor: strings.TrimSpace(valueArgs[2])}
+ body, err := json.Marshal(payload)
if err != nil {
log.Fatalln(err)
}
- fmt.Println(URIString)
HttpPostRequestBuilder(URIString, body)
case "NewApplcmDeleteCommand":
///ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}
var body []byte
URIString = common.ApplcmUri + strings.TrimSpace(valueArgs[0])
+
+ //Empty body for Delete Command.
body = jsonEmptyBodyFormat()
- fmt.Println(URIString)
HttpDeleteRequestBuilder(URIString, body)
case "NewApplcmStartCommand":
var body []byte
URIString = common.ApplcmUri + strings.TrimSpace(valueArgs[0]) + common.InstantiateUri
- body = jsonEmptyBodyFormat()
- fmt.Println(URIString)
+
+ selectedMECHostInfo := model.SelectedMECHostInfo{HostName: strings.TrimSpace(valueArgs[1]),
+ HostId: strings.TrimSpace(valueArgs[2])}
+ //Payload
+ payload := model.InstantiateApplicationReq{SelectedMECHostInfo: selectedMECHostInfo}
+ body, err := json.Marshal(payload)
+ if err != nil {
+ fmt.Println(err)
+ }
HttpPostRequestBuilder(URIString, body)
case "NewApplcmTerminateCommand":
var body []byte
URIString = common.ApplcmUri + strings.TrimSpace(valueArgs[0]) + common.TerminateUri
body = jsonEmptyBodyFormat()
- fmt.Println(URIString)
HttpPostRequestBuilder(URIString, body)
-
}
-
return nil
}
import (
"bytes"
"ealt/cmd/common"
- "encoding/json"
"fmt"
"io"
"io/ioutil"
func httpEndPointBuider(uri string) string {
- return "http://" + strings.TrimSpace(MECMClusterIP) + strings.TrimSpace(APPLCMPort) + uri
+ return "http://" + strings.TrimSpace(MECMClusterIP) + ":" + strings.TrimSpace(APPLCMPort) + uri
}
func HttpDeleteRequestBuilder(uri string, body []byte) {
uri = httpEndPointBuider(uri)
+ fmt.Println("Request URL :\t" + uri)
request, err := http.NewRequest(http.MethodDelete, uri, bytes.NewBuffer(body))
request.Header.Set("Content-Type", "application/json")
if err != nil {
log.Fatalln(err)
}
-
response, err := client.Do(request)
if err != nil {
log.Fatalln(err)
log.Fatalln(err)
}
- fmt.Println(string(output))
+ fmt.Println("Response Data: \n" + string(output))
}
func HttpPostRequestBuilder(uri string, body []byte) error {
uri = httpEndPointBuider(uri)
+ fmt.Println("Request URL :\t" + uri)
+ fmt.Println("Request Body :\t" + string(body) + "\n")
request, err := http.NewRequest(http.MethodPost, uri, bytes.NewBuffer(body))
request.Header.Set("Content-Type", "application/json")
- fmt.Println(request)
+ //fmt.Println(request)
if err != nil {
log.Fatalln(err)
}
-
response, err := client.Do(request)
if err != nil {
log.Fatalln(err)
log.Fatalln(err)
}
- fmt.Println(string(output))
+ fmt.Println("Response Data: \n\n" + string(output))
return nil
}
func HttpMultiPartPostRequestBuilder(uri string, body []byte, file string) error {
filepath := getFilePathWithName(file)
+ fmt.Println("File Path :" + filepath)
uri = httpEndPointBuider(uri)
-
+ fmt.Println("Request URL :\t" + uri)
request, err := fileUploadRequest(uri, "file", filepath)
+ if err != nil {
+ log.Fatalln(err)
+ }
response, err := client.Do(request)
if err != nil {
log.Fatalln(err)
+ } else {
+ body := &bytes.Buffer{}
+ _, err := body.ReadFrom(response.Body)
+ if err != nil {
+ log.Fatal(err)
+ }
+ response.Body.Close()
+ fmt.Println(response.StatusCode)
+ fmt.Println(response.Header)
+
+ // fmt.Println(body)
+ // var result map[string]interface{}
+ // json.NewDecoder(response.Body).Decode(&result)
+ // fmt.Println(result)
}
- var result map[string]interface{}
- json.NewDecoder(response.Body).Decode(&result)
- fmt.Println(result)
-
return nil
}
if err != nil {
log.Fatalln(err)
}
- request.Header.Set("Content-Type", "multipart/form-data")
+ request.Header.Add("Content-Type", multiPartWriter.FormDataContentType())
+ //request.Header.Set("Content-Type", "multipart/form-data")
return request, err
}
package cmd
import (
- "fmt"
-
appCmds "ealt/cmd/appm"
"github.com/spf13/cobra"
Use: "app",
Short: "The command is used for Application Management in the EALT Edge System.",
Long: `The command is used for Application Management in the EALT Edge System.
- It has multiple options like create , delete`,
- Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("app called")
- },
+ It has options: create , delete`,
}
func init() {
package cmd
import (
- "fmt"
-
applcmCmds "ealt/cmd/applcmpkg"
"github.com/spf13/cobra"
2. Start
3. Delete
4. Stop.`,
- Run: func(cmd *cobra.Command, args []string) {
- fmt.Println("applcm called")
- },
}
func init() {
func NewApplcmDeleteCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "delete",
- Short: "Install Complete EALT Deployment Environment",
- Long: `Install Complete EALT Deployment Environment`,
+ Short: "Delete the application from the MEP Node.",
+ Long: `Delete the application from the MEP Node.`,
RunE: func(cmd *cobra.Command, args []string) error {
- var theFlags []string
- theFlags[0] = cmd.Flag("appid").Value.String()
-
+ theFlags := []string{cmd.Flag("appid").Value.String()}
err := adapter.BuilderRequest(theFlags, "NewApplcmDeleteCommand")
if err != nil {
return err
import (
"ealt/cmd/adapter"
- "fmt"
"github.com/spf13/cobra"
)
Short: "To start the application instance on MEP Node",
Long: `To start the application instance on MEP Node`,
RunE: func(cmd *cobra.Command, args []string) error {
- theFlags := []string{cmd.Flag("appid").Value.String()}
- //theFlags[0] = cmd.Flag("appid").Value.String()
- fmt.Println(theFlags[0])
+ theFlags := []string{cmd.Flag("appid").Value.String(),
+ cmd.Flag("hostname").Value.String(),
+ cmd.Flag("hostip").Value.String()}
err := adapter.BuilderRequest(theFlags, "NewApplcmStartCommand")
if err != nil {
return err
},
}
cmd.Flags().StringP("appid", "i", "", "Application Instance ID to be started")
+ cmd.Flags().StringP("hostname", "n", "", "Host Name where the App has to be instantiated")
+ cmd.Flags().StringP("hostip", "o", "", "Host IP / MEP Node IP")
cmd.MarkFlagRequired("appid")
+ cmd.MarkFlagRequired("hostname")
+ cmd.MarkFlagRequired("hostip")
return cmd
}
func NewApplcmTerminateCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "kill",
- Short: "To kill the application ",
- Long: `Install Complete EALT Deployment Environment`,
+ Short: "To terminate the application instance id.",
+ Long: `To terminate the application instance id on MEP Node.`,
RunE: func(cmd *cobra.Command, args []string) error {
- var theFlags []string
- theFlags[0] = cmd.Flag("appid").Value.String()
+ theFlags := []string{cmd.Flag("appid").Value.String()}
err := adapter.BuilderRequest(theFlags, "NewApplcmTerminateCommand")
if err != nil {
return err
return nil
},
}
-
cmd.Flags().StringP("appid", "i", "", "Application Instance ID to be terminated")
cmd.MarkFlagRequired("appid")
-
return cmd
}
Short: "To create the application on MEP Node",
Long: `To create the application on MEP Node`,
RunE: func(cmd *cobra.Command, args []string) error {
- var theFlags []string
- theFlags[0] = cmd.Flag("packagefile").Value.String()
+ theFlags := []string{cmd.Flag("packagefile").Value.String()}
err := adapter.BuilderRequest(theFlags, "NewAppCreateCommand")
if err != nil {
return err
func NewAppDeleteCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "delete",
- Short: "Install Complete EALT Deployment Environment",
- Long: `Install Complete EALT Deployment Environment`,
+ Short: "Remove the Application Package from the MECM Host.",
+ Long: `Remove the Application Package from the MECM Host.`,
RunE: func(cmd *cobra.Command, args []string) error {
- var theFlags []string
- theFlags[0] = cmd.Flag("pkgid").Value.String()
+ theFlags := []string{cmd.Flag("packageid").Value.String()}
err := adapter.BuilderRequest(theFlags, "NewAppDeleteCommand")
if err != nil {
return err
package common
const (
- AppmUri = "/ealtedge/mepm/app_pkgm/v1/app_packages/"
- ApplcmUri = "/ealtedge/mepm/app_lcm/v1/app_instances/"
+ AppmUri = "/ealtedge/mepm/app_pkgm/v1/app_packages/"
+ AppmUriCreate = "/ealtedge/mepm/app_pkgm/v1/app_packages"
+ ApplcmUri = "/ealtedge/mepm/app_lcm/v1/app_instances/"
+ ApplcmUriCreate = "/ealtedge/mepm/app_lcm/v1/app_instances"
InstantiateUri = "/instantiate"
TerminateUri = "/terminate"
--- /dev/null
+/*
+Copyright © 2020 NAME HERE <EMAIL ADDRESS>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+package model
+
+type InstantiateApplicationReq struct {
+ SelectedMECHostInfo SelectedMECHostInfo `json:"selectedMECHostInfo"`
+}
+
+type SelectedMECHostInfo struct {
+ HostName string `json:"hostName"`
+ HostId string `json:"hostId"`
+}
+type CreateApplicationReq struct {
+ AppDID string `json:"appDId"`
+ AppInstancename string `json:"appInstancename"`
+ AppInstanceDescriptor string `json:"appInstanceDescriptor"`
+}