[CCSDK-6] Populate seed code
[ccsdk/sli/adaptors.git] / resource-assignment / provider / src / test / java / jtest / org / openecomp / sdnc / ra / DataSetup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 ONAP Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package jtest.org.openecomp.sdnc.ra;
23
24 import java.util.Date;
25
26 import jtest.util.org.openecomp.sdnc.ra.TestDb;
27 import jtest.util.org.openecomp.sdnc.ra.TestTable;
28
29 public class DataSetup {
30
31         private TestDb testDb;
32
33         private TestTable vpePool = null;
34         private TestTable vplspePool = null;
35         private TestTable pserver = null;
36         private TestTable serviceResource = null;
37         private TestTable resource = null;
38         private TestTable allocationItem = null;
39
40         private static final String[] VPE_POOL_COLUMNS = {
41                 "vpe_name", "ipv4_oam_address", "loopback0_ipv4_address", "provisioning_status", "aic_site_id",
42                 "availability_zone", "vlan_id_outer", "vendor", "physical_intf_name", "physical_intf_speed",
43                 "physical_intf_units", "vpe_uuid", "vpe_id", "image_filename" };
44
45         private static final String[] VPLSPE_POOL_COLUMNS = {
46                 "vplspe_name", "aic_site_id", "availability_zone", "physical_intf_name", "physical_intf_speed",
47                 "physical_intf_units", "loopback0_ipv4_address", "vlan_id_outer", "vplspe_uuid", "image_filename",
48                 "provisioning_status", "vendor" };
49
50         private static final String[] PSERVER_COLUMNS = {
51                 "hostname", "ptnii_equip_name", "number_of_cpus", "disk_in_gigabytes", "ram_in_megabytes", "equip_type",
52                 "equip_vendor", "equip_model", "fqdn", "pserver_selflink", "ipv4_oam_address", "serial_number",
53                 "pserver_id", "internet_topology", "aic_site_id", "in_maint", "pserver_name2", "purpose" };
54
55         private static final String[] SERVICE_RESOURCE_COLUMNS = {
56                 "service_instance_id", "service_status", "service_change_number", "resource_set_id", "resource_union_id" };
57
58         private static final String[] RESOURCE_COLUMNS = { "asset_id", "resource_name", "resource_type", "lt_used" };
59
60         private static final String[] ALLOCATION_ITEM_COLUMNS = {
61                 "resource_id", "application_id", "resource_set_id", "resource_union_id", "resource_share_group_list",
62                 "lt_used", "allocation_time" };
63
64         private void initTables() {
65                 if (vpePool == null)
66                         vpePool = testDb.table("VPE_POOL", "vpe_name", VPE_POOL_COLUMNS);
67                 if (vplspePool == null)
68                         vplspePool = testDb.table("VPLSPE_POOL", "vplspe_name", VPLSPE_POOL_COLUMNS);
69                 if (pserver == null)
70                         pserver = testDb.table("PSERVER", "hostname", PSERVER_COLUMNS);
71                 if (serviceResource == null)
72                         serviceResource = testDb.table("SERVICE_RESOURCE", "service_resource_id", SERVICE_RESOURCE_COLUMNS);
73                 if (resource == null)
74                         resource = testDb.table("RESOURCE", "resource_id", RESOURCE_COLUMNS);
75                 if (allocationItem == null)
76                         allocationItem = testDb.table("ALLOCATION_ITEM", "allocation_item_id", ALLOCATION_ITEM_COLUMNS);
77         }
78
79         public void cleanup() {
80                 initTables();
81                 vpePool.delete("true");
82                 vplspePool.delete("true");
83                 pserver.delete("true");
84                 serviceResource.delete("true");
85                 allocationItem.delete("true");
86                 resource.delete("true");
87         }
88
89         public void setupVpePort(
90                 String aicSiteId,
91                 String vpeId,
92                 String interfaceName,
93                 String provStatus,
94                 String imageFileName) {
95                 initTables();
96                 vpePool.add(vpeId, "127.0.0.1", "107.134.152.139", provStatus, aicSiteId, "mtanj-esx-az01", "3501",
97                         "JUNIPER", interfaceName, "1", "GBPS", "vpe002", "VPESAT-auttx200me6", imageFileName);
98         }
99
100         public void setupVplspePort(
101                 String aicSiteId,
102                 String vplspeId,
103                 String interfaceName,
104                 String provStatus,
105                 String imageFileName) {
106                 initTables();
107                 vplspePool.add(vplspeId, aicSiteId, "mtanj-esx-az01", interfaceName, "100", "GBPS", "192.168.119.32", "3501",
108                         "vpls002", imageFileName, provStatus, "JUNIPER");
109         }
110
111         public void setupPserver(String hostname, String aicSiteId) {
112                 initTables();
113                 pserver.add(hostname, hostname + "srv1", 4, 1000, 16000, "equip_type", "equip_vendor", "equip_model", "fqdn",
114                         "pserver_selflink", "123.123.123.123", "serial_number", "pserver_id", "internet_topology", aicSiteId,
115                         "N", hostname, "purpose");
116         }
117
118         public void setupService(
119                 String serviceInstanceId,
120                 String status,
121                 int changeNumber,
122                 long speedKbps,
123                 String vpeId,
124                 String vplspeId,
125                 String serverId) {
126                 initTables();
127
128                 String resourceSetId = serviceInstanceId + "/" + changeNumber;
129                 String resourceUnionId = serviceInstanceId;
130
131                 serviceResource.add(serviceInstanceId, status, changeNumber, resourceSetId, resourceUnionId);
132
133                 Long rid = resource.getId("asset_id = '" + vpeId + "/ae0' AND resource_name = 'Bandwidth'");
134                 if (rid == null) {
135                         resource.add(vpeId + "/ae0", "Bandwidth", "Limit", 1);
136                         rid = resource.getLastId();
137                 }
138                 allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, speedKbps, new Date());
139
140                 rid = resource.getId("asset_id = '" + vplspeId + "' AND resource_name = 'Bandwidth'");
141                 if (rid == null) {
142                         resource.add(vplspeId, "Bandwidth", "Limit", 1);
143                         rid = resource.getLastId();
144                 }
145                 allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, speedKbps, new Date());
146
147                 rid = resource.getId("asset_id = '" + serverId + "' AND resource_name = 'Bandwidth'");
148                 if (rid == null) {
149                         resource.add(serverId, "Bandwidth", "Limit", 1);
150                         rid = resource.getLastId();
151                 }
152                 allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, speedKbps, new Date());
153
154                 rid = resource.getId("asset_id = '" + serverId + "' AND resource_name = 'Connection'");
155                 if (rid == null) {
156                         resource.add(serverId, "Connection", "Limit", 1);
157                         rid = resource.getLastId();
158                 }
159                 allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, 1, new Date());
160         }
161
162         public boolean serviceNotInDb(String serviceInstanceId, String status, Integer changeNumber) {
163                 String where = "service_instance_id = '" + serviceInstanceId + "'";
164                 if (status != null)
165                         where += " AND service_status = '" + status + "'";
166                 if (changeNumber != null)
167                         where += " AND service_change_number = " + changeNumber;
168
169                 if (serviceResource.exists(where))
170                         return false;
171
172                 where = "resource_union_id = '" + serviceInstanceId + "'";
173                 if (changeNumber != null)
174                         where += " AND resource_set_id = '" + serviceInstanceId + "/" + changeNumber + "'";
175
176                 if (allocationItem.exists(where))
177                         return false;
178
179                 return true;
180         }
181
182         public boolean serviceCorrectInDb(String serviceInstanceId, String status, int changeNumber, long speedKbps) {
183                 String where = "service_instance_id = '" + serviceInstanceId + "' AND service_status = '" + status +
184                         "' AND service_change_number = " + changeNumber;
185                 if (!serviceResource.exists(where))
186                         return false;
187
188                 where = "resource_union_id = '" + serviceInstanceId + "' AND resource_set_id = '" + serviceInstanceId + "/" +
189                         changeNumber + "' AND lt_used = " + speedKbps;
190                 if (!allocationItem.exists(where))
191                         return false;
192
193                 return true;
194         }
195
196         public boolean serviceCorrectInDb(
197                 String vpeId,
198                 String aicSiteId,
199                 String serviceInstanceId,
200                 String status,
201                 int changeNumber,
202                 long speedKbps) {
203
204                 String where = "service_instance_id = '" + serviceInstanceId + "' AND service_status = '" + status +
205                         "' AND service_change_number = " + changeNumber;
206                 if (!serviceResource.exists(where))
207                         return false;
208
209                 Long vpebwrid = resource.getId("asset_id = '" + vpeId + "/ae0' AND resource_name = 'Bandwidth'");
210                 if (vpebwrid == null)
211                         return false;
212
213                 where = "resource_id = " + vpebwrid + " AND resource_union_id = '" + serviceInstanceId +
214                         "' AND resource_set_id = '" + serviceInstanceId + "/" + changeNumber + "' AND lt_used = " + speedKbps;
215                 if (!allocationItem.exists(where))
216                         return false;
217
218                 Long srvbwrid = resource.getId("asset_id = '" + aicSiteId + "/Server1' AND resource_name = 'Bandwidth'");
219                 if (srvbwrid == null)
220                         return false;
221
222                 where = "resource_id = " + srvbwrid + " AND resource_union_id = '" + serviceInstanceId +
223                         "' AND resource_set_id = '" + serviceInstanceId + "/" + changeNumber + "' AND lt_used = " + speedKbps;
224                 if (!allocationItem.exists(where))
225                         return false;
226
227                 Long srvconrid = resource.getId("asset_id = '" + aicSiteId + "/Server1' AND resource_name = 'Connection'");
228                 if (srvconrid == null)
229                         return false;
230
231                 where = "resource_id = " + srvconrid + " AND resource_union_id = '" + serviceInstanceId +
232                         "' AND resource_set_id = '" + serviceInstanceId + "/" + changeNumber + "' AND lt_used = 1";
233                 if (!allocationItem.exists(where))
234                         return false;
235
236                 return true;
237         }
238
239         public boolean serviceCorrectInDb(
240                 String serviceInstanceId,
241                 String endPointPosition,
242                 String status,
243                 int changeNumber,
244                 long speedKbps) {
245                 String where = "service_instance_id = '" + serviceInstanceId + "' AND service_status = '" + status +
246                         "' AND service_change_number = " + changeNumber;
247                 if (!serviceResource.exists(where))
248                         return false;
249
250                 where = "resource_union_id = '" + serviceInstanceId + "/" + endPointPosition + "' AND resource_set_id = '" +
251                         serviceInstanceId + "/" + endPointPosition + "/" + changeNumber + "' AND lt_used = " + speedKbps;
252                 if (!allocationItem.exists(where))
253                         return false;
254
255                 return true;
256         }
257
258         public void setTestDb(TestDb testDb) {
259                 this.testDb = testDb;
260         }
261 }