Decompose RPC implementation classes
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / sal / RemoveGroupImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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 com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import org.opendaylight.openflowplugin.api.openflow.FlowGroupStatus;
16 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
17 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
18 import org.opendaylight.openflowplugin.impl.util.ErrorUtil;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroup;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 public final class RemoveGroupImpl extends AbstractGroupRpc<RemoveGroupInput, RemoveGroupOutput>
28         implements RemoveGroup {
29     private static final Logger LOG = LoggerFactory.getLogger(RemoveGroupImpl.class);
30
31     public RemoveGroupImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
32             final ConvertorExecutor convertorExecutor) {
33         super(requestContextStack, deviceContext, convertorExecutor, RemoveGroupOutput.class);
34     }
35
36     @Override
37     public ListenableFuture<RpcResult<RemoveGroupOutput>> invoke(final RemoveGroupInput input) {
38         final var resultFuture = single.canUseSingleLayerSerialization() ? single.handleServiceCall(input)
39             : multi.handleServiceCall(input);
40
41         Futures.addCallback(resultFuture, new FutureCallback<>() {
42             @Override
43             public void onSuccess(final RpcResult<RemoveGroupOutput> result) {
44                 if (result.isSuccessful()) {
45                     if (LOG.isDebugEnabled()) {
46                         LOG.debug("Group remove with id={} finished without error", input.getGroupId().getValue());
47                         deviceContext.getDeviceGroupRegistry().appendHistoryGroup(input.getGroupId(),
48                             input.getGroupType(), FlowGroupStatus.REMOVED);
49                     }
50                 } else {
51                     LOG.warn("Group remove with id={} failed, errors={}", input.getGroupId().getValue(),
52                         ErrorUtil.errorsToString(result.getErrors()));
53                     LOG.debug("Group input={}", input);
54                 }
55             }
56
57             @Override
58             public void onFailure(final Throwable throwable) {
59                 LOG.warn("Service call for removing group={} failed", input.getGroupId().getValue(), throwable);
60             }
61         }, MoreExecutors.directExecutor());
62         return resultFuture;
63     }
64 }