Sha256: 774082ed0daa2e9669a95c9592895a231c98631a129698ab024d245f21842cc2

Contents?: true

Size: 1.85 KB

Versions: 35

Compression:

Stored size: 1.85 KB

Contents

require_relative 'paths'
require 'terminal-table'

module AppletHelper
    include Paths
    
    private
    def path_to_jenkins_slave_applets
        "#{path_to_environment}/Applets/Slave"
    end
    
    def path_to_jenkins_master_applet
        "#{path_to_environment}/Applets/master-agent.jnlp"
    end
    
    def applets_in_environment
        Dir["#{path_to_jenkins_slave_applets}/*.jnlp"]
    end
    
    public
    def should_start_slave
        File.exist?(path_to_environment)
    end
    
    def start_master
        `javaws "#{path_to_jenkins_master_applet}" 1>/dev/null`
    end
    
    def start_slave
        applets = applets_in_environment
        
        rows = []

        applets.each_with_index do |applet_file, index|
            file_name = File.basename(applet_file, ".jnlp")
            rows << [index, file_name]
        end

        table = Terminal::Table.new :headings => ['Index', 'Slave name'], :rows => rows
        puts(table)
        
        while true
            print('Enter index > ')
            user_input = STDIN.gets.to_i
            
            if (0...applets.count).include?(user_input)
                `javaws "#{applets[user_input]}" 1>/dev/null`
                break
            end
        end
    end

    def stop_applets
        begin
            java_processes = `jps -v`

            applets = applets_in_environment
            applets << path_to_jenkins_master_applet

            applets.each do |file_path|
                java_processes.each_line do |line|
                    if line.include? file_path
                        pid = line.split.first
                        `kill -9 #{pid}`
                        puts("Process #{pid} stoped")
                    end
                end
            end
            puts("Stop applets: done")
        rescue
            puts("Stop applets: fail")
        end
    end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
nixenvironment-0.0.161 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.160 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.159 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.158 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.157 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.156 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.155 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.154 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.153 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.152 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.150 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.148 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.141 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.147 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.146 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.145 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.144 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.143 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.142 lib/nixenvironment/jenkins/Modules/applet_helper.rb
nixenvironment-0.0.138.1 lib/nixenvironment/jenkins/Modules/applet_helper.rb