org.cloudfoundry.operations.CloudFoundryOperations Java Examples

The following examples show how to use org.cloudfoundry.operations.CloudFoundryOperations. 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: CfCreateServiceHelperTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateServiceWithNoExistingService() {
    CloudFoundryOperations cfOps = mock(CloudFoundryOperations.class);
    Services mockServices = mock(Services.class);

    when(mockServices
        .getInstance(any(GetServiceInstanceRequest.class)))
        .thenReturn(Mono.empty());

    when(cfOps.services()).thenReturn(mockServices);

    CfServiceDetail cfServiceDetail = ImmutableCfServiceDetail
        .builder().name("testName")
        .plan("testPlan")
        .instanceName("inst")
        .build();


    Mono<ServiceInstance> createServiceResult = this.cfCreateServiceHelper.createService(cfOps, cfServiceDetail);

    StepVerifier.create(createServiceResult)
        .verifyComplete();
}
 
Example #2
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 #3
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 #4
Source File: CfCreateServicesTask.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@TaskAction
public void cfCreateServiceTask() {

    CloudFoundryOperations cfOperations = getCfOperations();
    CfProperties cfProperties = getCfProperties();

    List<Mono<Void>> createServicesResult = cfProperties.cfServices()
        .stream()
        .map(service -> createServiceHelper.createService(cfOperations, service).then())
        .collect(Collectors.toList());

    List<Mono<Void>> createUserProvidedServicesResult = cfProperties.cfUserProvidedServices()
        .stream()
        .map(service -> userProvidedServiceHelper.createUserProvidedService(cfOperations, service))
        .collect(Collectors.toList());

    Flux.merge(createServicesResult).toIterable().forEach(r -> {
    });
    Flux.merge(createUserProvidedServicesResult).toIterable().forEach(r -> {
    });
}
 
Example #5
Source File: CfRenameAppTask.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@TaskAction
public void renameApp() {
    CloudFoundryOperations cfOperations = getCfOperations();
    CfProperties cfAppProperties = getCfProperties();

    if (getNewName() == null) {
        throw new RuntimeException("New name not provided");
    }

    CfProperties oldCfProperties = cfAppProperties;

    CfProperties newCfProperties = ImmutableCfProperties.copyOf(oldCfProperties).withName(getNewName());

    Mono<Void> resp = renameDelegate.renameApp(cfOperations, oldCfProperties, newCfProperties);

    resp.block(Duration.ofMillis(defaultWaitTimeout));
}
 
Example #6
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 #7
Source File: CfMapRouteDelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void mapRoutesExplicitWithInvalidDomains() {
    CfMapRouteDelegate cfMapRouteDelegate = new CfMapRouteDelegate();
    CloudFoundryOperations cfOperations = mock(CloudFoundryOperations.class);
    Routes mockRoutes = mock(Routes.class);
    when(mockRoutes.map(any(MapRouteRequest.class))).thenReturn(Mono.just(123));
    when(cfOperations.routes()).thenReturn(mockRoutes);
    Domains mockDomains = mock(Domains.class);
    when(mockDomains.list())
        .thenReturn(
            Flux.just(
                Domain.builder().id("id1").name("test1.domain").type("typ").status(Status.SHARED).build(),
                Domain.builder().id("id2").name("test2.domain").type("typ").status(Status.SHARED).build()
            )
        );

    when(cfOperations.domains()).thenReturn(mockDomains);
    CfProperties cfProperties = sampleApp(Arrays.asList("app1.test1.domain", "app2.invalid.domain"));
    Flux<Integer> result = cfMapRouteDelegate
        .mapRoute(cfOperations, cfProperties);
    StepVerifier.create(result)
        .expectError(IllegalArgumentException.class)
        .verify();
}
 
