2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.sal.restconf.impl;
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;
20 public final class StatisticsRestconfServiceWrapper implements RestconfService {
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();
39 private static final StatisticsRestconfServiceWrapper INSTANCE = new StatisticsRestconfServiceWrapper();
41 private RestconfService delegate;
44 private StatisticsRestconfServiceWrapper() {
47 private StatisticsRestconfServiceWrapper(final RestconfService delegate) {
48 this.delegate = delegate;
52 public static StatisticsRestconfServiceWrapper getInstance() {
56 public static StatisticsRestconfServiceWrapper newInstance(RestconfService delegate) {
57 INSTANCE.delegate = delegate;
59 //return new StatisticsRestconfServiceWrapper(delegate);
63 public Object getRoot() {
64 return this.delegate.getRoot();
68 public NormalizedNodeContext getModules(final UriInfo uriInfo) {
69 return this.delegate.getModules(uriInfo);
73 public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
74 return this.delegate.getModules(identifier, uriInfo);
78 public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
79 return this.delegate.getModule(identifier, uriInfo);
83 public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
84 return this.delegate.getOperations(uriInfo);
88 public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
89 return this.delegate.getOperations(identifier, uriInfo);
93 public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
94 final UriInfo uriInfo) {
95 this.rpc.incrementAndGet();
96 return this.delegate.invokeRpc(identifier, payload, uriInfo);
100 public NormalizedNodeContext invokeRpc(final String identifier, final String noPayload, final UriInfo uriInfo) {
101 this.rpc.incrementAndGet();
102 return this.delegate.invokeRpc(identifier, noPayload, uriInfo);
105 @SuppressWarnings("checkstyle:IllegalCatch")
107 public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
108 this.configGet.incrementAndGet();
109 NormalizedNodeContext normalizedNodeContext = null;
111 normalizedNodeContext = this.delegate.readConfigurationData(identifier, uriInfo);
112 if (normalizedNodeContext.getData() != null) {
113 this.successGetConfig.incrementAndGet();
115 this.failureGetConfig.incrementAndGet();
117 } catch (final Exception e) {
118 this.failureGetConfig.incrementAndGet();
121 return normalizedNodeContext;
124 @SuppressWarnings("checkstyle:IllegalCatch")
126 public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
127 this.operationalGet.incrementAndGet();
128 NormalizedNodeContext normalizedNodeContext = null;
130 normalizedNodeContext = this.delegate.readOperationalData(identifier, uriInfo);
131 if (normalizedNodeContext.getData() != null) {
132 this.successGetOperational.incrementAndGet();
134 this.failureGetOperational.incrementAndGet();
136 } catch (final Exception e) {
137 this.failureGetOperational.incrementAndGet();
140 return normalizedNodeContext;
143 @SuppressWarnings("checkstyle:IllegalCatch")
145 public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload,
146 final UriInfo uriInfo) {
147 this.configPut.incrementAndGet();
148 Response response = null;
150 response = this.delegate.updateConfigurationData(identifier, payload, uriInfo);
151 if (response.getStatus() == Status.OK.getStatusCode()) {
152 this.successPut.incrementAndGet();
154 this.failurePut.incrementAndGet();
156 } catch (final Exception e) {
157 this.failurePut.incrementAndGet();
163 @SuppressWarnings("checkstyle:IllegalCatch")
165 public Response createConfigurationData(final String identifier, final NormalizedNodeContext payload,
166 final UriInfo uriInfo) {
167 this.configPost.incrementAndGet();
168 Response response = null;
170 response = this.delegate.createConfigurationData(identifier, payload, uriInfo);
171 if (response.getStatus() == Status.OK.getStatusCode()) {
172 this.successPost.incrementAndGet();
174 this.failurePost.incrementAndGet();
176 } catch (final Exception e) {
177 this.failurePost.incrementAndGet();
183 @SuppressWarnings("checkstyle:IllegalCatch")
185 public Response createConfigurationData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
186 this.configPost.incrementAndGet();
187 Response response = null;
189 response = this.delegate.createConfigurationData(payload, uriInfo);
190 if (response.getStatus() == Status.OK.getStatusCode()) {
191 this.successPost.incrementAndGet();
193 this.failurePost.incrementAndGet();
195 } catch (final Exception e) {
196 this.failurePost.incrementAndGet();
202 @SuppressWarnings("checkstyle:IllegalCatch")
204 public Response deleteConfigurationData(final String identifier) {
205 this.configDelete.incrementAndGet();
206 Response response = null;
208 response = this.delegate.deleteConfigurationData(identifier);
209 if (response.getStatus() == Status.OK.getStatusCode()) {
210 this.successDelete.incrementAndGet();
212 this.failureDelete.incrementAndGet();
214 } catch (final Exception e) {
215 this.failureDelete.incrementAndGet();
222 public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
223 return this.delegate.subscribeToStream(identifier, uriInfo);
227 public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
228 return this.delegate.getAvailableStreams(uriInfo);
232 public PatchStatusContext patchConfigurationData(final String identifier, final PatchContext payload,
233 final UriInfo uriInfo) {
234 return this.delegate.patchConfigurationData(identifier, payload, uriInfo);
238 public PatchStatusContext patchConfigurationData(final PatchContext payload, final UriInfo uriInfo) {
239 return this.delegate.patchConfigurationData(payload, uriInfo);
242 public BigInteger getConfigDelete() {
243 return BigInteger.valueOf(this.configDelete.get());
246 public BigInteger getConfigGet() {
247 return BigInteger.valueOf(this.configGet.get());
250 public BigInteger getConfigPost() {
251 return BigInteger.valueOf(this.configPost.get());
254 public BigInteger getConfigPut() {
255 return BigInteger.valueOf(this.configPut.get());
258 public BigInteger getOperationalGet() {
259 return BigInteger.valueOf(this.operationalGet.get());
262 public BigInteger getRpc() {
263 return BigInteger.valueOf(this.rpc.get());
266 public BigInteger getSuccessGetConfig() {
267 return BigInteger.valueOf(this.successGetConfig.get());
270 public BigInteger getSuccessGetOperational() {
271 return BigInteger.valueOf(this.successGetOperational.get());
274 public BigInteger getSuccessPost() {
275 return BigInteger.valueOf(this.successPost.get());
278 public BigInteger getSuccessPut() {
279 return BigInteger.valueOf(this.successPut.get());
282 public BigInteger getSuccessDelete() {
283 return BigInteger.valueOf(this.successDelete.get());
286 public BigInteger getFailureGetConfig() {
287 return BigInteger.valueOf(this.failureGetConfig.get());
290 public BigInteger getFailureGetOperational() {
291 return BigInteger.valueOf(this.failureGetOperational.get());
294 public BigInteger getFailurePost() {
295 return BigInteger.valueOf(this.failurePost.get());
298 public BigInteger getFailurePut() {
299 return BigInteger.valueOf(this.failurePut.get());
302 public BigInteger getFailureDelete() {
303 return BigInteger.valueOf(this.failureDelete.get());