提交 39562691 编写于 作者: Z zhangminglei 提交者: zentol

[FLINK-6655] Add validateAndNormalizeUri method to MemoryArchivist

This closes #4156.
上级 3f0ac26e
......@@ -18,13 +18,14 @@
package org.apache.flink.runtime.jobmanager
import java.io.IOException
import java.net.URI
import java.util
import akka.actor.ActorRef
import grizzled.slf4j.Logger
import org.apache.flink.api.common.JobID
import org.apache.flink.configuration.Configuration
import org.apache.flink.core.fs.Path
import org.apache.flink.core.fs.{FileSystem, Path}
import org.apache.flink.runtime.jobgraph.JobStatus
import org.apache.flink.runtime.messages.accumulators._
import org.apache.flink.runtime.webmonitor.WebMonitorUtils
......@@ -34,7 +35,6 @@ import org.apache.flink.runtime.executiongraph.{ArchivedExecutionGraph, Executio
import org.apache.flink.runtime.history.FsJobArchivist
import org.apache.flink.runtime.messages.ArchiveMessages._
import org.apache.flink.runtime.messages.JobManagerMessages._
import org.apache.flink.runtime.state.filesystem.FsStateBackend
import scala.collection.mutable
import scala.concurrent.future
......@@ -198,7 +198,7 @@ class MemoryArchivist(
// so we aren't archiving it yet.
if (archivePath.isDefined && graph.getState.isGloballyTerminalState) {
try {
val p = FsStateBackend.validateAndNormalizeUri(archivePath.get.toUri)
val p = validateAndNormalizeUri(archivePath.get.toUri)
future {
try {
FsJobArchivist.archiveJob(p, graph)
......@@ -255,4 +255,48 @@ class MemoryArchivist(
graphs.remove(jobID)
}
}
/**
* Checks and normalizes the archive path URI. This method first checks the validity of the
* URI (scheme, path, availability of a matching file system) and then normalizes the URL
* to a path.
*
* If the URI does not include an authority, but the file system configured for the URI has an
* authority, then the normalized path will include this authority.
*
* @param archivePathUri The URI to check and normalize.
* @return a normalized URI as a Path.
*
* @throws IllegalArgumentException Thrown, if the URI misses schema or path.
* @throws IOException Thrown, if no file system can be found for the URI's scheme.
*/
@throws[IOException]
private def validateAndNormalizeUri(archivePathUri: URI): Path = {
val scheme = archivePathUri.getScheme
val path = archivePathUri.getPath
// some validity checks
if (scheme == null) {
throw new IllegalArgumentException("The scheme (hdfs://, file://, etc) is null. " +
"Please specify the file system scheme explicitly in the URI: " + archivePathUri)
}
if (path == null) {
throw new IllegalArgumentException("The path to store the job archives is null. " +
"Please specify a directory path for storing job archives. and the URI is: " +
archivePathUri)
}
if (path.length == 0 || path == "/") {
throw new IllegalArgumentException("Cannot use the root directory for storing job archives.")
}
if (!FileSystem.isFlinkSupportedScheme(archivePathUri.getScheme)) {
// skip verification checks for non-flink supported filesystem
// this is because the required filesystem classes may not be available to the flink client
throw new IllegalArgumentException("No file system found with scheme " + scheme
+ ", referenced in file URI '" + archivePathUri.toString + "'.")
}
new Path(archivePathUri)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册