[CCSDK-6] Populate seed code
[ccsdk/sli/adaptors.git] / resource-assignment / provider / src / main / java / org / openecomp / sdnc / ra / alloc / VrfAllocationRule.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 ONAP Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.sdnc.ra.alloc;
23
24 import java.util.ArrayList;
25 import java.util.HashSet;
26 import java.util.Set;
27
28 import org.openecomp.sdnc.ra.comp.AllocationRule;
29 import org.openecomp.sdnc.ra.comp.ServiceData;
30 import org.openecomp.sdnc.ra.equip.data.EquipmentData;
31 import org.openecomp.sdnc.rm.data.AllocationAction;
32 import org.openecomp.sdnc.rm.data.AllocationRequest;
33 import org.openecomp.sdnc.rm.data.LimitAllocationRequest;
34 import org.openecomp.sdnc.rm.data.MultiResourceAllocationRequest;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 public class VrfAllocationRule implements AllocationRule {
39
40         private static final Logger log = LoggerFactory.getLogger(VrfAllocationRule.class);
41
42         @Override
43         public AllocationRequest buildAllocationRequest(
44                 String resourceUnionId,
45                 String resourceSetId,
46                 String endPointPosition,
47                 ServiceData serviceData,
48                 EquipmentData equipmentData,
49                 boolean checkOnly,
50                 boolean change) {
51                 String vrfName = (String) serviceData.data.get("vrf-name");
52                 if (vrfName == null)
53                         return null;
54
55                 log.info("vrfName: " + vrfName);
56
57                 Set<String> resourceShareGroupList = new HashSet<>();
58                 resourceShareGroupList.add(vrfName);
59
60                 LimitAllocationRequest ar = new LimitAllocationRequest();
61                 ar.resourceSetId = resourceSetId;
62                 ar.resourceUnionId = resourceUnionId;
63                 ar.resourceShareGroupList = resourceShareGroupList;
64                 ar.resourceName = "VRF";
65                 ar.assetId = equipmentData.equipmentId;
66                 ar.missingResourceAction = AllocationAction.Succeed_Allocate;
67                 ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
68                 ar.replace = true;
69                 ar.strict = false;
70                 ar.checkLimit = 999999999;
71                 ar.checkCount = 1;
72                 ar.allocateCount = 1;
73
74                 String v4MulticastStr = (String) serviceData.data.get("v4-multicast");
75                 String v6MulticastStr = (String) serviceData.data.get("v6-multicast");
76                 boolean v4Multicast = v4MulticastStr != null &&
77                         (v4MulticastStr.equalsIgnoreCase("Y") || v4MulticastStr.equalsIgnoreCase("true"));
78                 boolean v6Multicast = v6MulticastStr != null &&
79                         (v6MulticastStr.equalsIgnoreCase("Y") || v6MulticastStr.equalsIgnoreCase("true"));
80                 if (v4Multicast || v6Multicast) {
81                         LimitAllocationRequest ar2 = new LimitAllocationRequest();
82                         ar2.resourceSetId = resourceSetId;
83                         ar2.resourceUnionId = resourceUnionId;
84                         ar2.resourceShareGroupList = resourceShareGroupList;
85                         ar2.resourceName = "MVRF";
86                         ar2.assetId = equipmentData.equipmentId;
87                         ar2.missingResourceAction = AllocationAction.Succeed_Allocate;
88                         ar2.expiredResourceAction = AllocationAction.Succeed_Allocate;
89                         ar2.replace = true;
90                         ar2.strict = false;
91                         ar2.checkLimit = 999999999;
92                         ar2.checkCount = 1;
93                         ar2.allocateCount = 1;
94
95                         MultiResourceAllocationRequest mar = new MultiResourceAllocationRequest();
96                         mar.resourceSetId = resourceSetId;
97                         mar.resourceUnionId = resourceUnionId;
98                         mar.resourceShareGroupList = resourceShareGroupList;
99                         mar.assetId = equipmentData.equipmentId;
100                         mar.missingResourceAction = AllocationAction.Succeed_Allocate;
101                         mar.expiredResourceAction = AllocationAction.Succeed_Allocate;
102                         mar.allocationRequestList = new ArrayList<>();
103                         mar.allocationRequestList.add(ar);
104                         mar.allocationRequestList.add(ar2);
105
106                         return mar;
107                 }
108
109                 return ar;
110         }
111 }