From b125c4959896a05c351b5c087f25ac0cfd5764da Mon Sep 17 00:00:00 2001 From: brunogoossens Date: Thu, 12 Mar 2015 11:39:48 +0100 Subject: [PATCH 1/8] adding better project structure --- app/AppKernel.php | 1 + app/config/routing.yml | 5 ++++ .../AdminBundle/Resources/config/services.yml | 3 -- .../BBBBundle/BBBLoadBalancerBBBBundle.php | 9 ++++++ .../Controller/BBBAPIController.php | 2 +- .../BBBLoadBalancerBBBExtension.php | 28 ++++++++++++++++++ .../DependencyInjection/Configuration.php | 29 +++++++++++++++++++ .../BBBBundle/Resources/config/services.yml | 4 +++ .../Resources/views/Default/index.html.twig | 1 + .../Service/BBBService.php | 2 +- .../Controller/DefaultControllerTest.php | 17 +++++++++++ 11 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 src/BBBLoadBalancer/BBBBundle/BBBLoadBalancerBBBBundle.php rename src/BBBLoadBalancer/{AdminBundle => BBBBundle}/Controller/BBBAPIController.php (99%) create mode 100644 src/BBBLoadBalancer/BBBBundle/DependencyInjection/BBBLoadBalancerBBBExtension.php create mode 100644 src/BBBLoadBalancer/BBBBundle/DependencyInjection/Configuration.php create mode 100644 src/BBBLoadBalancer/BBBBundle/Resources/config/services.yml create mode 100644 src/BBBLoadBalancer/BBBBundle/Resources/views/Default/index.html.twig rename src/BBBLoadBalancer/{AdminBundle => BBBBundle}/Service/BBBService.php (97%) create mode 100644 src/BBBLoadBalancer/BBBBundle/Tests/Controller/DefaultControllerTest.php diff --git a/app/AppKernel.php b/app/AppKernel.php index 07245cc..094c0fb 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -19,6 +19,7 @@ public function registerBundles() new BBBLoadBalancer\AdminBundle\BBBLoadBalancerAdminBundle(), new BBBLoadBalancer\ThemeBundle\BBBLoadBalancerThemeBundle(), new BBBLoadBalancer\UserBundle\BBBLoadBalancerUserBundle(), + new BBBLoadBalancer\BBBBundle\BBBLoadBalancerBBBBundle(), ); if (in_array($this->getEnvironment(), array('dev', 'test'))) { diff --git a/app/config/routing.yml b/app/config/routing.yml index 848e5ff..c5bab21 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -1,3 +1,8 @@ +bbb_load_balancer_bbb: + resource: "@BBBLoadBalancerBBBBundle/Controller/" + type: annotation + prefix: / + bbb_load_balancer_theme: resource: "@BBBLoadBalancerThemeBundle/Controller/" type: annotation diff --git a/src/BBBLoadBalancer/AdminBundle/Resources/config/services.yml b/src/BBBLoadBalancer/AdminBundle/Resources/config/services.yml index bff16ac..bb9d5c3 100644 --- a/src/BBBLoadBalancer/AdminBundle/Resources/config/services.yml +++ b/src/BBBLoadBalancer/AdminBundle/Resources/config/services.yml @@ -2,9 +2,6 @@ services: meeting: class: BBBLoadBalancer\AdminBundle\Service\MeetingService arguments: [ @doctrine_mongodb, @validator ] - bbb: - class: BBBLoadBalancer\AdminBundle\Service\BBBService - arguments: [ %bbb.salt%, @logger ] server: class: BBBLoadBalancer\AdminBundle\Service\ServerService arguments: [ @doctrine_mongodb, @bbb, @validator, @meeting, @logger ] \ No newline at end of file diff --git a/src/BBBLoadBalancer/BBBBundle/BBBLoadBalancerBBBBundle.php b/src/BBBLoadBalancer/BBBBundle/BBBLoadBalancerBBBBundle.php new file mode 100644 index 0000000..400182a --- /dev/null +++ b/src/BBBLoadBalancer/BBBBundle/BBBLoadBalancerBBBBundle.php @@ -0,0 +1,9 @@ +processConfiguration($configuration, $configs); + + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); + } +} diff --git a/src/BBBLoadBalancer/BBBBundle/DependencyInjection/Configuration.php b/src/BBBLoadBalancer/BBBBundle/DependencyInjection/Configuration.php new file mode 100644 index 0000000..eb69050 --- /dev/null +++ b/src/BBBLoadBalancer/BBBBundle/DependencyInjection/Configuration.php @@ -0,0 +1,29 @@ +root('bbb_load_balancer_bbb'); + + // Here you should define the parameters that are allowed to + // configure your bundle. See the documentation linked above for + // more information on that topic. + + return $treeBuilder; + } +} diff --git a/src/BBBLoadBalancer/BBBBundle/Resources/config/services.yml b/src/BBBLoadBalancer/BBBBundle/Resources/config/services.yml new file mode 100644 index 0000000..a48f98e --- /dev/null +++ b/src/BBBLoadBalancer/BBBBundle/Resources/config/services.yml @@ -0,0 +1,4 @@ +services: + bbb: + class: BBBLoadBalancer\BBBBundle\Service\BBBService + arguments: [ %bbb.salt%, @logger ] \ No newline at end of file diff --git a/src/BBBLoadBalancer/BBBBundle/Resources/views/Default/index.html.twig b/src/BBBLoadBalancer/BBBBundle/Resources/views/Default/index.html.twig new file mode 100644 index 0000000..4ce626e --- /dev/null +++ b/src/BBBLoadBalancer/BBBBundle/Resources/views/Default/index.html.twig @@ -0,0 +1 @@ +Hello {{ name }}! diff --git a/src/BBBLoadBalancer/AdminBundle/Service/BBBService.php b/src/BBBLoadBalancer/BBBBundle/Service/BBBService.php similarity index 97% rename from src/BBBLoadBalancer/AdminBundle/Service/BBBService.php rename to src/BBBLoadBalancer/BBBBundle/Service/BBBService.php index 2f866b0..53ef216 100644 --- a/src/BBBLoadBalancer/AdminBundle/Service/BBBService.php +++ b/src/BBBLoadBalancer/BBBBundle/Service/BBBService.php @@ -1,6 +1,6 @@ request('GET', '/hello/Fabien'); + + $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); + } +} From a3d6df4bc3b71a4247e7c6083a93e1d38c4a4487 Mon Sep 17 00:00:00 2001 From: brunogoossens Date: Thu, 12 Mar 2015 11:56:16 +0100 Subject: [PATCH 2/8] adding permission settings for readme file --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7e789e2..ab6311a 100644 --- a/README.md +++ b/README.md @@ -65,23 +65,24 @@ Get composer Update and install packages with composer - $ composer update + $ composer install Start server (without apache or nginx) $ app/console server:run --env=prod If you want to configure an other server like apache or nginx, you can follow [this](http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html) guide. +Make sure if you use a webserver, that it has write access to the app/cache and app/log folders. You can read more about this [here](http://symfony.com/doc/current/book/installation.html). Search the page for "Setting up Permissions". To automatically enable and disable servers based on there status, you can add this cronjob. * * * * * /path/to/project/app/console bbblb:servers:check --env=prod -To remove stopped meetings from the load balancer. +To remove stopped meetings from the load balancer, add this cronjob. * * * * * /path/to/project/app/console bbblb:meetings:cleanup --env=prod # Adding BBB Servers to the load balancer # Access the web interface: http://127.0.0.1:8000 (or vhost configured in apache or nginx) -The first time you access this page, you must create an admin user. After creating this user, you can manage the BBB load balancer. You need to add at least 1 BBB server to the list of servers before you can use the load balancer. +The first time you access this page, you must create an admin user. After creating this user, you can manage the BBB load balancer. You need to add at least 1 BBB server to the list of servers before you can use the load balancer. After setting up the load balancer, you should change your client applications BBB url to the new BBB load balancer URL. From 63f7708bcd8f4ec326f8aeebe7c40816753e28d0 Mon Sep 17 00:00:00 2001 From: brunogoossens Date: Thu, 12 Mar 2015 16:11:38 +0100 Subject: [PATCH 3/8] changing readme file --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ab6311a..bb63bec 100644 --- a/README.md +++ b/README.md @@ -86,3 +86,4 @@ To remove stopped meetings from the load balancer, add this cronjob. Access the web interface: http://127.0.0.1:8000 (or vhost configured in apache or nginx) The first time you access this page, you must create an admin user. After creating this user, you can manage the BBB load balancer. You need to add at least 1 BBB server to the list of servers before you can use the load balancer. After setting up the load balancer, you should change your client applications BBB url to the new BBB load balancer URL. +(http://127.0.0.1/bigbluebutton) \ No newline at end of file From 9bc026e5c7e7198df5971ba17a27194b1f40edc2 Mon Sep 17 00:00:00 2001 From: brunogoossens Date: Tue, 17 Mar 2015 14:47:51 +0100 Subject: [PATCH 4/8] fix #10: adding status response for the load balancer --- .../Controller/DefaultAPIController.php | 44 +++++++++++++++++++ .../Resources/public/js/templates/API.html | 3 ++ 2 files changed, 47 insertions(+) create mode 100644 src/BBBLoadBalancer/AdminBundle/Controller/DefaultAPIController.php diff --git a/src/BBBLoadBalancer/AdminBundle/Controller/DefaultAPIController.php b/src/BBBLoadBalancer/AdminBundle/Controller/DefaultAPIController.php new file mode 100644 index 0000000..e69948a --- /dev/null +++ b/src/BBBLoadBalancer/AdminBundle/Controller/DefaultAPIController.php @@ -0,0 +1,44 @@ + array() + ); + + // return all servers + $servers = $this->get('server')->getServersBy(array("enabled" => true, "up" => true)); + if(empty($servers)){ + return new JsonResponse(array( + "status" => "ERROR", + "message" => "No Servers found that are enabled and up." + ) + ); + } + + $servercount = count($servers); + + return new JsonResponse(array( + "status" => "OK", + "message" => "$servercount servers are used by the load balancer." + ) + ); + } +} \ No newline at end of file diff --git a/src/BBBLoadBalancer/AdminBundle/Resources/public/js/templates/API.html b/src/BBBLoadBalancer/AdminBundle/Resources/public/js/templates/API.html index fb8fa37..44a27eb 100644 --- a/src/BBBLoadBalancer/AdminBundle/Resources/public/js/templates/API.html +++ b/src/BBBLoadBalancer/AdminBundle/Resources/public/js/templates/API.html @@ -27,6 +27,9 @@

