completed work on

[Task #6952] Catalogue Resolver: update on the fly the Application Profile for VRE's used to resolve Product URL


git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@144442 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-02-28 16:26:18 +00:00
parent ff5e080b06
commit c6e3ac624d
2 changed files with 29 additions and 21 deletions

View File

@ -310,11 +310,14 @@ public class CatalogueResolver extends HttpServlet{
public void run() { public void run() {
try { try {
String fullScope = cer.getValueOfParameter(CatalogueRequestParameter.GCUBE_SCOPE.getKey()); String fullScope = cer.getValueOfParameter(CatalogueRequestParameter.GCUBE_SCOPE.getKey());
UpdateApplicationProfileCatalogueResolver.validateEndPoint(scopeToEncDecr, vreName, fullScope); boolean endPointUpdated = UpdateApplicationProfileCatalogueResolver.validateEndPoint(scopeToEncDecr, vreName, fullScope);
if(endPointUpdated)
appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(scopeToEncDecr, true);
} }
catch (ApplicationProfileNotFoundException e) { catch (ApplicationProfileNotFoundException e) {
// TODO Auto-generated catch block logger.error("Error during validating Application Profile", e);
e.printStackTrace();
} }
}; };
}.start(); }.start();

View File

@ -40,17 +40,17 @@ public class UpdateApplicationProfileCatalogueResolver {
private static Logger logger = Logger.getLogger(UpdateApplicationProfileCatalogueResolver.class); private static Logger logger = Logger.getLogger(UpdateApplicationProfileCatalogueResolver.class);
private static boolean useRootScope = false; private static boolean useRootScope = false;
/** /**
* Validate end point. If the EndPoint VRE-FULLNAME does not exist it will be added to Application Profile: {@link ApplicationProfileReaderForCatalogueResolver#RESOURCE_NAME} * Validate end point. If the EndPoint VRE-FULLNAME does not exist it will be added to Application Profile: {@link ApplicationProfileReaderForCatalogueResolver#RESOURCE_NAME}
* *
* @param scopeToInstanceResolver the scope to instance resolver * @param scopeToInstanceResolver the scope to instance resolver
* @param VRE the vre * @param VRE the vre
* @param fullScope the full scope * @param fullScope the full scope
* @return true, if Application Profile has been updated. No otherwise
* @throws ApplicationProfileNotFoundException the application profile not found exception * @throws ApplicationProfileNotFoundException the application profile not found exception
*/ */
public static void validateEndPoint(String scopeToInstanceResolver, String VRE, String fullScope) throws ApplicationProfileNotFoundException { public static boolean validateEndPoint(String scopeToInstanceResolver, String VRE, String fullScope) throws ApplicationProfileNotFoundException {
logger.info("Checking if the VRE_NAME: "+VRE+", exists into Application Profile: "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+" using scope: "+scopeToInstanceResolver); logger.info("Checking if the VRE_NAME: "+VRE+" exists into Application Profile: "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+" using scope: "+scopeToInstanceResolver);
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(scopeToInstanceResolver, true); ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(scopeToInstanceResolver, true);
Element root = appPrCatResolver.getRootDocument(); Element root = appPrCatResolver.getRootDocument();
String originalScope = null; String originalScope = null;
@ -61,11 +61,11 @@ public class UpdateApplicationProfileCatalogueResolver {
//List<String> vreName = helper.evaluate("/Resource/Profile/Body/EndPoint[SCOPE='" +scopeFound.toString() + "']/VRE_NAME/text()"); //List<String> vreName = helper.evaluate("/Resource/Profile/Body/EndPoint[SCOPE='" +scopeFound.toString() + "']/VRE_NAME/text()");
if(fullScope.compareTo(scopeFound)==0){ if(fullScope.compareTo(scopeFound)==0){
logger.info("The full scope: " + fullScope + ", exists into "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+", skipping update VRE_NAME: "+VRE); logger.info("The full scope: " + fullScope + ", exists into "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+", skipping update VRE_NAME: "+VRE);
return; return false;
} }
} }
logger.info("The full scope: " + fullScope + ", does not exist into "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+", creating the new end point VRE_NAME: "+VRE+", fullScope: "+fullScope); logger.info("The full scope: " + fullScope + " does not exist into "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+", creating the new end point VRE_NAME: "+VRE+", fullScope: "+fullScope);
NodeList body = root.getElementsByTagName(ApplicationProfileReaderForCatalogueResolver.BODY); NodeList body = root.getElementsByTagName(ApplicationProfileReaderForCatalogueResolver.BODY);
if(body==null || body.getLength()==0) if(body==null || body.getLength()==0)
@ -81,7 +81,7 @@ public class UpdateApplicationProfileCatalogueResolver {
DOMSource source2 = new DOMSource(document); DOMSource source2 = new DOMSource(document);
transformer.transform(source2, result); transformer.transform(source2, result);
logger.trace("Updated resource: \n"+result.getWriter().toString()); logger.debug("Updated resource: \n"+result.getWriter().toString());
originalScope = ScopeProvider.instance.get(); originalScope = ScopeProvider.instance.get();
String discoveryScope = useRootScope?ScopeUtil.getInfrastructureNameFromScope(scopeToInstanceResolver):scopeToInstanceResolver; String discoveryScope = useRootScope?ScopeUtil.getInfrastructureNameFromScope(scopeToInstanceResolver):scopeToInstanceResolver;
@ -90,7 +90,8 @@ public class UpdateApplicationProfileCatalogueResolver {
ScopedPublisher rp=RegistryPublisherFactory.scopedPublisher(); ScopedPublisher rp=RegistryPublisherFactory.scopedPublisher();
Resource resource = toResource(result); Resource resource = toResource(result);
rp.update(resource); rp.update(resource);
logger.trace("Generic Resource updated on IS successfully"); logger.info("Application Profile: "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+" updated on IS successfully using scope: "+discoveryScope);
return true;
} }
catch (Exception e) { catch (Exception e) {
logger.error("Error ", e); logger.error("Error ", e);
@ -137,20 +138,24 @@ public class UpdateApplicationProfileCatalogueResolver {
newEndPoint.appendChild(newScope); newEndPoint.appendChild(newScope);
newEndPoint.appendChild(newVREName); newEndPoint.appendChild(newVREName);
logger.info("Adding the "+ApplicationProfileReaderForCatalogueResolver.END_POINT+":");
logger.info(ApplicationProfileReaderForCatalogueResolver.VRE_NAME +": "+VRE +" - "+ApplicationProfileReaderForCatalogueResolver.SCOPE +" "+fullScope);
document.getElementsByTagName(ApplicationProfileReaderForCatalogueResolver.BODY).item(0).appendChild(newEndPoint); document.getElementsByTagName(ApplicationProfileReaderForCatalogueResolver.BODY).item(0).appendChild(newEndPoint);
return document; return document;
} }
public static void main(String[] args) { // public static void main(String[] args) {
//
String scope = "/gcube"; // String scope = "/gcube";
try { // try {
UpdateApplicationProfileCatalogueResolver.validateEndPoint( // UpdateApplicationProfileCatalogueResolver.validateEndPoint(
scope, "gcube", "/gcube/devsec"); // scope, "gcube", "/gcube/devsec");
} // }
catch (Exception e) { // catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
} }