1 /*
2 * This file is part of Waarp Project (named also Waarp or GG).
3 *
4 * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5 * tags. See the COPYRIGHT.txt in the distribution for a full listing of
6 * individual contributors.
7 *
8 * All Waarp Project is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * Waarp . If not, see <http://www.gnu.org/licenses/>.
19 */
20 package org.waarp.openr66.context.task;
21
22 import org.waarp.common.command.exception.CommandAbstractException;
23 import org.waarp.common.database.exception.WaarpDatabaseException;
24 import org.waarp.openr66.context.R66Session;
25 import org.waarp.openr66.protocol.exception.OpenR66ProtocolNetworkException;
26 import org.waarp.openr66.s3.WaarpR66S3Client;
27 import org.waarp.openr66.s3.taskfactory.S3TaskFactory;
28 import org.waarp.openr66.s3.taskfactory.S3TaskFactory.S3TaskType;
29
30 /**
31 * S3 GET and DELETE Task<br>
32 * <br>
33 * The Rule shall be using SENDMD5THROUGHMODE or SENDTHROUGHMODE mode
34 * (respectively 7 or 5) or RECVMD5THROUGHMODE or RECVTHROUGHMODE mode
35 * (respectively 8 or 6) as pre-tasks since the file does not exist at
36 * startup.<br>
37 * <p>
38 * Result of arguments will be as a S3 GET command.<br>
39 * Format is the following:<br>
40 * "-URL url of S3 service <br>
41 * -accessKey access Key for S3 service <br>
42 * -secretKey secret Key for S3 service <br>
43 * -bucketName bucket Name where to retrieve the object <br>
44 * -sourceName source Name from the bucket to select the final Object <br>
45 * -file final File path (absolute or relative from IN path) <br>
46 * [-getTags [* or list of tag names comma separated without space]]" <br>
47 * <br>
48 * <br>
49 * The order of actions will be:<br>
50 * 1) connection to S3 service using access Key and Secret Key<br>
51 * 2) Retrieve from the bucket the source Object and store it in the file specified<br>
52 * 3) if getTags is true, the informations are added to transferInfo and fileInfo<br>
53 * 4) the current File is set to this new GET file<br>
54 * 5) the sender send an update on file information (name and size)<br>
55 * 6) the remote S3 Object is deleted<br>
56 */
57 public class S3GetAndDeleteTask extends S3GetTask {
58 private static final S3TaskFactory.S3TaskType taskType =
59 S3TaskFactory.S3TaskType.S3GETDELETE;
60
61 /**
62 * Constructor
63 *
64 * @param argRule
65 * @param delay
66 * @param argTransfer
67 * @param session
68 */
69 public S3GetAndDeleteTask(final String argRule, final int delay,
70 final String argTransfer,
71 final R66Session session) {
72 super(argRule, delay, argTransfer, session);
73 }
74
75 /**
76 * The order of actions will be:<br>
77 * 1) connection to S3 service using access Key and Secret Key<br>
78 * 2) Retrieve from the bucket the source Object and store it in the file specified<br>
79 * 3) if getTags is true, the informations are added to transferInfo and fileInfo<br>
80 * 4) the current File is set to this new GET file<br>
81 * 5) the sender send an update on file information (name and size)<br>
82 * 6) the remote S3 Object is deleted<br>
83 */
84 @Override
85 public void run() {
86 try {
87 internalRun();
88 final WaarpR66S3Client s3Client =
89 new WaarpR66S3Client(taskUtil.getAccessKey(), taskUtil.getSecretKey(),
90 taskUtil.getUrl());
91 s3Client.deleteFile(taskUtil.getBucketName(), taskUtil.getSourceName());
92 // The update will be done after PRE task done
93 logger.debug("GET and DELETED {}", taskUtil.getSourceName());
94 futureCompletion.setSuccess();
95 } catch (final OpenR66ProtocolNetworkException | CommandAbstractException |
96 WaarpDatabaseException e) {
97 finalizeInError(e, "Error while S3 Action");
98 }
99 }
100
101 @Override
102 public final S3TaskType getS3TaskType() {
103 return taskType;
104 }
105 }