2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.data;
24 import java.io.IOException;
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;
38 public class DataObjectAcessorStatus extends DataObjectAcessor<Data> {
40 final String ESDATATYPE_FAULTCURRENT_SEVERITY_KEY = "severity";
42 private final ExtRestClient dbClient;
43 private final Entity entity;
45 public DataObjectAcessorStatus(HtDatabaseClient dbClient, Entity entity)
46 throws ClassNotFoundException {
47 super(dbClient, entity, Data.class, false);
48 this.dbClient = dbClient;
52 QueryResult<Data> getDataStatus() throws IOException {
53 SearchRequest request = getNewInstanceOfSearchRequest(entity);
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);
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)).
65 long toalsize = data.length;
66 return new QueryResult<Data>(1L, 1L, new SearchResult<Data>(data, toalsize));
71 private static SearchRequest getNewInstanceOfSearchRequest(Entity entity) {
72 return new SearchRequest(entity.getName(), entity.getName());