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