Skip to content

Commit

Permalink
feat(provider/kafka): add new TruncateKafkaTopicRecords action (#488)
Browse files Browse the repository at this point in the history
fix: #488
  • Loading branch information
fhussonnois committed Jan 5, 2025
1 parent bd455be commit 52ad33d
Show file tree
Hide file tree
Showing 24 changed files with 510 additions and 283 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,85 @@
*/
package io.streamthoughts.jikkou.core.models;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import io.streamthoughts.jikkou.core.annotation.Reflectable;
import jakarta.validation.constraints.NotNull;
import java.util.Objects;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;

public class BaseHasMetadata implements HasMetadata {
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"apiVersion",
"kind",
"metadata"
})
@Reflectable
public abstract class BaseHasMetadata implements HasMetadata {

private String kind;
private String apiVersion;
private ObjectMeta metadata;
/**
* Kind attached to the resource.
*/
@JsonProperty("kind")
@JsonPropertyDescription("Kind attached to the resource.")
@NotNull
protected final String kind;

/**
* Creates a new {@link BaseHasMetadata} instance.
* ApiVersion attached to the resource.
*/
public BaseHasMetadata() {
this(new ObjectMeta());
}
@JsonProperty("apiVersion")
@JsonPropertyDescription("ApiVersion attached to the resource.")
protected final String apiVersion;

/**
* Metadata attached to the resource.
*/
@JsonProperty("metadata")
@JsonPropertyDescription("Metadata attached to the resource.")
protected final ObjectMeta metadata;

/**
* Creates a new {@link BaseHasMetadata} instance.
*
* @param metadata The object metadata.
* @param metadata The metadata object.
*/
public BaseHasMetadata(ObjectMeta metadata) {
this.metadata = metadata;
public BaseHasMetadata(final ObjectMeta metadata) {
this(null, null, metadata);
}

/**
* Creates a new {@link BaseHasMetadata} instance.
*
* @param kind The resource kind.
* @param apiVersion The resource API Version.
* @param metadata The object metadata..
* @param kind The resource Kind.
* @param metadata The resource metadata.
*/
public BaseHasMetadata(String kind,
String apiVersion,
ObjectMeta metadata) {
this.kind = kind;
this.apiVersion = apiVersion;
this.metadata = metadata;
public BaseHasMetadata(@Nullable final String apiVersion,
@Nullable final String kind,
@Nullable final ObjectMeta metadata) {
this.apiVersion = Optional.ofNullable(apiVersion).orElseGet(() -> Resource.getApiVersion(this.getClass()));
this.kind = Optional.ofNullable(kind).orElseGet(() -> Resource.getKind(this.getClass()));
this.metadata = Optional.ofNullable(metadata).orElse(new ObjectMeta());
}

/**
* {@inheritDoc}
**/
@Override
public String getKind() {
return Optional.of(kind).orElse(Resource.getKind(this.getClass()));
return kind;
}

/**
* {@inheritDoc}
**/
@Override
public String getApiVersion() {
return Optional.of(apiVersion).orElse(Resource.getApiVersion(this.getClass()));
return apiVersion;
}

/**
Expand All @@ -73,8 +99,20 @@ public ObjectMeta getMetadata() {
* {@inheritDoc}
**/
@Override
public HasMetadata withMetadata(ObjectMeta metadata) {
this.metadata = metadata;
return this;
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BaseHasMetadata that = (BaseHasMetadata) o;
return Objects.equals(kind, that.kind) &&
Objects.equals(apiVersion, that.apiVersion) &&
Objects.equals(metadata, that.metadata);
}

/**
* {@inheritDoc}
**/
@Override
public int hashCode() {
return Objects.hash(kind, apiVersion, metadata);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io.streamthoughts.jikkou.core.annotation.Reflectable;
import jakarta.validation.constraints.NotNull;
import java.util.Objects;
import java.util.Optional;

/**
* Base class for defining a specific resource.
Expand All @@ -32,29 +31,7 @@
"spec"
})
@Reflectable
public abstract class SpecificResource<T extends SpecificResource<T, S>, S> implements HasMetadata, HasSpec<S> {

/**
* Kind attached to the resource.
*/
@JsonProperty("kind")
@JsonPropertyDescription("Kind attached to the resource.")
@NotNull
protected final String kind;

/**
* ApiVersion attached to the resource.
*/
@JsonProperty("apiVersion")
@JsonPropertyDescription("ApiVersion attached to the resource.")
protected final String apiVersion;

/**
* Metadata attached to the resource.
*/
@JsonProperty("metadata")
@JsonPropertyDescription("Metadata attached to the resource.")
protected final ObjectMeta metadata;
public abstract class SpecificResource<T extends SpecificResource<T, S>, S> extends BaseHasMetadata implements HasMetadata, HasSpec<S> {

/**
* Specification object attached to the resource.
Expand Down Expand Up @@ -92,36 +69,10 @@ public SpecificResource(final String apiVersion,
final String kind,
final ObjectMeta metadata,
final S spec) {
this.apiVersion = Optional.ofNullable(apiVersion).orElseGet(() -> Resource.getApiVersion(this.getClass()));
this.kind = Optional.ofNullable(kind).orElseGet(() -> Resource.getKind(this.getClass()));
this.metadata = Optional.ofNullable(metadata).orElse(new ObjectMeta());
super(apiVersion, kind, metadata);
this.spec = spec;
}

/**
* {@inheritDoc}
**/
@Override
public String getKind() {
return kind;
}

/**
* {@inheritDoc}
**/
@Override
public String getApiVersion() {
return apiVersion;
}

/**
* {@inheritDoc}
**/
@Override
public ObjectMeta getMetadata() {
return metadata;
}

/**
* {@inheritDoc}
**/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,7 @@
})
@JsonDeserialize
@Reflectable
public abstract class SpecificResourceList<T extends SpecificResourceList<T, E>, E extends HasMetadata> implements ResourceList<E> {

/**
* Kind attached to the resource.
*/
@JsonProperty("kind")
@JsonPropertyDescription("Kind attached to the resource.")
@NotNull
protected final String kind;

/**
* ApiVersion attached to the resource.
*/
@JsonProperty("apiVersion")
@JsonPropertyDescription("ApiVersion attached to the resource.")
protected final String apiVersion;

/**
* Metadata attached to the resource.
*/
@JsonProperty("metadata")
@JsonPropertyDescription("Metadata attached to the resource.")
protected final ObjectMeta metadata;
public abstract class SpecificResourceList<T extends SpecificResourceList<T, E>, E extends HasMetadata> extends BaseHasMetadata implements ResourceList<E> {

/**
* List of specification objects
Expand Down Expand Up @@ -94,28 +72,10 @@ public SpecificResourceList(final String apiVersion,
final String kind,
final ObjectMeta metadata,
final List<E> items) {
this.apiVersion = apiVersion;
this.kind = kind;
this.metadata = metadata;
super(apiVersion, kind, metadata);
this.items = items;
}

/**
* {@inheritDoc}
**/
@Override
public String getKind() {
return Optional.ofNullable(kind).orElseGet(() -> Resource.getKind(this.getClass()));
}

/**
* {@inheritDoc}
**/
@Override
public String getApiVersion() {
return Optional.ofNullable(apiVersion).orElseGet(() -> Resource.getApiVersion(this.getClass()));
}

/**
* {@inheritDoc}
**/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.streamthoughts.jikkou.core.annotation.Reflectable;
import io.streamthoughts.jikkou.core.models.BaseHasMetadata;
import io.streamthoughts.jikkou.core.models.HasMetadata;
import io.streamthoughts.jikkou.core.models.ObjectMeta;
import io.streamthoughts.jikkou.core.models.ObjectTemplate;
import jakarta.validation.constraints.NotNull;
import java.beans.ConstructorProperties;
import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -36,29 +35,7 @@
})
@JsonDeserialize
@Reflectable
public class GenericResource implements HasMetadata {

/**
* ApiVersion attached to the resource.
*/
@JsonProperty("apiVersion")
@JsonPropertyDescription("ApiVersion attached to the resource.")
private final String apiVersion;

/**
* Kind attached to the resource.
*/
@JsonProperty("kind")
@JsonPropertyDescription("Kind attached to the resource.")
@NotNull
private final String kind;

/**
* Metadata attached to the resource.
*/
@JsonProperty("metadata")
@JsonPropertyDescription("Metadata attached to the resource.")
private final ObjectMeta metadata;
public class GenericResource extends BaseHasMetadata implements HasMetadata {

@JsonProperty("template")
private final ObjectTemplate template;
Expand Down Expand Up @@ -101,34 +78,11 @@ public GenericResource(final String apiVersion,
final ObjectMeta metadata,
final ObjectTemplate template,
final Map<String, Object> additionalProperties) {
this.apiVersion = apiVersion;
this.kind = kind;
this.metadata = metadata;
super(apiVersion, kind, metadata);
this.template = template;
this.additionalProperties = additionalProperties;
}

/**
* (Required)
*/
@JsonProperty("apiVersion")
public String getApiVersion() {
return apiVersion;
}

/**
* (Required)
*/
@JsonProperty("kind")
public String getKind() {
return kind;
}

@JsonProperty("metadata")
public ObjectMeta getMetadata() {
return metadata;
}

/**
* (Required)
*/
Expand All @@ -152,26 +106,18 @@ public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

/**
* {@inheritDoc}
**/
/** {@inheritDoc} **/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GenericResource resource = (GenericResource) o;
return Objects.equals(apiVersion, resource.apiVersion) &&
Objects.equals(kind, resource.kind) &&
Objects.equals(metadata, resource.metadata) &&
Objects.equals(template, resource.template) &&
Objects.equals(additionalProperties, resource.additionalProperties);
if (!super.equals(o)) return false;
GenericResource that = (GenericResource) o;
return Objects.equals(template, that.template) && Objects.equals(additionalProperties, that.additionalProperties);
}

/**
* {@inheritDoc}
**/
/** {@inheritDoc} **/
@Override
public int hashCode() {
return Objects.hash(apiVersion, kind, metadata, template, additionalProperties);
return Objects.hash(super.hashCode(), template, additionalProperties);
}
}
Loading

0 comments on commit 52ad33d

Please sign in to comment.