1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.waarp.vitam.common;
22
23 import fr.gouv.vitam.access.external.client.AdminExternalClient;
24 import fr.gouv.vitam.access.external.client.AdminExternalClientFactory;
25 import fr.gouv.vitam.access.external.client.VitamPoolingClient;
26 import fr.gouv.vitam.common.exception.InvalidParseOperationException;
27 import fr.gouv.vitam.common.exception.VitamClientException;
28 import fr.gouv.vitam.common.exception.VitamException;
29 import fr.gouv.vitam.common.json.JsonHandler;
30 import org.waarp.common.logging.WaarpLogger;
31 import org.waarp.common.logging.WaarpLoggerFactory;
32 import org.waarp.vitam.dip.DipRequest;
33
34 import java.io.File;
35 import java.util.concurrent.TimeUnit;
36
37
38
39
40 public class OperationCheck {
41
42
43
44 private static final WaarpLogger logger =
45 WaarpLoggerFactory.getLogger(OperationCheck.class);
46
47 private static int retry = 3;
48 private static int delay = 100;
49 private static boolean result;
50 private final AdminExternalClient client;
51
52 public OperationCheck(AdminExternalClient client) {
53 this.client = client;
54 }
55
56
57
58
59
60
61
62 public static void setRetry(int retryToSet, int delayToSet) {
63 retry = retryToSet;
64 delay = delayToSet;
65 }
66
67
68
69
70 public static int getRetry() {
71 return retry;
72 }
73
74
75
76
77 public static int getDelay() {
78 return delay;
79 }
80
81 public static boolean getResult() {
82 return result;
83 }
84
85 public static void main(String[] args) {
86 if (args.length < 1) {
87 logger.error("{} needs 1 argument: json_request_file",
88 OperationCheck.class.getSimpleName());
89 return;
90 }
91 File file = new File(args[0]);
92 if (!file.canRead()) {
93 logger.error("{} needs 1 valid argument: json_request_file",
94 OperationCheck.class.getSimpleName());
95 result = false;
96 return;
97 }
98 DipRequest dipRequest;
99 try {
100 dipRequest = JsonHandler.getFromFile(file, DipRequest.class);
101 } catch (InvalidParseOperationException e) {
102 logger.error("{} needs 1 valid argument: json_request_file",
103 OperationCheck.class.getSimpleName());
104 result = false;
105 return;
106 }
107 try (AdminExternalClient client = AdminExternalClientFactory.getInstance()
108 .getClient()) {
109 OperationCheckperationCheck">OperationCheck operationCheck = new OperationCheck(client);
110 if (operationCheck.checkAvailabilityAtr(dipRequest.getTenantId(),
111 dipRequest.getRequestId())) {
112 logger.warn("Operation {} for tenant {} is finished",
113 dipRequest.getRequestId(), dipRequest.getTenantId());
114 result = true;
115 } else {
116 logger.warn("Operation {} for tenant {} is started or unknown",
117 dipRequest.getRequestId(), dipRequest.getTenantId());
118 result = false;
119 }
120 }
121 }
122
123
124
125
126
127
128
129
130
131 public boolean checkAvailabilityAtr(int tenantId, String requestId) {
132 try {
133 VitamPoolingClient vitamPoolingClient = new VitamPoolingClient(client);
134 return vitamPoolingClient
135 .wait(tenantId, requestId, retry, delay, TimeUnit.MILLISECONDS);
136 } catch (VitamClientException e) {
137 logger.warn(e);
138 return false;
139 } catch (VitamException e) {
140 logger.info(e);
141 return false;
142 }
143 }
144 }