2 * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.aclservice.recovery;
10 import com.google.common.base.Optional;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.List;
16 import javax.inject.Inject;
17 import javax.inject.Singleton;
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.genius.srm.ServiceRecoveryInterface;
21 import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
22 import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
23 import org.opendaylight.netvirt.aclservice.listeners.AclInterfaceListener;
24 import org.opendaylight.netvirt.aclservice.utils.AclDataUtil;
25 import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.types.rev170711.NetvirtAclInstance;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAclBuilder;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
38 public class AclInstanceRecoveryHandler implements ServiceRecoveryInterface {
40 private static final Logger LOG = LoggerFactory.getLogger(AclInstanceRecoveryHandler.class);
41 private final DataBroker dataBroker;
42 private final AclDataUtil aclDataUtil;
43 private final AclInterfaceListener aclInterfaceListener;
46 public AclInstanceRecoveryHandler(ServiceRecoveryRegistry serviceRecoveryRegistry, DataBroker dataBroker,
47 AclDataUtil aclDataUtil, AclInterfaceListener aclInterfaceListener) {
48 this.dataBroker = dataBroker;
49 this.aclDataUtil = aclDataUtil;
50 this.aclInterfaceListener = aclInterfaceListener;
51 serviceRecoveryRegistry.registerServiceRecoveryRegistry(buildServiceRegistryKey(), this);
55 public void recoverService(String entityId) {
56 LOG.info("Recover ACL instance {}", entityId);
57 Uuid aclId = new Uuid(entityId);
58 Collection<AclInterface> aclInterfaces = aclDataUtil.getInterfaceList(aclId);
59 for (AclInterface aclInterface : aclInterfaces) {
60 String aclInterfaceId = aclInterface.getInterfaceId();
61 Optional<Interface> interfaceOptional = AclServiceUtils.getInterface(dataBroker,
63 if (interfaceOptional.isPresent()) {
64 Interface interfaceBefore = interfaceOptional.get();
65 LOG.debug("Starting Recovery of acl Instance {} for interface {}", entityId, interfaceBefore.getName());
66 InterfaceAcl interfaceAclBefore = interfaceBefore.augmentation(InterfaceAcl.class);
67 List<Uuid> sgList = new ArrayList<>(interfaceAclBefore.getSecurityGroups());
69 InterfaceAcl interfaceAclAfter = new InterfaceAclBuilder(interfaceAclBefore).setSecurityGroups(sgList)
71 Interface interfaceAfter = new InterfaceBuilder(interfaceBefore)
72 .addAugmentation(InterfaceAcl.class,interfaceAclAfter).build();
73 aclInterfaceListener.update(null, interfaceBefore, interfaceAfter);
74 aclInterfaceListener.update(null, interfaceAfter, interfaceBefore);
76 LOG.error("Interfaces not present for aclInterface {} ", aclInterfaceId);
81 private String buildServiceRegistryKey() {
82 return NetvirtAclInstance.class.toString();