From 7125ec37c0833555e43d563da87cf0c2ce86cd20 Mon Sep 17 00:00:00 2001 From: jfaulkner Date: Fri, 24 Nov 2023 16:17:07 +0000 Subject: [PATCH 1/3] chore: Update dependencies --- CHANGELOG.md | 11 + cli/README.md | 80 ---- cli/pom.xml | 153 ------- .../streamregistry/cli/Cli.java | 36 -- .../streamregistry/cli/action/Action.java | 27 -- .../cli/action/EventSenderAction.java | 40 -- .../cli/action/GraphQLEventSenderAction.java | 49 --- .../streamregistry/cli/command/Apply.java | 166 -------- .../cli/command/delete/Delete.java | 230 ---------- .../cli/command/delete/EntityClient.java | 204 --------- .../cli/command/delete/EntityDeleter.java | 72 ---- .../cli/command/delete/Formatter.java | 216 ---------- .../cli/command/delete/KeyConverter.java | 111 ----- .../delete/StreamAndSchemaDiscoverer.java | 80 ---- .../cli/option/EntityOptions.java | 161 ------- .../cli/option/ObjectNodeConverter.java | 30 -- .../cli/option/TagConverter.java | 28 -- cli/src/main/resources/client.graphql | 80 ---- cli/src/main/resources/logback.xml | 32 -- .../streamregistry/cli/CliTest.java | 52 --- .../cli/action/EventSenderActionTest.java | 88 ---- .../streamregistry/cli/command/ApplyTest.java | 193 --------- .../cli/command/delete/DeleteTest.java | 393 ------------------ .../cli/command/delete/EntityDeleterTest.java | 59 --- .../delete/StreamAndSchemaDiscovererTest.java | 83 ---- .../cli/command/delete/StringPrintStream.java | 43 -- .../core/services/ProcessBindingService.java | 34 +- .../services/ProcessBindingServiceTest.java | 40 +- graphql/api/pom.xml | 4 - .../streamregistry/graphql/StateHelper.java | 6 +- it/pom.xml | 1 - pom.xml | 29 +- state/graphql-sender/pom.xml | 1 - 33 files changed, 72 insertions(+), 2760 deletions(-) delete mode 100644 cli/README.md delete mode 100644 cli/pom.xml delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/Cli.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/Action.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/EventSenderAction.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/GraphQLEventSenderAction.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/Apply.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/Delete.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityClient.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityDeleter.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/Formatter.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/KeyConverter.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StreamAndSchemaDiscoverer.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/EntityOptions.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/ObjectNodeConverter.java delete mode 100644 cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/TagConverter.java delete mode 100644 cli/src/main/resources/client.graphql delete mode 100644 cli/src/main/resources/logback.xml delete mode 100644 cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/CliTest.java delete mode 100644 cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/action/EventSenderActionTest.java delete mode 100644 cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/ApplyTest.java delete mode 100644 cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/DeleteTest.java delete mode 100644 cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityDeleterTest.java delete mode 100644 cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StreamAndSchemaDiscovererTest.java delete mode 100644 cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StringPrintStream.java diff --git a/CHANGELOG.md b/CHANGELOG.md index e4ef84828..9fa273779 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [unreleased] +### Changed +- Removed the `cli` module. It is no longer recommended to directly interact with the underlying Kafka topic (and hasn't been since cascading deletes were introduced). + +### Updated +- Updated spring-boot from 3.1.5 to 3.1.6 +- Updated snakeyaml from 1.3.3 to 2.0.0 (Spring supports both versions, newest schema registry client already uses 2.0.0) +- Updated kotlin from 1.7.10 to 1.8.22 +- Updated schema-registry-client from 7.4.0 to 7.5.2 +- Updated commons-text from 1.9 to 1.10.0 + ## [2.0.2] 2023-11-06 ### Fixed - `DefaultEntityViewUpdater` to handle receiving double delete events correctly. diff --git a/cli/README.md b/cli/README.md deleted file mode 100644 index 11c03575f..000000000 --- a/cli/README.md +++ /dev/null @@ -1,80 +0,0 @@ - -# streamctl - -## Warning -This is a low level tool that bypasses Stream Registry model validation and constraints. Use with extreme caution. Breaking the internal state has the potential for prevent all agent and registry processing. Some considerations: - -### Triple check what you are deleting -* Check - * Target environemnt (Stream Registry URL) - * Entity key - -### Do NOT create orphans -This is a sure way to make state inconsistent. Do not delete parent entities without also deleting their children. - -* **Delete a `Schema`:** - * also delete in `ConsumerBindings`, `Consumers`, `ProducerBindings`, `Producers`, `StreamBindings`, `Stream` -* **Delete a `Stream`:** - * also delete in `ConsumerBindings`, `Consumers`, `ProducerBindings`, `Producers`, `StreamBindings` - * also delete `Schema` after if no longer needed -* **Delete a `StreamBinding`:** - * also delete `ConsumerBindings`, `ProducerBindings` -* **Delete a `Consumer`:** - * also delete `ConsumerBinding` -* **Delete a `Producer`:** - * also delete `ProducerBinding` - -Determine children by querying the target entities graph using the GraphQL endpoint. - -**BEWARE OF AGENTS** Agents create bindings from other entities. If you delete a binding, it may be rapdidly recreated by an agent from the parent entity. If this is a problem, delete the parent first, but don't forget to delete the children. - -## Example Usage - -Use help to see all available commands and options: - -```shell script -java -jar cli/target/stream-registry-cli-*-shaded.jar --help -``` - -Delete a domain: - -```shell script -java -jar cli/target/stream-registry-cli-*-shaded.jar \ - delete domain \ - --bootstrapServers=kafka:9092 \ - --topic=_streamregistry \ - --schemaRegistryUrl=http://schema-registry \ - --domain=my_domain -``` - -Delete a streamBinding status: - -```shell script -java -jar cli/target/stream-registry-cli-*-shaded.jar \ - delete streamBinding \ - --bootstrapServers=kafka:9092 \ - --topic=_streamregistry \ - --schemaRegistryUrl=http://schema-registry \ - --domain=my_domain \ - --stream=my_stream \ - --version=1 \ - --zone=my_zone \ - --infrastructure=my_infrastructure \ - --statusName=agentStatus -``` - -Delete a stream and all child entities: - -```shell script -java -jar cli/target/stream-registry-cli-*-shaded.jar \ - delete stream \ - --streamRegistryUrl=http://stream-registry/graphql \ - --bootstrapServers=kafka:9092 \ - --topic=_streamregistry \ - --schemaRegistryUrl=http://schema-registry \ - --domain=my_domain \ - --stream=my_stream \ - --version=1 \ - --cascade \ - --dryRun -``` diff --git a/cli/pom.xml b/cli/pom.xml deleted file mode 100644 index 96cd14f38..000000000 --- a/cli/pom.xml +++ /dev/null @@ -1,153 +0,0 @@ - - - 4.0.0 - - - com.expediagroup.streamplatform - stream-registry - 2.0.3-SNAPSHOT - - - stream-registry-cli - - - 4.4.0 - ${project.build.directory}/graphql-schema/schema.json - com.expediagroup.streamplatform.streamregistry.cli.graphql - - - - - com.expediagroup.streamplatform - stream-registry-state-graphql-sender - ${project.version} - - - com.expediagroup.streamplatform - stream-registry-state-kafka-sender - ${project.version} - - - - ch.qos.logback - logback-classic - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - - - com.google.guava - guava - - - info.picocli - picocli - ${picocli.version} - - - org.projectlombok - lombok - provided - - - - junit - junit - test - - - org.hamcrest - hamcrest-core - test - - - org.mockito - mockito-core - test - - - - - - - com.expediagroup.streamplatform - stream-registry-graphql-maven-plugin - ${project.version} - - - - generate - - generate-sources - - stream-registry.graphql - ${introspectionFile} - - - - - - com.expediagroup.streamplatform - stream-registry-graphql-api - ${project.version} - - - - - com.github.sparow199 - apollo-client-maven-plugin - 3.3.1 - - - graphql-generate-sources - - generate - - generate-sources - - ${project.basedir}/src/main/resources - ${project.build.directory}/generated-sources/graphql-client - ${introspectionFile} - ${clientPackage} - - com.fasterxml.jackson.databind.node.ObjectNode - - true - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - com.expediagroup.streamplatform.streamregistry.cli.Cli - - - true - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - ${clientPackage} - - - - - - diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/Cli.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/Cli.java deleted file mode 100644 index b43912d14..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/Cli.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli; - -import picocli.CommandLine; -import picocli.CommandLine.Command; - -import com.expediagroup.streamplatform.streamregistry.cli.command.Apply; -import com.expediagroup.streamplatform.streamregistry.cli.command.delete.Delete; - -@Command( - name = "streamctl", - subcommands = { - Apply.class, - Delete.class - }, - mixinStandardHelpOptions = true -) -public class Cli { - public static void main(String[] args) { - System.exit(new CommandLine(new Cli()).execute(args)); - } -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/Action.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/Action.java deleted file mode 100644 index 663f9d528..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/Action.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.action; - -import java.io.PrintStream; - -public interface Action extends Runnable { - @Override - default void run() { - run(System.out, System.err); - } - - void run(PrintStream out, PrintStream err); -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/EventSenderAction.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/EventSenderAction.java deleted file mode 100644 index 31a0ad9f9..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/EventSenderAction.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.action; - -import java.io.PrintStream; -import java.util.List; - -import com.expediagroup.streamplatform.streamregistry.state.EventSender; -import com.expediagroup.streamplatform.streamregistry.state.model.event.Event; - -public interface EventSenderAction extends Action { - @Override - default void run(PrintStream out, PrintStream err) { - try (EventSender sender = sender()) { - events().forEach(event -> { - sender.send(event).join(); - out.printf("Sent: %s%n", event); - }); - } catch (Exception e) { - e.printStackTrace(err); - } - } - - EventSender sender(); - - List> events(); -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/GraphQLEventSenderAction.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/GraphQLEventSenderAction.java deleted file mode 100644 index a7e3bedc6..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/action/GraphQLEventSenderAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.action; - -import lombok.Getter; - -import com.apollographql.apollo.ApolloClient; - -import picocli.CommandLine.Option; - -import com.expediagroup.streamplatform.streamregistry.state.EventSender; -import com.expediagroup.streamplatform.streamregistry.state.graphql.Credentials; -import com.expediagroup.streamplatform.streamregistry.state.graphql.DefaultApolloClientFactory; -import com.expediagroup.streamplatform.streamregistry.state.graphql.GraphQLEventSender; - -public abstract class GraphQLEventSenderAction implements EventSenderAction { - @Option(names = "--streamRegistryUrl", required = true) - @Getter String streamRegistryUrl; - - @Option(names = "--streamRegistryUsername", required = false) - @Getter String streamRegistryUsername; - - @Option(names = "--streamRegistryPassword", required = false) - @Getter String streamRegistryPassword; - - @Override - public EventSender sender() { - ApolloClient client; - if(streamRegistryUsername != null && streamRegistryPassword != null) { - client = new DefaultApolloClientFactory(streamRegistryUrl, new Credentials(streamRegistryUsername, streamRegistryPassword)).create(); - } else { - client = new DefaultApolloClientFactory(streamRegistryUrl).create(); - } - return new GraphQLEventSender(client); - } -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/Apply.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/Apply.java deleted file mode 100644 index 67cd958d6..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/Apply.java +++ /dev/null @@ -1,166 +0,0 @@ -/** - * Copyright (C) 2018-2021 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command; - -import static com.expediagroup.streamplatform.streamregistry.state.model.event.Event.specification; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import lombok.Getter; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import picocli.CommandLine.Command; -import picocli.CommandLine.Mixin; -import picocli.CommandLine.Option; - -import com.expediagroup.streamplatform.streamregistry.cli.action.GraphQLEventSenderAction; -import com.expediagroup.streamplatform.streamregistry.cli.option.EntityOptions; -import com.expediagroup.streamplatform.streamregistry.cli.option.ObjectNodeConverter; -import com.expediagroup.streamplatform.streamregistry.cli.option.TagConverter; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.DomainKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.InfrastructureKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.Key; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.SchemaKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ZoneKey; -import com.expediagroup.streamplatform.streamregistry.state.model.event.Event; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.DefaultSpecification; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.Principal; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.Specification; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.StreamSpecification; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.Tag; - -@Command(name = "apply", subcommands = { - Apply.Domain.class, - Apply.Schema.class, - Apply.Stream.class, - Apply.Zone.class, - Apply.Infrastructure.class, - Apply.Producer.class, - Apply.Consumer.class, - Apply.StreamBinding.class, - Apply.ProducerBinding.class, - Apply.ConsumerBinding.class -}) -public class Apply { - static abstract class Base, S extends Specification> extends GraphQLEventSenderAction { - static final ObjectMapper mapper = new ObjectMapper(); - - @Option(names = "--description", required = true) - protected String description; - @Option(names = "--tag", converter = TagConverter.class) - protected List tags = Collections.emptyList(); - @Option(names = "--type", required = true) - protected String type; - @Option(names = "--configuration", required = true, converter = ObjectNodeConverter.class) - protected ObjectNode configuration; - @Option(names = "--security", converter = ObjectNodeConverter.class) - protected ObjectNode security = mapper.createObjectNode(); - @Option(names = "--function", defaultValue = "") - protected String function; - - @Override - public List> events() { - return Collections.singletonList(specification(getEntityOptions().key(), getSpecification())); - } - - public Map> convertSecurityMap(ObjectNode security) { - return mapper.convertValue(security, new TypeReference>>(){}) - .entrySet().stream() - .collect(Collectors.toMap( - Map.Entry::getKey, - entry -> entry.getValue().stream().map(Principal::new).collect(Collectors.toList()) - )); - } - - protected abstract EntityOptions getEntityOptions(); - - protected abstract S getSpecification(); - } - - static abstract class Default> extends Base { - @Override - protected DefaultSpecification getSpecification() { - return new DefaultSpecification(description, tags, type, configuration, convertSecurityMap(security), function); - } - } - - @Command(name = "domain") - static class Domain extends Default { - @Mixin @Getter EntityOptions.Domain entityOptions; - } - - @Command(name = "schema") - static class Schema extends Default { - @Mixin @Getter EntityOptions.Schema entityOptions; - } - - @Command(name = "stream") - static class Stream extends Base { - @Mixin @Getter EntityOptions.ApplyStream entityOptions; - - @Override - protected StreamSpecification getSpecification() { - return new StreamSpecification(description, tags, type, configuration, convertSecurityMap(security), function, entityOptions.schemaKey()); - } - } - - @Command(name = "zone") - static class Zone extends Default { - @Mixin @Getter EntityOptions.Zone entityOptions; - } - - @Command(name = "infrastructure") - static class Infrastructure extends Default { - @Mixin @Getter EntityOptions.Infrastructure entityOptions; - } - - @Command(name = "producer") - static class Producer extends Default { - @Mixin @Getter EntityOptions.Producer entityOptions; - } - - @Command(name = "consumer") - static class Consumer extends Default { - @Mixin @Getter EntityOptions.Consumer entityOptions; - } - - @Command(name = "streamBinding") - static class StreamBinding extends Default { - @Mixin @Getter EntityOptions.StreamBinding entityOptions; - } - - @Command(name = "producerBinding") - static class ProducerBinding extends Default { - @Mixin @Getter EntityOptions.ProducerBinding entityOptions; - } - - @Command(name = "consumerBinding") - static class ConsumerBinding extends Default { - @Mixin @Getter EntityOptions.ConsumerBinding entityOptions; - } -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/Delete.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/Delete.java deleted file mode 100644 index 440f9ca44..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/Delete.java +++ /dev/null @@ -1,230 +0,0 @@ -/** - * Copyright (C) 2018-2021 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command.delete; - -import static java.util.Collections.unmodifiableList; -import static java.util.stream.Collectors.toSet; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import lombok.SneakyThrows; -import lombok.val; -import picocli.CommandLine.Command; -import picocli.CommandLine.Mixin; -import picocli.CommandLine.Option; - -import com.expediagroup.streamplatform.streamregistry.cli.action.Action; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.Key; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.SchemaKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamKey; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.Specification; - -@Command(name = "delete", subcommands = { - Delete.Domain.class, - Delete.Schema.class, - Delete.Stream.class, - Delete.Zone.class, - Delete.Infrastructure.class, - Delete.Producer.class, - Delete.Consumer.class, - Delete.StreamBinding.class, - Delete.ProducerBinding.class, - Delete.ConsumerBinding.class -}) -public class Delete { - static abstract class Base implements Action { - private final Formatter formatter = new Formatter(); - @Mixin EntityClient.Factory clientFactory; - @Mixin EntityDeleter.Factory deleterFactory; - @Option(names = "--dryRun") boolean dryRun; - - @SneakyThrows - @Override - public void run(PrintStream out, PrintStream err) { - val client = clientFactory.create(); - try (val deleter = deleterFactory.create()) { - run(out, err, client, deleter); - } - } - - void run(PrintStream out, PrintStream err, EntityClient client, EntityDeleter deleter) { - List> entities = findEntities(client); - if (entities.isEmpty()) { - err.println("No entities found!"); - return; - } - java.util.function.Consumer> report = k -> out.println(formatter.format(k)); - if (dryRun) { - entities.forEach(report); - } else { - entities.forEach(report.andThen(deleter::delete)); - } - } - - abstract List> findEntities(EntityClient client); - } - - @Command(name = "domain") - public static class Domain extends Base { - @Option(names = "--domain", required = true) private String domain; - - @Override - List> findEntities(EntityClient client) { - return unmodifiableList(client.getDomainKeys(domain)); - } - } - - @Command(name = "schema") - static class Schema extends Base { - @Option(names = "--domain", required = true) private String domain; - @Option(names = "--schema", required = true) private String schema; - - @Override - List> findEntities(EntityClient client) { - return unmodifiableList(client.getSchemaKeys(domain, schema)); - } - } - - @Command(name = "stream") - static class Stream extends Base { - @Option(names = "--domain", required = true) private String domain; - @Option(names = "--stream", required = true) private String stream; - @Option(names = "--version", required = true) private int version; - @Option(names = "--cascade") private boolean cascade; - - @Override - List> findEntities(EntityClient client) { - if (cascade) { - List> result = new ArrayList<>(); - result.addAll(client.getConsumerBindingKeys(domain, stream, version, null, null, null)); - result.addAll(client.getConsumerKeys(domain, stream, version, null, null)); - result.addAll(client.getProducerBindingKeys(domain, stream, version, null, null, null)); - result.addAll(client.getProducerKeys(domain, stream, version, null, null)); - result.addAll(client.getStreamBindingKeys(domain, stream, version, null, null)); - StreamAndSchemaDiscoverer discoverer = new StreamAndSchemaDiscoverer(client); - Map> streams = discoverer.discover(domain, stream, version); - result.addAll(streams.keySet()); - - result.addAll( - streams.values().stream() - .filter(Optional::isPresent) - .map(Optional::get) - .collect(toSet()) - ); - return unmodifiableList(result); - } - return unmodifiableList(new ArrayList<>(client.getStreamKeyWithSchemaKeys(domain, stream, version, null, null) - .keySet())); - } - } - - @Command(name = "zone") - static class Zone extends Base { - @Option(names = "--zone", required = true) private String zone; - - @Override - List> findEntities(EntityClient client) { - return unmodifiableList(client.getZoneKeys(zone)); - } - } - - @Command(name = "infrastructure") - static class Infrastructure extends Base { - @Option(names = "--zone", required = true) private String zone; - @Option(names = "--infrastructure", required = true) private String infrastructure; - - @Override - List> findEntities(EntityClient client) { - return unmodifiableList(client.getInfrastructureKeys(zone, infrastructure)); - } - } - - @Command(name = "producer") - static class Producer extends Base { - @Option(names = "--domain", required = true) private String domain; - @Option(names = "--stream", required = true) private String stream; - @Option(names = "--version", required = true) private int version; - @Option(names = "--zone", required = true) private String zone; - @Option(names = "--producer", required = true) private String producer; - - @Override - List> findEntities(EntityClient client) { - return unmodifiableList(client.getProducerKeys(domain, stream, version, zone, producer)); - } - } - - @Command(name = "consumer") - static class Consumer extends Base { - @Option(names = "--domain", required = true) private String domain; - @Option(names = "--stream", required = true) private String stream; - @Option(names = "--version", required = true) private int version; - @Option(names = "--zone", required = true) private String zone; - @Option(names = "--consumer", required = true) private String consumer; - - @Override - List> findEntities(EntityClient client) { - return unmodifiableList(client.getConsumerKeys(domain, stream, version, zone, consumer)); - } - } - - @Command(name = "streamBinding") - static class StreamBinding extends Base { - @Option(names = "--domain", required = true) private String domain; - @Option(names = "--stream", required = true) private String stream; - @Option(names = "--version", required = true) private int version; - @Option(names = "--zone", required = true) private String zone; - @Option(names = "--infrastructure", required = true) private String infrastructure; - - @Override - List> findEntities(EntityClient client) { - return unmodifiableList(client.getStreamBindingKeys(domain, stream, version, zone, infrastructure)); - } - } - - @Command(name = "producerBinding") - static class ProducerBinding extends Base { - @Option(names = "--domain", required = true) private String domain; - @Option(names = "--stream", required = true) private String stream; - @Option(names = "--version", required = true) private int version; - @Option(names = "--zone", required = true) private String zone; - @Option(names = "--infrastructure", required = true) private String infrastructure; - @Option(names = "--producer", required = true) private String producer; - - @Override - List> findEntities(EntityClient client) { - return unmodifiableList(client.getProducerBindingKeys(domain, stream, version, zone, infrastructure, producer)); - } - } - - @Command(name = "consumerBinding") - static class ConsumerBinding extends Base { - @Option(names = "--domain", required = true) private String domain; - @Option(names = "--stream", required = true) private String stream; - @Option(names = "--version", required = true) private int version; - @Option(names = "--zone", required = true) private String zone; - @Option(names = "--infrastructure", required = true) private String infrastructure; - @Option(names = "--consumer", required = true) private String consumer; - - @Override - List> findEntities(EntityClient client) { - return unmodifiableList(client.getConsumerBindingKeys(domain, stream, version, zone, infrastructure, consumer)); - } - } -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityClient.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityClient.java deleted file mode 100644 index 2a96a276c..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityClient.java +++ /dev/null @@ -1,204 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command.delete; - -import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toMap; - -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import lombok.RequiredArgsConstructor; - -import com.apollographql.apollo.ApolloClient; -import com.apollographql.apollo.api.Operation; -import com.apollographql.apollo.api.Query; - -import picocli.CommandLine.Option; - -import com.expediagroup.streamplatform.streamregistry.cli.graphql.ConsumerBindingQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.ConsumerQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.DomainQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.InfrastructureQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.ProducerBindingQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.ProducerQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.SchemaQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.StreamBindingQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.StreamQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.ZoneQuery; -import com.expediagroup.streamplatform.streamregistry.state.graphql.ApolloExecutor; -import com.expediagroup.streamplatform.streamregistry.state.graphql.Credentials; -import com.expediagroup.streamplatform.streamregistry.state.graphql.DefaultApolloClientFactory; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.DomainKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.InfrastructureKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.SchemaKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ZoneKey; - -@RequiredArgsConstructor -class EntityClient { - private final ApolloExecutor executor; - private final KeyConverter converter; - - List getDomainKeys(String domain) { - return execute( - DomainQuery.builder() - .domain(domain) - .build()) - .getDomain().getByQuery().stream() - .map(x -> converter.domainKey(x.getKey())).collect(toList()); - } - - List getSchemaKeys(String domain, String schema) { - return execute( - SchemaQuery.builder() - .domain(domain) - .schema(schema) - .build()) - .getSchema().getByQuery().stream() - .map(x -> converter.schemaKey(x.getKey())).collect(toList()); - } - - Map getStreamKeyWithSchemaKeys(String domain, String stream, Integer version, String schemaDomain, String schema) { - return execute( - StreamQuery.builder() - .domain(domain) - .stream(stream) - .version(version) - .schemaDomain(schemaDomain) - .schema(schema) - .build()) - .getStream().getByQuery().stream() - .collect(toMap( - x -> converter.streamKey(x.getKey()), - x -> converter.schemaKey(x.getSchema().getKey()) - )); - } - - List getZoneKeys(String zone) { - return execute( - ZoneQuery.builder() - .zone(zone) - .build()) - .getZone().getByQuery().stream() - .map(x -> converter.zoneKey(x.getKey())).collect(toList()); - } - - List getInfrastructureKeys(String zone, String infrastructure) { - return execute( - InfrastructureQuery.builder() - .zone(zone) - .infrastructure(infrastructure) - .build()) - .getInfrastructure().getByQuery().stream() - .map(x -> converter.infrastructureKey(x.getKey())).collect(toList()); - } - - List getProducerKeys(String domain, String stream, int version, String zone, String producer) { - return execute( - ProducerQuery.builder() - .domain(domain) - .stream(stream) - .version(version) - .zone(zone) - .producer(producer) - .build()) - .getProducer().getByQuery().stream() - .map(x -> converter.producerKey(x.getKey())).collect(toList()); - } - - List getConsumerKeys(String domain, String stream, int version, String zone, String consumer) { - return execute( - ConsumerQuery.builder() - .domain(domain) - .stream(stream) - .version(version) - .zone(zone) - .consumer(consumer) - .build()) - .getConsumer().getByQuery().stream() - .map(x -> converter.consumerKey(x.getKey())).collect(toList()); - } - - List getProducerBindingKeys(String domain, String stream, int version, String zone, String infrastructure, String producer) { - return execute( - ProducerBindingQuery.builder() - .domain(domain) - .stream(stream) - .version(version) - .zone(zone) - .infrastructure(infrastructure) - .producer(producer) - .build()) - .getProducerBinding().getByQuery().stream() - .map(x -> converter.producerBindingKey(x.getKey())).collect(toList()); - } - - List getConsumerBindingKeys(String domain, String stream, int version, String zone, String infrastructure, String consumer) { - return execute( - ConsumerBindingQuery.builder() - .domain(domain) - .stream(stream) - .version(version) - .zone(zone) - .infrastructure(infrastructure) - .consumer(consumer) - .build()) - .getConsumerBinding().getByQuery().stream() - .map(x -> converter.consumerBindingKey(x.getKey())).collect(toList()); - } - - List getStreamBindingKeys(String domain, String stream, int version, String zone, String infrastructure) { - return execute( - StreamBindingQuery.builder() - .domain(domain) - .stream(stream) - .version(version) - .zone(zone) - .infrastructure(infrastructure) - .build()) - .getStreamBinding().getByQuery().stream() - .map(x -> converter.streamBindingKey(x.getKey())).collect(toList()); - } - - private T execute(Query, V> query) { - return executor.execute(query).join().getData().get(); - } - - static class Factory { - @Option(names = "--streamRegistryUrl", required = true) String streamRegistryUrl; - @Option(names = "--streamRegistryUsername", required = false) String streamRegistryUsername; - @Option(names = "--streamRegistryPassword", required = false) String streamRegistryPassword; - - EntityClient create() { - ApolloClient client; - if (streamRegistryUsername != null && streamRegistryPassword != null) { - client = new DefaultApolloClientFactory(streamRegistryUrl, new Credentials(streamRegistryUsername, streamRegistryPassword)).create(); - } else { - client = new DefaultApolloClientFactory(streamRegistryUrl).create(); - } - ApolloExecutor executor = new ApolloExecutor(client); - KeyConverter converter = new KeyConverter(); - return new EntityClient(executor, converter); - } - } -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityDeleter.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityDeleter.java deleted file mode 100644 index 3fb145b7b..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityDeleter.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command.delete; - -import static com.expediagroup.streamplatform.streamregistry.state.model.event.Event.specificationDeletion; -import static com.expediagroup.streamplatform.streamregistry.state.model.event.Event.statusDeletion; - -import java.io.Closeable; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.LinkedBlockingDeque; - -import lombok.RequiredArgsConstructor; -import picocli.CommandLine.Option; - -import com.expediagroup.streamplatform.streamregistry.state.kafka.KafkaEventSender; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.Key; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.Specification; - -@RequiredArgsConstructor -class EntityDeleter implements Closeable { - private final KafkaEventSender sender; - private final BlockingQueue> queue = new LinkedBlockingDeque<>(); - - void delete(Key key) { - queue.add(sender.send(statusDeletion(key, "agentStatus"))); - queue.add(sender.send(specificationDeletion(key))); - } - - @Override - public void close() { - waitForFutures(); - sender.close(); - } - - private void waitForFutures() { - List> futures = new ArrayList<>(); - queue.drainTo(futures); - futures.forEach(CompletableFuture::join); - } - - static class Factory { - @Option(names = "--bootstrapServers", required = true) String bootstrapServers; - @Option(names = "--topic", required = true, defaultValue = "_streamregistry") String topic; - @Option(names = "--schemaRegistryUrl", required = true) String schemaRegistryUrl; - - EntityDeleter create() { - KafkaEventSender.Config config = KafkaEventSender.Config.builder() - .bootstrapServers(bootstrapServers) - .topic(topic) - .schemaRegistryUrl(schemaRegistryUrl) - .build(); - KafkaEventSender sender = new KafkaEventSender(config); - return new EntityDeleter(sender); - } - } -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/Formatter.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/Formatter.java deleted file mode 100644 index f16a61a03..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/Formatter.java +++ /dev/null @@ -1,216 +0,0 @@ -/** - * Copyright (C) 2018-2021 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command.delete; - -import static com.fasterxml.jackson.core.Version.unknownVersion; -import static com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.WRITE_DOC_START_MARKER; - -import java.io.IOException; -import java.util.ArrayList; - -import lombok.SneakyThrows; -import lombok.val; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; - -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.DomainKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.InfrastructureKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.Key; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.SchemaKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ZoneKey; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.Specification; - -public class Formatter { - private static final ObjectMapper mapper = new ObjectMapper(new YAMLFactory().disable(WRITE_DOC_START_MARKER)) - .registerModule(new SimpleModule("keys", unknownVersion(), new ArrayList>() {{ - add(new DomainKeySerializer()); - add(new SchemaKeySerializer()); - add(new StreamKeySerializer()); - add(new ZoneKeySerializer()); - add(new InfrastructureKeySerializer()); - add(new ProducerKeySerializer()); - add(new ConsumerKeySerializer()); - add(new StreamBindingKeySerializer()); - add(new ProducerBindingKeySerializer()); - add(new ConsumerBindingKeySerializer()); - }})); - - @SneakyThrows - public String format(Key key) { - return mapper.writeValueAsString(key); - } - - private static abstract class NestedKeySerializer extends StdSerializer { - private final String name; - - protected NestedKeySerializer(Class kClass, String name) { - super(kClass); - this.name = name; - } - - @Override - public void serialize(K key, JsonGenerator g, SerializerProvider p) throws IOException { - val localStartObject = !g.getOutputContext().inObject(); - if (localStartObject) { - g.writeStartObject(); - g.writeFieldName(name); - g.writeStartObject(); - } - serialize(key, g); - if (localStartObject) { - g.writeEndObject(); - g.writeEndObject(); - } - } - - protected abstract void serialize(K key, JsonGenerator g) throws IOException; - } - - private static class DomainKeySerializer extends NestedKeySerializer { - protected DomainKeySerializer() { - super(DomainKey.class, "domain"); - } - - @Override - public void serialize(DomainKey key, JsonGenerator g) throws IOException { - g.writeStringField("domain", key.getName()); - } - } - - private static class SchemaKeySerializer extends NestedKeySerializer { - protected SchemaKeySerializer() { - super(SchemaKey.class, "schema"); - } - - @Override - public void serialize(SchemaKey key, JsonGenerator g) throws IOException { - g.writeObject(key.getDomainKey()); - g.writeStringField("schema", key.getName()); - } - } - - private static class StreamKeySerializer extends NestedKeySerializer { - protected StreamKeySerializer() { - super(StreamKey.class, "stream"); - } - - @Override - public void serialize(StreamKey key, JsonGenerator g) throws IOException { - g.writeObject(key.getDomainKey()); - g.writeStringField("stream", key.getName()); - g.writeNumberField("version", key.getVersion()); - } - } - - private static class ZoneKeySerializer extends NestedKeySerializer { - protected ZoneKeySerializer() { - super(ZoneKey.class, "zone"); - } - - @Override - public void serialize(ZoneKey key, JsonGenerator g) throws IOException { - g.writeStringField("zone", key.getName()); - } - } - - private static class InfrastructureKeySerializer extends NestedKeySerializer { - protected InfrastructureKeySerializer() { - super(InfrastructureKey.class, "infrastructure"); - } - - @Override - public void serialize(InfrastructureKey key, JsonGenerator g) throws IOException { - g.writeObject(key.getZoneKey()); - g.writeStringField("infrastructure", key.getName()); - } - } - - private static class ProducerKeySerializer extends NestedKeySerializer { - protected ProducerKeySerializer() { - super(ProducerKey.class, "producer"); - } - - @Override - public void serialize(ProducerKey key, JsonGenerator g) throws IOException { - g.writeObject(key.getStreamKey()); - g.writeObject(key.getZoneKey()); - g.writeStringField("producer", key.getName()); - } - } - - private static class ConsumerKeySerializer extends NestedKeySerializer { - protected ConsumerKeySerializer() { - super(ConsumerKey.class, "consumer"); - } - - @Override - public void serialize(ConsumerKey key, JsonGenerator g) throws IOException { - g.writeObject(key.getStreamKey()); - g.writeObject(key.getZoneKey()); - g.writeStringField("consumer", key.getName()); - } - } - - private static class StreamBindingKeySerializer extends NestedKeySerializer { - protected StreamBindingKeySerializer() { - super(StreamBindingKey.class, "streamBinding"); - } - - @Override - public void serialize(StreamBindingKey key, JsonGenerator g) throws IOException { - g.writeObject(key.getStreamKey()); - g.writeObject(key.getInfrastructureKey()); - } - } - - private static class ProducerBindingKeySerializer extends NestedKeySerializer { - protected ProducerBindingKeySerializer() { - super(ProducerBindingKey.class, "producerBinding"); - } - - @Override - public void serialize(ProducerBindingKey key, JsonGenerator g) throws IOException { - g.writeObject(key.getStreamBindingKey().getStreamKey()); - g.writeObject(key.getStreamBindingKey().getInfrastructureKey()); - g.writeStringField("producer", key.getProducerKey().getName()); - } - } - - private static class ConsumerBindingKeySerializer extends NestedKeySerializer { - protected ConsumerBindingKeySerializer() { - super(ConsumerBindingKey.class, "consumerBinding"); - } - - @Override - public void serialize(ConsumerBindingKey key, JsonGenerator g) throws IOException { - g.writeObject(key.getStreamBindingKey().getStreamKey()); - g.writeObject(key.getStreamBindingKey().getInfrastructureKey()); - g.writeStringField("consumer", key.getConsumerKey().getName()); - } - } -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/KeyConverter.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/KeyConverter.java deleted file mode 100644 index 5ea4518d3..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/KeyConverter.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Copyright (C) 2018-2021 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command.delete; - -import lombok.val; - -import com.expediagroup.streamplatform.streamregistry.cli.graphql.ConsumerBindingQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.ConsumerQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.DomainQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.InfrastructureQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.ProducerBindingQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.ProducerQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.SchemaQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.StreamBindingQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.StreamQuery; -import com.expediagroup.streamplatform.streamregistry.cli.graphql.ZoneQuery; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.DomainKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.InfrastructureKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.SchemaKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ZoneKey; - -class KeyConverter { - DomainKey domainKey(DomainQuery.Key key) { - return new DomainKey(key.getName()); - } - - SchemaKey schemaKey(SchemaQuery.Key key) { - val domainKey = new DomainKey(key.getDomain()); - return new SchemaKey(domainKey, key.getName()); - } - - SchemaKey schemaKey(StreamQuery.Key1 key) { - val domainKey = new DomainKey(key.getDomain()); - return new SchemaKey(domainKey, key.getName()); - } - - ZoneKey zoneKey(ZoneQuery.Key key) { - return new ZoneKey(key.getName()); - } - - InfrastructureKey infrastructureKey(InfrastructureQuery.Key key) { - val zoneKey = new ZoneKey(key.getZone()); - return new InfrastructureKey(zoneKey, key.getName()); - } - - StreamKey streamKey(StreamQuery.Key key) { - val domainKey = new DomainKey(key.getDomain()); - return new StreamKey(domainKey, key.getName(), key.getVersion()); - } - - ProducerKey producerKey(ProducerQuery.Key key) { - val domainKey = new DomainKey(key.getStreamDomain()); - val streamKey = new StreamKey(domainKey, key.getStreamName(), key.getStreamVersion()); - val zoneKey = new ZoneKey(key.getZone()); - return new ProducerKey(streamKey, zoneKey, key.getName()); - } - - ConsumerKey consumerKey(ConsumerQuery.Key key) { - val domainKey = new DomainKey(key.getStreamDomain()); - val streamKey = new StreamKey(domainKey, key.getStreamName(), key.getStreamVersion()); - val zoneKey = new ZoneKey(key.getZone()); - return new ConsumerKey(streamKey, zoneKey, key.getName()); - } - - ProducerBindingKey producerBindingKey(ProducerBindingQuery.Key key) { - val domainKey = new DomainKey(key.getStreamDomain()); - val streamKey = new StreamKey(domainKey, key.getStreamName(), key.getStreamVersion()); - val zoneKey = new ZoneKey(key.getInfrastructureZone()); - val producerKey = new ProducerKey(streamKey, zoneKey, key.getProducerName()); - val infrastructureKey = new InfrastructureKey(zoneKey, key.getInfrastructureName()); - val streamBindingKey = new StreamBindingKey(streamKey, infrastructureKey); - return new ProducerBindingKey(producerKey, streamBindingKey); - } - - ConsumerBindingKey consumerBindingKey(ConsumerBindingQuery.Key key) { - val domainKey = new DomainKey(key.getStreamDomain()); - val streamKey = new StreamKey(domainKey, key.getStreamName(), key.getStreamVersion()); - val zoneKey = new ZoneKey(key.getInfrastructureZone()); - val consumerKey = new ConsumerKey(streamKey, zoneKey, key.getConsumerName()); - val infrastructureKey = new InfrastructureKey(zoneKey, key.getInfrastructureName()); - val streamBindingKey = new StreamBindingKey(streamKey, infrastructureKey); - return new ConsumerBindingKey(consumerKey, streamBindingKey); - } - - StreamBindingKey streamBindingKey(StreamBindingQuery.Key key) { - val domainKey = new DomainKey(key.getStreamDomain()); - val streamKey = new StreamKey(domainKey, key.getStreamName(), key.getStreamVersion()); - val zoneKey = new ZoneKey(key.getInfrastructureZone()); - val infrastructureKey = new InfrastructureKey(zoneKey, key.getInfrastructureName()); - return new StreamBindingKey(streamKey, infrastructureKey); - } -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StreamAndSchemaDiscoverer.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StreamAndSchemaDiscoverer.java deleted file mode 100644 index d88ba82d1..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StreamAndSchemaDiscoverer.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command.delete; - -import static java.util.stream.Collectors.groupingBy; -import static java.util.stream.Collectors.mapping; -import static java.util.stream.Collectors.toMap; -import static java.util.stream.Collectors.toSet; -import static lombok.AccessLevel.PACKAGE; - -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; - -import lombok.RequiredArgsConstructor; - -import com.google.common.collect.Sets; - -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.SchemaKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamKey; - -@RequiredArgsConstructor(access = PACKAGE) -class StreamAndSchemaDiscoverer { - private final EntityClient client; - - Map> discover(String domain, String stream, Integer version) { - Map candidates = client.getStreamKeyWithSchemaKeys(domain, stream, version, null, null); - Map> groupedCandidates = groupBySchema(candidates); - - Map> groupedAll = groupedAll(groupedCandidates.keySet()); - - Set deletableSchemas = groupedCandidates.entrySet().stream() - .filter(groupedCandidate -> canDeleteSchema(groupedAll, groupedCandidate)) - .map(Entry::getKey) - .collect(toSet()); - - return candidates.entrySet().stream() - .collect(toMap( - Entry::getKey, - e -> Optional.of(e.getValue()).filter(deletableSchemas::contains) - )); - } - - private Map> groupedAll(Set candidateSchemas) { - Map all = candidateSchemas.stream() - .map(x -> client.getStreamKeyWithSchemaKeys(null, null, null, x.getDomainKey().getName(), x.getName())) - .flatMap(x -> x.entrySet().stream()) - .collect(toMap(Entry::getKey, Entry::getValue)); - return groupBySchema(all); - } - - private boolean canDeleteSchema(Map> groupedAll, Entry> groupedCandidate) { - Set candidateStreams = groupedCandidate.getValue(); - Set allStreams = groupedAll.get(groupedCandidate.getKey()); - int remainingStreamsCount = Sets.difference(allStreams, candidateStreams).size(); - return remainingStreamsCount == 0; - } - - private Map> groupBySchema(Map streams) { - return streams.entrySet().stream() - .collect(groupingBy( - Entry::getValue, - mapping(Entry::getKey, toSet()) - )); - } -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/EntityOptions.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/EntityOptions.java deleted file mode 100644 index 1923fbc1e..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/EntityOptions.java +++ /dev/null @@ -1,161 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.option; - -import lombok.Data; -import picocli.CommandLine.Mixin; -import picocli.CommandLine.Option; - -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.DomainKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.InfrastructureKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.Key; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.SchemaKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ZoneKey; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.DefaultSpecification; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.Specification; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.StreamSpecification; - -public interface EntityOptions, S extends Specification> { - K key(); - - @Data - class Domain implements EntityOptions { - @Option(names = "--domain", required = true) private String domain; - - @Override - public DomainKey key() { - return new DomainKey(domain); - } - } - - @Data - class Schema implements EntityOptions { - @Mixin private Domain domain; - @Option(names = "--schema", required = true) private String schema; - - @Override - public SchemaKey key() { - return new SchemaKey(domain.key(), schema); - } - } - - @Data - class Stream implements EntityOptions { - @Mixin Domain domain; - @Option(names = "--stream", required = true) private String stream; - @Option(names = "--version", required = true) private int version; - - @Override - public StreamKey key() { - return new StreamKey(domain.key(), stream, version); - } - } - - @Data - class ApplyStream extends Stream { - @Option(names = "--schemaDomain", required = true) private String schemaDomain; - @Option(names = "--schema", required = true) private String schema; - - public SchemaKey schemaKey() { - return new SchemaKey(new DomainKey(schemaDomain), schema); - } - } - - @Data - class Zone implements EntityOptions { - @Option(names = "--zone", required = true) private String zone; - - @Override - public ZoneKey key() { - return new ZoneKey(zone); - } - } - - @Data - class Infrastructure implements EntityOptions { - @Mixin private Zone zone; - @Option(names = "--infrastructure", required = true) private String infrastructure; - - @Override - public InfrastructureKey key() { - return new InfrastructureKey(zone.key(), infrastructure); - } - } - - @Data - class Producer implements EntityOptions { - @Mixin private Stream stream; - @Mixin private Zone zone; - @Option(names = "--producer", required = true) private String producer; - - @Override - public ProducerKey key() { - return new ProducerKey(stream.key(), zone.key(), producer); - } - } - - @Data - class Consumer implements EntityOptions { - @Mixin private Stream stream; - @Mixin private Zone zone; - @Option(names = "--consumer", required = true) private String consumer; - - public ConsumerKey key() { - return new ConsumerKey(stream.key(), zone.key(), consumer); - } - } - - @Data - class StreamBinding implements EntityOptions { - @Mixin private Stream stream; - @Mixin private Infrastructure infrastructure; - - @Override - public StreamBindingKey key() { - return new StreamBindingKey(stream.key(), infrastructure.key()); - } - } - - @Data - class ProducerBinding implements EntityOptions { - @Mixin private StreamBinding streamBinding; - @Option(names = "--producer", required = true) private String producer; - - @Override - public ProducerBindingKey key() { - StreamBindingKey key = streamBinding.key(); - return new ProducerBindingKey(new ProducerKey(key.getStreamKey(), key.getInfrastructureKey().getZoneKey(), producer), key); - } - } - - @Data - class ConsumerBinding implements EntityOptions { - @Mixin private StreamBinding streamBinding; - @Option(names = "--consumer", required = true) private String consumer; - - @Override - public ConsumerBindingKey key() { - StreamBindingKey key = streamBinding.key(); - return new ConsumerBindingKey(new ConsumerKey(key.getStreamKey(), key.getInfrastructureKey().getZoneKey(), consumer), key); - } - } -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/ObjectNodeConverter.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/ObjectNodeConverter.java deleted file mode 100644 index 613ff864d..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/ObjectNodeConverter.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.option; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import picocli.CommandLine.ITypeConverter; - -public class ObjectNodeConverter implements ITypeConverter { - private final ObjectMapper mapper = new ObjectMapper(); - - @Override - public ObjectNode convert(String value) throws Exception { - return mapper.readValue(value, ObjectNode.class); - } -} diff --git a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/TagConverter.java b/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/TagConverter.java deleted file mode 100644 index f825e11d5..000000000 --- a/cli/src/main/java/com/expediagroup/streamplatform/streamregistry/cli/option/TagConverter.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.option; - -import picocli.CommandLine.ITypeConverter; - -import com.expediagroup.streamplatform.streamregistry.state.model.specification.Tag; - -public class TagConverter implements ITypeConverter { - @Override - public Tag convert(String value) { - String[] split = value.split(":"); - return new Tag(split[0], split[1]); - } -} diff --git a/cli/src/main/resources/client.graphql b/cli/src/main/resources/client.graphql deleted file mode 100644 index d49a602e8..000000000 --- a/cli/src/main/resources/client.graphql +++ /dev/null @@ -1,80 +0,0 @@ -query Domain($domain: String) { - domain { - byQuery(key: {nameRegex: $domain}) { - key { name } - } - } -} - -query Schema($domain: String, $schema: String) { - schema { - byQuery(key: {domainRegex: $domain, nameRegex: $schema}) { - key { domain name } - } - } -} - -query Stream($domain: String, $stream: String, $version: Int, $schemaDomain: String, $schema: String) { - stream { - byQuery(key: {domainRegex: $domain, nameRegex: $stream, version: $version}, schema: {domainRegex: $schemaDomain, nameRegex: $schema}) { - key { domain name version } - schema { key { domain name } } - } - } -} - -query Zone($zone: String) { - zone { - byQuery(key: {nameRegex: $zone}) { - key { name } - } - } -} - -query Infrastructure($zone: String, $infrastructure: String) { - infrastructure { - byQuery(key: {zoneRegex: $zone, nameRegex: $infrastructure}) { - key { zone name } - } - } -} - -query Producer($domain: String, $stream: String, $version: Int, $zone: String, $producer: String) { - producer { - byQuery(key: {streamDomainRegex: $domain, streamNameRegex: $stream, streamVersion: $version, zoneRegex: $zone, nameRegex: $producer}) { - key { streamDomain streamName streamVersion zone name } - } - } -} - -query Consumer($domain: String, $stream: String, $version: Int, $zone: String, $consumer: String) { - consumer { - byQuery(key: {streamDomainRegex: $domain, streamNameRegex: $stream, streamVersion: $version, zoneRegex: $zone, nameRegex: $consumer}) { - key { streamDomain streamName streamVersion zone name } - } - } -} - -query ProducerBinding($domain: String, $stream: String, $version: Int, $zone: String, $infrastructure: String, $producer: String) { - producerBinding { - byQuery(key: {streamDomainRegex: $domain, streamNameRegex: $stream, streamVersion: $version, infrastructureZoneRegex: $zone, infrastructureNameRegex: $infrastructure, producerNameRegex: $producer}) { - key { streamDomain streamName streamVersion infrastructureZone infrastructureName producerName } - } - } -} - -query ConsumerBinding($domain: String, $stream: String, $version: Int, $zone: String, $infrastructure: String, $consumer: String) { - consumerBinding { - byQuery(key: {streamDomainRegex: $domain, streamNameRegex: $stream, streamVersion: $version, infrastructureZoneRegex: $zone, infrastructureNameRegex: $infrastructure, consumerNameRegex: $consumer}) { - key { streamDomain streamName streamVersion infrastructureZone infrastructureName consumerName } - } - } -} - -query StreamBinding($domain: String, $stream: String, $version: Int, $zone: String, $infrastructure: String) { - streamBinding { - byQuery(key: {streamDomainRegex: $domain, streamNameRegex: $stream, streamVersion: $version, infrastructureZoneRegex: $zone, infrastructureNameRegex: $infrastructure}) { - key { streamDomain streamName streamVersion infrastructureZone infrastructureName } - } - } -} diff --git a/cli/src/main/resources/logback.xml b/cli/src/main/resources/logback.xml deleted file mode 100644 index 01893dbe7..000000000 --- a/cli/src/main/resources/logback.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - %d [%thread] %-5level %logger{35} - %msg%n - - - - - - - - - - - diff --git a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/CliTest.java b/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/CliTest.java deleted file mode 100644 index 10882df43..000000000 --- a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/CliTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli; - -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -import picocli.CommandLine; -import picocli.CommandLine.ParseResult; -import picocli.CommandLine.UnmatchedArgumentException; - -import com.expediagroup.streamplatform.streamregistry.cli.command.Apply; -import com.expediagroup.streamplatform.streamregistry.cli.command.delete.Delete; - -public class CliTest { - private final CommandLine underTest = new CommandLine(new Cli()); - - @Test - public void apply() { - ParseResult result = underTest.parseArgs("apply"); - Object object = result.subcommand().commandSpec().userObject(); - assertThat(object, is(instanceOf(Apply.class))); - } - - @Test - public void delete() { - ParseResult result = underTest.parseArgs("delete"); - Object object = result.subcommand().commandSpec().userObject(); - assertThat(object, is(instanceOf(Delete.class))); - } - - @Test(expected = UnmatchedArgumentException.class) - public void unknown() { - underTest.parseArgs("unknown"); - } -} diff --git a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/action/EventSenderActionTest.java b/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/action/EventSenderActionTest.java deleted file mode 100644 index 435dc2d44..000000000 --- a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/action/EventSenderActionTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright (C) 2018-2021 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.action; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doCallRealMethod; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import com.expediagroup.streamplatform.streamregistry.state.EventSender; -import com.expediagroup.streamplatform.streamregistry.state.model.event.Event; - -@RunWith(MockitoJUnitRunner.class) -public class EventSenderActionTest { - @Mock private EventSenderAction underTest; - @Mock private EventSender sender; - @Mock private CompletableFuture future; - @Mock private Event event; - - @Before - public void before() { - when(underTest.sender()).thenReturn(sender); - when(sender.send(any())).thenReturn(future); - when(underTest.events()).thenReturn(Collections.singletonList(event)); - doCallRealMethod().when(underTest).run(any(), any()); - } - - @Test - public void success() { - ByteArrayOutputStream baosOut = new ByteArrayOutputStream(); - PrintStream out = new PrintStream(baosOut); - - ByteArrayOutputStream baosErr = new ByteArrayOutputStream(); - PrintStream err = new PrintStream(baosErr); - - underTest.run(out, err); - - verify(sender).send(event); - verify(future).join(); - - assertThat(baosOut.toString(), is("Sent: event\n")); - assertThat(baosErr.toString(), is("")); - } - - @Test - public void failure() { - doThrow(CompletionException.class).when(future).join(); - - ByteArrayOutputStream baosOut = new ByteArrayOutputStream(); - PrintStream out = new PrintStream(baosOut); - - ByteArrayOutputStream baosErr = new ByteArrayOutputStream(); - PrintStream err = new PrintStream(baosErr); - - underTest.run(out, err); - - assertThat(baosOut.toString(), is("")); - assertThat(baosErr.toString(), is("java.util.concurrent.CompletionException\n")); - } -} diff --git a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/ApplyTest.java b/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/ApplyTest.java deleted file mode 100644 index 67f7e11d3..000000000 --- a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/ApplyTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * Copyright (C) 2018-2021 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command; - -import static com.google.common.collect.ObjectArrays.concat; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import org.junit.Test; - -import picocli.CommandLine; -import picocli.CommandLine.ParseResult; - -import com.expediagroup.streamplatform.streamregistry.cli.action.GraphQLEventSenderAction; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.DomainKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.InfrastructureKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.SchemaKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ZoneKey; -import com.expediagroup.streamplatform.streamregistry.state.model.event.Event; -import com.expediagroup.streamplatform.streamregistry.state.model.event.SpecificationEvent; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.Principal; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.Specification; -import com.expediagroup.streamplatform.streamregistry.state.model.specification.Tag; - -public class ApplyTest { - private final CommandLine underTest = new CommandLine(new Apply()); - - private final String[] graphqlOptions = {"--streamRegistryUrl=streamRegistryUrl", "--streamRegistryUsername=streamRegistryUsername", "--streamRegistryPassword=streamRegistryPassword"}; - private final String[] configurationOptions = {"--description=description", "--tag=a:b", "--tag=c:d", "--type=type", "--configuration={\"e\":\"f\"}", "--security={\"admin\":[\"user1\"],\"creator\":[\"user2\",\"user3\"]}"}; - - private final ObjectMapper mapper = new ObjectMapper(); - private final ObjectNode configuration = mapper.createObjectNode() - .put("e", "f"); - private final Map> security = new HashMap>() {{ - put("admin", Arrays.asList(new Principal("user1"))); - put("creator", Arrays.asList(new Principal("user2"), new Principal("user3"))); - }}; - - private final DomainKey domainKey = new DomainKey("domain"); - private final SchemaKey schemaKey = new SchemaKey(domainKey, "schema"); - private final StreamKey streamKey = new StreamKey(domainKey, "stream", 1); - private final ZoneKey zoneKey = new ZoneKey("zone"); - private final InfrastructureKey infrastructureKey = new InfrastructureKey(zoneKey, "infrastructure"); - private final ProducerKey producerKey = new ProducerKey(streamKey, zoneKey, "producer"); - private final ConsumerKey consumerKey = new ConsumerKey(streamKey, zoneKey, "consumer"); - private final StreamBindingKey streamBindingKey = new StreamBindingKey(streamKey, infrastructureKey); - private final ProducerBindingKey producerBindingKey = new ProducerBindingKey(producerKey, streamBindingKey); - private final ConsumerBindingKey consumerBindingKey = new ConsumerBindingKey(consumerKey, streamBindingKey); - - @Test - public void domain() { - ParseResult result = parseArgs("domain", - "--domain=domain"); - assertEvent(result, domainKey); - } - - @Test - public void schema() { - ParseResult result = parseArgs("schema", - "--domain=domain", "--schema=schema"); - assertEvent(result, schemaKey); - } - - @Test - public void stream() { - ParseResult result = parseArgs("stream", - "--domain=domain", "--stream=stream", "--version=1", - "--schemaDomain=schemaDomain", "--schema=schema"); - assertEvent(result, streamKey); - } - - @Test - public void zone() { - ParseResult result = underTest.parseArgs("zone", - "--streamRegistryUrl=streamRegistryUrl", - "--streamRegistryUsername=streamRegistryUsername", - "--streamRegistryPassword=streamRegistryPassword", - "--description=description", "--tag=a:b", "--tag=c:d", "--type=type", "--configuration={\"e\":\"f\"}", - "--security={\"admin\":[\"user1\"],\"creator\":[\"user2\",\"user3\"]}", - "--zone=zone"); - assertEvent(result, zoneKey); - } - - @Test - public void zone_withoutCredentials() { - ParseResult result = underTest.parseArgs("zone", - "--streamRegistryUrl=streamRegistryUrl", - "--description=description", "--tag=a:b", "--tag=c:d", "--type=type", "--configuration={\"e\":\"f\"}", - "--zone=zone"); - GraphQLEventSenderAction action = (GraphQLEventSenderAction) result.subcommand().commandSpec().userObject(); - List> events = action.events(); - assertThat(events.size(), is(1)); - } - - @Test - public void infrastructure() { - ParseResult result = parseArgs("infrastructure", - "--zone=zone", "--infrastructure=infrastructure"); - assertEvent(result, infrastructureKey); - } - - @Test - public void producer() { - ParseResult result = parseArgs("producer", - "--domain=domain", "--stream=stream", "--version=1", "--zone=zone", "--producer=producer"); - assertEvent(result, producerKey); - } - - @Test - public void consumer() { - ParseResult result = parseArgs("consumer", - "--domain=domain", "--stream=stream", "--version=1", "--zone=zone", "--consumer=consumer"); - assertEvent(result, consumerKey); - } - - @Test - public void streamBinding() { - ParseResult result = parseArgs("streamBinding", - "--domain=domain", "--stream=stream", "--version=1", "--zone=zone", "--infrastructure=infrastructure"); - assertEvent(result, streamBindingKey); - } - - @Test - public void producerBinding() { - ParseResult result = parseArgs("producerBinding", - "--domain=domain", "--stream=stream", "--version=1", "--zone=zone", "--infrastructure=infrastructure", "--producer=producer"); - assertEvent(result, producerBindingKey); - } - - @Test - public void consumerBinding() { - ParseResult result = parseArgs("consumerBinding", - "--domain=domain", "--stream=stream", "--version=1", "--zone=zone", "--infrastructure=infrastructure", "--consumer=consumer"); - assertEvent(result, consumerBindingKey); - } - - private ParseResult parseArgs(String entity, String... args) { - return underTest.parseArgs(concat(concat(concat(entity, graphqlOptions), configurationOptions, String.class), args, String.class)); - } - - private void assertEvent(ParseResult result, Entity.Key key) { - GraphQLEventSenderAction action = (GraphQLEventSenderAction) result.subcommand().commandSpec().userObject(); - assertGraphQLOptions(action); - List> events = action.events(); - assertThat(events.size(), is(1)); - SpecificationEvent event = (SpecificationEvent) events.get(0); - assertThat(event.getKey(), is(key)); - Specification specification = event.getSpecification(); - assertThat(specification.getDescription(), is("description")); - assertThat(specification.getTags(), is(new ArrayList() {{ - add(new Tag("a", "b")); - add(new Tag("c", "d")); - }})); - assertThat(specification.getType(), is("type")); - assertThat(specification.getConfiguration(), is(configuration)); - assertThat(specification.getSecurity(), is(security)); - } - - private void assertGraphQLOptions(GraphQLEventSenderAction action) { - assertThat(action.getStreamRegistryUrl(), is("streamRegistryUrl")); - assertThat(action.getStreamRegistryUsername(), is("streamRegistryUsername")); - assertThat(action.getStreamRegistryPassword(), is("streamRegistryPassword")); - } -} diff --git a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/DeleteTest.java b/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/DeleteTest.java deleted file mode 100644 index 03ff490e6..000000000 --- a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/DeleteTest.java +++ /dev/null @@ -1,393 +0,0 @@ -/** - * Copyright (C) 2018-2021 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command.delete; - -import static com.google.common.collect.ObjectArrays.concat; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; -import static org.mockito.Mockito.when; - -import java.util.Collections; -import java.util.HashMap; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InOrder; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import picocli.CommandLine; -import picocli.CommandLine.ParseResult; - -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ConsumerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.DomainKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.InfrastructureKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ProducerKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.SchemaKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamBindingKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.ZoneKey; - -@RunWith(MockitoJUnitRunner.Silent.class) -public class DeleteTest { - private final CommandLine underTest = new CommandLine(new Delete()); - - private final String[] standardOptions = {"--bootstrapServers=bootstrapServers", "--schemaRegistryUrl=schemaRegistryUrl", "--streamRegistryUrl=streamRegistryUrl", "--streamRegistryUsername=streamRegistryUsername", "--streamRegistryPassword=streamRegistryPassword"}; - - private static final String DOMAIN = "domain"; - private static final String SCHEMA = "schema"; - private static final String STREAM = "stream"; - private static final int VERSION = 1; - private static final String ZONE = "zone"; - private static final String INFRASTRUCTURE = "infrastructure"; - private static final String PRODUCER = "producer"; - private static final String CONSUMER = "consumer"; - private static final String STREAM_BINDING = "streamBinding"; - private static final String PRODUCER_BINDING = "producerBinding"; - private static final String CONSUMER_BINDING = "consumerBinding"; - - private static final String DOMAIN_ARG = "--domain=" + DOMAIN; - private static final String SCHEMA_ARG = "--schema=" + SCHEMA; - private static final String STREAM_ARG = "--stream=" + STREAM; - private static final String VERSION_ARG = "--version=" + VERSION; - private static final String ZONE_ARG = "--zone=" + ZONE; - private static final String INFRASTRUCTURE_ARG = "--infrastructure=" + INFRASTRUCTURE; - private static final String PRODUCER_ARG = "--producer=" + PRODUCER; - private static final String CONSUMER_ARG = "--consumer=" + CONSUMER; - private static final String DRY_RUN_ARG = "--dryRun"; - private static final String CASCADE_ARG = "--cascade"; - - private final DomainKey domainKey = new DomainKey(DOMAIN); - private final SchemaKey schemaKey = new SchemaKey(domainKey, SCHEMA); - private final StreamKey streamKey = new StreamKey(domainKey, STREAM, VERSION); - private final StreamKey streamKey2 = new StreamKey(domainKey, STREAM, 2); - private final ZoneKey zoneKey = new ZoneKey(ZONE); - private final InfrastructureKey infrastructureKey = new InfrastructureKey(zoneKey, INFRASTRUCTURE); - private final ProducerKey producerKey = new ProducerKey(streamKey, zoneKey, PRODUCER); - private final ConsumerKey consumerKey = new ConsumerKey(streamKey, zoneKey, CONSUMER); - private final StreamBindingKey streamBindingKey = new StreamBindingKey(streamKey, infrastructureKey); - private final ProducerBindingKey producerBindingKey = new ProducerBindingKey(producerKey, streamBindingKey); - private final ConsumerBindingKey consumerBindingKey = new ConsumerBindingKey(consumerKey, streamBindingKey); - - @Mock private EntityClient client; - @Mock private EntityDeleter deleter; - private final StringPrintStream out = StringPrintStream.create(); - private final StringPrintStream err = StringPrintStream.create(); - - @Test - public void noEntitiesFound() { - when(client.getDomainKeys(DOMAIN)) - .thenReturn(Collections.emptyList()); - - run(DOMAIN, - DOMAIN_ARG); - - verifyNoInteractions(deleter); - } - - @Test - public void domain() { - when(client.getDomainKeys(DOMAIN)) - .thenReturn(Collections.singletonList(domainKey)); - - run(DOMAIN, - DOMAIN_ARG); - - verify(deleter).delete(domainKey); - } - - @Test - public void domainDryRun() { - when(client.getDomainKeys(DOMAIN)) - .thenReturn(Collections.singletonList(domainKey)); - - run(DOMAIN, DRY_RUN_ARG, - DOMAIN_ARG); - - verifyNoInteractions(deleter); - } - - @Test - public void schema() { - when(client.getSchemaKeys(DOMAIN, SCHEMA)) - .thenReturn(Collections.singletonList(schemaKey)); - - run(SCHEMA, - DOMAIN_ARG, SCHEMA_ARG); - - verify(deleter).delete(schemaKey); - } - - @Test - public void schemaDryRun() { - when(client.getSchemaKeys(DOMAIN, SCHEMA)) - .thenReturn(Collections.singletonList(schemaKey)); - - run(SCHEMA, DRY_RUN_ARG, - DOMAIN_ARG, SCHEMA_ARG); - - verifyNoInteractions(deleter); - } - - @Test - public void stream() { - when(client.getStreamKeyWithSchemaKeys(DOMAIN, STREAM, VERSION, null, null)) - .thenReturn(Collections.singletonMap(streamKey, schemaKey)); - - run(STREAM, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG); - - verify(deleter).delete(streamKey); - } - - @Test - public void streamDryRun() { - when(client.getStreamKeyWithSchemaKeys(DOMAIN, STREAM, VERSION, null, null)) - .thenReturn(Collections.singletonMap(streamKey, schemaKey)); - - run(STREAM, DRY_RUN_ARG, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG); - - verifyNoInteractions(deleter); - } - - @Test - public void streamCascade() { - when(client.getConsumerBindingKeys(DOMAIN, STREAM, VERSION, null, null, null)) - .thenReturn(Collections.singletonList(consumerBindingKey)); - when(client.getConsumerKeys(DOMAIN, STREAM, VERSION, null, null)) - .thenReturn(Collections.singletonList(consumerKey)); - when(client.getProducerBindingKeys(DOMAIN, STREAM, VERSION, null, null, null)) - .thenReturn(Collections.singletonList(producerBindingKey)); - when(client.getProducerKeys(DOMAIN, STREAM, VERSION, null, null)) - .thenReturn(Collections.singletonList(producerKey)); - when(client.getStreamBindingKeys(DOMAIN, STREAM, VERSION, null, null)) - .thenReturn(Collections.singletonList(streamBindingKey)); - when(client.getStreamKeyWithSchemaKeys(DOMAIN, STREAM, VERSION, null, null)) - .thenReturn(Collections.singletonMap(streamKey, schemaKey)); - when(client.getStreamKeyWithSchemaKeys(null, null, null, DOMAIN, SCHEMA)) - .thenReturn(Collections.singletonMap(streamKey, schemaKey)); - - run(STREAM, CASCADE_ARG, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG); - - InOrder inOrder = inOrder(deleter); - inOrder.verify(deleter).delete(consumerBindingKey); - inOrder.verify(deleter).delete(consumerKey); - inOrder.verify(deleter).delete(producerBindingKey); - inOrder.verify(deleter).delete(producerKey); - inOrder.verify(deleter).delete(streamBindingKey); - inOrder.verify(deleter).delete(streamKey); - inOrder.verify(deleter).delete(schemaKey); - } - - @Test - public void streamCascadeReusedSchema() { - when(client.getConsumerBindingKeys(DOMAIN, STREAM, VERSION, null, null, null)) - .thenReturn(Collections.singletonList(consumerBindingKey)); - when(client.getConsumerKeys(DOMAIN, STREAM, VERSION, null, null)) - .thenReturn(Collections.singletonList(consumerKey)); - when(client.getProducerBindingKeys(DOMAIN, STREAM, VERSION, null, null, null)) - .thenReturn(Collections.singletonList(producerBindingKey)); - when(client.getProducerKeys(DOMAIN, STREAM, VERSION, null, null)) - .thenReturn(Collections.singletonList(producerKey)); - when(client.getStreamBindingKeys(DOMAIN, STREAM, VERSION, null, null)) - .thenReturn(Collections.singletonList(streamBindingKey)); - when(client.getStreamKeyWithSchemaKeys(DOMAIN, STREAM, VERSION, null, null)) - .thenReturn(Collections.singletonMap(streamKey, schemaKey)); - when(client.getStreamKeyWithSchemaKeys(null, null, null, DOMAIN, SCHEMA)) - .thenReturn(new HashMap() {{ - put(streamKey, schemaKey); - put(streamKey2, schemaKey); - }}); - - run(STREAM, CASCADE_ARG, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG); - - InOrder inOrder = inOrder(deleter); - inOrder.verify(deleter).delete(consumerBindingKey); - inOrder.verify(deleter).delete(consumerKey); - inOrder.verify(deleter).delete(producerBindingKey); - inOrder.verify(deleter).delete(producerKey); - inOrder.verify(deleter).delete(streamBindingKey); - inOrder.verify(deleter).delete(streamKey); - inOrder.verify(deleter, never()).delete(schemaKey); - } - - @Test - public void zone() { - when(client.getZoneKeys(ZONE)) - .thenReturn(Collections.singletonList(zoneKey)); - - run(ZONE, - ZONE_ARG); - - verify(deleter).delete(zoneKey); - } - - @Test - public void zoneDryRun() { - when(client.getZoneKeys(ZONE)) - .thenReturn(Collections.singletonList(zoneKey)); - - run(ZONE, DRY_RUN_ARG, - ZONE_ARG); - - verifyNoInteractions(deleter); - } - - @Test - public void infrastructure() { - when(client.getInfrastructureKeys(ZONE, INFRASTRUCTURE)) - .thenReturn(Collections.singletonList(infrastructureKey)); - - run(INFRASTRUCTURE, - ZONE_ARG, INFRASTRUCTURE_ARG); - - verify(deleter).delete(infrastructureKey); - } - - @Test - public void infrastructureDryRun() { - when(client.getInfrastructureKeys(ZONE, INFRASTRUCTURE)) - .thenReturn(Collections.singletonList(infrastructureKey)); - - run(INFRASTRUCTURE, DRY_RUN_ARG, - ZONE_ARG, INFRASTRUCTURE_ARG); - - verifyNoInteractions(deleter); - } - - @Test - public void producer() { - when(client.getProducerKeys(DOMAIN, STREAM, VERSION, ZONE, PRODUCER)) - .thenReturn(Collections.singletonList(producerKey)); - - run(PRODUCER, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG, ZONE_ARG, PRODUCER_ARG); - - verify(deleter).delete(producerKey); - } - - @Test - public void producerDryRun() { - when(client.getProducerKeys(DOMAIN, STREAM, VERSION, ZONE, PRODUCER)) - .thenReturn(Collections.singletonList(producerKey)); - - run(PRODUCER, DRY_RUN_ARG, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG, ZONE_ARG, PRODUCER_ARG); - - verifyNoInteractions(deleter); - } - - @Test - public void consumer() { - when(client.getConsumerKeys(DOMAIN, STREAM, VERSION, ZONE, CONSUMER)) - .thenReturn(Collections.singletonList(consumerKey)); - - run(CONSUMER, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG, ZONE_ARG, CONSUMER_ARG); - - verify(deleter).delete(consumerKey); - } - - @Test - public void consumerDryRun() { - when(client.getConsumerKeys(DOMAIN, STREAM, VERSION, ZONE, CONSUMER)) - .thenReturn(Collections.singletonList(consumerKey)); - - run(CONSUMER, DRY_RUN_ARG, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG, ZONE_ARG, CONSUMER_ARG); - - verifyNoInteractions(deleter); - } - - @Test - public void streamBinding() { - when(client.getStreamBindingKeys(DOMAIN, STREAM, VERSION, ZONE, INFRASTRUCTURE)) - .thenReturn(Collections.singletonList(streamBindingKey)); - - run(STREAM_BINDING, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG, ZONE_ARG, INFRASTRUCTURE_ARG); - - verify(deleter).delete(streamBindingKey); - } - - @Test - public void streamBindingDryRun() { - when(client.getStreamBindingKeys(DOMAIN, STREAM, VERSION, ZONE, INFRASTRUCTURE)) - .thenReturn(Collections.singletonList(streamBindingKey)); - - run(STREAM_BINDING, DRY_RUN_ARG, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG, ZONE_ARG, INFRASTRUCTURE_ARG); - - verifyNoInteractions(deleter); - } - - @Test - public void producerBinding() { - when(client.getProducerBindingKeys(DOMAIN, STREAM, VERSION, ZONE, INFRASTRUCTURE, PRODUCER)) - .thenReturn(Collections.singletonList(producerBindingKey)); - - run(PRODUCER_BINDING, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG, ZONE_ARG, INFRASTRUCTURE_ARG, PRODUCER_ARG); - - verify(deleter).delete(producerBindingKey); - } - - @Test - public void producerBindingDryRun() { - when(client.getProducerBindingKeys(DOMAIN, STREAM, VERSION, ZONE, INFRASTRUCTURE, PRODUCER)) - .thenReturn(Collections.singletonList(producerBindingKey)); - - run(PRODUCER_BINDING, DRY_RUN_ARG, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG, ZONE_ARG, INFRASTRUCTURE_ARG, PRODUCER_ARG); - - verifyNoInteractions(deleter); - } - - @Test - public void consumerBinding() { - when(client.getConsumerBindingKeys(DOMAIN, STREAM, VERSION, ZONE, INFRASTRUCTURE, CONSUMER)) - .thenReturn(Collections.singletonList(consumerBindingKey)); - - run(CONSUMER_BINDING, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG, ZONE_ARG, INFRASTRUCTURE_ARG, CONSUMER_ARG); - - verify(deleter).delete(consumerBindingKey); - } - - @Test - public void consumerBindingDryRun() { - when(client.getConsumerBindingKeys(DOMAIN, STREAM, VERSION, ZONE, INFRASTRUCTURE, CONSUMER)) - .thenReturn(Collections.singletonList(consumerBindingKey)); - - run(CONSUMER_BINDING, DRY_RUN_ARG, - DOMAIN_ARG, STREAM_ARG, VERSION_ARG, ZONE_ARG, INFRASTRUCTURE_ARG, CONSUMER_ARG); - - verifyNoInteractions(deleter); - } - - private void run(String entity, String... args) { - ParseResult result = underTest.parseArgs(concat(concat(entity, standardOptions), args, String.class)); - Delete.Base action = (Delete.Base) result.subcommand().commandSpec().userObject(); - action.run(out, err, client, deleter); - } -} diff --git a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityDeleterTest.java b/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityDeleterTest.java deleted file mode 100644 index 4f2761314..000000000 --- a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/EntityDeleterTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (C) 2018-2020 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command.delete; - -import static com.expediagroup.streamplatform.streamregistry.state.model.event.Event.specificationDeletion; -import static com.expediagroup.streamplatform.streamregistry.state.model.event.Event.statusDeletion; -import static java.util.concurrent.CompletableFuture.completedFuture; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import com.expediagroup.streamplatform.streamregistry.state.kafka.KafkaEventSender; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.DomainKey; - -@RunWith(MockitoJUnitRunner.class) -public class EntityDeleterTest { - @Mock private KafkaEventSender sender; - - private EntityDeleter underTest; - - @Before - public void before() { - underTest = new EntityDeleter(sender); - } - - @Test - public void test() { - when(sender.send(any())) - .thenReturn(completedFuture(null)) - .thenReturn(completedFuture(null)); - - DomainKey domainKey = new DomainKey("domain"); - - underTest.delete(domainKey); - underTest.close(); - - verify(sender).send(statusDeletion(domainKey, "agentStatus")); - verify(sender).send(specificationDeletion(domainKey)); - } -} diff --git a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StreamAndSchemaDiscovererTest.java b/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StreamAndSchemaDiscovererTest.java deleted file mode 100644 index f06e01234..000000000 --- a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StreamAndSchemaDiscovererTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright (C) 2018-2021 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command.delete; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.mockito.Mockito.when; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.DomainKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.SchemaKey; -import com.expediagroup.streamplatform.streamregistry.state.model.Entity.StreamKey; - -@RunWith(MockitoJUnitRunner.class) -public class StreamAndSchemaDiscovererTest { - @Mock - private EntityClient client; - - @InjectMocks - private StreamAndSchemaDiscoverer underTest; - - private final DomainKey domainKey = new DomainKey("domain"); - private final SchemaKey schemaKey = new SchemaKey(domainKey, "schema"); - private final StreamKey streamKey1 = new StreamKey(domainKey, "stream", 1); - private final StreamKey streamKey2 = new StreamKey(domainKey, "stream", 2); - - @Before - public void before() { - when(client.getStreamKeyWithSchemaKeys("domain", ".*", 1, null, null)) - .thenReturn(Collections.singletonMap(streamKey1, schemaKey)); - } - - @Test - public void schemaIsPresent() { - when(client.getStreamKeyWithSchemaKeys(null, null, null, "domain", "schema")) - .thenReturn(Collections.singletonMap(streamKey1, schemaKey)); - - Map> result = underTest.discover("domain", ".*", 1); - - assertThat(result.size(), is(1)); - assertThat(result.get(streamKey1).isPresent(), is(true)); - } - - @Test - public void reusedSchemaIsRemoved() { - when(client.getStreamKeyWithSchemaKeys(null, null, null, "domain", "schema")) - .thenReturn( - new HashMap() {{ - put(streamKey1, schemaKey); - put(streamKey2, schemaKey); - }} - ); - - Map> result = underTest.discover("domain", ".*", 1); - - assertThat(result.size(), is(1)); - assertThat(result.get(streamKey1).isPresent(), is(false)); - } -} diff --git a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StringPrintStream.java b/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StringPrintStream.java deleted file mode 100644 index 10f1d1e75..000000000 --- a/cli/src/test/java/com/expediagroup/streamplatform/streamregistry/cli/command/delete/StringPrintStream.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (C) 2018-2021 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.cli.command.delete; - -import static java.nio.charset.StandardCharsets.UTF_8; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; - -class StringPrintStream extends PrintStream { - private static final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - StringPrintStream() throws UnsupportedEncodingException { - super(baos, true, UTF_8.name()); - } - - static StringPrintStream create() { - try { - return new StringPrintStream(); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - - @Override - public String toString() { - return new String(baos.toByteArray(), UTF_8); - } -} diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingService.java index f82aacdbf..b5a2399ef 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingService.java @@ -1,12 +1,12 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. - *

