summaryrefslogtreecommitdiffstats
path: root/netconf/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java
blob: afe4be00e8f96c4506afae0e5b5ef661eec4c3c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.netconf.sal.restconf.impl;

import java.math.BigInteger;
import java.util.concurrent.atomic.AtomicLong;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import org.opendaylight.netconf.sal.rest.api.RestconfService;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchStatusContext;

@Singleton
public final class StatisticsRestconfServiceWrapper implements RestconfService {

    AtomicLong operationalGet = new AtomicLong();
    AtomicLong configGet = new AtomicLong();
    AtomicLong rpc = new AtomicLong();
    AtomicLong configPost = new AtomicLong();
    AtomicLong configPut = new AtomicLong();
    AtomicLong configDelete = new AtomicLong();
    AtomicLong successGetConfig = new AtomicLong();
    AtomicLong successGetOperational = new AtomicLong();
    AtomicLong successPost = new AtomicLong();
    AtomicLong successPut = new AtomicLong();
    AtomicLong successDelete = new AtomicLong();
    AtomicLong failureGetConfig = new AtomicLong();
    AtomicLong failureGetOperational = new AtomicLong();
    AtomicLong failurePost = new AtomicLong();
    AtomicLong failurePut = new AtomicLong();
    AtomicLong failureDelete = new AtomicLong();

    private final RestconfService delegate;

    @Inject
    public StatisticsRestconfServiceWrapper(final RestconfImpl delegate) {
        this.delegate = delegate;
    }

    /**
     * Factory method.
     *
     * @deprecated Just use {@link #StatisticsRestconfServiceWrapper(RestconfImpl)} constructor instead.
     */
    @Deprecated
    public static StatisticsRestconfServiceWrapper newInstance(RestconfImpl delegate) {
        return new StatisticsRestconfServiceWrapper(delegate);
    }

    @Override
    public Object getRoot() {
        return this.delegate.getRoot();
    }

    @Override
    public NormalizedNodeContext getModules(final UriInfo uriInfo) {
        return this.delegate.getModules(uriInfo);
    }

