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