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.acessor;
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.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.read.status.output.Data;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.status.output.DataBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.status.entity.FaultsBuilder;
39 public class DataObjectAcessorStatus extends DataObjectAcessor<Data> {
41 final String ESDATATYPE_FAULTCURRENT_SEVERITY_KEY = "severity";
43 private final ExtRestClient dbClient;
44 private final Entity entity;
46 public DataObjectAcessorStatus(HtDatabaseClient dbClient, Entity entity) throws ClassNotFoundException {
47 super(dbClient, entity, Data.class);
48 this.dbClient = dbClient;
52 public QueryResult<Data> getDataStatus() throws IOException {
53 SearchRequest request = getNewInstanceOfSearchRequest(entity);
54 request.setQuery(QueryBuilders.matchAllQuery().aggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY).size(0));
55 SearchResponse response = this.dbClient.search(request);
56 AggregationEntries aggs = response.getAggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY);
58 Data[] data = {new DataBuilder().setFaults(new FaultsBuilder().setCriticals(aggs.getOrDefault("Critical", 0L))
59 .setMajors(aggs.getOrDefault("Major", 0L)).setMinors(aggs.getOrDefault("Minor", 0L))
60 .setWarnings(aggs.getOrDefault("Warning", 0L)).build()).build()};
61 long toalsize = data.length;
62 return new QueryResult<Data>(1L, 1L, new SearchResult<Data>(data, toalsize));
67 private static SearchRequest getNewInstanceOfSearchRequest(Entity entity) {
68 return new SearchRequest(entity.getName(), entity.getName());