Initial OpenECOMP Demo commit
[demo.git] / vnfs / honeycomb_plugin / sample_plugin / sample-plugin-impl / src / main / java / io / fd / honeycomb / tutorial / write / ModuleWriterFactory.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /*
18  * Modifications copyright (c) 2017 AT&T Intellectual Property
19  */
20 package io.fd.honeycomb.tutorial.write;
21
22 import com.google.inject.Inject;
23 import io.fd.honeycomb.translate.impl.write.GenericWriter;
24 import io.fd.honeycomb.translate.v3po.util.NamingContext;
25 import io.fd.honeycomb.translate.write.WriterFactory;
26 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
27 import javax.annotation.Nonnull;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.sample.plugin.rev160918.SamplePlugin;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.sample.plugin.rev160918.sample.plugin.params.PgStreams;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.sample.plugin.rev160918.sample.plugin.params.pg.streams.PgStream;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.openvpp.jvpp.core.future.FutureJVppCore;
33
34 /**
35  * Factory producing writers for sample-plugin plugin's data.
36  */
37 public final class ModuleWriterFactory implements WriterFactory {
38
39     private static final InstanceIdentifier<SamplePlugin> ROOT_CONTAINER_ID = InstanceIdentifier.create(SamplePlugin.class);
40
41     /**
42      * Injected vxlan naming context shared with writer, provided by this plugin
43      */
44     @Inject
45     private NamingContext pgNamingContext;
46     /**
47      * Injected jvpp core APIs, provided by Honeycomb's infrastructure
48      */
49     @Inject
50     private FutureJVppCore jvppCore;
51
52     @Override
53     public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
54         // Unlike ReaderFactory, there's no need to add structural writers, just the writers that actually do something
55
56         // register writer for vxlan tunnel
57         registry.add(new GenericWriter<>(
58                 // What part of subtree this writer handles is identified by an InstanceIdentifier
59                 ROOT_CONTAINER_ID.child(PgStreams.class).child(PgStream.class),
60                 // Customizer (the actual translation code to do the heavy lifting)
61                 new PgWriteCustomizer(jvppCore, pgNamingContext)));
62     }
63 }