private void verifyLogStreamExists() { DescribeLogStreamsRequest request = new DescribeLogStreamsRequest().withLogGroupName(logGroup).withLogStreamNamePrefix(logStream); DescribeLogStreamsResult result = awsLogsClient.describeLogStreams(request); for (LogStream stream : result.getLogStreams()) { if (logStream.equals(stream.getLogStreamName())) { sequenceToken = stream.getUploadSequenceToken(); return; } } if (createLogDests) { callLogClientMethod("createLogStream", new CreateLogStreamRequest(logGroup, logStream)); } else { logWarn("Log-stream '" + logStream + "' doesn't exist and not created", null); } }
private String createLogGroupAndLogStreamIfNeeded() { LOGGER.debug("Attempting to locate the log group [{}]", logGroupName); final DescribeLogGroupsResult describeLogGroupsResult = awsLogsClient.describeLogGroups(new DescribeLogGroupsRequest().withLogGroupNamePrefix(logGroupName)); boolean createLogGroup = true; if (describeLogGroupsResult != null && describeLogGroupsResult.getLogGroups() != null && !describeLogGroupsResult.getLogGroups().isEmpty()) { createLogGroup = !describeLogGroupsResult.getLogGroups().stream().anyMatch(g -> g.getLogGroupName().equals(logGroupName)); } if (createLogGroup) { LOGGER.debug("Creating log group [{}]", logGroupName); final CreateLogGroupRequest createLogGroupRequest = new CreateLogGroupRequest(logGroupName); awsLogsClient.createLogGroup(createLogGroupRequest); } String logSequenceToken = null; boolean createLogStream = true; LOGGER.debug("Attempting to locate the log stream [{}] for group [{}]", logStreamName, logGroupName); final DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest(logGroupName).withLogStreamNamePrefix(logStreamName); final DescribeLogStreamsResult describeLogStreamsResult = awsLogsClient.describeLogStreams(describeLogStreamsRequest); if (describeLogStreamsResult != null && describeLogStreamsResult.getLogStreams() != null && !describeLogStreamsResult.getLogStreams().isEmpty()) { for (final LogStream ls : describeLogStreamsResult.getLogStreams()) { if (logStreamName.equals(ls.getLogStreamName())) { createLogStream = false; logSequenceToken = ls.getUploadSequenceToken(); LOGGER.debug("Found log stream [{}] with sequence token [{}]", logStreamName, logSequenceToken); break; } } } if (createLogStream) { LOGGER.debug("Creating log stream [{}] for group [{}]", logStreamName, logGroupName); final CreateLogStreamRequest createLogStreamRequest = new CreateLogStreamRequest(logGroupName, logStreamName); awsLogsClient.createLogStream(createLogStreamRequest); } return logSequenceToken; }
private void createLogStream() { try { awsLogs.createLogStream(new CreateLogStreamRequest().withLogGroupName(logGroupName).withLogStreamName(logStreamName)); } catch (final ResourceAlreadyExistsException e) { addStatus(new InfoStatus(e.getMessage(), this)); } }