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.controller.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.controller.sal.rest.api.RestconfService;
17 public class StatisticsRestconfServiceWrapper implements RestconfService {
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();
36 private static final StatisticsRestconfServiceWrapper INSTANCE = new StatisticsRestconfServiceWrapper(RestconfImpl.getInstance());
38 final RestconfService delegate;
40 private StatisticsRestconfServiceWrapper(final RestconfService delegate) {
41 this.delegate = delegate;
44 public static StatisticsRestconfServiceWrapper getInstance() {
49 public Object getRoot() {
50 return delegate.getRoot();
54 public NormalizedNodeContext getModules(final UriInfo uriInfo) {
55 return delegate.getModules(uriInfo);
59 public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
60 return delegate.getModules(identifier, uriInfo);
64 public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
65 return delegate.getModule(identifier, uriInfo);
69 public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
70 return delegate.getOperations(uriInfo);
74 public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
75 return delegate.getOperations(identifier, uriInfo);
79 public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
80 rpc.incrementAndGet();
81 return delegate.invokeRpc(identifier, payload, uriInfo);
85 public NormalizedNodeContext invokeRpc(final String identifier, final String noPayload, final UriInfo uriInfo) {
86 rpc.incrementAndGet();
87 return delegate.invokeRpc(identifier, noPayload, uriInfo);
91 public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
92 configGet.incrementAndGet();
93 NormalizedNodeContext normalizedNodeContext = null;
95 normalizedNodeContext = delegate.readConfigurationData(identifier, uriInfo);
96 if (normalizedNodeContext.getData() != null) {
97 successGetConfig.incrementAndGet();
100 failureGetConfig.incrementAndGet();
102 } catch (Exception e) {
103 failureGetConfig.incrementAndGet();
106 return normalizedNodeContext;
110 public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
111 operationalGet.incrementAndGet();
112 NormalizedNodeContext normalizedNodeContext = null;
114 normalizedNodeContext = delegate.readOperationalData(identifier, uriInfo);
115 if (normalizedNodeContext.getData() != null) {
116 successGetOperational.incrementAndGet();
119 failureGetOperational.incrementAndGet();
121 } catch (Exception e) {
122 failureGetOperational.incrementAndGet();
125 return normalizedNodeContext;
129 public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload) {
130 configPut.incrementAndGet();
131 Response response = null;
133 response = delegate.updateConfigurationData(identifier, payload);
134 if (response.getStatus() == Status.OK.getStatusCode()) {
135 successPut.incrementAndGet();
138 failurePut.incrementAndGet();
140 } catch (Exception e) {
141 failurePut.incrementAndGet();
148 public Response createConfigurationData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
149 configPost.incrementAndGet();
150 Response response = null;
152 response = delegate.createConfigurationData(identifier, payload, uriInfo);
153 if (response.getStatus() == Status.OK.getStatusCode()) {
154 successPost.incrementAndGet();
157 failurePost.incrementAndGet();
159 } catch (Exception e) {
160 failurePost.incrementAndGet();
167 public Response createConfigurationData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
168 configPost.incrementAndGet();
169 Response response = null;
171 response = delegate.createConfigurationData(payload, uriInfo);
172 if (response.getStatus() == Status.OK.getStatusCode()) {
173 successPost.incrementAndGet();
176 failurePost.incrementAndGet();
178 }catch (Exception e) {
179 failurePost.incrementAndGet();
186 public Response deleteConfigurationData(final String identifier) {
187 configDelete.incrementAndGet();
188 Response response = null;
190 response = delegate.deleteConfigurationData(identifier);
191 if (response.getStatus() == Status.OK.getStatusCode()) {
192 successDelete.incrementAndGet();
195 failureDelete.incrementAndGet();
197 } catch (Exception e) {
198 failureDelete.incrementAndGet();
205 public Response subscribeToStream(final String identifier, final UriInfo uriInfo) {
206 return delegate.subscribeToStream(identifier, uriInfo);
210 public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
211 return delegate.getAvailableStreams(uriInfo);
214 public BigInteger getConfigDelete() {
215 return BigInteger.valueOf(configDelete.get());
218 public BigInteger getConfigGet() {
219 return BigInteger.valueOf(configGet.get());
222 public BigInteger getConfigPost() {
223 return BigInteger.valueOf(configPost.get());
226 public BigInteger getConfigPut() {
227 return BigInteger.valueOf(configPut.get());
230 public BigInteger getOperationalGet() {
231 return BigInteger.valueOf(operationalGet.get());
234 public BigInteger getRpc() {
235 return BigInteger.valueOf(rpc.get());
238 public BigInteger getSuccessGetConfig() {
239 return BigInteger.valueOf(successGetConfig.get());
242 public BigInteger getSuccessGetOperational() {
243 return BigInteger.valueOf(successGetOperational.get());
246 public BigInteger getSuccessPost() {
247 return BigInteger.valueOf(successPost.get());
250 public BigInteger getSuccessPut() {
251 return BigInteger.valueOf(successPut.get());
254 public BigInteger getSuccessDelete() {
255 return BigInteger.valueOf(successDelete.get());
258 public BigInteger getFailureGetConfig() {
259 return BigInteger.valueOf(failureGetConfig.get());
262 public BigInteger getFailureGetOperational() {
263 return BigInteger.valueOf(failureGetOperational.get());
266 public BigInteger getFailurePost() {
267 return BigInteger.valueOf(failurePost.get());
270 public BigInteger getFailurePut() {
271 return BigInteger.valueOf(failurePut.get());
274 public BigInteger getFailureDelete() {
275 return BigInteger.valueOf(failureDelete.get());