<commit_before>/*
 * Copyright (c) 2016 NEC Corporation. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

package org.opendaylight.vtn.manager.internal.util.flow;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.util.concurrent.FutureCallback;

import org.opendaylight.vtn.manager.VTNException;

import org.opendaylight.vtn.manager.internal.util.concurrent.AbstractVTNFuture;
import org.opendaylight.vtn.manager.internal.util.inventory.NodeRpcInvocation;
import org.opendaylight.vtn.manager.internal.util.inventory.NodeRpcWatcher;
import org.opendaylight.vtn.manager.internal.util.rpc.RpcUtils;

import org.opendaylight.yangtools.yang.common.RpcResult;

import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;

import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInputBuilder;

/**
 * {@code SendBarrierRpc} describes an invocation of send-barrier RPC provided
 * by the flow-capable-transaction service.
 */
public final class SendBarrierRpc
    extends NodeRpcInvocation<SendBarrierInput, Void>
    implements FutureCallback<RpcResult<Void>> {
    /**
     * Logger instance.
     */
    private static final Logger  LOG =
        LoggerFactory.getLogger(SendBarrierRpc.class);

    /**
     * Send a barrier request to the specified node.
     *
     * @param w     The node RPC watcher.
     * @param fcts  MD-SAL flow-capable-transaction service.
     * @param node  Reference to the target node.
     * @return  A {@link SendBarrierRpc} instance.
     */
    public static SendBarrierRpc create(
        NodeRpcWatcher w, FlowCapableTransactionService fcts, NodeRef node) {
        SendBarrierInput input = new SendBarrierInputBuilder().
            setNode(node).build();
        return new SendBarrierRpc(w, fcts, input);
    }

    /**
     * Issue a send-barrier RPC request.
     *
     * @param w     The node RPC watcher.
     * @param fcts  MD-SAL flow-capable-transaction service.
     * @param in    The RPC input.
     */
    public SendBarrierRpc(
        NodeRpcWatcher w, FlowCapableTransactionService fcts,
        SendBarrierInput in) {
        super(w, in, in.getNode(), fcts.sendBarrier(in), false);
    }

    // RpcRequest

    /**
     * Return the name of the RPC.
     *
     * @return  "send-barrier".
     */
    @Override
    public String getName() {
        return "send-barrier";
    }

    /**
     * Record a log message that indicates an failure of send-barrier RPC.
     *
     * @param msg    An error message.
     * @param cause  A throwable that indicates the cause of failure.
     */
    private void logError(String msg, Throwable cause) {
        // Don't record error log if the send-barrier RPC was canceled.
        if (isNodeRemoved() || isDisconnected()) {
            LOG.trace("send-barrier RPC has been canceled: node={}",
                      getNode());
        } else {
            LOG.error(msg + ": node=" + getNode(), cause);
        }
    }

    // FutureCallback

    /**
     * Invoked when a barrier request has been processed successfully.
     *
     * @param result  The result of the send-barrier RPC.
     */
    @Override
    public void onSuccess(RpcResult<Void> result) {
        complete();
        try {
            RpcUtils.checkResult(this, result, LOG);
            LOG.trace("send-barrier RPC has completed: node={}", getNode());
        } catch (VTNException e) {
            logError("send-barrier RPC has failed", e);
        }
    }

    /**
     * Invoked when a barrier request has failed.
     *
     * @param t  A throwable that indicates the cause of failure.
     */
    @Override
    public void onFailure(Throwable t) {
        complete();
        logError("send-barrier RPC has thrown an exception",
                 AbstractVTNFuture.getCause(t));
    }
}
<commit_msg>Bug 8184: Suppress unnecessary send-barrier RPC error logs.<commit_after>/*
 * Copyright (c) 2016, 2017 NEC Corporation. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

package org.opendaylight.vtn.manager.internal.util.flow;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.util.concurrent.FutureCallback;

import org.opendaylight.vtn.manager.VTNException;

import org.opendaylight.vtn.manager.internal.util.concurrent.AbstractVTNFuture;
import org.opendaylight.vtn.manager.internal.util.inventory.NodeRpcInvocation;
import org.opendaylight.vtn.manager.internal.util.inventory.NodeRpcWatcher;
import org.opendaylight.vtn.manager.internal.util.rpc.RpcUtils;

import org.opendaylight.yangtools.yang.common.RpcResult;

import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;

import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInputBuilder;

/**
 * {@code SendBarrierRpc} describes an invocation of send-barrier RPC provided
 * by the flow-capable-transaction service.
 */
public final class SendBarrierRpc
    extends NodeRpcInvocation<SendBarrierInput, Void>
    implements FutureCallback<RpcResult<Void>> {
    /**
     * Logger instance.
     */
    private static final Logger  LOG =
        LoggerFactory.getLogger(SendBarrierRpc.class);

    /**
     * Send a barrier request to the specified node.
     *
     * @param w     The node RPC watcher.
     * @param fcts  MD-SAL flow-capable-transaction service.
     * @param node  Reference to the target node.
     * @return  A {@link SendBarrierRpc} instance.
     */
    public static SendBarrierRpc create(
        NodeRpcWatcher w, FlowCapableTransactionService fcts, NodeRef node) {
        SendBarrierInput input = new SendBarrierInputBuilder().
            setNode(node).build();
        return new SendBarrierRpc(w, fcts, input);
    }

    /**
     * Issue a send-barrier RPC request.
     *
     * @param w     The node RPC watcher.
     * @param fcts  MD-SAL flow-capable-transaction service.
     * @param in    The RPC input.
     */
    public SendBarrierRpc(
        NodeRpcWatcher w, FlowCapableTransactionService fcts,
        SendBarrierInput in) {
        super(w, in, in.getNode(), fcts.sendBarrier(in), false);
    }

    // RpcRequest

    /**
     * Return the name of the RPC.
     *
     * @return  "send-barrier".
     */
    @Override
    public String getName() {
        return "send-barrier";
    }

    /**
     * Record a log message that indicates an failure of send-barrier RPC.
     *
     * @param msg    An error message.
     * @param cause  A throwable that indicates the cause of failure.
     */
    private void logError(String msg, Throwable cause) {
        // Don't record error log if the send-barrier RPC was canceled.
        if (!needErrorLog(cause) || isNodeRemoved() || isDisconnected()) {
            LOG.trace("send-barrier RPC has been canceled: node={}",
                      getNode());
        } else {
            LOG.error(msg + ": node=" + getNode(), cause);
        }
    }

    // FutureCallback

    /**
     * Invoked when a barrier request has been processed successfully.
     *
     * @param result  The result of the send-barrier RPC.
     */
    @Override
    public void onSuccess(RpcResult<Void> result) {
        complete();
        try {
            RpcUtils.checkResult(this, result, LOG);
            LOG.trace("send-barrier RPC has completed: node={}", getNode());
        } catch (VTNException e) {
            logError("send-barrier RPC has failed", e);
        }
    }

    /**
     * Invoked when a barrier request has failed.
     *
     * @param t  A throwable that indicates the cause of failure.
     */
    @Override
    public void onFailure(Throwable t) {
        complete();
        logError("send-barrier RPC has thrown an exception",
                 AbstractVTNFuture.getCause(t));
    }
}

{'fraction_non_alphanumeric': 0.10078868012062167, 'fraction_numerical': 0.009742519137091163, 'mean_word_length': 2.721622788088045, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5017781', 'n_tokens_mistral': 2709, 'n_tokens_neox': 2625, 'n_words': 655}