afc4eedb2c9d7b495c3f31e554da49b51f9298cf
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / restconf / impl / StatisticsRestconfServiceWrapper.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.sal.restconf.impl;
9
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;
16 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
17
18 public class StatisticsRestconfServiceWrapper implements RestconfService {
19
20     AtomicLong operationalGet = new AtomicLong();
21     AtomicLong configGet = new AtomicLong();
22     AtomicLong rpc = new AtomicLong();
23     AtomicLong configPost = new AtomicLong();
24     AtomicLong configPut = new AtomicLong();
25     AtomicLong configDelete = new AtomicLong();
26     AtomicLong successGetConfig = new AtomicLong();
27     AtomicLong successGetOperational = new AtomicLong();
28     AtomicLong successPost = new AtomicLong();
29     AtomicLong successPut = new AtomicLong();
30     AtomicLong successDelete = new AtomicLong();
31     AtomicLong failureGetConfig = new AtomicLong();
32     AtomicLong failureGetOperational = new AtomicLong();
33     AtomicLong failurePost = new AtomicLong();
34     AtomicLong failurePut = new AtomicLong();
35     AtomicLong failureDelete = new AtomicLong();
36
37     private static final StatisticsRestconfServiceWrapper INSTANCE =
38             new StatisticsRestconfServiceWrapper(RestconfImpl.getInstance());
39
40     final RestconfService delegate;
41
42     private StatisticsRestconfServiceWrapper(final RestconfService delegate) {
43         this.delegate = delegate;
44     }
45
46     public static StatisticsRestconfServiceWrapper getInstance() {
47         return INSTANCE;
48     }
49
50     @Override
51     public Object getRoot() {
52         return this.delegate.getRoot();
53     }
54
55     @Override
56     public NormalizedNodeContext getModules(final UriInfo uriInfo) {
57         return this.delegate.getModules(uriInfo);
58     }
59
60     @Override
61     public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
62         return this.delegate.getModules(identifier, uriInfo);
63     }
64
65     @Override
66     public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
67         return this.delegate.getModule(identifier, uriInfo);
68     }
69
70     @Override
71     public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
72         return this.delegate.getOperations(uriInfo);
73     }
74
75     @Override
76     public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
77         return this.delegate.getOperations(identifier, uriInfo);
78     }
79
80     @Override
81     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
82             final UriInfo uriInfo) {
83         this.rpc.incrementAndGet();
84         return this.delegate.invokeRpc(identifier, payload, uriInfo);
85     }
86
87     @Override
88     public NormalizedNodeContext invokeRpc(final String identifier, final String noPayload, final UriInfo uriInfo) {
89         this.rpc.incrementAndGet();
90         return this.delegate.invokeRpc(identifier, noPayload, uriInfo);
91     }
92
93     @SuppressWarnings("checkstyle:IllegalCatch")
94     @Override
95     public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
96         this.configGet.incrementAndGet();
97         NormalizedNodeContext normalizedNodeContext = null;
98         try {
99             normalizedNodeContext = this.delegate.readConfigurationData(identifier, uriInfo);
100             if (normalizedNodeContext.getData() != null) {
101                 this.successGetConfig.incrementAndGet();
102             } else {
103                 this.failureGetConfig.incrementAndGet();
104             }
105         } catch (final Exception e) {
106             this.failureGetConfig.incrementAndGet();
107             throw e;
108         }
109         return normalizedNodeContext;
110     }
111
112     @SuppressWarnings("checkstyle:IllegalCatch")
113     @Override
114     public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
115         this.operationalGet.incrementAndGet();
116         NormalizedNodeContext normalizedNodeContext = null;
117         try {
118             normalizedNodeContext = this.delegate.readOperationalData(identifier, uriInfo);
119             if (normalizedNodeContext.getData() != null) {
120                 this.successGetOperational.incrementAndGet();
121             } else {
122                 this.failureGetOperational.incrementAndGet();
123             }
124         } catch (final Exception e) {
125             this.failureGetOperational.incrementAndGet();
126             throw e;
127         }
128         return normalizedNodeContext;
129     }
130
131     @SuppressWarnings("checkstyle:IllegalCatch")
132     @Override
133     public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload,
134             final UriInfo uriInfo) {
135         this.configPut.incrementAndGet();
136         Response response = null;
137         try {
138             response = this.delegate.updateConfigurationData(identifier, payload, uriInfo);
139             if (response.getStatus() == Status.OK.getStatusCode()) {
140                 this.successPut.incrementAndGet();
141             } else {
142                 this.failurePut.incrementAndGet();
143             }
144         } catch (final Exception e) {
145             this.failurePut.incrementAndGet();
146             throw e;
147         }
148         return response;
149     }
150
151     @SuppressWarnings("checkstyle:IllegalCatch")
152     @Override
153     public Response createConfigurationData(final String identifier, final NormalizedNodeContext payload,
154             final UriInfo uriInfo) {
155         this.configPost.incrementAndGet();
156         Response response = null;
157         try {
158             response = this.delegate.createConfigurationData(identifier, payload, uriInfo);
159             if (response.getStatus() == Status.OK.getStatusCode()) {
160                 this.successPost.incrementAndGet();
161             } else {
162                 this.failurePost.incrementAndGet();
163             }
164         } catch (final Exception e) {
165             this.failurePost.incrementAndGet();
166             throw e;
167         }
168         return response;
169     }
170
171     @SuppressWarnings("checkstyle:IllegalCatch")
172     @Override
173     public Response createConfigurationData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
174         this.configPost.incrementAndGet();
175         Response response = null;
176         try {
177             response = this.delegate.createConfigurationData(payload, uriInfo);
178             if (response.getStatus() == Status.OK.getStatusCode()) {
179                 this.successPost.incrementAndGet();
180             } else {
181                 this.failurePost.incrementAndGet();
182             }
183         } catch (final Exception e) {
184             this.failurePost.incrementAndGet();
185             throw e;
186         }
187         return response;
188     }
189
190     @SuppressWarnings("checkstyle:IllegalCatch")
191     @Override
192     public Response deleteConfigurationData(final String identifier) {
193         this.configDelete.incrementAndGet();
194         Response response = null;
195         try {
196             response = this.delegate.deleteConfigurationData(identifier);
197             if (response.getStatus() == Status.OK.getStatusCode()) {
198                 this.successDelete.incrementAndGet();
199             } else {
200                 this.failureDelete.incrementAndGet();
201             }
202         } catch (final Exception e) {
203             this.failureDelete.incrementAndGet();
204             throw e;
205         }
206         return response;
207     }
208
209     @Override
210     public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
211         return this.delegate.subscribeToStream(identifier, uriInfo);
212     }
213
214     @Override
215     public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
216         return this.delegate.getAvailableStreams(uriInfo);
217     }
218
219     @Override
220     public PatchStatusContext patchConfigurationData(final String identifier, final PatchContext payload,
221                                                      final UriInfo uriInfo) {
222         return this.delegate.patchConfigurationData(identifier, payload, uriInfo);
223     }
224
225     @Override
226     public PatchStatusContext patchConfigurationData(final PatchContext payload, final UriInfo uriInfo) {
227         return this.delegate.patchConfigurationData(payload, uriInfo);
228     }
229
230     public BigInteger getConfigDelete() {
231         return BigInteger.valueOf(this.configDelete.get());
232     }
233
234     public BigInteger getConfigGet() {
235         return BigInteger.valueOf(this.configGet.get());
236     }
237
238     public BigInteger getConfigPost() {
239         return BigInteger.valueOf(this.configPost.get());
240     }
241
242     public BigInteger getConfigPut() {
243         return BigInteger.valueOf(this.configPut.get());
244     }
245
246     public BigInteger getOperationalGet() {
247         return BigInteger.valueOf(this.operationalGet.get());
248     }
249
250     public BigInteger getRpc() {
251         return BigInteger.valueOf(this.rpc.get());
252     }
253
254     public BigInteger getSuccessGetConfig() {
255         return BigInteger.valueOf(this.successGetConfig.get());
256     }
257
258     public BigInteger getSuccessGetOperational() {
259         return BigInteger.valueOf(this.successGetOperational.get());
260     }
261
262     public BigInteger getSuccessPost() {
263         return BigInteger.valueOf(this.successPost.get());
264     }
265
266     public BigInteger getSuccessPut() {
267         return BigInteger.valueOf(this.successPut.get());
268     }
269
270     public BigInteger getSuccessDelete() {
271         return BigInteger.valueOf(this.successDelete.get());
272     }
273
274     public BigInteger getFailureGetConfig() {
275         return BigInteger.valueOf(this.failureGetConfig.get());
276     }
277
278     public BigInteger getFailureGetOperational() {
279         return BigInteger.valueOf(this.failureGetOperational.get());
280     }
281
282     public BigInteger getFailurePost() {
283         return BigInteger.valueOf(this.failurePost.get());
284     }
285
286     public BigInteger getFailurePut() {
287         return BigInteger.valueOf(this.failurePut.get());
288     }
289
290     public BigInteger getFailureDelete() {
291         return BigInteger.valueOf(this.failureDelete.get());
292     }
293 }