diff --git a/src/main/java/uk/gov/hmcts/reform/preapi/media/MediaKind.java b/src/main/java/uk/gov/hmcts/reform/preapi/media/MediaKind.java index a73cc9cdd0..e1a2ed8ee1 100644 --- a/src/main/java/uk/gov/hmcts/reform/preapi/media/MediaKind.java +++ b/src/main/java/uk/gov/hmcts/reform/preapi/media/MediaKind.java @@ -93,6 +93,8 @@ public class MediaKind implements IMediaService { private final String issuer; private final String symmetricKey; protected boolean enableStreamingLocatorOnStart; + private final int jobPollingInterval; + private final int streamingEndpointPollingInterval; private final MediaKindClient mediaKindClient; private final AzureIngestStorageService azureIngestStorageService; @@ -119,6 +121,8 @@ public MediaKind( @Value("${mediakind.issuer:}") String issuer, @Value("${mediakind.symmetricKey:}") String symmetricKey, @Value("${mediakind.streaming-locator-on-start:false}") Boolean enableStreamingLocatorOnStart, + @Value("${mediakind.job-poll-interval}") int jobPollingInterval, + @Value("${mediakind.streaming-endpoint-polling-interval}") int streamingEndpointPollingInterval, MediaKindClient mediaKindClient, AzureIngestStorageService azureIngestStorageService, AzureFinalStorageService azureFinalStorageService @@ -129,6 +133,8 @@ public MediaKind( this.subscription = subscription; this.issuer = issuer; this.symmetricKey = symmetricKey; + this.jobPollingInterval = jobPollingInterval; + this.streamingEndpointPollingInterval = streamingEndpointPollingInterval; this.mediaKindClient = mediaKindClient; this.azureIngestStorageService = azureIngestStorageService; this.azureFinalStorageService = azureFinalStorageService; @@ -458,11 +464,7 @@ private String refreshStreamingLocatorForUser(String userId, String assetName) { .atTime(LocalTime.MAX) .atZone(now.getOffset()) .toInstant() - )) - .build()) - .build() - ); - + )).build()).build()); return streamingLocatorName; } @@ -491,12 +493,9 @@ private void assertStreamingPolicyExists(String defaultContentKeyPolicy) { new StreamingPolicyContentKeys() .withDefaultKey(new DefaultKey() .withLabel("ContentKey_AES") - .withPolicyName(defaultContentKeyPolicy))) - ) - .build() - ) - .build() - ); + .withPolicyName(defaultContentKeyPolicy)))) + .build()) + .build()); } } @@ -552,12 +551,9 @@ private void assertTransformExists(String transformName) { MkTransformOutput.builder() .relativePriority(MkTransformOutput.MkTransformPriority.Normal) .preset(getMkBuiltInPreset(transformName)) - .build() - )) - .build() - ) - .build() - ); + .build())) + .build()) + .build()); } } @@ -616,7 +612,7 @@ private JobState waitEncodeComplete(String jobName, String transformName) throws MkJob job = null; do { if (job != null) { - TimeUnit.MILLISECONDS.sleep(10000); + TimeUnit.MILLISECONDS.sleep(jobPollingInterval); } job = mediaKindClient.getJob(transformName, jobName); } while (!hasJobCompleted(job)); @@ -626,7 +622,7 @@ private JobState waitEncodeComplete(String jobName, String transformName) throws private MkStreamingEndpoint checkStreamingEndpointReady(MkStreamingEndpoint endpoint) throws InterruptedException { var endpointName = endpoint.getName(); while (endpoint.getProperties().getResourceState() != MkStreamingEndpointProperties.ResourceState.Running) { - TimeUnit.MILLISECONDS.sleep(2000); // wait 2 seconds + TimeUnit.MILLISECONDS.sleep(streamingEndpointPollingInterval); // wait 2 seconds endpoint = mediaKindClient.getStreamingEndpointByName(endpointName); } return endpoint; @@ -638,17 +634,14 @@ private void createLiveOutput(String liveEventName, String liveOutputName) { liveEventName, liveOutputName, MkLiveOutput.builder() - .properties(MkLiveOutput.MkLiveOutputProperties.builder() - .description( - "Live output for: " + liveEventName - ) - .assetName(liveEventName) - .archiveWindowLength("PT8H") - .hls(new Hls().withFragmentsPerTsSegment(5)) - .manifestName(liveEventName) - .build()) - .build() - ); + .properties(MkLiveOutput.MkLiveOutputProperties.builder() + .description("Live output for: " + liveEventName) + .assetName(liveEventName) + .archiveWindowLength("PT8H") + .hls(new Hls().withFragmentsPerTsSegment(5)) + .manifestName(liveEventName) + .build()) + .build()); } catch (ConflictException e) { throw new ConflictException("Live Output: " + liveOutputName); } catch (NotFoundException e) { @@ -680,8 +673,7 @@ private void createAsset(String assetName, .storageAccountName(isFinal ? finalStorageAccount : ingestStorageAccount) .description(description) .build()) - .build() - ); + .build()); } catch (ConflictException e) { throw new ConflictException("Asset: " + assetName); } @@ -693,54 +685,48 @@ private void createLiveEvent(CaptureSessionDTO captureSession) { mediaKindClient.putLiveEvent( getSanitisedLiveEventId(captureSession.getId()), MkLiveEvent.builder() - .location(LOCATION) - .tags(Map.of( - "environment", environmentTag, - "application", "pre-recorded evidence", - "businessArea", "cross-cutting", - "builtFrom", "pre-api" - )) - .properties(MkLiveEventProperties.builder() - .encoding(new LiveEventEncoding() - .withEncodingType(LiveEventEncodingType.PASSTHROUGH_BASIC) - ) - .description(captureSession.getBookingId().toString()) - .useStaticHostname(true) - .input(MkLiveEventProperties.MkLiveEventInput.builder() - .streamingProtocol(MkLiveEventProperties.StreamingProtocol.RTMPS) - .keyFrameIntervalDuration("PT6S") - .accessToken(accessToken.toString()) - .accessControl( - new LiveEventInputAccessControl() - .withIp(new IpAccessControl() - .withAllow( - List.of(new IpRange() - .withName("AllowAll") - .withAddress("0.0.0.0") - .withSubnetPrefixLength(0) - ) - ) - ) - ) - .build() - ) - .preview(new LiveEventPreview() - .withAccessControl( - new LiveEventPreviewAccessControl() - .withIp(new IpAccessControl() - .withAllow( - List.of(new IpRange() - .withName("AllowAll") - .withAddress("0.0.0.0") - .withSubnetPrefixLength(0) - ) - ) - ) - ) - ) + .location(LOCATION) + .tags(Map.of( + "environment", environmentTag, + "application", "pre-recorded evidence", + "businessArea", "cross-cutting", + "builtFrom", "pre-api" + )) + .properties( + MkLiveEventProperties.builder() + .encoding(new LiveEventEncoding().withEncodingType(LiveEventEncodingType.PASSTHROUGH_BASIC)) + .description(captureSession.getBookingId().toString()) + .useStaticHostname(true) + .input( + MkLiveEventProperties.MkLiveEventInput.builder() + .streamingProtocol(MkLiveEventProperties.StreamingProtocol.RTMPS) + .keyFrameIntervalDuration("PT6S") + .accessToken(accessToken.toString()) + .accessControl( + new LiveEventInputAccessControl() + .withIp( + new IpAccessControl() + .withAllow( + List.of( + new IpRange() + .withName("AllowAll") + .withAddress("0.0.0.0") + .withSubnetPrefixLength(0))))) + .build()) + .preview( + new LiveEventPreview() + .withAccessControl( + new LiveEventPreviewAccessControl() + .withIp( + new IpAccessControl() + .withAllow( + List.of( + new IpRange() + .withName("AllowAll") + .withAddress("0.0.0.0") + .withSubnetPrefixLength(0)))))) .build()) - .build() - ); + .build()); } catch (ConflictException e) { log.info("Live Event already exists. Continuing..."); } @@ -800,8 +786,7 @@ private MkStreamingEndpoint assertStreamingEndpointExists(String endpointName) t MkStreamingEndpointSku .builder() .name(Tier.Standard) - .build() - ) + .build()) .build()) .build()); mediaKindClient.startStreamingEndpoint(endpointName); @@ -835,8 +820,7 @@ private void createStreamingLocator(String sanitisedLiveEventId) { .streamingLocatorId(sanitisedLiveEventId) .streamingPolicyName(STREAMING_POLICY_CLEAR_STREAMING_ONLY) .build()) - .build() - ); + .build()); } catch (ConflictException e) { log.info("Streaming locator already exists"); } catch (Exception e) { diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index dee8bfa51e..17b89de998 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -85,6 +85,8 @@ mediakind: issuer: ${ISSUER:https://sts.windows.net/531ff96d-0ae9-462a-8d2d-bec7c0b42082/} symmetricKey: ${SYMMETRIC_KEY:} streaming-locator-on-start: ${ENABLE_STREAMING_LOCATOR_ON_START:false} + job-poll-interval: 10000 + streaming-endpoint-polling-interval: 2000 media-service: ${MEDIA_SERVICE:MediaKind} diff --git a/src/test/java/uk/gov/hmcts/reform/preapi/media/MediaKindTest.java b/src/test/java/uk/gov/hmcts/reform/preapi/media/MediaKindTest.java index d13ab99241..5f9dc3f792 100644 --- a/src/test/java/uk/gov/hmcts/reform/preapi/media/MediaKindTest.java +++ b/src/test/java/uk/gov/hmcts/reform/preapi/media/MediaKindTest.java @@ -71,6 +71,8 @@ "mediakind.issuer=testIssuer", "mediakind.symmetricKey=testSymmetricKey", "mediakind.streaming-locator-on-start=true", + "mediakind.job-poll-interval=10", + "mediakind.streaming-endpoint-polling-interval=10" }) public class MediaKindTest { @MockitoBean