@@ -4,148 +4,144 @@ class ClustersController < AuthenticatedUsersController
44 { clusters : ClusterPresenter . list ( clusters ) } . to_json
55 end
66
7- get '/clusters/:cluster_id' do
8- cluster = Tendrl ::Cluster . find ( params [ :cluster_id ] )
9- status 200
10- ClusterPresenter . single (
11- params [ :cluster_id ] => cluster . attributes
12- ) . to_json
7+ before '/clusters/:cluster_id/?*?' do
8+ @cluster = Tendrl ::Cluster . new ( params [ :cluster_id ] )
9+ #@cluster.gd2.get("/ping")
1310 end
1411
15- get '/clusters/:cluster_id/nodes' do
16- nodes = Tendrl ::Node . find_all_by_cluster_id ( params [ :cluster_id ] )
17- node_list = NodePresenter . list ( nodes ) . map do |node_data |
18- bricks = Tendrl ::Brick . find_all_by_cluster_id_and_node_fqdn (
19- params [ :cluster_id ] , node_data [ 'fqdn' ]
20- )
21- node_data . merge ( bricks_count : bricks . size )
22- end
23- { nodes : node_list } . to_json
12+ get '/clusters/:cluster_id' do
13+ state = @cluster . gd2 . state
14+ state . to_json
2415 end
2516
26- get '/clusters/:cluster_id/nodes/:node_id/bricks' do
27- node = Tendrl ::Node . find_by_cluster_id (
28- params [ :cluster_id ] , params [ :node_id ]
29- )
30- halt 404 unless node . present?
31- bricks = Tendrl ::Brick . find_all_by_cluster_id_and_node_fqdn (
32- params [ :cluster_id ] , node [ 'fqdn' ]
33- )
34- { bricks : BrickPresenter . list ( bricks ) } . to_json
17+ get '/clusters/:cluster_id/peers' do
18+ peers = @cluster . gd2 . peers
19+ { peers : peers } . to_json
3520 end
3621
3722 get '/clusters/:cluster_id/volumes' do
38- volumes = Tendrl :: Volume . find_all_by_cluster_id ( params [ :cluster_id ] )
39- { volumes : VolumePresenter . list ( volumes ) } . to_json
23+ volumes = @cluster . gd2 . volumes
24+ { volumes : volumes } . to_json
4025 end
4126
42- get '/clusters/:cluster_id/volumes/:volume_id/bricks' do
43- references = Tendrl ::Brick . find_refs_by_cluster_id_and_volume_id (
44- params [ :cluster_id ] , params [ :volume_id ]
45- )
46- bricks = Tendrl ::Brick . find_by_cluster_id_and_refs ( params [ :cluster_id ] , references )
47- { bricks : BrickPresenter . list ( bricks ) } . to_json
27+ post '/import' do
28+ new_endpoint = {
29+ gd2_url : parsed_body [ 'gd2_url' ] ,
30+ secret : parsed_body [ 'secret' ]
31+ }
32+ gd2 = Gd2Client . new new_endpoint
33+ state = gd2 . state
34+ cluster = Tendrl ::Cluster . new state [ 'cluster-id' ]
35+ unless cluster . endpoints . include? new_endpoint
36+ Tendrl . etcd . create_in_order (
37+ "/clusters/#{ state [ 'cluster-id' ] } /endpoints" ,
38+ value : new_endpoint . to_json
39+ )
40+ end
41+ status 201
42+ state . merge ( endpoints : cluster . endpoints ) . to_json
4843 end
4944
50- get '/clusters/:cluster_id/notifications' do
51- notifications = Tendrl ::Notification . all
52- NotificationPresenter . list_by_integration_id ( notifications , params [ :cluster_id ] ) . to_json
53- end
45+ #get '/clusters/:cluster_id/nodes/:node_id/bricks' do
46+ #node = Tendrl::Node.find_by_cluster_id(
47+ #params[:cluster_id], params[:node_id]
48+ #)
49+ #halt 404 unless node.present?
50+ #bricks = Tendrl::Brick.find_all_by_cluster_id_and_node_fqdn(
51+ #params[:cluster_id], node['fqdn']
52+ #)
53+ #{ bricks: BrickPresenter.list(bricks) }.to_json
54+ #end
5455
55- get '/clusters/:cluster_id/jobs' do
56- begin
57- jobs = Tendrl ::Job . all
58- rescue Etcd ::KeyNotFound
59- jobs = [ ]
60- end
61- { jobs : JobPresenter . list_by_integration_id ( jobs , params [ :cluster_id ] ) } . to_json
62- end
56+ #get '/clusters/:cluster_id/volumes/:volume_id/bricks' do
57+ #references = Tendrl::Brick.find_refs_by_cluster_id_and_volume_id(
58+ #params[:cluster_id], params[:volume_id]
59+ #)
60+ #bricks = Tendrl::Brick.find_by_cluster_id_and_refs(params[:cluster_id], references)
61+ #{ bricks: BrickPresenter.list(bricks) }.to_json
62+ #end
6363
64- post '/clusters/:cluster_id/import' do
65- Tendrl . load_node_definitions
66- Tendrl ::Cluster . exist? params [ :cluster_id ]
67- flow = Tendrl ::Flow . new ( 'namespace.tendrl' , 'ImportCluster' )
68- body = JSON . parse ( request . body . read )
69- body [ 'Cluster.volume_profiling_flag' ] = if [ 'enable' , 'disable' ] . include? ( body [ 'Cluster.volume_profiling_flag' ] )
70- body [ 'Cluster.volume_profiling_flag' ]
71- else
72- 'leave-as-is'
73- end
74- job = Tendrl ::Job . new (
75- current_user ,
76- flow ,
77- integration_id : params [ :cluster_id ] ) . create ( body )
78- status 202
79- { job_id : job . job_id } . to_json
80- end
64+ #get '/clusters/:cluster_id/notifications' do
65+ #notifications = Tendrl::Notification.all
66+ #NotificationPresenter.list_by_integration_id(notifications, params[:cluster_id]).to_json
67+ #end
8168
82- post '/clusters/:cluster_id/unmanage' do
83- Tendrl . load_node_definitions
84- flow = Tendrl ::Flow . new ( 'namespace.tendrl' , 'UnmanageCluster' )
85- body = JSON . parse ( request . body . string . present? ? request . body . string : '{}' )
86- job = Tendrl ::Job . new (
87- current_user ,
88- flow ,
89- integration_id : params [ :cluster_id ] ) . create ( body )
90- status 202
91- { job_id : job . job_id } . to_json
92- end
69+ #get '/clusters/:cluster_id/jobs' do
70+ #begin
71+ #jobs = Tendrl::Job.all
72+ #rescue Etcd::KeyNotFound
73+ #jobs = []
74+ #end
75+ #{ jobs: JobPresenter.list_by_integration_id(jobs, params[:cluster_id]) }.to_json
76+ #end
9377
94- post '/clusters/:cluster_id/expand ' do
95- Tendrl . load_node_definitions
96- flow = Tendrl ::Flow . new 'namespace.tendrl' , 'ExpandClusterWithDetectedPeers'
97- job = Tendrl :: Job . new (
98- current_user ,
99- flow ,
100- integration_id : params [ :cluster_id ]
101- ) . create ( { } )
102- status 202
103- { job_id : job . job_id } . to_json
104- end
78+ # post '/clusters/:cluster_id/unmanage ' do
79+ # Tendrl.load_node_definitions
80+ # flow = Tendrl::Flow.new( 'namespace.tendrl', 'UnmanageCluster')
81+ #body = JSON.parse(request.body.string.present? ? request.body.string : '{}')
82+ #job = Tendrl::Job.new(
83+ #current_user ,
84+ #flow,
85+ #integration_id: params[:cluster_id] ).create(body )
86+ # status 202
87+ # { job_id: job.job_id }.to_json
88+ # end
10589
106- post '/clusters/:cluster_id/profiling' do
107- Tendrl . load_definitions ( params [ :cluster_id ] )
108- body = JSON . parse ( request . body . read )
109- volume_profiling_flag = if [ 'enable' , 'disable' ] . include? ( body [ 'Cluster.volume_profiling_flag' ] )
110- body [ 'Cluster.volume_profiling_flag' ]
111- else
112- 'leave-as-is'
113- end
114- flow = Tendrl ::Flow . new ( 'namespace.gluster' , 'EnableDisableVolumeProfiling' )
90+ #post '/clusters/:cluster_id/expand' do
91+ #Tendrl.load_node_definitions
92+ #flow = Tendrl::Flow.new 'namespace.tendrl', 'ExpandClusterWithDetectedPeers'
93+ #job = Tendrl::Job.new(
94+ #current_user,
95+ #flow,
96+ #integration_id: params[:cluster_id]
97+ #).create({})
98+ #status 202
99+ #{ job_id: job.job_id }.to_json
100+ #end
115101
116- job = Tendrl :: Job . new (
117- current_user ,
118- flow ,
119- integration_id : params [ :cluster_id ] ,
120- type : 'sds'
121- ) . create ( 'Cluster.volume_profiling_flag' => volume_profiling_flag )
122- status 202
123- { job_id : job . job_id } . to_json
124- end
102+ #post '/clusters/:cluster_id/profiling' do
103+ #Tendrl.load_definitions(params[:cluster_id])
104+ #body = JSON.parse(request.body.read)
105+ #volume_profiling_flag = if ['enable', 'disable'].include?(body['Cluster.volume_profiling_flag'])
106+ #body['Cluster.volume_profiling_flag']
107+ #else
108+ #'leave-as-is'
109+ #end
110+ #flow = Tendrl::Flow.new('namespace.gluster', 'EnableDisableVolumeProfiling')
125111
126- post '/clusters/:cluster_id/volumes/:volume_id/start_profiling' do
127- Tendrl . load_definitions ( params [ :cluster_id ] )
128- flow = Tendrl ::Flow . new ( 'namespace.gluster' , 'StartProfiling' , 'Volume' )
129- job = Tendrl ::Job . new (
130- current_user ,
131- flow ,
132- integration_id : params [ :cluster_id ] ,
133- type : 'sds'
134- ) . create ( 'Volume.vol_id' => params [ :volume_id ] )
135- status 202
136- { job_id : job . job_id } . to_json
137- end
112+ #job = Tendrl::Job.new(
113+ #current_user,
114+ #flow,
115+ #integration_id: params[:cluster_id],
116+ #type: 'sds'
117+ #).create('Cluster.volume_profiling_flag' => volume_profiling_flag)
118+ #status 202
119+ #{ job_id: job.job_id }.to_json
120+ #end
138121
139- post '/clusters/:cluster_id/volumes/:volume_id/stop_profiling' do
140- Tendrl . load_definitions ( params [ :cluster_id ] )
141- flow = Tendrl ::Flow . new ( 'namespace.gluster' , 'StopProfiling' , 'Volume' )
142- job = Tendrl ::Job . new (
143- current_user ,
144- flow ,
145- integration_id : params [ :cluster_id ] ,
146- type : 'sds'
147- ) . create ( 'Volume.vol_id' => params [ :volume_id ] )
148- status 202
149- { job_id : job . job_id } . to_json
150- end
122+ #post '/clusters/:cluster_id/volumes/:volume_id/start_profiling' do
123+ #Tendrl.load_definitions(params[:cluster_id])
124+ #flow = Tendrl::Flow.new('namespace.gluster', 'StartProfiling', 'Volume')
125+ #job = Tendrl::Job.new(
126+ #current_user,
127+ #flow,
128+ #integration_id: params[:cluster_id],
129+ #type: 'sds'
130+ #).create('Volume.vol_id' => params[:volume_id])
131+ #status 202
132+ #{ job_id: job.job_id }.to_json
133+ #end
134+
135+ #post '/clusters/:cluster_id/volumes/:volume_id/stop_profiling' do
136+ #Tendrl.load_definitions(params[:cluster_id])
137+ #flow = Tendrl::Flow.new('namespace.gluster', 'StopProfiling', 'Volume')
138+ #job = Tendrl::Job.new(
139+ #current_user,
140+ #flow,
141+ #integration_id: params[:cluster_id],
142+ #type: 'sds'
143+ #).create('Volume.vol_id' => params[:volume_id])
144+ #status 202
145+ #{ job_id: job.job_id }.to_json
146+ #end
151147end
0 commit comments