org.apache.flink.runtime.jobgraph.SavepointRestoreSettings Java Examples

The following examples show how to use org.apache.flink.runtime.jobgraph.SavepointRestoreSettings. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JarRunHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
private SavepointRestoreSettings getSavepointRestoreSettings(
		final @Nonnull HandlerRequest<JarRunRequestBody, JarRunMessageParameters> request)
			throws RestHandlerException {

	final JarRunRequestBody requestBody = request.getRequestBody();

	final boolean allowNonRestoredState = fromRequestBodyOrQueryParameter(
		requestBody.getAllowNonRestoredState(),
		() -> getQueryParameter(request, AllowNonRestoredStateQueryParameter.class),
		false,
		log);
	final String savepointPath = fromRequestBodyOrQueryParameter(
		emptyToNull(requestBody.getSavepointPath()),
		() -> emptyToNull(getQueryParameter(request, SavepointPathQueryParameter.class)),
		null,
		log);
	final SavepointRestoreSettings savepointRestoreSettings;
	if (savepointPath != null) {
		savepointRestoreSettings = SavepointRestoreSettings.forPath(
			savepointPath,
			allowNonRestoredState);
	} else {
		savepointRestoreSettings = SavepointRestoreSettings.none();
	}
	return savepointRestoreSettings;
}
 
Example #2
Source File: DFCusterClient.java    From df_data_service with Apache License 2.0 6 votes vote down vote up
private JobGraph getJobGraph(FlinkPlan optPlan, List<URL> jarFiles, List<URL> classpaths, SavepointRestoreSettings savepointSettings) {
	JobGraph job;
	if (optPlan instanceof StreamingPlan) {
		job = ((StreamingPlan) optPlan).getJobGraph();
		job.setSavepointRestoreSettings(savepointSettings);
	} else {
		JobGraphGenerator gen = new JobGraphGenerator(this.flinkConfig);
		job = gen.compileJobGraph((OptimizedPlan) optPlan);
	}

	for (URL jar : jarFiles) {
		try {
			job.addJar(new Path(jar.toURI()));
		} catch (URISyntaxException e) {
			throw new RuntimeException("URL is invalid. This should not happen.", e);
		}
	}

	job.setClasspaths(classpaths);

	return job;
}
 
Example #3
Source File: ClassPathJobGraphRetrieverTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testJobGraphRetrievalJobClassNameHasPrecedenceOverClassPath() throws FlinkException, FileNotFoundException {
	final File testJar = new File("non-existing");

	final ClassPathJobGraphRetriever classPathJobGraphRetriever = new ClassPathJobGraphRetriever(
		new JobID(),
		SavepointRestoreSettings.none(),
		PROGRAM_ARGUMENTS,
		// Both a class name is specified and a JAR "is" on the class path
		// The class name should have precedence.
		TestJob.class.getCanonicalName(),
		() -> Collections.singleton(testJar));

	final JobGraph jobGraph = classPathJobGraphRetriever.retrieveJobGraph(new Configuration());

	assertThat(jobGraph.getName(), is(equalTo(TestJob.class.getCanonicalName() + "-suffix")));
}
 
Example #4
Source File: JarRunHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JarRunResponseBody> handleRequest(
		@Nonnull final HandlerRequest<JarRunRequestBody, JarRunMessageParameters> request,
		@Nonnull final DispatcherGateway gateway) throws RestHandlerException {

	final Configuration effectiveConfiguration = new Configuration(configuration);
	effectiveConfiguration.set(DeploymentOptions.ATTACHED, false);
	effectiveConfiguration.set(DeploymentOptions.TARGET, EmbeddedExecutor.NAME);

	final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);
	context.applyToConfiguration(effectiveConfiguration);
	SavepointRestoreSettings.toConfiguration(getSavepointRestoreSettings(request), effectiveConfiguration);

	final PackagedProgram program = context.toPackagedProgram(effectiveConfiguration);

	return CompletableFuture
			.supplyAsync(() -> applicationRunner.run(gateway, program, effectiveConfiguration), executor)
			.thenApply(jobIds -> {
				if (jobIds.isEmpty()) {
					throw new CompletionException(new ProgramInvocationException("No jobs submitted."));
				}
				return new JarRunResponseBody(jobIds.get(0));
			});
}
 
