@Test public void testCreanupWOHwithoutPreservedFlavor() throws WorkflowOperationException, MediaPackageException { Map<String, String> wfInstConfig = new Hashtable<>(); wfInstConfig.put(CleanupWorkflowOperationHandler.DELETE_EXTERNAL, "true"); MediaPackageBuilder mpBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder(); MediaPackage mp = mpBuilder.createNew(); MediaPackageElement track1 = addElementToMediaPackage(mp, MediaPackageElement.Type.Track, "presenter", "source", null); track1.setURI(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX, WorkingFileRepository.COLLECTION_PATH_PREFIX, "asset", mp.getIdentifier().toString(), track1.getIdentifier(), "track.mp4")); cleanupWOH.start(createWorkflowInstance(wfInstConfig, mp), null); Assert.assertEquals("Media package shouldn't contain any elements", 0, mp.getElements().length); Assert.assertEquals("One file wasn't deleted on remote repository", 1, deletedFilesURIs.size()); }
@Override public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { cleanUpJobArgument(workflowInstance); MediaPackage mediaPackage = workflowInstance.getMediaPackage(); WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation(); String flavors = currentOperation.getConfiguration(PRESERVE_FLAVOR_PROPERTY); final List<MediaPackageElementFlavor> flavorsToPreserve = new ArrayList<MediaPackageElementFlavor>(); boolean deleteExternal = BooleanUtils.toBoolean(currentOperation.getConfiguration(DELETE_EXTERNAL)); String delayStr = currentOperation.getConfiguration(DELAY); int delay = 1; if (delayStr != null) { try { delay = Integer.parseInt(delayStr); } catch (NumberFormatException e) { logger.warn("Invalid value '{}' for delay in workflow operation configuration (should be integer)", delayStr); } } if (delay > 0) { try { logger.debug("Sleeping {}s before removing workflow files", delay); Thread.sleep(delay * 1000); } catch (InterruptedException e) { } } for (String flavor : asList(flavors)) flavorsToPreserve.add(MediaPackageElementFlavor.parseFlavor(flavor)); List<MediaPackageElement> elementsToRemove = new ArrayList<>(); for (MediaPackageElement element : mediaPackage.getElements()) { if (element.getURI() == null) continue; if (!isPreserved(element, flavorsToPreserve)) elementsToRemove.add(element); } List<String> externalBaseUrls = null; if (deleteExternal) { externalBaseUrls = getAllWorkingFileRepositoryUrls(); externalBaseUrls.remove(workspace.getBaseUri().toString()); } for (MediaPackageElement elementToRemove : elementsToRemove) { if (deleteExternal) { for (String repository : externalBaseUrls) { logger.debug("Removing {} from repository {}", elementToRemove.getURI(), repository); try { removeElementFromRepository(elementToRemove, repository); } catch (TrustedHttpClientException ex) { logger.debug("Removing media package element {} from repository {} failed: {}", elementToRemove.getURI(), repository, ex.getMessage()); } } } logger.debug("Removing {} from the workspace", elementToRemove.getURI()); try { mediaPackage.remove(elementToRemove); workspace.delete(elementToRemove.getURI()); } catch (NotFoundException ex) { logger.debug("Workspace doesn't contain element with Id '{}' from media package '{}': {}", elementToRemove.getIdentifier(), mediaPackage.getIdentifier().toString(), ex.getMessage()); } catch (IOException ex) { logger.warn("Unable to remove element with Id '{}' from the media package '{}': {}", elementToRemove.getIdentifier(), mediaPackage.getIdentifier().toString(), ex.getMessage()); } } return createResult(mediaPackage, Action.CONTINUE); }
CleanupWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { cleanUpJobArgument(workflowInstance); MediaPackage mediaPackage = workflowInstance.getMediaPackage(); WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation(); String flavors = currentOperation.getConfiguration(PRESERVE_FLAVOR_PROPERTY); final List<MediaPackageElementFlavor> flavorsToPreserve = new ArrayList<MediaPackageElementFlavor>(); boolean deleteExternal = BooleanUtils.toBoolean(currentOperation.getConfiguration(DELETE_EXTERNAL)); String delayStr = currentOperation.getConfiguration(DELAY); int delay = 1; if (delayStr != null) { try { delay = Integer.parseInt(delayStr); } catch (NumberFormatException e) { logger.warn("Invalid value '{}' for delay in workflow operation configuration (should be integer)", delayStr); } } if (delay > 0) { try { logger.debug("Sleeping {}s before removing workflow files", delay); Thread.sleep(delay * 1000); } catch (InterruptedException e) { } } for (String flavor : asList(flavors)) flavorsToPreserve.add(MediaPackageElementFlavor.parseFlavor(flavor)); List<MediaPackageElement> elementsToRemove = new ArrayList<>(); for (MediaPackageElement element : mediaPackage.getElements()) { if (element.getURI() == null) continue; if (!isPreserved(element, flavorsToPreserve)) elementsToRemove.add(element); } List<String> externalBaseUrls = null; if (deleteExternal) { externalBaseUrls = getAllWorkingFileRepositoryUrls(); externalBaseUrls.remove(workspace.getBaseUri().toString()); } for (MediaPackageElement elementToRemove : elementsToRemove) { if (deleteExternal) { for (String repository : externalBaseUrls) { logger.debug("Removing {} from repository {}", elementToRemove.getURI(), repository); try { removeElementFromRepository(elementToRemove, repository); } catch (TrustedHttpClientException ex) { logger.debug("Removing media package element {} from repository {} failed: {}", elementToRemove.getURI(), repository, ex.getMessage()); } } } logger.debug("Removing {} from the workspace", elementToRemove.getURI()); try { mediaPackage.remove(elementToRemove); workspace.delete(elementToRemove.getURI()); } catch (NotFoundException ex) { logger.debug("Workspace doesn't contain element with Id '{}' from media package '{}': {}", elementToRemove.getIdentifier(), mediaPackage.getIdentifier().toString(), ex.getMessage()); } catch (IOException ex) { logger.warn("Unable to remove element with Id '{}' from the media package '{}': {}", elementToRemove.getIdentifier(), mediaPackage.getIdentifier().toString(), ex.getMessage()); } } return createResult(mediaPackage, Action.CONTINUE); } }
CleanupWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { cleanUpJobArgument(workflowInstance); MediaPackage mediaPackage = workflowInstance.getMediaPackage(); WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation(); String flavors = currentOperation.getConfiguration(PRESERVE_FLAVOR_PROPERTY); final List<MediaPackageElementFlavor> flavorsToPreserve = new ArrayList<MediaPackageElementFlavor>(); boolean deleteExternal = BooleanUtils.toBoolean(currentOperation.getConfiguration(DELETE_EXTERNAL)); String delayStr = currentOperation.getConfiguration(DELAY); int delay = 1; if (delayStr != null) { try { delay = Integer.parseInt(delayStr); } catch (NumberFormatException e) { logger.warn("Invalid value '{}' for delay in workflow operation configuration (should be integer)", delayStr); } } if (delay > 0) { try { logger.debug("Sleeping {}s before removing workflow files", delay); Thread.sleep(delay * 1000); } catch (InterruptedException e) { } } for (String flavor : asList(flavors)) flavorsToPreserve.add(MediaPackageElementFlavor.parseFlavor(flavor)); List<MediaPackageElement> elementsToRemove = new ArrayList<>(); for (MediaPackageElement element : mediaPackage.getElements()) { if (element.getURI() == null) continue; if (!isPreserved(element, flavorsToPreserve)) elementsToRemove.add(element); } List<String> externalBaseUrls = null; if (deleteExternal) { externalBaseUrls = getAllWorkingFileRepositoryUrls(); externalBaseUrls.remove(workspace.getBaseUri().toString()); } for (MediaPackageElement elementToRemove : elementsToRemove) { if (deleteExternal) { for (String repository : externalBaseUrls) { logger.debug("Removing {} from repository {}", elementToRemove.getURI(), repository); try { removeElementFromRepository(elementToRemove, repository); } catch (TrustedHttpClientException ex) { logger.debug("Removing media package element {} from repository {} failed: {}", elementToRemove.getURI(), repository, ex.getMessage()); } } } logger.debug("Removing {} from the workspace", elementToRemove.getURI()); try { mediaPackage.remove(elementToRemove); workspace.delete(elementToRemove.getURI()); } catch (NotFoundException ex) { logger.debug("Workspace doesn't contain element with Id '{}' from media package '{}': {}", elementToRemove.getIdentifier(), mediaPackage.getIdentifier().toString(), ex.getMessage()); } catch (IOException ex) { logger.warn("Unable to remove element with Id '{}' from the media package '{}': {}", elementToRemove.getIdentifier(), mediaPackage.getIdentifier().toString(), ex.getMessage()); } } return createResult(mediaPackage, Action.CONTINUE); }  }
CleanupWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { cleanUpJobArgument(workflowInstance); MediaPackage mediaPackage = workflowInstance.getMediaPackage(); WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation(); String flavors = currentOperation.getConfiguration(PRESERVE_FLAVOR_PROPERTY); final List<MediaPackageElementFlavor> flavorsToPreserve = new ArrayList<MediaPackageElementFlavor>(); boolean deleteExternal = BooleanUtils.toBoolean(currentOperation.getConfiguration(DELETE_EXTERNAL)); String delayStr = currentOperation.getConfiguration(DELAY); int delay = 1; if (delayStr != null) { try { delay = Integer.parseInt(delayStr); } catch (NumberFormatException e) { logger.warn("Invalid value '{}' for delay in workflow operation configuration (should be integer)", delayStr); } } if (delay > 0) { try { logger.debug("Sleeping {}s before removing workflow files", delay); Thread.sleep(delay * 1000); } catch (InterruptedException e) { } } for (String flavor : asList(flavors)) flavorsToPreserve.add(MediaPackageElementFlavor.parseFlavor(flavor)); List<MediaPackageElement> elementsToRemove = new ArrayList<>(); for (MediaPackageElement element : mediaPackage.getElements()) { if (element.getURI() == null) continue; if (!isPreserved(element, flavorsToPreserve)) elementsToRemove.add(element); } List<String> externalBaseUrls = null; if (deleteExternal) { externalBaseUrls = getAllWorkingFileRepositoryUrls(); externalBaseUrls.remove(workspace.getBaseUri().toString()); } for (MediaPackageElement elementToRemove : elementsToRemove) { if (deleteExternal) { for (String repository : externalBaseUrls) { logger.debug("Removing {} from repository {}", elementToRemove.getURI(), repository); try { removeElementFromRepository(elementToRemove, repository); } catch (TrustedHttpClientException ex) { logger.debug("Removing media package element {} from repository {} failed: {}", elementToRemove.getURI(), repository, ex.getMessage()); } } } logger.debug("Removing {} from the workspace", elementToRemove.getURI()); try { mediaPackage.remove(elementToRemove); workspace.delete(elementToRemove.getURI()); } catch (NotFoundException ex) { logger.debug("Workspace doesn't contain element with Id '{}' from media package '{}': {}", elementToRemove.getIdentifier(), mediaPackage.getIdentifier().toString(), ex.getMessage()); } catch (IOException ex) { logger.warn("Unable to remove element with Id '{}' from the media package '{}': {}", elementToRemove.getIdentifier(), mediaPackage.getIdentifier().toString(), ex.getMessage()); } } return createResult(mediaPackage, Action.CONTINUE); }  void setWorkspace(Workspace workspace); void setTrustedHttpClient(TrustedHttpClient client); void cleanUpJobArgument(WorkflowInstance workflowInstance); @Override WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context); }
CleanupWorkflowOperationHandler extends AbstractWorkflowOperationHandler { @Override public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException { cleanUpJobArgument(workflowInstance); MediaPackage mediaPackage = workflowInstance.getMediaPackage(); WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation(); String flavors = currentOperation.getConfiguration(PRESERVE_FLAVOR_PROPERTY); final List<MediaPackageElementFlavor> flavorsToPreserve = new ArrayList<MediaPackageElementFlavor>(); boolean deleteExternal = BooleanUtils.toBoolean(currentOperation.getConfiguration(DELETE_EXTERNAL)); String delayStr = currentOperation.getConfiguration(DELAY); int delay = 1; if (delayStr != null) { try { delay = Integer.parseInt(delayStr); } catch (NumberFormatException e) { logger.warn("Invalid value '{}' for delay in workflow operation configuration (should be integer)", delayStr); } } if (delay > 0) { try { logger.debug("Sleeping {}s before removing workflow files", delay); Thread.sleep(delay * 1000); } catch (InterruptedException e) { } } for (String flavor : asList(flavors)) flavorsToPreserve.add(MediaPackageElementFlavor.parseFlavor(flavor)); List<MediaPackageElement> elementsToRemove = new ArrayList<>(); for (MediaPackageElement element : mediaPackage.getElements()) { if (element.getURI() == null) continue; if (!isPreserved(element, flavorsToPreserve)) elementsToRemove.add(element); } List<String> externalBaseUrls = null; if (deleteExternal) { externalBaseUrls = getAllWorkingFileRepositoryUrls(); externalBaseUrls.remove(workspace.getBaseUri().toString()); } for (MediaPackageElement elementToRemove : elementsToRemove) { if (deleteExternal) { for (String repository : externalBaseUrls) { logger.debug("Removing {} from repository {}", elementToRemove.getURI(), repository); try { removeElementFromRepository(elementToRemove, repository); } catch (TrustedHttpClientException ex) { logger.debug("Removing media package element {} from repository {} failed: {}", elementToRemove.getURI(), repository, ex.getMessage()); } } } logger.debug("Removing {} from the workspace", elementToRemove.getURI()); try { mediaPackage.remove(elementToRemove); workspace.delete(elementToRemove.getURI()); } catch (NotFoundException ex) { logger.debug("Workspace doesn't contain element with Id '{}' from media package '{}': {}", elementToRemove.getIdentifier(), mediaPackage.getIdentifier().toString(), ex.getMessage()); } catch (IOException ex) { logger.warn("Unable to remove element with Id '{}' from the media package '{}': {}", elementToRemove.getIdentifier(), mediaPackage.getIdentifier().toString(), ex.getMessage()); } } return createResult(mediaPackage, Action.CONTINUE); }  void setWorkspace(Workspace workspace); void setTrustedHttpClient(TrustedHttpClient client); void cleanUpJobArgument(WorkflowInstance workflowInstance); @Override WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context); static final String PRESERVE_FLAVOR_PROPERTY; static final String DELETE_EXTERNAL; static final String DELAY; }