Search in sources :

Example 1 with Builder

use of org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder in project controller by opendaylight.

the class ShardManager method doCreatePrefixShard.

private void doCreatePrefixShard(final PrefixShardConfiguration config, final ShardIdentifier shardId, final String shardName) {
    configuration.addPrefixShardConfiguration(config);
    final Builder builder = newShardDatastoreContextBuilder(shardName);
    builder.logicalStoreType(config.getPrefix().getDatastoreType()).storeRoot(config.getPrefix().getRootIdentifier());
    DatastoreContext shardDatastoreContext = builder.build();
    final Map<String, String> peerAddresses = getPeerAddresses(shardName);
    final boolean isActiveMember = true;
    LOG.debug("{} doCreatePrefixShard: shardId: {}, memberNames: {}, peerAddresses: {}, isActiveMember: {}", persistenceId(), shardId, config.getShardMemberNames(), peerAddresses, isActiveMember);
    final ShardInformation info = new ShardInformation(shardName, shardId, peerAddresses, shardDatastoreContext, Shard.builder(), peerAddressResolver);
    info.setActiveMember(isActiveMember);
    localShards.put(info.getShardName(), info);
    if (schemaContext != null) {
        info.setSchemaContext(schemaContext);
        info.setActor(newShardActor(info));
    }
}
Also used : DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) Builder(org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder)

Example 2 with Builder

use of org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder in project controller by opendaylight.

the class DistributedDataStoreRemotingIntegrationTest method sendDatastoreContextUpdate.

private static void sendDatastoreContextUpdate(final AbstractDataStore dataStore, final Builder builder) {
    final Builder newBuilder = DatastoreContext.newBuilderFrom(builder.build());
    final DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class);
    final Answer<DatastoreContext> answer = invocation -> newBuilder.build();
    Mockito.doAnswer(answer).when(mockContextFactory).getBaseDatastoreContext();
    Mockito.doAnswer(answer).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString());
    dataStore.onDatastoreContextUpdated(mockContextFactory);
}
Also used : Arrays(java.util.Arrays) DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) ActorRef(akka.actor.ActorRef) Cluster(akka.cluster.Cluster) Optional(com.google.common.base.Optional) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BigInteger(java.math.BigInteger) ApplyJournalEntries(org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) RequestTimeoutException(org.opendaylight.controller.cluster.access.client.RequestTimeoutException) Matchers.any(org.mockito.Matchers.any) Builder(org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) Await(scala.concurrent.Await) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) TestModel(org.opendaylight.controller.md.cluster.datastore.model.TestModel) RunWith(org.junit.runner.RunWith) AddressFromURIString(akka.actor.AddressFromURIString) InMemorySnapshotStore(org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore) TimeoutNow(org.opendaylight.controller.cluster.raft.base.messages.TimeoutNow) Mockito.timeout(org.mockito.Mockito.timeout) Answer(org.mockito.stubbing.Answer) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) Before(org.junit.Before) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Parameter(org.junit.runners.Parameterized.Parameter) Assert.assertTrue(org.junit.Assert.assertTrue) Throwables(com.google.common.base.Throwables) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Assert.assertEquals(org.junit.Assert.assertEquals) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) CarsModel(org.opendaylight.controller.md.cluster.datastore.model.CarsModel) GetShardDataTree(org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) Patterns(akka.pattern.Patterns) Assert.fail(org.junit.Assert.fail) DOMStoreTransactionChain(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain) Parameterized(org.junit.runners.Parameterized) Address(akka.actor.Address) ClientBackedDataStore(org.opendaylight.controller.cluster.databroker.ClientBackedDataStore) ImmutableMap(com.google.common.collect.ImmutableMap) FiniteDuration(scala.concurrent.duration.FiniteDuration) Collection(java.util.Collection) PeopleModel(org.opendaylight.controller.md.cluster.datastore.model.PeopleModel) List(java.util.List) ImmutableNodes(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes) ActorSystem(akka.actor.ActorSystem) ConcurrentDOMDataBroker(org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) ReadyLocalTransaction(org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction) ForwardedReadyTransaction(org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TransactionChainListener(org.opendaylight.mdsal.common.api.TransactionChainListener) Stopwatch(com.google.common.base.Stopwatch) Supplier(com.google.common.base.Supplier) Parameters(org.junit.runners.Parameterized.Parameters) InMemoryJournal(org.opendaylight.controller.cluster.raft.utils.InMemoryJournal) CommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply) ActorSelection(akka.actor.ActorSelection) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) DataTreeConfiguration(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) Shutdown(org.opendaylight.controller.cluster.raft.client.messages.Shutdown) ConfigFactory(com.typesafe.config.ConfigFactory) Assume(org.junit.Assume) SchemaContextHelper(org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper) ImmutableContainerNodeBuilder(org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) LinkedList(java.util.LinkedList) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) Assert.assertNotNull(org.junit.Assert.assertNotNull) Future(scala.concurrent.Future) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) TestKit(akka.testkit.javadsl.TestKit) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) Mockito.verify(org.mockito.Mockito.verify) Futures(akka.dispatch.Futures) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) CollectionNodeBuilder(org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder) Collections(java.util.Collections) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ReadyTransactionReply(org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionReply) Builder(org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder) ImmutableContainerNodeBuilder(org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder) CollectionNodeBuilder(org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder)

