2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.sparky.dal.rest;
27 import org.onap.aai.sparky.analytics.AbstractStatistics;
28 import org.onap.aai.sparky.dal.NetworkTransaction;
31 * The Class RestOperationalStatistics.
33 public class RestOperationalStatistics extends AbstractStatistics {
35 private static final String GET_1XX = "GET_1XX";
36 private static final String GET_2XX = "GET_2XX";
37 private static final String GET_3XX = "GET_3XX";
38 private static final String GET_4XX = "GET_4XX";
39 private static final String GET_5XX = "GET_5XX";
40 private static final String GET_6XX = "GET_6XX";
42 private static final String PUT_1XX = "PUT_1XX";
43 private static final String PUT_2XX = "PUT_2XX";
44 private static final String PUT_3XX = "PUT_3XX";
45 private static final String PUT_4XX = "PUT_4XX";
46 private static final String PUT_5XX = "PUT_5XX";
47 private static final String PUT_6XX = "PUT_6XX";
49 private static final String POST_1XX = "POST_1XX";
50 private static final String POST_2XX = "POST_2XX";
51 private static final String POST_3XX = "POST_3XX";
52 private static final String POST_4XX = "POST_4XX";
53 private static final String POST_5XX = "POST_5XX";
54 private static final String POST_6XX = "POST_6XX";
56 private static final String DELETE_1XX = "DELETE_1XX";
57 private static final String DELETE_2XX = "DELETE_2XX";
58 private static final String DELETE_3XX = "DELETE_3XX";
59 private static final String DELETE_4XX = "DELETE_4XX";
60 private static final String DELETE_5XX = "DELETE_5XX";
61 private static final String DELETE_6XX = "DELETE_6XX";
64 * Creates the counters.
66 private void createCounters() {
89 addCounter(DELETE_1XX);
90 addCounter(DELETE_2XX);
91 addCounter(DELETE_3XX);
92 addCounter(DELETE_4XX);
93 addCounter(DELETE_5XX);
94 addCounter(DELETE_6XX);
100 * Gets the result code.
103 * @return the result code
105 private int getResultCode(NetworkTransaction txn) {
111 if (txn.getOperationResult() == null) {
115 return txn.getOperationResult().getResultCode();
124 public void updateCounters(NetworkTransaction txn) {
130 int rc = getResultCode(txn);
132 switch (txn.getOperationType()) {
136 if (100 <= rc && rc <= 199) {
138 } else if (200 <= rc && rc <= 299) {
140 } else if (300 <= rc && rc <= 399) {
142 } else if (400 <= rc && rc <= 499) {
144 } else if (500 <= rc && rc <= 599) {
146 } else if (600 <= rc && rc <= 699) {
155 if (100 <= rc && rc <= 199) {
157 } else if (200 <= rc && rc <= 299) {
159 } else if (300 <= rc && rc <= 399) {
161 } else if (400 <= rc && rc <= 499) {
163 } else if (500 <= rc && rc <= 599) {
165 } else if (600 <= rc && rc <= 699) {
174 if (100 <= rc && rc <= 199) {
175 pegCounter(POST_1XX);
176 } else if (200 <= rc && rc <= 299) {
177 pegCounter(POST_2XX);
178 } else if (300 <= rc && rc <= 399) {
179 pegCounter(POST_3XX);
180 } else if (400 <= rc && rc <= 499) {
181 pegCounter(POST_4XX);
182 } else if (500 <= rc && rc <= 599) {
183 pegCounter(POST_5XX);
184 } else if (600 <= rc && rc <= 699) {
185 pegCounter(POST_6XX);
193 if (100 <= rc && rc <= 199) {
194 pegCounter(DELETE_1XX);
195 } else if (200 <= rc && rc <= 299) {
196 pegCounter(DELETE_2XX);
197 } else if (300 <= rc && rc <= 399) {
198 pegCounter(DELETE_3XX);
199 } else if (400 <= rc && rc <= 499) {
200 pegCounter(DELETE_4XX);
201 } else if (500 <= rc && rc <= 599) {
202 pegCounter(DELETE_5XX);
203 } else if (600 <= rc && rc <= 699) {
204 pegCounter(DELETE_6XX);
211 // not expecting anything else yet
219 * Instantiates a new rest operational statistics.
221 public RestOperationalStatistics() {
225 public String getStatisticsReport() {
227 StringBuilder sb = new StringBuilder(128);
230 .append(String.format(
231 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ",
232 HttpMethod.DELETE, getCounterValue(DELETE_1XX), getCounterValue(DELETE_2XX),
233 getCounterValue(DELETE_3XX), getCounterValue(DELETE_4XX), getCounterValue(DELETE_5XX),
234 getCounterValue(DELETE_6XX)));
236 sb.append("\n ").append(String.format(
237 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.PUT,
238 getCounterValue(PUT_1XX), getCounterValue(PUT_2XX), getCounterValue(PUT_3XX),
239 getCounterValue(PUT_4XX), getCounterValue(PUT_5XX), getCounterValue(PUT_6XX)));
241 sb.append("\n ").append(String.format(
242 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.POST,
243 getCounterValue(POST_1XX), getCounterValue(POST_2XX), getCounterValue(POST_3XX),
244 getCounterValue(POST_4XX), getCounterValue(POST_5XX), getCounterValue(POST_6XX)));
246 sb.append("\n ").append(String.format(
247 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.GET,
248 getCounterValue(GET_1XX), getCounterValue(GET_2XX), getCounterValue(GET_3XX),
249 getCounterValue(GET_4XX), getCounterValue(GET_5XX), getCounterValue(GET_6XX)));
251 return sb.toString();