GetUrlTaskRunner extends BaseStreamingTaskRunner { public String performTask(String taskParameters) { GetUrlTaskParameters taskParams = GetUrlTaskParameters.deserialize(taskParameters); String spaceId = taskParams.getSpaceId(); String contentId = taskParams.getContentId(); String resourcePrefix = taskParams.getResourcePrefix(); log.info("Performing " + TASK_NAME + " task with parameters: spaceId=" + spaceId + ", contentId=" + contentId + ", resourcePrefix=" + resourcePrefix); String bucketName = unwrappedS3Provider.getBucketName(spaceId); GetUrlTaskResult taskResult = new GetUrlTaskResult(); checkThatStreamingServiceIsEnabled(spaceId, TASK_NAME); StreamingDistributionSummary existingDist = getExistingDistribution(bucketName); if (null == existingDist) { throw new UnsupportedTaskException(TASK_NAME, "The " + TASK_NAME + " task can only be used after a space has " + "been configured to enable open streaming. Use " + StorageTaskConstants.ENABLE_STREAMING_TASK_NAME + " to enable open streaming on this space."); } String domainName = existingDist.getDomainName(); if (!existingDist.getTrustedSigners().getItems().isEmpty()) { throw new UnsupportedTaskException(TASK_NAME, "The " + TASK_NAME + " task cannot be used to request a stream " + "from a secure distribution. Use " + StorageTaskConstants.GET_SIGNED_URL_TASK_NAME + " instead."); } String resourceId = contentId; if (null != resourcePrefix && !resourcePrefix.equals("")) { resourceId = resourcePrefix + contentId; } taskResult.setStreamUrl("rtmp: String toReturn = taskResult.serialize(); log.info("Result of " + TASK_NAME + " task: " + toReturn); return toReturn; } GetUrlTaskRunner(StorageProvider s3Provider,
                            S3StorageProvider unwrappedS3Provider,
                            AmazonCloudFrontClient cfClient); String getName(); String performTask(String taskParameters);  }
@Test public void testPerformTask1() throws Exception { BaseStreamingTaskRunner runner = createRunner(createMockStorageProvider(), createMockUnwrappedS3StorageProvider(), createMockS3ClientV1(), createMockCFClientV4(false)); try { runner.performTask(null); fail("Exception expected"); } catch (Exception expected) { assertNotNull(expected); } GetUrlTaskParameters taskParams = new GetUrlTaskParameters(); taskParams.setSpaceId(spaceId); taskParams.setContentId(contentId); String results = runner.performTask(taskParams.serialize()); String streamUrl = GetUrlTaskResult.deserialize(results).getStreamUrl(); assertEquals(streamUrl, "rtmp: }
@Test public void testPerformTask2() throws Exception { BaseStreamingTaskRunner runner = createRunner(createMockStorageProvider(), createMockUnwrappedS3StorageProvider(), createMockS3ClientV1(), createMockCFClientV3()); GetUrlTaskParameters taskParams = new GetUrlTaskParameters(); taskParams.setSpaceId(spaceId); taskParams.setContentId(contentId); try { runner.performTask(taskParams.serialize()); fail("Exception expected"); } catch (UnsupportedTaskException e) { assertTrue(e.getMessage() .contains(StorageTaskConstants.ENABLE_STREAMING_TASK_NAME)); } }
@Test public void testPerformTask3() throws Exception { BaseStreamingTaskRunner runner = createRunner(createMockStorageProvider(), createMockUnwrappedS3StorageProvider(), createMockS3ClientV1(), createMockCFClientV4(true)); GetUrlTaskParameters taskParams = new GetUrlTaskParameters(); taskParams.setSpaceId(spaceId); taskParams.setContentId(contentId); try { runner.performTask(taskParams.serialize()); fail("Exception expected"); } catch (UnsupportedTaskException e) { assertTrue(e.getMessage() .contains(StorageTaskConstants.GET_SIGNED_URL_TASK_NAME)); } }
@Test public void testPerformTask4() throws Exception { BaseStreamingTaskRunner runner = createRunner(createMockStorageProvider(new HashMap<String, String>(), true), createMockUnwrappedS3StorageProvider(), createMockS3ClientV1(), createMockCFClientV1()); GetUrlTaskParameters taskParams = new GetUrlTaskParameters(); taskParams.setSpaceId(spaceId); taskParams.setContentId(contentId); try { runner.performTask(taskParams.serialize()); fail("Exception expected"); } catch (UnsupportedTaskException e) { assertTrue(e.getMessage() .contains(StorageTaskConstants.ENABLE_STREAMING_TASK_NAME)); } }