本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/kinesis.Kinesis类的典型用法代码示例。如果您正苦于以下问题:Golang Kinesis类的具体用法?Golang Kinesis怎么用?Golang Kinesis使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Kinesis类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateKinesisShardLevelMetrics
func updateKinesisShardLevelMetrics(conn *kinesis.Kinesis, d *schema.ResourceData) error {
sn := d.Get("name").(string)
o, n := d.GetChange("shard_level_metrics")
if o == nil {
o = new(schema.Set)
}
if n == nil {
n = new(schema.Set)
}
os := o.(*schema.Set)
ns := n.(*schema.Set)
disableMetrics := os.Difference(ns)
if disableMetrics.Len() != 0 {
metrics := disableMetrics.List()
log.Printf("[DEBUG] Disabling shard level metrics %v for stream %s", metrics, sn)
props := &kinesis.DisableEnhancedMonitoringInput{
StreamName: aws.String(sn),
ShardLevelMetrics: expandStringList(metrics),
}
_, err := conn.DisableEnhancedMonitoring(props)
if err != nil {
return fmt.Errorf("Failure to disable shard level metrics for stream %s: %s", sn, err)
}
if err := waitForKinesisToBeActive(conn, sn); err != nil {
return err
}
}
enabledMetrics := ns.Difference(os)
if enabledMetrics.Len() != 0 {
metrics := enabledMetrics.List()
log.Printf("[DEBUG] Enabling shard level metrics %v for stream %s", metrics, sn)
props := &kinesis.EnableEnhancedMonitoringInput{
StreamName: aws.String(sn),
ShardLevelMetrics: expandStringList(metrics),
}
_, err := conn.EnableEnhancedMonitoring(props)
if err != nil {
return fmt.Errorf("Failure to enable shard level metrics for stream %s: %s", sn, err)
}
if err := waitForKinesisToBeActive(conn, sn); err != nil {
return err
}
}
return nil
}
示例2: setKinesisRetentionPeriod
func setKinesisRetentionPeriod(conn *kinesis.Kinesis, d *schema.ResourceData) error {
sn := d.Get("name").(string)
oraw, nraw := d.GetChange("retention_period")
o := oraw.(int)
n := nraw.(int)
if n == 0 {
log.Printf("[DEBUG] Kinesis Stream (%q) Retention Period Not Changed", sn)
return nil
}
if n > o {
log.Printf("[DEBUG] Increasing %s Stream Retention Period to %d", sn, n)
_, err := conn.IncreaseStreamRetentionPeriod(&kinesis.IncreaseStreamRetentionPeriodInput{
StreamName: aws.String(sn),
RetentionPeriodHours: aws.Int64(int64(n)),
})
if err != nil {
return err
}
} else {
log.Printf("[DEBUG] Decreasing %s Stream Retention Period to %d", sn, n)
_, err := conn.DecreaseStreamRetentionPeriod(&kinesis.DecreaseStreamRetentionPeriodInput{
StreamName: aws.String(sn),
RetentionPeriodHours: aws.Int64(int64(n)),
})
if err != nil {
return err
}
}
stateConf := &resource.StateChangeConf{
Pending: []string{"UPDATING"},
Target: []string{"ACTIVE"},
Refresh: streamStateRefreshFunc(conn, sn),
Timeout: 5 * time.Minute,
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
_, err := stateConf.WaitForState()
if err != nil {
return fmt.Errorf(
"Error waiting for Kinesis Stream (%s) to become active: %s",
sn, err)
}
return nil
}
示例3: readKinesisStreamState
func readKinesisStreamState(conn *kinesis.Kinesis, sn string) (kinesisStreamState, error) {
describeOpts := &kinesis.DescribeStreamInput{
StreamName: aws.String(sn),
}
var state kinesisStreamState
err := conn.DescribeStreamPages(describeOpts, func(page *kinesis.DescribeStreamOutput, last bool) (shouldContinue bool) {
state.arn = aws.StringValue(page.StreamDescription.StreamARN)
state.status = aws.StringValue(page.StreamDescription.StreamStatus)
state.shardCount += len(page.StreamDescription.Shards)
return !last
})
return state, err
}
示例4: DeleteStream
func DeleteStream(service *kinesis.Kinesis, streamName string) {
params := &kinesis.DeleteStreamInput{
StreamName: aws.String(streamName),
}
resp, err := service.DeleteStream(params)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println("Response from deleteStream")
fmt.Println(resp)
}
示例5: readKinesisStreamState
func readKinesisStreamState(conn *kinesis.Kinesis, sn string) (kinesisStreamState, error) {
describeOpts := &kinesis.DescribeStreamInput{
StreamName: aws.String(sn),
}
var state kinesisStreamState
err := conn.DescribeStreamPages(describeOpts, func(page *kinesis.DescribeStreamOutput, last bool) (shouldContinue bool) {
state.arn = aws.StringValue(page.StreamDescription.StreamARN)
state.status = aws.StringValue(page.StreamDescription.StreamStatus)
state.shardCount += len(openShards(page.StreamDescription.Shards))
state.retentionPeriod = aws.Int64Value(page.StreamDescription.RetentionPeriodHours)
state.shardLevelMetrics = flattenKinesisShardLevelMetrics(page.StreamDescription.EnhancedMonitoring)
return !last
})
return state, err
}
示例6: setTagsKinesis
// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tags"
func setTagsKinesis(conn *kinesis.Kinesis, d *schema.ResourceData) error {
sn := d.Get("name").(string)
if d.HasChange("tags") {
oraw, nraw := d.GetChange("tags")
o := oraw.(map[string]interface{})
n := nraw.(map[string]interface{})
create, remove := diffTagsKinesis(tagsFromMapKinesis(o), tagsFromMapKinesis(n))
// Set tags
if len(remove) > 0 {
log.Printf("[DEBUG] Removing tags: %#v", remove)
k := make([]*string, len(remove), len(remove))
for i, t := range remove {
k[i] = t.Key
}
_, err := conn.RemoveTagsFromStream(&kinesis.RemoveTagsFromStreamInput{
StreamName: aws.String(sn),
TagKeys: k,
})
if err != nil {
return err
}
}
if len(create) > 0 {
log.Printf("[DEBUG] Creating tags: %#v", create)
t := make(map[string]*string)
for _, tag := range create {
t[*tag.Key] = tag.Value
}
_, err := conn.AddTagsToStream(&kinesis.AddTagsToStreamInput{
StreamName: aws.String(sn),
Tags: t,
})
if err != nil {
return err
}
}
}
return nil
}
示例7: CreateStream
func CreateStream(service *kinesis.Kinesis, streamName string) {
params := &kinesis.CreateStreamInput{
ShardCount: aws.Int64(1),
StreamName: aws.String(streamName),
}
resp, err := service.CreateStream(params)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println("Response from CreateStream:")
fmt.Println(resp)
fmt.Println(err)
}
示例8: streamStateRefreshFunc
func streamStateRefreshFunc(conn *kinesis.Kinesis, sn string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
describeOpts := &kinesis.DescribeStreamInput{
StreamName: aws.String(sn),
}
resp, err := conn.DescribeStream(describeOpts)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "ResourceNotFoundException" {
return 42, "DESTROYED", nil
}
return nil, awsErr.Code(), err
}
return nil, "failed", err
}
return resp.StreamDescription, *resp.StreamDescription.StreamStatus, nil
}
}
示例9: CheckStreamStatus
func CheckStreamStatus(status string, service *kinesis.Kinesis, streamName string) bool {
descParams := &kinesis.DescribeStreamInput{
StreamName: aws.String(streamName),
}
for i := 0; i < 30; i++ {
respDescribe, err := service.DescribeStream(descParams)
if *respDescribe.StreamDescription.StreamStatus == status {
return true
}
fmt.Println(respDescribe)
fmt.Println(err)
time.Sleep(500 * time.Millisecond)
}
return false
}
示例10: setKinesisRetentionPeriod
func setKinesisRetentionPeriod(conn *kinesis.Kinesis, d *schema.ResourceData) error {
sn := d.Get("name").(string)
oraw, nraw := d.GetChange("retention_period")
o := oraw.(int)
n := nraw.(int)
if n == 0 {
log.Printf("[DEBUG] Kinesis Stream (%q) Retention Period Not Changed", sn)
return nil
}
if n > o {
log.Printf("[DEBUG] Increasing %s Stream Retention Period to %d", sn, n)
_, err := conn.IncreaseStreamRetentionPeriod(&kinesis.IncreaseStreamRetentionPeriodInput{
StreamName: aws.String(sn),
RetentionPeriodHours: aws.Int64(int64(n)),
})
if err != nil {
return err
}
} else {
log.Printf("[DEBUG] Decreasing %s Stream Retention Period to %d", sn, n)
_, err := conn.DecreaseStreamRetentionPeriod(&kinesis.DecreaseStreamRetentionPeriodInput{
StreamName: aws.String(sn),
RetentionPeriodHours: aws.Int64(int64(n)),
})
if err != nil {
return err
}
}
if err := waitForKinesisToBeActive(conn, sn); err != nil {
return err
}
return nil
}