Skip to content

Commit

Permalink
Delete Metadata.origin.
Browse files Browse the repository at this point in the history
Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
  • Loading branch information
yufei-cai committed Apr 7, 2022
1 parent 5db44f3 commit 00618b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
import org.eclipse.ditto.json.JsonValue;
import org.eclipse.ditto.policies.model.Policy;
import org.eclipse.ditto.policies.model.PolicyId;
import org.eclipse.ditto.policies.model.ResourceKey;
import org.eclipse.ditto.things.model.Thing;
import org.eclipse.ditto.things.model.ThingId;
import org.eclipse.ditto.things.model.signals.commands.ThingCommand;
import org.eclipse.ditto.thingsearch.api.UpdateReason;
import org.eclipse.ditto.thingsearch.service.persistence.PersistenceConstants;
import org.eclipse.ditto.thingsearch.service.persistence.write.model.Metadata;
Expand Down Expand Up @@ -105,14 +103,13 @@ public static ThingWriteModel toWriteModel(final JsonObject thing,
final long thingRevision = thing.getValueOrThrow(Thing.JsonFields.REVISION);
final var nullablePolicyId = thing.getValue(Thing.JsonFields.POLICY_ID).map(PolicyId::of).orElse(null);
final var metadata = Metadata.of(thingId, thingRevision, nullablePolicyId, policyRevision,
Optional.ofNullable(oldMetadata).flatMap(Metadata::getModified).orElse(null),
Optional.ofNullable(oldMetadata).map(Metadata::getEvents).orElse(List.of()),
Optional.ofNullable(oldMetadata).map(Metadata::getTimers).orElse(List.of()),
Optional.ofNullable(oldMetadata).map(Metadata::getSenders).orElse(List.of()),
Optional.ofNullable(oldMetadata).flatMap(Metadata::getOrigin).orElse(null),
Optional.ofNullable(oldMetadata).map(Metadata::getUpdateReasons)
.orElse(List.of(UpdateReason.UNKNOWN))
);
Optional.ofNullable(oldMetadata).flatMap(Metadata::getModified).orElse(null),
Optional.ofNullable(oldMetadata).map(Metadata::getEvents).orElse(List.of()),
Optional.ofNullable(oldMetadata).map(Metadata::getTimers).orElse(List.of()),
Optional.ofNullable(oldMetadata).map(Metadata::getSenders).orElse(List.of()),
Optional.ofNullable(oldMetadata).map(Metadata::getUpdateReasons)
.orElse(List.of(UpdateReason.UNKNOWN))
);

return ThingWriteModel.of(metadata, toBsonDocument(thing, policy, metadata));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public final class Metadata {
private final List<ActorRef> senders;
private final boolean invalidateThing;
private final boolean invalidatePolicy;
@Nullable private final ActorRef origin;
private final List<UpdateReason> updateReasons;

private Metadata(final ThingId thingId,
Expand All @@ -65,7 +64,6 @@ private Metadata(final ThingId thingId,
final Collection<ActorRef> senders,
final boolean invalidateThing,
final boolean invalidatePolicy,
@Nullable final ActorRef origin,
final Collection<UpdateReason> updateReasons) {

this.thingId = thingId;
Expand All @@ -78,7 +76,6 @@ private Metadata(final ThingId thingId,
this.senders = List.copyOf(senders);
this.invalidateThing = invalidateThing;
this.invalidatePolicy = invalidatePolicy;
this.origin = origin;
this.updateReasons = List.copyOf(updateReasons);
}

Expand All @@ -99,7 +96,7 @@ public static Metadata of(final ThingId thingId,
@Nullable final StartedTimer timer) {

return new Metadata(thingId, thingRevision, policyId, policyRevision, null,
List.of(), null != timer ? List.of(timer) : List.of(), List.of(), false, false, null,
List.of(), null != timer ? List.of(timer) : List.of(), List.of(), false, false,
List.of(UpdateReason.UNKNOWN));
}

Expand All @@ -124,7 +121,7 @@ public static Metadata of(final ThingId thingId,

return new Metadata(thingId, thingRevision, policyId, policyRevision, null, events,
null != timer ? List.of(timer) : List.of(),
null != sender ? List.of(sender) : List.of(), false, false, null, List.of(UpdateReason.UNKNOWN));
null != sender ? List.of(sender) : List.of(), false, false, List.of(UpdateReason.UNKNOWN));
}

/**
Expand All @@ -138,7 +135,6 @@ public static Metadata of(final ThingId thingId,
* @param events the events included in the metadata causing the search update.
* @param timers the timers measuring the search updater's consistency lag.
* @param senders the senders.
* @param origin the origin.
* @param updateReasons the update reasons.
* @return the new Metadata object.
*/
Expand All @@ -150,11 +146,10 @@ public static Metadata of(final ThingId thingId,
final List<ThingEvent<?>> events,
final Collection<StartedTimer> timers,
final Collection<ActorRef> senders,
@Nullable final ActorRef origin,
final Collection<UpdateReason> updateReasons) {

return new Metadata(thingId, thingRevision, policyId, policyRevision, modified, events, timers, senders,
false, false, origin, updateReasons);
false, false, updateReasons);
}

/**
Expand All @@ -176,7 +171,7 @@ public static Metadata of(final ThingId thingId,
@Nullable final StartedTimer timer) {

return new Metadata(thingId, thingRevision, policyId, policyRevision, modified,
List.of(), null != timer ? List.of(timer) : List.of(), List.of(), false, false, null,
List.of(), null != timer ? List.of(timer) : List.of(), List.of(), false, false,
List.of(UpdateReason.UNKNOWN));
}

Expand Down Expand Up @@ -221,17 +216,7 @@ public Metadata export() {
*/
public Metadata invalidateCaches(final boolean invalidateThing, final boolean invalidatePolicy) {
return new Metadata(thingId, thingRevision, policyId, policyRevision, modified, events, timers, senders,
invalidateThing, invalidatePolicy, origin, updateReasons);
}

/**
* Create a copy of this metadata with origin.
*
* @return the copy.
*/
public Metadata withOrigin(@Nullable final ActorRef origin) {
return new Metadata(thingId, thingRevision, policyId, policyRevision, modified, events, timers, senders,
invalidateThing, invalidatePolicy, origin, updateReasons);
invalidateThing, invalidatePolicy, updateReasons);
}

