ab2d936cf32a567bf418b09b0c5359f5886a6dae
[ccsdk/sli/adaptors.git] / resource-assignment / provider / src / test / java / jtest / org / onap / ccsdk / sli / adaptors / ra / TestReserve.java
1 package jtest.org.onap.ccsdk.sli.adaptors.ra;
2
3 import static org.junit.Assert.assertNotNull;
4 import java.util.ArrayList;
5 import java.util.Arrays;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9 import org.junit.Assert;
10 import org.junit.FixMethodOrder;
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.junit.runners.MethodSorters;
14 import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
15 import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceEntity;
16 import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceRequest;
17 import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse;
18 import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceTarget;
19 import org.onap.ccsdk.sli.adaptors.rm.data.AllocationStatus;
20 import org.onap.ccsdk.sli.adaptors.rm.data.Range;
21 import org.onap.ccsdk.sli.adaptors.rm.data.ResourceType;
22 import org.onap.ccsdk.sli.adaptors.util.str.StrUtil;
23 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
24 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.jdbc.core.JdbcTemplate;
29 import org.springframework.test.context.ContextConfiguration;
30 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
31 import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestTable;
32
33 @RunWith(SpringJUnit4ClassRunner.class)
34 @ContextConfiguration(locations = { "classpath:test-context.xml" })
35 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
36 public class TestReserve {
37
38     private static final Logger log = LoggerFactory.getLogger(TestReserve.class);
39
40     private JdbcTemplate jdbcTemplate;
41
42     private static final String[] RESOURCE_COLUMNS = { "asset_id", "resource_name", "resource_type", "lt_used" };
43
44     private static final String[] ALLOCATION_ITEM_COLUMNS = { "resource_id", "application_id", "resource_set_id",
45             "resource_union_id", "resource_share_group_list", "lt_used", "allocation_time" };
46
47     @Autowired
48     public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
49         this.jdbcTemplate = jdbcTemplate;
50     }
51
52     @Autowired(required = true)
53     private ResourceAllocator resourceAllocator;
54
55     /*
56      * @Autowired(required = true) private ResourceAllocatorApi
57      * resourceAllocatorApi;
58      */
59
60     @Autowired(required = true)
61     private DataSetup dataSetup;
62
63     @Test
64     public void test001() throws Exception {
65         String t = "001";
66         log.info("============== reserve " + t + " ================================");
67         log.info("=== Test successful response - new start - all resources available");
68
69         // String service1 = "reserve" + t + "/service1";
70
71         dataSetup.cleanup();
72
73         TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS);
74         TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id",
75                 ALLOCATION_ITEM_COLUMNS);
76
77         SvcLogicContext ctx = new SvcLogicContext();
78         ctx.setAttribute("ra-input.service-model", "ADIG");
79         ctx.setAttribute("ra-input.check-only", "false");
80         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
81         ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
82         ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100");
83         ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps");
84
85         ctx.setAttribute("ra-input.reservation-target-data.vnf-type", "VPE");
86         ctx.setAttribute("ra-input.reservation-target-data.vpe-name", "mdt300vpe54");
87         ctx.setAttribute("ra-input.reservation-target-id", "mdt300vpe54");
88         ctx.setAttribute("ra-input.reservation-target-type", "VNF");
89
90         ctx.setAttribute("ra-input.reservation-target-data.max-vpe-bandwidth-mbps", "5000");
91
92         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
93
94         Assert.assertTrue(st == QueryStatus.SUCCESS);
95
96         resource.print();
97         allocationItem.print();
98
99         ctx.setAttribute("ra-input.service-model", "ADIG");
100         ctx.setAttribute("ra-input.check-only", "false");
101         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
102         ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
103         ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100");
104         ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps");
105
106         ctx.setAttribute("ra-input.reservation-target-data.service-speed", "100");
107         ctx.setAttribute("ra-input.reservation-target-data.service-speed-unit", "Mbps");
108         ctx.setAttribute("ra-input.reservation-target-id", "ICORESITEID-123456");
109         ctx.setAttribute("ra-input.reservation-target-type", "Port");
110
111         st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
112
113         Assert.assertTrue(st == QueryStatus.SUCCESS);
114
115         ctx.setAttribute("ra-input.service-model", "ADIG");
116         ctx.setAttribute("ra-input.check-only", "false");
117         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
118         ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
119         ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100");
120         ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps");
121
122         ctx.setAttribute("ra-input.reservation-target-data.vnf-type", "VPE");
123         ctx.setAttribute("ra-input.reservation-target-data.vpe-name", "mdt300vpe54");
124         ctx.setAttribute("ra-input.reservation-target-id", "mdt300vpe54");
125         ctx.setAttribute("ra-input.reservation-target-type", "AffinityLink");
126
127         st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
128
129         Assert.assertTrue(st == QueryStatus.SUCCESS);
130
131         resource.print();
132         allocationItem.print();
133
134         /* Query Using ReservationEntityId using ServiceLogicContext */
135         ctx = new SvcLogicContext();
136         ctx.setAttribute("ra-input.service-model", "ADIG");
137         ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
138         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
139
140         st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
141         Assert.assertTrue(st == QueryStatus.SUCCESS);
142
143         /* Query Using ReservationTargetId using ServiceLogicContext */
144         ctx = new SvcLogicContext();
145         ctx.setAttribute("ra-input.service-model", "ADIG");
146         ctx.setAttribute("ra-input.reservation-target-id", "ICORESITEID-123456");
147         ctx.setAttribute("ra-input.reservation-target-type", "Port");
148         ctx.setAttribute("ra-input.resource-name", "Bandwidth");
149
150         st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
151         Assert.assertTrue(st == QueryStatus.SUCCESS);
152
153         log.info("========================  Query Using ResourceEntity==============================");
154         /* Query Using ResourceEntity bean */
155         ResourceEntity sd = new ResourceEntity();
156         sd.resourceEntityId = "ICOREPVCID-123456";
157         sd.resourceEntityType = "SI";
158
159         ResourceRequest rr = new ResourceRequest();
160         rr.serviceModel = "ADIG";
161         rr.resourceName = "cust-vlan-id";
162         rr.requestType = "New";
163         rr.rangeMaxOverride = -1;
164         rr.rangeMinOverride = -1;
165
166         List<ResourceResponse> rsList = new ArrayList<>();
167         resourceAllocator.query(sd, null, null, rsList);
168
169         rsList.forEach(r -> {
170             StrUtil.info(log, r);
171         });
172
173         log.info("========================  release Using ResourceEntity==============================");
174         rsList = new ArrayList<>();
175         AllocationStatus status = resourceAllocator.release(sd);
176         Assert.assertTrue(status == AllocationStatus.Success);
177
178         log.info("========================  Query Using ResourceEntity==============================");
179         rsList = new ArrayList<>();
180         resourceAllocator.query(sd, null, null, rsList);
181
182         rsList.forEach(r -> {
183             StrUtil.info(log, r);
184         });
185
186     }
187
188     @Test
189     public void test002() throws Exception {
190         String t = "002";
191         log.info("============== reserve " + t + " ================================");
192         log.info("=== Test successful response - new start - all resources available");
193
194         Map<String, String> data = new HashMap<>();
195         data.put("service-speed", "100");
196         data.put("service-speed-unit", "Mbps");
197
198         ResourceEntity sd = new ResourceEntity();
199         sd.resourceEntityId = "ICOREPVCID-123456";
200         sd.resourceEntityType = "SI";
201         sd.data = data;
202
203         data = new HashMap<>();
204         data.put("vnf-type", "VPE");
205         data.put("vpe-name", "mdt300vpe54");
206         data.put("max-vpe-bandwidth-mbps", "5000");
207
208         ResourceTarget rt = new ResourceTarget();
209         rt.resourceTargetId = "mdt300vpe54";
210         rt.resourceTargetType = "VNF";
211         rt.data = data;
212
213         ResourceRequest rr = new ResourceRequest();
214         rr.serviceModel = "ADIG";
215         // rr.resourceName = "cust-vlan-id";
216         rr.requestType = "New";
217         rr.rangeMaxOverride = -1;
218         rr.rangeMinOverride = -1;
219
220         List<ResourceResponse> rsList = new ArrayList<>();
221
222         resourceAllocator.reserve(sd, rt, rr, rsList);
223
224         rsList.forEach(r -> {
225             StrUtil.info(log, r);
226         });
227
228         log.info("========================  Query + t ==============================");
229         rsList = new ArrayList<>();
230         resourceAllocator.query(sd, null, rr, rsList);
231
232         rsList.forEach(r -> {
233             StrUtil.info(log, r);
234         });
235         assertNotNull(rsList);
236
237     }
238
239     @Test
240     public void test003() throws Exception {
241         String t = "003";
242         log.info("============== reserve " + t + " ================================");
243         log.info("=== Test successful response - new start - all resources available");
244
245         ResourceEntity sd = new ResourceEntity();
246         sd.resourceEntityId = "gblond2003me6";
247         sd.resourceEntityType = "VNF";
248
249         ResourceTarget rt = new ResourceTarget();
250         rt.resourceTargetId = "MDTWNJ21A5";
251         rt.resourceTargetType = "Site";
252
253         ResourceRequest rr = new ResourceRequest();
254         rr.serviceModel = "MY-SERV-MODEL";
255         rr.resourceName = "VPE-Cust";
256         // rr.requestType = "New";
257         // rr.rangeMaxOverride = 5;
258         // rr.rangeMinOverride = 5;
259
260         List<ResourceResponse> rsList = new ArrayList<>();
261         resourceAllocator.reserve(sd, rt, rr, rsList);
262
263         rsList.forEach(r -> {
264             StrUtil.info(log, r);
265         });
266
267         log.info("========================  Query + t ==============================");
268         rsList = new ArrayList<>();
269         resourceAllocator.query(sd, null, rr, rsList);
270
271         rsList.forEach(r -> {
272             StrUtil.info(log, r);
273         });
274         assertNotNull(sd);
275
276     }
277
278     @Test
279     public void test004() throws Exception {
280         String t = "004";
281         log.info("============== reserve " + t + " ================================");
282         log.info("=== Test successful response - new start - all resources available");
283
284         ResourceEntity sd = new ResourceEntity();
285         sd.resourceEntityId = "gblond2003me6";
286         sd.resourceEntityType = "VNF";
287
288         ResourceTarget rt = new ResourceTarget();
289         rt.resourceTargetId = "MDTWNJ21A5";
290         rt.resourceTargetType = "Site";
291
292         List<ResourceRequest> rrs = new ArrayList<>();
293         ResourceRequest rr = new ResourceRequest();
294         rr.serviceModel = "MY-SERV-MODEL";
295         rr.resourceName = "VPE-Cust";
296         rrs.add(rr);
297
298         rr = new ResourceRequest();
299         rr.serviceModel = "MY-SERV-MODEL";
300         rr.resourceName = "VPE-Core1";
301         rrs.add(rr);
302
303         rr = new ResourceRequest();
304         rr.serviceModel = "MY-SERV-MODEL";
305         rr.resourceName = "VPE-Core2";
306         rrs.add(rr);
307
308         List<ResourceResponse> rsList = new ArrayList<>();
309         // resourceAllocator.reserve(sd, rt, rrs, rsList);
310
311         rsList.forEach(r -> {
312             StrUtil.info(log, r);
313         });
314
315         log.info("========================  Query + t ==============================");
316         rsList = new ArrayList<>();
317         resourceAllocator.query(sd, null, rr, rsList);
318
319         rsList.forEach(r -> {
320             StrUtil.info(log, r);
321         });
322         assertNotNull(rr);
323
324     }
325
326     @Test
327     public void test005() throws Exception {
328         String t = "005";
329         log.info("============== reserve " + t + " ================================");
330         log.info("=== Test successful response - new start - all resources available");
331
332         // String service1 = "reserve" + t + "/service1";
333
334         dataSetup.cleanup();
335
336         TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS);
337         TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id",
338                 ALLOCATION_ITEM_COLUMNS);
339
340         SvcLogicContext ctx = new SvcLogicContext();
341         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
342         ctx.setAttribute("ra-input.check-only", "false");
343         ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Cust");
344         ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
345
346         ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
347         ctx.setAttribute("ra-input.reservation-target-type", "Site");
348
349         ctx.setAttribute("ra-input.resource-name", "cust-vlan-id");
350
351         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
352
353         Assert.assertTrue(st == QueryStatus.SUCCESS);
354
355         resource.print();
356         allocationItem.print();
357
358         ctx = new SvcLogicContext();
359         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
360         ctx.setAttribute("ra-input.check-only", "false");
361         ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1");
362         ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
363
364         ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
365         ctx.setAttribute("ra-input.reservation-target-type", "Site");
366
367         ctx.setAttribute("ra-input.resource-name", "vlan-id-inner");
368
369         st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
370
371         Assert.assertTrue(st == QueryStatus.SUCCESS);
372
373         resource.print();
374         allocationItem.print();
375
376         ctx = new SvcLogicContext();
377         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
378         ctx.setAttribute("ra-input.check-only", "false");
379         ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core2");
380         ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
381
382         ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
383         ctx.setAttribute("ra-input.reservation-target-type", "Site");
384
385         ctx.setAttribute("ra-input.resource-name", "vlan-id-inner");
386         ctx.setAttribute("ra-input.replace", "false");
387
388         st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
389
390         Assert.assertTrue(st == QueryStatus.SUCCESS);
391
392         resource.print();
393         allocationItem.print();
394
395         /* Query Using ReservationEntityId using ServiceLogicContext */
396         ctx = new SvcLogicContext();
397         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
398         ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
399         ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1");
400
401         st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
402         Assert.assertTrue(st == QueryStatus.SUCCESS);
403
404         /* Query Using ReservationTargetId using ServiceLogicContext */
405         ctx = new SvcLogicContext();
406         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
407         ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
408         ctx.setAttribute("ra-input.reservation-target-type", "Site");
409         ctx.setAttribute("ra-input.resource-name", "vlan-id-inner");
410
411         st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
412         Assert.assertTrue(st == QueryStatus.SUCCESS);
413
414         log.info("========================  Query Using ResourceEntity==============================");
415         /* Query Using ResourceEntity bean */
416         ResourceEntity sd = new ResourceEntity();
417         sd.resourceEntityId = "gblond2003me6";
418         sd.resourceEntityType = "VPE-Core1";
419
420         ResourceRequest rr = new ResourceRequest();
421         rr.serviceModel = "MY-SERV-MODEL-1";
422         rr.resourceName = "vlan-id-inner";
423         rr.requestType = "New";
424         rr.rangeMaxOverride = -1;
425         rr.rangeMinOverride = -1;
426
427         List<ResourceResponse> rsList = new ArrayList<>();
428         resourceAllocator.query(sd, null, null, rsList);
429
430         rsList.forEach(r -> {
431             StrUtil.info(log, r);
432         });
433
434         /*
435          * log.
436          * info("========================  release Using ResourceEntity=============================="
437          * ); rsList = new ArrayList<ResourceResponse>(); AllocationStatus status =
438          * resourceAllocator.release(sd); Assert.assertTrue(status ==
439          * AllocationStatus.Success);
440          *
441          *
442          * log.
443          * info("========================  Query Using ResourceEntity=============================="
444          * ); rsList = new ArrayList<ResourceResponse>(); resourceAllocator.query(sd,
445          * null, null, rsList);
446          *
447          *
448          * rsList.forEach(r -> { StrUtil.info(log, r); });
449          */
450
451     }
452
453     @Test
454     public void test006() throws Exception {
455         String t = "006";
456         log.info("============== reserve " + t + " ================================");
457         log.info("=== Test successful response - new start - all resources available");
458
459         ResourceEntity sd = new ResourceEntity();
460         sd.resourceEntityId = "gblond2003me6";
461         sd.resourceEntityType = "VPE-Cust";
462
463         ResourceTarget rt = new ResourceTarget();
464         rt.resourceTargetId = "MDTWNJ21A5";
465         rt.resourceTargetType = "Site";
466
467         ResourceRequest rr = new ResourceRequest();
468         rr.serviceModel = "MY-SERV-MODEL-1";
469         rr.resourceName = "cust-vlan-id";
470
471         List<ResourceResponse> rsList = new ArrayList<>();
472         resourceAllocator.reserve(sd, rt, rr, rsList);
473
474         rsList.forEach(r -> {
475             StrUtil.info(log, r);
476         });
477
478         log.info("========================  Query + t ==============================");
479         rsList = new ArrayList<>();
480         resourceAllocator.query(sd, null, rr, rsList);
481
482         rsList.forEach(r -> {
483             StrUtil.info(log, r);
484         });
485         assertNotNull(rsList);
486
487     }
488
489     @Test
490     public void test007() throws Exception {
491         String t = "007";
492         log.info("============== reserve " + t + " ================================");
493         log.info("=== Test successful response - new start - all resources available");
494
495         dataSetup.cleanup();
496
497         TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS);
498         TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id",
499                 ALLOCATION_ITEM_COLUMNS);
500
501         ResourceEntity sd = new ResourceEntity();
502         sd.resourceEntityId = "gblond2003me6";
503         sd.resourceEntityType = "VPE";
504         sd.resourceEntityVersion = "1";
505
506         ResourceTarget rt = new ResourceTarget();
507         rt.resourceTargetId = "MDTWNJ21A5";
508         rt.resourceTargetType = "Site";
509
510         ResourceRequest rr = new ResourceRequest();
511         rr.serviceModel = "MY-SERV-MODEL";
512         // rr.resourceName = "vlan-id-outer";
513         rr.endPointPosition = "VPE-Cust";
514         rr.rangeMaxOverride = -1;
515         rr.rangeMinOverride = -1;
516
517         List<ResourceResponse> rsList = new ArrayList<>();
518         resourceAllocator.reserve(sd, rt, rr, rsList);
519
520         // VPE-Core1
521         sd = new ResourceEntity();
522         sd.resourceEntityId = "gblond2003me6";
523         sd.resourceEntityType = "VPE";
524         sd.resourceEntityVersion = "1";
525
526         rt = new ResourceTarget();
527         rt.resourceTargetId = "MDTWNJ21A5";
528         rt.resourceTargetType = "Site";
529
530         rr = new ResourceRequest();
531         rr.serviceModel = "MY-SERV-MODEL";
532         // rr.resourceName = "vlan-id-filter";
533         rr.endPointPosition = "VPE-Core1";
534         rr.rangeMaxOverride = -1;
535         rr.rangeMinOverride = -1;
536
537         rsList = new ArrayList<>();
538         resourceAllocator.reserve(sd, rt, rr, rsList);
539
540         // VPE-Core2
541         sd = new ResourceEntity();
542         sd.resourceEntityId = "gblond2003me6";
543         sd.resourceEntityType = "VPE";
544         sd.resourceEntityVersion = "1";
545
546         rt = new ResourceTarget();
547         rt.resourceTargetId = "MDTWNJ21A5";
548         rt.resourceTargetType = "Site";
549
550         rr = new ResourceRequest();
551         rr.serviceModel = "MY-SERV-MODEL";
552         // rr.resourceName = "vlan-id-filter";
553         rr.endPointPosition = "VPE-Core2";
554         rr.rangeMaxOverride = -1;
555         rr.rangeMinOverride = -1;
556
557         rsList = new ArrayList<>();
558         resourceAllocator.reserve(sd, rt, rr, rsList);
559
560         // VPE-Core3
561         sd = new ResourceEntity();
562         sd.resourceEntityId = "gblond2003me6";
563         sd.resourceEntityType = "VPE";
564         sd.resourceEntityVersion = "1";
565
566         rt = new ResourceTarget();
567         rt.resourceTargetId = "MDTWNJ21A5";
568         rt.resourceTargetType = "Site";
569
570         rr = new ResourceRequest();
571         rr.serviceModel = "MY-SERV-MODEL";
572         // rr.resourceName = "vlan-id-filter";
573         rr.endPointPosition = "VPE-Core3";
574         rr.rangeMaxOverride = -1;
575         rr.rangeMinOverride = -1;
576
577         rsList = new ArrayList<>();
578         resourceAllocator.reserve(sd, rt, rr, rsList);
579
580         rsList.forEach(r -> {
581             StrUtil.info(log, r);
582         });
583
584         resource.print();
585         allocationItem.print();
586
587         log.info("========================  Query + t ==============================");
588         rsList = new ArrayList<>();
589         resourceAllocator.query(sd, null, rr, rsList);
590
591         rsList.forEach(r -> {
592             StrUtil.info(log, r);
593         });
594
595         SvcLogicContext ctx = new SvcLogicContext();
596         ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
597         ctx.setAttribute("ra-input.reservation-entity-type", "VPE");
598
599         QueryStatus st = resourceAllocator.release("NetworkCapacity", "gblond2003me6", ctx);
600         Assert.assertTrue(st == QueryStatus.SUCCESS);
601
602     }
603
604     @Test
605     public void test008() throws Exception {
606         String t = "008";
607         log.info("============== reserve " + t + " ================================");
608         log.info("=== Test range-force-new-numbers = false");
609
610         String entityId = "reserve" + t;
611         String targetId = "port-id-1";
612         String resourceName = "cust-vlan-id";
613
614         String assetId = "VNF::" + targetId;
615         String resourceUnion = "SI::" + entityId;
616         String resourceSet1 = resourceUnion + "::1";
617         String resourceSet2 = resourceUnion + "::2";
618
619         dataSetup.cleanup();
620
621         dataSetup.setupRangeItem(resourceName, assetId, resourceSet1, resourceUnion, "201");
622
623         SvcLogicContext ctx = new SvcLogicContext();
624         ctx.setAttribute("ra-input.service-model", "ADIG");
625         ctx.setAttribute("ra-input.check-only", "false");
626
627         ctx.setAttribute("ra-input.resource-name", resourceName);
628         ctx.setAttribute("ra-input.range-force-new-numbers", "false");
629
630         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
631         ctx.setAttribute("ra-input.reservation-entity-id", entityId);
632         ctx.setAttribute("ra-input.reservation-entity-version", "2");
633
634         ctx.setAttribute("ra-input.reservation-target-id", targetId);
635         ctx.setAttribute("ra-input.reservation-target-type", "VNF");
636
637         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
638
639         Assert.assertTrue(st == QueryStatus.SUCCESS);
640         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet1, "201"));
641         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet2, "201"));
642
643         Assert.assertEquals(ctx.getAttribute("resource-list_length"), "1");
644         Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-name"), "cust-vlan-id");
645         Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-target-type"), "VNF");
646         Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-target-id"), "port-id-1");
647         Assert.assertEquals(ctx.getAttribute("resource-list[0].status"), "Success");
648         Assert.assertEquals(ctx.getAttribute("resource-list[0].allocated"), "201");
649         Assert.assertEquals(ctx.getAttribute("resource-list[0].used"), "201");
650         Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list_length"), "1");
651         Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list[0].min"), "2");
652         Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list[0].max"), "1000");
653     }
654
655     @Test
656     public void test009() throws Exception {
657         String t = "009";
658         log.info("============== reserve " + t + " ================================");
659         log.info("=== Test range-force-new-numbers = true");
660
661         String entityId = "reserve" + t;
662         String targetId = "port-id-1";
663         String resourceName = "cust-vlan-id";
664
665         String assetId = "VNF::" + targetId;
666         String resourceUnion = "SI::" + entityId;
667         String resourceSet1 = resourceUnion + "::1";
668         String resourceSet2 = resourceUnion + "::2";
669
670         dataSetup.cleanup();
671
672         dataSetup.setupRangeItem(resourceName, assetId, resourceSet1, resourceUnion, "201");
673
674         SvcLogicContext ctx = new SvcLogicContext();
675         ctx.setAttribute("ra-input.service-model", "ADIG");
676         ctx.setAttribute("ra-input.check-only", "false");
677
678         ctx.setAttribute("ra-input.resource-name", resourceName);
679         ctx.setAttribute("ra-input.range-force-new-numbers", "true");
680
681         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
682         ctx.setAttribute("ra-input.reservation-entity-id", entityId);
683         ctx.setAttribute("ra-input.reservation-entity-version", "2");
684
685         ctx.setAttribute("ra-input.reservation-target-id", targetId);
686         ctx.setAttribute("ra-input.reservation-target-type", "VNF");
687
688         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
689
690         Assert.assertTrue(st == QueryStatus.SUCCESS);
691         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet1, "201"));
692         Assert.assertFalse(dataSetup.checkRangeItem(resourceName, assetId, resourceSet2, "201"));
693     }
694
695     @Test
696     public void test0010_vlantag_with_resourcemodel() throws Exception {
697
698         String t = "0010";
699         log.info("============== reserve " + t + " ================================");
700
701         dataSetup.cleanup();
702
703         TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS);
704         TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id",
705                 ALLOCATION_ITEM_COLUMNS);
706
707         ResourceEntity sd = new ResourceEntity();
708         sd.resourceEntityId = "gblond2003me6";
709         sd.resourceEntityType = "VNF";
710         sd.resourceEntityVersion = "1";
711
712         ResourceTarget rt = new ResourceTarget();
713         rt.resourceTargetId = "MDTWNJ21A5";
714         rt.resourceTargetType = "Site";
715
716         ResourceRequest rr = new ResourceRequest();
717         rr.serviceModel = "MY-SERV-MODEL_3456";
718         rr.resourceName = "vlan-id-outer";
719         rr.endPointPosition = "VPE-Core1";
720         rr.rangeMaxOverride = 3901;
721         rr.rangeMinOverride = 3900;
722         rr.resourceType = ResourceType.Range;
723
724         List<ResourceResponse> rsList = new ArrayList<>();
725         resourceAllocator.reserve(sd, rt, rr, rsList);
726
727         resource.print();
728         allocationItem.print();
729
730         Range range = new Range();
731         range.min = 3900;
732         range.max = 3901;
733
734         sd = new ResourceEntity();
735         sd.resourceEntityId = "gblond2003me6";
736         sd.resourceEntityType = "VNF";
737         sd.resourceEntityVersion = "1";
738
739         rt = new ResourceTarget();
740         rt.resourceTargetId = "MDTWNJ21A5";
741         rt.resourceTargetType = "Site";
742
743         rr = new ResourceRequest();
744         rr.serviceModel = "MY-SERV-MODEL_3456";
745         rr.resourceName = "vlan-id-outer";
746         rr.endPointPosition = "VPE-Core2";
747         rr.rangeMaxOverride = -1;
748         rr.rangeMinOverride = -1;
749         rr.rangeOverrideList = Arrays.asList(range);
750         rr.resourceType = ResourceType.Range;
751
752         rsList = new ArrayList<>();
753         resourceAllocator.reserve(sd, rt, rr, rsList);
754
755         resource.print();
756         allocationItem.print();
757
758         sd = new ResourceEntity();
759         sd.resourceEntityId = "gblond2003me6";
760         sd.resourceEntityType = "VNF";
761         sd.resourceEntityVersion = "1";
762
763         rt = new ResourceTarget();
764         rt.resourceTargetId = "MDTWNJ21A5";
765         rt.resourceTargetType = "Site";
766
767         Range range1 = new Range();
768         range1.min = 3900;
769         range1.max = 3901;
770
771         Range range2 = new Range();
772         range2.min = 3904;
773         range2.max = 3905;
774
775         rr = new ResourceRequest();
776         rr.serviceModel = "MY-SERV-MODEL_3456";
777         rr.resourceName = "vlan-id-outer";
778         rr.endPointPosition = "VPE-Core3";
779         rr.rangeMaxOverride = -1;
780         rr.rangeMinOverride = -1;
781         rr.rangeOverrideList = new ArrayList<>();
782         rr.rangeOverrideList.add(range1);
783         rr.rangeOverrideList.add(range2);
784         rr.resourceType = ResourceType.Range;
785
786         rsList = new ArrayList<>();
787         AllocationStatus status = resourceAllocator.reserve(sd, rt, rr, rsList);
788         Assert.assertTrue(status == AllocationStatus.Success);
789
790         resource.print();
791         allocationItem.print();
792
793         sd = new ResourceEntity();
794         sd.resourceEntityId = "gblond2003me6";
795         sd.resourceEntityType = "VNF";
796         sd.resourceEntityVersion = "1";
797
798         rr = new ResourceRequest();
799         rr.endPointPosition = "VPE-Core2";
800         status = resourceAllocator.release(sd, rr);
801         Assert.assertTrue(status == AllocationStatus.Success);
802
803         resource.print();
804         allocationItem.print();
805
806     }
807
808     @Test
809     public void test011() throws Exception {
810         String t = "011";
811         log.info("============== reserve " + t + " ================================");
812         log.info("=== Test range-next-in-sequence = true");
813
814         String entityId = "reserve" + t;
815         String targetId = "port-id-1";
816         String resourceName = "vlan-id-filter";
817
818         String assetId = "Site::" + targetId;
819         String resourceUnion = "SI::" + entityId;
820         String resourceSet = resourceUnion + "::1";
821
822         dataSetup.cleanup();
823         dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008");
824
825         SvcLogicContext ctx = new SvcLogicContext();
826         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL");
827         ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2");
828         ctx.setAttribute("ra-input.check-only", "false");
829
830         ctx.setAttribute("ra-input.resource-name", resourceName);
831         ctx.setAttribute("ra-input.range-next-in-sequence", "true");
832
833         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
834         ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test");
835         ctx.setAttribute("ra-input.reservation-entity-version", "1");
836
837         ctx.setAttribute("ra-input.reservation-target-id", targetId);
838         ctx.setAttribute("ra-input.reservation-target-type", "Site");
839
840         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
841
842         Assert.assertTrue(st == QueryStatus.SUCCESS);
843         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1009"));
844     }
845
846     @Test
847     public void test012() throws Exception {
848         String t = "012";
849         log.info("============== reserve " + t + " ================================");
850         log.info("=== Test range-next-in-sequence = false");
851
852         String entityId = "reserve" + t;
853         String targetId = "port-id-1";
854         String resourceName = "vlan-id-filter";
855
856         String assetId = "Site::" + targetId;
857         String resourceUnion = "SI::" + entityId;
858         String resourceSet = resourceUnion + "::1";
859
860         dataSetup.cleanup();
861         dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008");
862
863         SvcLogicContext ctx = new SvcLogicContext();
864         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL");
865         ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2");
866         ctx.setAttribute("ra-input.check-only", "false");
867
868         ctx.setAttribute("ra-input.resource-name", resourceName);
869         ctx.setAttribute("ra-input.range-next-in-sequence", "false");
870
871         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
872         ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test");
873         ctx.setAttribute("ra-input.reservation-entity-version", "1");
874
875         ctx.setAttribute("ra-input.reservation-target-id", targetId);
876         ctx.setAttribute("ra-input.reservation-target-type", "Site");
877
878         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
879
880         Assert.assertTrue(st == QueryStatus.SUCCESS);
881         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1003"));
882     }
883
884     @Test
885     public void test013() throws Exception {
886         String t = "013";
887         log.info("============== reserve " + t + " ================================");
888         log.info("=== Test range-next-in-sequence = true - multiple ranges");
889
890         String entityId = "reserve" + t;
891         String targetId = "port-id-1";
892         String resourceName = "vlan-id-filter";
893
894         String assetId = "Site::" + targetId;
895         String resourceUnion = "SI::" + entityId;
896         String resourceSet = resourceUnion + "::1";
897
898         dataSetup.cleanup();
899         dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008,2205-2221");
900
901         SvcLogicContext ctx = new SvcLogicContext();
902         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL");
903         ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2");
904         ctx.setAttribute("ra-input.check-only", "false");
905
906         ctx.setAttribute("ra-input.resource-name", resourceName);
907         ctx.setAttribute("ra-input.range-next-in-sequence", "true");
908
909         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
910         ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test");
911         ctx.setAttribute("ra-input.reservation-entity-version", "1");
912
913         ctx.setAttribute("ra-input.reservation-target-id", targetId);
914         ctx.setAttribute("ra-input.reservation-target-type", "Site");
915
916         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
917
918         Assert.assertTrue(st == QueryStatus.SUCCESS);
919         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "2222"));
920     }
921
922     @Test
923     public void test014() throws Exception {
924         String t = "014";
925         log.info("============== reserve " + t + " ================================");
926         log.info("=== Test range-next-in-sequence = true - no previously reserved numbers");
927
928         String entityId = "reserve" + t;
929         String targetId = "port-id-1";
930         String resourceName = "vlan-id-filter";
931
932         String assetId = "Site::" + targetId;
933
934         dataSetup.cleanup();
935
936         SvcLogicContext ctx = new SvcLogicContext();
937         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL");
938         ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2");
939         ctx.setAttribute("ra-input.check-only", "false");
940
941         ctx.setAttribute("ra-input.resource-name", resourceName);
942         ctx.setAttribute("ra-input.range-next-in-sequence", "true");
943
944         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
945         ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test");
946         ctx.setAttribute("ra-input.reservation-entity-version", "1");
947
948         ctx.setAttribute("ra-input.reservation-target-id", targetId);
949         ctx.setAttribute("ra-input.reservation-target-type", "Site");
950
951         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
952
953         Assert.assertTrue(st == QueryStatus.SUCCESS);
954         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1002"));
955     }
956 }