Skip to content
Draft
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 @@ -22,7 +22,6 @@
import static com.michelin.kafkactl.util.constant.ResourceKind.RESOURCE_DEFINITION;

import com.michelin.kafkactl.hook.AuthenticatedHook;
import com.michelin.kafkactl.model.Metadata;
import com.michelin.kafkactl.model.Resource;
import com.michelin.kafkactl.service.FormatService;
import io.micronaut.core.annotation.ReflectiveAccess;
Expand Down Expand Up @@ -58,7 +57,7 @@ public Integer onAuthSuccess() {
try {
List<Resource> resources = apiResourcesService.listResourceDefinitions().stream()
.map(apiResource -> Resource.builder()
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name(apiResource.getKind())
.build())
.spec(Map.of(
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/michelin/kafkactl/command/Connector.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import com.michelin.kafkactl.hook.AuthenticatedHook;
import com.michelin.kafkactl.model.ApiResource;
import com.michelin.kafkactl.model.Metadata;
import com.michelin.kafkactl.model.Resource;
import com.michelin.kafkactl.service.FormatService;
import com.michelin.kafkactl.service.ResourceService;
Expand Down Expand Up @@ -92,7 +91,7 @@ public Integer onAuthSuccess() {

List<Resource> changeConnectorResponses = connectors.stream()
.map(connector -> Resource.builder()
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.namespace(namespace)
.name(connector)
.build())
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/michelin/kafkactl/command/Delete.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.michelin.kafkactl.hook.DryRunHook;
import com.michelin.kafkactl.model.ApiResource;
import com.michelin.kafkactl.model.Metadata;
import com.michelin.kafkactl.model.Resource;
import com.michelin.kafkactl.service.FileService;
import com.michelin.kafkactl.service.FormatService;
Expand Down Expand Up @@ -159,7 +158,7 @@ private List<Resource> parseResources(String namespace) {

// Generate a single resource with minimum details from input
var builder = Resource.builder()
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name(config.nameConfig.resourceName)
.namespace(namespace)
.build())
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/michelin/kafkactl/command/ResetOffsets.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.michelin.kafkactl.command;

import com.michelin.kafkactl.hook.DryRunHook;
import com.michelin.kafkactl.model.Metadata;
import com.michelin.kafkactl.model.Resource;
import com.michelin.kafkactl.service.ResourceService;
import io.micronaut.core.annotation.ReflectiveAccess;
Expand Down Expand Up @@ -99,7 +98,10 @@ public Integer onAuthSuccess() throws IOException {
Resource consumerGroupResetOffset = Resource.builder()
.apiVersion("v1")
.kind("ConsumerGroupResetOffsets")
.metadata(Metadata.builder().namespace(namespace).name(group).build())
.metadata(Resource.Metadata.builder()
.namespace(namespace)
.name(group)
.build())
.spec(consumerGroupResetOffsetSpec)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import com.michelin.kafkactl.hook.ValidCurrentContextHook;
import com.michelin.kafkactl.mixin.UnmaskTokenMixin;
import com.michelin.kafkactl.model.Metadata;
import com.michelin.kafkactl.model.Resource;
import com.michelin.kafkactl.property.KafkactlProperties;
import com.michelin.kafkactl.service.FormatService;
Expand Down Expand Up @@ -74,7 +73,7 @@ public Integer onContextValid() {

String currentContextName = configService.getCurrentContextName();
Resource currentContextAsResource = Resource.builder()
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name(currentContextName != null ? currentContextName : StringUtils.EMPTY_STRING)
.build())
.spec(specs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import com.michelin.kafkactl.hook.HelpHook;
import com.michelin.kafkactl.mixin.UnmaskTokenMixin;
import com.michelin.kafkactl.model.Metadata;
import com.michelin.kafkactl.model.Resource;
import com.michelin.kafkactl.property.KafkactlProperties;
import com.michelin.kafkactl.service.FormatService;
Expand Down Expand Up @@ -83,7 +82,7 @@ public Integer call() {
}

return Resource.builder()
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name(userContext.getName())
.build())
.spec(specs)
Expand Down
48 changes: 0 additions & 48 deletions src/main/java/com/michelin/kafkactl/model/Metadata.java

This file was deleted.

66 changes: 66 additions & 0 deletions src/main/java/com/michelin/kafkactl/model/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@
*/
package com.michelin.kafkactl.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.micronaut.core.annotation.ReflectiveAccess;
import java.util.Date;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/** Resource. */
@Data
Expand All @@ -41,4 +47,64 @@ public class Resource {
private Map<String, Object> spec;

private Object status;

@Getter
@Setter
@Builder
@ToString
@ReflectiveAccess
@NoArgsConstructor
@AllArgsConstructor
public static class Metadata {
private String name;
private String namespace;
private String cluster;
private Map<String, String> labels;

@JsonFormat(shape = JsonFormat.Shape.STRING)
private Date creationTimestamp;

private Status status;

@Getter
@Setter
@Builder
@ReflectiveAccess
@NoArgsConstructor
@AllArgsConstructor
public static class Status {
private Phase phase;
private String message;

@JsonFormat(shape = JsonFormat.Shape.STRING)
private Date lastUpdateTime;
}

public enum Phase {
PENDING("Pending"),
FAIL("Fail"),
SUCCESS("Success");

private final String name;

Phase(String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}

@JsonCreator
public static Phase fromString(String key) {
for (Phase type : Phase.values()) {
if (type.name().equalsIgnoreCase(key)) {
return type;
}
}
return null;
}
}
}
}
8 changes: 1 addition & 7 deletions src/main/java/com/michelin/kafkactl/model/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
@NoArgsConstructor
@AllArgsConstructor
public class Status {
@Builder.Default
private String apiVersion = "v1";

@Builder.Default
private String kind = "Status";

private StatusPhase status;
private String message;
private String reason;
Expand All @@ -51,7 +45,7 @@ public enum StatusPhase {
FAILED;

/**
* Build status phase from string. This is because Ns4Kafka returns capitalised status phases.
* Build status phase from string. This is because Ns4Kafka returns capitalized status phases.
*
* @param key the key
* @return the status phase
Expand Down
17 changes: 8 additions & 9 deletions src/test/java/com/michelin/kafkactl/command/ApplyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import com.michelin.kafkactl.Kafkactl;
import com.michelin.kafkactl.model.ApiResource;
import com.michelin.kafkactl.model.Metadata;
import com.michelin.kafkactl.model.Resource;
import com.michelin.kafkactl.property.KafkactlProperties;
import com.michelin.kafkactl.service.ApiResourcesService;
Expand Down Expand Up @@ -150,7 +149,7 @@ void shouldNotApplyWhenInvalidResources() {
Resource resource = Resource.builder()
.kind("Topic")
.apiVersion("v1")
.metadata(Metadata.builder().name("prefix.topic").build())
.metadata(Resource.Metadata.builder().name("prefix.topic").build())
.spec(Collections.emptyMap())
.build();

Expand All @@ -174,7 +173,7 @@ void shouldNotApplyWhenNamespaceMismatch() {
Resource resource = Resource.builder()
.kind("Topic")
.apiVersion("v1")
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name("prefix.topic")
.namespace("namespace")
.build())
Expand All @@ -200,7 +199,7 @@ void shouldNotApplyWhenHttpClientResponseException() {
Resource resource = Resource.builder()
.kind("Topic")
.apiVersion("v1")
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name("prefix.topic")
.namespace("namespace")
.build())
Expand Down Expand Up @@ -233,7 +232,7 @@ void shouldApply() {
Resource resource = Resource.builder()
.kind("Topic")
.apiVersion("v1")
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name("prefix.topic")
.namespace("namespace")
.build())
Expand Down Expand Up @@ -274,7 +273,7 @@ void shouldApplyDryRun() {
Resource resource = Resource.builder()
.kind("Topic")
.apiVersion("v1")
.metadata(Metadata.builder().name("prefix.topic").build())
.metadata(Resource.Metadata.builder().name("prefix.topic").build())
.spec(Collections.emptyMap())
.build();

Expand Down Expand Up @@ -316,7 +315,7 @@ void shouldApplySchema() {
Resource resource = Resource.builder()
.kind("Schema")
.apiVersion("v1")
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name("prefix.schema")
.namespace("namespace")
.build())
Expand Down Expand Up @@ -359,7 +358,7 @@ void shouldApplyInlineSchema() {
Resource resource = Resource.builder()
.kind("Schema")
.apiVersion("v1")
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name("prefix.schema")
.namespace("namespace")
.build())
Expand Down Expand Up @@ -406,7 +405,7 @@ void shouldNotApplySchemaWhenNotExist() {
Resource resource = Resource.builder()
.kind("Schema")
.apiVersion("v1")
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name("prefix.schema")
.namespace("namespace")
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import com.michelin.kafkactl.Kafkactl;
import com.michelin.kafkactl.model.ApiResource;
import com.michelin.kafkactl.model.Metadata;
import com.michelin.kafkactl.model.Resource;
import com.michelin.kafkactl.property.KafkactlProperties;
import com.michelin.kafkactl.service.ApiResourcesService;
Expand Down Expand Up @@ -128,7 +127,7 @@ void shouldChangeState() {
Resource resource = Resource.builder()
.kind("Connector")
.apiVersion("v1")
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name("prefix.connector")
.namespace("namespace")
.build())
Expand Down Expand Up @@ -156,7 +155,7 @@ void shouldChangeStateOfAll() {
Resource resource = Resource.builder()
.kind("Connector")
.apiVersion("v1")
.metadata(Metadata.builder()
.metadata(Resource.Metadata.builder()
.name("prefix.connector")
.namespace("namespace")
.build())
Expand Down
Loading