當前位置: 首頁>>代碼示例>>Golang>>正文


Golang kinesis.Kinesis類代碼示例

本文整理匯總了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
}
開發者ID:Originate,項目名稱:terraform,代碼行數:54,代碼來源:resource_aws_kinesis_stream.go

示例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
}
開發者ID:fromonesrc,項目名稱:terraform,代碼行數:51,代碼來源:resource_aws_kinesis_stream.go

示例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
}
開發者ID:autotune,項目名稱:terraform,代碼行數:14,代碼來源:resource_aws_kinesis_stream.go

示例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)

}
開發者ID:luck02,項目名稱:goPublish,代碼行數:16,代碼來源:testHelpers.go

示例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
}
開發者ID:Originate,項目名稱:terraform,代碼行數:16,代碼來源:resource_aws_kinesis_stream.go

示例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
}
開發者ID:AssertSelenium,項目名稱:terraform,代碼行數:49,代碼來源:tags_kinesis.go

示例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)
}
開發者ID:luck02,項目名稱:goPublish,代碼行數:17,代碼來源:testHelpers.go

示例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
	}
}
開發者ID:saulshanabrook,項目名稱:terraform,代碼行數:19,代碼來源:resource_aws_kinesis_stream.go

示例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
}
開發者ID:luck02,項目名稱:goPublish,代碼行數:21,代碼來源:testHelpers.go

示例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
}
開發者ID:Originate,項目名稱:terraform,代碼行數:39,代碼來源:resource_aws_kinesis_stream.go


注:本文中的github.com/aws/aws-sdk-go/service/kinesis.Kinesis類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。