all post update/create actions have been moved to a separate thread to speed up the answer

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@152494 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-08-04 13:16:36 +00:00
parent c35c19434c
commit 66e1a0e3a3
1 changed files with 39 additions and 29 deletions

View File

@ -429,7 +429,7 @@ public class CommonServiceUtils {
sourcesList.add(sourceSysType.toLowerCase()); sourcesList.add(sourceSysType.toLowerCase());
databaseSource += sourceSysType + " "; databaseSource += sourceSysType + " ";
} }
// create the Database Source information // create the Database Source information
customFields.put(Common.GRSF_DATABASE_SOURCE, Arrays.asList(databaseSource.trim())); customFields.put(Common.GRSF_DATABASE_SOURCE, Arrays.asList(databaseSource.trim()));
@ -508,10 +508,10 @@ public class CommonServiceUtils {
* @throws InterruptedException * @throws InterruptedException
*/ */
public static void actionsPostCreateOrUpdate( public static void actionsPostCreateOrUpdate(
String datasetId, String futureName, Common record, String apiKey, String username, String organization, String itemUrl, final String datasetId, final String futureName, final Common record, final String apiKey, final String username, final String organization, String itemUrl,
ResponseCreationBean responseBean, DataCatalogue catalogue, ResponseCreationBean responseBean, final DataCatalogue catalogue,
Map<String, String> namespaces, Set<String> groups, String context, Map<String, String> namespaces, final Set<String> groups, final String context,
String token, String futureTitle, String authorFullname, ServletContext contextServlet, boolean isUpdated, String description) throws InterruptedException { final String token, final String futureTitle, final String authorFullname, final ServletContext contextServlet, final boolean isUpdated, String description) throws InterruptedException {
// on create, we need to add the item url and set the description // on create, we need to add the item url and set the description
if(!isUpdated){ if(!isUpdated){
@ -531,31 +531,41 @@ public class CommonServiceUtils {
responseBean.setItemUrl(itemUrl); responseBean.setItemUrl(itemUrl);
responseBean.setKbUuid(record.getUuid()); responseBean.setKbUuid(record.getUuid());
// manage groups (wait thread to die: ckan doesn't support too much concurrency on same record ...) // it is needed...
if(!groups.isEmpty()){ final String itemUrlForThread = itemUrl;
logger.info("Launching thread for association to the list of groups " + groups);
AssociationToGroupThread threadGroups = new AssociationToGroupThread(new ArrayList<String>(groups), datasetId, organization, username, catalogue, apiKey);
threadGroups.start();
logger.debug("Waiting association thread to die..");
threadGroups.join();
logger.debug("Ok, it died");
}
// manage time series as resources new Thread(new Runnable() {
logger.info("Launching thread for time series handling");
new ManageTimeSeriesThread(record, futureName, username, catalogue, context, token).start();
// write a post if the product has been published in grsf context @Override
if(!isUpdated && context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY))){ public void run() {
new WritePostCatalogueManagerThread( try {
context, // manage groups (wait thread to die: ckan doesn't support too much concurrency on same record ...)
token, if(!groups.isEmpty()){
futureTitle, logger.info("Launching thread for association to the list of groups " + groups);
itemUrl, AssociationToGroupThread threadGroups = new AssociationToGroupThread(new ArrayList<String>(groups), datasetId, organization, username, catalogue, apiKey);
false, threadGroups.start();
new ArrayList<String>(), threadGroups.join();
authorFullname).start(); }
logger.info("Thread to write a post about the new product has been launched"); // manage time series as resources
} logger.info("Launching thread for time series handling");
new ManageTimeSeriesThread(record, futureName, username, catalogue, context, token).start();
// write a post if the product has been published in grsf context
if(!isUpdated && context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY))){
new WritePostCatalogueManagerThread(
context,
token,
futureTitle,
itemUrlForThread,
false,
new ArrayList<String>(),
authorFullname).start();
logger.info("Thread to write a post about the new product has been launched");
}
}catch (InterruptedException e) {
logger.error("Error", e);
}
}
}).start();
} }
} }