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));
}
}
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);
}
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;
}
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();
}
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);
}
Aggregations