5811550e6d6190447bcec5d92db2860863e54031
[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.queries.QueryBuilder;
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.database.elasticsearch.data.rpctypehelper.QueryResult;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionLogStatus;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.status.output.Data;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.status.output.DataBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.status.entity.FaultsBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.status.entity.NetworkElementConnectionsBuilder;
41 import org.opendaylight.yangtools.yang.common.Uint32;
42
43 public class DataObjectAcessorStatus extends DataObjectAcessor<Data> {
44
45     final String ESDATATYPE_FAULTCURRENT_SEVERITY_KEY = "severity";
46     final String ESDATATYPE_NECON_CONNECTIONSTATE_KEY = "status";
47
48     private final ExtRestClient dbClient;
49
50     public DataObjectAcessorStatus(HtDatabaseClient dbClient, Entity entity, boolean doFullsizeRequests)
51             throws ClassNotFoundException {
52         super(dbClient, entity, Data.class, doFullsizeRequests);
53         this.dbClient = dbClient;
54
55     }
56
57     public QueryResult<Data> getDataStatus() throws IOException {
58         SearchRequest request = getNewInstanceOfSearchRequest(Entity.Faultcurrent);
59         QueryBuilder query = QueryBuilders.matchAllQuery().aggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY).size(0);
60         if(this.doFullsizeRequest) {
61             query.doFullsizeRequest();
62         }
63         request.setQuery(query);
64         SearchResponse response = this.dbClient.search(request);
65         AggregationEntries aggs = response.getAggregations(ESDATATYPE_FAULTCURRENT_SEVERITY_KEY);
66
67         DataBuilder builder = new DataBuilder().setFaults(
68                 new FaultsBuilder().setCriticals(YangHelper2.getLongOrUint32(aggs.getOrDefault("Critical", 0L)))
69                         .setMajors(YangHelper2.getLongOrUint32(aggs.getOrDefault("Major", 0L)))
70                         .setMinors(YangHelper2.getLongOrUint32(aggs.getOrDefault("Minor", 0L)))
71                         .setWarnings(YangHelper2.getLongOrUint32(aggs.getOrDefault("Warning", 0L))).build());
72
73         request = getNewInstanceOfSearchRequest(Entity.NetworkelementConnection);
74         query = QueryBuilders.matchAllQuery().aggregations(ESDATATYPE_NECON_CONNECTIONSTATE_KEY).size(0);
75         if(this.doFullsizeRequest) {
76             query.doFullsizeRequest();
77         }
78         request.setQuery(query);
79         response = this.dbClient.search(request);
80         aggs = response.getAggregations(ESDATATYPE_NECON_CONNECTIONSTATE_KEY);
81         builder.setNetworkElementConnections(new NetworkElementConnectionsBuilder()
82                 .setConnected(Uint32.valueOf(aggs.getOrDefault(ConnectionLogStatus.Connected.getName(), 0L)))
83                 .setConnecting(Uint32.valueOf(aggs.getOrDefault(ConnectionLogStatus.Connecting.getName(), 0L)))
84                 .setDisconnected(Uint32.valueOf(aggs.getOrDefault(ConnectionLogStatus.Disconnected.getName(), 0L)))
85                 .setUnableToConnect(
86                         Uint32.valueOf(aggs.getOrDefault(ConnectionLogStatus.UnableToConnect.getName(), 0L)))
87                 .setMounted(Uint32.valueOf(aggs.getOrDefault(ConnectionLogStatus.Mounted.getName(), 0L)))
88                 .setUnmounted(Uint32.valueOf(aggs.getOrDefault(ConnectionLogStatus.Unmounted.getName(), 0L)))
89                 .setUndefined(Uint32.valueOf(aggs.getOrDefault(ConnectionLogStatus.Undefined.getName(), 0L)))
90                 .setTotal(Uint32.valueOf(response.getTotal())).build());
91
92         long toalsize = 1;
93         return new QueryResult<Data>(1L, 1L, new SearchResult<Data>(new Data[] {builder.build()}, toalsize));
94
95     }
96
97
98     private static SearchRequest getNewInstanceOfSearchRequest(Entity entity) {
99         return new SearchRequest(entity.getName(), entity.getName());
100     }
101
102
103 }