aboutsummaryrefslogtreecommitdiffstats
path: root/platform-logic/generic-resource-api/src/main/xml/GENERIC-RESOURCE-API_naming-policy-generate-unique-name.xml
blob: 23aece7c6b05900a9dcd0327af5df5b3224855e8 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<service-logic
    xmlns='http://www.onap.org/sdnc/svclogic'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.onap.org/sdnc/svclogic ./svclogic.xsd' module='GENERIC-RESOURCE-API' version='${project.version}'>
    <method rpc='naming-policy-generate-unique-name' mode='sync'>
        <block atomic="true">
            <switch test='`$generate-unique-name-input.action`'>
                <outcome value=''>
                    <return status='failure'>
                        <parameter name='generate-unique-name-output.error-message' value='generate-unique-name-input.action not supplied' />
                    </return>
                </outcome>
                <outcome value='ASSIGN'>
                    <block atomic="true">
                        <switch test='`$generate-unique-name-input.context-id`'>
                            <outcome value=''>
                                <return status='failure'>
                                    <parameter name='error-message' 
	value="generate-unique-name-input.context-id cannot be null for ASSIGN action" />
                                </return>
                            </outcome>
                        </switch>
                        <switch test='`$generate-unique-name-input.name-table-type`'>
                            <outcome value=''>
                                <return status='failure'>
                                    <parameter name='generate-unique-name-output.error-message' value='generate-unique-name-input.name-table-type not supplied' />
                                </return>
                            </outcome>
                            <outcome value='VNF_INSTANCE'>
                                <set>
                                    <parameter name='tmp.gname.custom-query-string' value='nodes/generic-vnfs?vnf-name=' />
                                </set>
                            </outcome>
                            <outcome value='VM_INSTANCE'>
                                <set>
                                    <parameter name='tmp.gname.custom-query-string' value='nodes/vservers?vserver-name=' />
                                </set>
                            </outcome>
                            <outcome value='NETWORK_INSTANCE'>
                                <set>
                                    <parameter name='tmp.gname.custom-query-string' value='nodes/l3-networks?network-name=' />
                                </set>
                            </outcome>
                            <outcome value='SERVICE_INSTANCE'>
                                <set>
                                    <parameter name='tmp.gname.custom-query-string' value='nodes/service-instances?service-instance-name=' />
                                </set>
                            </outcome>
                            <outcome value='VNFC_INSTANCE'>
                                <set>
                                    <parameter name='tmp.gname.custom-query-string' value='nodes/vnfcs?vnfc-name=' />
                                </set>
                            </outcome>
                        </switch>
                        <set>
                            <parameter name='tmp.gun.nononap' value='NON-ONAP' />
                        </set>
                        <set>
                            <parameter name='tmp.gun.transient' value='TRANSIENT' />
                        </set>
                        <set>
                            <parameter name='tmp.grn.loop.flag' value='true' />
                        </set>
                        <while test='`$tmp.grn.loop.flag`'>
                            <block atomic="true">
                                <call module='GENERIC-RESOURCE-API' rpc='generate-unique-name' mode='sync' >
                                    <outcome value='failure'>
                                        <block atomic="true">
                                            <set>
                                                <parameter name='tmp.grn.loop.flag' value='false' />
                                            </set>
                                            <return status='failure'>
                                                <parameter name='error-message' 
	value="`'Encountered error in naming-policy-generate-unique-name: ' + 
		$generate-unique-name-output.error-message`" />
                                            </return>
                                        </block>
                                    </outcome>
                                </call>
                                <execute plugin="org.onap.ccsdk.sli.core.slipluginutils.SliStringUtils" method="urlEncode">
                                    <parameter name="source" value='`$generate-unique-name-output.generated-name`'/>
                                    <parameter name="outputPath" value="encoded-name" />
                                </execute>
                                <save plugin="org.onap.ccsdk.sli.adaptors.aai.AAIService" 
	resource="custom-query"
      key="format = 'resource'"
      force="true"
      local-only="false"
      pfx="tmp.nodes-query">
                                    <parameter name="start[0]" value="`$tmp.gname.custom-query-string + 
			$encoded-name`" />
                                    <parameter name="start_length" value="1" />
                                    <outcome value='not-found'>
                                        <set>
                                            <parameter name='tmp.grn.loop.flag' value='false' />
                                        </set>
                                    </outcome>
                                    <outcome value='failure'>
                                        <block atomic='true'>
                                            <set>
                                                <parameter name='tmp.grn.loop.flag' value='false' />
                                            </set>
                                            <return status='failure'>
                                                <parameter name='error-message' 
	value="`'Error updating GENERIC_RESOURCE_NAME.context_id from TRANSIENT to ' 
		+ $tmp.context-id.nononap`" />
                                            </return>
                                        </block>
                                    </outcome>
                                    <outcome value='success'>
                                        <update plugin='org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource' resource='SQL'
	key="update GENERIC_RESOURCE_NAME set context_id = $tmp.gun.nononap  
		WHERE type = $generate-unique-name-input.name-table-type 
		AND context_id = $tmp.gun.transient">
                                            <outcome value='failure'>
                                                <return status='failure'>
                                                    <parameter name='error-message' 
	value="`'Error updating GENERIC_RESOURCE_NAME.context_id from TRANSIENT to ' 
		+ $tmp.context-id.nononap`" />
                                                </return>
                                            </outcome>
                                            <outcome value='not-found'>
                                                <return status='failure'>
                                                    <parameter name='error-message' 
	value="`'No GENERIC_RESOURCE_NAME found with context_id = TRANSIENT and type = ' 
		+ $generate-unique-name-input.name-table-type`"/>
                                                </return>
                                            </outcome>
                                        </update>
                                    </outcome>
                                </save>
                            </block>
                        </while>
                        <update plugin='org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource' resource='SQL'
	key="update GENERIC_RESOURCE_NAME set context_id = $generate-unique-name-input.context-id   
		WHERE type = $generate-unique-name-input.name-table-type 
		AND name = $generate-unique-name-output.generated-name 
		AND context_id = $tmp.gun.transient">
                            <outcome value='failure'>
                                <return status='failure'>
                                    <parameter name='error-message' 
	value="`'Error updating GENERIC_RESOURCE_NAME.context_id from TRANSIENT to ' 
		+ $tmp.context-id.nononap`" />
                                </return>
                            </outcome>
                            <outcome value='not-found'>
                                <return status='failure'>
                                    <parameter name='error-message' 
	value="`'No GENERIC_RESOURCE_NAME found with context_id = TRANSIENT and type = ' 
		+ $generate-unique-name-input.name-table-type`"/>
                                </return>
                            </outcome>
                        </update>
                    </block>
                </outcome>
                <outcome value='DELETE'>
                    <block atomic='true'>
                        <set>
                            <parameter name='rollback-generated-names-input.naming-type' value='`$generate-unique-name-input.name-table-type`' />
                        </set>
                        <set>
                            <parameter name='rollback-generated-names-input.context-id' value='`$generate-unique-name-input.context-id`' />
                        </set>
                        <call module='GENERIC-RESOURCE-API' rpc='rollback-generated-names' mode='sync' >
                            <outcome value='failure'>
                                <return status='failure'>
                                    <parameter name='error-message' 
	value="`'Encountered error in rollback-generated-names: ' + 
		$error-message`" />
                                </return>
                            </outcome>
                        </call>
                    </block>
                </outcome>
                <outcome value='Other'>
                    <return status='failure'>
                        <parameter name='generate-unique-name-output.error-message' value='Invalid generate-unique-name-input.action. Valid values are ASSIGN or DELETE' />
                    </return>
                </outcome>
            </switch>
        </block>
    </method>
</service-logic>