1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.openr66.protocol.localhandler;
21
22 import com.fasterxml.jackson.databind.node.ObjectNode;
23 import io.netty.handler.traffic.TrafficCounter;
24 import org.joda.time.DateTime;
25 import org.waarp.common.database.DbAdmin;
26 import org.waarp.common.database.DbPreparedStatement;
27 import org.waarp.common.database.DbSession;
28 import org.waarp.common.database.data.AbstractDbData.UpdatedInfo;
29 import org.waarp.common.database.exception.WaarpDatabaseNoConnectionException;
30 import org.waarp.common.database.exception.WaarpDatabaseSqlException;
31 import org.waarp.common.json.JsonHandler;
32 import org.waarp.common.logging.WaarpLogger;
33 import org.waarp.common.logging.WaarpLoggerFactory;
34 import org.waarp.openr66.commander.CommanderNoDb;
35 import org.waarp.openr66.context.ErrorCode;
36 import org.waarp.openr66.database.data.DbTaskRunner;
37 import org.waarp.openr66.database.data.DbTaskRunner.TASKSTEP;
38 import org.waarp.openr66.protocol.configuration.Configuration;
39 import org.waarp.openr66.protocol.snmp.R66PrivateMib;
40 import org.waarp.openr66.protocol.utils.ChannelUtils;
41 import org.waarp.snmp.WaarpSnmpAgent;
42 import org.waarp.snmp.interf.WaarpInterfaceMonitor;
43 import org.waarp.snmp.r66.WaarpPrivateMib.MibLevel;
44 import org.waarp.snmp.r66.WaarpPrivateMib.WaarpDetailedValuesIndex;
45 import org.waarp.snmp.r66.WaarpPrivateMib.WaarpErrorValuesIndex;
46 import org.waarp.snmp.r66.WaarpPrivateMib.WaarpGlobalValuesIndex;
47
48 import static org.waarp.common.database.DbConstant.*;
49
50
51
52
53
54 public class Monitoring implements WaarpInterfaceMonitor {
55
56
57
58 private static final WaarpLogger logger =
59 WaarpLoggerFactory.getLogger(Monitoring.class);
60
61 public WaarpSnmpAgent agent;
62
63
64 public long nbNetworkConnection;
65 public long secondsRunning;
66 public long nbThread;
67 public long bandwidthIn;
68 public long bandwidthOut;
69
70
71 private final long startMonitor = System.currentTimeMillis();
72 private final long pastLimit;
73 private long currentLimit;
74 private final long minimalDelay;
75 private long lastTry;
76 private DbSession dbSession;
77 private final TrafficCounter trafficCounter =
78 Configuration.configuration.getGlobalTrafficShapingHandler()
79 .trafficCounter();
80
81
82 private DbPreparedStatement countInfo;
83
84
85 private DbPreparedStatement countInActiveTransfer;
86 private DbPreparedStatement countOutActiveTransfer;
87 private DbPreparedStatement countInTotalTransfer;
88 private DbPreparedStatement countOutTotalTransfer;
89 private DbPreparedStatement countInErrorTransfer;
90 private DbPreparedStatement countOutErrorTransfer;
91 private DbPreparedStatement countStepAllTransfer;
92 private DbPreparedStatement countStepNotask;
93 private DbPreparedStatement countStepPretask;
94 private DbPreparedStatement countStepTransfer;
95 private DbPreparedStatement countStepPosttask;
96 private DbPreparedStatement countStepAllDone;
97 private DbPreparedStatement countStepError;
98
99
100 private DbPreparedStatement countAllRunningStep;
101 private DbPreparedStatement countRunningStep;
102 private DbPreparedStatement countInitOkStep;
103 private DbPreparedStatement countPreProcessingOkStep;
104 private DbPreparedStatement countTransferOkStep;
105 private DbPreparedStatement countPostProcessingOkStep;
106 private DbPreparedStatement countCompleteOkStep;
107
108
109 private DbPreparedStatement countStatus;
110
111
112 public long nbCountInfoUnknown;
113 public long nbCountInfoNotUpdated;
114 public long nbCountInfoInterrupted;
115 public long nbCountInfoToSubmit;
116 public long nbCountInfoError;
117 public long nbCountInfoRunning;
118 public long nbCountInfoDone;
119
120 public long nbInActiveTransfer;
121 public long nbOutActiveTransfer;
122 public long lastInActiveTransfer = System.currentTimeMillis();
123 public long lastOutActiveTransfer = System.currentTimeMillis();
124 public long nbInTotalTransfer;
125 public long nbOutTotalTransfer;
126 public long nbInErrorTransfer;
127 public long nbOutErrorTransfer;
128
129
130 public long nbCountStepAllTransfer;
131 public long nbCountStepNotask;
132 public long nbCountStepPretask;
133 public long nbCountStepTransfer;
134 public long nbCountStepPosttask;
135 public long nbCountStepAllDone;
136 public long nbCountStepError;
137
138
139 public long nbCountAllRunningStep;
140 public long nbCountRunningStep;
141 public long nbCountInitOkStep;
142 public long nbCountPreProcessingOkStep;
143 public long nbCountTransferOkStep;
144 public long nbCountPostProcessingOkStep;
145 public long nbCountCompleteOkStep;
146
147
148 public long nbCountStatusConnectionImpossible;
149 public long nbCountStatusServerOverloaded;
150 public long nbCountStatusBadAuthent;
151 public long nbCountStatusExternalOp;
152 public long nbCountStatusTransferError;
153 public long nbCountStatusMD5Error;
154 public long nbCountStatusDisconnection;
155 public long nbCountStatusFinalOp;
156 public long nbCountStatusUnimplemented;
157 public long nbCountStatusInternal;
158 public long nbCountStatusWarning;
159 public long nbCountStatusQueryAlreadyFinished;
160 public long nbCountStatusQueryStillRunning;
161 public long nbCountStatusNotKnownHost;
162 public long nbCountStatusQueryRemotelyUnknown;
163 public long nbCountStatusCommandNotFound;
164 public long nbCountStatusPassThroughMode;
165 public long nbCountStatusRemoteShutdown;
166 public long nbCountStatusShutdown;
167 public long nbCountStatusRemoteError;
168 public long nbCountStatusStopped;
169 public long nbCountStatusCanceled;
170 public long nbCountStatusFileNotFound;
171 public long nbCountStatusUnknown;
172
173
174
175
176
177
178 public Monitoring(final long pastLimit, final long minimalDelay,
179 final DbSession session) {
180 this.pastLimit = pastLimit;
181 this.minimalDelay = minimalDelay;
182 if (session != null) {
183 dbSession = session;
184 } else {
185 try {
186 dbSession = new DbSession(admin, false);
187 } catch (final WaarpDatabaseNoConnectionException e) {
188 dbSession = admin.getSession();
189 }
190 }
191 initialize();
192 }
193
194
195
196
197
198 @Override
199 public final void initialize() {
200 if (dbSession == null || dbSession.isDisActive()) {
201 logger.warn("Cannot Initialize monitoring");
202 return;
203 }
204 try {
205 logger.debug("Initialize monitoring");
206
207 countInfo = DbTaskRunner.getCountInfoPrepareStatement(dbSession);
208
209 countInActiveTransfer =
210 DbTaskRunner.getCountInOutRunningPrepareStatement(dbSession, true,
211 true);
212 countOutActiveTransfer =
213 DbTaskRunner.getCountInOutRunningPrepareStatement(dbSession, false,
214 true);
215 countInTotalTransfer =
216 DbTaskRunner.getCountInOutRunningPrepareStatement(dbSession, true,
217 false);
218 countOutTotalTransfer =
219 DbTaskRunner.getCountInOutRunningPrepareStatement(dbSession, false,
220 false);
221
222 countInErrorTransfer =
223 DbTaskRunner.getCountInOutErrorPrepareStatement(dbSession, true);
224 countOutErrorTransfer =
225 DbTaskRunner.getCountInOutErrorPrepareStatement(dbSession, false);
226
227
228 countStepAllTransfer =
229 DbTaskRunner.getCountStepPrepareStatement(dbSession, null);
230 countStepNotask =
231 DbTaskRunner.getCountStepPrepareStatement(dbSession, TASKSTEP.NOTASK);
232 countStepPretask = DbTaskRunner.getCountStepPrepareStatement(dbSession,
233 TASKSTEP.PRETASK);
234 countStepTransfer = DbTaskRunner.getCountStepPrepareStatement(dbSession,
235 TASKSTEP.TRANSFERTASK);
236 countStepPosttask = DbTaskRunner.getCountStepPrepareStatement(dbSession,
237 TASKSTEP.POSTTASK);
238 countStepAllDone = DbTaskRunner.getCountStepPrepareStatement(dbSession,
239 TASKSTEP.ALLDONETASK);
240 countStepError = DbTaskRunner.getCountStepPrepareStatement(dbSession,
241 TASKSTEP.ERRORTASK);
242
243
244 countAllRunningStep =
245 DbTaskRunner.getCountStatusRunningPrepareStatement(dbSession, null);
246 countRunningStep =
247 DbTaskRunner.getCountStatusRunningPrepareStatement(dbSession,
248 ErrorCode.Running);
249 countInitOkStep =
250 DbTaskRunner.getCountStatusRunningPrepareStatement(dbSession,
251 ErrorCode.InitOk);
252 countPreProcessingOkStep =
253 DbTaskRunner.getCountStatusRunningPrepareStatement(dbSession,
254 ErrorCode.PreProcessingOk);
255 countTransferOkStep =
256 DbTaskRunner.getCountStatusRunningPrepareStatement(dbSession,
257 ErrorCode.TransferOk);
258 countPostProcessingOkStep =
259 DbTaskRunner.getCountStatusRunningPrepareStatement(dbSession,
260 ErrorCode.PostProcessingOk);
261 countCompleteOkStep =
262 DbTaskRunner.getCountStatusRunningPrepareStatement(dbSession,
263 ErrorCode.CompleteOk);
264
265
266 countStatus = DbTaskRunner.getCountStatusPrepareStatement(dbSession);
267 } catch (final WaarpDatabaseNoConnectionException ignored) {
268
269 } catch (final WaarpDatabaseSqlException ignored) {
270
271 }
272 }
273
274
275
276
277 @Override
278 public final void releaseResources() {
279 if (dbSession == null || dbSession.isDisActive()) {
280 return;
281 }
282 try {
283 logger.debug("Release monitoring");
284
285 countInfo.realClose();
286
287 countInActiveTransfer.realClose();
288 countOutActiveTransfer.realClose();
289 countInTotalTransfer.realClose();
290 countOutTotalTransfer.realClose();
291 countInErrorTransfer.realClose();
292 countOutErrorTransfer.realClose();
293
294
295 countStepAllTransfer.realClose();
296 countStepNotask.realClose();
297 countStepPretask.realClose();
298 countStepTransfer.realClose();
299 countStepPosttask.realClose();
300 countStepAllDone.realClose();
301 countStepError.realClose();
302
303
304 countAllRunningStep.realClose();
305 countRunningStep.realClose();
306 countInitOkStep.realClose();
307 countPreProcessingOkStep.realClose();
308 countTransferOkStep.realClose();
309 countPostProcessingOkStep.realClose();
310 countCompleteOkStep.realClose();
311
312
313 countStatus.realClose();
314 } catch (final Exception ignored) {
315
316 }
317 if (!dbSession.equals(admin.getSession())) {
318 if (DbAdmin.getNbConnection() > 0) {
319 dbSession.forceDisconnect();
320 }
321 dbSession = null;
322 }
323 }
324
325
326
327
328 public final long lastRunTimeMs() {
329 return lastTry;
330 }
331
332
333
334
335 public final void run() {
336 run(-1, false);
337 }
338
339
340
341
342 public final void run(final long nbSecond) {
343 run(nbSecond, false);
344 }
345
346
347
348
349
350
351 public final void run(final boolean detail) {
352 run(-1, detail);
353 }
354
355
356
357
358 private boolean reCompute() {
359 final long limitDate = System.currentTimeMillis();
360 if (limitDate < lastTry + minimalDelay) {
361
362 return false;
363 }
364 lastTry = limitDate;
365 return true;
366 }
367
368
369
370
371
372 public final void run(final long nbSecond, final boolean detail) {
373 synchronized (trafficCounter) {
374 long limitDate = System.currentTimeMillis();
375 final long nbMs;
376 if (nbSecond <= 0) {
377 nbMs = pastLimit;
378 } else {
379 nbMs = nbSecond * 1000;
380 }
381 if (dbSession != null && dbSession.isDisActive()) {
382 dbSession.checkConnectionNoException();
383 }
384 if (dbSession == null || dbSession.isDisActive()) {
385 nbNetworkConnection =
386 ChannelUtils.nbCommandChannels(Configuration.configuration);
387 bandwidthIn = trafficCounter.lastReadThroughput() >> 7;
388 bandwidthOut = trafficCounter.lastWriteThroughput() >> 7;
389 nbThread = Thread.activeCount();
390 secondsRunning = (limitDate - startMonitor) / 1000;
391
392 if (!reCompute()) {
393
394 return;
395 }
396 limitDate -= nbMs;
397 currentLimit = limitDate;
398
399
400 nbCountInfoToSubmit = CommanderNoDb.todoList.size();
401 if (Configuration.configuration.getInternalRunner() != null) {
402 nbCountInfoRunning = Configuration.configuration.getInternalRunner()
403 .nbInternalRunner();
404 } else {
405 if (Configuration.configuration.getServerConnectedChannelGroup() !=
406 null) {
407 nbCountInfoRunning =
408 Configuration.configuration.getServerConnectedChannelGroup()
409 .size();
410 } else {
411 nbCountInfoRunning =
412 Configuration.configuration.getServerChannelGroup().size();
413 }
414 }
415
416 nbCountAllRunningStep = nbCountInfoRunning;
417 } else {
418 nbNetworkConnection = DbAdmin.getNbConnection();
419 bandwidthIn = trafficCounter.lastReadThroughput() >> 7;
420 bandwidthOut = trafficCounter.lastWriteThroughput() >> 7;
421 nbThread = Thread.activeCount();
422 secondsRunning = (limitDate - startMonitor) / 1000;
423
424 if (!reCompute()) {
425
426 return;
427 }
428 limitDate -= nbMs;
429 currentLimit = limitDate;
430
431 try {
432
433 nbCountInfoUnknown =
434 DbTaskRunner.getResultCountPrepareStatement(countInfo,
435 UpdatedInfo.UNKNOWN,
436 limitDate);
437 nbCountInfoNotUpdated =
438 DbTaskRunner.getResultCountPrepareStatement(countInfo,
439 UpdatedInfo.NOTUPDATED,
440 limitDate);
441 nbCountInfoInterrupted =
442 DbTaskRunner.getResultCountPrepareStatement(countInfo,
443 UpdatedInfo.INTERRUPTED,
444 limitDate);
445 nbCountInfoToSubmit =
446 DbTaskRunner.getResultCountPrepareStatement(countInfo,
447 UpdatedInfo.TOSUBMIT,
448 limitDate);
449 nbCountInfoError =
450 DbTaskRunner.getResultCountPrepareStatement(countInfo,
451 UpdatedInfo.INERROR,
452 limitDate);
453 nbCountInfoRunning =
454 DbTaskRunner.getResultCountPrepareStatement(countInfo,
455 UpdatedInfo.RUNNING,
456 limitDate);
457 nbCountInfoDone =
458 DbTaskRunner.getResultCountPrepareStatement(countInfo,
459 UpdatedInfo.DONE,
460 limitDate);
461
462
463 DbTaskRunner.finishSelectOrCountPrepareStatement(
464 countInActiveTransfer, limitDate);
465 nbInActiveTransfer = DbTaskRunner.getResultCountPrepareStatement(
466 countInActiveTransfer);
467 DbTaskRunner.finishSelectOrCountPrepareStatement(
468 countOutActiveTransfer, limitDate);
469 nbOutActiveTransfer = DbTaskRunner.getResultCountPrepareStatement(
470 countOutActiveTransfer);
471 DbTaskRunner.finishSelectOrCountPrepareStatement(countInTotalTransfer,
472 limitDate);
473 nbInTotalTransfer =
474 DbTaskRunner.getResultCountPrepareStatement(countInTotalTransfer);
475 DbTaskRunner.finishSelectOrCountPrepareStatement(
476 countOutTotalTransfer, limitDate);
477 nbOutTotalTransfer = DbTaskRunner.getResultCountPrepareStatement(
478 countOutTotalTransfer);
479
480 DbTaskRunner.finishSelectOrCountPrepareStatement(
481 countOutErrorTransfer, limitDate);
482 nbOutErrorTransfer = DbTaskRunner.getResultCountPrepareStatement(
483 countOutErrorTransfer);
484 DbTaskRunner.finishSelectOrCountPrepareStatement(countInErrorTransfer,
485 limitDate);
486 nbInErrorTransfer =
487 DbTaskRunner.getResultCountPrepareStatement(countInErrorTransfer);
488
489 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepAllTransfer,
490 limitDate);
491 nbCountStepAllTransfer =
492 DbTaskRunner.getResultCountPrepareStatement(countStepAllTransfer);
493 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepNotask,
494 limitDate);
495 nbCountStepNotask =
496 DbTaskRunner.getResultCountPrepareStatement(countStepNotask);
497 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepPretask,
498 limitDate);
499 nbCountStepPretask =
500 DbTaskRunner.getResultCountPrepareStatement(countStepPretask);
501 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepTransfer,
502 limitDate);
503 nbCountStepTransfer =
504 DbTaskRunner.getResultCountPrepareStatement(countStepTransfer);
505 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepPosttask,
506 limitDate);
507 nbCountStepPosttask =
508 DbTaskRunner.getResultCountPrepareStatement(countStepPosttask);
509 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepAllDone,
510 limitDate);
511 nbCountStepAllDone =
512 DbTaskRunner.getResultCountPrepareStatement(countStepAllDone);
513 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepError,
514 limitDate);
515 nbCountStepError =
516 DbTaskRunner.getResultCountPrepareStatement(countStepError);
517
518 DbTaskRunner.finishSelectOrCountPrepareStatement(countAllRunningStep,
519 limitDate);
520 nbCountAllRunningStep =
521 DbTaskRunner.getResultCountPrepareStatement(countAllRunningStep);
522
523 if (detail) {
524
525 DbTaskRunner.finishSelectOrCountPrepareStatement(countRunningStep,
526 limitDate);
527 nbCountRunningStep =
528 DbTaskRunner.getResultCountPrepareStatement(countRunningStep);
529 DbTaskRunner.finishSelectOrCountPrepareStatement(countInitOkStep,
530 limitDate);
531 nbCountInitOkStep =
532 DbTaskRunner.getResultCountPrepareStatement(countInitOkStep);
533 DbTaskRunner.finishSelectOrCountPrepareStatement(
534 countPreProcessingOkStep, limitDate);
535 nbCountPreProcessingOkStep =
536 DbTaskRunner.getResultCountPrepareStatement(
537 countPreProcessingOkStep);
538 DbTaskRunner.finishSelectOrCountPrepareStatement(
539 countTransferOkStep, limitDate);
540 nbCountTransferOkStep = DbTaskRunner.getResultCountPrepareStatement(
541 countTransferOkStep);
542 DbTaskRunner.finishSelectOrCountPrepareStatement(
543 countPostProcessingOkStep, limitDate);
544 nbCountPostProcessingOkStep =
545 DbTaskRunner.getResultCountPrepareStatement(
546 countPostProcessingOkStep);
547 DbTaskRunner.finishSelectOrCountPrepareStatement(
548 countCompleteOkStep, limitDate);
549 nbCountCompleteOkStep = DbTaskRunner.getResultCountPrepareStatement(
550 countCompleteOkStep);
551
552
553 nbCountStatusConnectionImpossible =
554 DbTaskRunner.getResultCountPrepareStatement(countStatus,
555 ErrorCode.ConnectionImpossible,
556 limitDate);
557 nbCountStatusServerOverloaded =
558 DbTaskRunner.getResultCountPrepareStatement(countStatus,
559 ErrorCode.ServerOverloaded,
560 limitDate);
561 nbCountStatusBadAuthent =
562 DbTaskRunner.getResultCountPrepareStatement(countStatus,
563 ErrorCode.BadAuthent,
564 limitDate);
565 nbCountStatusExternalOp =
566 DbTaskRunner.getResultCountPrepareStatement(countStatus,
567 ErrorCode.ExternalOp,
568 limitDate);
569 nbCountStatusTransferError =
570 DbTaskRunner.getResultCountPrepareStatement(countStatus,
571 ErrorCode.TransferError,
572 limitDate);
573 nbCountStatusMD5Error =
574 DbTaskRunner.getResultCountPrepareStatement(countStatus,
575 ErrorCode.MD5Error,
576 limitDate);
577 nbCountStatusDisconnection =
578 DbTaskRunner.getResultCountPrepareStatement(countStatus,
579 ErrorCode.Disconnection,
580 limitDate);
581 nbCountStatusFinalOp =
582 DbTaskRunner.getResultCountPrepareStatement(countStatus,
583 ErrorCode.FinalOp,
584 limitDate);
585 nbCountStatusUnimplemented =
586 DbTaskRunner.getResultCountPrepareStatement(countStatus,
587 ErrorCode.Unimplemented,
588 limitDate);
589 nbCountStatusInternal =
590 DbTaskRunner.getResultCountPrepareStatement(countStatus,
591 ErrorCode.Internal,
592 limitDate);
593 nbCountStatusWarning =
594 DbTaskRunner.getResultCountPrepareStatement(countStatus,
595 ErrorCode.Warning,
596 limitDate);
597 nbCountStatusQueryAlreadyFinished =
598 DbTaskRunner.getResultCountPrepareStatement(countStatus,
599 ErrorCode.QueryAlreadyFinished,
600 limitDate);
601 nbCountStatusQueryStillRunning =
602 DbTaskRunner.getResultCountPrepareStatement(countStatus,
603 ErrorCode.QueryStillRunning,
604 limitDate);
605 nbCountStatusNotKnownHost =
606 DbTaskRunner.getResultCountPrepareStatement(countStatus,
607 ErrorCode.NotKnownHost,
608 limitDate);
609 nbCountStatusQueryRemotelyUnknown =
610 DbTaskRunner.getResultCountPrepareStatement(countStatus,
611 ErrorCode.QueryRemotelyUnknown,
612 limitDate);
613 nbCountStatusCommandNotFound =
614 DbTaskRunner.getResultCountPrepareStatement(countStatus,
615 ErrorCode.CommandNotFound,
616 limitDate);
617 nbCountStatusPassThroughMode =
618 DbTaskRunner.getResultCountPrepareStatement(countStatus,
619 ErrorCode.PassThroughMode,
620 limitDate);
621 nbCountStatusRemoteShutdown =
622 DbTaskRunner.getResultCountPrepareStatement(countStatus,
623 ErrorCode.RemoteShutdown,
624 limitDate);
625 nbCountStatusShutdown =
626 DbTaskRunner.getResultCountPrepareStatement(countStatus,
627 ErrorCode.Shutdown,
628 limitDate);
629 nbCountStatusRemoteError =
630 DbTaskRunner.getResultCountPrepareStatement(countStatus,
631 ErrorCode.RemoteError,
632 limitDate);
633 nbCountStatusStopped =
634 DbTaskRunner.getResultCountPrepareStatement(countStatus,
635 ErrorCode.StoppedTransfer,
636 limitDate);
637 nbCountStatusCanceled =
638 DbTaskRunner.getResultCountPrepareStatement(countStatus,
639 ErrorCode.CanceledTransfer,
640 limitDate);
641 nbCountStatusFileNotFound =
642 DbTaskRunner.getResultCountPrepareStatement(countStatus,
643 ErrorCode.FileNotFound,
644 limitDate);
645 nbCountStatusUnknown =
646 DbTaskRunner.getResultCountPrepareStatement(countStatus,
647 ErrorCode.Unknown,
648 limitDate);
649 }
650 } catch (final WaarpDatabaseNoConnectionException ignored) {
651
652 } catch (final WaarpDatabaseSqlException ignored) {
653
654 }
655 }
656 }
657 }
658
659
660
661
662
663
664 public final String exportXml(final boolean detail) {
665 final StringBuilder builder = new StringBuilder("<STATUS>")
666
667 .append("<HostID>").append(Configuration.configuration.getHostId())
668 .append("</HostID>").append("<Date>").append(new DateTime())
669 .append("</Date>").append("<LastRun>").append(new DateTime(lastTry))
670 .append("</LastRun>").append("<FromDate>")
671 .append(new DateTime(currentLimit)).append("</FromDate>")
672 .append("<SecondsRunning>").append(secondsRunning)
673 .append("</SecondsRunning>").append("<NetworkConnections>")
674 .append(nbNetworkConnection).append("</NetworkConnections>")
675 .append("<NbThreads>").append(nbThread).append("</NbThreads>")
676 .append("<InBandwidth>").append(bandwidthIn).append("</InBandwidth>")
677 .append("<OutBandwidth>").append(bandwidthOut).append("</OutBandwidth>")
678
679
680 .append("<OVERALL>").append("<AllTransfer>")
681 .append(nbCountStepAllTransfer).append("</AllTransfer>")
682 .append("<Unknown>").append(nbCountInfoUnknown).append("</Unknown>")
683 .append("<NotUpdated>").append(nbCountInfoNotUpdated)
684 .append("</NotUpdated>").append("<Interrupted>")
685 .append(nbCountInfoInterrupted).append("</Interrupted>")
686 .append("<ToSubmit>").append(nbCountInfoToSubmit).append("</ToSubmit>")
687 .append("<Error>").append(nbCountInfoError).append("</Error>")
688 .append("<Running>").append(nbCountInfoRunning).append("</Running>")
689 .append("<Done>").append(nbCountInfoDone).append("</Done>")
690 .append("<InRunning>").append(nbInActiveTransfer).append("</InRunning>")
691 .append("<OutRunning>").append(nbOutActiveTransfer)
692 .append("</OutRunning>").append("<LastInRunning>")
693 .append(new DateTime(lastInActiveTransfer)).append("</LastInRunning>")
694 .append("<LastOutRunning>").append(new DateTime(lastOutActiveTransfer))
695 .append("</LastOutRunning>").append("<InAll>").append(nbInTotalTransfer)
696 .append("</InAll>").append("<OutAll>").append(nbOutTotalTransfer)
697 .append("</OutAll>").append("<InError>").append(nbInErrorTransfer)
698 .append("</InError>").append("<OutError>").append(nbOutErrorTransfer)
699 .append("</OutError>").append("</OVERALL>")
700
701
702 .append("<STEPS>").append("<Notask>").append(nbCountStepNotask)
703 .append("</Notask>").append("<Pretask>").append(nbCountStepPretask)
704 .append("</Pretask>").append("<Transfer>").append(nbCountStepTransfer)
705 .append("</Transfer>").append("<Posttask>").append(nbCountStepPosttask)
706 .append("</Posttask>").append("<AllDone>").append(nbCountStepAllDone)
707 .append("</AllDone>").append("<Error>").append(nbCountStepError)
708 .append("</Error>").append("</STEPS>")
709
710
711 .append("<RUNNINGSTEPS>").append("<AllRunning>")
712 .append(nbCountAllRunningStep).append("</AllRunning>");
713 if (detail) {
714 builder.append("<Running>").append(nbCountRunningStep)
715 .append("</Running>").append("<InitOk>").append(nbCountInitOkStep)
716 .append("</InitOk>").append("<PreProcessingOk>")
717 .append(nbCountPreProcessingOkStep).append("</PreProcessingOk>")
718 .append("<TransferOk>").append(nbCountTransferOkStep)
719 .append("</TransferOk>").append("<PostProcessingOk>")
720 .append(nbCountPostProcessingOkStep).append("</PostProcessingOk>")
721 .append("<CompleteOk>").append(nbCountCompleteOkStep)
722 .append("</CompleteOk>");
723 }
724 builder.append("</RUNNINGSTEPS>");
725
726 if (detail) {
727
728 builder.append("<ERRORTYPES>").append("<ConnectionImpossible>")
729 .append(nbCountStatusConnectionImpossible)
730 .append("</ConnectionImpossible>").append("<ServerOverloaded>")
731 .append(nbCountStatusServerOverloaded)
732 .append("</ServerOverloaded>").append("<BadAuthent>")
733 .append(nbCountStatusBadAuthent).append("</BadAuthent>")
734 .append("<ExternalOp>").append(nbCountStatusExternalOp)
735 .append("</ExternalOp>").append("<TransferError>")
736 .append(nbCountStatusTransferError).append("</TransferError>")
737 .append("<MD5Error>").append(nbCountStatusMD5Error)
738 .append("</MD5Error>").append("<Disconnection>")
739 .append(nbCountStatusDisconnection).append("</Disconnection>")
740 .append("<FinalOp>").append(nbCountStatusFinalOp)
741 .append("</FinalOp>").append("<Unimplemented>")
742 .append(nbCountStatusUnimplemented).append("</Unimplemented>")
743 .append("<Internal>").append(nbCountStatusInternal)
744 .append("</Internal>").append("<Warning>")
745 .append(nbCountStatusWarning).append("</Warning>")
746 .append("<QueryAlreadyFinished>")
747 .append(nbCountStatusQueryAlreadyFinished)
748 .append("</QueryAlreadyFinished>").append("<QueryStillRunning>")
749 .append(nbCountStatusQueryStillRunning)
750 .append("</QueryStillRunning>").append("<KnownHost>")
751 .append(nbCountStatusNotKnownHost).append("</KnownHost>")
752 .append("<RemotelyUnknown>")
753 .append(nbCountStatusQueryRemotelyUnknown)
754 .append("</RemotelyUnknown>").append("<CommandNotFound>")
755 .append(nbCountStatusCommandNotFound).append("</CommandNotFound>")
756 .append("<PassThroughMode>").append(nbCountStatusPassThroughMode)
757 .append("</PassThroughMode>").append("<RemoteShutdown>")
758 .append(nbCountStatusRemoteShutdown).append("</RemoteShutdown>")
759 .append("<Shutdown>").append(nbCountStatusShutdown)
760 .append("</Shutdown>").append("<RemoteError>")
761 .append(nbCountStatusRemoteError).append("</RemoteError>")
762 .append("<Stopped>").append(nbCountStatusStopped)
763 .append("</Stopped>").append("<Canceled>")
764 .append(nbCountStatusCanceled).append("</Canceled>")
765 .append("<FileNotFound>").append(nbCountStatusFileNotFound)
766 .append("</FileNotFound>").append("<Unknown>")
767 .append(nbCountStatusUnknown).append("</Unknown>")
768 .append("</ERRORTYPES>");
769 }
770 builder.append("</STATUS>");
771 return builder.toString();
772 }
773
774
775
776
777
778
779 public final String exportJson(final boolean detail) {
780 return JsonHandler.prettyPrint(exportAsJson(detail));
781 }
782
783
784
785
786
787
788 public final ObjectNode exportAsJson(final boolean detail) {
789 ObjectNode node = JsonHandler.createObjectNode();
790 node = node.putObject("STATUS");
791
792 node.put("HostID", Configuration.configuration.getHostId());
793 node.put("Date", new DateTime().toString());
794 node.put("LastRun", new DateTime(lastTry).toString());
795 node.put("FromDate", new DateTime(currentLimit).toString());
796 node.put("SecondsRunning", secondsRunning);
797 node.put("NetworkConnections", nbNetworkConnection);
798 node.put("NbThreads", nbThread);
799 node.put("InBandwidth", bandwidthIn);
800 node.put("OutBandwidth", bandwidthOut);
801
802
803 ObjectNode node2 = node.putObject("OVERALL");
804 node2.put("AllTransfer", nbCountStepAllTransfer);
805 node2.put("Unknown", nbCountInfoUnknown);
806 node2.put("NotUpdated", nbCountInfoNotUpdated);
807 node2.put("Interrupted", nbCountInfoInterrupted);
808 node2.put("ToSubmit", nbCountInfoToSubmit);
809 node2.put("Error", nbCountInfoError);
810 node2.put("Running", nbCountInfoRunning);
811 node2.put("Done", nbCountInfoDone);
812 node2.put("InRunning", nbInActiveTransfer);
813 node2.put("OutRunning", nbOutActiveTransfer);
814 node2.put("LastInRunning", new DateTime(lastInActiveTransfer).toString());
815 node2.put("LastOutRunning", new DateTime(lastOutActiveTransfer).toString());
816 node2.put("InAll", nbInTotalTransfer);
817 node2.put("OutAll", nbOutTotalTransfer);
818 node2.put("InError", nbInErrorTransfer);
819 node2.put("OutError", nbOutErrorTransfer);
820
821
822 node2 = node.putObject("STEPS");
823 node2.put("Notask", nbCountStepNotask);
824 node2.put("Pretask", nbCountStepPretask);
825 node2.put("Transfer", nbCountStepTransfer);
826 node2.put("Posttask", nbCountStepPosttask);
827 node2.put("AllDone", nbCountStepAllDone);
828 node2.put("Error", nbCountStepError);
829
830
831 node2 = node.putObject("RUNNINGSTEPS");
832 node2.put("AllRunning", nbCountAllRunningStep);
833 if (detail) {
834 node2.put("Running", nbCountRunningStep);
835 node2.put("InitOk", nbCountInitOkStep);
836 node2.put("PreProcessingOk", nbCountPreProcessingOkStep);
837 node2.put("TransferOk", nbCountTransferOkStep);
838 node2.put("PostProcessingOk", nbCountPostProcessingOkStep);
839 node2.put("CompleteOk", nbCountCompleteOkStep);
840 }
841
842 if (detail) {
843
844 node2 = node.putObject("ERRORTYPES");
845 node2.put("ConnectionImpossible", nbCountStatusConnectionImpossible);
846 node2.put("ServerOverloaded", nbCountStatusServerOverloaded);
847 node2.put("BadAuthent", nbCountStatusBadAuthent);
848 node2.put("ExternalOp", nbCountStatusExternalOp);
849 node2.put("TransferError", nbCountStatusTransferError);
850 node2.put("MD5Error", nbCountStatusMD5Error);
851 node2.put("Disconnection", nbCountStatusDisconnection);
852 node2.put("FinalOp", nbCountStatusFinalOp);
853 node2.put("Unimplemented", nbCountStatusUnimplemented);
854 node2.put("Internal", nbCountStatusInternal);
855 node2.put("Warning", nbCountStatusWarning);
856 node2.put("QueryAlreadyFinished", nbCountStatusQueryAlreadyFinished);
857 node2.put("QueryStillRunning", nbCountStatusQueryStillRunning);
858 node2.put("KnownHost", nbCountStatusNotKnownHost);
859 node2.put("RemotelyUnknown", nbCountStatusQueryRemotelyUnknown);
860 node2.put("CommandNotFound", nbCountStatusCommandNotFound);
861 node2.put("PassThroughMode", nbCountStatusPassThroughMode);
862 node2.put("RemoteShutdown", nbCountStatusRemoteShutdown);
863 node2.put("Shutdown", nbCountStatusShutdown);
864 node2.put("RemoteError", nbCountStatusRemoteError);
865 node2.put("Stopped", nbCountStatusStopped);
866 node2.put("Canceled", nbCountStatusCanceled);
867 node2.put("FileNotFound", nbCountStatusFileNotFound);
868 node2.put("Unknown", nbCountStatusUnknown);
869 }
870 return node;
871 }
872
873 @Override
874 public final void setAgent(final WaarpSnmpAgent agent) {
875 this.agent = agent;
876 lastInActiveTransfer = this.agent.getUptimeSystemTime();
877 lastOutActiveTransfer = this.agent.getUptimeSystemTime();
878 }
879
880
881
882
883
884
885
886 public final void run(final int type, final int entry) {
887 final long nbMs =
888 Configuration.configuration.getAgentSnmp().getUptime() + 100;
889 final MibLevel level = MibLevel.values()[type];
890 switch (level) {
891 case globalInfo:
892 if (((R66PrivateMib) agent.getMib()).rowGlobal != null) {
893 run(nbMs, WaarpGlobalValuesIndex.values()[entry]);
894 }
895 return;
896 case detailedInfo:
897 if (((R66PrivateMib) agent.getMib()).rowDetailed != null) {
898 run(nbMs, WaarpDetailedValuesIndex.values()[entry]);
899 }
900 return;
901 case errorInfo:
902 if (((R66PrivateMib) agent.getMib()).rowError != null) {
903 run(nbMs, WaarpErrorValuesIndex.values()[entry]);
904 }
905 return;
906 case trapInfo:
907 case staticInfo:
908 default:
909 break;
910 }
911 }
912
913
914
915
916
917
918
919 protected final void updateGlobalValue(final int rank, final long value) {
920 ((R66PrivateMib) agent.getMib()).rowGlobal.setValue(rank, value);
921 }
922
923
924
925
926
927
928
929 protected final void updateDetailedValue(final int rank, final long value) {
930 ((R66PrivateMib) agent.getMib()).rowDetailed.setValue(rank, value);
931 }
932
933
934
935
936
937
938
939 protected final void updateErrorValue(final int rank, final long value) {
940 ((R66PrivateMib) agent.getMib()).rowError.setValue(rank, value);
941 }
942
943
944
945
946
947
948
949 protected final void run(final long nbMs,
950 final WaarpGlobalValuesIndex entry) {
951 synchronized (trafficCounter) {
952 long val;
953 final long limitDate = System.currentTimeMillis() - nbMs;
954 if (dbSession == null || dbSession.isDisActive()) {
955 switch (entry) {
956 case applUptime:
957 case memoryUsed:
958 case memoryFree:
959 case memoryTotal:
960 case applLastChange:
961 case applOperStatus:
962 return;
963 case applInboundAssociations:
964 updateGlobalValue(entry.ordinal(), nbInActiveTransfer);
965 return;
966 case applOutboundAssociations:
967 updateGlobalValue(entry.ordinal(), nbOutActiveTransfer);
968 return;
969 case applAccumInboundAssociations:
970 updateGlobalValue(entry.ordinal(), nbInTotalTransfer);
971 return;
972 case applAccumOutboundAssociations:
973 updateGlobalValue(entry.ordinal(), nbOutTotalTransfer);
974 return;
975 case applLastInboundActivity:
976 val = (lastInActiveTransfer - agent.getUptimeSystemTime()) / 10;
977 if (val < 0) {
978 val = 0;
979 }
980 updateGlobalValue(entry.ordinal(), val);
981 return;
982 case applLastOutboundActivity:
983 val = (lastOutActiveTransfer - agent.getUptimeSystemTime()) / 10;
984 if (val < 0) {
985 val = 0;
986 }
987 updateGlobalValue(entry.ordinal(), val);
988 return;
989 case applRejectedInboundAssociations:
990 updateGlobalValue(entry.ordinal(), nbInErrorTransfer);
991 return;
992 case applFailedOutboundAssociations:
993 updateGlobalValue(entry.ordinal(), nbOutErrorTransfer);
994 return;
995 case applInboundBandwidthKBS:
996 val = trafficCounter.lastReadThroughput() >> 10;
997 updateGlobalValue(entry.ordinal(), val);
998 return;
999 case applOutboundBandwidthKBS:
1000 val = trafficCounter.lastWriteThroughput() >> 10;
1001 updateGlobalValue(entry.ordinal(), val);
1002 return;
1003 case nbInfoUnknown:
1004 updateGlobalValue(entry.ordinal(), nbCountInfoUnknown);
1005 return;
1006 case nbInfoNotUpdated:
1007 updateGlobalValue(entry.ordinal(), nbCountInfoNotUpdated);
1008 return;
1009 case nbInfoInterrupted:
1010 updateGlobalValue(entry.ordinal(), nbCountInfoInterrupted);
1011 return;
1012 case nbInfoToSubmit:
1013 nbCountInfoToSubmit = CommanderNoDb.todoList.size();
1014 updateGlobalValue(entry.ordinal(), nbCountInfoToSubmit);
1015 return;
1016 case nbInfoError:
1017 updateGlobalValue(entry.ordinal(), nbCountInfoError);
1018 return;
1019 case nbInfoRunning:
1020 nbCountInfoRunning = Configuration.configuration.getInternalRunner()
1021 .nbInternalRunner();
1022 updateGlobalValue(entry.ordinal(), nbCountInfoRunning);
1023 return;
1024 case nbInfoDone:
1025 updateGlobalValue(entry.ordinal(), nbCountInfoDone);
1026 return;
1027 case nbStepAllTransfer:
1028 updateGlobalValue(entry.ordinal(), nbCountStepAllTransfer);
1029 return;
1030 case nbThreads:
1031 nbThread = Thread.activeCount();
1032 updateGlobalValue(entry.ordinal(), nbThread);
1033 return;
1034 case nbNetworkConnection:
1035 nbNetworkConnection =
1036 ChannelUtils.nbCommandChannels(Configuration.configuration);
1037 updateGlobalValue(entry.ordinal(), nbNetworkConnection);
1038 return;
1039 }
1040 return;
1041 }
1042
1043 try {
1044 switch (entry) {
1045 case applUptime:
1046 case memoryUsed:
1047 case memoryFree:
1048 case memoryTotal:
1049 case applLastChange:
1050 case applOperStatus:
1051 return;
1052 case applInboundAssociations:
1053 DbTaskRunner.finishSelectOrCountPrepareStatement(
1054 countInActiveTransfer, limitDate);
1055 nbInActiveTransfer = DbTaskRunner.getResultCountPrepareStatement(
1056 countInActiveTransfer);
1057 updateGlobalValue(entry.ordinal(), nbInActiveTransfer);
1058 return;
1059 case applOutboundAssociations:
1060 DbTaskRunner.finishSelectOrCountPrepareStatement(
1061 countOutActiveTransfer, limitDate);
1062 nbOutActiveTransfer = DbTaskRunner.getResultCountPrepareStatement(
1063 countOutActiveTransfer);
1064 updateGlobalValue(entry.ordinal(), nbOutActiveTransfer);
1065 return;
1066 case applAccumInboundAssociations:
1067 DbTaskRunner.finishSelectOrCountPrepareStatement(
1068 countInTotalTransfer, limitDate);
1069 nbInTotalTransfer = DbTaskRunner.getResultCountPrepareStatement(
1070 countInTotalTransfer);
1071 updateGlobalValue(entry.ordinal(), nbInTotalTransfer);
1072 return;
1073 case applAccumOutboundAssociations:
1074 DbTaskRunner.finishSelectOrCountPrepareStatement(
1075 countOutTotalTransfer, limitDate);
1076 nbOutTotalTransfer = DbTaskRunner.getResultCountPrepareStatement(
1077 countOutTotalTransfer);
1078 updateGlobalValue(entry.ordinal(), nbOutTotalTransfer);
1079 return;
1080 case applLastInboundActivity:
1081 val = (lastInActiveTransfer - agent.getUptimeSystemTime()) / 10;
1082 if (val < 0) {
1083 val = 0;
1084 }
1085 updateGlobalValue(entry.ordinal(), val);
1086 return;
1087 case applLastOutboundActivity:
1088 val = (lastOutActiveTransfer - agent.getUptimeSystemTime()) / 10;
1089 if (val < 0) {
1090 val = 0;
1091 }
1092 updateGlobalValue(entry.ordinal(), val);
1093 return;
1094 case applRejectedInboundAssociations:
1095 DbTaskRunner.finishSelectOrCountPrepareStatement(
1096 countInErrorTransfer, limitDate);
1097 nbInErrorTransfer = DbTaskRunner.getResultCountPrepareStatement(
1098 countInErrorTransfer);
1099 updateGlobalValue(entry.ordinal(), nbInErrorTransfer);
1100 return;
1101 case applFailedOutboundAssociations:
1102 DbTaskRunner.finishSelectOrCountPrepareStatement(
1103 countOutErrorTransfer, limitDate);
1104 nbOutErrorTransfer = DbTaskRunner.getResultCountPrepareStatement(
1105 countOutErrorTransfer);
1106 updateGlobalValue(entry.ordinal(), nbOutErrorTransfer);
1107 return;
1108 case applInboundBandwidthKBS:
1109 val = trafficCounter.lastReadThroughput() >> 10;
1110 updateGlobalValue(entry.ordinal(), val);
1111 return;
1112 case applOutboundBandwidthKBS:
1113 val = trafficCounter.lastWriteThroughput() >> 10;
1114 updateGlobalValue(entry.ordinal(), val);
1115 return;
1116 case nbInfoUnknown:
1117 nbCountInfoUnknown =
1118 DbTaskRunner.getResultCountPrepareStatement(countInfo,
1119 UpdatedInfo.UNKNOWN,
1120 limitDate);
1121 updateGlobalValue(entry.ordinal(), nbCountInfoUnknown);
1122 return;
1123 case nbInfoNotUpdated:
1124 nbCountInfoNotUpdated =
1125 DbTaskRunner.getResultCountPrepareStatement(countInfo,
1126 UpdatedInfo.NOTUPDATED,
1127 limitDate);
1128 updateGlobalValue(entry.ordinal(), nbCountInfoNotUpdated);
1129 return;
1130 case nbInfoInterrupted:
1131 nbCountInfoInterrupted =
1132 DbTaskRunner.getResultCountPrepareStatement(countInfo,
1133 UpdatedInfo.INTERRUPTED,
1134 limitDate);
1135 updateGlobalValue(entry.ordinal(), nbCountInfoInterrupted);
1136 return;
1137 case nbInfoToSubmit:
1138 nbCountInfoToSubmit =
1139 DbTaskRunner.getResultCountPrepareStatement(countInfo,
1140 UpdatedInfo.TOSUBMIT,
1141 limitDate);
1142 updateGlobalValue(entry.ordinal(), nbCountInfoToSubmit);
1143 return;
1144 case nbInfoError:
1145 nbCountInfoError =
1146 DbTaskRunner.getResultCountPrepareStatement(countInfo,
1147 UpdatedInfo.INERROR,
1148 limitDate);
1149 updateGlobalValue(entry.ordinal(), nbCountInfoError);
1150 return;
1151 case nbInfoRunning:
1152 nbCountInfoRunning =
1153 DbTaskRunner.getResultCountPrepareStatement(countInfo,
1154 UpdatedInfo.RUNNING,
1155 limitDate);
1156 updateGlobalValue(entry.ordinal(), nbCountInfoRunning);
1157 return;
1158 case nbInfoDone:
1159 nbCountInfoDone =
1160 DbTaskRunner.getResultCountPrepareStatement(countInfo,
1161 UpdatedInfo.DONE,
1162 limitDate);
1163 updateGlobalValue(entry.ordinal(), nbCountInfoDone);
1164 return;
1165 case nbStepAllTransfer:
1166 DbTaskRunner.finishSelectOrCountPrepareStatement(
1167 countStepAllTransfer, limitDate);
1168 nbCountStepAllTransfer =
1169 DbTaskRunner.getResultCountPrepareStatement(
1170 countStepAllTransfer);
1171 updateGlobalValue(entry.ordinal(), nbCountStepAllTransfer);
1172 return;
1173 case nbThreads:
1174 nbThread = Thread.activeCount();
1175 updateGlobalValue(entry.ordinal(), nbThread);
1176 return;
1177 case nbNetworkConnection:
1178 nbNetworkConnection = DbAdmin.getNbConnection();
1179 updateGlobalValue(entry.ordinal(), nbNetworkConnection);
1180 }
1181 } catch (final WaarpDatabaseNoConnectionException ignored) {
1182
1183 } catch (final WaarpDatabaseSqlException ignored) {
1184
1185 }
1186 }
1187 }
1188
1189
1190
1191
1192
1193
1194
1195 protected final void run(final long nbMs,
1196 final WaarpDetailedValuesIndex entry) {
1197 synchronized (trafficCounter) {
1198 final long limitDate = System.currentTimeMillis() - nbMs;
1199 if (dbSession == null || dbSession.isDisActive()) {
1200 switch (entry) {
1201 case nbStepNotask:
1202 updateDetailedValue(entry.ordinal(), nbCountStepNotask);
1203 return;
1204 case nbStepPretask:
1205 updateDetailedValue(entry.ordinal(), nbCountStepPretask);
1206 return;
1207 case nbStepTransfer:
1208 updateDetailedValue(entry.ordinal(), nbCountStepTransfer);
1209 return;
1210 case nbStepPosttask:
1211 updateDetailedValue(entry.ordinal(), nbCountStepPosttask);
1212 return;
1213 case nbStepAllDone:
1214 updateDetailedValue(entry.ordinal(), nbCountStepAllDone);
1215 return;
1216 case nbStepError:
1217 updateDetailedValue(entry.ordinal(), nbCountStepError);
1218 return;
1219 case nbAllRunningStep:
1220 nbCountAllRunningStep =
1221 Configuration.configuration.getInternalRunner()
1222 .nbInternalRunner();
1223 updateDetailedValue(entry.ordinal(), nbCountAllRunningStep);
1224 return;
1225 case nbRunningStep:
1226 updateDetailedValue(entry.ordinal(), nbCountRunningStep);
1227 return;
1228 case nbInitOkStep:
1229 updateDetailedValue(entry.ordinal(), nbCountInitOkStep);
1230 return;
1231 case nbPreProcessingOkStep:
1232 updateDetailedValue(entry.ordinal(), nbCountPreProcessingOkStep);
1233 return;
1234 case nbTransferOkStep:
1235 updateDetailedValue(entry.ordinal(), nbCountTransferOkStep);
1236 return;
1237 case nbPostProcessingOkStep:
1238 updateDetailedValue(entry.ordinal(), nbCountPostProcessingOkStep);
1239 return;
1240 case nbCompleteOkStep:
1241 updateDetailedValue(entry.ordinal(), nbCountCompleteOkStep);
1242 return;
1243 }
1244 return;
1245 }
1246
1247 try {
1248 switch (entry) {
1249 case nbStepNotask:
1250 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepNotask,
1251 limitDate);
1252 nbCountStepNotask =
1253 DbTaskRunner.getResultCountPrepareStatement(countStepNotask);
1254 updateDetailedValue(entry.ordinal(), nbCountStepNotask);
1255 return;
1256 case nbStepPretask:
1257 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepPretask,
1258 limitDate);
1259 nbCountStepPretask =
1260 DbTaskRunner.getResultCountPrepareStatement(countStepPretask);
1261 updateDetailedValue(entry.ordinal(), nbCountStepPretask);
1262 return;
1263 case nbStepTransfer:
1264 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepTransfer,
1265 limitDate);
1266 nbCountStepTransfer =
1267 DbTaskRunner.getResultCountPrepareStatement(countStepTransfer);
1268 updateDetailedValue(entry.ordinal(), nbCountStepTransfer);
1269 return;
1270 case nbStepPosttask:
1271 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepPosttask,
1272 limitDate);
1273 nbCountStepPosttask =
1274 DbTaskRunner.getResultCountPrepareStatement(countStepPosttask);
1275 updateDetailedValue(entry.ordinal(), nbCountStepPosttask);
1276 return;
1277 case nbStepAllDone:
1278 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepAllDone,
1279 limitDate);
1280 nbCountStepAllDone =
1281 DbTaskRunner.getResultCountPrepareStatement(countStepAllDone);
1282 updateDetailedValue(entry.ordinal(), nbCountStepAllDone);
1283 return;
1284 case nbStepError:
1285 DbTaskRunner.finishSelectOrCountPrepareStatement(countStepError,
1286 limitDate);
1287 nbCountStepError =
1288 DbTaskRunner.getResultCountPrepareStatement(countStepError);
1289 updateDetailedValue(entry.ordinal(), nbCountStepError);
1290 return;
1291 case nbAllRunningStep:
1292 DbTaskRunner.finishSelectOrCountPrepareStatement(
1293 countAllRunningStep, limitDate);
1294 nbCountAllRunningStep = DbTaskRunner.getResultCountPrepareStatement(
1295 countAllRunningStep);
1296 updateDetailedValue(entry.ordinal(), nbCountAllRunningStep);
1297 return;
1298 case nbRunningStep:
1299 DbTaskRunner.finishSelectOrCountPrepareStatement(countRunningStep,
1300 limitDate);
1301 nbCountRunningStep =
1302 DbTaskRunner.getResultCountPrepareStatement(countRunningStep);
1303 updateDetailedValue(entry.ordinal(), nbCountRunningStep);
1304 return;
1305 case nbInitOkStep:
1306 DbTaskRunner.finishSelectOrCountPrepareStatement(countInitOkStep,
1307 limitDate);
1308 nbCountInitOkStep =
1309 DbTaskRunner.getResultCountPrepareStatement(countInitOkStep);
1310 updateDetailedValue(entry.ordinal(), nbCountInitOkStep);
1311 return;
1312 case nbPreProcessingOkStep:
1313 DbTaskRunner.finishSelectOrCountPrepareStatement(
1314 countPreProcessingOkStep, limitDate);
1315 nbCountPreProcessingOkStep =
1316 DbTaskRunner.getResultCountPrepareStatement(
1317 countPreProcessingOkStep);
1318 updateDetailedValue(entry.ordinal(), nbCountPreProcessingOkStep);
1319 return;
1320 case nbTransferOkStep:
1321 DbTaskRunner.finishSelectOrCountPrepareStatement(
1322 countTransferOkStep, limitDate);
1323 nbCountTransferOkStep = DbTaskRunner.getResultCountPrepareStatement(
1324 countTransferOkStep);
1325 updateDetailedValue(entry.ordinal(), nbCountTransferOkStep);
1326 return;
1327 case nbPostProcessingOkStep:
1328 DbTaskRunner.finishSelectOrCountPrepareStatement(
1329 countPostProcessingOkStep, limitDate);
1330 nbCountPostProcessingOkStep =
1331 DbTaskRunner.getResultCountPrepareStatement(
1332 countPostProcessingOkStep);
1333 updateDetailedValue(entry.ordinal(), nbCountPostProcessingOkStep);
1334 return;
1335 case nbCompleteOkStep:
1336 DbTaskRunner.finishSelectOrCountPrepareStatement(
1337 countCompleteOkStep, limitDate);
1338 nbCountCompleteOkStep = DbTaskRunner.getResultCountPrepareStatement(
1339 countCompleteOkStep);
1340 updateDetailedValue(entry.ordinal(), nbCountCompleteOkStep);
1341 }
1342 } catch (final WaarpDatabaseNoConnectionException e) {
1343 logger.info("Database No Connection Error: Cannot execute Monitoring",
1344 e);
1345 try {
1346 dbSession.getAdmin().getDbModel().validConnection(dbSession);
1347 } catch (final WaarpDatabaseNoConnectionException ignored) {
1348
1349 }
1350 } catch (final WaarpDatabaseSqlException e) {
1351 logger.info("Database No Connection Error: Cannot execute Monitoring",
1352 e);
1353 try {
1354 dbSession.getAdmin().getDbModel().validConnection(dbSession);
1355 } catch (final WaarpDatabaseNoConnectionException ignored) {
1356
1357 }
1358 }
1359 }
1360 }
1361
1362
1363
1364
1365
1366
1367
1368 protected final void run(final long nbMs, final WaarpErrorValuesIndex entry) {
1369 synchronized (trafficCounter) {
1370 final long limitDate = System.currentTimeMillis() - nbMs;
1371 if (dbSession == null || dbSession.isDisActive()) {
1372 return;
1373 }
1374
1375 switch (entry) {
1376 case nbStatusConnectionImpossible:
1377 nbCountStatusConnectionImpossible =
1378 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1379 ErrorCode.ConnectionImpossible,
1380 limitDate);
1381 updateErrorValue(entry.ordinal(), nbCountStatusConnectionImpossible);
1382 return;
1383 case nbStatusServerOverloaded:
1384 nbCountStatusServerOverloaded =
1385 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1386 ErrorCode.ServerOverloaded,
1387 limitDate);
1388 updateErrorValue(entry.ordinal(), nbCountStatusServerOverloaded);
1389 return;
1390 case nbStatusBadAuthent:
1391 nbCountStatusBadAuthent =
1392 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1393 ErrorCode.BadAuthent,
1394 limitDate);
1395 updateErrorValue(entry.ordinal(), nbCountStatusBadAuthent);
1396 return;
1397 case nbStatusExternalOp:
1398 nbCountStatusExternalOp =
1399 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1400 ErrorCode.ExternalOp,
1401 limitDate);
1402 updateErrorValue(entry.ordinal(), nbCountStatusExternalOp);
1403 return;
1404 case nbStatusTransferError:
1405 nbCountStatusTransferError =
1406 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1407 ErrorCode.TransferError,
1408 limitDate);
1409 updateErrorValue(entry.ordinal(), nbCountStatusTransferError);
1410 return;
1411 case nbStatusMD5Error:
1412 nbCountStatusMD5Error =
1413 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1414 ErrorCode.MD5Error,
1415 limitDate);
1416 updateErrorValue(entry.ordinal(), nbCountStatusMD5Error);
1417 return;
1418 case nbStatusDisconnection:
1419 nbCountStatusDisconnection =
1420 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1421 ErrorCode.Disconnection,
1422 limitDate);
1423 updateErrorValue(entry.ordinal(), nbCountStatusDisconnection);
1424 return;
1425 case nbStatusFinalOp:
1426 nbCountStatusFinalOp =
1427 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1428 ErrorCode.FinalOp,
1429 limitDate);
1430 updateErrorValue(entry.ordinal(), nbCountStatusFinalOp);
1431 return;
1432 case nbStatusUnimplemented:
1433 nbCountStatusUnimplemented =
1434 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1435 ErrorCode.Unimplemented,
1436 limitDate);
1437 updateErrorValue(entry.ordinal(), nbCountStatusUnimplemented);
1438 return;
1439 case nbStatusInternal:
1440 nbCountStatusInternal =
1441 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1442 ErrorCode.Internal,
1443 limitDate);
1444 updateErrorValue(entry.ordinal(), nbCountStatusInternal);
1445 return;
1446 case nbStatusWarning:
1447 nbCountStatusWarning =
1448 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1449 ErrorCode.Warning,
1450 limitDate);
1451 updateErrorValue(entry.ordinal(), nbCountStatusWarning);
1452 return;
1453 case nbStatusQueryAlreadyFinished:
1454 nbCountStatusQueryAlreadyFinished =
1455 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1456 ErrorCode.QueryAlreadyFinished,
1457 limitDate);
1458 updateErrorValue(entry.ordinal(), nbCountStatusQueryAlreadyFinished);
1459 return;
1460 case nbStatusQueryStillRunning:
1461 nbCountStatusQueryStillRunning =
1462 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1463 ErrorCode.QueryStillRunning,
1464 limitDate);
1465 updateErrorValue(entry.ordinal(), nbCountStatusQueryStillRunning);
1466 return;
1467 case nbStatusNotKnownHost:
1468 nbCountStatusNotKnownHost =
1469 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1470 ErrorCode.NotKnownHost,
1471 limitDate);
1472 updateErrorValue(entry.ordinal(), nbCountStatusNotKnownHost);
1473 return;
1474 case nbStatusQueryRemotelyUnknown:
1475 nbCountStatusQueryRemotelyUnknown =
1476 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1477 ErrorCode.QueryRemotelyUnknown,
1478 limitDate);
1479 updateErrorValue(entry.ordinal(), nbCountStatusQueryRemotelyUnknown);
1480 return;
1481 case nbStatusCommandNotFound:
1482 nbCountStatusCommandNotFound =
1483 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1484 ErrorCode.CommandNotFound,
1485 limitDate);
1486 updateErrorValue(entry.ordinal(), nbCountStatusCommandNotFound);
1487 return;
1488 case nbStatusPassThroughMode:
1489 nbCountStatusPassThroughMode =
1490 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1491 ErrorCode.PassThroughMode,
1492 limitDate);
1493 updateErrorValue(entry.ordinal(), nbCountStatusPassThroughMode);
1494 return;
1495 case nbStatusRemoteShutdown:
1496 nbCountStatusRemoteShutdown =
1497 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1498 ErrorCode.RemoteShutdown,
1499 limitDate);
1500 updateErrorValue(entry.ordinal(), nbCountStatusRemoteShutdown);
1501 return;
1502 case nbStatusShutdown:
1503 nbCountStatusShutdown =
1504 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1505 ErrorCode.Shutdown,
1506 limitDate);
1507 updateErrorValue(entry.ordinal(), nbCountStatusShutdown);
1508 return;
1509 case nbStatusRemoteError:
1510 nbCountStatusRemoteError =
1511 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1512 ErrorCode.RemoteError,
1513 limitDate);
1514 updateErrorValue(entry.ordinal(), nbCountStatusRemoteError);
1515 return;
1516 case nbStatusStopped:
1517 nbCountStatusStopped =
1518 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1519 ErrorCode.StoppedTransfer,
1520 limitDate);
1521 updateErrorValue(entry.ordinal(), nbCountStatusStopped);
1522 return;
1523 case nbStatusCanceled:
1524 nbCountStatusCanceled =
1525 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1526 ErrorCode.CanceledTransfer,
1527 limitDate);
1528 updateErrorValue(entry.ordinal(), nbCountStatusCanceled);
1529 return;
1530 case nbStatusFileNotFound:
1531 nbCountStatusFileNotFound =
1532 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1533 ErrorCode.FileNotFound,
1534 limitDate);
1535 updateErrorValue(entry.ordinal(), nbCountStatusFileNotFound);
1536 return;
1537 case nbStatusUnknown:
1538 nbCountStatusUnknown =
1539 DbTaskRunner.getResultCountPrepareStatement(countStatus,
1540 ErrorCode.Unknown,
1541 limitDate);
1542 updateErrorValue(entry.ordinal(), nbCountStatusUnknown);
1543 }
1544 }
1545 }
1546 }