Search in sources :

Example 71 with Result

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.Result in project openflowplugin by opendaylight.

the class ResponseExpectedRpcListenerTest method testDiscard.

/**
 * Test object creation.
 */
@Test
public void testDiscard() {
    RpcResponseKey key = new RpcResponseKey(12345L, BarrierOutput.class.getName());
    ResponseExpectedRpcListener<OfHeader> listener = new ResponseExpectedRpcListener<>("MESSAGE", "Failed to send message", responseCache, key);
    listener.discard();
    RpcError rpcError = AbstractRpcListener.buildRpcError("Failed to send message", "check switch connection", new TimeoutException("Request timed out"));
    SettableFuture<RpcResult<?>> result = SettableFuture.create();
    result.set(RpcResultBuilder.failed().withRpcError(rpcError).build());
    try {
        Assert.assertEquals("Wrong result", result.get().getErrors().iterator().next().getMessage(), listener.getResult().get().getErrors().iterator().next().getMessage());
        Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult());
        Assert.assertEquals("Wrong result", result.get().isSuccessful(), listener.getResult().get().isSuccessful());
    } catch (InterruptedException | ExecutionException e) {
        fail("Problem accessing result");
    }
}
Also used : OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ExecutionException(java.util.concurrent.ExecutionException) BarrierOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 72 with Result

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.Result in project openflowplugin by opendaylight.

the class SalFlatBatchServiceImpl method executeBatchPlan.

@VisibleForTesting
Future<RpcResult<ProcessFlatBatchOutput>> executeBatchPlan(final List<BatchStepJob> batchJobsChain) {
    BatchStepJob batchJob;
    final List<ListenableFuture<RpcResult<ProcessFlatBatchOutput>>> firedJobs = new ArrayList<>();
    ListenableFuture<RpcResult<ProcessFlatBatchOutput>> chainSummaryResult = FlatBatchUtil.createEmptyRpcBatchResultFuture(true);
    for (int i = 0; i < batchJobsChain.size(); i++) {
        batchJob = batchJobsChain.get(i);
        // wire actual job with chain
        firedJobs.add(Futures.transformAsync(chainSummaryResult, batchJob.getStepFunction(), MoreExecutors.directExecutor()));
        // if barrier after actual job is needed or it is the last job -> merge fired job results with chain result
        if ((batchJob.getPlanStep().isBarrierAfter()) || (i == batchJobsChain.size() - 1)) {
            firedJobs.add(0, chainSummaryResult);
            chainSummaryResult = FlatBatchUtil.mergeJobsResultsFutures(firedJobs);
            firedJobs.clear();
        }
    }
    return chainSummaryResult;
}
Also used : BatchStepJob(org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 73 with Result

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.Result in project openflowplugin by opendaylight.

the class SalFlatBatchServiceImpl method prepareBatchChain.

@VisibleForTesting
List<BatchStepJob> prepareBatchChain(final List<BatchPlanStep> batchPlan, final NodeRef node, final boolean exitOnFirstError) {
    // create batch API calls based on plan steps
    final List<BatchStepJob> chainJobs = new ArrayList<>();
    int stepOffset = 0;
    for (final BatchPlanStep planStep : batchPlan) {
        final int currentOffset = stepOffset;
        chainJobs.add(new BatchStepJob(planStep, chainInput -> {
            if (exitOnFirstError && !chainInput.isSuccessful()) {
                LOG.debug("error on flat batch chain occurred -> skipping step {}", planStep.getStepType());
                return FlatBatchUtil.createEmptyRpcBatchResultFuture(false);
            }
            LOG.trace("batch progressing on step type {}, previous steps result: {}", planStep.getStepType(), chainInput.isSuccessful());
            return getChainOutput(node, planStep, currentOffset);
        }));
        stepOffset += planStep.getTaskBag().size();
    }
    return chainJobs;
}
Also used : BatchStepJob(org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput) ProcessFlatBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput) UpdateMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput) AddGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInput) LoggerFactory(org.slf4j.LoggerFactory) SalFlatBatchService(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.SalFlatBatchService) SalFlowsBatchService(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.SalFlowsBatchService) FlatBatchGroupAdapters(org.opendaylight.openflowplugin.impl.services.batch.FlatBatchGroupAdapters) AddMetersBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutput) ArrayList(java.util.ArrayList) RemoveGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchInput) FlatBatchUtil(org.opendaylight.openflowplugin.impl.util.FlatBatchUtil) RemoveGroupsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchOutput) Future(java.util.concurrent.Future) BatchStepJob(org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob) AddGroupsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchOutput) SalMetersBatchService(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.SalMetersBatchService) SalFlowService(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService) UpdateGroupsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput) UpdateMetersBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchOutput) AddFlowsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutput) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) RemoveFlowsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput) Logger(org.slf4j.Logger) UpdateFlowsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchOutput) AddMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput) RemoveFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInput) SalGroupsBatchService(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.SalGroupsBatchService) FlatBatchMeterAdapters(org.opendaylight.openflowplugin.impl.services.batch.FlatBatchMeterAdapters) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) BatchPlanStep(org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) PathUtil(org.opendaylight.openflowplugin.impl.util.PathUtil) UpdateFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInput) RemoveMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput) Preconditions(com.google.common.base.Preconditions) UpdateGroupsBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchOutput) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RemoveMetersBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchOutput) FlatBatchFlowAdapters(org.opendaylight.openflowplugin.impl.services.batch.FlatBatchFlowAdapters) ArrayList(java.util.ArrayList) BatchPlanStep(org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 74 with Result

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.Result in project openflowplugin by opendaylight.

the class DeviceFlowRegistryImpl method fillFromDatastore.

private CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> fillFromDatastore(final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<FlowCapableNode> path) {
    // Create new read-only transaction
    final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction();
    // Bail out early if transaction is null
    if (transaction == null) {
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read transaction is null"));
    }
    // Prepare read operation from datastore for path
    final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> future = transaction.read(logicalDatastoreType, path);
    // Bail out early if future is null
    if (future == null) {
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Future from read transaction is null"));
    }
    Futures.addCallback(future, new FutureCallback<Optional<FlowCapableNode>>() {

        @Override
        public void onSuccess(@Nonnull Optional<FlowCapableNode> result) {
            result.asSet().stream().filter(Objects::nonNull).filter(flowCapableNode -> Objects.nonNull(flowCapableNode.getTable())).flatMap(flowCapableNode -> flowCapableNode.getTable().stream()).filter(Objects::nonNull).filter(table -> Objects.nonNull(table.getFlow())).flatMap(table -> table.getFlow().stream()).filter(Objects::nonNull).filter(flow -> Objects.nonNull(flow.getId())).forEach(flowConsumer);
            // After we are done with reading from datastore, close the transaction
            transaction.close();
        }

        @Override
        public void onFailure(Throwable throwable) {
            // Even when read operation failed, close the transaction
            transaction.close();
        }
    }, MoreExecutors.directExecutor());
    return future;
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Arrays(java.util.Arrays) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DeviceFlowRegistry(org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry) LoggerFactory(org.slf4j.LoggerFactory) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) ArrayList(java.util.ArrayList) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Optional(com.google.common.base.Optional) Map(java.util.Map) FlowDescriptor(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor) Nonnull(javax.annotation.Nonnull) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) BiMap(com.google.common.collect.BiMap) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) ThreadSafe(javax.annotation.concurrent.ThreadSafe) Maps(com.google.common.collect.Maps) FutureCallback(com.google.common.util.concurrent.FutureCallback) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Objects(java.util.Objects) Consumer(java.util.function.Consumer) GeneralAugMatchNodesNodeTableFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow) HashBiMap(com.google.common.collect.HashBiMap) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) Objects(java.util.Objects)

