Search in sources :

Example 1 with ResourceNotFoundException

use of com.amazonaws.services.logs.model.ResourceNotFoundException in project cloudbreak by hortonworks.

the class CloudwatchRecordWorker method describeLogStreams.

@VisibleForTesting
DescribeLogStreamsResult describeLogStreams() {
    DescribeLogStreamsRequest describeLogStreams = new DescribeLogStreamsRequest();
    describeLogStreams.setLogGroupName(logGroup);
    describeLogStreams.setLogStreamNamePrefix(logStream);
    try {
        DescribeLogStreamsResult describeLogStreamsResult = getAwsLogsClient().describeLogStreams(describeLogStreams);
        if (!describeLogStreamsResult.getLogStreams().isEmpty()) {
            return describeLogStreamsResult;
        } else {
            CreateLogStreamRequest createLogStreamRequest = new CreateLogStreamRequest();
            createLogStreamRequest.setLogGroupName(logGroup);
            createLogStreamRequest.setLogStreamName(logStream);
            getAwsLogsClient().createLogStream(createLogStreamRequest);
            return getAwsLogsClient().describeLogStreams(describeLogStreams);
        }
    } catch (ResourceNotFoundException re) {
        LOGGER.error("Error during describing AWS CloudWatch log streams: log group '{}' not found", logGroup, re);
        throw re;
    }
}
Also used : CreateLogStreamRequest(com.amazonaws.services.logs.model.CreateLogStreamRequest) DescribeLogStreamsRequest(com.amazonaws.services.logs.model.DescribeLogStreamsRequest) DescribeLogStreamsResult(com.amazonaws.services.logs.model.DescribeLogStreamsResult) ResourceNotFoundException(com.amazonaws.services.logs.model.ResourceNotFoundException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ResourceNotFoundException

use of com.amazonaws.services.logs.model.ResourceNotFoundException in project ranger by apache.

the class AmazonCloudWatchAuditDestination method pushLogEvents.

private String pushLogEvents(PutLogEventsRequest req, boolean retryingOnInvalidSeqToken, AWSLogs client) {
    String sequenceToken;
    try {
        PutLogEventsResult re = client.putLogEvents(req);
        sequenceToken = re.getNextSequenceToken();
    } catch (ResourceNotFoundException ex) {
        if (!retryingOnInvalidSeqToken) {
            createLogStream();
            return pushLogEvents(req, true, client);
        }
        throw ex;
    } catch (InvalidSequenceTokenException ex) {
        if (retryingOnInvalidSeqToken) {
            LOG.error("Unexpected invalid sequence token. Possible race condition occurred");
            throw ex;
        }
        // LogStream may exist before first push attempt, re-obtain the sequence token
        if (LOG.isDebugEnabled()) {
            LOG.debug("Invalid sequence token. Plugin possibly restarted. Updating the sequence token and retrying");
        }
        sequenceToken = ex.getExpectedSequenceToken();
        req.setSequenceToken(sequenceToken);
        return pushLogEvents(req, true, client);
    }
    return sequenceToken;
}
Also used : InvalidSequenceTokenException(com.amazonaws.services.logs.model.InvalidSequenceTokenException) PutLogEventsResult(com.amazonaws.services.logs.model.PutLogEventsResult) ResourceNotFoundException(com.amazonaws.services.logs.model.ResourceNotFoundException)

Example 3 with ResourceNotFoundException

use of com.amazonaws.services.logs.model.ResourceNotFoundException in project aws-sdk-android by aws-amplify.

the class ResourceNotFoundExceptionUnmarshaller method unmarshall.

@Override
public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception {
    ResourceNotFoundException e = (ResourceNotFoundException) super.unmarshall(error);
    e.setErrorCode("ResourceNotFoundException");
    return e;
}
Also used : ResourceNotFoundException(com.amazonaws.services.logs.model.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (com.amazonaws.services.logs.model.ResourceNotFoundException)3 CreateLogStreamRequest (com.amazonaws.services.logs.model.CreateLogStreamRequest)1 DescribeLogStreamsRequest (com.amazonaws.services.logs.model.DescribeLogStreamsRequest)1 DescribeLogStreamsResult (com.amazonaws.services.logs.model.DescribeLogStreamsResult)1 InvalidSequenceTokenException (com.amazonaws.services.logs.model.InvalidSequenceTokenException)1 PutLogEventsResult (com.amazonaws.services.logs.model.PutLogEventsResult)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1