コード例 #1
0
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
0
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
0
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
0
ファイル: testHelpers.go プロジェクト: luck02/goPublish
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
0
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
0
// 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
0
ファイル: testHelpers.go プロジェクト: luck02/goPublish
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
0
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
0
ファイル: testHelpers.go プロジェクト: luck02/goPublish
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
0
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
}