Java源码示例:org.springframework.cloud.deployer.spi.local.LocalDeployerProperties

示例1
@Bean
@Profile("local")
public Platform localDeployers(LocalPlatformProperties localPlatformProperties) {
	List<Deployer> deployers = new ArrayList<>();
	Map<String, LocalDeployerProperties> localDeployerPropertiesMap = localPlatformProperties.getAccounts();
	if (localDeployerPropertiesMap.isEmpty()) {
		localDeployerPropertiesMap.put("default", new LocalDeployerProperties());
	}
	for (Map.Entry<String, LocalDeployerProperties> entry : localDeployerPropertiesMap
			.entrySet()) {
		LocalAppDeployer localAppDeployer = new LocalAppDeployer(entry.getValue());
		Deployer deployer = new Deployer(entry.getKey(), "local", localAppDeployer);
		deployer.setDescription(prettyPrintLocalDeployerProperties(entry.getValue()));
		deployers.add(deployer);
	}

	return new Platform("Local", deployers);
}
 
示例2
private static AppDeploymentRequest createAppDeploymentRequest(String app, String stream) {
	MavenResource resource = new MavenResource.Builder()
			.artifactId(app)
			.groupId("org.springframework.cloud.stream.app")
			.version("1.0.0.BUILD-SNAPSHOT")
			.build();
	Map<String, String> properties = new HashMap<>();
	properties.put("server.port", "0");
	if (app.contains("-source-")) {
		properties.put("spring.cloud.stream.bindings.output.destination", stream);
	}
	else {
		properties.put("spring.cloud.stream.bindings.input.destination", stream);
		properties.put("spring.cloud.stream.bindings.input.group", "default");
	}
	AppDefinition definition = new AppDefinition(app, properties);
	Map<String, String> deploymentProperties = new HashMap<>();
	deploymentProperties.put(AppDeployer.GROUP_PROPERTY_KEY, stream);
	/*
	 * This will allow output to be logged to the output of the process that started
	 * the application.
	 */
	deploymentProperties.put(LocalDeployerProperties.INHERIT_LOGGING, "true");
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, deploymentProperties);
	return request;
}
 
示例3
private String prettyPrintLocalDeployerProperties(LocalDeployerProperties localDeployerProperties) {
	StringBuilder builder = new StringBuilder();
	if (localDeployerProperties.getJavaOpts() != null) {
		builder.append("JavaOpts = [" + localDeployerProperties.getJavaOpts() + "], ");
	}
	builder.append("ShutdownTimeout = [" + localDeployerProperties.getShutdownTimeout() + "], ");
	builder.append("EnvVarsToInherit = ["
			+ StringUtils.arrayToCommaDelimitedString(localDeployerProperties.getEnvVarsToInherit()) + "], ");
	builder.append("JavaCmd = [" + localDeployerProperties.getJavaCmd() + "], ");
	builder.append("WorkingDirectoriesRoot = [" + localDeployerProperties.getWorkingDirectoriesRoot() + "], ");
	builder.append("DeleteFilesOnExit = [" + localDeployerProperties.isDeleteFilesOnExit() + "]");
	return builder.toString();
}
 
示例4
@Test
public void basicCrud() {
	LocalAppDeployer localAppDeployer = new LocalAppDeployer(new LocalDeployerProperties());
	Deployer deployer = new Deployer("localDeployer", "local", localAppDeployer);
	deployer.setDescription("This is a test local Deployer.");
	this.deployerRepository.save(deployer);
	// Count is 2 including the default one which was added at the time of bootstrap.
	assertThat(deployerRepository.count()).isEqualTo(2);
	assertThat(deployer.getId()).isNotEmpty();
	assertThat(deployerRepository.findByName("localDeployer")).isNotNull();
	assertThat(deployerRepository.findByName("localDeployer").getDescription()).isNotNull();
	assertThat(deployerRepository.findByName("default").getDescription()).isNotNull();
}
 
示例5
@Test
public void deserializationTest() {
	Map<String, LocalDeployerProperties> localAccounts = this.localPlatformProperties.getAccounts();
	assertThat(localAccounts).hasSize(2);
	assertThat(localAccounts).containsKeys("localDev", "localDevDebug");
	assertThat(localAccounts.get("localDev").getShutdownTimeout()).isEqualTo(60);
	assertThat(localAccounts.get("localDevDebug").getJavaOpts()).isEqualTo("-Xdebug");
}
 
示例6
@Bean
public TaskLauncher taskLauncher() {
	LocalDeployerProperties localDeployerProperties = new LocalDeployerProperties();

	localDeployerProperties.setDeleteFilesOnExit(false);

	return new LocalTaskLauncher(localDeployerProperties);
}
 
示例7
public static void main(String[] args) throws InterruptedException {
	LocalAppDeployer deployer = new LocalAppDeployer(new LocalDeployerProperties());
	String logId = deployer.deploy(createAppDeploymentRequest("log-sink-kafka", "ticktock"));
	String timeId = deployer.deploy(createAppDeploymentRequest("time-source-kafka", "ticktock"));
	for (int i = 0; i < 12; i++) {
		Thread.sleep(5 * 1000);
		System.out.println("time: " + deployer.status(timeId));
		System.out.println("log:  " + deployer.status(logId));
	}
	deployer.undeploy(timeId);
	deployer.undeploy(logId);
	System.out.println("time after undeploy: " + deployer.status(timeId));
	System.out.println("log after undeploy:  " + deployer.status(logId));
}
 
示例8
public static void main(String[] args) throws InterruptedException {
	LocalTaskLauncher launcher = new LocalTaskLauncher(new LocalDeployerProperties());
	String timestampId = launcher.launch(createAppDeploymentRequest("timestamp-task"));
	for (int i = 0; i < 50; i++) {
		Thread.sleep(100);
		System.out.println("timestamp: " + launcher.status(timestampId));
	}
	// timestamp completes quickly, but we can 'cancel' the running task
	launcher.cancel(timestampId);
	System.out.println("timestamp after cancel: " + launcher.status(timestampId));
}
 
示例9
@Override
protected void before() {
	originalDataflowServerPort = System.getProperty(DATAFLOW_PORT_PROPERTY);

	this.dataflowServerPort = SocketUtils.findAvailableTcpPort();

	logger.info("Setting Dataflow Server port to " + this.dataflowServerPort);

	System.setProperty(DATAFLOW_PORT_PROPERTY, String.valueOf(this.dataflowServerPort));

	originalConfigLocation = System.getProperty("spring.config.additional-locationn");

	if (!StringUtils.isEmpty(configurationLocation)) {
		final Resource resource = new PathMatchingResourcePatternResolver().getResource(configurationLocation);
		if (!resource.exists()) {
		  throw new IllegalArgumentException(String.format("Resource 'configurationLocation' ('%s') does not exist.", configurationLocation));
		}
		System.setProperty("spring.config.additional-location", configurationLocation);
	}

	app = new SpringApplication(TestConfig.class);

	configurableApplicationContext = (WebApplicationContext) app.run(new String[] {
			"--spring.cloud.kubernetes.enabled=false",
			"--" + FeaturesProperties.FEATURES_PREFIX + "." + FeaturesProperties.STREAMS_ENABLED + "="
					+ this.streamsEnabled,
			"--" + FeaturesProperties.FEATURES_PREFIX + "." + FeaturesProperties.TASKS_ENABLED + "="
					+ this.tasksEnabled,
			"--" + FeaturesProperties.FEATURES_PREFIX + "." + FeaturesProperties.SCHEDULES_ENABLED + "="
					+ this.schedulesEnabled,
			"--spring.cloud.skipper.client.serverUri=http://localhost:" + this.skipperServerPort + "/api"
	});
	skipperClient = configurableApplicationContext.getBean(SkipperClient.class);
	LauncherRepository launcherRepository = configurableApplicationContext.getBean(LauncherRepository.class);
	launcherRepository.save(new Launcher("default", "local", new LocalTaskLauncher(new LocalDeployerProperties())));
	Collection<Filter> filters = configurableApplicationContext.getBeansOfType(Filter.class).values();
	mockMvc = MockMvcBuilders.webAppContextSetup(configurableApplicationContext)
			.addFilters(filters.toArray(new Filter[filters.size()])).build();
	dataflowPort = configurableApplicationContext.getEnvironment().resolvePlaceholders("${server.port}");
}
 
