本文整理匯總了Java中org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.createLocalEnvironment方法的典型用法代碼示例。如果您正苦於以下問題:Java StreamExecutionEnvironment.createLocalEnvironment方法的具體用法?Java StreamExecutionEnvironment.createLocalEnvironment怎麽用?Java StreamExecutionEnvironment.createLocalEnvironment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.flink.streaming.api.environment.StreamExecutionEnvironment
的用法示例。
在下文中一共展示了StreamExecutionEnvironment.createLocalEnvironment方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
Properties properties = new Properties();
properties.load(new FileInputStream("src/main/resources/application.properties"));
Properties mqttProperties = new Properties();
// client id = a:<Organization_ID>:<App_Id>
mqttProperties.setProperty(MQTTSource.CLIENT_ID,
String.format("a:%s:%s",
properties.getProperty("Org_ID"),
properties.getProperty("App_Id")));
// mqtt server url = tcp://<Org_ID>.messaging.internetofthings.ibmcloud.com:1883
mqttProperties.setProperty(MQTTSource.URL,
String.format("tcp://%s.messaging.internetofthings.ibmcloud.com:1883",
properties.getProperty("Org_ID")));
// topic = iot-2/type/<Device_Type>/id/<Device_ID>/evt/<Event_Id>/fmt/json
mqttProperties.setProperty(MQTTSource.TOPIC,
String.format("iot-2/type/%s/id/%s/evt/%s/fmt/json",
properties.getProperty("Device_Type"),
properties.getProperty("Device_ID"),
properties.getProperty("EVENT_ID")));
mqttProperties.setProperty(MQTTSource.USERNAME, properties.getProperty("API_Key"));
mqttProperties.setProperty(MQTTSource.PASSWORD, properties.getProperty("APP_Authentication_Token"));
MQTTSource mqttSource = new MQTTSource(mqttProperties);
DataStreamSource<String> tempratureDataSource = env.addSource(mqttSource);
DataStream<String> stream = tempratureDataSource.map((MapFunction<String, String>) s -> s);
stream.print();
env.execute("Temperature Analysis");
}
示例2: main
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
StreamExecutionEnvironment execEnv = StreamExecutionEnvironment.createLocalEnvironment();
StreamTableEnvironment env = StreamTableEnvironment.getTableEnvironment(execEnv);
execEnv.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
CompilationResult res = new CompilationResult();
try {
JobDescriptor job = getJobConf(System.in);
res.jobGraph(new JobCompiler(env, job).getJobGraph());
} catch (Throwable e) {
res.remoteThrowable(e);
}
try (OutputStream out = chooseOutputStream(args)) {
out.write(res.serialize());
}
}
示例3: testEventTimeOrderedWriter
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
@Test
public void testEventTimeOrderedWriter() throws Exception {
StreamExecutionEnvironment execEnv = StreamExecutionEnvironment.createLocalEnvironment();
String streamName = "testEventTimeOrderedWriter";
SETUP_UTILS.createTestStream(streamName, 1);
DataStreamSource<Integer> dataStream = execEnv
.addSource(new IntegerGeneratingSource(false, EVENT_COUNT_PER_SOURCE));
FlinkPravegaWriter<Integer> pravegaSink = new FlinkPravegaWriter<>(
SETUP_UTILS.getControllerUri(),
SETUP_UTILS.getScope(),
streamName,
new IntSerializer(),
event -> "fixedkey");
FlinkPravegaUtils.writeToPravegaInEventTimeOrder(dataStream, pravegaSink, 1);
Assert.assertNotNull(execEnv.getExecutionPlan());
}
示例4: createJobGraph
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
private JobGraph createJobGraph(ExecutionMode mode) {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
env.enableCheckpointing(500, CheckpointingMode.EXACTLY_ONCE);
env.setRestartStrategy(RestartStrategies.noRestart());
env.setStateBackend(new MemoryStateBackend());
switch (mode) {
case MIGRATE:
createMigrationJob(env);
break;
case RESTORE:
createRestoredJob(env);
break;
}
return StreamingJobGraphGenerator.createJobGraph(env.getStreamGraph());
}
示例5: testNodeHashIdenticalSources
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
/**
* Tests that there are no collisions with two identical sources.
*
* <pre>
* [ (src0) ] --\
* +--> [ (sink) ]
* [ (src1) ] --/
* </pre>
*/
@Test
public void testNodeHashIdenticalSources() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
env.setParallelism(4);
env.disableOperatorChaining();
DataStream<String> src0 = env.addSource(new NoOpSourceFunction());
DataStream<String> src1 = env.addSource(new NoOpSourceFunction());
src0.union(src1).addSink(new NoOpSinkFunction());
JobGraph jobGraph = env.getStreamGraph().getJobGraph();
List<JobVertex> vertices = jobGraph.getVerticesSortedTopologicallyFromSources();
assertTrue(vertices.get(0).isInputVertex());
assertTrue(vertices.get(1).isInputVertex());
assertNotNull(vertices.get(0).getID());
assertNotNull(vertices.get(1).getID());
assertNotEquals(vertices.get(0).getID(), vertices.get(1).getID());
}
示例6: testNodeHashIdenticalNodes
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
/**
* Tests that there are no collisions with two identical intermediate nodes connected to the
* same predecessor.
*
* <pre>
* /-> [ (map) ] -> [ (sink) ]
* [ (src) ] -+
* \-> [ (map) ] -> [ (sink) ]
* </pre>
*/
@Test
public void testNodeHashIdenticalNodes() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
env.setParallelism(4);
env.disableOperatorChaining();
DataStream<String> src = env.addSource(new NoOpSourceFunction());
src.map(new NoOpMapFunction()).addSink(new NoOpSinkFunction());
src.map(new NoOpMapFunction()).addSink(new NoOpSinkFunction());
JobGraph jobGraph = env.getStreamGraph().getJobGraph();
Set<JobVertexID> vertexIds = new HashSet<>();
for (JobVertex vertex : jobGraph.getVertices()) {
assertTrue(vertexIds.add(vertex.getID()));
}
}
示例7: testChangedOperatorName
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
/**
* Tests that a changed operator name does not affect the hash.
*/
@Test
public void testChangedOperatorName() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
env.addSource(new NoOpSourceFunction(), "A").map(new NoOpMapFunction());
JobGraph jobGraph = env.getStreamGraph().getJobGraph();
JobVertexID expected = jobGraph.getVerticesAsArray()[0].getID();
env = StreamExecutionEnvironment.createLocalEnvironment();
env.addSource(new NoOpSourceFunction(), "B").map(new NoOpMapFunction());
jobGraph = env.getStreamGraph().getJobGraph();
JobVertexID actual = jobGraph.getVerticesAsArray()[0].getID();
assertEquals(expected, actual);
}
示例8: testUserProvidedHashing
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
@Test
public void testUserProvidedHashing() {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
List<String> userHashes = Arrays.asList("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
env.addSource(new NoOpSourceFunction(), "src").setUidHash(userHashes.get(0))
.map(new NoOpMapFunction())
.filter(new NoOpFilterFunction())
.keyBy(new NoOpKeySelector())
.reduce(new NoOpReduceFunction()).name("reduce").setUidHash(userHashes.get(1));
StreamGraph streamGraph = env.getStreamGraph();
int idx = 1;
for (JobVertex jobVertex : streamGraph.getJobGraph().getVertices()) {
List<JobVertexID> idAlternatives = jobVertex.getIdAlternatives();
Assert.assertEquals(idAlternatives.get(idAlternatives.size() - 1).toString(), userHashes.get(idx));
--idx;
}
}
示例9: createExecutionEnvironment
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
public StreamExecutionEnvironment createExecutionEnvironment() {
Boolean runLocally = parameters.getBoolean("run-locally", false);
StreamExecutionEnvironment environment = runLocally
? StreamExecutionEnvironment.createLocalEnvironment()
: StreamExecutionEnvironment.getExecutionEnvironment();
environment.enableCheckpointing(parameters.getLong("flink-checkpoint-interval", 10000));
environment.getCheckpointConfig().setCheckpointingMode(CheckpointingMode.EXACTLY_ONCE);
environment.getCheckpointConfig().setMaxConcurrentCheckpoints(1);
environment.getCheckpointConfig().setCheckpointTimeout(parameters.getLong("flink-checkpoint-timeout", 60000));
return environment;
}
示例10: testNodeHashAfterSourceUnchaining
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
/**
* Tests that (un)chaining affects the node hash (for sources).
*
* <pre>
* A (chained): [ (src0) -> (map) -> (filter) -> (sink) ]
* B (unchained): [ (src0) ] -> [ (map) -> (filter) -> (sink) ]
* </pre>
*
* <p>The hashes for the single vertex in A and the source vertex in B need to be different.
*/
@Test
public void testNodeHashAfterSourceUnchaining() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
env.setParallelism(4);
env.addSource(new NoOpSourceFunction())
.map(new NoOpMapFunction())
.filter(new NoOpFilterFunction())
.addSink(new NoOpSinkFunction());
JobGraph jobGraph = env.getStreamGraph().getJobGraph();
JobVertexID sourceId = jobGraph.getVerticesSortedTopologicallyFromSources()
.get(0).getID();
env = StreamExecutionEnvironment.createLocalEnvironment();
env.setParallelism(4);
env.addSource(new NoOpSourceFunction())
.map(new NoOpMapFunction())
.startNewChain()
.filter(new NoOpFilterFunction())
.addSink(new NoOpSinkFunction());
jobGraph = env.getStreamGraph().getJobGraph();
JobVertexID unchainedSourceId = jobGraph.getVerticesSortedTopologicallyFromSources()
.get(0).getID();
assertNotEquals(sourceId, unchainedSourceId);
}
示例11: testNodeHashAfterIntermediateUnchaining
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
/**
* Tests that (un)chaining affects the node hash (for intermediate nodes).
*
* <pre>
* A (chained): [ (src0) -> (map) -> (filter) -> (sink) ]
* B (unchained): [ (src0) ] -> [ (map) -> (filter) -> (sink) ]
* </pre>
*
* <p>The hashes for the single vertex in A and the source vertex in B need to be different.
*/
@Test
public void testNodeHashAfterIntermediateUnchaining() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
env.setParallelism(4);
env.addSource(new NoOpSourceFunction())
.map(new NoOpMapFunction()).name("map")
.startNewChain()
.filter(new NoOpFilterFunction())
.addSink(new NoOpSinkFunction());
JobGraph jobGraph = env.getStreamGraph().getJobGraph();
JobVertex chainedMap = jobGraph.getVerticesSortedTopologicallyFromSources().get(1);
assertTrue(chainedMap.getName().startsWith("map"));
JobVertexID chainedMapId = chainedMap.getID();
env = StreamExecutionEnvironment.createLocalEnvironment();
env.setParallelism(4);
env.addSource(new NoOpSourceFunction())
.map(new NoOpMapFunction()).name("map")
.startNewChain()
.filter(new NoOpFilterFunction())
.startNewChain()
.addSink(new NoOpSinkFunction());
jobGraph = env.getStreamGraph().getJobGraph();
JobVertex unchainedMap = jobGraph.getVerticesSortedTopologicallyFromSources().get(1);
assertEquals("map", unchainedMap.getName());
JobVertexID unchainedMapId = unchainedMap.getID();
assertNotEquals(chainedMapId, unchainedMapId);
}
示例12: testManualHashAssignmentCollisionThrowsException
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
/**
* Tests that a collision on the manual hash throws an Exception.
*/
@Test(expected = IllegalArgumentException.class)
public void testManualHashAssignmentCollisionThrowsException() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
env.setParallelism(4);
env.disableOperatorChaining();
env.addSource(new NoOpSourceFunction()).uid("source")
.map(new NoOpMapFunction()).uid("source") // Collision
.addSink(new NoOpSinkFunction());
// This call is necessary to generate the job graph
env.getStreamGraph().getJobGraph();
}
示例13: testManualHashAssignmentForIntermediateNodeInChain
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
/**
* Tests that a manual hash for an intermediate chain node is accepted.
*/
@Test
public void testManualHashAssignmentForIntermediateNodeInChain() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
env.setParallelism(4);
env.addSource(new NoOpSourceFunction())
// Intermediate chained node
.map(new NoOpMapFunction()).uid("map")
.addSink(new NoOpSinkFunction());
env.getStreamGraph().getJobGraph();
}
示例14: testManualHashAssignmentForStartNodeInInChain
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
/**
* Tests that a manual hash at the beginning of a chain is accepted.
*/
@Test
public void testManualHashAssignmentForStartNodeInInChain() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
env.setParallelism(4);
env.addSource(new NoOpSourceFunction()).uid("source")
.map(new NoOpMapFunction())
.addSink(new NoOpSinkFunction());
env.getStreamGraph().getJobGraph();
}
示例15: testUserProvidedHashingOnChainSupported
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //導入方法依賴的package包/類
@Test
public void testUserProvidedHashingOnChainSupported() {
StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
env.addSource(new NoOpSourceFunction(), "src").setUidHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
.map(new NoOpMapFunction()).setUidHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
.filter(new NoOpFilterFunction()).setUidHash("cccccccccccccccccccccccccccccccc")
.keyBy(new NoOpKeySelector())
.reduce(new NoOpReduceFunction()).name("reduce").setUidHash("dddddddddddddddddddddddddddddddd");
env.getStreamGraph().getJobGraph();
}