org.cloudfoundry.operations.DefaultCloudFoundryOperations Java Examples

The following examples show how to use org.cloudfoundry.operations.DefaultCloudFoundryOperations. 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: StopAppPolicyExecutorTask.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
protected Mono<HistoricalRecord> stopApplication(AppDetail detail) {
	return DefaultCloudFoundryOperations.builder()
            .from(opsClient)
            .organization(detail.getOrganization())
            .space(detail.getSpace())
            .build()
.getCloudFoundryClient()
.applicationsV3()
	.stop(
			StopApplicationRequest
				.builder()
					.applicationId(detail.getAppId())
					.build())
	.then(Mono.just(HistoricalRecord
				.builder()
					.transactionDateTime(LocalDateTime.now())
					.actionTaken("stop")
					.organization(detail.getOrganization())
					.space(detail.getSpace())
					.appId(detail.getAppId())
					.type("application")
					.name(detail.getAppName())
					.build()));
}
 
Example #2
Source File: DeleteAppPolicyExecutorTask.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
@Autowired
public DeleteAppPolicyExecutorTask(
		PasSettings settings,
		DefaultCloudFoundryOperations opsClient,
		AppDetailService appInfoService,
		AppRelationshipService appRelationshipService,
		PoliciesService policiesService,
		HistoricalRecordService historicalRecordService
		) {
	this.settings = settings;
    this.opsClient = opsClient;
    this.appInfoService = appInfoService;
    this.appRelationshipService = appRelationshipService;
    this.policiesService = policiesService;
    this.historicalRecordService = historicalRecordService;
}
 
Example #3
Source File: ScaleAppInstancesPolicyExecutorTask.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
protected Mono<HistoricalRecord> scaleApplication(ApplicationPolicy policy, AppDetail detail) {
	return DefaultCloudFoundryOperations.builder()
            .from(opsClient)
            .organization(detail.getOrganization())
            .space(detail.getSpace())
            .build()
.applications()
	.scale(
			ScaleApplicationRequest
				.builder()
					.name(detail.getAppName())
					.instances(policy.getOption("instances-to", Integer.class))
					.build())
	.then(Mono.just(HistoricalRecord
				.builder()
					.transactionDateTime(LocalDateTime.now())
					.actionTaken("scale-instances")
					.organization(detail.getOrganization())
					.space(detail.getSpace())
					.appId(detail.getAppId())
					.type("application")
					.name(detail.getAppName())
					.build()));
}
 
Example #4
Source File: DeleteServiceInstancePolicyExecutorTask.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
protected Mono<HistoricalRecord> deleteServiceInstance(ServiceInstanceDetail sd) {
	return DefaultCloudFoundryOperations.builder()
            .from(opsClient)
            .organization(sd.getOrganization())
            .space(sd.getSpace())
            .build()
	.services()
		.deleteInstance(DeleteServiceInstanceRequest.builder().name(sd.getName()).build())
		.then(Mono.just(HistoricalRecord
					.builder()
						.transactionDateTime(LocalDateTime.now())
						.actionTaken("delete")
						.organization(sd.getOrganization())
						.space(sd.getSpace())
						.serviceInstanceId(sd.getServiceInstanceId())
						.type("service-instance")
						.name(String.join("__", sd.getName(), sd.getType(), sd.getPlan()))
						.build()));
}
 
Example #5
Source File: DeleteAppPolicyExecutorTask.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
protected Mono<HistoricalRecord> unbindServiceInstance(AppRelationship relationship) {
	return DefaultCloudFoundryOperations.builder()
            .from(opsClient)
            .organization(relationship.getOrganization())
            .space(relationship.getSpace())
            .build()
            	.services()
            		.unbind(
            				UnbindServiceInstanceRequest
            					.builder()
            						.applicationName(relationship.getAppName())
            						.serviceInstanceName(relationship.getServiceName())
            						.build())
            		.then(Mono.just(HistoricalRecord
								.builder()
									.transactionDateTime(LocalDateTime.now())
									.actionTaken("unbind")
									.organization(relationship.getOrganization())
									.space(relationship.getSpace())
									.appId(relationship.getAppId())
									.serviceInstanceId(relationship.getServiceInstanceId())
									.type("service-instance")
									.name(serviceInstanceName(relationship))
									.build()));
}
 
