-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
dora/core/common/src/main/java/alluxio/job/MoveJobRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.job; | ||
|
||
import alluxio.grpc.MoveJobPOptions; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.MoreObjects; | ||
import com.google.common.base.Preconditions; | ||
|
||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
/** | ||
* The request of moving files. | ||
*/ | ||
@ThreadSafe | ||
public class MoveJobRequest implements JobRequest { | ||
private static final String TYPE = "move"; | ||
private static final long serialVersionUID = -8565405317284410500L; | ||
private final String mDst; | ||
private final MoveJobPOptions mOptions; | ||
private final String mSrc; | ||
|
||
/** | ||
* @param src the source file path | ||
* @param dst the destination file path | ||
* @param options move job options | ||
**/ | ||
public MoveJobRequest(@JsonProperty("src") String src, | ||
@JsonProperty("dst") String dst, | ||
@JsonProperty("copyJobPOptions") MoveJobPOptions options) { | ||
mSrc = Preconditions.checkNotNull(src, "The source path cannot be null"); | ||
mDst = Preconditions.checkNotNull(dst, "The destination path cannot be null"); | ||
mOptions = Preconditions.checkNotNull(options, "The job options cannot be null"); | ||
} | ||
|
||
/** | ||
* @return the source file path | ||
*/ | ||
public String getSrc() { | ||
return mSrc; | ||
} | ||
|
||
/** | ||
* @return the file path | ||
*/ | ||
public String getDst() { | ||
return mDst; | ||
} | ||
|
||
/** | ||
* @return job options | ||
*/ | ||
public MoveJobPOptions getOptions() { | ||
return mOptions; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects | ||
.toStringHelper(this) | ||
.add("Src", mSrc) | ||
.add("Dst", mDst) | ||
.add("Options", mOptions) | ||
.toString(); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return TYPE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
dora/core/server/master/src/main/java/alluxio/master/job/MoveJobFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package alluxio.master.job; | ||
|
||
import alluxio.AlluxioURI; | ||
import alluxio.conf.Configuration; | ||
import alluxio.grpc.MoveJobPOptions; | ||
import alluxio.job.MoveJobRequest; | ||
import alluxio.master.file.DefaultFileSystemMaster; | ||
import alluxio.scheduler.job.Job; | ||
import alluxio.scheduler.job.JobFactory; | ||
import alluxio.security.User; | ||
import alluxio.security.authentication.AuthenticatedClientUser; | ||
import alluxio.underfs.UnderFileSystem; | ||
import alluxio.underfs.UnderFileSystemConfiguration; | ||
import alluxio.wire.FileInfo; | ||
|
||
import java.util.Optional; | ||
import java.util.OptionalLong; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Factory for creating {@link MoveJob}s that get file infos from master. | ||
*/ | ||
public class MoveJobFactory implements JobFactory { | ||
private final DefaultFileSystemMaster mFs; | ||
private final MoveJobRequest mRequest; | ||
|
||
/** | ||
* Create factory. | ||
* @param request copy job request | ||
* @param fsMaster file system master | ||
*/ | ||
public MoveJobFactory(MoveJobRequest request, DefaultFileSystemMaster fsMaster) { | ||
mFs = fsMaster; | ||
mRequest = request; | ||
} | ||
|
||
@Override | ||
public Job<?> create() { | ||
MoveJobPOptions options = mRequest.getOptions(); | ||
String src = mRequest.getSrc(); | ||
OptionalLong bandwidth = | ||
options.hasBandwidth() ? OptionalLong.of(options.getBandwidth()) : OptionalLong.empty(); | ||
boolean partialListing = options.hasPartialListing() && options.getPartialListing(); | ||
boolean verificationEnabled = options.hasVerify() && options.getVerify(); | ||
boolean overwrite = options.hasOverwrite() && options.getOverwrite(); | ||
boolean checkContent = options.hasCheckContent() && options.getCheckContent(); | ||
UnderFileSystem ufs = mFs.getUfsManager().getOrAdd(new AlluxioURI(src), | ||
UnderFileSystemConfiguration.defaults(Configuration.global())); | ||
Iterable<FileInfo> fileIterator = new UfsFileIterable(ufs, src, Optional | ||
.ofNullable(AuthenticatedClientUser.getOrNull()) | ||
.map(User::getName), partialListing, FileInfo::isCompleted); | ||
Optional<String> user = Optional | ||
.ofNullable(AuthenticatedClientUser.getOrNull()) | ||
.map(User::getName); | ||
return new MoveJob(src, mRequest.getDst(), overwrite, user, UUID.randomUUID().toString(), | ||
bandwidth, partialListing, verificationEnabled, checkContent, fileIterator, | ||
Optional.empty()); | ||
} | ||
} |