packageName = strings.TrimSpace(valueArgs[0])
HttpMultiPartPostRequestBuilder(URIString, body, packageName)
+ case "NewAppInfoCommand":
+ URIString = common.AppmUri
+ var body []byte
+ URIString = common.AppmUri + strings.TrimSpace(valueArgs[0])
+ body = jsonEmptyBodyFormat()
+ HttpGetRequestBuilder(URIString, body)
+
case "NewAppDeleteCommand":
//The Delete Application Package URI
//ealtedge/mepm/app_pkgm/v1/app_packages/{{ID}}
}
HttpPostRequestBuilder(URIString, body)
+ case "NewApplcmInfoCommand":
+ //appLCM Get Application URI
+ ///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()
+ HttpGetRequestBuilder(URIString, body)
+
case "NewApplcmDeleteCommand":
//appLCM Delete Application URI
///ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}
import (
"bytes"
"ealt/cmd/common"
+ "encoding/json"
"fmt"
"io"
"io/ioutil"
}
-func HttpDeleteRequestBuilder(uri string, body []byte) {
+//Function to build the Get Requests for Application Package
+//Management and Application Life Cycle Management.
+func HttpGetRequestBuilder(uri string, body []byte) {
uri = httpEndPointBuider(uri)
fmt.Println("Request URL :\t" + uri)
- request, err := http.NewRequest(http.MethodDelete, uri, bytes.NewBuffer(body))
+ request, err := http.NewRequest(http.MethodGet, uri, bytes.NewBuffer(body))
request.Header.Set("Content-Type", "application/json")
if err != nil {
if err != nil {
log.Fatalln(err)
}
-
fmt.Println("Response Data: \n" + string(output))
+}
+
+//HTTP DELETE Message Builder
+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)
+ }
+ defer response.Body.Close()
+ output, err := ioutil.ReadAll(response.Body)
+ if err != nil {
+ log.Fatalln(err)
+ }
+ fmt.Println("Response Data: \n" + string(output))
}
func HttpPostRequestBuilder(uri string, body []byte) error {
request, err := http.NewRequest(http.MethodPost, uri, bytes.NewBuffer(body))
request.Header.Set("Content-Type", "application/json")
- //fmt.Println(request)
-
if err != nil {
log.Fatalln(err)
}
fmt.Println("File Path :" + filepath)
uri = httpEndPointBuider(uri)
fmt.Println("Request URL :\t" + uri)
- request, err := fileUploadRequest(uri, "file", filepath)
+ request, err := fileUploadRequest(uri, "file", filepath, file)
if err != nil {
log.Fatalln(err)
}
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)
- }
+ fmt.Println("Response Body:")
+ fmt.Println(body)
+ var result map[string]interface{}
+ json.NewDecoder(response.Body).Decode(&result)
+
+ fmt.Println("ID has to be send in Create Application Instance Request")
+ }
return nil
}
return ONBOARDPACKAGEPATH + common.PATHSLASH + file
}
-func fileUploadRequest(uri string, paramName, filepath string) (*http.Request, error) {
+func fileUploadRequest(uri string, paramName, filepath, filename string) (*http.Request, error) {
file, err := os.Open(filepath)
if err != nil {
defer file.Close()
//Buffer to store the request body as bytes
- var requestBody bytes.Buffer
- multiPartWriter := multipart.NewWriter(&requestBody)
+ //var requestBody bytes.Buffer
+ requestBody := &bytes.Buffer{}
+ multiPartWriter := multipart.NewWriter(requestBody)
- fileWriter, err := multiPartWriter.CreateFormFile("file_field", filepath)
+ fileWriter, err := multiPartWriter.CreateFormFile(paramName, filename)
if err != nil {
log.Fatalln(err)
}
//Close multiwriter
multiPartWriter.Close()
+ if err != nil {
+ return nil, err
+ }
+
+ request, err := http.NewRequest(http.MethodPost, uri, requestBody)
+ request.Header.Set("Content-Type", multiPartWriter.FormDataContentType())
+ //request.Header.Set("Content-Type", "multipart/form-data")
- request, err := http.NewRequest(http.MethodPost, uri, &requestBody)
if err != nil {
log.Fatalln(err)
}
- request.Header.Add("Content-Type", multiPartWriter.FormDataContentType())
- //request.Header.Set("Content-Type", "multipart/form-data")
+
return request, err
}
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 options: create , delete`,
+ It has options: create , info and delete`,
}
func init() {
appCmd.AddCommand(appCmds.NewAppCreateCommand())
appCmd.AddCommand(appCmds.NewAppDeleteCommand())
+ appCmd.AddCommand(appCmds.NewAppInfoCommand())
rootCmd.AddCommand(appCmd)
}
some API which can be used to manage the Applicaton running on the MEP Node
The command have following options :
1. Create
- 2. Start
- 3. Delete
- 4. Stop.`,
+ 2. Info
+ 3. Start
+ 4. Delete
+ 5. Stop.`,
}
func init() {
applcmCmd.AddCommand(applcmCmds.NewApplcmStartCommand())
applcmCmd.AddCommand(applcmCmds.NewApplcmDeleteCommand())
applcmCmd.AddCommand(applcmCmds.NewApplcmTerminateCommand())
+ applcmCmd.AddCommand(applcmCmds.NewApplcmInfoCommand())
rootCmd.AddCommand(applcmCmd)
},
}
- cmd.Flags().StringP("appid", "i", "", "Application Instance ID to be started")
+ cmd.Flags().StringP("appid", "i", "", "Application Instance ID to be Deleted!!")
cmd.MarkFlagRequired("appid")
return cmd
}
--- /dev/null
+/*
+Copyright 2020 Huawei Technologies Co., Ltd.
+
+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 applcmpkg
+
+import (
+ "ealt/cmd/adapter"
+
+ "github.com/spf13/cobra"
+)
+
+// allCmd represents the all command
+func NewApplcmInfoCommand() *cobra.Command {
+ var cmd = &cobra.Command{
+ Use: "info",
+ Short: "Get the Application Instance Details..",
+ Long: `The command display the details of the Application Instance running on the MEP Host.`,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ theFlags := []string{cmd.Flag("appid").Value.String()}
+ err := adapter.BuilderRequest(theFlags, "NewApplcmInfoCommand")
+ if err != nil {
+ return err
+ }
+ return nil
+ },
+ }
+
+ cmd.Flags().StringP("appid", "i", "", "Application Instance ID for which details are to be fetched")
+ cmd.MarkFlagRequired("appid")
+ return cmd
+}
func NewApplcmTerminateCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "kill",
- Short: "To terminate the application instance id.",
- Long: `To terminate the application instance id on MEP Node.`,
+ Short: "To terminate the application instance.",
+ Long: `To terminate the application instance on MEP Node.`,
RunE: func(cmd *cobra.Command, args []string) error {
theFlags := []string{cmd.Flag("appid").Value.String()}
err := adapter.BuilderRequest(theFlags, "NewApplcmTerminateCommand")
--- /dev/null
+/*
+Copyright 2020 Huawei Technologies Co., Ltd.
+
+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 appm
+
+import (
+ "ealt/cmd/adapter"
+
+ "github.com/spf13/cobra"
+)
+
+// allCmd represents the all command
+func NewAppInfoCommand() *cobra.Command {
+ var cmd = &cobra.Command{
+ Use: "info",
+ Short: "Get Information on the Onbarded Application.",
+ Long: `Get Information on the Onbarded Application.`,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ theFlags := []string{cmd.Flag("packageid").Value.String()}
+ err := adapter.BuilderRequest(theFlags, "NewAppInfoCommand")
+ if err != nil {
+ return err
+ }
+ return nil
+ },
+ }
+
+ cmd.Flags().StringP("packageid", "i", "", "Application Package ID which is onbarded")
+ cmd.MarkFlagRequired("packageid")
+
+ return cmd
+}
return nil
},
}
- cmd.Flags().StringP("packagefile", "f", "", "Application Package File to be onboarded to MEP")
+ cmd.Flags().StringP("packagefile", "f", "", "Application Package File to be onboarded.")
cmd.MarkFlagRequired("packagefile")
return cmd
}