2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
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=========================================================
21 package org.onap.aai.sparky.dal.rest;
23 import org.onap.aai.sparky.analytics.AbstractStatistics;
24 import org.onap.aai.sparky.dal.NetworkTransaction;
27 * The Class RestOperationalStatistics.
29 public class RestOperationalStatistics extends AbstractStatistics {
31 private static final String GET_1XX = "GET_1XX";
32 private static final String GET_2XX = "GET_2XX";
33 private static final String GET_3XX = "GET_3XX";
34 private static final String GET_4XX = "GET_4XX";
35 private static final String GET_5XX = "GET_5XX";
36 private static final String GET_6XX = "GET_6XX";
38 private static final String PUT_1XX = "PUT_1XX";
39 private static final String PUT_2XX = "PUT_2XX";
40 private static final String PUT_3XX = "PUT_3XX";
41 private static final String PUT_4XX = "PUT_4XX";
42 private static final String PUT_5XX = "PUT_5XX";
43 private static final String PUT_6XX = "PUT_6XX";
45 private static final String POST_1XX = "POST_1XX";
46 private static final String POST_2XX = "POST_2XX";
47 private static final String POST_3XX = "POST_3XX";
48 private static final String POST_4XX = "POST_4XX";
49 private static final String POST_5XX = "POST_5XX";
50 private static final String POST_6XX = "POST_6XX";
52 private static final String DELETE_1XX = "DELETE_1XX";
53 private static final String DELETE_2XX = "DELETE_2XX";
54 private static final String DELETE_3XX = "DELETE_3XX";
55 private static final String DELETE_4XX = "DELETE_4XX";
56 private static final String DELETE_5XX = "DELETE_5XX";
57 private static final String DELETE_6XX = "DELETE_6XX";
60 * Creates the counters.
62 private void createCounters() {
85 addCounter(DELETE_1XX);
86 addCounter(DELETE_2XX);
87 addCounter(DELETE_3XX);
88 addCounter(DELETE_4XX);
89 addCounter(DELETE_5XX);
90 addCounter(DELETE_6XX);
96 * Gets the result code.
99 * @return the result code
101 private int getResultCode(NetworkTransaction txn) {
107 if (txn.getOperationResult() == null) {
111 return txn.getOperationResult().getResultCode();
120 public void updateCounters(NetworkTransaction txn) {
126 int rc = getResultCode(txn);
128 switch (txn.getOperationType()) {
132 if (100 <= rc && rc <= 199) {
134 } else if (200 <= rc && rc <= 299) {
136 } else if (300 <= rc && rc <= 399) {
138 } else if (400 <= rc && rc <= 499) {
140 } else if (500 <= rc && rc <= 599) {
142 } else if (600 <= rc && rc <= 699) {
151 if (100 <= rc && rc <= 199) {
153 } else if (200 <= rc && rc <= 299) {
155 } else if (300 <= rc && rc <= 399) {
157 } else if (400 <= rc && rc <= 499) {
159 } else if (500 <= rc && rc <= 599) {
161 } else if (600 <= rc && rc <= 699) {
170 if (100 <= rc && rc <= 199) {
171 pegCounter(POST_1XX);
172 } else if (200 <= rc && rc <= 299) {
173 pegCounter(POST_2XX);
174 } else if (300 <= rc && rc <= 399) {
175 pegCounter(POST_3XX);
176 } else if (400 <= rc && rc <= 499) {
177 pegCounter(POST_4XX);
178 } else if (500 <= rc && rc <= 599) {
179 pegCounter(POST_5XX);
180 } else if (600 <= rc && rc <= 699) {
181 pegCounter(POST_6XX);
189 if (100 <= rc && rc <= 199) {
190 pegCounter(DELETE_1XX);
191 } else if (200 <= rc && rc <= 299) {
192 pegCounter(DELETE_2XX);
193 } else if (300 <= rc && rc <= 399) {
194 pegCounter(DELETE_3XX);
195 } else if (400 <= rc && rc <= 499) {
196 pegCounter(DELETE_4XX);
197 } else if (500 <= rc && rc <= 599) {
198 pegCounter(DELETE_5XX);
199 } else if (600 <= rc && rc <= 699) {
200 pegCounter(DELETE_6XX);
207 // not expecting anything else yet
215 * Instantiates a new rest operational statistics.
217 public RestOperationalStatistics() {
221 public String getStatisticsReport() {
223 StringBuilder sb = new StringBuilder(128);
226 .append(String.format(
227 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ",
228 HttpMethod.DELETE, getCounterValue(DELETE_1XX), getCounterValue(DELETE_2XX),
229 getCounterValue(DELETE_3XX), getCounterValue(DELETE_4XX), getCounterValue(DELETE_5XX),
230 getCounterValue(DELETE_6XX)));
232 sb.append("\n ").append(String.format(
233 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.PUT,
234 getCounterValue(PUT_1XX), getCounterValue(PUT_2XX), getCounterValue(PUT_3XX),
235 getCounterValue(PUT_4XX), getCounterValue(PUT_5XX), getCounterValue(PUT_6XX)));
237 sb.append("\n ").append(String.format(
238 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.POST,
239 getCounterValue(POST_1XX), getCounterValue(POST_2XX), getCounterValue(POST_3XX),
240 getCounterValue(POST_4XX), getCounterValue(POST_5XX), getCounterValue(POST_6XX)));
242 sb.append("\n ").append(String.format(
243 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.GET,
244 getCounterValue(GET_1XX), getCounterValue(GET_2XX), getCounterValue(GET_3XX),
245 getCounterValue(GET_4XX), getCounterValue(GET_5XX), getCounterValue(GET_6XX)));
247 return sb.toString();