Example #8
Source File: CfAppEnvDelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetEnvironmentsNoApplication() {
    CloudFoundryOperations cfOperations = mock(CloudFoundryOperations.class);
    CfProperties cfAppProperties = sampleApp();

    Applications mockApplications = mock(Applications.class);
    when(cfOperations.applications()).thenReturn(mockApplications);

    when(mockApplications.getEnvironments(any(GetApplicationEnvironmentsRequest.class)))
        .thenReturn(Mono.error(new RuntimeException("No such Environment")));

    Mono<Optional<ApplicationEnvironments>> appDetailsMono = appEnvDelegate.getAppEnv(cfOperations, cfAppProperties);

    StepVerifier
        .create(appDetailsMono)
        .expectNextMatches(appEnv -> !appEnv.isPresent())
        .expectComplete()
        .verify();
}
 
Example #9
Source File: CfUnMapRouteDelegate.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
public Flux<Void> unmapRoute(CloudFoundryOperations cfOperations, CfProperties cfProperties) {

        if (cfProperties.routes() != null && !cfProperties.routes().isEmpty()) {
            Mono<List<DecomposedRoute>> decomposedRoutes = CfRouteUtil.decomposedRoutes(cfOperations, cfProperties.routes(), cfProperties.path());

            Flux<Void> unmapRoutesFlux = decomposedRoutes
                .flatMapMany(Flux::fromIterable)
                .flatMap(route ->
                    unmapRoute(cfOperations, cfProperties.name(), route.getHost(), route.getDomain(), route.getPort(), route.getPath()));

            return unmapRoutesFlux;
            
        } else {
            return unmapRoute(cfOperations, cfProperties.name(), cfProperties.host(), cfProperties.domain(), null, cfProperties.path()).flux();
        }
    }
 
Example #10
Source File: CloudFoundryAppDeployer.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private Mono<UpdateServiceInstanceResponse> updateServiceInstanceIfNecessary(UpdateServiceInstanceRequest request,
	CloudFoundryOperations cloudFoundryOperations) {
	// service instances can be updated with a change to the plan, name, or parameters;
	// of these only parameter changes are supported, so don't update if the
	// backing service instance has no parameters
	if (request.getParameters() == null || request.getParameters().isEmpty()) {
		return Mono.empty();
	}

	final String serviceInstanceName = request.getServiceInstanceName();

	return cloudFoundryOperations.services().updateInstance(
		org.cloudfoundry.operations.services.UpdateServiceInstanceRequest.builder()
			.serviceInstanceName(serviceInstanceName)
			.completionTimeout(apiPollingTimeout(request.getProperties()))
			.parameters(request.getParameters())
			.build())
		.then(Mono.just(UpdateServiceInstanceResponse.builder()
			.name(serviceInstanceName)
			.build()));
}
 
Example #11
Source File: CfPushDelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testCfPushWithoutEnvOrServices() throws Exception {
    CloudFoundryOperations cfOperations = mock(CloudFoundryOperations.class);
    Applications mockApplications = mock(Applications.class);
    when(cfOperations.applications()).thenReturn(mockApplications);
    when(mockApplications.push(any(PushApplicationRequest.class))).thenReturn(Mono.empty());
    when(mockApplications.restart(any(RestartApplicationRequest.class))).thenReturn(Mono.empty());

    Services mockServices = mock(Services.class);
    when(cfOperations.services()).thenReturn(mockServices);
    ServiceInstance mockInstance = ServiceInstance.builder().name("testservice").id("id").type(ServiceInstanceType.MANAGED).build();
    when(mockServices.getInstance(any(GetServiceInstanceRequest.class))).thenReturn(Mono.just(mockInstance));

    CfProperties cfAppProperties = sampleApp();
    cfPushDelegate.push(cfOperations, cfAppProperties);
}
 
Example #12
Source File: CloudFoundryAppDeployer.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private Mono<Void> rebindServiceInstance(String serviceInstanceName,
	CloudFoundryOperations cloudFoundryOperations) {
	return cloudFoundryOperations.services()
		.getInstance(org.cloudfoundry.operations.services.GetServiceInstanceRequest.builder()
			.name(serviceInstanceName)
			.build())
		.map(ServiceInstance::getApplications)
		.flatMap(applications -> Flux.fromIterable(applications)
			.flatMap(application -> cloudFoundryOperations.services().unbind(
				UnbindServiceInstanceRequest.builder()
					.applicationName(application)
					.serviceInstanceName(serviceInstanceName)
					.build())
				.then(cloudFoundryOperations.services().bind(
					BindServiceInstanceRequest.builder()
						.applicationName(application)
						.serviceInstanceName(serviceInstanceName)
						.build()))
			)
			.then(Mono.empty()));
}
 
Example #13
Source File: CloudFoundryAppDeployer.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private Mono<Void> unbindServiceInstance(String serviceInstanceName,
	CloudFoundryOperations cloudFoundryOperations) {
	return cloudFoundryOperations.services()
		.getInstance(org.cloudfoundry.operations.services.GetServiceInstanceRequest.builder()
			.name(serviceInstanceName)
			.build())
		.doOnError(e -> LOG.error(String.format("Error getting service instance. serviceInstanceName=%s, " +
			ERROR_LOG_TEMPLATE, serviceInstanceName, e.getMessage()), e))
		.onErrorResume(e -> Mono.empty())
		.map(ServiceInstance::getApplications)
		.flatMap(applications -> Flux.fromIterable(applications)
			.flatMap(application -> cloudFoundryOperations.services().unbind(
				UnbindServiceInstanceRequest.builder()
					.applicationName(application)
					.serviceInstanceName(serviceInstanceName)
					.build())
			)
			.doOnError(e -> LOG.error(String.format("Error unbinding service instance. serviceInstanceName=%s, " +
				ERROR_LOG_TEMPLATE, serviceInstanceName, e.getMessage()), e))
			.onErrorResume(e -> Mono.empty())
			.then(Mono.empty()));
}
 
Example #14
Source File: CfServicesDetailHelperTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetServiceDetails() {
    CloudFoundryOperations cfOps = mock(CloudFoundryOperations.class);
    Services mockServices = mock(Services.class);

    when(mockServices
        .getInstance(any(GetServiceInstanceRequest.class)))
        .thenReturn(Mono.just(ServiceInstance.builder()
            .id("id")
            .type(ServiceInstanceType.MANAGED)
            .name("test")
            .build()));

    when(cfOps.services()).thenReturn(mockServices);

    Mono<Optional<ServiceInstance>> serviceDetailMono =
        this.cfServicesDetailHelper.getServiceInstanceDetail(cfOps, "srvc");

    StepVerifier.create(serviceDetailMono).expectNextMatches(serviceInstance ->
        serviceInstance.isPresent());
}
 
Example #15
Source File: CfUnmapDelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void unmapExplicitRoutesInvalidDomain() {
    CfUnMapRouteDelegate cfUnmap = new CfUnMapRouteDelegate();
    CloudFoundryOperations cfOperations = mock(CloudFoundryOperations.class);
    Routes mockRoutes = mock(Routes.class);
    when(mockRoutes.unmap(any(UnmapRouteRequest.class))).thenReturn(Mono.empty());
    when(cfOperations.routes()).thenReturn(mockRoutes);
    Domains mockDomains = mock(Domains.class);
    when(mockDomains.list())
        .thenReturn(
            Flux.just(
                Domain.builder().id("id1").name("test1.domain").type("typ").status(Status.SHARED).build(),
                Domain.builder().id("id2").name("test2.domain").type("typ").status(Status.SHARED).build()
            )
        );

    when(cfOperations.domains()).thenReturn(mockDomains);

    CfProperties cfProperties = sampleApp(Arrays.asList("app1.test1.domain", "app2.invalid.domain"));
    Flux<Void> result = cfUnmap.unmapRoute(cfOperations, cfProperties);
    StepVerifier.create(result)
        .expectError(IllegalArgumentException.class)
        .verify();
}
 
