2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3 * Copyright (c) 2024 PANTHEON.tech, s.r.o.
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
9 package org.opendaylight.openflowplugin.impl.services.sal;
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.UpdateGroup;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroup;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public final class UpdateGroupImpl extends AbstractGroupRpc<Group, UpdateGroupOutput> implements UpdateGroup {
30 private static final Logger LOG = LoggerFactory.getLogger(UpdateGroupImpl.class);
32 public UpdateGroupImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
33 final ConvertorExecutor convertorExecutor) {
34 super(requestContextStack, deviceContext, convertorExecutor, UpdateGroupOutput.class);
38 public ListenableFuture<RpcResult<UpdateGroupOutput>> invoke(final UpdateGroupInput input) {
39 final var resultFuture = single.canUseSingleLayerSerialization()
40 ? single.handleServiceCall(input.getUpdatedGroup())
41 : multi.handleServiceCall(input.getUpdatedGroup());
43 Futures.addCallback(resultFuture, new FutureCallback<>() {
45 public void onSuccess(final RpcResult<UpdateGroupOutput> result) {
46 if (result.isSuccessful()) {
47 UpdatedGroup updatedGroup = input.getUpdatedGroup();
48 deviceContext.getDeviceGroupRegistry().appendHistoryGroup(
49 updatedGroup.getGroupId(), updatedGroup.getGroupType(), FlowGroupStatus.MODIFIED);
50 if (LOG.isDebugEnabled()) {
51 LOG.debug("Group update with original id={} finished without error",
52 input.getOriginalGroup().getGroupId().getValue());
55 LOG.warn("Group update with original id={} failed, errors={}",
56 input.getOriginalGroup().getGroupId(), ErrorUtil.errorsToString(result.getErrors()));
57 LOG.debug("Group input={}", input.getUpdatedGroup());
62 public void onFailure(final Throwable throwable) {
63 LOG.warn("Service call for updating group={} failed", input.getOriginalGroup().getGroupId(), throwable);
65 }, MoreExecutors.directExecutor());