Skip to content

Commit

Permalink
fix: Adding configurable property to handle double delete events corr…
Browse files Browse the repository at this point in the history
…ectly (#347)

fix: Adding configurable property to handle double delete events correctly (#347)
  • Loading branch information
ojhagaurov authored Jan 23, 2024
1 parent f0f51fa commit 55fb7db
Show file tree
Hide file tree
Showing 18 changed files with 728 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ 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).

### Updated
- Adding Configurable property to enable or disable checking if entity exists in EntityView during delete.

## [unreleased]
### Added
- stream-registry bom
Expand Down
5 changes: 5 additions & 0 deletions graphql/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2018-2023 Expedia, Inc.
* Copyright (C) 2018-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,13 +15,47 @@
*/
package com.expediagroup.streamplatform.streamregistry.graphql;

import java.util.Collections;
import java.util.Optional;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.SchemaKeyInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.SpecificationInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput;
import com.expediagroup.streamplatform.streamregistry.model.Specification;
import com.expediagroup.streamplatform.streamregistry.model.Stated;
import com.expediagroup.streamplatform.streamregistry.model.Status;
import com.expediagroup.streamplatform.streamregistry.model.keys.SchemaKey;

public class StateHelper {

private static final ObjectMapper mapper = new ObjectMapper();

public static void maintainState(Stated stated, Optional<? extends Stated> existing) {
existing.ifPresent(value -> stated.setStatus(value.getStatus()));
}

public static Specification specification() {
return SpecificationInput.builder()
.description("description")
.tags(Collections.emptyList())
.type("default")
.configuration(mapper.createObjectNode())
.security(Collections.emptyList())
.build().asSpecification();
}

public static Status status() {
return StatusInput.builder()
.agentStatus(mapper.createObjectNode())
.build().asStatus();
}

public static SchemaKey schemaKey() {
return SchemaKeyInput.builder()
.domain("domain")
.name("name")
.build().asSchemaKey();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2018-2021 Expedia, Inc.
* Copyright (C) 2018-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,10 +19,12 @@

import lombok.RequiredArgsConstructor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.expediagroup.streamplatform.streamregistry.core.services.ConsumerBindingService;
import com.expediagroup.streamplatform.streamregistry.core.views.ConsumerBindingView;
import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ConsumerBindingKeyInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.SpecificationInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput;
Expand All @@ -32,9 +34,13 @@
@Component
@RequiredArgsConstructor
public class ConsumerBindingMutationImpl implements ConsumerBindingMutation {

private final ConsumerBindingService consumerBindingService;
private final ConsumerBindingView consumerBindingView;

@Value("${entityView.exist.check.enabled:true}")
private boolean checkExistEnabled;

@Override
public ConsumerBinding insert(ConsumerBindingKeyInput key, SpecificationInput specification) {
return consumerBindingService.create(asConsumerBinding(key, specification)).get();
Expand All @@ -57,7 +63,12 @@ public ConsumerBinding upsert(ConsumerBindingKeyInput key, SpecificationInput sp

@Override
public Boolean delete(ConsumerBindingKeyInput key) {
consumerBindingView.get(key.asConsumerBindingKey()).ifPresent(consumerBindingService::delete);
if (checkExistEnabled) {
consumerBindingView.get(key.asConsumerBindingKey()).ifPresent(consumerBindingService::delete);
} else {
ConsumerBinding consumerBinding = new ConsumerBinding(key.asConsumerBindingKey(), StateHelper.specification(), StateHelper.status());
consumerBindingService.delete(consumerBinding);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2018-2021 Expedia, Inc.
* Copyright (C) 2018-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,10 +19,12 @@

import lombok.RequiredArgsConstructor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.expediagroup.streamplatform.streamregistry.core.services.ConsumerService;
import com.expediagroup.streamplatform.streamregistry.core.views.ConsumerView;
import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ConsumerKeyInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.SpecificationInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput;
Expand All @@ -32,9 +34,13 @@
@Component
@RequiredArgsConstructor
public class ConsumerMutationImpl implements ConsumerMutation {

private final ConsumerService consumerService;
private final ConsumerView consumerView;

@Value("${entityView.exist.check.enabled:true}")
private boolean checkExistEnabled;

@Override
public Consumer insert(ConsumerKeyInput key, SpecificationInput specification) {
return consumerService.create(asConsumer(key, specification)).get();
Expand All @@ -57,7 +63,12 @@ public Consumer upsert(ConsumerKeyInput key, SpecificationInput specification) {

@Override
public Boolean delete(ConsumerKeyInput key) {
consumerView.get(key.asConsumerKey()).ifPresent(consumerService::delete);
if (checkExistEnabled) {
consumerView.get(key.asConsumerKey()).ifPresent(consumerService::delete);
} else {
Consumer consumer = new Consumer(key.asConsumerKey(), StateHelper.specification(), StateHelper.status());
consumerService.delete(consumer);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2018-2022 Expedia, Inc.
* Copyright (C) 2018-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,7 @@
@Component
@RequiredArgsConstructor
public class DomainMutationImpl implements DomainMutation {

private final DomainService domainService;
private final DomainView domainView;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2018-2021 Expedia, Inc.
* Copyright (C) 2018-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,7 @@
@Component
@RequiredArgsConstructor
public class InfrastructureMutationImpl implements InfrastructureMutation {

private final InfrastructureService infrastructureService;
private final InfrastructureView infrastructureView;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2018-2021 Expedia, Inc.
* Copyright (C) 2018-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,10 +19,12 @@

import lombok.RequiredArgsConstructor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.expediagroup.streamplatform.streamregistry.core.services.ProducerBindingService;
import com.expediagroup.streamplatform.streamregistry.core.views.ProducerBindingView;
import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ProducerBindingKeyInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.SpecificationInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput;
Expand All @@ -32,6 +34,10 @@
@Component
@RequiredArgsConstructor
public class ProducerBindingMutationImpl implements ProducerBindingMutation {

@Value("${entityView.exist.check.enabled:true}")
private boolean checkExistEnabled;

private final ProducerBindingService producerBindingService;
private final ProducerBindingView producerBindingView;

Expand All @@ -57,7 +63,12 @@ public ProducerBinding upsert(ProducerBindingKeyInput key, SpecificationInput sp

@Override
public Boolean delete(ProducerBindingKeyInput key) {
producerBindingView.get(key.asProducerBindingKey()).ifPresent(producerBindingService::delete);
if (checkExistEnabled) {
producerBindingView.get(key.asProducerBindingKey()).ifPresent(producerBindingService::delete);
} else {
ProducerBinding producerBinding = new ProducerBinding(key.asProducerBindingKey(), StateHelper.specification(), StateHelper.status());
producerBindingService.delete(producerBinding);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2018-2021 Expedia, Inc.
* Copyright (C) 2018-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,20 +19,25 @@

import lombok.RequiredArgsConstructor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.expediagroup.streamplatform.streamregistry.core.services.ProducerService;
import com.expediagroup.streamplatform.streamregistry.core.views.ProducerView;
import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ProducerKeyInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.SpecificationInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput;
import com.expediagroup.streamplatform.streamregistry.graphql.mutation.ProducerMutation;
import com.expediagroup.streamplatform.streamregistry.model.Producer;


@Component
@RequiredArgsConstructor
public class ProducerMutationImpl implements ProducerMutation {

@Value("${entityView.exist.check.enabled:true}")
private boolean checkExistEnabled;

private final ProducerService producerService;
private final ProducerView producerView;

Expand All @@ -58,7 +63,12 @@ public Producer upsert(ProducerKeyInput key, SpecificationInput specification) {

@Override
public Boolean delete(ProducerKeyInput key) {
producerView.get(key.asProducerKey()).ifPresent(producerService::delete);
if (checkExistEnabled) {
producerView.get(key.asProducerKey()).ifPresent(producerService::delete);
} else {
Producer producer = new Producer(key.asProducerKey(), StateHelper.specification(), StateHelper.status());
producerService.delete(producer);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2018-2021 Expedia, Inc.
* Copyright (C) 2018-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,10 +29,10 @@
import com.expediagroup.streamplatform.streamregistry.graphql.mutation.SchemaMutation;
import com.expediagroup.streamplatform.streamregistry.model.Schema;


@Component
@RequiredArgsConstructor
public class SchemaMutationImpl implements SchemaMutation {

private final SchemaService schemaService;
private final SchemaView schemaView;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2018-2021 Expedia, Inc.
* Copyright (C) 2018-2024 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,10 +19,12 @@

import lombok.RequiredArgsConstructor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.expediagroup.streamplatform.streamregistry.core.services.StreamBindingService;
import com.expediagroup.streamplatform.streamregistry.core.views.StreamBindingView;
import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.SpecificationInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput;
import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StreamBindingKeyInput;
Expand All @@ -32,6 +34,10 @@
@Component
@RequiredArgsConstructor
public class StreamBindingMutationImpl implements StreamBindingMutation {

@Value("${entityView.exist.check.enabled:true}")
private boolean checkExistEnabled;

private final StreamBindingService streamBindingService;
private final StreamBindingView streamBindingView;

Expand All @@ -57,7 +63,12 @@ public StreamBinding upsert(StreamBindingKeyInput key, SpecificationInput specif

@Override
public Boolean delete(StreamBindingKeyInput key) {
streamBindingView.get(key.asStreamBindingKey()).ifPresent(streamBindingService::delete);
if (checkExistEnabled) {
streamBindingView.get(key.asStreamBindingKey()).ifPresent(streamBindingService::delete);
} else {
StreamBinding streamBinding = new StreamBinding(key.asStreamBindingKey(), StateHelper.specification(), StateHelper.status());
streamBindingService.delete(streamBinding);
}
return true;
}

Expand Down
Loading

0 comments on commit 55fb7db

Please sign in to comment.