aa9da01ad20b7b1d3cefb4d40803e582fdf5e308
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.data.acessor;
23
24 import java.io.IOException;
25
26 import org.onap.ccsdk.features.sdnr.wt.common.database.ExtRestClient;
27 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
28 import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult;
29 import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest;
30 import org.onap.ccsdk.features.sdnr.wt.common.database.responses.AggregationEntries;
31 import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.rpctypehelper.QueryByFilter;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.rpctypehelper.QueryResult;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput;
36 import org.opendaylight.yangtools.yang.binding.DataObject;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 public class DataObjectAcessorPm<T extends DataObject> extends DataObjectAcessor<T> {
41
42     private final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorPm.class);
43
44     private static final String UUID_KEY = "uuid-interface";
45     private static final String NODE_KEY = "node-name";
46     private static final String KEY = "node-name";
47
48
49     public enum Intervall {
50         PMDATA15M("historicalperformance15min", "historicalperformance15min"), PMDATA24H("historicalperformance24h",
51                 "historicalperformance24h");
52
53         String index;
54         String type;
55
56         Intervall(String index, String type) {
57             this.index = index;
58             this.type = type;
59         }
60
61         public String getIndex() {
62             return index;
63         }
64
65         public String getType() {
66             return type;
67         }
68     }
69
70     private ExtRestClient dbClient;
71     private Intervall mode;
72
73     public DataObjectAcessorPm(HtDatabaseClient dbClient, Intervall mode, Entity entity, Class<T> clazz)
74             throws ClassNotFoundException {
75         super(dbClient, entity, clazz);
76         LOG.info("DataObjectAcessorPm");
77         this.dbClient = dbClient;
78         this.mode = mode;
79     }
80
81     /**
82      * get aggregated list of ltps for filter NODE_KEY
83      * 
84      * @param input
85      * @return
86      * @throws IOException
87      */
88     public QueryResult<String> getDataLtpList(EntityInput input) throws IOException {
89
90         QueryByFilter queryByFilter = new QueryByFilter(input);
91         SearchRequest request =
92                 queryByFilter.getSearchRequestByFilter(NODE_KEY, UUID_KEY, mode.getIndex(), mode.getType());
93         try {
94             SearchResponse response = this.dbClient.search(request);
95             AggregationEntries aggs = response.getAggregations(UUID_KEY);
96             String[] uuids =
97                     aggs.getKeysAsPagedStringList(queryByFilter.getPageSize(), queryByFilter.getPageStartIndex());
98             long totalSize = aggs.size();
99             return new QueryResult<String>(queryByFilter.getPage(), queryByFilter.getPageSize(),
100                     new SearchResult<String>(uuids, totalSize));
101         } catch (IOException e) {
102             throw new IOException("problem reading ltps for req=" + request, e);
103         }
104     }
105
106     /**
107      * get aggregated devices list
108      * 
109      * @param input filter should be empty/no filter handled, only sortorder for KEY ('node-name')
110      * @return
111      * @throws IOException
112      */
113     public QueryResult<String> getDataDeviceList(EntityInput input) throws IOException {
114
115         QueryByFilter queryByFilter = new QueryByFilter(input);
116         SearchRequest request =
117                 queryByFilter.getSearchRequestBySortOrder(NODE_KEY, UUID_KEY, mode.getIndex(), mode.getType());
118         try {
119             SearchResponse response = this.dbClient.search(request);
120             AggregationEntries aggs = response.getAggregations(KEY);
121             String[] uuids =
122                     aggs.getKeysAsPagedStringList(queryByFilter.getPageSize(), queryByFilter.getPageStartIndex());
123             long totalSize = aggs.size();
124             return new QueryResult<String>(queryByFilter.getPage(), queryByFilter.getPageSize(),
125                     new SearchResult<String>(uuids, totalSize));
126         } catch (IOException e) {
127             throw new IOException("problem reading nodes for req=" + request, e);
128         }
129
130     }
131
132 }