Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: STREAMP-12186: adding disable flags for entity status support #358

Merged
merged 9 commits into from
Jun 13, 2024

Conversation

andykruth-ii
Copy link
Contributor

@andykruth-ii andykruth-ii commented Jun 11, 2024

Adding flags to disable Entity Status.

  • Implemented an old TODO to separate repository save functions into two that will allow specification and status saving to be done separately. This will help in disabling entity status support
  • Updated all Entity Service Classes to use these distinct save methods
  • Updated all Entity Mutation Implementations to make the updateStatus mutation a NOOP which does not persist the status when a toggle is disabled
  • Added a convenience constructor to all Entity Model classes that does not require a status value.
  • Updated the DefaultEntityView, DefaultEntityViewUpdater and KafkaEventReceiver with option disable toggle for entity status

@@ -1,5 +1,5 @@
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All entity service classes are updated to use separated saveSpecification and saveStatus repository methods.

return consumerBindingService.updateStatus(consumerBinding, status.asStatus()).get();
} else {
return consumerBinding;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the individual entity mutation implementation classes have this new Spring value toggle, set to true by default which is the current mode of operation.

When set to false an updateStatus mutation will NOT update the entity status via the entity service, it will just be a successful NOOP.

public static StatusInput statusInput() {
return StatusInput.builder().agentStatus(mapper.createObjectNode()).build();
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a convenience test class to generate a statusInput

verify(consumerBindingService, never()).updateStatus(consumerBinding.get(), statusInput.asStatus());
assertEquals(consumerBinding.get(), result);
}

private ConsumerBindingKeyInput getConsumerBindingInputKey() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each entity has these two additional tests to test that when entity status is enabled (default) the entity service is called to update the status. The second test is for when entity status is disabled, the entity service should NOT be called when an updateStatus mutation is received.

this.key = key;
this.specification = specification;
this.status = new Status();
}
}
Copy link
Contributor Author

@andykruth-ii andykruth-ii Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all Entity Model classes, adding this additional convenience constructor which allows for creating Entities without needed to specify a status value.

T saveSpecification(T entity);

T saveStatus(T entity);

Optional<T> findById(ID id);

List<T> findAll();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally handling a TODO from long ago, deprecating the save method in favor of two separate saveSpecification and saveStatus methods.

this.specification = specification;
this.status = new DefaultStatus();
}

public interface Key<S extends Specification> {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New convenience constructor so that a status does not need to be passed in.

public DefaultEntityView(EventReceiver receiver) {
this(receiver, new ConcurrentHashMap<>());
}


@Override
public CompletableFuture<Void> load(@NonNull EntityViewListener listener) {
val future = new CompletableFuture<Void>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an optional entityStatusEnabled flag to all constructor patterns will can be used to disable entity status persistence.

Copy link
Contributor

@jamespfaulkner jamespfaulkner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions:

Rather than having multiple instances of the entityStatusEnabled in all instances of the *MutationImpl classes, would it be simpler to just ignore these in the KafkaEventSender? enableStatuses could be added to Config there, the sending could then be changed to something like:

  @Override
  public <K extends Entity.Key<S>, S extends Specification> CompletableFuture<Void> send(@NonNull Event<K, S> event) {
    if (!config.enableStatuses && (event instanceof StatusEvent<K, S> || event instanceof StatusDeletionEvent<K, S>)) {
      return CompletableFuture.completedFuture(null);
    }

    val avroEvent = converter.toAvro(event);
    return send(avroEvent.getKey(), avroEvent.getValue());
  }

We'd then remove the if/else in all *MutationImpl.


Second question, and maybe this is progress for a follow up. Would it be possible to change the Event class hierarchy in allow easier differentiation between entity/status events.

I'm thinking two new interfaces with SpecificationEvent/StatusEvent/SpecificationDeletionEvent/StatusDeletionEvent extending the correct interface.

public interface EntityEvent<K extends Entity.Key<S>, S extends Specification> extends Event<K, S> { }

public interface StatusEvent<K extends Entity.Key<S>, S extends Specification> extends Event<K, S> { }

We could then have a new EventReceiverListener which deals only with the entity events (meaning agents really are shielded from Status events...

<K extends Entity.Key<S>, S extends Specification> void onEvent(EntityEvent<K, S> event);

@andykruth-ii
Copy link
Contributor Author

@jamespfaulkner - OK summary of updates:

  • Added the entity status toggle to KafkaEventSender similar to KafkaEventReceiver
  • Better tests for KafkaEventReceiver
  • Removed all MutationImpl changes, no longer necessary
  • Removed all EntityView changes, no longer necessary
  • removed repository.send method instead of deprecating so that we get a compile error instead of runtime error
  • removed futures on single event send in saveSpecification

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import lombok.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: star import

@andykruth-ii andykruth-ii merged commit 2b6c5b6 into master Jun 13, 2024
2 checks passed
@andykruth-ii andykruth-ii deleted the feat/STREAMP-12186/status-deprecation branch June 13, 2024 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants