org.cloudfoundry.client.v2.Metadata Java Examples

The following examples show how to use org.cloudfoundry.client.v2.Metadata. 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: CloudFoundryAppDeployerUpdateApplicationTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private void mockDomainsAndRoutesUpdate() {
	given(applicationsV2.update(any()))
		.willReturn(Mono.just(UpdateApplicationResponse.builder()
			.build()));
	given(spaces.get(any())).willReturn(
		Mono.just(
			SpaceDetail.builder()
				.id("space-id")
				.name("space-name")
				.organization("org-name")
				.build()));
	given(domains.list()).willReturn(getDomains());
	given(routes.create(any())).willAnswer(invocation -> {
		CreateRouteRequest createRouteRequest = invocation.getArgument(0);
		return Mono.just(CreateRouteResponse.builder()
			.metadata(Metadata
				.builder()
				.id(getRouteIdForDomain(createRouteRequest.getDomainId()))
				.build()).build());
	});
	given(applicationsV2.associateRoute(any()))
		.willReturn(Mono.empty());
}
 
Example #2
Source File: CFAccessorSimulator.java    From promregator with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ListOrganizationsResponse> retrieveOrgId(String orgName) {
	
	if ("simorg".equals(orgName)) {
		
		OrganizationResource or = OrganizationResource.builder().entity(
				OrganizationEntity.builder().name(orgName).build()
			).metadata(
				Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(ORG_UUID).build()
				// Note that UpdatedAt is not set here, as this can also happen in real life!
			).build();
		
		List<OrganizationResource> list = new LinkedList<>();
		list.add(or);
		
		ListOrganizationsResponse resp = ListOrganizationsResponse.builder().addAllResources(list).build();
		
		return Mono.just(resp).delayElement(this.getSleepRandomDuration());
	}
	log.error("Invalid OrgId request");
	return null;
}
 
Example #3
Source File: CFAccessorSimulator.java    From promregator with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ListSpacesResponse> retrieveSpaceId(String orgId, String spaceName) {
	if ("simspace".equals(spaceName) && orgId.equals(ORG_UUID)) {
		
		SpaceResource sr = SpaceResource.builder().entity(
				SpaceEntity.builder().name(spaceName).build()
			).metadata(
				Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(SPACE_UUID).build()
			).build();
		List<SpaceResource> list = new LinkedList<>();
		list.add(sr);
		ListSpacesResponse resp = ListSpacesResponse.builder().addAllResources(list).build();
		
		return Mono.just(resp).delayElement(this.getSleepRandomDuration());
	}
	
	log.error("Invalid SpaceId request");
	return null;
}
 
Example #4
Source File: CFAccessorSimulator.java    From promregator with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ListApplicationsResponse> retrieveAllApplicationIdsInSpace(String orgId, String spaceId) {
	if (orgId.equals(ORG_UUID) && spaceId.equals(SPACE_UUID)) {
		List<ApplicationResource> list = new LinkedList<>();

		
		for (int i = 1;i<=100;i++) {
			ApplicationResource ar = null;
			ar = ApplicationResource.builder().entity(
					ApplicationEntity.builder().name("testapp"+i).state("STARTED").build()
				).metadata(
						Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(APP_UUID_PREFIX+i).build()
				).build();
		
			list.add(ar);
			
		}
		ListApplicationsResponse resp = ListApplicationsResponse.builder().addAllResources(list).build();
		return Mono.just(resp).delayElement(this.getSleepRandomDuration());
	}
	log.error("Invalid retrieveAllApplicationIdsInSpace request");
	return null;
}
 
Example #5
Source File: CFAccessorMassMock.java    From promregator with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ListOrganizationsResponse> retrieveOrgId(String orgName) {
	
	if ("unittestorg".equals(orgName)) {
		
		OrganizationResource or = OrganizationResource.builder().entity(
				OrganizationEntity.builder().name(orgName).build()
			).metadata(
				Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_ORG_UUID).build()
				// Note that UpdatedAt is not set here, as this can also happen in real life!
			).build();
		
		List<org.cloudfoundry.client.v2.organizations.OrganizationResource> list = new LinkedList<>();
		list.add(or);
		
		ListOrganizationsResponse resp = org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse.builder().addAllResources(list).build();
		
		return Mono.just(resp).delayElement(this.getSleepRandomDuration());
	}
	Assert.fail("Invalid OrgId request");
	return null;
}
 
