Search in sources :

Example 21 with EdgeConnectorForKVSConfiguration

use of com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class DiskManagerTest method testWatchService_Path_Register_Failed_Case.

@Test
public void testWatchService_Path_Register_Failed_Case() {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = Collections.singletonList(EdgeConnectorForKVSConfiguration.builder().videoRecordFolderPath(Paths.get("NonExistentFile.txt")).localDataRetentionPeriodInMinutes(LOCAL_DATA_RETENTION_PERIOD_IN_MINUTES).build());
    List<WatchEvent<?>> events = new ArrayList<>();
    testWatchEventCallBack = new TestWatchEventCallBack(events);
    diskManager = new DiskManager(edgeConnectorForKVSConfigurationList, diskManagerUtil, watchServiceExecutor, fileCleanerService, testWatchEventCallBack);
    // then
    try {
        diskManager.setupDiskManagerThread();
    } catch (EdgeConnectorForKVSException e) {
        assertEquals(e.getClass(), EdgeConnectorForKVSException.class);
    }
}
Also used : EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) TestWatchEventCallBack(com.aws.iot.edgeconnectorforkvs.diskmanager.callback.TestWatchEventCallBack) ArrayList(java.util.ArrayList) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) WatchEvent(java.nio.file.WatchEvent) Test(org.junit.jupiter.api.Test)

Example 22 with EdgeConnectorForKVSConfiguration

use of com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class SiteWiseManager method buildEdgeConnectorForKVSConfiguration.

private EdgeConnectorForKVSConfiguration buildEdgeConnectorForKVSConfiguration(String cameraSiteWiseAssetId) throws IllegalAccessException {
    DescribeAssetResponse assetResponse = siteWiseClient.describeAsset(cameraSiteWiseAssetId);
    EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = new EdgeConnectorForKVSConfiguration();
    edgeConnectorForKVSConfiguration.setSiteWiseAssetId(cameraSiteWiseAssetId);
    for (AssetProperty assetProperty : assetResponse.assetProperties()) {
        GetAssetPropertyValueResponse result;
        Field[] fields = edgeConnectorForKVSConfiguration.getClass().getDeclaredFields();
        for (Field field : fields) {
            if (field.getName().equalsIgnoreCase(assetProperty.name())) {
                result = siteWiseClient.getAssetPropertyValue(cameraSiteWiseAssetId, assetProperty.id());
                if (result != null && result.propertyValue() != null) {
                    if (field.getType() == String.class) {
                        field.set(edgeConnectorForKVSConfiguration, result.propertyValue().value().stringValue());
                        break;
                    } else if (field.getType() == Integer.TYPE || field.getType() == Integer.class) {
                        field.set(edgeConnectorForKVSConfiguration, result.propertyValue().value().integerValue());
                        break;
                    }
                }
            }
        }
        if (assetProperty.name().equalsIgnoreCase(Constants.SITE_WISE_VIDEO_UPLOADED_TIME_RANGE_MEASUREMENT_NAME)) {
            edgeConnectorForKVSConfiguration.setVideoUploadedTimeRangePropertyId(assetProperty.id());
        }
        if (assetProperty.name().equalsIgnoreCase(Constants.SITE_WISE_VIDEO_RECORDED_TIME_RANGE_MEASUREMENT_NAME)) {
            edgeConnectorForKVSConfiguration.setVideoRecordedTimeRangePropertyId(assetProperty.id());
        }
        if (assetProperty.name().equalsIgnoreCase(Constants.SITE_WISE_CACHED_VIDEO_AGE_OUT_ON_EDGE_MEASUREMENT_NAME)) {
            edgeConnectorForKVSConfiguration.setCachedVideoAgeOutOnEdgePropertyId(assetProperty.id());
        }
        if (assetProperty.name().equalsIgnoreCase(Constants.SITE_WISE_VIDEO_UPLOAD_REQUEST_MEASUREMENT_NAME)) {
            if (assetProperty.notification().state() == PropertyNotificationState.ENABLED) {
                edgeConnectorForKVSConfiguration.setVideoUploadRequestMqttTopic(assetProperty.notification().topic());
            } else {
                log.warn("Video Upload Request MQTT Notification Disabled for Asset Id " + cameraSiteWiseAssetId);
            }
        }
    }
    return edgeConnectorForKVSConfiguration;
}
Also used : Field(java.lang.reflect.Field) DescribeAssetResponse(software.amazon.awssdk.services.iotsitewise.model.DescribeAssetResponse) GetAssetPropertyValueResponse(software.amazon.awssdk.services.iotsitewise.model.GetAssetPropertyValueResponse) AssetProperty(software.amazon.awssdk.services.iotsitewise.model.AssetProperty) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration)

