/* * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.netvirt.aclservice.recovery; import java.util.Optional; import javax.inject.Inject; import javax.inject.Singleton; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.netvirt.aclservice.listeners.AclInterfaceListener; import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils; import org.opendaylight.serviceutils.srm.ServiceRecoveryInterface; import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.NetvirtAclInterface; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Singleton public class AclInterfaceRecoveryHandler implements ServiceRecoveryInterface { private static final Logger LOG = LoggerFactory.getLogger(AclInterfaceRecoveryHandler.class); private final DataBroker dataBroker; private final AclInterfaceListener aclInterfaceListener; @Inject public AclInterfaceRecoveryHandler(ServiceRecoveryRegistry serviceRecoveryRegistry, DataBroker dataBroker, AclInterfaceListener aclInterfaceListener) { serviceRecoveryRegistry.registerServiceRecoveryRegistry(buildServiceRegistryKey(), this); this.dataBroker = dataBroker; this.aclInterfaceListener = aclInterfaceListener; } @Override public void recoverService(String entityId) { LOG.info("Recover ACL interface {}", entityId); Optional interfaceOp = AclServiceUtils.getInterface(dataBroker, entityId); if (interfaceOp.isPresent()) { Interface aclInterface = interfaceOp.get(); InstanceIdentifier interfaceIdentifier = AclServiceUtils.getInterfaceIdentifier(entityId); aclInterfaceListener.add(interfaceIdentifier, aclInterface); } else { LOG.warn("{} is not valid ACL interface", entityId); } } private String buildServiceRegistryKey() { return NetvirtAclInterface.class.toString(); } }