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.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;
23 public final class StatisticsRestconfServiceWrapper implements RestconfService {
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();
42 private final RestconfService delegate;
45 public StatisticsRestconfServiceWrapper(final RestconfImpl delegate) {
46 this.delegate = delegate;
52 * @deprecated Just use {@link #StatisticsRestconfServiceWrapper(RestconfImpl)} constructor instead.
55 public static StatisticsRestconfServiceWrapper newInstance(RestconfImpl delegate) {
56 return new StatisticsRestconfServiceWrapper(delegate);
60 public Object getRoot() {
61 return this.delegate.getRoot();
65 public NormalizedNodeContext getModules(final UriInfo uriInfo) {
66 return this.delegate.getModules(uriInfo);
70 public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
71 return this.delegate.getModules(identifier, uriInfo);
75 public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
76 return this.delegate.getModule(identifier, uriInfo);
80 public String getOperationsJSON() {
81 return this.delegate.getOperationsJSON();
85 public String getOperationsXML() {
86 return this.delegate.getOperationsXML();
90 public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
91 return this.delegate.getOperations(identifier, uriInfo);
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);
101 @SuppressWarnings("checkstyle:IllegalCatch")
103 public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
104 this.configGet.incrementAndGet();
105 NormalizedNodeContext normalizedNodeContext = null;
107 normalizedNodeContext = this.delegate.readConfigurationData(identifier, uriInfo);
108 if (normalizedNodeContext.getData() != null) {
109 this.successGetConfig.incrementAndGet();
111 this.failureGetConfig.incrementAndGet();
113 } catch (final Exception e) {
114 this.failureGetConfig.incrementAndGet();
117 return normalizedNodeContext;
120 @SuppressWarnings("checkstyle:IllegalCatch")
122 public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
123 this.operationalGet.incrementAndGet();
124 NormalizedNodeContext normalizedNodeContext = null;
126 normalizedNodeContext = this.delegate.readOperationalData(identifier, uriInfo);
127 if (normalizedNodeContext.getData() != null) {
128 this.successGetOperational.incrementAndGet();
130 this.failureGetOperational.incrementAndGet();
132 } catch (final Exception e) {
133 this.failureGetOperational.incrementAndGet();
136 return normalizedNodeContext;
139 @SuppressWarnings("checkstyle:IllegalCatch")
141 public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload,
142 final UriInfo uriInfo) {
143 this.configPut.incrementAndGet();
144 Response response = null;
146 response = this.delegate.updateConfigurationData(identifier, payload, uriInfo);
147 if (response.getStatus() == Status.OK.getStatusCode()) {
148 this.successPut.incrementAndGet();
150 this.failurePut.incrementAndGet();
152 } catch (final Exception e) {
153 this.failurePut.incrementAndGet();
159 @SuppressWarnings("checkstyle:IllegalCatch")
161 public Response createConfigurationData(final String identifier, final NormalizedNodeContext payload,
162 final UriInfo uriInfo) {
163 this.configPost.incrementAndGet();
164 Response response = null;
166 response = this.delegate.createConfigurationData(identifier, payload, uriInfo);
167 if (response.getStatus() == Status.OK.getStatusCode()) {
168 this.successPost.incrementAndGet();
170 this.failurePost.incrementAndGet();
172 } catch (final Exception e) {
173 this.failurePost.incrementAndGet();
179 @SuppressWarnings("checkstyle:IllegalCatch")
181 public Response createConfigurationData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
182 this.configPost.incrementAndGet();
183 Response response = null;
185 response = this.delegate.createConfigurationData(payload, uriInfo);
186 if (response.getStatus() == Status.OK.getStatusCode()) {
187 this.successPost.incrementAndGet();
189 this.failurePost.incrementAndGet();
191 } catch (final Exception e) {
192 this.failurePost.incrementAndGet();
198 @SuppressWarnings("checkstyle:IllegalCatch")
200 public Response deleteConfigurationData(final String identifier) {
201 this.configDelete.incrementAndGet();
202 Response response = null;
204 response = this.delegate.deleteConfigurationData(identifier);
205 if (response.getStatus() == Status.OK.getStatusCode()) {
206 this.successDelete.incrementAndGet();
208 this.failureDelete.incrementAndGet();
210 } catch (final Exception e) {
211 this.failureDelete.incrementAndGet();
218 public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
219 return this.delegate.subscribeToStream(identifier, uriInfo);
223 public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
224 return this.delegate.getAvailableStreams(uriInfo);
228 public PatchStatusContext patchConfigurationData(final String identifier, final PatchContext payload,
229 final UriInfo uriInfo) {
230 return this.delegate.patchConfigurationData(identifier, payload, uriInfo);
234 public PatchStatusContext patchConfigurationData(final PatchContext payload, final UriInfo uriInfo) {
235 return this.delegate.patchConfigurationData(payload, uriInfo);
238 public BigInteger getConfigDelete() {
239 return BigInteger.valueOf(this.configDelete.get());
242 public BigInteger getConfigGet() {
243 return BigInteger.valueOf(this.configGet.get());
246 public BigInteger getConfigPost() {
247 return BigInteger.valueOf(this.configPost.get());
250 public BigInteger getConfigPut() {
251 return BigInteger.valueOf(this.configPut.get());
254 public BigInteger getOperationalGet() {
255 return BigInteger.valueOf(this.operationalGet.get());
258 public BigInteger getRpc() {
259 return BigInteger.valueOf(this.rpc.get());
262 public BigInteger getSuccessGetConfig() {
263 return BigInteger.valueOf(this.successGetConfig.get());
266 public BigInteger getSuccessGetOperational() {
267 return BigInteger.valueOf(this.successGetOperational.get());
270 public BigInteger getSuccessPost() {
271 return BigInteger.valueOf(this.successPost.get());
274 public BigInteger getSuccessPut() {
275 return BigInteger.valueOf(this.successPut.get());
278 public BigInteger getSuccessDelete() {
279 return BigInteger.valueOf(this.successDelete.get());
282 public BigInteger getFailureGetConfig() {
283 return BigInteger.valueOf(this.failureGetConfig.get());
286 public BigInteger getFailureGetOperational() {
287 return BigInteger.valueOf(this.failureGetOperational.get());
290 public BigInteger getFailurePost() {
291 return BigInteger.valueOf(this.failurePost.get());
294 public BigInteger getFailurePut() {
295 return BigInteger.valueOf(this.failurePut.get());
298 public BigInteger getFailureDelete() {
299 return BigInteger.valueOf(this.failureDelete.get());