Search in sources :

Example 1 with CreateLogStreamRequest

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

the class AmazonCloudWatchAuditDestination method createLogStream.

private void createLogStream() {
    AWSLogs client = getClient();
    CreateLogStreamRequest req = new CreateLogStreamRequest().withLogGroupName(logGroupName).withLogStreamName(logStreamName);
    LOG.info(String.format("Creating Log Stream `%s` in Log Group `%s`", logStreamName, logGroupName));
    client.createLogStream(req);
}
Also used : CreateLogStreamRequest(com.amazonaws.services.logs.model.CreateLogStreamRequest) AWSLogs(com.amazonaws.services.logs.AWSLogs)

Example 2 with CreateLogStreamRequest

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

the class CloudwatchRecordWorkerTest method testDescribeLogStreamsWhenLogStreamDoesNotExist.

@Test
public void testDescribeLogStreamsWhenLogStreamDoesNotExist() {
    DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest();
    describeLogStreamsRequest.setLogGroupName("TestGroup");
    describeLogStreamsRequest.setLogStreamNamePrefix(underTest.initLogStream("TestStream"));
    DescribeLogStreamsResult describeLogStreamsResult = new DescribeLogStreamsResult();
    Set<LogStream> logStreams = new HashSet<>();
    describeLogStreamsResult.setLogStreams(logStreams);
    when(awsLogsClient.describeLogStreams(describeLogStreamsRequest)).thenReturn(describeLogStreamsResult);
    when(awsLogsClient.describeLogStreams(describeLogStreamsRequest)).thenReturn(describeLogStreamsResult);
    CreateLogStreamRequest createLogStreamRequest = new CreateLogStreamRequest();
    createLogStreamRequest.setLogGroupName("TestGroup");
    createLogStreamRequest.setLogStreamName(underTest.initLogStream("TestStream"));
    when(awsLogsClient.createLogStream(createLogStreamRequest)).thenReturn(new CreateLogStreamResult());
    underTest.describeLogStreams();
    verify(awsLogsClient, times(2)).describeLogStreams(describeLogStreamsRequest);
    verify(awsLogsClient, times(1)).createLogStream(createLogStreamRequest);
}
Also used : CreateLogStreamRequest(com.amazonaws.services.logs.model.CreateLogStreamRequest) CreateLogStreamResult(com.amazonaws.services.logs.model.CreateLogStreamResult) DescribeLogStreamsRequest(com.amazonaws.services.logs.model.DescribeLogStreamsRequest) LogStream(com.amazonaws.services.logs.model.LogStream) DescribeLogStreamsResult(com.amazonaws.services.logs.model.DescribeLogStreamsResult) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with CreateLogStreamRequest

use of com.amazonaws.services.logs.model.CreateLogStreamRequest 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 4 with CreateLogStreamRequest

use of com.amazonaws.services.logs.model.CreateLogStreamRequest in project quarkus-logging-cloudwatch by quarkiverse.

the class LoggingCloudWatchHandlerValueFactory method createLogStreamIfNeeded.

private String createLogStreamIfNeeded(AWSLogs awsLogs, LoggingCloudWatchConfig config) {
    String token = null;
    DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest(config.logGroup.get());
    // We need to filter down, as CW returns by default only 50 streams and ours may not be in it.
    describeLogStreamsRequest.withLogStreamNamePrefix(config.logStreamName.get());
    List<LogStream> logStreams = awsLogs.describeLogStreams(describeLogStreamsRequest).getLogStreams();
    boolean found = false;
    for (LogStream ls : logStreams) {
        if (ls.getLogStreamName().equals(config.logStreamName.get())) {
            found = true;
            token = ls.getUploadSequenceToken();
        }
    }
    if (!found) {
        awsLogs.createLogStream(new CreateLogStreamRequest(config.logGroup.get(), config.logStreamName.get()));
    }
    return token;
}
Also used : CreateLogStreamRequest(com.amazonaws.services.logs.model.CreateLogStreamRequest) DescribeLogStreamsRequest(com.amazonaws.services.logs.model.DescribeLogStreamsRequest) LogStream(com.amazonaws.services.logs.model.LogStream)

Aggregations

CreateLogStreamRequest (com.amazonaws.services.logs.model.CreateLogStreamRequest)4 DescribeLogStreamsRequest (com.amazonaws.services.logs.model.DescribeLogStreamsRequest)3 DescribeLogStreamsResult (com.amazonaws.services.logs.model.DescribeLogStreamsResult)2 LogStream (com.amazonaws.services.logs.model.LogStream)2 AWSLogs (com.amazonaws.services.logs.AWSLogs)1 CreateLogStreamResult (com.amazonaws.services.logs.model.CreateLogStreamResult)1 ResourceNotFoundException (com.amazonaws.services.logs.model.ResourceNotFoundException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashSet (java.util.HashSet)1 Test (org.junit.jupiter.api.Test)1