c1a6b2936d9641f787c17fb6f7fae703dca538ba
[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;
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.queries.QueryBuilders;
30 import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest;
31 import org.onap.ccsdk.features.sdnr.wt.common.database.responses.AggregationEntries;
32 import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.status.output.Data;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.status.output.DataBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.status.entity.FaultsBuilder;
37
38 public class DataObjectAcessorStatus extends DataObjectAcessor<Data> {
39
40         final String ESDATATYPE_FAULTCURRENT_SEVERITY_KEY = "severity";
41
42         private final ExtRestClient dbClient;
43         private final Entity entity;
44
45         public DataObjectAcessorStatus(HtDatabaseClient dbClient, Entity entity)
46                         throws ClassNotFoundException {
47                 super(dbClient, entity, Data.class, false);
48                 this.dbClient = dbClient;
49                 this.entity = entity;
50         }
51
52         QueryResult<Data> getDataStatus() throws IOException {
53         SearchRequest request = getNewInstanceOfSearchRequest(entity);
54         request.setQuery(
55                         QueryBuilders.matchAllQuery().aggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY).size(0));
56                 SearchResponse response = this.dbClient.search(request);
57                 AggregationEntries aggs = response.getAggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY);
58
59                 Data[] data = { new DataBuilder().setFaults(new FaultsBuilder().
60                                                 setCriticals(aggs.getOrDefault("Critical",0L)).
61                                                 setMajors(aggs.getOrDefault("Major", 0L)).
62                                                 setMinors(aggs.getOrDefault("Minor", 0L)).
63                                                 setWarnings(aggs.getOrDefault("Warning", 0L)).
64                                                 build()).build() };
65                 long toalsize = data.length;
66                 return new QueryResult<Data>(1L, 1L, new SearchResult<Data>(data, toalsize));
67
68         }
69
70
71     private static SearchRequest getNewInstanceOfSearchRequest(Entity entity) {
72         return new SearchRequest(entity.getName(), entity.getName());
73     }
74
75
76 }