Decompose RPC implementation classes
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / sal / ControlBundleImpl.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
3  * Copyright (c) 2024 PANTHEON.tech, s.r.o.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9 package org.opendaylight.openflowplugin.impl.services.sal;
10
11 import static java.util.Objects.requireNonNull;
12
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import com.google.common.util.concurrent.MoreExecutors;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenter;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterInputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundle;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundleInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundleOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlSalBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.bundle.control.sal.SalControlDataBuilder;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public final class ControlBundleImpl implements ControlBundle {
29     private static final Logger LOG = LoggerFactory.getLogger(ControlBundleImpl.class);
30
31     private final SendExperimenter sendExperimenter;
32
33     public ControlBundleImpl(final SendExperimenter sendExperimenter) {
34         this.sendExperimenter = requireNonNull(sendExperimenter);
35     }
36
37     @Override
38     public ListenableFuture<RpcResult<ControlBundleOutput>> invoke(final ControlBundleInput input) {
39         LOG.debug("Control message for device {} and bundle type {}", input.getNode(), input.getType());
40         return Futures.transform(sendExperimenter.invoke(new SendExperimenterInputBuilder()
41             .setNode(input.getNode())
42             .setExperimenterMessageOfChoice(new BundleControlSalBuilder()
43                 .setSalControlData(new SalControlDataBuilder(input).build())
44                 .build())
45             .build()), result ->
46                 result.isSuccessful() ? RpcResultBuilder.<ControlBundleOutput>success().build()
47                     : RpcResultBuilder.<ControlBundleOutput>failed().build(),
48             MoreExecutors.directExecutor());
49     }
50 }