org.cloudfoundry.reactor.DefaultConnectionContext Java Examples

The following examples show how to use org.cloudfoundry.reactor.DefaultConnectionContext. 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: AbstractCfTask.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
protected CloudFoundryOperations getCfOperations() {
    CfProperties cfAppProperties = this.cfPropertiesMapper.getProperties();

    ConnectionContext connectionContext = DefaultConnectionContext.builder()
        .apiHost(cfAppProperties.ccHost())
        .skipSslValidation(true)
        .proxyConfiguration(tryGetProxyConfiguration(cfAppProperties))
        .build();

    TokenProvider tokenProvider = getTokenProvider(cfAppProperties);

    CloudFoundryClient cfClient = ReactorCloudFoundryClient.builder()
        .connectionContext(connectionContext)
        .tokenProvider(tokenProvider)
        .build();

    DefaultCloudFoundryOperations cfOperations = DefaultCloudFoundryOperations.builder()
        .cloudFoundryClient(cfClient)
        .organization(cfAppProperties.org())
        .space(cfAppProperties.space())
        .build();

    return cfOperations;
}
 
Example #2
Source File: ReactiveCFAccessorImpl.java    From promregator with Apache License 2.0 6 votes vote down vote up
private DefaultConnectionContext connectionContext(ProxyConfiguration proxyConfiguration) throws ConfigurationException {
	if (apiHost != null && PATTERN_HTTP_BASED_PROTOCOL_PREFIX.matcher(apiHost).find()) {
		throw new ConfigurationException("cf.api_host configuration parameter must not contain an http(s)://-like prefix; specify the hostname only instead");
	}

	Builder connctx = DefaultConnectionContext.builder()
			.apiHost(apiHost)
			.skipSslValidation(skipSSLValidation);
	
	if (proxyConfiguration != null) {
		connctx = connctx.proxyConfiguration(proxyConfiguration);
	}
	
	if (this.connectionPoolSize != null) {
		connctx = connctx.connectionPoolSize(this.connectionPoolSize);
	}
	
	if (this.threadPoolSize != null) {
		connctx = connctx.threadPoolSize(this.threadPoolSize);
	}
	
	return connctx.build();
}
 
Example #3
Source File: PlatformCloudFoundryOperations.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
private CloudFoundryOperations buildCloudFoundryOperations(String platformName) {
	CloudFoundryPlatformProperties.CloudFoundryProperties cloudFoundryProperties = this.cloudFoundryPlatformProperties
			.getAccounts()
			.get(platformName);
	CloudFoundryConnectionProperties connectionProperties = cloudFoundryProperties.getConnection();
	ConnectionContext connectionContext = DefaultConnectionContext.builder()
			.apiHost(connectionProperties.getUrl().getHost())
			.skipSslValidation(connectionProperties.isSkipSslValidation())
			.build();
	Builder tokenProviderBuilder = PasswordGrantTokenProvider.builder()
			.username(connectionProperties.getUsername())
			.password(connectionProperties.getPassword())
			.loginHint(connectionProperties.getLoginHint());
	if (StringUtils.hasText(connectionProperties.getClientId())) {
		tokenProviderBuilder.clientId(connectionProperties.getClientId());
	}
	if (StringUtils.hasText(connectionProperties.getClientSecret())) {
		tokenProviderBuilder.clientSecret(connectionProperties.getClientSecret());
	}
	TokenProvider tokenProvider = tokenProviderBuilder.build();
	CloudFoundryClient cloudFoundryClient = ReactorCloudFoundryClient.builder()
			.connectionContext(connectionContext)
			.tokenProvider(tokenProvider)
			.build();
	return DefaultCloudFoundryOperations
			.builder().cloudFoundryClient(cloudFoundryClient)
			.organization(connectionProperties.getOrg())
			.space(connectionProperties.getSpace()).build();
}
 
Example #4
Source File: CloudFoundryClientAutoConfigurationTest.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private void assertCloudFoundryClientBeansPresent(
		AssertableApplicationContext context) {
	assertThat(context).hasSingleBean(ReactorCloudFoundryClient.class);
	assertThat(context).hasSingleBean(DefaultCloudFoundryOperations.class);
	assertThat(context).hasSingleBean(DefaultConnectionContext.class);
	assertThat(context).hasSingleBean(DopplerClient.class);
	assertThat(context).hasSingleBean(RoutingClient.class);
	assertThat(context).hasSingleBean(PasswordGrantTokenProvider.class);
	assertThat(context).hasSingleBean(ReactorUaaClient.class);
}
 
