forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-9818] Add cluster component command line parser
The cluster component command line parser is responsible for parsing the common command line arguments with which the cluster components are started. These include the configDir, webui-port and dynamic properties. This closes apache#6314.
- Loading branch information
1 parent
c2e0e24
commit ab9bd87
Showing
12 changed files
with
561 additions
and
26 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
56 changes: 56 additions & 0 deletions
56
.../src/main/java/org/apache/flink/runtime/entrypoint/ClusterConfigurationParserFactory.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,56 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.runtime.entrypoint; | ||
|
||
import org.apache.flink.runtime.entrypoint.parser.ParserResultFactory; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.Options; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import java.util.Properties; | ||
|
||
import static org.apache.flink.runtime.entrypoint.parser.CommandLineOptions.CONFIG_DIR_OPTION; | ||
import static org.apache.flink.runtime.entrypoint.parser.CommandLineOptions.DYNAMIC_PROPERTY_OPTION; | ||
|
||
/** | ||
* Parser factory which generates a {@link ClusterConfiguration} from the given | ||
* list of command line arguments. | ||
*/ | ||
public class ClusterConfigurationParserFactory implements ParserResultFactory<ClusterConfiguration> { | ||
|
||
@Override | ||
public Options getOptions() { | ||
final Options options = new Options(); | ||
options.addOption(CONFIG_DIR_OPTION); | ||
options.addOption(DYNAMIC_PROPERTY_OPTION); | ||
|
||
return options; | ||
} | ||
|
||
@Override | ||
public ClusterConfiguration createResult(@Nonnull CommandLine commandLine) { | ||
final String configDir = commandLine.getOptionValue(CONFIG_DIR_OPTION.getOpt()); | ||
|
||
final Properties dynamicProperties = commandLine.getOptionProperties(DYNAMIC_PROPERTY_OPTION.getOpt()); | ||
|
||
return new ClusterConfiguration(configDir, dynamicProperties, commandLine.getArgs()); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
...ime/src/main/java/org/apache/flink/runtime/entrypoint/EntrypointClusterConfiguration.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,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.runtime.entrypoint; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* Basic {@link ClusterConfiguration} for entry points. | ||
*/ | ||
public class EntrypointClusterConfiguration extends ClusterConfiguration { | ||
|
||
private final int restPort; | ||
|
||
public EntrypointClusterConfiguration(@Nonnull String configDir, @Nonnull Properties dynamicProperties, @Nonnull String[] args, int restPort) { | ||
super(configDir, dynamicProperties, args); | ||
this.restPort = restPort; | ||
} | ||
|
||
public int getRestPort() { | ||
return restPort; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...java/org/apache/flink/runtime/entrypoint/EntrypointClusterConfigurationParserFactory.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,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.runtime.entrypoint; | ||
|
||
import org.apache.flink.runtime.entrypoint.parser.ParserResultFactory; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.Options; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import java.util.Properties; | ||
|
||
import static org.apache.flink.runtime.entrypoint.parser.CommandLineOptions.CONFIG_DIR_OPTION; | ||
import static org.apache.flink.runtime.entrypoint.parser.CommandLineOptions.DYNAMIC_PROPERTY_OPTION; | ||
import static org.apache.flink.runtime.entrypoint.parser.CommandLineOptions.REST_PORT_OPTION; | ||
|
||
/** | ||
* Parser factory for {@link EntrypointClusterConfiguration}. | ||
*/ | ||
public class EntrypointClusterConfigurationParserFactory implements ParserResultFactory<EntrypointClusterConfiguration> { | ||
|
||
@Override | ||
public Options getOptions() { | ||
final Options options = new Options(); | ||
options.addOption(CONFIG_DIR_OPTION); | ||
options.addOption(REST_PORT_OPTION); | ||
options.addOption(DYNAMIC_PROPERTY_OPTION); | ||
|
||
return options; | ||
} | ||
|
||
@Override | ||
public EntrypointClusterConfiguration createResult(@Nonnull CommandLine commandLine) { | ||
final String configDir = commandLine.getOptionValue(CONFIG_DIR_OPTION.getOpt()); | ||
final Properties dynamicProperties = commandLine.getOptionProperties(DYNAMIC_PROPERTY_OPTION.getOpt()); | ||
final String restPortStr = commandLine.getOptionValue(REST_PORT_OPTION.getOpt(), "-1"); | ||
final int restPort = Integer.parseInt(restPortStr); | ||
|
||
return new EntrypointClusterConfiguration( | ||
configDir, | ||
dynamicProperties, | ||
commandLine.getArgs(), | ||
restPort); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/FlinkParseException.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,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.runtime.entrypoint; | ||
|
||
import org.apache.flink.util.FlinkException; | ||
|
||
/** | ||
* Exception which indicates that the parsing of command line | ||
* arguments failed. | ||
*/ | ||
public class FlinkParseException extends FlinkException { | ||
|
||
private static final long serialVersionUID = 5164983338744708430L; | ||
|
||
public FlinkParseException(String message) { | ||
super(message); | ||
} | ||
|
||
public FlinkParseException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public FlinkParseException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
...-runtime/src/main/java/org/apache/flink/runtime/entrypoint/parser/CommandLineOptions.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,52 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.runtime.entrypoint.parser; | ||
|
||
import org.apache.commons.cli.Option; | ||
|
||
/** | ||
* Container class for command line options. | ||
*/ | ||
public class CommandLineOptions { | ||
|
||
public static final Option CONFIG_DIR_OPTION = Option.builder("c") | ||
.longOpt("configDir") | ||
.required(true) | ||
.hasArg(true) | ||
.argName("configuration directory") | ||
.desc("Directory which contains the configuration file flink-conf.yml.") | ||
.build(); | ||
|
||
public static final Option REST_PORT_OPTION = Option.builder("r") | ||
.longOpt("webui-port") | ||
.required(false) | ||
.hasArg(true) | ||
.argName("rest port") | ||
.desc("Port for the rest endpoint and the web UI.") | ||
.build(); | ||
|
||
public static final Option DYNAMIC_PROPERTY_OPTION = Option.builder("D") | ||
.argName("property=value") | ||
.numberOfArgs(2) | ||
.valueSeparator('=') | ||
.desc("use value for given property") | ||
.build(); | ||
|
||
private CommandLineOptions() {} | ||
} |
Oops, something went wrong.