afe4be00e8f96c4506afae0e5b5ef661eec4c3c6
[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.netconf.sal.rest.impl.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 String getOperationsJSON() {
81         return this.delegate.getOperationsJSON();
82     }
83
84     @Override
85     public String getOperationsXML() {
86         return this.delegate.getOperationsXML();
87     }
88
89     @Override
90     public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
91         return this.delegate.getOperations(identifier, uriInfo);
92     }
93
94     @Override
95     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
96             final UriInfo uriInfo) {
97         this.rpc.incrementAndGet();
98         return this.delegate.invokeRpc(identifier, payload, uriInfo);
99     }
100
101     @SuppressWarnings("checkstyle:IllegalCatch")
102     @Override
103     public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
104         this.configGet.incrementAndGet();
105         NormalizedNodeContext normalizedNodeContext = null;
106         try {
107             normalizedNodeContext = this.delegate.readConfigurationData(identifier, uriInfo);
108             if (normalizedNodeContext.getData() != null) {
109                 this.successGetConfig.incrementAndGet();
110             } else {
111                 this.failureGetConfig.incrementAndGet();
112             }
113         } catch (final Exception e) {
114             this.failureGetConfig.incrementAndGet();
115             throw e;
116         }
117         return normalizedNodeContext;
118     }
119
120     @SuppressWarnings("checkstyle:IllegalCatch")
121     @Override
122     public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
123         this.operationalGet.incrementAndGet();
124         NormalizedNodeContext normalizedNodeContext = null;
125         try {
126             normalizedNodeContext = this.delegate.readOperationalData(identifier, uriInfo);
127             if (normalizedNodeContext.getData() != null) {
128                 this.successGetOperational.incrementAndGet();
129             } else {
130                 this.failureGetOperational.incrementAndGet();
131             }
132         } catch (final Exception e) {
133             this.failureGetOperational.incrementAndGet();
134             throw e;
135         }
136         return normalizedNodeContext;
137     }
138
139     @SuppressWarnings("checkstyle:IllegalCatch")
140     @Override
141     public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload,
142             final UriInfo uriInfo) {
143         this.configPut.incrementAndGet();
144         Response response = null;
145         try {
146             response = this.delegate.updateConfigurationData(identifier, payload, uriInfo);
147             if (response.getStatus() == Status.OK.getStatusCode()) {
148                 this.successPut.incrementAndGet();
149             } else {
150                 this.failurePut.incrementAndGet();
151             }
152         } catch (final Exception e) {
153             this.failurePut.incrementAndGet();
154             throw e;
155         }
156         return response;
157     }
158
159     @SuppressWarnings("checkstyle:IllegalCatch")
160     @Override
161     public Response createConfigurationData(final String identifier, final NormalizedNodeContext payload,
162             final UriInfo uriInfo) {
163         this.configPost.incrementAndGet();
164         Response response = null;
165         try {
166             response = this.delegate.createConfigurationData(identifier, payload, uriInfo);
167             if (response.getStatus() == Status.OK.getStatusCode()) {
168                 this.successPost.incrementAndGet();
169             } else {
170                 this.failurePost.incrementAndGet();
171             }
172         } catch (final Exception e) {
173             this.failurePost.incrementAndGet();
174             throw e;
175         }
176         return response;
177     }
178
179     @SuppressWarnings("checkstyle:IllegalCatch")
180     @Override
181     public Response createConfigurationData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
182         this.configPost.incrementAndGet();
183         Response response = null;
184         try {
185             response = this.delegate.createConfigurationData(payload, uriInfo);
186             if (response.getStatus() == Status.OK.getStatusCode()) {
187                 this.successPost.incrementAndGet();
188             } else {
189                 this.failurePost.incrementAndGet();
190             }
191         } catch (final Exception e) {
192             this.failurePost.incrementAndGet();
193             throw e;
194         }
195         return response;
196     }
197
198     @SuppressWarnings("checkstyle:IllegalCatch")
199     @Override
200     public Response deleteConfigurationData(final String identifier) {
201         this.configDelete.incrementAndGet();
202         Response response = null;
203         try {
204             response = this.delegate.deleteConfigurationData(identifier);
205             if (response.getStatus() == Status.OK.getStatusCode()) {
206                 this.successDelete.incrementAndGet();
207             } else {
208                 this.failureDelete.incrementAndGet();
209             }
210         } catch (final Exception e) {
211             this.failureDelete.incrementAndGet();
212             throw e;
213         }
214         return response;
215     }
216
217     @Override
218     public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
219         return this.delegate.subscribeToStream(identifier, uriInfo);
220     }
221
222     @Override
223     public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
224         return this.delegate.getAvailableStreams(uriInfo);
225     }
226
227     @Override
228     public PatchStatusContext patchConfigurationData(final String identifier, final PatchContext payload,
229                                                      final UriInfo uriInfo) {
230         return this.delegate.patchConfigurationData(identifier, payload, uriInfo);
231     }
232
233     @Override
234     public PatchStatusContext patchConfigurationData(final PatchContext payload, final UriInfo uriInfo) {
235         return this.delegate.patchConfigurationData(payload, uriInfo);
236     }
237
238     public BigInteger getConfigDelete() {
239         return BigInteger.valueOf(this.configDelete.get());
240     }
241
242     public BigInteger getConfigGet() {
243         return BigInteger.valueOf(this.configGet.get());
244     }
245
246     public BigInteger getConfigPost() {
247         return BigInteger.valueOf(this.configPost.get());
248     }
249
250     public BigInteger getConfigPut() {
251         return BigInteger.valueOf(this.configPut.get());
252     }
253
254     public BigInteger getOperationalGet() {
255         return BigInteger.valueOf(this.operationalGet.get());
256     }
257
258     public BigInteger getRpc() {
259         return BigInteger.valueOf(this.rpc.get());
260     }
261
262     public BigInteger getSuccessGetConfig() {
263         return BigInteger.valueOf(this.successGetConfig.get());
264     }
265
266     public BigInteger getSuccessGetOperational() {
267         return BigInteger.valueOf(this.successGetOperational.get());
268     }
269
270     public BigInteger getSuccessPost() {
271         return BigInteger.valueOf(this.successPost.get());
272     }
273
274     public BigInteger getSuccessPut() {
275         return BigInteger.valueOf(this.successPut.get());
276     }
277
278     public BigInteger getSuccessDelete() {
279         return BigInteger.valueOf(this.successDelete.get());
280     }
281
282     public BigInteger getFailureGetConfig() {
283         return BigInteger.valueOf(this.failureGetConfig.get());
284     }
285
286     public BigInteger getFailureGetOperational() {
287         return BigInteger.valueOf(this.failureGetOperational.get());
288     }
289
290     public BigInteger getFailurePost() {
291         return BigInteger.valueOf(this.failurePost.get());
292     }
293
294     public BigInteger getFailurePut() {
295         return BigInteger.valueOf(this.failurePut.get());
296     }
297
298     public BigInteger getFailureDelete() {
299         return BigInteger.valueOf(this.failureDelete.get());
300     }
301 }