fluentd-server 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env +5 -2
- data/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +12 -0
- data/Procfile +2 -0
- data/README.md +19 -7
- data/Rakefile +7 -9
- data/db/migrate/{20140512203133_create_posts.rb → 0001_create_posts.rb} +0 -0
- data/db/migrate/0002_create_delayed_jobs.rb +22 -0
- data/db/migrate/0003_create_tasks.rb +14 -0
- data/db/schema.rb +25 -1
- data/fluentd-server.gemspec +4 -0
- data/jobs/.gitkeep +0 -0
- data/lib/fluentd_server/cli.rb +55 -5
- data/lib/fluentd_server/config.rb +12 -0
- data/lib/fluentd_server/decorator.rb +23 -1
- data/lib/fluentd_server/{environments.rb → environment.rb} +17 -1
- data/lib/fluentd_server/model.rb +59 -1
- data/lib/fluentd_server/task_runner.rb +88 -0
- data/lib/fluentd_server/version.rb +1 -1
- data/lib/fluentd_server/web.rb +68 -21
- data/lib/fluentd_server/web_helper.rb +14 -10
- data/public/css/bootstrap.min.css +4 -4
- data/public/js/bootstrap.min.js +4 -5
- data/{bench → spec/bench}/bench.rb +0 -0
- data/{bench → spec/bench}/result.md +1 -1
- data/spec/model_spec.rb +33 -0
- data/spec/spec_helper.rb +8 -3
- data/spec/task_runner_spec.rb +27 -0
- data/spec/tmp/.gitkeep +0 -0
- data/spec/web_helper_spec.rb +15 -0
- data/spec/web_spec.rb +103 -1
- data/views/_js.slim +30 -0
- data/views/_navbar.slim +6 -4
- data/views/_style.slim +4 -0
- data/views/layout.slim +8 -11
- data/views/posts/create.slim +3 -2
- data/views/posts/edit.slim +4 -3
- data/views/posts/layout.slim +8 -0
- data/views/posts/menu.slim +7 -0
- data/views/tasks/ajax.erb +21 -0
- data/views/tasks/show.slim +24 -0
- metadata +124 -53
- data/spec/api_spec.rb +0 -42
- data/views/posts/index.slim +0 -9
data/lib/fluentd_server/web.rb
CHANGED
@@ -5,7 +5,7 @@ require 'slim'
|
|
5
5
|
|
6
6
|
require 'fluentd_server'
|
7
7
|
require 'fluentd_server/config'
|
8
|
-
require 'fluentd_server/
|
8
|
+
require 'fluentd_server/environment'
|
9
9
|
require 'fluentd_server/model'
|
10
10
|
require 'fluentd_server/decorator'
|
11
11
|
require 'fluentd_server/logger'
|
@@ -24,18 +24,12 @@ class FluentdServer::Web < Sinatra::Base
|
|
24
24
|
helpers Sinatra::RedirectWithFlash
|
25
25
|
register Sinatra::ActiveRecordExtension
|
26
26
|
|
27
|
-
# get ALL posts
|
28
|
-
get "/" do
|
29
|
-
@posts = Post.order("name ASC")
|
30
|
-
slim :"posts/index"
|
31
|
-
end
|
32
|
-
|
33
27
|
# create new post
|
34
|
-
get
|
35
|
-
@tab = '
|
36
|
-
@
|
28
|
+
get %r{^/$|^/posts/create$} do
|
29
|
+
@tab = 'posts'
|
30
|
+
@posts = Post.order("name ASC")
|
37
31
|
@post = Post.new
|
38
|
-
slim :"posts/
|
32
|
+
slim :"posts/layout"
|
39
33
|
end
|
40
34
|
|
41
35
|
post "/posts" do
|
@@ -49,15 +43,16 @@ class FluentdServer::Web < Sinatra::Base
|
|
49
43
|
|
50
44
|
# edit post
|
51
45
|
get "/posts/:id/edit" do
|
52
|
-
@
|
53
|
-
@post = Post.
|
54
|
-
|
55
|
-
|
46
|
+
@tab = 'posts'
|
47
|
+
@post = Post.find_by(id: params[:id])
|
48
|
+
redirect "/" unless @post
|
49
|
+
@posts = Post.order("name ASC")
|
50
|
+
slim :"posts/layout"
|
56
51
|
end
|
57
52
|
|
58
53
|
post "/posts/:id" do
|
59
|
-
@post = Post.
|
60
|
-
|
54
|
+
@post = Post.find_by(id: params[:id])
|
55
|
+
redirect "/" unless @post
|
61
56
|
if @post.update(params[:post])
|
62
57
|
redirect "/posts/#{@post.id}/edit", :notice => @post.decorate.success_message
|
63
58
|
else
|
@@ -66,12 +61,12 @@ class FluentdServer::Web < Sinatra::Base
|
|
66
61
|
end
|
67
62
|
|
68
63
|
# delete post
|
69
|
-
|
70
|
-
@post = Post.find_by(
|
64
|
+
post "/posts/:id/delete" do
|
65
|
+
@post = Post.find_by(id: params[:id])
|
71
66
|
if @post.destroy
|
72
|
-
redirect "/", :notice => @post.decorate.success_message
|
67
|
+
redirect "/posts/create", :notice => @post.decorate.success_message
|
73
68
|
else
|
74
|
-
redirect "/", :error => @post.decorate.error_message
|
69
|
+
redirect "/posts/create", :error => @post.decorate.error_message
|
75
70
|
end
|
76
71
|
end
|
77
72
|
|
@@ -98,4 +93,56 @@ class FluentdServer::Web < Sinatra::Base
|
|
98
93
|
content_type :text
|
99
94
|
@post.decorate.render_body(query_params)
|
100
95
|
end
|
96
|
+
|
97
|
+
# list tasks
|
98
|
+
get "/tasks" do
|
99
|
+
@tab = 'tasks'
|
100
|
+
@tasks = Task.limit(20).order("id DESC")
|
101
|
+
slim :"tasks/show"
|
102
|
+
end
|
103
|
+
|
104
|
+
# show task
|
105
|
+
get "/tasks/:id" do
|
106
|
+
@tab = 'tasks'
|
107
|
+
@tasks = Task.limit(20).order("id DESC")
|
108
|
+
@task = Task.find_by(id: params[:id])
|
109
|
+
slim :"tasks/show"
|
110
|
+
end
|
111
|
+
|
112
|
+
# get task body in json for ajax
|
113
|
+
get "/json/tasks/:id/body" do
|
114
|
+
content_type :json
|
115
|
+
offset = params[:offset].to_i
|
116
|
+
task = Task.find_by(id: params[:id])
|
117
|
+
body = task.body(offset).to_s
|
118
|
+
bytes = body.bytesize
|
119
|
+
more_data = !task.finished? || bytes > offset
|
120
|
+
{
|
121
|
+
body: body,
|
122
|
+
bytes: bytes,
|
123
|
+
moreData: more_data,
|
124
|
+
}.to_json.tap {|json| logger.debug json }
|
125
|
+
end
|
126
|
+
|
127
|
+
# restart task
|
128
|
+
post "/task/restart" do
|
129
|
+
@task = ::Task.create_and_delete(name: 'Restart')
|
130
|
+
@task.restart
|
131
|
+
redirect "/tasks/#{@task.id}"
|
132
|
+
end
|
133
|
+
|
134
|
+
# status task
|
135
|
+
post "/task/status" do
|
136
|
+
@task = ::Task.create_and_delete(name: 'Status')
|
137
|
+
@task.status
|
138
|
+
redirect "/tasks/#{@task.id}"
|
139
|
+
end
|
140
|
+
|
141
|
+
# configtest task
|
142
|
+
post "/task/configtest" do
|
143
|
+
@task = ::Task.create_and_delete(name: 'Configtest')
|
144
|
+
@task.configtest
|
145
|
+
redirect "/tasks/#{@task.id}"
|
146
|
+
end
|
147
|
+
|
101
148
|
end
|
@@ -73,19 +73,23 @@ module FluentdServer::WebHelper
|
|
73
73
|
CGI.escape(str)
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
77
|
-
|
76
|
+
def active_if(cond)
|
77
|
+
'active' if cond
|
78
78
|
end
|
79
79
|
|
80
|
-
def
|
81
|
-
|
80
|
+
def disabled_if(cond)
|
81
|
+
'disabled="disabled"' if cond
|
82
82
|
end
|
83
83
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
def bootstrap_flash
|
85
|
+
slim <<-EOF
|
86
|
+
- if flash[:notice]
|
87
|
+
p.alert.alert-success
|
88
|
+
== flash[:notice]
|
89
|
+
- if flash[:error]
|
90
|
+
p.alert.alert-danger
|
91
|
+
== flash[:error]
|
92
|
+
EOF
|
90
93
|
end
|
94
|
+
|
91
95
|
end
|