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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
package org.openecomp.sdc.toscaparser.api.functions;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import org.openecomp.sdc.toscaparser.api.DataEntity;
import org.openecomp.sdc.toscaparser.api.TopologyTemplate;
import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.parameters.Input;
public class GetInput extends Function {
public GetInput(TopologyTemplate toscaTpl,Object context,String name,ArrayList<Object> _args) {
super(toscaTpl,context,name,_args);
}
@Override
void validate() {
if(args.size() != 1) {
//ERROR under investigation
ExceptionCollector.appendWarning(String.format(
"ValueError: Expected one argument for function \"get_input\" but received \"%s\"",
args.toString()));
}
boolean bFound = false;
for(Input inp: toscaTpl.getInputs()) {
if(inp.getName().equals(args.get(0))) {
bFound = true;
break;
}
}
if(!bFound) {
ExceptionCollector.appendException(String.format(
"UnknownInputError: Unknown input \"%s\"",args.get(0)));
}
}
public Object result() {
if(toscaTpl.getParsedParams() != null &&
toscaTpl.getParsedParams().get(getInputName()) != null) {
LinkedHashMap<String,Object> ttinp = (LinkedHashMap<String,Object>)toscaTpl.getTpl().get("inputs");
LinkedHashMap<String,Object> ttinpinp = (LinkedHashMap<String,Object>)ttinp.get(getInputName());
String type = (String)ttinpinp.get("type");
return DataEntity.validateDatatype(
type, toscaTpl.getParsedParams().get(getInputName()),null,null,null);
}
Input inputDef = null;
for(Input inpDef: toscaTpl.getInputs()) {
if(getInputName().equals(inpDef.getName())) {
inputDef = inpDef;
break;
}
}
if(inputDef != null) {
return inputDef.getDefault();
}
return null;
}
public String getInputName() {
return (String)args.get(0);
}
}
/*python
class GetInput(Function):
"""Get a property value declared within the input of the service template.
Arguments:
* Input name.
Example:
* get_input: port
"""
def validate(self):
if len(self.args) != 1:
ExceptionCollector.appendException(
ValueError(_(
'Expected one argument for function "get_input" but '
'received "%s".') % self.args))
inputs = [input.name for input in self.tosca_tpl.inputs]
if self.args[0] not in inputs:
ExceptionCollector.appendException(
UnknownInputError(input_name=self.args[0]))
def result(self):
if self.tosca_tpl.parsed_params and \
self.input_name in self.tosca_tpl.parsed_params:
return DataEntity.validate_datatype(
self.tosca_tpl.tpl['inputs'][self.input_name]['type'],
self.tosca_tpl.parsed_params[self.input_name])
input = [input_def for input_def in self.tosca_tpl.inputs
if self.input_name == input_def.name][0]
return input.default
@property
def input_name(self):
return self.args[0]
*/
|