fixed a problem with wf confs

This commit is contained in:
Michele Artini 2024-01-16 09:39:13 +01:00
parent aba43e4429
commit 188bd79906
4 changed files with 32 additions and 27 deletions

View File

@ -112,11 +112,11 @@ public class ApiController extends DnetRestController {
throws Exception {
final WfConfiguration conf = this.wfManagerService.findWorkflowConfiguration(id);
if (overrideStartWfs.length > 0) {
conf.setWorkflows(Arrays.asList(overrideStartWfs));
}
final String family = WfConfigurationUtils.calculateFamily(conf, false);
this.wfManagerService.prepareNewJob(conf, false);
final String[] wfTemplateIds = overrideStartWfs.length > 0 ? overrideStartWfs : conf.getWorkflows().toArray(new String[conf.getWorkflows().size()]);
this.wfManagerService.prepareNewJob(conf, family, wfTemplateIds);
if (StringUtils.isNotBlank(conf.getApiId())) { return this.wfManagerService.recentHistoryForApiId(conf.getApiId()); }
if (StringUtils.isNotBlank(conf.getDsId())) { return this.wfManagerService.recentHistoryForDsId(conf.getDsId()); }
@ -129,7 +129,9 @@ public class ApiController extends DnetRestController {
public List<WfJournalEntry> destroyWorkflowConfiguration(@PathVariable final String id) throws Exception {
final WfConfiguration conf = this.wfManagerService.findWorkflowConfiguration(id);
this.wfManagerService.prepareNewJob(conf, true);
final String family = WfConfigurationUtils.calculateFamily(conf, true);
this.wfManagerService.prepareNewJob(conf, family, conf.getDestroyWf());
if (StringUtils.isNotBlank(conf.getApiId())) { return this.wfManagerService.recentHistoryForApiId(conf.getApiId()); }
if (StringUtils.isNotBlank(conf.getDsId())) { return this.wfManagerService.recentHistoryForDsId(conf.getDsId()); }

View File

@ -17,6 +17,7 @@ import eu.dnetlib.domain.wfs.jobs.JobStatus;
import eu.dnetlib.domain.wfs.jobs.WfJournalEntry;
import eu.dnetlib.wfs.repository.WfConfigurationRepository;
import eu.dnetlib.wfs.repository.WfJournalEntryRepository;
import eu.dnetlib.wfs.utils.WfConfigurationUtils;
@Service
public class ScheduledWorkflowLauncher {
@ -48,7 +49,9 @@ public class ScheduledWorkflowLauncher {
.filter(this::isReady)
.forEach(conf -> {
try {
this.workflowManagerService.prepareNewJob(conf, false);
final String family = WfConfigurationUtils.calculateFamily(conf, false);
final String[] wfTemplateIds = conf.getWorkflows().toArray(new String[conf.getWorkflows().size()]);
this.workflowManagerService.prepareNewJob(conf, family, wfTemplateIds);
} catch (final Exception e) {
log.error("Error launching scheduled wf conf: " + conf.getId(), e);
}

View File

@ -12,6 +12,8 @@ import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.data.domain.PageRequest;
@ -49,6 +51,8 @@ public class WorkflowManagerService {
private static final int MAX_HISTORY_SIZE = 50;
private static final Log log = LogFactory.getLog(WorkflowManagerService.class);
@Autowired
private WfJournalEntryRepository wfJournalEntryRepository;
@ -102,6 +106,7 @@ public class WorkflowManagerService {
.toList();
conf.setConfigured(WfConfigurationUtils.isConfigured(wfTemplates, conf));
log.debug("Saving wf conf " + conf.getId());
return this.wfConfigurationRepository.save(conf);
}
@ -140,37 +145,18 @@ public class WorkflowManagerService {
this.wfSubscriptionRepository.saveAll(subscriptions);
}
public WfRunningJob prepareNewJob(final WfConfiguration conf, final boolean destroy) throws WorkflowManagerException {
public WfRunningJob prepareNewJob(final WfConfiguration conf, final String family, final String... wfTemplateIds) throws WorkflowManagerException {
final String wfConfId = conf.getId();
final String name = conf.getName();
final String family;
if (destroy) {
if (StringUtils.isNotBlank(conf.getDsId())) {
family = WorkflowsConstants.REPO_BYE_FAMILY;
} else {
family = WorkflowsConstants.GENERIC_DESTROY_WF_FAMILY;
}
} else if (StringUtils.isBlank(conf.getSection())) {
if (StringUtils.isNotBlank(conf.getDsId())) {
family = WorkflowsConstants.AGGREGATION_FAMILY;
} else {
family = WorkflowsConstants.UNKNOWN_FAMILY;
}
} else {
family = conf.getSection();
}
final String dsId = conf.getDsId();
final String dsName = conf.getDsName();
final String apiId = conf.getApiId();
final SimpleResourceClient client = this.clientFactory.getClient(SimpleResourceClient.class);
final List<ImmutablePair<String, WfTemplate>> wfTemplates = (destroy ? Arrays.asList(conf.getDestroyWf()) : conf.getWorkflows())
.stream()
final List<ImmutablePair<String, WfTemplate>> wfTemplates = Arrays.stream(wfTemplateIds)
.map(wf -> new ImmutablePair<>(wf, client.findResourceContent(WorkflowsConstants.WF_TEMPLATE, wf, WfTemplate.class)))
.toList();

View File

@ -124,4 +124,18 @@ public class WfConfigurationUtils {
return res;
}
public static String calculateFamily(final WfConfiguration conf, final boolean destroy) {
if (destroy) {
if (StringUtils.isNotBlank(conf.getDsId())) { return WorkflowsConstants.REPO_BYE_FAMILY; }
return WorkflowsConstants.GENERIC_DESTROY_WF_FAMILY;
}
if (!StringUtils.isBlank(conf.getSection())) { return conf.getSection(); }
if (StringUtils.isNotBlank(conf.getDsId())) { return WorkflowsConstants.AGGREGATION_FAMILY; }
return WorkflowsConstants.UNKNOWN_FAMILY;
}
}