use of com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class EdgeConnectorForKVSServiceTest method test_initMQTTSubscription_onError.
@Test
public void test_initMQTTSubscription_onError(@TempDir Path tempDir) throws IOException, InterruptedException {
// when
List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = EdgeConnectorForKVSConfiguration.builder().kinesisVideoStreamName(MOCK_KINESIS_VIDEO_STREAM_NAME).captureStartTime(START_TIME_NEVER).liveStreamingStartTime(START_TIME_NEVER).videoUploadRequestMqttTopic(VIDEO_UPLOAD_REQUEST_MQTT_TOPIC).videoRecordFolderPath(tempDir).recordingRequestsCount(0).liveStreamingRequestsCount(0).build();
edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration);
// Mock for initConfiguration
when(siteWiseManager.initEdgeConnectorForKVSServiceConfiguration(any())).thenReturn(edgeConnectorForKVSConfigurationList);
// Mock for initSecretsManager
when(secretsClient.getSecretValue(any())).thenReturn(gson.toJson(secretMap));
doAnswer(invocationOnMock -> {
VideoUploadRequestEvent event = invocationOnMock.getArgument(1);
event.onError("Test Error");
return null;
}).when(videoUploadRequestHandler).subscribeToMqttTopic(any(), any());
// then
edgeConnectorForKVSService.setUpSharedEdgeConnectorForKVSService();
edgeConnectorForKVSService.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
Thread.sleep(3000);
assertEquals(0, edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount());
assertEquals(0, edgeConnectorForKVSConfiguration.getRecordingRequestsCount());
}
use of com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class EdgeConnectorForKVSServiceTest method test_initMQTTSubscription_onStartHistorical.
@Test
public void test_initMQTTSubscription_onStartHistorical(@TempDir Path tempDir) throws IOException, InterruptedException {
// when
List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = EdgeConnectorForKVSConfiguration.builder().kinesisVideoStreamName(MOCK_KINESIS_VIDEO_STREAM_NAME).captureStartTime(START_TIME_NEVER).liveStreamingStartTime(START_TIME_NEVER).videoUploadRequestMqttTopic(VIDEO_UPLOAD_REQUEST_MQTT_TOPIC).videoRecordFolderPath(tempDir).recordingRequestsCount(0).liveStreamingRequestsCount(0).build();
edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration);
// Mock for initConfiguration
when(siteWiseManager.initEdgeConnectorForKVSServiceConfiguration(any())).thenReturn(edgeConnectorForKVSConfigurationList);
// Mock for initSecretsManager
when(secretsClient.getSecretValue(any())).thenReturn(gson.toJson(secretMap));
doAnswer(invocationOnMock -> {
VideoUploadRequestEvent event = invocationOnMock.getArgument(1);
event.onStart(IS_LIVE_FALSE, EVENT_TIMESTAMP, START_TIME, END_TIME);
return null;
}).when(videoUploadRequestHandler).subscribeToMqttTopic(any(), any());
// then
edgeConnectorForKVSService.setUpSharedEdgeConnectorForKVSService();
edgeConnectorForKVSService.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
Thread.sleep(3000);
assertEquals(0, edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount());
assertEquals(0, edgeConnectorForKVSConfiguration.getRecordingRequestsCount());
}
use of com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class EdgeConnectorForKVSService method initMQTTSubscription.
private void initMQTTSubscription(EdgeConnectorForKVSConfiguration configuration) {
VideoUploadRequestEvent event = new VideoUploadRequestEvent() {
@Override
public void onStart(boolean isLive, long updateTimestamp, long startTime, long endTime) {
if (isLive) {
log.info("Received Live Streaming request for stream: " + configuration.getKinesisVideoStreamName());
ScheduledFuture<?> future = configuration.getStopLiveStreamingTaskFuture();
if (future == null) {
// Kick-off Live Streaming for 5 mins
// do it only for the first request
log.info("Start Live Streaming");
liveStreamingExecutor.submit(() -> {
try {
startLiveVideoStreaming(configuration);
} catch (Exception ex) {
log.error("Error starting live video streaming." + ex.getMessage());
configuration.getFatalStatus().set(true);
}
});
} else {
log.info("Live Streaming was already started. Continue Streaming.");
// Cancel the previously started scheduled task
// and restart the task below
future.cancel(false);
}
Runnable task = getStopLiveStreamingTask(configuration);
future = stopLiveStreamingExecutor.schedule(task, LIVE_STREAMING_STOP_TIMER_DELAY_IN_SECONDS, TimeUnit.SECONDS);
configuration.setStopLiveStreamingTaskFuture(future);
log.info("Schedule Live Streaming to stop after " + LIVE_STREAMING_STOP_TIMER_DELAY_IN_SECONDS + "s for stream: " + configuration.getKinesisVideoStreamName());
} else {
try {
startHistoricalVideoUploading(configuration, startTime, endTime);
} catch (Exception ex) {
log.error("Error starting historical video uploading." + ex.getMessage());
configuration.getFatalStatus().set(true);
}
}
}
@Override
public void onError(String errMessage) {
log.info("MQTT Error " + errMessage + " for stream " + configuration.getKinesisVideoStreamName());
}
};
if (configuration.getVideoUploadRequestMqttTopic() != null) {
videoUploadRequestHandler.subscribeToMqttTopic(configuration.getVideoUploadRequestMqttTopic(), event);
}
}
use of com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class EdgeConnectorForKVSServiceTest method test_initMQTTSubscription_onStartLive.
@Test
public void test_initMQTTSubscription_onStartLive(@TempDir Path tempDir) throws IOException, InterruptedException {
// when
List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = EdgeConnectorForKVSConfiguration.builder().kinesisVideoStreamName(MOCK_KINESIS_VIDEO_STREAM_NAME).captureStartTime(START_TIME_NEVER).liveStreamingStartTime(START_TIME_NEVER).videoUploadRequestMqttTopic(VIDEO_UPLOAD_REQUEST_MQTT_TOPIC).videoRecordFolderPath(tempDir).recordingRequestsCount(0).liveStreamingRequestsCount(0).build();
edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration);
// Mock for initConfiguration
when(siteWiseManager.initEdgeConnectorForKVSServiceConfiguration(any())).thenReturn(edgeConnectorForKVSConfigurationList);
// Mock for initSecretsManager
when(secretsClient.getSecretValue(any())).thenReturn(gson.toJson(secretMap));
doAnswer(invocationOnMock -> {
VideoUploadRequestEvent event = invocationOnMock.getArgument(1);
event.onStart(IS_LIVE_TRUE, EVENT_TIMESTAMP, START_TIME, END_TIME);
return null;
}).when(videoUploadRequestHandler).subscribeToMqttTopic(any(), any());
// then
edgeConnectorForKVSService.setUpSharedEdgeConnectorForKVSService();
edgeConnectorForKVSService.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
Thread.sleep(3000);
assertEquals(1, edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount());
assertEquals(1, edgeConnectorForKVSConfiguration.getRecordingRequestsCount());
}
use of com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class EdgeConnectorForKVSServiceTest method test_cleanUp_singleCamera_happyCase.
@Test
public void test_cleanUp_singleCamera_happyCase(@TempDir Path tempDir) throws IOException, InterruptedException {
// mock
List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
VideoRecorder videoRecorder = Mockito.mock(VideoRecorder.class);
VideoUploader videoUploader = Mockito.mock(VideoUploader.class);
PipedOutputStream pipedOutputStream = Mockito.mock(PipedOutputStream.class);
EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = EdgeConnectorForKVSConfiguration.builder().kinesisVideoStreamName(MOCK_KINESIS_VIDEO_STREAM_NAME).captureStartTime(START_TIME_NEVER).liveStreamingStartTime(START_TIME_NEVER).videoUploadRequestMqttTopic(VIDEO_UPLOAD_REQUEST_MQTT_TOPIC).videoRecordFolderPath(tempDir).recordingRequestsCount(0).liveStreamingRequestsCount(0).videoRecorder(videoRecorder).build();
edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration);
// when
// Mock for initConfiguration
when(siteWiseManager.initEdgeConnectorForKVSServiceConfiguration(any())).thenReturn(edgeConnectorForKVSConfigurationList);
// Mock for initSecretsManager
when(secretsClient.getSecretValue(any())).thenReturn(gson.toJson(secretMap));
doNothing().when(videoUploader).close();
doNothing().when(pipedOutputStream).flush();
doNothing().when(pipedOutputStream).close();
doNothing().when(videoRecorder).stopRecording();
when(videoRecorder.getStatus()).thenReturn(RecorderStatus.STOPPED);
doAnswer(invocationOnMock -> {
VideoUploadRequestEvent event = invocationOnMock.getArgument(1);
event.onStart(IS_LIVE_TRUE, EVENT_TIMESTAMP, START_TIME, END_TIME);
return null;
}).when(videoUploadRequestHandler).subscribeToMqttTopic(any(), any());
// then
edgeConnectorForKVSService.setUpSharedEdgeConnectorForKVSService();
edgeConnectorForKVSService.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
Thread.sleep(3000);
assertEquals(1, edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount());
assertEquals(1, edgeConnectorForKVSConfiguration.getRecordingRequestsCount());
edgeConnectorForKVSService.cleanUpEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
// verify
assertEquals(0, edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount());
assertEquals(0, edgeConnectorForKVSConfiguration.getRecordingRequestsCount());
}
Aggregations