+ * Copyright (C) 2018-2023 Expedia, Inc. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

+ * * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,6 +15,20 @@ */ package com.expediagroup.streamplatform.streamregistry.core.services; +import static java.util.stream.Collectors.toList; + +import java.util.List; +import java.util.Optional; +import java.util.function.Predicate; + +import lombok.RequiredArgsConstructor; +import lombok.val; + +import org.springframework.security.access.prepost.PostAuthorize; +import org.springframework.security.access.prepost.PostFilter; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Component; + import com.expediagroup.streamplatform.streamregistry.core.handlers.HandlerService; import com.expediagroup.streamplatform.streamregistry.core.validators.ProcessBindingValidator; import com.expediagroup.streamplatform.streamregistry.core.validators.ValidationException; @@ -23,18 +37,6 @@ import com.expediagroup.streamplatform.streamregistry.model.Status; import com.expediagroup.streamplatform.streamregistry.model.keys.ProcessBindingKey; import com.expediagroup.streamplatform.streamregistry.repository.ProcessBindingRepository; -import lombok.RequiredArgsConstructor; -import lombok.val; -import org.springframework.security.access.prepost.PostAuthorize; -import org.springframework.security.access.prepost.PostFilter; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Optional; -import java.util.function.Predicate; - -import static java.util.stream.Collectors.toList; @Component @RequiredArgsConstructor diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingServiceTest.java index 691c56b74..a7e42e8bc 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingServiceTest.java @@ -1,12 +1,12 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. - *

