Permalink
Browse files

added working node model and routes, job.rb needs refactoring and cle…

…anup, but this Closes #2
  • Loading branch information...
Pete Skomoroch
Pete Skomoroch committed May 24, 2009
1 parent 1a71e9f commit f8168aef33aa37cc5345a163702b5646c900fb54
@@ -0,0 +1,99 @@
+class NodesController < ApplicationController
+ layout 'green'
+
+
+ before_filter :find_job
+
+ # GET /nodes
+ # GET /nodes.xml
+ def index
+ @nodes = Node.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @nodes }
+ end
+ end
+
+ # GET /nodes/1
+ # GET /nodes/1.xml
+ def show
+ @node = Node.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @node }
+ end
+ end
+
+ # GET /nodes/new
+ # GET /nodes/new.xml
+ def new
+ @node = @job.nodes.build
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @node }
+ end
+ end
+
+ # GET /nodes/1/edit
+ def edit
+ @node = @job.nodes.find(params[:id])
+ end
+
+ # POST /nodes
+ # POST /nodes.xml
+ def create
+ @node = Node.new(params[:node])
+
+ respond_to do |format|
+ if (@job.nodes << @node)
+ flash[:notice] = 'Node was successfully created.'
+ format.html { redirect_to job_url(@job) }
+ format.xml { render :xml => @node, :status => :created, :location => @node }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @node.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /nodes/1
+ # PUT /nodes/1.xml
+ def update
+ @node = @job.nodes.find(params[:id])
+
+ respond_to do |format|
+ if @node.update_attributes(params[:node])
+ flash[:notice] = 'Node was successfully updated.'
+ format.html { redirect_to job_url(@job) }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @node.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /nodes/1
+ # DELETE /nodes/1.xml
+ def destroy
+ node = @job.nodes.find(params[:id])
+ @job.nodes.delete(node)
+
+ respond_to do |format|
+ format.html { redirect_to job_url(@job) }
+ format.xml { head :ok }
+ end
+ end
+
+private
+
+ def find_job
+ @job_id = params[:job_id]
+ return(redirect_to(jobs_url)) unless @job_id
+ @job = Job.find(@job_id)
+ end
+
+end
@@ -0,0 +1,2 @@
+module NodesHelper
+end
View
@@ -1,4 +1,6 @@
class Job < ActiveRecord::Base
+ has_many :nodes
+
include AASM
# Set defaults
@@ -196,19 +198,37 @@ def launch_cluster
puts bootscript_content
- @master_node = @ec2.run_instances(image_id=self.master_ami_id, min_count=1, max_count=1, group_ids=[APP_CONFIG['web_security_group'], self.master_security_group], key_name=self.keypair, user_data=bootscript_content, addressing_type = 'public', instance_type = self.instance_type, kernel_id = nil, ramdisk_id = nil, availability_zone = self.availability_zone, block_device_mappings = nil)
- @master_instance_id = @master_node[0][:aws_instance_id]
- @master_instance_state = @master_node[0][:aws_state]
+ node_description = @ec2.run_instances(image_id=self.master_ami_id, min_count=1, max_count=1, group_ids=[APP_CONFIG['web_security_group'], self.master_security_group], key_name=self.keypair, user_data=bootscript_content, addressing_type = 'public', instance_type = self.instance_type, kernel_id = nil, ramdisk_id = nil, availability_zone = self.availability_zone, block_device_mappings = nil)
+
+ @node = Node.new(:job_id => self.id)
+ @node.save
+ update_node(@node, node_description)
+
+
+ @master_instance_id = node_description[0][:aws_instance_id]
+ @master_instance_state = node_description[0][:aws_state]
# wait until instance has launched, then we can set hostname etc...
while @master_instance_state != 'running'
- @master_node = @ec2.describe_instances(@master_instance_id)
- @master_instance_state = @master_node[0][:aws_state]
+ node_description = @ec2.describe_instances(@master_instance_id)
+ update_node(@node, node_description)
+ # need to set Node properties based on node_description response...
+ # self.nodes.build(node_description[0])
+ # self.nodes.build({:aws_image_id => "ami-e444444d"})
+ # acme = Company.new({:name => "Acme, Inc"})
+ # acme.employees.build({:first_name => "John"})
+ # acme.employees.build({:first_name => "Mary"})
+ # acme.employees.build({:first_name => "Sue"})
+ # acme.save
+
+
+
+ @master_instance_state = node_description[0][:aws_state]
self.save
sleep 10
end
- self.set_master_instance_metadata(@master_node)
+ self.set_master_instance_metadata(node_description)
######## Launch Worker Nodes ##########
@@ -250,6 +270,22 @@ def launch_cluster
end
end
+
+ def update_node(node, node_description)
+ node.aws_image_id = node_description[0][:aws_image_id]
+ node.aws_instance_id = node_description[0][:aws_instance_id]
+ node.aws_state = node_description[0][:aws_state]
+ node.dns_name = node_description[0][:dns_name]
+ node.ssh_key_name = node_description[0][:ssh_key_name]
+ node.aws_groups = node_description[0][:aws_groups].join(" ")
+ node.private_dns_name = node_description[0][:private_dns_name]
+ node.aws_instance_type = node_description[0][:aws_instance_type]
+ node.aws_launch_time = node_description[0][:aws_launch_time]
+ node.aws_availability_zone = node_description[0][:aws_availability_zone]
+ node.is_configured = false
+ node.save
+ end
+
def terminate_cluster_later
# push cluster termination off to background using delayed_job
View
@@ -0,0 +1,3 @@
+class Node < ActiveRecord::Base
+ belongs_to :job
+end
@@ -2,6 +2,7 @@
<%= link_to 'Back', jobs_path %> |
<%= link_to 'Cancel Job', cancel_job_path(@job), :method => :put if @job.is_cancellable? %>
+<h2>Job Details:</h2>
<table border="0" width="100%" cellpadding="10">
<tr>
@@ -169,3 +170,36 @@
</tr>
</table>
+<h2>Cluster Node Information:</h2>
+<table>
+<tr>
+ <th>Aws image</th>
+ <th>Aws instance</th>
+ <th>Aws state</th>
+ <th>Dns name</th>
+ <th>Ssh key name</th>
+ <th>Aws groups</th>
+ <th>Private dns name</th>
+ <th>Aws instance type</th>
+ <th>Aws launch time</th>
+ <th>availability zone</th>
+ <th>Is configured</th>
+</tr>
+
+<% @job.nodes.each do |n| %>
+ <tr>
+ <td><%=h n.aws_image_id %></td>
+ <td><%=h n.aws_instance_id %></td>
+ <td><%=h n.aws_state %></td>
+ <td><%=h n.dns_name %></td>
+ <td><%=h n.ssh_key_name %></td>
+ <td><%=h n.aws_groups %></td>
+ <td><%=h n.private_dns_name %></td>
+ <td><%=h n.aws_instance_type %></td>
+ <td><%=h n.aws_launch_time %></td>
+ <td><%=h n.aws_availability_zone %></td>
+ <td><%=h n.is_configured %></td>
+ </tr>
+<% end %>
+
+</table>
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>Nodes: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield %>
+
+</body>
+</html>
@@ -0,0 +1,60 @@
+<h1>Editing node</h1>
+
+<% form_for(@node) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :job %><br />
+ <%= f.text_field :job %>
+ </p>
+ <p>
+ <%= f.label :aws_image_id %><br />
+ <%= f.text_area :aws_image_id %>
+ </p>
+ <p>
+ <%= f.label :aws_instance_id %><br />
+ <%= f.text_area :aws_instance_id %>
+ </p>
+ <p>
+ <%= f.label :aws_state %><br />
+ <%= f.text_area :aws_state %>
+ </p>
+ <p>
+ <%= f.label :dns_name %><br />
+ <%= f.text_area :dns_name %>
+ </p>
+ <p>
+ <%= f.label :ssh_key_name %><br />
+ <%= f.text_area :ssh_key_name %>
+ </p>
+ <p>
+ <%= f.label :aws_groups %><br />
+ <%= f.text_area :aws_groups %>
+ </p>
+ <p>
+ <%= f.label :private_dns_name %><br />
+ <%= f.text_area :private_dns_name %>
+ </p>
+ <p>
+ <%= f.label :aws_instance_type %><br />
+ <%= f.text_area :aws_instance_type %>
+ </p>
+ <p>
+ <%= f.label :aws_launch_time %><br />
+ <%= f.text_area :aws_launch_time %>
+ </p>
+ <p>
+ <%= f.label :aws_availability_zone %><br />
+ <%= f.text_area :aws_availability_zone %>
+ </p>
+ <p>
+ <%= f.label :is_configured %><br />
+ <%= f.check_box :is_configured %>
+ </p>
+ <p>
+ <%= f.submit 'Update' %>
+ </p>
+<% end %>
+
+<%= link_to 'Show', @node %> |
+<%= link_to 'Back', nodes_path %>
@@ -0,0 +1,37 @@
+<h1>Listing nodes for Job <%= @job.id %></h1>
+
+<table>
+ <tr>
+ <th>Job</th>
+ <th>Aws image</th>
+ <th>Aws instance</th>
+ <th>Aws state</th>
+ <th>Dns name</th>
+ <th>Ssh key name</th>
+ <th>Aws groups</th>
+ <th>Private dns name</th>
+ <th>Aws instance type</th>
+ <th>Aws launch time</th>
+ <th>Aws availability zone</th>
+ <th>Is configured</th>
+ </tr>
+
+<% @job.nodes.each do |node| %>
+ <tr>
+ <td><%=h node.job_id %></td>
+ <td><%=h node.aws_image_id %></td>
+ <td><%=h node.aws_instance_id %></td>
+ <td><%=h node.aws_state %></td>
+ <td><%=h node.dns_name %></td>
+ <td><%=h node.ssh_key_name %></td>
+ <td><%=h node.aws_groups %></td>
+ <td><%=h node.private_dns_name %></td>
+ <td><%=h node.aws_instance_type %></td>
+ <td><%=h node.aws_launch_time %></td>
+ <td><%=h node.aws_availability_zone %></td>
+ <td><%=h node.is_configured %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
Oops, something went wrong.

0 comments on commit f8168ae

Please sign in to comment.