4dd52f43ad7a3c63feb4817a196472af31989894
[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) throws ClassNotFoundException {
46         super(dbClient, entity, Data.class, false);
47         this.dbClient = dbClient;
48         this.entity = entity;
49     }
50
51     QueryResult<Data> getDataStatus() throws IOException {
52         SearchRequest request = getNewInstanceOfSearchRequest(entity);
53         request.setQuery(QueryBuilders.matchAllQuery().aggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY).size(0));
54         SearchResponse response = this.dbClient.search(request);
55         AggregationEntries aggs = response.getAggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY);
56
57         Data[] data = {new DataBuilder().setFaults(new FaultsBuilder().setCriticals(aggs.getOrDefault("Critical", 0L))
58                 .setMajors(aggs.getOrDefault("Major", 0L)).setMinors(aggs.getOrDefault("Minor", 0L))
59                 .setWarnings(aggs.getOrDefault("Warning", 0L)).build()).build()};
60         long toalsize = data.length;
61         return new QueryResult<Data>(1L, 1L, new SearchResult<Data>(data, toalsize));
62
63     }
64
65
66     private static SearchRequest getNewInstanceOfSearchRequest(Entity entity) {
67         return new SearchRequest(entity.getName(), entity.getName());
68     }
69
70
71 }