From caf354617a561071859dc600f4051c8ff6025ea0 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 17 May 2023 18:04:14 +0200 Subject: [PATCH] Fixed tests --- .../publisher/ERManagementTest.java | 2 + .../publisher/InvalidOperationTest.java | 30 +- .../publisher/old/ERManagementTest.java | 235 ++++----- .../publisher/old/MultiContextTest.java | 25 +- .../publisher/old/RRClientTest.java | 142 ----- .../publisher/old/SmartgearResourcesTest.java | 484 ------------------ 6 files changed, 123 insertions(+), 795 deletions(-) delete mode 100644 src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/RRClientTest.java delete mode 100644 src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/SmartgearResourcesTest.java diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java index 4cf6e31..cc04c34 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java @@ -91,6 +91,8 @@ public class ERManagementTest extends ContextTest { }else { resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); } + resourceRegistryPublisher.setIncludeMeta(true); + resourceRegistryPublisher.setAllMeta(true); } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/InvalidOperationTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/InvalidOperationTest.java index 2543597..ee9c416 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/InvalidOperationTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/InvalidOperationTest.java @@ -9,10 +9,9 @@ import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl; import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; -import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; import org.gcube.informationsystem.serialization.ElementMapper; +import org.gcube.informationsystem.utils.UUIDManager; import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl; @@ -22,11 +21,13 @@ import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentified import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet; +import org.gcube.resourcemanagement.model.reference.entities.resources.Actor; import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration; import org.gcube.resourcemanagement.model.reference.entities.resources.EService; import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin; import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; +import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,7 +36,7 @@ public class InvalidOperationTest extends ERManagementTest { private static Logger logger = LoggerFactory.getLogger(InvalidOperationTest.class); - public static final String ACTIVATES = "{\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascade\",\"delete\":\"cascade\"},\"" + Element.TYPE_PROPERTY + "\":\"Activates\",\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Configuration\",\"uuid\":\"CONFIGURATION_UUID\"},\"target\":{\"" + IdentifiableElement.ID_PROPERTY + "\":\"ESERVICE_UUID\",\"" + Element.TYPE_PROPERTY + "\":\"EService\"}}"; + public static final String ACTIVATES = "{\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascade\",\"delete\":\"cascade\"},\"" + Element.TYPE_PROPERTY + "\":\"Activates\",\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Configuration\",\"" + IdentifiableElement.ID_PROPERTY + "\":\"CONFIGURATION_UUID\"},\"target\":{\"" + IdentifiableElement.ID_PROPERTY + "\":\"ESERVICE_UUID\",\"" + Element.TYPE_PROPERTY + "\":\"EService\"}}"; public static final String ACTOR = "{\"" + Element.TYPE_PROPERTY + "\":\"Actor\",\"metadata\":null,\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"metadata\":null,\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"remove\":\"cascade\",\"delete\":\"cascade\",\"add\":\"propagate\"},\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Actor\",\"metadata\":null},\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"ContactFacet\",\"metadata\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}"; @Test(expected = SchemaViolationException.class) @@ -58,7 +59,7 @@ public class InvalidOperationTest extends ERManagementTest { String json = ACTIVATES.replace("CONFIGURATION_UUID", configuration.getID().toString()); json = json.replace("ESERVICE_UUID", eService.getID().toString()); - resourceRegistryPublisher.create(json); + ((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(Activates.NAME, json, UUIDManager.getInstance().generateValidUUID()); }finally { resourceRegistryPublisher.delete(configuration); @@ -66,17 +67,6 @@ public class InvalidOperationTest extends ERManagementTest { } } - @Test(expected = ResourceAlreadyPresentException.class) - public void testRecreate() throws Exception { - EService eService = createEService(); - try { - resourceRegistryPublisher.create(eService); - }finally { - resourceRegistryPublisher.delete(eService); - } - } - - @Test(expected = SchemaViolationException.class) public void testCreateStandAloneFacet() throws Exception { CPUFacet cpuFacet = new CPUFacetImpl(); @@ -102,15 +92,9 @@ public class InvalidOperationTest extends ERManagementTest { resourceRegistryPublisher.create(runningPlugin); } - @Test(expected = ResourceRegistryException.class) - public void testCreateAnEntityDifferentFromDeclared() throws Exception { - EService eService = ERManagementTest.instantiateValidEService(); - resourceRegistryPublisher.create(eService); - } - @Test(expected = SchemaViolationException.class) public void testCreateAbstractEntity() throws Exception { - resourceRegistryPublisher.create(ACTOR); + ((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(Actor.NAME, ACTOR, UUIDManager.getInstance().generateValidUUID()); } @Test(expected = SchemaViolationException.class) @@ -184,7 +168,7 @@ public class InvalidOperationTest extends ERManagementTest { String json = ElementMapper.marshal(consistsOf); json = json.replaceAll(SimpleFacet.NAME, EService.NAME); - resourceRegistryPublisher.create(json); + ((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(ConsistsOf.NAME, json, UUIDManager.getInstance().generateValidUUID()); throw new Exception("A ConsistsOf has been created between two resoures. This should not happen"); } finally { resourceRegistryPublisher.delete(map.get(EService.NAME)); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/ERManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/ERManagementTest.java index 6eb76b5..c5ca2dd 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/ERManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/ERManagementTest.java @@ -26,8 +26,8 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; -import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl; @@ -40,23 +40,30 @@ import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetI 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.LicenseFacetImpl; +import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl; +import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl; +import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl; import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl; import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet; +import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet; +import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit; import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet; import org.gcube.resourcemanagement.model.reference.entities.resources.EService; import org.gcube.resourcemanagement.model.reference.entities.resources.GCubeResource; import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; +import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory; +import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory; import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates; import org.junit.Assert; @@ -89,6 +96,7 @@ public class ERManagementTest extends ContextTest { @Test public void testEncrypted() throws Exception { EService eService = new EServiceImpl(); + AccessPointFacet accessPointFacet = new AccessPointFacetImpl(); URL endpoint = new URL("https://d4science.org:443"); accessPointFacet.setEndpoint(endpoint.toURI()); @@ -97,9 +105,28 @@ public class ERManagementTest extends ContextTest { accessPointFacet.setAdditionalProperty(PASSWORD, encrypted); eService.addFacet(accessPointFacet); + SoftwareFacet softwareFacet = new SoftwareFacetImpl(); + softwareFacet.setGroup("InformationSystem"); + softwareFacet.setName("resource-registry"); + softwareFacet.setVersion("1.1.0"); + + IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl(eService, softwareFacet, + null); + eService.addFacet(isIdentifiedBy); + + EventFacet eventFacet = new EventFacetImpl(); + eventFacet.setDate(Calendar.getInstance().getTime()); + eventFacet.setEvent("Created"); + eService.addFacet(eventFacet); + + StateFacet stateFacet = new StateFacetImpl(); + stateFacet.setValue("ready"); + eService.addFacet(stateFacet); + ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); EService receivedEservice = resourceRegistryPublisher.create(eService); - AccessPointFacet receivedFacet = (AccessPointFacet) receivedEservice.getFacets().get(0); + + AccessPointFacet receivedFacet = (AccessPointFacet) receivedEservice.getFacets(AccessPointFacet.class).get(0); UUID eServiceUUID = receivedEservice.getID(); UUID facetUUID = receivedFacet.getID(); @@ -117,7 +144,7 @@ public class ERManagementTest extends ContextTest { UUID receivedEServiceUUID = receivedEservice.getID(); Assert.assertTrue(eServiceUUID.compareTo(receivedEServiceUUID)==0); - receivedFacet = (AccessPointFacet) receivedEservice.getFacets().get(0); + receivedFacet = (AccessPointFacet) receivedEservice.getFacets(AccessPointFacet.class).get(0); UUID receivedFacetUUID = receivedFacet.getID(); Assert.assertTrue(facetUUID.compareTo(receivedFacetUUID)==0); @@ -300,56 +327,6 @@ public class ERManagementTest extends ContextTest { Assert.assertTrue(deleted); } - @Test - public void testCreateReadDeleteFacet() throws Exception { - CPUFacet cpuFacet = new CPUFacetImpl(); - cpuFacet.setClockSpeed("1 GHz"); - cpuFacet.setModel("Opteron"); - cpuFacet.setVendor("AMD"); - - CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet); - - Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed()) == 0); - Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0); - Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0); - - UUID uuid = createdCpuFacet.getID(); - - CPUFacet readCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid); - Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0); - Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0); - Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0); - Assert.assertTrue(uuid.compareTo(readCpuFacet.getID()) == 0); - - String newVendor = "Intel"; - String newClockSpeed = "2 GHz"; - readCpuFacet.setVendor(newVendor); - readCpuFacet.setClockSpeed(newClockSpeed); - - String additionPropertyKey = "My"; - String additionPropertyValue = "Test"; - readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue); - - CPUFacet updatedCpuFacet = resourceRegistryPublisher.updateFacet(readCpuFacet); - Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(updatedCpuFacet.getClockSpeed()) == 0); - Assert.assertTrue(readCpuFacet.getModel().compareTo(updatedCpuFacet.getModel()) == 0); - Assert.assertTrue(readCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor()) == 0); - Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)) - .compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0); - Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID()) == 0); - - CPUFacet readUpdatedCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid); - Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed()) == 0); - Assert.assertTrue(updatedCpuFacet.getModel().compareTo(readUpdatedCpuFacet.getModel()) == 0); - Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0); - Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)) - .compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0); - Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID()) == 0); - - boolean deleted = resourceRegistryPublisher.deleteFacet(readUpdatedCpuFacet); - Assert.assertTrue(deleted); - } - public Map createHostingNodeAndEService() throws Exception { Map map = new HashMap<>(); @@ -364,29 +341,71 @@ public class ERManagementTest extends ContextTest { null); eService.addFacet(isIdentifiedBy); + AccessPointFacet accessPointFacet = new AccessPointFacetImpl(); + accessPointFacet.setEndpoint(new URI("https://localhost")); + accessPointFacet.setEntryName("port1"); + eService.addFacet(accessPointFacet); + + EventFacet eventFacet = new EventFacetImpl(); + eventFacet.setDate(Calendar.getInstance().getTime()); + eventFacet.setEvent("Created"); + eService.addFacet(eventFacet); + + StateFacet stateFacet = new StateFacetImpl(); + stateFacet.setValue("ready"); + eService.addFacet(stateFacet); + eService = resourceRegistryPublisher.createResource(eService); map.put(EService.NAME, eService); +// networkingFacet = resourceRegistryPublisher.createFacet(networkingFacet); +// logger.debug("Unmarshalled {} {}", NetworkingFacet.NAME, networkingFacet); + + HostingNode hostingNode = new HostingNodeImpl(); + NetworkingFacet networkingFacet = new NetworkingFacetImpl(); networkingFacet.setIPAddress("146.48.87.183"); networkingFacet.setHostName("pc-frosini.isti.cnr.it"); networkingFacet.setDomainName("isti.cnr.it"); networkingFacet.setMask("255.255.248.0"); networkingFacet.setBroadcastAddress("146.48.87.255"); - - networkingFacet = resourceRegistryPublisher.createFacet(networkingFacet); - logger.debug("Unmarshalled {} {}", NetworkingFacet.NAME, networkingFacet); - - HostingNode hostingNode = new HostingNodeImpl(); - + + isIdentifiedBy = new IsIdentifiedByImpl(hostingNode, networkingFacet, null); + hostingNode.addFacet(isIdentifiedBy); + CPUFacet cpuFacet = new CPUFacetImpl(); cpuFacet.setClockSpeed("1 GHz"); cpuFacet.setModel("Opteron"); cpuFacet.setVendor("AMD"); hostingNode.addFacet(cpuFacet); - isIdentifiedBy = new IsIdentifiedByImpl(hostingNode, networkingFacet, null); - hostingNode.addFacet(isIdentifiedBy); + MemoryFacet ram = new MemoryFacetImpl(); + ram.setSize(8); + ram.setUnit(MemoryUnit.GB); + ram.setUsed(2); + + HasVolatileMemory hasVolatileMemory = + new HasVolatileMemoryImpl(hostingNode, ram, null); + hostingNode.addFacet(hasVolatileMemory); + + + MemoryFacet disk = new MemoryFacetImpl(); + disk.setSize(256); + disk.setUnit(MemoryUnit.GB); + disk.setUsed(120); + + HasPersistentMemory hasPersistentMemory = + new HasPersistentMemoryImpl(hostingNode, disk, null); + hostingNode.addFacet(hasPersistentMemory); + + StateFacet hnStateFacet = new StateFacetImpl(); + hnStateFacet.setValue("certified"); + hostingNode.addFacet(hnStateFacet); + + EventFacet hnEventFacet = new EventFacetImpl(); + hnEventFacet.setDate(Calendar.getInstance().getTime()); + hnEventFacet.setEvent("Created"); + hostingNode.addFacet(hnEventFacet); PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade); @@ -425,55 +444,25 @@ public class ERManagementTest extends ContextTest { Facet shared = hostingNode.getConsistsOf().get(0).getTarget(); UUID sharedFacetUUID = shared.getID(); - ConsistsOf consistsOf = new ConsistsOfImpl(eService, shared, null); - consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf); - - boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME)); - Assert.assertTrue(deleted); - - deleted = resourceRegistryPublisher.deleteResource(map.get(HostingNode.NAME)); - Assert.assertTrue(deleted); - try { - resourceRegistryClient.getInstance(Facet.class, sharedFacetUUID); - throw new Exception(String.format("Shared Facet %s was not deleted", shared)); - } catch(ResourceRegistryException e) { - logger.debug("Shared Facet was not foud as expected"); + ConsistsOf consistsOf = new ConsistsOfImpl(eService, shared, null); + consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf); + } catch (SchemaViolationException e) { + logger.debug("As expected ", e); + } finally { + boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME)); + Assert.assertTrue(deleted); + + deleted = resourceRegistryPublisher.deleteResource(map.get(HostingNode.NAME)); + Assert.assertTrue(deleted); + + try { + resourceRegistryClient.getInstance(Facet.class, sharedFacetUUID); + throw new Exception(String.format("Shared Facet %s was not deleted", shared)); + } catch(ResourceRegistryException e) { + logger.debug("Shared Facet was not found as expected"); + } } - } - - @Test - public void testCreateResourceAndFacet() throws Exception { - - HostingNode hostingNode = new HostingNodeImpl(); - hostingNode = resourceRegistryPublisher.createResource(hostingNode); - - CPUFacet cpuFacet = new CPUFacetImpl(); - cpuFacet.setClockSpeed("1 GHz"); - cpuFacet.setModel("Opteron"); - cpuFacet.setVendor("AMD"); - - CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet); - - ConsistsOf consistsOf = new ConsistsOfImpl(hostingNode, createdCpuFacet, - null); - consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf); - - UUID consistOfUUID = consistsOf.getID(); - - boolean detached = resourceRegistryPublisher.deleteConsistsOf(consistsOf); - - if(detached) { - logger.trace("{} {} with uuid {} removed successfully", ConsistsOf.NAME, Relation.NAME, consistOfUUID); - } else { - String error = String.format("Unable to remove %s %s with uuid %s", ConsistsOf.NAME, Relation.NAME, - consistOfUUID); - logger.error(error); - throw new Exception(error); - } - - boolean deleted = resourceRegistryPublisher.deleteResource(hostingNode); - Assert.assertTrue(deleted); } @@ -653,39 +642,13 @@ public class ERManagementTest extends ContextTest { @Test public void testCreateHostingNodeThenActivatesWithEService() throws Exception { - HostingNode hostingNode = new HostingNodeImpl(); - - CPUFacet cpuFacet = new CPUFacetImpl(); - cpuFacet.setClockSpeed("1 GHz"); - cpuFacet.setModel("Opteron"); - cpuFacet.setVendor("AMD"); - hostingNode.addFacet(cpuFacet); - - NetworkingFacet networkingFacet = new NetworkingFacetImpl(); - networkingFacet.setIPAddress("146.48.87.183"); - networkingFacet.setHostName("pc-frosini.isti.cnr.it"); - networkingFacet.setDomainName("isti.cnr.it"); - networkingFacet.setMask("255.255.248.0"); - networkingFacet.setBroadcastAddress("146.48.87.255"); - - IsIdentifiedBy hnIsIdentifiedBy = new IsIdentifiedByImpl( - hostingNode, networkingFacet, null); - hostingNode.addFacet(hnIsIdentifiedBy); + HostingNode hostingNode = org.gcube.informationsystem.resourceregistry.publisher.ERManagementTest.instantiateValidHostingNode(); hostingNode = resourceRegistryPublisher.createResource(hostingNode); /* -------- */ - EService eService = new EServiceImpl(); - - SoftwareFacet softwareFacet = new SoftwareFacetImpl(); - softwareFacet.setGroup("InformationSystem"); - softwareFacet.setName("resource-registry"); - softwareFacet.setVersion("1.1.0"); - - IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl(eService, softwareFacet, - null); - eService.addFacet(isIdentifiedBy); + EService eService = org.gcube.informationsystem.resourceregistry.publisher.ERManagementTest.instantiateValidEService(); PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/MultiContextTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/MultiContextTest.java index 3b6ef54..8166932 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/MultiContextTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/MultiContextTest.java @@ -72,7 +72,7 @@ public class MultiContextTest extends ContextTest { protected ResourceRegistryClient resourceRegistryClient; public MultiContextTest() throws Exception { - ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE); + // ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE); if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) { resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL); resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL); @@ -127,7 +127,6 @@ public class MultiContextTest extends ContextTest { IsIdentifiedBy isIdentifiedByHNNF = new IsIdentifiedByImpl(hostingNode, networkingFacet, null); hostingNode.addFacet(isIdentifiedByHNNF); - CPUFacet cpuFacet = new CPUFacetImpl(); cpuFacet.setClockSpeed("1 GHz"); cpuFacet.setModel("Opteron"); @@ -154,23 +153,29 @@ public class MultiContextTest extends ContextTest { new HasPersistentMemoryImpl(hostingNode, disk, null); hostingNode.addFacet(hasPersistentMemory); + StateFacet hnStateFacet = new StateFacetImpl(); + hnStateFacet.setValue("certified"); + hostingNode.addFacet(hnStateFacet); + + EventFacet hnEventFacet = new EventFacetImpl(); + hnEventFacet.setDate(Calendar.getInstance().getTime()); + hnEventFacet.setEvent("Created"); + hostingNode.addFacet(hnEventFacet); + + Activates activates = new ActivatesImpl(hostingNode, createdEService, null); hostingNode.attachResource(activates); HostingNode createdHN = resourceRegistryPublisher.createResource(hostingNode); logger.debug("Created : {}", createdHN); - - - - - logger.debug("Changing token to test add to scope"); - ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE); - - UUID hostingNodeUUID = createdHN.getID(); UUID eServiceUUID = createdEService.getID(); + UUID alternativeContextUUID = ContextCache.getInstance().getUUIDByFullName(ALTERNATIVE_TEST_SCOPE); + + resourceRegistryPublisher.addResourceToContext(createdHN, alternativeContextUUID, false); + logger.debug("Changing token to test add to scope"); ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/RRClientTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/RRClientTest.java deleted file mode 100644 index ae5620b..0000000 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/RRClientTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/** - * - */ -package org.gcube.informationsystem.resourceregistry.publisher.old; - -import java.util.List; -import java.util.UUID; - -import org.gcube.informationsystem.model.reference.entities.Facet; -import org.gcube.informationsystem.model.reference.entities.Resource; -import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetNotFoundException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException; -import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; -import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; -import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl; -import org.gcube.informationsystem.resourceregistry.publisher.ContextTest; -import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher; -import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory; -import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl; -import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; -import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet; -import org.gcube.resourcemanagement.model.reference.entities.resources.EService; -import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) - * - */ -public class RRClientTest extends ContextTest { - - private static final Logger logger = LoggerFactory.getLogger(EntityManagementTest.class); - - protected ResourceRegistryPublisher resourceRegistryPublisher; - protected ResourceRegistryClient resourceRegistryClient; - - public RRClientTest(){ - if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) { - resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL); - resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL); - }else { - resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); - resourceRegistryClient = ResourceRegistryClientFactory.create(); - } - logger.trace("{} and {} created", - ResourceRegistryPublisher.class.getSimpleName(), - ResourceRegistryClient.class.getSimpleName()); - } - - @Test - public void testGetFacet() throws FacetNotFoundException, ResourceRegistryException{ - CPUFacet cpuFacet = new CPUFacetImpl(); - cpuFacet.setClockSpeed("1 GHz"); - cpuFacet.setModel("Opteron"); - cpuFacet.setVendor("AMD"); - - CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet); - - Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0); - Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0); - Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0); - - UUID uuid = createdCpuFacet.getID(); - - Facet f = resourceRegistryClient.getInstance(Facet.class, uuid); - Assert.assertTrue(f instanceof CPUFacet); - - CPUFacet readCpuFacet = (CPUFacet) f; - Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0); - Assert.assertTrue(readCpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0); - Assert.assertTrue(readCpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0); - - - readCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid); - Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0); - Assert.assertTrue(readCpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0); - Assert.assertTrue(readCpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0); - - - boolean deleted = resourceRegistryPublisher.deleteFacet(createdCpuFacet); - Assert.assertTrue(deleted); - } - - @Test - public void testGetResource() throws ResourceNotFoundException, ResourceRegistryException{ - EService eService = new EServiceImpl(); - - SoftwareFacet softwareFacet = new SoftwareFacetImpl(); - softwareFacet.setGroup("InformationSystem"); - softwareFacet.setName("resource-registry"); - softwareFacet.setVersion("1.1.0"); - - IsIdentifiedBy isIdentifiedByESSF = new IsIdentifiedByImpl<>(eService, softwareFacet, null); - eService.addFacet(isIdentifiedByESSF); - - EService createdEService = resourceRegistryPublisher.createResource(eService); - - List idenficationFacets = createdEService.getIdentificationFacets(); - Assert.assertTrue(idenficationFacets!=null); - Assert.assertTrue(idenficationFacets.size()==1); - Facet f = idenficationFacets.get(0); - Assert.assertTrue(f!=null); - Assert.assertTrue(f instanceof SoftwareFacet); - SoftwareFacet createdSoftwareFacet = (SoftwareFacet) f; - Assert.assertTrue(createdSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup())==0); - Assert.assertTrue(createdSoftwareFacet.getName().compareTo(softwareFacet.getName())==0); - Assert.assertTrue(createdSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0); - - - Resource resource = resourceRegistryClient.getInstance(Resource.class, createdEService.getID()); - Assert.assertTrue(resource.getID().compareTo(createdEService.getID())==0); - Assert.assertTrue(resource instanceof EService); - - EService readEService = resourceRegistryClient.getInstance(EService.class, createdEService.getID()); - Assert.assertTrue(readEService.getID().compareTo(createdEService.getID())==0); - List idFacets = readEService.getIdentificationFacets(); - Assert.assertTrue(idFacets!=null); - Assert.assertTrue(idFacets.size()==1); - f = idFacets.get(0); - Assert.assertTrue(f!=null); - Assert.assertTrue(f instanceof SoftwareFacet); - SoftwareFacet readSoftwareFacet = (SoftwareFacet) f; - Assert.assertTrue(readSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup())==0); - Assert.assertTrue(readSoftwareFacet.getName().compareTo(softwareFacet.getName())==0); - Assert.assertTrue(readSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0); - Assert.assertTrue(readSoftwareFacet.getID().compareTo(createdSoftwareFacet.getID())==0); - - - boolean deleted = resourceRegistryPublisher.deleteResource(createdEService); - Assert.assertTrue(deleted); - - } - -} diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/SmartgearResourcesTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/SmartgearResourcesTest.java deleted file mode 100644 index 3cc5ab1..0000000 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/SmartgearResourcesTest.java +++ /dev/null @@ -1,484 +0,0 @@ -/** - * - */ -package org.gcube.informationsystem.resourceregistry.publisher.old; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.lang.management.OperatingSystemMXBean; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.nio.file.FileStore; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.management.AttributeNotFoundException; -import javax.management.InstanceNotFoundException; -import javax.management.MBeanException; -import javax.management.MBeanServer; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; -import javax.management.ReflectionException; - -import org.gcube.com.fasterxml.jackson.core.JsonParseException; -import org.gcube.com.fasterxml.jackson.databind.JsonMappingException; -import org.gcube.informationsystem.base.reference.Element; -import org.gcube.informationsystem.model.reference.entities.Facet; -import org.gcube.informationsystem.model.reference.entities.Resource; -import org.gcube.informationsystem.model.reference.relations.ConsistsOf; -import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.publisher.ContextTest; -import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher; -import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory; -import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl; -import org.gcube.informationsystem.serialization.ElementMapper; -import org.gcube.informationsystem.utils.UUIDManager; -import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.SimplePropertyFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl; -import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl; -import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl; -import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; -import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit; -import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.SimplePropertyFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet; -import org.gcube.resourcemanagement.model.reference.entities.resources.EService; -import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; -import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory; -import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory; -import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -public class SmartgearResourcesTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(SmartgearResourcesTest.class); - - protected ResourceRegistryPublisher resourceRegistryPublisher; - - public SmartgearResourcesTest(){ - if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) { - resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL); - }else { - resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); - } - } - - public static final String HOSTING_NODE = "{\"" + Element.TYPE_PROPERTY + "\":\"HostingNode\",\"uuid\":\"f0460614-9ffb-4ecd-bf52-d91e8d81d604\",\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"NetworkingFacet\",\"@metadata\":null,\"hostName\":\"pc-frosini.isti.cnr.it\",\"domainName\":\"isti.cnr.it\",\"mask\":null,\"broadcastAddress\":null,\"ipaddress\":\"127.0.1.1\",\"Port\":8080}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"CPUFacet\",\"@metadata\":null,\"model\":\"Intel(R) Core(TM) i5-3450 CPU @ 3.10GHz\",\"vendor\":\"GenuineIntel\",\"clockSpeed\":\"2872.828\",\"cache_size\":\"6144 KB\",\"flags\":\"fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts\",\"bogomips\":\"6199.91\",\"fpu\":\"yes\",\"stepping\":\"9\",\"address_sizes\":\"36 bits physical, 48 bits virtual\",\"wp\":\"yes\",\"clflush_size\":\"64\",\"siblings\":\"4\",\"microcode\":\"0x17\",\"cpu_family\":\"6\",\"cpu_cores\":\"4\",\"physical_id\":\"0\",\"cpuid_level\":\"13\",\"fpu_exception\":\"yes\",\"apicid\":\"0\",\"cache_alignment\":\"64\",\"processor\":\"0\",\"core_id\":\"0\",\"initial_apicid\":\"0\",\"modelNumber\":\"58\"}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"CPUFacet\",\"@metadata\":null,\"model\":\"Intel(R) Core(TM) i5-3450 CPU @ 3.10GHz\",\"vendor\":\"GenuineIntel\",\"clockSpeed\":\"2617.199\",\"cache_size\":\"6144 KB\",\"flags\":\"fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts\",\"bogomips\":\"6199.91\",\"fpu\":\"yes\",\"stepping\":\"9\",\"address_sizes\":\"36 bits physical, 48 bits virtual\",\"wp\":\"yes\",\"clflush_size\":\"64\",\"siblings\":\"4\",\"microcode\":\"0x17\",\"cpu_family\":\"6\",\"cpu_cores\":\"4\",\"physical_id\":\"0\",\"cpuid_level\":\"13\",\"fpu_exception\":\"yes\",\"apicid\":\"2\",\"cache_alignment\":\"64\",\"processor\":\"1\",\"core_id\":\"1\",\"initial_apicid\":\"2\",\"modelNumber\":\"58\"}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"CPUFacet\",\"@metadata\":null,\"model\":\"Intel(R) Core(TM) i5-3450 CPU @ 3.10GHz\",\"vendor\":\"GenuineIntel\",\"clockSpeed\":\"2610.660\",\"cache_size\":\"6144 KB\",\"flags\":\"fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts\",\"bogomips\":\"6199.91\",\"fpu\":\"yes\",\"stepping\":\"9\",\"address_sizes\":\"36 bits physical, 48 bits virtual\",\"wp\":\"yes\",\"clflush_size\":\"64\",\"siblings\":\"4\",\"microcode\":\"0x17\",\"cpu_family\":\"6\",\"cpu_cores\":\"4\",\"physical_id\":\"0\",\"cpuid_level\":\"13\",\"fpu_exception\":\"yes\",\"apicid\":\"4\",\"cache_alignment\":\"64\",\"processor\":\"2\",\"core_id\":\"2\",\"initial_apicid\":\"4\",\"modelNumber\":\"58\"}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"CPUFacet\",\"@metadata\":null,\"model\":\"Intel(R) Core(TM) i5-3450 CPU @ 3.10GHz\",\"vendor\":\"GenuineIntel\",\"clockSpeed\":\"2712.257\",\"cache_size\":\"6144 KB\",\"flags\":\"fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts\",\"bogomips\":\"6199.91\",\"fpu\":\"yes\",\"stepping\":\"9\",\"address_sizes\":\"36 bits physical, 48 bits virtual\",\"wp\":\"yes\",\"clflush_size\":\"64\",\"siblings\":\"4\",\"microcode\":\"0x17\",\"cpu_family\":\"6\",\"cpu_cores\":\"4\",\"physical_id\":\"0\",\"cpuid_level\":\"13\",\"fpu_exception\":\"yes\",\"apicid\":\"6\",\"cache_alignment\":\"64\",\"processor\":\"3\",\"core_id\":\"3\",\"initial_apicid\":\"6\",\"modelNumber\":\"58\"}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"SoftwareFacet\",\"@metadata\":null,\"name\":\"amd64\",\"group\":\"Linux\",\"version\":\"4.4.0-47-generic\",\"description\":null,\"qualifier\":null,\"optional\":false}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"SimplePropertyFacet\",\"@metadata\":null,\"name\":\"ENVIRONMENT_VARIABLES\",\"value\":\"\",\"TERM\":\"xterm\",\"XDG_SESSION_PATH\":\"/org/freedesktop/DisplayManager/Session0\",\"JAVA_HOME\":\"/usr/lib/jvm/java-7-oracle\",\"J2REDIR\":\"/usr/lib/jvm/java-7-oracle/jre\",\"LESSCLOSE\":\"/usr/bin/lesspipe %s %s\",\"UPSTART_SESSION\":\"unix:abstract=/com/ubuntu/upstart-session/1000/1613\",\"J2SDKDIR\":\"/usr/lib/jvm/java-7-oracle\",\"SESSION_MANAGER\":\"local/pc-frosini.isti.cnr.it:@/tmp/.ICE-unix/1849,unix/pc-frosini.isti.cnr.it:/tmp/.ICE-unix/1849\",\"LC_NUMERIC\":\"it_IT.UTF-8\",\"GNOME_DESKTOP_SESSION_ID\":\"this-is-deprecated\",\"Java\":\"1.7.0_80\",\"COMPIZ_CONFIG_PROFILE\":\"ubuntu\",\"GDMSESSION\":\"ubuntu\",\"IM_CONFIG_PHASE\":\"1\",\"MANDATORY_PATH\":\"/usr/share/gconf/ubuntu.mandatory.path\",\"SmartGearsDistributionBundle\":\"2.0.1-SNAPSHOT\",\"PWD\":\"/home/lucafrosini/Desktop/SmartGears-Bundle\",\"SESSIONTYPE\":\"gnome-session\",\"GIO_LAUNCHED_DESKTOP_FILE_PID\":\"7474\",\"GTK_IM_MODULE\":\"ibus\",\"XDG_GREETER_DATA_DIR\":\"/var/lib/lightdm-data/lucafrosini\",\"XDG_SESSION_TYPE\":\"x11\",\"NLSPATH\":\"/usr/dt/lib/nls/msg/%L/%N.cat\",\"TERMINATOR_UUID\":\"urn:uuid:7e1ff3e9-f2ca-4c64-b5db-922901ce32dc\",\"XDG_MENU_PREFIX\":\"gnome-\",\"LC_ADDRESS\":\"it_IT.UTF-8\",\"ghn-update-interval-in-secs\":\"60\",\"XDG_CONFIG_DIRS\":\"/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg\",\"XDG_CURRENT_DESKTOP\":\"Unity\",\"QT_LINUX_ACCESSIBILITY_ALWAYS_ON\":\"1\",\"GHN_HOME\":\"/home/lucafrosini/Desktop/SmartGears-Bundle/SmartGears\",\"XAUTHORITY\":\"/home/lucafrosini/.Xauthority\",\"GDM_LANG\":\"en_US\",\"XDG_SEAT\":\"seat0\",\"SmartGears\":\"2.2.0-SNAPSHOT\",\"CATALINA_PID\":\"/home/lucafrosini/Desktop/SmartGears-Bundle/tomcat.pid\",\"XDG_SESSION_ID\":\"c2\",\"XDG_SEAT_PATH\":\"/org/freedesktop/DisplayManager/Seat0\",\"XDG_VTNR\":\"7\",\"LC_TIME\":\"it_IT.UTF-8\",\"GNOME_KEYRING_CONTROL\":\"\",\"GTK_MODULES\":\"gail:atk-bridge:unity-gtk-module\",\"LC_TELEPHONE\":\"it_IT.UTF-8\",\"SHLVL\":\"2\",\"XFILESEARCHPATH\":\"/usr/dt/app-defaults/%L/Dt\",\"GTK2_MODULES\":\"overlay-scrollbar\",\"COMPIZ_BIN_PATH\":\"/usr/bin/\",\"COLORTERM\":\"gnome-terminal\",\"JOB\":\"unity-settings-daemon\",\"UPSTART_JOB\":\"unity7\",\"LC_NAME\":\"it_IT.UTF-8\",\"IBUS_DISABLE_SNOOPER\":\"1\",\"XDG_DATA_DIRS\":\"/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop\",\"QT_QPA_PLATFORMTHEME\":\"appmenu-qt5\",\"QT_IM_MODULE\":\"ibus\",\"GIO_LAUNCHED_DESKTOP_FILE\":\"/usr/share/applications/terminator.desktop\",\"UPSTART_INSTANCE\":\"\",\"LOGNAME\":\"lucafrosini\",\"WINDOWID\":\"81788932\",\"LC_PAPER\":\"it_IT.UTF-8\",\"SmartGearsDistribution\":\"2.0.0-SNAPSHOT\",\"SESSION\":\"ubuntu\",\"GPG_AGENT_INFO\":\"/home/lucafrosini/.gnupg/S.gpg-agent:0:1\",\"LC_IDENTIFICATION\":\"it_IT.UTF-8\",\"DERBY_HOME\":\"/usr/lib/jvm/java-7-oracle/db\",\"XMODIFIERS\":\"@im=ibus\",\"LD_LIBRARY_PATH\":\"/home/lucafrosini/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64\",\"UPSTART_EVENTS\":\"xsession started\",\"OLDPWD\":\"/home/lucafrosini/Desktop/SmartGears-Bundle\",\"DBUS_SESSION_BUS_ADDRESS\":\"unix:abstract=/tmp/dbus-mf1KaSOYwP\",\"SHELL\":\"/bin/bash\",\"GNOME_KEYRING_PID\":\"\",\"LANGUAGE\":\"en_US\",\"QT_ACCESSIBILITY\":\"1\",\"DESKTOP_SESSION\":\"ubuntu\",\"INSTANCE\":\"\",\"DISPLAY\":\":0\",\"CLUTTER_IM_MODULE\":\"xim\",\"LC_MONETARY\":\"it_IT.UTF-8\",\"USER\":\"lucafrosini\",\"CATALINA_HOME\":\"/home/lucafrosini/Desktop/SmartGears-Bundle/tomcat\",\"HOME\":\"/home/lucafrosini\",\"LESSOPEN\":\"| /usr/bin/lesspipe %s\",\"QT4_IM_MODULE\":\"xim\",\"CATALINA_OPTS\":\"-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n -Xmx2000m -Xms2000m\",\"DEFAULTS_PATH\":\"/usr/share/gconf/ubuntu.default.path\",\"ORBIT_SOCKETDIR\":\"/tmp/orbit-lucafrosini\",\"XDG_SESSION_DESKTOP\":\"ubuntu\",\"LC_MEASUREMENT\":\"it_IT.UTF-8\",\"BUNDLE_HOME\":\"/home/lucafrosini/Desktop/SmartGears-Bundle\",\"XDG_RUNTIME_DIR\":\"/run/user/1000\",\"LANG\":\"en_US.UTF-8\"}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"StateFacet\",\"@metadata\":null,\"value\":\"started\"}},{\"" + Element.TYPE_PROPERTY + "\":\"HasVolatileMemory\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"MemoryFacet\",\"@metadata\":null,\"size\":15736,\"used\":9042,\"unit\":\"MB\"},\"memoryType\":\"RAM\"},{\"" + Element.TYPE_PROPERTY + "\":\"HasVolatileMemory\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"MemoryFacet\",\"@metadata\":null,\"size\":1917,\"used\":374,\"unit\":\"MB\",\"jvmMaxMemory\":1917},\"memoryType\":\"JVM\"},{\"" + Element.TYPE_PROPERTY + "\":\"HasPersistentMemory\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"MemoryFacet\",\"@metadata\":null,\"size\":273894,\"used\":101270,\"unit\":\"MB\"}}],\"isRelatedTo\":[]}"; - public static final String ESERVICE = "{\"" + Element.TYPE_PROPERTY + "\":\"EService\",\"uuid\":\"3ace4bd0-e5cd-49a3-97a8-a0a9468ce6d4\",\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"SoftwareFacet\",\"@metadata\":null,\"name\":\"WhnManager\",\"group\":\"VREManagement\",\"version\":\"2.0.0-SNAPSHOT\",\"description\":\"Web Hosting Node Service\",\"qualifier\":null,\"optional\":false}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"@metadata\":null,\"entryName\":\"whnmanager\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/vremanagement/ws/whnmanager\",\"protocol\":null,\"description\":null,\"authorization\":{\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}},{\"" + Element.TYPE_PROPERTY + "\":\"ConsistsOf\",\"@metadata\":null,\"relationProperty\":null,\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"AccessPointFacet\",\"@metadata\":null,\"entryName\":\"WhnManager-remote-management\",\"endpoint\":\"https://pc-frosini.isti.cnr.it:8080/whn-manager/gcube/resource\",\"protocol\":null,\"description\":null,\"authorization\":{\"" + Element.TYPE_PROPERTY + "\":\"ValueSchema\",\"value\":\"gcube-token\",\"schema\":null},\"properties\":null}}],\"isRelatedTo\":[]}"; - - @Test - public void testHostingNode() throws JsonParseException, JsonMappingException, IOException, ResourceRegistryException{ - HostingNode hostingNode = ElementMapper.unmarshal(HostingNode.class, HOSTING_NODE); - logger.debug("Going to create {}", hostingNode); - - hostingNode = resourceRegistryPublisher.createResource(hostingNode); - logger.debug("Created : {}", hostingNode); - - Assert.assertTrue(hostingNode!=null); - Assert.assertTrue(hostingNode.getMetadata()!=null); - Assert.assertTrue(hostingNode.getID()!=null); - - boolean deleted = resourceRegistryPublisher.deleteResource(hostingNode); - Assert.assertTrue(deleted); - } - - @Test - public void testEService() throws JsonParseException, JsonMappingException, IOException, ResourceRegistryException{ - EService eService = ElementMapper.unmarshal(EService.class, ESERVICE); - logger.debug("Going to create {}", eService); - - eService = resourceRegistryPublisher.createResource(eService); - logger.debug("Created : {}", eService); - - Assert.assertTrue(eService!=null); - Assert.assertTrue(eService.getMetadata()!=null); - Assert.assertTrue(eService.getID()!=null); - - boolean deleted = resourceRegistryPublisher.deleteResource(eService); - Assert.assertTrue(deleted); - - } - - - public static final String MEMORY_TYPE = "memoryType"; - public static final String MEMORY_TYPE_RAM = "RAM"; - public static final String MEMORY_TYPE_JVM = "JVM"; - public static final String JVM_MAX_MEMORY = "jvmMaxMemory"; - - @Test - public void testHostingNodeOperations() throws ResourceRegistryException, IOException{ - UUID uuid = UUIDManager.getInstance().generateValidUUID(); - - HostingNode hostingNode = new HostingNodeImpl(); - hostingNode.setID(uuid); - - NetworkingFacet networkingFacet = new NetworkingFacetImpl(); - try { - networkingFacet.setIPAddress(InetAddress.getLocalHost().getHostAddress()); - } catch (UnknownHostException e) { - logger.warn("unable to detect the IP address of the host"); - } - networkingFacet.setHostName("pc-frosini.isti.cnr.it"); - networkingFacet.setDomainName(getDomain(networkingFacet.getHostName())); - - networkingFacet.setAdditionalProperty("Port", 8080); - IsIdentifiedBy isIdentifiedBy = - new IsIdentifiedByImpl<>(hostingNode, networkingFacet, null); - hostingNode.addFacet(isIdentifiedBy); - - List cpuFacets = getCPUFacets(); - for (CPUFacet cpuFacet: cpuFacets) { - hostingNode.addFacet(cpuFacet); - } - - - SoftwareFacet softwareFacet = new SoftwareFacetImpl(); - OperatingSystemMXBean mxbean = ManagementFactory.getOperatingSystemMXBean(); - softwareFacet.setGroup(mxbean.getName()); // softwareFacet.setGroup(System.getProperty("os.name")); - softwareFacet.setName(mxbean.getArch()); // softwareFacet.setName(System.getProperty("os.arch")); - softwareFacet.setVersion(mxbean.getVersion()); // softwareFacet.setName(System.getProperty("os.version")); - hostingNode.addFacet(softwareFacet); - - - SimplePropertyFacet simplePropertyFacet = addEnvironmentVariables(); - hostingNode.addFacet(simplePropertyFacet); - - StateFacet stateFacet = getStateFacet(null); - hostingNode.addFacet(stateFacet); - - - MemoryFacet ramFacet = getRamInfo(null); - HasVolatileMemory hasVolatileRAMMemory = - new HasVolatileMemoryImpl( - hostingNode, ramFacet, null); - hasVolatileRAMMemory.setAdditionalProperty(MEMORY_TYPE, MEMORY_TYPE_RAM); - hostingNode.addFacet(hasVolatileRAMMemory); - - MemoryFacet jvmMemoryFacet = getJVMMemoryInfo(null); - HasVolatileMemory hasVolatileJVMMemory = - new HasVolatileMemoryImpl( - hostingNode, jvmMemoryFacet, null); - hasVolatileJVMMemory.setAdditionalProperty(MEMORY_TYPE, MEMORY_TYPE_JVM); - hostingNode.addFacet(hasVolatileJVMMemory); - - MemoryFacet disk = getDiskSpace(null); - HasPersistentMemory hasPersistentMemory = - new HasPersistentMemoryImpl(hostingNode, disk, null); - hostingNode.addFacet(hasPersistentMemory); - - HostingNode hostingNodeToUpdate = resourceRegistryPublisher.createResource(hostingNode); - - List> consistsOfToRemove = new ArrayList<>(); - - List> consistsOfList = hostingNodeToUpdate.getConsistsOf(); - for(ConsistsOf c : consistsOfList){ - - if(c.getTarget() instanceof StateFacet){ - stateFacet = (StateFacet) c.getTarget(); - stateFacet = getStateFacet(stateFacet); - continue; - } - - - if(c instanceof HasVolatileMemory){ - String memoryType = (String) c.getAdditionalProperty(MEMORY_TYPE); - if(memoryType.compareTo(MEMORY_TYPE_RAM)==0){ - ramFacet = (MemoryFacet) c.getTarget(); - ramFacet = getRamInfo(ramFacet); - continue; - } - - if(memoryType.compareTo(MEMORY_TYPE_JVM)==0){ - jvmMemoryFacet = (MemoryFacet) c.getTarget(); - jvmMemoryFacet = getJVMMemoryInfo(jvmMemoryFacet); - continue; - } - - } - - if(c instanceof HasPersistentMemory){ - disk = (MemoryFacet) c.getTarget(); - disk = getDiskSpace(disk); - continue; - } - - consistsOfToRemove.add(c); - - } - - consistsOfList.removeAll(consistsOfToRemove); - - HostingNode updatedHostingNode = resourceRegistryPublisher.updateResource(hostingNodeToUpdate); - logger.debug("Upodate Hosting Node {}", updatedHostingNode); - - boolean deleted = resourceRegistryPublisher.deleteResource(updatedHostingNode); - Assert.assertTrue(deleted); - - } - - - - private StateFacet getStateFacet(StateFacet stateFacet){ - if(stateFacet == null){ - stateFacet = new StateFacetImpl(); - } - stateFacet.setValue("ready"); - return stateFacet; - } - - public static final String MESSAGE = "message"; - - private MemoryFacet getDiskSpace(MemoryFacet memoryFacet){ - if(memoryFacet == null){ - memoryFacet = new MemoryFacetImpl(); - } - - long free = 0; - long total = 0; - try { - FileStore fileStore = Files.getFileStore(Paths.get("./")); - free = fileStore.getUsableSpace() / 1048576; // 1048576 = 1024*1024 user to convert bytes in MByte - total = fileStore.getTotalSpace() / 1048576; // 1048576 = 1024*1024 user to convert bytes in MByte - } catch (IOException ioe) { - logger.warn("Unable to detect disk space information", ioe); - memoryFacet.setAdditionalProperty(MESSAGE, "Unable to detect disk space information."); - } - - memoryFacet.setUnit(MemoryUnit.MB); - memoryFacet.setSize(total); - memoryFacet.setUsed(total-free); - - return memoryFacet; - } - - private static final long BYTE_TO_MB = 1024*1024; - - private MemoryFacet getRamInfo(MemoryFacet memoryFacet) { - if(memoryFacet == null){ - memoryFacet = new MemoryFacetImpl(); - } - - /* - OperatingSystemMXBean mxbean = ManagementFactory.getOperatingSystemMXBean(); - com.sun.management.OperatingSystemMXBean sunmxbean = (com.sun.management.OperatingSystemMXBean) mxbean; - long freeMemory = sunmxbean.getFreePhysicalMemorySize() / 1048576; // in MB - long totalMemory = sunmxbean.getTotalPhysicalMemorySize() / 1048576; // in MB - */ - - MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); - long freeMemory; - try { - freeMemory = Long.parseLong(mBeanServer.getAttribute(new ObjectName("java.lang","type","OperatingSystem"), "FreePhysicalMemorySize").toString()) / BYTE_TO_MB; - } catch (NumberFormatException | InstanceNotFoundException | AttributeNotFoundException - | MalformedObjectNameException | ReflectionException | MBeanException e) { - logger.warn("Unable to get free memory from Operating System. Going to get JVM Memory. Better than nothing"); - long allocatedMemory = (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()); - freeMemory = Runtime.getRuntime().maxMemory() - allocatedMemory; - } - long totalMemory; - try { - totalMemory = Long.parseLong(mBeanServer.getAttribute(new ObjectName("java.lang","type","OperatingSystem"), "TotalPhysicalMemorySize").toString()) / BYTE_TO_MB; - } catch (NumberFormatException | InstanceNotFoundException | AttributeNotFoundException - | MalformedObjectNameException | ReflectionException | MBeanException e) { - logger.warn("Unable to total memory from Operating System. Going to get JVM Memory. Better than nothing"); - totalMemory = Runtime.getRuntime().maxMemory(); - } - - memoryFacet.setUnit(MemoryUnit.MB); - memoryFacet.setSize(totalMemory); - memoryFacet.setUsed(totalMemory - freeMemory); - - return memoryFacet; - } - - - private MemoryFacet getJVMMemoryInfo(MemoryFacet memoryFacet) { - if(memoryFacet == null){ - memoryFacet = new MemoryFacetImpl(); - } - - long jvmFreeMemory = Runtime.getRuntime().freeMemory() / 1048576; // 1048576 = 1024*1024 user to convert bytes in MByte - long jvmTotalMemory = Runtime.getRuntime().totalMemory() / 1048576; // 1048576 = 1024*1024 user to convert bytes in MByte - long jvmMaxMemory = Runtime.getRuntime().maxMemory() / 1048576; // 1048576 = 1024*1024 user to convert bytes in MByte - - memoryFacet.setUnit(MemoryUnit.MB); - memoryFacet.setSize(jvmTotalMemory); - memoryFacet.setUsed(jvmTotalMemory-jvmFreeMemory); - memoryFacet.setAdditionalProperty(JVM_MAX_MEMORY, jvmMaxMemory); - - return memoryFacet; - } - - - private static String sanitizeKey(String key){ - return key.trim().replace(" ", "_"); - } - - private SimplePropertyFacet addEnvironmentVariables() { - - - Map map = new HashMap(); - map.putAll(System.getenv()); - - SimplePropertyFacet simplePropertyFacet = new SimplePropertyFacetImpl(); - simplePropertyFacet.setName("ENVIRONMENT_VARIABLES"); - simplePropertyFacet.setValue(""); - - for (Map.Entry entry : map.entrySet()) { - String varname = entry.getKey(); - if ((varname.compareToIgnoreCase("CLASSPATH") == 0) || - (varname.compareToIgnoreCase("PATH") == 0) || - (varname.contains("SSH")) || - (varname.contains("MAIL")) || - (varname.compareToIgnoreCase("LS_COLORS") == 0)) { - continue; - } - - simplePropertyFacet.setAdditionalProperty(sanitizeKey(entry.getKey()), entry.getValue()); - - } - - - simplePropertyFacet.setAdditionalProperty("Java", System.getProperty("java.version")); - - return simplePropertyFacet; - } - - - private static String getDomain(String hostname) { - try { - Pattern pattern = Pattern.compile("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})"); - Matcher regexMatcher = pattern.matcher(hostname); - if (regexMatcher.matches()) { //it's an IP address, nothing to trim - return hostname; - } - return hostname.substring(hostname.indexOf(".")+1); - }catch(Exception e){ - logger.warn("Error while getting domain from hostname"); - return hostname; - } - } - - - public static final String CPU_PROCESSOR = "processor"; - public static final String CPU_VENDOR_ID = "vendor_id"; - public static final String CPU_MODEL_NAME = "model name"; - public static final String CPU_CPU_MHZ = "cpu MHz"; - public static final String CPU_MODEL_T = "model\t"; - public static final String CPU_MODEL_B = "model\b"; - public static final String CPU_MODEL_NUMBER = "modelNumber"; - - public static List getCPUFacets() { - - List cpuFacets = new ArrayList<>(); - - File file = new File("/proc/cpuinfo"); - - if (!file.exists()) { - logger.warn("cannot acquire CPU info (no /proc/cpuinfo)"); - return cpuFacets; - } - - BufferedReader input = null; - - try { - input = new BufferedReader(new FileReader(file)); - - String line = null; - - CPUFacet cpuFacet = null; - - while ((line = input.readLine()) != null) { - - if ((line.startsWith(CPU_PROCESSOR))) { // add the current processor to the map - cpuFacet = new CPUFacetImpl(); - cpuFacets.add(cpuFacet); - } - - try { - if (line.contains(CPU_VENDOR_ID)) { - cpuFacet.setVendor(line.split(":")[1].trim()); - continue; - } - } catch (Exception e) { - continue; - } - - - try { - if (line.contains(CPU_MODEL_NAME)){ - cpuFacet.setModel(line.split(":")[1].trim()); - continue; - } - } catch (Exception e){ - continue; - } - - try { - if (line.contains(CPU_CPU_MHZ)) { - cpuFacet.setClockSpeed(line.split(":")[1].trim()); - continue; - } - } catch (Exception e) { - continue; - } - - - try { - if ((line.contains(CPU_MODEL_T)) || (line.contains(CPU_MODEL_B))){ - cpuFacet.setAdditionalProperty(CPU_MODEL_NUMBER, line.split(":")[1].trim()); - continue; - } - } catch (Exception e) { - continue; - } - - - - try { - String[] nameValue = line.split(":"); - cpuFacet.setAdditionalProperty(sanitizeKey(nameValue[0]), line.split(":")[1].trim()); - } catch (Exception e) { - - } - - } - } catch (Exception e) { - logger.warn("unable to acquire CPU info", e); - } finally { - if (input != null) { - try { - input.close(); - } catch (IOException e) { - logger.warn("unable to close stream", e); - } - } - } - return cpuFacets; - } - -}