2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.infra.distro.data;
19 import com.google.inject.Inject;
20 import com.google.inject.name.Named;
22 import io.fd.honeycomb.binding.init.ProviderTrait;
23 import io.fd.honeycomb.data.impl.PersistingDataTreeAdapter;
24 import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration;
25 import io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule;
27 import java.nio.file.Paths;
29 import org.opendaylight.controller.sal.core.api.model.SchemaService;
30 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
31 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public abstract class PersistingDataTreeProvider extends ProviderTrait<DataTree> {
37 private static final Logger LOG = LoggerFactory.getLogger(PersistingDataTreeProvider.class);
40 private SchemaService schemaService;
42 protected HoneycombConfiguration config;
45 public DataTree create() {
47 ? new PersistingDataTreeAdapter(getDelegate(), schemaService, Paths.get(getPath()))
51 public abstract String getPath();
53 public abstract TreeType getType();
55 public abstract DataTree getDelegate();
57 protected abstract boolean isEnabled();
59 public static final class ConfigPersistingDataTreeProvider extends PersistingDataTreeProvider {
62 @Named(ConfigAndOperationalPipelineModule.HONEYCOMB_CONFIG_NONPERSIST)
63 private DataTree delegate;
66 public String getPath() {
67 return config.peristConfigPath;
71 public TreeType getType() {
72 return TreeType.CONFIGURATION;
76 public DataTree getDelegate() {
81 protected boolean isEnabled() {
82 return config.isConfigPersistenceEnabled();
86 public static final class ContextPersistingDataTreeProvider extends PersistingDataTreeProvider {
89 @Named(ContextPipelineModule.HONEYCOMB_CONTEXT_NOPERSIST)
90 private DataTree delegate;
93 public String getPath() {
94 return config.peristContextPath;
98 public TreeType getType() {
99 return TreeType.OPERATIONAL;
103 public DataTree getDelegate() {
108 protected boolean isEnabled() {
109 return config.isContextPersistenceEnabled();