6486312279a6177a28eb8fb330355b5f6c31cd0b
[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.database.elasticsearch.data.acessor;
23
24 import java.io.IOException;
25 import org.onap.ccsdk.features.sdnr.wt.common.database.ExtRestClient;
26 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
27 import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult;
28 import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest;
29 import org.onap.ccsdk.features.sdnr.wt.common.database.responses.AggregationEntries;
30 import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.rpctypehelper.QueryByFilter;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.rpctypehelper.QueryResult;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput;
35 import org.opendaylight.yangtools.yang.binding.DataObject;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 @Deprecated
40 public class DataObjectAcessorInventory<T extends DataObject> extends DataObjectAcessorWithId<T> {
41
42     private final Logger LOG = LoggerFactory.getLogger(DataObjectAcessorInventory.class);
43
44     private static final String KEY = "node-id";
45
46     private ExtRestClient dbClient;
47
48     public DataObjectAcessorInventory(HtDatabaseClient dbClient, Entity entity, Class<T> clazz,
49                                       boolean doFullsizeRequest) throws ClassNotFoundException {
50         super(dbClient, entity, clazz, doFullsizeRequest);
51         LOG.info("Create DataObjectAcessorInventory");
52         this.dbClient = dbClient;
53     }
54
55
56     /**
57      * get aggregated devices list
58      *
59      * @param input filter should be empty/no filter handled, only sortorder for KEY ('node-name')
60      * @return
61      * @throws IOException
62      */
63     public QueryResult<String> getDataDeviceList(EntityInput input) {
64
65         QueryByFilter queryByFilter = new QueryByFilter(input);
66         SearchRequest request =
67                 queryByFilter.getSearchRequestAggregated(KEY,this.getDataTypeName(), this.getDataTypeName(), this.doFullsizeRequest);
68         try {
69             SearchResponse response = this.dbClient.search(request);
70             AggregationEntries aggs = response.getAggregations(KEY);
71             String[] uuids =
72                     aggs.getKeysAsPagedStringList(queryByFilter.getPageSize(), queryByFilter.getPageStartIndex());
73             long totalSize = aggs.size();
74             return new QueryResult<String>(queryByFilter.getPage(), queryByFilter.getPageSize(),
75                     new SearchResult<String>(uuids, totalSize));
76         } catch (IOException e) {
77             throw new RuntimeException("problem reading nodes for req=" + request, e);
78         }
79
80     }
81
82 }