Fix vFWCL Heat template for instantiation with Robot
[demo.git] / vnfs / honeycomb_plugin / stream-count / stream-count-impl / src / main / java / org / onap / vnf / vfw / ElementCrudService.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) 2019 AT&T Intellectual Property
19  */
20
21 package org.onap.vnf.vfw;
22
23 import io.fd.honeycomb.translate.read.ReadFailedException;
24 import io.fd.honeycomb.translate.write.WriteFailedException;
25 import java.util.Collections;
26 import java.util.List;
27 import javax.annotation.Nonnull;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.stream.count.rev190118.StreamCountState;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.stream.count.rev190118.stream.count.params.Streams;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.stream.count.rev190118.stream.count.params.StreamsBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.stream.count.rev190118.StreamNum;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 /**
37  * Simple example of class handling Crud operations for plugin.
38  * <p/>
39  * No real handling, serves just as an illustration.
40  *
41  * TODO update javadoc
42  */
43 final class ElementCrudService implements CrudService<Streams> {
44
45     private static final Logger LOG = LoggerFactory.getLogger(ElementCrudService.class);
46
47     @Override
48     public void writeData(@Nonnull final InstanceIdentifier<Streams> identifier, @Nonnull final Streams data)
49             throws WriteFailedException {
50         if (data != null) {
51
52             // Performs any logic needed for persisting such data
53             LOG.info("Writing path[{}] / data [{}]", identifier, data);
54         } else {
55             throw new WriteFailedException.CreateFailedException(identifier, data,
56                     new NullPointerException("Provided data are null"));
57         }
58     }
59
60     @Override
61     public void deleteData(@Nonnull final InstanceIdentifier<Streams> identifier, @Nonnull final Streams data)
62             throws WriteFailedException {
63         if (data != null) {
64
65             // Performs any logic needed for persisting such data
66             LOG.info("Removing path[{}] / data [{}]", identifier, data);
67         } else {
68             throw new WriteFailedException.DeleteFailedException(identifier,
69                     new NullPointerException("Provided data are null"));
70         }
71     }
72
73     @Override
74     public void updateData(@Nonnull final InstanceIdentifier<Streams> identifier, @Nonnull final Streams dataOld,
75                            @Nonnull final Streams dataNew) throws WriteFailedException {
76         if (dataOld != null && dataNew != null) {
77
78             // Performs any logic needed for persisting such data
79             LOG.info("Update path[{}] from [{}] to [{}]", identifier, dataOld, dataNew);
80         } else {
81             throw new WriteFailedException.DeleteFailedException(identifier,
82                     new NullPointerException("Provided data are null"));
83         }
84     }
85
86     @Override
87     public Streams readSpecific(@Nonnull final InstanceIdentifier<Streams> identifier) throws ReadFailedException {
88
89         // load data by this key
90         // *Key class will always contain key of entity, in this case long value
91
92         return new StreamsBuilder()
93                 .setActiveStreams(new StreamNum(1L))
94                 .build();
95     }
96
97     @Override
98     public List<Streams> readAll() throws ReadFailedException {
99         // read all data under parent node,in this case {@link ModuleState}
100         return Collections.singletonList(
101                 readSpecific(InstanceIdentifier.create(StreamCountState.class).child(Streams.class)));
102     }
103 }