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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.env +5 -2
  3. data/.gitignore +2 -0
  4. data/.travis.yml +3 -0
  5. data/CHANGELOG.md +12 -0
  6. data/Procfile +2 -0
  7. data/README.md +19 -7
  8. data/Rakefile +7 -9
  9. data/db/migrate/{20140512203133_create_posts.rb → 0001_create_posts.rb} +0 -0
  10. data/db/migrate/0002_create_delayed_jobs.rb +22 -0
  11. data/db/migrate/0003_create_tasks.rb +14 -0
  12. data/db/schema.rb +25 -1
  13. data/fluentd-server.gemspec +4 -0
  14. data/jobs/.gitkeep +0 -0
  15. data/lib/fluentd_server/cli.rb +55 -5
  16. data/lib/fluentd_server/config.rb +12 -0
  17. data/lib/fluentd_server/decorator.rb +23 -1
  18. data/lib/fluentd_server/{environments.rb → environment.rb} +17 -1
  19. data/lib/fluentd_server/model.rb +59 -1
  20. data/lib/fluentd_server/task_runner.rb +88 -0
  21. data/lib/fluentd_server/version.rb +1 -1
  22. data/lib/fluentd_server/web.rb +68 -21
  23. data/lib/fluentd_server/web_helper.rb +14 -10
  24. data/public/css/bootstrap.min.css +4 -4
  25. data/public/js/bootstrap.min.js +4 -5
  26. data/{bench → spec/bench}/bench.rb +0 -0
  27. data/{bench → spec/bench}/result.md +1 -1
  28. data/spec/model_spec.rb +33 -0
  29. data/spec/spec_helper.rb +8 -3
  30. data/spec/task_runner_spec.rb +27 -0
  31. data/spec/tmp/.gitkeep +0 -0
  32. data/spec/web_helper_spec.rb +15 -0
  33. data/spec/web_spec.rb +103 -1
  34. data/views/_js.slim +30 -0
  35. data/views/_navbar.slim +6 -4
  36. data/views/_style.slim +4 -0
  37. data/views/layout.slim +8 -11
  38. data/views/posts/create.slim +3 -2
  39. data/views/posts/edit.slim +4 -3
  40. data/views/posts/layout.slim +8 -0
  41. data/views/posts/menu.slim +7 -0
  42. data/views/tasks/ajax.erb +21 -0
  43. data/views/tasks/show.slim +24 -0
  44. metadata +124 -53
  45. data/spec/api_spec.rb +0 -42
  46. data/views/posts/index.slim +0 -9
@@ -5,7 +5,7 @@ require 'slim'
5
5
 
6
6
  require 'fluentd_server'
7
7
  require 'fluentd_server/config'
8
- require 'fluentd_server/environments'
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 "/posts/create" do
35
- @tab = 'create'
36
- @title = 'Create'
28
+ get %r{^/$|^/posts/create$} do
29
+ @tab = 'posts'
30
+ @posts = Post.order("name ASC")
37
31
  @post = Post.new
38
- slim :"posts/create"
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
- @title = 'Edit'
53
- @post = Post.find(params[:id])
54
- return 404 unless @post
55
- slim :"posts/edit"
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.find(params[:id])
60
- return 404 unless @post
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
- get "/posts/:name/delete" do
70
- @post = Post.find_by(name: params[:name])
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 title
77
- @title || 'Welcome'
76
+ def active_if(cond)
77
+ 'active' if cond
78
78
  end
79
79
 
80
- def tab
81
- @tab || 'welcome'
80
+ def disabled_if(cond)
81
+ 'disabled="disabled"' if cond
82
82
  end
83
83
 
84
- def active(_tab)
85
- if tab == _tab
86
- 'active'
87
- else
88
- ''
89
- end
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