Example #6
Source File: StackChangeAppInstancesPolicyExecutorTask.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
private Mono<UpdateApplicationResponse> assignTargetStack(ApplicationPolicy policy, AppDetail detail) {
	LifecycleData data =
		BuildpackLifecycleData
			.builder()
			.stack(policy.getOption("stack-to", String.class))
			.build();
	Lifecycle lifecycle =
		Lifecycle
			.builder()
			.type(LifecycleType.BUILDPACK)
			.data(data)
			.build();
	return DefaultCloudFoundryOperations.builder()
               .from(opsClient)
               .organization(detail.getOrganization())
               .space(detail.getSpace())
               .build()
			.getCloudFoundryClient()
				.applicationsV3()
				.update(
						UpdateApplicationRequest
							.builder()
								.applicationId(detail.getAppId())
								.lifecycle(lifecycle)
								.build());
}
 
Example #7
Source File: CloudFoundryTestSupport.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 6 votes vote down vote up
@Bean
public CloudFoundryOperations cloudFoundryOperations(CloudFoundryClient cloudFoundryClient,
													 ConnectionContext connectionContext,
													 TokenProvider tokenProvider,
													 CloudFoundryConnectionProperties properties) {
	ReactorDopplerClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();

	ReactorUaaClient.builder()
		.connectionContext(connectionContext)
		.tokenProvider(tokenProvider)
		.build();

	return DefaultCloudFoundryOperations.builder()
		.cloudFoundryClient(cloudFoundryClient)
		.organization(properties.getOrg())
		.space(properties.getSpace())
		.build();
}
 
Example #8
Source File: AppDetailTask.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
@Autowired
public AppDetailTask(
        PivnetCache pivnetCache,
        PasSettings settings,
		DefaultCloudFoundryOperations opsClient,
        AppDetailService appDetailsService,
        EventsService eventsService,
        BuildpacksCache buildpacksCache,
        StacksCache stacksCache,
        ApplicationEventPublisher publisher,
        AppDetailReadyToBeCollectedDecider appDetailReadyToBeCollectedDecider) {
    this.pivnetCache = pivnetCache;
    this.settings = settings;
    this.opsClient = opsClient;
    this.appDetailsService = appDetailsService;
    this.eventsService = eventsService;
    this.buildpacksCache = buildpacksCache;
    this.stacksCache = stacksCache;
    this.publisher = publisher;
    this.appDetailReadyToBeCollectedDecider = appDetailReadyToBeCollectedDecider;
}
 
Example #9
Source File: UserCloudFoundryService.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
public UserCloudFoundryService(CloudFoundryOperations cloudFoundryOperations, CloudFoundryProperties cloudFoundryProperties) {
	DefaultCloudFoundryOperations sourceCloudFoundryOperations =
		(DefaultCloudFoundryOperations) cloudFoundryOperations;

	this.targetOrg = cloudFoundryProperties.getDefaultOrg() + "-instances";
	this.targetSpace = cloudFoundryProperties.getDefaultSpace();

	ClientCredentialsGrantTokenProvider tokenProvider = ClientCredentialsGrantTokenProvider.builder()
		.clientId(USER_CLIENT_ID)
		.clientSecret(USER_CLIENT_SECRET)
		.build();

	ReactorCloudFoundryClient cloudFoundryClient = ReactorCloudFoundryClient.builder()
		.from((ReactorCloudFoundryClient) sourceCloudFoundryOperations.getCloudFoundryClient())
		.tokenProvider(tokenProvider)
		.build();

	this.cloudFoundryOperations = DefaultCloudFoundryOperations
		.builder()
		.from(sourceCloudFoundryOperations)
		.space(targetSpace)
		.organization(targetOrg)
		.cloudFoundryClient(cloudFoundryClient)
		.build();
}
 
Example #10
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 #11
Source File: DeleteAppPolicyExecutorTask.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
protected Mono<HistoricalRecord> deleteServiceInstance(AppRelationship relationship) {
	return DefaultCloudFoundryOperations.builder()
            .from(opsClient)
            .organization(relationship.getOrganization())
            .space(relationship.getSpace())
            .build()
	.services()
		.deleteInstance(DeleteServiceInstanceRequest.builder().name(relationship.getServiceName()).build())
		.then(Mono.just(HistoricalRecord
					.builder()
						.transactionDateTime(LocalDateTime.now())
						.actionTaken("delete")
						.organization(relationship.getOrganization())
						.space(relationship.getSpace())
						.appId(relationship.getAppId())
						.serviceInstanceId(relationship.getServiceInstanceId())
						.type("service-instance")
						.name(serviceInstanceName(relationship))
						.build()));
}
 
