cloudstore-developers

Removed large files

2/18/2014 1:35:25 PM

Details

diff --git a/distributed-jmeter/cloudscale/aws_distributed_jmeter.py b/distributed-jmeter/cloudscale/aws_distributed_jmeter.py
index a57466f..7eb9545 100644
--- a/distributed-jmeter/cloudscale/aws_distributed_jmeter.py
+++ b/distributed-jmeter/cloudscale/aws_distributed_jmeter.py
@@ -1,6 +1,7 @@
 import boto, boto.ec2
 import sys, os, time
 import paramiko
+import subprocess
 import logging
 from cloudscale import models
 
@@ -8,9 +9,8 @@ logger = logging.getLogger(__name__)
 
 class CreateInstance:
 
-    def __init__(self, config_path, cfg, key_pair, key_name, scenario_path, num_virtual_users, num_slaves):
+    def __init__(self, config_path, cfg, key_pair, key_name, scenario_path, num_slaves):
         self.scenario_path = scenario_path
-        self.num_virtual_users = num_virtual_users
         self.num_slaves = num_slaves
         self.key_pair = key_pair
         self.key_name = key_name
@@ -35,7 +35,7 @@ class CreateInstance:
         time.sleep(60) # wait for status checks
         self.log("Setting up master ...")
         self.setup_master(slaves, instance)
-        self.write_config(config_path, instance)
+        #self.write_config(config_path, instance)
 
     def log(self, msg, fin=0):
         logger.info(msg)
@@ -54,16 +54,19 @@ class CreateInstance:
         ssh = paramiko.SSHClient()
         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 
+        #ip_addr = '54.194.221.83'
+        ip_addr = instance.ip_address
+
         if self.key_pair:
-            ssh.connect(instance.ip_address, username="ubuntu", key_filename=os.path.abspath(self.key_pair))
+            ssh.connect(ip_addr, username="ubuntu", key_filename=os.path.abspath(self.key_pair))
         else:
-            ssh.connect(instance.ip_address, username="ubuntu", password="root")
+            ssh.connect(ip_addr, username="ubuntu", password="root")
 
         scp = paramiko.SFTPClient.from_transport(ssh.get_transport())
         dirname = os.path.abspath(os.path.dirname(__file__))
 
         self.log("Transfering jmeter_master.tar.gz ...")
-        scp.put( dirname + '/../../scripts/jmeter_master.tar.gz', 'jmeter.tar.gz')
+        scp.put( dirname + '/../scripts/jmeter_master.tar.gz', 'jmeter.tar.gz')
 
         self.log("Transfering JMeter scenario ...")
         scp.put( self.scenario_path, 'scenario.jmx')
@@ -74,29 +77,29 @@ class CreateInstance:
 
         ip_addresses = [instance.private_ip_address for instance in slaves]
         # ip_addresses = ['172.31.31.9', '172.31.26.205']
-        self.log( ip_addresses )
         cmd = "~/jmeter/bin/jmeter -n -t ~/scenario.jmx -R %s -l scenario.jtl -j scenario.log" % ",".join(ip_addresses)
-        self.log("Executing {0}".format(cmd))
+        self.log("Executing your JMeter scenario. This can take a while. Please wait ...")
         stdin, stdout, stderr = ssh.exec_command(cmd)
         # wait for JMeter to execute
         stdout.readlines()
 
         # get reports
-        userpath = "{0}/../static/results/{1}".format(dirname, os.path.basename(self.scenario_path)[:-4])
-        try:
-            os.makedirs(userpath)
-        except OSError as e:
-            if e.errno != 17:
-                raise
-            pass
+        resultspath = "{0}/../static/results/".format(dirname)
+
+        tmp_userpath = "/tmp/{0}".format(os.path.basename(self.scenario_path)[:-4])
+        os.makedirs(tmp_userpath, 0777)
+        scp.get("/home/ubuntu/scenario.log", "{0}/{1}".format(tmp_userpath, "scenario.log"))
+        scp.get("/home/ubuntu/scenario.jtl", "{0}/{1}".format(tmp_userpath, "scenario.jtl"))
 
-        scp.get("/home/ubuntu/scenario.log", "{0}/{1}".format(userpath, "scenario.log"))
-        scp.get("/home/ubuntu/scenario.jtl", "{0}/{1}".format(userpath, "scenario.jtl"))
+        cmd = "cp -r {0} {1}".format(tmp_userpath, resultspath)
+        p = subprocess.check_output(cmd.split())
 
         scp.close()
         ssh.close()
 
         self.log("Finished! You can now download report files.", 1)
+        instance_ids = [inst.id for inst in slaves] + [instance.id]
+        self.conn.terminate_instances(instance_ids=instance_ids)
 
     def setup_slaves(self, instances):
         for instance in instances:
@@ -111,7 +114,7 @@ class CreateInstance:
             scp = paramiko.SFTPClient.from_transport(ssh.get_transport())
             dirname = os.path.abspath(os.path.dirname(__file__))
             self.log("Transfering jmeter_slave.tar.gz ...")
-            scp.put( dirname + '/../../scripts/jmeter_slave.tar.gz', 'jmeter.tar.gz')
+            scp.put( dirname + '/../scripts/jmeter_slave.tar.gz', 'jmeter.tar.gz')
 
             self.log( "Installing Java 7 on slave ..." )
             _, stdout, _ = ssh.exec_command("sudo apt-get -y install openjdk-7-jdk; tar xvf jmeter.tar.gz")
diff --git a/distributed-jmeter/cloudscale/forms.py b/distributed-jmeter/cloudscale/forms.py
index e9a1ff1..cca38fa 100644
--- a/distributed-jmeter/cloudscale/forms.py
+++ b/distributed-jmeter/cloudscale/forms.py
@@ -2,4 +2,3 @@ from django import forms
 
 class UploadScenarioForm(forms.Form):
     scenario = forms.FileField()
-    virtual_users = forms.CharField(max_length=6)
\ No newline at end of file
diff --git a/distributed-jmeter/cloudscale/tasks.py b/distributed-jmeter/cloudscale/tasks.py
index 014b18f..cc94ba7 100644
--- a/distributed-jmeter/cloudscale/tasks.py
+++ b/distributed-jmeter/cloudscale/tasks.py
@@ -5,17 +5,21 @@ import os, subprocess
 import logging
 import time
 import sys
-import redis
 from cloudscale.aws_distributed_jmeter import CreateInstance
 from cloudscale.aws_distributed_jmeter import read_config
 from cloudscale.models import Log
 logger = logging.getLogger(__name__)
 
 @shared_task
-def run_tests(scenario_path, vu):
+def run_tests(scenario_path):
+    # sys.path.append("{0}/../../scripts/aws/".format(os.path.abspath(os.path.dirname(__file__))))
+    # print sys.path
+    # import run_test
+    #redis_instance = redis.Redis()
+    # logger.info("Calling program ...")
     basedir = os.path.abspath(os.path.dirname(__file__))
-    config_path = '%s/../config.ini' % basedir
+    config_path = '%s/../conf/config.ini' % basedir
     cfg = read_config(config_path)
     key_name = cfg.get('EC2', 'key_name')
     key_pair = cfg.get('EC2', 'key_pair')
-    CreateInstance(config_path, cfg, key_pair, key_name, scenario_path, vu, 2)
+    CreateInstance(config_path, cfg, key_pair, key_name, scenario_path, 2)
\ No newline at end of file
diff --git a/distributed-jmeter/cloudscale/views.py b/distributed-jmeter/cloudscale/views.py
index f48171c..9451d79 100644
--- a/distributed-jmeter/cloudscale/views.py
+++ b/distributed-jmeter/cloudscale/views.py
@@ -7,11 +7,12 @@ import logging
 from cloudscale import models
 import json
 from django.core.mail import send_mail
+from django.conf import settings
 
 logger = logging.getLogger(__name__)
 
 def home(request):
-    return render(request, 'home.html', {'form' : forms.UploadScenarioForm()})
+    return render(request, 'home.html', {'form' : forms.UploadScenarioForm(), 'url_prefix' : settings.URL_PREFIX})
 
 def upload(request):
     errors = False
@@ -30,14 +31,14 @@ def upload(request):
                 errors = True
             else:
                 filename = handle_uploaded_file(request.FILES['scenario'])
-                start_test(filename, request.POST['virtual_users'])
+                start_test(filename)
         else:
             messages.error(request, "You didn't fill in the form!")
             errors = True
     else:
         return redirect('/')
 
-    messages.success(request, "Your scenario was successfully uploaded and started. Results are available <a href=\"http://localhost:8000/report/{0}\">here</a>".format(os.path.basename(filename)[:-4]))
+    messages.success(request, "Your scenario was successfully uploaded and started. Results are available <a href=\"{1}/report/{0}\">here</a>".format(os.path.basename(filename)[:-4], settings.URL_PREFIX))
     return render(request, 'home.html', {'form' : form, 'errors' : errors})
 
 def handle_uploaded_file(file):
@@ -50,7 +51,7 @@ def handle_uploaded_file(file):
     destination.close()
     return scenario_path
 
-def start_test(scenario_path, vu):
+def start_test(scenario_path):
     from tasks import run_tests
     userpath = "{0}/../static/results/{1}".format(os.path.abspath(os.path.dirname(__file__)), os.path.basename(scenario_path)[:-4])
     try:
@@ -59,14 +60,14 @@ def start_test(scenario_path, vu):
         if e.errno != 17:
             raise
         pass
-    run_tests.delay(scenario_path, vu)
+    run_tests.delay(scenario_path)
 
 def report(request, id):
     dir = "{0}/../static/results/{1}".format(os.path.abspath(os.path.dirname(__file__)), id)
     error = None
     if not os.path.exists(dir):
         error = "Request with id {0} doesn't exist!"
-    return render(request, 'report.html', {'error' : error, 'id' : id})
+    return render(request, 'report.html', {'error' : error, 'id' : id, 'url_prefix' : settings.URL_PREFIX})
 
 def check(request, id):
     response = {}
@@ -88,7 +89,7 @@ def check(request, id):
     return HttpResponse(json.dumps(response), content_type="application/json")
 
 def about(request):
-    return render(request, 'about.html')
+    return render(request, 'about.html', {'url_prefix' : settings.URL_PREFIX})
 
 def contact(request):
     if request.method == 'POST':
diff --git a/distributed-jmeter/scripts/jmeter_master.tar.gz.txt b/distributed-jmeter/scripts/jmeter_master.tar.gz.txt
new file mode 100644
index 0000000..9c93a0a
--- /dev/null
+++ b/distributed-jmeter/scripts/jmeter_master.tar.gz.txt
@@ -0,0 +1 @@
+Get it on http://cloudscale.xlab.si/github/jmeter_master.tar.gz
diff --git a/distributed-jmeter/scripts/jmeter_slave.tar.gz.txt b/distributed-jmeter/scripts/jmeter_slave.tar.gz.txt
new file mode 100644
index 0000000..de629d6
--- /dev/null
+++ b/distributed-jmeter/scripts/jmeter_slave.tar.gz.txt
@@ -0,0 +1 @@
+Get it on http://cloudscale.xlab.si/github/jmeter_slave.tar.gz
diff --git a/distributed-jmeter/templates/about.html b/distributed-jmeter/templates/about.html
index c13cb05..13238d8 100644
--- a/distributed-jmeter/templates/about.html
+++ b/distributed-jmeter/templates/about.html
@@ -16,7 +16,7 @@
     <p>
         Currently we run distributed JMeter on one master instance and two slave instances
         on Amazon Web Services. If you have a need to increase that please
-        <a href="/contact">contact us</a>.
+        <a href="{{ url_prefix }}/contact">contact us</a>.
     </p>
 </div>
 {% endblock %}
\ No newline at end of file
diff --git a/distributed-jmeter/templates/home.html b/distributed-jmeter/templates/home.html
index 40ccdcb..df2743c 100644
--- a/distributed-jmeter/templates/home.html
+++ b/distributed-jmeter/templates/home.html
@@ -4,9 +4,12 @@
         <h1>How to use it</h1>
 
         <p class="lead">
-            Use <a href="http://jmeter.apache.org">JMeter GUI</a> to create scenario. Notice that your scenario must have <b><a href="http://jmeter.apache.org/usermanual/component_reference.html#Aggregate_Report">
-            Aggregate Report Listener</b></a> registered.<br /><br />
-            Then upload your JMeter script in form below and specify how many virtual users (VU) do you want per second.
+            Use the <a href="http://jmeter.apache.org">JMeter GUI</a> to create a scenario. Notice that your scenario must
+            have an <b>
+            <a href="http://jmeter.apache.org/usermanual/component_reference.html#Aggregate_Report">
+                Aggregate Report Listener
+            </a></b> registered.<br /><br />
+            Then upload your JMeter script in the form below and specify how many virtual users (VU) do you want per second.
         </p>
 
     </div>
@@ -31,7 +34,7 @@
                 {% endif %}
             {% endfor %}
         {% endif %}
-        <form action="/upload" method="post" name="upload-form"
+        <form action="{{ url_prefix }}/upload" method="post" name="upload-form"
                 {% if form.is_multipart %} enctype="multipart/form-data" {% endif %} >
             {% csrf_token %}
             <div class="form-group form-scenario-upload">
diff --git a/distributed-jmeter/templates/report.html b/distributed-jmeter/templates/report.html
index 60ec4d7..58bb394 100644
--- a/distributed-jmeter/templates/report.html
+++ b/distributed-jmeter/templates/report.html
@@ -1,4 +1,5 @@
 {% extends "base.html" %}
+{% load staticfiles %}
 {% block content %}
     <div class="{% if error %}alert alert-danger{% endif %}">
         {% if error %}
@@ -13,9 +14,9 @@
         <div class="log">
         </div>
         <div class="download-buttons">
-            <a href="/static/results/{{ id }}/scenario.jtl" id="download-jtl" class="btn disabled btn-success">
+            <a href="{{ url_prefix }}/static/results/{{ id }}/scenario.jtl" id="download-jtl" class="btn disabled btn-success">
                Download JTL file</a>
-            <a href="/static/results/{{ id }}/scenario.log" id="download-log" class="btn disabled btn-success">
+            <a href="{{ url_prefix }}/static/results/{{ id }}/scenario.log" id="download-log" class="btn disabled btn-success">
                Download LOG file
             </a>
         </div>
@@ -28,7 +29,7 @@
 <script type="text/javascript">
     timer = null
     function doPoll(finish) {
-        $.getJSON('/check/{{ id }}', function (json) {
+        $.getJSON('{{ url_prefix }}/check/{{ id }}', function (json) {
             processData(json)
             if (json['finished'] == 1)
             {
diff --git a/distributed-jmeter/webapp/settings.py b/distributed-jmeter/webapp/settings.py
index bb38827..04bdd5e 100644
--- a/distributed-jmeter/webapp/settings.py
+++ b/distributed-jmeter/webapp/settings.py
@@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/1.6/ref/settings/
 import os
 BASE_DIR = os.path.dirname(os.path.dirname(__file__))
 
-
+URL_PREFIX = ''
 # Quick-start development settings - unsuitable for production
 # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
 
@@ -80,7 +80,7 @@ USE_TZ = True
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/1.6/howto/static-files/
 
-STATIC_URL = '/static/'
+STATIC_URL = '{0}/static/'.format(URL_PREFIX)
 
 TEMPLATE_DIRS = (
     os.path.join(BASE_DIR, 'templates'),
@@ -164,3 +164,8 @@ LOGGING = {
     },
 }
 
+try:
+    from local_settings import *
+except ImportError:
+    pass
+
diff --git a/distributed-jmeter/webapp/urls.py b/distributed-jmeter/webapp/urls.py
index 2d32479..2f5d50f 100644
--- a/distributed-jmeter/webapp/urls.py
+++ b/distributed-jmeter/webapp/urls.py
@@ -1,13 +1,14 @@
 from django.conf.urls import patterns, include, url
-
+from django.conf import settings
 from django.contrib import admin
 admin.autodiscover()
 
+print 'url prefix:', settings.URL_PREFIX
 urlpatterns = patterns('',
     # Examples:
     # url(r'^$', 'webapp.views.home', name='home'),
     # url(r'^blog/', include('blog.urls')),
-    url(r'^$', 'cloudscale.views.home', name='home'),
+    url(r'^$',  'cloudscale.views.home', name='home'),
     url(r'^upload/?', 'cloudscale.views.upload', name='upload'),
     url(r'^admin/', include(admin.site.urls)),
     url(r'^report/(?P<id>(.*))$', 'cloudscale.views.report', name='report'),