[CCSDK-6] Populate seed code
[ccsdk/sli/adaptors.git] / resource-assignment / provider / src / main / java / org / openecomp / sdnc / ra / alloc / ServingSiteAllocationRule.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 org.openecomp.sdnc.ra.comp.AllocationRule;
25 import org.openecomp.sdnc.ra.comp.ServiceData;
26 import org.openecomp.sdnc.ra.equip.data.EquipmentData;
27 import org.openecomp.sdnc.rm.data.AllocationAction;
28 import org.openecomp.sdnc.rm.data.AllocationRequest;
29 import org.openecomp.sdnc.rm.data.LimitAllocationRequest;
30 import org.openecomp.sdnc.util.vrf.VpnParam;
31 import org.openecomp.sdnc.util.vrf.VrfUtil;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class ServingSiteAllocationRule implements AllocationRule {
36
37         private static final Logger log = LoggerFactory.getLogger(ServingSiteAllocationRule.class);
38
39         @Override
40         public AllocationRequest buildAllocationRequest(
41                 String resourceUnionId,
42                 String resourceSetId,
43                 String endPointPosition,
44                 ServiceData serviceData,
45                 EquipmentData equipmentData,
46                 boolean checkOnly,
47                 boolean change) {
48                 String vrfName = (String) serviceData.data.get("vrf-name");
49                 if (vrfName == null)
50                         return null;
51
52                 log.info("vrfName: " + vrfName);
53
54                 String v4ServingSiteStr = (String) serviceData.data.get("v4-serving-site");
55                 String v6ServingSiteStr = (String) serviceData.data.get("v6-serving-site");
56                 boolean v4ServingSite = v4ServingSiteStr != null &&
57                         (v4ServingSiteStr.equalsIgnoreCase("Y") || v4ServingSiteStr.equalsIgnoreCase("true"));
58                 boolean v6ServingSite = v6ServingSiteStr != null &&
59                         (v6ServingSiteStr.equalsIgnoreCase("Y") || v6ServingSiteStr.equalsIgnoreCase("true"));
60                 if (!v4ServingSite && !v6ServingSite)
61                         return null;
62
63                 VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName);
64
65                 LimitAllocationRequest ar = new LimitAllocationRequest();
66                 ar.resourceSetId = resourceSetId;
67                 ar.resourceUnionId = resourceUnionId;
68                 ar.resourceName = "ServingSite";
69                 ar.assetId = equipmentData.equipmentId + "-" + vpnp.vpnId;
70                 ar.missingResourceAction = AllocationAction.Succeed_Allocate;
71                 ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
72                 ar.replace = true;
73                 ar.strict = false;
74                 ar.checkLimit = 1;
75                 ar.checkCount = 1;
76                 ar.allocateCount = 1;
77
78                 return ar;
79         }
80 }