Skip to content

Commit f9f3a04

Browse files
committed
Do not expose model context
Do not expose model context from LightyServices because global model context can be retrieved from DOMSchemaService. Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
1 parent 1f2a12b commit f9f3a04

File tree

11 files changed

+18
-37
lines changed

11 files changed

+18
-37
lines changed

lighty-core/lighty-controller-guice-di/src/main/java/io/lighty/core/controller/guice/LightyControllerModule.java

-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
3939
import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
4040
import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
41-
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
4241
import org.slf4j.Logger;
4342
import org.slf4j.LoggerFactory;
4443

@@ -64,7 +63,6 @@ protected void configure() {
6463
.toInstance(lightyServices.getDiagStatusService());
6564
bind(ActorSystemProvider.class)
6665
.toInstance(lightyServices.getActorSystemProvider());
67-
bind(EffectiveModelContext.class).toInstance(lightyServices.getEffectiveModelContext());
6866
bind(DOMSchemaService.class)
6967
.toInstance(lightyServices.getDOMSchemaService());
7068
bind(DOMSchemaService.YangTextSourceExtension.class)

lighty-core/lighty-controller-guice-di/src/test/java/io/lighty/core/controller/guice/tests/TestService.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ public class TestService {
4848
@Inject
4949
private ActorSystemProvider actorSystemProvider;
5050

51-
@Inject
52-
private EffectiveModelContext effectiveModelContext;
53-
5451
@Inject
5552
private DOMSchemaService domSchemaService;
5653

@@ -156,7 +153,7 @@ public ActorSystemProvider getActorSystemProvider() {
156153
}
157154

158155
public EffectiveModelContext getSchemaContext() {
159-
return effectiveModelContext;
156+
return getDomSchemaService().getGlobalContext();
160157
}
161158

162159
public DOMSchemaService getDomSchemaService() {

lighty-core/lighty-controller-spring-di/src/main/java/io/lighty/core/controller/spring/LightyCoreSpringConfiguration.java

-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
3939
import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
4040
import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
41-
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
4241
import org.slf4j.Logger;
4342
import org.slf4j.LoggerFactory;
4443
import org.springframework.context.annotation.Bean;
@@ -138,11 +137,6 @@ public ActorSystemProvider actorSystemProvider() {
138137
return this.lightyController.getServices().getActorSystemProvider();
139138
}
140139

141-
@Bean(destroyMethod = "")
142-
public EffectiveModelContext effectiveModelContext() {
143-
return this.lightyController.getServices().getEffectiveModelContext();
144-
}
145-
146140
@Bean(destroyMethod = "")
147141
@Primary
148142
public DOMSchemaService domSchemaService() {

lighty-core/lighty-controller-spring-di/src/test/java/io/lighty/core/controller/spring/LightyCoreSpringConfigurationTest.java

-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
4747
import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
4848
import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
49-
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
5049
import org.slf4j.Logger;
5150
import org.slf4j.LoggerFactory;
5251
import org.springframework.beans.factory.annotation.Autowired;
@@ -79,9 +78,6 @@ public class LightyCoreSpringConfigurationTest extends AbstractJUnit4SpringConte
7978
@Autowired
8079
ActorSystemProvider actorSystemProviderTestProperty;
8180

82-
@Autowired
83-
EffectiveModelContext effectiveModelContext;
84-
8581
@Autowired
8682
DOMSchemaService domSchemaServiceTestProperty;
8783

@@ -177,7 +173,6 @@ public void testLightyBeansExists() {
177173
assertNotNull(lightyModuleRegistryServiceTestProperty);
178174
assertNotNull(diagStatusServiceTestProperty);
179175
assertNotNull(actorSystemProviderTestProperty);
180-
assertNotNull(effectiveModelContext);
181176
assertNotNull(domSchemaServiceTestProperty);
182177
assertNotNull(domYangTextSourceProviderTestProperty);
183178
assertNotNull(domMountPointServiceTestProperty);

lighty-core/lighty-controller/src/main/java/io/lighty/core/controller/api/LightyServices.java

-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
4343
import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
4444
import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
45-
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
4645
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
4746

4847
/**
@@ -61,8 +60,6 @@ public interface LightyServices extends LightyModuleRegistryService {
6160

6261
ActorSystemProvider getActorSystemProvider();
6362

64-
EffectiveModelContext getEffectiveModelContext();
65-
6663
DOMSchemaService getDOMSchemaService();
6764

6865
DOMSchemaService.YangTextSourceExtension getYangTextSourceExtension();

lighty-core/lighty-controller/src/main/java/io/lighty/core/controller/impl/LightyControllerImpl.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import akka.actor.Terminated;
1111
import akka.management.javadsl.AkkaManagement;
1212
import com.google.common.base.Stopwatch;
13-
import com.google.common.util.concurrent.ListenableFuture;
13+
import com.google.common.util.concurrent.Futures;
1414
import com.typesafe.config.Config;
1515
import io.lighty.codecs.util.exception.DeserializationException;
1616
import io.lighty.core.cluster.ClusteringHandler;
@@ -122,8 +122,7 @@
122122
import org.opendaylight.yangtools.util.DurationStatisticsTracker;
123123
import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
124124
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
125-
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
126-
import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
125+
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
127126
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
128127
import org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory;
129128
import org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory;
@@ -273,8 +272,13 @@ protected boolean initProcedure() {
273272
this.snapshotResolver = new ModuleInfoSnapshotResolver("binding-dom-codec", yangParserFactory);
274273
this.modelsRegistration = snapshotResolver.registerModuleInfos(modelSet);
275274
this.moduleInfoSnapshot = snapshotResolver.takeSnapshot();
276-
this.schemaService = new FixedDOMSchemaService(this::getEffectiveModelContext,
277-
sourceId -> (ListenableFuture<YangTextSource>) moduleInfoSnapshot.yangTextSource(sourceId));
275+
this.schemaService = new FixedDOMSchemaService(() -> moduleInfoSnapshot.modelContext(), sourceId -> {
276+
try {
277+
return Futures.immediateFuture(moduleInfoSnapshot.getYangTextSource(sourceId));
278+
} catch (MissingSchemaSourceException e) {
279+
return Futures.immediateFailedFuture(e);
280+
}
281+
});
278282

279283
// INIT CODEC FACTORY
280284

@@ -359,7 +363,7 @@ protected boolean initProcedure() {
359363
final InitialConfigData initialData = this.initialConfigData.get();
360364
try (InputStream inputStream = initialData.getAsInputStream()) {
361365
FileToDatastoreUtils.importConfigDataFile(inputStream, initialData.getFormat(),
362-
getEffectiveModelContext(), this.getClusteredDOMDataBroker(), true);
366+
moduleInfoSnapshot.modelContext(), this.getClusteredDOMDataBroker(), true);
363367
} catch (TimeoutException | ExecutionException | IOException | DeserializationException e) {
364368
LOG.error("Exception occurred while importing config data from file", e);
365369
return false;
@@ -504,11 +508,6 @@ public ActorSystemProvider getActorSystemProvider() {
504508
return this.actorSystemProvider;
505509
}
506510

507-
@Override
508-
public EffectiveModelContext getEffectiveModelContext() {
509-
return this.moduleInfoSnapshot.modelContext();
510-
}
511-
512511
@Override
513512
public DOMSchemaService getDOMSchemaService() {
514513
return this.schemaService;

lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/impl/tests/LightyControllerTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public void controllerSimpleTest() {
2424
lightyController.getServices().getDiagStatusService().getAllServiceDescriptors());
2525
Assert.assertNotNull(lightyController.getServices().getActorSystemProvider());
2626
Assert.assertNotNull(lightyController.getServices().getActorSystemProvider().getActorSystem());
27-
Assert.assertNotNull(lightyController.getServices().getEffectiveModelContext());
2827
Assert.assertNotNull(lightyController.getServices().getDOMSchemaService());
2928
Assert.assertNotNull(lightyController.getServices().getYangTextSourceExtension());
3029
Assert.assertNotNull(lightyController.getServices().getDOMNotificationRouter());

lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/util/FileToDatastoreUtilsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private void importFile(final String path, final YangInstanceIdentifier yii, fin
157157
FileToDatastoreUtils.importConfigDataFile(FileToDatastoreUtils.class.getResourceAsStream(path),
158158
yii,
159159
format,
160-
lightyController.getServices().getEffectiveModelContext(),
160+
lightyController.getServices().getDOMSchemaService().getGlobalContext(),
161161
lightyController.getServices().getClusteredDOMDataBroker(),
162162
true);
163163
}

lighty-modules/lighty-bgp/src/main/java/io/lighty/modules/bgp/deployer/BgpModule.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public BgpModule(final EffectiveModelContext modelContext, final DataBroker data
107107
}
108108

109109
public BgpModule(final LightyServices lightyServices) {
110-
this(lightyServices.getEffectiveModelContext(),
110+
this(lightyServices.getDOMSchemaService().getGlobalContext(),
111111
lightyServices.getBindingDataBroker(), lightyServices.getClusteredDOMDataBroker(),
112112
lightyServices.getBindingCodecTreeFactory(),
113113
lightyServices.getAdapterContext().currentSerializer().getRuntimeContext(),

lighty-modules/lighty-netconf-sb/src/test/java/io/lighty/modules/southbound/netconf/tests/SampleConfigTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public void loadTopLevelSingleNodeModelsFromJsonConfig() throws Exception {
2929
final LightyController lightyController = getLightyController("sampleConfigSingleNode.json");
3030
assertTrue(lightyController.start().get(TIME_OUT, TimeUnit.SECONDS));
3131

32-
final int loadedModulesSize = lightyController.getServices().getEffectiveModelContext().getModules().size();
32+
final int loadedModulesSize = lightyController.getServices().getDOMSchemaService().getGlobalContext()
33+
.getModules().size();
3334
assertTrue(lightyController.shutdown(TIME_OUT, TimeUnit.SECONDS));
3435

3536
assertEquals(loadedModulesSize, 17);
@@ -40,7 +41,8 @@ public void loadTopLevelClusterModelsFromJsonConfig() throws Exception {
4041
final LightyController lightyController = getLightyController("sampleConfigCluster.json");
4142
assertTrue(lightyController.start().get(TIME_OUT, TimeUnit.SECONDS));
4243

43-
final int loadedModulesSize = lightyController.getServices().getEffectiveModelContext().getModules().size();
44+
final int loadedModulesSize = lightyController.getServices().getDOMSchemaService().getGlobalContext()
45+
.getModules().size();
4446
assertTrue(lightyController.shutdown(TIME_OUT, TimeUnit.SECONDS));
4547

4648
assertEquals(loadedModulesSize, 17);

lighty-modules/lighty-restconf-nb-community/src/test/java/io/lighty/modules/northbound/restconf/community/impl/tests/YangPatchTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void patchDataReplaceTest() throws Exception {
6363
final PatchContext patchContext = new PatchContext("test-patch", List.of(entityReplace));
6464

6565
final var strategy = new MdsalRestconfStrategy(DatabindContext.ofModel(getLightyController()
66-
.getServices().getEffectiveModelContext()), getLightyController().getServices()
66+
.getServices().getDOMSchemaService().getGlobalContext()), getLightyController().getServices()
6767
.getClusteredDOMDataBroker(), getLightyController().getServices().getDOMRpcService(),
6868
getLightyController().getServices()
6969
.getDOMActionService(), getLightyController().getServices().getYangTextSourceExtension(),

0 commit comments

Comments
 (0)