Example #6
Source File: CFAccessorMassMock.java    From promregator with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ListSpacesResponse> retrieveSpaceId(String orgId, String spaceName) {
	if ("unittestspace".equals(spaceName) && orgId.equals(UNITTEST_ORG_UUID)) {
		
		SpaceResource sr = SpaceResource.builder().entity(
				SpaceEntity.builder().name(spaceName).build()
			).metadata(
				Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_SPACE_UUID).build()
			).build();
		List<SpaceResource> list = new LinkedList<>();
		list.add(sr);
		ListSpacesResponse resp = ListSpacesResponse.builder().addAllResources(list).build();
		return Mono.just(resp).delayElement(this.getSleepRandomDuration());
	}
	
	Assert.fail("Invalid SpaceId request");
	return null;
}
 
Example #7
Source File: CFAccessorMassMock.java    From promregator with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ListApplicationsResponse> retrieveAllApplicationIdsInSpace(String orgId, String spaceId) {
	if (orgId.equals(UNITTEST_ORG_UUID) && spaceId.equals(UNITTEST_SPACE_UUID)) {
		List<ApplicationResource> list = new LinkedList<>();

		
		for (int i = 0;i<100;i++) {
			ApplicationResource ar = null;
			ar = ApplicationResource.builder().entity(
					ApplicationEntity.builder().name("testapp"+i).build()
				).metadata(
						Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_APP_UUID_PREFIX+i).build()
				).build();
		
			list.add(ar);
			
		}
		ListApplicationsResponse resp = ListApplicationsResponse.builder().addAllResources(list).build();
		return Mono.just(resp).delayElement(this.getSleepRandomDuration());
	}
	Assert.fail("Invalid retrieveAllApplicationIdsInSpace request");
	return null;
}
 
Example #8
Source File: CloudFoundryTaskPlatformFactoryTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Mono<ListSpacesResponse> listSpacesResponse() {
	ListSpacesResponse response = ListSpacesResponse.builder()
			.addAllResources(Collections.<SpaceResource>singletonList(
					SpaceResource.builder()
							.metadata(Metadata.builder().id("123").build()).build())
			).build();
	return Mono.just(response);
}
 
Example #9
Source File: CloudFoundryTaskPlatformFactoryTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Mono<ListOrganizationsResponse> listOrganizationsResponse() {
	ListOrganizationsResponse response = ListOrganizationsResponse.builder()
			.addAllResources(Collections.<OrganizationResource>singletonList(
					OrganizationResource.builder()
							.metadata(Metadata.builder().id("123").build()).build())
			).build();
	return Mono.just(response);
}
 
Example #10
Source File: CloudFoundrySchedulerTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Mono<ListSpacesResponse> listSpacesResponse() {
	ListSpacesResponse response = ListSpacesResponse.builder()
			.addAllResources(Collections.<SpaceResource>singletonList(
					SpaceResource.builder()
							.metadata(Metadata.builder().id("123").build()).build())
			).build();
	return Mono.just(response);
}
 
Example #11
Source File: CloudFoundrySchedulerTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Mono<ListOrganizationsResponse> listOrganizationsResponse() {
	ListOrganizationsResponse response = ListOrganizationsResponse.builder()
			.addAllResources(Collections.<OrganizationResource>singletonList(
					OrganizationResource.builder()
							.metadata(Metadata.builder().id("123").build()).build())
			).build();
	return Mono.just(response);
}
 
Example #12
Source File: MultiplePlatformTypeTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Mono<ListSpacesResponse> listSpacesResponse() {
	ListSpacesResponse response = ListSpacesResponse.builder()
			.addAllResources(Collections.<SpaceResource>singletonList(
					SpaceResource.builder()
							.metadata(Metadata.builder().id("123").build()).build())
			).build();
	return Mono.just(response);
}
 
Example #13
Source File: MultiplePlatformTypeTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private Mono<ListOrganizationsResponse> listOrganizationsResponse() {
	ListOrganizationsResponse response = ListOrganizationsResponse.builder()
			.addAllResources(Collections.<OrganizationResource>singletonList(
					OrganizationResource.builder()
							.metadata(Metadata.builder().id("123").build()).build())
			).build();
	return Mono.just(response);
}
 
Example #14
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private Mono<ListSpacesResponse> listSpacesResponse() {
	ListSpacesResponse response = ListSpacesResponse.builder()
			.addAllResources(Collections.<SpaceResource>singletonList(
					SpaceResource.builder()
							.metadata(Metadata.builder().id("123").build()).build())
			).build();
	return Mono.just(response);
}
 
Example #15
Source File: CloudFoundryTaskLauncherTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private Mono<ListOrganizationsResponse> listOrganizationsResponse() {
	ListOrganizationsResponse response = ListOrganizationsResponse.builder()
	.addAllResources(Collections.<OrganizationResource>singletonList(
			OrganizationResource.builder()
					.metadata(Metadata.builder().id("123").build()).build())
	).build();
	return Mono.just(response);
}
 
