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.
26 package org.openecomp.sparky.dal.rest;
28 import org.openecomp.sparky.analytics.AbstractStatistics;
29 import org.openecomp.sparky.dal.NetworkTransaction;
32 * The Class RestOperationalStatistics.
34 public class RestOperationalStatistics extends AbstractStatistics {
36 private static final String GET_1XX = "GET_1XX";
37 private static final String GET_2XX = "GET_2XX";
38 private static final String GET_3XX = "GET_3XX";
39 private static final String GET_4XX = "GET_4XX";
40 private static final String GET_5XX = "GET_5XX";
41 private static final String GET_6XX = "GET_6XX";
43 private static final String PUT_1XX = "PUT_1XX";
44 private static final String PUT_2XX = "PUT_2XX";
45 private static final String PUT_3XX = "PUT_3XX";
46 private static final String PUT_4XX = "PUT_4XX";
47 private static final String PUT_5XX = "PUT_5XX";
48 private static final String PUT_6XX = "PUT_6XX";
50 private static final String POST_1XX = "POST_1XX";
51 private static final String POST_2XX = "POST_2XX";
52 private static final String POST_3XX = "POST_3XX";
53 private static final String POST_4XX = "POST_4XX";
54 private static final String POST_5XX = "POST_5XX";
55 private static final String POST_6XX = "POST_6XX";
57 private static final String DELETE_1XX = "DELETE_1XX";
58 private static final String DELETE_2XX = "DELETE_2XX";
59 private static final String DELETE_3XX = "DELETE_3XX";
60 private static final String DELETE_4XX = "DELETE_4XX";
61 private static final String DELETE_5XX = "DELETE_5XX";
62 private static final String DELETE_6XX = "DELETE_6XX";
65 * Creates the counters.
67 private void createCounters() {
90 addCounter(DELETE_1XX);
91 addCounter(DELETE_2XX);
92 addCounter(DELETE_3XX);
93 addCounter(DELETE_4XX);
94 addCounter(DELETE_5XX);
95 addCounter(DELETE_6XX);
101 * Gets the result code.
104 * @return the result code
106 private int getResultCode(NetworkTransaction txn) {
112 if (txn.getOperationResult() == null) {
116 return txn.getOperationResult().getResultCode();
125 public void updateCounters(NetworkTransaction txn) {
131 int rc = getResultCode(txn);
133 switch (txn.getOperationType()) {
137 if (100 <= rc && rc <= 199) {
139 } else if (200 <= rc && rc <= 299) {
141 } else if (300 <= rc && rc <= 399) {
143 } else if (400 <= rc && rc <= 499) {
145 } else if (500 <= rc && rc <= 599) {
147 } else if (600 <= rc && rc <= 699) {
156 if (100 <= rc && rc <= 199) {
158 } else if (200 <= rc && rc <= 299) {
160 } else if (300 <= rc && rc <= 399) {
162 } else if (400 <= rc && rc <= 499) {
164 } else if (500 <= rc && rc <= 599) {
166 } else if (600 <= rc && rc <= 699) {
175 if (100 <= rc && rc <= 199) {
176 pegCounter(POST_1XX);
177 } else if (200 <= rc && rc <= 299) {
178 pegCounter(POST_2XX);
179 } else if (300 <= rc && rc <= 399) {
180 pegCounter(POST_3XX);
181 } else if (400 <= rc && rc <= 499) {
182 pegCounter(POST_4XX);
183 } else if (500 <= rc && rc <= 599) {
184 pegCounter(POST_5XX);
185 } else if (600 <= rc && rc <= 699) {
186 pegCounter(POST_6XX);
194 if (100 <= rc && rc <= 199) {
195 pegCounter(DELETE_1XX);
196 } else if (200 <= rc && rc <= 299) {
197 pegCounter(DELETE_2XX);
198 } else if (300 <= rc && rc <= 399) {
199 pegCounter(DELETE_3XX);
200 } else if (400 <= rc && rc <= 499) {
201 pegCounter(DELETE_4XX);
202 } else if (500 <= rc && rc <= 599) {
203 pegCounter(DELETE_5XX);
204 } else if (600 <= rc && rc <= 699) {
205 pegCounter(DELETE_6XX);
212 // not expecting anything else yet
220 * Instantiates a new rest operational statistics.
222 public RestOperationalStatistics() {
226 public String getStatisticsReport() {
228 StringBuilder sb = new StringBuilder(128);
231 .append(String.format(
232 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ",
233 HttpMethod.DELETE, getCounterValue(DELETE_1XX), getCounterValue(DELETE_2XX),
234 getCounterValue(DELETE_3XX), getCounterValue(DELETE_4XX), getCounterValue(DELETE_5XX),
235 getCounterValue(DELETE_6XX)));
237 sb.append("\n ").append(String.format(
238 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.PUT,
239 getCounterValue(PUT_1XX), getCounterValue(PUT_2XX), getCounterValue(PUT_3XX),
240 getCounterValue(PUT_4XX), getCounterValue(PUT_5XX), getCounterValue(PUT_6XX)));
242 sb.append("\n ").append(String.format(
243 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.POST,
244 getCounterValue(POST_1XX), getCounterValue(POST_2XX), getCounterValue(POST_3XX),
245 getCounterValue(POST_4XX), getCounterValue(POST_5XX), getCounterValue(POST_6XX)));
247 sb.append("\n ").append(String.format(
248 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.GET,
249 getCounterValue(GET_1XX), getCounterValue(GET_2XX), getCounterValue(GET_3XX),
250 getCounterValue(GET_4XX), getCounterValue(GET_5XX), getCounterValue(GET_6XX)));
252 return sb.toString();