Example #12
Source File: DeleteAppPolicyExecutorTask.java    From cf-butler with Apache License 2.0 6 votes vote down vote up
protected Mono<HistoricalRecord> deleteApplication(AppDetail detail) {
	return DefaultCloudFoundryOperations.builder()
            .from(opsClient)
            .organization(detail.getOrganization())
            .space(detail.getSpace())
            .build()
.applications()
	.delete(
			DeleteApplicationRequest
				.builder()
					.name(detail.getAppName())
					.deleteRoutes(true)
					.build())
	.then(Mono.just(HistoricalRecord
				.builder()
					.transactionDateTime(LocalDateTime.now())
					.actionTaken("delete")
					.organization(detail.getOrganization())
					.space(detail.getSpace())
					.appId(detail.getAppId())
					.type("application")
					.name(detail.getAppName())
					.build()));
}
 
Example #13
Source File: CloudFoundryService.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
public Mono<SpaceSummary> getOrCreateSpace(String orgName, String spaceName) {
	Spaces spaceOperations = DefaultCloudFoundryOperations.builder()
		.from((DefaultCloudFoundryOperations) this.cloudFoundryOperations)
		.organization(orgName)
		.build()
		.spaces();

	return getSpace(spaceOperations, spaceName).switchIfEmpty(spaceOperations.create(CreateSpaceRequest.builder()
		.name(spaceName)
		.organization(orgName)
		.build())
		.then(getSpace(spaceOperations, spaceName)));
}
 
Example #14
Source File: CloudFoundryClientConfiguration.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Bean
protected CloudFoundryOperations cloudFoundryOperations(CloudFoundryProperties properties,
	CloudFoundryClient client,
	DopplerClient dopplerClient,
	UaaClient uaaClient) {
	return DefaultCloudFoundryOperations.builder()
		.cloudFoundryClient(client)
		.dopplerClient(dopplerClient)
		.uaaClient(uaaClient)
		.organization(properties.getDefaultOrg())
		.space(properties.getDefaultSpace())
		.build();
}
 
Example #15
Source File: CloudFoundryOperationsUtils.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
protected Mono<CloudFoundryOperations> getOperationsForOrgAndSpace(String organization, String space) {
	return Mono.just(this.operations)
		.cast(DefaultCloudFoundryOperations.class)
		.map(cfOperations -> DefaultCloudFoundryOperations.builder()
			.from(cfOperations)
			.organization(organization)
			.space(space)
			.build());
}
 
Example #16
Source File: CloudFoundryOperationsUtils.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
protected Mono<CloudFoundryOperations> getOperationsForSpace(String space) {
	return Mono.just(this.operations)
		.cast(DefaultCloudFoundryOperations.class)
		.map(cfOperations -> DefaultCloudFoundryOperations.builder()
			.from(cfOperations)
			.space(space)
			.build());
}
 
Example #17
Source File: CloudFoundryAppDeployerAutoConfiguration.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
/**
 * Provide a {@link CloudFoundryOperations} bean
 *
 * @param properties the CloudFoundryTargetProperties bean
 * @param client the CloudFoundryClient bean
 * @param dopplerClient the DopplerClient bean
 * @param uaaClient the UaaClient bean
 * @return the bean
 */
@Bean
public CloudFoundryOperations cloudFoundryOperations(CloudFoundryTargetProperties properties,
	CloudFoundryClient client, DopplerClient dopplerClient, @UaaClientQualifier UaaClient uaaClient) {
	return DefaultCloudFoundryOperations.builder()
		.cloudFoundryClient(client)
		.dopplerClient(dopplerClient)
		.uaaClient(uaaClient)
		.organization(properties.getDefaultOrg())
		.space(properties.getDefaultSpace())
		.build();
}
 
Example #18
Source File: CloudFoundryClientConfiguration.java    From bootiful-testing-online-training with Apache License 2.0 5 votes vote down vote up
@Bean
public DefaultCloudFoundryOperations cloudFoundryOperations(
	CloudFoundryClient cfc,
	ReactorDopplerClient dopplerClient,
	ReactorUaaClient uaaClient,
	@Value("${cf.org}") String organization,
	@Value("${cf.space}") String space) {
	return DefaultCloudFoundryOperations.builder()
		.cloudFoundryClient(cfc)
		.dopplerClient(dopplerClient)
		.uaaClient(uaaClient)
		.organization(organization)
		.space(space)
		.build();
}
 
Example #19
Source File: CloudFoundryService.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private CloudFoundryOperations createOperationsForSpace(String space) {
	final String defaultOrg = cloudFoundryProperties.getDefaultOrg();
	return DefaultCloudFoundryOperations.builder()
		.from((DefaultCloudFoundryOperations) cloudFoundryOperations)
		.organization(defaultOrg)
		.space(space)
		.build();
}
 
