Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 67 additions & 83 deletions src/main/java/uk/gov/hmcts/reform/preapi/media/MediaKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -429,7 +435,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));
Expand Down Expand Up @@ -465,11 +471,7 @@ private String refreshStreamingLocatorForUser(String userId, String assetName) {
.atTime(LocalTime.MAX)
.atZone(now.getOffset())
.toInstant()
))
.build())
.build()
);

)).build()).build());
return streamingLocatorName;
}

Expand Down Expand Up @@ -498,12 +500,9 @@ private void assertStreamingPolicyExists(String defaultContentKeyPolicy) {
new StreamingPolicyContentKeys()
.withDefaultKey(new DefaultKey()
.withLabel("ContentKey_AES")
.withPolicyName(defaultContentKeyPolicy)))
)
.build()
)
.build()
);
.withPolicyName(defaultContentKeyPolicy))))
.build())
.build());
}
}

Expand Down Expand Up @@ -559,12 +558,9 @@ private void assertTransformExists(String transformName) {
MkTransformOutput.builder()
.relativePriority(MkTransformOutput.MkTransformPriority.Normal)
.preset(getMkBuiltInPreset(transformName))
.build()
))
.build()
)
.build()
);
.build()))
.build())
.build());
}
}

Expand Down Expand Up @@ -621,7 +617,7 @@ private String runEncodeTransform(String inputAssetName,
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;
Expand All @@ -633,17 +629,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) {
Expand Down Expand Up @@ -675,8 +668,7 @@ private void createAsset(String assetName,
.storageAccountName(isFinal ? finalStorageAccount : ingestStorageAccount)
.description(description)
.build())
.build()
);
.build());
} catch (ConflictException e) {
throw new ConflictException("Asset: " + assetName);
}
Expand All @@ -688,54 +680,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...");
}
Expand Down Expand Up @@ -795,8 +781,7 @@ private MkStreamingEndpoint assertStreamingEndpointExists(String endpointName) t
MkStreamingEndpointSku
.builder()
.name(Tier.Standard)
.build()
)
.build())
.build())
.build());
mediaKindClient.startStreamingEndpoint(endpointName);
Expand Down Expand Up @@ -830,8 +815,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) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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
Expand Down