+ * Copyright (C) 2018-2023 Expedia, Inc. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

+ * * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,15 +16,16 @@ package com.expediagroup.streamplatform.streamregistry.core.services; -import com.expediagroup.streamplatform.streamregistry.core.handlers.HandlerService; -import com.expediagroup.streamplatform.streamregistry.core.validators.ProcessBindingValidator; -import com.expediagroup.streamplatform.streamregistry.core.views.ProcessBindingView; -import com.expediagroup.streamplatform.streamregistry.model.ProcessBinding; -import com.expediagroup.streamplatform.streamregistry.model.Specification; -import com.expediagroup.streamplatform.streamregistry.model.Status; -import com.expediagroup.streamplatform.streamregistry.model.keys.ProcessBindingKey; -import com.expediagroup.streamplatform.streamregistry.repository.ProcessBindingRepository; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Optional; + import com.fasterxml.jackson.databind.ObjectMapper; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,13 +33,14 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import java.util.Optional; - -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import com.expediagroup.streamplatform.streamregistry.core.handlers.HandlerService; +import com.expediagroup.streamplatform.streamregistry.core.validators.ProcessBindingValidator; +import com.expediagroup.streamplatform.streamregistry.core.views.ProcessBindingView; +import com.expediagroup.streamplatform.streamregistry.model.ProcessBinding; +import com.expediagroup.streamplatform.streamregistry.model.Specification; +import com.expediagroup.streamplatform.streamregistry.model.Status; +import com.expediagroup.streamplatform.streamregistry.model.keys.ProcessBindingKey; +import com.expediagroup.streamplatform.streamregistry.repository.ProcessBindingRepository; @RunWith(MockitoJUnitRunner.class) public class ProcessBindingServiceTest { diff --git a/graphql/api/pom.xml b/graphql/api/pom.xml index 800ddec34..7f0d96c0d 100644 --- a/graphql/api/pom.xml +++ b/graphql/api/pom.xml @@ -53,10 +53,6 @@ graphiql-spring-boot-starter ${graphiql-spring-boot.version} - - com.hotels.beans - bean-utils-library - org.projectlombok lombok diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/StateHelper.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/StateHelper.java index 940f10cce..01e0bf744 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/StateHelper.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/StateHelper.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2023 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,6 @@ public class StateHelper { public static void maintainState(Stated stated, Optional existing) { - if (existing.isPresent()) { - stated.setStatus(existing.get().getStatus()); - } + existing.ifPresent(value -> stated.setStatus(value.getStatus())); } } diff --git a/it/pom.xml b/it/pom.xml index 2f9c43417..c789d0916 100644 --- a/it/pom.xml +++ b/it/pom.xml @@ -73,7 +73,6 @@ org.jetbrains annotations - 19.0.0 diff --git a/pom.xml b/pom.xml index 173718333..ce2fe72ba 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,6 @@ app - cli core graphql/api graphql/maven-plugin @@ -70,16 +69,18 @@ UTF-8 0.8.11 - 7.4.0 + 1.10.0 + 7.5.2 1.11.3 2.5.14 3.1.6 - 1.4.7.3 - 32.0.0-jre + 32.1.3-jre 21.0 - 1.7.10 + 1.8.22 + 24.0.1 1.7.26 - 3.1.5 + 2.0 + 3.1.6 1.18.3 2.17.1 3.3.3 @@ -123,6 +124,16 @@ avro ${avro.version} + + org.yaml + snakeyaml + 2.0 + + + org.apache.commons + commons-text + ${commons-text.version} + io.confluent kafka-streams-avro-serde @@ -158,9 +169,9 @@ ${graphql-java.version} - com.hotels.beans - bean-utils-library - ${bull.version} + org.jetbrains + annotations + ${jetbrains.annotations.version} org.jetbrains.kotlin diff --git a/state/graphql-sender/pom.xml b/state/graphql-sender/pom.xml index 593a9ba3a..32c70ee03 100644 --- a/state/graphql-sender/pom.xml +++ b/state/graphql-sender/pom.xml @@ -44,7 +44,6 @@ org.jetbrains annotations - 19.0.0 org.projectlombok From bc8dd0d2d88396b898ff37d0086cd85897af07a8 Mon Sep 17 00:00:00 2001 From: jfaulkner Date: Fri, 24 Nov 2023 16:33:28 +0000 Subject: [PATCH 2/3] chore: Update dependencies. Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fa273779..398d32247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Updated kotlin from 1.7.10 to 1.8.22 - Updated schema-registry-client from 7.4.0 to 7.5.2 - Updated commons-text from 1.9 to 1.10.0 +- Removed bean-utils-library, which didn't appear to be in use. ## [2.0.2] 2023-11-06 ### Fixed From e57a131ceb3dc4e431ae9a56906e9ae5aaa9f54d Mon Sep 17 00:00:00 2001 From: jfaulkner Date: Fri, 24 Nov 2023 16:48:52 +0000 Subject: [PATCH 3/3] chore: Update dependencies. use variable --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ce2fe72ba..45abab57f 100644 --- a/pom.xml +++ b/pom.xml @@ -127,7 +127,7 @@ org.yaml snakeyaml - 2.0 + ${snakeyaml.version} org.apache.commons