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 6, 2025
1 parent dde0d80 commit ac66fa7
Show file tree
Hide file tree
Showing 27 changed files with 706 additions and 2 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([0123]\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
15 changes: 15 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,7 @@ 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;

/**
* Constructs a MinionServer instance.
Expand Down Expand Up @@ -352,4 +353,18 @@ 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;
}
}
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 = "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 @@ -2669,4 +2671,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,7 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
table="suseMinionInfo">
<key column="server_id"/>
<property name="minionId" column="minion_id" />
<property name="containerRuntime" column="container_runtime" type="string" length="20" />
<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
14 changes: 14 additions & 0 deletions java/code/src/com/suse/manager/utils/SaltUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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 @@ -1870,6 +1871,19 @@ private static void handleHardwareProfileUpdate(MinionServer server,
).distinct().toList()
);
server.setPayg(result.getInstanceFlavor().map(o -> o.equals("PAYG")).orElse(false));
server.setContainerRuntime(result.getContainerRuntime());

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 @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;


/**
Expand Down Expand Up @@ -86,6 +87,12 @@ 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();

/**
* @return the grains
*/
Expand Down Expand Up @@ -244,4 +251,19 @@ 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);
}
}
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;
}
}
33 changes: 33 additions & 0 deletions java/code/src/com/suse/scc/model/SCCHwInfoJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import com.google.gson.annotations.SerializedName;

import java.util.Set;

/**
* This is a System Item send to SCC for registration.
*/
Expand All @@ -31,9 +33,16 @@ public class SCCHwInfoJson {
private String uuid;
private String hypervisor;

private String uname;

@SerializedName("container_runtime")
private String containerRuntime;

@SerializedName("cloud_provider")
private String cloudProvider;

private Set<SAPJson> sap;

public int getCpus() {
return cpus;
}
Expand Down Expand Up @@ -89,4 +98,28 @@ public int getMemTotal() {
public void setMemTotal(int memTotalIn) {
memTotal = memTotalIn;
}

public Set<SAPJson> getSap() {
return sap;
}

public void setSap(Set<SAPJson> sapIn) {
sap = sapIn;
}

public String getUname() {
return uname;
}

public void setUname(String unameIn) {
uname = unameIn;
}

public String getContainerRuntime() {
return containerRuntime;
}

public void setContainerRuntime(String containerRuntimeIn) {
containerRuntime = containerRuntimeIn;
}
}
Loading

0 comments on commit ac66fa7

Please sign in to comment.