Amazon Redshift
管理指南 (API Version 2012-12-01)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。点 击 Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

使用适用于 Java 的 AWS 开发工具包查看事件

以下示例列出了指定群集的事件以及指定事件源类型。本示例展示了如何使用分页。

有关运行以下示例的分步说明,请参阅 使用 Eclipse 运行 Amazon Redshift 的 Java 示例。您需要更新代码并指定群集标识符和事件源类型。

Copy
import java.io.IOException; import java.util.Date; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.PropertiesCredentials; import com.amazonaws.services.redshift.AmazonRedshiftClient; import com.amazonaws.services.redshift.model.*; public class ListEvents { public static AmazonRedshiftClient client; public static String clusterIdentifier = "***provide cluster identifier***"; public static String eventSourceType = "***provide source type***"; // e.g. cluster-snapshot public static void main(String[] args) throws IOException { AWSCredentials credentials = new PropertiesCredentials( ListEvents.class .getResourceAsStream("AwsCredentials.properties")); client = new AmazonRedshiftClient(credentials); try { listEvents(); } catch (Exception e) { System.err.println("Operation failed: " + e.getMessage()); } } private static void listEvents() { long oneWeeksAgoMilli = (new Date()).getTime() - (7L*24L*60L*60L*1000L); Date oneWeekAgo = new Date(); oneWeekAgo.setTime(oneWeeksAgoMilli); String marker = null; do { DescribeEventsRequest request = new DescribeEventsRequest() .withSourceIdentifier(clusterIdentifier) .withSourceType(eventSourceType) .withStartTime(oneWeekAgo) .withMaxRecords(20); DescribeEventsResult result = client.describeEvents(request); marker = result.getMarker(); for (Event event : result.getEvents()) { printEvent(event); } } while (marker != null); } static void printEvent(Event event) { if (event == null) { System.out.println("\nEvent object is null."); return; } System.out.println("\nEvent metadata:\n"); System.out.format("SourceID: %s\n", event.getSourceIdentifier()); System.out.format("Type: %s\n", event.getSourceType()); System.out.format("Message: %s\n", event.getMessage()); System.out.format("Date: %s\n", event.getDate()); } }