Example #5
Source File: StandaloneApplicationClusterConfigurationParserFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public StandaloneApplicationClusterConfiguration createResult(@Nonnull CommandLine commandLine) throws FlinkParseException {
	final String configDir = commandLine.getOptionValue(CONFIG_DIR_OPTION.getOpt());
	final Properties dynamicProperties = commandLine.getOptionProperties(DYNAMIC_PROPERTY_OPTION.getOpt());
	final int restPort = getRestPort(commandLine);
	final String hostname = commandLine.getOptionValue(HOST_OPTION.getOpt());
	final SavepointRestoreSettings savepointRestoreSettings = CliFrontendParser.createSavepointRestoreSettings(commandLine);
	final JobID jobId = getJobId(commandLine);
	final String jobClassName = commandLine.getOptionValue(JOB_CLASS_NAME_OPTION.getOpt());

	return new StandaloneApplicationClusterConfiguration(
		configDir,
		dynamicProperties,
		commandLine.getArgs(),
		hostname,
		restPort,
		savepointRestoreSettings,
		jobId,
		jobClassName);
}
 
Example #6
Source File: ClassPathJobGraphRetrieverTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testJobGraphRetrieval() throws FlinkException {
	final int parallelism = 42;
	final Configuration configuration = new Configuration();
	configuration.setInteger(CoreOptions.DEFAULT_PARALLELISM, parallelism);
	final JobID jobId = new JobID();

	final ClassPathJobGraphRetriever classPathJobGraphRetriever = new ClassPathJobGraphRetriever(
		jobId,
		SavepointRestoreSettings.none(),
		PROGRAM_ARGUMENTS,
		TestJob.class.getCanonicalName());

	final JobGraph jobGraph = classPathJobGraphRetriever.retrieveJobGraph(configuration);

	assertThat(jobGraph.getName(), is(equalTo(TestJob.class.getCanonicalName() + "-suffix")));
	assertThat(jobGraph.getMaximumParallelism(), is(parallelism));
	assertEquals(jobGraph.getJobID(), jobId);
}
 
Example #7
Source File: RemoteStreamEnvironment.java    From flink with Apache License 2.0 6 votes vote down vote up
private static Configuration validateAndGetEffectiveConfiguration(
		final Configuration configuration,
		final String host,
		final int port,
		final String[] jarFiles,
		final URL[] classpaths,
		final SavepointRestoreSettings savepointRestoreSettings) {
	RemoteEnvironmentConfigUtils.validate(host, port);
	return getEffectiveConfiguration(
			getClientConfiguration(configuration),
			host,
			port,
			jarFiles,
			getClasspathURLs(classpaths),
			savepointRestoreSettings);
}
 
Example #8
Source File: RemoteStreamExecutionEnvironmentTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoteExecutionWithSavepoint() throws Exception {
	SavepointRestoreSettings restoreSettings = SavepointRestoreSettings.forPath("fakePath");
	RemoteStreamEnvironment env = new RemoteStreamEnvironment("fakeHost", 1,
		null, new String[]{}, null, restoreSettings);
	env.fromElements(1).map(x -> x * 2);

	RestClusterClient mockedClient = Mockito.mock(RestClusterClient.class);
	JobExecutionResult expectedResult = new JobExecutionResult(null, 0, null);

	PowerMockito.whenNew(RestClusterClient.class).withAnyArguments().thenReturn(mockedClient);
	when(mockedClient.run(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.eq(restoreSettings)))
		.thenReturn(expectedResult);

	JobExecutionResult actualResult = env.execute("fakeJobName");
	Assert.assertEquals(expectedResult, actualResult);
}
 
Example #9
Source File: ClassPathJobGraphRetrieverTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointRestoreSettings() throws FlinkException {
	final Configuration configuration = new Configuration();
	final SavepointRestoreSettings savepointRestoreSettings = SavepointRestoreSettings.forPath("foobar", true);
	final JobID jobId = new JobID();

	final ClassPathJobGraphRetriever classPathJobGraphRetriever = new ClassPathJobGraphRetriever(
		jobId,
		savepointRestoreSettings,
		PROGRAM_ARGUMENTS,
		TestJob.class.getCanonicalName());

	final JobGraph jobGraph = classPathJobGraphRetriever.retrieveJobGraph(configuration);

	assertThat(jobGraph.getSavepointRestoreSettings(), is(equalTo(savepointRestoreSettings)));
	assertEquals(jobGraph.getJobID(), jobId);
}
 
