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 model "ealt/cmd/model"
28 func BuilderRequest(valueArgs []string, command string) error {
33 case "NewAppCreateCommand":
35 //ealtedge/mepm/app_pkgm/v1/app_packages/
36 //read the file from the system.
37 URIString = common.AppmUriCreate
38 var packageName string
40 body = jsonEmptyBodyFormat()
41 packageName = strings.TrimSpace(valueArgs[0])
42 HttpMultiPartPostRequestBuilder(URIString, body, packageName)
44 case "NewAppInfoCommand":
45 URIString = common.AppmUri
47 URIString = common.AppmUri + strings.TrimSpace(valueArgs[0])
48 body = jsonEmptyBodyFormat()
49 HttpGetRequestBuilder(URIString, body)
51 case "NewAppDeleteCommand":
52 //The Delete Application Package URI
53 //ealtedge/mepm/app_pkgm/v1/app_packages/{{ID}}
55 URIString = common.AppmUri + strings.TrimSpace(valueArgs[0])
56 body = jsonEmptyBodyFormat()
57 HttpDeleteRequestBuilder(URIString, body)
59 case "NewApplcmCreateCommand":
60 //appLCM application Creation URI
61 //ealtedge/mepm/app_lcm/v1/app_instances
64 URIString = common.ApplcmUriCreate
65 //Assigning the AppLcm Create Command Line Flags to the Json Paylod.
66 payload := model.CreateApplicationReq{AppDID: strings.TrimSpace(valueArgs[0]),
67 AppInstancename: strings.TrimSpace(valueArgs[1]),
68 AppInstanceDescriptor: strings.TrimSpace(valueArgs[2])}
69 body, err := json.Marshal(payload)
74 HttpPostRequestBuilder(URIString, body)
76 case "NewApplcmInfoCommand":
77 //appLCM Get Application URI
78 ///ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}
80 URIString = common.ApplcmUri + strings.TrimSpace(valueArgs[0])
82 //Empty body for Delete Command.
83 body = jsonEmptyBodyFormat()
84 HttpGetRequestBuilder(URIString, body)
86 case "NewApplcmDeleteCommand":
87 //appLCM Delete Application URI
88 ///ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}
90 URIString = common.ApplcmUri + strings.TrimSpace(valueArgs[0])
92 //Empty body for Delete Command.
93 body = jsonEmptyBodyFormat()
94 HttpDeleteRequestBuilder(URIString, body)
96 case "NewApplcmStartCommand":
97 //applcm application instantiate uri
98 //ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}/instantiate
101 URIString = common.ApplcmUri + strings.TrimSpace(valueArgs[0]) + common.InstantiateUri
103 selectedMECHostInfo := model.SelectedMECHostInfo{HostName: strings.TrimSpace(valueArgs[1]),
104 HostId: strings.TrimSpace(valueArgs[2])}
106 payload := model.InstantiateApplicationReq{SelectedMECHostInfo: selectedMECHostInfo}
107 body, err := json.Marshal(payload)
111 HttpPostRequestBuilder(URIString, body)
113 case "NewApplcmTerminateCommand":
114 //applcm application terminate uri
115 //ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}/terminate
117 URIString = common.ApplcmUri + strings.TrimSpace(valueArgs[0]) + common.TerminateUri
118 body = jsonEmptyBodyFormat()
119 HttpPostRequestBuilder(URIString, body)
124 func jsonEmptyBodyFormat() []byte {
126 jsonstr = []byte(`{"":""}`)