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);
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
}
Aggregations