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
data/lib/pione/agent/logger.rb
CHANGED
@@ -9,8 +9,8 @@ module Pione
|
|
9
9
|
attr_reader :output_location # output location
|
10
10
|
|
11
11
|
# Create a logger agent.
|
12
|
-
def initialize(
|
13
|
-
super(
|
12
|
+
def initialize(tuple_space, location)
|
13
|
+
super(tuple_space)
|
14
14
|
@log_id = Time.now.iso8601(3)
|
15
15
|
@log_location = location.directory? ? location + "pione-process.log" : location
|
16
16
|
@output_location = get_output_location
|
@@ -73,7 +73,7 @@ module Pione
|
|
73
73
|
if @log_location.real_appendable?
|
74
74
|
@log_location
|
75
75
|
else
|
76
|
-
Location[
|
76
|
+
Location[Temppath.mkdir + @log_location.basename]
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -4,27 +4,38 @@ module Pione
|
|
4
4
|
class Messenger < TupleSpaceClient
|
5
5
|
set_agent_type :messenger, self
|
6
6
|
|
7
|
+
# @param tuple_space [TupleSpace::TupleSpaceServer]
|
8
|
+
# tuple space
|
9
|
+
# @param receiver [Log::MessageLogReceiver]
|
10
|
+
# message log receiver
|
11
|
+
def initialize(tuple_space, receiver)
|
12
|
+
super(tuple_space)
|
13
|
+
|
14
|
+
# message log receiver
|
15
|
+
@receiver = receiver
|
16
|
+
end
|
17
|
+
|
7
18
|
#
|
8
19
|
# agent activities
|
9
20
|
#
|
10
21
|
|
11
|
-
define_transition :
|
22
|
+
define_transition :pass
|
12
23
|
|
13
|
-
chain :init => :
|
14
|
-
chain :
|
24
|
+
chain :init => :pass
|
25
|
+
chain :pass => :pass
|
15
26
|
|
16
27
|
#
|
17
28
|
# transitions
|
18
29
|
#
|
19
30
|
|
20
|
-
# Transits to the state
|
21
|
-
def
|
31
|
+
# Transits to the state `pass`.
|
32
|
+
def transit_to_pass
|
22
33
|
tuples = take_all(TupleSpace::MessageTuple.any)
|
23
34
|
tuples.sort{|a,b| a.timestamp <=> b.timestamp}.each do |tuple|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
35
|
+
tuple.contents.tap do |contents|
|
36
|
+
(contents.kind_of?(String) ? [contents] : contents).each do |msg|
|
37
|
+
@receiver.receive(msg, tuple.level, tuple.head, tuple.color)
|
38
|
+
end
|
28
39
|
end
|
29
40
|
end
|
30
41
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Pione
|
2
|
+
module Agent
|
3
|
+
class NotificationListener < BasicAgent
|
4
|
+
#
|
5
|
+
# instance methods
|
6
|
+
#
|
7
|
+
|
8
|
+
# notification handler threads
|
9
|
+
attr_reader :notification_handlers
|
10
|
+
|
11
|
+
# @param model [NotificationListenerModel]
|
12
|
+
# notification-listner model
|
13
|
+
# @param uri [URI]
|
14
|
+
# listening port
|
15
|
+
def initialize(model, uri)
|
16
|
+
super()
|
17
|
+
@uri = uri
|
18
|
+
@model = model
|
19
|
+
@notification_handlers = ThreadGroup.new
|
20
|
+
@lock = Mutex.new
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# agent activities
|
25
|
+
#
|
26
|
+
|
27
|
+
define_transition :receive
|
28
|
+
|
29
|
+
chain :init => :receive
|
30
|
+
chain :receive => :receive
|
31
|
+
|
32
|
+
#
|
33
|
+
# transitions
|
34
|
+
#
|
35
|
+
|
36
|
+
# Initialize the agent.
|
37
|
+
def transit_to_init
|
38
|
+
Log::SystemLog.info('Notification listener starts listening notification messages on "%s".' % @uri)
|
39
|
+
@receiver = Notification::Receiver.new(@uri)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Receive notification messages and make a message handler thread.
|
43
|
+
def transit_to_receive
|
44
|
+
# receive a notification
|
45
|
+
transmitter_host, message = @receiver.receive
|
46
|
+
|
47
|
+
# handle the notification in new thread
|
48
|
+
thread = Util::FreeThreadGenerator.generate do
|
49
|
+
handle_notification(transmitter_host, message)
|
50
|
+
end
|
51
|
+
@notification_handlers.add(thread)
|
52
|
+
rescue StandardError => e
|
53
|
+
Log::Debug.notification("Receiver agent has received bad data from %s, so it ignored and reopen socket." % ip_address)
|
54
|
+
@receiver.reopen
|
55
|
+
end
|
56
|
+
|
57
|
+
# Close receiver socket.
|
58
|
+
def transit_to_terminate
|
59
|
+
# kill threads of notification handler
|
60
|
+
@notification_handlers.list.each {|thread| thread.kill.join}
|
61
|
+
# close socket
|
62
|
+
@receiver.close unless @receiver.closed?
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# helper method
|
67
|
+
#
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# Notify the notification message to recipients.
|
72
|
+
def handle_notification(transmitter_host, message)
|
73
|
+
# notify the message to recepients
|
74
|
+
bad_recipients = @model.recipients.each_with_object([]) do |uri, bad_recipients|
|
75
|
+
begin
|
76
|
+
Timeout.timeout(3) {DRb::DRbObject.new_with_uri(uri).notify(message)}
|
77
|
+
rescue Timeout::Error, DRb::DRbConnError, DRbPatch::ReplyReaderError => e
|
78
|
+
Log::Debug.notification("Notification recipient %s disconnected: %s" % [uri, e.message])
|
79
|
+
bad_recipients << uri
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# delete bad recipients
|
84
|
+
@model.delete_recipient(*bad_recipients)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Pione
|
2
|
+
module Agent
|
3
|
+
# `TaskWorkerBroker` is an agent for providing task workers to tuple spaces.
|
4
|
+
class TaskWorkerBroker < BasicAgent
|
5
|
+
set_agent_type :task_worker_broker, self
|
6
|
+
|
7
|
+
#
|
8
|
+
# instance methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def initialize(model)
|
12
|
+
super()
|
13
|
+
@model = model
|
14
|
+
@provider = Global.task_worker_provider.new(model)
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# activity definitions
|
19
|
+
#
|
20
|
+
|
21
|
+
define_transition :count_tuple_space
|
22
|
+
define_transition :provide_task_worker
|
23
|
+
define_transition :sleep
|
24
|
+
define_transition :check_tuple_space
|
25
|
+
define_transition :check_task_worker_life
|
26
|
+
|
27
|
+
chain :init => [:count_tuple_space, :check_task_worker_life]
|
28
|
+
chain :count_tuple_space => lambda {|agent, res|
|
29
|
+
res > 0 ? :provide_task_worker : :sleep
|
30
|
+
}
|
31
|
+
chain :provide_task_worker => lambda {|agent, rebalance|
|
32
|
+
rebalance ? :provide_task_worker : :sleep
|
33
|
+
}
|
34
|
+
chain :sleep => :count_tuple_space
|
35
|
+
chain :check_tuple_space => :count_tuple_space
|
36
|
+
chain :check_task_worker_life => :check_task_worker_life
|
37
|
+
|
38
|
+
define_exception_handler Restart => :check_tuple_space
|
39
|
+
|
40
|
+
#
|
41
|
+
# transitions
|
42
|
+
#
|
43
|
+
|
44
|
+
def transit_to_init
|
45
|
+
Log::SystemLog.info "Task worker broker starts the activity."
|
46
|
+
end
|
47
|
+
|
48
|
+
def transit_to_count_tuple_space
|
49
|
+
@model.tuple_space.size
|
50
|
+
end
|
51
|
+
|
52
|
+
def transit_to_provide_task_worker
|
53
|
+
@provider.provide
|
54
|
+
end
|
55
|
+
|
56
|
+
def transit_to_check_tuple_space
|
57
|
+
@model.check_tuple_space
|
58
|
+
end
|
59
|
+
|
60
|
+
def transit_to_sleep
|
61
|
+
if @model.tuple_space.size == 0 or @model.excess_task_workers == 0
|
62
|
+
sleep Global.task_worker_broker_long_sleep_time
|
63
|
+
else
|
64
|
+
sleep Global.task_worker_broker_short_sleep_time
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def transit_to_check_task_worker_life
|
69
|
+
@model.delete_dead_task_workers
|
70
|
+
sleep Global.task_worker_broker_short_sleep_time
|
71
|
+
end
|
72
|
+
|
73
|
+
# Send bye messages to tuple spaces when the agent is terminated.
|
74
|
+
def transit_to_terminate
|
75
|
+
@model.tuple_space_lock.synchronize do
|
76
|
+
@model.tuple_spaces.each do |tuple_space|
|
77
|
+
Util.ignore_exception {timeout(1) {tuple_space.bye}}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
Log::SystemLog.info "Task worker broker ends the activity."
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -77,8 +77,9 @@ module Pione
|
|
77
77
|
@execution_thread = Thread.new do
|
78
78
|
begin
|
79
79
|
engine.handle
|
80
|
-
rescue RuleEngine::
|
81
|
-
|
80
|
+
rescue RuleEngine::RuleExecutionError, Lang::LangError => e
|
81
|
+
user_message("ERROR: " + e.message, 0, "info", :red)
|
82
|
+
write(TupleSpace::CommandTuple.new(name: "terminate", args: [System::Status.error(e.message)]))
|
82
83
|
terminate
|
83
84
|
end
|
84
85
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Pione
|
2
2
|
module Agent
|
3
|
-
# TupleSpaceProvider is an agent that provides tuple space
|
3
|
+
# TupleSpaceProvider is an agent that provides a URI of tuple space as
|
4
|
+
# notification messages.
|
4
5
|
class TupleSpaceProvider < BasicAgent
|
5
6
|
set_agent_type :tuple_space_provider, self
|
6
7
|
|
@@ -8,59 +9,40 @@ module Pione
|
|
8
9
|
# instance methods
|
9
10
|
#
|
10
11
|
|
11
|
-
|
12
|
+
# @param provider [URI]
|
13
|
+
# URI of the tuple space
|
14
|
+
# @param targets [Array<URI>]
|
15
|
+
# target URIs
|
16
|
+
def initialize(uri, targets=Global.notification_targets)
|
12
17
|
super()
|
13
|
-
@
|
14
|
-
@
|
18
|
+
@targets = targets
|
19
|
+
@notification = Notification::Message.new(
|
20
|
+
"TUPLE_SPACE_PROVIDER", "TUPLE_SPACE", {"front" => uri}
|
21
|
+
)
|
15
22
|
end
|
16
23
|
|
17
24
|
#
|
18
25
|
# agent activities
|
19
26
|
#
|
20
27
|
|
21
|
-
define_transition :
|
28
|
+
define_transition :send_message
|
22
29
|
define_transition :sleep
|
23
30
|
|
24
|
-
chain :init => :
|
25
|
-
chain :
|
26
|
-
chain :sleep => :
|
31
|
+
chain :init => :send_message
|
32
|
+
chain :send_message => :sleep
|
33
|
+
chain :sleep => :send_message
|
27
34
|
|
28
35
|
#
|
29
36
|
# transitions
|
30
37
|
#
|
31
38
|
|
32
|
-
def
|
33
|
-
|
39
|
+
def transit_to_send_message
|
40
|
+
Notification::Transmitter.transmit(@notification, @targets)
|
34
41
|
end
|
35
42
|
|
36
43
|
def transit_to_sleep
|
37
44
|
sleep 5
|
38
45
|
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# helper methods
|
42
|
-
#
|
43
|
-
|
44
|
-
# Send presence notification packets to tuple space receivers.
|
45
|
-
def send_packet
|
46
|
-
# open a UDP socket
|
47
|
-
socket = UDPSocket.open
|
48
|
-
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, 1)
|
49
|
-
|
50
|
-
# send broadcast packets
|
51
|
-
Global.presence_notification_addresses.each do |address|
|
52
|
-
begin
|
53
|
-
Log::Debug.presence_notification do
|
54
|
-
"provider sends presence notification packet from %s to %s" % [@front.uri, address, Time.now]
|
55
|
-
end
|
56
|
-
socket.send(@reference, 0, address.host, address.port)
|
57
|
-
rescue => e
|
58
|
-
Log::SystemLog.warn("tuple space provider agent failed to send a packet: %s" % e.message)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
ensure
|
62
|
-
socket.close
|
63
|
-
end
|
64
46
|
end
|
65
47
|
end
|
66
48
|
end
|
data/lib/pione/command.rb
CHANGED
@@ -1,28 +1,46 @@
|
|
1
1
|
module Pione
|
2
2
|
# Command is a name space for PIONE command classes.
|
3
|
-
module Command
|
3
|
+
module Command
|
4
|
+
def self.load_all
|
5
|
+
require 'pione/command/pione-action'
|
6
|
+
require 'pione/command/pione-action-exec'
|
7
|
+
require 'pione/command/pione-action-list'
|
8
|
+
require 'pione/command/pione-action-print'
|
9
|
+
require 'pione/command/pione-clean'
|
10
|
+
require 'pione/command/pione-compile'
|
11
|
+
require 'pione/command/pione-config'
|
12
|
+
require 'pione/command/pione-config-get'
|
13
|
+
require 'pione/command/pione-config-list'
|
14
|
+
require 'pione/command/pione-config-set'
|
15
|
+
require 'pione/command/pione-config-unset'
|
16
|
+
require 'pione/command/pione-diagnosis'
|
17
|
+
require 'pione/command/pione-diagnosis-notification'
|
18
|
+
require 'pione/command/pione-lang'
|
19
|
+
require 'pione/command/pione-lang-check-syntax'
|
20
|
+
require 'pione/command/pione-log'
|
21
|
+
require 'pione/command/pione-log-format'
|
22
|
+
require 'pione/command/pione-log-list-id'
|
23
|
+
require 'pione/command/pione-package'
|
24
|
+
require 'pione/command/pione-package-add'
|
25
|
+
require 'pione/command/pione-package-build'
|
26
|
+
require 'pione/command/pione-package-show'
|
27
|
+
require 'pione/command/pione-package-update'
|
28
|
+
end
|
29
|
+
end
|
4
30
|
end
|
5
31
|
|
6
32
|
require 'pione/command/command-exception'
|
33
|
+
require 'pione/command/common'
|
7
34
|
require 'pione/command/spawner'
|
8
35
|
require 'pione/command/option'
|
36
|
+
require 'pione/command/action'
|
9
37
|
require 'pione/command/basic-command'
|
10
38
|
require 'pione/command/pione-command'
|
11
39
|
require 'pione/command/pione-client'
|
12
40
|
require 'pione/command/pione-task-worker'
|
13
|
-
require 'pione/command/pione-broker'
|
41
|
+
require 'pione/command/pione-task-worker-broker'
|
14
42
|
require 'pione/command/pione-tuple-space-provider'
|
15
|
-
require 'pione/command/pione-
|
43
|
+
require 'pione/command/pione-notification-listener'
|
16
44
|
require 'pione/command/pione-tuple-space-viewer'
|
17
|
-
require 'pione/command/pione-
|
18
|
-
|
19
|
-
require 'pione/command/pione-relay-account-db'
|
20
|
-
require 'pione/command/pione-clean' # pione clean
|
21
|
-
require 'pione/command/pione-syntax-checker'
|
22
|
-
require 'pione/command/pione-log' # pione log
|
23
|
-
require 'pione/command/pione-val' # pione-val
|
24
|
-
require 'pione/command/pione-package'
|
25
|
-
require 'pione/command/pione-compiler'
|
26
|
-
require 'pione/command/pione-update-package-info' # pione update-package-info
|
27
|
-
require 'pione/command/pione-action' # pione action
|
28
|
-
require 'pione/command/pione-action-list' # pione action:list
|
45
|
+
require 'pione/command/pione-val'
|
46
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Pione
|
2
|
+
module Command
|
3
|
+
# `InitAction` is a set of actions for PIONE commands initialization.
|
4
|
+
module InitAction
|
5
|
+
extend Rootage::ActionCollection
|
6
|
+
|
7
|
+
define(:front) do |item|
|
8
|
+
item.desc = "Initialize a front server"
|
9
|
+
|
10
|
+
item.assign(:front) do
|
11
|
+
test(cmd.info[:front])
|
12
|
+
|
13
|
+
cmd.info[:front].new(cmd)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module CommonAction
|
19
|
+
extend Rootage::ActionCollection
|
20
|
+
|
21
|
+
define(:load_domain_dump) do |item|
|
22
|
+
item.desc = "Load a domain dump file"
|
23
|
+
|
24
|
+
item.assign(:domain_dump) do
|
25
|
+
test(model[:domain_dump_location])
|
26
|
+
|
27
|
+
if model[:domain_dump_location]
|
28
|
+
System::DomainDump.load(model[:domain_dump_location])
|
29
|
+
else
|
30
|
+
cmd.abort('Domain dump "%s" not found.' % model[:domain_dump_location].uri)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module ProcessAction
|
37
|
+
extend Rootage::ActionCollection
|
38
|
+
|
39
|
+
define(:connect_parent) do |item|
|
40
|
+
item.desc = "Setup parent process connection"
|
41
|
+
|
42
|
+
item.process do
|
43
|
+
test(cmd.option_definition.find_item(:parent_front).requisite)
|
44
|
+
test(not(model.specified?(:parent_front)))
|
45
|
+
raise System::PioneBug.new("%{cmd} needs --parent-front" % {cmd: cmd.name})
|
46
|
+
end
|
47
|
+
|
48
|
+
item.process do
|
49
|
+
test(model[:parent_front])
|
50
|
+
model[:parent_front].register_child(Process.pid, model[:front].uri)
|
51
|
+
|
52
|
+
# delegate system logger
|
53
|
+
Global.system_logger = Log::DelegatableLogger.new(model[:parent_front].system_logger)
|
54
|
+
|
55
|
+
# start to watch parent process
|
56
|
+
Thread.new do
|
57
|
+
while true
|
58
|
+
# PPID 1 means the parent process is dead
|
59
|
+
if Process.ppid == 1 or Util.error?{model[:parent_front].ping}
|
60
|
+
break cmd.terminate
|
61
|
+
end
|
62
|
+
sleep 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
item.exception(Front::ChildRegistrationError) do |e|
|
68
|
+
cmd.terminate
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
define(:disconnect_parent) do |item|
|
73
|
+
item.desc = "Terminate parent process connection"
|
74
|
+
|
75
|
+
item.process do
|
76
|
+
test(model[:parent_front])
|
77
|
+
|
78
|
+
# maybe parent process is dead in this timing
|
79
|
+
Util.ignore_exception do
|
80
|
+
model[:parent_front].unregister_child(Process.pid)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
define(:terminate_children) do |item|
|
86
|
+
item.desc = "Terminate child processes"
|
87
|
+
|
88
|
+
item.process do
|
89
|
+
Sys::ProcTable.ps.select {|ps|
|
90
|
+
if ps.ppid == Process.pid
|
91
|
+
Util.ignore_exception {Process.kill(:TERM, ps.pid)}
|
92
|
+
end
|
93
|
+
}
|
94
|
+
|
95
|
+
# wait all children
|
96
|
+
children = Process.waitall.map{|(pid, _)| pid}
|
97
|
+
if not(children.empty?)
|
98
|
+
arg = {name: cmd.name, pid: children.join(", ")}
|
99
|
+
Log::Debug.system('"%{name}" has killed #%{pid}' % arg)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|