Example #10
Source File: ClassPathJobGraphRetrieverTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testJobGraphRetrievalJobClassNameHasPrecedenceOverClassPath() throws FlinkException, FileNotFoundException {
	final File testJar = new File("non-existing");

	final ClassPathJobGraphRetriever classPathJobGraphRetriever = new ClassPathJobGraphRetriever(
		new JobID(),
		SavepointRestoreSettings.none(),
		PROGRAM_ARGUMENTS,
		// Both a class name is specified and a JAR "is" on the class path
		// The class name should have precedence.
		TestJob.class.getCanonicalName(),
		() -> Collections.singleton(testJar));

	final JobGraph jobGraph = classPathJobGraphRetriever.retrieveJobGraph(new Configuration());

	assertThat(jobGraph.getName(), is(equalTo(TestJob.class.getCanonicalName() + "-suffix")));
}
 
Example #11
Source File: RemoteStreamEnvironmentTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoteExecutionWithSavepoint() throws Exception {
	SavepointRestoreSettings restoreSettings = SavepointRestoreSettings.forPath("fakePath");
	JobID jobID = new JobID();

	TestExecutorServiceLoader testExecutorServiceLoader = new TestExecutorServiceLoader(jobID);
	RemoteStreamEnvironment env = new RemoteStreamEnvironment(
			testExecutorServiceLoader,
			"fakeHost",
			1,
			null,
			new String[]{},
			null,
			restoreSettings);

	env.fromElements(1).map(x -> x * 2);

	JobExecutionResult actualResult = env.execute("fakeJobName");
	assertThat(actualResult.getJobID(), is(jobID));
	assertThat(
			testExecutorServiceLoader.getActualSavepointRestoreSettings(), is(restoreSettings));
}
 
Example #12
Source File: RemoteStreamEnvironment.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Executes the job remotely.
 *
 * <p>This method can be used independent of the {@link StreamExecutionEnvironment} type.
 * @return The result of the job execution, containing elapsed time and accumulators.
 */
@PublicEvolving
public static JobExecutionResult executeRemotely(StreamExecutionEnvironment streamExecutionEnvironment,
	List<URL> jarFiles,
	String host,
	int port,
	Configuration clientConfiguration,
	List<URL> globalClasspaths,
	String jobName,
	SavepointRestoreSettings savepointRestoreSettings
) throws ProgramInvocationException {
	StreamGraph streamGraph = streamExecutionEnvironment.getStreamGraph();
	streamGraph.setJobName(jobName);
	return executeRemotely(streamGraph,
		streamExecutionEnvironment.getClass().getClassLoader(),
		streamExecutionEnvironment.getConfig(),
		jarFiles,
		host,
		port,
		clientConfiguration,
		globalClasspaths,
		savepointRestoreSettings);
}
 
Example #13
Source File: JarRunHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private SavepointRestoreSettings getSavepointRestoreSettings(
		final @Nonnull HandlerRequest<JarRunRequestBody, JarRunMessageParameters> request)
			throws RestHandlerException {

	final JarRunRequestBody requestBody = request.getRequestBody();

	final boolean allowNonRestoredState = fromRequestBodyOrQueryParameter(
		requestBody.getAllowNonRestoredState(),
		() -> getQueryParameter(request, AllowNonRestoredStateQueryParameter.class),
		false,
		log);
	final String savepointPath = fromRequestBodyOrQueryParameter(
		emptyToNull(requestBody.getSavepointPath()),
		() -> emptyToNull(getQueryParameter(request, SavepointPathQueryParameter.class)),
		null,
		log);
	final SavepointRestoreSettings savepointRestoreSettings;
	if (savepointPath != null) {
		savepointRestoreSettings = SavepointRestoreSettings.forPath(
			savepointPath,
			allowNonRestoredState);
	} else {
		savepointRestoreSettings = SavepointRestoreSettings.none();
	}
	return savepointRestoreSettings;
}
 
