forked from Alluxio/alluxio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RESTful API for distributed load
Add RESTful API for distributed load. ### Usage: **SUBMIT:** description: submit a load job example: `http://localhost:28080/v1/load?path=/&opType=submit&partialListing=false&&verify=true&bandwidth=1000&loadMetadataOnly=false&verbose=true&skipIfExists=true` **STOP:** description: stop the load job example: http://localhost:28080/v1/load?path=/&opType=stop **PROGRESS:** description: get the progress of the load job example: `http://localhost:28080/v1/load?path=/&opType=progress&progressFormat=text&verbose=true` pr-link: Alluxio#18254 change-id: cid-8a2e4f6747d7ba6cb8c25032cc13ce4ec719da8f
- Loading branch information
1 parent
8e169df
commit 7c3b462
Showing
5 changed files
with
636 additions
and
12 deletions.
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
98 changes: 98 additions & 0 deletions
98
dora/core/common/src/main/java/alluxio/underfs/UfsFileStatusIterator.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,98 @@ | ||
/* | ||
* 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.underfs; | ||
|
||
import alluxio.collections.Pair; | ||
import alluxio.util.io.PathUtils; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Iterator; | ||
import java.util.LinkedList; | ||
import java.util.NoSuchElementException; | ||
|
||
/** | ||
* This base under file system status iterator is for listing files iteratively. | ||
*/ | ||
public class UfsFileStatusIterator implements Iterator<UfsStatus> { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(UfsFileStatusIterator.class); | ||
|
||
private final UnderFileSystem mUfs; | ||
|
||
private final String mPath; | ||
|
||
/** | ||
* Each element is a pair of (full path, UfsStatus). | ||
*/ | ||
private LinkedList<Pair<String, UfsStatus>> mPathsToProcess = new LinkedList<>(); | ||
|
||
/** | ||
* This base under file system status iterator is for listing files iteratively. | ||
* @param ufs the under file system | ||
* @param path the path for listing files | ||
*/ | ||
public UfsFileStatusIterator(UnderFileSystem ufs, String path) { | ||
mUfs = ufs; | ||
mPath = path; | ||
initQueue(path); | ||
} | ||
|
||
private void initQueue(String path) { | ||
try { | ||
UfsStatus[] statuses = mUfs.listStatus(path); | ||
if (statuses != null) { | ||
for (UfsStatus status : statuses) { | ||
mPathsToProcess.addFirst( | ||
new Pair<>(PathUtils.concatPath(path, status.getName()), status)); | ||
} | ||
} | ||
} catch (IOException e) { | ||
LOG.error("Failed to list files when calling listStatus", e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return !mPathsToProcess.isEmpty(); | ||
} | ||
|
||
@Override | ||
public UfsStatus next() { | ||
if (mPathsToProcess.isEmpty()) { | ||
throw new NoSuchElementException(); | ||
} | ||
final Pair<String, UfsStatus> pathToProcessPair = mPathsToProcess.remove(); | ||
final String pathToProcess = pathToProcessPair.getFirst(); | ||
UfsStatus pathStatus = pathToProcessPair.getSecond(); | ||
if (pathStatus.isFile()) { | ||
return pathStatus; | ||
} | ||
|
||
// The path is a directory, add all of its subpaths | ||
try { | ||
UfsStatus[] children = mUfs.listStatus(pathToProcess); | ||
if (children != null) { | ||
for (UfsStatus child : children) { | ||
mPathsToProcess.addFirst( | ||
new Pair<>(PathUtils.concatPath(pathToProcess, child.getName()), child)); | ||
} | ||
} | ||
} catch (IOException e) { | ||
LOG.error("Failed to list files when calling listStatus", e); | ||
throw new RuntimeException(e); | ||
} | ||
return next(); | ||
} | ||
} |
Oops, something went wrong.