Skip to content
Browse files

Job routerv2 becomes router. Create a job router_next for next-genera…

…tion router. Create package nginx_next for nginx 1.2.

Change-Id: I0fb31221dcbf402537bd9ab6bcee4fa6e49946ab
  • Loading branch information...
1 parent 02d7dc3 commit d57285c7318d1d5025f3e434dd20287c2e11720f @anfernee anfernee committed Apr 11, 2012
View
3 .gitmodules
@@ -7,9 +7,6 @@
[submodule "src/tools"]
path = src/tools
url = git@github.com:cloudfoundry/vcap-tools.git
-[submodule "src/core_routerv2"]
- path = src/core_routerv2
- url = git@github.com:cloudfoundry/vcap.git
[submodule "src/vblob_src"]
path = src/vblob_src
url = git@github.com:cloudfoundry/vblob.git
View
13 config/blobs.yml
@@ -493,3 +493,16 @@ dashboard/dashboard-1.0-SNAPSHOT-ea587daf.war:
object_id: eyJvaWQiOiI0ZTRlNzhiY2ExMWUxMjEwMDRlNGU3ZDUxMWY4MjEwNGY5OWE2%0AZDdkYTRlNSIsInNpZyI6Ik4wdmltNHA4RkhuVXhTb2lhMmhpTkRnQ29Baz0i%0AfQ==%0A
sha: fd96a1dff68c13719ecfcc322afa5e5d398fa740
size: 16571890
+nginx/nginx-1.1.17.tar.gz:
+ object_id: eyJvaWQiOiI0ZTRlNzhiY2ExMWUxMjIyMDRlNGU5ODYzOGI3NjMwNGY2Y2Uy%0AMDZiNTI0NiIsInNpZyI6IitOWUdtQUNjWjA0VVdUT3BFcHZPdlBOeWlKWT0i%0AfQ==%0A
+ sha: 60c02ddc7e742d8aa959531f5a63684380e798e8
+nginx/nginx-lua.v0.4.1.tar.gz:
+ object_id: eyJvaWQiOiI0ZTRlNzhiY2E2MWUxMjEyMDRlNGU4NmVlYmU1OTEwNGY2Y2Uy%0AMTAxNjZlYSIsInNpZyI6IkhVNG5UWjNSbG8wZmIybDlRSnNCYk02MUNhQT0i%0AfQ==%0A
+ sha: fd37ffa48a618b2e521ea9797d13f523640fad4f
+nginx/pcre-8.21.tar.gz:
+ object_id: eyJvaWQiOiI0ZTRlNzhiY2EyMWUxMjIyMDRlNGU5ODYzOTI2YjEwNGY2Y2Uy%0AMTllZTYzOCIsInNpZyI6ImpUNkxCbkNnR09BTlBwbFEySE1NNVJ3bW9TWT0i%0AfQ==%0A
+ sha: dffb43eff9729c0999843a86ef97961b8c4f6ac8
+nginx/nginx-1.2.0.tar.gz:
+ object_id: eyJvaWQiOiI0ZTRlNzhiY2ExMWUxMjIwMDRlNGU4ZWM2NDg0MzEwNGZhMGE4%0AZDYxMTJmMiIsInNpZyI6InowZ1hkV1JOaWtpOUZhTndiTVFqVzZpdEdDND0i%0AfQ==%0A
+ sha: 15cec8d1b8dbf2007f9f99594a08a2f45814034e
+ size: 716067
View
12 jobs/router/spec
@@ -2,16 +2,16 @@
name: router
templates:
- nginx_ctl: bin/nginx_ctl
- router_ctl: bin/router_ctl
- router.yml.erb: config/router.yml
- nginx.conf.erb: config/nginx.conf
- mime.types: config/mime.types
+ nginx_ctl: bin/nginx_ctl
+ router_ctl: bin/router_ctl
+ router.yml.erb: config/router.yml
+ nginx.conf.erb: config/nginx.conf
+ mime.types: config/mime.types
syslog_forwarder.conf.erb: config/syslog_forwarder.conf
packages:
- common
- router
- nginx
- ruby
- - syslog_aggregator
+ - syslog_aggregator
View
68 jobs/router/templates/nginx.conf.erb
@@ -1,6 +1,7 @@
-<% require "base64" %>
+
user root root;
worker_processes 1;
+worker_rlimit_nofile 16384;
error_log /var/vcap/sys/log/nginx/nginx.error.log;
pid /var/vcap/sys/run/nginx/nginx.pid;
@@ -39,10 +40,6 @@ http {
client_max_body_size 256M;
- upstream router {
- server unix:/var/vcap/sys/run/router/router.sock;
- }
-
<% if properties.router.status %>
upstream router_status {
server <%= spec.networks.send(properties.networks.apps).ip %>:<%= properties.router.status.port %>;
@@ -54,6 +51,17 @@ http {
server_name "<%= properties.domain %>";
server_name_in_redirect off;
+ #TODO: how to make this internal location totally transparent to outside
+ location = /vcapuls {
+ internal;
+ # We should use rewrite_by_lua to scrub subrequest headers
+ # as uls doesn't care those headers at all.
+ # Given there are some exceptions to clear some headers,
+ # we just leave them as is.
+
+ proxy_pass http://unix:/var/vcap/sys/run/router/router.sock:/;
+ }
+
location / {
access_log /var/vcap/sys/log/nginx/router.access.log main;
proxy_buffering off;
@@ -64,6 +72,7 @@ http {
proxy_send_timeout <%= properties.router.client_inactivity_timeout || 30 %>;
proxy_read_timeout <%= properties.router.app_inactivity_timeout || 30 %>;
+ set $health_monitor '';
<% if properties.router.status %>
if ($http_user_agent = "HTTP-Monitor/1.1") {
set $health_monitor T;
@@ -72,13 +81,60 @@ http {
set $health_monitor "${health_monitor}T";
}
if ($health_monitor = TT) {
+ # Trigger a subrequest to sync the latest few stats of the worker to uls,
+ # if we have multiple workers, there will be still few stats not synced for
+ # the workers which don't get this monitor request.
+ access_by_lua '
+ local uls = require ("uls")
+ ngx.log(ngx.DEBUG, "monitor trigger stats syncup")
+
+ -- generate one subrequest to uls to update stats
+ ngx.location.capture(
+ "/vcapuls", {body = uls.generate_stats_request()}
+ )
+ ';
+
more_set_input_headers "Authorization: Basic <%= Base64.encode64("#{properties.router.status.user}:#{properties.router.status.password}").strip %>";
rewrite ^.*$ /healthz break;
proxy_pass http://router_status;
}
<% end %>
- proxy_pass http://router;
+ # We intend to have one "if" block to avoid the above monitor location
+ # to twist with below upstream locator server handling.
+ # ("if" block effectively creates a nested location and will inherit
+ # all the rewrite/access phase handlers of outer location)
+ if ($health_monitor != TT) {
+ # The following variables are used by lua module code.
+ # DO NOT remove or rename any of them!
+ set $backend_addr ''; # Backend server address returned from uls for this request
+ set $uls_req_tags ''; # Request tags returned from uls for this request to catalog statistics
+ set $router_ip '';
+ set $timestamp 0;
+ set $trace '';
+ set $sticky '';
+
+ access_by_lua '
+ local uls = require ("uls")
+ uls.pre_process_subrequest(ngx, "<%= properties.router.trace_key or 22 %>")
+
+ -- generate one subrequest to uls for url query
+ local res = ngx.location.capture(
+ "/vcapuls", {body = uls.generate_uls_request(ngx)}
+ )
+
+ uls.post_process_subrequest(ngx, res)
+ ';
+
+ proxy_pass http://$backend_addr;
+
+ # Handling response from backend servers
+ header_filter_by_lua '
+ local uls = require ("uls")
+
+ uls.post_process_response(ngx)
+ ';
+ }
}
}
}
View
3 jobs/router/templates/nginx_ctl
@@ -16,6 +16,9 @@ case $1 in
echo $$ > $PIDFILE
+ export LUA_PATH="/var/vcap/packages/router/router/ext/nginx/?.lua"
+ export LUA_CPATH="/var/vcap/packages/nginx/lib/?.so"
+
exec /var/vcap/packages/nginx/sbin/nginx \
-c /var/vcap/jobs/router/config/nginx.conf \
>>$LOG_DIR/nginx.stdout.log \
View
5 jobs/router/templates/router.yml.erb
@@ -8,7 +8,7 @@ logging:
<% end %>
file: /var/vcap/sys/log/router/router.log
pid: /var/vcap/sys/run/router/router.pid
-index: <%= spec.index %>
+index: <%= properties.router.offset ? properties.router.offset + spec.index : spec.index %>
<% if properties.router.local_route %>
local_route: <%= properties.router.local_route %>
<% end %>
@@ -18,6 +18,3 @@ status:
user: <%= properties.router.status.user %>
password: <%= properties.router.status.password %>
<% end %>
-<% if properties.router.client_inactivity_timeout %>
-client_inactivity_timeout: <%= properties.router.client_inactivity_timeout %>
-<% end %>
View
8 jobs/router/templates/router_ctl
@@ -2,10 +2,11 @@
export PATH=/var/vcap/packages/ruby/bin:$PATH
+CONF_DIR=/var/vcap/jobs/router/config
+
RUN_DIR=/var/vcap/sys/run/router
LOG_DIR=/var/vcap/sys/log/router
PIDFILE=$RUN_DIR/router.pid
-JOB_DIR=/var/vcap/jobs/router
source /var/vcap/packages/common/utils.sh
@@ -45,11 +46,11 @@ case $1 in
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
<% if properties.syslog_aggregator %>
- /var/vcap/packages/syslog_aggregator/setup_syslog_forwarder.sh $JOB_DIR/config
+ /var/vcap/packages/syslog_aggregator/setup_syslog_forwarder.sh $CONF_DIR
<% end %>
exec /var/vcap/packages/router/bin/router \
- -c $JOB_DIR/config/router.yml \
+ -c /var/vcap/jobs/router/config/router.yml \
>>$LOG_DIR/router.stdout.log \
2>>$LOG_DIR/router.stderr.log
@@ -62,6 +63,7 @@ case $1 in
*)
echo "Usage: router_ctl {start|stop}"
+
;;
esac
View
11 jobs/router_next/monit
@@ -0,0 +1,11 @@
+check process nginx
+ with pidfile /var/vcap/sys/run/nginx/nginx.pid
+ start program "/var/vcap/jobs/router_next/bin/nginx_ctl start"
+ stop program "/var/vcap/jobs/router_next/bin/nginx_ctl stop"
+ group vcap
+
+check process router
+ with pidfile /var/vcap/sys/run/router/router.pid
+ start program "/var/vcap/jobs/router_next/bin/router_ctl start"
+ stop program "/var/vcap/jobs/router_next/bin/router_ctl stop"
+ group vcap
View
8 jobs/routerv2/spec → jobs/router_next/spec
@@ -1,5 +1,5 @@
---
-name: routerv2
+name: router_next
templates:
nginx_ctl: bin/nginx_ctl
@@ -8,12 +8,10 @@ templates:
nginx.conf.erb: config/nginx.conf
mime.types: config/mime.types
syslog_forwarder.conf.erb: config/syslog_forwarder.conf
- uls.lua.erb: lib/uls.lua
- tablesave.lua: lib/tablesave.lua
packages:
- common
- - routerv2
- - nginx
+ - router
+ - nginx_next
- ruby
- syslog_aggregator
View
0 jobs/routerv2/templates/mime.types → jobs/router_next/templates/mime.types
File renamed without changes.
View
99 jobs/routerv2/templates/nginx.conf.erb → jobs/router_next/templates/nginx.conf.erb
@@ -19,7 +19,7 @@ http {
log_format main '$host - [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
- '$remote_addr $http_x_forwarded_for response_time:$upstream_response_time';
+ '$remote_addr response_time:$upstream_response_time';
access_log /var/vcap/sys/log/nginx/nginx.access.log main;
@@ -59,7 +59,7 @@ http {
# Given there are some exceptions to clear some headers,
# we just leave them as is.
- proxy_pass http://unix:/var/vcap/sys/run/routerv2/router.sock:/;
+ proxy_pass http://unix:/var/vcap/sys/run/router/router.sock:/;
}
location / {
@@ -86,18 +86,11 @@ http {
# the workers which don't get this monitor request.
access_by_lua '
local uls = require ("uls")
- local cjson = require("cjson")
+ ngx.log(ngx.DEBUG, "monitor trigger stats syncup")
- local uls_req_spec = {}
- local req_stats = uls.serialize_request_statistics()
- if req_stats then
- uls_req_spec[uls.ULS_STATS_UPDATE] = req_stats
- ngx.log(ngx.DEBUG, "monitor trigger stats syncup")
- end
-
- -- generate one subrequest to uls with uls_req_spec
+ -- generate one subrequest to uls to update stats
ngx.location.capture(
- "/vcapuls", {body = cjson.encode(uls_req_spec)}
+ "/vcapuls", {body = uls.generate_stats_request()}
)
';
@@ -112,60 +105,25 @@ http {
# ("if" block effectively creates a nested location and will inherit
# all the rewrite/access phase handlers of outer location)
if ($health_monitor != TT) {
- # Backend server address returned from uls for this request
- set $backend_addr '';
- # Request tags returned from uls for this request to catalog statistics
- set $uls_req_tags '';
+ # The following variables are used by lua module code.
+ # DO NOT remove or rename any of them!
+ set $backend_addr ''; # Backend server address returned from uls for this request
+ set $uls_req_tags ''; # Request tags returned from uls for this request to catalog statistics
set $router_ip '';
set $timestamp 0;
set $trace '';
set $sticky '';
access_by_lua '
local uls = require ("uls")
- local cjson = require("cjson")
-
- if string.len(ngx.var.http_host) == 0 then
- ngx.exit(ngx.HTTP_BAD_REQUEST)
- end
-
- ngx.var.timestamp = ngx.time()
-
- local uls_req_spec = {}
- uls_req_spec[uls.ULS_HOST_QUERY] = ngx.var.http_host
-
- local uls_sticky_session = uls.retrieve_vcap_sticky_session(
- ngx.req.get_headers()[uls.COOKIE_HEADER])
- if uls_sticky_session then
- uls_req_spec[uls.ULS_STICKY_SESSION] = uls_sticky_session
- ngx.log(ngx.DEBUG, "req sticks to backend session:"..uls_sticky_session)
- end
-
- if ngx.req.get_headers()[uls.VCAP_TRACE_HEADER] then
- ngx.var.trace = "Y"
- end
-
- local req_stats = uls.serialize_request_statistics()
- if req_stats then
- uls_req_spec[uls.ULS_STATS_UPDATE] = req_stats
- end
+ uls.pre_process_subrequest(ngx, "<%= properties.router.trace_key or 22 %>")
- -- generate one subrequest to uls with uls_req_spec
+ -- generate one subrequest to uls for url query
local res = ngx.location.capture(
- "/vcapuls", {body = cjson.encode(uls_req_spec)}
+ "/vcapuls", {body = uls.generate_uls_request(ngx)}
)
- if res.status ~= 200 then
- ngx.exit(ngx.HTTP_NOT_FOUND)
- end
-
- local msg = cjson.decode(res.body)
- ngx.var.backend_addr = msg[uls.ULS_BACKEND_ADDR]
- ngx.var.uls_req_tags = msg[uls.ULS_REQEST_TAGS]
- ngx.var.router_ip = msg[uls.ULS_ROUTER_IP]
- ngx.var.sticky = msg[uls.ULS_STICKY_SESSION]
- ngx.log(ngx.DEBUG, "route request with host header:"..
- ngx.var.http_host.." to:"..ngx.var.backend_addr)
+ uls.post_process_subrequest(ngx, res)
';
proxy_pass http://$backend_addr;
@@ -174,36 +132,7 @@ http {
header_filter_by_lua '
local uls = require ("uls")
- uls.vcap_store_stats(ngx.var.uls_req_tags, ngx.status,
- (ngx.time() - ngx.var.timestamp) * 1000)
-
- if ngx.var.trace == "Y" then
- ngx.header[uls.VCAP_BACKEND_HEADER] = ngx.var.backend_addr
- ngx.header[uls.VCAP_ROUTER_HEADER] = ngx.var.router_ip
- end
-
- local cookies = ngx.header.set_cookie
- if not cookies then return end
-
- if type(cookies) ~= "table" then cookies = {cookies} end
- local sticky = false
- for _, val in ipairs(cookies) do
- local i, j = string.find(val:upper(), uls.STICKY_SESSIONS)
- if i then
- sticky = true
- break
- end
- end
- if not sticky then return end
-
- local vcap_cookie = uls.VCAP_SESSION_ID.."="..ngx.var.sticky
- ngx.log(ngx.DEBUG, "generate cookie:"..vcap_cookie.." for resp from:"..
- ngx.var.backend_addr)
- table.insert(cookies, vcap_cookie)
- -- ngx.header.set_cookie incorrectly makes header to "set-cookie",
- -- so workaround to set "Set-Cookie" directly
- -- ngx.header.set_cookie = cookies
- ngx.header["Set-Cookie"] = cookies
+ uls.post_process_response(ngx)
';
}
}
View
8 jobs/routerv2/templates/nginx_ctl → jobs/router_next/templates/nginx_ctl
@@ -16,11 +16,11 @@ case $1 in
echo $$ > $PIDFILE
- export LUA_PATH="/var/vcap/jobs/routerv2/lib/?.lua"
- export LUA_CPATH="/var/vcap/packages/nginx/lib/?.so"
+ export LUA_PATH="/var/vcap/packages/router/router/ext/nginx/?.lua"
+ export LUA_CPATH="/var/vcap/packages/nginx_next/lib/?.so"
- exec /var/vcap/packages/nginx/sbin/nginx \
- -c /var/vcap/jobs/routerv2/config/nginx.conf \
+ exec /var/vcap/packages/nginx_next/sbin/nginx \
+ -c /var/vcap/jobs/router_next/config/nginx.conf \
>>$LOG_DIR/nginx.stdout.log \
2>>$LOG_DIR/nginx.stderr.log
View
6 jobs/routerv2/templates/router.yml.erb → jobs/router_next/templates/router.yml.erb
@@ -1,13 +1,13 @@
---
-sock: /var/vcap/sys/run/routerv2/router.sock
+sock: /var/vcap/sys/run/router/router.sock
mbus: nats://<%= properties.nats.user %>:<%= properties.nats.password %>@<%= properties.nats.address %>:<%= properties.nats.port %>
logging:
level: info
<% if properties.syslog_aggregator %>
syslog: vcap.router
<% end %>
- file: /var/vcap/sys/log/routerv2/router.log
-pid: /var/vcap/sys/run/routerv2/router.pid
+ file: /var/vcap/sys/log/router/router.log
+pid: /var/vcap/sys/run/router/router.pid
index: <%= properties.router.offset ? properties.router.offset + spec.index : spec.index %>
<% if properties.router.local_route %>
local_route: <%= properties.router.local_route %>
View
10 jobs/routerv2/templates/router_ctl → jobs/router_next/templates/router_ctl
@@ -2,10 +2,10 @@
export PATH=/var/vcap/packages/ruby/bin:$PATH
-CONF_DIR=/var/vcap/jobs/routerv2/config
+CONF_DIR=/var/vcap/jobs/router_next/config
-RUN_DIR=/var/vcap/sys/run/routerv2
-LOG_DIR=/var/vcap/sys/log/routerv2
+RUN_DIR=/var/vcap/sys/run/router
+LOG_DIR=/var/vcap/sys/log/router
PIDFILE=$RUN_DIR/router.pid
source /var/vcap/packages/common/utils.sh
@@ -49,8 +49,8 @@ case $1 in
/var/vcap/packages/syslog_aggregator/setup_syslog_forwarder.sh $CONF_DIR
<% end %>
- exec /var/vcap/packages/routerv2/bin/router \
- -c /var/vcap/jobs/routerv2/config/router.yml \
+ exec /var/vcap/packages/router/bin/router \
+ -c /var/vcap/jobs/router_next/config/router.yml \
>>$LOG_DIR/router.stdout.log \
2>>$LOG_DIR/router.stderr.log
View
0 ...terv2/templates/syslog_forwarder.conf.erb → ..._next/templates/syslog_forwarder.conf.erb
File renamed without changes.
View
11 jobs/routerv2/monit
@@ -1,11 +0,0 @@
-check process nginx
- with pidfile /var/vcap/sys/run/nginx/nginx.pid
- start program "/var/vcap/jobs/routerv2/bin/nginx_ctl start"
- stop program "/var/vcap/jobs/routerv2/bin/nginx_ctl stop"
- group vcap
-
-check process router
- with pidfile /var/vcap/sys/run/routerv2/router.pid
- start program "/var/vcap/jobs/routerv2/bin/router_ctl start"
- stop program "/var/vcap/jobs/routerv2/bin/router_ctl stop"
- group vcap
View
180 jobs/routerv2/templates/tablesave.lua
@@ -1,180 +0,0 @@
---[[
- Save Table to File/Stringtable
- Load Table from File/Stringtable
- v 0.94
-
- Lua 5.1 compatible
-
- Userdata and indices of these are not saved
- Functions are saved via string.dump, so make sure it has no upvalues
- References are saved
-
- table.save( table [, filename] )
-
- Saves a table so it can be called via the table.load function again
- table must a object of type 'table'
- filename is optional, and may be a string representing a filename or true/1
-
- table.save( table )
- on success: returns a string representing the table (stringtable)
- (uses a string as buffer, ideal for smaller tables)
- table.save( table, true or 1 )
- on success: returns a string representing the table (stringtable)
- (uses io.tmpfile() as buffer, ideal for bigger tables)
- table.save( table, "filename" )
- on success: returns 1
- (saves the table to file "filename")
- on failure: returns as second argument an error msg
- ----------------------------------------------------
- table.load( filename or stringtable )
-
- Loads a table that has been saved via the table.save function
-
- on success: returns a previously saved table
- on failure: returns as second argument an error msg
- ----------------------------------------------------
-
- chillcode, http://lua-users.org/wiki/SaveTableToFile
- Licensed under the same terms as Lua itself.
-]]--
-do
- -- declare local variables
- --// exportstring( string )
- --// returns a "Lua" portable version of the string
- local function exportstring( s )
- s = string.format( "%q",s )
- -- to replace
- s = string.gsub( s,"\\\n","\\n" )
- s = string.gsub( s,"\r","\\r" )
- s = string.gsub( s,string.char(26),"\"..string.char(26)..\"" )
- return s
- end
---// The Save Function
-function table.save( tbl,filename )
- local charS,charE = " ","\n"
- local file,err
- -- create a pseudo file that writes to a string and return the string
- if not filename then
- file = { write = function( self,newstr ) self.str = self.str..newstr end, str = "" }
- charS,charE = "",""
- -- write table to tmpfile
- elseif filename == true or filename == 1 then
- charS,charE,file = "","",io.tmpfile()
- -- write table to file
- -- use io.open here rather than io.output, since in windows when clicking on a file opened with io.output will create an error
- else
- file,err = io.open( filename, "w" )
- if err then return _,err end
- end
- -- initiate variables for save procedure
- local tables,lookup = { tbl },{ [tbl] = 1 }
- file:write( "return {"..charE )
- for idx,t in ipairs( tables ) do
- if filename and filename ~= true and filename ~= 1 then
- file:write( "-- Table: {"..idx.."}"..charE )
- end
- file:write( "{"..charE )
- local thandled = {}
- for i,v in ipairs( t ) do
- thandled[i] = true
- -- escape functions and userdata
- if type( v ) ~= "userdata" then
- -- only handle value
- if type( v ) == "table" then
- if not lookup[v] then
- table.insert( tables, v )
- lookup[v] = #tables
- end
- file:write( charS.."{"..lookup[v].."},"..charE )
- elseif type( v ) == "function" then
- file:write( charS.."loadstring("..exportstring(string.dump( v )).."),"..charE )
- else
- local value = ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
- file:write( charS..value..","..charE )
- end
- end
- end
- for i,v in pairs( t ) do
- -- escape functions and userdata
- if (not thandled[i]) and type( v ) ~= "userdata" then
- -- handle index
- if type( i ) == "table" then
- if not lookup[i] then
- table.insert( tables,i )
- lookup[i] = #tables
- end
- file:write( charS.."[{"..lookup[i].."}]=" )
- else
- local index = ( type( i ) == "string" and "["..exportstring( i ).."]" ) or string.format( "[%d]",i )
- file:write( charS..index.."=" )
- end
- -- handle value
- if type( v ) == "table" then
- if not lookup[v] then
- table.insert( tables,v )
- lookup[v] = #tables
- end
- file:write( "{"..lookup[v].."},"..charE )
- elseif type( v ) == "function" then
- file:write( "loadstring("..exportstring(string.dump( v )).."),"..charE )
- else
- local value = ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
- file:write( value..","..charE )
- end
- end
- end
- file:write( "},"..charE )
- end
- file:write( "}" )
- -- Return Values
- -- return stringtable from string
- if not filename then
- -- set marker for stringtable
- return file.str.."--|"
- -- return stringttable from file
- elseif filename == true or filename == 1 then
- file:seek ( "set" )
- -- no need to close file, it gets closed and removed automatically
- -- set marker for stringtable
- return file:read( "*a" ).."--|"
- -- close file and return 1
- else
- file:close()
- return 1
- end
-end
-
---// The Load Function
-function table.load( sfile )
- -- catch marker for stringtable
- if string.sub( sfile,-3,-1 ) == "--|" then
- tables,err = loadstring( sfile )
- else
- tables,err = loadfile( sfile )
- end
- if err then return _,err
- end
- tables = tables()
- for idx = 1,#tables do
- local tolinkv,tolinki = {},{}
- for i,v in pairs( tables[idx] ) do
- if type( v ) == "table" and tables[v[1]] then
- table.insert( tolinkv,{ i,tables[v[1]] } )
- end
- if type( i ) == "table" and tables[i[1]] then
- table.insert( tolinki,{ i,tables[i[1]] } )
- end
- end
- -- link values, first due to possible changes of indices
- for _,v in ipairs( tolinkv ) do
- tables[idx][v[1]] = v[2]
- end
- -- link indices
- for _,v in ipairs( tolinki ) do
- tables[idx][v[2]],tables[idx][v[1]] = tables[idx][v[1]],nil
- end
- end
- return tables[1]
-end
--- close do
-end
View
157 jobs/routerv2/templates/uls.lua.erb
@@ -1,157 +0,0 @@
---------------------------------------------------------------------------------
--- Title: uls.lua
--- Description: Helper for nginx talking to uls(Upstream Locator Server)
--- Legal: Copyright (c) 2011 VMware, Inc.
---------------------------------------------------------------------------------
-
--- import dependencies
-local openssl = require("openssl")
-local base64 = require("base64")
-local cjson = require("cjson")
-require("tablesave")
-
-module("uls", package.seeall)
-_VERSION = '1.0'
-
-VCAP_SESSION_ID = "__VCAP_ID__"
-VCAP_COOKIE = "__VCAP_ID__=([^;]+)"
-SET_COOKIE_HEADER = "Set-Cookie"
-STICKY_SESSIONS = "JSESSIONID"
-COOKIE_HEADER = "Cookie"
-HOST_HEADER = "Host"
-VCAP_BACKEND_HEADER = "X-Vcap-Backend"
-VCAP_ROUTER_HEADER = "X-Vcap-Router"
-VCAP_TRACE_HEADER = "X-Vcap-Trace"
-
--- From nginx to uls
-ULS_HOST_QUERY = "host"
-ULS_STATS_UPDATE = "stats"
-ULS_STATS_LATENCY = "response_latency"
-ULS_STATS_SAMPLES = "response_samples"
-ULS_STATS_CODES = "response_codes"
-ULS_STICKY_SESSION = "sticky_session"
--- For both diretion
--- When ULS_BACKEND_ADDR sent from nginx to uls, it means sticky address
-ULS_BACKEND_ADDR = "backend_addr"
-ULS_REQEST_TAGS = "request_tags"
-ULS_ROUTER_IP = "router_ip"
-
-SESSION_KEY = "<%= properties.router.session_key %>"
-TRACE_KEY = "<%= properties.router.trace_key %>"
-
---[[
- Message between nginx and uls (as http body)
- nginx -> uls
- {
- "host": api.vcap.me,
- "backend_addr": 10.117.9.178:9022,
- "stats": [
- {
- "request_tags": xxx,
- "response_latency": xxx,
- "response_samples": xxx,
- "response_codes": {
- {"responses_xxx":xxx},
- {"responses_2xx":xxx}
- }
- },
- {
- "request_tags": xxx,
- "response_latency": xxx,
- "response_samples": xxx,
- "response_codes": {
- {"responses_xxx":xxx},
- {"responses_2xx":xxx}
- {"responses_5xx":xxx},
- }
- }
- ]
- }
-
- nginx <- uls
- {
- "backend_addr": xxx,
- "request_tags": xxx,
- "router_ip": xxx
- }
---]]
-
--- Per nginx worker global variables
--- We don't need any lock as nginx callback in a single thread
-stats_not_synced = {}
-request_num = 0
-
---------------------------------------------------------------------------------
--- Utilities
---------------------------------------------------------------------------------
-
--- Retrieve ip:port if the input cookies have vcap cookie
-function retrieve_vcap_sticky_session(cookies)
- if not cookies then return nil end
- if type(cookies) ~= "table" then cookies = {cookies} end
-
- for _, val in ipairs(cookies) do
- local i, j = string.find(val, VCAP_COOKIE)
- if i then
- assert(i + string.len(VCAP_SESSION_ID) + 1 < j)
- local sticky = string.sub(val, i + string.len(VCAP_SESSION_ID) + 1, j)
- return sticky
- end
- end
- return nil
-end
-
--- Save per request stats into per worker store
-function vcap_store_stats(req_tags, response_code, latency)
-
- request_num = request_num + 1
- local stats = stats_not_synced[req_tags]
- if not stats then
- stats = {[ULS_STATS_CODES] = {},
- [ULS_STATS_LATENCY] = 0,
- [ULS_STATS_SAMPLES] = 0}
-
- stats_not_synced[req_tags] = stats
- end
-
- local response_code_metric = "responses_xxx"
- if response_code >= 200 and response_code < 300 then
- response_code_metric = "responses_2xx"
- elseif response_code >= 300 and response_code < 400 then
- response_code_metric = "responses_3xx"
- elseif response_code >= 400 and response_code < 500 then
- response_code_metric = "responses_4xx"
- elseif response_code >= 500 and response_code < 600 then
- response_code_metric = "responses_5xx"
- end
-
- if not stats[ULS_STATS_CODES][response_code_metric] then
- stats[ULS_STATS_CODES][response_code_metric] = 1
- else
- stats[ULS_STATS_CODES][response_code_metric] =
- stats[ULS_STATS_CODES][response_code_metric] + 1
- end
-
- local t = stats[ULS_STATS_LATENCY] * stats[ULS_STATS_SAMPLES] + latency
- stats[ULS_STATS_SAMPLES] = stats[ULS_STATS_SAMPLES] + 1
- stats[ULS_STATS_LATENCY] = t / stats[ULS_STATS_SAMPLES]
-
-end
-
--- Assemble saved stats to return to the caller, then cleanup
-function serialize_request_statistics()
- if request_num == 0 then return nil end
-
- local stats = {}
- for k, v in pairs(stats_not_synced) do
- table.insert(stats, {[ULS_REQEST_TAGS] = k,
- [ULS_STATS_LATENCY] = v[ULS_STATS_LATENCY],
- [ULS_STATS_SAMPLES] = v[ULS_STATS_SAMPLES],
- [ULS_STATS_CODES] = v[ULS_STATS_CODES]})
- end
-
- -- clean stats
- request_num = 0
- stats_not_synced = {}
- return stats
-end
View
4 packages/nginx/packaging
@@ -43,6 +43,8 @@ cd ..
echo "Building lua..."
(
+ set -e
+
cd lua-5.1.4
make linux install INSTALL_TOP=${BOSH_INSTALL_TARGET}/lua
cd ..
@@ -73,6 +75,8 @@ echo "Building lua..."
echo "Building nginx..."
(
+ set -e
+
cd nginx-0.8.54
export LUA_LIB=${BOSH_INSTALL_TARGET}/lua/lib
export LUA_INC=${BOSH_INSTALL_TARGET}/lua/include
View
92 packages/nginx_next/packaging
@@ -0,0 +1,92 @@
+# abort script on any command that exit with a non zero value
+set -e
+
+echo "Extracting lua..."
+tar xzvf nginx/lua-5.1.4.tar.gz
+
+echo "Extracting lua openssl..."
+tar xzvf nginx/lua-openssl-0.1.1.tar.gz
+
+echo "Extracting lua json..."
+tar xzvf nginx/lua-cjson-1.0.3.tar.gz
+
+echo "Extracting lua base64..."
+tar xzvf nginx/lbase64.tar.gz
+
+echo "Extracting nginx dev kit module..."
+tar xzvf nginx/devel-kit-v0.2.17rc2.tar.gz
+
+echo "Extracting nginx lua module..."
+tar xzvf nginx/nginx-lua.v0.4.1.tar.gz
+
+echo "Extracting pcre..."
+tar xzvf nginx/pcre-8.21.tar.gz
+
+echo "Extracting headers-more module..."
+tar xzvf nginx/headers-more-v0.15rc1.tgz
+
+echo "Extracting nginx_upload module..."
+tar xzvf nginx/nginx_upload_module-2.2.0.tar.gz
+
+echo "Patching upload module"
+cd nginx_upload_module-2.2.0
+patch < ../nginx/upload_module_put_support.patch
+cd ..
+
+echo "Extracting nginx..."
+tar xzvf nginx/nginx-1.2.0.tar.gz
+
+echo "Building lua..."
+(
+ set -e
+
+ cd lua-5.1.4
+ make linux install INSTALL_TOP=${BOSH_INSTALL_TARGET}/lua
+ cd ..
+
+ cd zhaozg-lua-openssl-5ecb647
+ sed 's!^PREFIX=.*!PREFIX='${BOSH_INSTALL_TARGET}/lua'!' config > tmp
+ sed 's!^CC=.*!CC= gcc $(CFLAGS)!' tmp > config
+ make
+ make install
+ cd ..
+
+ cd lua-cjson-1.0.3
+ sed 's!^PREFIX ?=.*!PREFIX ?='${BOSH_INSTALL_TARGET}/lua'!' Makefile > tmp
+ mv tmp Makefile
+ make
+ make install
+ cd ..
+
+ cd base64
+ sed 's!^LUAINC=.*!LUAINC='${BOSH_INSTALL_TARGET}/lua/include'!' Makefile > tmp
+ sed 's!^LUABIN=.*!LUABIN='${BOSH_INSTALL_TARGET}/lua/bin'!' tmp > Makefile
+ sed 's!^CFLAGS=.*!CFLAGS= $(INCS) $(WARN) -fPIC -O2 $G!' Makefile > tmp
+ mv tmp Makefile
+ make
+ cp base64.so ${BOSH_INSTALL_TARGET}/lua/lib/lua/5.1
+ cd ..
+)
+
+echo "Building nginx..."
+(
+ set -e
+
+ cd nginx-1.2.0
+ export LUA_LIB=${BOSH_INSTALL_TARGET}/lua/lib
+ export LUA_INC=${BOSH_INSTALL_TARGET}/lua/include
+ ./configure \
+ --prefix=${BOSH_INSTALL_TARGET} \
+ --with-pcre=../pcre-8.21 \
+ --with-http_ssl_module \
+ --add-module=../headers-more-v0.15rc1 \
+ --add-module=../nginx_upload_module-2.2.0 \
+ --add-module=../simpl-ngx_devel_kit-bc97eea \
+ --add-module=../chaoslawful-lua-nginx-module-204ce2b
+
+ make
+ make install
+
+ mkdir -p ${BOSH_INSTALL_TARGET}/lib
+ cp ${BOSH_INSTALL_TARGET}/lua/lib/lua/5.1/* ${BOSH_INSTALL_TARGET}/lib
+)
View
14 packages/nginx_next/spec
@@ -0,0 +1,14 @@
+---
+name: nginx_next
+files:
+- nginx/headers-more-v0.15rc1.tgz
+- nginx/nginx-1.2.0.tar.gz
+- nginx/pcre-8.21.tar.gz
+- nginx/nginx_upload_module-2.2.0.tar.gz
+- nginx/upload_module_put_support.patch
+- nginx/devel-kit-v0.2.17rc2.tar.gz
+- nginx/nginx-lua.v0.4.1.tar.gz
+- nginx/lbase64.tar.gz
+- nginx/lua-5.1.4.tar.gz
+- nginx/lua-cjson-1.0.3.tar.gz
+- nginx/lua-openssl-0.1.1.tar.gz
View
9 packages/routerv2/packaging
@@ -1,9 +0,0 @@
-# abort script on any command that exit with a non zero value
-set -e
-
-cp -a * ${BOSH_INSTALL_TARGET}
-
-(
- cd ${BOSH_INSTALL_TARGET}/router
- /var/vcap/packages/ruby/bin/bundle --local install --deployment
-)
View
10 packages/routerv2/pre_packaging
@@ -1,10 +0,0 @@
-# abort script on any command that exit with a non zero value
-set -e
-
-cd ${BUILD_DIR}
-
-cp -a core_routerv2/router .
-cp -a core_routerv2/bin .
-cp -a core_routerv2/common .
-
-rm -rf core_routerv2
View
8 packages/routerv2/spec
@@ -1,8 +0,0 @@
----
-name: routerv2
-dependencies:
-- ruby
-files:
-- core_routerv2/bin/router
-- core_routerv2/router/**/*
-- core_routerv2/common/**/*
1 src/core_routerv2
@@ -1 +0,0 @@
-Subproject commit 97f4c8cc28f9a2efea537dad04e4f2f51cea9a7b

0 comments on commit d57285c

Please sign in to comment.
Something went wrong with that request. Please try again.