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.device.DeviceContext;
16 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
17 import org.opendaylight.openflowplugin.impl.util.ErrorUtil;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeter;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public final class UpdateMeterImpl extends AbstractMeterRpc<Meter, UpdateMeterOutput> implements UpdateMeter {
28 private static final Logger LOG = LoggerFactory.getLogger(UpdateMeterImpl.class);
30 public UpdateMeterImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
31 final ConvertorExecutor convertorExecutor) {
32 super(requestContextStack, deviceContext, convertorExecutor, UpdateMeterOutput.class);
36 public ListenableFuture<RpcResult<UpdateMeterOutput>> invoke(final UpdateMeterInput input) {
37 final var resultFuture = single.canUseSingleLayerSerialization()
38 ? single.handleServiceCall(input.getUpdatedMeter())
39 : multi.handleServiceCall(input.getUpdatedMeter());
41 Futures.addCallback(resultFuture, new FutureCallback<>() {
43 public void onSuccess(final RpcResult<UpdateMeterOutput> result) {
44 if (result.isSuccessful()) {
45 if (LOG.isDebugEnabled()) {
46 LOG.debug("Meter update with id={} finished without error",
47 input.getOriginalMeter().getMeterId());
50 LOG.warn("Meter update with id={} failed, errors={}", input.getOriginalMeter().getMeterId(),
51 ErrorUtil.errorsToString(result.getErrors()));
52 LOG.debug("Meter input={}", input.getUpdatedMeter());
57 public void onFailure(final Throwable throwable) {
58 LOG.warn("Service call for updating meter={} failed", input.getOriginalMeter().getMeterId(), throwable);
60 }, MoreExecutors.directExecutor());