Example #5
Source File: CloudFoundryClientAutoConfiguration.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy
@ConditionalOnMissingBean
public DefaultConnectionContext connectionContext() {
	String apiHost = this.cloudFoundryProperties.getUrl();
	Boolean skipSslValidation = this.cloudFoundryProperties.isSkipSslValidation();

	return DefaultConnectionContext.builder().apiHost(apiHost)
			.skipSslValidation(skipSslValidation).build();
}
 
Example #6
Source File: CloudFoundryPlatformConnectionContextProvider.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
public ConnectionContext connectionContext(String account) {
	CloudFoundryConnectionProperties connectionProperties =
		this.platformProperties.accountProperties(account).getConnection();
	this.connectionContexts.putIfAbsent(account, DefaultConnectionContext.builder()
		.apiHost(connectionProperties.getUrl().getHost())
		.skipSslValidation(connectionProperties.isSkipSslValidation())
		.build());
	return connectionContexts.get(account);
}
 
Example #7
Source File: CloudFoundryTestSupport.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
public ConnectionContext connectionContext(CloudFoundryConnectionProperties properties) {
	return DefaultConnectionContext.builder()
			.apiHost(properties.getUrl().getHost())
			.skipSslValidation(properties.isSkipSslValidation())
			.build();
}
 
Example #8
Source File: CloudFoundryDeployerAutoConfiguration.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public ConnectionContext connectionContext(CloudFoundryConnectionProperties properties) {
	return DefaultConnectionContext.builder()
		.apiHost(properties.getUrl().getHost())
		.skipSslValidation(properties.isSkipSslValidation())
		.build();
}
 
Example #9
Source File: PcfDevIntegrationTests.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
    public void getAppDetailTests() {
        ConnectionContext connectionContext = DefaultConnectionContext.builder()
            .apiHost("api.local.pcfdev.io")
            .skipSslValidation(true)
            .build();

        TokenProvider tokenProvider = PasswordGrantTokenProvider.builder()
            .password("admin")
            .username("admin")
            .build();

        CloudFoundryClient cfClient = ReactorCloudFoundryClient.builder()
            .connectionContext(connectionContext)
            .tokenProvider(tokenProvider)
            .build();

        CloudFoundryOperations cfOperations = DefaultCloudFoundryOperations.builder()
            .cloudFoundryClient(cfClient)
            .organization("pcfdev-org")
            .space("pcfdev-space")
            .build();

        CfAppDetailsDelegate appDetailsTaskDelegate = new CfAppDetailsDelegate();
        CfProperties cfAppProps = envDetails();
        Mono<Optional<ApplicationDetail>> applicationDetailMono = appDetailsTaskDelegate
            .getAppDetails(cfOperations, cfAppProps);


//		Mono<Void> resp = applicationDetailMono.then(applicationDetail -> Mono.fromSupplier(() -> {
//			return 1;
//		})).then();
//
//		resp.block();
//		ApplicationDetail applicationDetail = applicationDetailMono.block(Duration.ofMillis(5000));
//		System.out.println("applicationDetail = " + applicationDetail);
    }
 
Example #10
Source File: CloudFoundryClientFactory.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
private ConnectionContext createConnectionContext(String controllerApiHost) {
    DefaultConnectionContext.Builder builder = DefaultConnectionContext.builder()
                                                                       .apiHost(controllerApiHost);
    getSslHandshakeTimeout().ifPresent(builder::sslHandshakeTimeout);
    getConnectTimeout().ifPresent(builder::connectTimeout);
    getConnectionPoolSize().ifPresent(builder::connectionPoolSize);
    getThreadPoolSize().ifPresent(builder::threadPoolSize);
    builder.additionalHttpClientConfiguration(client -> client.metrics(true));
    return builder.build();
}
 
Example #11
Source File: ResourceMetadataService.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Autowired
public ResourceMetadataService(
    WebClient webClient,
    DefaultConnectionContext connectionContext,
    TokenProvider tokenProvider,
    PasSettings settings) {
    this.webClient = webClient;
    this.connectionContext = connectionContext;
    this.tokenProvider = tokenProvider;
    this.settings = settings;
}
 