/**
Expand All @@ -241,7 +226,7 @@ public Metadata withOrigin(@Nullable final ActorRef origin) {
*/
public Metadata withSender(final ActorRef sender) {
return new Metadata(thingId, thingRevision, policyId, policyRevision, modified, events, timers, List.of(sender),
invalidateThing, invalidatePolicy, origin, updateReasons);
invalidateThing, invalidatePolicy, updateReasons);
}

/**
Expand All @@ -251,16 +236,7 @@ public Metadata withSender(final ActorRef sender) {
*/
public Metadata withUpdateReason(final UpdateReason reason) {
return new Metadata(thingId, thingRevision, policyId, policyRevision, modified, events, timers, senders,
invalidateThing, invalidatePolicy, origin, List.of(reason));
}

/**
* Return the ThingUpdater that created this object, if any.
*
* @return The ThingUpdater.
*/
public Optional<ActorRef> getOrigin() {
return Optional.ofNullable(origin);
invalidateThing, invalidatePolicy, List.of(reason));
}

/**
Expand Down Expand Up @@ -410,7 +386,7 @@ public Metadata append(final Metadata newMetadata) {
newMetadata.policyRevision, newMetadata.modified, newEvents, newTimers, newSenders,
invalidateThing || newMetadata.invalidateThing,
invalidatePolicy || newMetadata.invalidatePolicy,
newMetadata.origin, newReasons);
newReasons);
}

/**
Expand Down Expand Up @@ -466,14 +442,13 @@ public boolean equals(final Object o) {
Objects.equals(senders, that.senders) &&
invalidateThing == that.invalidateThing &&
invalidatePolicy == that.invalidatePolicy &&
Objects.equals(origin, that.origin) &&
Objects.equals(updateReasons, that.updateReasons);
}

@Override
public int hashCode() {
return Objects.hash(thingId, thingRevision, policyId, policyRevision, modified, events, timers, senders,
invalidateThing, invalidatePolicy, origin, updateReasons);
invalidateThing, invalidatePolicy, updateReasons);
}

@Override
Expand All @@ -489,7 +464,6 @@ public String toString() {
", senders=" + senders +
", invalidateThing=" + invalidateThing +
", invalidatePolicy=" + invalidatePolicy +
", origin=" + origin +
", updateReasons=" + updateReasons +
"]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,9 @@ private static void reportIncorrectPatch(final WriteResultAndErrors writeResultA
writeResultAndErrors.getWriteModels().forEach(model -> {
if (model.isPatchUpdate()) {
final var abstractModel = model.getDitto();
final var response =
createFailureResponse(abstractModel.getMetadata(), INCORRECT_PATCH_HEADERS.toBuilder()
.correlationId(writeResultAndErrors.getBulkWriteCorrelationId()).build());
LOGGER.withCorrelationId(writeResultAndErrors.getBulkWriteCorrelationId())
.warn("Encountered incorrect patch update for metadata: <{}> and filter: <{}>",
abstractModel.getMetadata(), abstractModel.getFilter());
abstractModel.getMetadata()
.getOrigin()
.ifPresent(updater -> updater.tell(response, ActorRef.noSender()));
} else {
LOGGER.withCorrelationId(writeResultAndErrors.getBulkWriteCorrelationId())
.info("Skipping retry of full update in a batch with an incorrect patch: <{}>",
Expand Down

0 comments on commit 00618b8

Please sign in to comment.