BigBlueButton API

BBB Load Balancer API

The API can be used on the endpoint "/api" and can only be used with the JSON format. To get access, you need to add the API key to the header of the request with the name "API-key".
Example header: API-key:CTCTn8rMMvjj2AGoQkUBC5iEpfbvplb1eOVCWmoJRH2ThIi83c. Each user has his own API key.


+

Status

+

/api/status (GET)

+

List servers

/api/servers (GET)


From 43f337bc9710e629ebf5d4d306d671afd4f918a6 Mon Sep 17 00:00:00 2001 From: brunogoossens Date: Tue, 17 Mar 2015 14:48:16 +0100 Subject: [PATCH 5/8] changing readme file and error response --- README.md | 42 ++++++++++++------- .../views/Exception/error.json.twig | 2 +- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index bb63bec..177867e 100644 --- a/README.md +++ b/README.md @@ -34,19 +34,23 @@ You can use a chef recipe to setup your server or setup a vagrant box. Dependencies - sudo apt-get install php5-common - sudo apt-get install php5 - sudo apt-get install php5-xcache - sudo apt-get install php5-mongo - sudo apt-get install php5-fpm - sudo apt-get install php5-curl - sudo apt-get install mongodb - sudo apt-get install npm + php5-common + php5-cli + php5 + php5-xcache + php5-mongo + php5-fpm + php5-curl + mongodb + npm + node + git + curl Get the code - git clone git@github.com:brunogoossens/BBB-Load-Balancer.git /var/www/bbb-load-balancer - cd /var/www/bbb-load-balancer + $ git clone https://github.com/brunogoossens/BBB-Load-Balancer.git /var/www/bbb-load-balancer + $ cd /var/www/bbb-load-balancer Get NPM packages @@ -56,16 +60,16 @@ Edit the config file $ cp app/config/parameters.yml.dist app/config/parameters.yml -Change the bbb.salt value inside the file. The salt must be the same on all BBB servers +Change the bbb.salt value inside the new file. The salt must be the same on all BBB servers You can also change other values if you like. Get composer $ curl -s https://getcomposer.org/installer | php -Update and install packages with composer +Install packages with composer - $ composer install + $ ./composer.phar install Start server (without apache or nginx) @@ -86,4 +90,14 @@ To remove stopped meetings from the load balancer, add this cronjob. Access the web interface: http://127.0.0.1:8000 (or vhost configured in apache or nginx) The first time you access this page, you must create an admin user. After creating this user, you can manage the BBB load balancer. You need to add at least 1 BBB server to the list of servers before you can use the load balancer. After setting up the load balancer, you should change your client applications BBB url to the new BBB load balancer URL. -(http://127.0.0.1/bigbluebutton) \ No newline at end of file +(http://127.0.0.1/bigbluebutton) + +# Updating the loadbalancer # + +So we added cool new features to the repository but you have deployed old code. You should do the following commands to get the newest code. + + $ cd /var/www/bbb-load-balancer + $ git pull + $ app/console cache:clear --env=prod + $ app/console assets:install + $ app/console assetic:dump --env=prod \ No newline at end of file diff --git a/app/Resources/TwigBundle/views/Exception/error.json.twig b/app/Resources/TwigBundle/views/Exception/error.json.twig index 4560cb1..8fd3a10 100644 --- a/app/Resources/TwigBundle/views/Exception/error.json.twig +++ b/app/Resources/TwigBundle/views/Exception/error.json.twig @@ -1 +1 @@ -[{{ { 'message': exception.message }|json_encode|raw }}] +[{{ { 'status_text': status_text, 'message': exception.message }|json_encode|raw }}] From edbe5faa3b0891a1ce189b5491587235a1db1757 Mon Sep 17 00:00:00 2001 From: brunogoossens Date: Tue, 17 Mar 2015 15:47:29 +0100 Subject: [PATCH 6/8] making node path configurable and changing readme file --- README.md | 2 -- app/config/config.yml | 1 + app/config/parameters.yml.dist | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 177867e..f2f784a 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,8 @@ Dependencies php5-common php5-cli - php5 php5-xcache php5-mongo - php5-fpm php5-curl mongodb npm diff --git a/app/config/config.yml b/app/config/config.yml index 440d7bc..8ae9764 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -37,6 +37,7 @@ twig: # Assetic Configuration assetic: + node: "%sys.path_node%" debug: "%kernel.debug%" use_controller: false bundles: [ "BBBLoadBalancerThemeBundle", "BBBLoadBalancerAdminBundle" ] diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index c278bf7..287614f 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -14,6 +14,8 @@ parameters: debug_redirects: false use_assetic_controller: true + sys.path_node: node + app.site_name: BBB Load Balancer app.domain: domainname.com app.email_name: BBB Load Balancer From 83c96bd660bd57d9c3c476ed41b62fd6b33e55eb Mon Sep 17 00:00:00 2001 From: brunogoossens Date: Tue, 17 Mar 2015 15:50:11 +0100 Subject: [PATCH 7/8] changing readme file --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f2f784a..8ccaf4c 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,10 @@ Dependencies git curl -Get the code +Get the code (change the destination) - $ git clone https://github.com/brunogoossens/BBB-Load-Balancer.git /var/www/bbb-load-balancer - $ cd /var/www/bbb-load-balancer + $ git clone https://github.com/brunogoossens/BBB-Load-Balancer.git /path/of/project + $ cd /path/of/project Get NPM packages @@ -78,11 +78,11 @@ Make sure if you use a webserver, that it has write access to the app/cache and To automatically enable and disable servers based on there status, you can add this cronjob. - * * * * * /path/to/project/app/console bbblb:servers:check --env=prod + * * * * * /path/of/project/app/console bbblb:servers:check --env=prod To remove stopped meetings from the load balancer, add this cronjob. - * * * * * /path/to/project/app/console bbblb:meetings:cleanup --env=prod + * * * * * /path/of/project/app/console bbblb:meetings:cleanup --env=prod # Adding BBB Servers to the load balancer # @@ -94,7 +94,7 @@ The first time you access this page, you must create an admin user. After creati So we added cool new features to the repository but you have deployed old code. You should do the following commands to get the newest code. - $ cd /var/www/bbb-load-balancer + $ cd /path/of/project/bbb-load-balancer $ git pull $ app/console cache:clear --env=prod $ app/console assets:install From 9f44bd0f3de1378daf9fc5c7f8d884c667876f2f Mon Sep 17 00:00:00 2001 From: brunogoossens Date: Tue, 17 Mar 2015 15:57:07 +0100 Subject: [PATCH 8/8] removing dummy files --- .../Tests/Controller/DefaultControllerTest.php | 17 ----------------- .../Resources/views/Default/index.html.twig | 1 - .../Tests/Controller/DefaultControllerTest.php | 17 ----------------- .../Tests/Controller/DefaultControllerTest.php | 17 ----------------- 4 files changed, 52 deletions(-) delete mode 100644 src/BBBLoadBalancer/AdminBundle/Tests/Controller/DefaultControllerTest.php delete mode 100644 src/BBBLoadBalancer/BBBBundle/Resources/views/Default/index.html.twig delete mode 100644 src/BBBLoadBalancer/BBBBundle/Tests/Controller/DefaultControllerTest.php delete mode 100644 src/BBBLoadBalancer/ThemeBundle/Tests/Controller/DefaultControllerTest.php diff --git a/src/BBBLoadBalancer/AdminBundle/Tests/Controller/DefaultControllerTest.php b/src/BBBLoadBalancer/AdminBundle/Tests/Controller/DefaultControllerTest.php deleted file mode 100644 index 2889118..0000000 --- a/src/BBBLoadBalancer/AdminBundle/Tests/Controller/DefaultControllerTest.php +++ /dev/null @@ -1,17 +0,0 @@ -request('GET', '/hello/Fabien'); - - $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); - } -} diff --git a/src/BBBLoadBalancer/BBBBundle/Resources/views/Default/index.html.twig b/src/BBBLoadBalancer/BBBBundle/Resources/views/Default/index.html.twig deleted file mode 100644 index 4ce626e..0000000 --- a/src/BBBLoadBalancer/BBBBundle/Resources/views/Default/index.html.twig +++ /dev/null @@ -1 +0,0 @@ -Hello {{ name }}! diff --git a/src/BBBLoadBalancer/BBBBundle/Tests/Controller/DefaultControllerTest.php b/src/BBBLoadBalancer/BBBBundle/Tests/Controller/DefaultControllerTest.php deleted file mode 100644 index 90b9528..0000000 --- a/src/BBBLoadBalancer/BBBBundle/Tests/Controller/DefaultControllerTest.php +++ /dev/null @@ -1,17 +0,0 @@ -request('GET', '/hello/Fabien'); - - $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); - } -} diff --git a/src/BBBLoadBalancer/ThemeBundle/Tests/Controller/DefaultControllerTest.php b/src/BBBLoadBalancer/ThemeBundle/Tests/Controller/DefaultControllerTest.php deleted file mode 100644 index 312a12e..0000000 --- a/src/BBBLoadBalancer/ThemeBundle/Tests/Controller/DefaultControllerTest.php +++ /dev/null @@ -1,17 +0,0 @@ -request('GET', '/hello/Fabien'); - - $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); - } -}