/** * @param e connection exception * @param <T> rpc result return type * @return error wrapped inside {@link RpcResult} which is wrapped inside future */ public static <T> SettableFuture<RpcResult<T>> getRpcErrorFuture(ConnectionException e) { List<RpcError> rpcErrorList = wrapConnectionErrorIntoRpcErrors(e); SettableFuture<RpcResult<T>> futureWithError = SettableFuture.create(); futureWithError.set(RpcResultBuilder.<T>failed().withRpcErrors(rpcErrorList).build()); return futureWithError; }
@Override public void onFailure(final Throwable ex) { LOG.info("Failed to commit Rule", ex); futureResult.set(RpcResultBuilder.<UpdateAlertFieldContentRuleOutput> failed() .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build()); } });
@Override public void onFailure(final Throwable ex) { LOG.debug("Failed to commit Rule", ex); futureResult.set(RpcResultBuilder.<PauseStreamOutput> failed() .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build()); } });
@Override public void onFailure(final Throwable ex) { LOG.debug("Failed to commit stream Rule", ex); futureResult.set(RpcResultBuilder.<SetRuleOutput> failed() .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build()); } });
@Override public void onFailure(final Throwable ex) { LOG.info("Failed to commit Rule", ex); futureResult.set(RpcResultBuilder.<UpdateAlertMessageCountRuleOutput> failed() .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build()); } });
@Override public void onFailure(final Throwable ex) { LOG.debug("Failed to commit Rule", ex); futureResult.set(RpcResultBuilder.<DeleteStreamOutput> failed() .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build()); } });
@Override public void onFailure(final Throwable ex) { LOG.debug("Failed to commit Rule", ex); futureResult.set(RpcResultBuilder.<UpdateStreamOutput> failed() .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build()); } });
@Override public void onFailure(final Throwable ex) { LOG.debug("Failed to commit Rule", ex); futureResult.set(RpcResultBuilder.<ResumeStreamOutput> failed() .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build()); } });
@Override public void onFailure(final Throwable ex) { LOG.info("Failed to commit Rule", ex); futureResult.set(RpcResultBuilder.<DeleteAlertMessageCountRuleOutput> failed() .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build()); } });
@Override public void onFailure(final Throwable ex) { LOG.info("Failed to commit Rule", ex); futureResult.set(RpcResultBuilder.<DeleteAlertFieldContentRuleOutput> failed() .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build()); } });
@Override public void onFailure(final Throwable ex) { LOG.info("Failed to commit Rule", ex); futureResult.set(RpcResultBuilder.<UpdateAlertFieldValueRuleOutput> failed() .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build()); } });
@Override public void onFailure(final Throwable ex) { LOG.info("Failed to commit Rule", ex); futureResult.set(RpcResultBuilder.<DeleteAlertFieldValueRuleOutput> failed() .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build()); } });
/** * DOMRpcResult does not have a notion of success, hence we have to reverse-engineer it by looking at reported * errors and checking whether they are just warnings. */ static <T> RpcResult<T> rpcResultFromDOM(final Collection<? extends RpcError> errors, final @Nullable T result) { return RpcResultBuilder.<T>status(errors.stream().noneMatch(err -> err.getSeverity() == ErrorSeverity.ERROR)) .withResult(result).withRpcErrors(errors).build(); } }
@Override public ListenableFuture<RpcResult<Void>> apply( List<RpcResult<Void>> results ) throws Exception { boolean atLeastOneSucceeded = false; Builder<RpcError> errorList = ImmutableList.builder(); for( RpcResult<Void> result: results ) { if( result.isSuccessful() ) { atLeastOneSucceeded = true; } if( result.getErrors() != null ) { errorList.addAll( result.getErrors() ); } } return Futures.immediateFuture( RpcResultBuilder.<Void> status( atLeastOneSucceeded ) .withRpcErrors( errorList.build() ).build() ); } } );
/** * Returns a builder from another RpcResult. * * @param other the other RpcResult. */ public static <T> RpcResultBuilder<T> from(final RpcResult<T> other) { return new RpcResultBuilder<>(other.isSuccessful(), other.getResult()) .withRpcErrors(other.getErrors()); }
/** * Returns a builder from another RpcResult. * * @param other the other RpcResult. */ public static <T> RpcResultBuilder<T> from(final RpcResult<T> other) { return new RpcResultBuilder<>(other.isSuccessful(), other.getResult()) .withRpcErrors(other.getErrors()); }
@Override public RpcResult<UpdateMeterOutput> apply(final RpcResult<Void> inputArg) { UpdateMeterOutputBuilder meterModOutput = new UpdateMeterOutputBuilder(); BigInteger bigIntXid = BigInteger.valueOf(input.getXid()); meterModOutput.setTransactionId(new TransactionId(bigIntXid)); UpdateMeterOutput result = meterModOutput.build(); RpcResult<UpdateMeterOutput> rpcResult = RpcResultBuilder .<UpdateMeterOutput>status(inputArg.isSuccessful()).withResult(result) .withRpcErrors(inputArg.getErrors()).build(); return rpcResult; } });
@Override public RpcResult<UpdateGroupOutput> apply(final RpcResult<Void> inputArg) { UpdateGroupOutputBuilder groupModOutput = new UpdateGroupOutputBuilder(); BigInteger bigIntXid = BigInteger.valueOf(input.getXid()); groupModOutput.setTransactionId(new TransactionId(bigIntXid)); UpdateGroupOutput result = groupModOutput.build(); RpcResult<UpdateGroupOutput> rpcResult = RpcResultBuilder .<UpdateGroupOutput>status(inputArg.isSuccessful()).withResult(result) .withRpcErrors(inputArg.getErrors()).build(); return rpcResult; } });
@Override public RpcResult<UpdatePortOutput> apply(final RpcResult<Void> inputArg) { UpdatePortOutputBuilder portModOutput = new UpdatePortOutputBuilder(); BigInteger bigIntXid = BigInteger.valueOf(input.getXid()); portModOutput.setTransactionId(new TransactionId(bigIntXid)); UpdatePortOutput result = portModOutput.build(); RpcResult<UpdatePortOutput> rpcResult = RpcResultBuilder .<UpdatePortOutput>status(inputArg.isSuccessful()).withResult(result) .withRpcErrors(inputArg.getErrors()).build(); return rpcResult; } });
@Override public RpcResult<UpdateFlowOutput> apply(final RpcResult<Void> inputArg) { UpdateFlowOutputBuilder flowModOutput = new UpdateFlowOutputBuilder(); BigInteger bigIntXid = BigInteger.valueOf(input.getXid()); flowModOutput.setTransactionId(new TransactionId(bigIntXid)); UpdateFlowOutput result = flowModOutput.build(); RpcResult<UpdateFlowOutput> rpcResult = RpcResultBuilder .<UpdateFlowOutput>status(inputArg.isSuccessful()) .withResult(result).withRpcErrors(inputArg.getErrors()) .build(); return rpcResult; } });