-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtopo_output.go
89 lines (78 loc) · 3.5 KB
/
topo_output.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France.
//
// 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 deployments
import (
"context"
"github.com/ystia/yorc/v4/storage"
"github.com/ystia/yorc/v4/storage/types"
"github.com/ystia/yorc/v4/tosca"
"path"
"github.com/pkg/errors"
"github.com/ystia/yorc/v4/helper/consulutil"
)
func getParameterDefinition(ctx context.Context, deploymentID, parameterName, parameterType string) (bool, *tosca.ParameterDefinition, error) {
valuePath := path.Join(consulutil.DeploymentKVPrefix, deploymentID, "topology", parameterType, parameterName)
parameterDef := new(tosca.ParameterDefinition)
exist, err := storage.GetStore(types.StoreTypeDeployment).Get(valuePath, parameterDef)
if err != nil {
return false, nil, err
}
return exist, parameterDef, nil
}
// GetTopologyInputParameter returns the definition of a topology input parameter
func GetTopologyInputParameter(ctx context.Context, deploymentID, parameterName string) (bool, *tosca.ParameterDefinition, error) {
return getParameterDefinition(ctx, deploymentID, parameterName, "inputs")
}
// GetTopologyInputsNames returns the list of inputs for the deployment
func GetTopologyInputsNames(ctx context.Context, deploymentID string) ([]string, error) {
optPaths, err := storage.GetStore(types.StoreTypeDeployment).Keys(path.Join(consulutil.DeploymentKVPrefix, deploymentID, "/topology/inputs"))
if err != nil {
return nil, errors.Wrap(err, consulutil.ConsulGenericErrMsg)
}
for i := range optPaths {
optPaths[i] = path.Base(optPaths[i])
}
return optPaths, nil
}
// GetTopologyOutputValue returns the value of a given topology output
func GetTopologyOutputValue(ctx context.Context, deploymentID, outputName string, nestedKeys ...string) (*TOSCAValue, error) {
dataType, err := GetTopologyOutputType(ctx, deploymentID, outputName)
if err != nil {
return nil, err
}
exist, paramDef, err := getParameterDefinition(ctx, deploymentID, outputName, "outputs")
if err != nil || !exist {
return nil, err
}
// TODO this is not clear in the specification but why do we return a single value in this context as in case of attributes and multi-instances
// we can have different results.
// We have to improve this.
res, err := getValueAssignment(ctx, deploymentID, "", "0", "", dataType, paramDef.Value, nestedKeys...)
if err != nil || res != nil {
return res, err
}
// check the default
return getValueAssignment(ctx, deploymentID, "", "0", "", dataType, paramDef.Default, nestedKeys...)
}
// GetTopologyOutputsNames returns the list of outputs for the deployment
func GetTopologyOutputsNames(ctx context.Context, deploymentID string) ([]string, error) {
optPaths, err := storage.GetStore(types.StoreTypeDeployment).Keys(path.Join(consulutil.DeploymentKVPrefix, deploymentID, "/topology/outputs"))
if err != nil {
return nil, errors.Wrap(err, consulutil.ConsulGenericErrMsg)
}
for i := range optPaths {
optPaths[i] = path.Base(optPaths[i])
}
return optPaths, nil
}