pione 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.s3cfg +42 -0
- data/.travis.yml +18 -4
- data/.yardopts +1 -0
- data/Gemfile +3 -0
- data/History.txt +14 -0
- data/Procfile +7 -0
- data/Rakefile +25 -0
- data/bin/pione-interactive +6 -0
- data/bin/{pione-compiler → pione-notification-listener} +1 -1
- data/bin/{pione-broker → pione-task-worker-broker} +1 -1
- data/doc/man/pione-list-param.md +36 -0
- data/example/ActionError/ActionError.pione +9 -0
- data/example/ActionError/pione-package.json +15 -0
- data/example/CountChar/CountChar.pione +1 -1
- data/example/ScoreAggregation/ScoreAggregation.pione +1 -1
- data/example/Touch/pione-package.json +15 -0
- data/lib/pione.rb +12 -0
- data/lib/pione/agent.rb +3 -3
- data/lib/pione/agent/basic-agent.rb +10 -4
- data/lib/pione/agent/input-generator.rb +3 -3
- data/lib/pione/agent/{process-manager.rb → job-manager.rb} +10 -7
- data/lib/pione/agent/job-terminator.rb +2 -2
- data/lib/pione/agent/logger.rb +3 -3
- data/lib/pione/agent/messenger.rb +20 -9
- data/lib/pione/agent/notification-listener.rb +88 -0
- data/lib/pione/agent/task-worker-broker.rb +84 -0
- data/lib/pione/agent/task-worker.rb +3 -2
- data/lib/pione/agent/tuple-space-client.rb +1 -0
- data/lib/pione/agent/tuple-space-provider.rb +17 -35
- data/lib/pione/command.rb +33 -15
- data/lib/pione/command/action.rb +105 -0
- data/lib/pione/command/basic-command.rb +34 -376
- data/lib/pione/command/command-exception.rb +12 -11
- data/lib/pione/command/common.rb +198 -0
- data/lib/pione/command/option.rb +159 -204
- data/lib/pione/command/pione-action-exec.rb +85 -0
- data/lib/pione/command/pione-action-list.rb +43 -19
- data/lib/pione/command/pione-action-print.rb +79 -0
- data/lib/pione/command/pione-action.rb +8 -67
- data/lib/pione/command/pione-clean.rb +88 -68
- data/lib/pione/command/pione-client.rb +475 -332
- data/lib/pione/command/pione-command.rb +14 -31
- data/lib/pione/command/pione-compile.rb +90 -0
- data/lib/pione/command/pione-config-get.rb +53 -0
- data/lib/pione/command/pione-config-list.rb +64 -0
- data/lib/pione/command/pione-config-set.rb +59 -0
- data/lib/pione/command/pione-config-unset.rb +50 -0
- data/lib/pione/command/pione-config.rb +61 -0
- data/lib/pione/command/pione-diagnosis-notification.rb +235 -0
- data/lib/pione/command/pione-diagnosis.rb +21 -0
- data/lib/pione/command/pione-interactive.rb +188 -0
- data/lib/pione/command/pione-lang-check-syntax.rb +163 -0
- data/lib/pione/command/pione-lang-interactive.rb +146 -0
- data/lib/pione/command/pione-lang.rb +22 -0
- data/lib/pione/command/pione-log-format.rb +163 -0
- data/lib/pione/command/pione-log-list-id.rb +48 -0
- data/lib/pione/command/pione-log.rb +19 -101
- data/lib/pione/command/pione-notification-listener.rb +95 -0
- data/lib/pione/command/pione-package-add.rb +137 -0
- data/lib/pione/command/pione-package-build.rb +122 -0
- data/lib/pione/command/pione-package-show.rb +96 -0
- data/lib/pione/command/pione-package-update.rb +59 -0
- data/lib/pione/command/pione-package.rb +11 -139
- data/lib/pione/command/pione-task-worker-broker.rb +88 -0
- data/lib/pione/command/pione-task-worker.rb +148 -98
- data/lib/pione/command/pione-tuple-space-provider.rb +62 -54
- data/lib/pione/command/pione-tuple-space-viewer.rb +105 -83
- data/lib/pione/command/pione-val.rb +39 -39
- data/lib/pione/command/spawner.rb +34 -27
- data/lib/pione/front.rb +4 -2
- data/lib/pione/front/basic-front.rb +86 -23
- data/lib/pione/front/client-front.rb +2 -2
- data/lib/pione/front/diagnosis-notification-front.rb +40 -0
- data/lib/pione/front/front-exception.rb +7 -1
- data/lib/pione/front/notification-listener-front.rb +36 -0
- data/lib/pione/front/notification-recipient-interface.rb +19 -0
- data/lib/pione/front/relay-front.rb +4 -4
- data/lib/pione/front/task-worker-broker-front.rb +19 -0
- data/lib/pione/front/task-worker-front.rb +2 -2
- data/lib/pione/front/tuple-space-provider-front.rb +3 -2
- data/lib/pione/global.rb +3 -1
- data/lib/pione/global/client-variable.rb +1 -1
- data/lib/pione/global/config.rb +63 -7
- data/lib/pione/global/diagnosis-variable.rb +26 -0
- data/lib/pione/global/item.rb +28 -5
- data/lib/pione/global/log-variable.rb +6 -5
- data/lib/pione/global/network-variable.rb +75 -4
- data/lib/pione/global/path-variable.rb +1 -1
- data/lib/pione/global/system-variable.rb +12 -12
- data/lib/pione/global/task-worker-broker-variable.rb +43 -0
- data/lib/pione/global/tuple-space-notifier-variable.rb +3 -55
- data/lib/pione/lang/boolean.rb +4 -0
- data/lib/pione/lang/data-expr.rb +1 -1
- data/lib/pione/lang/integer.rb +1 -1
- data/lib/pione/lang/string.rb +4 -0
- data/lib/pione/lang/type.rb +1 -1
- data/lib/pione/location.rb +1 -0
- data/lib/pione/location/data-location.rb +41 -13
- data/lib/pione/location/dropbox-location.rb +175 -56
- data/lib/pione/location/ftp-location.rb +4 -1
- data/lib/pione/location/http-location.rb +5 -3
- data/lib/pione/location/https-location.rb +4 -2
- data/lib/pione/location/local-location.rb +6 -3
- data/lib/pione/location/location-exception.rb +12 -0
- data/lib/pione/location/notification-scheme.rb +46 -0
- data/lib/pione/log.rb +8 -7
- data/lib/pione/log/debug.rb +9 -9
- data/lib/pione/log/domain-log.rb +6 -1
- data/lib/pione/log/message-log-receiver.rb +32 -0
- data/lib/pione/log/system-log.rb +62 -141
- data/lib/pione/model.rb +7 -0
- data/lib/pione/model/notification-listener-model.rb +29 -0
- data/lib/pione/model/task-worker-broker-model.rb +129 -0
- data/lib/pione/notification.rb +13 -0
- data/lib/pione/notification/address.rb +104 -0
- data/lib/pione/notification/exception.rb +10 -0
- data/lib/pione/notification/message.rb +109 -0
- data/lib/pione/notification/receiver.rb +90 -0
- data/lib/pione/notification/recipient.rb +68 -0
- data/lib/pione/notification/task-worker-broker-recipient.rb +85 -0
- data/lib/pione/notification/transmitter.rb +84 -0
- data/lib/pione/pnml.rb +35 -0
- data/lib/pione/pnml/annotation-extractor.rb +47 -0
- data/lib/pione/pnml/compiler.rb +176 -0
- data/lib/pione/pnml/input-merge-complement.rb +78 -0
- data/lib/pione/pnml/input-parallelization-complement.rb +75 -0
- data/lib/pione/pnml/input-reduction.rb +80 -0
- data/lib/pione/pnml/invalid-arc-elimination.rb +41 -0
- data/lib/pione/pnml/io-expansion.rb +88 -0
- data/lib/pione/pnml/isolated-element-elimination.rb +32 -0
- data/lib/pione/pnml/net-rewriter.rb +44 -0
- data/lib/pione/pnml/output-decomposition-complement.rb +77 -0
- data/lib/pione/pnml/output-reduction.rb +86 -0
- data/lib/pione/pnml/output-synchronization-complement.rb +77 -0
- data/lib/pione/pnml/pione-model.rb +417 -0
- data/lib/pione/pnml/pnml-exception.rb +23 -0
- data/lib/pione/pnml/pnml-model.rb +368 -0
- data/lib/pione/pnml/reader.rb +51 -0
- data/lib/pione/rule-engine/action-handler.rb +8 -6
- data/lib/pione/rule-engine/basic-handler.rb +5 -5
- data/lib/pione/rule-engine/engine-exception.rb +7 -6
- data/lib/pione/rule-engine/flow-handler.rb +27 -18
- data/lib/pione/system.rb +3 -1
- data/lib/pione/system/domain-dump.rb +34 -0
- data/lib/pione/system/file-cache.rb +92 -13
- data/lib/pione/system/init.rb +3 -0
- data/lib/pione/system/normalizer.rb +40 -0
- data/lib/pione/system/status.rb +5 -5
- data/lib/pione/system/system-exception.rb +14 -1
- data/lib/pione/task-worker-broker.rb +7 -0
- data/lib/pione/task-worker-broker/basic-provider.rb +20 -0
- data/lib/pione/task-worker-broker/easy-provider.rb +65 -0
- data/lib/pione/test-helper.rb +27 -0
- data/lib/pione/test-helper/command-helper.rb +9 -101
- data/lib/pione/tuple-space/basic-tuple.rb +1 -1
- data/lib/pione/tuple-space/tuple-definition.yml +4 -6
- data/lib/pione/tuple-space/tuple-space-interface.rb +3 -45
- data/lib/pione/tuple-space/tuple-space-server.rb +45 -0
- data/lib/pione/util.rb +1 -2
- data/lib/pione/util/boolean-value.rb +62 -0
- data/lib/pione/util/completion.rb +111 -0
- data/lib/pione/util/evaluatable.rb +13 -27
- data/lib/pione/util/package-parameters-list.rb +15 -27
- data/lib/pione/util/zip.rb +8 -3
- data/lib/pione/version.rb +1 -1
- data/lib/rootage.rb +20 -0
- data/lib/rootage/action.rb +114 -0
- data/lib/rootage/argument.rb +46 -0
- data/lib/rootage/command.rb +218 -0
- data/lib/rootage/core.rb +532 -0
- data/lib/rootage/exception.rb +107 -0
- data/lib/rootage/help.rb +148 -0
- data/lib/rootage/help.txt.erb +31 -0
- data/lib/rootage/log.rb +226 -0
- data/lib/rootage/normalizer.rb +184 -0
- data/lib/rootage/option.rb +152 -0
- data/lib/rootage/scenario-test-result.erb +39 -0
- data/lib/rootage/scenario.rb +362 -0
- data/lib/rootage/test-helper.rb +115 -0
- data/man/pione-list-param.1 +44 -0
- data/misc/clock.rb +9 -0
- data/misc/machine-info.sh +21 -0
- data/misc/pione-completion.bash +238 -0
- data/misc/pione-completion.erb +53 -0
- data/misc/pione-completion.zsh +238 -0
- data/misc/pione.god +22 -0
- data/misc/ui.xml +23 -0
- data/pione.gemspec +3 -1
- data/test/agent/spec_basic-agent.rb +1 -1
- data/test/agent/spec_input-generator.rb +2 -2
- data/test/agent/spec_messenger.rb +6 -9
- data/test/agent/spec_notification-listener.rb +80 -0
- data/test/agent/{spec_broker.rb → spec_task-worker-broker.rb} +13 -10
- data/test/agent/spec_tuple-space-provider.rb +10 -6
- data/test/command/command-behavior.rb +3 -11
- data/test/command/data/pione-list-param/AdvancedParameters.pione +12 -0
- data/test/command/data/pione-list-param/BasicParameters.pione +12 -0
- data/test/command/spec_pione-action-exec.rb +16 -0
- data/test/command/spec_pione-action-list.rb +15 -10
- data/test/command/spec_pione-action-print.rb +14 -0
- data/test/command/spec_pione-action.rb +6 -19
- data/test/command/spec_pione-clean.rb +29 -46
- data/test/command/spec_pione-client.rb +29 -36
- data/test/command/spec_pione-command.rb +6 -6
- data/test/command/{spec_pione-compiler.rb → spec_pione-compile.rb} +11 -13
- data/test/command/spec_pione-config-get.rb +47 -0
- data/test/command/spec_pione-config-list.rb +42 -0
- data/test/command/spec_pione-config-set.rb +38 -0
- data/test/command/spec_pione-config-unset.rb +44 -0
- data/test/command/spec_pione-config.rb +11 -0
- data/test/command/spec_pione-diagnosis-notification.rb +23 -0
- data/test/command/spec_pione-diagnosis.rb +11 -0
- data/test/command/spec_pione-lang-check-syntax.rb +12 -0
- data/test/command/spec_pione-lang.rb +11 -0
- data/test/command/spec_pione-log-format.rb +29 -0
- data/test/command/spec_pione-log-list-id.rb +17 -0
- data/test/command/spec_pione-log.rb +6 -20
- data/test/command/spec_pione-package-add.rb +55 -0
- data/test/command/spec_pione-package-build.rb +57 -0
- data/test/command/spec_pione-package-show.rb +72 -0
- data/test/command/{spec_pione-update-package-info.rb → spec_pione-package-update.rb} +12 -13
- data/test/command/spec_pione-package.rb +4 -104
- data/test/command/spec_pione-val.rb +10 -7
- data/test/global/spec_config.rb +50 -0
- data/test/global/spec_item.rb +1 -1
- data/test/literate-action/data/HelloWorld.md +1 -1
- data/test/location/location-behavior.rb +1 -1
- data/test/location/spec_dropbox-location.rb +39 -0
- data/test/location/spec_notification-scheme.rb +37 -0
- data/test/log/spec_debug.rb +5 -4
- data/test/log/spec_message-log-receiver.rb +13 -0
- data/test/log/spec_message-log.rb +6 -9
- data/test/log/spec_system-log.rb +5 -3
- data/test/notification/spec_address.rb +229 -0
- data/test/notification/spec_message.rb +30 -0
- data/test/notification/spec_receiver.rb +36 -0
- data/test/notification/spec_transmitter.rb +37 -0
- data/test/pnml/data/ConditionalBranchIf.pnml +270 -0
- data/test/pnml/data/ConditionalBranchIfElse.pnml +309 -0
- data/test/pnml/data/IOExpansionComplex.pnml +363 -0
- data/test/pnml/data/IOExpansionSimple.pnml +140 -0
- data/test/pnml/data/InputMergeComplementComplex.pnml +381 -0
- data/test/pnml/data/InputMergeComplementSimple.pnml +248 -0
- data/test/pnml/data/InputParallelizationComplementComplex.pnml +433 -0
- data/test/pnml/data/InputParallelizationComplementSimple.pnml +288 -0
- data/test/pnml/data/InputReductionComplex.pnml +192 -0
- data/test/pnml/data/InputReductionLong.pnml +344 -0
- data/test/pnml/data/InputReductionSimple.pnml +140 -0
- data/test/pnml/data/IsolatedElementElimination.pnml +171 -0
- data/test/pnml/data/OutputDecompositionComplementComplex.pnml +381 -0
- data/test/pnml/data/OutputDecompositionComplementSimple.pnml +242 -0
- data/test/pnml/data/OutputReductionComplex.pnml +186 -0
- data/test/pnml/data/OutputReductionLong.pnml +344 -0
- data/test/pnml/data/OutputReductionSimple.pnml +140 -0
- data/test/pnml/data/OutputSynchronizationComplementComplex.pnml +498 -0
- data/test/pnml/data/OutputSynchronizationComplementSimple.pnml +347 -0
- data/test/pnml/data/SampleNet.pnml +238 -0
- data/test/pnml/spec_input-merge-complement.rb +40 -0
- data/test/pnml/spec_input-parallelization-complement.rb +50 -0
- data/test/pnml/spec_input-reduction.rb +113 -0
- data/test/pnml/spec_invalid-arc-elimination.rb +33 -0
- data/test/pnml/spec_io-expansion.rb +126 -0
- data/test/pnml/spec_isolated-element-elimination.rb +25 -0
- data/test/pnml/spec_output-decomposition-complement.rb +40 -0
- data/test/pnml/spec_output-reduction.rb +114 -0
- data/test/pnml/spec_output-synchronization-complement.rb +62 -0
- data/test/pnml/spec_pione-element.rb +144 -0
- data/test/pnml/spec_pnml-element.rb +373 -0
- data/test/pnml/spec_reader.rb +16 -0
- data/test/rootage/spec_argument.rb +18 -0
- data/test/rootage/spec_command.rb +239 -0
- data/test/rootage/spec_core.rb +198 -0
- data/test/rootage/spec_scenario.rb +149 -0
- data/test/system/{spec_domain-info.rb → spec_domain-dump.rb} +6 -6
- data/test/system/spec_file-cache.rb +6 -9
- data/test/tuple-space/spec_finished-tuple.rb +1 -1
- data/test/util/{spec_package-parameters-list_1.pione → data/package-parameters-list/Param1.pione} +0 -0
- data/test/util/{spec_package-parameters-list_2.pione → data/package-parameters-list/Param2.pione} +0 -0
- data/test/util/{spec_package-parameters-list_3.pione → data/package-parameters-list/Param3.pione} +0 -0
- data/test/util/{spec_package-parameters-list_4.pione → data/package-parameters-list/Param4.pione} +0 -0
- data/test/util/spec_boolean-value.rb +32 -0
- data/test/util/spec_completion.rb +22 -0
- data/test/util/spec_package-parameters-list.rb +39 -52
- data/test/util/spec_zip.rb +28 -1
- metadata +288 -47
- data/bin/pione-tuple-space-receiver +0 -5
- data/lib/pione/agent/broker.rb +0 -304
- data/lib/pione/agent/tuple-space-receiver.rb +0 -137
- data/lib/pione/command/pione-broker.rb +0 -104
- data/lib/pione/command/pione-compiler.rb +0 -57
- data/lib/pione/command/pione-relay-account-db.rb +0 -141
- data/lib/pione/command/pione-relay-client-db.rb +0 -118
- data/lib/pione/command/pione-relay.rb +0 -59
- data/lib/pione/command/pione-syntax-checker.rb +0 -214
- data/lib/pione/command/pione-tuple-space-receiver.rb +0 -111
- data/lib/pione/command/pione-update-package-info.rb +0 -53
- data/lib/pione/front/broker-front.rb +0 -22
- data/lib/pione/front/tuple-space-receiver-front.rb +0 -11
- data/lib/pione/global/broker-variable.rb +0 -33
- data/lib/pione/system/domain-info.rb +0 -25
- data/lib/pione/util/pnml-compiler.rb +0 -168
- data/test/agent/spec_tuple-space-receiver.rb +0 -47
- data/test/util/spec_pnml-compiler.rb +0 -32
@@ -1,398 +1,56 @@
|
|
1
1
|
module Pione
|
2
2
|
module Command
|
3
|
-
# BasicCommand provides PIONE command
|
4
|
-
# "init", "setup", "
|
5
|
-
# processings as each phases.
|
6
|
-
class BasicCommand
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
attr_reader :exception_handler
|
17
|
-
|
18
|
-
def inherited(subclass)
|
19
|
-
subclass.instance_eval do
|
20
|
-
@phase_option = {:init => {}, :setup => {}, :execution => {}, :termination => {}}
|
21
|
-
@option_definition = OptionDefinition.new
|
22
|
-
@command_name = nil
|
23
|
-
@command_name_block = nil
|
24
|
-
@command_banner = nil
|
25
|
-
@command_front = nil
|
26
|
-
@command_front_block = nil
|
27
|
-
@init_actions = Array.new
|
28
|
-
@setup_actions = Array.new
|
29
|
-
@execution_actions = Array.new
|
30
|
-
@termination_actions = Array.new
|
31
|
-
@exception_handler = {:init => {}, :setup => {}, :execution => {}, :termination => {}}
|
32
|
-
|
33
|
-
# define init phase actions
|
34
|
-
init :process_name
|
35
|
-
init :signal_trap
|
36
|
-
init :option
|
37
|
-
init :front
|
38
|
-
init :process_additional_information
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def option_parser_mode(mode)
|
43
|
-
@option_definition.parser_mode = mode
|
44
|
-
end
|
45
|
-
|
46
|
-
# Set progaram name or return the name.
|
47
|
-
def command_name(name=nil, &b)
|
48
|
-
if name
|
49
|
-
@command_name = name
|
50
|
-
@command_name_block = block_given? ? b : nil
|
51
|
-
else
|
52
|
-
@command_name
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Set program banner or return the banner.
|
57
|
-
def command_banner(banner=nil)
|
58
|
-
if banner
|
59
|
-
@command_banner = banner
|
60
|
-
else
|
61
|
-
@command_banner
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Set command front or return the front class.
|
66
|
-
def command_front(front_class=nil, &b)
|
67
|
-
if front_class
|
68
|
-
@command_front = front_class
|
69
|
-
@command_front_block = b
|
70
|
-
else
|
71
|
-
@command_front
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
forward :@option_definition, :use, :use_option
|
76
|
-
forward :@option_definition, :define, :define_option
|
77
|
-
forward :@option_definition, :item, :option_item
|
78
|
-
forward :@option_definition, :default, :option_default
|
79
|
-
forward :@option_definition, :validate, :validate_option
|
80
|
-
|
81
|
-
# Run the command with the arguments.
|
82
|
-
def run(argv)
|
83
|
-
self.new(argv).run
|
84
|
-
end
|
85
|
-
|
86
|
-
# Set setup phase options.
|
87
|
-
def init_phase(option)
|
88
|
-
set_phase_option(:init, option)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Set setup phase options.
|
92
|
-
def setup_phase(option)
|
93
|
-
set_phase_option(:setup, option)
|
94
|
-
end
|
95
|
-
|
96
|
-
# Set execution phase options.
|
97
|
-
def execution_phase(option)
|
98
|
-
set_phase_option(:execution, option)
|
99
|
-
end
|
100
|
-
|
101
|
-
# Set termination phase options.
|
102
|
-
def termination_phase(option)
|
103
|
-
set_phase_option(:termination, option)
|
104
|
-
end
|
105
|
-
|
106
|
-
# Register the action to init phase.
|
107
|
-
def init(action, option={})
|
108
|
-
register_action(@init_actions, action, option)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Register the action to setup phase.
|
112
|
-
def setup(action, option={})
|
113
|
-
register_action(@setup_actions, action, option)
|
114
|
-
end
|
115
|
-
|
116
|
-
# Register the action to execution phase.
|
117
|
-
def execute(action, option={})
|
118
|
-
register_action(@execution_actions, action, option)
|
119
|
-
end
|
120
|
-
|
121
|
-
# Register the action to termination phase.
|
122
|
-
def terminate(action, option={})
|
123
|
-
register_action(@termination_actions, action, option)
|
124
|
-
end
|
125
|
-
|
126
|
-
def handle_exception(phase_name, exceptions, &action)
|
127
|
-
exceptions.each {|e| @exception_handler[phase_name][e] = action}
|
128
|
-
end
|
129
|
-
|
130
|
-
def handle_setup_exception(*exceptions, &action)
|
131
|
-
handle_exception(:setup, exceptions, &action)
|
132
|
-
end
|
133
|
-
|
134
|
-
def handle_execution_exception(*exceptions, &action)
|
135
|
-
handle_exception(:execution, exceptions, &action)
|
136
|
-
end
|
137
|
-
|
138
|
-
def handle_termination_exception(*exceptions, &action)
|
139
|
-
handle_exception(:termination, exceptions, &action)
|
140
|
-
end
|
3
|
+
# BasicCommand provides PIONE's basic command structure. PIONE commands have
|
4
|
+
# 4 phases: "init", "setup", "execution", "termination". Concrete commands
|
5
|
+
# implement some processings as each phases.
|
6
|
+
class BasicCommand < Rootage::StandardCommand
|
7
|
+
phase(:init) do |seq|
|
8
|
+
seq.clear
|
9
|
+
seq << Rootage::InitAction.signal_trap
|
10
|
+
seq << Rootage::InitAction.option
|
11
|
+
seq << Rootage::InitAction.argument
|
12
|
+
seq << Rootage::InitAction.program_name
|
13
|
+
seq << InitAction.front
|
14
|
+
seq << Rootage::InitAction.program_name # for showing front address
|
15
|
+
end
|
141
16
|
|
142
|
-
|
17
|
+
# Return the program name with the front URI and the parent's front URI.
|
18
|
+
def program_name
|
19
|
+
additions = []
|
143
20
|
|
144
|
-
#
|
145
|
-
|
146
|
-
|
21
|
+
# front server URI
|
22
|
+
if model[:front]
|
23
|
+
additions << "front: %s" % model[:front].uri
|
147
24
|
end
|
148
25
|
|
149
|
-
#
|
150
|
-
|
151
|
-
|
152
|
-
_action.each do |key, val|
|
153
|
-
phase_actions << [key.is_a?(Array) ? key : [key], val, option]
|
154
|
-
end
|
26
|
+
# parent front server URI
|
27
|
+
if model[:parent_front]
|
28
|
+
additions << "parent: %s" % model[:parent_front].uri
|
155
29
|
end
|
156
|
-
end
|
157
|
-
|
158
|
-
attr_reader :option
|
159
|
-
attr_reader :running_thread
|
160
|
-
|
161
|
-
forward! :class, :option_definition, :command_name, :command_name_block
|
162
|
-
forward! :class, :command_banner, :command_front, :command_front_block
|
163
30
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
@__phase_name__ = nil
|
169
|
-
@__action_name__ = nil
|
170
|
-
|
171
|
-
# process has just one command object
|
172
|
-
Global.command = self
|
173
|
-
end
|
174
|
-
|
175
|
-
# Run 4 phase lifecycle of the command. This fires actions in each phase.
|
176
|
-
def run
|
177
|
-
@running_thread = Thread.current
|
178
|
-
enter_phase(:init)
|
179
|
-
enter_phase(:setup)
|
180
|
-
enter_phase(:execution)
|
181
|
-
terminate # => enter_phase(:termination) and exit
|
182
|
-
end
|
183
|
-
|
184
|
-
# Enter setup phase.
|
185
|
-
def enter_phase(phase_name)
|
186
|
-
# avoid double launch
|
187
|
-
return if @__phase_name__ == phase_name
|
188
|
-
|
189
|
-
# show debug message for entering phase
|
190
|
-
Log::Debug.system("%s enters phase \"%s\"" % [command_name, phase_name])
|
191
|
-
|
192
|
-
limit = self.class.phase_option[phase_name][:timeout]
|
193
|
-
phase_keyword, actions = find_phase_actions(phase_name)
|
194
|
-
timeout(limit) do
|
195
|
-
@__phase_name__ = phase_name
|
196
|
-
actions.each do |(targets, action_name, action_option)|
|
197
|
-
# check current mode is target or not
|
198
|
-
if not(targets.empty?) and not(targets.include?(option[:action_mode]))
|
199
|
-
next
|
200
|
-
end
|
201
|
-
|
202
|
-
# show debug message for firing action
|
203
|
-
Log::Debug.system("%s fires action \"%s\" in phase \"%s\"" % [command_name, action_name, phase_name])
|
204
|
-
|
205
|
-
# fire action
|
206
|
-
@__action_name__ = action_name
|
207
|
-
full_action_name = ("%s_%s" % [phase_keyword, action_name]).to_sym
|
208
|
-
if action_option[:module]
|
209
|
-
# call action in command action module
|
210
|
-
instance_eval(&action_option[:module].get(full_action_name))
|
211
|
-
else
|
212
|
-
# call action in self object
|
213
|
-
method(full_action_name).call
|
214
|
-
end
|
215
|
-
end
|
31
|
+
if additions.empty?
|
32
|
+
name
|
33
|
+
else
|
34
|
+
"%s (%s)" % [name, additions.join(", ")]
|
216
35
|
end
|
217
|
-
rescue *self.class.exception_handler[phase_name].keys => e
|
218
|
-
self.class.exception_handler[phase_name][e.class].call(self, e)
|
219
|
-
rescue Timeout::Error
|
220
|
-
args = [command_name, @__action_name__, @__phase_name__, limit]
|
221
|
-
abort("%s timeouted at action \"%s\" in phase \"%s\". (%i sec)" % args)
|
222
|
-
end
|
223
|
-
|
224
|
-
# Terminate the command. Note that this enters in termination phase first,
|
225
|
-
# and command exit.
|
226
|
-
def terminate
|
227
|
-
enter_phase(:termination)
|
228
|
-
exit # end with status code
|
229
|
-
end
|
230
|
-
|
231
|
-
# Return true if it is in init phase.
|
232
|
-
def init?
|
233
|
-
@__phase_name__ == :init
|
234
|
-
end
|
235
|
-
|
236
|
-
# Return true if it is in setup phase.
|
237
|
-
def setup?
|
238
|
-
@__phase_name__ == :setup
|
239
|
-
end
|
240
|
-
|
241
|
-
# Return true if it is in execution phase.
|
242
|
-
def execution?
|
243
|
-
@__phase_name__ == :execution
|
244
|
-
end
|
245
|
-
|
246
|
-
# Return true if it is in termination phase.
|
247
|
-
def termination?
|
248
|
-
@__phase_name__ == :termination
|
249
36
|
end
|
250
37
|
|
251
|
-
# Exit running command and return status.
|
252
|
-
|
253
|
-
Log::Debug.system("%s exits with status \"%s\"" % [command_name, @__exit_status__])
|
254
|
-
Global.system_logger.terminate
|
255
|
-
Kernel.exit(Global.exit_status)
|
256
|
-
end
|
257
|
-
|
258
|
-
# Exit running command and return failure status. Note that this method
|
259
|
-
# enters termination phase before it exits.
|
38
|
+
# Exit the running command and return failure status. Note that this
|
39
|
+
# method enters termination phase before it exits.
|
260
40
|
def abort(msg_or_exception, pos=caller(1).first)
|
261
41
|
# hide the message because some option errors are meaningless
|
262
|
-
|
263
|
-
|
264
|
-
# setup abortion message
|
265
|
-
msg = msg_or_exception.is_a?(Exception) ? msg_or_exception.message : msg_or_exception
|
266
|
-
|
267
|
-
# show the message
|
268
|
-
if invisible
|
269
|
-
Log::Debug.system(msg, pos)
|
270
|
-
else
|
271
|
-
Log::SystemLog.fatal(msg, pos)
|
42
|
+
if msg_or_exception.is_a?(HideableOptionError)
|
43
|
+
Log::Debug.system(msg_or_exception.message, pos)
|
272
44
|
end
|
273
45
|
|
274
|
-
|
275
|
-
Global.exit_status = false
|
276
|
-
|
277
|
-
# go to termination phase
|
278
|
-
terminate
|
46
|
+
super
|
279
47
|
end
|
280
48
|
|
281
49
|
private
|
282
50
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
end
|
287
|
-
|
288
|
-
# Initialize signal trap actions.
|
289
|
-
def init_signal_trap
|
290
|
-
# explicit exit for signal INT (exit status code: failure)
|
291
|
-
Signal.trap(:INT) do
|
292
|
-
abort("%s is terminated by signal INT" % command_name)
|
293
|
-
end
|
294
|
-
|
295
|
-
# implicit abortion for signal TERM (exit status code: success)
|
296
|
-
Signal.trap(:TERM) do
|
297
|
-
Log::Debug.system("%s is terminated by signal TERM" % command_name)
|
298
|
-
terminate
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
# Initialize command options.
|
303
|
-
def init_option
|
304
|
-
@option = option_definition.parse(@argv, command_name, command_banner)
|
305
|
-
rescue OptionParser::ParseError, OptionError => e
|
306
|
-
abort(e)
|
307
|
-
end
|
308
|
-
|
309
|
-
# Initialize front server of this process if it needs.
|
310
|
-
def init_front
|
311
|
-
if command_front
|
312
|
-
front_args = command_front_block ? command_front_block.call(self) : []
|
313
|
-
Global.front = command_front.new(*front_args)
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
# Modify process name to be with the additional informations.
|
318
|
-
def init_process_additional_information
|
319
|
-
if self.class.command_name_block
|
320
|
-
$PROGRAM_NAME = "%s (%s)" % [command_name, command_name_block.call(self)]
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
# Find phase actions by phase name.
|
325
|
-
def find_phase_actions(phase_name)
|
326
|
-
case phase_name
|
327
|
-
when :init; [:init, self.class.init_actions]
|
328
|
-
when :setup; [:setup, self.class.setup_actions]
|
329
|
-
when :execution; [:execute, self.class.execution_actions]
|
330
|
-
when :termination; [:terminate, self.class.termination_actions]
|
331
|
-
end
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
module CommandActionInterface
|
336
|
-
class << self
|
337
|
-
def extended(mod)
|
338
|
-
mod.instance_variable_set(:@action, Hash.new)
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
# Return the named action.
|
343
|
-
def get(name)
|
344
|
-
@action[name] || (raise ActionNotFound.new(self, name))
|
345
|
-
end
|
346
|
-
|
347
|
-
def define_action(name, &b)
|
348
|
-
@action[name] = b
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
module CommonCommandAction
|
353
|
-
extend CommandActionInterface
|
354
|
-
|
355
|
-
define_action(:terminate_child_process) do |cmd|
|
356
|
-
if Global.front
|
357
|
-
# send signal TERM to the child process
|
358
|
-
Global.front.child.each do |pid, uri|
|
359
|
-
Util.ignore_exception {Process.kill(:TERM, pid)}
|
360
|
-
end
|
361
|
-
|
362
|
-
# wait all children
|
363
|
-
children = Process.waitall.map{|(pid, _)| pid}
|
364
|
-
if not(children.empty?)
|
365
|
-
Log::Debug.system("%s killed #%s" % [cmd.command_name, children.join(", ")])
|
366
|
-
end
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
define_action(:setup_parent_process_connection) do |cmd|
|
371
|
-
cmd.option[:parent_front].add_child(Process.pid, Global.front.uri)
|
372
|
-
ParentFrontWatchDog.new(self) # start to watch parent process
|
373
|
-
end
|
374
|
-
|
375
|
-
define_action(:terminate_parent_process_connection) do |cmd|
|
376
|
-
# maybe parent process is dead in this timing
|
377
|
-
Util.ignore_exception do
|
378
|
-
cmd.option[:parent_front].remove_child(Process.pid)
|
379
|
-
end
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
class ParentFrontWatchDog
|
384
|
-
def initialize(command)
|
385
|
-
@command = command
|
386
|
-
|
387
|
-
Thread.new do
|
388
|
-
while true
|
389
|
-
# PPID 1 means the parent process is dead
|
390
|
-
if Process.ppid == 1 or Util.error?{command.option[:parent_front].ping}
|
391
|
-
break @command.terminate
|
392
|
-
end
|
393
|
-
sleep 1
|
394
|
-
end
|
395
|
-
end
|
51
|
+
def exit_process
|
52
|
+
model[:front].terminate if model[:front]
|
53
|
+
Global.system_logger.terminate
|
396
54
|
end
|
397
55
|
end
|
398
56
|
end
|
@@ -3,25 +3,26 @@ module Pione
|
|
3
3
|
class CommandException < StandardError; end
|
4
4
|
|
5
5
|
# SpawnError is raised when the command failed to run.
|
6
|
-
class SpawnError < CommandException
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
class OptionError < CommandException
|
13
|
-
def initialize(msg)
|
14
|
-
@msg = msg
|
6
|
+
class SpawnError < CommandException
|
7
|
+
def initialize(caller, callee, argv, cause)
|
8
|
+
@caller = caller
|
9
|
+
@callee = callee
|
10
|
+
@argv = argv
|
11
|
+
@cause = cause
|
15
12
|
end
|
16
13
|
|
17
14
|
def message
|
18
|
-
|
15
|
+
args = {caller: @caller, callee: @callee, argv: @argv, cause: @cause}
|
16
|
+
'"%{caller}" has failed to spawn "%{callee}" %{argv}: %{cause}' % args
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
20
|
+
# SpawnerRetry is raised when we need to try spawn check.
|
21
|
+
class SpawnerRetry < CommandException; end
|
22
|
+
|
22
23
|
# HideableOptionError is same as OptionError, but it is better for users
|
23
24
|
# that this error is ignored in some cases.
|
24
|
-
class HideableOptionError < OptionError; end
|
25
|
+
class HideableOptionError < Rootage::OptionError; end
|
25
26
|
|
26
27
|
class ActionNotFound < CommandException
|
27
28
|
def initialize(mod, name)
|