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