Example #16
Source File: CloudFoundryTaskLauncherCachingTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private Mono<ListSpacesResponse> listSpacesResponse(AtomicBoolean error) {
	// defer so that we can conditionally throw within mono
	return Mono.defer(() -> {
		if (error.get()) {
			throw new RuntimeException();
		}
		ListSpacesResponse response = ListSpacesResponse.builder()
			.addAllResources(Collections.<SpaceResource>singletonList(
				SpaceResource.builder()
						.metadata(Metadata.builder().id("123").build()).build())
		)
		.build();
		return Mono.just(response);
	});
}
 
Example #17
Source File: CloudFoundryTaskLauncherCachingTests.java    From spring-cloud-deployer-cloudfoundry with Apache License 2.0 5 votes vote down vote up
private Mono<ListOrganizationsResponse> listOrganizationsResponse(AtomicBoolean error) {
	// defer so that we can conditionally throw within mono
	return Mono.defer(() -> {
		if (error.get()) {
			throw new RuntimeException();
		}
		ListOrganizationsResponse response = ListOrganizationsResponse.builder()
			.addAllResources(Collections.<OrganizationResource>singletonList(
				OrganizationResource.builder()
						.metadata(Metadata.builder().id("123").build()).build())
			)
			.build();
		return Mono.just(response);
	});
}
 
Example #18
Source File: RawCloudEntity.java    From cf-java-client-sap with Apache License 2.0 5 votes vote down vote up
protected static CloudMetadata parseResourceMetadata(org.cloudfoundry.client.v2.Resource<?> resource) {
    Metadata metadata = resource.getMetadata();
    return ImmutableCloudMetadata.builder()
                                 .guid(parseNullableGuid(metadata.getId()))
                                 .createdAt(parseNullableDate(metadata.getCreatedAt()))
                                 .updatedAt(parseNullableDate(metadata.getUpdatedAt()))
                                 .url(metadata.getUrl())
                                 .build();
}
 
Example #19
Source File: CFAccessorMock.java    From promregator with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<ListApplicationsResponse> retrieveAllApplicationIdsInSpace(String orgId, String spaceId) {
	if (orgId.equals(UNITTEST_ORG_UUID) && spaceId.equals(UNITTEST_SPACE_UUID)) {
		List<ApplicationResource> list = new LinkedList<>();

		ApplicationResource ar = ApplicationResource.builder().entity(
				ApplicationEntity.builder().name("testapp").state("STARTED").build()
			).metadata(
					Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_APP1_UUID).build()
			).build();
		list.add(ar);
		
		ar = ApplicationResource.builder().entity(
				ApplicationEntity.builder().name("testapp2").state("STARTED").build()
			).metadata(
					Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_APP2_UUID).build()
			).build();
		list.add(ar);
		
		ListApplicationsResponse resp = ListApplicationsResponse.builder().addAllResources(list).build();
		return Mono.just(resp);
	} else if (UNITTEST_SPACE_UUID_DOESNOTEXIST.equals(spaceId)) {
		return Mono.just(ListApplicationsResponse.builder().build());
	} else if (UNITTEST_SPACE_UUID_EXCEPTION.equals(spaceId)) {
		return Mono.just(ListApplicationsResponse.builder().build()).map( x-> { throw new Error("exception on AllAppIdsInSpace"); });
	}
	
	Assert.fail("Invalid process request");
	return null;
}
 
Example #20
Source File: CFAccessorMock.java    From promregator with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<ListOrganizationsResponse> retrieveOrgId(String orgName) {
	
	if ("unittestorg".equalsIgnoreCase(orgName)) {
		
		OrganizationResource or = OrganizationResource.builder().entity(
				OrganizationEntity.builder().name("unittestorg").build()
			).metadata(
				Metadata.builder().createdAt(CREATED_AT_TIMESTAMP).id(UNITTEST_ORG_UUID).build()
				// Note that UpdatedAt is not set here, as this can also happen in real life!
			).build();
		
		List<org.cloudfoundry.client.v2.organizations.OrganizationResource> list = new LinkedList<>();
		list.add(or);
		
		ListOrganizationsResponse resp = org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse.builder().addAllResources(list).build();
		
		return Mono.just(resp);
	} else if ("doesnotexist".equals(orgName)) {
		return Mono.just(org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse.builder().resources(new ArrayList<>()).build());
	} else if ("exception".equals(orgName)) {
		return Mono.just(org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse.builder().build())
				.map(x -> {throw new Error("exception org name provided");});
	}
	Assert.fail("Invalid OrgId request");
	return null;
}
 
