Update adaptors to sodium
[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         rr.applicationId = "myapp";
220
221         List<ResourceResponse> rsList = new ArrayList<>();
222
223         resourceAllocator.reserve(sd, rt, rr, rsList);
224
225         rsList.forEach(r -> {
226             StrUtil.info(log, r);
227         });
228
229         log.info("========================  Query + t ==============================");
230         rsList = new ArrayList<>();
231         resourceAllocator.query(sd, null, rr, rsList);
232
233         rsList.forEach(r -> {
234             StrUtil.info(log, r);
235         });
236         assertNotNull(rsList);
237
238     }
239
240     @Test
241     public void test003() throws Exception {
242         String t = "003";
243         log.info("============== reserve " + t + " ================================");
244         log.info("=== Test successful response - new start - all resources available");
245
246         ResourceEntity sd = new ResourceEntity();
247         sd.resourceEntityId = "gblond2003me6";
248         sd.resourceEntityType = "VNF";
249
250         ResourceTarget rt = new ResourceTarget();
251         rt.resourceTargetId = "MDTWNJ21A5";
252         rt.resourceTargetType = "Site";
253
254         ResourceRequest rr = new ResourceRequest();
255         rr.serviceModel = "MY-SERV-MODEL";
256         rr.resourceName = "VPE-Cust";
257         // rr.requestType = "New";
258         // rr.rangeMaxOverride = 5;
259         // rr.rangeMinOverride = 5;
260
261         List<ResourceResponse> rsList = new ArrayList<>();
262         resourceAllocator.reserve(sd, rt, rr, rsList);
263
264         rsList.forEach(r -> {
265             StrUtil.info(log, r);
266         });
267
268         log.info("========================  Query + t ==============================");
269         rsList = new ArrayList<>();
270         resourceAllocator.query(sd, null, rr, rsList);
271
272         rsList.forEach(r -> {
273             StrUtil.info(log, r);
274         });
275         assertNotNull(sd);
276
277     }
278
279     @Test
280     public void test004() throws Exception {
281         String t = "004";
282         log.info("============== reserve " + t + " ================================");
283         log.info("=== Test successful response - new start - all resources available");
284
285         ResourceEntity sd = new ResourceEntity();
286         sd.resourceEntityId = "gblond2003me6";
287         sd.resourceEntityType = "VNF";
288
289         ResourceTarget rt = new ResourceTarget();
290         rt.resourceTargetId = "MDTWNJ21A5";
291         rt.resourceTargetType = "Site";
292
293         List<ResourceRequest> rrs = new ArrayList<>();
294         ResourceRequest rr = new ResourceRequest();
295         rr.serviceModel = "MY-SERV-MODEL";
296         rr.resourceName = "VPE-Cust";
297         rrs.add(rr);
298
299         rr = new ResourceRequest();
300         rr.serviceModel = "MY-SERV-MODEL";
301         rr.resourceName = "VPE-Core1";
302         rrs.add(rr);
303
304         rr = new ResourceRequest();
305         rr.serviceModel = "MY-SERV-MODEL";
306         rr.resourceName = "VPE-Core2";
307         rrs.add(rr);
308
309         List<ResourceResponse> rsList = new ArrayList<>();
310         // resourceAllocator.reserve(sd, rt, rrs, rsList);
311
312         rsList.forEach(r -> {
313             StrUtil.info(log, r);
314         });
315
316         log.info("========================  Query + t ==============================");
317         rsList = new ArrayList<>();
318         resourceAllocator.query(sd, null, rr, rsList);
319
320         rsList.forEach(r -> {
321             StrUtil.info(log, r);
322         });
323         assertNotNull(rr);
324
325     }
326
327     @Test
328     public void test005() throws Exception {
329         String t = "005";
330         log.info("============== reserve " + t + " ================================");
331         log.info("=== Test successful response - new start - all resources available");
332
333         // String service1 = "reserve" + t + "/service1";
334
335         dataSetup.cleanup();
336
337         TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS);
338         TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id",
339                 ALLOCATION_ITEM_COLUMNS);
340
341         SvcLogicContext ctx = new SvcLogicContext();
342         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
343         ctx.setAttribute("ra-input.check-only", "false");
344         ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Cust");
345         ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
346
347         ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
348         ctx.setAttribute("ra-input.reservation-target-type", "Site");
349
350         ctx.setAttribute("ra-input.resource-name", "cust-vlan-id");
351
352         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
353
354         Assert.assertTrue(st == QueryStatus.SUCCESS);
355
356         resource.print();
357         allocationItem.print();
358
359         ctx = new SvcLogicContext();
360         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
361         ctx.setAttribute("ra-input.check-only", "false");
362         ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1");
363         ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
364
365         ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
366         ctx.setAttribute("ra-input.reservation-target-type", "Site");
367
368         ctx.setAttribute("ra-input.resource-name", "vlan-id-inner");
369
370         st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
371
372         Assert.assertTrue(st == QueryStatus.SUCCESS);
373
374         resource.print();
375         allocationItem.print();
376
377         ctx = new SvcLogicContext();
378         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
379         ctx.setAttribute("ra-input.check-only", "false");
380         ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core2");
381         ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
382
383         ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
384         ctx.setAttribute("ra-input.reservation-target-type", "Site");
385
386         ctx.setAttribute("ra-input.resource-name", "vlan-id-inner");
387         ctx.setAttribute("ra-input.replace", "false");
388
389         st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
390
391         Assert.assertTrue(st == QueryStatus.SUCCESS);
392
393         resource.print();
394         allocationItem.print();
395
396         /* Query Using ReservationEntityId using ServiceLogicContext */
397         ctx = new SvcLogicContext();
398         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
399         ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
400         ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1");
401
402         st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
403         Assert.assertTrue(st == QueryStatus.SUCCESS);
404
405         /* Query Using ReservationTargetId using ServiceLogicContext */
406         ctx = new SvcLogicContext();
407         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
408         ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
409         ctx.setAttribute("ra-input.reservation-target-type", "Site");
410         ctx.setAttribute("ra-input.resource-name", "vlan-id-inner");
411
412         st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
413         Assert.assertTrue(st == QueryStatus.SUCCESS);
414
415         log.info("========================  Query Using ResourceEntity==============================");
416         /* Query Using ResourceEntity bean */
417         ResourceEntity sd = new ResourceEntity();
418         sd.resourceEntityId = "gblond2003me6";
419         sd.resourceEntityType = "VPE-Core1";
420
421         ResourceRequest rr = new ResourceRequest();
422         rr.serviceModel = "MY-SERV-MODEL-1";
423         rr.resourceName = "vlan-id-inner";
424         rr.requestType = "New";
425         rr.rangeMaxOverride = -1;
426         rr.rangeMinOverride = -1;
427
428         List<ResourceResponse> rsList = new ArrayList<>();
429         resourceAllocator.query(sd, null, null, rsList);
430
431         rsList.forEach(r -> {
432             StrUtil.info(log, r);
433         });
434
435         /*
436          * log.
437          * info("========================  release Using ResourceEntity=============================="
438          * ); rsList = new ArrayList<ResourceResponse>(); AllocationStatus status =
439          * resourceAllocator.release(sd); Assert.assertTrue(status ==
440          * AllocationStatus.Success);
441          *
442          *
443          * log.
444          * info("========================  Query Using ResourceEntity=============================="
445          * ); rsList = new ArrayList<ResourceResponse>(); resourceAllocator.query(sd,
446          * null, null, rsList);
447          *
448          *
449          * rsList.forEach(r -> { StrUtil.info(log, r); });
450          */
451
452     }
453
454     @Test
455     public void test006() throws Exception {
456         String t = "006";
457         log.info("============== reserve " + t + " ================================");
458         log.info("=== Test successful response - new start - all resources available");
459
460         ResourceEntity sd = new ResourceEntity();
461         sd.resourceEntityId = "gblond2003me6";
462         sd.resourceEntityType = "VPE-Cust";
463
464         ResourceTarget rt = new ResourceTarget();
465         rt.resourceTargetId = "MDTWNJ21A5";
466         rt.resourceTargetType = "Site";
467
468         ResourceRequest rr = new ResourceRequest();
469         rr.serviceModel = "MY-SERV-MODEL-1";
470         rr.resourceName = "cust-vlan-id";
471
472         List<ResourceResponse> rsList = new ArrayList<>();
473         resourceAllocator.reserve(sd, rt, rr, rsList);
474
475         rsList.forEach(r -> {
476             StrUtil.info(log, r);
477         });
478
479         log.info("========================  Query + t ==============================");
480         rsList = new ArrayList<>();
481         resourceAllocator.query(sd, null, rr, rsList);
482
483         rsList.forEach(r -> {
484             StrUtil.info(log, r);
485         });
486         assertNotNull(rsList);
487
488     }
489
490     @Test
491     public void test007() throws Exception {
492         String t = "007";
493         log.info("============== reserve " + t + " ================================");
494         log.info("=== Test successful response - new start - all resources available");
495
496         dataSetup.cleanup();
497
498         TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS);
499         TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id",
500                 ALLOCATION_ITEM_COLUMNS);
501
502         ResourceEntity sd = new ResourceEntity();
503         sd.resourceEntityId = "gblond2003me6";
504         sd.resourceEntityType = "VPE";
505         sd.resourceEntityVersion = "1";
506
507         ResourceTarget rt = new ResourceTarget();
508         rt.resourceTargetId = "MDTWNJ21A5";
509         rt.resourceTargetType = "Site";
510
511         ResourceRequest rr = new ResourceRequest();
512         rr.serviceModel = "MY-SERV-MODEL";
513         // rr.resourceName = "vlan-id-outer";
514         rr.endPointPosition = "VPE-Cust";
515         rr.rangeMaxOverride = -1;
516         rr.rangeMinOverride = -1;
517         rr.applicationId = "myapp";
518
519         List<ResourceResponse> rsList = new ArrayList<>();
520         resourceAllocator.reserve(sd, rt, rr, rsList);
521
522         // VPE-Core1
523         sd = new ResourceEntity();
524         sd.resourceEntityId = "gblond2003me6";
525         sd.resourceEntityType = "VPE";
526         sd.resourceEntityVersion = "1";
527
528         rt = new ResourceTarget();
529         rt.resourceTargetId = "MDTWNJ21A5";
530         rt.resourceTargetType = "Site";
531
532         rr = new ResourceRequest();
533         rr.serviceModel = "MY-SERV-MODEL";
534         // rr.resourceName = "vlan-id-filter";
535         rr.endPointPosition = "VPE-Core1";
536         rr.rangeMaxOverride = -1;
537         rr.rangeMinOverride = -1;
538         rr.applicationId = "myapp";
539
540         rsList = new ArrayList<>();
541         resourceAllocator.reserve(sd, rt, rr, rsList);
542
543         // VPE-Core2
544         sd = new ResourceEntity();
545         sd.resourceEntityId = "gblond2003me6";
546         sd.resourceEntityType = "VPE";
547         sd.resourceEntityVersion = "1";
548
549         rt = new ResourceTarget();
550         rt.resourceTargetId = "MDTWNJ21A5";
551         rt.resourceTargetType = "Site";
552
553         rr = new ResourceRequest();
554         rr.serviceModel = "MY-SERV-MODEL";
555         // rr.resourceName = "vlan-id-filter";
556         rr.endPointPosition = "VPE-Core2";
557         rr.rangeMaxOverride = -1;
558         rr.rangeMinOverride = -1;
559         rr.applicationId = "myapp";
560
561         rsList = new ArrayList<>();
562         resourceAllocator.reserve(sd, rt, rr, rsList);
563
564         // VPE-Core3
565         sd = new ResourceEntity();
566         sd.resourceEntityId = "gblond2003me6";
567         sd.resourceEntityType = "VPE";
568         sd.resourceEntityVersion = "1";
569
570         rt = new ResourceTarget();
571         rt.resourceTargetId = "MDTWNJ21A5";
572         rt.resourceTargetType = "Site";
573
574         rr = new ResourceRequest();
575         rr.serviceModel = "MY-SERV-MODEL";
576         // rr.resourceName = "vlan-id-filter";
577         rr.endPointPosition = "VPE-Core3";
578         rr.rangeMaxOverride = -1;
579         rr.rangeMinOverride = -1;
580         rr.applicationId = "myapp";
581
582         rsList = new ArrayList<>();
583         resourceAllocator.reserve(sd, rt, rr, rsList);
584
585         rsList.forEach(r -> {
586             StrUtil.info(log, r);
587         });
588
589         resource.print();
590         allocationItem.print();
591
592         log.info("========================  Query + t ==============================");
593         rsList = new ArrayList<>();
594         resourceAllocator.query(sd, null, rr, rsList);
595
596         rsList.forEach(r -> {
597             StrUtil.info(log, r);
598         });
599
600         SvcLogicContext ctx = new SvcLogicContext();
601         ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
602         ctx.setAttribute("ra-input.reservation-entity-type", "VPE");
603
604         QueryStatus st = resourceAllocator.release("NetworkCapacity", "gblond2003me6", ctx);
605         Assert.assertTrue(st == QueryStatus.SUCCESS);
606
607     }
608
609     @Test
610     public void test008() throws Exception {
611         String t = "008";
612         log.info("============== reserve " + t + " ================================");
613         log.info("=== Test range-force-new-numbers = false");
614
615         String entityId = "reserve" + t;
616         String targetId = "port-id-1";
617         String resourceName = "cust-vlan-id";
618
619         String assetId = "VNF::" + targetId;
620         String resourceUnion = "SI::" + entityId;
621         String resourceSet1 = resourceUnion + "::1";
622         String resourceSet2 = resourceUnion + "::2";
623
624         dataSetup.cleanup();
625
626         dataSetup.setupRangeItem(resourceName, assetId, resourceSet1, resourceUnion, "201");
627
628         SvcLogicContext ctx = new SvcLogicContext();
629         ctx.setAttribute("ra-input.service-model", "ADIG");
630         ctx.setAttribute("ra-input.check-only", "false");
631
632         ctx.setAttribute("ra-input.resource-name", resourceName);
633         ctx.setAttribute("ra-input.range-force-new-numbers", "false");
634
635         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
636         ctx.setAttribute("ra-input.reservation-entity-id", entityId);
637         ctx.setAttribute("ra-input.reservation-entity-version", "2");
638
639         ctx.setAttribute("ra-input.reservation-target-id", targetId);
640         ctx.setAttribute("ra-input.reservation-target-type", "VNF");
641
642         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
643
644         Assert.assertTrue(st == QueryStatus.SUCCESS);
645         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet1, "201"));
646         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet2, "201"));
647
648         Assert.assertEquals(ctx.getAttribute("resource-list_length"), "1");
649         Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-name"), "cust-vlan-id");
650         Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-target-type"), "VNF");
651         Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-target-id"), "port-id-1");
652         Assert.assertEquals(ctx.getAttribute("resource-list[0].status"), "Success");
653         Assert.assertEquals(ctx.getAttribute("resource-list[0].allocated"), "201");
654         Assert.assertEquals(ctx.getAttribute("resource-list[0].used"), "201");
655         Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list_length"), "1");
656         Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list[0].min"), "2");
657         Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list[0].max"), "1000");
658     }
659
660     @Test
661     public void test009() throws Exception {
662         String t = "009";
663         log.info("============== reserve " + t + " ================================");
664         log.info("=== Test range-force-new-numbers = true");
665
666         String entityId = "reserve" + t;
667         String targetId = "port-id-1";
668         String resourceName = "cust-vlan-id";
669
670         String assetId = "VNF::" + targetId;
671         String resourceUnion = "SI::" + entityId;
672         String resourceSet1 = resourceUnion + "::1";
673         String resourceSet2 = resourceUnion + "::2";
674
675         dataSetup.cleanup();
676
677         dataSetup.setupRangeItem(resourceName, assetId, resourceSet1, resourceUnion, "201");
678
679         SvcLogicContext ctx = new SvcLogicContext();
680         ctx.setAttribute("ra-input.service-model", "ADIG");
681         ctx.setAttribute("ra-input.check-only", "false");
682
683         ctx.setAttribute("ra-input.resource-name", resourceName);
684         ctx.setAttribute("ra-input.range-force-new-numbers", "true");
685
686         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
687         ctx.setAttribute("ra-input.reservation-entity-id", entityId);
688         ctx.setAttribute("ra-input.reservation-entity-version", "2");
689
690         ctx.setAttribute("ra-input.reservation-target-id", targetId);
691         ctx.setAttribute("ra-input.reservation-target-type", "VNF");
692
693         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
694
695         Assert.assertTrue(st == QueryStatus.SUCCESS);
696         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet1, "201"));
697         Assert.assertFalse(dataSetup.checkRangeItem(resourceName, assetId, resourceSet2, "201"));
698     }
699
700     @Test
701     public void test0010_vlantag_with_resourcemodel() throws Exception {
702
703         String t = "0010";
704         log.info("============== reserve " + t + " ================================");
705
706         dataSetup.cleanup();
707
708         TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS);
709         TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id",
710                 ALLOCATION_ITEM_COLUMNS);
711
712         ResourceEntity sd = new ResourceEntity();
713         sd.resourceEntityId = "gblond2003me6";
714         sd.resourceEntityType = "VNF";
715         sd.resourceEntityVersion = "1";
716
717         ResourceTarget rt = new ResourceTarget();
718         rt.resourceTargetId = "MDTWNJ21A5";
719         rt.resourceTargetType = "Site";
720
721         ResourceRequest rr = new ResourceRequest();
722         rr.serviceModel = "MY-SERV-MODEL_3456";
723         rr.resourceName = "vlan-id-outer";
724         rr.endPointPosition = "VPE-Core1";
725         rr.rangeMaxOverride = 3901;
726         rr.rangeMinOverride = 3900;
727         rr.resourceType = ResourceType.Range;
728         rr.applicationId = "myapp";
729
730         List<ResourceResponse> rsList = new ArrayList<>();
731         resourceAllocator.reserve(sd, rt, rr, rsList);
732
733         resource.print();
734         allocationItem.print();
735
736         Range range = new Range();
737         range.min = 3900;
738         range.max = 3901;
739
740         sd = new ResourceEntity();
741         sd.resourceEntityId = "gblond2003me6";
742         sd.resourceEntityType = "VNF";
743         sd.resourceEntityVersion = "1";
744
745         rt = new ResourceTarget();
746         rt.resourceTargetId = "MDTWNJ21A5";
747         rt.resourceTargetType = "Site";
748
749         rr = new ResourceRequest();
750         rr.serviceModel = "MY-SERV-MODEL_3456";
751         rr.resourceName = "vlan-id-outer";
752         rr.endPointPosition = "VPE-Core2";
753         rr.rangeMaxOverride = -1;
754         rr.rangeMinOverride = -1;
755         rr.rangeOverrideList = Arrays.asList(range);
756         rr.resourceType = ResourceType.Range;
757         rr.applicationId = "myapp";
758
759         rsList = new ArrayList<>();
760         resourceAllocator.reserve(sd, rt, rr, rsList);
761
762         resource.print();
763         allocationItem.print();
764
765         sd = new ResourceEntity();
766         sd.resourceEntityId = "gblond2003me6";
767         sd.resourceEntityType = "VNF";
768         sd.resourceEntityVersion = "1";
769
770         rt = new ResourceTarget();
771         rt.resourceTargetId = "MDTWNJ21A5";
772         rt.resourceTargetType = "Site";
773
774         Range range1 = new Range();
775         range1.min = 3900;
776         range1.max = 3901;
777
778         Range range2 = new Range();
779         range2.min = 3904;
780         range2.max = 3905;
781
782         rr = new ResourceRequest();
783         rr.serviceModel = "MY-SERV-MODEL_3456";
784         rr.resourceName = "vlan-id-outer";
785         rr.endPointPosition = "VPE-Core3";
786         rr.rangeMaxOverride = -1;
787         rr.rangeMinOverride = -1;
788         rr.rangeOverrideList = new ArrayList<>();
789         rr.rangeOverrideList.add(range1);
790         rr.rangeOverrideList.add(range2);
791         rr.applicationId = "myapp";
792         rr.resourceType = ResourceType.Range;
793
794         rsList = new ArrayList<>();
795         AllocationStatus status = resourceAllocator.reserve(sd, rt, rr, rsList);
796         Assert.assertTrue(status == AllocationStatus.Success);
797
798         resource.print();
799         allocationItem.print();
800
801         sd = new ResourceEntity();
802         sd.resourceEntityId = "gblond2003me6";
803         sd.resourceEntityType = "VNF";
804         sd.resourceEntityVersion = "1";
805
806         rr = new ResourceRequest();
807         rr.endPointPosition = "VPE-Core2";
808         status = resourceAllocator.release(sd, rr);
809         Assert.assertTrue(status == AllocationStatus.Success);
810
811         resource.print();
812         allocationItem.print();
813
814     }
815
816     @Test
817     public void test011() throws Exception {
818         String t = "011";
819         log.info("============== reserve " + t + " ================================");
820         log.info("=== Test range-next-in-sequence = true");
821
822         String entityId = "reserve" + t;
823         String targetId = "port-id-1";
824         String resourceName = "vlan-id-filter";
825
826         String assetId = "Site::" + targetId;
827         String resourceUnion = "SI::" + entityId;
828         String resourceSet = resourceUnion + "::1";
829
830         dataSetup.cleanup();
831         dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008");
832
833         SvcLogicContext ctx = new SvcLogicContext();
834         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL");
835         ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2");
836         ctx.setAttribute("ra-input.check-only", "false");
837
838         ctx.setAttribute("ra-input.resource-name", resourceName);
839         ctx.setAttribute("ra-input.range-next-in-sequence", "true");
840
841         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
842         ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test");
843         ctx.setAttribute("ra-input.reservation-entity-version", "1");
844
845         ctx.setAttribute("ra-input.reservation-target-id", targetId);
846         ctx.setAttribute("ra-input.reservation-target-type", "Site");
847
848         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
849
850         Assert.assertTrue(st == QueryStatus.SUCCESS);
851         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1009"));
852     }
853
854     @Test
855     public void test012() throws Exception {
856         String t = "012";
857         log.info("============== reserve " + t + " ================================");
858         log.info("=== Test range-next-in-sequence = false");
859
860         String entityId = "reserve" + t;
861         String targetId = "port-id-1";
862         String resourceName = "vlan-id-filter";
863
864         String assetId = "Site::" + targetId;
865         String resourceUnion = "SI::" + entityId;
866         String resourceSet = resourceUnion + "::1";
867
868         dataSetup.cleanup();
869         dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008");
870
871         SvcLogicContext ctx = new SvcLogicContext();
872         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL");
873         ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2");
874         ctx.setAttribute("ra-input.check-only", "false");
875
876         ctx.setAttribute("ra-input.resource-name", resourceName);
877         ctx.setAttribute("ra-input.range-next-in-sequence", "false");
878
879         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
880         ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test");
881         ctx.setAttribute("ra-input.reservation-entity-version", "1");
882
883         ctx.setAttribute("ra-input.reservation-target-id", targetId);
884         ctx.setAttribute("ra-input.reservation-target-type", "Site");
885
886         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
887
888         Assert.assertTrue(st == QueryStatus.SUCCESS);
889         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1003"));
890     }
891
892     @Test
893     public void test013() throws Exception {
894         String t = "013";
895         log.info("============== reserve " + t + " ================================");
896         log.info("=== Test range-next-in-sequence = true - multiple ranges");
897
898         String entityId = "reserve" + t;
899         String targetId = "port-id-1";
900         String resourceName = "vlan-id-filter";
901
902         String assetId = "Site::" + targetId;
903         String resourceUnion = "SI::" + entityId;
904         String resourceSet = resourceUnion + "::1";
905
906         dataSetup.cleanup();
907         dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008,2205-2221");
908
909         SvcLogicContext ctx = new SvcLogicContext();
910         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL");
911         ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2");
912         ctx.setAttribute("ra-input.check-only", "false");
913
914         ctx.setAttribute("ra-input.resource-name", resourceName);
915         ctx.setAttribute("ra-input.range-next-in-sequence", "true");
916
917         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
918         ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test");
919         ctx.setAttribute("ra-input.reservation-entity-version", "1");
920
921         ctx.setAttribute("ra-input.reservation-target-id", targetId);
922         ctx.setAttribute("ra-input.reservation-target-type", "Site");
923
924         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
925
926         Assert.assertTrue(st == QueryStatus.SUCCESS);
927         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "2222"));
928     }
929
930     @Test
931     public void test014() throws Exception {
932         String t = "014";
933         log.info("============== reserve " + t + " ================================");
934         log.info("=== Test range-next-in-sequence = true - no previously reserved numbers");
935
936         String entityId = "reserve" + t;
937         String targetId = "port-id-1";
938         String resourceName = "vlan-id-filter";
939
940         String assetId = "Site::" + targetId;
941
942         dataSetup.cleanup();
943
944         SvcLogicContext ctx = new SvcLogicContext();
945         ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL");
946         ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2");
947         ctx.setAttribute("ra-input.check-only", "false");
948
949         ctx.setAttribute("ra-input.resource-name", resourceName);
950         ctx.setAttribute("ra-input.range-next-in-sequence", "true");
951
952         ctx.setAttribute("ra-input.reservation-entity-type", "SI");
953         ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test");
954         ctx.setAttribute("ra-input.reservation-entity-version", "1");
955
956         ctx.setAttribute("ra-input.reservation-target-id", targetId);
957         ctx.setAttribute("ra-input.reservation-target-type", "Site");
958
959         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
960
961         Assert.assertTrue(st == QueryStatus.SUCCESS);
962         Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1002"));
963     }
964 }