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