use of org.apache.flink.client.program.ContextEnvironment in project flink by apache.
the class StreamExecutionEnvironmentTest method testDefaultParallelismIsDefault.
@Test
public void testDefaultParallelismIsDefault() {
assertEquals(ExecutionConfig.PARALLELISM_DEFAULT, StreamExecutionEnvironment.createLocalEnvironment().getParallelism());
assertEquals(ExecutionConfig.PARALLELISM_DEFAULT, StreamExecutionEnvironment.createRemoteEnvironment("dummy", 1234).getParallelism());
StreamExecutionEnvironment contextEnv = new StreamContextEnvironment(new ContextEnvironment(mock(ClusterClient.class), Collections.<URL>emptyList(), Collections.<URL>emptyList(), this.getClass().getClassLoader(), null));
assertEquals(ExecutionConfig.PARALLELISM_DEFAULT, contextEnv.getParallelism());
}
use of org.apache.flink.client.program.ContextEnvironment in project flink by apache.
the class FlinkSubmitter method submitTopology.
/**
* Submits a topology to run on the cluster. A topology runs forever or until explicitly killed. The given {@link
* FlinkProgressListener} is ignored because progress bars are not supported by Flink.
*
* @param name
* the name of the storm.
* @param stormConf
* the topology-specific configuration. See {@link Config}.
* @param topology
* the processing to execute.
* @throws AlreadyAliveException
* if a topology with this name is already running
* @throws InvalidTopologyException
* if an invalid topology was submitted
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void submitTopology(final String name, final Map stormConf, final FlinkTopology topology) throws AlreadyAliveException, InvalidTopologyException {
if (!Utils.isValidConf(stormConf)) {
throw new IllegalArgumentException("Storm conf is not valid. Must be json-serializable");
}
final Configuration flinkConfig = GlobalConfiguration.loadConfiguration();
if (!stormConf.containsKey(Config.NIMBUS_HOST)) {
stormConf.put(Config.NIMBUS_HOST, flinkConfig.getString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, "localhost"));
}
if (!stormConf.containsKey(Config.NIMBUS_THRIFT_PORT)) {
stormConf.put(Config.NIMBUS_THRIFT_PORT, new Integer(flinkConfig.getInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, 6123)));
}
final String serConf = JSONValue.toJSONString(stormConf);
final FlinkClient client = FlinkClient.getConfiguredClient(stormConf);
try {
if (client.getTopologyJobId(name) != null) {
throw new RuntimeException("Topology with name `" + name + "` already exists on cluster");
}
String localJar = System.getProperty("storm.jar");
if (localJar == null) {
try {
for (final URL url : ((ContextEnvironment) ExecutionEnvironment.getExecutionEnvironment()).getJars()) {
// TODO verify that there is only one jar
localJar = new File(url.toURI()).getAbsolutePath();
}
} catch (final URISyntaxException e) {
// ignore
} catch (final ClassCastException e) {
// ignore
}
}
logger.info("Submitting topology " + name + " in distributed mode with conf " + serConf);
client.submitTopologyWithOpts(name, localJar, topology);
} catch (final InvalidTopologyException e) {
logger.warn("Topology submission exception: " + e.get_msg());
throw e;
} catch (final AlreadyAliveException e) {
logger.warn("Topology already alive exception", e);
throw e;
}
logger.info("Finished submitting topology: " + name);
}
Aggregations