fog-hadoop 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +38 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/CONTRIBUTING.md +40 -0
- data/CONTRIBUTORS.md +1 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +51 -0
- data/Rakefile +112 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/yarn.md +91 -0
- data/fog-hadoop.gemspec +60 -0
- data/lib/fog/hadoop.rb +24 -0
- data/lib/fog/hadoop/compute.rb +35 -0
- data/lib/fog/hadoop/requests/compute/get_app_stats.rb +40 -0
- data/lib/fog/hadoop/requests/compute/get_app_stats_detail.rb +30 -0
- data/lib/fog/hadoop/requests/compute/get_info.rb +37 -0
- data/lib/fog/hadoop/requests/compute/get_metrics.rb +49 -0
- data/lib/fog/hadoop/requests/compute/get_node.rb +38 -0
- data/lib/fog/hadoop/requests/compute/list_nodes.rb +55 -0
- data/lib/fog/hadoop/script.rb +22 -0
- data/lib/fog/hadoop/utils/request.rb +27 -0
- data/lib/fog/hadoop/version.rb +5 -0
- data/spec/spec_helper.rb +6 -0
- data/supported.md +19 -0
- data/tests/hadoop/requests/compute/app_stats_tests.rb +44 -0
- data/tests/hadoop/requests/compute/info_tests.rb +32 -0
- data/tests/hadoop/requests/compute/metric_tests.rb +45 -0
- data/tests/hadoop/requests/compute/nodes_tests.rb +52 -0
- data/tests/helper.rb +22 -0
- metadata +275 -0
data/lib/fog/hadoop.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'fog/core'
|
2
|
+
require 'fog/json'
|
3
|
+
require 'fog/hadoop/utils/request'
|
4
|
+
|
5
|
+
module Fog
|
6
|
+
module Compute
|
7
|
+
autoload :Hadoop, File.expand_path('../hadoop/compute', __FILE__)
|
8
|
+
end
|
9
|
+
|
10
|
+
module Hadoop
|
11
|
+
extend Fog::Provider
|
12
|
+
|
13
|
+
|
14
|
+
# Miscs
|
15
|
+
## Startup Script
|
16
|
+
#autoload :Script, File.expand_path('../sakuracloud/script', __FILE__)
|
17
|
+
|
18
|
+
service(:compute, 'Compute')
|
19
|
+
|
20
|
+
def self.yarn_endpoint
|
21
|
+
"/ws/v1/cluster"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Hadoop < Fog::Service
|
4
|
+
requires :hadoop_compute_api_url
|
5
|
+
|
6
|
+
recognizes :compute_api_url
|
7
|
+
|
8
|
+
|
9
|
+
request_path 'fog/hadoop/requests/compute'
|
10
|
+
request :get_info
|
11
|
+
request :get_app_stats
|
12
|
+
request :get_app_stats_detail
|
13
|
+
request :get_metrics
|
14
|
+
request :get_node
|
15
|
+
request :list_nodes
|
16
|
+
|
17
|
+
class Real
|
18
|
+
include Fog::Hadoop::Utils::Request
|
19
|
+
|
20
|
+
def initialize(options = {})
|
21
|
+
|
22
|
+
@compute_api_url = options[:hadoop_compute_api_url] || 'https://localhost:8088/'
|
23
|
+
Fog.credentials[:@compute_api_url] = options[:hadoop_compute_api_url]
|
24
|
+
@connection = Fog::Core::Connection.new(@compute_api_url)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Mock
|
29
|
+
def initialize(options = {})
|
30
|
+
@compute_api_url = options[:hadoop_compute_api_url] || 'https://localhost:8088/'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end #SakuraCloud
|
34
|
+
end #Compute
|
35
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Hadoop
|
4
|
+
class Real
|
5
|
+
def get_app_stats
|
6
|
+
request(
|
7
|
+
:expects => [200, 203],
|
8
|
+
:method => 'GET',
|
9
|
+
:path => "#{Fog::Hadoop.yarn_endpoint}/appstatistics"
|
10
|
+
).body["appStatInfo"]["statItem"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class Mock
|
14
|
+
def get_app_stats
|
15
|
+
response = Excon::Response.new
|
16
|
+
response.status = 200
|
17
|
+
response.body =
|
18
|
+
[
|
19
|
+
{
|
20
|
+
"state" => "accepted",
|
21
|
+
"type" => "mapreduce",
|
22
|
+
"count" => 4
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"state" => "running",
|
26
|
+
"type" => "mapreduce",
|
27
|
+
"count" => 1
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"state" => "finished",
|
31
|
+
"type" => "mapreduce",
|
32
|
+
"count" => 7
|
33
|
+
}
|
34
|
+
]
|
35
|
+
response
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Hadoop
|
4
|
+
class Real
|
5
|
+
def get_app_stats_detail(options = {})
|
6
|
+
request(
|
7
|
+
:expects => [200, 203],
|
8
|
+
:method => 'GET',
|
9
|
+
:path => "#{Fog::Hadoop.yarn_endpoint}/appstatistics?#{URI.encode_www_form(options)}"
|
10
|
+
).body["appStatInfo"]["statItem"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class Mock
|
14
|
+
def get_app_stats_detail(options = {})
|
15
|
+
response = Excon::Response.new
|
16
|
+
response.status = 200
|
17
|
+
response.body =
|
18
|
+
[
|
19
|
+
{
|
20
|
+
"state" => "accepted",
|
21
|
+
"type" => "mapreduce",
|
22
|
+
"count" => 4
|
23
|
+
}
|
24
|
+
]
|
25
|
+
response
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Hadoop
|
4
|
+
class Real
|
5
|
+
def get_info
|
6
|
+
request(
|
7
|
+
:expects => [200, 203],
|
8
|
+
:method => 'GET',
|
9
|
+
:path => "#{Fog::Hadoop.yarn_endpoint}/info"
|
10
|
+
).body["clusterInfo"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class Mock
|
14
|
+
def get_info
|
15
|
+
response = Excon::Response.new
|
16
|
+
response.status = 200
|
17
|
+
response.body =
|
18
|
+
{
|
19
|
+
"id" => 1324053971963,
|
20
|
+
"startedOn" => 1324053971963,
|
21
|
+
"state" => "STARTED",
|
22
|
+
"resourceManagerVersion" => "0.23.1-SNAPSHOT",
|
23
|
+
"resourceManagerBuildVersion" => "0.23.1-SNAPSHOT from 1214049 by user1"\
|
24
|
+
" source checksum 050cd664439d931c8743a6428fd6a693",
|
25
|
+
"resourceManagerVersionBuiltOn" => "Tue Dec 13 22:12:48 CST 2011",
|
26
|
+
"hadoopVersion" => "0.23.1-SNAPSHOT",
|
27
|
+
"hadoopBuildVersion" => "0.23.1-SNAPSHOT from 1214049 by user1"\
|
28
|
+
" source checksum 11458df3bb77342dca5f917198fad328",
|
29
|
+
"hadoopVersionBuiltOn" => "Tue Dec 13 22:12:26 CST 2011"
|
30
|
+
|
31
|
+
}
|
32
|
+
response
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Hadoop
|
4
|
+
class Real
|
5
|
+
def get_metrics
|
6
|
+
request(
|
7
|
+
:expects => 200,
|
8
|
+
:method => 'GET',
|
9
|
+
:path => "#{Fog::Hadoop.yarn_endpoint}/metrics"
|
10
|
+
).body["clusterMetrics"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class Mock
|
14
|
+
def get_metrics
|
15
|
+
response = Excon::Response.new
|
16
|
+
response.status = 200
|
17
|
+
response.body =
|
18
|
+
{
|
19
|
+
"appsSubmitted" => 0,
|
20
|
+
"appsCompleted" => 0,
|
21
|
+
"appsPending" => 0,
|
22
|
+
"appsRunning" => 0,
|
23
|
+
"appsFailed" => 0,
|
24
|
+
"appsKilled" => 0,
|
25
|
+
"reservedMB" => 0,
|
26
|
+
"availableMB" => 17408,
|
27
|
+
"allocatedMB" => 0,
|
28
|
+
"reservedVirtualCores" => 0,
|
29
|
+
"availableVirtualCores" => 7,
|
30
|
+
"allocatedVirtualCores" => 1,
|
31
|
+
"containersAllocated" => 0,
|
32
|
+
"containersReserved" => 0,
|
33
|
+
"containersPending" => 0,
|
34
|
+
"totalMB" => 17408,
|
35
|
+
"totalVirtualCores" => 8,
|
36
|
+
"totalNodes" => 1,
|
37
|
+
"lostNodes" => 0,
|
38
|
+
"unhealthyNodes" => 0,
|
39
|
+
"decommissionedNodes" => 0,
|
40
|
+
"rebootedNodes" => 0,
|
41
|
+
"activeNodes" => 1
|
42
|
+
}
|
43
|
+
|
44
|
+
response
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Hadoop
|
4
|
+
class Real
|
5
|
+
def get_node(node_ref)
|
6
|
+
request(
|
7
|
+
:expects => [200, 203],
|
8
|
+
:method => 'GET',
|
9
|
+
:path => "#{Fog::Hadoop.yarn_endpoint}/nodes/#{node_ref}"
|
10
|
+
).body["node"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class Mock
|
14
|
+
def get_node(node_ref)
|
15
|
+
response = Excon::Response.new
|
16
|
+
response.status = 200
|
17
|
+
response.body =
|
18
|
+
{
|
19
|
+
"rack" => "\/default-rack",
|
20
|
+
"state" => "NEW",
|
21
|
+
"id" => "h2:1235",
|
22
|
+
"nodeHostName" => "h2",
|
23
|
+
"nodeHTTPAddress" => "h2:2",
|
24
|
+
"healthStatus" => "Healthy",
|
25
|
+
"lastHealthUpdate" => 1324056895432,
|
26
|
+
"healthReport" => "Healthy",
|
27
|
+
"numContainers" => 0,
|
28
|
+
"usedMemoryMB" => 0,
|
29
|
+
"availMemoryMB" => 5120,
|
30
|
+
"usedVirtualCores" => 0,
|
31
|
+
"availableVirtualCores" => 8
|
32
|
+
}
|
33
|
+
response
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Hadoop
|
4
|
+
class Real
|
5
|
+
def list_nodes
|
6
|
+
request(
|
7
|
+
:expects => 200,
|
8
|
+
:method => 'GET',
|
9
|
+
:path => "#{Fog::Hadoop.yarn_endpoint}/nodes"
|
10
|
+
).body["nodes"]["node"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class Mock
|
14
|
+
def list_nodes
|
15
|
+
response = Excon::Response.new
|
16
|
+
response.status = 200
|
17
|
+
response.body =
|
18
|
+
[
|
19
|
+
{
|
20
|
+
"rack" => "\/default-rack",
|
21
|
+
"state" => "NEW",
|
22
|
+
"id" => "h2:1235",
|
23
|
+
"nodeHostName" => "h2",
|
24
|
+
"nodeHTTPAddress" => "h2:2",
|
25
|
+
"healthStatus" => "Healthy",
|
26
|
+
"lastHealthUpdate" => 1324056895432,
|
27
|
+
"healthReport" => "Healthy",
|
28
|
+
"numContainers" => 0,
|
29
|
+
"usedMemoryMB" => 0,
|
30
|
+
"availMemoryMB" => 8192,
|
31
|
+
"usedVirtualCores" => 0,
|
32
|
+
"availableVirtualCores" => 8
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"rack" => "\/default-rack",
|
36
|
+
"state" => "NEW",
|
37
|
+
"id" => "h1:1234",
|
38
|
+
"nodeHostName" => "h1",
|
39
|
+
"nodeHTTPAddress" => "h1:2",
|
40
|
+
"healthStatus" => "Healthy",
|
41
|
+
"lastHealthUpdate" => 1324056895092,
|
42
|
+
"healthReport" => "Healthy",
|
43
|
+
"numContainers" => 0,
|
44
|
+
"usedMemoryMB" => 0,
|
45
|
+
"availMemoryMB" => 8192,
|
46
|
+
"usedVirtualCores" => 0,
|
47
|
+
"availableVirtualCores" => 8
|
48
|
+
}
|
49
|
+
]
|
50
|
+
response
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fog
|
2
|
+
module Hadoop
|
3
|
+
class Script < Fog::Service
|
4
|
+
|
5
|
+
class Real
|
6
|
+
include Fog::Hadoop::Utils::Request
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
|
10
|
+
|
11
|
+
@connection = Fog::Core::Connection.new(@service_api_url)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Mock
|
16
|
+
def initialize(options={})
|
17
|
+
@service_api_url = options[:service_api_url]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Hadoop
|
5
|
+
module Utils
|
6
|
+
module Request
|
7
|
+
def request(params)
|
8
|
+
response = parse @connection.request(params)
|
9
|
+
|
10
|
+
response
|
11
|
+
## SakuraCloud API returns Japanese message.
|
12
|
+
# This wrapper decodes and show message to be human readble.
|
13
|
+
rescue Excon::Errors::HTTPStatusError => e
|
14
|
+
Fog::Logger.warning ::JSON.parse(e.response.body)['error_msg']
|
15
|
+
raise e
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def parse(response)
|
20
|
+
return response if response.body.empty?
|
21
|
+
response.body = Fog::JSON.decode(response.body)
|
22
|
+
response
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/supported.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Supported Hadoop Projects
|
2
|
+
|
3
|
+
## Supported
|
4
|
+
|
5
|
+
| Project | Fog Type | API Version(s) | Compliance | Notes |
|
6
|
+
|------------------|---------------|----------------|------------|-------|
|
7
|
+
| Yarn | Compute | v1 | TBD | |
|
8
|
+
| Hdfs | Volume | v1 | TBD | |
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
## YARN
|
13
|
+
|
14
|
+
| Service | GET |Notes |
|
15
|
+
|------------------|---------------|-------------------------------------|
|
16
|
+
| Yarn | Info |/ws/v1/cluster/info |
|
17
|
+
| | AppStats |/ws/v1/cluster/appstatistics |
|
18
|
+
| | Metrics |/ws/v1/cluster/metrics |
|
19
|
+
| | Nodes |/ws/v1/cluster/nodes |
|
@@ -0,0 +1,44 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:hadoop] | app stats request', ['hadoop', 'compute']) do
|
2
|
+
|
3
|
+
@app_stats_format = {
|
4
|
+
"state" => String,
|
5
|
+
"type" => String,
|
6
|
+
"count" => Integer
|
7
|
+
}
|
8
|
+
|
9
|
+
tests('success') do
|
10
|
+
tests('#get_app_stats') do
|
11
|
+
stats = hadoop_compute_service.get_app_stats
|
12
|
+
test 'returns a Hash' do
|
13
|
+
stats.body.is_a? Array
|
14
|
+
end
|
15
|
+
if Fog.mock?
|
16
|
+
tests('Info').formats(@app_stats_format, false) do
|
17
|
+
stats.body.first
|
18
|
+
end
|
19
|
+
tests('Info').formats(@app_stats_format, false) do
|
20
|
+
stats.body.last
|
21
|
+
end
|
22
|
+
else
|
23
|
+
returns(200) { stats.status }
|
24
|
+
returns(true) { stats.body.is_a? Hash }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
tests('#get_app_stats_detail') do
|
29
|
+
stats_detail = hadoop_compute_service.get_app_stats_detail(:states => "accepted")
|
30
|
+
test 'returns a Hash' do
|
31
|
+
stats_detail.body.is_a? Array
|
32
|
+
end
|
33
|
+
if Fog.mock?
|
34
|
+
tests('Info').formats(@app_stats_format, false) do
|
35
|
+
stats_detail.body.first
|
36
|
+
end
|
37
|
+
else
|
38
|
+
returns(200) { stats_detail.status }
|
39
|
+
returns(true) { stats_detail.body.is_a? Hash }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|