--- /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.genius.srm;
+
+public interface RecoverableListener {
+ /**
+ * register a recoverable listener.
+ */
+ void registerListener();
+
+ /**
+ * Deregister a recoverable listener.
+ */
+ void deregisterListener();
+}
\ No newline at end of file
--- /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.genius.srm;
+
+public interface ServiceRecoveryInterface {
+ /**
+ * Initiates recovery mechanism for a particular interface-manager entity.
+ *
+ * @param entityId
+ * The unique identifier for the service instance.
+ */
+ void recoverService(String entityId);
+}
\ No newline at end of file
--- /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.genius.srm;
+
+import java.util.List;
+
+public interface ServiceRecoveryRegistry {
+
+ void registerServiceRecoveryRegistry(String entityName,
+ ServiceRecoveryInterface serviceRecoveryHandler);
+
+ void addRecoverableListener(String serviceName, RecoverableListener recoverableListener);
+
+ void removeRecoverableListener(String serviceName, RecoverableListener recoverableListener);
+
+ List<RecoverableListener> getRecoverableListeners(String serviceName);
+}
\ No newline at end of file
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>org.ops4j.pax.cdi</groupId>
+ <artifactId>pax-cdi-api</artifactId>
+ <optional>true</optional>
+ </dependency>
</dependencies>
<build>
--- /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.genius.srm.impl;
+
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.genius.datastoreutils.listeners.AbstractClusteredSyncDataTreeChangeListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.ServiceOps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.Services;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.Operations;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Singleton
+public class ServiceRecoveryListener extends AbstractClusteredSyncDataTreeChangeListener<Operations> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ServiceRecoveryListener.class);
+
+ private final ServiceRecoveryManager serviceRecoveryManager;
+
+ @Inject
+ public ServiceRecoveryListener(DataBroker dataBroker, ServiceRecoveryManager serviceRecoveryManager) {
+ super(dataBroker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ServiceOps.class)
+ .child(Services.class).child(Operations.class));
+ this.serviceRecoveryManager = serviceRecoveryManager;
+ }
+
+ @Override
+ public void add(@Nonnull Operations operations) {
+ LOG.info("Service Recovery operation triggered for service: {}", operations);
+ serviceRecoveryManager.recoverService(operations.getEntityType(), operations.getEntityName(),
+ operations.getEntityId());
+ }
+
+ @Override
+ public void remove(@Nonnull Operations removedDataObject) {
+
+ }
+
+ @Override
+ public void update(@Nonnull Operations originalDataObject, @Nonnull Operations updatedDataObject) {
+ add(updatedDataObject);
+ }
+}
--- /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.genius.srm.impl;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.types.rev170711.EntityNameBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.types.rev170711.EntityTypeBase;
+
+@Singleton
+public final class ServiceRecoveryManager {
+
+ private final ServiceRecoveryRegistryImpl serviceRecoveryRegistry;
+
+ @Inject
+ public ServiceRecoveryManager(ServiceRecoveryRegistryImpl serviceRecoveryRegistry) {
+ this.serviceRecoveryRegistry = serviceRecoveryRegistry;
+ }
+
+ private String getServiceRegistryKey(Class<? extends EntityNameBase> entityName) {
+ return entityName.toString();
+ }
+
+ /**
+ * Initiates recovery mechanism for a particular interface-manager entity.
+ * This method tries to check whether there is a registered handler for the incoming
+ * service recovery request within interface-manager and redirects the call
+ * to the respective handler if found.
+ * @param entityType
+ * The type of service recovery. eg :SERVICE or INSTANCE.
+ * @param entityName
+ * The type entity for which recovery has to be started. eg : INTERFACE or DPN.
+ * @param entityId
+ * The unique id to represent the entity to be recovered
+ */
+ public void recoverService(Class<? extends EntityTypeBase> entityType,
+ Class<? extends EntityNameBase> entityName, String entityId) {
+ String serviceRegistryKey = getServiceRegistryKey(entityName);
+ serviceRecoveryRegistry.getRegisteredServiceRecoveryHandler(serviceRegistryKey).recoverService(entityId);
+ }
+}
--- /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.genius.srm.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.inject.Singleton;
+
+import org.opendaylight.genius.srm.RecoverableListener;
+import org.opendaylight.genius.srm.ServiceRecoveryInterface;
+import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
+import org.ops4j.pax.cdi.api.OsgiServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Singleton
+@OsgiServiceProvider(classes = ServiceRecoveryRegistry.class)
+public class ServiceRecoveryRegistryImpl implements ServiceRecoveryRegistry {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ServiceRecoveryRegistryImpl.class);
+
+ private final Map<String, ServiceRecoveryInterface> serviceRecoveryRegistry = new ConcurrentHashMap<>();
+
+ private final Map<String, List<RecoverableListener>> recoverableListenersMap =
+ new ConcurrentHashMap<String, List<RecoverableListener>>();
+
+ @Override
+ public void registerServiceRecoveryRegistry(String entityName,
+ ServiceRecoveryInterface serviceRecoveryHandler) {
+ serviceRecoveryRegistry.put(entityName, serviceRecoveryHandler);
+ LOG.trace("Registered service recovery handler for {}", entityName);
+ }
+
+ @Override
+ public synchronized void addRecoverableListener(String serviceName, final RecoverableListener recoverableListener) {
+ List<RecoverableListener> recoverableListeners = recoverableListenersMap.get(serviceName);
+ if (recoverableListeners == null) {
+ recoverableListeners = Collections.synchronizedList(new ArrayList<>());
+ recoverableListenersMap.put(serviceName, recoverableListeners);
+ }
+
+ recoverableListeners.add(recoverableListener);
+ }
+
+ @Override
+ public void removeRecoverableListener(String serviceName, final RecoverableListener recoverableListener) {
+ if (recoverableListenersMap.get(serviceName) != null) {
+ recoverableListenersMap.get(serviceName).remove(recoverableListener);
+ }
+ }
+
+ @Override
+ public List<RecoverableListener> getRecoverableListeners(String serviceName) {
+ return recoverableListenersMap.get(serviceName);
+ }
+
+ ServiceRecoveryInterface getRegisteredServiceRecoveryHandler(String entityName) {
+ return serviceRecoveryRegistry.get(entityName);
+ }
+}
\ No newline at end of file
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.genius.srm;
+package org.opendaylight.genius.srm.impl;
import com.google.common.util.concurrent.Futures;
import java.util.concurrent.Future;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.genius.srm;
+package org.opendaylight.genius.srm.impl;
import com.google.common.collect.ImmutableMap;
import java.util.concurrent.ExecutionException;