Class: Zillabyte::Command::Flows
- Defined in:
- lib/zillabyte/cli/flows.rb
Overview
HIDDEN: superclass for components and apps
Direct Known Subclasses
Constant Summary collapse
- MAX_POLL_SECONDS =
60 * 15
- POLL_SLEEP =
2.0
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#authorize ⇒ Object
flows:authorize [ID] [SCOPE].
-
#delete ⇒ Object
flows:delete ID.
-
#details ⇒ Object
flows:details ID.
-
#errors ⇒ Object
flows:errors ID.
-
#info ⇒ Object
flows:info [DIR].
-
#kill ⇒ Object
flows:kill ID.
-
#live_run ⇒ Object
flows:live_run [OPERATION_NAME] [PIPE_NAME] [DIR].
-
#local ⇒ Object
flows:local [RPC_ARGS].
-
#logs ⇒ Object
flows:logs ID [OPERATION_NAME].
- #on_exit(flow_type) ⇒ Object
-
#pause ⇒ Object
flows:pause ID.
-
#prep ⇒ Object
flows:prep [DIR].
-
#pull ⇒ Object
flows:pull ID DIR.
-
#push ⇒ Object
flows:push [DIR].
-
#resume ⇒ Object
flows:resume.
-
#scale ⇒ Object
apps:scale ID OPERATION_NAME PARALLELISM.
Methods inherited from Base
Methods included from Helpers
#app, #ask, #command, #create_git_remote, #display, #error, #extract_app_from_git_config, #extract_app_in_dir, #format_with_bang, #friendly_dir, #get_flow_ui_link, #get_info, #get_rich_info, #git, #handle_downloading_manifest, #has_git?, #longest, #read_multiline, #truncate_message, #version_okay?, #with_tty
Constructor Details
This class inherits a constructor from Zillabyte::Command::Base
Instance Method Details
#authorize ⇒ Object
flows:authorize [ID] [SCOPE]
Changes permission of the flow.
–id ID # The dataset id –public # Makes the flow public (default) –private # Makes the flow private
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/zillabyte/cli/flows.rb', line 168 def id = [:id] || shift_argument if id.nil? id = read_name_from_conf() end make_public = [:public] make_private = [:private] error("no id given", type) if id.nil? error("both --public and --private cannot be given", type) if make_public && make_private scope = "public" if make_private scope = "private" end res = self.api.request( :expects => 200, :method => :post, :path => "/flows/#{CGI.escape(id)}/authorizations", :body => {:scope => scope}.to_json ).body display "Authorization updated" end |
#delete ⇒ Object
flows:delete ID
Deletes a flow. If the flow is running, this command will kill it.
-f, –force # Don’t ask for confirmation –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
# File 'lib/zillabyte/cli/flows.rb', line 617 def delete id = [:id] || shift_argument if id.nil? id = read_name_from_conf() end forced = [:force] type = [:output_type] if not forced if !type.nil? error("specify -f, --force to confirm deletion", type) end while true display "This operation cannot be undone. Are you sure you want to delete this flow? (yes/no):", false confirm = ask break if confirm == "yes" || confirm == "no" display "Please enter 'yes' to delete the flow or 'no' to exit" end end confirmed = forced || confirm == "yes" if confirmed display "Destroying flow ##{id}...please wait..." if type.nil? response = api.flows.create_delete(id, ) if response["job_id"] [:job_id] = response["job_id"] flow_id = response["flow_id"] start = Time.now.utc display "Destroy request sent. Please wait..." if type.nil? while(Time.now.utc < start + MAX_POLL_SECONDS) do # Poll res = self.api.flows.poll_delete(flow_id, ) case res['status'] when 'completed' if res['return'] if type == "json" display "{}" else display "Flow ##{id} destroyed" end else throw "something is wrong: #{res}" end # success! continue below break when 'running' sleep(POLL_SLEEP) else throw "unknown status: #{res}" end end elsif response["error"] error(response["error"], type) else error("remote server error (f413)", type) end end end |
#details ⇒ Object
flows:details ID
List details for a flow.
–output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/zillabyte/cli/flows.rb', line 357 def details flow_id = [:id] || shift_argument type = [:output_type] if flow_id.nil? flow_id = read_name_from_conf() end res = api.request( :expects => 200, :method => :get, :path => "/flows/#{flow_id}/details", :body => .to_json ) return if res.body.nil? error(res.body["error"], type) if res.body["error"] return if res.body["state"].nil? flow_state = res.body["state"] if type.nil? display "State: #{flow_state}" elsif ["KILLED", "RETIRED"].member? flow_state display res.body.to_json return end return if res.body["instances"].nil? instances = res.body["instances"].select do |instance| !instance.nil? end if instances.empty? if type display res.body.to_json end return end # a nested hash so can't map directly # instead i'll map separately and then merge the arrays heading1 = ["type", "name"] # a level deeper heading2 = ["consumed", "emitted", "errors", "parallelism"] # for the table output headings = heading1 + heading2 # get the values for the headings type_name = instances.map do |instance| heading1.map do |heading| instance[heading] end end # get the values for the headings stats = instances.map do |instance| heading2.map do |heading| instance["stats"][heading] end end # combine the arrays rows = type_name.zip(stats).map{|x,y| x.concat y} # check if it's from a dataset. # if the source is a dataset, there's a sharder. # remove source types, and hardcode sharder-named instances as source from_dataset = false rows.each do | row | if row[1].scan("sharder").length != 0 from_dataset = true break end end if from_dataset == true rows = rows.each do |row| if row[0].scan("source").length != 0 rows.delete(row) end end rows = rows.each do |row| if row[1].scan("sharder").length != 0 row[0] = "source" end end end # rows to be output to the CLI rows = rows.group_by { |type, name, consumed, emitted, errors, parallelism| name }.map{ |hashkey, array| [array[0][0], hashkey, array.inject(0){ |sum, i | sum + i[2].to_i }, array.inject(0){ |sum, i | sum + i[3].to_i },array.inject(0){ |sum, i | sum + i[4].to_i }, array.inject(0){|value, i| i[5].to_i}]} # example sums: [["sink", "has_facebook_likebox_and_vwo", 73, 0, 0], ["source", "sharder.1", 16, 10367872, 1], ["each", "each_3", 10367872, 73, 0]] # calculate percentage for the user to see attempts = 0 total = 0 if from_dataset == true rows.each do |instance| if instance[0] == "source" total = instance[3] end end rows.each do |instance| if instance[0] == "each" attempts = instance[2] end end end if attempts > 0 && total > 0 completion = attempts/total*100 else completion = 0 end # output on the CLI if type.nil? require('colorize') require("zillabyte/cli/helpers/table_output_builder") display TableOutputBuilder.build_terminal_table(headings, rows) if from_dataset == true display "percent complete: #{completion}%\n" end display "To view error details, type "+"`zillabyte errors`".colorize(:green)+"." else display res.body.to_json end end |
#errors ⇒ Object
flows:errors ID
Show recent errors generated by the flow.
–output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/zillabyte/cli/flows.rb', line 294 def errors require("colorize") # Init flow_id = [:id] || shift_argument # No name? if flow_id.nil? flow_id = read_name_from_conf() end type = [:output_type] # Make the request require("cgi") res = api.request( :expects => 200, :method => :get, :body => .to_json, :path => "/flows/#{CGI.escape(flow_id)}/errors" ) # Render display "Recent errors:" if type.nil? headings = ["operation", "date", "error"] rows = (res.body["recent_errors"] || []).map do |row| if row['date'] d = row['date'] else d = nil end [row['name'], d, row['message']] end rows.sort! do |a,b| a[0] <=> b[0] end color_map = {} colors = [:green, :yellow, :magenta, :cyan, :light_black, :light_green, :light_yellow, :light_blue, :light_magenta, :light_cyan] rows.each do |row| name = row[0] time = row[1] = row[2].strip color_map[name] ||= colors.shift if time display "#{"* #{name} - #{time}".colorize(color_map[name])}:" if type.nil? else display "#{"* #{name}".colorize(color_map[name])}:" if type.nil? end .split('\n').each do |sub_line| display " #{sub_line}" if type.nil? end end end |
#info ⇒ Object
flows:info [DIR]
Outputs the info for the flow in the dir.
–pretty # Pretty prints the info output –dir DIR # Flow directory –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN –host HOST # #HIDDEN –port PORT # #HIDDEN –unix_socket PATH # #HIDDEN
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/zillabyte/cli/flows.rb', line 563 def info # Init require 'socket' type = [:output_type] dir = [:dir] || shift_argument if dir.nil? dir = Dir.pwd else dir = File.(dir) end host = [:host] port = [:port] unix_socket = [:unix_socket] if (host && port) # Do we have a host, port? If so, delegate to the multilang... flow_info = Zillabyte::Helpers.get_info(dir, ) socket = TCPSocket.new(host, port) socket.write(flow_info.to_json) socket.close() exit elsif unix_socket flow_info = Zillabyte::Helpers.get_info(dir, ) socket = UNIXSocket.new(unix_socket) socket.write(flow_info.to_json) socket.close() exit else # Otherwise, start our own tcp socket and get the info, print to stdout flow_info = Zillabyte::Helpers.get_info(dir, ) if [:pretty] puts JSON.pretty_generate(flow_info) else puts flow_info.to_json end exit end end |
#kill ⇒ Object
flows:kill ID
Kills the given flow.
–config CONFIG_FILE # Use the given config file –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 |
# File 'lib/zillabyte/cli/flows.rb', line 1063 def kill id = [:id] || shift_argument type = [:output_type] if id.nil? id = read_name_from_conf() end display "Killing flow ##{id}...please wait..." if type.nil? response = api.flows.create_kill(id, ) if response["job_id"] [:job_id] = response["job_id"] flow_id = response["flow_id"] start = Time.now.utc display "Kill request sent. Please wait..." if type.nil? while(Time.now.utc < start + MAX_POLL_SECONDS) do # Poll res = self.api.flows.poll_kill(flow_id, ) case res['status'] when 'completed' if res['return'] if type == "json" display "{}" else display "Flow ##{id} killed" end else throw "something is wrong: #{res}" end # success! continue below break when 'running' sleep(POLL_SLEEP) # display ".", false else throw "unknown status: #{res}" end end elsif response["error"] error(response["error"], type) else error("remote server error (f569)", type) end end |
#live_run ⇒ Object
flows:live_run [OPERATION_NAME] [PIPE_NAME] [DIR]
Runs a local flow with live data.
–config CONFIG_FILE # Use the given config file –dir DIR # Flow directory –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN –host HOST # #HIDDEN –port PORT # #HIDDEN –unix_socket PATH # #HIDDEN
HIDDEN:
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/zillabyte/cli/flows.rb', line 520 def live_run require("zillabyte/cli/config") name = [:name] || shift_argument type = [:output_type] host = [:host] port = [:port] unix_socket = [:unix_socket] dir = [:dir] || shift_argument if dir.nil? dir = Dir.pwd else dir = File.(dir) end = Zillabyte::CLI::Config.get_config_info(dir, ) if .nil? error("could not find meta information for: #{dir}", type) end if(host && port) exec(Zillabyte::Helpers.command("--execute_live --name #{name.to_s} --host \"#{host}\" --port #{port}",type, dir)) elsif (unix_socket) exec(Zillabyte::Helpers.command("--execute_live --name #{name.to_s} --unix_socket \"#{unix_socket}\"",type, dir)) else exec(Zillabyte::Helpers.command("--execute_live --name #{name.to_s}",type, dir)) end end |
#local ⇒ Object
flows:local [RPC_ARGS]
Run a flow locally with sample data.
–dir DIR # Flow directory –input_file INPUT_FILE # Input csv file containing parameters for multiple queries –output_prefix OUTPUT_PREFIX # Prefix for output file containing app results. Results will be stored in [prefix]_.csv for each sink. –env ENV # HIDDEN –use_local_jar # HIDDEN –verbose # HIDDEN
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
# File 'lib/zillabyte/cli/flows.rb', line 703 def local require('colorize') def on_exit(flow_type) display "*"*79 if flow_type == "component" display "If you are happy with your RPC and would like to run it in parallel on our servers, please use `zillabyte execute`.".colorize(:green) else display "If you are happy with your app and would like to run it in parallel on our servers, please use `zillabyte push`.".colorize(:green) end display "*"*79 end dir = [:dir] if dir.nil? dir = Dir.pwd else dir = File.(dir) end env = [:env] || "prod" # Get the flow_type require("zillabyte/api/flows") = get_rich_info(dir, session, {:test => true}) if .nil? || ["nodes"].nil? error "this is not a valid zillabyte flow directory" exit end if ["flow_type"] == "component" #component file = [:input_file] component_input_stream = nil fields = [] ["nodes"].each do |node| if node["type"] == "input" component_input_stream = node["name"] fields = node["fields"].map {|field| field.keys.first} break end end component_args = [] if file require('csv') CSV.foreach(file) do |line| line_arg = {} line.each_with_index do |l, i| line_arg[fields[i]] = l end component_args << line_arg end else args = {} count = 0 while(true) do next_arg = shift_argument break if next_arg.nil? args[fields[count]] = next_arg count += 1 end component_args << args if !args.empty? end if component_args.empty? display "No input arguments given for RPC. Please see 'zillabyte help test' or 'zillabyte help local' for details." exit(1) end component_args = {component_input_stream => component_args} else #app output_prefix = [:output_prefix] end # Check that multilang version is atleast 0.1.0 version = ["multilang_version"] || "0.0.0" language = ["language"] require('zillabyte/auth') auth_token = Zillabyte::Auth.api_key_or_nil if !version_okay?(version, Zillabyte::CLI::VERSION) display "The version of zillabyte used in your flow is outdated." display "Please upgrade your zillabyte CLI using 'bundle update zillabyte; gem cleanup zillabyte'." case language when "python" display "Then upgrade your zillabyte Python library using '[sudo] pip install zillabyte --upgrade'." when "javascript" # something end return end # Take care of downloading the jar local = [:env] == "local" || [:use_local_jar] ? true : false jar_path = Zillabyte::Command::Download.new.jar(local) # Submit app to jar require('pty') require('json') require('shellwords') cmd = "java -jar #{jar_path} --flow.name #{["name"]} --flow.class #{["flow_type"]} --directory #{dir}" if env == "test" or env == "staging" cmd += " --api.host test.api.zillabyte.com --api.port 80" elsif env == "prod" cmd += " --api.host api.zillabyte.com --api.port 80" end cmd += " --rpc.args #{Shellwords.escape(component_args.to_json)}" if component_args cmd += " --output.prefix #{output_prefix}" if output_prefix cmd += " --auth.token #{auth_token}" if auth_token match_str = "[f#{["name"]}]" display "Begin local execution..." begin PTY.spawn(cmd) do |r, w, pid| done_cycle = false begin r.each do |line| if [:verbose] display line else if(line.include? match_str) line = line.chomp!.split(match_str).last if !done_cycle if line.include? "[ERROR]" display line.colorize(:red) elsif line.include? "sinking tuple:" display line.colorize(:green) else display line end end end done_cycle = true if(line.include? "[app][RUN] Transitioned to state WAITING" or line.include? "[app][RUN] Transitioned to state IDLE") end end rescue Errno::EIO => e # process has finished end end rescue Exception => e # Do nothing on error... ensure on_exit ["flow_type"] end end |
#logs ⇒ Object
flows:logs ID [OPERATION_NAME]
Streams logs for the flow from our cluster.
–operation OPERATION_NAME # Specify the operation to show logs for -v, –verbose LEVEL # Sets the verbosity (error, info, debug) [default: info] –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/zillabyte/cli/flows.rb', line 264 def logs flow_id = [:id] || shift_argument if flow_id.nil? flow_id = read_name_from_conf() end operation_id = [:operation] || shift_argument || '_ALL_' category = [:verbose] || '_ALL_' type = [:output_type] carry_settings = { :category => category } display "Retrieving logs for flow ##{flow_id}...please wait..." if type.nil? hash = self.api.logs.get(flow_id, operation_id, ) fetch_logs(hash, operation_id) end |
#on_exit(flow_type) ⇒ Object
705 706 707 708 709 710 711 712 713 |
# File 'lib/zillabyte/cli/flows.rb', line 705 def on_exit(flow_type) display "*"*79 if flow_type == "component" display "If you are happy with your RPC and would like to run it in parallel on our servers, please use `zillabyte execute`.".colorize(:green) else display "If you are happy with your app and would like to run it in parallel on our servers, please use `zillabyte push`.".colorize(:green) end display "*"*79 end |
#pause ⇒ Object
flows:pause ID
Pause a flow
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 |
# File 'lib/zillabyte/cli/flows.rb', line 854 def pause id = [:id] || shift_argument type = [:output_type] if id.nil? id = read_name_from_conf() end display "Pausing flow ##{id}...please wait..." if type.nil? response = api.flows.create_pause(id, ) if response["job_id"] [:job_id] = response["job_id"] flow_id = response["flow_id"] start = Time.now.utc display "Pause request sent. Please wait..." if type.nil? while(Time.now.utc < start + MAX_POLL_SECONDS) do # Poll res = self.api.flows.poll_pause(flow_id, ) case res['status'] when 'completed' if res['return'] if type == "json" display "{}" else display "Flow ##{id} paused" end else throw "something is wrong: #{res}" end # success! continue below break when 'running' sleep(POLL_SLEEP) # display ".", false else throw "unknown status: #{res}" end end elsif response["error"] error(response["error"], type) else error("remote server error (f569)", type) end end |
#prep ⇒ Object
flows:prep [DIR]
Performs any necessary initialization for the flow.
–dir DIR # Flow directory –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN –mode MODE # Specify development or production mode for dependencies #HIDDEN
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/zillabyte/cli/flows.rb', line 206 def prep() require("zillabyte/cli/config") require("shellwords") type = [:output_type] dir = [:dir] || shift_argument if dir.nil? dir = Dir.pwd else dir = File.(dir) end = Zillabyte::CLI::Config.get_config_info(dir) if .nil? error("The specified directory (#{dir}) does not appear to contain a valid Zillabyte configuration file.", type) end case ["language"] when "ruby" base_cmd = "cd \"#{['home_dir']}\"; unset BUNDLE_GEMFILE; unset RUBYOPT;" bundle_install_cmd = case [:mode] when "mock", /^mock-.+/ # Don't run 'bundle install' in test mode => speed things up. This assumes # all gems are already installed locally! else exec(base_cmd + "bundle install") end when "python" vDir = "#{['home_dir']}/vEnv" lock_file = ['home_dir']+"/zillabyte_thread_lock_file" if File.exists?(lock_file) sleep(1) while File.exists?(lock_file) else begin # TODO: won't the ~/zb1/ break in LXC and users' machines? cmd = "touch #{Shellwords.escape(lock_file)}; virtualenv --clear --system-site-packages #{Shellwords.escape(vDir)}; PYTHONPATH=$PYTHONPATH:~/zb1/multilang/python/Zillabyte #{Shellwords.escape(vDir)}/bin/pip install -r #{Shellwords.escape(File.join(['home_dir'], "requirements.txt"))}" system cmd, :out => :out ensure File.delete(lock_file) if File.exists?(lock_file) end end when "js" end end |
#pull ⇒ Object
flows:pull ID DIR
Pulls a flow source to a directory.
–force # Pulls even if the directory exists –dir DIR # Flow directory –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
Examples:
$ zillabyte flows:pull 27 .
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/zillabyte/cli/flows.rb', line 22 def pull flow_id = [:id] || shift_argument type = [:output_type] dir = [:dir] || shift_argument error("no directory given", type) if dir.nil? dir = File.(dir) error("no id given", type) if flow_id.nil? # Create if not exists.. if File.exists?(dir) if Dir.entries(dir).size != 2 and [:force].nil? error("target directory not empty. use --force to override", type) end else require("fileutils") FileUtils.mkdir_p(dir) end res = api.flows.pull_to_directory flow_id, dir, session, if res['error'] error("error: #{res['error_message']}", type) else if type == "json" display "{}" else display "Flow ##{res['id']} pulled to #{friendly_dir(dir)}" end end end |
#push ⇒ Object
flows:push [DIR]
Uploads a flow. –force # Don’t ask for confirmation –config CONFIG_FILE # Use the given config file –dir DIR # Flow directory –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN –public # Make the flow public
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/zillabyte/cli/flows.rb', line 67 def push since = Time.now.utc.to_s dir = [:dir] if dir.nil? dir = Dir.pwd else dir = File.(dir) end type = [:output_type] forced = [:force] # Get the meta info require('zillabyte/api/flows') [:local_flag] = 1 hash = get_rich_info(dir, session, ) if hash.nil? session.error("unable to extract #{flow_type} meta information", type) if session end if hash["error"] session.error(hash["error_message"], type) if session end flow_type = hash["flow_type"] flow_name = hash["name"] # Before killing live flow (with same name), ask for confirmation before push unless force flag is on if !forced if flow_type == "app" flows = api.app.list else flows = api.component.list end flows.each do |flow| if flow_name == flow["name"] if flow["state"] == "RUNNING" display "This flow is already running and will be terminated. Continue? [y/N]: ", false input = ask if !(input.downcase == "y" || input.downcase == "yes") return end end break end end end res = api.flows.push_directory dir, hash, session, if res['error'] error("error: #{res['error_message']}", type) else display "#{flow_type} ##{res['id']} #{res['action']}" if type.nil? end display "Setting up your #{flow_type}... please wait..." if type.nil? sleep(2) # wait for kill command hash = self.api.logs.get(res['id'], nil, ) if flow_type == "app" fetch_logs(hash, "_ALL_", ["App deployed", "STOP_LOGGING"]) elsif flow_type == "component" fetch_logs(hash, "_ALL_", ["Component registered", "STOP_LOGGING"]) end if type == "json" display "{}" else display "*"*79 if flow_type == "app" display "App deployed: #{get_flow_ui_link(res).colorize(:light_yellow)}" display "`zillabyte details`".colorize(:green)+" : to check the progress of your app." display "`zillabyte logs`".colorize(:green)+" : to look at log output." display "`zillabyte kill`".colorize(:green)+" : to stop your app on our servers." display "To inspect/download data produced by your app:" display "`zillabyte data:show [RELATION_NAME]`".colorize(:cyan)+" : to inspect your data." display "`zillabyte data:pull [RELATION_NAME] [OUTPUT_PREFIX] [DIRECTORY]`".colorize(:cyan)+" : to download your data." elsif flow_type == "component" display "Component registered: #{get_flow_ui_link(res).colorize(:light_yellow)}" display "Your component may now be embedded in any application!" display "`zillabyte execute`".colorize(:green)+" : to run your component as an RPC." end display "*"*79 end end |
#resume ⇒ Object
flows:resume
Resume a paused flow ID
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 |
# File 'lib/zillabyte/cli/flows.rb', line 910 def resume id = [:id] || shift_argument type = [:output_type] if id.nil? id = read_name_from_conf() end display "Resume flow ##{id}...please wait..." if type.nil? response = api.flows.create_resume(id, ) if response["job_id"] [:job_id] = response["job_id"] flow_id = response["flow_id"] start = Time.now.utc display "Resume request sent. Please wait..." if type.nil? while(Time.now.utc < start + MAX_POLL_SECONDS) do # Poll res = self.api.flows.poll_resume(flow_id, ) case res['status'] when 'completed' if res['return'] if type == "json" display "{}" else display "Flow ##{id} resumed" end else throw "something is wrong: #{res}" end # success! continue below break when 'running' sleep(POLL_SLEEP) # display ".", false else throw "unknown status: #{res}" end end elsif response["error"] error(response["error"], type) else error("remote server error (f569)", type) end end |
#scale ⇒ Object
apps:scale ID OPERATION_NAME PARALLELISM
Change the parallelism of of app or operation
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 |
# File 'lib/zillabyte/cli/flows.rb', line 969 def scale id = [:id] || shift_argument if id.nil? id = read_name_from_conf() end name = [:name] || shift_argument parallelism = [:parallelism] || shift_argument type = [:output_type] # Read current metadata from API display "Fetching configuration for flow ##{id}...please wait..." if type.nil? [:flow_id] = id response = api.flows.(id, ) if response["meta"] = response["meta"] nodes = ["nodes"] # Set new parallelism if necessary scaling = false nodes.each_with_index do |node, i| if node["name"] == name && node["parallelism"] != parallelism ["nodes"][i]["parallelism"] = parallelism scaling = true break end end if scaling display "Scaling flow ##{id}...please wait..." if type.nil? [:flow_config] = response = api.flows.create_scale(id, ) if response["job_id"] [:job_id] = response["job_id"] flow_id = response["flow_id"] start = Time.now.utc display "Scaling request sent. Please wait..." if type.nil? while(Time.now.utc < start + MAX_POLL_SECONDS) do # Poll .delete(:flow_config) res = self.api.flows.poll_scale(flow_id, ) case res['status'] when 'completed' if res['return'] if type == "json" display "{}" else display "Flow ##{id} scaled" end else throw "something is wrong: #{res}" end # success! continue below break when 'running' sleep(POLL_SLEEP) # display ".", false else throw "unknown status: #{res}" end end elsif response["error"] error(response["error"], type) else error("remote server error (f569)", type) end else error("Unable to find operation #{name}", type) end elsif response["error"] error(response["error"], type) end end |