Example 23 with EdgeConnectorForKVSConfiguration

use of com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class EdgeConnectorForKVSService method initKinesisVideoStream.

private void initKinesisVideoStream() {
    for (EdgeConnectorForKVSConfiguration configuration : edgeConnectorForKVSConfigurationList) {
        String kinesisVideoStreamName = configuration.getKinesisVideoStreamName();
        Optional<StreamInfo> result = kvsClient.describeStream(kinesisVideoStreamName);
        if (!result.isPresent()) {
            log.info("Configured KinesisVideoStream name :" + kinesisVideoStreamName + " does not exist, creating it ...");
            kvsClient.createStream(kinesisVideoStreamName);
            log.info("Created KinesisVideoStream name :" + kinesisVideoStreamName);
        }
    }
}
Also used : StreamInfo(com.amazonaws.services.kinesisvideo.model.StreamInfo) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration)

Example 24 with EdgeConnectorForKVSConfiguration

use of com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class VideoFileManagerTest method setUp.

@BeforeEach
@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
public void setUp() {
    EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = new EdgeConnectorForKVSConfiguration();
    edgeConnectorForKVSConfiguration.setLocalDataRetentionPeriodInMinutes(LOCAL_DATA_RETENTION_PERIOD_IN_MINUTES);
    edgeConnectorForKVSConfiguration.setStreamManager(streamManager);
    when(streamManager.pushData(any(), any(), any(), any())).thenReturn(0L);
    this.directoryPath = Paths.get("/mock/videoTest/");
    edgeConnectorForKVSConfiguration.setVideoRecordFolderPath(directoryPath);
    this.edgeConnectorForKVSConfigurationList = new ArrayList<>();
    edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration);
    long video_file_1_timeStamp = LocalDateTime.now().minusMinutes(VIDEO_FILE_1_CACHED_TIME_IN_MINUTES).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    long video_file_2_timeStamp = LocalDateTime.now().minusMinutes(VIDEO_FILE_2_CACHED_TIME_IN_MINUTES).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    this.videoFilePath_1 = Paths.get("/mock/videoTest/video_" + video_file_1_timeStamp + ".mkv");
    this.videoFilePath_2 = Paths.get("/mock/videoTest/video_" + video_file_2_timeStamp + ".mkv");
    diskManagerUtil = new DiskManagerUtil();
    diskManagerUtil.appendRecordFileToDirPath(directoryPath, videoFilePath_1);
    diskManagerUtil.appendRecordFileToDirPath(directoryPath, videoFilePath_2);
    videoFileManager = VideoFileManager.builder().diskManagerUtil(diskManagerUtil).edgeConnectorForKVSConfigurationList(edgeConnectorForKVSConfigurationList).build();
}
Also used : EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) BeforeEach(org.junit.jupiter.api.BeforeEach) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 25 with EdgeConnectorForKVSConfiguration

use of com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration 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());
}
Also used : ArrayList(java.util.ArrayList) VideoUploadRequestEvent(com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

EdgeConnectorForKVSConfiguration (com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration)51 Test (org.junit.jupiter.api.Test)39 ArrayList (java.util.ArrayList)37 ReentrantLock (java.util.concurrent.locks.ReentrantLock)12 VideoRecorder (com.aws.iot.edgeconnectorforkvs.videorecorder.VideoRecorder)8 VideoUploader (com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader)8 TestWatchEventCallBack (com.aws.iot.edgeconnectorforkvs.diskmanager.callback.TestWatchEventCallBack)5 VideoUploadRequestEvent (com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent)5 EdgeConnectorForKVSException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)5 PipedOutputStream (java.io.PipedOutputStream)5 WatchEvent (java.nio.file.WatchEvent)5 IOException (java.io.IOException)4 EdgeConnectorForKVSUnrecoverableException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSUnrecoverableException)3 PipedInputStream (java.io.PipedInputStream)3 KvsStreamingException (com.aws.iot.edgeconnectorforkvs.videouploader.model.exceptions.KvsStreamingException)2 Field (java.lang.reflect.Field)2 Path (java.nio.file.Path)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2