2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.sdnc.ra.check;
26 import org.openecomp.sdnc.ra.comp.EquipmentCheck;
27 import org.openecomp.sdnc.ra.comp.ServiceData;
28 import org.openecomp.sdnc.ra.equip.data.EquipmentData;
29 import org.openecomp.sdnc.rm.comp.ResourceManager;
30 import org.openecomp.sdnc.rm.data.AllocationItem;
31 import org.openecomp.sdnc.rm.data.Resource;
32 import org.openecomp.sdnc.util.vrf.VpnParam;
33 import org.openecomp.sdnc.util.vrf.VrfUtil;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class HubWithRgCheck implements EquipmentCheck {
39 private static final Logger log = LoggerFactory.getLogger(HubWithRgCheck.class);
41 private ResourceManager resourceManager;
44 public boolean checkEquipment(
45 String endPointPosition,
46 ServiceData serviceData,
47 EquipmentData equipData,
48 Map<String, Object> equipmentConstraints) {
49 String vrfName = (String) serviceData.data.get("vrf-name");
53 // Check if this is HUB. If not, this check is not applicable
54 VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName);
55 if (vpnp.siteType == null || !vpnp.siteType.equals("HUB"))
58 boolean rgPresent = vpnp.routeGroupName != null;
60 // First check if a new VRF would be required. If not, we are good
61 Resource r = resourceManager.getResource("VRF", equipData.equipmentId);
62 if (r != null && r.allocationItems != null) {
63 for (AllocationItem ai : r.allocationItems)
64 if (ai.resourceShareGroupList.contains(vrfName))
67 String resourceUnionId = serviceData.serviceInstanceId + '/' + serviceData.endPointPosition;
69 // Check if there is already another HUB VRF with RG presence that does not match the requested
70 for (AllocationItem ai : r.allocationItems) {
72 // Skip the allocation item for the current service instance, if there, in case it is a change order
73 if (ai.resourceUnionId.equals(resourceUnionId))
76 if (ai.resourceShareGroupList != null && ai.resourceShareGroupList.size() > 0) {
77 String vrfName2 = ai.resourceShareGroupList.iterator().next();
78 VpnParam vpnp2 = VrfUtil.parseVrfInstanceName(vrfName2);
80 if (vpnp2.siteType == null || !vpnp2.siteType.equals("HUB"))
83 boolean rgPresent2 = vpnp2.routeGroupName != null;
85 if (rgPresent && !rgPresent2) {
86 log.info("Skipping VPE " + equipData.equipmentId +
87 ": This request requires new HUB with RG VRF, " +
88 "but there is already another HUB VRF with no RG: " + vrfName2 + ".");
91 if (!rgPresent && rgPresent2) {
92 log.info("Skipping VPE " + equipData.equipmentId +
93 ": This request requires new HUB VRF with no RG, " +
94 "but there is already another HUB with RG VRF: " + vrfName2 + ".");
104 public void setResourceManager(ResourceManager resourceManager) {
105 this.resourceManager = resourceManager;