1 package jtest.org.onap.ccsdk.sli.adaptors.ra;
3 import static org.junit.Assert.assertNotNull;
4 import java.util.ArrayList;
5 import java.util.Arrays;
6 import java.util.HashMap;
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;
33 @RunWith(SpringJUnit4ClassRunner.class)
34 @ContextConfiguration(locations = { "classpath:test-context.xml" })
35 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
36 public class TestReserve {
38 private static final Logger log = LoggerFactory.getLogger(TestReserve.class);
40 private JdbcTemplate jdbcTemplate;
42 private static final String[] RESOURCE_COLUMNS = { "asset_id", "resource_name", "resource_type", "lt_used" };
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" };
48 public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
49 this.jdbcTemplate = jdbcTemplate;
52 @Autowired(required = true)
53 private ResourceAllocator resourceAllocator;
56 * @Autowired(required = true) private ResourceAllocatorApi
57 * resourceAllocatorApi;
60 @Autowired(required = true)
61 private DataSetup dataSetup;
64 public void test001() throws Exception {
66 log.info("============== reserve " + t + " ================================");
67 log.info("=== Test successful response - new start - all resources available");
69 // String service1 = "reserve" + t + "/service1";
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);
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");
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");
90 ctx.setAttribute("ra-input.reservation-target-data.max-vpe-bandwidth-mbps", "5000");
92 QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
94 Assert.assertTrue(st == QueryStatus.SUCCESS);
97 allocationItem.print();
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");
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");
111 st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
113 Assert.assertTrue(st == QueryStatus.SUCCESS);
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");
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");
127 st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
129 Assert.assertTrue(st == QueryStatus.SUCCESS);
132 allocationItem.print();
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");
140 st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
141 Assert.assertTrue(st == QueryStatus.SUCCESS);
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");
150 st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
151 Assert.assertTrue(st == QueryStatus.SUCCESS);
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";
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;
166 List<ResourceResponse> rsList = new ArrayList<>();
167 resourceAllocator.query(sd, null, null, rsList);
169 rsList.forEach(r -> {
170 StrUtil.info(log, r);
173 log.info("======================== release Using ResourceEntity==============================");
174 rsList = new ArrayList<>();
175 AllocationStatus status = resourceAllocator.release(sd);
176 Assert.assertTrue(status == AllocationStatus.Success);
178 log.info("======================== Query Using ResourceEntity==============================");
179 rsList = new ArrayList<>();
180 resourceAllocator.query(sd, null, null, rsList);
182 rsList.forEach(r -> {
183 StrUtil.info(log, r);
189 public void test002() throws Exception {
191 log.info("============== reserve " + t + " ================================");
192 log.info("=== Test successful response - new start - all resources available");
194 Map<String, String> data = new HashMap<>();
195 data.put("service-speed", "100");
196 data.put("service-speed-unit", "Mbps");
198 ResourceEntity sd = new ResourceEntity();
199 sd.resourceEntityId = "ICOREPVCID-123456";
200 sd.resourceEntityType = "SI";
203 data = new HashMap<>();
204 data.put("vnf-type", "VPE");
205 data.put("vpe-name", "mdt300vpe54");
206 data.put("max-vpe-bandwidth-mbps", "5000");
208 ResourceTarget rt = new ResourceTarget();
209 rt.resourceTargetId = "mdt300vpe54";
210 rt.resourceTargetType = "VNF";
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";
221 List<ResourceResponse> rsList = new ArrayList<>();
223 resourceAllocator.reserve(sd, rt, rr, rsList);
225 rsList.forEach(r -> {
226 StrUtil.info(log, r);
229 log.info("======================== Query + t ==============================");
230 rsList = new ArrayList<>();
231 resourceAllocator.query(sd, null, rr, rsList);
233 rsList.forEach(r -> {
234 StrUtil.info(log, r);
236 assertNotNull(rsList);
241 public void test003() throws Exception {
243 log.info("============== reserve " + t + " ================================");
244 log.info("=== Test successful response - new start - all resources available");
246 ResourceEntity sd = new ResourceEntity();
247 sd.resourceEntityId = "gblond2003me6";
248 sd.resourceEntityType = "VNF";
250 ResourceTarget rt = new ResourceTarget();
251 rt.resourceTargetId = "MDTWNJ21A5";
252 rt.resourceTargetType = "Site";
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;
261 List<ResourceResponse> rsList = new ArrayList<>();
262 resourceAllocator.reserve(sd, rt, rr, rsList);
264 rsList.forEach(r -> {
265 StrUtil.info(log, r);
268 log.info("======================== Query + t ==============================");
269 rsList = new ArrayList<>();
270 resourceAllocator.query(sd, null, rr, rsList);
272 rsList.forEach(r -> {
273 StrUtil.info(log, r);
280 public void test004() throws Exception {
282 log.info("============== reserve " + t + " ================================");
283 log.info("=== Test successful response - new start - all resources available");
285 ResourceEntity sd = new ResourceEntity();
286 sd.resourceEntityId = "gblond2003me6";
287 sd.resourceEntityType = "VNF";
289 ResourceTarget rt = new ResourceTarget();
290 rt.resourceTargetId = "MDTWNJ21A5";
291 rt.resourceTargetType = "Site";
293 List<ResourceRequest> rrs = new ArrayList<>();
294 ResourceRequest rr = new ResourceRequest();
295 rr.serviceModel = "MY-SERV-MODEL";
296 rr.resourceName = "VPE-Cust";
299 rr = new ResourceRequest();
300 rr.serviceModel = "MY-SERV-MODEL";
301 rr.resourceName = "VPE-Core1";
304 rr = new ResourceRequest();
305 rr.serviceModel = "MY-SERV-MODEL";
306 rr.resourceName = "VPE-Core2";
309 List<ResourceResponse> rsList = new ArrayList<>();
310 // resourceAllocator.reserve(sd, rt, rrs, rsList);
312 rsList.forEach(r -> {
313 StrUtil.info(log, r);
316 log.info("======================== Query + t ==============================");
317 rsList = new ArrayList<>();
318 resourceAllocator.query(sd, null, rr, rsList);
320 rsList.forEach(r -> {
321 StrUtil.info(log, r);
328 public void test005() throws Exception {
330 log.info("============== reserve " + t + " ================================");
331 log.info("=== Test successful response - new start - all resources available");
333 // String service1 = "reserve" + t + "/service1";
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);
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");
347 ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
348 ctx.setAttribute("ra-input.reservation-target-type", "Site");
350 ctx.setAttribute("ra-input.resource-name", "cust-vlan-id");
352 QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
354 Assert.assertTrue(st == QueryStatus.SUCCESS);
357 allocationItem.print();
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");
365 ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
366 ctx.setAttribute("ra-input.reservation-target-type", "Site");
368 ctx.setAttribute("ra-input.resource-name", "vlan-id-inner");
370 st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
372 Assert.assertTrue(st == QueryStatus.SUCCESS);
375 allocationItem.print();
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");
383 ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
384 ctx.setAttribute("ra-input.reservation-target-type", "Site");
386 ctx.setAttribute("ra-input.resource-name", "vlan-id-inner");
387 ctx.setAttribute("ra-input.replace", "false");
389 st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
391 Assert.assertTrue(st == QueryStatus.SUCCESS);
394 allocationItem.print();
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");
402 st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
403 Assert.assertTrue(st == QueryStatus.SUCCESS);
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");
412 st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
413 Assert.assertTrue(st == QueryStatus.SUCCESS);
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";
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;
428 List<ResourceResponse> rsList = new ArrayList<>();
429 resourceAllocator.query(sd, null, null, rsList);
431 rsList.forEach(r -> {
432 StrUtil.info(log, r);
437 * info("======================== release Using ResourceEntity=============================="
438 * ); rsList = new ArrayList<ResourceResponse>(); AllocationStatus status =
439 * resourceAllocator.release(sd); Assert.assertTrue(status ==
440 * AllocationStatus.Success);
444 * info("======================== Query Using ResourceEntity=============================="
445 * ); rsList = new ArrayList<ResourceResponse>(); resourceAllocator.query(sd,
446 * null, null, rsList);
449 * rsList.forEach(r -> { StrUtil.info(log, r); });
455 public void test006() throws Exception {
457 log.info("============== reserve " + t + " ================================");
458 log.info("=== Test successful response - new start - all resources available");
460 ResourceEntity sd = new ResourceEntity();
461 sd.resourceEntityId = "gblond2003me6";
462 sd.resourceEntityType = "VPE-Cust";
464 ResourceTarget rt = new ResourceTarget();
465 rt.resourceTargetId = "MDTWNJ21A5";
466 rt.resourceTargetType = "Site";
468 ResourceRequest rr = new ResourceRequest();
469 rr.serviceModel = "MY-SERV-MODEL-1";
470 rr.resourceName = "cust-vlan-id";
472 List<ResourceResponse> rsList = new ArrayList<>();
473 resourceAllocator.reserve(sd, rt, rr, rsList);
475 rsList.forEach(r -> {
476 StrUtil.info(log, r);
479 log.info("======================== Query + t ==============================");
480 rsList = new ArrayList<>();
481 resourceAllocator.query(sd, null, rr, rsList);
483 rsList.forEach(r -> {
484 StrUtil.info(log, r);
486 assertNotNull(rsList);
491 public void test007() throws Exception {
493 log.info("============== reserve " + t + " ================================");
494 log.info("=== Test successful response - new start - all resources available");
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);
502 ResourceEntity sd = new ResourceEntity();
503 sd.resourceEntityId = "gblond2003me6";
504 sd.resourceEntityType = "VPE";
505 sd.resourceEntityVersion = "1";
507 ResourceTarget rt = new ResourceTarget();
508 rt.resourceTargetId = "MDTWNJ21A5";
509 rt.resourceTargetType = "Site";
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";
519 List<ResourceResponse> rsList = new ArrayList<>();
520 resourceAllocator.reserve(sd, rt, rr, rsList);
523 sd = new ResourceEntity();
524 sd.resourceEntityId = "gblond2003me6";
525 sd.resourceEntityType = "VPE";
526 sd.resourceEntityVersion = "1";
528 rt = new ResourceTarget();
529 rt.resourceTargetId = "MDTWNJ21A5";
530 rt.resourceTargetType = "Site";
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";
540 rsList = new ArrayList<>();
541 resourceAllocator.reserve(sd, rt, rr, rsList);
544 sd = new ResourceEntity();
545 sd.resourceEntityId = "gblond2003me6";
546 sd.resourceEntityType = "VPE";
547 sd.resourceEntityVersion = "1";
549 rt = new ResourceTarget();
550 rt.resourceTargetId = "MDTWNJ21A5";
551 rt.resourceTargetType = "Site";
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";
561 rsList = new ArrayList<>();
562 resourceAllocator.reserve(sd, rt, rr, rsList);
565 sd = new ResourceEntity();
566 sd.resourceEntityId = "gblond2003me6";
567 sd.resourceEntityType = "VPE";
568 sd.resourceEntityVersion = "1";
570 rt = new ResourceTarget();
571 rt.resourceTargetId = "MDTWNJ21A5";
572 rt.resourceTargetType = "Site";
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";
582 rsList = new ArrayList<>();
583 resourceAllocator.reserve(sd, rt, rr, rsList);
585 rsList.forEach(r -> {
586 StrUtil.info(log, r);
590 allocationItem.print();
592 log.info("======================== Query + t ==============================");
593 rsList = new ArrayList<>();
594 resourceAllocator.query(sd, null, rr, rsList);
596 rsList.forEach(r -> {
597 StrUtil.info(log, r);
600 SvcLogicContext ctx = new SvcLogicContext();
601 ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
602 ctx.setAttribute("ra-input.reservation-entity-type", "VPE");
604 QueryStatus st = resourceAllocator.release("NetworkCapacity", "gblond2003me6", ctx);
605 Assert.assertTrue(st == QueryStatus.SUCCESS);
610 public void test008() throws Exception {
612 log.info("============== reserve " + t + " ================================");
613 log.info("=== Test range-force-new-numbers = false");
615 String entityId = "reserve" + t;
616 String targetId = "port-id-1";
617 String resourceName = "cust-vlan-id";
619 String assetId = "VNF::" + targetId;
620 String resourceUnion = "SI::" + entityId;
621 String resourceSet1 = resourceUnion + "::1";
622 String resourceSet2 = resourceUnion + "::2";
626 dataSetup.setupRangeItem(resourceName, assetId, resourceSet1, resourceUnion, "201");
628 SvcLogicContext ctx = new SvcLogicContext();
629 ctx.setAttribute("ra-input.service-model", "ADIG");
630 ctx.setAttribute("ra-input.check-only", "false");
632 ctx.setAttribute("ra-input.resource-name", resourceName);
633 ctx.setAttribute("ra-input.range-force-new-numbers", "false");
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");
639 ctx.setAttribute("ra-input.reservation-target-id", targetId);
640 ctx.setAttribute("ra-input.reservation-target-type", "VNF");
642 QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
644 Assert.assertTrue(st == QueryStatus.SUCCESS);
645 Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet1, "201"));
646 Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet2, "201"));
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");
661 public void test009() throws Exception {
663 log.info("============== reserve " + t + " ================================");
664 log.info("=== Test range-force-new-numbers = true");
666 String entityId = "reserve" + t;
667 String targetId = "port-id-1";
668 String resourceName = "cust-vlan-id";
670 String assetId = "VNF::" + targetId;
671 String resourceUnion = "SI::" + entityId;
672 String resourceSet1 = resourceUnion + "::1";
673 String resourceSet2 = resourceUnion + "::2";
677 dataSetup.setupRangeItem(resourceName, assetId, resourceSet1, resourceUnion, "201");
679 SvcLogicContext ctx = new SvcLogicContext();
680 ctx.setAttribute("ra-input.service-model", "ADIG");
681 ctx.setAttribute("ra-input.check-only", "false");
683 ctx.setAttribute("ra-input.resource-name", resourceName);
684 ctx.setAttribute("ra-input.range-force-new-numbers", "true");
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");
690 ctx.setAttribute("ra-input.reservation-target-id", targetId);
691 ctx.setAttribute("ra-input.reservation-target-type", "VNF");
693 QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
695 Assert.assertTrue(st == QueryStatus.SUCCESS);
696 Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet1, "201"));
697 Assert.assertFalse(dataSetup.checkRangeItem(resourceName, assetId, resourceSet2, "201"));
701 public void test0010_vlantag_with_resourcemodel() throws Exception {
704 log.info("============== reserve " + t + " ================================");
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);
712 ResourceEntity sd = new ResourceEntity();
713 sd.resourceEntityId = "gblond2003me6";
714 sd.resourceEntityType = "VNF";
715 sd.resourceEntityVersion = "1";
717 ResourceTarget rt = new ResourceTarget();
718 rt.resourceTargetId = "MDTWNJ21A5";
719 rt.resourceTargetType = "Site";
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";
730 List<ResourceResponse> rsList = new ArrayList<>();
731 resourceAllocator.reserve(sd, rt, rr, rsList);
734 allocationItem.print();
736 Range range = new Range();
740 sd = new ResourceEntity();
741 sd.resourceEntityId = "gblond2003me6";
742 sd.resourceEntityType = "VNF";
743 sd.resourceEntityVersion = "1";
745 rt = new ResourceTarget();
746 rt.resourceTargetId = "MDTWNJ21A5";
747 rt.resourceTargetType = "Site";
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";
759 rsList = new ArrayList<>();
760 resourceAllocator.reserve(sd, rt, rr, rsList);
763 allocationItem.print();
765 sd = new ResourceEntity();
766 sd.resourceEntityId = "gblond2003me6";
767 sd.resourceEntityType = "VNF";
768 sd.resourceEntityVersion = "1";
770 rt = new ResourceTarget();
771 rt.resourceTargetId = "MDTWNJ21A5";
772 rt.resourceTargetType = "Site";
774 Range range1 = new Range();
778 Range range2 = new Range();
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;
794 rsList = new ArrayList<>();
795 AllocationStatus status = resourceAllocator.reserve(sd, rt, rr, rsList);
796 Assert.assertTrue(status == AllocationStatus.Success);
799 allocationItem.print();
801 sd = new ResourceEntity();
802 sd.resourceEntityId = "gblond2003me6";
803 sd.resourceEntityType = "VNF";
804 sd.resourceEntityVersion = "1";
806 rr = new ResourceRequest();
807 rr.endPointPosition = "VPE-Core2";
808 status = resourceAllocator.release(sd, rr);
809 Assert.assertTrue(status == AllocationStatus.Success);
812 allocationItem.print();
817 public void test011() throws Exception {
819 log.info("============== reserve " + t + " ================================");
820 log.info("=== Test range-next-in-sequence = true");
822 String entityId = "reserve" + t;
823 String targetId = "port-id-1";
824 String resourceName = "vlan-id-filter";
826 String assetId = "Site::" + targetId;
827 String resourceUnion = "SI::" + entityId;
828 String resourceSet = resourceUnion + "::1";
831 dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008");
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");
838 ctx.setAttribute("ra-input.resource-name", resourceName);
839 ctx.setAttribute("ra-input.range-next-in-sequence", "true");
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");
845 ctx.setAttribute("ra-input.reservation-target-id", targetId);
846 ctx.setAttribute("ra-input.reservation-target-type", "Site");
848 QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
850 Assert.assertTrue(st == QueryStatus.SUCCESS);
851 Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1009"));
855 public void test012() throws Exception {
857 log.info("============== reserve " + t + " ================================");
858 log.info("=== Test range-next-in-sequence = false");
860 String entityId = "reserve" + t;
861 String targetId = "port-id-1";
862 String resourceName = "vlan-id-filter";
864 String assetId = "Site::" + targetId;
865 String resourceUnion = "SI::" + entityId;
866 String resourceSet = resourceUnion + "::1";
869 dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008");
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");
876 ctx.setAttribute("ra-input.resource-name", resourceName);
877 ctx.setAttribute("ra-input.range-next-in-sequence", "false");
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");
883 ctx.setAttribute("ra-input.reservation-target-id", targetId);
884 ctx.setAttribute("ra-input.reservation-target-type", "Site");
886 QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
888 Assert.assertTrue(st == QueryStatus.SUCCESS);
889 Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1003"));
893 public void test013() throws Exception {
895 log.info("============== reserve " + t + " ================================");
896 log.info("=== Test range-next-in-sequence = true - multiple ranges");
898 String entityId = "reserve" + t;
899 String targetId = "port-id-1";
900 String resourceName = "vlan-id-filter";
902 String assetId = "Site::" + targetId;
903 String resourceUnion = "SI::" + entityId;
904 String resourceSet = resourceUnion + "::1";
907 dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008,2205-2221");
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");
914 ctx.setAttribute("ra-input.resource-name", resourceName);
915 ctx.setAttribute("ra-input.range-next-in-sequence", "true");
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");
921 ctx.setAttribute("ra-input.reservation-target-id", targetId);
922 ctx.setAttribute("ra-input.reservation-target-type", "Site");
924 QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
926 Assert.assertTrue(st == QueryStatus.SUCCESS);
927 Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "2222"));
931 public void test014() throws Exception {
933 log.info("============== reserve " + t + " ================================");
934 log.info("=== Test range-next-in-sequence = true - no previously reserved numbers");
936 String entityId = "reserve" + t;
937 String targetId = "port-id-1";
938 String resourceName = "vlan-id-filter";
940 String assetId = "Site::" + targetId;
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");
949 ctx.setAttribute("ra-input.resource-name", resourceName);
950 ctx.setAttribute("ra-input.range-next-in-sequence", "true");
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");
956 ctx.setAttribute("ra-input.reservation-target-id", targetId);
957 ctx.setAttribute("ra-input.reservation-target-type", "Site");
959 QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
961 Assert.assertTrue(st == QueryStatus.SUCCESS);
962 Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1002"));