Search in sources :

Example 6 with ProducerException

use of com.amazonaws.kinesisvideo.producer.ProducerException in project aws-sdk-android by aws-amplify.

the class DefaultServiceCallbacksImpl method tagResource.

@Override
public void tagResource(@NonNull final String resourceArn, @Nullable final Tag[] tags, final long callAfter, final long timeout, @Nullable final byte[] authData, final int authType, final long streamHandle, final KinesisVideoProducerStream stream) throws ProducerException {
    Preconditions.checkState(isInitialized(), "Service callbacks object should be initialized first");
    final long delay = calculateRelativeServiceCallAfter(callAfter);
    final Runnable task = new Runnable() {

        @Override
        public void run() {
            final KinesisVideoCredentialsProvider credentialsProvider = getCredentialsProvider(authData, log);
            final long timeoutInMillis = timeout / Time.HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
            int statusCode = HTTP_OK;
            Map<String, String> tagsMap = null;
            if (null != tags) {
                // Convert the tags to map
                tagsMap = new HashMap<String, String>(tags.length);
                for (final Tag tag : tags) {
                    tagsMap.put(tag.getName(), tag.getValue());
                }
            }
            try {
                kinesisVideoServiceClient.tagStream(resourceArn, tagsMap, timeoutInMillis, credentialsProvider);
            } catch (final KinesisVideoException e) {
                log.error("Kinesis Video service client returned an error " + e.getMessage() + ". Reporting to Kinesis Video PIC.");
                statusCode = getStatusCodeFromException(e);
            }
            if (statusCode != HTTP_OK) {
                // TODO: more URI validation
                statusCode = HTTP_BAD_REQUEST;
            }
            try {
                kinesisVideoProducer.tagResourceResult(stream, streamHandle, statusCode);
            } catch (final ProducerException e) {
                throw new RuntimeException(e);
            }
        }
    };
    executor.schedule(task, delay, TimeUnit.NANOSECONDS);
}
Also used : ProducerException(com.amazonaws.kinesisvideo.producer.ProducerException) Tag(com.amazonaws.kinesisvideo.producer.Tag) KinesisVideoCredentialsProvider(com.amazonaws.kinesisvideo.auth.KinesisVideoCredentialsProvider) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)

Aggregations

KinesisVideoCredentialsProvider (com.amazonaws.kinesisvideo.auth.KinesisVideoCredentialsProvider)6 KinesisVideoException (com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)6 ProducerException (com.amazonaws.kinesisvideo.producer.ProducerException)6 KinesisVideoCredentials (com.amazonaws.kinesisvideo.auth.KinesisVideoCredentials)1 StreamDescription (com.amazonaws.kinesisvideo.producer.StreamDescription)1 Tag (com.amazonaws.kinesisvideo.producer.Tag)1