Permalink
Browse files

[cm] Includes parcel management which includes:

  * Determinig the latest parcel version for a given package
  * Downloading the latest parcel
  * Distributing parcel to all hosts
  * Activating the parcel
  • Loading branch information...
1 parent 2fc464e commit 56165b83169adb9732f88c9d79af8ff82f6ab540 @ashrithr ashrithr committed Mar 20, 2014
@@ -0,0 +1,32 @@
+define cm::api::parcels::activate($product_name = 'CDH', $product_version = '') {
+ require cm::api::params
+
+ $cluster_name = $cm::params::cm_cluster_name
+ $parcel_version = inline_template("<%=
+ require 'rubygems'
+ require 'json'
+ require 'open-uri'
+ JSON.parse(open(\"${cm::api::params::cm_domain}/api/${cm::api::params::api_version}/clusters/${cluster_name}/parcels\",
+ :http_basic_authentication => [\"${cm::params::cm_username}\", \"${cm::params::cm_password}\"]).string)['items'].map do |i|
+ i['version'] if(i['product'] == '${product_name}' && i['version'] =~ /${product_version}/)
+ end.compact!.first
+ %>")
+
+ # Distribute parcels
+ curl { "activate-parcel-${product_name}-${product_version}":
+ domain => "http://${::cm::params::cm_server_host}:${::cm::params::cm_api_port}",
+ post => "/api/${::cm::api::params::api_version}/clusters/${cluster_name}/parcels/products/${product_name}/versions/${parcel_version}/commands/activate",
+ parameters => "{}",
+ request_type => 'json',
+ username => $::cm::params::cm_username,
+ password => $::cm::params::cm_password,
+ returns => '200',
+ only_if => {
+ 'get' => "/api/${::cm::api::params::api_version}/clusters/${cluster_name}/parcels/products/${product_name}/versions/${parcel_version}",
+ 'returns' => '200',
+ 'contains_key' => "stage",
+ 'contains_value' => 'DISTRIBUTED'
+ },
+ log_to => "/var/log/ankus/cm_api/parcels_${name}"
+ }
+}
@@ -0,0 +1,23 @@
+# Adds a host to existing cluster
+define cm::api::parcels::add_host_to_cluster {
+ require cm::api::params
+
+ curl { "add-host-${name}-to-cluster":
+ domain => "http://${::cm::params::cm_server_host}:${::cm::params::cm_api_port}",
+ post => "/api/${::cm::api::params::api_version}/clusters/${::cm::api::params::cluster_name}/hosts",
+ parameters => "{
+ 'items' => [
+ 'hostId' => '${name}'
+ ]
+ }",
+ request_type => 'json',
+ username => $::cm::params::cm_username,
+ password => $::cm::params::cm_password,
+ returns => '200',
+ only_if => {
+ 'get' => "/api/${::cm::api::params::api_version}/clusters/${::cm::api::params::cluster_name}/hosts",
+ 'does_not_contain' => "$..hostId[?(@ == '${name}')]"
+ },
+ log_to => "/var/log/ankus/cm_api/add_host_${name}_to_cluster"
+ }
+}
@@ -0,0 +1,28 @@
+# Downloads, distributes and activates parcels
+class cm::api::parcels::configure inherits cm::api::params {
+ # valid product name ['CDH', 'ACCUMULO', 'SOLR', 'IMPALA', 'SPARK']
+ cm::api::parcels::download { 'Download CDH':
+ product_name => 'CDH',
+ product_version => '4'
+ } ->
+ cm::api::parcels::download { 'Download IMPALA':
+ product_name => 'IMPALA'
+ } ->
+ # add hosts to the cluster specified
+ cm::api::parcels::add_host_to_cluster { $::cm::params::cm_nodes:
+ } ->
+ cm::api::parcels::distribute { 'Distribute CDH':
+ product_name => 'CDH',
+ product_version => '4'
+ } ->
+ cm::api::parcels::distribute { 'Distribute IMPALA':
+ product_name => 'IMPALA'
+ } ->
+ cm::api::parcels::activate { 'Activate CDH':
+ product_name => 'CDH',
+ product_version => '4'
+ } ->
+ cm::api::parcels::activate { 'Distribute IMPALA':
+ product_name => 'IMPALA'
+ }
+}
@@ -0,0 +1,42 @@
+define cm::api::parcels::distribute($product_name = 'CDH', $product_version = '') {
+ require cm::api::params
+
+ $cluster_name = $cm::params::cm_cluster_name
+ $parcel_version = inline_template("<%=
+ require 'rubygems'
+ require 'json'
+ require 'open-uri'
+ JSON.parse(open(\"${cm::api::params::cm_domain}/api/${cm::api::params::api_version}/clusters/${cluster_name}/parcels\",
+ :http_basic_authentication => [\"${cm::params::cm_username}\", \"${cm::params::cm_password}\"]).string)['items'].map do |i|
+ i['version'] if(i['product'] == '${product_name}' && i['version'] =~ /${product_version}/)
+ end.compact!.first
+ %>")
+
+ # Distribute parcels
+ curl { "distribute-parcel-${product_name}-${product_version}":
+ domain => "http://${::cm::params::cm_server_host}:${::cm::params::cm_api_port}",
+ post => "/api/${::cm::api::params::api_version}/clusters/${cluster_name}/parcels/products/${product_name}/versions/${parcel_version}/commands/startDistribution",
+ parameters => "{}",
+ request_type => 'json',
+ username => $::cm::params::cm_username,
+ password => $::cm::params::cm_password,
+ returns => '200',
+ only_if => {
+ 'get' => "/api/${::cm::api::params::api_version}/clusters/${cluster_name}/parcels/products/${product_name}/versions/${parcel_version}",
+ 'returns' => '200',
+ 'contains_key' => "stage",
+ 'contains_value' => 'DOWNLOADED'
+ },
+ log_to => "/var/log/ankus/cm_api/parcels_${name}"
+ }
+
+ # wait until parcel download get's completed
+ wait_for { "${product_name}-${product_version} parcel distribution completes":
+ query => "/usr/bin/curl --silent -X GET -u \"${::cm::params::cm_username}:${::cm::params::cm_password}\" -i -H \"content-type:application/json\" http://${::cm::params::cm_server_host}:${::cm::params::cm_api_port}/api/${::cm::api::params::api_version}/clusters/${cluster_name}/parcels/products/${product_name}/versions/${parcel_version}",
+ regex => '.*stage.*:.*DISTRIBUTED.*',
+ giveup_regex => '.*stage.*:.*ACTIVATED.*',
+ polling_frequency => 15,
+ max_retries => 100,
+ subscribe => Curl["distribute-parcel-${product_name}-${product_version}"]
+ }
+}
@@ -0,0 +1,44 @@
+# Downloads specified parcel and waits until download completes
+define cm::api::parcels::download($product_name = 'CDH', $product_version = '') {
+ require cm::api::params
+
+ $cluster_name = $cm::params::cm_cluster_name
+ $parcel_version = inline_template("<%=
+ require 'rubygems'
+ require 'json'
+ require 'open-uri'
+ JSON.parse(open(\"${cm::api::params::cm_domain}/api/${cm::api::params::api_version}/clusters/${cluster_name}/parcels\",
+ :http_basic_authentication => [\"${cm::params::cm_username}\", \"${cm::params::cm_password}\"]).string)['items'].map do |i|
+ i['version'] if(i['product'] == '${product_name}' && i['version'] =~ /${product_version}/)
+ end.compact!.first
+ %>")
+
+ # Issue download
+ curl { "download-parcel-${product_name}-${product_version}":
+ domain => "http://${::cm::params::cm_server_host}:${::cm::params::cm_api_port}",
+ post => "/api/${::cm::api::params::api_version}/clusters/${cluster_name}/parcels/products/${product_name}/versions/${parcel_version}/commands/startDownload",
+ parameters => "{}",
+ request_type => 'json',
+ username => $::cm::params::cm_username,
+ password => $::cm::params::cm_password,
+ returns => '200',
+ only_if => {
+ 'get' => "/api/${::cm::api::params::api_version}/clusters/${cluster_name}/parcels/products/${product_name}/versions/${parcel_version}",
+ 'returns' => '200',
+ 'contains_key' => "stage",
+ 'contains_value' => 'AVAILABLE_REMOTELY'
+ },
+ log_to => "/var/log/ankus/cm_api/parcels_${name}"
+ }
+
+ # wait until parcel download get's completed
+ wait_for { "${product_name}-${product_version} parcel download completes":
+ query => "/usr/bin/curl --silent -X GET -u \"${::cm::params::cm_username}:${::cm::params::cm_password}\" -i -H \"content-type:application/json\" http://${::cm::params::cm_server_host}:${::cm::params::cm_api_port}/api/${::cm::api::params::api_version}/clusters/${cluster_name}/parcels/products/${product_name}/versions/${parcel_version}",
+ regex => '.*stage.*:.*DOWNLOADED.*',
+ giveup_regex => '.*stage.*:.*DISTRIBUTED.*|.*stage.*:.*ACTIVATED.*',
+ polling_frequency => 15,
+ max_retries => 100,
+ refreshonly => true,
+ subscribe => Curl["download-parcel-${product_name}-${product_version}"]
+ }
+}

0 comments on commit 56165b8

Please sign in to comment.