Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void dispatchPackage(SoftwareBundle bundle, SoftwareBundlePackage pkg, M
.softwareBundleId(bundle.getId())
.build();
if (viaOrder) {
packageUpdateDispatchService.dispatchAdminUpdateNow(rows, pkg.getBrewPackageType());
packageUpdateDispatchService.dispatchAdminUpdate(rows, pkg.getBrewPackageType(), bundle.getUpdateSettings());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ private void dispatchPackage(SoftwareSchedule schedule, SoftwareSchedulePackage
.build();

if (!orderTargets.isEmpty()) {
packageUpdateDispatchService.dispatchAdminUpdateNow(rows.toBuilder().machineIds(orderTargets).build(),
pkg.getBrewPackageType());
packageUpdateDispatchService.dispatchAdminUpdate(rows.toBuilder().machineIds(orderTargets).build(),
pkg.getBrewPackageType(), schedule.getUpdateSettings());
}
if (scriptTargets.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.openframe.data.document.rmm.script.Script;
import com.openframe.data.document.rmm.script.ScriptShell;
import com.openframe.data.document.rmm.script.ScriptType;
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.SoftwareExecutionId;
import com.openframe.data.nats.packageupdate.PackageUpdateDispatchService;
Expand Down Expand Up @@ -138,7 +140,7 @@ void dispatch_mixedOs_routesPerPackage() {
}

@Test
@DisplayName("update: feature-enabled devices get a package-update order, the rest the script, under the schedule's execution id")
@DisplayName("update: feature-enabled devices get a package-update order with the schedule's update settings, the rest the script, under the schedule's execution id")
void dispatch_update_splitsOrderAndScriptTargets() {
when(tenantIdProvider.getTenantId()).thenReturn(TENANT);
when(machineRepository.findByTenantIdAndMachineIdIn(eq(TENANT), any()))
Expand All @@ -147,19 +149,22 @@ void dispatch_update_splitsOrderAndScriptTargets() {
.thenReturn(Optional.of(script("brew-update-id", OsType.MAC_OS)));
when(packageUpdateEligibility.eligibleMachines(SoftwareAction.UPDATE, List.of("m-1", "m-2")))
.thenReturn(Set.of("m-1"));
PackageUpdateSettings settings = PackageUpdateSettings.builder()
.mode(PackageUpdateMode.FORCE).countdownSeconds(120).build();

SoftwareSchedule schedule = SoftwareSchedule.builder()
.id("ss-1").tenantId(TENANT).createdBy("user-1").action(SoftwareAction.UPDATE)
.packages(List.of(SoftwareSchedulePackage.builder()
.packageManager(PackageManagerType.BREW).packageName("slack").brewPackageType(BrewPackageType.CASK)
.build()))
.updateSettings(settings)
.build();

dispatcher.dispatch(schedule, List.of("m-1", "m-2"), Instant.now());

String executionId = SoftwareExecutionId.forSchedule("ss-1", PackageManagerType.BREW, "slack");
ArgumentCaptor<RunningExecutionRows> order = ArgumentCaptor.forClass(RunningExecutionRows.class);
verify(packageUpdateDispatchService).dispatchAdminUpdateNow(order.capture(), eq(BrewPackageType.CASK));
verify(packageUpdateDispatchService).dispatchAdminUpdate(order.capture(), eq(BrewPackageType.CASK), eq(settings));
assertThat(order.getValue().getExecutionId()).isEqualTo(executionId);
assertThat(order.getValue().getMachineIds()).containsExactly("m-1");
assertThat(order.getValue().getScriptId()).isEqualTo("brew-update-id");
Expand Down Expand Up @@ -195,7 +200,7 @@ void dispatch_update_allEligible_noScript() {
dispatcher.dispatch(schedule, List.of("m-1"), Instant.now());

ArgumentCaptor<RunningExecutionRows> order = ArgumentCaptor.forClass(RunningExecutionRows.class);
verify(packageUpdateDispatchService).dispatchAdminUpdateNow(order.capture(), eq(BrewPackageType.CASK));
verify(packageUpdateDispatchService).dispatchAdminUpdate(order.capture(), eq(BrewPackageType.CASK), any());
assertThat(order.getValue().getMachineIds()).containsExactly("m-1");
verify(scriptExecutionRepository, never()).saveQueued(any());
verify(softwareNatsPublisher, never()).publishSoftware(any(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.openframe.data.document.rmm.script.Script;
import com.openframe.data.document.rmm.script.ScriptShell;
import com.openframe.data.document.rmm.script.ScriptType;
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.SoftwareBundle;
import com.openframe.data.document.rmm.software.SoftwareBundlePackage;
Expand Down Expand Up @@ -65,16 +67,20 @@ void setUp() {
}

@Test
@DisplayName("update on a feature-enabled device: a package-update order under the bundle's execution id, no script")
@DisplayName("update on a feature-enabled device: a package-update order under the bundle's execution id and with its update settings, no script")
void update_eligibleDevice_sendsOrder() {
when(scriptRepository.findByTenantIdAndNameAndType(TENANT, "__software__brew-update", ScriptType.SOFTWARE))
.thenReturn(Optional.of(script("brew-update-id")));
when(packageUpdateEligibility.isEligible(SoftwareAction.UPDATE, mac)).thenReturn(true);
PackageUpdateSettings settings = PackageUpdateSettings.builder()
.mode(PackageUpdateMode.WAIT).deadlineSeconds(86_400L).countdownSeconds(600).build();
SoftwareBundle bundle = bundle(SoftwareAction.UPDATE);
bundle.setUpdateSettings(settings);

dispatcher.dispatch(bundle(SoftwareAction.UPDATE), mac);
dispatcher.dispatch(bundle, mac);

ArgumentCaptor<RunningExecutionRows> order = ArgumentCaptor.forClass(RunningExecutionRows.class);
verify(packageUpdateDispatchService).dispatchAdminUpdateNow(order.capture(), eq(BrewPackageType.CASK));
verify(packageUpdateDispatchService).dispatchAdminUpdate(order.capture(), eq(BrewPackageType.CASK), eq(settings));
RunningExecutionRows rows = order.getValue();
assertThat(rows.getExecutionId()).isEqualTo(SoftwareExecutionId.forBundle("b-1", PackageManagerType.BREW, "slack"));
assertThat(rows.getMachineIds()).containsExactly("m-1");
Expand All @@ -97,7 +103,7 @@ void update_notEligible_runsScript() {
verify(scriptExecutionRepository).saveQueued(rows.capture());
assertThat(rows.getValue().getMachineIds()).containsExactly("m-1");
verify(softwareNatsPublisher).publishSoftware(eq("m-1"), any());
verify(packageUpdateDispatchService, never()).dispatchAdminUpdateNow(any(), any());
verify(packageUpdateDispatchService, never()).dispatchAdminUpdate(any(), any(), any());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.openframe.data.document.rmm.software.PackageUpdateDeviceState;
import com.openframe.data.document.rmm.software.PackageUpdateMode;
import com.openframe.data.document.rmm.software.PackageUpdateRequest;
import com.openframe.data.document.rmm.software.PackageUpdateSettings;
import com.openframe.data.document.rmm.software.PackageUpdateSource;
import com.openframe.data.document.rmm.software.SoftwareAction;
import com.openframe.data.document.rmm.software.SoftwareActionStatus;
Expand Down Expand Up @@ -41,6 +42,17 @@ public void dispatchAdminUpdateNow(RunningExecutionRows execution, BrewPackageTy
DEFAULT_FORCE_COUNTDOWN_SECONDS, null);
}

// Bundles and schedules saved before Update Settings existed carry none and keep the old behaviour.
public void dispatchAdminUpdate(RunningExecutionRows execution, BrewPackageType brewPackageType,
PackageUpdateSettings settings) {
if (settings == null) {
dispatchAdminUpdateNow(execution, brewPackageType);
return;
}
dispatch(execution, brewPackageType, PackageUpdateSource.ADMIN, settings.getMode(),
settings.getCountdownSeconds(), settings.getDeadlineSeconds());
}

// Every dispatch is its own request, so a shared execution id never collides on the request index.
public void dispatch(RunningExecutionRows execution, BrewPackageType brewPackageType, PackageUpdateSource source,
PackageUpdateMode mode, Integer forceCountdownSeconds, Long deadlineSeconds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.openframe.data.document.rmm.software.PackageUpdateDeviceState;
import com.openframe.data.document.rmm.software.PackageUpdateMode;
import com.openframe.data.document.rmm.software.PackageUpdateRequest;
import com.openframe.data.document.rmm.software.PackageUpdateSettings;
import com.openframe.data.document.rmm.software.PackageUpdateSource;
import com.openframe.data.document.rmm.software.SoftwareAction;
import com.openframe.data.document.rmm.software.SoftwareActionStatus;
Expand Down Expand Up @@ -108,6 +109,53 @@ void adminUpdateNow_winget_persistsRequestDeviceStatesAndOrdersPerMachine() {
.containsExactlyInAnyOrder("m1", "m2");
}

@Test
void adminUpdate_withSettings_ordersWithTheirModeDeadlineAndCountdown() {
when(tenantIdProvider.getTenantId()).thenReturn("t1");
PackageUpdateSettings settings = PackageUpdateSettings.builder()
.mode(PackageUpdateMode.WAIT).deadlineSeconds(259_200L).countdownSeconds(900).build();

service.dispatchAdminUpdate(rows("exec-1", PackageManagerType.WINGET, "Google.Chrome", "m1"), null, settings);

ArgumentCaptor<PackageUpdateRequest> req = ArgumentCaptor.forClass(PackageUpdateRequest.class);
verify(requestRepository).save(req.capture());
assertThat(req.getValue().getSource()).isEqualTo(PackageUpdateSource.ADMIN);
assertThat(req.getValue().getMode()).isEqualTo(PackageUpdateMode.WAIT);
assertThat(req.getValue().getDeadlineSeconds()).isEqualTo(259_200L);
assertThat(req.getValue().getForceCountdownSeconds()).isEqualTo(900);
}

@Test
void adminUpdate_force_sendsTheCountdownWithTheOrder() {
when(tenantIdProvider.getTenantId()).thenReturn("t1");
PackageUpdateSettings settings = PackageUpdateSettings.builder()
.mode(PackageUpdateMode.FORCE).countdownSeconds(120).build();

service.dispatchAdminUpdate(rows("exec-1", PackageManagerType.WINGET, "Google.Chrome", "m1"), null, settings);

ArgumentCaptor<PackageUpdateRequest> req = ArgumentCaptor.forClass(PackageUpdateRequest.class);
verify(requestRepository).save(req.capture());
assertThat(req.getValue().getMode()).isEqualTo(PackageUpdateMode.FORCE);
assertThat(req.getValue().getDeadlineSeconds()).isNull();
ArgumentCaptor<PackageUpdateDeliverySeed> seed = ArgumentCaptor.forClass(PackageUpdateDeliverySeed.class);
verify(deliveryDispatcher).dispatch(seed.capture());
assertThat(seed.getValue().getMode()).isEqualTo(PackageUpdateMode.FORCE);
assertThat(seed.getValue().getCountdownSeconds()).isEqualTo(120);
}

@Test
void adminUpdate_withoutSettings_keepsTheUpdateNowDefaults() {
when(tenantIdProvider.getTenantId()).thenReturn("t1");

service.dispatchAdminUpdate(rows("exec-1", PackageManagerType.WINGET, "Google.Chrome", "m1"), null, null);

ArgumentCaptor<PackageUpdateRequest> req = ArgumentCaptor.forClass(PackageUpdateRequest.class);
verify(requestRepository).save(req.capture());
assertThat(req.getValue().getMode()).isEqualTo(PackageUpdateMode.WAIT);
assertThat(req.getValue().getDeadlineSeconds()).isNull();
assertThat(req.getValue().getForceCountdownSeconds()).isEqualTo(300);
}

@Test
void adminUpdateNow_writesHistoryRowsOwnedByTheRequest_beforeAnyOrder() {
when(tenantIdProvider.getTenantId()).thenReturn("t1");
Expand Down
Loading