Class: Aliyun::Odps::Resources

Inherits:
ServiceObject show all
Defined in:
lib/aliyun/odps/model/resources.rb

Overview

Methods for Resources

Instance Attribute Summary

Attributes inherited from ServiceObject

#master

Instance Method Summary collapse

Methods inherited from ServiceObject

build, #client, #initialize, #project, service_pool

Constructor Details

This class inherits a constructor from Aliyun::Odps::ServiceObject

Instance Method Details

#create(name, type, options = {}) ⇒ Resource

Create resource in project

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :comment (String)

    specify resource comment

  • :table (String)

    specify table or table partition name, if your table have partitions, must contains partition spec together with format: tab1 partition(region=‘bj’,year=‘2011’)

  • :file (File|BinData)

    specify the source code or file path

Returns:

See Also:



67
68
69
70
71
72
73
74
75
76
# File 'lib/aliyun/odps/model/resources.rb', line 67

def create(name, type, options = {})
  Utils.stringify_keys!(options)
  path = "/projects/#{project.name}/resources/"

  headers = build_create_base_headers(name, type, options)
  body = build_create_base_body(options)

  location = client.post(path, headers: headers, body: body).headers['Location']
  Resource.new(name: name, resource_type: type, comment: options['comment'], location: location)
end

#delete(name) ⇒ true

Delete resource in project

Returns:

  • (true)

See Also:



107
108
109
110
111
# File 'lib/aliyun/odps/model/resources.rb', line 107

def delete(name)
  path = "/projects/#{project.name}/resources/#{name}"

  !!client.delete(path)
end

#get(name) ⇒ Resource Also known as: resource

Get resource of project

Returns:

See Also:



34
35
36
37
38
# File 'lib/aliyun/odps/model/resources.rb', line 34

def get(name)
  path = "/projects/#{project.name}/resources/#{name}"
  resp = client.get(path)
  build_resource(resp)
end

#get_meta(name) ⇒ Resource Also known as: head

Get resource information in project

Returns:

See Also:



48
49
50
51
52
# File 'lib/aliyun/odps/model/resources.rb', line 48

def get_meta(name)
  path = "/projects/#{project.name}/resources/#{name}"
  resp = client.head(path)
  build_resource(resp)
end

#list(options = {}) ⇒ List

List resources of project

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :name (String)

    specify resource name

  • :owner (String)

    specify resource owner

  • :marker (String)
  • :maxitems (String) — default: 1000

Returns:

See Also:



16
17
18
19
20
21
22
23
24
25
# File 'lib/aliyun/odps/model/resources.rb', line 16

def list(options = {})
  Utils.stringify_keys!(options)
  path = "/projects/#{project.name}/resources"
  query = Utils.hash_slice(options, 'name', 'owner', 'marker', 'maxitems')
  result = client.get(path, query: query).parsed_response

  Aliyun::Odps::List.build(result, %w(Resources Resource)) do |hash|
    Resource.new(hash)
  end
end

#update(name, type, options = {}) ⇒ true

Update resource in project

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :comment (String)

    specify resource comment

  • :table (String)

    specify table or table partition name

  • :file (File|Bin Data)

    specify the source code or file path

Returns:

  • (true)

See Also:



90
91
92
93
94
95
96
97
98
# File 'lib/aliyun/odps/model/resources.rb', line 90

def update(name, type, options = {})
  Utils.stringify_keys!(options)
  path = "/projects/#{project.name}/resources/#{name}"

  headers = build_create_base_headers(name, type, options)
  body = build_create_base_body(options)

  !!client.put(path, headers: headers, body: body)
end