<artifactId>idmanager-api</artifactId>
<version>${genius.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.genius</groupId>
+ <artifactId>srm-api</artifactId>
+ <version>${genius.version}</version>
+ </dependency>
<dependency>
<groupId>org.opendaylight.infrautils</groupId>
<artifactId>inject</artifactId>
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.genius.srm.RecoverableListener;
+import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
import org.opendaylight.netvirt.aclservice.api.AclInterfaceCache;
import org.opendaylight.netvirt.aclservice.api.AclServiceManager;
import org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action;
@Singleton
public class AclElanInterfaceListener extends AsyncDataTreeChangeListenerBase<ElanInterface, AclElanInterfaceListener>
- implements ClusteredDataTreeChangeListener<ElanInterface> {
+ implements ClusteredDataTreeChangeListener<ElanInterface>, RecoverableListener {
private static final Logger LOG = LoggerFactory.getLogger(AclElanInterfaceListener.class);
private final AclServiceManager aclServiceManager;
@Inject
public AclElanInterfaceListener(AclServiceManager aclServiceManager, AclClusterUtil aclClusterUtil,
- DataBroker dataBroker, AclInterfaceCache aclInterfaceCache) {
+ DataBroker dataBroker, AclInterfaceCache aclInterfaceCache,
+ ServiceRecoveryRegistry serviceRecoveryRegistry) {
super(ElanInterface.class, AclElanInterfaceListener.class);
this.aclServiceManager = aclServiceManager;
this.aclClusterUtil = aclClusterUtil;
this.dataBroker = dataBroker;
this.aclInterfaceCache = aclInterfaceCache;
+ serviceRecoveryRegistry.addRecoverableListener(AclServiceUtils.getRecoverServiceRegistryKey(), this);
}
@Override
@PostConstruct
public void init() {
LOG.info("{} start", getClass().getSimpleName());
+ registerListener();
+ }
+
+ @Override
+ public void registerListener() {
registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
}
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.genius.srm.RecoverableListener;
+import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
import org.opendaylight.netvirt.aclservice.api.AclInterfaceCache;
import org.opendaylight.netvirt.aclservice.api.AclServiceManager;
import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
@Singleton
public class AclEventListener extends AsyncDataTreeChangeListenerBase<Acl, AclEventListener> implements
- ClusteredDataTreeChangeListener<Acl> {
+ ClusteredDataTreeChangeListener<Acl>, RecoverableListener {
private static final Logger LOG = LoggerFactory.getLogger(AclEventListener.class);
@Inject
public AclEventListener(AclServiceManager aclServiceManager, AclClusterUtil aclClusterUtil, DataBroker dataBroker,
- AclDataUtil aclDataUtil, AclServiceUtils aclServicUtils, AclInterfaceCache aclInterfaceCache) {
+ AclDataUtil aclDataUtil, AclServiceUtils aclServicUtils, AclInterfaceCache aclInterfaceCache,
+ ServiceRecoveryRegistry serviceRecoveryRegistry) {
super(Acl.class, AclEventListener.class);
this.aclServiceManager = aclServiceManager;
this.aclClusterUtil = aclClusterUtil;
this.aclDataUtil = aclDataUtil;
this.aclServiceUtils = aclServicUtils;
this.aclInterfaceCache = aclInterfaceCache;
+ serviceRecoveryRegistry.addRecoverableListener(AclServiceUtils.getRecoverServiceRegistryKey(), this);
}
@Override
@PostConstruct
public void init() {
LOG.info("{} start", getClass().getSimpleName());
+ registerListener();
+ }
+
+ @Override
+ public void registerListener() {
registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
}
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.genius.srm.RecoverableListener;
+import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
import org.opendaylight.netvirt.aclservice.api.AclInterfaceCache;
import org.opendaylight.netvirt.aclservice.api.AclServiceManager;
import org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action;
@Singleton
public class AclInterfaceListener extends AsyncDataTreeChangeListenerBase<Interface, AclInterfaceListener>
- implements ClusteredDataTreeChangeListener<Interface> {
+ implements ClusteredDataTreeChangeListener<Interface>, RecoverableListener {
private static final Logger LOG = LoggerFactory.getLogger(AclInterfaceListener.class);
private final AclServiceManager aclServiceManager;
@Inject
public AclInterfaceListener(AclServiceManager aclServiceManager, AclClusterUtil aclClusterUtil,
DataBroker dataBroker, AclDataUtil aclDataUtil, AclInterfaceCache aclInterfaceCache,
- AclServiceUtils aclServicUtils) {
+ AclServiceUtils aclServicUtils, ServiceRecoveryRegistry serviceRecoveryRegistry) {
super(Interface.class, AclInterfaceListener.class);
this.aclServiceManager = aclServiceManager;
this.aclClusterUtil = aclClusterUtil;
this.aclDataUtil = aclDataUtil;
this.aclInterfaceCache = aclInterfaceCache;
this.aclServiceUtils = aclServicUtils;
+ serviceRecoveryRegistry.addRecoverableListener(AclServiceUtils.getRecoverServiceRegistryKey(), this);
}
@Override
@PostConstruct
public void init() {
LOG.info("{} start", getClass().getSimpleName());
+ registerListener();
+ }
+
+ @Override
+ public void registerListener() {
registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
}
}
@Override
- protected void remove(InstanceIdentifier<Interface> key, Interface port) {
+ public void remove(InstanceIdentifier<Interface> key, Interface port) {
LOG.trace("Received AclInterface remove event, port={}", port);
String interfaceId = port.getName();
AclInterface aclInterface = aclInterfaceCache.remove(interfaceId);
}
@Override
- protected void update(InstanceIdentifier<Interface> key, Interface portBefore, Interface portAfter) {
+ public void update(InstanceIdentifier<Interface> key, Interface portBefore, Interface portAfter) {
if (portBefore.getAugmentation(ParentRefs.class) == null
&& portAfter.getAugmentation(ParentRefs.class) != null) {
LOG.trace("Ignoring event for update in ParentRefs for {} ", portAfter.getName());
}
@Override
- protected void add(InstanceIdentifier<Interface> key, Interface port) {
+ public void add(InstanceIdentifier<Interface> key, Interface port) {
LOG.trace("Received AclInterface add event, port={}", port);
InterfaceAcl aclInPort = port.getAugmentation(InterfaceAcl.class);
if (aclInPort != null && aclInPort.isPortSecurityEnabled()) {
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
+import org.opendaylight.genius.srm.RecoverableListener;
+import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
import org.opendaylight.netvirt.aclservice.api.AclInterfaceCache;
import org.opendaylight.netvirt.aclservice.api.AclServiceManager;
import org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action;
@Singleton
public class AclInterfaceStateListener extends AsyncDataTreeChangeListenerBase<Interface,
- AclInterfaceStateListener> implements ClusteredDataTreeChangeListener<Interface> {
+ AclInterfaceStateListener> implements ClusteredDataTreeChangeListener<Interface>, RecoverableListener {
private static final Logger LOG = LoggerFactory.getLogger(AclInterfaceStateListener.class);
@Inject
public AclInterfaceStateListener(AclServiceManager aclServiceManger, AclClusterUtil aclClusterUtil,
DataBroker dataBroker, AclDataUtil aclDataUtil, IInterfaceManager interfaceManager,
- AclInterfaceCache aclInterfaceCache, AclServiceUtils aclServicUtils) {
+ AclInterfaceCache aclInterfaceCache, AclServiceUtils aclServicUtils,
+ ServiceRecoveryRegistry serviceRecoveryRegistry) {
super(Interface.class, AclInterfaceStateListener.class);
this.aclServiceManger = aclServiceManger;
this.aclClusterUtil = aclClusterUtil;
this.interfaceManager = interfaceManager;
this.aclInterfaceCache = aclInterfaceCache;
this.aclServiceUtils = aclServicUtils;
+ serviceRecoveryRegistry.addRecoverableListener(AclServiceUtils.getRecoverServiceRegistryKey(), this);
}
@Override
@PostConstruct
public void init() {
LOG.info("{} start", getClass().getSimpleName());
+ registerListener();
+ }
+
+ @Override
+ public void registerListener() {
registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
}
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
+import org.opendaylight.genius.srm.RecoverableListener;
+import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
import org.opendaylight.netvirt.aclservice.utils.AclConstants;
import org.opendaylight.netvirt.aclservice.utils.AclNodeDefaultFlowsTxBuilder;
* during when node is discovered.
*/
@Singleton
-public class AclNodeListener extends AsyncDataTreeChangeListenerBase<FlowCapableNode, AclNodeListener> {
+public class AclNodeListener extends AsyncDataTreeChangeListenerBase<FlowCapableNode, AclNodeListener>
+ implements RecoverableListener {
private static final Logger LOG = LoggerFactory.getLogger(AclNodeListener.class);
@Inject
public AclNodeListener(final IMdsalApiManager mdsalManager, DataBroker dataBroker, AclserviceConfig config,
- AclServiceUtils aclServiceUtils, JobCoordinator jobCoordinator) {
+ AclServiceUtils aclServiceUtils, JobCoordinator jobCoordinator,
+ ServiceRecoveryRegistry serviceRecoveryRegistry) {
super(FlowCapableNode.class, AclNodeListener.class);
this.mdsalManager = mdsalManager;
this.config = config;
this.aclServiceUtils = aclServiceUtils;
this.jobCoordinator = jobCoordinator;
+ serviceRecoveryRegistry.addRecoverableListener(AclServiceUtils.getRecoverServiceRegistryKey(), this);
}
@Override
if (config != null) {
this.securityGroupMode = config.getSecurityGroupMode();
}
+ registerListener();
+ LOG.info("AclserviceConfig: {}", this.config);
+ }
+
+ @Override
+ public void registerListener() {
this.aclServiceUtils.createRemoteAclIdPool();
registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
- LOG.info("AclserviceConfig: {}", this.config);
+ }
+
+ @Override
+ public void deregisterListener() {
+ super.deregisterListener();
+ this.aclServiceUtils.deleteRemoteAclIdPool();
}
@Override
--- /dev/null
+/*
+ * 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 com.google.common.base.Optional;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.genius.srm.ServiceRecoveryInterface;
+import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
+import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
+import org.opendaylight.netvirt.aclservice.listeners.AclInterfaceListener;
+import org.opendaylight.netvirt.aclservice.utils.AclDataUtil;
+import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.types.rev170711.NetvirtAclInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAclBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+
+@Singleton
+public class AclInstanceRecoveryHandler implements ServiceRecoveryInterface {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AclInstanceRecoveryHandler.class);
+ private final DataBroker dataBroker;
+ private final AclDataUtil aclDataUtil;
+ private final AclInterfaceListener aclInterfaceListener;
+
+ @Inject
+ public AclInstanceRecoveryHandler(ServiceRecoveryRegistry serviceRecoveryRegistry, DataBroker dataBroker,
+ AclDataUtil aclDataUtil, AclInterfaceListener aclInterfaceListener) {
+ this.dataBroker = dataBroker;
+ this.aclDataUtil = aclDataUtil;
+ this.aclInterfaceListener = aclInterfaceListener;
+ serviceRecoveryRegistry.registerServiceRecoveryRegistry(buildServiceRegistryKey(), this);
+ }
+
+ @Override
+ public void recoverService(String entityId) {
+ LOG.info("Recover ACL instance {}", entityId);
+ Uuid aclId = new Uuid(entityId);
+ Collection<AclInterface> aclInterfaces = aclDataUtil.getInterfaceList(aclId);
+ for (AclInterface aclInterface : aclInterfaces) {
+ String aclInterfaceId = aclInterface.getInterfaceId();
+ Optional<Interface> interfaceOptional = AclServiceUtils.getInterface(dataBroker,
+ aclInterfaceId);
+ if (interfaceOptional.isPresent()) {
+ Interface interfaceBefore = interfaceOptional.get();
+ LOG.debug("Starting Recovery of acl Instance {} for interface {}", entityId, interfaceBefore.getName());
+ InterfaceAcl interfaceAclBefore = interfaceBefore.getAugmentation(InterfaceAcl.class);
+ List<Uuid> sgList = new ArrayList<>(interfaceAclBefore.getSecurityGroups());
+ sgList.remove(aclId);
+ InterfaceAcl interfaceAclAfter = new InterfaceAclBuilder(interfaceAclBefore).setSecurityGroups(sgList)
+ .build();
+ Interface interfaceAfter = new InterfaceBuilder(interfaceBefore)
+ .addAugmentation(InterfaceAcl.class,interfaceAclAfter).build();
+ aclInterfaceListener.update(null, interfaceBefore, interfaceAfter);
+ aclInterfaceListener.update(null, interfaceAfter, interfaceBefore);
+ } else {
+ LOG.error("Interfaces not present for aclInterface {} ", aclInterfaceId);
+ }
+ }
+ }
+
+ private String buildServiceRegistryKey() {
+ return NetvirtAclInstance.class.toString();
+ }
+}
--- /dev/null
+/*
+ * 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 com.google.common.base.Optional;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.genius.srm.ServiceRecoveryInterface;
+import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
+import org.opendaylight.netvirt.aclservice.listeners.AclInterfaceListener;
+import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
+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.genius.srm.types.rev170711.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<Interface> interfaceOp = AclServiceUtils.getInterface(dataBroker, entityId);
+ if (interfaceOp.isPresent()) {
+ Interface aclInterface = interfaceOp.get();
+ InstanceIdentifier<Interface> interfaceIdentifier = AclServiceUtils.getInterfaceIdentifier(entityId);
+ aclInterfaceListener.remove(interfaceIdentifier, aclInterface);
+ aclInterfaceListener.add(interfaceIdentifier, aclInterface);
+ } else {
+ LOG.warn("{} is not valid ACL interface", entityId);
+ }
+ }
+
+ private String buildServiceRegistryKey() {
+ return NetvirtAclInterface.class.toString();
+ }
+}
--- /dev/null
+/*
+ * 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.Queue;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.opendaylight.genius.srm.RecoverableListener;
+import org.opendaylight.genius.srm.ServiceRecoveryInterface;
+import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
+import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Singleton
+public class AclServiceRecoveryHandler implements ServiceRecoveryInterface {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AclServiceRecoveryHandler.class);
+ private final ServiceRecoveryRegistry serviceRecoveryRegistry;
+
+ @Inject
+ public AclServiceRecoveryHandler(final ServiceRecoveryRegistry serviceRecoveryRegistry) {
+ LOG.info("Registering IFM service recovery handlers");
+ this.serviceRecoveryRegistry = serviceRecoveryRegistry;
+ serviceRecoveryRegistry.registerServiceRecoveryRegistry(AclServiceUtils.getRecoverServiceRegistryKey(), this);
+ }
+
+ private void deregisterListeners() {
+ Queue<RecoverableListener> recoverableListeners =
+ serviceRecoveryRegistry.getRecoverableListeners(AclServiceUtils.getRecoverServiceRegistryKey());
+ recoverableListeners.forEach((recoverableListener -> recoverableListener.deregisterListener()));
+ }
+
+ private void registerListeners() {
+ Queue<RecoverableListener> recoverableListeners =
+ serviceRecoveryRegistry.getRecoverableListeners(AclServiceUtils.getRecoverServiceRegistryKey());
+ recoverableListeners.forEach((recoverableListener -> recoverableListener.registerListener()));
+ }
+
+ @Override
+ public void recoverService(final String entityId) {
+ LOG.info("Recover IFM service by deregistering and registering all relevant listeners");
+ deregisterListeners();
+ registerListeners();
+ }
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServicesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServicesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.types.rev170711.NetvirtAcl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.config.rev160806.AclserviceConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.AclPortsLookup;
return filteredAAPs;
}
+ public static String getRecoverServiceRegistryKey() {
+ return NetvirtAcl.class.toString();
+ }
+
private static InetAddress getInetAddress(IpPrefixOrAddress ipPrefixOrAddress) {
InetAddress inetAddress = null;
String addr = null;
<service ref="aclInterfaceCacheImpl"
interface="org.opendaylight.netvirt.aclservice.api.AclInterfaceCache" />
+ <reference id="serviceRecoveryRegistry"
+ interface="org.opendaylight.genius.srm.ServiceRecoveryRegistry"/>
</blueprint>
import org.opendaylight.genius.datastoreutils.testutils.TestableJobCoordinatorEventsWaiter;
import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
import org.opendaylight.genius.mdsalutil.interfaces.testutils.TestIMdsalApiManager;
+import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
import org.opendaylight.netvirt.aclservice.AclInterfaceCacheImpl;
import org.opendaylight.netvirt.aclservice.api.AclInterfaceCache;
import org.opendaylight.netvirt.aclservice.stats.TestOdlDirectStatisticsService;
bind(JobCoordinatorEventsWaiter.class).to(TestableJobCoordinatorEventsWaiter.class);
bind(AclInterfaceCache.class).toInstance(new AclInterfaceCacheImpl());
+ bind(ServiceRecoveryRegistry.class).toInstance(mock(ServiceRecoveryRegistry.class));
}
private AclserviceConfig aclServiceConfig() {