2 * Copyright © 2019 FRINX s.r.o. All rights reserved.
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
8 package org.opendaylight.netconf.client.mdsal;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.MoreExecutors;
14 import javax.inject.Singleton;
15 import org.opendaylight.mdsal.dom.api.DOMActionService;
16 import org.opendaylight.netconf.client.mdsal.api.ActionTransformer;
17 import org.opendaylight.netconf.client.mdsal.api.DeviceActionFactory;
18 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceCommunicator;
19 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices.Actions;
20 import org.osgi.service.component.annotations.Component;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Implementation of the factory for creation of {@link DOMActionService} instances that are provided by device.
26 * {@link DOMActionService} is implemented using {@link ActionTransformer} that builds NETCONF RPCs and
27 * transforms replied NETCONF message to action result, and using {@link RemoteDeviceCommunicator} that is responsible
28 * for sending of built RPCs to NETCONF client.
31 @Component(immediate = true, property = "type=default")
32 public class DeviceActionFactoryImpl implements DeviceActionFactory {
33 private static final Logger LOG = LoggerFactory.getLogger(DeviceActionFactoryImpl.class);
36 public Actions.Normalized createDeviceAction(final ActionTransformer messageTransformer,
37 final RemoteDeviceCommunicator listener) {
38 return (schemaPath, dataTreeIdentifier, input) -> {
39 requireNonNull(schemaPath);
40 requireNonNull(dataTreeIdentifier);
41 requireNonNull(input);
43 final var actionResultFuture = listener.sendRequest(
44 messageTransformer.toActionRequest(schemaPath, dataTreeIdentifier, input),
45 input.getIdentifier().getNodeType());
47 return Futures.transform(actionResultFuture, netconfMessageRpcResult -> {
48 if (netconfMessageRpcResult != null) {
49 return messageTransformer.toActionResult(schemaPath, netconfMessageRpcResult.getResult());
52 final String message = "Missing action result of action on schema path: " + schemaPath;
54 throw new IllegalStateException(message);
55 }, MoreExecutors.directExecutor());