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 java.util.Optional;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import org.opendaylight.mdsal.binding.api.DataBroker;
14 import org.opendaylight.netvirt.aclservice.listeners.AclInterfaceListener;
15 import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
16 import org.opendaylight.serviceutils.srm.ServiceRecoveryInterface;
17 import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.NetvirtAclInterface;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 public class AclInterfaceRecoveryHandler implements ServiceRecoveryInterface {
27 private static final Logger LOG = LoggerFactory.getLogger(AclInterfaceRecoveryHandler.class);
29 private final DataBroker dataBroker;
30 private final AclInterfaceListener aclInterfaceListener;
33 public AclInterfaceRecoveryHandler(ServiceRecoveryRegistry serviceRecoveryRegistry, DataBroker dataBroker,
34 AclInterfaceListener aclInterfaceListener) {
35 serviceRecoveryRegistry.registerServiceRecoveryRegistry(buildServiceRegistryKey(), this);
36 this.dataBroker = dataBroker;
37 this.aclInterfaceListener = aclInterfaceListener;
41 public void recoverService(String entityId) {
42 LOG.info("Recover ACL interface {}", entityId);
43 Optional<Interface> interfaceOp = AclServiceUtils.getInterface(dataBroker, entityId);
44 if (interfaceOp.isPresent()) {
45 Interface aclInterface = interfaceOp.get();
46 InstanceIdentifier<Interface> interfaceIdentifier = AclServiceUtils.getInterfaceIdentifier(entityId);
47 aclInterfaceListener.add(interfaceIdentifier, aclInterface);
49 LOG.warn("{} is not valid ACL interface", entityId);
53 private String buildServiceRegistryKey() {
54 return NetvirtAclInterface.class.toString();