Example #20
Source File: ScaleAppInstancesPolicyExecutorTask.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Autowired
public ScaleAppInstancesPolicyExecutorTask(
		PasSettings settings,
		DefaultCloudFoundryOperations opsClient,
		AppDetailService appInfoService,
		PoliciesService policiesService,
		HistoricalRecordService historicalRecordService
		) {
	this.settings = settings;
    this.opsClient = opsClient;
    this.appInfoService = appInfoService;
    this.policiesService = policiesService;
    this.historicalRecordService = historicalRecordService;
}
 
Example #21
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 #22
Source File: CfConfiguration.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Bean
DefaultCloudFoundryOperations defaultCloudFoundryOperations(
		CloudFoundryClient cloudFoundryClient, DopplerClient dopplerClient,
		UaaClient uaaClient, @Value("${cf.organization}") String organizationId,
		@Value("${cf.space}") String spaceId) {
	return DefaultCloudFoundryOperations.builder()
			.cloudFoundryClient(cloudFoundryClient).dopplerClient(dopplerClient)
			.uaaClient(uaaClient).organization(organizationId).space(spaceId).build();
}
 
Example #23
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 #24
Source File: CloudFoundryDeployerAutoConfiguration.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public CloudFoundryOperations cloudFoundryOperations(CloudFoundryClient cloudFoundryClient, CloudFoundryConnectionProperties properties) {
	return DefaultCloudFoundryOperations.builder()
		.cloudFoundryClient(cloudFoundryClient)
		.organization(properties.getOrg())
		.space(properties.getSpace())
		.build();
}
 
Example #25
Source File: CloudFoundryTaskPlatformFactory.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private CloudFoundryOperations cloudFoundryOperations(CloudFoundryClient cloudFoundryClient, String account) {
	return DefaultCloudFoundryOperations
			.builder().cloudFoundryClient(cloudFoundryClient)
			.organization(connectionProperties(account).getOrg())
			.dopplerClient(ReactorDopplerClient.builder()
					.connectionContext(connectionContext(account))
					.tokenProvider(tokenProvider(account)).build())
			.space(connectionProperties(account).getSpace()).build();
}
 
Example #26
Source File: CloudFoundryClientAutoConfiguration.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy
@ConditionalOnMissingBean
public DefaultCloudFoundryOperations cloudFoundryOperations(
		CloudFoundryClient cloudFoundryClient, DopplerClient dopplerClient,
		RoutingClient routingClient, UaaClient uaaClient) {
	String organization = this.cloudFoundryProperties.getOrg();
	String space = this.cloudFoundryProperties.getSpace();
	return DefaultCloudFoundryOperations.builder()
			.cloudFoundryClient(cloudFoundryClient).dopplerClient(dopplerClient)
			.routingClient(routingClient).uaaClient(uaaClient)
			.organization(organization).space(space).build();
}
 
Example #27
Source File: CloudFoundryClientAutoConfigurationTest.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void autoConfiguresBeansWithAllProperties() {
	this.contextRunner.withPropertyValues("spring.cloud.cloudfoundry.username=user",
			"spring.cloud.cloudfoundry.password=secret",
			"spring.cloud.cloudfoundry.org=myorg",
			"spring.cloud.cloudfoundry.space=myspace").run((context) -> {
				assertCloudFoundryClientBeansPresent(context);

				DefaultCloudFoundryOperations operations = context
						.getBean(DefaultCloudFoundryOperations.class);
				assertThat(operations.getOrganization()).isEqualTo("myorg");
				assertThat(operations.getSpace()).isEqualTo("myspace");
			});
}
 
Example #28
Source File: CloudFoundryClientAutoConfigurationTest.java    From spring-cloud-cloudfoundry with Apache License 2.0 5 votes vote down vote up
@Test
public void autoConfiguresBeansWithMinimalProperties() {
	this.contextRunner.withPropertyValues("spring.cloud.cloudfoundry.username=user",
			"spring.cloud.cloudfoundry.password=secret").run((context) -> {
				assertCloudFoundryClientBeansPresent(context);

				DefaultCloudFoundryOperations operations = context
						.getBean(DefaultCloudFoundryOperations.class);
				assertThat(operations.getOrganization()).isNullOrEmpty();
				assertThat(operations.getSpace()).isNullOrEmpty();
			});
}
 
Example #29
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 #30
Source File: AppRelationshipTask.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Autowired
public AppRelationshipTask(
		DefaultCloudFoundryOperations opsClient,
		AppRelationshipService service,
		ApplicationEventPublisher publisher
		) {
    this.opsClient = opsClient;
    this.service = service;
    this.publisher = publisher;
}