Java源码示例:org.springframework.boot.cloud.CloudPlatform

示例1
@Bean
@ConditionalOnCloudPlatform(CloudPlatform.CLOUD_FOUNDRY)
public ApplicationInformation cloudFoundryApplicationInformation(Environment environment) {
	String uri = environment.getProperty("vcap.application.uris[0]");

	String baseUrl = UriComponentsBuilder.newInstance()
			.scheme("https")
			.host(uri)
			.build()
			.toUriString();

	return new ApplicationInformation(baseUrl);
}
 
示例2
@Test
public void testLocalSchedulerEnabled() {
	assertFalse("K8s should be disabled", context.getEnvironment().containsProperty("kubernetes_service_host"));
	assertFalse("CF should be disabled", CloudPlatform.CLOUD_FOUNDRY.isActive(context.getEnvironment()));

	Scheduler scheduler = context.getBean(Scheduler.class);

	assertNotNull(scheduler);
	assertTrue(scheduler.getClass().getName().contains("LocalSchedulerAutoConfiguration"));
}
 
示例3
@Test
public void testKubernetesSchedulerEnabled() {
	assertTrue("K8s should be enabled", context.getEnvironment().containsProperty("kubernetes_service_host"));
	assertFalse("CF should be disabled", CloudPlatform.CLOUD_FOUNDRY.isActive(context.getEnvironment()));


	KubernetesSchedulerProperties props = context.getBean(KubernetesSchedulerProperties.class);
	assertNotNull(props);
}
 
示例4
@Test
public void testCloudFoundryScheudlerEnabled() {
	assertFalse("K8s should be disabled", context.getEnvironment().containsProperty("kubernetes_service_host"));
	assertTrue("CF should be enabled", CloudPlatform.CLOUD_FOUNDRY.isActive(context.getEnvironment()));

	CloudFoundrySchedulerProperties props = context.getBean(CloudFoundrySchedulerProperties.class);
	assertNotNull(props);
}
 
示例5
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
		SpringApplication application) {
	increaseInvocationCount();
	if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) {
		CfJdbcEnv cfJdbcEnv = new CfJdbcEnv();
		CfJdbcService cfJdbcService = null;
		try {
			cfJdbcService = cfJdbcEnv.findJdbcService();
			cfJdbcService = this.isEnabled(cfJdbcService, environment) ? cfJdbcService : null;
		} catch (Exception e) {

			List<CfJdbcService> jdbcServices = cfJdbcEnv.findJdbcServices().stream()
					.filter(service -> this.isEnabled(service, environment))
					.collect(Collectors.toList());

			if (jdbcServices.size() > 1) {
				if (invocationCount == 1) {
					DEFERRED_LOG.debug(
						"Skipping execution of CfDataSourceEnvironmentPostProcessor. "
							+ e.getMessage());
				}
				return;
			}

			cfJdbcService = jdbcServices.size() == 1 ? jdbcServices.get(0) : null;
		}
		if (cfJdbcService != null) {
			ConnectorLibraryDetector.assertNoConnectorLibrary();
			Map<String, Object> properties = new LinkedHashMap<>();
			properties.put("spring.datasource.url", cfJdbcService.getJdbcUrl());
			properties.put("spring.datasource.username", cfJdbcService.getUsername());
			properties.put("spring.datasource.password", cfJdbcService.getPassword());
			Object driverClassName = cfJdbcService.getDriverClassName();
			if (driverClassName != null) {
				properties.put("spring.datasource.driver-class-name", driverClassName);
			}

			MutablePropertySources propertySources = environment.getPropertySources();
			if (propertySources.contains(
					CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) {
				propertySources.addAfter(
						CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME,
						new MapPropertySource("cfenvjdbc", properties));
			}
			else {
				propertySources
						.addFirst(new MapPropertySource("cfenvjdbc", properties));
			}
			if (invocationCount == 1) {
				DEFERRED_LOG.info(
						"Setting spring.datasource properties from bound service ["
								+ cfJdbcService.getName() + "]");
			}
		}
	}
	else {
		DEFERRED_LOG.debug(
				"Not setting spring.datasource.url, not in Cloud Foundry Environment");
	}
}
 
示例6
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
	return !CloudPlatform.CLOUD_FOUNDRY.isActive(context.getEnvironment());
}
 
示例7
private boolean isCloudFoundryEnvironment(Environment environment) {
	return CloudPlatform.CLOUD_FOUNDRY.isActive(environment);
}
 
示例8
@Test(expected = NoSuchBeanDefinitionException.class)
public void testLocalSchedulerEnabled() {
	assertFalse(context.getEnvironment().containsProperty("kubernetes_service_host"));
	assertFalse(CloudPlatform.CLOUD_FOUNDRY.isActive(context.getEnvironment()));
	context.getBean(Scheduler.class);
}
 
示例9
public boolean isAutoDeregistration(Environment environment) {
	return (this.autoDeregistration != null) ? this.autoDeregistration
			: (CloudPlatform.getActive(environment) != null);
}