Fixed code

This commit is contained in:
Luca Frosini 2022-03-11 11:03:43 +01:00
parent 3751ae9796
commit 4839ac5b4e
3 changed files with 21 additions and 21 deletions

View File

@ -14,9 +14,11 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -29,6 +31,7 @@ import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
@ -44,6 +47,7 @@ import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClien
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.LocationFacetImpl;
@ -268,30 +272,28 @@ public class HostingNodeManager {
public static SoftwareFacet getOperativeSystem() {
SoftwareFacet osSoftwareFacet = new SoftwareFacetImpl();
OperatingSystemMXBean mxbean = ManagementFactory.getOperatingSystemMXBean();
osSoftwareFacet.setGroup(mxbean.getName()); // softwareFacet.setGroup(System.getProperty("os.name"));
String osName = mxbean.getName();
osSoftwareFacet.setGroup(osName); // softwareFacet.setGroup(System.getProperty("os.name"));
osSoftwareFacet.setName(mxbean.getArch()); // softwareFacet.setName(System.getProperty("os.arch"));
osSoftwareFacet.setVersion(mxbean.getVersion()); // softwareFacet.setName(System.getProperty("os.version"));
osSoftwareFacet.setVersion(mxbean.getVersion()); // softwareFacet.setVersion(System.getProperty("os.version"));
if(osSoftwareFacet.getGroup().compareTo("Linux")==0) {
JsonNode jsonNode = ElementMapper.getObjectMapper().valueToTree(osSoftwareFacet);
Set<String> fieldNames = new TreeSet<>();
Iterator<String> it = jsonNode.fieldNames();
while (it.hasNext()) fieldNames.add(it.next());
if(osName.compareTo("Linux")==0) {
// Adding Linux Distribution Info
LinuxDistributionInfo linuxDistributionInfo = new LinuxDistributionInfo();
Map<String, String> map = linuxDistributionInfo.getInfo();
Set<String> keys = map.keySet();
for(String key : keys) {
switch (key) {
case SoftwareFacet.NAME:
case SoftwareFacet.GROUP_PROPERTY:
case SoftwareFacet.VERSION_PROPERTY:
osSoftwareFacet.setAdditionalProperty("Distribution-" + key, map.get(key));
break;
default:
osSoftwareFacet.setAdditionalProperty(key, map.get(key));
break;
String k = key;
if(fieldNames.contains(key)) {
k = "linuxDistribution-" + k;
}
osSoftwareFacet.setAdditionalProperty(k, map.get(key));
}
}
return osSoftwareFacet;

View File

@ -2,7 +2,6 @@ package org.gcube.smartgears.handler.resourceregistry.resourcemanager;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
@ -44,9 +43,9 @@ public class LinuxDistributionInfo {
}
private String[] parseLine(String line) {
String[] splitted = line.split(":");
String[] splitted = line.split("=");
if (splitted.length < 2) {
splitted = line.split("=");
splitted = line.split(":");
}
String[] ret = new String[2];
ret[0] = splitted[0].trim();

View File

@ -58,13 +58,12 @@ public class HostingNodeManagerTest {
@Test
public void testGetLinuxDistributionInfo() {
LinuxDistributionInfo l = new LinuxDistributionInfo();
Map<String,String> map = l.getInfo();
LinuxDistributionInfo linuxDistributionInfo = new LinuxDistributionInfo();
Map<String,String> map = linuxDistributionInfo.getInfo();
logger.info("{}", map);
}
@Test
public void testGetOSFacet() {
SoftwareFacet softwareFacet = HostingNodeManager.getOperativeSystem();