Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include reboot required indication for non-Suse distros #7941

Merged
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
22 changes: 10 additions & 12 deletions java/code/src/com/redhat/rhn/domain/server/MinionServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
Expand All @@ -39,14 +40,7 @@ public class MinionServer extends Server implements SaltConfigurable {
private Integer sshPushPort;
private Set<AccessToken> accessTokens = new HashSet<>();
private Set<Pillar> pillars = new HashSet<>();
/**
We typically look at the packages installed on a system to identify whether a reboot is necessary.
This property initially only works for transactional systems, but the idea is that gradually the
other types of systems also provide this information directly to be stored here so we no longer rely
on package related inference to determine whether a reboot is necessary. Even because this
information does not always depend only on the packages.
*/
private Boolean rebootNeeded;
private Date rebootRequiredAfter;

/**
* Constructs a MinionServer instance.
Expand Down Expand Up @@ -325,11 +319,15 @@ private boolean updateServerPaths(Optional<Server> proxy, Optional<String> hostn
return changed;
}

public Boolean isRebootNeeded() {
return rebootNeeded;
public boolean isRebootNeeded() {
return getLastBoot() != null && rebootRequiredAfter != null && getLastBootAsDate().before(rebootRequiredAfter);
}

public Date getRebootRequiredAfter() {
return rebootRequiredAfter;
}

public void setRebootNeeded(Boolean rebootNeededIn) {
this.rebootNeeded = rebootNeededIn;
public void setRebootRequiredAfter(Date rebootRequiredAfterIn) {
rebootRequiredAfter = rebootRequiredAfterIn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,7 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
table="suseMinionInfo">
<key column="server_id"/>
<property name="minionId" column="minion_id" />
<!--
We typically look at the packages installed on a system to identify whether a reboot is necessary.
This property initially only works for transactional systems, but the idea is that gradually the
other types of systems also provide this information directly to be stored here so we no longer rely
on package related inference to determine whether a reboot is necessary. Even because this
information does not always depend only on the packages.
-->
<property name="rebootNeeded" column="reboot_needed" type="yes_no" />
<property name="rebootRequiredAfter" column="reboot_required_after" type="timestamp" />
<property name="osFamily" column="os_family" type="string" length="32" />
<property name="kernelLiveVersion" column="kernel_live_version" type="string" length="255" />
<property name="sshPushPort" column="ssh_push_port" access="field"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class UpgradeCommand extends BaseTransactionCommand {
UPGRADE_TASK_NAME + "refresh_custom_sls_files";
public static final String REFRESH_VIRTHOST_PILLARS =
UPGRADE_TASK_NAME + "virthost_pillar_refresh";
public static final String REFRESH_ALL_SYSTEMS_PILLARS =
UPGRADE_TASK_NAME + "all_systems_pillar_refresh";
public static final String SYSTEM_THRESHOLD_FROM_CONFIG =
UPGRADE_TASK_NAME + "system_threshold_conf";

Expand Down Expand Up @@ -152,6 +154,9 @@ public void upgrade() {
case SYSTEM_THRESHOLD_FROM_CONFIG:
convertSystemThresholdFromConfig();
break;
case REFRESH_ALL_SYSTEMS_PILLARS:
refreshAllSystemsPillar();
break;
default:
}
// always run this
Expand Down Expand Up @@ -359,6 +364,22 @@ private void refreshVirtHostPillar() {
}
}

/**
* Regenerate pillar data for every registered system.
*/
private void refreshAllSystemsPillar() {
try {
List<MinionServer> hosts = MinionServerFactory.listMinions();
hosts.forEach(MinionPillarManager.INSTANCE::generatePillar);
List<String> minionIds = hosts.stream().map(MinionServer::getMinionId).collect(Collectors.toList());
GlobalInstanceHolder.SALT_API.refreshPillar(new MinionList(minionIds));
log.info("Refreshed hosts pillar");
}
catch (Exception e) {
log.error("Error refreshing hosts pillar. Ignoring.", e);
}
}

private void convertSystemThresholdFromConfig() {
log.warn("Converting web.system_checkin_threshold to DB config");
SatConfigFactory.setSatConfigValue(SatConfigFactory.SYSTEM_CHECKIN_THRESHOLD,
Expand Down
5 changes: 4 additions & 1 deletion java/code/src/com/suse/manager/reactor/SaltReactor.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Date;
import java.util.Optional;
import java.util.stream.Stream;

Expand Down Expand Up @@ -326,7 +327,9 @@ else if (beaconEvent.getBeacon().equals("reboot_info")) {
Optional<MinionServer> minion = MinionServerFactory.findByMinionId(beaconEvent.getMinionId());
minion.ifPresent(
m -> {
m.setRebootNeeded((Boolean) beaconEvent.getData().get("reboot_needed"));
Boolean rebootRequired = (Boolean) beaconEvent.getData().get("reboot_needed");
Date rebootRequiredAfter = rebootRequired ? new Date() : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unboxing might throw NullPointerException, if reboot_needed can be null. if so use BooleanUtils.isTrue():

Suggested change
Date rebootRequiredAfter = rebootRequired ? new Date() : null;
Date rebootRequiredAfter = BooleanUtils.isTrue(rebootRequired) ? new Date() : null;

m.setRebootRequiredAfter(rebootRequiredAfter);
SystemManager.updateSystemOverview(m);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ public void setUp() {
public void testRebootInfoEvent() throws Exception {
MinionServer minion1 = MinionServerFactoryTest.createTestMinionServer(user);
minion1.setMinionId("slemicro100001");
minion1.setRebootNeeded(false);
minion1.setLastBoot(System.currentTimeMillis() / 1000);
minion1.setRebootRequiredAfter(null);

MinionServer minion2 = MinionServerFactoryTest.createTestMinionServer(user);
minion2.setMinionId("slemicro100002");
minion2.setRebootNeeded(false);
minion1.setLastBoot(System.currentTimeMillis() / 1000);
minion2.setRebootRequiredAfter(null);

// Event indicating that reboot is needed for minion 1
BeaconEvent event = buildRebootInfoEvent(minion1.getMinionId(), true);
Expand Down
4 changes: 4 additions & 0 deletions java/code/src/com/suse/manager/utils/SaltUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,10 @@ else if ("debian".equalsIgnoreCase(grains.getValueAsString("os"))) {
.map(n -> n.longValue())
.orElse(null));

result.getRebootRequired()
.map(flag -> (Boolean) flag.getChanges().getRet().get("reboot_required"))
.ifPresent(flag -> server.setRebootRequiredAfter(flag ? new Date() : null));

// Update live patching version
server.setKernelLiveVersion(result.getKernelLiveVersionInfo()
.map(klv -> klv.getChanges().getRet()).filter(Objects::nonNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ public class MinionGeneralPillarGenerator extends MinionPillarGeneratorBase {
public static final String CATEGORY = "general";

private static final int PKGSET_INTERVAL = 5;
private static final Integer REBOOT_INFO_INTERVAL = 10;

private static final Map<String, Object> PKGSET_BEACON_PROPS = new HashMap<>();
private static final Map<String, Object> REBOOT_INFO_BEACON_PROPS = new HashMap<>();

static {
PKGSET_BEACON_PROPS.put("interval", PKGSET_INTERVAL);
REBOOT_INFO_BEACON_PROPS.put("interval", REBOOT_INFO_INTERVAL);
}

/**
Expand Down Expand Up @@ -91,6 +95,7 @@ public Optional<Pillar> generatePillarData(MinionServer minion) {
minion.getOsFamily().toLowerCase().equals("redhat") ||
minion.getOsFamily().toLowerCase().equals("debian")) {
beaconConfig.put("pkgset", PKGSET_BEACON_PROPS);
beaconConfig.put("reboot_info", REBOOT_INFO_BEACON_PROPS);
}
if (!beaconConfig.isEmpty()) {
pillar.add("beacons", beaconConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class PkgProfileUpdateSlsResult {
@SerializedName("mgrcompat_|-status_uptime_|-status.uptime_|-module_run")
private Optional<StateApplyResult<Ret<Map<String, Object>>>> upTime = Optional.empty();

@SerializedName("mgrcompat_|-reboot_required_|-reboot_info.reboot_required_|-module_run")
private Optional<StateApplyResult<Ret<Map<String, Object>>>> rebootRequired = Optional.empty();

@SerializedName("mgrcompat_|-kernel_live_version_|-sumautil.get_kernel_live_version_|-module_run")
private Optional<StateApplyResult<Ret<KernelLiveVersionInfo>>> kernelLiveVersionInfo = Optional.empty();

Expand Down Expand Up @@ -103,6 +106,14 @@ public Optional<StateApplyResult<Ret<Map<String, Object>>>> getUpTime() {
return upTime;
}

/**
* Gets the reboot required indication
* @return optional of reboot required flag
*/
public Optional<StateApplyResult<Ret<Map<String, Object>>>> getRebootRequired() {
return rebootRequired;
}

/**
* Gets live patching info.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Include reboot required indication for non-Suse distros
18 changes: 9 additions & 9 deletions schema/spacewalk/common/tables/suseMinionInfo.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

CREATE TABLE suseMinionInfo
(
server_id NUMERIC NOT NULL
CONSTRAINT suse_minion_info_sid_fk
REFERENCES rhnServer (id)
ON DELETE CASCADE,
minion_id VARCHAR(256) NOT NULL,
os_family VARCHAR(32),
kernel_live_version VARCHAR(255),
ssh_push_port NUMERIC,
reboot_needed CHAR(1),
server_id NUMERIC NOT NULL
CONSTRAINT suse_minion_info_sid_fk
REFERENCES rhnServer (id)
ON DELETE CASCADE,
minion_id VARCHAR(256) NOT NULL,
os_family VARCHAR(32),
kernel_live_version VARCHAR(255),
ssh_push_port NUMERIC,
reboot_required_after TIMESTAMPTZ,
created TIMESTAMPTZ
DEFAULT (current_timestamp) NOT NULL,
modified TIMESTAMPTZ
Expand Down
5 changes: 3 additions & 2 deletions schema/spacewalk/postgres/procs/update_system_overview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ begin
(SELECT 1
FROM suseMinionInfo smi
WHERE smi.server_id = S.id
AND smi.reboot_needed = 'Y'
AND to_date('1970-01-01', 'YYYY-MM-DD')
+ numtodsinterval(S.last_boot, 'second') < smi.reboot_required_after at time zone 'UTC'
)
);
);

SELECT TRUE into new_kickstarting
FROM rhnKickstartSession KSS, rhnKickstartSessionState KSSS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ALTER TABLE suseMinionInfo ADD COLUMN IF NOT EXISTS
reboot_required_after TIMESTAMPTZ;

DO $$
BEGIN
IF EXISTS (
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'suseminioninfo' AND column_name = 'reboot_needed'
) THEN
UPDATE suseMinionInfo
SET reboot_required_after = CASE
WHEN reboot_needed = 'Y' THEN CURRENT_TIMESTAMP
ELSE NULL
END;
END IF;
END $$;

ALTER TABLE suseMinionInfo DROP COLUMN IF EXISTS reboot_needed;
Loading