Example #14
Source File: FlinkContainerFactory.java    From sylph with Apache License 2.0 6 votes vote down vote up
public static void setSavepoint(JobGraph jobGraph, Path appCheckPath, Configuration hadoopConf)
        throws Exception
{
    //How to use `savepoints` to restore a job
    jobGraph.setSavepointRestoreSettings(SavepointRestoreSettings.none());
    FileSystem fileSystem = FileSystem.get(hadoopConf);
    if (!fileSystem.exists(appCheckPath)) {
        return;
    }
    List<FileStatus> appCheckDirFiles = Stream.of(fileSystem.listStatus(appCheckPath))
            .filter(file -> file.getPath().getName().startsWith(CHECKPOINT_DIR_PREFIX))
            .sorted((x, y) -> Long.compare(y.getModificationTime(), x.getModificationTime()))
            .collect(Collectors.toList());
    for (FileStatus fileStatus : appCheckDirFiles) {
        Path metadataFile = new Path(fileStatus.getPath().toString(), METADATA_FILE_NAME);
        if (fileSystem.exists(metadataFile)) {
            //allowNonRestoredState (可选):布尔值,指定如果保存点包含无法映射回作业的状态,是否应拒绝作业提交。 default is false
            logger.info("Find Savepoint {}", metadataFile);
            jobGraph.setSavepointRestoreSettings(SavepointRestoreSettings.forPath(metadataFile.toString(), true));
            break;
        }
    }
}
 
Example #15
Source File: ClassPathPackagedProgramRetrieverTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointRestoreSettings() throws FlinkException, IOException, ProgramInvocationException {
	final Configuration configuration = new Configuration();
	final SavepointRestoreSettings savepointRestoreSettings = SavepointRestoreSettings.forPath("foobar", true);
	final JobID jobId = new JobID();

	configuration.setString(PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID, jobId.toHexString());
	SavepointRestoreSettings.toConfiguration(savepointRestoreSettings, configuration);

	final ClassPathPackagedProgramRetriever retrieverUnderTest =
		ClassPathPackagedProgramRetriever.newBuilder(PROGRAM_ARGUMENTS)
		.setJobClassName(TestJob.class.getCanonicalName())
		.build();

	final JobGraph jobGraph = retrieveJobGraph(retrieverUnderTest, configuration);

	assertThat(jobGraph.getSavepointRestoreSettings(), is(equalTo(savepointRestoreSettings)));
	assertEquals(jobGraph.getJobID(), jobId);
}
 
Example #16
Source File: StandaloneApplicationClusterConfigurationParserFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testEntrypointClusterConfigurationParsing() throws FlinkParseException {
	final String key = "key";
	final String value = "value";
	final int restPort = 1234;
	final String arg1 = "arg1";
	final String arg2 = "arg2";
	final String[] args = {"--configDir", confDirPath, "--webui-port", String.valueOf(restPort), "--job-classname", JOB_CLASS_NAME, String.format("-D%s=%s", key, value), arg1, arg2};

	final StandaloneApplicationClusterConfiguration clusterConfiguration = commandLineParser.parse(args);

	assertThat(clusterConfiguration.getConfigDir(), is(equalTo(confDirPath)));
	assertThat(clusterConfiguration.getJobClassName(), is(equalTo(JOB_CLASS_NAME)));
	assertThat(clusterConfiguration.getRestPort(), is(equalTo(restPort)));
	final Properties dynamicProperties = clusterConfiguration.getDynamicProperties();

	assertThat(dynamicProperties, hasEntry(key, value));

	assertThat(clusterConfiguration.getArgs(), arrayContaining(arg1, arg2));

	assertThat(clusterConfiguration.getSavepointRestoreSettings(), is(equalTo(SavepointRestoreSettings.none())));

	assertThat(clusterConfiguration.getJobId(), is(nullValue()));
}
 
Example #17
Source File: StandaloneJobClusterConfigurationParserFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testShortOptions() throws FlinkParseException {
	final String jobClassName = "foobar";
	final JobID jobId = new JobID();
	final String savepointRestorePath = "s3://foo/bar";

	final String[] args = {
		"-c", confDirPath,
		"-j", jobClassName,
		"-jid", jobId.toString(),
		"-s", savepointRestorePath,
		"-n"};

	final StandaloneJobClusterConfiguration clusterConfiguration = commandLineParser.parse(args);

	assertThat(clusterConfiguration.getConfigDir(), is(equalTo(confDirPath)));
	assertThat(clusterConfiguration.getJobClassName(), is(equalTo(jobClassName)));
	assertThat(clusterConfiguration.getJobId(), is(equalTo(jobId)));

	final SavepointRestoreSettings savepointRestoreSettings = clusterConfiguration.getSavepointRestoreSettings();
	assertThat(savepointRestoreSettings.restoreSavepoint(), is(true));
	assertThat(savepointRestoreSettings.getRestorePath(), is(equalTo(savepointRestorePath)));
	assertThat(savepointRestoreSettings.allowNonRestoredState(), is(true));
}
 
