2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.sparky.dal.rest;
25 import org.openecomp.sparky.analytics.AbstractStatistics;
26 import org.openecomp.sparky.dal.NetworkTransaction;
29 * The Class RestOperationalStatistics.
31 public class RestOperationalStatistics extends AbstractStatistics {
33 private static final String GET_1XX = "GET_1XX";
34 private static final String GET_2XX = "GET_2XX";
35 private static final String GET_3XX = "GET_3XX";
36 private static final String GET_4XX = "GET_4XX";
37 private static final String GET_5XX = "GET_5XX";
38 private static final String GET_6XX = "GET_6XX";
40 private static final String PUT_1XX = "PUT_1XX";
41 private static final String PUT_2XX = "PUT_2XX";
42 private static final String PUT_3XX = "PUT_3XX";
43 private static final String PUT_4XX = "PUT_4XX";
44 private static final String PUT_5XX = "PUT_5XX";
45 private static final String PUT_6XX = "PUT_6XX";
47 private static final String POST_1XX = "POST_1XX";
48 private static final String POST_2XX = "POST_2XX";
49 private static final String POST_3XX = "POST_3XX";
50 private static final String POST_4XX = "POST_4XX";
51 private static final String POST_5XX = "POST_5XX";
52 private static final String POST_6XX = "POST_6XX";
54 private static final String DELETE_1XX = "DELETE_1XX";
55 private static final String DELETE_2XX = "DELETE_2XX";
56 private static final String DELETE_3XX = "DELETE_3XX";
57 private static final String DELETE_4XX = "DELETE_4XX";
58 private static final String DELETE_5XX = "DELETE_5XX";
59 private static final String DELETE_6XX = "DELETE_6XX";
62 * Creates the counters.
64 private void createCounters() {
87 addCounter(DELETE_1XX);
88 addCounter(DELETE_2XX);
89 addCounter(DELETE_3XX);
90 addCounter(DELETE_4XX);
91 addCounter(DELETE_5XX);
92 addCounter(DELETE_6XX);
98 * Gets the result code.
101 * @return the result code
103 private int getResultCode(NetworkTransaction txn) {
109 if (txn.getOperationResult() == null) {
113 return txn.getOperationResult().getResultCode();
122 public void updateCounters(NetworkTransaction txn) {
128 int rc = getResultCode(txn);
130 switch (txn.getOperationType()) {
134 if (100 <= rc && rc <= 199) {
136 } else if (200 <= rc && rc <= 299) {
138 } else if (300 <= rc && rc <= 399) {
140 } else if (400 <= rc && rc <= 499) {
142 } else if (500 <= rc && rc <= 599) {
144 } else if (600 <= rc && rc <= 699) {
153 if (100 <= rc && rc <= 199) {
155 } else if (200 <= rc && rc <= 299) {
157 } else if (300 <= rc && rc <= 399) {
159 } else if (400 <= rc && rc <= 499) {
161 } else if (500 <= rc && rc <= 599) {
163 } else if (600 <= rc && rc <= 699) {
172 if (100 <= rc && rc <= 199) {
173 pegCounter(POST_1XX);
174 } else if (200 <= rc && rc <= 299) {
175 pegCounter(POST_2XX);
176 } else if (300 <= rc && rc <= 399) {
177 pegCounter(POST_3XX);
178 } else if (400 <= rc && rc <= 499) {
179 pegCounter(POST_4XX);
180 } else if (500 <= rc && rc <= 599) {
181 pegCounter(POST_5XX);
182 } else if (600 <= rc && rc <= 699) {
183 pegCounter(POST_6XX);
191 if (100 <= rc && rc <= 199) {
192 pegCounter(DELETE_1XX);
193 } else if (200 <= rc && rc <= 299) {
194 pegCounter(DELETE_2XX);
195 } else if (300 <= rc && rc <= 399) {
196 pegCounter(DELETE_3XX);
197 } else if (400 <= rc && rc <= 499) {
198 pegCounter(DELETE_4XX);
199 } else if (500 <= rc && rc <= 599) {
200 pegCounter(DELETE_5XX);
201 } else if (600 <= rc && rc <= 699) {
202 pegCounter(DELETE_6XX);
209 // not expecting anything else yet
217 * Instantiates a new rest operational statistics.
219 public RestOperationalStatistics() {
223 public String getStatisticsReport() {
225 StringBuilder sb = new StringBuilder(128);
228 .append(String.format(
229 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ",
230 HttpMethod.DELETE, getCounterValue(DELETE_1XX), getCounterValue(DELETE_2XX),
231 getCounterValue(DELETE_3XX), getCounterValue(DELETE_4XX), getCounterValue(DELETE_5XX),
232 getCounterValue(DELETE_6XX)));
234 sb.append("\n ").append(String.format(
235 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.PUT,
236 getCounterValue(PUT_1XX), getCounterValue(PUT_2XX), getCounterValue(PUT_3XX),
237 getCounterValue(PUT_4XX), getCounterValue(PUT_5XX), getCounterValue(PUT_6XX)));
239 sb.append("\n ").append(String.format(
240 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.POST,
241 getCounterValue(POST_1XX), getCounterValue(POST_2XX), getCounterValue(POST_3XX),
242 getCounterValue(POST_4XX), getCounterValue(POST_5XX), getCounterValue(POST_6XX)));
244 sb.append("\n ").append(String.format(
245 "%-12s 1XX: %-12d 2XX: %-12d 3XX: %-12d 4XX: %-12d 5XX: %-12d 6XX: %-12d ", HttpMethod.GET,
246 getCounterValue(GET_1XX), getCounterValue(GET_2XX), getCounterValue(GET_3XX),
247 getCounterValue(GET_4XX), getCounterValue(GET_5XX), getCounterValue(GET_6XX)));
249 return sb.toString();