2017-01-13 18:00:56 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.informationsystem.resourceregistry.publisher;
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import org.gcube.informationsystem.impl.embedded.PropagationConstraintImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.AccessPointFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.CPUFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.EventFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.LicenseFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.NetworkingFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.ServiceStateFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.SoftwareFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.resource.EServiceImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.resource.HostingNodeImpl;
|
|
|
|
import org.gcube.informationsystem.impl.relation.ConsistsOfImpl;
|
|
|
|
import org.gcube.informationsystem.impl.relation.IsIdentifiedByImpl;
|
|
|
|
import org.gcube.informationsystem.impl.relation.isrelatedto.HostsImpl;
|
2017-05-03 17:51:37 +02:00
|
|
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
2017-01-13 18:00:56 +01:00
|
|
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
2017-03-22 09:52:15 +01:00
|
|
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint.AddConstraint;
|
2017-01-13 18:00:56 +01:00
|
|
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint.RemoveConstraint;
|
|
|
|
import org.gcube.informationsystem.model.entity.Facet;
|
|
|
|
import org.gcube.informationsystem.model.entity.Resource;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.AccessPointFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.CPUFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.EventFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.LicenseFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.NetworkingFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.ServiceStateFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.SoftwareFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.resource.EService;
|
|
|
|
import org.gcube.informationsystem.model.entity.resource.HostingNode;
|
|
|
|
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
|
|
|
import org.gcube.informationsystem.model.relation.IsIdentifiedBy;
|
|
|
|
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
|
|
|
import org.gcube.informationsystem.model.relation.Relation;
|
|
|
|
import org.gcube.informationsystem.model.relation.isrelatedto.Hosts;
|
2017-01-13 18:20:14 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2017-04-03 18:44:47 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.client.Direction;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
2017-01-13 18:00:56 +01:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ERManagementTest extends ScopedTest {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory
|
|
|
|
.getLogger(ERManagementTest.class);
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
|
|
|
protected ResourceRegistryClient resourceRegistryClient;
|
2017-01-13 18:20:14 +01:00
|
|
|
|
|
|
|
public ERManagementTest() {
|
2017-01-13 18:00:56 +01:00
|
|
|
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
|
|
|
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
|
|
|
}
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
@Test
|
|
|
|
public void testCreateEService() throws Exception {
|
|
|
|
EService eService = new EServiceImpl();
|
|
|
|
|
|
|
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
|
|
|
softwareFacet.setGroup("InformationSystem");
|
|
|
|
softwareFacet.setName("resource-registry");
|
|
|
|
softwareFacet.setVersion("1.1.0");
|
|
|
|
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
|
|
|
|
eService, softwareFacet, null);
|
|
|
|
eService.addFacet(isIdentifiedBy);
|
|
|
|
|
|
|
|
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
|
|
|
accessPointFacet.setEndpoint(new URI("http://localhost"));
|
|
|
|
accessPointFacet.setEntryName("port1");
|
|
|
|
eService.addFacet(accessPointFacet);
|
|
|
|
|
|
|
|
EventFacet eventFacet = new EventFacetImpl();
|
|
|
|
eventFacet.setDate(Calendar.getInstance().getTime());
|
|
|
|
eventFacet.setValue("Created");
|
|
|
|
eService.addFacet(eventFacet);
|
|
|
|
|
|
|
|
ServiceStateFacet serviceStateFacet = new ServiceStateFacetImpl();
|
|
|
|
serviceStateFacet.setValue("ready");
|
|
|
|
eService.addFacet(serviceStateFacet);
|
|
|
|
|
|
|
|
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
|
|
|
licenseFacet.setName("EUPL");
|
|
|
|
licenseFacet
|
|
|
|
.setTextURL(new URL(
|
|
|
|
"https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
|
|
|
eService.addFacet(licenseFacet);
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
eService = resourceRegistryPublisher.createResource(EService.class,
|
|
|
|
eService);
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
boolean deleted = resourceRegistryPublisher.deleteResource(eService);
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreateReadDeleteFacet() throws Exception {
|
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(
|
|
|
|
CPUFacet.class, cpuFacet);
|
2017-01-13 18:00:56 +01:00
|
|
|
|
|
|
|
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.getHeader().getUUID();
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
CPUFacet readCpuFacet = resourceRegistryClient.getInstance(
|
|
|
|
CPUFacet.class, uuid);
|
2017-01-13 18:00:56 +01:00
|
|
|
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.getHeader().getUUID()) == 0);
|
|
|
|
|
|
|
|
String newVendor = "Intel";
|
|
|
|
String newClockSpeed = "2 GHz";
|
|
|
|
readCpuFacet.setVendor(newVendor);
|
|
|
|
readCpuFacet.setClockSpeed(newClockSpeed);
|
|
|
|
|
|
|
|
String additionPropertyKey = "My";
|
|
|
|
String additionPropertyValue = "Test";
|
|
|
|
readCpuFacet.setAdditionalProperty(additionPropertyKey,
|
|
|
|
additionPropertyValue);
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
CPUFacet updatedCpuFacet = resourceRegistryPublisher.updateFacet(
|
|
|
|
CPUFacet.class, readCpuFacet);
|
2017-01-13 18:00:56 +01:00
|
|
|
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.getHeader().getUUID()) == 0);
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
CPUFacet readUpdatedCpuFacet = resourceRegistryClient.getInstance(
|
|
|
|
CPUFacet.class, uuid);
|
2017-01-13 18:00:56 +01:00
|
|
|
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.getHeader().getUUID()) == 0);
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
boolean deleted = resourceRegistryPublisher
|
|
|
|
.deleteFacet(readUpdatedCpuFacet);
|
2017-01-13 18:00:56 +01:00
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
public Map<String, Resource> createHostingNodeAndEService()
|
|
|
|
throws Exception {
|
2017-01-13 18:00:56 +01:00
|
|
|
Map<String, Resource> map = new HashMap<>();
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
EService eService = new EServiceImpl();
|
|
|
|
|
|
|
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
|
|
|
softwareFacet.setGroup("InformationSystem");
|
|
|
|
softwareFacet.setName("resource-registry");
|
|
|
|
softwareFacet.setVersion("1.1.0");
|
|
|
|
|
|
|
|
IsIdentifiedBy<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(
|
|
|
|
eService, softwareFacet, null);
|
|
|
|
eService.addFacet(isIdentifiedBy);
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
eService = resourceRegistryPublisher.createResource(EService.class,
|
|
|
|
eService);
|
2017-01-13 18:00:56 +01:00
|
|
|
map.put(EService.NAME, eService);
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
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");
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
networkingFacet = resourceRegistryPublisher.createFacet(
|
|
|
|
NetworkingFacet.class, networkingFacet);
|
2017-01-13 18:00:56 +01:00
|
|
|
logger.debug("Unmarshalled {} {}", NetworkingFacet.NAME,
|
|
|
|
networkingFacet);
|
|
|
|
|
|
|
|
HostingNode hostingNode = new HostingNodeImpl();
|
|
|
|
|
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
|
|
|
hostingNode.addFacet(cpuFacet);
|
|
|
|
|
|
|
|
isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(hostingNode,
|
|
|
|
networkingFacet, null);
|
2017-04-07 14:00:02 +02:00
|
|
|
hostingNode.addFacet(isIdentifiedBy);
|
2017-01-13 18:00:56 +01:00
|
|
|
|
|
|
|
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
|
|
|
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
2017-03-22 09:52:15 +01:00
|
|
|
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
Hosts<HostingNode, EService> hosts = new HostsImpl<HostingNode, EService>(
|
|
|
|
hostingNode, eService, propagationConstraint);
|
|
|
|
hostingNode.attachResource(hosts);
|
2017-01-13 18:20:14 +01:00
|
|
|
|
|
|
|
hostingNode = resourceRegistryPublisher.createResource(
|
|
|
|
HostingNode.class, hostingNode);
|
2017-01-13 18:00:56 +01:00
|
|
|
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
|
|
|
|
map.put(HostingNode.NAME, hostingNode);
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
return map;
|
|
|
|
}
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
@Test
|
|
|
|
public void testCreateHostingNodeAndEService() throws Exception {
|
|
|
|
Map<String, Resource> map = createHostingNodeAndEService();
|
2017-01-13 18:20:14 +01:00
|
|
|
|
|
|
|
boolean deleted = resourceRegistryPublisher.deleteResource(map
|
|
|
|
.get(EService.NAME));
|
2017-01-13 18:00:56 +01:00
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
deleted = resourceRegistryPublisher.deleteResource(map
|
|
|
|
.get(HostingNode.NAME));
|
2017-01-13 18:00:56 +01:00
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Test
|
2017-01-13 18:20:14 +01:00
|
|
|
public void testCreateHostingNodeAndEServiceWithSharedFacet()
|
|
|
|
throws Exception {
|
2017-01-13 18:00:56 +01:00
|
|
|
Map<String, Resource> map = createHostingNodeAndEService();
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
EService eService = (EService) map.get(EService.NAME);
|
|
|
|
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
|
|
|
|
UUID sharedFacetUUID = shared.getHeader().getUUID();
|
2017-01-13 18:20:14 +01:00
|
|
|
|
|
|
|
ConsistsOf<EService, Facet> consistsOf = new ConsistsOfImpl<EService, Facet>(
|
|
|
|
eService, shared, null);
|
|
|
|
consistsOf = resourceRegistryPublisher.createConsistsOf(
|
|
|
|
ConsistsOf.class, consistsOf);
|
|
|
|
|
|
|
|
boolean deleted = resourceRegistryPublisher.deleteResource(map
|
|
|
|
.get(EService.NAME));
|
2017-01-13 18:00:56 +01:00
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
deleted = resourceRegistryPublisher.deleteResource(map
|
|
|
|
.get(HostingNode.NAME));
|
2017-01-13 18:00:56 +01:00
|
|
|
Assert.assertTrue(deleted);
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
try {
|
|
|
|
resourceRegistryClient.getInstance(Facet.class, sharedFacetUUID);
|
2017-01-13 18:20:14 +01:00
|
|
|
throw new Exception(String.format(
|
|
|
|
"Shared Facet %s was not deleted", shared));
|
|
|
|
} catch (ResourceRegistryException e) {
|
2017-01-13 18:00:56 +01:00
|
|
|
logger.debug("Shared Facet was not foud as expected");
|
2017-01-13 18:20:14 +01:00
|
|
|
}
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Test
|
|
|
|
public void testCreateResourceAndFacet() throws Exception {
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
HostingNode hostingNode = new HostingNodeImpl();
|
2017-01-13 18:20:14 +01:00
|
|
|
hostingNode = resourceRegistryPublisher.createResource(
|
|
|
|
HostingNode.class, hostingNode);
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
2017-01-13 18:20:14 +01:00
|
|
|
|
|
|
|
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(
|
|
|
|
CPUFacet.class, cpuFacet);
|
|
|
|
|
|
|
|
ConsistsOf<HostingNode, Facet> consistsOf = new ConsistsOfImpl<HostingNode, Facet>(
|
|
|
|
hostingNode, createdCpuFacet, null);
|
|
|
|
consistsOf = resourceRegistryPublisher.createConsistsOf(
|
|
|
|
ConsistsOf.class, consistsOf);
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
UUID consistOfUUID = consistsOf.getHeader().getUUID();
|
|
|
|
|
2017-01-13 18:20:14 +01:00
|
|
|
boolean detached = resourceRegistryPublisher
|
|
|
|
.deleteConsistsOf(consistsOf);
|
2017-01-13 18:00:56 +01:00
|
|
|
|
|
|
|
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);
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Test
|
2017-01-13 18:20:14 +01:00
|
|
|
public void testGetAll() throws Exception {
|
2017-01-13 18:00:56 +01:00
|
|
|
Map<String, List<Resource>> resources = new HashMap<>();
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
final int MAX = 5;
|
|
|
|
int typeNumber = 0;
|
2017-01-13 18:20:14 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < MAX; i++) {
|
|
|
|
Map<String, Resource> map = createHostingNodeAndEService();
|
|
|
|
if (typeNumber == 0) {
|
2017-01-13 18:00:56 +01:00
|
|
|
typeNumber = map.size();
|
|
|
|
}
|
2017-01-13 18:20:14 +01:00
|
|
|
for (String key : map.keySet()) {
|
|
|
|
if (!resources.containsKey(key)) {
|
2017-01-13 18:00:56 +01:00
|
|
|
resources.put(key, new ArrayList<Resource>());
|
|
|
|
}
|
|
|
|
resources.get(key).add(map.get(key));
|
|
|
|
}
|
|
|
|
}
|
2017-01-13 18:20:14 +01:00
|
|
|
|
|
|
|
/* Getting all instances of created specific Resources */
|
|
|
|
for (String key : resources.keySet()) {
|
|
|
|
List<Resource> list = (List<Resource>) resourceRegistryClient
|
|
|
|
.getInstances(key, false);
|
2017-01-13 18:00:56 +01:00
|
|
|
logger.debug("{} are {} : {} ", key, list.size(), list);
|
2017-01-13 18:20:14 +01:00
|
|
|
Assert.assertTrue(list.size() == MAX);
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
/* Getting all Resources polymorphic and non polymorphic */
|
2017-01-13 18:20:14 +01:00
|
|
|
List<Resource> list = (List<Resource>) resourceRegistryClient
|
|
|
|
.getInstances(Resource.NAME, true);
|
2017-01-13 18:00:56 +01:00
|
|
|
logger.debug("{} are {} : {} ", Resource.NAME, list.size(), list);
|
2017-01-13 18:20:14 +01:00
|
|
|
Assert.assertTrue(list.size() == (MAX * typeNumber));
|
|
|
|
|
|
|
|
list = (List<Resource>) resourceRegistryClient.getInstances(
|
|
|
|
Resource.NAME, false);
|
|
|
|
Assert.assertTrue(list.size() == 0);
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
/* Getting all IsRelatedTo polymorphic and non polymorphic */
|
2017-01-13 18:20:14 +01:00
|
|
|
|
|
|
|
List<Resource> resourcesList = (List<Resource>) resourceRegistryClient
|
|
|
|
.getInstances(IsRelatedTo.NAME, true);
|
|
|
|
logger.debug("{} are {} : {} ", IsRelatedTo.NAME, resourcesList.size(),
|
|
|
|
resourcesList);
|
|
|
|
Assert.assertTrue(resourcesList.size() == MAX);
|
|
|
|
|
|
|
|
resourcesList = (List<Resource>) resourceRegistryClient.getInstances(
|
|
|
|
IsRelatedTo.NAME, false);
|
|
|
|
Assert.assertTrue(resourcesList.size() == 0);
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
/* Getting all ConsistsOf polymorphic and non polymorphic */
|
2017-01-13 18:20:14 +01:00
|
|
|
|
|
|
|
List<Resource> consistsOfPolimorphicList = (List<Resource>) resourceRegistryClient
|
|
|
|
.getInstances(ConsistsOf.NAME, true);
|
|
|
|
logger.debug("{} are {} : {} ", IsRelatedTo.NAME,
|
|
|
|
consistsOfPolimorphicList.size(), consistsOfPolimorphicList);
|
|
|
|
|
|
|
|
List<Resource> consistsOfNonPolimorphicList = (List<Resource>) resourceRegistryClient
|
|
|
|
.getInstances(ConsistsOf.NAME, false);
|
|
|
|
logger.debug("{} are {} : {} ", IsRelatedTo.NAME,
|
|
|
|
consistsOfNonPolimorphicList.size(),
|
|
|
|
consistsOfNonPolimorphicList);
|
|
|
|
|
|
|
|
Assert.assertTrue(consistsOfPolimorphicList.size() >= consistsOfNonPolimorphicList
|
|
|
|
.size());
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
/* Removing created Entity and Relation to have a clean DB */
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
List<Resource> resourceList = resources.get(HostingNode.NAME);
|
2017-01-13 18:20:14 +01:00
|
|
|
for (Resource r : resourceList) {
|
2017-01-13 18:00:56 +01:00
|
|
|
boolean deleted = resourceRegistryPublisher.deleteResource(r);
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
|
|
|
}
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
@Test
|
2017-01-13 18:20:14 +01:00
|
|
|
public void testGetAllFrom() throws Exception {
|
|
|
|
Map<String, Resource> map = createHostingNodeAndEService();
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
EService eService = (EService) map.get(EService.NAME);
|
|
|
|
UUID eServiceUUID = eService.getHeader().getUUID();
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
|
|
|
|
UUID hostingNodeUUID = hostingNode.getHeader().getUUID();
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
/* EService */
|
2017-01-13 18:20:14 +01:00
|
|
|
List<Resource> resourceList = resourceRegistryClient
|
|
|
|
.getInstancesFromEntity(IsRelatedTo.NAME, true, eServiceUUID,
|
|
|
|
Direction.both);
|
|
|
|
Assert.assertTrue(resourceList.size() == 1);
|
2017-01-13 18:00:56 +01:00
|
|
|
Resource sourceResource = resourceList.get(0);
|
2017-01-13 18:20:14 +01:00
|
|
|
Resource targetResource = sourceResource.getIsRelatedTo().get(0)
|
|
|
|
.getTarget();
|
|
|
|
Assert.assertTrue(sourceResource.getHeader().getUUID()
|
|
|
|
.compareTo(hostingNodeUUID) == 0);
|
|
|
|
Assert.assertTrue(targetResource.getHeader().getUUID()
|
|
|
|
.compareTo(eServiceUUID) == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
IsRelatedTo.NAME, true, eServiceUUID, Direction.in);
|
|
|
|
Assert.assertTrue(resourceList.size() == 1);
|
2017-01-13 18:00:56 +01:00
|
|
|
sourceResource = resourceList.get(0);
|
|
|
|
targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
|
2017-01-13 18:20:14 +01:00
|
|
|
Assert.assertTrue(sourceResource.getHeader().getUUID()
|
|
|
|
.compareTo(hostingNodeUUID) == 0);
|
|
|
|
Assert.assertTrue(targetResource.getHeader().getUUID()
|
|
|
|
.compareTo(eServiceUUID) == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
IsRelatedTo.NAME, true, eServiceUUID, Direction.out);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
IsRelatedTo.NAME, false, eServiceUUID, Direction.both);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
IsRelatedTo.NAME, false, eServiceUUID, Direction.in);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
IsRelatedTo.NAME, false, eServiceUUID, Direction.out);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
2017-01-13 18:00:56 +01:00
|
|
|
/* END EService */
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
/* Hosting Node */
|
2017-01-13 18:20:14 +01:00
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
IsRelatedTo.NAME, true, hostingNodeUUID, Direction.both);
|
|
|
|
Assert.assertTrue(resourceList.size() == 1);
|
2017-01-13 18:00:56 +01:00
|
|
|
sourceResource = resourceList.get(0);
|
|
|
|
targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
|
2017-01-13 18:20:14 +01:00
|
|
|
Assert.assertTrue(sourceResource.getHeader().getUUID()
|
|
|
|
.compareTo(hostingNodeUUID) == 0);
|
|
|
|
Assert.assertTrue(targetResource.getHeader().getUUID()
|
|
|
|
.compareTo(eServiceUUID) == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
IsRelatedTo.NAME, true, hostingNodeUUID, Direction.in);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
IsRelatedTo.NAME, true, hostingNodeUUID, Direction.out);
|
|
|
|
Assert.assertTrue(resourceList.size() == 1);
|
2017-01-13 18:00:56 +01:00
|
|
|
sourceResource = resourceList.get(0);
|
|
|
|
targetResource = sourceResource.getIsRelatedTo().get(0).getTarget();
|
2017-01-13 18:20:14 +01:00
|
|
|
Assert.assertTrue(sourceResource.getHeader().getUUID()
|
|
|
|
.compareTo(hostingNodeUUID) == 0);
|
|
|
|
Assert.assertTrue(targetResource.getHeader().getUUID()
|
|
|
|
.compareTo(eServiceUUID) == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
IsRelatedTo.NAME, false, hostingNodeUUID, Direction.both);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
IsRelatedTo.NAME, false, hostingNodeUUID, Direction.in);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
IsRelatedTo.NAME, false, hostingNodeUUID, Direction.out);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
2017-01-13 18:00:56 +01:00
|
|
|
/* END HostingNode */
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
Facet identificationFacet = eService.getIdentificationFacets().get(0);
|
2017-01-13 18:20:14 +01:00
|
|
|
UUID identificationFacetUUID = identificationFacet.getHeader()
|
|
|
|
.getUUID();
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
/* SoftwareFacet of Eservice */
|
2017-01-13 18:20:14 +01:00
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
ConsistsOf.NAME, true, identificationFacetUUID, Direction.both);
|
|
|
|
Assert.assertTrue(resourceList.size() == 1);
|
2017-01-13 18:00:56 +01:00
|
|
|
sourceResource = resourceList.get(0);
|
2017-01-13 18:20:14 +01:00
|
|
|
Facet targetIdentificationFacet = sourceResource
|
|
|
|
.getIdentificationFacets().get(0);
|
|
|
|
Assert.assertTrue(sourceResource.getHeader().getUUID()
|
|
|
|
.compareTo(eServiceUUID) == 0);
|
|
|
|
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID()
|
|
|
|
.compareTo(identificationFacetUUID) == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
ConsistsOf.NAME, true, identificationFacetUUID, Direction.in);
|
|
|
|
Assert.assertTrue(resourceList.size() == 1);
|
2017-01-13 18:00:56 +01:00
|
|
|
sourceResource = resourceList.get(0);
|
2017-01-13 18:20:14 +01:00
|
|
|
targetIdentificationFacet = sourceResource.getIdentificationFacets()
|
|
|
|
.get(0);
|
|
|
|
Assert.assertTrue(sourceResource.getHeader().getUUID()
|
|
|
|
.compareTo(eServiceUUID) == 0);
|
|
|
|
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID()
|
|
|
|
.compareTo(identificationFacetUUID) == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient.getInstancesFromEntity(
|
|
|
|
ConsistsOf.NAME, true, identificationFacetUUID, Direction.out);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
resourceList = resourceRegistryClient
|
|
|
|
.getInstancesFromEntity(ConsistsOf.NAME, false,
|
|
|
|
identificationFacetUUID, Direction.both);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
resourceRegistryClient.getInstancesFromEntity(ConsistsOf.NAME, false,
|
|
|
|
identificationFacetUUID, Direction.in);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
|
|
|
|
|
|
|
resourceRegistryClient.getInstancesFromEntity(ConsistsOf.NAME, false,
|
|
|
|
identificationFacetUUID, Direction.out);
|
|
|
|
Assert.assertTrue(resourceList.size() == 0);
|
2017-01-13 18:00:56 +01:00
|
|
|
/* END SoftwareFacet of Eservice */
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
/* Removing created Entity and Relation to have a clean DB */
|
|
|
|
boolean deleted = resourceRegistryPublisher.deleteResource(hostingNode);
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
}
|
2017-01-13 18:20:14 +01:00
|
|
|
|
2017-05-03 17:51:37 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Test
|
|
|
|
public void testCreateHostingNodeThenHostsWithEService()
|
|
|
|
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<HostingNode, NetworkingFacet> hnIsIdentifiedBy = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(hostingNode,
|
|
|
|
networkingFacet, null);
|
|
|
|
hostingNode.addFacet(hnIsIdentifiedBy);
|
|
|
|
|
|
|
|
|
|
|
|
hostingNode = resourceRegistryPublisher.createResource(HostingNode.class, hostingNode);
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- */
|
|
|
|
|
|
|
|
|
|
|
|
EService eService = new EServiceImpl();
|
|
|
|
|
|
|
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
|
|
|
softwareFacet.setGroup("InformationSystem");
|
|
|
|
softwareFacet.setName("resource-registry");
|
|
|
|
softwareFacet.setVersion("1.1.0");
|
|
|
|
|
|
|
|
IsIdentifiedBy<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(
|
|
|
|
eService, softwareFacet, null);
|
|
|
|
eService.addFacet(isIdentifiedBy);
|
|
|
|
|
|
|
|
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
|
|
|
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
|
|
|
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
|
|
|
|
|
|
|
|
Hosts<HostingNode, EService> hosts = new HostsImpl<HostingNode, EService>(
|
|
|
|
hostingNode, eService, propagationConstraint);
|
|
|
|
|
|
|
|
hosts = resourceRegistryPublisher.createIsRelatedTo(Hosts.class, hosts);
|
|
|
|
hostingNode.attachResource(hosts);
|
|
|
|
|
|
|
|
logger.debug("Created Hosts is {}", ISMapper.marshal(hosts));
|
|
|
|
|
|
|
|
boolean deleted = resourceRegistryPublisher.deleteResource(hostingNode);
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-13 18:00:56 +01:00
|
|
|
}
|