private PayloadGroup onboardNextPayloadGroup( Workspace workspace, PayloadGroup currentPayloadGroup) throws PersistenceException { PayloadGroup nextPayloadGroup = currentPayloadGroup.getNextPayloadGroup(); workspace.removeActivePayloadGroup(currentPayloadGroup); if (nextPayloadGroup != null) { workspace.addActivePayloadGroup(nextPayloadGroup); } return nextPayloadGroup; }
private List<Payload> onboardNextPayloads(Workspace workspace, PayloadGroup payloadGroup) throws PersistenceException { if (payloadGroup == null) { return ListUtils.EMPTY_LIST; } List<Payload> payloads = payloadGroup.getPayloads(); if (payloads.size() > 0) { workspace.addActivePayloads(payloads); } return payloads; }
@Override public void forceTerminate(Workspace workspace, Payload payload) throws PersistenceException { workspace.setStatus(Status.FORCE_TERMINATED); }
public void run() { ResourceResolver resourceResolver = null; Resource configResource; long start = System.currentTimeMillis(); int total = 0; boolean stopped = false; try { resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null); configResource = resourceResolver.getResource(configPath); final Config config = configResource.adaptTo(Config.class); final Workspace workspace = config.getWorkspace(); if (workspace.isStopped()) { return; } try { SyntheticWorkflowModel model = syntheticWorkflowRunner.getSyntheticWorkflowModel( resourceResolver, config.getWorkflowModelId(), true); resourceResolver .adaptTo(Session.class) .getWorkspace() .getObservationManager() .setUserData("changedByWorkflowProcess"); PayloadGroup payloadGroup = null; if (workspace.getActivePayloadGroups().size() > 0) { payloadGroup = workspace.getActivePayloadGroups().get(0); } while (payloadGroup != null) { List<Payload> payloads = workspace.getActivePayloads(); if (payloads.size() == 0) { // payloads size is 0, so onboard next payload group payloadGroup = onboardNextPayloadGroup(workspace, payloadGroup); if (payloadGroup != null) { payloads = onboardNextPayloads(workspace, payloadGroup); } } // Safety check; if payloads comes in null then immediately break from loop as there is // no work to do if (payloads == null || payloads.size() == 0) { break; } for (Payload payload : payloads) { if (workspace.isStopping() || workspace.isStopped()) { stop(workspace); stopped = true; break; } try { if (config.isAutoThrottle()) { // Wait before starting more work throttledTaskRunner.waitForLowCpuAndLowMemory(); } long processStart = System.currentTimeMillis(); swr.execute(resourceResolver, payload.getPayloadPath(), model, false, false); complete(workspace, payload); log.info( "Processed [ {} ] in {} ms", payload.getPayloadPath(), System.currentTimeMillis() - processStart); } catch (WorkflowException e) { fail(workspace, payload); log.warn("Synthetic Workflow could not process [ {} ]", payload.getPath(), e); } catch (Exception e) { // Complete call failed; consider it failed log.warn("Complete call on [ {} ] failed", payload.getPath(), e); fail(workspace, payload); } total++; } // end for workspace.commit(); if (stopped) { log.info("Bulk Synthetic Workflow run has been stopped."); break; } } // end while // Stop check in case a STOP request is made that breaks the while loop if (!stopped) { complete(workspace); } log.info( "Grand total of [ {} ] payloads saved in {} ms", total, System.currentTimeMillis() - start); } catch (Exception e) { log.error("Error processing Bulk Synthetic Workflow execution.", e); } } catch (LoginException e) { log.error("Error processing Bulk Synthetic Workflow execution.", e); } finally { if (resourceResolver != null) { resourceResolver.close(); } } }