Example #18
Source File: JobMasterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private JobGraph createJobGraphFromJobVerticesWithCheckpointing(SavepointRestoreSettings savepointRestoreSettings, JobVertex... jobVertices) {
	final JobGraph jobGraph = new JobGraph(jobVertices);

	// enable checkpointing which is required to resume from a savepoint
	final CheckpointCoordinatorConfiguration checkpoinCoordinatorConfiguration = new CheckpointCoordinatorConfiguration(
		1000L,
		1000L,
		1000L,
		1,
		CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION,
		true,
		false,
		false,
		0);
	final JobCheckpointingSettings checkpointingSettings = new JobCheckpointingSettings(
		Collections.emptyList(),
		Collections.emptyList(),
		Collections.emptyList(),
		checkpoinCoordinatorConfiguration,
		null);
	jobGraph.setSnapshotSettings(checkpointingSettings);
	jobGraph.setSavepointRestoreSettings(savepointRestoreSettings);

	return jobGraph;
}
 
Example #19
Source File: JobMasterTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
private JobGraph createJobGraphFromJobVerticesWithCheckpointing(SavepointRestoreSettings savepointRestoreSettings, JobVertex... jobVertices) {
	final JobGraph jobGraph = new JobGraph(jobVertices);

	// enable checkpointing which is required to resume from a savepoint
	final CheckpointCoordinatorConfiguration checkpoinCoordinatorConfiguration = new CheckpointCoordinatorConfiguration(
		1000L,
		1000L,
		1000L,
		1,
		CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION,
		true);
	final JobCheckpointingSettings checkpointingSettings = new JobCheckpointingSettings(
		Collections.emptyList(),
		Collections.emptyList(),
		Collections.emptyList(),
		checkpoinCoordinatorConfiguration,
		null);
	jobGraph.setSnapshotSettings(checkpointingSettings);
	jobGraph.setSavepointRestoreSettings(savepointRestoreSettings);

	return jobGraph;
}
 
Example #20
Source File: StandaloneJobClusterConfigurationParserFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testEntrypointClusterConfigurationParsing() throws FlinkParseException {
	final String key = "key";
	final String value = "value";
	final int restPort = 1234;
	final String arg1 = "arg1";
	final String arg2 = "arg2";
	final String[] args = {"--configDir", confDirPath, "--webui-port", String.valueOf(restPort), "--job-classname", JOB_CLASS_NAME, String.format("-D%s=%s", key, value), arg1, arg2};

	final StandaloneJobClusterConfiguration clusterConfiguration = commandLineParser.parse(args);

	assertThat(clusterConfiguration.getConfigDir(), is(equalTo(confDirPath)));
	assertThat(clusterConfiguration.getJobClassName(), is(equalTo(JOB_CLASS_NAME)));
	assertThat(clusterConfiguration.getRestPort(), is(equalTo(restPort)));
	final Properties dynamicProperties = clusterConfiguration.getDynamicProperties();

	assertThat(dynamicProperties, hasEntry(key, value));

	assertThat(clusterConfiguration.getArgs(), arrayContaining(arg1, arg2));

	assertThat(clusterConfiguration.getSavepointRestoreSettings(), is(equalTo(SavepointRestoreSettings.none())));

	assertThat(clusterConfiguration.getJobId(), is(nullValue()));
}
 
Example #21
Source File: AbstractOperatorRestoreTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void restoreJob(ClassLoader classLoader, ClusterClient<?> clusterClient, Deadline deadline, String savepointPath) throws Exception {
	JobGraph jobToRestore = createJobGraph(ExecutionMode.RESTORE);
	jobToRestore.setSavepointRestoreSettings(SavepointRestoreSettings.forPath(savepointPath, allowNonRestoredState));

	assertNotNull("Job doesn't have a JobID.", jobToRestore.getJobID());

	clusterClient.submitJob(jobToRestore, classLoader);

	CompletableFuture<JobStatus> jobStatusFuture = FutureUtils.retrySuccessfulWithDelay(
		() -> clusterClient.getJobStatus(jobToRestore.getJobID()),
		Time.milliseconds(50),
		deadline,
		(jobStatus) -> jobStatus == JobStatus.FINISHED,
		TestingUtils.defaultScheduledExecutor());
	assertEquals(
		JobStatus.FINISHED,
		jobStatusFuture.get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS));
}
 