Example #21
Source File: CloudFoundryAppDeployerTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void deleteServiceInstanceWithTarget() {
	given(operationsServices.deleteInstance(
		org.cloudfoundry.operations.services.DeleteServiceInstanceRequest.builder()
			.name("service-instance-name")
			.completionTimeout(Duration.ofSeconds(DEFAULT_COMPLETION_DURATION))
			.build()))
		.willReturn(Mono.empty());

	given(operationsServices.getInstance(GetServiceInstanceRequest.builder().name("service-instance-name").build()))
		.willReturn(Mono.just(ServiceInstance.builder()
			.id("siid")
			.type(ServiceInstanceType.MANAGED)
			.name("service-instance-name")
			.applications("app1", "app2")
			.build()));

	given(operationsServices.unbind(UnbindServiceInstanceRequest.builder()
		.serviceInstanceName("service-instance-name")
		.applicationName("app1")
		.build()))
		.willReturn(Mono.empty());

	given(operationsServices.unbind(UnbindServiceInstanceRequest.builder()
		.serviceInstanceName("service-instance-name")
		.applicationName("app2")
		.build()))
		.willReturn(Mono.empty());

	given(operationsOrganizations
		.get(
			OrganizationInfoRequest
				.builder()
				.name("default-org")
				.build()))
		.willReturn(Mono.just(
			OrganizationDetail
				.builder()
				.id("default-org-id")
				.name("default-org")
				.quota(OrganizationQuota
					.builder()
					.id("quota-id")
					.instanceMemoryLimit(0)
					.organizationId("default-org-id")
					.name("quota")
					.paidServicePlans(false)
					.totalMemoryLimit(0)
					.totalRoutes(0)
					.totalServiceInstances(0)
					.build())
				.build()));

	given(clientOrganizations
		.listSpaces(ListOrganizationSpacesRequest
			.builder()
			.name("service-instance-id")
			.organizationId("default-org-id")
			.page(1)
			.build()))
		.willReturn(Mono.just(ListOrganizationSpacesResponse
			.builder()
			.resource(SpaceResource
				.builder()
				.entity(SpaceEntity
					.builder()
					.name("service-instance-id")
					.build())
				.metadata(Metadata
					.builder()
					.id("service-instance-space-id")
					.build())
				.build())
			.build()));

	given(clientSpaces
		.delete(DeleteSpaceRequest
			.builder()
			.spaceId("service-instance-space-id")
			.build()))
		.willReturn(Mono.empty());

	DeleteServiceInstanceRequest request =
		DeleteServiceInstanceRequest.builder()
			.serviceInstanceName("service-instance-name")
			.properties(emptyMap())
			.properties(singletonMap(TARGET_PROPERTY_KEY, "service-instance-id"))
			.build();

	StepVerifier.create(
		appDeployer.deleteServiceInstance(request))
		.assertNext(response -> assertThat(response.getName()).isEqualTo("service-instance-name"))
		.verifyComplete();
}
 
Example #22
Source File: CloudFoundryAppDeployerUpdateApplicationTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void updateAppWithDomainAndNoHost() {
	given(applicationsV2.update(any()))
		.willReturn(Mono.just(
			UpdateApplicationResponse.builder().build()));

	given(domains.list())
		.willReturn(getDomains());

	given(spaces.get(any()))
		.willReturn(Mono.just(SpaceDetail.builder()
			.id("space-id")
			.name("space-name")
			.organization("org-name")
			.build()));
	given(routes.create(any()))
		.willReturn(Mono.just(CreateRouteResponse.builder()
			.metadata(Metadata
				.builder()
				.id("route-id")
				.build())
			.build()));
	given(applicationsV2.associateRoute(any()))
		.willReturn(Mono.empty());

	Map<String, String> properties = new HashMap<>();
	properties.put("domain", "my.domain.com");

	UpdateApplicationRequest request = UpdateApplicationRequest.builder()
		.name(APP_NAME)
		.path(APP_PATH)
		.properties(properties)
		.build();

	StepVerifier.create(appDeployer.update(request))
		.assertNext(response -> assertThat(response.getName()).isEqualTo(APP_NAME))
		.verifyComplete();


	then(routes).should().create(CreateRouteRequest.builder()
		.domainId("myDomainComId")
		.spaceId("space-id")
		.host(null)
		.build());
	then(applicationsV2).should().associateRoute(AssociateApplicationRouteRequest
		.builder()
		.applicationId(APP_ID)
		.routeId("route-id")
		.build());
}