    @Override
    public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
        return this.delegate.getModules(identifier, uriInfo);
    }

    @Override
    public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
        return this.delegate.getModule(identifier, uriInfo);
    }

    @Override
    public String getOperationsJSON() {
        return this.delegate.getOperationsJSON();
    }

    @Override
    public String getOperationsXML() {
        return this.delegate.getOperationsXML();
    }

    @Override
    public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
        return this.delegate.getOperations(identifier, uriInfo);
    }

    @Override
    public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
            final UriInfo uriInfo) {
        this.rpc.incrementAndGet();
        return this.delegate.invokeRpc(identifier, payload, uriInfo);
    }

    @SuppressWarnings("checkstyle:IllegalCatch")
    @Override
    public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
        this.configGet.incrementAndGet();
        NormalizedNodeContext normalizedNodeContext = null;
        try {
            normalizedNodeContext = this.delegate.readConfigurationData(identifier, uriInfo);
            if (normalizedNodeContext.getData() != null) {
                this.successGetConfig.incrementAndGet();
            } else {
                this.failureGetConfig.incrementAndGet();
            }
        } catch (final Exception e) {
            this.failureGetConfig.incrementAndGet();
            throw e;
        }
        return normalizedNodeContext;
    }

    @SuppressWarnings("checkstyle:IllegalCatch")
    @Override
    public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
        this.operationalGet.incrementAndGet();
        NormalizedNodeContext normalizedNodeContext = null;
        try {
            normalizedNodeContext = this.delegate.readOperationalData(identifier, uriInfo);
            if (normalizedNodeContext.getData() != null) {
                this.successGetOperational.incrementAndGet();
            } else {
                this.failureGetOperational.incrementAndGet();
            }
        } catch (final Exception e) {
            this.failureGetOperational.incrementAndGet();
            throw e;
        }
        return normalizedNodeContext;
    }

    @SuppressWarnings("checkstyle:IllegalCatch")
    @Override
    public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload,
            final UriInfo uriInfo) {
        this.configPut.incrementAndGet();
        Response response = null;
        try {
            response = this.delegate.updateConfigurationData(identifier, payload, uriInfo);
            if (response.getStatus() == Status.OK.getStatusCode()) {
                this.successPut.incrementAndGet();
            } else {
                this.failurePut.incrementAndGet();
            }
        } catch (final Exception e) {
            this.failurePut.incrementAndGet();
            throw e;
        }
        return response;
    }

    @SuppressWarnings("checkstyle:IllegalCatch")
    @Override
    public Response createConfigurationData(final String identifier, final NormalizedNodeContext payload,
            final UriInfo uriInfo) {
        this.configPost.incrementAndGet();
        Response response = null;
        try {
            response = this.delegate.createConfigurationData(identifier, payload, uriInfo);
            if (response.getStatus() == Status.OK.getStatusCode()) {
                this.successPost.incrementAndGet();
            } else {
                this.failurePost.incrementAndGet();
            }
        } catch (final Exception e) {
            this.failurePost.incrementAndGet();
            throw e;
        }
        return response;
    }

    @SuppressWarnings("checkstyle:IllegalCatch")
    @Override
    public Response createConfigurationData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
        this.configPost.incrementAndGet();
        Response response = null;
        try {
            response = this.delegate.createConfigurationData(payload, uriInfo);
            if (response.getStatus() == Status.OK.getStatusCode()) {
                this.successPost.incrementAndGet();
            } else {
                this.failurePost.incrementAndGet();
            }
        } catch (final Exception e) {
            this.failurePost.incrementAndGet();
            throw e;
        }
        return response;
    }

    @SuppressWarnings("checkstyle:IllegalCatch")
    @Override
    public Response deleteConfigurationData(final String identifier) {
        this.configDelete.incrementAndGet();
        Response response = null;
        try {
            response = this.delegate.deleteConfigurationData(identifier);
            if (response.getStatus() == Status.OK.getStatusCode()) {
                this.successDelete.incrementAndGet();
            } else {
                this.failureDelete.incrementAndGet();
            }
        } catch (final Exception e) {
            this.failureDelete.incrementAndGet();
            throw e;
        }
        return response;
    }

    @Override
    public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
        return this.delegate.subscribeToStream(identifier, uriInfo);
    }

    @Override
    public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
        return this.delegate.getAvailableStreams(uriInfo);
    }

    @Override
    public PatchStatusContext patchConfigurationData(final String identifier, final PatchContext payload,
                                                     final UriInfo uriInfo) {
        return this.delegate.patchConfigurationData(identifier, payload, uriInfo);
    }

    @Override
    public PatchStatusContext patchConfigurationData(final PatchContext payload, final UriInfo uriInfo) {
        return this.delegate.patchConfigurationData(payload, uriInfo);
    }

    public BigInteger getConfigDelete() {
        return BigInteger.valueOf(this.configDelete.get());
    }

    public BigInteger getConfigGet() {
        return BigInteger.valueOf(this.configGet.get());
    }

    public BigInteger getConfigPost() {
        return BigInteger.valueOf(this.configPost.get());
    }

    public BigInteger getConfigPut() {
        return BigInteger.valueOf(this.configPut.get());
    }

    public BigInteger getOperationalGet() {
        return BigInteger.valueOf(this.operationalGet.get());
    }

    public BigInteger getRpc() {
        return BigInteger.valueOf(this.rpc.get());
    }

    public BigInteger getSuccessGetConfig() {
        return BigInteger.valueOf(this.successGetConfig.get());
    }

    public BigInteger getSuccessGetOperational() {
        return BigInteger.valueOf(this.successGetOperational.get());
    }

    public BigInteger getSuccessPost() {
        return BigInteger.valueOf(this.successPost.get());
    }

    public BigInteger getSuccessPut() {
        return BigInteger.valueOf(this.successPut.get());
    }

    public BigInteger getSuccessDelete() {
        return BigInteger.valueOf(this.successDelete.get());
    }

    public BigInteger getFailureGetConfig() {
        return BigInteger.valueOf(this.failureGetConfig.get());
    }

    public BigInteger getFailureGetOperational() {
        return BigInteger.valueOf(this.failureGetOperational.get());
    }

    public BigInteger getFailurePost() {
        return BigInteger.valueOf(this.failurePost.get());
    }

    public BigInteger getFailurePut() {
        return BigInteger.valueOf(this.failurePut.get());
    }

    public BigInteger getFailureDelete() {
        return BigInteger.valueOf(this.failureDelete.get());
    }
}