Example #22
Source File: ClusterClient.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static JobGraph getJobGraph(Configuration flinkConfig, FlinkPlan optPlan, List<URL> jarFiles, List<URL> classpaths, SavepointRestoreSettings savepointSettings) {
	JobGraph job;
	if (optPlan instanceof StreamingPlan) {
		job = ((StreamingPlan) optPlan).getJobGraph();
		job.setSavepointRestoreSettings(savepointSettings);
	} else {
		JobGraphGenerator gen = new JobGraphGenerator(flinkConfig);
		job = gen.compileJobGraph((OptimizedPlan) optPlan);
	}

	for (URL jar : jarFiles) {
		try {
			job.addJar(new Path(jar.toURI()));
		} catch (URISyntaxException e) {
			throw new RuntimeException("URL is invalid. This should not happen.", e);
		}
	}

	job.setClasspaths(classpaths);

	return job;
}
 
Example #23
Source File: StandaloneJobClusterConfigurationParserFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnlyRequiredArguments() throws FlinkParseException {
	final String[] args = {"--configDir", confDirPath};

	final StandaloneJobClusterConfiguration clusterConfiguration = commandLineParser.parse(args);

	assertThat(clusterConfiguration.getConfigDir(), is(equalTo(confDirPath)));
	assertThat(clusterConfiguration.getDynamicProperties(), is(equalTo(new Properties())));
	assertThat(clusterConfiguration.getArgs(), is(new String[0]));
	assertThat(clusterConfiguration.getRestPort(), is(equalTo(-1)));
	assertThat(clusterConfiguration.getHostname(), is(nullValue()));
	assertThat(clusterConfiguration.getSavepointRestoreSettings(), is(equalTo(SavepointRestoreSettings.none())));
	assertThat(clusterConfiguration.getJobId(), is(nullValue()));
	assertThat(clusterConfiguration.getJobClassName(),  is(nullValue()));
}
 
Example #24
Source File: JarRunHandlerParameterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
JobGraph validateDefaultGraph() {
	JobGraph jobGraph = super.validateDefaultGraph();
	final SavepointRestoreSettings savepointRestoreSettings = jobGraph.getSavepointRestoreSettings();
	assertFalse(savepointRestoreSettings.allowNonRestoredState());
	Assert.assertNull(savepointRestoreSettings.getRestorePath());
	return jobGraph;
}
 
Example #25
Source File: StandaloneJobClusterConfigurationParserFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSavepointRestoreSettingsParsing() throws FlinkParseException {
	final String restorePath = "foobar";
	final String[] args = {"-c", confDirPath, "-j", JOB_CLASS_NAME, "-s", restorePath, "-n"};
	final StandaloneJobClusterConfiguration standaloneJobClusterConfiguration = commandLineParser.parse(args);

	final SavepointRestoreSettings savepointRestoreSettings = standaloneJobClusterConfiguration.getSavepointRestoreSettings();

	assertThat(savepointRestoreSettings.restoreSavepoint(), is(true));
	assertThat(savepointRestoreSettings.getRestorePath(), is(equalTo(restorePath)));
	assertThat(savepointRestoreSettings.allowNonRestoredState(), is(true));
}
 
Example #26
Source File: StatefulFunctionsJobGraphRetriever.java    From flink-statefun with Apache License 2.0 5 votes vote down vote up
StatefulFunctionsJobGraphRetriever(
    JobID jobId,
    SavepointRestoreSettings savepointRestoreSettings,
    int parallelism,
    String[] programArguments) {
  this.jobId = requireNonNull(jobId, "jobId");
  this.savepointRestoreSettings =
      requireNonNull(savepointRestoreSettings, "savepointRestoreSettings");
  this.parallelism = parallelism;
  this.programArguments = requireNonNull(programArguments, "programArguments");
}
 
