Repository navigation
feat(os-update): delivery type for the install command CU-17tkuw67mjh #3352
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
Merged
+193
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...data-nats/src/main/java/com/openframe/data/nats/delivery/OsUpdateInstallDeliverySeed.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.openframe.data.nats.delivery; | ||
|
|
||
| import com.openframe.data.document.delivery.DeliveryType; | ||
| import com.openframe.delivery.spec.DeliverySeed; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| public class OsUpdateInstallDeliverySeed implements DeliverySeed { | ||
|
|
||
| private final String machineId; | ||
| private final String requestId; | ||
| private final List<String> identifiers; | ||
|
|
||
| @Override | ||
| public DeliveryType getType() { | ||
| return DeliveryType.OS_UPDATE_INSTALL; | ||
| } | ||
|
|
||
| @Override | ||
| public String getTargetId() { | ||
| return requestId; | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
...data-nats/src/main/java/com/openframe/data/nats/delivery/OsUpdateInstallDeliverySpec.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package com.openframe.data.nats.delivery; | ||
|
|
||
| import com.openframe.data.document.delivery.DeliveryType; | ||
| import com.openframe.data.nats.rmm.model.OsUpdateInstallMessage; | ||
| import com.openframe.delivery.spec.DeliveryRequest; | ||
| import com.openframe.delivery.spec.DeliverySpec; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import static java.lang.String.format; | ||
|
|
||
| // One command per device and request, with every update the device has to install by it. | ||
| @Component | ||
| @ConditionalOnProperty("spring.cloud.stream.enabled") | ||
| public class OsUpdateInstallDeliverySpec implements DeliverySpec<OsUpdateInstallDeliverySeed, OsUpdateInstallMessage> { | ||
|
|
||
| private static final String SUBJECT_TEMPLATE = "machine.%s.os-update-install"; | ||
|
|
||
| @Override | ||
| public DeliveryType getType() { | ||
| return DeliveryType.OS_UPDATE_INSTALL; | ||
| } | ||
|
|
||
| @Override | ||
| public Class<OsUpdateInstallMessage> getPayloadClass() { | ||
| return OsUpdateInstallMessage.class; | ||
| } | ||
|
|
||
| @Override | ||
| public DeliveryRequest<OsUpdateInstallMessage> request(OsUpdateInstallDeliverySeed seed) { | ||
| OsUpdateInstallMessage message = OsUpdateInstallMessage.builder() | ||
| .requestId(seed.getRequestId()) | ||
| .identifiers(seed.getIdentifiers()) | ||
| .build(); | ||
| return DeliveryRequest.<OsUpdateInstallMessage>builder() | ||
| .type(DeliveryType.OS_UPDATE_INSTALL) | ||
| .targetId(seed.getTargetId()) | ||
| .machineId(seed.getMachineId()) | ||
| .payload(message) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public String subject(String machineId) { | ||
| return format(SUBJECT_TEMPLATE, machineId); | ||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
...ame-data-nats/src/main/java/com/openframe/data/nats/rmm/model/OsUpdateInstallMessage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.openframe.data.nats.rmm.model; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.openframe.delivery.spec.DeliveryPayload; | ||
| import com.openframe.delivery.spec.DeliveryRef; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| // WARNING: the agent answers DONE on machine.<id>.delivery.result once it has written the command down, not once | ||
| // the updates are installed: the outcome of each update is not a result of the delivery. | ||
| @Data | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public class OsUpdateInstallMessage implements DeliveryPayload { | ||
|
|
||
| private DeliveryRef delivery; | ||
| private String requestId; | ||
| // OsUpdate.identifier of every update the device has to install by this command. | ||
| private List<String> identifiers; | ||
| } |
89 changes: 89 additions & 0 deletions
89
...-nats/src/test/java/com/openframe/data/nats/delivery/OsUpdateInstallDeliverySpecTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package com.openframe.data.nats.delivery; | ||
|
|
||
| import com.openframe.data.document.delivery.DeliveryType; | ||
| import com.openframe.data.nats.rmm.model.OsUpdateInstallMessage; | ||
| import com.openframe.delivery.spec.DeliveryRef; | ||
| import com.openframe.delivery.spec.DeliveryRequest; | ||
| import org.junit.jupiter.api.Test; | ||
| import tools.jackson.databind.JsonNode; | ||
| import tools.jackson.databind.json.JsonMapper; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class OsUpdateInstallDeliverySpecTest { | ||
|
|
||
| private static final String MACHINE_ID = "m-1"; | ||
| private static final String REQUEST_ID = "req-1"; | ||
| private static final String CUMULATIVE_UPDATE = "a1b2c3d4-0000-4444-8888-99aabbccddee:201"; | ||
| private static final String DEFENDER_UPDATE = "ffeeddcc-1111-2222-3333-445566778899:198"; | ||
|
|
||
| private final OsUpdateInstallDeliverySpec spec = new OsUpdateInstallDeliverySpec(); | ||
| private final JsonMapper mapper = new JsonMapper(); | ||
|
|
||
| @Test | ||
| void typePayloadAndSubject_installCommandOfOneMachine() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use the three-part test name here, e.g. |
||
| // setup | ||
|
|
||
| // execution | ||
| DeliveryType type = spec.getType(); | ||
| Class<OsUpdateInstallMessage> payloadClass = spec.getPayloadClass(); | ||
| String subject = spec.subject(MACHINE_ID); | ||
| boolean deliversToEveryMachine = spec.canDeliverToEveryMachine(); | ||
|
|
||
| // verifications | ||
| assertThat(type).isEqualTo(DeliveryType.OS_UPDATE_INSTALL); | ||
| assertThat(payloadClass).isEqualTo(OsUpdateInstallMessage.class); | ||
| assertThat(subject).isEqualTo("machine.m-1.os-update-install"); | ||
| assertThat(deliversToEveryMachine).isFalse(); | ||
| } | ||
|
|
||
| @Test | ||
| void request_seedWithTwoUpdates_oneCommandOfTheRequestWithBothAndNoDeliveryBlock() { | ||
| // setup | ||
| OsUpdateInstallDeliverySeed seed = OsUpdateInstallDeliverySeed.builder() | ||
| .machineId(MACHINE_ID) | ||
| .requestId(REQUEST_ID) | ||
| .identifiers(List.of(CUMULATIVE_UPDATE, DEFENDER_UPDATE)) | ||
| .build(); | ||
|
|
||
| // execution | ||
| DeliveryRequest<OsUpdateInstallMessage> request = spec.request(seed); | ||
|
|
||
| // verifications | ||
| assertThat(request.getType()).isEqualTo(DeliveryType.OS_UPDATE_INSTALL); | ||
| assertThat(request.getTargetId()).isEqualTo(REQUEST_ID); | ||
| assertThat(request.getMachineId()).isEqualTo(MACHINE_ID); | ||
| assertThat(request.isForEveryMachine()).isFalse(); | ||
| assertThat(request.getDueAt()).isNull(); | ||
| assertThat(request.getOfflineBehavior()).isNull(); | ||
| assertThat(request.getReconnectWindowSeconds()).isNull(); | ||
| OsUpdateInstallMessage payload = request.getPayload(); | ||
| assertThat(payload.getRequestId()).isEqualTo(REQUEST_ID); | ||
| assertThat(payload.getIdentifiers()).containsExactly(CUMULATIVE_UPDATE, DEFENDER_UPDATE); | ||
| assertThat(payload.getDelivery()).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void message_onTheWire_requestIdIdentifiersAndTheDeliveryBlockTheAgentCopiesBack() { | ||
| // setup | ||
| OsUpdateInstallMessage message = OsUpdateInstallMessage.builder() | ||
| .delivery(new DeliveryRef(DeliveryType.OS_UPDATE_INSTALL, REQUEST_ID, "disp-1")) | ||
| .requestId(REQUEST_ID) | ||
| .identifiers(List.of(CUMULATIVE_UPDATE, DEFENDER_UPDATE)) | ||
| .build(); | ||
|
|
||
| // execution | ||
| JsonNode json = mapper.readTree(mapper.writeValueAsString(message)); | ||
|
|
||
| // verifications | ||
| assertThat(json.propertyNames()).containsExactlyInAnyOrder("delivery", "requestId", "identifiers"); | ||
| assertThat(json.get("requestId").asString()).isEqualTo(REQUEST_ID); | ||
| assertThat(json.get("identifiers")).extracting(JsonNode::asString) | ||
| .containsExactly(CUMULATIVE_UPDATE, DEFENDER_UPDATE); | ||
| assertThat(json.get("delivery").get("type").asString()).isEqualTo("OS_UPDATE_INSTALL"); | ||
| assertThat(json.get("delivery").get("targetId").asString()).isEqualTo(REQUEST_ID); | ||
| assertThat(json.get("delivery").get("dispatchId").asString()).isEqualTo("disp-1"); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could we use short class Javadocs for the seed, spec, and message? That would keep the one-command-per-device-and-request contract and the meaning of
DONEwhere callers can find them.