Java Code Examples for org.springframework.cloud.deployer.spi.local.LocalDeployerProperties

The following examples show how to use org.springframework.cloud.deployer.spi.local.LocalDeployerProperties. These examples are extracted from open source projects. 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
@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);
}
 
Example 2
Source Project: spring-cloud-deployer-local   Source File: TickTock.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 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();
}
 
Example 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();
}
 
Example 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");
}
 
Example 6
@Bean
public TaskLauncher taskLauncher() {
	LocalDeployerProperties localDeployerProperties = new LocalDeployerProperties();

	localDeployerProperties.setDeleteFilesOnExit(false);

	return new LocalTaskLauncher(localDeployerProperties);
}
 
Example 7
Source Project: spring-cloud-deployer-local   Source File: TickTock.java    License: Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 8
Source Project: spring-cloud-deployer-local   Source File: TimeStamp.java    License: Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 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}");
}
 
Example 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();
}
 
Example 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();
}
 
Example 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");
}
 
Example 13
Source Project: spring-cloud-task   Source File: TaskLauncherSinkTests.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public TaskLauncher taskLauncher() {
	LocalDeployerProperties props = new LocalDeployerProperties();
	props.setDeleteFilesOnExit(false);

	return new LocalTaskLauncher(props);
}
 
Example 14
public Map<String, LocalDeployerProperties> getAccounts() {
	return accounts;
}
 
Example 15
public void setAccounts(Map<String, LocalDeployerProperties> accounts) {
	this.accounts = accounts;
}
 
Example 16
@Override
public Launcher createLauncher(String account) {
	LocalDeployerProperties deployerProperties = platformProperties.accountProperties(account);
	return doCreateLauncher(account, deployerProperties);
}
 
Example 17
private Launcher createDefaultLauncher() {
	return doCreateLauncher("default", new LocalDeployerProperties());
}
 
Example 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;
}
 
Example 19
@Bean
public TaskLauncher taskLauncher() {
	testTaskLauncher = new LocalTaskLauncher(new LocalDeployerProperties());
	return testTaskLauncher;
}
 
Example 20
Source Project: spring-cloud-consul   Source File: ConsulBinderTests.java    License: Apache License 2.0 4 votes vote down vote up
public ConsulBinderTests() {
	LocalDeployerProperties properties = new LocalDeployerProperties();
	properties.setDeleteFilesOnExit(false);
	this.deployer = new ClasspathDeployer(properties);
}
 
Example 21
Source Project: spring-cloud-consul   Source File: ConsulBinderTests.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Instantiates a new local app deployer.
 * @param properties the properties
 */
ClasspathDeployer(LocalDeployerProperties properties) {
	super(properties);
}