Skip to content

Commit

Permalink
Send additional data to SCC (jsc#SUMA-406)
Browse files Browse the repository at this point in the history
  • Loading branch information
wweellddeerr committed Jan 22, 2025
1 parent 22f49ed commit 35f114b
Show file tree
Hide file tree
Showing 28 changed files with 775 additions and 3 deletions.
2 changes: 1 addition & 1 deletion java/buildconf/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
^/\*$
(^ \* Copyright \(c\) (20([0123]\d|20)--)?20(1\d|2[01234]) (Red Hat, Inc.|SUSE LLC)$)+
(^ \* Copyright \(c\) (20([01234]\d|20)--)?20(1\d|2[012345]) (Red Hat, Inc.|SUSE LLC)$)+
^ \*$
^ \* This software is licensed to you under the GNU General Public License,$
^ \* version 2 \(GPLv2\). There is NO WARRANTY for this software, express or$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import com.redhat.rhn.domain.scc.SCCRepositoryTokenAuth;
import com.redhat.rhn.domain.scc.SCCSubscription;
import com.redhat.rhn.domain.server.Pillar;
import com.redhat.rhn.domain.server.SAPWorkload;
import com.redhat.rhn.domain.server.ServerAppStream;
import com.redhat.rhn.domain.server.ansible.AnsiblePath;
import com.redhat.rhn.domain.server.ansible.InventoryPath;
Expand Down Expand Up @@ -203,7 +204,8 @@ private AnnotationRegistry() {
ServerAppStream.class,
AppStream.class,
AppStreamApi.class,
TokenChannelAppStream.class
TokenChannelAppStream.class,
SAPWorkload.class
);

/**
Expand Down
30 changes: 30 additions & 0 deletions java/code/src/com/redhat/rhn/domain/server/MinionServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class MinionServer extends Server implements SaltConfigurable {
private Set<AccessToken> accessTokens = new HashSet<>();
private Set<Pillar> pillars = new HashSet<>();
private Date rebootRequiredAfter;
private String containerRuntime;
private String uname;

/**
* Constructs a MinionServer instance.
Expand Down Expand Up @@ -352,4 +354,32 @@ public Date getRebootRequiredAfter() {
public void setRebootRequiredAfter(Date rebootRequiredAfterIn) {
rebootRequiredAfter = rebootRequiredAfterIn;
}

/**
* @return the container runtime
*/
public String getContainerRuntime() {
return containerRuntime;
}

/**
* @param containerRuntimeIn the container runtime to set
*/
public void setContainerRuntime(String containerRuntimeIn) {
this.containerRuntime = containerRuntimeIn;
}

/**
* @return the uname
*/
public String getUname() {
return uname;
}

/**
* @param unameIn the uname to set
*/
public void setUname(String unameIn) {
uname = unameIn;
}
}
114 changes: 114 additions & 0 deletions java/code/src/com/redhat/rhn/domain/server/SAPWorkload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright (c) 2025 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/
package com.redhat.rhn.domain.server;

import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "suseServerSAPWorkload")
public class SAPWorkload {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "sap_system_id")
private String systemIdSAP;

@Column(name = "instance_type")
private String instanceType;

@ManyToOne
@JoinColumn(name = "server_id")
private Server server;

/**
* Constructs a SAPWorkload instance.
*/
public SAPWorkload() { }

/**
* Constructs a SAPWorkload instance with the specified server, system ID, and instance type.
*
* @param serverIn the server
* @param systemIdSAPIn the SAP system
* @param instanceTypeIn the SAP type of instance
*/
public SAPWorkload(Server serverIn, String systemIdSAPIn, String instanceTypeIn) {
this.server = serverIn;
this.systemIdSAP = systemIdSAPIn;
this.instanceType = instanceTypeIn;
}

public Long getId() {
return id;
}

public void setId(Long idIn) {
id = idIn;
}

public String getSystemIdSAP() {
return systemIdSAP;
}

public void setSystemIdSAP(String systemIdSAPIn) {
systemIdSAP = systemIdSAPIn;
}

public String getInstanceType() {
return instanceType;
}

public void setInstanceType(String instanceTypeIn) {
instanceType = instanceTypeIn;
}

public Server getServer() {
return server;
}

public void setServer(Server serverIn) {
server = serverIn;
}

@Override
public boolean equals(Object oIn) {
if (this == oIn) {
return true;
}
if (oIn == null || getClass() != oIn.getClass()) {
return false;
}
SAPWorkload that = (SAPWorkload) oIn;
return Objects.equals(systemIdSAP, that.systemIdSAP) &&
Objects.equals(instanceType, that.instanceType) &&
Objects.equals(server, that.server);
}

