*/
package org.opendaylight.controller.cluster.datastore;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashMap;
import org.opendaylight.controller.md.sal.dom.store.impl.DOMImmutableDataChangeEvent;
import org.opendaylight.controller.md.sal.dom.store.impl.ResolveDataChangeEventsTask;
import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerTree;
-import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
* This class is not part of the API contract and is subject to change at any time.
*/
@NotThreadSafe
-@VisibleForTesting
-public final class ShardDataTree extends ShardDataTreeTransactionParent {
+public class ShardDataTree extends ShardDataTreeTransactionParent {
private static final Logger LOG = LoggerFactory.getLogger(ShardDataTree.class);
private static final ShardDataTreeNotificationManager MANAGER = new ShardDataTreeNotificationManager();
private final Map<String, ShardDataTreeTransactionChain> transactionChains = new HashMap<>();
private final ShardDataTreeChangePublisher treeChangePublisher = new ShardDataTreeChangePublisher();
private final ListenerTree listenerTree = ListenerTree.create();
private final TipProducingDataTree dataTree;
+ private SchemaContext schemaContext;
ShardDataTree(final SchemaContext schemaContext) {
dataTree = InMemoryDataTreeFactory.getInstance().create();
- if (schemaContext != null) {
- dataTree.setSchemaContext(schemaContext);
- }
+ updateSchemaContext(schemaContext);
+
}
TipProducingDataTree getDataTree() {
return dataTree;
}
+ SchemaContext getSchemaContext() {
+ return schemaContext;
+ }
+
void updateSchemaContext(final SchemaContext schemaContext) {
+ Preconditions.checkNotNull(schemaContext);
+ this.schemaContext = schemaContext;
dataTree.setSchemaContext(schemaContext);
}
ReadWriteShardDataTreeTransaction newReadWriteTransaction(final String txId, final String chainId) {
if (Strings.isNullOrEmpty(chainId)) {
- return new ReadWriteShardDataTreeTransaction(this, txId, dataTree.takeSnapshot().newModification());
+ return new ReadWriteShardDataTreeTransaction(ShardDataTree.this, txId, dataTree.takeSnapshot()
+ .newModification());
}
return ensureTransactionChain(chainId).newReadWriteTransaction(txId);
}
- void notifyListeners(final DataTreeCandidateTip candidate) {
+ void notifyListeners(final DataTreeCandidate candidate) {
LOG.debug("Notifying listeners on candidate {}", candidate);
// DataTreeChanges first, as they are more light-weight
if (chain != null) {
chain.close();
} else {
- LOG.warn("Closing non-existent transaction chain {}", transactionChainId);
+ LOG.debug("Closing non-existent transaction chain {}", transactionChainId);
}
}
return new SimpleEntry<>(reg, event);
}
+ void applyForeignCandidate(final String identifier, final DataTreeCandidate foreign) throws DataValidationFailedException {
+ LOG.debug("Applying foreign transaction {}", identifier);
+
+ final DataTreeModification mod = dataTree.takeSnapshot().newModification();
+ DataTreeCandidates.applyToModification(mod, foreign);
+ mod.ready();
+
+ LOG.trace("Applying foreign modification {}", mod);
+ dataTree.validate(mod);
+ final DataTreeCandidate candidate = dataTree.prepare(mod);
+ dataTree.commit(candidate);
+ notifyListeners(candidate);
+ }
+
@Override
void abortTransaction(final AbstractShardDataTreeTransaction<?> transaction) {
// Intentional no-op
}
@Override
- DOMStoreThreePhaseCommitCohort finishTransaction(final ReadWriteShardDataTreeTransaction transaction) {
+ ShardDataTreeCohort finishTransaction(final ReadWriteShardDataTreeTransaction transaction) {
final DataTreeModification snapshot = transaction.getSnapshot();
snapshot.ready();
- return new ShardDataTreeCohort(this, snapshot);
+ return new SimpleShardDataTreeCohort(this, snapshot, transaction.getId());
}
}