2016-11-14 16:33:35 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2021-07-05 17:31:42 +02:00
|
|
|
package org.gcube.informationsystem.resourceregistry.publisher.old;
|
2016-11-14 16:33:35 +01:00
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.Calendar;
|
2020-11-03 16:32:41 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2016-11-14 16:33:35 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2021-10-25 11:40:21 +02:00
|
|
|
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
|
|
|
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
|
2021-07-07 10:18:57 +02:00
|
|
|
import org.gcube.informationsystem.model.reference.ERElement;
|
2019-02-06 10:01:35 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
2020-11-04 16:23:29 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
2018-06-04 15:31:13 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
2017-04-11 15:23:45 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2017-04-03 18:44:47 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
2022-07-25 11:24:11 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl;
|
2021-07-05 17:31:42 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.publisher.ContextTest;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
|
2022-07-25 11:24:11 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl;
|
2019-02-06 10:18:06 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
|
|
|
|
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;
|
2020-12-21 23:10:21 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
|
2019-02-06 10:18:06 +01:00
|
|
|
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;
|
2019-12-05 12:13:19 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
2019-02-06 10:18:06 +01:00
|
|
|
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;
|
2019-12-05 12:13:19 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit;
|
2019-02-06 10:18:06 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
2020-12-21 23:10:21 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
|
2019-02-06 10:18:06 +01:00
|
|
|
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;
|
2019-12-05 12:13:19 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
2019-02-06 10:18:06 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
|
2016-11-14 16:33:35 +01:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*
|
|
|
|
*/
|
2019-02-13 12:23:10 +01:00
|
|
|
public class MultiContextTest extends ContextTest {
|
2016-11-14 16:33:35 +01:00
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory
|
|
|
|
.getLogger(MultiContextTest.class);
|
|
|
|
|
|
|
|
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
|
|
|
protected ResourceRegistryClient resourceRegistryClient;
|
|
|
|
|
2020-11-03 16:32:41 +01:00
|
|
|
public MultiContextTest() throws Exception {
|
2023-05-17 18:04:14 +02:00
|
|
|
// ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE);
|
2022-07-25 11:24:11 +02:00
|
|
|
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();
|
|
|
|
}
|
2016-11-14 16:33:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreateEServiceHostingNode() 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();
|
2021-02-22 09:47:26 +01:00
|
|
|
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
2016-11-14 16:33:35 +01:00
|
|
|
accessPointFacet.setEntryName("port1");
|
|
|
|
eService.addFacet(accessPointFacet);
|
|
|
|
|
|
|
|
EventFacet eventFacet = new EventFacetImpl();
|
|
|
|
eventFacet.setDate(Calendar.getInstance().getTime());
|
2021-08-04 15:15:02 +02:00
|
|
|
eventFacet.setEvent("Created");
|
2016-11-14 16:33:35 +01:00
|
|
|
eService.addFacet(eventFacet);
|
|
|
|
|
2020-12-21 23:10:21 +01:00
|
|
|
StateFacet stateFacet = new StateFacetImpl();
|
|
|
|
stateFacet.setValue("ready");
|
|
|
|
eService.addFacet(stateFacet);
|
2016-11-14 16:33:35 +01:00
|
|
|
|
|
|
|
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-10-03 17:48:37 +02:00
|
|
|
EService createdEService = resourceRegistryPublisher.createResource(eService);
|
2017-04-11 15:23:45 +02:00
|
|
|
logger.debug("Created : {}", createdEService);
|
2016-11-14 16:33:35 +01:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedByHNNF = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(hostingNode, networkingFacet, null);
|
|
|
|
hostingNode.addFacet(isIdentifiedByHNNF);
|
|
|
|
|
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
|
|
|
hostingNode.addFacet(cpuFacet);
|
|
|
|
|
|
|
|
|
|
|
|
MemoryFacet ram = new MemoryFacetImpl();
|
|
|
|
ram.setSize(8);
|
|
|
|
ram.setUnit(MemoryUnit.GB);
|
|
|
|
ram.setUsed(2);
|
|
|
|
|
|
|
|
HasVolatileMemory<HostingNode, MemoryFacet> hasVolatileMemory =
|
|
|
|
new HasVolatileMemoryImpl<HostingNode, MemoryFacet>(hostingNode, ram, null);
|
|
|
|
hostingNode.addFacet(hasVolatileMemory);
|
|
|
|
|
|
|
|
|
|
|
|
MemoryFacet disk = new MemoryFacetImpl();
|
|
|
|
disk.setSize(256);
|
|
|
|
disk.setUnit(MemoryUnit.GB);
|
|
|
|
disk.setUsed(120);
|
|
|
|
|
|
|
|
HasPersistentMemory<HostingNode, MemoryFacet> hasPersistentMemory =
|
|
|
|
new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(hostingNode, disk, null);
|
|
|
|
hostingNode.addFacet(hasPersistentMemory);
|
|
|
|
|
2023-05-17 18:04:14 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
2018-10-02 09:24:05 +02:00
|
|
|
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(hostingNode, createdEService, null);
|
|
|
|
hostingNode.attachResource(activates);
|
2016-11-14 16:33:35 +01:00
|
|
|
|
2017-10-03 17:48:37 +02:00
|
|
|
HostingNode createdHN = resourceRegistryPublisher.createResource(hostingNode);
|
2016-11-14 16:33:35 +01:00
|
|
|
logger.debug("Created : {}", createdHN);
|
|
|
|
|
2023-04-28 11:49:11 +02:00
|
|
|
UUID hostingNodeUUID = createdHN.getID();
|
|
|
|
UUID eServiceUUID = createdEService.getID();
|
2017-04-11 15:23:45 +02:00
|
|
|
|
2023-05-17 18:04:14 +02:00
|
|
|
UUID alternativeContextUUID = ContextCache.getInstance().getUUIDByFullName(ALTERNATIVE_TEST_SCOPE);
|
|
|
|
|
|
|
|
resourceRegistryPublisher.addResourceToContext(createdHN, alternativeContextUUID, false);
|
|
|
|
|
2017-04-11 15:23:45 +02:00
|
|
|
logger.debug("Changing token to test add to scope");
|
2020-02-05 16:33:15 +01:00
|
|
|
ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE);
|
2017-04-11 15:23:45 +02:00
|
|
|
|
|
|
|
try {
|
2022-02-09 13:30:20 +01:00
|
|
|
resourceRegistryClient.existInstance(EService.class, eServiceUUID);
|
2018-06-04 15:31:13 +02:00
|
|
|
} catch (NotFoundException e) {
|
2017-04-11 15:23:45 +02:00
|
|
|
throw e;
|
2018-06-04 15:31:13 +02:00
|
|
|
} catch (AvailableInAnotherContextException e) {
|
2017-04-11 15:23:45 +02:00
|
|
|
// Good
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2022-02-09 13:30:20 +01:00
|
|
|
resourceRegistryClient.existInstance(HostingNode.class, hostingNodeUUID);
|
2018-06-04 15:31:13 +02:00
|
|
|
} catch (NotFoundException e) {
|
2017-04-11 15:23:45 +02:00
|
|
|
throw e;
|
2018-06-04 15:31:13 +02:00
|
|
|
} catch (AvailableInAnotherContextException e) {
|
2017-04-11 15:23:45 +02:00
|
|
|
// Good
|
|
|
|
} catch (ResourceRegistryException e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-25 09:28:03 +02:00
|
|
|
List<ERElement> affectedInstances = resourceRegistryPublisher.addResourceToCurrentContext(createdHN, false);
|
2021-07-07 10:18:57 +02:00
|
|
|
logger.debug("{} added to context. Affected instances are {}", createdHN, affectedInstances);
|
|
|
|
//Assert.assertTrue(addedToContext);
|
2017-02-24 11:51:22 +01:00
|
|
|
|
2016-11-14 16:33:35 +01:00
|
|
|
try {
|
2022-02-09 13:30:20 +01:00
|
|
|
resourceRegistryClient.existInstance(EService.class, eServiceUUID);
|
2018-06-12 16:06:59 +02:00
|
|
|
}catch(AvailableInAnotherContextException e){
|
|
|
|
logger.debug("Resource with {} Available in another Context as Expected", eServiceUUID.toString());
|
2016-11-14 16:33:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean deleted = resourceRegistryPublisher.deleteResource(createdHN);
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
2017-01-12 12:44:50 +01:00
|
|
|
|
|
|
|
logger.debug("Restoring original scope");
|
2020-02-05 16:33:15 +01:00
|
|
|
ContextTest.setContextByName(ContextTest.DEFAULT_TEST_SCOPE);
|
2017-01-12 12:44:50 +01:00
|
|
|
|
2017-04-11 15:23:45 +02:00
|
|
|
deleted = resourceRegistryPublisher.deleteResource(createdEService);
|
2016-11-14 16:33:35 +01:00
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-03 16:32:41 +01:00
|
|
|
@Test
|
|
|
|
public void testGetAllContexts() throws Exception {
|
|
|
|
List<Context> contexts = resourceRegistryPublisher.getAllContext();
|
|
|
|
logger.debug("{}", contexts);
|
|
|
|
|
|
|
|
ContextCache contextCache = ContextCache.getInstance();
|
|
|
|
Map<UUID, String> uuidToContextFullName = contextCache.getUUIDToContextFullNameAssociation();
|
|
|
|
logger.debug("{}", uuidToContextFullName);
|
|
|
|
|
|
|
|
|
|
|
|
for(Context c : contexts) {
|
2023-04-28 11:49:11 +02:00
|
|
|
UUID uuid = c.getID();
|
2020-11-03 16:32:41 +01:00
|
|
|
if(c.getParent()!=null) {
|
|
|
|
IsParentOf isParentOf = c.getParent();
|
|
|
|
Context parentContext = isParentOf.getSource();
|
2023-04-28 11:49:11 +02:00
|
|
|
UUID parentUUID = parentContext.getID();
|
2020-11-03 16:32:41 +01:00
|
|
|
Assert.assertEquals(parentContext, contextCache.getContextByUUID(parentUUID));
|
|
|
|
List<IsParentOf> children = parentContext.getChildren();
|
|
|
|
boolean found = false;
|
|
|
|
for(IsParentOf ipo : children) {
|
|
|
|
if(ipo.equals(isParentOf)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Assert.assertTrue(found);
|
2023-04-28 11:49:11 +02:00
|
|
|
logger.debug("{} : {} (parent {} : {})", c.getID(), contextCache.getContextFullNameByUUID(uuid), parentUUID, contextCache.getContextFullNameByUUID(parentUUID));
|
2020-11-03 16:32:41 +01:00
|
|
|
}else {
|
2023-04-28 11:49:11 +02:00
|
|
|
logger.debug("{} : {}", c.getID(), contextCache.getContextFullNameByUUID(uuid));
|
2020-11-03 16:32:41 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-04 19:12:52 +01:00
|
|
|
|
|
|
|
Context currentContext = resourceRegistryPublisher.getCurrentContext();
|
|
|
|
logger.debug("Current context : {}", currentContext);
|
|
|
|
|
|
|
|
for(Context c : contexts) {
|
2023-04-28 11:49:11 +02:00
|
|
|
UUID uuid = c.getID();
|
2020-11-04 19:12:52 +01:00
|
|
|
Context context = resourceRegistryPublisher.getContext(uuid);
|
|
|
|
String fullName = ContextCache.getInstance().getContextFullNameByUUID(uuid);
|
|
|
|
logger.debug("{} - {} : {}", uuid, fullName, context);
|
|
|
|
}
|
2020-11-03 16:32:41 +01:00
|
|
|
}
|
|
|
|
|
2016-11-14 16:33:35 +01:00
|
|
|
}
|