Example #27
Source File: FlinkRequiresStableInputTest.java    From beam with Apache License 2.0 5 votes vote down vote up
private JobID restoreFromSavepoint(Pipeline pipeline, String savepointDir)
    throws ExecutionException, InterruptedException {
  JobGraph jobGraph = getJobGraph(pipeline);
  SavepointRestoreSettings savepointSettings = SavepointRestoreSettings.forPath(savepointDir);
  jobGraph.setSavepointRestoreSettings(savepointSettings);
  return flinkCluster.submitJob(jobGraph).get().getJobID();
}
 
Example #28
Source File: StandaloneApplicationClusterConfigurationParserFactoryTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntrypointClusterConfigurationToConfigurationParsing() throws FlinkParseException {
	final JobID jobID = JobID.generate();
	final SavepointRestoreSettings savepointRestoreSettings = SavepointRestoreSettings.forPath("/test/savepoint/path", true);
	final String key = DeploymentOptions.TARGET.key();
	final String value = "testDynamicExecutorConfig";
	final int restPort = 1234;
	final String arg1 = "arg1";
	final String arg2 = "arg2";
	final String[] args = {
			"--configDir", confDirPath,
			"--job-id", jobID.toHexString(),
			"--fromSavepoint", savepointRestoreSettings.getRestorePath(),
			"--allowNonRestoredState",
			"--webui-port", String.valueOf(restPort),
			"--job-classname", JOB_CLASS_NAME,
			String.format("-D%s=%s", key, value),
			arg1, arg2};

	final StandaloneApplicationClusterConfiguration clusterConfiguration = commandLineParser.parse(args);
	assertThat(clusterConfiguration.getJobClassName(), is(equalTo(JOB_CLASS_NAME)));
	assertThat(clusterConfiguration.getArgs(), arrayContaining(arg1, arg2));

	final Configuration configuration = StandaloneApplicationClusterEntryPoint
			.loadConfigurationFromClusterConfig(clusterConfiguration);

	final String strJobId = configuration.get(PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID);
	assertThat(JobID.fromHexString(strJobId), is(equalTo(jobID)));
	assertThat(SavepointRestoreSettings.fromConfiguration(configuration), is(equalTo(savepointRestoreSettings)));

	assertThat(configuration.get(RestOptions.PORT), is(equalTo(restPort)));
	assertThat(configuration.get(DeploymentOptions.TARGET), is(equalTo(value)));
}
 
Example #29
Source File: ClassPathJobGraphRetriever.java    From flink with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
ClassPathJobGraphRetriever(
		@Nonnull JobID jobId,
		@Nonnull SavepointRestoreSettings savepointRestoreSettings,
		@Nonnull String[] programArguments,
		@Nullable String jobClassName,
		@Nonnull Supplier<Iterable<File>> jarsOnClassPath) {
	this.jobId = requireNonNull(jobId, "jobId");
	this.savepointRestoreSettings = requireNonNull(savepointRestoreSettings, "savepointRestoreSettings");
	this.programArguments = requireNonNull(programArguments, "programArguments");
	this.jobClassName = jobClassName;
	this.jarsOnClassPath = requireNonNull(jarsOnClassPath, "jarsOnClassPath");
}
 
Example #30
Source File: SavepointWriterITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private void validateBootstrap(String savepointPath) throws ProgramInvocationException {
	StreamExecutionEnvironment sEnv = StreamExecutionEnvironment.getExecutionEnvironment();
	sEnv.setStateBackend(backend);

	CollectSink.accountList.clear();

	sEnv.fromCollection(accounts)
		.keyBy(acc -> acc.id)
		.flatMap(new UpdateAndGetAccount())
		.uid(ACCOUNT_UID)
		.addSink(new CollectSink());

	sEnv
		.fromCollection(currencyRates)
		.connect(sEnv.fromCollection(currencyRates).broadcast(descriptor))
		.process(new CurrencyValidationFunction())
		.uid(CURRENCY_UID)
		.addSink(new DiscardingSink<>());

	JobGraph jobGraph = sEnv.getStreamGraph().getJobGraph();
	jobGraph.setSavepointRestoreSettings(SavepointRestoreSettings.forPath(savepointPath, false));

	ClusterClient<?> client = miniClusterResource.getClusterClient();
	ClientUtils.submitJobAndWaitForResult(client, jobGraph, SavepointWriterITCase.class.getClassLoader());

	Assert.assertEquals("Unexpected output", 3, CollectSink.accountList.size());
}