1 package jtest.org.onap.ccsdk.sli.adaptors.ra;
3 import java.util.ArrayList;
4 import java.util.HashMap;
7 import org.junit.Assert;
8 import org.junit.FixMethodOrder;
10 import org.junit.runner.RunWith;
11 import org.junit.runners.MethodSorters;
12 import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
13 import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceEntity;
14 import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceRequest;
15 import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse;
16 import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceTarget;
17 import org.onap.ccsdk.sli.adaptors.rm.data.AllocationStatus;
18 import org.onap.ccsdk.sli.adaptors.util.str.StrUtil;
19 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
20 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.jdbc.core.JdbcTemplate;
25 import org.springframework.test.context.ContextConfiguration;
26 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
27 import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestTable;
29 @RunWith(SpringJUnit4ClassRunner.class)
30 @ContextConfiguration(locations = {"classpath:test-context.xml"})
31 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
32 public class TestReserve {
34 private static final Logger log = LoggerFactory.getLogger(TestReserve.class);
36 private JdbcTemplate jdbcTemplate;
38 private static final String[] RESOURCE_COLUMNS = {"asset_id", "resource_name", "resource_type", "lt_used"};
40 private static final String[] ALLOCATION_ITEM_COLUMNS = {"resource_id", "application_id", "resource_set_id",
41 "resource_union_id", "resource_share_group_list", "lt_used", "allocation_time"};
45 public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
46 this.jdbcTemplate = jdbcTemplate;
49 @Autowired(required = true)
50 private ResourceAllocator resourceAllocator;
53 * @Autowired(required = true) private ResourceAllocatorApi resourceAllocatorApi;
56 @Autowired(required = true)
57 private DataSetup dataSetup;
60 public void test001() throws Exception {
62 log.info("============== reserve " + t + " ================================");
63 log.info("=== Test successful response - new start - all resources available");
65 // String service1 = "reserve" + t + "/service1";
69 TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS);
70 TestTable allocationItem =
71 new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id", ALLOCATION_ITEM_COLUMNS);
74 SvcLogicContext ctx = new SvcLogicContext();
75 ctx.setAttribute("ra-input.service-model", "ADIG");
76 ctx.setAttribute("ra-input.check-only", "false");
77 ctx.setAttribute("ra-input.reservation-entity-type", "SI");
78 ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
79 ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100");
80 ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps");
82 ctx.setAttribute("ra-input.reservation-target-data.vnf-type", "VPE");
83 ctx.setAttribute("ra-input.reservation-target-data.vpe-name", "mdt300vpe54");
84 ctx.setAttribute("ra-input.reservation-target-id", "mdt300vpe54");
85 ctx.setAttribute("ra-input.reservation-target-type", "VNF");
87 ctx.setAttribute("ra-input.reservation-target-data.max-vpe-bandwidth-mbps", "5000");
90 QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
92 Assert.assertTrue(st == QueryStatus.SUCCESS);
95 allocationItem.print();
97 ctx.setAttribute("ra-input.service-model", "ADIG");
98 ctx.setAttribute("ra-input.check-only", "false");
99 ctx.setAttribute("ra-input.reservation-entity-type", "SI");
100 ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
101 ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100");
102 ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps");
104 ctx.setAttribute("ra-input.reservation-target-data.service-speed", "100");
105 ctx.setAttribute("ra-input.reservation-target-data.service-speed-unit", "Mbps");
106 ctx.setAttribute("ra-input.reservation-target-id", "ICORESITEID-123456");
107 ctx.setAttribute("ra-input.reservation-target-type", "Port");
110 st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
112 Assert.assertTrue(st == QueryStatus.SUCCESS);
114 ctx.setAttribute("ra-input.service-model", "ADIG");
115 ctx.setAttribute("ra-input.check-only", "false");
116 ctx.setAttribute("ra-input.reservation-entity-type", "SI");
117 ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
118 ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100");
119 ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps");
121 ctx.setAttribute("ra-input.reservation-target-data.vnf-type", "VPE");
122 ctx.setAttribute("ra-input.reservation-target-data.vpe-name", "mdt300vpe54");
123 ctx.setAttribute("ra-input.reservation-target-id", "mdt300vpe54");
124 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();
135 /* Query Using ReservationEntityId using ServiceLogicContext */
136 ctx = new SvcLogicContext();
137 ctx.setAttribute("ra-input.service-model", "ADIG");
138 ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
139 ctx.setAttribute("ra-input.reservation-entity-type", "SI");
142 st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
143 Assert.assertTrue(st == QueryStatus.SUCCESS);
146 /* Query Using ReservationTargetId using ServiceLogicContext */
147 ctx = new SvcLogicContext();
148 ctx.setAttribute("ra-input.service-model", "ADIG");
149 ctx.setAttribute("ra-input.reservation-target-id", "ICORESITEID-123456");
150 ctx.setAttribute("ra-input.reservation-target-type", "Port");
151 ctx.setAttribute("ra-input.resource-name", "Bandwidth");
153 st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
154 Assert.assertTrue(st == QueryStatus.SUCCESS);
156 log.info("======================== Query Using ResourceEntity==============================");
157 /* Query Using ResourceEntity bean */
158 ResourceEntity sd = new ResourceEntity();
159 sd.resourceEntityId = "ICOREPVCID-123456";
160 sd.resourceEntityType = "SI";
163 ResourceRequest rr = new ResourceRequest();
164 rr.serviceModel = "ADIG";
165 rr.resourceName = "cust-vlan-id";
166 rr.requestType = "New";
167 rr.rangeMaxOverride = -1;
168 rr.rangeMinOverride = -1;
170 List<ResourceResponse> rsList = new ArrayList<>();
171 resourceAllocator.query(sd, null, null, rsList);
173 rsList.forEach(r -> {
174 StrUtil.info(log, r);
177 log.info("======================== release Using ResourceEntity==============================");
178 rsList = new ArrayList<>();
179 AllocationStatus status = resourceAllocator.release(sd);
180 Assert.assertTrue(status == AllocationStatus.Success);
183 log.info("======================== Query Using ResourceEntity==============================");
184 rsList = new ArrayList<>();
185 resourceAllocator.query(sd, null, null, rsList);
188 rsList.forEach(r -> {
189 StrUtil.info(log, r);
195 public void test002() throws Exception {
197 log.info("============== reserve " + t + " ================================");
198 log.info("=== Test successful response - new start - all resources available");
200 Map<String, String> data = new HashMap<>();
201 data.put("service-speed", "100");
202 data.put("service-speed-unit", "Mbps");
204 ResourceEntity sd = new ResourceEntity();
205 sd.resourceEntityId = "ICOREPVCID-123456";
206 sd.resourceEntityType = "SI";
209 data = new HashMap<>();
210 data.put("vnf-type", "VPE");
211 data.put("vpe-name", "mdt300vpe54");
212 data.put("max-vpe-bandwidth-mbps", "5000");
214 ResourceTarget rt = new ResourceTarget();
215 rt.resourceTargetId = "mdt300vpe54";
216 rt.resourceTargetType = "VNF";
219 ResourceRequest rr = new ResourceRequest();
220 rr.serviceModel = "ADIG";
221 // rr.resourceName = "cust-vlan-id";
222 rr.requestType = "New";
223 rr.rangeMaxOverride = -1;
224 rr.rangeMinOverride = -1;
226 List<ResourceResponse> rsList = new ArrayList<>();
228 resourceAllocator.reserve(sd, rt, rr, rsList);
230 rsList.forEach(r -> {
231 StrUtil.info(log, r);
234 log.info("======================== Query + t ==============================");
235 rsList = new ArrayList<>();
236 resourceAllocator.query(sd, null, rr, rsList);
238 rsList.forEach(r -> {
239 StrUtil.info(log, r);
246 public void test003() throws Exception {
248 log.info("============== reserve " + t + " ================================");
249 log.info("=== Test successful response - new start - all resources available");
251 ResourceEntity sd = new ResourceEntity();
252 sd.resourceEntityId = "gblond2003me6";
253 sd.resourceEntityType = "VNF";
255 ResourceTarget rt = new ResourceTarget();
256 rt.resourceTargetId = "MDTWNJ21A5";
257 rt.resourceTargetType = "Site";
260 ResourceRequest rr= new ResourceRequest();
261 rr.serviceModel = "MY-SERV-MODEL";
262 rr.resourceName = "VPE-Cust";
263 //rr.requestType = "New";
264 //rr.rangeMaxOverride = 5;
265 //rr.rangeMinOverride = 5;
267 List <ResourceResponse> rsList = new ArrayList<ResourceResponse>();
268 resourceAllocator.reserve(sd, rt, rr, rsList);
270 rsList.forEach(r -> {
271 StrUtil.info(log, r);
274 log.info("======================== Query + t ==============================");
275 rsList = new ArrayList<org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse>();
276 resourceAllocator.query(sd, null, rr, rsList);
278 rsList.forEach(r -> {
279 StrUtil.info(log, r);
288 public void test004() throws Exception {
290 log.info("============== reserve " + t + " ================================");
291 log.info("=== Test successful response - new start - all resources available");
293 ResourceEntity sd = new ResourceEntity();
294 sd.resourceEntityId = "gblond2003me6";
295 sd.resourceEntityType = "VNF";
297 ResourceTarget rt = new ResourceTarget();
298 rt.resourceTargetId = "MDTWNJ21A5";
299 rt.resourceTargetType = "Site";
301 List<ResourceRequest> rrs = new ArrayList<ResourceRequest>();
302 ResourceRequest rr= new ResourceRequest();
303 rr.serviceModel = "MY-SERV-MODEL";
304 rr.resourceName = "VPE-Cust";
307 rr= new ResourceRequest();
308 rr.serviceModel = "MY-SERV-MODEL";
309 rr.resourceName = "VPE-Core1";
312 rr= new ResourceRequest();
313 rr.serviceModel = "MY-SERV-MODEL";
314 rr.resourceName = "VPE-Core2";
319 List <ResourceResponse> rsList = new ArrayList<ResourceResponse>();
320 //resourceAllocator.reserve(sd, rt, rrs, rsList);
322 rsList.forEach(r -> {
323 StrUtil.info(log, r);
326 log.info("======================== Query + t ==============================");
327 rsList = new ArrayList<org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse>();
328 resourceAllocator.query(sd, null, rr, rsList);
330 rsList.forEach(r -> {
331 StrUtil.info(log, r);
338 public void test005() throws Exception {
340 log.info("============== reserve " + t + " ================================");
341 log.info("=== Test successful response - new start - all resources available");
343 //String service1 = "reserve" + t + "/service1";
347 TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS);
348 TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id",
349 ALLOCATION_ITEM_COLUMNS);
352 SvcLogicContext ctx = new SvcLogicContext();
353 ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
354 ctx.setAttribute("ra-input.check-only", "false");
355 ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Cust");
356 ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
358 ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
359 ctx.setAttribute("ra-input.reservation-target-type", "Site");
361 ctx.setAttribute("ra-input.resource-name", "cust-vlan-id");
364 QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
366 Assert.assertTrue(st == QueryStatus.SUCCESS);
369 allocationItem.print();
371 ctx = new SvcLogicContext();
372 ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
373 ctx.setAttribute("ra-input.check-only", "false");
374 ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1");
375 ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
377 ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
378 ctx.setAttribute("ra-input.reservation-target-type", "Site");
380 ctx.setAttribute("ra-input.resource-name", "vlan-id-inner");
383 st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
385 Assert.assertTrue(st == QueryStatus.SUCCESS);
388 allocationItem.print();
390 ctx = new SvcLogicContext();
391 ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
392 ctx.setAttribute("ra-input.check-only", "false");
393 ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core2");
394 ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
396 ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
397 ctx.setAttribute("ra-input.reservation-target-type", "Site");
399 ctx.setAttribute("ra-input.resource-name", "vlan-id-inner");
400 ctx.setAttribute("ra-input.replace", "false");
403 st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
405 Assert.assertTrue(st == QueryStatus.SUCCESS);
408 allocationItem.print();
411 /*Query Using ReservationEntityId using ServiceLogicContext*/
412 ctx = new SvcLogicContext();
413 ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
414 ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
415 ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1");
418 st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
419 Assert.assertTrue(st == QueryStatus.SUCCESS);
422 /*Query Using ReservationTargetId using ServiceLogicContext*/
423 ctx = new SvcLogicContext();
424 ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1");
425 ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5");
426 ctx.setAttribute("ra-input.reservation-target-type", "Site");
427 ctx.setAttribute("ra-input.resource-name", "vlan-id-inner");
429 st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx);
430 Assert.assertTrue(st == QueryStatus.SUCCESS);
432 log.info("======================== Query Using ResourceEntity==============================");
433 /*Query Using ResourceEntity bean*/
434 ResourceEntity sd = new ResourceEntity();
435 sd.resourceEntityId = "gblond2003me6";
436 sd.resourceEntityType = "VPE-Core1";
439 ResourceRequest rr= new ResourceRequest();
440 rr.serviceModel = "MY-SERV-MODEL-1";
441 rr.resourceName = "vlan-id-inner";
442 rr.requestType = "New";
443 rr.rangeMaxOverride = -1;
444 rr.rangeMinOverride = -1;
446 List <ResourceResponse> rsList = new ArrayList<ResourceResponse>();
447 resourceAllocator.query(sd, null, null, rsList);
449 rsList.forEach(r -> {
450 StrUtil.info(log, r);
453 /*log.info("======================== release Using ResourceEntity==============================");
454 rsList = new ArrayList<ResourceResponse>();
455 AllocationStatus status = resourceAllocator.release(sd);
456 Assert.assertTrue(status == AllocationStatus.Success);
459 log.info("======================== Query Using ResourceEntity==============================");
460 rsList = new ArrayList<ResourceResponse>();
461 resourceAllocator.query(sd, null, null, rsList);
464 rsList.forEach(r -> {
465 StrUtil.info(log, r);
473 public void test006() throws Exception {
475 log.info("============== reserve " + t + " ================================");
476 log.info("=== Test successful response - new start - all resources available");
478 ResourceEntity sd = new ResourceEntity();
479 sd.resourceEntityId = "gblond2003me6";
480 sd.resourceEntityType = "VPE-Cust";
482 ResourceTarget rt = new ResourceTarget();
483 rt.resourceTargetId = "MDTWNJ21A5";
484 rt.resourceTargetType = "Site";
487 ResourceRequest rr= new ResourceRequest();
488 rr.serviceModel = "MY-SERV-MODEL-1";
489 rr.resourceName = "cust-vlan-id";
492 List <ResourceResponse> rsList = new ArrayList<ResourceResponse>();
493 resourceAllocator.reserve(sd, rt, rr, rsList);
495 rsList.forEach(r -> {
496 StrUtil.info(log, r);
499 log.info("======================== Query + t ==============================");
500 rsList = new ArrayList<org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse>();
501 resourceAllocator.query(sd, null, rr, rsList);
503 rsList.forEach(r -> {
504 StrUtil.info(log, r);
510 public void test007() throws Exception {
512 log.info("============== reserve " + t + " ================================");
513 log.info("=== Test successful response - new start - all resources available");
517 TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS);
518 TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id",
519 ALLOCATION_ITEM_COLUMNS);
522 ResourceEntity sd = new ResourceEntity();
523 sd.resourceEntityId = "gblond2003me6";
524 sd.resourceEntityType = "VPE";
525 sd.resourceEntityVersion = "1";
527 ResourceTarget rt = new ResourceTarget();
528 rt.resourceTargetId = "MDTWNJ21A5";
529 rt.resourceTargetType = "Site";
532 ResourceRequest rr= new ResourceRequest();
533 rr.serviceModel = "MY-SERV-MODEL";
534 //rr.resourceName = "vlan-id-outer";
535 rr.endPointPosition="VPE-Cust";
536 rr.rangeMaxOverride = -1;
537 rr.rangeMinOverride = -1;
540 List <ResourceResponse> rsList = new ArrayList<ResourceResponse>();
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";
554 rr= new ResourceRequest();
555 rr.serviceModel = "MY-SERV-MODEL";
556 //rr.resourceName = "vlan-id-filter";
557 rr.endPointPosition="VPE-Core1";
558 rr.rangeMaxOverride = -1;
559 rr.rangeMinOverride = -1;
562 rsList = new ArrayList<ResourceResponse>();
563 resourceAllocator.reserve(sd, rt, rr, rsList);
567 sd = new ResourceEntity();
568 sd.resourceEntityId = "gblond2003me6";
569 sd.resourceEntityType = "VPE";
570 sd.resourceEntityVersion = "1";
572 rt = new ResourceTarget();
573 rt.resourceTargetId = "MDTWNJ21A5";
574 rt.resourceTargetType = "Site";
577 rr= new ResourceRequest();
578 rr.serviceModel = "MY-SERV-MODEL";
579 //rr.resourceName = "vlan-id-filter";
580 rr.endPointPosition="VPE-Core2";
581 rr.rangeMaxOverride = -1;
582 rr.rangeMinOverride = -1;
585 rsList = new ArrayList<ResourceResponse>();
586 resourceAllocator.reserve(sd, rt, rr, rsList);
590 sd = new ResourceEntity();
591 sd.resourceEntityId = "gblond2003me6";
592 sd.resourceEntityType = "VPE";
593 sd.resourceEntityVersion = "1";
595 rt = new ResourceTarget();
596 rt.resourceTargetId = "MDTWNJ21A5";
597 rt.resourceTargetType = "Site";
600 rr= new ResourceRequest();
601 rr.serviceModel = "MY-SERV-MODEL";
602 //rr.resourceName = "vlan-id-filter";
603 rr.endPointPosition="VPE-Core3";
604 rr.rangeMaxOverride = -1;
605 rr.rangeMinOverride = -1;
608 rsList = new ArrayList<ResourceResponse>();
609 resourceAllocator.reserve(sd, rt, rr, rsList);
611 rsList.forEach(r -> {
612 StrUtil.info(log, r);
616 allocationItem.print();
618 log.info("======================== Query + t ==============================");
619 rsList = new ArrayList<org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse>();
620 resourceAllocator.query(sd, null, rr, rsList);
622 rsList.forEach(r -> {
623 StrUtil.info(log, r);
628 SvcLogicContext ctx = new SvcLogicContext();
629 ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6");
630 ctx.setAttribute("ra-input.reservation-entity-type", "VPE");
633 QueryStatus st = resourceAllocator.release("NetworkCapacity", "gblond2003me6", ctx);
634 Assert.assertTrue(st == QueryStatus.SUCCESS);