Search in sources :

Example 6 with EdgeConnectorForKVSException

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

the class JobScheduler method start.

/**
 * Start the Quartz Scheduler.
 */
public void start() {
    try {
        Scheduler sched = this.schedulerFactory.getScheduler();
        sched.start();
        log.info("Started Scheduler");
    } catch (SchedulerException ex) {
        final String errorMessage = String.format("Error starting JobScheduler: " + ex.getMessage());
        log.error(errorMessage);
        throw new EdgeConnectorForKVSException(errorMessage, ex);
    }
}
Also used : EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler)

Example 7 with EdgeConnectorForKVSException

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

the class SecretsClient method getSecretValue.

/**
 * Wrapper for getSecretValue function in SecretsManagerClient.
 * @param secretId - secretArn for the secret
 * @return secret value as String
 * @throws EdgeConnectorForKVSException - Wrapper to all exception thrown by SecretsManagerClient
 */
public String getSecretValue(@NonNull String secretId) throws EdgeConnectorForKVSException {
    try {
        log.info("Retrieving Secret Value for " + secretId);
        GetSecretValueRequest secretValueRequest = GetSecretValueRequest.builder().secretId(secretId).versionStage(VERSION_STAGE).build();
        GetSecretValueResponse secretValueResponse = this.secretsManagerClient.getSecretValue(secretValueRequest);
        return secretValueResponse.secretString();
    } catch (Exception e) {
        final String errorMessage = String.format("Could not getSecretValue for secretId: %s", secretId);
        log.error(errorMessage);
        throw new EdgeConnectorForKVSException(errorMessage, e);
    }
}
Also used : EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)

Example 8 with EdgeConnectorForKVSException

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

the class SiteWiseClient method getAssetHierarchiesIdList.

/**
 * Return all AssetHierarchies Id as String list
 * @param siteWiseAssetId siteWiseAssetId
 * @return List which contains asset hierarchiesId
 * @throws EdgeConnectorForKVSException - EdgeConnectorForKVS generic exception
 */
public List<String> getAssetHierarchiesIdList(@NonNull String siteWiseAssetId) throws EdgeConnectorForKVSException {
    DescribeAssetResponse describeAssetResponse = describeAsset(siteWiseAssetId);
    if (describeAssetResponse.hasAssetHierarchies()) {
        return describeAssetResponse.assetHierarchies().stream().map(AssetHierarchy::id).collect(Collectors.toList());
    } else {
        final String errorMessage = String.format("Failed to getAssetHierarchiesIdList from given siteWiseAssetId, " + "please check EdgeConnectorForKVS configuration and ensure given provide SiteWise property " + "generated from EdgeConnectorForKVSHubDeviceModel. siteWiseAssetId : %s", siteWiseAssetId);
        log.error(errorMessage);
        throw new EdgeConnectorForKVSException(errorMessage);
    }
}
Also used : EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) DescribeAssetResponse(software.amazon.awssdk.services.iotsitewise.model.DescribeAssetResponse)

Example 9 with EdgeConnectorForKVSException

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

the class StreamManager method createMessageStream.

/**
 * Creates a message stream where data is written to.
 *
 * @param msgStreamName - Name of the stream manager message stream
 */
public void createMessageStream(@NonNull String msgStreamName) {
    this.msgStreamName = msgStreamName;
    IoTSiteWiseConfig ioTSiteWiseConfig = new IoTSiteWiseConfig();
    ioTSiteWiseConfig.setIdentifier(UUID.randomUUID().toString());
    ioTSiteWiseConfig.setBatchSize(STREAM_MANAGER_SITEWISE_BATCH_SIZE);
    List<IoTSiteWiseConfig> ioTSiteWiseConfigs = new ArrayList<IoTSiteWiseConfig>();
    ioTSiteWiseConfigs.add(ioTSiteWiseConfig);
    try {
        if (streamManagerClient == null) {
            streamManagerClient = StreamManagerClientFactory.standard().build();
        }
        streamManagerClient.createMessageStream(new MessageStreamDefinition().withName(// Required.
        msgStreamName).withMaxSize(// Default is 256 MB.
        STREAM_MANAGER_MAX_STREAM_SIZE).withStreamSegmentSize(// Default is 16 MB.
        STREAM_MANAGER_STREAM_SEGMENT_SIZE).withTimeToLiveMillis(// By default, no TTL is enabled.
        null).withStrategyOnFull(// Required.
        StrategyOnFull.OverwriteOldestData).withPersistence(// Default is File.
        Persistence.File).withFlushOnWrite(// Default is false.
        false).withExportDefinition(new ExportDefinition().withIotSitewise(ioTSiteWiseConfigs)));
    } catch (Exception ex) {
        final String errorMsg = String.format("Error Creating Stream %s: %s", msgStreamName, ex.getMessage());
        log.error(errorMsg);
        throw new EdgeConnectorForKVSException(errorMsg, ex);
    }
}
Also used : EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) ArrayList(java.util.ArrayList) ExportDefinition(com.amazonaws.greengrass.streammanager.model.export.ExportDefinition) IoTSiteWiseConfig(com.amazonaws.greengrass.streammanager.model.export.IoTSiteWiseConfig) MessageStreamDefinition(com.amazonaws.greengrass.streammanager.model.MessageStreamDefinition) EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StreamManagerException(com.amazonaws.greengrass.streammanager.client.exception.StreamManagerException)