示例10
private String prettyPrintLocalDeployerProperties(LocalDeployerProperties localDeployerProperties) {
	StringBuilder builder = new StringBuilder();
	if (localDeployerProperties.getJavaOpts() != null) {
		builder.append("JavaOpts = [" + localDeployerProperties.getJavaOpts() + "], ");
	}
	builder.append("ShutdownTimeout = [" + localDeployerProperties.getShutdownTimeout() + "], ");
	builder.append("EnvVarsToInherit = ["
			+ StringUtils.arrayToCommaDelimitedString(localDeployerProperties.getEnvVarsToInherit()) + "], ");
	builder.append("JavaCmd = [" + localDeployerProperties.getJavaCmd() + "], ");
	builder.append("WorkingDirectoriesRoot = [" + localDeployerProperties.getWorkingDirectoriesRoot() + "], ");
	builder.append("DeleteFilesOnExit = [" + localDeployerProperties.isDeleteFilesOnExit() + "]");
	return builder.toString();
}
 
示例11
@Test
public void createsConfiguredPlatform() {
	LocalPlatformProperties platformProperties = new LocalPlatformProperties();
	platformProperties.setAccounts(Collections.singletonMap("custom",new LocalDeployerProperties()));
	LocalTaskPlatformFactory taskPlatformFactory = new LocalTaskPlatformFactory(platformProperties, null);
	TaskPlatform taskPlatform = taskPlatformFactory.createTaskPlatform();
	assertThat(taskPlatform.getLaunchers()).hasSize(1);
	assertThat(taskPlatform.getName()).isEqualTo("Local");
	assertThat(taskPlatform.getLaunchers().get(0).getType()).isEqualTo(taskPlatform.getName());
	assertThat(taskPlatform.getLaunchers().get(0).getName()).isEqualTo("custom");
	assertThat(taskPlatform.getLaunchers().get(0).getTaskLauncher()).isInstanceOf(LocalTaskLauncher.class);
	assertThat(taskPlatform.getLaunchers().get(0).getDescription()).isNotEmpty();
}
 
示例12
@Test
public void deserializationTest() {
	Map<String, LocalDeployerProperties> localAccounts = this.localPlatformProperties.getAccounts();
	assertThat(localAccounts).hasSize(2);
	assertThat(localAccounts).containsKeys("localDev", "localDevDebug");
	assertThat(localAccounts.get("localDev").getShutdownTimeout()).isEqualTo(60);
	assertThat(localAccounts.get("localDevDebug").getJavaOpts()).isEqualTo("-Xdebug");
}
 
示例13
@Bean
public TaskLauncher taskLauncher() {
	LocalDeployerProperties props = new LocalDeployerProperties();
	props.setDeleteFilesOnExit(false);

	return new LocalTaskLauncher(props);
}
 
示例14
public Map<String, LocalDeployerProperties> getAccounts() {
	return accounts;
}
 
示例15
public void setAccounts(Map<String, LocalDeployerProperties> accounts) {
	this.accounts = accounts;
}
 
示例16
@Override
public Launcher createLauncher(String account) {
	LocalDeployerProperties deployerProperties = platformProperties.accountProperties(account);
	return doCreateLauncher(account, deployerProperties);
}
 
示例17
private Launcher createDefaultLauncher() {
	return doCreateLauncher("default", new LocalDeployerProperties());
}
 
示例18
private Launcher doCreateLauncher(String account, LocalDeployerProperties deployerProperties) {
	LocalTaskLauncher localTaskLauncher = new LocalTaskLauncher(deployerProperties);
	Launcher launcher = new Launcher(account, LOCAL_PLATFORM_TYPE, localTaskLauncher, localScheduler);
	launcher.setDescription(prettyPrintLocalDeployerProperties(deployerProperties));
	return launcher;
}
 
示例19
@Bean
public TaskLauncher taskLauncher() {
	testTaskLauncher = new LocalTaskLauncher(new LocalDeployerProperties());
	return testTaskLauncher;
}
 
示例20
public ConsulBinderTests() {
	LocalDeployerProperties properties = new LocalDeployerProperties();
	properties.setDeleteFilesOnExit(false);
	this.deployer = new ClasspathDeployer(properties);
}
 
示例21
/**
 * Instantiates a new local app deployer.
 * @param properties the properties
 */
ClasspathDeployer(LocalDeployerProperties properties) {
	super(properties);
}