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.ra.rule.dao.VpeLockDao;
30 import org.openecomp.sdnc.rm.comp.ResourceManager;
31 import org.openecomp.sdnc.rm.data.AllocationItem;
32 import org.openecomp.sdnc.rm.data.Resource;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class VpeLockCheck implements EquipmentCheck {
38 private static final Logger log = LoggerFactory.getLogger(VpeLockCheck.class);
40 private VpeLockDao vpeLockDao;
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 String vpeName = (String) equipData.data.get("vpe-id");
54 String vpeLock = vpeLockDao.getVpeLock(vpeName);
58 if (vpeLock.equals("vpe-total-lock")) {
59 log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock + " on it.");
63 if (vpeLock.equals("vpe-vrf-lock") && requiresNewVrf(equipData.equipmentId, vrfName)) {
64 log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock +
65 " on it and it requires a new VRF for VPN: " + vrfName + ".");
69 if (vpeLock.equals("vpe-mvrf-lock") && requiresNewMVrf(equipData.equipmentId, vrfName)) {
70 log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock +
71 " on it and it requires a new multicast VRF for VPN: " + vrfName + ".");
78 boolean requiresNewVrf(String equipmentId, String vrfName) {
79 Resource r = resourceManager.getResource("VRF", equipmentId);
80 if (r == null || r.allocationItems == null)
83 for (AllocationItem ai : r.allocationItems) {
84 if (ai.resourceShareGroupList.contains(vrfName))
91 boolean requiresNewMVrf(String equipmentId, String vrfName) {
92 Resource r = resourceManager.getResource("MVRF", equipmentId);
93 if (r == null || r.allocationItems == null)
96 for (AllocationItem ai : r.allocationItems) {
97 if (ai.resourceShareGroupList.contains(vrfName))
104 public void setVpeLockDao(VpeLockDao vpeLockDao) {
105 this.vpeLockDao = vpeLockDao;
108 public void setResourceManager(ResourceManager resourceManager) {
109 this.resourceManager = resourceManager;