Example #16
Source File: CfAutoPilotDelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutopilotNewAppShouldCallPushAlone() {
    Project project = mock(Project.class);
    CloudFoundryOperations cfOperations = mock(CloudFoundryOperations.class);
    CfProperties cfAppProperties = sampleApp();

    when(detailsTaskDelegate.getAppDetails(cfOperations, cfAppProperties)).thenReturn(Mono.just(Optional.empty()));

    when(cfPushDelegate.push(cfOperations, cfAppProperties)).thenReturn(Mono.empty());

    Mono<Void> resp = this.cfAutoPilotTask.runAutopilot(project, cfOperations, cfAppProperties);

    StepVerifier.create(resp)
        .expectComplete()
        .verify();

    verify(cfRenameAppDelegate, times(0)).renameApp(any(CloudFoundryOperations.class),
        any(CfProperties.class), any(CfProperties.class));

    verify(cfPushDelegate, times(1)).push(any(CloudFoundryOperations.class), any(CfProperties.class));

    verify(deleteDelegate, times(0)).deleteApp(any(CloudFoundryOperations.class), any(CfProperties.class));
}
 
Example #17
Source File: CfUnmapDelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void unmapExplicitRoutes() {
    CfUnMapRouteDelegate cfUnmap = new CfUnMapRouteDelegate();
    CloudFoundryOperations cfOperations = mock(CloudFoundryOperations.class);
    Routes mockRoutes = mock(Routes.class);
    when(mockRoutes.unmap(any(UnmapRouteRequest.class))).thenReturn(Mono.empty());
    when(cfOperations.routes()).thenReturn(mockRoutes);
    Domains mockDomains = mock(Domains.class);
    when(mockDomains.list())
        .thenReturn(
            Flux.just(
                Domain.builder().id("id1").name("test1.domain").type("typ").status(Status.SHARED).build(),
                Domain.builder().id("id2").name("test2.domain").type("typ").status(Status.SHARED).build()
            )
        );

    when(cfOperations.domains()).thenReturn(mockDomains);
    
    CfProperties cfProperties = sampleApp(Arrays.asList("app1.test1.domain", "app2.test2.domain"));
    Flux<Void> result = cfUnmap.unmapRoute(cfOperations, cfProperties);
    StepVerifier.create(result)
        .expectComplete()
        .verify();
}
 
Example #18
Source File: CfAppEnvDelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetEnvironmentsNoException() {
    CloudFoundryOperations cfOperations = mock(CloudFoundryOperations.class);
    CfProperties cfAppProperties = sampleApp();

    ApplicationEnvironments appEnvironment = sampleAppEnvironment();

    Applications mockApplications = mock(Applications.class);
    when(cfOperations.applications()).thenReturn(mockApplications);

    when(mockApplications.getEnvironments(any(GetApplicationEnvironmentsRequest.class))).thenReturn(Mono.just(appEnvironment));

    Mono<Optional<ApplicationEnvironments>> appEnvMono = appEnvDelegate.getAppEnv(cfOperations, cfAppProperties);

    StepVerifier
        .create(appEnvMono)
        .expectNextMatches(appEnv -> appEnv.isPresent())
        .expectComplete()
        .verify();
}
 
Example #19
Source File: CloudFoundryTaskLauncher.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
public CloudFoundryTaskLauncher(CloudFoundryClient client,
											CloudFoundryDeploymentProperties deploymentProperties,
											CloudFoundryOperations operations,
										    RuntimeEnvironmentInfo runtimeEnvironmentInfo) {
	super(client, deploymentProperties, runtimeEnvironmentInfo);
	this.client = client;
	this.deploymentProperties = deploymentProperties;
	this.operations = operations;
}
 
