From 7fa2687862340cde3a80bfe13966c607e447992d Mon Sep 17 00:00:00 2001 From: Andrii Koropets Date: Tue, 27 Oct 2026 15:42:28 +0200 Subject: [PATCH 1/4] Added graphql for update --- .../software/CreateSoftwareScheduleInput.java | 6 + .../software/PackageUpdateSettingsInput.java | 23 ++++ .../rmm/software/SoftwareAutoUpdateInput.java | 15 +++ .../rmm/software/SoftwareBundleResponse.java | 4 + .../software/SoftwareScheduleResponse.java | 4 + .../software/SubmitSoftwareBundleInput.java | 6 + .../software/UpdateSoftwareScheduleInput.java | 6 + .../software/PackageUpdateSettingsMapper.java | 63 +++++++++ .../rmm/software/SoftwareBundleService.java | 15 ++- .../rmm/software/SoftwareScheduleService.java | 5 + .../PackageUpdateSettingsMapperTest.java | 123 ++++++++++++++++++ .../software/SoftwareBundleServiceTest.java | 81 ++++++++++++ .../resources/schema/software-bundle.graphqls | 11 +- .../schema/software-schedule.graphqls | 12 ++ .../main/resources/schema/software.graphqls | 40 ++++++ .../software/SoftwareScheduleServiceTest.java | 72 ++++++++++ .../rmm/schedule/SoftwareSchedule.java | 5 + .../rmm/software/PackageUpdateSettings.java | 19 +++ .../rmm/software/SoftwareAutoUpdate.java | 17 +++ .../document/rmm/software/SoftwareBundle.java | 2 + 20 files changed, 526 insertions(+), 3 deletions(-) create mode 100644 openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/PackageUpdateSettingsInput.java create mode 100644 openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareAutoUpdateInput.java create mode 100644 openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/PackageUpdateSettingsMapper.java create mode 100644 openframe-api-lib/src/test/java/com/openframe/api/service/rmm/software/PackageUpdateSettingsMapperTest.java create mode 100644 openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/PackageUpdateSettings.java create mode 100644 openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareAutoUpdate.java diff --git a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/CreateSoftwareScheduleInput.java b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/CreateSoftwareScheduleInput.java index 141ade8764..de7a1f24a7 100644 --- a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/CreateSoftwareScheduleInput.java +++ b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/CreateSoftwareScheduleInput.java @@ -39,4 +39,10 @@ public class CreateSoftwareScheduleInput { private Long repeat; private List machineIds; + + @Valid + private PackageUpdateSettingsInput updateSettings; + + @Valid + private SoftwareAutoUpdateInput autoUpdate; } diff --git a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/PackageUpdateSettingsInput.java b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/PackageUpdateSettingsInput.java new file mode 100644 index 0000000000..6fbff4d20a --- /dev/null +++ b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/PackageUpdateSettingsInput.java @@ -0,0 +1,23 @@ +package com.openframe.api.dto.rmm.software; + +import com.openframe.data.document.rmm.software.PackageUpdateMode; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Positive; +import lombok.Data; + +@Data +public class PackageUpdateSettingsInput { + + @NotNull + private PackageUpdateMode mode; + + @Positive(message = "deadlineSeconds must be positive") + @Max(value = 2_592_000, message = "deadlineSeconds must not exceed 30 days") + private Long deadlineSeconds; + + @NotNull + @Positive(message = "countdownSeconds must be positive") + @Max(value = 3_600, message = "countdownSeconds must not exceed 1 hour") + private Integer countdownSeconds; +} diff --git a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareAutoUpdateInput.java b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareAutoUpdateInput.java new file mode 100644 index 0000000000..d229d9fd39 --- /dev/null +++ b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareAutoUpdateInput.java @@ -0,0 +1,15 @@ +package com.openframe.api.dto.rmm.software; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +public class SoftwareAutoUpdateInput { + + @NotNull + private Boolean enabled; + + @Valid + private PackageUpdateSettingsInput settings; +} diff --git a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareBundleResponse.java b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareBundleResponse.java index 8a2bd2669a..e5f2459ea5 100644 --- a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareBundleResponse.java +++ b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareBundleResponse.java @@ -1,6 +1,8 @@ package com.openframe.api.dto.rmm.software; +import com.openframe.data.document.rmm.software.PackageUpdateSettings; import com.openframe.data.document.rmm.software.SoftwareAction; +import com.openframe.data.document.rmm.software.SoftwareAutoUpdate; import com.openframe.data.document.rmm.software.SoftwareBundleMode; import com.openframe.data.document.rmm.software.SoftwareBundlePackage; import com.openframe.data.document.rmm.software.SoftwareBundleStatus; @@ -20,6 +22,8 @@ public class SoftwareBundleResponse { private SoftwareBundleStatus status; private List machineIds; private List packages; + private PackageUpdateSettings updateSettings; + private SoftwareAutoUpdate autoUpdate; private Instant startAt; private String scheduleId; private String createdBy; diff --git a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareScheduleResponse.java b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareScheduleResponse.java index 7b53544682..a36b58eb83 100644 --- a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareScheduleResponse.java +++ b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareScheduleResponse.java @@ -7,7 +7,9 @@ import com.openframe.data.document.rmm.schedule.ScheduleTimeReference; import com.openframe.data.document.rmm.schedule.SoftwareSchedulePackage; import com.openframe.data.document.rmm.script.ScriptStatus; +import com.openframe.data.document.rmm.software.PackageUpdateSettings; import com.openframe.data.document.rmm.software.SoftwareAction; +import com.openframe.data.document.rmm.software.SoftwareAutoUpdate; import lombok.Builder; import lombok.Data; @@ -23,6 +25,8 @@ public class SoftwareScheduleResponse { private String description; private SoftwareAction action; private List packages; + private PackageUpdateSettings updateSettings; + private SoftwareAutoUpdate autoUpdate; private ScheduleDeviceSelectionMode selectionMode; private ScheduleDeviceCriteria deviceCriteria; private ScheduleScriptTrigger trigger; diff --git a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SubmitSoftwareBundleInput.java b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SubmitSoftwareBundleInput.java index 3dd1b3d581..971662c319 100644 --- a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SubmitSoftwareBundleInput.java +++ b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SubmitSoftwareBundleInput.java @@ -25,4 +25,10 @@ public class SubmitSoftwareBundleInput { @Valid private SoftwareBundleScheduleInput schedule; + + @Valid + private PackageUpdateSettingsInput updateSettings; + + @Valid + private SoftwareAutoUpdateInput autoUpdate; } diff --git a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/UpdateSoftwareScheduleInput.java b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/UpdateSoftwareScheduleInput.java index 717fab26ff..3ecc6bc77f 100644 --- a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/UpdateSoftwareScheduleInput.java +++ b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/UpdateSoftwareScheduleInput.java @@ -42,4 +42,10 @@ public class UpdateSoftwareScheduleInput { private Long repeat; private List machineIds; + + @Valid + private PackageUpdateSettingsInput updateSettings; + + @Valid + private SoftwareAutoUpdateInput autoUpdate; } diff --git a/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/PackageUpdateSettingsMapper.java b/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/PackageUpdateSettingsMapper.java new file mode 100644 index 0000000000..ba4c68983b --- /dev/null +++ b/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/PackageUpdateSettingsMapper.java @@ -0,0 +1,63 @@ +package com.openframe.api.service.rmm.software; + +import com.openframe.api.dto.rmm.software.PackageUpdateSettingsInput; +import com.openframe.api.dto.rmm.software.SoftwareAutoUpdateInput; +import com.openframe.core.exception.BadRequestException; +import com.openframe.data.document.rmm.software.PackageUpdateMode; +import com.openframe.data.document.rmm.software.PackageUpdateSettings; +import com.openframe.data.document.rmm.software.SoftwareAction; +import com.openframe.data.document.rmm.software.SoftwareAutoUpdate; +import lombok.experimental.UtilityClass; + +import java.time.Duration; + +@UtilityClass +public class PackageUpdateSettingsMapper { + + static final long DEFAULT_DEADLINE_SECONDS = Duration.ofDays(7).toSeconds(); + static final int DEFAULT_COUNTDOWN_SECONDS = (int) Duration.ofMinutes(5).toSeconds(); + + public PackageUpdateSettings updateSettings(SoftwareAction action, PackageUpdateSettingsInput input) { + if (action != SoftwareAction.UPDATE) { + rejectOutsideUpdate(input, "updateSettings"); + return null; + } + return input == null ? defaults() : toDomain(input); + } + + public SoftwareAutoUpdate autoUpdate(SoftwareAction action, SoftwareAutoUpdateInput input) { + if (action != SoftwareAction.UPDATE) { + rejectOutsideUpdate(input, "autoUpdate"); + return null; + } + if (input == null || !input.getEnabled()) { + return SoftwareAutoUpdate.builder().enabled(false).build(); + } + PackageUpdateSettings settings = input.getSettings() == null ? null : toDomain(input.getSettings()); + return SoftwareAutoUpdate.builder().enabled(true).settings(settings).build(); + } + + private PackageUpdateSettings defaults() { + return PackageUpdateSettings.builder() + .mode(PackageUpdateMode.WAIT) + .deadlineSeconds(DEFAULT_DEADLINE_SECONDS) + .countdownSeconds(DEFAULT_COUNTDOWN_SECONDS) + .build(); + } + + private PackageUpdateSettings toDomain(PackageUpdateSettingsInput input) { + PackageUpdateMode mode = input.getMode(); + Long deadlineSeconds = mode == PackageUpdateMode.FORCE ? null : input.getDeadlineSeconds(); + return PackageUpdateSettings.builder() + .mode(mode) + .deadlineSeconds(deadlineSeconds) + .countdownSeconds(input.getCountdownSeconds()) + .build(); + } + + private void rejectOutsideUpdate(Object input, String field) { + if (input != null) { + throw new BadRequestException(field + " applies to UPDATE only: an app that is not installed yet cannot be running"); + } + } +} diff --git a/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareBundleService.java b/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareBundleService.java index 5e14fb7e85..1a435cd02c 100644 --- a/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareBundleService.java +++ b/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareBundleService.java @@ -14,6 +14,8 @@ import com.openframe.data.document.rmm.schedule.ScheduleOfflineBehavior; import com.openframe.data.document.rmm.schedule.ScheduleTimeReference; import com.openframe.data.document.rmm.script.OsType; +import com.openframe.data.document.rmm.software.PackageUpdateSettings; +import com.openframe.data.document.rmm.software.SoftwareAutoUpdate; import com.openframe.data.document.rmm.software.SoftwareBundle; import com.openframe.data.document.rmm.software.SoftwareBundleMode; import com.openframe.data.document.rmm.software.SoftwareBundleOnlineDispatch; @@ -134,15 +136,19 @@ public SoftwareBundleResponse submit(SubmitSoftwareBundleInput input, String act packageManagerAvailability.requireSoftwareManageable(machineIds, managers); Map deviceOsTypes = machinePlatformResolver.osTypesByMachineId(machineIds); rejectDevicesWithoutCompatiblePackage(machineIds, packages, deviceOsTypes); + PackageUpdateSettings updateSettings = PackageUpdateSettingsMapper.updateSettings(input.getAction(), input.getUpdateSettings()); + SoftwareAutoUpdate autoUpdate = PackageUpdateSettingsMapper.autoUpdate(input.getAction(), input.getAutoUpdate()); entity.setAction(input.getAction()); entity.setPackages(packages); + entity.setUpdateSettings(updateSettings); + entity.setAutoUpdate(autoUpdate); Instant now = Instant.now(); if (input.getSchedule() != null) { entity.setMode(SoftwareBundleMode.SCHEDULED); entity.setStartAt(input.getSchedule().getStartAt()); - submitScheduled(entity, input.getSchedule(), actor); + submitScheduled(entity, input, actor); } else { entity.setMode(SoftwareBundleMode.NOW); armOnlineDispatch(entity, now); @@ -250,7 +256,8 @@ private static OsType osTypeOf(PackageManagerType packageManager) { return packageManager == PackageManagerType.BREW ? OsType.MAC_OS : OsType.WINDOWS; } - private void submitScheduled(SoftwareBundle bundle, SoftwareBundleScheduleInput sched, String actor) { + private void submitScheduled(SoftwareBundle bundle, SubmitSoftwareBundleInput submit, String actor) { + SoftwareBundleScheduleInput sched = submit.getSchedule(); CreateSoftwareScheduleInput input = new CreateSoftwareScheduleInput(); input.setName(sched.getName() != null ? sched.getName() : scheduleName(bundle)); input.setDescription(sched.getDescription()); @@ -263,6 +270,8 @@ private void submitScheduled(SoftwareBundle bundle, SoftwareBundleScheduleInput input.setStartAt(sched.getStartAt()); input.setRepeat(sched.getRepeat()); input.setMachineIds(bundle.getMachineIds()); + input.setUpdateSettings(submit.getUpdateSettings()); + input.setAutoUpdate(submit.getAutoUpdate()); SoftwareScheduleResponse schedule = softwareScheduleService.create(input, actor); bundle.setScheduleId(schedule.getId()); @@ -361,6 +370,8 @@ private static SoftwareBundleResponse toResponse(SoftwareBundle b) { .status(b.getStatus()) .machineIds(b.getMachineIds() == null ? List.of() : b.getMachineIds()) .packages(b.getPackages() == null ? List.of() : b.getPackages()) + .updateSettings(b.getUpdateSettings()) + .autoUpdate(b.getAutoUpdate()) .startAt(b.getStartAt()) .scheduleId(b.getScheduleId()) .createdBy(b.getCreatedBy()) diff --git a/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareScheduleService.java b/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareScheduleService.java index 35cbb54195..fec3530dbb 100644 --- a/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareScheduleService.java +++ b/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareScheduleService.java @@ -66,6 +66,8 @@ public SoftwareScheduleResponse create(CreateSoftwareScheduleInput input, String .description(input.getDescription()) .action(input.getAction()) .packages(packages) + .updateSettings(PackageUpdateSettingsMapper.updateSettings(input.getAction(), input.getUpdateSettings())) + .autoUpdate(PackageUpdateSettingsMapper.autoUpdate(input.getAction(), input.getAutoUpdate())) .trigger(ScheduleScriptTrigger.DATE_TIME) .timeReference(timeReference) .offlineBehavior(input.getOfflineBehavior()) @@ -100,6 +102,8 @@ public SoftwareScheduleResponse update(UpdateSoftwareScheduleInput input, String entity.setDescription(input.getDescription()); entity.setAction(input.getAction()); entity.setPackages(packages); + entity.setUpdateSettings(PackageUpdateSettingsMapper.updateSettings(input.getAction(), input.getUpdateSettings())); + entity.setAutoUpdate(PackageUpdateSettingsMapper.autoUpdate(input.getAction(), input.getAutoUpdate())); entity.setTimeReference(timeReference); entity.setOfflineBehavior(input.getOfflineBehavior()); entity.setReconnectWindowSeconds(input.getReconnectWindowSeconds()); @@ -286,6 +290,7 @@ private SoftwareScheduleResponse toResponse(SoftwareSchedule s) { return SoftwareScheduleResponse.builder() .id(s.getId()).name(s.getName()).description(s.getDescription()) .action(s.getAction()).packages(s.getPackages()) + .updateSettings(s.getUpdateSettings()).autoUpdate(s.getAutoUpdate()) .selectionMode(s.getSelectionMode()).deviceCriteria(s.getDeviceCriteria()) .trigger(s.getTrigger()).timeReference(s.getTimeReference()) .offlineBehavior(s.getOfflineBehavior()).reconnectWindowSeconds(s.getReconnectWindowSeconds()) diff --git a/openframe-api-lib/src/test/java/com/openframe/api/service/rmm/software/PackageUpdateSettingsMapperTest.java b/openframe-api-lib/src/test/java/com/openframe/api/service/rmm/software/PackageUpdateSettingsMapperTest.java new file mode 100644 index 0000000000..47f5eb9cd0 --- /dev/null +++ b/openframe-api-lib/src/test/java/com/openframe/api/service/rmm/software/PackageUpdateSettingsMapperTest.java @@ -0,0 +1,123 @@ +package com.openframe.api.service.rmm.software; + +import com.openframe.api.dto.rmm.software.PackageUpdateSettingsInput; +import com.openframe.api.dto.rmm.software.SoftwareAutoUpdateInput; +import com.openframe.core.exception.BadRequestException; +import com.openframe.data.document.rmm.software.PackageUpdateMode; +import com.openframe.data.document.rmm.software.PackageUpdateSettings; +import com.openframe.data.document.rmm.software.SoftwareAction; +import com.openframe.data.document.rmm.software.SoftwareAutoUpdate; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class PackageUpdateSettingsMapperTest { + + @Test + @DisplayName("UPDATE without settings: the screen's defaults, wait, then a 5-minute countdown 7 days after the first try") + void updateSettings_updateWithoutSettings_screenDefaults() { + PackageUpdateSettings settings = PackageUpdateSettingsMapper.updateSettings(SoftwareAction.UPDATE, null); + + assertThat(settings.getMode()).isEqualTo(PackageUpdateMode.WAIT); + assertThat(settings.getDeadlineSeconds()).isEqualTo(604_800L); + assertThat(settings.getCountdownSeconds()).isEqualTo(300); + } + + @Test + @DisplayName("UPDATE, wait without a deadline: kept as given, the update waits for the user") + void updateSettings_waitWithoutDeadline_keptAsGiven() { + PackageUpdateSettings settings = PackageUpdateSettingsMapper.updateSettings(SoftwareAction.UPDATE, + settings(PackageUpdateMode.WAIT, null, 120)); + + assertThat(settings.getMode()).isEqualTo(PackageUpdateMode.WAIT); + assertThat(settings.getDeadlineSeconds()).isNull(); + assertThat(settings.getCountdownSeconds()).isEqualTo(120); + } + + @Test + @DisplayName("UPDATE, force: the deadline is dropped, a forced install closes the app at once") + void updateSettings_force_deadlineDropped() { + PackageUpdateSettings settings = PackageUpdateSettingsMapper.updateSettings(SoftwareAction.UPDATE, + settings(PackageUpdateMode.FORCE, 86_400L, 60)); + + assertThat(settings.getMode()).isEqualTo(PackageUpdateMode.FORCE); + assertThat(settings.getDeadlineSeconds()).isNull(); + assertThat(settings.getCountdownSeconds()).isEqualTo(60); + } + + @Test + @DisplayName("INSTALL: no settings, and settings sent with it are rejected") + void updateSettings_install_noneAndGivenRejected() { + assertThat(PackageUpdateSettingsMapper.updateSettings(SoftwareAction.INSTALL, null)).isNull(); + assertThatThrownBy(() -> PackageUpdateSettingsMapper.updateSettings(SoftwareAction.INSTALL, + settings(PackageUpdateMode.WAIT, null, 300))) + .isInstanceOf(BadRequestException.class) + .hasMessageContaining("updateSettings"); + } + + @Test + @DisplayName("UPDATE without auto-update: off") + void autoUpdate_updateWithoutInput_off() { + SoftwareAutoUpdate autoUpdate = PackageUpdateSettingsMapper.autoUpdate(SoftwareAction.UPDATE, null); + + assertThat(autoUpdate.isEnabled()).isFalse(); + assertThat(autoUpdate.getSettings()).isNull(); + } + + @Test + @DisplayName("auto-update on without settings: the same settings as the update") + void autoUpdate_enabledWithoutSettings_sameAsTheUpdate() { + SoftwareAutoUpdate autoUpdate = PackageUpdateSettingsMapper.autoUpdate(SoftwareAction.UPDATE, autoUpdate(true, null)); + + assertThat(autoUpdate.isEnabled()).isTrue(); + assertThat(autoUpdate.getSettings()).isNull(); + } + + @Test + @DisplayName("auto-update on with settings: its own settings, read by the same rules as the update's") + void autoUpdate_enabledWithSettings_ownSettings() { + SoftwareAutoUpdate autoUpdate = PackageUpdateSettingsMapper.autoUpdate(SoftwareAction.UPDATE, + autoUpdate(true, settings(PackageUpdateMode.FORCE, 3_600L, 30))); + + assertThat(autoUpdate.isEnabled()).isTrue(); + assertThat(autoUpdate.getSettings().getMode()).isEqualTo(PackageUpdateMode.FORCE); + assertThat(autoUpdate.getSettings().getDeadlineSeconds()).isNull(); + assertThat(autoUpdate.getSettings().getCountdownSeconds()).isEqualTo(30); + } + + @Test + @DisplayName("auto-update off: settings sent with it are dropped") + void autoUpdate_disabled_settingsDropped() { + SoftwareAutoUpdate autoUpdate = PackageUpdateSettingsMapper.autoUpdate(SoftwareAction.UPDATE, + autoUpdate(false, settings(PackageUpdateMode.WAIT, null, 300))); + + assertThat(autoUpdate.isEnabled()).isFalse(); + assertThat(autoUpdate.getSettings()).isNull(); + } + + @Test + @DisplayName("INSTALL: no auto-update, and auto-update sent with it is rejected") + void autoUpdate_install_noneAndGivenRejected() { + assertThat(PackageUpdateSettingsMapper.autoUpdate(SoftwareAction.INSTALL, null)).isNull(); + assertThatThrownBy(() -> PackageUpdateSettingsMapper.autoUpdate(SoftwareAction.INSTALL, autoUpdate(true, null))) + .isInstanceOf(BadRequestException.class) + .hasMessageContaining("autoUpdate"); + } + + private static PackageUpdateSettingsInput settings(PackageUpdateMode mode, Long deadlineSeconds, int countdownSeconds) { + PackageUpdateSettingsInput input = new PackageUpdateSettingsInput(); + input.setMode(mode); + input.setDeadlineSeconds(deadlineSeconds); + input.setCountdownSeconds(countdownSeconds); + return input; + } + + private static SoftwareAutoUpdateInput autoUpdate(boolean enabled, PackageUpdateSettingsInput settings) { + SoftwareAutoUpdateInput input = new SoftwareAutoUpdateInput(); + input.setEnabled(enabled); + input.setSettings(settings); + return input; + } +} diff --git a/openframe-api-lib/src/test/java/com/openframe/api/service/rmm/software/SoftwareBundleServiceTest.java b/openframe-api-lib/src/test/java/com/openframe/api/service/rmm/software/SoftwareBundleServiceTest.java index 384263ad3e..40f898ae44 100644 --- a/openframe-api-lib/src/test/java/com/openframe/api/service/rmm/software/SoftwareBundleServiceTest.java +++ b/openframe-api-lib/src/test/java/com/openframe/api/service/rmm/software/SoftwareBundleServiceTest.java @@ -1,12 +1,18 @@ package com.openframe.api.service.rmm.software; +import com.openframe.api.dto.rmm.software.CreateSoftwareScheduleInput; +import com.openframe.api.dto.rmm.software.PackageUpdateSettingsInput; +import com.openframe.api.dto.rmm.software.SoftwareAutoUpdateInput; import com.openframe.api.dto.rmm.software.SoftwareBundleResponse; +import com.openframe.api.dto.rmm.software.SoftwareBundleScheduleInput; import com.openframe.api.dto.rmm.software.SoftwarePackageInput; +import com.openframe.api.dto.rmm.software.SoftwareScheduleResponse; import com.openframe.api.dto.rmm.software.SubmitSoftwareBundleInput; import com.openframe.core.exception.BadRequestException; import com.openframe.data.document.packagesearch.BrewPackageType; import com.openframe.data.document.packagesearch.PackageManagerType; import com.openframe.data.document.rmm.script.OsType; +import com.openframe.data.document.rmm.software.PackageUpdateMode; import com.openframe.data.document.rmm.software.SoftwareAction; import com.openframe.data.document.rmm.software.SoftwareActionResult; import com.openframe.data.document.rmm.software.SoftwareActionStatus; @@ -201,6 +207,81 @@ void submit_brewNoType_rejected() { verify(bundleRepository, never()).save(any()); } + @Test + @DisplayName("submit UPDATE without settings: the screen's defaults are stored and returned, auto-update off") + void submit_update_defaultSettingsStoredAndReturned() { + SoftwareBundle draft = pending(SoftwareBundleMode.NOW, null, List.of("m1")); + when(bundleRepository.findByTenantIdAndId(TENANT, BUNDLE_ID)).thenReturn(Optional.of(draft)); + when(machinePlatformResolver.osTypesByMachineId(any())).thenReturn(java.util.Map.of("m1", OsType.MAC_OS)); + when(onlineDispatchRepository.findByTenantIdAndMachineIdAndBundleId(eq(TENANT), anyString(), eq(BUNDLE_ID))) + .thenReturn(Optional.empty()); + SubmitSoftwareBundleInput input = submitInput(brewPkg("slack")); + input.setAction(SoftwareAction.UPDATE); + + SoftwareBundleResponse res = service.submit(input, USER); + + ArgumentCaptor saved = ArgumentCaptor.forClass(SoftwareBundle.class); + verify(bundleRepository).save(saved.capture()); + assertThat(saved.getValue().getUpdateSettings()).satisfies(s -> { + assertThat(s.getMode()).isEqualTo(PackageUpdateMode.WAIT); + assertThat(s.getDeadlineSeconds()).isEqualTo(604_800L); + assertThat(s.getCountdownSeconds()).isEqualTo(300); + }); + assertThat(saved.getValue().getAutoUpdate().isEnabled()).isFalse(); + assertThat(res.getUpdateSettings()).isEqualTo(saved.getValue().getUpdateSettings()); + assertThat(res.getAutoUpdate()).isEqualTo(saved.getValue().getAutoUpdate()); + } + + @Test + @DisplayName("submit INSTALL with update settings: rejected before anything is saved or dispatched") + void submit_installWithUpdateSettings_rejectedNothingSaved() { + SoftwareBundle draft = pending(SoftwareBundleMode.NOW, null, List.of("m1")); + when(bundleRepository.findByTenantIdAndId(TENANT, BUNDLE_ID)).thenReturn(Optional.of(draft)); + when(machinePlatformResolver.osTypesByMachineId(any())).thenReturn(java.util.Map.of("m1", OsType.MAC_OS)); + SubmitSoftwareBundleInput input = submitInput(brewPkg("slack")); + input.setUpdateSettings(settingsInput(PackageUpdateMode.FORCE, null, 60)); + + assertThatThrownBy(() -> service.submit(input, USER)) + .isInstanceOf(BadRequestException.class) + .hasMessageContaining("updateSettings"); + verify(bundleRepository, never()).save(any()); + verifyNoInteractions(onlineDispatchRepository, softwareActionResultRepository, softwareScheduleService); + } + + @Test + @DisplayName("submit SCHEDULED UPDATE: the settings travel to the schedule it creates") + void submit_scheduledUpdate_settingsForwardedToTheSchedule() { + SoftwareBundle draft = pending(SoftwareBundleMode.NOW, null, List.of("m1")); + when(bundleRepository.findByTenantIdAndId(TENANT, BUNDLE_ID)).thenReturn(Optional.of(draft)); + when(machinePlatformResolver.osTypesByMachineId(any())).thenReturn(java.util.Map.of("m1", OsType.MAC_OS)); + when(softwareScheduleService.create(any(), eq(USER))).thenReturn(SoftwareScheduleResponse.builder().id("s1").build()); + SubmitSoftwareBundleInput input = submitInput(brewPkg("slack")); + input.setAction(SoftwareAction.UPDATE); + SoftwareBundleScheduleInput schedule = new SoftwareBundleScheduleInput(); + schedule.setStartAt(Instant.parse("2026-09-15T02:00:00Z")); + input.setSchedule(schedule); + PackageUpdateSettingsInput settings = settingsInput(PackageUpdateMode.WAIT, 86_400L, 120); + SoftwareAutoUpdateInput autoUpdate = new SoftwareAutoUpdateInput(); + autoUpdate.setEnabled(true); + input.setUpdateSettings(settings); + input.setAutoUpdate(autoUpdate); + + service.submit(input, USER); + + ArgumentCaptor created = ArgumentCaptor.forClass(CreateSoftwareScheduleInput.class); + verify(softwareScheduleService).create(created.capture(), eq(USER)); + assertThat(created.getValue().getUpdateSettings()).isSameAs(settings); + assertThat(created.getValue().getAutoUpdate()).isSameAs(autoUpdate); + } + + private static PackageUpdateSettingsInput settingsInput(PackageUpdateMode mode, Long deadlineSeconds, int countdownSeconds) { + PackageUpdateSettingsInput input = new PackageUpdateSettingsInput(); + input.setMode(mode); + input.setDeadlineSeconds(deadlineSeconds); + input.setCountdownSeconds(countdownSeconds); + return input; + } + private static SubmitSoftwareBundleInput submitInput(SoftwarePackageInput... packages) { SubmitSoftwareBundleInput input = new SubmitSoftwareBundleInput(); input.setId(BUNDLE_ID); diff --git a/openframe-api-service-core/src/main/resources/schema/software-bundle.graphqls b/openframe-api-service-core/src/main/resources/schema/software-bundle.graphqls index 9b536f9826..4e6948daea 100644 --- a/openframe-api-service-core/src/main/resources/schema/software-bundle.graphqls +++ b/openframe-api-service-core/src/main/resources/schema/software-bundle.graphqls @@ -67,9 +67,14 @@ input SubmitSoftwareBundleInput { packages: [SoftwarePackageInput!]! """Null: run now (Device-Online). Set: create a software schedule.""" schedule: SoftwareBundleScheduleInput + """UPDATE only, rejected for INSTALL. Null: wait & notify, a countdown 7 days after the first try, 5 minutes long.""" + updateSettings: PackageUpdateSettingsInput + """UPDATE only, rejected for INSTALL. Null: no auto-update.""" + autoUpdate: SoftwareAutoUpdateInput } -"""Same fields and rules as CreateSoftwareScheduleInput, minus action / packages / machineIds.""" +"""Same fields and rules as CreateSoftwareScheduleInput, minus action / packages / machineIds / updateSettings / +autoUpdate (those come with the submit itself).""" input SoftwareBundleScheduleInput { """Null: the server names it, e.g. "Install jq, wget".""" name: String @@ -92,6 +97,10 @@ type SoftwareBundle implements Node { mode: SoftwareBundleMode "Empty while PENDING; set by submit." packages: [SoftwareBundlePackage!]! + "How the update behaves on a device. Null for INSTALL and while PENDING." + updateSettings: PackageUpdateSettings + "Keep it auto-updated. Null for INSTALL and while PENDING." + autoUpdate: SoftwareAutoUpdate "Number of assigned devices." deviceCount: Int! diff --git a/openframe-api-service-core/src/main/resources/schema/software-schedule.graphqls b/openframe-api-service-core/src/main/resources/schema/software-schedule.graphqls index 0225e4a748..9612a956fa 100644 --- a/openframe-api-service-core/src/main/resources/schema/software-schedule.graphqls +++ b/openframe-api-service-core/src/main/resources/schema/software-schedule.graphqls @@ -57,6 +57,10 @@ type SoftwareSchedule implements Node { action: SoftwareAction! """The packages this schedule installs/updates.""" packages: [SoftwareSchedulePackage!]! + """How the update behaves on a device. Null for INSTALL.""" + updateSettings: PackageUpdateSettings + """Keep it auto-updated. Null for INSTALL.""" + autoUpdate: SoftwareAutoUpdate """How this schedule targets devices: SPECIFIC (an explicit machine set) or CRITERIA (a live rule; devices registered later that match are included automatically). Never null — legacy schedules read as SPECIFIC.""" selectionMode: ScheduleDeviceSelectionMode! @@ -145,6 +149,10 @@ input CreateSoftwareScheduleInput { repeat: Long "SPECIFIC target device ids (Machine global ids)." machineIds: [ID!] + "UPDATE only, rejected for INSTALL. Null: wait & notify, a countdown 7 days after the first try, 5 minutes long." + updateSettings: PackageUpdateSettingsInput + "UPDATE only, rejected for INSTALL. Null: no auto-update." + autoUpdate: SoftwareAutoUpdateInput } """Full-replacement (PUT) payload for an existing software schedule.""" @@ -161,4 +169,8 @@ input UpdateSoftwareScheduleInput { repeat: Long "Full replacement of the assigned device set (Machine global ids). Null leaves the assignment untouched." machineIds: [ID!] + "UPDATE only, rejected for INSTALL. Full replacement: null resets to the defaults (wait & notify, 7 days, 5 minutes)." + updateSettings: PackageUpdateSettingsInput + "UPDATE only, rejected for INSTALL. Full replacement: null turns auto-update off." + autoUpdate: SoftwareAutoUpdateInput } diff --git a/openframe-api-service-core/src/main/resources/schema/software.graphqls b/openframe-api-service-core/src/main/resources/schema/software.graphqls index d531c413e3..945dc03263 100644 --- a/openframe-api-service-core/src/main/resources/schema/software.graphqls +++ b/openframe-api-service-core/src/main/resources/schema/software.graphqls @@ -404,3 +404,43 @@ type SoftwareDispatchResult { packageName: String! executionId: String! } + +# ────────── Update settings (Update Software → "Update Settings" / "Auto-update") ────────── + +"""What an update does on a device where the app is running.""" +enum PackageUpdateMode { + "Wait & notify: the user gets Update now or Ask later; once they close the app, it updates." + WAIT + "Force install: the user gets a short countdown, then the app closes and updates." + FORCE +} + +"""How an update behaves on a device where the app is running. UPDATE only.""" +type PackageUpdateSettings { + mode: PackageUpdateMode! + "WAIT only: seconds after the first try before the countdown starts. Null = no deadline, the update waits." + deadlineSeconds: Long + "Seconds of countdown before the app is closed: after the deadline (WAIT) or right away (FORCE)." + countdownSeconds: Int! +} + +input PackageUpdateSettingsInput { + mode: PackageUpdateMode! + "WAIT only, up to 2592000 (30 days); ignored for FORCE. Null = no deadline (\"Countdown after the deadline\" off)." + deadlineSeconds: Long + "Up to 3600 (1 hour)." + countdownSeconds: Int! +} + +"""Keep it auto-updated: after this update, every new version is installed on the same devices. UPDATE only.""" +type SoftwareAutoUpdate { + enabled: Boolean! + "The settings the auto-updates run with. Null = the update's own (\"Same settings for auto-update\")." + settings: PackageUpdateSettings +} + +input SoftwareAutoUpdateInput { + enabled: Boolean! + "Null = the update's own settings (\"Same settings for auto-update\"). Ignored while enabled is false." + settings: PackageUpdateSettingsInput +} diff --git a/openframe-api-service-core/src/test/java/com/openframe/api/service/rmm/software/SoftwareScheduleServiceTest.java b/openframe-api-service-core/src/test/java/com/openframe/api/service/rmm/software/SoftwareScheduleServiceTest.java index 00bf41569a..933359c66a 100644 --- a/openframe-api-service-core/src/test/java/com/openframe/api/service/rmm/software/SoftwareScheduleServiceTest.java +++ b/openframe-api-service-core/src/test/java/com/openframe/api/service/rmm/software/SoftwareScheduleServiceTest.java @@ -1,6 +1,8 @@ package com.openframe.api.service.rmm.software; import com.openframe.api.dto.rmm.software.CreateSoftwareScheduleInput; +import com.openframe.api.dto.rmm.software.PackageUpdateSettingsInput; +import com.openframe.api.dto.rmm.software.SoftwareAutoUpdateInput; import com.openframe.api.dto.rmm.software.SoftwareSchedulePackageInput; import com.openframe.api.dto.rmm.software.SoftwareScheduleResponse; import com.openframe.api.dto.rmm.software.UpdateSoftwareScheduleInput; @@ -16,6 +18,7 @@ import com.openframe.data.document.rmm.schedule.SoftwareSchedule; import com.openframe.data.document.rmm.schedule.SoftwareScheduleMachineAssigned; import com.openframe.data.document.rmm.script.ScriptStatus; +import com.openframe.data.document.rmm.software.PackageUpdateMode; import com.openframe.data.document.rmm.software.SoftwareAction; import com.openframe.data.repository.rmm.SoftwareScheduleMachineAssignedRepository; import com.openframe.data.repository.rmm.SoftwareScheduleRepository; @@ -265,6 +268,75 @@ void getMachineIds_delegatesToResolver() { assertThat(service.getMachineIds(SCHEDULE_ID)).containsExactly("m-7", "m-8"); } + @Test + @DisplayName("create UPDATE: the update settings and auto-update are stored and returned, a forced install keeps no deadline") + void createUpdateStoresAndReturnsSettings() { + when(scheduleRepository.existsByTenantIdAndNameAndStatusIn(TENANT_ID, "Nightly Slack", UNIQUE_STATUSES)) + .thenReturn(false); + createInput.setAction(SoftwareAction.UPDATE); + createInput.setUpdateSettings(settingsInput(PackageUpdateMode.FORCE, 3_600L, 60)); + SoftwareAutoUpdateInput autoUpdate = new SoftwareAutoUpdateInput(); + autoUpdate.setEnabled(true); + createInput.setAutoUpdate(autoUpdate); + + SoftwareScheduleResponse response = service.create(createInput, ACTOR); + + ArgumentCaptor captor = ArgumentCaptor.forClass(SoftwareSchedule.class); + verify(scheduleRepository).save(captor.capture()); + SoftwareSchedule saved = captor.getValue(); + assertThat(saved.getUpdateSettings().getMode()).isEqualTo(PackageUpdateMode.FORCE); + assertThat(saved.getUpdateSettings().getDeadlineSeconds()).isNull(); + assertThat(saved.getUpdateSettings().getCountdownSeconds()).isEqualTo(60); + assertThat(saved.getAutoUpdate().isEnabled()).isTrue(); + assertThat(saved.getAutoUpdate().getSettings()).isNull(); + assertThat(response.getUpdateSettings()).isEqualTo(saved.getUpdateSettings()); + assertThat(response.getAutoUpdate()).isEqualTo(saved.getAutoUpdate()); + } + + @Test + @DisplayName("create INSTALL with update settings: rejected before anything is saved") + void createInstallWithUpdateSettingsRejected() { + when(scheduleRepository.existsByTenantIdAndNameAndStatusIn(TENANT_ID, "Nightly Slack", UNIQUE_STATUSES)) + .thenReturn(false); + createInput.setUpdateSettings(settingsInput(PackageUpdateMode.WAIT, null, 300)); + + assertThatThrownBy(() -> service.create(createInput, ACTOR)) + .isInstanceOf(BadRequestException.class) + .hasMessageContaining("updateSettings"); + verify(scheduleRepository, never()).save(any(SoftwareSchedule.class)); + } + + @Test + @DisplayName("update UPDATE without settings: the full replacement resets them to the screen's defaults, auto-update off") + void updateWithoutSettingsResetsToDefaults() { + SoftwareSchedule existing = existingActive(); + when(scheduleRepository.findByTenantIdAndId(TENANT_ID, SCHEDULE_ID)).thenReturn(Optional.of(existing)); + when(scheduleRepository.existsByTenantIdAndNameAndIdNotAndStatusIn( + eq(TENANT_ID), anyString(), eq(SCHEDULE_ID), eq(UNIQUE_STATUSES))).thenReturn(false); + UpdateSoftwareScheduleInput input = new UpdateSoftwareScheduleInput(); + input.setId(SCHEDULE_ID); + input.setName("Nightly Slack"); + input.setAction(SoftwareAction.UPDATE); + input.setPackages(List.of(pkg(PackageManagerType.WINGET, "vscode", null))); + input.setStartAt(Instant.parse("2026-09-16T03:30:00Z")); + + SoftwareScheduleResponse response = service.update(input, ACTOR); + + assertThat(existing.getUpdateSettings().getMode()).isEqualTo(PackageUpdateMode.WAIT); + assertThat(existing.getUpdateSettings().getDeadlineSeconds()).isEqualTo(604_800L); + assertThat(existing.getUpdateSettings().getCountdownSeconds()).isEqualTo(300); + assertThat(existing.getAutoUpdate().isEnabled()).isFalse(); + assertThat(response.getUpdateSettings()).isEqualTo(existing.getUpdateSettings()); + } + + private static PackageUpdateSettingsInput settingsInput(PackageUpdateMode mode, Long deadlineSeconds, int countdownSeconds) { + PackageUpdateSettingsInput input = new PackageUpdateSettingsInput(); + input.setMode(mode); + input.setDeadlineSeconds(deadlineSeconds); + input.setCountdownSeconds(countdownSeconds); + return input; + } + private static SoftwareSchedule existingActive() { return SoftwareSchedule.builder() .id(SCHEDULE_ID).tenantId(TENANT_ID).name("Nightly Slack") diff --git a/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/schedule/SoftwareSchedule.java b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/schedule/SoftwareSchedule.java index 13406f5952..78643e628f 100644 --- a/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/schedule/SoftwareSchedule.java +++ b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/schedule/SoftwareSchedule.java @@ -1,7 +1,9 @@ package com.openframe.data.document.rmm.schedule; import com.openframe.data.document.TenantScoped; +import com.openframe.data.document.rmm.software.PackageUpdateSettings; import com.openframe.data.document.rmm.software.SoftwareAction; +import com.openframe.data.document.rmm.software.SoftwareAutoUpdate; import com.openframe.data.document.rmm.script.ScriptStatus; import lombok.AllArgsConstructor; import lombok.Builder; @@ -38,6 +40,9 @@ public class SoftwareSchedule implements TenantScoped { private SoftwareAction action; private List packages; + // UPDATE only; null for INSTALL + private PackageUpdateSettings updateSettings; + private SoftwareAutoUpdate autoUpdate; @Builder.Default private ScheduleDeviceSelectionMode selectionMode = ScheduleDeviceSelectionMode.SPECIFIC; diff --git a/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/PackageUpdateSettings.java b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/PackageUpdateSettings.java new file mode 100644 index 0000000000..a9be1c3c13 --- /dev/null +++ b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/PackageUpdateSettings.java @@ -0,0 +1,19 @@ +package com.openframe.data.document.rmm.software; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PackageUpdateSettings { + + private PackageUpdateMode mode; + + private Long deadlineSeconds; + + private Integer countdownSeconds; +} diff --git a/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareAutoUpdate.java b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareAutoUpdate.java new file mode 100644 index 0000000000..225b2bb8fc --- /dev/null +++ b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareAutoUpdate.java @@ -0,0 +1,17 @@ +package com.openframe.data.document.rmm.software; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SoftwareAutoUpdate { + + private boolean enabled; + + private PackageUpdateSettings settings; +} diff --git a/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareBundle.java b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareBundle.java index 52e5e94ea3..f2a16b1e8b 100644 --- a/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareBundle.java +++ b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareBundle.java @@ -27,6 +27,8 @@ public class SoftwareBundle implements TenantScoped { private SoftwareBundleStatus status; private List machineIds; private List packages; + private PackageUpdateSettings updateSettings; + private SoftwareAutoUpdate autoUpdate; private Instant startAt; private String scheduleId; private List executionIds; From c7f7e45499d6c6c4fdea6dce7caa06bd4df9e978 Mon Sep 17 00:00:00 2001 From: Andrii Koropets Date: Wed, 28 Oct 2026 00:49:38 +0200 Subject: [PATCH 2/4] Added waiting and version --- .../SoftwareActionDeviceResponse.java | 3 + .../rmm/software/SoftwareActionResponse.java | 2 + .../software/SoftwareActionDetailService.java | 36 +++++++++- .../rmm/software/SoftwareActionService.java | 2 + .../SoftwareActionDetailServiceTest.java | 72 ++++++++++++++++++- .../resources/schema/software-action.graphqls | 10 +++ .../PackageUpdateExecutionRecorder.java | 9 ++- .../PackageUpdateExecutionRecorderTest.java | 22 +++++- .../document/rmm/script/ScriptExecution.java | 1 + .../PackageUpdateDeviceStateRepository.java | 3 + ...ftwareActionAggregationRepositoryImpl.java | 35 +++++++-- .../RmmIntegrationTestApplication.java | 4 +- ...wareActionAggregationRepositoryImplIT.java | 47 ++++++++++++ 13 files changed, 229 insertions(+), 17 deletions(-) diff --git a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareActionDeviceResponse.java b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareActionDeviceResponse.java index f293337679..ef1443c434 100644 --- a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareActionDeviceResponse.java +++ b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareActionDeviceResponse.java @@ -1,5 +1,6 @@ package com.openframe.api.dto.rmm.software; +import com.openframe.data.document.device.DeviceStatus; import com.openframe.data.document.rmm.software.SoftwareActionStatus; import lombok.Builder; import lombok.Data; @@ -14,6 +15,8 @@ public class SoftwareActionDeviceResponse { private String hostname; private String organizationId; private String organizationName; + private DeviceStatus deviceStatus; + private Instant lastSeen; private SoftwareActionStatus status; private Integer exitCode; diff --git a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareActionResponse.java b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareActionResponse.java index 1442efa0ea..a3db96320e 100644 --- a/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareActionResponse.java +++ b/openframe-api-lib/src/main/java/com/openframe/api/dto/rmm/software/SoftwareActionResponse.java @@ -16,12 +16,14 @@ public class SoftwareActionResponse { private String executionId; private String software; + private String version; private SoftwareAction action; private PackageManagerType engine; private SoftwareActionStatus status; private int totalMachineCount; private int respondedMachineCount; + private int waitingMachineCount; private Instant scheduledAt; private Instant dispatchedAt; diff --git a/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareActionDetailService.java b/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareActionDetailService.java index 8f89db450b..eddc5d182e 100644 --- a/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareActionDetailService.java +++ b/openframe-api-lib/src/main/java/com/openframe/api/service/rmm/software/SoftwareActionDetailService.java @@ -3,14 +3,15 @@ import com.openframe.api.dto.rmm.software.SoftwareActionDeviceFilterInput; import com.openframe.api.dto.rmm.software.SoftwareActionDeviceResponse; import com.openframe.data.document.device.Machine; -import com.openframe.data.document.organization.Organization; import com.openframe.data.document.rmm.schedule.DeviceOnlineDispatchStatus; import com.openframe.data.document.rmm.schedule.SoftwareScheduleMachineAssigned; import com.openframe.data.document.rmm.script.ExecutionStatus; import com.openframe.data.document.rmm.script.ScriptExecution; +import com.openframe.data.document.rmm.software.PackageUpdateDeviceState; import com.openframe.data.document.rmm.software.SoftwareActionStatus; import com.openframe.data.repository.device.MachineRepository; import com.openframe.data.repository.organization.OrganizationRepository; +import com.openframe.data.repository.rmm.PackageUpdateDeviceStateRepository; import com.openframe.data.repository.rmm.ScriptExecutionRepository; import com.openframe.data.repository.rmm.SoftwareBundleOnlineDispatchRepository; import com.openframe.data.repository.rmm.SoftwareScheduleMachineAssignedRepository; @@ -41,6 +42,7 @@ public class SoftwareActionDetailService { private final SoftwareBundleOnlineDispatchRepository bundleOnlineDispatchRepository; private final SoftwareScheduleOnlineDispatchRepository scheduleOnlineDispatchRepository; private final SoftwareScheduleMachineAssignedRepository scheduleMachineAssignedRepository; + private final PackageUpdateDeviceStateRepository packageUpdateDeviceStateRepository; private final MachineRepository machineRepository; private final OrganizationRepository organizationRepository; private final TenantIdProvider tenantIdProvider; @@ -63,9 +65,11 @@ public List devices(String executionId, String bun // 3. Overlay execution leaves — the real outcome wins over any pending state. if (hasText(executionId)) { - for (ScriptExecution leaf : scriptExecutionRepository.findByTenantIdAndExecutionId(tenantId, executionId)) { + List leaves = scriptExecutionRepository.findByTenantIdAndExecutionId(tenantId, executionId); + for (ScriptExecution leaf : leaves) { byMachine.put(leaf.getMachineId(), fromLeaf(leaf)); } + overlayWaiting(tenantId, leaves, byMachine); } enrichWithCustomer(tenantId, byMachine); @@ -98,6 +102,28 @@ private void addPending(Map byMachine, Str } } + // 4. A running package update reads WAITING from its device state, so rows recorded before the leaf carried + // the waiting flag show it too. + private void overlayWaiting(String tenantId, List leaves, + Map byMachine) { + Map requestByMachine = new HashMap<>(); + for (ScriptExecution leaf : leaves) { + if (hasText(leaf.getPackageUpdateRequestId()) && isRunning(leaf.getStatus())) { + requestByMachine.put(leaf.getMachineId(), leaf.getPackageUpdateRequestId()); + } + } + if (requestByMachine.isEmpty()) { + return; + } + for (PackageUpdateDeviceState state : packageUpdateDeviceStateRepository + .findByTenantIdAndRequestIdIn(tenantId, new HashSet<>(requestByMachine.values()))) { + if (state.getStatus() == SoftwareActionStatus.WAITING + && state.getRequestId().equals(requestByMachine.get(state.getMachineId()))) { + byMachine.get(state.getMachineId()).setStatus(SoftwareActionStatus.WAITING); + } + } + } + // Batch-load hostname and customer in two queries, not per row. private void enrichWithCustomer(String tenantId, Map byMachine) { if (byMachine.isEmpty()) { @@ -125,6 +151,8 @@ private void enrichWithCustomer(String tenantId, Map rows = service.devices(EXEC, null, null, null, null); + + assertThat(status(rows, "m-waiting")).isEqualTo(SoftwareActionStatus.WAITING); + assertThat(status(rows, "m-running")).isEqualTo(SoftwareActionStatus.IN_PROGRESS); + assertThat(status(rows, "m-done")).isEqualTo(SoftwareActionStatus.COMPLETED); + assertThat(status(rows, "m-old-request")).isEqualTo(SoftwareActionStatus.IN_PROGRESS); + + List waiting = service.devices(EXEC, null, null, filter(List.of(SoftwareActionStatus.WAITING), null), null); + assertThat(waiting).extracting(SoftwareActionDeviceResponse::getMachineId).containsExactly("m-waiting"); + } + + @Test + @DisplayName("leaves that are not package updates never read device states") + void scriptLeavesSkipDeviceStates() { + when(scriptExecutionRepository.findByTenantIdAndExecutionId(TENANT, EXEC)).thenReturn(List.of( + leaf("m1", ExecutionStatus.RUNNING))); + + service.devices(EXEC, null, null, null, null); + + verifyNoInteractions(packageUpdateDeviceStateRepository); + } + + @Test + @DisplayName("each row carries the device's connectivity and last-seen time") + void deviceConnectivity() { + Instant lastSeen = Instant.parse("2026-10-27T10:00:00Z"); + when(scriptExecutionRepository.findByTenantIdAndExecutionId(TENANT, EXEC)).thenReturn(List.of( + leaf("m1", ExecutionStatus.SUCCESS))); + Machine m1 = machine("m1", "m1-host", null); + m1.setStatus(DeviceStatus.OFFLINE); + m1.setLastSeen(lastSeen); + when(machineRepository.findByTenantIdAndMachineIdIn(eq(TENANT), any())).thenReturn(List.of(m1)); + + SoftwareActionDeviceResponse row = service.devices(EXEC, null, null, null, null).getFirst(); + + assertThat(row.getDeviceStatus()).isEqualTo(DeviceStatus.OFFLINE); + assertThat(row.getLastSeen()).isEqualTo(lastSeen); + } + private static SoftwareActionDeviceFilterInput filter(List statuses, List organizationIds) { SoftwareActionDeviceFilterInput f = new SoftwareActionDeviceFilterInput(); f.setStatuses(statuses); @@ -144,6 +204,14 @@ private static ScriptExecution leaf(String machineId, ExecutionStatus status) { return ScriptExecution.builder().machineId(machineId).status(status).build(); } + private static ScriptExecution updateLeaf(String machineId, ExecutionStatus status, String requestId) { + return ScriptExecution.builder().machineId(machineId).status(status).packageUpdateRequestId(requestId).build(); + } + + private static PackageUpdateDeviceState deviceState(String requestId, String machineId, SoftwareActionStatus status) { + return PackageUpdateDeviceState.builder().requestId(requestId).machineId(machineId).status(status).build(); + } + private static SoftwareBundleOnlineDispatch bundleSentinel(String machineId, DeviceOnlineDispatchStatus status) { return SoftwareBundleOnlineDispatch.builder().machineId(machineId).status(status).build(); } diff --git a/openframe-api-service-core/src/main/resources/schema/software-action.graphqls b/openframe-api-service-core/src/main/resources/schema/software-action.graphqls index 49c67b41c1..54b54950cf 100644 --- a/openframe-api-service-core/src/main/resources/schema/software-action.graphqls +++ b/openframe-api-service-core/src/main/resources/schema/software-action.graphqls @@ -45,6 +45,8 @@ type SoftwareActionRun { executionId: String! "Package name (the SOFTWARE column)." software: String! + "Version the action installs or updates to. Null = latest." + version: String "INSTALL or UPDATE." action: SoftwareAction! "Package manager engine — BREW / WINGET / CHOCO." @@ -54,6 +56,8 @@ type SoftwareActionRun { totalMachineCount: Int! "Devices that have finished (X in X / Y)." respondedMachineCount: Int! + "Devices whose update waits on the device — a user prompt or an open app (the N WAITING chip)." + waitingMachineCount: Int! "When a SCHEDULED action will fire. Null once dispatched / for NOW." scheduledAt: Instant "When the action was dispatched. Null while SCHEDULED." @@ -69,6 +73,8 @@ type SoftwareActionRun { enum SoftwareActionStatus { SCHEDULED IN_PROGRESS + "A package update waits on the device: a user prompt or an open app. Any waiting device makes the action WAITING." + WAITING COMPLETED FAILED } @@ -79,6 +85,10 @@ type SoftwareActionDevice { hostname: String organizationId: String organizationName: String + "Device connectivity (ONLINE / OFFLINE / ...), for the online dot." + deviceStatus: DeviceStatus + "Last time the device was seen, shown while it is offline." + lastSeen: Instant status: SoftwareActionStatus! exitCode: Int stdout: String diff --git a/openframe-client-core/src/main/java/com/openframe/client/listener/packageupdate/PackageUpdateExecutionRecorder.java b/openframe-client-core/src/main/java/com/openframe/client/listener/packageupdate/PackageUpdateExecutionRecorder.java index d7b1205457..0c50bb72e3 100644 --- a/openframe-client-core/src/main/java/com/openframe/client/listener/packageupdate/PackageUpdateExecutionRecorder.java +++ b/openframe-client-core/src/main/java/com/openframe/client/listener/packageupdate/PackageUpdateExecutionRecorder.java @@ -43,11 +43,13 @@ public void record(PackageUpdateRequest request, String machineId, PackageUpdate Instant now = Instant.now(); switch (event.getState()) { case WAITING -> { - if (row.getStatus() == ExecutionStatus.RUNNING) { + if (row.getStatus() == ExecutionStatus.RUNNING && Boolean.TRUE.equals(row.getWaiting())) { return; } - // a retried request waits again: the previous attempt's outcome no longer applies - update(row, ExecutionStatus.RUNNING, null, null, null, null); + if (row.getStatus() != ExecutionStatus.RUNNING) { + update(row, ExecutionStatus.RUNNING, null, null, null, null); + } + row.setWaiting(true); } case DONE -> update(row, ExecutionStatus.SUCCESS, now, null, summary(event), null); case FAILED -> { @@ -62,6 +64,7 @@ public void record(PackageUpdateRequest request, String machineId, PackageUpdate private static void update(ScriptExecution row, ExecutionStatus status, Instant finishedAt, Integer exitCode, String stdout, String error) { row.setStatus(status); + row.setWaiting(null); row.setFinishedAt(finishedAt); row.setExitCode(exitCode); row.setStdout(stdout); diff --git a/openframe-client-core/src/test/java/com/openframe/client/listener/packageupdate/PackageUpdateExecutionRecorderTest.java b/openframe-client-core/src/test/java/com/openframe/client/listener/packageupdate/PackageUpdateExecutionRecorderTest.java index f792a06e30..0fa6bc292b 100644 --- a/openframe-client-core/src/test/java/com/openframe/client/listener/packageupdate/PackageUpdateExecutionRecorderTest.java +++ b/openframe-client-core/src/test/java/com/openframe/client/listener/packageupdate/PackageUpdateExecutionRecorderTest.java @@ -76,10 +76,24 @@ void waiting_marksQueuedRowRunning() { recorder.record(request, "m1", event(State.WAITING)); assertThat(row.getStatus()).isEqualTo(ExecutionStatus.RUNNING); + assertThat(row.getWaiting()).isTrue(); assertThat(row.getStatusChangedAt()).isNotNull(); verify(scriptExecutionRepository).save(row); } + @Test + void waiting_onARunningRowWithoutTheFlag_marksItWaiting() { + ScriptExecution row = rowFound(ExecutionStatus.RUNNING); + row.setStdout("kept"); + + recorder.record(request, "m1", event(State.WAITING)); + + assertThat(row.getStatus()).isEqualTo(ExecutionStatus.RUNNING); + assertThat(row.getWaiting()).isTrue(); + assertThat(row.getStdout()).isEqualTo("kept"); + verify(scriptExecutionRepository).save(row); + } + @Test void waiting_afterAFailedAttempt_clearsTheOldOutcome() { ScriptExecution row = rowFound(ExecutionStatus.FAILED); @@ -95,8 +109,8 @@ void waiting_afterAFailedAttempt_clearsTheOldOutcome() { } @Test - void waiting_againWhileRunning_writesNothing() { - rowFound(ExecutionStatus.RUNNING); + void waiting_againWhileWaiting_writesNothing() { + rowFound(ExecutionStatus.RUNNING).setWaiting(true); recorder.record(request, "m1", event(State.WAITING)); @@ -106,10 +120,12 @@ void waiting_againWhileRunning_writesNothing() { @Test void done_upgraded_succeedsWithSummary() { ScriptExecution row = rowFound(ExecutionStatus.RUNNING); + row.setWaiting(true); recorder.record(request, "m1", done(Done.Result.UPGRADED, "4.36.140", true)); assertThat(row.getStatus()).isEqualTo(ExecutionStatus.SUCCESS); + assertThat(row.getWaiting()).isNull(); assertThat(row.getFinishedAt()).isNotNull(); assertThat(row.getStdout()).isEqualTo("Updated (4.36.140), reboot required."); assertThat(row.getError()).isNull(); @@ -129,10 +145,12 @@ void done_alreadyLatest_succeeds() { @Test void failed_failsWithReasonMessageAndExitCode() { ScriptExecution row = rowFound(ExecutionStatus.RUNNING); + row.setWaiting(true); recorder.record(request, "m1", failed(Failed.Reason.MANAGER_ERROR, "winget exited 1", 1L)); assertThat(row.getStatus()).isEqualTo(ExecutionStatus.FAILED); + assertThat(row.getWaiting()).isNull(); assertThat(row.getFinishedAt()).isNotNull(); assertThat(row.getError()).isEqualTo("MANAGER_ERROR: winget exited 1"); assertThat(row.getExitCode()).isEqualTo(1); diff --git a/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/script/ScriptExecution.java b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/script/ScriptExecution.java index 4b42e3ae15..1206f5fde0 100644 --- a/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/script/ScriptExecution.java +++ b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/script/ScriptExecution.java @@ -69,6 +69,7 @@ public class ScriptExecution implements TenantScoped { private String packageUpdateRequestId; private ExecutionStatus status; + private Boolean waiting; private Instant dispatchedAt; private Instant statusChangedAt; diff --git a/openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/rmm/PackageUpdateDeviceStateRepository.java b/openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/rmm/PackageUpdateDeviceStateRepository.java index 3e14ce2b1d..245b43fd54 100644 --- a/openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/rmm/PackageUpdateDeviceStateRepository.java +++ b/openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/rmm/PackageUpdateDeviceStateRepository.java @@ -4,6 +4,7 @@ import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; +import java.util.Collection; import java.util.List; import java.util.Optional; @@ -14,5 +15,7 @@ public interface PackageUpdateDeviceStateRepository extends MongoRepository findByTenantIdAndRequestId(String tenantId, String requestId); + List findByTenantIdAndRequestIdIn(String tenantId, Collection requestIds); + long deleteByTenantIdAndRequestId(String tenantId, String requestId); } diff --git a/openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/rmm/SoftwareActionAggregationRepositoryImpl.java b/openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/rmm/SoftwareActionAggregationRepositoryImpl.java index 92904f6dc4..f3f2ca4b3e 100644 --- a/openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/rmm/SoftwareActionAggregationRepositoryImpl.java +++ b/openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/rmm/SoftwareActionAggregationRepositoryImpl.java @@ -141,6 +141,7 @@ private static Document lookupExecutions() { new Document("$ne", Arrays.asList("$softwareAction", null)))))), new Document("$group", new Document("_id", null) .append("responded", new Document("$addToSet", cond(inArr("$status", TERMINAL), "$machineId", null))) + .append("waiting", new Document("$addToSet", cond(isWaiting(), "$machineId", null))) .append("hasInProgress", new Document("$max", cond(inArr("$status", IN_PROGRESS), 1, 0))) .append("failed", new Document("$max", cond(new Document("$eq", Arrays.asList("$status", ExecutionStatus.FAILED.name())), 1, 0))) @@ -156,24 +157,41 @@ private static List reconcileStages() { stages.add(ctx -> new Document("$addFields", new Document("_exec", new Document("$arrayElemAt", Arrays.asList("$exec", 0))))); Object hasLeaves = new Document("$gt", Arrays.asList(new Document("$ifNull", Arrays.asList("$_exec.execCount", 0)), 0)); - Object responded = new Document("$size", new Document("$setDifference", List.of( - new Document("$ifNull", Arrays.asList("$_exec.responded", Collections.emptyList())), - Collections.singletonList(null)))); - Object liveStatus = cond(new Document("$gt", Arrays.asList(new Document("$ifNull", Arrays.asList("$_exec.hasInProgress", 0)), 0)), - SoftwareActionStatus.IN_PROGRESS.name(), - cond(new Document("$gt", Arrays.asList(new Document("$ifNull", Arrays.asList("$_exec.failed", 0)), 0)), - SoftwareActionStatus.FAILED.name(), SoftwareActionStatus.COMPLETED.name())); + Object responded = machineCount("$_exec.responded"); + Object waiting = machineCount("$_exec.waiting"); + // same precedence as the package-update roll-up: any waiting device makes the whole action WAITING + Object liveStatus = cond(new Document("$gt", Arrays.asList(waiting, 0)), + SoftwareActionStatus.WAITING.name(), + cond(new Document("$gt", Arrays.asList(new Document("$ifNull", Arrays.asList("$_exec.hasInProgress", 0)), 0)), + SoftwareActionStatus.IN_PROGRESS.name(), + cond(new Document("$gt", Arrays.asList(new Document("$ifNull", Arrays.asList("$_exec.failed", 0)), 0)), + SoftwareActionStatus.FAILED.name(), SoftwareActionStatus.COMPLETED.name()))); stages.add(ctx -> new Document("$addFields", new Document() .append("respondedMachineCount", cond(hasLeaves, responded, 0)) + .append("waitingMachineCount", cond(hasLeaves, waiting, 0)) .append("status", cond(hasLeaves, liveStatus, "$status")))); return stages; } + private static Document isWaiting() { + return new Document("$and", List.of( + new Document("$eq", Arrays.asList("$status", ExecutionStatus.RUNNING.name())), + new Document("$eq", Arrays.asList("$waiting", true)))); + } + + // distinct machine ids collected by the lookup, without the null the $cond adds for non-matching leaves + private static Document machineCount(String field) { + return new Document("$size", new Document("$setDifference", List.of( + new Document("$ifNull", Arrays.asList(field, Collections.emptyList())), + Collections.singletonList(null)))); + } + private static Document projectDoc() { return new Document("_id", 0) .append("executionId", 1) .append("packageManager", 1) .append("packageName", 1) + .append("version", 1) .append("action", 1) .append("initiatedBy", 1) .append("bundleId", 1) @@ -181,6 +199,7 @@ private static Document projectDoc() { .append("dispatchedAt", 1) .append("totalMachineCount", 1) .append("respondedMachineCount", 1) + .append("waitingMachineCount", 1) .append("status", 1); } @@ -214,10 +233,12 @@ private static SoftwareActionSummary toSummary(Document doc) { .executionId(doc.getString("executionId")) .packageManager(enumOrNull(doc.getString("packageManager"), PackageManagerType.class)) .packageName(doc.getString("packageName")) + .version(doc.getString("version")) .action(enumOrNull(doc.getString("action"), SoftwareAction.class)) .status(enumOrNull(doc.getString("status"), SoftwareActionStatus.class)) .totalMachineCount(intValue(doc.get("totalMachineCount"))) .respondedMachineCount(intValue(doc.get("respondedMachineCount"))) + .waitingMachineCount(intValue(doc.get("waitingMachineCount"))) .dispatchedAt(instantOrNull(doc.get("dispatchedAt"))) .initiatedBy(doc.getString("initiatedBy")) .bundleId(doc.getString("bundleId")) diff --git a/openframe-data-mongo-sync/src/test/java/com/openframe/data/integration/support/RmmIntegrationTestApplication.java b/openframe-data-mongo-sync/src/test/java/com/openframe/data/integration/support/RmmIntegrationTestApplication.java index f2dcade956..8d11d5605f 100644 --- a/openframe-data-mongo-sync/src/test/java/com/openframe/data/integration/support/RmmIntegrationTestApplication.java +++ b/openframe-data-mongo-sync/src/test/java/com/openframe/data/integration/support/RmmIntegrationTestApplication.java @@ -5,6 +5,7 @@ import com.openframe.data.repository.rmm.CustomScriptScheduleRepositoryImpl; import com.openframe.data.repository.rmm.CustomScheduleScriptExecutionRepositoryImpl; import com.openframe.data.repository.rmm.CustomScriptExecutionRepositoryImpl; +import com.openframe.data.repository.rmm.SoftwareActionAggregationRepositoryImpl; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.Import; @@ -33,7 +34,8 @@ CustomScriptRepositoryImpl.class, CustomScriptScheduleRepositoryImpl.class, CustomScheduleScriptExecutionRepositoryImpl.class, - CustomScriptExecutionRepositoryImpl.class + CustomScriptExecutionRepositoryImpl.class, + SoftwareActionAggregationRepositoryImpl.class }) public class RmmIntegrationTestApplication { } diff --git a/openframe-data-mongo-sync/src/test/java/com/openframe/data/repository/rmm/SoftwareActionAggregationRepositoryImplIT.java b/openframe-data-mongo-sync/src/test/java/com/openframe/data/repository/rmm/SoftwareActionAggregationRepositoryImplIT.java index 4480471a12..ed261b5fb1 100644 --- a/openframe-data-mongo-sync/src/test/java/com/openframe/data/repository/rmm/SoftwareActionAggregationRepositoryImplIT.java +++ b/openframe-data-mongo-sync/src/test/java/com/openframe/data/repository/rmm/SoftwareActionAggregationRepositoryImplIT.java @@ -1,6 +1,7 @@ package com.openframe.data.repository.rmm; import com.openframe.data.document.packagesearch.PackageManagerType; +import com.openframe.data.document.rmm.filter.SoftwareActionQueryFilter; import com.openframe.data.document.rmm.script.ExecutionStatus; import com.openframe.data.document.rmm.script.ScriptExecution; import com.openframe.data.document.rmm.software.SoftwareAction; @@ -107,6 +108,43 @@ void scheduledBecomesVisibleAfterFiring() { assertThat(byExec.get("exec-sched2").getRespondedMachineCount()).isEqualTo(1); } + @Test + @DisplayName("a waiting device makes the action WAITING and counts in waitingMachineCount") + void waitingDevices() { + action("exec-wait", 3, SoftwareActionStatus.IN_PROGRESS); + leaf("exec-wait", "m1", ExecutionStatus.SUCCESS); + waitingLeaf("exec-wait", "m2"); + leaf("exec-wait", "m3", ExecutionStatus.RUNNING); + + action("exec-run", 1, SoftwareActionStatus.IN_PROGRESS); + leaf("exec-run", "m1", ExecutionStatus.RUNNING); + + Map byExec = allRows(); + assertThat(byExec.get("exec-wait").getStatus()).isEqualTo(SoftwareActionStatus.WAITING); + assertThat(byExec.get("exec-wait").getWaitingMachineCount()).isEqualTo(1); + assertThat(byExec.get("exec-wait").getRespondedMachineCount()).isEqualTo(1); + assertThat(byExec.get("exec-run").getStatus()).isEqualTo(SoftwareActionStatus.IN_PROGRESS); + assertThat(byExec.get("exec-run").getWaitingMachineCount()).isZero(); + + SoftwareActionQueryFilter waitingOnly = SoftwareActionQueryFilter.builder() + .statuses(List.of(SoftwareActionStatus.WAITING)).build(); + assertThat(repository.count(TENANT, waitingOnly, null)).isEqualTo(1); + assertThat(repository.facet(TENANT, null, null, "status")) + .containsEntry("WAITING", 1).containsEntry("IN_PROGRESS", 1); + } + + @Test + @DisplayName("the action's version comes through on the row") + void versionIsProjected() { + mongoTemplate.save(SoftwareActionResult.builder() + .id("exec-v").tenantId(TENANT).executionId("exec-v") + .action(SoftwareAction.INSTALL).packageManager(PackageManagerType.BREW).packageName("slack") + .version("4.36.140").status(SoftwareActionStatus.IN_PROGRESS).totalMachineCount(1) + .dispatchedAt(Instant.now()).build()); + + assertThat(repository.findByExecutionId(TENANT, "exec-v").orElseThrow().getVersion()).isEqualTo("4.36.140"); + } + private Map allRows() { return repository.findPage(TENANT, null, null, "dispatchedAt", Sort.Direction.DESC, 0, 50).stream() .collect(Collectors.toMap(SoftwareActionSummary::getExecutionId, Function.identity())); @@ -127,13 +165,22 @@ private void action(String executionId, int totalMachineCount, SoftwareActionSta .build()); } + private void waitingLeaf(String executionId, String machineId) { + leaf(executionId, machineId, ExecutionStatus.RUNNING, true); + } + private void leaf(String executionId, String machineId, ExecutionStatus status) { + leaf(executionId, machineId, status, null); + } + + private void leaf(String executionId, String machineId, ExecutionStatus status, Boolean waiting) { mongoTemplate.save(ScriptExecution.builder() .tenantId(TENANT) .executionId(executionId) .scriptId("script-1") .machineId(machineId) .status(status) + .waiting(waiting) .softwareAction(SoftwareAction.INSTALL) .packageManager(PackageManagerType.BREW) .packageName("slack") From 82281db6568c57cd5796d88a5d365715f0f0a981 Mon Sep 17 00:00:00 2001 From: Andrii Koropets Date: Wed, 28 Oct 2026 01:00:16 +0200 Subject: [PATCH 3/4] Added waiting and version --- .../resources/schema/software-action.graphqls | 18 +++ .../main/resources/schema/software.graphqls | 107 +++++++++++++++++- .../rmm/software/SoftwareActionSummary.java | 2 + 3 files changed, 124 insertions(+), 3 deletions(-) diff --git a/openframe-api-service-core/src/main/resources/schema/software-action.graphqls b/openframe-api-service-core/src/main/resources/schema/software-action.graphqls index 54b54950cf..ef43a715bc 100644 --- a/openframe-api-service-core/src/main/resources/schema/software-action.graphqls +++ b/openframe-api-service-core/src/main/resources/schema/software-action.graphqls @@ -49,6 +49,8 @@ type SoftwareActionRun { version: String "INSTALL or UPDATE." action: SoftwareAction! + "The ACTION column: Install / Update / Auto-update / Adopt." + kind: SoftwareActionKind! "Package manager engine — BREW / WINGET / CHOCO." engine: PackageManagerType! status: SoftwareActionStatus! @@ -70,6 +72,17 @@ type SoftwareActionRun { scheduleId: String } +"""What a software action did, as the ACTION column shows it.""" +enum SoftwareActionKind { + INSTALL + "An update an admin started (now or scheduled)." + UPDATE + "An update started by an auto-update policy when a new version came out." + AUTO_UPDATE + "A manually installed copy reinstalled with a package manager." + ADOPT +} + enum SoftwareActionStatus { SCHEDULED IN_PROGRESS @@ -85,6 +98,8 @@ type SoftwareActionDevice { hostname: String organizationId: String organizationName: String + "What ran on this device: UPDATE, or ADOPT for a device that had the title installed manually." + kind: SoftwareActionKind "Device connectivity (ONLINE / OFFLINE / ...), for the online dot." deviceStatus: DeviceStatus "Last time the device was seen, shown while it is offline." @@ -121,6 +136,8 @@ type SoftwareActionRunEdge { input SoftwareActionFilterInput { statuses: [SoftwareActionStatus!] actions: [SoftwareAction!] + "The ACTION dropdown (Install / Update / Auto-update / Adopt)." + kinds: [SoftwareActionKind!] engines: [PackageManagerType!] } @@ -129,6 +146,7 @@ input SoftwareActionFilterInput { type SoftwareActionFilters { statuses: [ScriptFilterOption!]! actions: [ScriptFilterOption!]! + kinds: [ScriptFilterOption!]! engines: [ScriptFilterOption!]! filteredCount: Int! } diff --git a/openframe-api-service-core/src/main/resources/schema/software.graphqls b/openframe-api-service-core/src/main/resources/schema/software.graphqls index 945dc03263..5ee5dca702 100644 --- a/openframe-api-service-core/src/main/resources/schema/software.graphqls +++ b/openframe-api-service-core/src/main/resources/schema/software.graphqls @@ -10,7 +10,7 @@ extend type Query { """Paginated list of software titles installed across the tenant's fleet. One row = one software title (aggregated across devices). - Sortable fields: name, devicesCount, cveCount, highestSeverity (default: Fleet order by name). + Sortable fields: name, devicesCount, cveCount, highestSeverity, adoptionCount (default: Fleet order by name). An unknown sort field is rejected as a client error (BAD_REQUEST), not a server error.""" softwares( filter: SoftwareFilterInput, @@ -23,8 +23,9 @@ extend type Query { ): SoftwareConnection! """Devices that have a given software title installed, with each device's own - installed version and per-device software status (OUTDATED / SCHEDULED_UPDATE / …). - Powers the Software → Devices tab.""" + installed version and per-device software status (OUTDATED / SCHEDULED_UPDATE / …), + who installed it, its adoption and auto-update. Powers the Software → Devices tab. + Sortable fields: softwareVersion.""" softwareDevices( softwareId: ID!, filter: SoftwareOnDeviceFilterInput, @@ -159,6 +160,19 @@ type Software { """False when the vulnerability scanner could not find a matching CPE entry — shown as "no CPE match" instead of a severity badge.""" cpeMatched: Boolean + + """Kind of software — the Type field on the detail page (e.g. "Application").""" + type: SoftwareType + + """AUTO-UPDATE column and the detail page's "Turn Off Auto-Update" button. ON = an auto-update policy + keeps this title updated, OFF = a package manager installed it but no policy does. Null ("–") = no device + has it from a package manager, so there is nothing to auto-update.""" + autoUpdate: SoftwareAutoUpdateStatus + + """Devices that have this title installed manually (installedBy UNMANAGED) and can be adopted — the + ADOPTION column and the "N devices have … installed manually" banner with Adopt. Null or 0 = "–", no banner. + Sortable as adoptionCount.""" + adoptionCount: Int } type SoftwareVulnerabilitySummary { @@ -172,6 +186,28 @@ type SoftwareOnDevice { device: Machine! softwareVersion: String status: SoftwareOnDeviceStatus + + """INSTALLED BY column: the package manager that installed it here (WINGET / CHOCOLATEY / BREW), or + UNMANAGED for "Manually". Null = unknown.""" + installedBy: SoftwareSource + + """Set while an adoption of this device runs or after it failed — the ADOPTING / ADOPTION FAILED chip that + replaces installedBy. ADOPTING on an offline device shows "Starts when online" (from device.status). + Null = no adoption.""" + adoption: SoftwareAdoption + + """AUTO-UPDATE column for this device: ON / OFF. Null ("–") = installed manually, nothing to auto-update.""" + autoUpdate: SoftwareAutoUpdateStatus +} + +"""An adoption of one device: the manually installed copy is reinstalled with a package manager, so it can be +updated.""" +type SoftwareAdoption { + status: SoftwareAdoptionStatus! + "The package manager the copy is reinstalled with." + packageManager: PackageManagerType + "Why the adoption failed. FAILED only." + error: String } # ────────── Vulnerability (CVE row) ────────── @@ -207,6 +243,30 @@ enum SoftwareCveSeverity { NONE } +"""Kind of software, from the inventory source.""" +enum SoftwareType { + "Desktop applications (Windows programs, macOS apps)." + APPLICATION + "Browser extensions and add-ons." + BROWSER_EXTENSION + "OS and package-manager packages (deb, rpm, Homebrew, Chocolatey, …)." + PACKAGE + OTHER +} + +"""Whether an auto-update policy keeps software updated.""" +enum SoftwareAutoUpdateStatus { + ON + OFF +} + +enum SoftwareAdoptionStatus { + "Reinstall with a package manager is queued or running; on an offline device it starts when it comes online." + ADOPTING + "The reinstall failed; the manually installed copy is left as it was." + FAILED +} + """Per-device software state: static (UP_TO_DATE / OUTDATED) or in a lifecycle transition (SCHEDULED_UPDATE / UNINSTALLING / SCHEDULED_UNINSTALL).""" enum SoftwareOnDeviceStatus { @@ -258,10 +318,16 @@ type SoftwareFilters { sources: [SoftwareFilterOption!]! versionStatuses: [SoftwareFilterOption!]! severities: [SoftwareFilterOption!]! + "AUTO-UPDATE dropdown: ON / OFF." + autoUpdateStatuses: [SoftwareFilterOption!]! } type SoftwareOnDeviceFilters { statuses: [SoftwareFilterOption!]! + "INSTALLED BY dropdown: WINGET / CHOCOLATEY / BREW / UNMANAGED (Manually)." + installedBy: [SoftwareFilterOption!]! + "AUTO-UPDATE dropdown: ON / OFF." + autoUpdateStatuses: [SoftwareFilterOption!]! } type SoftwareFilterOption { @@ -277,11 +343,16 @@ input SoftwareFilterInput { versionStatuses: [SoftwareVersionStatus!] minSeverity: SoftwareCveSeverity deviceTagIds: [ID!] + autoUpdateStatuses: [SoftwareAutoUpdateStatus!] } input SoftwareOnDeviceFilterInput { statuses: [SoftwareOnDeviceStatus!] deviceTagIds: [ID!] + "The Customer filter of the Adopt device picker." + organizationIds: [ID!] + installedBy: [SoftwareSource!] + autoUpdateStatuses: [SoftwareAutoUpdateStatus!] } input SoftwareVulnerabilityFilterInput { @@ -379,6 +450,36 @@ extend type Mutation { """Update one or more catalog packages on the given devices, immediately. Each package is dispatched as its own RMM execution; returns one result (with its executionId) per package.""" updateSoftware(input: SoftwareManagementInput!): [SoftwareDispatchResult!]! + + """Adopt a software title on devices that have it installed manually: reinstall it with a package manager, + so it can be updated. Runs now; an offline device starts when it comes online. The device picker lists + softwareDevices(softwareId, filter: {installedBy: [UNMANAGED]}). Returns one result per package manager used + (each its own execution, shown as an ADOPT row in Software Actions).""" + adoptSoftware(input: AdoptSoftwareInput!): [SoftwareDispatchResult!]! + + """Turn off auto-update for a software title on every device ("Turn Off Auto-Update"). Running updates + finish; no new version is installed automatically. Turned on again through Update Software (autoUpdate). + Idempotent: a title that has no auto-update is returned as it is. Unknown softwareId → NOT_FOUND.""" + turnOffSoftwareAutoUpdate(softwareId: ID!): Software! +} + +# ────────── Adopt ────────── + +input AdoptSoftwareInput { + "The software title (Software.id) to adopt." + softwareId: ID! + "Selected devices (Machine global ids). Each must have the title installed manually. 1..100." + machineIds: [ID!]! + "Package Manager for Windows. macOS devices always adopt with Brew." + windowsPackageManager: SoftwareAdoptionWindowsManager! = MATCH_CUSTOMER +} + +"""Which package manager adopts the title on Windows devices.""" +enum SoftwareAdoptionWindowsManager { + "The manager each customer already uses for this app; Winget if none." + MATCH_CUSTOMER + WINGET + CHOCOLATEY } """A set of catalog packages to install/update on a set of devices.""" diff --git a/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareActionSummary.java b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareActionSummary.java index 7c55ad6b43..4b8c030b5a 100644 --- a/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareActionSummary.java +++ b/openframe-data-mongo-common/src/main/java/com/openframe/data/document/rmm/software/SoftwareActionSummary.java @@ -13,10 +13,12 @@ public class SoftwareActionSummary { private String executionId; private PackageManagerType packageManager; private String packageName; + private String version; private SoftwareAction action; private SoftwareActionStatus status; private int totalMachineCount; private int respondedMachineCount; + private int waitingMachineCount; private Instant dispatchedAt; private String initiatedBy; From 78b07a272d7cb4945a680edaa64402cfcc4060b0 Mon Sep 17 00:00:00 2001 From: Andrii Koropets Date: Wed, 28 Oct 2026 01:13:34 +0200 Subject: [PATCH 4/4] Contract: added adoption, organizations and deviceStatuses --- .../resources/schema/software-action.graphqls | 1 + .../main/resources/schema/software.graphqls | 40 ++++++++++++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/openframe-api-service-core/src/main/resources/schema/software-action.graphqls b/openframe-api-service-core/src/main/resources/schema/software-action.graphqls index ef43a715bc..90acdd8570 100644 --- a/openframe-api-service-core/src/main/resources/schema/software-action.graphqls +++ b/openframe-api-service-core/src/main/resources/schema/software-action.graphqls @@ -120,6 +120,7 @@ organizationIds is the Customer filter.""" input SoftwareActionDeviceFilterInput { statuses: [SoftwareActionStatus!] organizationIds: [ID!] + deviceTagIds: [ID!] } type SoftwareActionRunConnection { diff --git a/openframe-api-service-core/src/main/resources/schema/software.graphqls b/openframe-api-service-core/src/main/resources/schema/software.graphqls index 5ee5dca702..5f6c87b243 100644 --- a/openframe-api-service-core/src/main/resources/schema/software.graphqls +++ b/openframe-api-service-core/src/main/resources/schema/software.graphqls @@ -164,13 +164,13 @@ type Software { """Kind of software — the Type field on the detail page (e.g. "Application").""" type: SoftwareType - """AUTO-UPDATE column and the detail page's "Turn Off Auto-Update" button. ON = an auto-update policy - keeps this title updated, OFF = a package manager installed it but no policy does. Null ("–") = no device - has it from a package manager, so there is nothing to auto-update.""" + """AUTO-UPDATE column and the detail page's "Turn Off Auto-Update" button (shown while ON). + Filterable with the same values (SoftwareFilterInput.autoUpdateStatuses). Null = unknown.""" autoUpdate: SoftwareAutoUpdateStatus """Devices that have this title installed manually (installedBy UNMANAGED) and can be adopted — the - ADOPTION column and the "N devices have … installed manually" banner with Adopt. Null or 0 = "–", no banner. + ADOPTION column and the "N devices have … installed manually" banner with Adopt. Null or 0 = "–", no banner; + always 0 when autoUpdate is NO_PACKAGE (nothing to adopt with). Sortable as adoptionCount.""" adoptionCount: Int } @@ -196,7 +196,8 @@ type SoftwareOnDevice { Null = no adoption.""" adoption: SoftwareAdoption - """AUTO-UPDATE column for this device: ON / OFF. Null ("–") = installed manually, nothing to auto-update.""" + """AUTO-UPDATE column for this device. Filterable with the same values + (SoftwareOnDeviceFilterInput.autoUpdateStatuses). Null = unknown.""" autoUpdate: SoftwareAutoUpdateStatus } @@ -254,10 +255,16 @@ enum SoftwareType { OTHER } -"""Whether an auto-update policy keeps software updated.""" +"""Whether software can be and is kept updated automatically — the AUTO-UPDATE column and its filter.""" enum SoftwareAutoUpdateStatus { + "An auto-update policy keeps it updated (the ON tag)." ON + "A package manager installed it, but no auto-update policy covers it (the OFF tag)." OFF + "No package manager has a package for this app, so it can't be auto-updated or adopted (\"No package found\")." + NO_PACKAGE + "Installed by hand: it needs adoption first (\"–\")." + NEEDS_ADOPTION } enum SoftwareAdoptionStatus { @@ -318,7 +325,7 @@ type SoftwareFilters { sources: [SoftwareFilterOption!]! versionStatuses: [SoftwareFilterOption!]! severities: [SoftwareFilterOption!]! - "AUTO-UPDATE dropdown: ON / OFF." + "AUTO-UPDATE dropdown: ON / OFF / NO_PACKAGE / NEEDS_ADOPTION." autoUpdateStatuses: [SoftwareFilterOption!]! } @@ -326,8 +333,12 @@ type SoftwareOnDeviceFilters { statuses: [SoftwareFilterOption!]! "INSTALLED BY dropdown: WINGET / CHOCOLATEY / BREW / UNMANAGED (Manually)." installedBy: [SoftwareFilterOption!]! - "AUTO-UPDATE dropdown: ON / OFF." + "AUTO-UPDATE dropdown: ON / OFF / NO_PACKAGE / NEEDS_ADOPTION." autoUpdateStatuses: [SoftwareFilterOption!]! + "CUSTOMER dropdown of the Adopt device picker: value = organizationId, label = its name." + organizations: [SoftwareFilterOption!]! + "STATUS dropdown of the Adopt device picker: the device statuses." + deviceStatuses: [SoftwareFilterOption!]! } type SoftwareFilterOption { @@ -349,8 +360,10 @@ input SoftwareFilterInput { input SoftwareOnDeviceFilterInput { statuses: [SoftwareOnDeviceStatus!] deviceTagIds: [ID!] - "The Customer filter of the Adopt device picker." + "The CUSTOMER filter of the Adopt device picker." organizationIds: [ID!] + "The STATUS filter of the Adopt device picker (the device's own status, e.g. ACTIVE = Managed)." + deviceStatuses: [DeviceStatus!] installedBy: [SoftwareSource!] autoUpdateStatuses: [SoftwareAutoUpdateStatus!] } @@ -468,8 +481,13 @@ extend type Mutation { input AdoptSoftwareInput { "The software title (Software.id) to adopt." softwareId: ID! - "Selected devices (Machine global ids). Each must have the title installed manually. 1..100." - machineIds: [ID!]! + """Selected devices (Machine global ids), 1..100. Devices that do not have the title installed manually are + skipped. Null = every device matching filter + search ("Add All Devices").""" + machineIds: [ID!] + """With machineIds null: the devices to adopt, as the picker's softwareDevices(softwareId, filter, search) lists + them. Always narrowed to installedBy UNMANAGED. Ignored when machineIds is set.""" + filter: SoftwareOnDeviceFilterInput + search: String "Package Manager for Windows. macOS devices always adopt with Brew." windowsPackageManager: SoftwareAdoptionWindowsManager! = MATCH_CUSTOMER }