Refactor schema api contract
This commit is contained in:
parent
08d855f975
commit
d853862790
4 changed files with 67 additions and 66 deletions
|
@ -5,6 +5,11 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||||
public class NotFoundException extends RuntimeException {
|
public class NotFoundException extends RuntimeException {
|
||||||
|
|
||||||
|
public NotFoundException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
public NotFoundException(String message) {
|
public NotFoundException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.provectus.kafka.ui.cluster.service;
|
||||||
import com.provectus.kafka.ui.cluster.exception.NotFoundException;
|
import com.provectus.kafka.ui.cluster.exception.NotFoundException;
|
||||||
import com.provectus.kafka.ui.cluster.model.ClustersStorage;
|
import com.provectus.kafka.ui.cluster.model.ClustersStorage;
|
||||||
import com.provectus.kafka.ui.model.NewSchemaSubject;
|
import com.provectus.kafka.ui.model.NewSchemaSubject;
|
||||||
import com.provectus.kafka.ui.model.SubjectSchema;
|
import com.provectus.kafka.ui.model.SchemaSubject;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -19,10 +19,10 @@ import reactor.core.publisher.Mono;
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class SchemaRegistryService {
|
public class SchemaRegistryService {
|
||||||
public static final String URL_SUBJECTS = "/subjects";
|
private static final String URL_SUBJECTS = "/subjects";
|
||||||
public static final String URL_SUBJECT = "/subjects/{subjectName}";
|
private static final String URL_SUBJECT = "/subjects/{subjectName}";
|
||||||
public static final String URL_SUBJECT_VERSIONS = "/subjects/{subjectName}/versions";
|
private static final String URL_SUBJECT_VERSIONS = "/subjects/{subjectName}/versions";
|
||||||
public static final String URL_SUBJECT_BY_VERSION = "/subjects/{subjectName}/versions/{version}";
|
private static final String URL_SUBJECT_BY_VERSION = "/subjects/{subjectName}/versions/{version}";
|
||||||
|
|
||||||
private final ClustersStorage clustersStorage;
|
private final ClustersStorage clustersStorage;
|
||||||
private final WebClient webClient;
|
private final WebClient webClient;
|
||||||
|
@ -33,7 +33,7 @@ public class SchemaRegistryService {
|
||||||
.uri(cluster.getSchemaRegistry() + URL_SUBJECTS)
|
.uri(cluster.getSchemaRegistry() + URL_SUBJECTS)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.bodyToFlux(String.class))
|
.bodyToFlux(String.class))
|
||||||
.orElse(Flux.empty());
|
.orElse(Flux.error(new NotFoundException("No such cluster")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Flux<Integer> getSchemaSubjectVersions(String clusterName, String subjectName) {
|
public Flux<Integer> getSchemaSubjectVersions(String clusterName, String subjectName) {
|
||||||
|
@ -43,47 +43,47 @@ public class SchemaRegistryService {
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.onStatus(HttpStatus.NOT_FOUND::equals, resp -> Mono.error(new NotFoundException("No such subject")))
|
.onStatus(HttpStatus.NOT_FOUND::equals, resp -> Mono.error(new NotFoundException("No such subject")))
|
||||||
.bodyToFlux(Integer.class))
|
.bodyToFlux(Integer.class))
|
||||||
.orElse(Flux.empty());
|
.orElse(Flux.error(new NotFoundException("No such cluster")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Flux<SubjectSchema> getSchemaSubjectByVersion(String clusterName, String subjectName, Integer version) {
|
public Flux<SchemaSubject> getSchemaSubjectByVersion(String clusterName, String subjectName, Integer version) {
|
||||||
return clustersStorage.getClusterByName(clusterName)
|
return clustersStorage.getClusterByName(clusterName)
|
||||||
.map(cluster -> webClient.get()
|
.map(cluster -> webClient.get()
|
||||||
.uri(cluster.getSchemaRegistry() + URL_SUBJECT_BY_VERSION, subjectName, version)
|
.uri(cluster.getSchemaRegistry() + URL_SUBJECT_BY_VERSION, subjectName, version)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.onStatus(HttpStatus.NOT_FOUND::equals, resp -> Mono.error(new NotFoundException("No such subject or version")))
|
.onStatus(HttpStatus.NOT_FOUND::equals, resp -> Mono.error(new NotFoundException("No such subject or version")))
|
||||||
.bodyToFlux(SubjectSchema.class))
|
.bodyToFlux(SchemaSubject.class))
|
||||||
.orElse(Flux.empty());
|
.orElse(Flux.error(new NotFoundException()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<Object> deleteSchemaSubjectByVersion(String clusterName, String subjectName, Integer version) {
|
public Mono<ResponseEntity<Void>> deleteSchemaSubjectByVersion(String clusterName, String subjectName, Integer version) {
|
||||||
return clustersStorage.getClusterByName(clusterName)
|
return clustersStorage.getClusterByName(clusterName)
|
||||||
.map(cluster -> webClient.delete()
|
.map(cluster -> webClient.delete()
|
||||||
.uri(cluster.getSchemaRegistry() + URL_SUBJECT_BY_VERSION, subjectName, version)
|
.uri(cluster.getSchemaRegistry() + URL_SUBJECT_BY_VERSION, subjectName, version)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.onStatus(HttpStatus.NOT_FOUND::equals, resp -> Mono.error(new NotFoundException("No such subject or version")))
|
.onStatus(HttpStatus.NOT_FOUND::equals, resp -> Mono.error(new NotFoundException("No such subject or version")))
|
||||||
.bodyToMono(Object.class))
|
.toBodilessEntity())
|
||||||
.orElse(Mono.empty());
|
.orElse(Mono.error(new NotFoundException("No such cluster")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<Object> deleteSchemaSubject(String clusterName, String subjectName) {
|
public Mono<ResponseEntity<Void>> deleteSchemaSubject(String clusterName, String subjectName) {
|
||||||
return clustersStorage.getClusterByName(clusterName)
|
return clustersStorage.getClusterByName(clusterName)
|
||||||
.map(cluster -> webClient.delete()
|
.map(cluster -> webClient.delete()
|
||||||
.uri(cluster.getSchemaRegistry() + URL_SUBJECT, subjectName)
|
.uri(cluster.getSchemaRegistry() + URL_SUBJECT, subjectName)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.onStatus(HttpStatus.NOT_FOUND::equals, resp -> Mono.error(new NotFoundException("No such subject or version")))
|
.onStatus(HttpStatus.NOT_FOUND::equals, resp -> Mono.error(new NotFoundException("No such subject or version")))
|
||||||
.bodyToMono(Object.class))
|
.toBodilessEntity())
|
||||||
.orElse(Mono.empty());
|
.orElse(Mono.error(new NotFoundException("No such cluster")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<ResponseEntity<SubjectSchema>> createNewSubject(String clusterName, String subjectSchema, Mono<NewSchemaSubject> newSchemaSubject) {
|
public Mono<ResponseEntity<SchemaSubject>> createNewSubject(String clusterName, String subjectSchema, Mono<NewSchemaSubject> newSchemaSubject) {
|
||||||
return clustersStorage.getClusterByName(clusterName)
|
return clustersStorage.getClusterByName(clusterName)
|
||||||
.map(cluster -> webClient.post()
|
.map(cluster -> webClient.post()
|
||||||
.uri(cluster.getSchemaRegistry() + URL_SUBJECT_VERSIONS, subjectSchema)
|
.uri(cluster.getSchemaRegistry() + URL_SUBJECT_VERSIONS, subjectSchema)
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.body(BodyInserters.fromPublisher(newSchemaSubject, NewSchemaSubject.class))
|
.body(BodyInserters.fromPublisher(newSchemaSubject, NewSchemaSubject.class))
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.toEntity(SubjectSchema.class))
|
.toEntity(SchemaSubject.class))
|
||||||
.orElse(Mono.empty());
|
.orElse(Mono.error(new NotFoundException("No such cluster")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,35 +103,41 @@ public class MetricsRestController implements ApiClustersApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<ResponseEntity<Flux<SubjectSchema>>> getSchemaSubjectByVersion(String clusterName, String subjectName, Integer version, ServerWebExchange exchange) {
|
public Mono<ResponseEntity<Flux<SchemaSubject>>> getSchemaByVersion(String clusterName, String schemaName, Integer version, ServerWebExchange exchange) {
|
||||||
Flux<SubjectSchema> flux = schemaRegistryService.getSchemaSubjectByVersion(clusterName, subjectName, version);
|
Flux<SchemaSubject> flux = schemaRegistryService.getSchemaSubjectByVersion(clusterName, schemaName, version);
|
||||||
return Mono.just(ResponseEntity.ok(flux));
|
return Mono.just(ResponseEntity.ok(flux)).onErrorReturn(ResponseEntity.notFound().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<ResponseEntity<Flux<String>>> getSchemaSubjects(String clusterName, ServerWebExchange exchange) {
|
public Mono<ResponseEntity<Flux<String>>> getSchemas(String clusterName, ServerWebExchange exchange) {
|
||||||
Flux<String> subjects = schemaRegistryService.getAllSchemaSubjects(clusterName);
|
Flux<String> subjects = schemaRegistryService.getAllSchemaSubjects(clusterName);
|
||||||
return Mono.just(ResponseEntity.ok(subjects));
|
return Mono.just(ResponseEntity.ok(subjects));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<ResponseEntity<Flux<Integer>>> getSchemaSubjectVersions(String clusterName, String subjectName, ServerWebExchange exchange) {
|
public Mono<ResponseEntity<Flux<Integer>>> getSchemaVersions(String clusterName, String subjectName, ServerWebExchange exchange) {
|
||||||
return Mono.just(ResponseEntity.ok(schemaRegistryService.getSchemaSubjectVersions(clusterName, subjectName)));
|
return Mono.just(ResponseEntity.ok(schemaRegistryService.getSchemaSubjectVersions(clusterName, subjectName)))
|
||||||
|
.onErrorReturn(ResponseEntity.notFound().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<ResponseEntity<Object>> deleteSchemaByVersion(String clusterName, String subjectName, Integer version, ServerWebExchange exchange) {
|
public Mono<ResponseEntity<Void>> deleteSchemaByVersion(String clusterName, String subjectName, Integer version, ServerWebExchange exchange) {
|
||||||
return Mono.just(ResponseEntity.ok(schemaRegistryService.deleteSchemaSubjectByVersion(clusterName, subjectName, version)));
|
return schemaRegistryService.deleteSchemaSubjectByVersion(clusterName, subjectName, version)
|
||||||
|
.onErrorReturn(ResponseEntity.notFound().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<ResponseEntity<Object>> deleteSchemaSubject(String clusterName, String subjectName, ServerWebExchange exchange) {
|
public Mono<ResponseEntity<Void>> deleteSchema(String clusterName, String subjectName, ServerWebExchange exchange) {
|
||||||
return Mono.just(ResponseEntity.ok(schemaRegistryService.deleteSchemaSubject(clusterName, subjectName)));
|
return schemaRegistryService.deleteSchemaSubject(clusterName, subjectName)
|
||||||
|
.onErrorReturn(ResponseEntity.notFound().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<ResponseEntity<SubjectSchema>> createNewSubjectSchema(String clusterName, String subjectName, @Valid Mono<NewSchemaSubject> newSchemaSubject, ServerWebExchange exchange) {
|
public Mono<ResponseEntity<SchemaSubject>> createNewSchema(String clusterName, String schemaName,
|
||||||
return schemaRegistryService.createNewSubject(clusterName, subjectName, newSchemaSubject);
|
@Valid Mono<NewSchemaSubject> newSchemaSubject,
|
||||||
|
ServerWebExchange exchange) {
|
||||||
|
return schemaRegistryService.createNewSubject(clusterName, schemaName, newSchemaSubject)
|
||||||
|
.onErrorReturn(ResponseEntity.notFound().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -335,12 +335,12 @@ paths:
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/ConsumerGroup'
|
$ref: '#/components/schemas/ConsumerGroup'
|
||||||
|
|
||||||
/api/clusters/{clusterName}/schema/subjects:
|
/api/clusters/{clusterName}/schemas:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
- /api/clusters
|
- /api/clusters
|
||||||
summary: get all subjects from schema registry
|
summary: get all schemas from Schema Registry service
|
||||||
operationId: getSchemaSubjects
|
operationId: getSchemas
|
||||||
parameters:
|
parameters:
|
||||||
- name: clusterName
|
- name: clusterName
|
||||||
in: path
|
in: path
|
||||||
|
@ -357,19 +357,19 @@ paths:
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
/api/clusters/{clusterName}/schema/subjects/{subjectName}:
|
/api/clusters/{clusterName}/schemas/{schemaName}:
|
||||||
delete:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- /api/clusters
|
- /api/clusters
|
||||||
summary: delete subject from schema registry
|
summary: delete schema from Schema Registry service
|
||||||
operationId: deleteSchemaSubject
|
operationId: deleteSchema
|
||||||
parameters:
|
parameters:
|
||||||
- name: clusterName
|
- name: clusterName
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
- name: subjectName
|
- name: schemaName
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
|
@ -377,24 +377,22 @@ paths:
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: OK
|
description: OK
|
||||||
content:
|
404:
|
||||||
application/json:
|
description: Not found
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
|
|
||||||
/api/clusters/{clusterName}/schema/subjects/{subjectName}/versions:
|
/api/clusters/{clusterName}/schemas/{schemaName}/versions:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
- /api/clusters
|
- /api/clusters
|
||||||
summary: get subject versions from schema registry
|
summary: get all version of schema from Schema Registry service
|
||||||
operationId: getSchemaSubjectVersions
|
operationId: getSchemaVersions
|
||||||
parameters:
|
parameters:
|
||||||
- name: clusterName
|
- name: clusterName
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
- name: subjectName
|
- name: schemaName
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
|
@ -412,14 +410,14 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- /api/clusters
|
- /api/clusters
|
||||||
summary: create a new subject schema
|
summary: create a new subject schema
|
||||||
operationId: createNewSubjectSchema
|
operationId: createNewSchema
|
||||||
parameters:
|
parameters:
|
||||||
- name: clusterName
|
- name: clusterName
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
- name: subjectName
|
- name: schemaName
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
|
@ -435,21 +433,21 @@ paths:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/SubjectSchema'
|
$ref: '#/components/schemas/SchemaSubject'
|
||||||
|
|
||||||
/api/clusters/{clusterName}/schema/subjects/{subjectName}/versions/{version}:
|
/api/clusters/{clusterName}/schemas/{schemaName}/versions/{version}:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
- /api/clusters
|
- /api/clusters
|
||||||
summary: get schema of subject by version from schema registry
|
summary: get schema by version from Schema Registry service
|
||||||
operationId: getSchemaSubjectByVersion
|
operationId: getSchemaByVersion
|
||||||
parameters:
|
parameters:
|
||||||
- name: clusterName
|
- name: clusterName
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
- name: subjectName
|
- name: schemaName
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
|
@ -467,7 +465,7 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/SubjectSchema'
|
$ref: '#/components/schemas/SchemaSubject'
|
||||||
delete:
|
delete:
|
||||||
tags:
|
tags:
|
||||||
- /api/clusters
|
- /api/clusters
|
||||||
|
@ -479,7 +477,7 @@ paths:
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
- name: subjectName
|
- name: schemaName
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
|
@ -490,18 +488,10 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
responses:
|
responses:
|
||||||
204:
|
200:
|
||||||
description: Deleted
|
description: OK
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
404:
|
404:
|
||||||
description: Not found
|
description: Not found
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: object
|
|
||||||
|
|
||||||
components:
|
components:
|
||||||
schemas:
|
schemas:
|
||||||
|
@ -827,7 +817,7 @@ components:
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
type: number
|
type: number
|
||||||
|
|
||||||
SubjectSchema:
|
SchemaSubject:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
subject:
|
subject:
|
||||||
|
|
Loading…
Add table
Reference in a new issue