Example 10 with EdgeConnectorForKVSException

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

the class StreamManager method pushData.

/**
 * Pushes data to an existing stream.
 *
 * @param assetId         - SiteWise asset id
 * @param propertyId      - SiteWise property id
 * @param val             - value to be pushed (Long, String, Double or Boolean)
 * @param updateTimeStamp - update time stamp
 * @return - sequence number
 */
public long pushData(@NonNull String assetId, @NonNull String propertyId, @NonNull Object val, Optional<Date> updateTimeStamp) {
    try {
        if (streamManagerClient == null || msgStreamName == null) {
            final String errorMsg = String.format("Error pushing data to Stream. Property Id: %s." + "Please create a message stream first.", propertyId);
            log.error(errorMsg);
            throw new EdgeConnectorForKVSException(errorMsg);
        }
        Variant variant = null;
        if (val instanceof Integer) {
            variant = new Variant().withIntegerValue(Long.valueOf((Integer) val));
        } else if (val instanceof String) {
            variant = new Variant().withStringValue((String) val);
        } else if (val instanceof Double) {
            variant = new Variant().withDoubleValue((Double) val);
        } else if (val instanceof Boolean) {
            variant = new Variant().withBooleanValue((Boolean) val);
        } else {
            final String errorMsg = String.format("Trying to push invalid val type", msgStreamName, propertyId);
            log.error(errorMsg);
            throw new EdgeConnectorForKVSException(errorMsg);
        }
        List<AssetPropertyValue> entries = new ArrayList<>();
        long epochSecond = Instant.now().getEpochSecond();
        if (updateTimeStamp.isPresent()) {
            epochSecond = updateTimeStamp.get().toInstant().getEpochSecond();
        }
        TimeInNanos timestamp = new TimeInNanos().withTimeInSeconds(epochSecond);
        AssetPropertyValue entry = new AssetPropertyValue().withValue(variant).withQuality(Quality.GOOD).withTimestamp(timestamp);
        entries.add(entry);
        PutAssetPropertyValueEntry putAssetPropertyValueEntry = new PutAssetPropertyValueEntry().withEntryId(UUID.randomUUID().toString()).withAssetId(assetId).withPropertyId(propertyId).withPropertyValues(entries);
        log.debug("Pushing data to Message Stream: " + msgStreamName);
        log.trace("For SiteWise Asset ID: " + assetId);
        log.trace("For SiteWise Property ID: " + propertyId);
        log.trace("Value: " + entries.get(0).toString());
        return streamManagerClient.appendMessage(msgStreamName, ValidateAndSerialize.validateAndSerializeToJsonBytes(putAssetPropertyValueEntry));
    } catch (StreamManagerException | JsonProcessingException ex) {
        final String errorMsg = String.format("Error pushing data to Stream: %s, Property Id: %s", msgStreamName, propertyId);
        log.error(errorMsg);
        return 0L;
    }
}
Also used : EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) PutAssetPropertyValueEntry(com.amazonaws.greengrass.streammanager.model.sitewise.PutAssetPropertyValueEntry) ArrayList(java.util.ArrayList) AssetPropertyValue(com.amazonaws.greengrass.streammanager.model.sitewise.AssetPropertyValue) StreamManagerException(com.amazonaws.greengrass.streammanager.client.exception.StreamManagerException) Variant(com.amazonaws.greengrass.streammanager.model.sitewise.Variant) TimeInNanos(com.amazonaws.greengrass.streammanager.model.sitewise.TimeInNanos) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

EdgeConnectorForKVSException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)17 ArrayList (java.util.ArrayList)7 EdgeConnectorForKVSConfiguration (com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration)4 Scheduler (org.quartz.Scheduler)4 SchedulerException (org.quartz.SchedulerException)4 IOException (java.io.IOException)3 DescribeAssetResponse (software.amazon.awssdk.services.iotsitewise.model.DescribeAssetResponse)3 StreamManagerException (com.amazonaws.greengrass.streammanager.client.exception.StreamManagerException)2 TestWatchEventCallBack (com.aws.iot.edgeconnectorforkvs.diskmanager.callback.TestWatchEventCallBack)2 EdgeConnectorForKVSUnrecoverableException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSUnrecoverableException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 WatchEvent (java.nio.file.WatchEvent)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.jupiter.api.Test)2 JobDetail (org.quartz.JobDetail)2 MessageStreamDefinition (com.amazonaws.greengrass.streammanager.model.MessageStreamDefinition)1 ExportDefinition (com.amazonaws.greengrass.streammanager.model.export.ExportDefinition)1 IoTSiteWiseConfig (com.amazonaws.greengrass.streammanager.model.export.IoTSiteWiseConfig)1 AssetPropertyValue (com.amazonaws.greengrass.streammanager.model.sitewise.AssetPropertyValue)1