-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aravinda Vishwanathapura <[email protected]>
- Loading branch information
1 parent
e4644aa
commit 3139736
Showing
7 changed files
with
171 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
require "moana_types" | ||
|
||
require "../conf" | ||
require "./helpers" | ||
require "../datastore/*" | ||
require "./ping" | ||
require "./volume_utils.cr" | ||
|
||
ACTION_VOLUME_START = "volume_start" | ||
ACTION_VOLUME_STOP = "volume_stop" | ||
|
||
node_action ACTION_VOLUME_START do |data| | ||
handle_node_volume_start_stop(data, "start") | ||
end | ||
|
||
node_action ACTION_VOLUME_STOP do |data| | ||
handle_node_volume_start_stop(data, "stop") | ||
end | ||
|
||
def volume_start_stop(env, action) | ||
pool_name = env.params.url["pool_name"] | ||
volume_name = env.params.url["volume_name"] | ||
|
||
volume = Datastore.get_volume(pool_name, volume_name) | ||
|
||
if volume.nil? | ||
env.response.status_code = 400 | ||
return {"error": "Volume doesn't exists"}.to_json | ||
end | ||
|
||
return volume.to_json if action == "start" && volume.state == "Started" | ||
return volume.to_json if action == "stop" && volume.state == "Stopped" | ||
|
||
nodes = participating_nodes(pool_name, volume) | ||
node_details_add_to_volume(volume, nodes) | ||
|
||
# TODO: Add to missed_ops if a node is not reachable | ||
|
||
# Generate Services and Volfiles if Volume to be started | ||
services, volfiles = services_and_volfiles(volume) | ||
|
||
resp = dispatch_action( | ||
action == "start" ? ACTION_VOLUME_START : ACTION_VOLUME_STOP, | ||
pool_name, | ||
nodes, | ||
{services, volfiles, volume}.to_json | ||
) | ||
|
||
if !resp.ok | ||
env.response.status_code = 400 | ||
return node_errors("Failed to #{action} the Volume", resp.node_responses).to_json | ||
end | ||
|
||
# Save Services details | ||
services.each do |node, svcs| | ||
svcs.each do |svc| | ||
if action == "start" | ||
# Enable each Services | ||
Datastore.enable_service(pool_name, node, svc) | ||
else | ||
# Disable each Services | ||
Datastore.disable_service(pool_name, node, svc) | ||
end | ||
end | ||
end | ||
|
||
volume.state = action == "start" ? "Started" : "Stopped" | ||
Datastore.update_volume(pool_name, volume) | ||
|
||
volume.to_json | ||
end | ||
|
||
post "/api/v1/pools/:pool_name/volumes/:volume_name/start" do |env| | ||
volume_start_stop(env, "start") | ||
end | ||
|
||
post "/api/v1/pools/:pool_name/volumes/:volume_name/stop" do |env| | ||
volume_start_stop(env, "stop") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters