Browse files

Revised deployment script and added files for Romualdo\'s diagrams.

  • Loading branch information...
1 parent d470f61 commit b2e33809df4974d0dbc14b422b67690d12f81dc4 John Paul Lewicke committed Dec 24, 2010
Showing with 178 additions and 7 deletions.
  1. +20 −0 README.md
  2. +13 −7 config/deploy.rb
  3. +33 −0 public/Diagrams/CreditLine.svg
  4. +112 −0 public/Diagrams/DiagramFunctions.js
View
20 README.md
@@ -47,6 +47,24 @@ So far, Rivulet has been successfully run on OS X and Ubuntu 10.10/10.4. It shou
9. Try Rivulet's client by opening up [http://localhost:4567/](http://localhost:4567/) in your web browser(only tested on Firefox so far).
+## Deploying Rivulet to EC2
+
+If you want to run Rivulet on [http://aws.amazon.com/ec2/](Amazon's Elastic Compute Cloud), you can download a copy of Rivulet(steps 1 and 2 above), and then take the following steps to launch your own copy of Rivulet on EC2:
+
+1. Signup for Amazon Web Services and configure your keys and environment variables the way they describe.
+
+2. Create a .caprc file in your home directory to store information about passwords and the locations of certain cryptographic keys. Mine looks sort of like this:
+`set :aws_private_key_path, "/Users/jplewicke/.ec2/ec2-keypair"
+set :password, "sudo_password"
+set :aws_private_key_name, "ec2-keypair"
+ssh_options[:keys] = %w(/Users/jplewicke/.ssh/id_rsa)`
+
+3. Make sure you have [https://github.com/capistrano/capistrano](Capistrano) installed by running `cap -V`.
+
+4. Change directories so that you're in the rivulet directory.
+
+5. Run `cap ec2:setup_server`.
+
## Using Rivulet
If you're trying to get Rivulet talking to another webapp, you'll probably want to reference either routes.rb or test.rb to see some examples of how to communicate with Rivulet from the command line.
@@ -65,4 +83,6 @@ The JQuery files in public/ contain their own licensing information.
## Acknowledgements
+Romualdo has helped a ton with testing and wrote an awesome graphical viewer for the current status of credit relationships.
+
Thanks to Romualdo and Miles for testing Rivulet on their setups, and to Ryan for getting this whole crazy Ripple thing going in the first place.
View
20 config/deploy.rb
@@ -132,6 +132,7 @@
download_rivulet
install_gems
run_install_test
+ launch_rivulet
end
desc "Update apt-get sources"
@@ -163,6 +164,10 @@
run "tar xvzf jruby-bin-1.5.6.tar.gz"
run "rm -f jruby-bin-1.5.6.tar.gz"
run "mv jruby-1.5.6 jruby"
+
+ #Setup JRUBY environment information. Need to have the right path for deploy user,
+ #sudoing, and any other users.
+
run "echo export JRUBY_HOME=`pwd`/jruby >> ~/.bashrc"
run "echo 'export PATH=$PATH:$JRUBY_HOME/bin' >> ~/.bashrc"
run "echo 'alias sudo=\"sudo env PATH=$PATH\"' >> ~/.bashrc"
@@ -188,7 +193,7 @@
desc "Download gems and Rivulet dependencies"
task :install_gems do
set :jruby_path, "/home/deploy/jruby/bin/jruby"
- #set :jruby_path, "jruby"
+ set :jruby_path, "jruby"
run "#{sudo} #{jruby_path} -S gem install bundler"
run ""
run "cd rivulet ; ls -altr"
@@ -199,11 +204,12 @@
task :run_install_test do
run "cd rivulet ; #{jruby_path} -S bundle exec test_init.rb"
run "cd rivulet ; #{jruby_path} -S bundle exec test.rb"
- run "ls -altr /etc/environment"
- run "#{sudo} cat /etc/sudoers"
- run "echo $PATH"
- run "#{sudo} echo $PATH"
- run "jruby -v"
- run "#{sudo} jruby -v"
end
+
+ desc "Launch the Rivulet website."
+ task :launch_rivulet do
+ run "#{sudo} nohup jruby -S bundle exec glassfish -p 80 > log.log < /dev/null 2>&1 &"
+ puts "Rivulet is now running at http://#{hostname} ."
+ puts "You can access this server by running \" ssh deploy@#{hostname} \"."
+ end
end
View
33 public/Diagrams/CreditLine.svg
@@ -0,0 +1,33 @@
+<?xml version="1.0" standalone="yes"?>
+
+<svg version="1.1" viewBox="0.0 0.0 240.0 110.0" fill="none" stroke="none" stroke-linecap="square" stroke-miterlimit="10" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<defs>
+<path id="DefleftBracket" d="M2.5728436 11.069412Q0.83846855 8.866287 -0.37246892 5.913162Q-1.5834064 2.960037 -1.5834064 -0.19621299Q-1.5834064 -2.993088 -0.67715645 -5.539963Q0.36971858 -8.508713 2.5728436 -11.446213L4.0884686 -11.446213Q2.6665936 -9.008713 2.2134686 -7.977463Q1.4947186 -6.352463 1.0884686 -4.602463Q0.58846855 -2.399338 0.58846855 -0.19621299Q0.58846855 5.444412 4.0884686 11.069412L2.5728436 11.069412Z" fill-rule="nonzero" fill="black">
+</path>
+</defs>
+<g id="Line_Point" display="inline">
+ <g id="line_with_Center" display="inline">
+ <line x1="40" y1="40" x2="200" y2="40" style="stroke:rgb(99,99,99);stroke-width:2"/>
+ <line x1="120" y1="30" x2="120" y2="50" style="stroke:rgb(99,99,99);stroke-width:2"/>
+ </g>
+ <circle id="balancePoint" cx="120" cy="40" r="0.3em" fill="#00ff00" stroke="#073763" stroke-width="2.0"></circle>
+ <text id="balanceText" x="120" y="13" font-size="14" font-family="arial" fill="Black" text-anchor="middle" > ..... </text>
+</g>
+<g id="Node1" display="inline">
+<circle id="Node1_circle" cx="40" cy="40" r="1.5em" fill="#f1c232" stroke="#073763" stroke-width="2.0"></circle>
+<text id="text1" x="40" y="45" font-size="14" font-family="arial" fill="Black" text-anchor="middle"> node1 </text>
+</g>
+<g id="Node2" display="inline">
+<circle id="Node2_circle" cx="200" cy="40" r="1.5em" fill="#3d85c6" stroke="#073763" stroke-width="2.0"/>
+<text id="text2" x="200" y="45" font-size="14" font-family="arial" fill="Black" text-anchor="middle"> node2 </text>
+</g>
+<g id="leftLimit">
+ <use id="leftBracket" x="120" y="40" xlink:href="#DefleftBracket" />
+ <text id="leftLimitText" x="115" y="70" font-size="14" font-family="arial" fill="Black" text-anchor="middle" >l</text>
+</g>
+<g id="rightLimit">
+ <use id="rightBracket" x="120" y="40" width="10" xlink:href="#DefleftBracket" transform="rotate(180, 120, 40)"/>
+ <text id="rightLimitText" x="125" y="70" font-size="14" font-family="arial" fill="Black" text-anchor="middle" >......r</text>
+</g>
+</svg>
+
View
112 public/Diagrams/DiagramFunctions.js
@@ -0,0 +1,112 @@
+var ta;
+var t1;
+var t2;
+var tb;
+var n1;
+var n2;
+var n2_c;
+var bp;
+var lp;
+var l_l;//reference to left bracket and text
+var l_l_t;//reference to left text
+var r_l_t;//reference to right text
+var JSONstring;
+var myJSONObject = {"from":"Alice","to":"Bob","credit_accepted":9.0,"credit_offered":10.0,"debit_accepted":0.0,"debit_offered":0.0,"credit_offered":7.0,"credit_accepted":2.0,"credit_held":0.0,"debit_held":0.0,"net_owed":2.0};
+function prepare(){
+ var S=document.getElementById("sv");
+ var SD=S.getSVGDocument();
+ t1=SD.getElementById('text1');
+ t2=SD.getElementById('text2');
+ tb=SD.getElementById('balanceText');
+ n1=SD.getElementById('Node1');
+ n2=SD.getElementById('Node2');
+ n2_c=SD.getElementById('Node2_circle');
+ lp=SD.getElementById('Line_Point');
+ l_l=SD.getElementById('leftLimit');
+ l_l_t=SD.getElementById('leftLimitText');
+ r_l=SD.getElementById('rightLimit');
+ r_l_t=SD.getElementById('rightLimitText');
+ bp=SD.getElementById('balancePoint');
+ ta= document.getElementById('resultTextArea');
+ parse_JSON(ta);
+}
+
+function parse_JSON(ref_to_text_area){
+ JSONstring = ref_to_text_area.value;
+ myJSONObject = eval('(' + JSONstring + ')');// eval is unsafe, to be replaced ?? myJSONObject = JSON.parse(JSONstring, reviver); non funziona, forse devo importare qualche libreria??
+ myJSONObject.net_owed = -myJSONObject.net_owed//inversion of owed: ?? in Rivulet net_owed=3 means "to" is owed 3 by "from"
+}
+
+
+function change(v){
+ n2_c.setAttribute("fill", v);
+}
+function changeText(ref,value){
+ var VariableString = ref.firstChild;
+ VariableString.nodeValue = value ;
+}
+
+
+function balanceToString(from,to,balance,curr){
+ var balString = "none";
+ if (balance > 0) { balString = from + " owes " + balance + curr + " to " + to + "." ;
+ }
+ else if (balance < 0) { balString = from + " is owed " + ((-1) * balance) + curr + " by " + to + "." ;
+ }
+ else { balString = from + " and " + to + " are even.";
+ }
+ //alert("Created string:" + balString);
+ return balString; // returns a string describing balance
+}
+function set_balance_text(from,to,balance,curr) {
+ var bs = balanceToString(from,to,balance,curr);
+ //alert(bs);
+ changeText(tb,bs);
+}
+//interprets the JSON answer to an action and Draws a diagram
+function interpretVisualize() {
+ parse_JSON(ta);
+ if (myJSONObject.from != null && myJSONObject.to != null ){
+ var scaleFactor = 45 / Math.max( 1, Math.abs(myJSONObject.net_owed), Math.min(myJSONObject.credit_accepted,myJSONObject.credit_offered),Math.min(myJSONObject.debit_accepted,myJSONObject.debit_offered));//calculate max between balace point and limits
+ //calculate and set position of elements, set visibilities
+ n1.setAttribute("display","inline");
+ n2.setAttribute("display","inline");
+ lp.setAttribute("display","inline");
+ //move left limit
+ var l_l_translate_str = (-1 * Math.min(myJSONObject.credit_accepted,myJSONObject.credit_offered) * scaleFactor);//calculate move for left limit
+ l_l.setAttribute("display","inline");
+ l_l.setAttribute("transform","translate(" + l_l_translate_str +", 0 )");
+ //left limit text
+ changeText(l_l_t, Math.min(myJSONObject.credit_accepted,myJSONObject.credit_offered));
+ //move right limit
+ var r_l_translate_str = (+1 * Math.min(myJSONObject.debit_accepted,myJSONObject.debit_offered) * scaleFactor);//calculate move for left limit
+ r_l.setAttribute("display","inline");
+ r_l.setAttribute("transform","translate(" + r_l_translate_str +", 0 )");
+ //right limit text
+ changeText(r_l_t, Math.min(myJSONObject.debit_accepted,myJSONObject.debit_offered));
+ //balance text
+ set_balance_text(myJSONObject.from , myJSONObject.to , myJSONObject.net_owed ,'')
+ changeText(t1,myJSONObject.from);
+ changeText(t2,myJSONObject.to);
+ //move balance point
+ bp.setAttribute("transform","translate(" + (myJSONObject.net_owed * scaleFactor) +", 0 )");
+ }
+ else if ( myJSONObject.user != null ){
+ n1.setAttribute("display","inline");
+ n2.setAttribute("display","none");
+ lp.setAttribute("display","none");
+ l_l.setAttribute("display","none");
+ r_l.setAttribute("display","none");
+ changeText(t1,myJSONObject.user);
+ changeText(tb,"");
+ }
+ else {
+ n1.setAttribute("display","none");
+ n2.setAttribute("display","none");
+ lp.setAttribute("display","none");
+ l_l.setAttribute("display","none");
+ r_l.setAttribute("display","none");
+ changeText(tb,"");
+ alert("non trovati from to user");
+ }
+}

0 comments on commit b2e3380

Please sign in to comment.