Search in sources :

Example 1 with BindingNormalizedNodeSerializer

use of org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method testAddRemovePrefixShardReplica.

@Test
public void testAddRemovePrefixShardReplica() throws Exception {
    String name = "testAddPrefixShardReplica";
    String moduleShardsConfig = "module-shards-default.conf";
    final MemberNode member1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    final MemberNode replicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    final MemberNode replicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    member1.waitForMembersUp("member-2", "member-3");
    replicaNode2.kit().waitForMembersUp("member-1", "member-3");
    replicaNode3.kit().waitForMembersUp("member-1", "member-2");
    final ActorRef shardManager1 = member1.configDataStore().getActorContext().getShardManager();
    shardManager1.tell(new PrefixShardCreated(new PrefixShardConfiguration(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH), "prefix", Collections.singleton(MEMBER_1))), ActorRef.noSender());
    member1.kit().waitUntilLeader(member1.configDataStore().getActorContext(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
    final InstanceIdentifier<Cars> identifier = InstanceIdentifier.create(Cars.class);
    final BindingNormalizedNodeSerializer serializer = Mockito.mock(BindingNormalizedNodeSerializer.class);
    Mockito.doReturn(CarsModel.BASE_PATH).when(serializer).toYangInstanceIdentifier(identifier);
    addPrefixShardReplica(replicaNode2, identifier, serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-1");
    addPrefixShardReplica(replicaNode3, identifier, serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-1", "member-2");
    verifyRaftPeersPresent(member1.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-2", "member-3");
    removePrefixShardReplica(member1, identifier, "member-3", serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-2");
    verifyNoShardPresent(replicaNode3.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
    verifyRaftPeersPresent(replicaNode2.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-1");
    removePrefixShardReplica(member1, identifier, "member-2", serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
    verifyNoShardPresent(replicaNode2.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
}
Also used : Cars(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) ActorRef(akka.actor.ActorRef) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PrefixShardCreated(org.opendaylight.controller.cluster.sharding.messages.PrefixShardCreated) PrefixShardConfiguration(org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration) Test(org.junit.Test)

Example 2 with BindingNormalizedNodeSerializer

use of org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method testGetShardRole.

@Test
public void testGetShardRole() throws Exception {
    String name = "testGetShardRole";
    String moduleShardsConfig = "module-shards-default-member-1.conf";
    final MemberNode member1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    member1.kit().waitUntilLeader(member1.configDataStore().getActorContext(), "default");
    final RpcResult<GetShardRoleOutput> successResult = getShardRole(member1, Mockito.mock(BindingNormalizedNodeSerializer.class), "default");
    verifySuccessfulRpcResult(successResult);
    assertEquals("Leader", successResult.getResult().getRole());
    final RpcResult<GetShardRoleOutput> failedResult = getShardRole(member1, Mockito.mock(BindingNormalizedNodeSerializer.class), "cars");
    verifyFailedRpcResult(failedResult);
    final ActorRef shardManager1 = member1.configDataStore().getActorContext().getShardManager();
    shardManager1.tell(new PrefixShardCreated(new PrefixShardConfiguration(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH), "prefix", Collections.singleton(MEMBER_1))), ActorRef.noSender());
    member1.kit().waitUntilLeader(member1.configDataStore().getActorContext(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
    final InstanceIdentifier<Cars> identifier = InstanceIdentifier.create(Cars.class);
    final BindingNormalizedNodeSerializer serializer = Mockito.mock(BindingNormalizedNodeSerializer.class);
    Mockito.doReturn(CarsModel.BASE_PATH).when(serializer).toYangInstanceIdentifier(identifier);
    final RpcResult<GetPrefixShardRoleOutput> prefixSuccessResult = getPrefixShardRole(member1, identifier, serializer);
    verifySuccessfulRpcResult(prefixSuccessResult);
    assertEquals("Leader", prefixSuccessResult.getResult().getRole());
    final InstanceIdentifier<People> peopleId = InstanceIdentifier.create(People.class);
    Mockito.doReturn(PeopleModel.BASE_PATH).when(serializer).toYangInstanceIdentifier(peopleId);
    final RpcResult<GetPrefixShardRoleOutput> prefixFail = getPrefixShardRole(member1, peopleId, serializer);
    verifyFailedRpcResult(prefixFail);
}
Also used : Cars(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars) GetPrefixShardRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutput) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) ActorRef(akka.actor.ActorRef) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) People(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.People) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PrefixShardConfiguration(org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration) GetShardRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleOutput) PrefixShardCreated(org.opendaylight.controller.cluster.sharding.messages.PrefixShardCreated) Test(org.junit.Test)

Example 3 with BindingNormalizedNodeSerializer

use of org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer in project controller by opendaylight.

the class RpcServiceAdapter method transformFuture.

private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc, final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeSerializer codec) {
    return Futures.transform(domFuture, input -> {
        final NormalizedNode<?, ?> domData = input.getResult();
        final DataObject bindingResult;
        if (domData != null) {
            final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
            bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
        } else {
            bindingResult = null;
        }
        // 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.
        final Collection<RpcError> errors = input.getErrors();
        return RpcResult.class.cast(RpcResultBuilder.status(errors.stream().noneMatch(error -> error.getSeverity() == ErrorSeverity.ERROR)).withResult(bindingResult).withRpcErrors(errors).build());
    }, MoreExecutors.directExecutor());
}
Also used : DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) Proxy(java.lang.reflect.Proxy) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ErrorSeverity(org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) BindingReflections(org.opendaylight.yangtools.yang.binding.util.BindingReflections) RpcRoutingStrategy(org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy) RpcService(org.opendaylight.yangtools.yang.binding.RpcService) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Method(java.lang.reflect.Method) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) DOMRpcService(org.opendaylight.controller.md.sal.dom.api.DOMRpcService) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) QName(org.opendaylight.yangtools.yang.common.QName) Futures(com.google.common.util.concurrent.Futures) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) ImmutableNodes(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes) Entry(java.util.Map.Entry) Preconditions(com.google.common.base.Preconditions) InvocationHandler(java.lang.reflect.InvocationHandler) RpcError(org.opendaylight.yangtools.yang.common.RpcError) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 4 with BindingNormalizedNodeSerializer

use of org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer in project controller by opendaylight.

the class TracingBrokerTest method testPrintOpenTransactions.

@Test
// Finding resource leaks is the point of this test
@SuppressWarnings({ "resource", "unused" })
public void testPrintOpenTransactions() {
    DOMDataBroker domDataBroker = mock(DOMDataBroker.class, RETURNS_DEEP_STUBS);
    Config config = new ConfigBuilder().setTransactionDebugContextEnabled(true).build();
    BindingNormalizedNodeSerializer codec = mock(BindingNormalizedNodeSerializer.class);
    TracingBroker tracingBroker = new TracingBroker(domDataBroker, config, codec);
    DOMDataReadWriteTransaction tx = tracingBroker.newReadWriteTransaction();
    DOMTransactionChain txChain = tracingBroker.createTransactionChain(null);
    DOMDataReadWriteTransaction txFromChain = txChain.newReadWriteTransaction();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    boolean printReturnValue = tracingBroker.printOpenTransactions(ps);
    String output = new String(baos.toByteArray(), UTF_8);
    assertThat(printReturnValue).isTrue();
    // Assert expections about stack trace
    assertThat(output).contains("testPrintOpenTransactions(TracingBrokerTest.java");
    assertThat(output).doesNotContain(TracingBroker.class.getName());
    String previousLine = "";
    for (String line : output.split("\n")) {
        if (line.contains("(...")) {
            assertThat(previousLine.contains("(...)")).isFalse();
        }
        previousLine = line;
    }
// We don't do any verify/times on the mocks,
// because the main point of the test is just to verify that
// printOpenTransactions runs through without any exceptions
// (e.g. it used to have a ClassCastException).
}
Also used : PrintStream(java.io.PrintStream) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) Config(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsaltrace.rev160908.Config) ConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsaltrace.rev160908.ConfigBuilder) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TracingBroker(org.opendaylight.controller.md.sal.trace.dom.impl.TracingBroker) DOMTransactionChain(org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) Test(org.junit.Test)

Aggregations

BindingNormalizedNodeSerializer (org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer)4 Test (org.junit.Test)3 ActorRef (akka.actor.ActorRef)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 MemberNode (org.opendaylight.controller.cluster.datastore.MemberNode)2 PrefixShardConfiguration (org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration)2 PrefixShardCreated (org.opendaylight.controller.cluster.sharding.messages.PrefixShardCreated)2 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)2 Cars (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 Proxy (java.lang.reflect.Proxy)1