Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return list of deleted resources in resources deletion API #470

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ public Optional<Connector> get(String namespace, String connector) {
*
* @param namespace The namespace
* @param connector The connector to create
* @param dryrun Does the creation is a dry run
* @param dryrun Is dry run mode or not?
* @return The created connector
*/
@Post("{?dryrun}")
public Mono<HttpResponse<Connector>> apply(String namespace, @Valid @Body Connector connector,
public Mono<HttpResponse<Connector>> apply(String namespace,
@Valid @Body Connector connector,
@QueryValue(defaultValue = "false") boolean dryrun) {
Namespace ns = getNamespace(namespace);

Expand Down Expand Up @@ -162,14 +163,15 @@ public Mono<HttpResponse<Connector>> apply(String namespace, @Valid @Body Connec
*
* @param namespace The current namespace
* @param connector The current connector name to delete
* @param dryrun Run in dry mode or not
* @param dryrun Is dry run mode or not?
* @return A HTTP response
* @deprecated use {@link #bulkDelete(String, String, boolean)} instead.
*/
@Status(HttpStatus.NO_CONTENT)
@Delete("/{connector}{?dryrun}")
@Deprecated(since = "1.13.0")
public Mono<HttpResponse<Void>> delete(String namespace, String connector,
@Status(HttpStatus.NO_CONTENT)
public Mono<HttpResponse<Void>> delete(String namespace,
String connector,
@QueryValue(defaultValue = "false") boolean dryrun) {
Namespace ns = getNamespace(namespace);

Expand Down Expand Up @@ -206,14 +208,15 @@ public Mono<HttpResponse<Void>> delete(String namespace, String connector,
* Delete connectors.
*
* @param namespace The current namespace
* @param name The name parameter
* @param dryrun Run in dry mode or not
* @param name The name parameter
* @param dryrun Run in dry mode or not?
* @return A HTTP response
*/
@Status(HttpStatus.NO_CONTENT)
@Delete
public Mono<HttpResponse<Void>> bulkDelete(String namespace, @QueryValue(defaultValue = "*") String name,
@QueryValue(defaultValue = "false") boolean dryrun) {
@Status(HttpStatus.OK)
public Mono<HttpResponse<List<Connector>>> bulkDelete(String namespace,
@QueryValue(defaultValue = "*") String name,
@QueryValue(defaultValue = "false") boolean dryrun) {
Namespace ns = getNamespace(namespace);

List<Connector> connectors = connectorService.findByWildcardName(ns, name);
Expand All @@ -233,15 +236,15 @@ public Mono<HttpResponse<Void>> bulkDelete(String namespace, @QueryValue(default
}

if (dryrun) {
return Mono.just(HttpResponse.noContent());
return Mono.just(HttpResponse.ok(connectors));
}

return Flux.fromIterable(connectors)
.flatMap(connector -> {
sendEventLog(connector, ApplyStatus.deleted, connector.getSpec(), null, EMPTY_STRING);
return connectorService.delete(ns, connector);
})
.then(Mono.just(HttpResponse.noContent()));
.then(Mono.just(HttpResponse.ok(connectors)));
}

/**
Expand Down Expand Up @@ -305,7 +308,7 @@ public Mono<MutableHttpResponse<ChangeConnectorState>> changeState(String namesp
* Import unsynchronized connectors.
*
* @param namespace The namespace
* @param dryrun Is dry run mode or not ?
* @param dryrun Is dry run mode or not?
* @return The list of imported connectors
*/
@Post("/_/import{?dryrun}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ public class ConsumerGroupController extends NamespacedResourceController {
* @param namespace The namespace
* @param consumerGroup The consumer group
* @param consumerGroupResetOffsets The information about how to reset
* @param dryrun Is dry run mode or not ?
* @param dryrun Is dry run mode or not?
* @return The reset offsets response
*/
@Post("/{consumerGroup}/reset{?dryrun}")
public List<ConsumerGroupResetOffsetsResponse> resetOffsets(String namespace, String consumerGroup,
public List<ConsumerGroupResetOffsetsResponse> resetOffsets(String namespace,
String consumerGroup,
@Valid @Body
ConsumerGroupResetOffsets consumerGroupResetOffsets,
@QueryValue(defaultValue = "false") boolean dryrun)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Optional<Namespace> get(String namespace) {
* Create a namespace.
*
* @param namespace The namespace
* @param dryrun Does the creation is a dry run
* @param dryrun Is dry run mode or not?
* @return The created namespace
*/
@Post("{?dryrun}")
Expand Down Expand Up @@ -118,19 +118,21 @@ public HttpResponse<Namespace> apply(@Valid @Body Namespace namespace,
* Delete a namespace.
*
* @param namespace The namespace
* @param dryrun Is dry run mode or not ?
* @param dryrun Is dry run mode or not?
* @return An HTTP response
* @deprecated use bulkDelete instead.
*/
@Delete("/{namespace}{?dryrun}")
@Deprecated(since = "1.13.0")
public HttpResponse<Void> delete(String namespace, @QueryValue(defaultValue = "false") boolean dryrun) {
Optional<Namespace> optionalNamespace = namespaceService.findByName(namespace);

if (optionalNamespace.isEmpty()) {
return HttpResponse.notFound();
}

List<String> namespaceResources = namespaceService.findAllResourcesByNamespace(optionalNamespace.get());

if (!namespaceResources.isEmpty()) {
List<String> validationErrors = namespaceResources
.stream()
Expand All @@ -143,21 +145,31 @@ public HttpResponse<Void> delete(String namespace, @QueryValue(defaultValue = "f
return HttpResponse.noContent();
}

performDeletion(optionalNamespace.get());
sendEventLog(
optionalNamespace.get(),
ApplyStatus.deleted,
optionalNamespace.get().getSpec(),
null,
EMPTY_STRING
);

namespaceService.delete(optionalNamespace.get());

return HttpResponse.noContent();
}

/**
* Delete namespaces.
*
* @param dryrun Is dry run mode or not ?
* @param name The name parameter
* @param dryrun Is dry run mode or not?
* @param name The name parameter
* @return An HTTP response
*/
@Delete
public HttpResponse<Void> bulkDelete(@QueryValue(defaultValue = "*") String name,
@QueryValue(defaultValue = "false") boolean dryrun) {
public HttpResponse<List<Namespace>> bulkDelete(@QueryValue(defaultValue = "*") String name,
@QueryValue(defaultValue = "false") boolean dryrun) {
List<Namespace> namespaces = namespaceService.findByWildcardName(name);

if (namespaces.isEmpty()) {
return HttpResponse.notFound();
}
Expand All @@ -182,26 +194,21 @@ public HttpResponse<Void> bulkDelete(@QueryValue(defaultValue = "*") String name
}

if (dryrun) {
return HttpResponse.noContent();
return HttpResponse.ok(namespaces);
}

namespaces.forEach(this::performDeletion);
return HttpResponse.noContent();
}
namespaces.forEach(namespace -> {
sendEventLog(
namespace,
ApplyStatus.deleted,
namespace.getSpec(),
null,
EMPTY_STRING
);

/**
* Perform the deletion of the namespace and send an event log.
*
* @param namespace The namespace to delete
*/
private void performDeletion(Namespace namespace) {
sendEventLog(
namespace,
ApplyStatus.deleted,
namespace.getSpec(),
null,
EMPTY_STRING
);
namespaceService.delete(namespace);
namespaceService.delete(namespace);
});

return HttpResponse.ok(namespaces);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ public Optional<RoleBinding> get(String namespace, String name) {
*
* @param namespace The namespace
* @param roleBinding The role binding
* @param dryrun Does the creation is a dry run
* @param dryrun Is dry run mode or not?
* @return The created role binding
*/
@Post("{?dryrun}")
public HttpResponse<RoleBinding> apply(String namespace, @Valid @Body RoleBinding roleBinding,
public HttpResponse<RoleBinding> apply(String namespace,
@Valid @Body RoleBinding roleBinding,
@QueryValue(defaultValue = "false") boolean dryrun) {
Namespace ns = getNamespace(namespace);

Expand Down Expand Up @@ -112,9 +113,10 @@ public HttpResponse<RoleBinding> apply(String namespace, @Valid @Body RoleBindin
* @deprecated use {@link #bulkDelete(String, String, boolean)} instead.
*/
@Delete("/{name}{?dryrun}")
@Status(HttpStatus.NO_CONTENT)
@Deprecated(since = "1.13.0")
public HttpResponse<Void> delete(String namespace, String name,
@Status(HttpStatus.NO_CONTENT)
public HttpResponse<Void> delete(String namespace,
String name,
@QueryValue(defaultValue = "false") boolean dryrun) {
Optional<RoleBinding> roleBinding = roleBindingService.findByName(namespace, name);
if (roleBinding.isEmpty()) {
Expand Down Expand Up @@ -147,17 +149,19 @@ public HttpResponse<Void> delete(String namespace, String name,
* @param dryrun Is dry run mode or not?
* @return An HTTP response
*/
@Status(HttpStatus.NO_CONTENT)
@Delete
public HttpResponse<Void> bulkDelete(String namespace, @QueryValue(defaultValue = "*") String name,
@QueryValue(defaultValue = "false") boolean dryrun) {
@Status(HttpStatus.OK)
public HttpResponse<List<RoleBinding>> bulkDelete(String namespace,
@QueryValue(defaultValue = "*") String name,
@QueryValue(defaultValue = "false") boolean dryrun) {
List<RoleBinding> roleBindings = roleBindingService.findByWildcardName(namespace, name);

if (roleBindings.isEmpty()) {
return HttpResponse.notFound();
}

if (dryrun) {
return HttpResponse.noContent();
return HttpResponse.ok(roleBindings);
}

roleBindings.forEach(roleBinding -> {
Expand All @@ -171,6 +175,6 @@ public HttpResponse<Void> bulkDelete(String namespace, @QueryValue(defaultValue
roleBindingService.delete(roleBinding);
});

return HttpResponse.noContent();
return HttpResponse.ok(roleBindings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.time.Instant;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -88,11 +89,12 @@ public Mono<Schema> get(String namespace, String subject) {
*
* @param namespace The namespace
* @param schema The schema to create
* @param dryrun Does the creation is a dry run
* @param dryrun Is dry run mode or not?
* @return The created schema
*/
@Post
public Mono<HttpResponse<Schema>> apply(String namespace, @Valid @Body Schema schema,
public Mono<HttpResponse<Schema>> apply(String namespace,
@Valid @Body Schema schema,
@QueryValue(defaultValue = "false") boolean dryrun) {
Namespace ns = getNamespace(namespace);

Expand Down Expand Up @@ -161,12 +163,12 @@ public Mono<HttpResponse<Schema>> apply(String namespace, @Valid @Body Schema sc
* @param dryrun Run in dry mode or not?
* @return A HTTP response
*/
@Status(HttpStatus.NO_CONTENT)
@Delete
public Mono<HttpResponse<Void>> bulkDelete(String namespace,
@QueryValue(defaultValue = "*") String name,
@QueryValue("version") Optional<String> versionOptional,
@QueryValue(defaultValue = "false") boolean dryrun) {
@Status(HttpStatus.OK)
public Mono<HttpResponse<List<Schema>>> bulkDelete(String namespace,
@QueryValue(defaultValue = "*") String name,
@QueryValue("version") Optional<String> versionOptional,
@QueryValue(defaultValue = "false") boolean dryrun) {
Namespace ns = getNamespace(namespace);

return schemaService.findByWildcardName(ns, name)
Expand All @@ -176,17 +178,22 @@ public Mono<HttpResponse<Void>> bulkDelete(String namespace,
.map(Optional::of)
.defaultIfEmpty(Optional.empty()))
.collectList()
.flatMap(schemas -> {
if (schemas.isEmpty() || schemas.stream().anyMatch(Optional::isEmpty)) {
.flatMap(optionalSchemas -> {
if (optionalSchemas.isEmpty() || optionalSchemas.stream().anyMatch(Optional::isEmpty)) {
return Mono.just(HttpResponse.notFound());
}

List<Schema> schemas = optionalSchemas
.stream()
.filter(Optional::isPresent)
.map(Optional::get)
.toList();

if (dryrun) {
return Mono.just(HttpResponse.noContent());
return Mono.just(HttpResponse.ok(schemas));
}

return Flux.fromIterable(schemas)
.map(Optional::get)
.flatMap(schema -> (versionOptional.isEmpty()
? schemaService.deleteAllVersions(ns, schema.getMetadata().getName()) :
schemaService.deleteVersion(ns, schema.getMetadata().getName(), versionOptional.get()))
Expand All @@ -201,7 +208,7 @@ public Mono<HttpResponse<Void>> bulkDelete(String namespace,
);
return Mono.just(HttpResponse.noContent());
}))
.then(Mono.just(HttpResponse.noContent()));
.then(Mono.just(HttpResponse.ok(schemas)));
});
}

Expand All @@ -215,9 +222,9 @@ public Mono<HttpResponse<Void>> bulkDelete(String namespace,
* @return A HTTP response
* @deprecated use {@link #bulkDelete(String, String, Optional, boolean)} instead.
*/
@Status(HttpStatus.NO_CONTENT)
@Delete("/{subject}")
@Deprecated(since = "1.13.0")
@Status(HttpStatus.NO_CONTENT)
public Mono<HttpResponse<Void>> delete(String namespace,
@PathVariable String subject,
@QueryValue("version") Optional<String> versionOptional,
Expand Down Expand Up @@ -273,7 +280,8 @@ public Mono<HttpResponse<Void>> delete(String namespace,
* @return A schema compatibility state
*/
@Post("/{subject}/config")
public Mono<HttpResponse<SchemaCompatibilityState>> config(String namespace, @PathVariable String subject,
public Mono<HttpResponse<SchemaCompatibilityState>> config(String namespace,
@PathVariable String subject,
Schema.Compatibility compatibility) {
Namespace ns = getNamespace(namespace);

Expand Down
Loading