use of org.cloudfoundry.client.v2.resourcematch.Resource in project cf-java-client by cloudfoundry.
the class CloudFoundryCleaner method cleanRoutes.
private static Flux<Void> cleanRoutes(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
return getAllDomains(cloudFoundryClient).flatMapMany(domains -> PaginationUtils.requestClientV2Resources(page -> cloudFoundryClient.routes().list(ListRoutesRequest.builder().page(page).build())).map(resource -> Tuples.of(domains, resource))).filter(predicate((domains, route) -> nameFactory.isDomainName(domains.get(ResourceUtils.getEntity(route).getDomainId())) || nameFactory.isApplicationName(ResourceUtils.getEntity(route).getHost()) || nameFactory.isHostName(ResourceUtils.getEntity(route).getHost()))).flatMap(function((domains, route) -> cloudFoundryClient.routes().delete(DeleteRouteRequest.builder().async(true).routeId(ResourceUtils.getId(route)).build()).flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)).doOnError(t -> {
RouteEntity entity = ResourceUtils.getEntity(route);
LOGGER.error("Unable to delete route {}.{}:{}{}", entity.getHost(), domains.get(entity.getDomainId()), entity.getPort(), entity.getPath(), t);
})));
}
use of org.cloudfoundry.client.v2.resourcematch.Resource in project cf-java-client by cloudfoundry.
the class DefaultServices method toServiceInstance.
private static ServiceInstance toServiceInstance(UnionServiceInstanceResource resource, Optional<String> plan, List<String> applications, ServiceEntity serviceEntity) {
String extra = Optional.ofNullable(serviceEntity.getExtra()).orElse("");
Optional<String> documentationUrl = Optional.ofNullable(getExtraValue(extra, "documentationUrl"));
UnionServiceInstanceEntity serviceInstanceEntity = resource.getEntity();
LastOperation lastOperation = Optional.ofNullable(serviceInstanceEntity.getLastOperation()).orElse(LastOperation.builder().build());
return ServiceInstance.builder().applications(applications).dashboardUrl(serviceInstanceEntity.getDashboardUrl()).description(serviceEntity.getDescription()).documentationUrl(documentationUrl.orElse(null)).id(ResourceUtils.getId(resource)).lastOperation(lastOperation.getType()).message(lastOperation.getDescription()).name(serviceInstanceEntity.getName()).plan(plan.orElse(null)).service(serviceEntity.getLabel()).startedAt(lastOperation.getCreatedAt()).status(lastOperation.getState()).tags(serviceInstanceEntity.getTags()).type(ServiceInstanceType.from(serviceInstanceEntity.getType())).updatedAt(lastOperation.getUpdatedAt()).build();
}
use of org.cloudfoundry.client.v2.resourcematch.Resource in project cf-java-client by cloudfoundry.
the class DefaultRoutes method toRoute.
private static Route toRoute(List<String> applications, String domain, RouteResource resource, Optional<String> service, String space) {
RouteEntity entity = ResourceUtils.getEntity(resource);
Route.Builder builder = Route.builder().applications(applications).domain(domain).host(entity.getHost()).id(ResourceUtils.getId(resource)).path(entity.getPath()).space(space);
service.ifPresent(builder::service);
return builder.build();
}
use of org.cloudfoundry.client.v2.resourcematch.Resource in project cf-java-client by cloudfoundry.
the class DefaultApplications method convertToApplicationEvent.
private static ApplicationEvent convertToApplicationEvent(EventResource resource) {
EventEntity entity = resource.getEntity();
Date timestamp = null;
try {
timestamp = DateUtils.parseFromIso8601(entity.getTimestamp());
} catch (IllegalArgumentException iae) {
// do not set time
}
return ApplicationEvent.builder().actor(entity.getActorName()).description(eventDescription(getMetadataRequest(entity), getEntryNames(entity.getType()))).id(ResourceUtils.getId(resource)).event(entity.getType()).time(timestamp).build();
}
Aggregations