Example 75 with Result

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.Result in project openflowplugin by opendaylight.

the class FlatBatchFlowAdapters method convertBatchFlowResult.

/**
 * Convert batch result.
 * @param stepOffset offset of current batch plan step
 * @return converted {@link ProcessFlatBatchOutput} RPC result
 */
@VisibleForTesting
static <T extends BatchFlowOutputListGrouping> Function<RpcResult<T>, RpcResult<ProcessFlatBatchOutput>> convertBatchFlowResult(final int stepOffset) {
    return new Function<RpcResult<T>, RpcResult<ProcessFlatBatchOutput>>() {

        @Nullable
        @Override
        public RpcResult<ProcessFlatBatchOutput> apply(@Nonnull final RpcResult<T> input) {
            List<BatchFailure> batchFailures = wrapBatchFlowFailuresForFlat(input, stepOffset);
            ProcessFlatBatchOutputBuilder outputBuilder = new ProcessFlatBatchOutputBuilder().setBatchFailure(batchFailures);
            return RpcResultBuilder.<ProcessFlatBatchOutput>status(input.isSuccessful()).withRpcErrors(input.getErrors()).withResult(outputBuilder.build()).build();
        }
    };
}
Also used : Function(com.google.common.base.Function) BatchFailure(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailure) ProcessFlatBatchOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutputBuilder) Nonnull(javax.annotation.Nonnull) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ProcessFlatBatchOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Test (org.junit.Test)384 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)212 ArrayList (java.util.ArrayList)136 ExecutionException (java.util.concurrent.ExecutionException)134 ByteBuf (io.netty.buffer.ByteBuf)115 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)51 Collections (java.util.Collections)50 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)47 List (java.util.List)39 RouteAttributeContainer (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer)39 Statement (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement)39 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)33 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)31 BigInteger (java.math.BigInteger)28 AllocateIdInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput)28 AllocateIdInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder)28 AllocateIdOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput)27 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)26 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)25 IPV4UNICAST (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST)25