@Test public void postOperationsStatusCodes() throws IOException { controllerContext.setSchemas(schemaContextTestModule); mockInvokeRpc(cnSnDataOutput, true); String uri = "/operations/test-module:rpc-test"; assertEquals(200, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); mockInvokeRpc(null, true); assertEquals(204, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); mockInvokeRpc(null, false); assertEquals(500, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); List<RpcError> rpcErrors = new ArrayList<>(); rpcErrors.add( RpcResultBuilder.newError( ErrorType.RPC, "tag1", "message1", "applicationTag1", "info1", null)); rpcErrors.add( RpcResultBuilder.newWarning( ErrorType.PROTOCOL, "tag2", "message2", "applicationTag2", "info2", null)); mockInvokeRpc(null, false, rpcErrors); assertEquals(500, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); uri = "/operations/test-module:rpc-wrongtest"; assertEquals(400, post(uri, MediaType.APPLICATION_XML, xmlDataRpcInput)); }
/** * This method gets all necessary information for a system to construct a NSH header and * associated overlay packet to target the first service hop of a Rendered Service Path * * <p> * * @param input RPC input including a Rendered Service Path name * @return RPC output including a renderedServicePathFirstHop. */ @Override public Future<RpcResult<ReadRenderedServicePathFirstHopOutput>> readRenderedServicePathFirstHop( ReadRenderedServicePathFirstHopInput input) { RenderedServicePathFirstHop renderedServicePathFirstHop = null; RpcResultBuilder<ReadRenderedServicePathFirstHopOutput> rpcResultBuilder; renderedServicePathFirstHop = SfcProviderRenderedPathAPI.readRenderedServicePathFirstHop(input.getName()); ReadRenderedServicePathFirstHopOutput renderedServicePathFirstHopOutput = null; if (renderedServicePathFirstHop != null) { ReadRenderedServicePathFirstHopOutputBuilder renderedServicePathFirstHopOutputBuilder = new ReadRenderedServicePathFirstHopOutputBuilder(); renderedServicePathFirstHopOutputBuilder.setRenderedServicePathFirstHop( renderedServicePathFirstHop); renderedServicePathFirstHopOutput = renderedServicePathFirstHopOutputBuilder.build(); rpcResultBuilder = RpcResultBuilder.success(renderedServicePathFirstHopOutput); } else { String message = "Error Reading RSP First Hop from DataStore: " + input.getName(); rpcResultBuilder = RpcResultBuilder.<ReadRenderedServicePathFirstHopOutput>failed() .withError(ErrorType.APPLICATION, message); } return Futures.immediateFuture(rpcResultBuilder.build()); }
@Override public Future<RpcResult<DeleteRenderedPathOutput>> deleteRenderedPath( DeleteRenderedPathInput input) { boolean ret; RpcResultBuilder<DeleteRenderedPathOutput> rpcResultBuilder; // If a RSP is deleted we delete both SF and SFF operational states. SfcProviderServiceForwarderAPI.deletePathFromServiceForwarderStateExecutor(input.getName()); SfcProviderServiceFunctionAPI.deleteServicePathFromServiceFunctionStateExecutor( input.getName()); ret = SfcProviderRenderedPathAPI.deleteRenderedServicePathExecutor(input.getName()); DeleteRenderedPathOutputBuilder deleteRenderedPathOutputBuilder = new DeleteRenderedPathOutputBuilder(); deleteRenderedPathOutputBuilder.setResult(ret); if (ret) { rpcResultBuilder = RpcResultBuilder.success(deleteRenderedPathOutputBuilder.build()); } else { String message = "Error Deleting Rendered Service Path: " + input.getName(); rpcResultBuilder = RpcResultBuilder.<DeleteRenderedPathOutput>failed() .withError(ErrorType.APPLICATION, message); } return Futures.immediateFuture(rpcResultBuilder.build()); }
public OptimisticLockFailedException(final String message, final Throwable cause) { super( message, cause, RpcResultBuilder.newError( ErrorType.APPLICATION, "resource-denied", message, null, null, cause)); }
@Override public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics( GetFlowTablesStatisticsInput input) { GetFlowTablesStatisticsOutputBuilder builder = new GetFlowTablesStatisticsOutputBuilder(); TransactionId transId = new TransactionId(BigInteger.valueOf(TestUtils.getNewTransactionId())); builder.setTransactionId(transId); FlowTableStatisticsUpdateBuilder ftsBuilder = new FlowTableStatisticsUpdateBuilder(); FlowTableAndStatisticsMapBuilder ftasmBuilder = new FlowTableAndStatisticsMapBuilder(); List<FlowTableAndStatisticsMap> tableAndStatisticsMaps = new ArrayList<>(); ftasmBuilder.setKey(new FlowTableAndStatisticsMapKey(StatisticsManagerTest.getTableId())); ftasmBuilder.setActiveFlows(StatisticsManagerTest.COUNTER_32_TEST_VALUE); tableAndStatisticsMaps.add(ftasmBuilder.build()); ftsBuilder.setTransactionId(transId); ftsBuilder.setId(input.getNode().getValue().firstKeyOf(Node.class, NodeKey.class).getId()); ftsBuilder.setFlowTableAndStatisticsMap(tableAndStatisticsMaps); ftsBuilder.setMoreReplies(true); notifService.pushDelayedNotification(ftsBuilder.build(), 0); // 1st notification ftsBuilder.setMoreReplies(false); ftasmBuilder.setPacketsLookedUp(StatisticsManagerTest.COUNTER_64_TEST_VALUE); tableAndStatisticsMaps.clear(); tableAndStatisticsMaps.add(ftasmBuilder.build()); ftsBuilder.setFlowTableAndStatisticsMap(tableAndStatisticsMaps); notifService.pushDelayedNotification(ftsBuilder.build(), 0); // 2nd notification return Futures.immediateFuture(RpcResultBuilder.success(builder.build()).build()); }
private RpcResult<NetconfMessage> createErrorRpcResult( RpcError.ErrorType errorType, String message) { return RpcResultBuilder.<NetconfMessage>failed() .withError( errorType, NetconfDocumentedException.ErrorTag.operation_failed.getTagValue(), message) .build(); }
@Override public RpcResult<TransactionStatus> apply(final DOMRpcResult input) { if (isSuccess(input)) { return RpcResultBuilder.success(TransactionStatus.COMMITED).build(); } else { final RpcResultBuilder<TransactionStatus> failed = RpcResultBuilder.failed(); for (final RpcError rpcError : input.getErrors()) { failed.withError( rpcError.getErrorType(), rpcError.getTag(), rpcError.getMessage(), rpcError.getApplicationTag(), rpcError.getInfo(), rpcError.getCause()); } return failed.build(); } }
/** * This method reads all the necessary information for the first hop of a Rendered Service Path by * ServiceFunctionTypeIdentity list. * * <p> * * @param input RPC input including a ServiceFunctionTypeIdentity list * @return RPC output including a renderedServicePathFirstHop. */ @Override public Future<RpcResult<ReadRspFirstHopBySftListOutput>> readRspFirstHopBySftList( ReadRspFirstHopBySftListInput input) { RenderedServicePathFirstHop renderedServicePathFirstHop = null; renderedServicePathFirstHop = SfcProviderRenderedPathAPI.readRspFirstHopBySftList(input.getSfst(), input.getSftList()); ReadRspFirstHopBySftListOutput readRspFirstHopBySftListOutput = null; if (renderedServicePathFirstHop != null) { ReadRspFirstHopBySftListOutputBuilder readRspFirstHopBySftListOutputBuilder = new ReadRspFirstHopBySftListOutputBuilder(); readRspFirstHopBySftListOutputBuilder.setRenderedServicePathFirstHop( renderedServicePathFirstHop); readRspFirstHopBySftListOutput = readRspFirstHopBySftListOutputBuilder.build(); } RpcResultBuilder<ReadRspFirstHopBySftListOutput> rpcResultBuilder = RpcResultBuilder.success(readRspFirstHopBySftListOutput); return Futures.immediateFuture(rpcResultBuilder.build()); }
private static RpcError[] toRpcErrors(final List<RestconfError> from) { final RpcError[] to = new RpcError[from.size()]; int i = 0; for (final RestconfError e : from) { to[i++] = RpcResultBuilder.newError( toRpcErrorType(e.getErrorType()), e.getErrorTag().getTagValue(), e.getErrorMessage()); } return to; }
/** * Handling logger and result of callback - on success or on failure * * <ul> * <li>on success - set result to the factory * <li>on failure - throw exception * </ul> * * @param t - exception - if callback is onFailure * @param txType - type of operation (READ, POST, PUT, DELETE) * @param result - result of future - if callback is on Success * @param dataFactory - setter for result - in callback is onSuccess */ protected static <T> void handlingLoggerAndValues( @Nullable final Throwable t, final String txType, final T result, final FutureDataFactory<T> dataFactory) { if (t != null) { dataFactory.setFailureStatus(); LOG.warn("Transaction({}) FAILED!", txType, t); if (t instanceof DOMRpcException) { final List<RpcError> rpcErrorList = new ArrayList<>(); rpcErrorList.add( RpcResultBuilder.newError(RpcError.ErrorType.RPC, "operation-failed", t.getMessage())); dataFactory.setResult((T) new DefaultDOMRpcResult(rpcErrorList)); } else { throw new RestconfDocumentedException( " Transaction(" + txType + ") not committed correctly", t); } } else { LOG.trace("Transaction({}) SUCCESSFUL!", txType); dataFactory.setResult(result); } }
@Override public Future<RpcResult<NaiveTestOutput>> naiveTest(NaiveTestInput input) { NaiveTestOutput output = new NaiveTestOutputBuilder().setResult("Bingo").build(); return Futures.immediateFuture(RpcResultBuilder.success(output).build()); }
private void processMessage(final NetconfMessage message) { Request request = null; sessionLock.lock(); try { request = requests.peek(); if (request.future.isUncancellable()) { requests.poll(); } else { request = null; logger.warn("{}: Ignoring unsolicited message {}", id, msgToS(message)); } } finally { sessionLock.unlock(); } if (request != null) { logger.debug("{}: Message received {}", id, message); if (logger.isTraceEnabled()) { logger.trace( "{}: Matched request: {} to response: {}", id, msgToS(request.request), msgToS(message)); } try { NetconfMessageTransformUtil.checkValidReply(request.request, message); } catch (final NetconfDocumentedException e) { logger.warn( "{}: Invalid request-reply match, reply message contains different message-id, request: {}, response: {}", id, msgToS(request.request), msgToS(message), e); request.future.set( RpcResultBuilder.<NetconfMessage>failed() .withRpcError(NetconfMessageTransformUtil.toRpcError(e)) .build()); return; } try { NetconfMessageTransformUtil.checkSuccessReply(message); } catch (final NetconfDocumentedException e) { logger.warn( "{}: Error reply from remote device, request: {}, response: {}", id, msgToS(request.request), msgToS(message), e); request.future.set( RpcResultBuilder.<NetconfMessage>failed() .withRpcError(NetconfMessageTransformUtil.toRpcError(e)) .build()); return; } request.future.set(RpcResultBuilder.success(message).build()); } }
@Override public Future<RpcResult<CreateRenderedPathOutput>> createRenderedPath( CreateRenderedPathInput createRenderedPathInput) { ServiceFunctionPath createdServiceFunctionPath; RenderedServicePath renderedServicePath; RenderedServicePath revRenderedServicePath; CreateRenderedPathOutputBuilder createRenderedPathOutputBuilder = new CreateRenderedPathOutputBuilder(); RpcResult<CreateRenderedPathOutput> rpcResult; String retRspName = null; createdServiceFunctionPath = SfcProviderServicePathAPI.readServiceFunctionPathExecutor( createRenderedPathInput.getParentServiceFunctionPath()); if (createdServiceFunctionPath != null) { renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState( createdServiceFunctionPath, createRenderedPathInput); if (renderedServicePath != null) { retRspName = renderedServicePath.getName(); createRenderedPathOutputBuilder.setName(retRspName); rpcResult = RpcResultBuilder.success(createRenderedPathOutputBuilder.build()).build(); if ((createdServiceFunctionPath.getClassifier() != null) && SfcProviderServiceClassifierAPI.readServiceClassifierExecutor( createdServiceFunctionPath.getClassifier()) != null) { SfcProviderServiceClassifierAPI.addRenderedPathToServiceClassifierStateExecutor( createdServiceFunctionPath.getClassifier(), renderedServicePath.getName()); } else { LOG.warn("Classifier not provided or does not exist"); } if ((createdServiceFunctionPath.isSymmetric() != null) && createdServiceFunctionPath.isSymmetric()) { revRenderedServicePath = SfcProviderRenderedPathAPI.createSymmetricRenderedServicePathAndState( renderedServicePath); if (revRenderedServicePath == null) { LOG.error("Failed to create symmetric service path: {}"); } else if ((createdServiceFunctionPath.getSymmetricClassifier() != null) && SfcProviderServiceClassifierAPI.readServiceClassifierExecutor( createdServiceFunctionPath.getSymmetricClassifier()) != null) { SfcProviderServiceClassifierAPI.addRenderedPathToServiceClassifierStateExecutor( createdServiceFunctionPath.getSymmetricClassifier(), revRenderedServicePath.getName()); } else { LOG.warn("Symmetric Classifier not provided or does not exist"); } } } else { rpcResult = RpcResultBuilder.<CreateRenderedPathOutput>failed() .withError(ErrorType.APPLICATION, "Failed to create RSP") .build(); } } else { rpcResult = RpcResultBuilder.<CreateRenderedPathOutput>failed() .withError(ErrorType.APPLICATION, "Service Function Path does not exist") .build(); } return Futures.immediateFuture(rpcResult); }