Example 3 with Builder

use of org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder in project controller by opendaylight.

the class DatastoreContextIntrospector method update.

/**
 * Applies the given properties to the cached DatastoreContext and yields a new DatastoreContext
 * instance which can be obtained via {@link #getContext()}.
 *
 * @param properties the properties to apply
 * @return true if the cached DatastoreContext was updated, false otherwise.
 */
public synchronized boolean update(final Map<String, Object> properties) {
    currentProperties = null;
    if (properties == null || properties.isEmpty()) {
        return false;
    }
    LOG.debug("In update: properties: {}", properties);
    final ImmutableMap.Builder<String, Object> mapBuilder = ImmutableMap.<String, Object>builder();
    final Builder builder = DatastoreContext.newBuilderFrom(context);
    final String dataStoreTypePrefix = context.getDataStoreName() + '.';
    final List<String> keys = getSortedKeysByDatastoreType(properties.keySet(), dataStoreTypePrefix);
    boolean updated = false;
    for (String key : keys) {
        final Object value = properties.get(key);
        mapBuilder.put(key, value);
        // If the key is prefixed with the data store type, strip it off.
        if (key.startsWith(dataStoreTypePrefix)) {
            key = key.replaceFirst(dataStoreTypePrefix, "");
        }
        if (convertValueAndInvokeSetter(key, value, builder)) {
            updated = true;
        }
    }
    currentProperties = mapBuilder.build();
    if (updated) {
        context = builder.build();
    }
    return updated;
}
Also used : Builder(org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with Builder

use of org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder in project controller by opendaylight.

the class DatastoreContextIntrospector method getShardDatastoreContext.

public synchronized DatastoreContext getShardDatastoreContext(final String forShardName) {
    if (currentProperties == null) {
        return context;
    }
    final Builder builder = DatastoreContext.newBuilderFrom(context);
    final String dataStoreTypePrefix = context.getDataStoreName() + '.';
    final String shardNamePrefix = forShardName + '.';
    final List<String> keys = getSortedKeysByDatastoreType(currentProperties.keySet(), dataStoreTypePrefix);
    for (String key : keys) {
        final Object value = currentProperties.get(key);
        if (key.startsWith(dataStoreTypePrefix)) {
            key = key.replaceFirst(dataStoreTypePrefix, "");
        }
        if (key.startsWith(shardNamePrefix)) {
            key = key.replaceFirst(shardNamePrefix, "");
            convertValueAndInvokeSetter(key, value, builder);
        }
    }
    return builder.build();
}
Also used : Builder(org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder)

Example 5 with Builder

use of org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder in project controller by opendaylight.

the class ShardManager method addPrefixShard.

private void addPrefixShard(final String shardName, final YangInstanceIdentifier shardPrefix, final RemotePrimaryShardFound response, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }
    shardReplicaOperationsInProgress.add(shardName);
    final ShardInformation shardInfo;
    final boolean removeShardOnFailure;
    ShardInformation existingShardInfo = localShards.get(shardName);
    if (existingShardInfo == null) {
        removeShardOnFailure = true;
        ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), shardName);
        final Builder builder = newShardDatastoreContextBuilder(shardName);
        builder.storeRoot(shardPrefix).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName());
        DatastoreContext datastoreContext = builder.build();
        shardInfo = new ShardInformation(shardName, shardId, getPeerAddresses(shardName), datastoreContext, Shard.builder(), peerAddressResolver);
        shardInfo.setActiveMember(false);
        shardInfo.setSchemaContext(schemaContext);
        localShards.put(shardName, shardInfo);
        shardInfo.setActor(newShardActor(shardInfo));
    } else {
        removeShardOnFailure = false;
        shardInfo = existingShardInfo;
    }
    execAddShard(shardName, shardInfo, response, removeShardOnFailure, sender);
}
Also used : DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) Builder(org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)

Aggregations

Builder (org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder)5 ImmutableMap (com.google.common.collect.ImmutableMap)2 ActorRef (akka.actor.ActorRef)1 ActorSelection (akka.actor.ActorSelection)1 ActorSystem (akka.actor.ActorSystem)1 Address (akka.actor.Address)1 AddressFromURIString (akka.actor.AddressFromURIString)1 Cluster (akka.cluster.Cluster)1 Futures (akka.dispatch.Futures)1 Patterns (akka.pattern.Patterns)1 TestKit (akka.testkit.javadsl.TestKit)1 Optional (com.google.common.base.Optional)1 Stopwatch (com.google.common.base.Stopwatch)1 Supplier (com.google.common.base.Supplier)1 Throwables (com.google.common.base.Throwables)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 ConfigFactory (com.typesafe.config.ConfigFactory)1 BigInteger (java.math.BigInteger)1