github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dis/v2/streams/requests.go (about)

     1  package streams
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/openstack/common/tags"
     6  )
     7  
     8  const (
     9  	StreamTypeCommon   = "COMMON"
    10  	StreamTypeAdvanced = "ADVANCED"
    11  
    12  	DataTypeBlob = "BLOB"
    13  	DataTypeJson = "JSON"
    14  	DataTypeCsv  = "CSV"
    15  
    16  	CompressionTypeSnappy = "snappy"
    17  	CompressionTypeGzip   = "gzip"
    18  	CompressionTypeZip    = "zip"
    19  
    20  	StatusCreating    = "CREATING"
    21  	StatusRunning     = "RUNNING"
    22  	StatusTerminating = "TERMINATING"
    23  	StatusTerminated  = "TERMINATED"
    24  	StatusFrozen      = "FROZEN"
    25  )
    26  
    27  type CreateOpts struct {
    28  	// Each DIS stream has a unique name. A stream name is 1 to 64 characters in length. Only letters, digits,
    29  	// hyphens (-), and underscores (_) are allowed.
    30  	StreamName string `json:"stream_name" required:"true"`
    31  	// Quantity of the partitions into which data records in the newly created DIS stream will be distributed.
    32  	// Partitions are the base throughput unit of a DIS stream.
    33  	// The value range varies depending on the value of stream_type.
    34  	// If stream_type is not specified or set to COMMON, the value of partition_count is an int from 1 to 50.
    35  	// If the tenant has created N common partitions, the maximum value of partition_count is 50-N.
    36  	// If stream_type is set to ADVANCED, the value of partition_count is an int from 1 to 10.
    37  	// If the tenant has created N advanced partitions, the maximum value of partition_count is 10-N.
    38  	PartitionCount int `json:"partition_count" required:"true"`
    39  	// Stream type. Possible values:
    40  	// COMMON: a common stream. The bandwidth is 1 MB/s.
    41  	// ADVANCED: an advanced stream. The bandwidth is 5 MB/s.
    42  	// Default value: COMMON
    43  	StreamType string `json:"stream_type,omitempty"`
    44  	// Source data type.
    45  	// Possible values:
    46  	// BLOB: a collection of binary data stored as a single entity in a database management system.
    47  	// JSON: an open-standard file format that uses human-readable text to transmit data objects consisting of attribute–value pairs and array data types.
    48  	// CSV: a simple text format for storing tabular data in a plain text file.
    49  	// Default value: BLOB
    50  	DataType string `json:"data_type,omitempty"`
    51  	// Period of time for which data is retained in the DIS stream.
    52  	// Value range: 24 to 72
    53  	// Unit: hour
    54  	// Default value: 24
    55  	// If this parameter is left unspecified, the default value will be used.
    56  	DataDuration int `json:"data_duration,omitempty"`
    57  	// Whether to enable automatic Scaling
    58  	// true: Turn on automatic scale out.
    59  	// false: Turn off automatic scale in.
    60  	// Disabled by default.
    61  	// Default value: false
    62  	AutoScaleEnabled *bool `json:"auto_scale_enabled,omitempty"`
    63  	// When auto scaling is enabled, the minimum number of slices for auto scaling.
    64  	// Minimum value: 1
    65  	AutoScaleMinPartitionCount *int `json:"auto_scale_min_partition_count,omitempty"`
    66  	// When auto scaling is enabled, the maximum number of slices for auto scaling.
    67  	AutoScaleMaxPartitionCount *int `json:"auto_scale_max_partition_count,omitempty"`
    68  	// Source data structure that defines JOSN and CSV formats. It is described in the syntax of Avro.
    69  	// For details about Avro, see http://avro.apache.org/docs/current/#schemas.
    70  	// NOTE:
    71  	// This parameter is mandatory when Dump File Format is Parquet or CarbonData.
    72  	DataSchema string `json:"data_schema,omitempty"`
    73  	// Related attributes of CSV format data, such as delimiter
    74  	CsvProperties *CsvProperty `json:"csv_properties,omitempty"`
    75  	// Data compression type, currently supports:
    76  	// snappy
    77  	// gzip
    78  	// zip
    79  	// No compression by default
    80  	CompressionFormat string             `json:"compression_format,omitempty"`
    81  	Tags              []tags.ResourceTag `json:"tags,omitempty"`
    82  	//the key must be:"_sys_enterprise_project_id"
    83  	SysTags []tags.ResourceTag `json:"sys_tags,omitempty"`
    84  }
    85  
    86  type CsvProperty struct {
    87  	Delimiter string `json:"delimiter"`
    88  }
    89  
    90  type GetOpts struct {
    91  	StartPartitionId string `q:"start_partitionId"`
    92  	// maximum number of partitions per request
    93  	//   value range:1~1000。
    94  	//   default:100。
    95  	LimitPartitions int `q:"limit_partitions"`
    96  }
    97  
    98  type ListStreamsOpts struct {
    99  	// maximum number of stream per request
   100  	// value range:1~100。
   101  	// default:10。
   102  	Limit int `q:"limit"`
   103  	// Return the stream list from this stream, the returned stream list does not include this stream name.
   104  	// do not pass this field when querying on the first page. When the returned result has_more_streams is true,
   105  	// the next page query is performed, and start_stream_name is the last stream name of the first page query result.
   106  	StartStreamName string `q:"start_stream_name"`
   107  }
   108  
   109  type UpdatePartitionOpt struct {
   110  	StreamName string `json:"stream_name" required:"true"`
   111  	// The number of target partitions to be changed.
   112  	// The value is an integer greater than 0.
   113  	// The set value greater than the current number of partitions means expansion,
   114  	// and less than the current number of partitions means shrinking.
   115  	//Notice:
   116  	// The total number of expansion and contraction times for each channel in an hour is up to 5 times,
   117  	// and if the expansion or contraction operation succeeds once within an hour, the expansion or contraction
   118  	// operation is not allowed in the last hour.
   119  	// Minimum value: 0
   120  	TargetPartitionCount int `json:"target_partition_count" required:"true"`
   121  }
   122  
   123  type CreatePolicyOpt struct {
   124  	StreamId string `json:"stream_id" required:"true"`
   125  	// Authorized users.
   126  	// If authorized to the specified tenant, the format is: domainName.*;
   127  	// if authorized to the specified sub-user under the tenant, the format is: domainName.userName;
   128  	//Support for adding multiple accounts, separated by ",", for example: domainName1.userName1,domainName2.userName2;
   129  	PrincipalName string `json:"principal_name" required:"true"`
   130  	// Authorized operation type: putRecords,getRecords
   131  	ActionType string `json:"action_type" required:"true"`
   132  	//Authorization impact type: accept,
   133  	Effect string `json:"effect" required:"true"`
   134  }
   135  
   136  func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*golangsdk.Result, error) {
   137  	b, err := golangsdk.BuildRequestBody(opts, "")
   138  	if err != nil {
   139  		return nil, err
   140  	}
   141  
   142  	var r golangsdk.Result
   143  	_, r.Err = c.Post(rootURL(c), b, nil, &golangsdk.RequestOpts{
   144  		MoreHeaders: map[string]string{
   145  			"Content-Type": "application/json",
   146  			"region":       c.AKSKAuthOptions.Region,
   147  		},
   148  	})
   149  	return &r, r.Err
   150  }
   151  
   152  func Get(c *golangsdk.ServiceClient, streamName string, opts GetOpts) (*StreamDetail, error) {
   153  	query, err := golangsdk.BuildQueryString(opts)
   154  	if err != nil {
   155  		return nil, err
   156  	}
   157  
   158  	url := resourceURL(c, streamName)
   159  	url += query.String()
   160  
   161  	var rst StreamDetail
   162  	_, err = c.Get(url, &rst, &golangsdk.RequestOpts{
   163  		MoreHeaders: map[string]string{
   164  			"Content-Type": "application/json",
   165  			"region":       c.AKSKAuthOptions.Region,
   166  		},
   167  	})
   168  
   169  	if err == nil {
   170  		return &rst, nil
   171  	}
   172  	return nil, err
   173  }
   174  
   175  func Delete(c *golangsdk.ServiceClient, streamName string) *golangsdk.ErrResult {
   176  	var r golangsdk.ErrResult
   177  	_, r.Err = c.Delete(resourceURL(c, streamName), &golangsdk.RequestOpts{
   178  		MoreHeaders: map[string]string{
   179  			"Content-Type": "application/json",
   180  			"region":       c.AKSKAuthOptions.Region,
   181  		},
   182  	})
   183  	return &r
   184  }
   185  
   186  func List(c *golangsdk.ServiceClient, opts ListStreamsOpts) (*ListResult, error) {
   187  	query, err := golangsdk.BuildQueryString(opts)
   188  	if err != nil {
   189  		return nil, err
   190  	}
   191  
   192  	url := rootURL(c) + query.String()
   193  
   194  	var rst ListResult
   195  	_, err = c.Get(url, &rst, &golangsdk.RequestOpts{
   196  		MoreHeaders: map[string]string{
   197  			"Content-Type": "application/json",
   198  			"region":       c.AKSKAuthOptions.Region,
   199  		},
   200  	})
   201  	if err == nil {
   202  		return &rst, nil
   203  	}
   204  	return nil, err
   205  }
   206  
   207  func UpdatePartition(c *golangsdk.ServiceClient, name string, opts UpdatePartitionOpt) (*golangsdk.Result, error) {
   208  	b, err := golangsdk.BuildRequestBody(opts, "")
   209  	if err != nil {
   210  		return nil, err
   211  	}
   212  
   213  	var r golangsdk.Result
   214  	_, err = c.Put(resourceURL(c, name), b, nil, &golangsdk.RequestOpts{
   215  		MoreHeaders: map[string]string{
   216  			"Content-Type": "application/json",
   217  			"region":       c.AKSKAuthOptions.Region,
   218  		},
   219  	})
   220  	return &r, err
   221  }
   222  
   223  func CreatePolicy(c *golangsdk.ServiceClient, streamName string, opts CreatePolicyOpt) (*golangsdk.Result, error) {
   224  	b, err := golangsdk.BuildRequestBody(opts, "")
   225  	if err != nil {
   226  		return nil, err
   227  	}
   228  
   229  	var r golangsdk.Result
   230  	_, err = c.Post(policiesURL(c, streamName), b, nil, &golangsdk.RequestOpts{
   231  		MoreHeaders: map[string]string{
   232  			"Content-Type": "application/json",
   233  			"region":       c.AKSKAuthOptions.Region,
   234  		},
   235  	})
   236  	return &r, err
   237  }
   238  
   239  func ListPolicies(c *golangsdk.ServiceClient, streamName string) (*ListPolicyResult, error) {
   240  	var rst ListPolicyResult
   241  	_, err := c.Get(policiesURL(c, streamName), &rst, &golangsdk.RequestOpts{
   242  		MoreHeaders: map[string]string{
   243  			"Content-Type": "application/json",
   244  			"region":       c.AKSKAuthOptions.Region,
   245  		},
   246  	})
   247  	if err == nil {
   248  		return &rst, nil
   249  	}
   250  	return nil, err
   251  }