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