Example #12
Source File: CloudFoundryClientConfiguration.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Bean
protected ConnectionContext connectionContext(CloudFoundryProperties properties) {
	return DefaultConnectionContext.builder()
		.apiHost(properties.getApiHost())
		.port(Optional.ofNullable(properties.getApiPort()))
		.skipSslValidation(properties.isSkipSslValidation())
		.secure(properties.isSecure())
		.build();
}
 
Example #13
Source File: CloudFoundryAppDeployerAutoConfigurationTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void clientIsCreatedWithCredentialsGrantConfiguration() {
	this.contextRunner
		.withPropertyValues(
			"spring.cloud.appbroker.deployer.cloudfoundry.api-host=api.example.local",
			"spring.cloud.appbroker.deployer.cloudfoundry.api-port=443",
			"spring.cloud.appbroker.deployer.cloudfoundry.default-org=example-org",
			"spring.cloud.appbroker.deployer.cloudfoundry.default-space=example-space",
			"spring.cloud.appbroker.deployer.cloudfoundry.client-id=oauth-client",
			"spring.cloud.appbroker.deployer.cloudfoundry.client-secret=secret"
		)
		.run((context) -> {
			assertThat(context).hasSingleBean(CloudFoundryTargetProperties.class);
			CloudFoundryTargetProperties targetProperties = context.getBean(CloudFoundryTargetProperties.class);
			assertThat(targetProperties.getApiHost()).isEqualTo("api.example.local");
			assertThat(targetProperties.getApiPort()).isEqualTo(443);
			assertThat(targetProperties.getDefaultOrg()).isEqualTo("example-org");
			assertThat(targetProperties.getDefaultSpace()).isEqualTo("example-space");
			assertThat(targetProperties.getClientId()).isEqualTo("oauth-client");
			assertThat(targetProperties.getClientSecret()).isEqualTo("secret");

			assertThat(context).hasSingleBean(AppDeployer.class);
			assertThat(context).hasSingleBean(AppManager.class);

			assertThat(context).hasSingleBean(ReactorCloudFoundryClient.class);
			assertThat(context).hasSingleBean(ReactorDopplerClient.class);
			assertThat(context).hasSingleBean(ReactorUaaClient.class);
			assertThat(context).hasSingleBean(CloudFoundryOperations.class);
			assertThat(context).hasSingleBean(CloudFoundryOperationsUtils.class);
			assertThat(context).hasSingleBean(DefaultConnectionContext.class);
			assertThat(context).hasSingleBean(ClientCredentialsGrantTokenProvider.class);
		});
}
 
Example #14
Source File: CloudFoundryAppDeployerAutoConfiguration.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
/**
 * Provide a {@link DefaultConnectionContext} bean
 *
 * @param properties the CloudFoundryTargetProperties bean
 * @return the bean
 */
@Bean
public DefaultConnectionContext connectionContext(CloudFoundryTargetProperties properties) {
	return DefaultConnectionContext.builder()
		.apiHost(properties.getApiHost())
		.port(Optional.ofNullable(properties.getApiPort()))
		.skipSslValidation(properties.isSkipSslValidation())
		.secure(properties.isSecure())
		.build();
}
 
Example #15
Source File: CloudFoundryClientConfiguration.java    From bootiful-testing-online-training with Apache License 2.0 5 votes vote down vote up
@Bean
DefaultConnectionContext connectionContext(
	@Value("${cf.api}") String apiHost,
	@Value("${cf.skip-ssl-validation:false}") boolean skipSsl) {
	if (apiHost.contains("://")) {
		apiHost = apiHost.split("://")[1];
	}
	return DefaultConnectionContext
		.builder()
		.skipSslValidation(skipSsl)
		.apiHost(apiHost)
		.build();
}
 
Example #16
Source File: ButlerConfig.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Bean
public DefaultConnectionContext connectionContext(PasSettings settings) {
    return DefaultConnectionContext
            .builder()
                .apiHost(settings.getApiHost())
                .skipSslValidation(settings.isSslValidationSkipped())
                .keepAlive(true)
                .connectionPoolSize(settings.getConnectionPoolSize())
                .connectTimeout(Duration.parse(settings.getConnectionTimeout()))
                .sslHandshakeTimeout(Duration.ofSeconds(30))
                .build();
}
 
