2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.sal.restconf.impl;
10 import java.math.BigInteger;
11 import java.util.concurrent.atomic.AtomicLong;
12 import javax.ws.rs.core.Response;
13 import javax.ws.rs.core.Response.Status;
14 import javax.ws.rs.core.UriInfo;
15 import org.opendaylight.netconf.sal.rest.api.RestconfService;
17 public class StatisticsRestconfServiceWrapper implements RestconfService {
19 AtomicLong operationalGet = new AtomicLong();
20 AtomicLong configGet = new AtomicLong();
21 AtomicLong rpc = new AtomicLong();
22 AtomicLong configPost = new AtomicLong();
23 AtomicLong configPut = new AtomicLong();
24 AtomicLong configDelete = new AtomicLong();
25 AtomicLong successGetConfig = new AtomicLong();
26 AtomicLong successGetOperational = new AtomicLong();
27 AtomicLong successPost = new AtomicLong();
28 AtomicLong successPut = new AtomicLong();
29 AtomicLong successDelete = new AtomicLong();
30 AtomicLong failureGetConfig = new AtomicLong();
31 AtomicLong failureGetOperational = new AtomicLong();
32 AtomicLong failurePost = new AtomicLong();
33 AtomicLong failurePut = new AtomicLong();
34 AtomicLong failureDelete = new AtomicLong();
36 private static final StatisticsRestconfServiceWrapper INSTANCE =
37 new StatisticsRestconfServiceWrapper(RestconfImpl.getInstance());
39 final RestconfService delegate;
41 private StatisticsRestconfServiceWrapper(final RestconfService delegate) {
42 this.delegate = delegate;
45 public static StatisticsRestconfServiceWrapper getInstance() {
50 public Object getRoot() {
51 return this.delegate.getRoot();
55 public NormalizedNodeContext getModules(final UriInfo uriInfo) {
56 return this.delegate.getModules(uriInfo);
60 public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
61 return this.delegate.getModules(identifier, uriInfo);
65 public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
66 return this.delegate.getModule(identifier, uriInfo);
70 public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
71 return this.delegate.getOperations(uriInfo);
75 public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
76 return this.delegate.getOperations(identifier, uriInfo);
80 public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
81 final UriInfo uriInfo) {
82 this.rpc.incrementAndGet();
83 return this.delegate.invokeRpc(identifier, payload, uriInfo);
87 public NormalizedNodeContext invokeRpc(final String identifier, final String noPayload, final UriInfo uriInfo) {
88 this.rpc.incrementAndGet();
89 return this.delegate.invokeRpc(identifier, noPayload, uriInfo);
92 @SuppressWarnings("checkstyle:IllegalCatch")
94 public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
95 this.configGet.incrementAndGet();
96 NormalizedNodeContext normalizedNodeContext = null;
98 normalizedNodeContext = this.delegate.readConfigurationData(identifier, uriInfo);
99 if (normalizedNodeContext.getData() != null) {
100 this.successGetConfig.incrementAndGet();
102 this.failureGetConfig.incrementAndGet();
104 } catch (final Exception e) {
105 this.failureGetConfig.incrementAndGet();
108 return normalizedNodeContext;
111 @SuppressWarnings("checkstyle:IllegalCatch")
113 public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
114 this.operationalGet.incrementAndGet();
115 NormalizedNodeContext normalizedNodeContext = null;
117 normalizedNodeContext = this.delegate.readOperationalData(identifier, uriInfo);
118 if (normalizedNodeContext.getData() != null) {
119 this.successGetOperational.incrementAndGet();
121 this.failureGetOperational.incrementAndGet();
123 } catch (final Exception e) {
124 this.failureGetOperational.incrementAndGet();
127 return normalizedNodeContext;
130 @SuppressWarnings("checkstyle:IllegalCatch")
132 public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload,
133 final UriInfo uriInfo) {
134 this.configPut.incrementAndGet();
135 Response response = null;
137 response = this.delegate.updateConfigurationData(identifier, payload, uriInfo);
138 if (response.getStatus() == Status.OK.getStatusCode()) {
139 this.successPut.incrementAndGet();
141 this.failurePut.incrementAndGet();
143 } catch (final Exception e) {
144 this.failurePut.incrementAndGet();
150 @SuppressWarnings("checkstyle:IllegalCatch")
152 public Response createConfigurationData(final String identifier, final NormalizedNodeContext payload,
153 final UriInfo uriInfo) {
154 this.configPost.incrementAndGet();
155 Response response = null;
157 response = this.delegate.createConfigurationData(identifier, payload, uriInfo);
158 if (response.getStatus() == Status.OK.getStatusCode()) {
159 this.successPost.incrementAndGet();
161 this.failurePost.incrementAndGet();
163 } catch (final Exception e) {
164 this.failurePost.incrementAndGet();
170 @SuppressWarnings("checkstyle:IllegalCatch")
172 public Response createConfigurationData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
173 this.configPost.incrementAndGet();
174 Response response = null;
176 response = this.delegate.createConfigurationData(payload, uriInfo);
177 if (response.getStatus() == Status.OK.getStatusCode()) {
178 this.successPost.incrementAndGet();
180 this.failurePost.incrementAndGet();
182 } catch (final Exception e) {
183 this.failurePost.incrementAndGet();
189 @SuppressWarnings("checkstyle:IllegalCatch")
191 public Response deleteConfigurationData(final String identifier) {
192 this.configDelete.incrementAndGet();
193 Response response = null;
195 response = this.delegate.deleteConfigurationData(identifier);
196 if (response.getStatus() == Status.OK.getStatusCode()) {
197 this.successDelete.incrementAndGet();
199 this.failureDelete.incrementAndGet();
201 } catch (final Exception e) {
202 this.failureDelete.incrementAndGet();
209 public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
210 return this.delegate.subscribeToStream(identifier, uriInfo);
214 public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
215 return this.delegate.getAvailableStreams(uriInfo);
219 public PatchStatusContext patchConfigurationData(final String identifier, final PatchContext payload,
220 final UriInfo uriInfo) {
221 return this.delegate.patchConfigurationData(identifier, payload, uriInfo);
225 public PatchStatusContext patchConfigurationData(final PatchContext payload, final UriInfo uriInfo) {
226 return this.delegate.patchConfigurationData(payload, uriInfo);
229 public BigInteger getConfigDelete() {
230 return BigInteger.valueOf(this.configDelete.get());
233 public BigInteger getConfigGet() {
234 return BigInteger.valueOf(this.configGet.get());
237 public BigInteger getConfigPost() {
238 return BigInteger.valueOf(this.configPost.get());
241 public BigInteger getConfigPut() {
242 return BigInteger.valueOf(this.configPut.get());
245 public BigInteger getOperationalGet() {
246 return BigInteger.valueOf(this.operationalGet.get());
249 public BigInteger getRpc() {
250 return BigInteger.valueOf(this.rpc.get());
253 public BigInteger getSuccessGetConfig() {
254 return BigInteger.valueOf(this.successGetConfig.get());
257 public BigInteger getSuccessGetOperational() {
258 return BigInteger.valueOf(this.successGetOperational.get());
261 public BigInteger getSuccessPost() {
262 return BigInteger.valueOf(this.successPost.get());
265 public BigInteger getSuccessPut() {
266 return BigInteger.valueOf(this.successPut.get());
269 public BigInteger getSuccessDelete() {
270 return BigInteger.valueOf(this.successDelete.get());
273 public BigInteger getFailureGetConfig() {
274 return BigInteger.valueOf(this.failureGetConfig.get());
277 public BigInteger getFailureGetOperational() {
278 return BigInteger.valueOf(this.failureGetOperational.get());
281 public BigInteger getFailurePost() {
282 return BigInteger.valueOf(this.failurePost.get());
285 public BigInteger getFailurePut() {
286 return BigInteger.valueOf(this.failurePut.get());
289 public BigInteger getFailureDelete() {
290 return BigInteger.valueOf(this.failureDelete.get());