@Override
public int hashCode() {
return Objects.hash(systemIdSAP, instanceType, server);
}
}
20 changes: 20 additions & 0 deletions java/code/src/com/redhat/rhn/domain/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public class Server extends BaseDomainHelper implements Identifiable {
private Boolean hasConfigFeature;
private Set<ServerAppStream> appStreams = new HashSet<>();

private Set<SAPWorkload> sapWorkloads = new HashSet<>();

private String cpe;

public static final String VALID_CNAMES = "valid_cnames_";
Expand Down Expand Up @@ -2667,4 +2669,22 @@ public void setAppStreams(Set<ServerAppStream> appStreamsIn) {
public boolean hasAppStreamModuleEnabled(String module, String stream) {
return getAppStreams().stream().anyMatch(it -> it.getName().equals(module) && it.getStream().equals(stream));
}

/**
* Getter for SAPWorkloads
*
* @return Set of SAPWorkload
*/
public Set<SAPWorkload> getSapWorkloads() {
return sapWorkloads;
}

/**
* Setter for SAPWorkloads
*
* @param sapWorkloadsIn to set
*/
public void setSapWorkloads(Set<SAPWorkload> sapWorkloadsIn) {
sapWorkloads = sapWorkloadsIn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<one-to-many class="com.redhat.rhn.domain.server.ClientCapability"/>
</set>

<set name="sapWorkloads" lazy="true" inverse="true" table="suseServerSAPWorkload" cascade="all-delete-orphan">
<key column="server_id"/>
<one-to-many class="com.redhat.rhn.domain.server.SAPWorkload"/>
</set>

<many-to-one name="org" class="com.redhat.rhn.domain.org.Org"
column="org_id" lazy="proxy"/>

Expand Down Expand Up @@ -197,6 +202,8 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
table="suseMinionInfo">
<key column="server_id"/>
<property name="minionId" column="minion_id" />
<property name="uname" column="uname" type="string" />
<property name="containerRuntime" column="container_runtime" type="string" />
<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" />
Expand Down
15 changes: 15 additions & 0 deletions java/code/src/com/suse/manager/utils/SaltUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import com.redhat.rhn.domain.server.InstalledPackage;
import com.redhat.rhn.domain.server.InstalledProduct;
import com.redhat.rhn.domain.server.MinionServer;
import com.redhat.rhn.domain.server.SAPWorkload;
import com.redhat.rhn.domain.server.Server;
import com.redhat.rhn.domain.server.ServerAppStream;
import com.redhat.rhn.domain.server.ServerFactory;
Expand Down Expand Up @@ -1858,6 +1859,20 @@ private static void handleHardwareProfileUpdate(MinionServer server,
).distinct().toList()
);
server.setPayg(result.getInstanceFlavor().map(o -> o.equals("PAYG")).orElse(false));
server.setContainerRuntime(result.getContainerRuntime());
server.setUname(result.getUname());

var sapWorkloads = result.getSAPWorkloads()
.map(m -> m.getChanges().getRet())
.orElse(Collections.emptySet())
.stream()
.map(workload -> new SAPWorkload(
server, workload.get("system_id"), workload.get("instance_type")
))
.collect(Collectors.toSet());

server.getSapWorkloads().retainAll(sapWorkloads);
server.getSapWorkloads().addAll(sapWorkloads);

// Let the action fail in case there is error messages
if (!hwMapper.getErrors().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.suse.salt.netapi.calls.modules.Network;
import com.suse.salt.netapi.calls.modules.Smbios;
import com.suse.salt.netapi.results.CmdResult;
import com.suse.salt.netapi.results.Ret;
import com.suse.salt.netapi.results.StateApplyResult;

Expand All @@ -28,6 +29,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;


/**
Expand Down Expand Up @@ -86,6 +88,15 @@ public class HwProfileUpdateSlsResult {
@SerializedName("mgrcompat_|-mainframe-sysinfo_|-mainframesysinfo.read_values_|-module_run")
private Optional<StateApplyResult<Ret<String>>> mainframeSysinfo = Optional.empty();

@SerializedName("mgrcompat_|-sap_workloads_|-sap.get_workloads_|-module_run")
private Optional<StateApplyResult<Ret<Set<Map<String, String>>>>> sapWorkloads = Optional.empty();

@SerializedName("mgrcompat_|-container_runtime_|-container_runtime.get_container_runtime_|-module_run")
private Optional<StateApplyResult<Ret<String>>> containerRuntime = Optional.empty();

@SerializedName("cmd_|-uname_|-uname -r -v_|-run")
private Optional<StateApplyResult<CmdResult>> uname = Optional.empty();

/**
* @return the grains
*/
Expand Down Expand Up @@ -244,4 +255,27 @@ public List<String> getCustomFqdns() {
)).orElseGet(Collections::emptyList);
}

/**
* Get system SAP workloads
* @return the list of system SAP workloads
*/
public Optional<StateApplyResult<Ret<Set<Map<String, String>>>>> getSAPWorkloads() {
return sapWorkloads;
}

/**
* Get the container runtime.
* @return the container runtime
*/
public String getContainerRuntime() {
return containerRuntime.map(retStateApplyResultIn -> retStateApplyResultIn.getChanges().getRet()).orElse(null);
}

/**
* Get the uname result
* @return the uname
*/
public String getUname() {
return uname.map(ret -> ret.getChanges().getStdout()).orElse(null);
}
}
46 changes: 46 additions & 0 deletions java/code/src/com/suse/scc/model/SAPJson.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2025 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/
package com.suse.scc.model;

import com.google.gson.annotations.SerializedName;

import java.util.List;

public class SAPJson {

@SerializedName("system_id")
private String systemId;

@SerializedName("instance_types")
private List<String> instanceTypes;

/**
* Constructor
* @param systemIdIn - the SAP system id
* @param instanceTypesIn - the array of SAP instance types
*/
public SAPJson(String systemIdIn, List<String> instanceTypesIn) {
systemId = systemIdIn;
instanceTypes = instanceTypesIn;
}

public String getSystemId() {
return systemId;
}

public List<String> getInstanceTypes() {
return instanceTypes;
}
}
Loading

0 comments on commit 35f114b

Please sign in to comment.