Example #17
Source File: EventsService.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Autowired
public EventsService(
    WebClient webClient,
    DefaultConnectionContext connectionContext,
    TokenProvider tokenProvider,
    PasSettings settings) {
    this.webClient = webClient;
    this.connectionContext = connectionContext;
    this.tokenProvider = tokenProvider;
    this.settings = settings;
}
 
Example #18
Source File: UsageService.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Autowired
public UsageService(
    OrganizationService orgService,
    WebClient webClient,
    DefaultConnectionContext connectionContext,
    TokenProvider tokenProvider,
    PasSettings settings,
    UsageCache cache) {
    this.orgService = orgService;
    this.webClient = webClient;
    this.connectionContext = connectionContext;
    this.tokenProvider = tokenProvider;
    this.settings = settings;
}
 
Example #19
Source File: CfConfiguration.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
@Bean
DefaultConnectionContext connectionContext(@Value("${cf.apiHost}") String apiHost) {
	return DefaultConnectionContext.builder().apiHost(apiHost).build();
}
 
Example #20
Source File: CloudFoundryAppDeployerAutoConfigurationTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void clientIsCreatedWithPasswordGrantConfiguration() {
	this.contextRunner
		.withPropertyValues(
			"spring.cloud.appbroker.deployer.cloudfoundry.api-host=api.example.local",
			"spring.cloud.appbroker.deployer.cloudfoundry.api-port=443",
			"spring.cloud.appbroker.deployer.cloudfoundry.default-org=example-org",
			"spring.cloud.appbroker.deployer.cloudfoundry.default-space=example-space",
			"spring.cloud.appbroker.deployer.cloudfoundry.username=user",
			"spring.cloud.appbroker.deployer.cloudfoundry.password=secret",
			"spring.cloud.appbroker.deployer.cloudfoundry.properties.memory=2G",
			"spring.cloud.appbroker.deployer.cloudfoundry.properties.count=3",
			"spring.cloud.appbroker.deployer.cloudfoundry.properties.buildpack=example-buildpack",
			"spring.cloud.appbroker.deployer.cloudfoundry.properties.domain=example.local"
		)
		.run((context) -> {
			assertThat(context).hasSingleBean(CloudFoundryTargetProperties.class);
			CloudFoundryTargetProperties targetProperties = context.getBean(CloudFoundryTargetProperties.class);
			assertThat(targetProperties.getApiHost()).isEqualTo("api.example.local");
			assertThat(targetProperties.getApiPort()).isEqualTo(443);
			assertThat(targetProperties.getDefaultOrg()).isEqualTo("example-org");
			assertThat(targetProperties.getDefaultSpace()).isEqualTo("example-space");
			assertThat(targetProperties.getUsername()).isEqualTo("user");
			assertThat(targetProperties.getPassword()).isEqualTo("secret");

			assertThat(context).hasSingleBean(CloudFoundryDeploymentProperties.class);
			CloudFoundryDeploymentProperties deploymentProperties = context
				.getBean(CloudFoundryDeploymentProperties.class);
			assertThat(deploymentProperties.getMemory()).isEqualTo("2G");
			assertThat(deploymentProperties.getCount()).isEqualTo(3);
			assertThat(deploymentProperties.getBuildpack()).isEqualTo("example-buildpack");
			assertThat(deploymentProperties.getDomain()).isEqualTo("example.local");

			assertThat(context).hasSingleBean(AppDeployer.class);
			assertThat(context).hasSingleBean(AppManager.class);
			assertThat(context).hasSingleBean(OAuth2Client.class);

			assertThat(context).hasSingleBean(ReactorCloudFoundryClient.class);
			assertThat(context).hasSingleBean(ReactorDopplerClient.class);
			assertThat(context).hasSingleBean(ReactorUaaClient.class);
			assertThat(context).hasSingleBean(CloudFoundryOperations.class);
			assertThat(context).hasSingleBean(CloudFoundryOperationsUtils.class);
			assertThat(context).hasSingleBean(DefaultConnectionContext.class);
			assertThat(context).hasSingleBean(PasswordGrantTokenProvider.class);
		});
}