-
Notifications
You must be signed in to change notification settings - Fork 231
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
add new wot-models definition update endpoint #1843 #2103
base: master
Are you sure you want to change the base?
add new wot-models definition update endpoint #1843 #2103
Conversation
aed41df
to
5d5b2f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @hu-ahmed and thanks a lot for providing this PR.
Looks already really promising .. I did a quick check and left a few comments before going deeper :)
...entation/src/main/resources/openapi/sources/schemas/things/migrateThingDefinitionRequest.yml
Show resolved
Hide resolved
...main/java/org/eclipse/ditto/things/model/signals/commands/modify/MigrateThingDefinition.java
Show resolved
Hide resolved
...main/java/org/eclipse/ditto/things/model/signals/commands/modify/MigrateThingDefinition.java
Show resolved
Hide resolved
...main/java/org/eclipse/ditto/things/model/signals/commands/modify/MigrateThingDefinition.java
Show resolved
Hide resolved
...main/java/org/eclipse/ditto/things/model/signals/commands/modify/MigrateThingDefinition.java
Show resolved
Hide resolved
...to/things/service/persistence/actors/strategies/commands/MigrateThingDefinitionStrategy.java
Show resolved
Hide resolved
...to/things/service/persistence/actors/strategies/commands/MigrateThingDefinitionStrategy.java
Show resolved
Hide resolved
...to/things/service/persistence/actors/strategies/commands/MigrateThingDefinitionStrategy.java
Show resolved
Hide resolved
...to/things/service/persistence/actors/strategies/commands/MigrateThingDefinitionStrategy.java
Show resolved
Hide resolved
...to/things/service/persistence/actors/strategies/commands/MigrateThingDefinitionStrategy.java
Show resolved
Hide resolved
...to/things/service/persistence/actors/strategies/commands/MigrateThingDefinitionStrategy.java
Show resolved
Hide resolved
ThingsModelFactory.newDefinition(command.getThingDefinitionUrl()), | ||
dittoHeaders | ||
) | ||
.thenApply(optionalSkeleton -> optionalSkeleton.orElseThrow()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orElseThrow
is not good here .. it will throw an IllegalArgumentException
which will not contain any useful information about why this failed.
I would suggest to throw a more meaningful subclass of WotException
, also maintaining dittoHeaders
to have proper propagation of correlation-id, trace, etc.
...to/things/service/persistence/actors/strategies/commands/MigrateThingDefinitionStrategy.java
Show resolved
Hide resolved
...to/things/service/persistence/actors/strategies/commands/MigrateThingDefinitionStrategy.java
Show resolved
Hide resolved
...to/things/service/persistence/actors/strategies/commands/MigrateThingDefinitionStrategy.java
Show resolved
Hide resolved
...to/things/service/persistence/actors/strategies/commands/MigrateThingDefinitionStrategy.java
Show resolved
Hide resolved
* before persisting changes. | ||
*/ | ||
@Immutable | ||
public final class MigrateThingDefinitionStrategy extends AbstractThingModifyCommandStrategy<MigrateThingDefinition> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test is missing for this strategy class.
...to/things/service/persistence/actors/strategies/commands/MigrateThingDefinitionStrategy.java
Show resolved
Hide resolved
this.thingDefinitionUrl = checkNotNull(thingDefinitionUrl, "thingDefinitionUrl"); | ||
this.migrationPayload = checkJsonSize(checkNotNull(migrationPayload, "migrationPayload"), dittoHeaders); | ||
this.patchConditions = | ||
Collections.unmodifiableMap(patchConditions != null ? patchConditions : Collections.emptyMap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this parameter patchConditions
is not marked as @Nullable
and (I think) cannot be null
from the code flow.
So no need to check for null ..
final MergeThingStrategy mergeStrategy = new MergeThingStrategy(context.getActorSystem()); | ||
final Result<ThingEvent<?>> mergeResult = mergeStrategy.doApply( | ||
context, | ||
existingThing, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why apply the mergeStrategy for the existingThing
here?
I would expect the updatedThing
.
So currently this e.g. validates the old, existingThing (as part of the MergeThingStrategy) against the WoT model instead of the new one.
#1843
The migrateThingDefinition endpoint introduces a comprehensive mechanism for migrating a Thing's definition while ensuring data consistency and applying necessary migrations. This endpoint is designed to facilitate seamless updates by incorporating a structured approach to definition changes and migration payloads.
Key Features:
Definition Update with Skeleton Generation:
The provided Thing definition URL is used to generate a new skeleton Thing, which serves as the baseline for the update.
The skeleton includes a hierarchical representation of the Thing, ensuring consistency with the WoT model.
Patch Condition Evaluation:
The migration payload can include multiple patch conditions, evaluated using RQL-based expressions to determine whether specific updates should be applied.
This allows for conditional updates based on existing Thing attributes or feature values.
Merging Strategy:
The update process merges the newly generated skeleton with the existing Thing while preserving essential attributes and properties.
An optional initialization step applies default values from the skeleton to fill in missing or incomplete properties.
Migration Payload Application:
The provided migration payload is selectively merged into the updated Thing, allowing for targeted modifications without overriding all properties.
Ensures data integrity by applying only necessary changes based on predefined rules.
Validation and Persistence:
Before finalizing the update, the modified Thing undergoes WoT model validation based on the current configuration, so either it will be rejected or logged as warning in case of inconsistency.
API Usage:
Endpoint:
POST /api/2/things/{thingId}/migrateDefinition
Request Body: