Porting naming to allow usage of gcat from other services as library

This commit is contained in:
luca.frosini 2023-06-23 18:01:12 +02:00
parent 5194e734aa
commit ce8f089de8
6 changed files with 41 additions and 39 deletions

View File

@ -64,7 +64,7 @@ public class GCatInitializator implements ApplicationManager {
facetBasedISConfigurationProxy.installQueryTemplate();
initialised = true;
}
facetBasedISConfigurationProxy.setGcatEServiceID(gcatEServiceID);
facetBasedISConfigurationProxy.setServiceEServiceID(gcatEServiceID);
facetBasedISConfigurationProxy.createCallsForToVirtualService();
}catch (Exception e) {
logger.warn("Gcat is not configured through the Facet Based IS in context {}. Please create/addToContext the expected resources ASAP. The Gcore IS will be used.", context);

View File

@ -62,18 +62,19 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
private static Logger logger = LoggerFactory.getLogger(FacetBasedISConfigurationProxy.class);
public final String QUERY_TEMPLATE_DIRECTORY_NAME = "query-template";
public final String GCAT_ESERVICE_UUID_VARNAME = "$uuid";
public final String SERVICE_ESERVICE_UUID_VARNAME = "$uuid";
public final String GET_CALLS_FOR_QUERY_TEMPLATE_FILENAME = "01-get-calls-for-query-template.json";
public final String QUERY_DIRECTORY_NAME = "query";
public final String GET_CATALOGUE_VIRTUAL_SERVICE_FILENAME = "01-get-catalogue-virtual-service.json";
public final String GET_GCAT_CONFIGURATION_FILENAME = "02-get-gcat-configuration.json";
public final String GET_SIMPLE_FACET_OF_GCAT_CONFIGURATION_FILENAME = "03-get-simple-facet-of-gcat-configuration.json";
public final String GET_CATALOGUE_CONFIGURATION_FILENAME = "02-get-catalogue-configuration.json";
public final String GET_SIMPLE_FACET_OF_CATALOGUE_CONFIGURATION_FILENAME = "03-get-simple-facet-of-catalogue-configuration.json";
public final String GET_ACCESS_POINT_FACET_OF_CKAN_SERVICE_FILENAME = "05-get-access-point-facet-of-ckan-service.json";
public final String GET_ACCESS_POINT_FACET_OF_POSTGRES_CKAN_DB_FILENAME = "07-get-access-point-facet-of-postgres-ckan-db.json";
public final String GET_ACCESS_POINT_FACET_OF_SOLR_SERVICE_FILENAME = "09-get-access-point-facet-of-solr-service.json";
protected QueryTemplate queryTemplate;
protected String serviceName;
public QueryTemplate getQueryTemplateFromFile(String queryTemplateFilename) throws Exception {
File queryTemplateFile = getJsonQueryTemplateFromFile(queryTemplateFilename);
@ -111,12 +112,12 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
}
//
// Configuration
// ----------------------
// IsCustomizedBy | |
// -----------------> | gcat-configuration |
// / | |
// / ----------------------
// Configuration
// ---------------------------
// IsCustomizedBy | |
// -----------------> | catalogue-configuration |
// / | |
// / ---------------------------
// EService VirtualService /
// ------------ -----------------------------
// | | CallsFor | |
@ -170,11 +171,13 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
protected SimpleFacet configurationSimpleFacet;
protected String gcatEServiceID;
protected String serviceEServiceID;
public FacetBasedISConfigurationProxy(String context) {
super(context);
serviceName = "gcat";
resourceRegistryClient = ResourceRegistryClientFactory.create();
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
rrqtc = ResourceRegistryQueryTemplateClientFactory.create();
@ -184,8 +187,7 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
}catch(Exception e) {
throw new RuntimeException(FacetBasedISConfigurationProxy.class.getSimpleName() + " cannot be used", e);
}
objectMapper = new ObjectMapper();
objectMapper = new ObjectMapper();
}
public VirtualService getVirtualService() {
@ -195,15 +197,15 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
return virtualService;
}
public void setGcatEServiceID(String gcatEServiceID) {
this.gcatEServiceID = gcatEServiceID;
public void setServiceEServiceID(String serviceEServiceID) {
this.serviceEServiceID = serviceEServiceID;
}
public List<CallsFor<EService, VirtualService>> getCallsForToVirtualService() throws Exception {
ResourceRegistryQueryTemplateClient rrqtc = ResourceRegistryQueryTemplateClientFactory.create();
ObjectNode objectNode = objectMapper.createObjectNode();
objectNode.put(GCAT_ESERVICE_UUID_VARNAME, gcatEServiceID);
objectNode.put(SERVICE_ESERVICE_UUID_VARNAME, serviceEServiceID);
List<CallsFor<EService, VirtualService>> callsForList = rrqtc.run(queryTemplate.getName(), objectNode);
return callsForList;
@ -228,11 +230,11 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
int size = callsForList.size();
UUID gcatEServiceUUID = UUID.fromString(gcatEServiceID);
UUID serviceEServiceUUID = UUID.fromString(serviceEServiceID);
if(size>1) {
logger.warn("There are {} instances of {} relation beetween gcat Eservice with UUID {} and the {} (catalogue-virtual-service). This is very strange because there should be only one. We are going to delete them and recreated a new one.",
callsForList.size(), CallsFor.NAME, gcatEServiceID, VirtualService.NAME);
logger.warn("There are {} instances of {} relation beetween {} Eservice with UUID {} and the {} (catalogue-virtual-service). This is very strange because there should be only one. We are going to delete them and recreated a new one.",
callsForList.size(), CallsFor.NAME, serviceName, serviceEServiceID, VirtualService.NAME);
logger.trace("{} relation instances that are going to be deleted are {}",
CallsFor.NAME, ElementMapper.marshal(callsForList));
deleteCallsForToVirtualService(callsForList);
@ -240,21 +242,21 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
}
if(size==0) {
logger.info("Going to create {} between {} (gcat with UUID={}) and the {}",
CallsFor.NAME, EService.NAME, gcatEServiceID, VirtualService.NAME);
logger.info("Going to create {} between {} ({} with UUID={}) and the {}",
CallsFor.NAME, EService.NAME, serviceName, serviceEServiceID, VirtualService.NAME);
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
propagationConstraint.setRemoveConstraint(RemoveConstraint.keep);
propagationConstraint.setDeleteConstraint(DeleteConstraint.keep);
EService gcatEService = new EServiceImpl();
gcatEService.setID(gcatEServiceUUID);
EService serviceEService = new EServiceImpl();
serviceEService.setID(serviceEServiceUUID);
VirtualService virtualService = queryVirtualService();
callsFor = new CallsForImpl<EService, VirtualService>(gcatEService, virtualService, propagationConstraint);
callsFor = new CallsForImpl<EService, VirtualService>(serviceEService, virtualService, propagationConstraint);
callsFor = resourceRegistryPublisher.create(callsFor);
}else if(size==1){
callsFor = callsForList.get(0);
logger.info("{} between {} (gcat with UUID={}) and the {} exists.\n{}",
CallsFor.NAME, EService.NAME, gcatEServiceID, VirtualService.NAME, ElementMapper.marshal(callsFor));
logger.info("{} between {} ({} with UUID={}) and the {} exists.\n{}",
CallsFor.NAME, EService.NAME, serviceName, serviceEServiceID, VirtualService.NAME, ElementMapper.marshal(callsFor));
}
return callsFor;
@ -309,13 +311,13 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
}
}
protected Configuration queryGcatConfiguration() throws Exception {
Configuration configuration = (Configuration) queryEntity(GET_GCAT_CONFIGURATION_FILENAME);
protected Configuration queryServiceConfiguration() throws Exception {
Configuration configuration = (Configuration) queryEntity(GET_CATALOGUE_CONFIGURATION_FILENAME);
return configuration;
}
protected SimpleFacet queryConfigurationSimpleFacet() throws Exception {
SimpleFacet configurationSimpleFacet = (SimpleFacet) queryEntity(GET_SIMPLE_FACET_OF_GCAT_CONFIGURATION_FILENAME);
SimpleFacet configurationSimpleFacet = (SimpleFacet) queryEntity(GET_SIMPLE_FACET_OF_CATALOGUE_CONFIGURATION_FILENAME);
return configurationSimpleFacet;
}
@ -483,8 +485,8 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleF
protected ServiceCatalogueConfiguration createOnIS() throws Exception {
UUID uuid = configurationSimpleFacet.getID();
if(uuid==null) {
Configuration gcatConfiguration = queryGcatConfiguration();
ConsistsOf<Configuration, SimpleFacet> co = new ConsistsOfImpl<>(gcatConfiguration, configurationSimpleFacet);
Configuration configuration = queryServiceConfiguration();
ConsistsOf<Configuration, SimpleFacet> co = new ConsistsOfImpl<>(configuration, configurationSimpleFacet);
co = resourceRegistryPublisher.create(co);
configurationSimpleFacet = co.getTarget();
setConfigurationInfoFromSimpleFacet(configurationSimpleFacet, catalogueConfiguration);

View File

@ -5,7 +5,7 @@
"@class": "IsIdentifiedBy",
"target": {
"@class": "IdentifierFacet",
"value": "gcat-configuration"
"value": "catalogue-configuration"
}
}
],

View File

@ -1,10 +1,10 @@
Configuration
----------------------
IsCustomizedBy | |
-----------------> | gcat-configuration |
/ | |
/ ----------------------
Configuration
---------------------------
IsCustomizedBy | |
-----------------> | catalogue-configuration |
/ | |
/ ---------------------------
EService VirtualService /
------------ -----------------------------
| | CallsFor | |

View File

@ -26,7 +26,7 @@ public class FacetBasedISConfigurationProxyTest extends ContextTest {
public void test() throws Exception {
FacetBasedISConfigurationProxyFactory facetBasedISConfigurationProxyFactory = new FacetBasedISConfigurationProxyFactory();
FacetBasedISConfigurationProxy fbiscp = facetBasedISConfigurationProxyFactory.getInstance();
fbiscp.setGcatEServiceID("f00bbacd-92b8-46d7-b41c-828f71a78753");
fbiscp.setServiceEServiceID("f00bbacd-92b8-46d7-b41c-828f71a78753");
CallsFor<EService, VirtualService> callsFor = fbiscp.createCallsForToVirtualService();
logger.debug("Created {}", ElementMapper.marshal(callsFor));