Add Action(Provider)Adapters 10/74610/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 28 Jul 2018 11:13:52 +0000 (13:13 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Jul 2018 08:44:22 +0000 (10:44 +0200)
This adds adapters based on MD-SAL to sal-binding-broker, allowing
actions to be invoked.

Change-Id: I7efa0ef81c239d12e7d61097daa6a36391e7b89b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMAdapterLoader.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ControllerActionProviderServiceAdapter.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ControllerActionServiceAdapter.java [new file with mode: 0644]

index 531f84a..5f2b6fd 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.controller.md.sal.binding.impl;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import java.util.Map;
+import org.opendaylight.controller.md.sal.binding.api.ActionProviderService;
+import org.opendaylight.controller.md.sal.binding.api.ActionService;
 import org.opendaylight.controller.md.sal.binding.api.BindingService;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
@@ -21,12 +23,14 @@ import org.opendaylight.controller.md.sal.dom.api.DOMService;
 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
 
 public abstract class BindingDOMAdapterLoader extends AdapterLoader<BindingService, DOMService> {
-    private static final Map<Class<?>,BindingDOMAdapterBuilder.Factory<?>> FACTORIES =
-        ImmutableMap.<Class<?>,BindingDOMAdapterBuilder.Factory<?>>builder()
-            .put(NotificationService.class,BindingDOMNotificationServiceAdapter.BUILDER_FACTORY)
-            .put(NotificationPublishService.class,BindingDOMNotificationPublishServiceAdapter.BUILDER_FACTORY)
-            .put(DataBroker.class,BindingDOMDataBrokerAdapter.BUILDER_FACTORY)
-            .put(RpcConsumerRegistry.class,BindingDOMRpcServiceAdapter.BUILDER_FACTORY)
+    private static final Map<Class<?>, BindingDOMAdapterBuilder.Factory<?>> FACTORIES =
+        ImmutableMap.<Class<?>, BindingDOMAdapterBuilder.Factory<?>>builder()
+            .put(NotificationService.class, BindingDOMNotificationServiceAdapter.BUILDER_FACTORY)
+            .put(NotificationPublishService.class, BindingDOMNotificationPublishServiceAdapter.BUILDER_FACTORY)
+            .put(DataBroker.class, BindingDOMDataBrokerAdapter.BUILDER_FACTORY)
+            .put(RpcConsumerRegistry.class, BindingDOMRpcServiceAdapter.BUILDER_FACTORY)
+            .put(ActionProviderService.class, ControllerActionProviderServiceAdapter.BUILDER_FACTORY)
+            .put(ActionService.class,  ControllerActionServiceAdapter.BUILDER_FACTORY)
             .build();
 
     private final BindingToNormalizedNodeCodec codec;
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ControllerActionProviderServiceAdapter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ControllerActionProviderServiceAdapter.java
new file mode 100644 (file)
index 0000000..ededf4e
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.controller.md.sal.binding.impl;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.controller.md.sal.binding.api.ActionProviderService;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMAdapterBuilder.Factory;
+import org.opendaylight.controller.md.sal.dom.api.DOMActionProviderService;
+import org.opendaylight.controller.md.sal.dom.api.DOMService;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.binding.dom.adapter.ActionProviderServiceAdapter;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.yang.binding.Action;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+final class ControllerActionProviderServiceAdapter implements ActionProviderService {
+    private static final class Builder extends BindingDOMAdapterBuilder<ActionProviderService> {
+        @Override
+        public Set<? extends Class<? extends DOMService>> getRequiredDelegates() {
+            return ImmutableSet.of(DOMActionProviderService.class);
+        }
+
+        @Override
+        protected ActionProviderService createInstance(BindingToNormalizedNodeCodec codec,
+                ClassToInstanceMap<DOMService> delegates) {
+            final DOMActionProviderService domAction = delegates.getInstance(DOMActionProviderService.class);
+            return new ControllerActionProviderServiceAdapter(requireNonNull(codec), domAction);
+        }
+    }
+
+    static final Factory<ActionProviderService> BUILDER_FACTORY = Builder::new;
+
+    private final ActionProviderServiceAdapter delegate;
+
+    ControllerActionProviderServiceAdapter(BindingToNormalizedNodeCodec codec, DOMActionProviderService domService) {
+        this.delegate = ActionProviderServiceAdapter.create(codec, domService);
+    }
+
+    @Override
+    public <O extends @NonNull DataObject, P extends @NonNull InstanceIdentifier<O>, T extends @NonNull Action<P, ?, ?>,
+            S extends T> ObjectRegistration<S> registerImplementation(Class<T> actionInterface, S implementation,
+                    LogicalDatastoreType datastore, Set<DataTreeIdentifier<O>> validNodes) {
+        return delegate.registerImplementation(actionInterface, implementation, datastore, validNodes);
+    }
+}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ControllerActionServiceAdapter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ControllerActionServiceAdapter.java
new file mode 100644 (file)
index 0000000..f209b3a
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.controller.md.sal.binding.impl;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.controller.md.sal.binding.api.ActionService;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMAdapterBuilder.Factory;
+import org.opendaylight.controller.md.sal.dom.api.DOMActionService;
+import org.opendaylight.controller.md.sal.dom.api.DOMService;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.binding.dom.adapter.ActionServiceAdapter;
+import org.opendaylight.yangtools.yang.binding.Action;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+final class ControllerActionServiceAdapter implements ActionService {
+    private static final class Builder extends BindingDOMAdapterBuilder<ActionService> {
+        @Override
+        public Set<? extends Class<? extends DOMService>> getRequiredDelegates() {
+            return ImmutableSet.of(DOMActionService.class);
+        }
+
+        @Override
+        protected ActionService createInstance(final BindingToNormalizedNodeCodec codec,
+                final ClassToInstanceMap<DOMService> delegates) {
+            final DOMActionService domAction = delegates.getInstance(DOMActionService.class);
+            return new ControllerActionServiceAdapter(requireNonNull(codec), domAction);
+        }
+    }
+
+    static final Factory<ActionService> BUILDER_FACTORY = Builder::new;
+    private final ActionServiceAdapter delegate;
+
+    ControllerActionServiceAdapter(final BindingToNormalizedNodeCodec codec, final DOMActionService domService) {
+        this.delegate = ActionServiceAdapter.create(codec, domService);
+    }
+
+    @Override
+    public <O extends @NonNull DataObject, T extends @NonNull Action<?, ?, ?>> T getActionHandle(
+            final Class<T> actionInterface, final Set<DataTreeIdentifier<O>> validNodes) {
+        return delegate.getActionHandle(actionInterface, validNodes);
+    }
+}

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.