use of com.amazonaws.services.logs.model.DescribeLogGroupsResult in project aws-athena-query-federation by awslabs.
the class CloudwatchTableResolver method loadLogGroup.
/**
* Optomizaiton that attempts to load a specific LogStream as identified by the TableName.
*
* @param schemaName The schemaName to load.
* @return The CloudwatchTableName or null if not found.
*/
private String loadLogGroup(String schemaName) throws TimeoutException {
DescribeLogGroupsRequest request = new DescribeLogGroupsRequest().withLogGroupNamePrefix(schemaName);
DescribeLogGroupsResult result = invoker.invoke(() -> awsLogs.describeLogGroups(request));
for (LogGroup next : result.getLogGroups()) {
String nextLogGroupName = next.getLogGroupName();
if (nextLogGroupName.equalsIgnoreCase(schemaName)) {
logger.info("loadLogGroup: Matched {} for {}", nextLogGroupName, schemaName);
return nextLogGroupName;
}
}
return null;
}
use of com.amazonaws.services.logs.model.DescribeLogGroupsResult in project cloudwatch-logback-appender by j256.
the class CloudWatchAppenderTest method testMoreAwsCallsMissingGroupAndStream.
@Test(timeout = 10000)
public void testMoreAwsCallsMissingGroupAndStream() throws InterruptedException {
CloudWatchAppender appender = new CloudWatchAppender();
AWSLogs logsClient = createMock(AWSLogs.class);
AmazonEC2 ec2Client = createMock(AmazonEC2.class);
appender.setTestAwsLogsClient(logsClient);
appender.setTestAmazonEc2Client(ec2Client);
appender.setMaxBatchSize(1);
appender.setRegion("region");
final String logGroup = "pfqoejpfqe";
appender.setLogGroup(logGroup);
final String logStream = "pffqjfqjpoqoejpfqe";
appender.setLogStream(logStream);
appender.setContext(LOGGER_CONTEXT);
PatternLayout layout = new PatternLayout();
layout.setContext(LOGGER_CONTEXT);
layout.setPattern("[%thread] %level %logger{20} - %msg%n%xThrowable");
layout.start();
appender.setLayout(layout);
final String loggerName = "name";
final Level level = Level.DEBUG;
String message = "kuuyuyuykkkyjtyh";
LoggingEvent event = createEvent(loggerName, level, message, System.currentTimeMillis());
String threadName = Thread.currentThread().getName();
final String fullMessage = "[" + threadName + "] " + level + " " + loggerName + " - " + message + "\n";
DescribeLogGroupsResult logGroupsResult = new DescribeLogGroupsResult().withLogGroups(Collections.<LogGroup>emptyList());
expect(logsClient.describeLogGroups(isA(DescribeLogGroupsRequest.class))).andReturn(logGroupsResult);
CreateLogGroupResult createLogGroupResult = new CreateLogGroupResult();
expect(logsClient.createLogGroup(isA(CreateLogGroupRequest.class))).andReturn(createLogGroupResult);
DescribeLogStreamsResult logStreamsResult = new DescribeLogStreamsResult().withLogStreams(Collections.<LogStream>emptyList());
expect(logsClient.describeLogStreams(isA(DescribeLogStreamsRequest.class))).andReturn(logStreamsResult);
CreateLogStreamResult createLogStreamResult = new CreateLogStreamResult();
expect(logsClient.createLogStream(isA(CreateLogStreamRequest.class))).andReturn(createLogStreamResult);
final PutLogEventsResult putLogEventsResult = new PutLogEventsResult();
String sequence = "ewopjfewfj";
putLogEventsResult.setNextSequenceToken(sequence);
expect(logsClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {
@Override
public PutLogEventsResult answer() {
PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
assertEquals(logGroup, request.getLogGroupName());
assertEquals(logStream, request.getLogStreamName());
List<InputLogEvent> events = request.getLogEvents();
assertEquals(1, events.size());
assertEquals(fullMessage, events.get(0).getMessage());
return putLogEventsResult;
}
}).times(2);
logsClient.shutdown();
// =====================================
replay(logsClient, ec2Client);
appender.start();
// for coverage
appender.start();
appender.append(event);
Thread.sleep(100);
appender.append(event);
while (appender.getEventsWrittenCount() < 2) {
Thread.sleep(100);
}
appender.stop();
verify(logsClient, ec2Client);
}
Aggregations