Example #20
Source File: CfBlueGreenStage2DelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testStage2ExistingAppAndBackup() {
    Project project = mock(Project.class);
    CloudFoundryOperations cfOperations = mock(CloudFoundryOperations.class);
    CfProperties cfAppProperties = sampleApp();

    Domains mockDomains = mock(Domains.class);
    when(mockDomains.list()).thenReturn(Flux.just(Domain.builder().id("id").name("test.com").status(Status.SHARED).build()));
    when(cfOperations.domains()).thenReturn(mockDomains);

    when(detailsTaskDelegate.getAppDetails(any(CloudFoundryOperations.class), any(CfProperties.class)))
        .thenReturn(Mono.just(Optional.of(sampleApplicationDetail())));

    when(this.mapRouteDelegate.mapRoute(any(CloudFoundryOperations.class), any(CfProperties.class))).thenReturn(Flux.empty());
    when(this.unMapRouteDelegate.unmapRoute(any(CloudFoundryOperations.class), any(CfProperties.class))).thenReturn(Flux.empty());
    when(this.renameAppTaskDelegate.renameApp(any(CloudFoundryOperations.class), any(CfProperties.class), any(CfProperties.class))).thenReturn(Mono.empty());
    when(this.deleteAppTaskDelegate.deleteApp(any(CloudFoundryOperations.class), any(CfProperties.class))).thenReturn(Mono.empty());
    when(this.stopDelegate.stopApp(any(CloudFoundryOperations.class), any(CfProperties.class))).thenReturn(Mono.empty());

    Mono<Void> resp = this.blueGreenStage2Delegate.runStage2(project, cfOperations, cfAppProperties);
    StepVerifier.create(resp)
        .expectComplete()
        .verify(Duration.ofMillis(2000L));

    //delete of old backup
    verify(this.deleteAppTaskDelegate, times(1)).deleteApp(any(CloudFoundryOperations.class), any(CfProperties.class));

    //mapping correct route to green
    verify(this.mapRouteDelegate, times(1)).mapRoute(any(CloudFoundryOperations.class), any(CfProperties.class));

    //unmapping green route from green app
    //unmapping route from existing app
    verify(this.unMapRouteDelegate, times(2)).unmapRoute(any(CloudFoundryOperations.class), any(CfProperties.class));

    //rename green to app
    //rename existing app to blue
    verify(this.renameAppTaskDelegate, times(2)).renameApp(any(CloudFoundryOperations.class), any(CfProperties.class), any(CfProperties.class));
}
 
Example #21
Source File: CfBlueGreenStage2DelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testStage2NoExistingApp() {
    Project project = mock(Project.class);
    CloudFoundryOperations cfOperations = mock(CloudFoundryOperations.class);
    CfProperties cfAppProperties = sampleApp();

    Domains mockDomains = mock(Domains.class);
    when(mockDomains.list()).thenReturn(Flux.just(Domain.builder().id("id").name("test.com").status(Status.SHARED).build()));
    when(cfOperations.domains()).thenReturn(mockDomains);



    when(detailsTaskDelegate.getAppDetails(any(CloudFoundryOperations.class), any(CfProperties.class)))
        .thenReturn(Mono.just(Optional.empty()));

    when(this.mapRouteDelegate.mapRoute(any(CloudFoundryOperations.class), any(CfProperties.class))).thenReturn(Flux.empty());
    when(this.unMapRouteDelegate.unmapRoute(any(CloudFoundryOperations.class), any(CfProperties.class))).thenReturn(Flux.empty());
    when(this.renameAppTaskDelegate.renameApp(any(CloudFoundryOperations.class), any(CfProperties.class), any(CfProperties.class))).thenReturn(Mono.empty());
    when(this.deleteAppTaskDelegate.deleteApp(any(CloudFoundryOperations.class), any(CfProperties.class))).thenReturn(Mono.empty());
    when(this.stopDelegate.stopApp(any(CloudFoundryOperations.class), any(CfProperties.class))).thenReturn(Mono.empty());

    Mono<Void> resp = this.blueGreenStage2Delegate.runStage2(project, cfOperations, cfAppProperties);
    StepVerifier.create(resp)
        .expectComplete()
        .verify(Duration.ofMillis(2000L));

    //delete of old backup should not be called..there is no backup app..
    verify(this.deleteAppTaskDelegate, times(0)).deleteApp(any(CloudFoundryOperations.class), any(CfProperties.class));

    //mapping correct route to green
    verify(this.mapRouteDelegate, times(1)).mapRoute(any(CloudFoundryOperations.class), any(CfProperties.class));

    //unmapping green route from green app
    verify(this.unMapRouteDelegate, times(1)).unmapRoute(any(CloudFoundryOperations.class), any(CfProperties.class));

    //rename green to app
    verify(this.renameAppTaskDelegate, times(1)).renameApp(any(CloudFoundryOperations.class), any(CfProperties.class), any(CfProperties.class));
}
 
