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.aai;
28 import org.openecomp.cl.api.Logger;
29 import org.openecomp.cl.eelf.LoggerFactory;
30 import org.openecomp.sparky.analytics.AbstractStatistics;
31 import org.openecomp.sparky.dal.NetworkTransaction;
32 import org.openecomp.sparky.dal.rest.OperationResult;
33 import org.openecomp.sparky.logging.AaiUiMsgs;
36 * The Class ActiveInventoryProcessingExceptionStatistics.
38 public class ActiveInventoryProcessingExceptionStatistics extends AbstractStatistics {
40 private static final Logger LOG =
41 LoggerFactory.getInstance().getLogger(ActiveInventoryAdapter.class);
43 private static final String NATIVE_SOCKET_CONNECT_EXCEPTION = "NativeSocketConnectException";
44 private static final String NATIVE_SOCKET_CONNECTION_RESET = "NativeSocketConnectionReset";
45 private static final String NATIVE_SOCKET_CONNECTION_REFUSED = "NativeSocketConnectionRefused";
46 private static final String CLIENT_TIMEOUT_EXCEPTION = "JerseyClientTimoutException";
47 private static final String UNKNOWN_EXCEPTION = "UnknownException";
50 * Creates the counters.
52 private void createCounters() {
53 addCounter(NATIVE_SOCKET_CONNECT_EXCEPTION);
54 addCounter(NATIVE_SOCKET_CONNECTION_RESET);
55 addCounter(NATIVE_SOCKET_CONNECTION_REFUSED);
56 addCounter(CLIENT_TIMEOUT_EXCEPTION);
57 addCounter(UNKNOWN_EXCEPTION);
61 * Instantiates a new active inventory processing exception statistics.
63 public ActiveInventoryProcessingExceptionStatistics() {
73 public void updateCounters(NetworkTransaction txn) {
79 OperationResult or = txn.getOperationResult();
81 if (or != null && !or.wasSuccessful()) {
83 if (or.getResultCode() != 404) {
85 String result = or.getResult();
90 * Try to classify exceptions and peg counters
93 if (result.contains("java.net.SocketTimeoutException: connect timed out")) {
94 pegCounter(CLIENT_TIMEOUT_EXCEPTION);
95 } else if (result.contains("java.net.ConnectException: Connection timed out: connect")) {
96 pegCounter(NATIVE_SOCKET_CONNECT_EXCEPTION);
97 } else if (result.contains("java.net.ConnectException: Connection refused: connect")) {
98 pegCounter(NATIVE_SOCKET_CONNECTION_REFUSED);
99 } else if (result.contains("java.net.SocketException: Connection reset")) {
100 pegCounter(NATIVE_SOCKET_CONNECTION_RESET);
102 pegCounter(UNKNOWN_EXCEPTION);
103 LOG.error(AaiUiMsgs.PEGGING_ERROR, result.toString());
113 public String getStatisticsReport() {
115 StringBuilder sb = new StringBuilder(128);
117 int nativeConnect = getCounterValue(NATIVE_SOCKET_CONNECT_EXCEPTION);
118 int nativeCxnReset = getCounterValue(NATIVE_SOCKET_CONNECTION_RESET);
119 int nativeCxnRefused = getCounterValue(NATIVE_SOCKET_CONNECTION_REFUSED);
120 int clientTimeout = getCounterValue(CLIENT_TIMEOUT_EXCEPTION);
121 int unknown = getCounterValue(UNKNOWN_EXCEPTION);
124 .append(String.format("%-40s: %-12d", NATIVE_SOCKET_CONNECT_EXCEPTION, nativeConnect));
126 .append(String.format("%-40s: %-12d", NATIVE_SOCKET_CONNECTION_RESET, nativeCxnReset));
128 .append(String.format("%-40s: %-12d", NATIVE_SOCKET_CONNECTION_REFUSED, nativeCxnRefused));
130 .append(String.format("%-40s: %-12d", CLIENT_TIMEOUT_EXCEPTION, clientTimeout));
131 sb.append("\n ").append(String.format("%-40s: %-12d", UNKNOWN_EXCEPTION, unknown));
133 return sb.toString();