Skip to content

Commit

Permalink
Move AbstractEnforcerActor to module ditto-policies-enforcement
Browse files Browse the repository at this point in the history
* Since this is relevant for enforcement it makes more sense to have it there

Signed-off-by: Yannic Klem <Yannic.Klem@bosch.io>
  • Loading branch information
Yannic92 committed May 25, 2022
1 parent 5e6475c commit e100846
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommand;
import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommandResponse;
import org.eclipse.ditto.connectivity.service.enforcement.ConnectivityCommandEnforcement;
import org.eclipse.ditto.internal.utils.persistentactors.AbstractEnforcerActor;
import org.eclipse.ditto.policies.enforcement.AbstractEnforcerActor;
import org.eclipse.ditto.policies.enforcement.PolicyEnforcer;
import org.eclipse.ditto.policies.model.PolicyId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ protected void becomeCorrupted() {
}

/**
* Asks the {@link AbstractEnforcerActor} child the passed {@code signal}, responding with a CompletionStage which
* is completed with the response.
* Asks the {@link org.eclipse.ditto.policies.enforcement.AbstractEnforcerActor} child the passed {@code signal},
* responding with a CompletionStage which is completed with the response.
* As the enforcer child is always located on the same node, this is a local method call, so the applied ask timeout
* is very low.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.internal.utils.persistentactors;
package org.eclipse.ditto.policies.enforcement;

import java.time.Duration;
import java.util.concurrent.CompletableFuture;
Expand All @@ -33,8 +33,6 @@
import org.eclipse.ditto.internal.utils.cluster.DistPubSubAccess;
import org.eclipse.ditto.internal.utils.namespaces.BlockedNamespaces;
import org.eclipse.ditto.policies.api.PolicyTag;
import org.eclipse.ditto.policies.enforcement.EnforcementReloaded;
import org.eclipse.ditto.policies.enforcement.PolicyEnforcer;
import org.eclipse.ditto.policies.model.Policy;
import org.eclipse.ditto.policies.model.PolicyId;
import org.eclipse.ditto.policies.model.enforcers.PolicyEnforcers;
Expand All @@ -46,9 +44,7 @@
import akka.japi.pf.ReceiveBuilder;

/**
* Abstract enforcer of commands performing authorization / enforcement of incoming signals
* targeting to be handled by either the {@link AbstractPersistenceActor} of incoming live signals to be published to
* pub/sub.
* Abstract enforcer of commands performing authorization / enforcement of incoming signals.
*
* @param <I> the type of the EntityId this enforcer actor enforces commands for.
* @param <S> the type of the Signals this enforcer actor enforces.
Expand Down Expand Up @@ -147,7 +143,7 @@ protected Receive activeBehaviour() {
return ReceiveBuilder.create()
.match(DistributedPubSubMediator.SubscribeAck.class, s -> log.debug("Got subscribeAck <{}>.", s))
.match(PolicyTag.class, pt -> pt.getEntityId().equals(policyIdForEnforcement),
pt -> performPolicyEnforcerReload()
pt -> performPolicyEnforcerReload()
)
.match(PolicyTag.class, pt -> {
// ignore policy tags not intended for this actor - not necessary to log on debug!
Expand Down Expand Up @@ -182,7 +178,8 @@ public Receive createReceive() {
private void reloadPolicyEnforcer(final Consumer<PolicyEnforcer> successConsumer) {
providePolicyIdForEnforcement()
.thenCompose(policyId -> {
this.policyIdForEnforcement = policyId; // policyId could be null, e.g. if entity is not yet existing
this.policyIdForEnforcement =
policyId; // policyId could be null, e.g. if entity is not yet existing
return providePolicyEnforcer(policyId);
})
.whenComplete((pEnf, throwable) -> {
Expand Down Expand Up @@ -268,7 +265,7 @@ private static boolean containsNamespaceOfEntityId(final ORSet<String> namespace
/**
* Enforces the passed {@code signal} using the {@code enforcement} of this actor.
* Successfully enforced signals are sent back to the {@code getSender()} - which is our dear parent, the Supervisor.
* Our parent is responsible for then forwarding the signal to the persistence actor.
* Our parent is responsible for then forwarding the signal to the actual responsible target.
*
* @param signal the {@code Signal} to enforce based in the {@code policyEnforcer}.
*/
Expand Down Expand Up @@ -326,8 +323,9 @@ private CompletionStage<Signal<?>> doEnforceSignal(final S signal, final ActorRe
return null;
} else {
log.withCorrelationId(signal)
.warning("Neither authorizedSignal nor throwable were present during enforcement of signal: " +
"<{}>", signal);
.warning(
"Neither authorizedSignal nor throwable were present during enforcement of signal: " +
"<{}>", signal);
return null;
}
});
Expand Down Expand Up @@ -359,7 +357,8 @@ private void filterResponse(final R commandResponse) {
filteredResponseStage.whenComplete((filteredResponse, throwable) -> {
if (null != filteredResponse) {
log.withCorrelationId(filteredResponse)
.info("Completed filtering of command response type <{}>", filteredResponse.getType());
.info("Completed filtering of command response type <{}>",
filteredResponse.getType());
sender.tell(filteredResponse, parent);
} else if (null != throwable) {
final DittoRuntimeException dittoRuntimeException =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.signals.Signal;
import org.eclipse.ditto.internal.utils.namespaces.BlockedNamespaces;
import org.eclipse.ditto.internal.utils.persistentactors.AbstractEnforcerActor;
import org.eclipse.ditto.policies.enforcement.AbstractEnforcerActor;
import org.eclipse.ditto.policies.api.commands.sudo.SudoRetrievePolicy;
import org.eclipse.ditto.policies.api.commands.sudo.SudoRetrievePolicyResponse;
import org.eclipse.ditto.policies.enforcement.PolicyEnforcer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.eclipse.ditto.internal.utils.cacheloaders.EnforcementCacheKey;
import org.eclipse.ditto.internal.utils.cacheloaders.config.AskWithRetryConfig;
import org.eclipse.ditto.internal.utils.namespaces.BlockedNamespaces;
import org.eclipse.ditto.internal.utils.persistentactors.AbstractEnforcerActor;
import org.eclipse.ditto.policies.enforcement.AbstractEnforcerActor;
import org.eclipse.ditto.json.JsonFieldSelector;
import org.eclipse.ditto.policies.enforcement.PolicyEnforcer;
import org.eclipse.ditto.policies.enforcement.PolicyEnforcerCacheLoader;
Expand Down

0 comments on commit e100846

Please sign in to comment.