Example #22
Source File: CfAutoPilotDelegateTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testCfAutoPilotExistingAppShouldCallRenameAndDelete() {
    Project project = mock(Project.class);
    CloudFoundryOperations cfOperations = mock(CloudFoundryOperations.class);
    CfProperties cfAppProperties = sampleApp();

    ApplicationDetail appDetail = sampleApplicationDetail();
    when(detailsTaskDelegate.getAppDetails(cfOperations, cfAppProperties))
        .thenReturn(Mono.just(Optional.of(appDetail)));

    when(cfRenameAppDelegate.renameApp(any(CloudFoundryOperations.class),
        any(CfProperties.class),
        any(CfProperties.class))).thenReturn(Mono.empty());

    when(cfPushDelegate.push(any(CloudFoundryOperations.class), any(CfProperties.class))).thenReturn(Mono.empty());
    when(deleteDelegate.deleteApp(any(CloudFoundryOperations.class),
        any(CfProperties.class))).thenReturn(Mono.empty());

    Mono<Void> resp = this.cfAutoPilotTask.runAutopilot(project, cfOperations, cfAppProperties);

    StepVerifier.create(resp)
        .expectComplete()
        .verify();

    verify(cfRenameAppDelegate, times(1)).renameApp(any(CloudFoundryOperations.class),
        any(CfProperties.class), any(CfProperties.class));

    verify(cfPushDelegate, times(1)).push(any(CloudFoundryOperations.class), any(CfProperties.class));

    verify(deleteDelegate, times(1)).deleteApp(any(CloudFoundryOperations.class), any(CfProperties.class));
}
 
Example #23
Source File: CfCreateServiceHelperTest.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateServiceWithAnExistingService() {
    CloudFoundryOperations cfOps = mock(CloudFoundryOperations.class);
    Services mockServices = mock(Services.class);

    when(mockServices
        .getInstance(any(GetServiceInstanceRequest.class)))
        .thenReturn(Mono.just(ServiceInstance.builder()
            .id("inst")
            .type(ServiceInstanceType.MANAGED)
            .name("inst")
            .build()));

    when(cfOps.services()).thenReturn(mockServices);

    CfServiceDetail cfServiceDetail = ImmutableCfServiceDetail
        .builder().name("testName")
        .plan("testPlan")
        .instanceName("inst")
        .build();
    
    
    Mono<ServiceInstance> createServiceResult = this.cfCreateServiceHelper.createService(cfOps, cfServiceDetail);

    StepVerifier.create(createServiceResult)
        .expectNextMatches(instance -> instance != null)
        .verifyComplete();
}
 
