Refs #11903: Use new REST interface in Resource Registry Publisher

Task-Url: https://support.d4science.org/issues/11903

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@169036 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2018-06-12 08:02:31 +00:00
parent 6e984b7acb
commit f57e55f9a4
1 changed files with 214 additions and 220 deletions

View File

@ -77,8 +77,8 @@ public class ERManagementTest extends ScopedTest {
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(eService,
softwareFacet, null);
IsIdentifiedBy<EService,Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService,Facet>(eService, softwareFacet,
null);
eService.addFacet(isIdentifiedBy);
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
@ -115,8 +115,8 @@ public class ERManagementTest extends ScopedTest {
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(eService,
softwareFacet, null);
IsIdentifiedBy<EService,Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService,Facet>(eService, softwareFacet,
null);
eService.addFacet(isIdentifiedBy);
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
@ -159,8 +159,8 @@ public class ERManagementTest extends ScopedTest {
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(eService,
softwareFacet, null);
IsIdentifiedBy<EService,Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService,Facet>(eService, softwareFacet,
null);
eService.addFacet(isIdentifiedBy);
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
@ -201,8 +201,8 @@ public class ERManagementTest extends ScopedTest {
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(eService,
softwareFacet, null);
IsIdentifiedBy<EService,Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService,Facet>(eService, softwareFacet,
null);
eService.addFacet(isIdentifiedBy);
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
@ -289,8 +289,8 @@ public class ERManagementTest extends ScopedTest {
Assert.assertTrue(deleted);
}
public Map<String, Resource> createHostingNodeAndEService() throws Exception {
Map<String, Resource> map = new HashMap<>();
public Map<String,Resource> createHostingNodeAndEService() throws Exception {
Map<String,Resource> map = new HashMap<>();
EService eService = new EServiceImpl();
@ -299,8 +299,8 @@ public class ERManagementTest extends ScopedTest {
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(eService,
softwareFacet, null);
IsIdentifiedBy<Resource,Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(eService, softwareFacet,
null);
eService.addFacet(isIdentifiedBy);
eService = resourceRegistryPublisher.createResource(eService);
@ -324,14 +324,14 @@ public class ERManagementTest extends ScopedTest {
cpuFacet.setVendor("AMD");
hostingNode.addFacet(cpuFacet);
isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(hostingNode, networkingFacet, null);
isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(hostingNode, networkingFacet, null);
hostingNode.addFacet(isIdentifiedBy);
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
Hosts<HostingNode, EService> hosts = new HostsImpl<HostingNode, EService>(hostingNode, eService,
Hosts<HostingNode,EService> hosts = new HostsImpl<HostingNode,EService>(hostingNode, eService,
propagationConstraint);
hostingNode.attachResource(hosts);
@ -344,7 +344,7 @@ public class ERManagementTest extends ScopedTest {
@Test
public void testCreateHostingNodeAndEService() throws Exception {
Map<String, Resource> map = createHostingNodeAndEService();
Map<String,Resource> map = createHostingNodeAndEService();
boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME));
Assert.assertTrue(deleted);
@ -355,7 +355,7 @@ public class ERManagementTest extends ScopedTest {
@Test
public void testCreateHostingNodeAndEServiceWithSharedFacet() throws Exception {
Map<String, Resource> map = createHostingNodeAndEService();
Map<String,Resource> map = createHostingNodeAndEService();
EService eService = (EService) map.get(EService.NAME);
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
@ -363,7 +363,7 @@ public class ERManagementTest extends ScopedTest {
Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
UUID sharedFacetUUID = shared.getHeader().getUUID();
ConsistsOf<EService, Facet> consistsOf = new ConsistsOfImpl<EService, Facet>(eService, shared, null);
ConsistsOf<EService,Facet> consistsOf = new ConsistsOfImpl<EService,Facet>(eService, shared, null);
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME));
@ -375,7 +375,7 @@ public class ERManagementTest extends ScopedTest {
try {
resourceRegistryClient.getInstance(Facet.class, sharedFacetUUID);
throw new Exception(String.format("Shared Facet %s was not deleted", shared));
} catch (ResourceRegistryException e) {
} catch(ResourceRegistryException e) {
logger.debug("Shared Facet was not foud as expected");
}
}
@ -393,7 +393,7 @@ public class ERManagementTest extends ScopedTest {
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
ConsistsOf<HostingNode, Facet> consistsOf = new ConsistsOfImpl<HostingNode, Facet>(hostingNode, createdCpuFacet,
ConsistsOf<HostingNode,Facet> consistsOf = new ConsistsOfImpl<HostingNode,Facet>(hostingNode, createdCpuFacet,
null);
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
@ -401,7 +401,7 @@ public class ERManagementTest extends ScopedTest {
boolean detached = resourceRegistryPublisher.deleteConsistsOf(consistsOf);
if (detached) {
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,
@ -417,18 +417,18 @@ public class ERManagementTest extends ScopedTest {
@Test
public void testGetAll() throws Exception {
Map<String, List<Resource>> resources = new HashMap<>();
Map<String,List<Resource>> resources = new HashMap<>();
final int MAX = 5;
int typeNumber = 0;
for (int i = 0; i < MAX; i++) {
Map<String, Resource> map = createHostingNodeAndEService();
if (typeNumber == 0) {
for(int i = 0; i < MAX; i++) {
Map<String,Resource> map = createHostingNodeAndEService();
if(typeNumber == 0) {
typeNumber = map.size();
}
for (String key : map.keySet()) {
if (!resources.containsKey(key)) {
for(String key : map.keySet()) {
if(!resources.containsKey(key)) {
resources.put(key, new ArrayList<Resource>());
}
resources.get(key).add(map.get(key));
@ -436,7 +436,7 @@ public class ERManagementTest extends ScopedTest {
}
/* Getting all instances of created specific Resources */
for (String key : resources.keySet()) {
for(String key : resources.keySet()) {
String instances = resourceRegistryClient.getInstances(key, false);
List<Resource> list = ISMapper.unmarshalList(Resource.class, instances);
logger.debug("{} are {} : {} ", key, list.size(), list);
@ -474,7 +474,7 @@ public class ERManagementTest extends ScopedTest {
/* Removing created Entity and Relation to have a clean DB */
List<Resource> resourceList = resources.get(HostingNode.NAME);
for (Resource r : resourceList) {
for(Resource r : resourceList) {
boolean deleted = resourceRegistryPublisher.deleteResource(r);
Assert.assertTrue(deleted);
}
@ -482,7 +482,7 @@ public class ERManagementTest extends ScopedTest {
@Test
public void testGetAllFrom() throws Exception {
Map<String, Resource> map = createHostingNodeAndEService();
Map<String,Resource> map = createHostingNodeAndEService();
EService eService = (EService) map.get(EService.NAME);
UUID eServiceUUID = eService.getHeader().getUUID();
@ -491,108 +491,102 @@ public class ERManagementTest extends ScopedTest {
UUID hostingNodeUUID = hostingNode.getHeader().getUUID();
/* EService */
List<Resource> resourceList = resourceRegistryClient.getInstancesFromEntity(IsRelatedTo.class, true,
eServiceUUID, Direction.both);
List<Resource> resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.both, true);
Assert.assertTrue(resourceList.size() == 1);
Resource sourceResource = resourceList.get(0);
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.class, true, eServiceUUID,
Direction.in);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.out, true);
Assert.assertTrue(resourceList.size() == 1);
sourceResource = resourceList.get(0);
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.class, true, eServiceUUID,
Direction.out);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.in, true);
Assert.assertTrue(resourceList.size() == 0);
resourceList = resourceRegistryClient.getInstancesFromEntity(IsRelatedTo.class, false, eServiceUUID,
Direction.both);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.both, false);
Assert.assertTrue(resourceList.size() == 0);
resourceList = resourceRegistryClient.getInstancesFromEntity(IsRelatedTo.class, false, eServiceUUID,
Direction.in);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.out, false);
Assert.assertTrue(resourceList.size() == 0);
resourceList = resourceRegistryClient.getInstancesFromEntity(IsRelatedTo.class, false, eServiceUUID,
Direction.out);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.in, false);
Assert.assertTrue(resourceList.size() == 0);
/* END EService */
/* Hosting Node */
resourceList = resourceRegistryClient.getInstancesFromEntity(IsRelatedTo.class, true, hostingNodeUUID,
Direction.both);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.both, true);
Assert.assertTrue(resourceList.size() == 1);
sourceResource = resourceList.get(0);
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.class, true, hostingNodeUUID,
Direction.in);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.out, true);
Assert.assertTrue(resourceList.size() == 0);
resourceList = resourceRegistryClient.getInstancesFromEntity(IsRelatedTo.class, true, hostingNodeUUID,
Direction.out);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.in, true);
Assert.assertTrue(resourceList.size() == 1);
sourceResource = resourceList.get(0);
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.class, false, hostingNodeUUID,
Direction.both);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.both, false);
Assert.assertTrue(resourceList.size() == 0);
resourceList = resourceRegistryClient.getInstancesFromEntity(IsRelatedTo.class, false, hostingNodeUUID,
Direction.in);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.out, false);
Assert.assertTrue(resourceList.size() == 0);
resourceList = resourceRegistryClient.getInstancesFromEntity(IsRelatedTo.class, false, hostingNodeUUID,
Direction.out);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.in, false);
Assert.assertTrue(resourceList.size() == 0);
/* END HostingNode */
Facet identificationFacet = eService.getIdentificationFacets().get(0);
UUID identificationFacetUUID = identificationFacet.getHeader().getUUID();
/* SoftwareFacet of Eservice */
resourceList = resourceRegistryClient.getInstancesFromEntity(ConsistsOf.class, true, identificationFacetUUID,
Direction.both);
/* Eservice with Software Facet as Identification Facet */
resourceList = resourceRegistryClient.getResourcesFromReferenceFacet(Resource.class, ConsistsOf.class, SoftwareFacet.class, identificationFacetUUID, true);
Assert.assertTrue(resourceList.size() == 1);
sourceResource = resourceList.get(0);
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.class, true, identificationFacetUUID,
Direction.in);
resourceList = resourceRegistryClient.getResourcesFromReferenceFacet(Resource.class, ConsistsOf.class, SoftwareFacet.class, identificationFacetUUID, false);
Assert.assertTrue(resourceList.size() == 0);
/* END Eservice with Software Facet as Identification Facet */
/* END SoftwareFacet of Eservice */
List<Facet> facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, true);
Assert.assertTrue(resourceList.size() == 1);
sourceResource = resourceList.get(0);
targetIdentificationFacet = sourceResource.getIdentificationFacets().get(0);
Assert.assertTrue(sourceResource.getHeader().getUUID().compareTo(eServiceUUID) == 0);
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0);
Facet facet = facets.get(0);
Assert.assertTrue(facet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0);
resourceList = resourceRegistryClient.getInstancesFromEntity(ConsistsOf.class, true, identificationFacetUUID,
Direction.out);
facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, false);
Assert.assertTrue(resourceList.size() == 0);
resourceList = resourceRegistryClient.getInstancesFromEntity(ConsistsOf.class, false, identificationFacetUUID,
Direction.both);
Assert.assertTrue(resourceList.size() == 0);
resourceList = resourceRegistryClient.getInstancesFromEntity(ConsistsOf.class, false, identificationFacetUUID,
Direction.in);
Assert.assertTrue(resourceList.size() == 0);
resourceList = resourceRegistryClient.getInstancesFromEntity(ConsistsOf.class, false, identificationFacetUUID,
Direction.out);
Assert.assertTrue(resourceList.size() == 0);
/* END SoftwareFacet of Eservice */
/* Removing created Entity and Relation to have a clean DB */
@ -618,7 +612,7 @@ public class ERManagementTest extends ScopedTest {
networkingFacet.setMask("255.255.248.0");
networkingFacet.setBroadcastAddress("146.48.87.255");
IsIdentifiedBy<HostingNode, NetworkingFacet> hnIsIdentifiedBy = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(
IsIdentifiedBy<HostingNode,NetworkingFacet> hnIsIdentifiedBy = new IsIdentifiedByImpl<HostingNode,NetworkingFacet>(
hostingNode, networkingFacet, null);
hostingNode.addFacet(hnIsIdentifiedBy);
@ -633,15 +627,15 @@ public class ERManagementTest extends ScopedTest {
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(eService,
softwareFacet, null);
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,
Hosts<HostingNode,EService> hosts = new HostsImpl<HostingNode,EService>(hostingNode, eService,
propagationConstraint);
hosts = resourceRegistryPublisher.createIsRelatedTo(hosts);