Cache full datastore context
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / md / cluster / datastore / model / SchemaContextHelper.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.md.cluster.datastore.model;
9
10 import java.io.InputStream;
11 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
12 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
13
14 public final class SchemaContextHelper {
15
16     public static final String ODL_DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
17     public static final String PEOPLE_YANG = "/people.yang";
18     public static final String CARS_YANG = "/cars.yang";
19
20     private static volatile EffectiveModelContext FULL;
21
22     private SchemaContextHelper() {
23
24     }
25
26     public static InputStream getInputStream(final String yangFileName) {
27         return SchemaContextHelper.class.getResourceAsStream(yangFileName);
28     }
29
30     public static EffectiveModelContext full() {
31         EffectiveModelContext ret = FULL;
32         if (ret == null) {
33             synchronized (SchemaContextHelper.class) {
34                 ret = FULL;
35                 if (ret == null) {
36                     ret = FULL = select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
37                 }
38             }
39         }
40
41         return ret;
42     }
43
44     public static EffectiveModelContext select(final String... schemaFiles) {
45         return YangParserTestUtils.parseYangResources(SchemaContextHelper.class, schemaFiles);
46     }
47
48     public static EffectiveModelContext distributedShardedDOMDataTreeSchemaContext() {
49         // we need prefix-shard-configuration and odl-datastore-test models
50         // for DistributedShardedDOMDataTree tests
51         return YangParserTestUtils.parseYangResources(SchemaContextHelper.class, ODL_DATASTORE_TEST_YANG,
52             "/META-INF/yang/prefix-shard-configuration@2017-01-10.yang");
53     }
54 }