MRI version bumpup for Aluminium
[netvirt.git] / aclservice / impl / src / main / java / org / opendaylight / netvirt / aclservice / recovery / AclInterfaceRecoveryHandler.java
1 /*
2  * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.aclservice.recovery;
9
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;
23
24 @Singleton
25 public class AclInterfaceRecoveryHandler implements ServiceRecoveryInterface {
26
27     private static final Logger LOG = LoggerFactory.getLogger(AclInterfaceRecoveryHandler.class);
28
29     private final DataBroker dataBroker;
30     private final AclInterfaceListener aclInterfaceListener;
31
32     @Inject
33     public AclInterfaceRecoveryHandler(ServiceRecoveryRegistry serviceRecoveryRegistry, DataBroker dataBroker,
34             AclInterfaceListener aclInterfaceListener) {
35         serviceRecoveryRegistry.registerServiceRecoveryRegistry(buildServiceRegistryKey(), this);
36         this.dataBroker = dataBroker;
37         this.aclInterfaceListener = aclInterfaceListener;
38     }
39
40     @Override
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);
48         } else {
49             LOG.warn("{} is not valid ACL interface", entityId);
50         }
51     }
52
53     private String buildServiceRegistryKey() {
54         return NetvirtAclInterface.class.toString();
55     }
56 }