Example #24
Source File: CfBlueGreenStage1Delegate.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
public Mono<Void> runStage1(Project project, CloudFoundryOperations cfOperations,
                            CfProperties cfProperties) {
    
    final String greenNameString = cfProperties.name() + "-green";
    final Mono<String> greenRouteStringMono = CfRouteUtil.getTempRoute(cfOperations, cfProperties, "green");

    Mono<Optional<ApplicationDetail>> appDetailMono = appDetailsDelegate
        .getAppDetails(cfOperations, cfProperties);

    // Get App Env Vars
    Mono<Optional<ApplicationEnvironments>> appEnvMono =
        appEnvDelegate.getAppEnv(cfOperations, cfProperties);

    Mono<ImmutableCfProperties> cfPropertiesMono = Mono.zip(appEnvMono, appDetailMono, greenRouteStringMono).map(function((appEnvOpt, appDetailOpt, greenRouteString) -> {
        LOGGER.lifecycle(
            "Running Blue Green Deploy - deploying a 'green' app. App '{}' with route '{}'",
            cfProperties.name(),
            greenRouteString);

        return appDetailOpt.map(appDetail -> {
            printAppDetail(appDetail);
            return ImmutableCfProperties.copyOf(cfProperties)
                .withName(greenNameString)
                .withHost(null)
                .withDomain(null)
                .withRoutes(Collections.singletonList(greenRouteString))
                .withInstances(appDetail.getInstances())
                .withMemory(appDetail.getMemoryLimit())
                .withDiskQuota(appDetail.getDiskQuota());
        }).orElse(ImmutableCfProperties.copyOf(cfProperties)
            .withName(greenNameString)
            .withHost(null)
            .withDomain(null)
            .withRoutes(Collections.singletonList(greenRouteString)));
    }));

    return cfPropertiesMono.flatMap(
        withNewNameAndRoute -> pushDelegate.push(cfOperations, withNewNameAndRoute));
}
 
Example #25
Source File: CfDeleteAppTask.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@TaskAction
public void deleteApp() {
    CloudFoundryOperations cfOperations = getCfOperations();
    CfProperties cfProperties = getCfProperties();

    Mono<Void> resp = deleteDelegate.deleteApp(cfOperations, cfProperties);
    resp.block(Duration.ofMillis(defaultWaitTimeout));
}
 
Example #26
Source File: CfBlueGreenStage2Task.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@TaskAction
public void runBlueGreen() {
    CloudFoundryOperations cfOperations = getCfOperations();
    CfProperties originalProperties = getCfProperties();

    Mono<Void> resp = blueGreenStage2Delegate.runStage2(getProject(), cfOperations, originalProperties);

    resp.block(Duration.ofMillis(defaultWaitTimeout));
}
 
Example #27
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 #28
Source File: CfUnMapRouteDelegate.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
private Mono<Void> unmapRoute(CloudFoundryOperations cfOperations, String appName, String host, String domain, Integer port, String path) {
    return cfOperations.routes()
        .unmap(UnmapRouteRequest
            .builder()
            .applicationName(appName)
            .host(host)
            .domain(domain)
            .port(port)
            .path(path)
            .build()).doOnSubscribe((s) -> {
            LOGGER.lifecycle("Unmapping hostname '{}' in domain '{}' with path '{}' of app '{}'", host,
                domain, path, appName);
        });
}
 
Example #29
Source File: CloudFoundryAppDeployer.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
public CloudFoundryAppDeployer(AppNameGenerator applicationNameGenerator,
	CloudFoundryDeploymentProperties deploymentProperties,
	CloudFoundryOperations operations,
	RuntimeEnvironmentInfo runtimeEnvironmentInfo
) {
	super(deploymentProperties, runtimeEnvironmentInfo);
	this.operations = operations;
	this.applicationNameGenerator = applicationNameGenerator;
}
 
Example #30
Source File: CfAppEnvDelegate.java    From ya-cf-app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
public Mono<Optional<ApplicationEnvironments>> getAppEnv(
    CloudFoundryOperations cfOperations, CfProperties cfProperties) {
    Mono<ApplicationEnvironments> applicationEnvironmentsMono = cfOperations.applications()
        .getEnvironments(GetApplicationEnvironmentsRequest.builder().name(cfProperties.name()).build())
        .doOnSubscribe((c) -> {
            LOGGER.lifecycle("Checking environment of app '{}'", cfProperties.name());
        });

    return applicationEnvironmentsMono
        .map(applicationEnvironments -> Optional.ofNullable(applicationEnvironments))
        .onErrorResume(Exception.class, e -> Mono.just(Optional.empty()));
}