pione 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.simplecov +1 -0
- data/History.txt +9 -0
- data/Rakefile +1 -71
- data/example/Fib/Fib.pione +9 -8
- data/example/HelloWorld/HelloWorld.pione +2 -0
- data/example/HelloWorld/pione-package.json +15 -0
- data/example/HelloWorld/scenario/Scenario.pione +2 -0
- data/example/HelloWorld/scenario/pione-scenario.json +10 -0
- data/example/SerialProcessing/SerialProcessing.pione +2 -0
- data/example/SerialProcessing/pione-package.json +15 -0
- data/example/SerialProcessing/scenario/Scenario.pione +1 -0
- data/example/SerialProcessing/scenario/pione-scenario.json +10 -0
- data/lib/pione.rb +28 -35
- data/lib/pione/agent.rb +4 -4
- data/lib/pione/agent/agent-exception.rb +52 -0
- data/lib/pione/agent/basic-agent.rb +246 -239
- data/lib/pione/agent/broker.rb +232 -216
- data/lib/pione/agent/input-generator.rb +113 -133
- data/lib/pione/agent/job-terminator.rb +38 -0
- data/lib/pione/agent/logger.rb +24 -54
- data/lib/pione/agent/messenger.rb +11 -16
- data/lib/pione/agent/process-manager.rb +50 -19
- data/lib/pione/agent/task-worker.rb +126 -236
- data/lib/pione/agent/tuple-space-client.rb +16 -39
- data/lib/pione/agent/tuple-space-provider.rb +66 -0
- data/lib/pione/agent/tuple-space-receiver.rb +137 -0
- data/lib/pione/command.rb +2 -3
- data/lib/pione/command/basic-command.rb +347 -207
- data/lib/pione/command/command-exception.rb +38 -0
- data/lib/pione/command/option.rb +112 -104
- data/lib/pione/command/pione-broker.rb +85 -43
- data/lib/pione/command/pione-clean.rb +51 -8
- data/lib/pione/command/pione-client.rb +321 -292
- data/lib/pione/command/pione-log.rb +92 -53
- data/lib/pione/command/pione-package.rb +112 -59
- data/lib/pione/command/pione-relay-account-db.rb +107 -78
- data/lib/pione/command/pione-relay-client-db.rb +93 -72
- data/lib/pione/command/pione-relay.rb +37 -32
- data/lib/pione/command/pione-syntax-checker.rb +112 -87
- data/lib/pione/command/pione-task-worker.rb +135 -118
- data/lib/pione/command/pione-tuple-space-provider.rb +83 -50
- data/lib/pione/command/pione-tuple-space-receiver.rb +89 -50
- data/lib/pione/command/pione-tuple-space-viewer.rb +101 -99
- data/lib/pione/command/pione-val.rb +50 -29
- data/lib/pione/command/spawner.rb +74 -0
- data/lib/pione/front.rb +0 -2
- data/lib/pione/front/basic-front.rb +48 -26
- data/lib/pione/front/broker-front.rb +8 -16
- data/lib/pione/front/client-front.rb +10 -18
- data/lib/pione/front/front-exception.rb +12 -0
- data/lib/pione/front/relay-front.rb +6 -6
- data/lib/pione/front/task-worker-front.rb +3 -9
- data/lib/pione/front/tuple-space-provider-front.rb +6 -14
- data/lib/pione/front/tuple-space-receiver-front.rb +4 -11
- data/lib/pione/global.rb +135 -0
- data/lib/pione/global/broker-variable.rb +20 -0
- data/lib/pione/global/client-variable.rb +18 -0
- data/lib/pione/global/input-generator-variable.rb +7 -0
- data/lib/pione/global/log-variable.rb +53 -0
- data/lib/pione/global/network-variable.rb +7 -0
- data/lib/pione/global/package-variable.rb +28 -0
- data/lib/pione/global/path-variable.rb +52 -0
- data/lib/pione/global/relay-variable.rb +86 -0
- data/lib/pione/global/system-variable.rb +39 -0
- data/lib/pione/global/task-worker-variable.rb +17 -0
- data/lib/pione/global/tuple-space-notifier-variable.rb +60 -0
- data/lib/pione/lang.rb +55 -0
- data/lib/pione/lang/basic-model.rb +45 -0
- data/lib/pione/lang/boolean.rb +86 -0
- data/lib/pione/lang/common-parser.rb +202 -0
- data/lib/pione/lang/conditional-branch-parser.rb +57 -0
- data/lib/pione/lang/conditional-branch-transformer.rb +36 -0
- data/lib/pione/lang/conditional-branch.rb +73 -0
- data/lib/pione/lang/context-parser.rb +39 -0
- data/lib/pione/lang/context-transformer.rb +41 -0
- data/lib/pione/lang/context.rb +229 -0
- data/lib/pione/lang/data-expr.rb +265 -0
- data/lib/pione/lang/declaration-parser.rb +174 -0
- data/lib/pione/lang/declaration-transformer.rb +153 -0
- data/lib/pione/lang/declaration.rb +322 -0
- data/lib/pione/lang/definition.rb +88 -0
- data/lib/pione/lang/document-parser.rb +19 -0
- data/lib/pione/lang/document-transformer.rb +12 -0
- data/lib/pione/lang/environment.rb +344 -0
- data/lib/pione/{parser → lang}/error-message.yml +0 -0
- data/lib/pione/lang/expr-parser.rb +228 -0
- data/lib/pione/{transformer → lang}/expr-transformer.rb +32 -44
- data/lib/pione/lang/expr.rb +70 -0
- data/lib/pione/lang/feature-expr.rb +425 -0
- data/lib/pione/lang/float.rb +104 -0
- data/lib/pione/lang/integer.rb +159 -0
- data/lib/pione/lang/interpolator-parser.rb +44 -0
- data/lib/pione/lang/interpolator-transformer.rb +13 -0
- data/lib/pione/lang/keyed-sequence.rb +98 -0
- data/lib/pione/lang/lang-exception.rb +224 -0
- data/lib/pione/lang/literal-parser.rb +134 -0
- data/lib/pione/lang/literal-transformer.rb +171 -0
- data/lib/pione/lang/message.rb +41 -0
- data/lib/pione/lang/ordinal-sequence.rb +203 -0
- data/lib/pione/lang/package-expr.rb +86 -0
- data/lib/pione/lang/parameters.rb +121 -0
- data/lib/pione/lang/piece.rb +42 -0
- data/lib/pione/{model → lang}/pione-method.rb +26 -63
- data/lib/pione/lang/rule-expr.rb +70 -0
- data/lib/pione/lang/sequence.rb +215 -0
- data/lib/pione/lang/string.rb +116 -0
- data/lib/pione/lang/ticket-expr.rb +48 -0
- data/lib/pione/{model → lang}/type.rb +70 -99
- data/lib/pione/lang/variable.rb +35 -0
- data/lib/pione/location.rb +13 -1
- data/lib/pione/{uri-scheme → location}/broadcast-scheme.rb +2 -2
- data/lib/pione/location/data-location.rb +22 -5
- data/lib/pione/location/dropbox-location.rb +10 -8
- data/lib/pione/{uri-scheme → location}/dropbox-scheme.rb +2 -2
- data/lib/pione/location/ftp-location.rb +6 -0
- data/lib/pione/location/git-repository-location.rb +6 -17
- data/lib/pione/{uri-scheme → location}/git-scheme.rb +2 -2
- data/lib/pione/location/http-location.rb +8 -1
- data/lib/pione/location/local-location.rb +57 -4
- data/lib/pione/{uri-scheme → location}/local-scheme.rb +2 -2
- data/lib/pione/location/{exception.rb → location-exception.rb} +13 -1
- data/lib/pione/{uri-scheme/basic-scheme.rb → location/location-scheme.rb} +7 -6
- data/lib/pione/{uri-scheme → location}/myftp-scheme.rb +2 -2
- data/lib/pione/log.rb +7 -6
- data/lib/pione/log/debug.rb +75 -0
- data/lib/pione/log/domain-log.rb +4 -5
- data/lib/pione/log/message-log.rb +2 -2
- data/lib/pione/log/process-log.rb +16 -25
- data/lib/pione/log/process-record.rb +1 -0
- data/lib/pione/log/system-log.rb +165 -55
- data/lib/pione/package.rb +21 -0
- data/lib/pione/package/document.rb +27 -0
- data/lib/pione/package/package-archiver.rb +152 -0
- data/lib/pione/package/package-cache.rb +79 -0
- data/lib/pione/package/package-database.rb +121 -0
- data/lib/pione/package/package-exception.rb +38 -0
- data/lib/pione/{component → package}/package-expander.rb +13 -7
- data/lib/pione/package/package-filename.rb +46 -0
- data/lib/pione/package/package-handler.rb +106 -0
- data/lib/pione/package/package-info.rb +72 -0
- data/lib/pione/package/package-reader.rb +202 -0
- data/lib/pione/package/package-scanner.rb +133 -0
- data/lib/pione/package/scenario-handler.rb +95 -0
- data/lib/pione/package/scenario-info.rb +34 -0
- data/lib/pione/package/scenario-reader.rb +29 -0
- data/lib/pione/package/scenario-scanner.rb +96 -0
- data/lib/pione/patch.rb +0 -1
- data/lib/pione/patch/drb-patch.rb +377 -298
- data/lib/pione/patch/rinda-patch.rb +4 -3
- data/lib/pione/relay/relay-socket.rb +1 -4
- data/lib/pione/rule-engine.rb +27 -0
- data/lib/pione/{rule-handler → rule-engine}/action-handler.rb +41 -40
- data/lib/pione/rule-engine/basic-handler.rb +266 -0
- data/lib/pione/rule-engine/data-finder.rb +97 -0
- data/lib/pione/{rule-handler → rule-engine}/empty-handler.rb +2 -3
- data/lib/pione/rule-engine/engine-exception.rb +33 -0
- data/lib/pione/rule-engine/flow-handler.rb +490 -0
- data/lib/pione/{rule-handler → rule-engine}/root-handler.rb +5 -14
- data/lib/pione/{rule-handler → rule-engine}/system-handler.rb +1 -1
- data/lib/pione/rule-engine/update-criteria.rb +111 -0
- data/lib/pione/system.rb +3 -1
- data/lib/pione/system/config.rb +12 -45
- data/lib/pione/system/domain-info.rb +3 -12
- data/lib/pione/system/init.rb +2 -8
- data/lib/pione/system/system-exception.rb +29 -0
- data/lib/pione/test-helper.rb +43 -0
- data/lib/pione/test-helper/command-helper.rb +65 -0
- data/lib/pione/test-helper/extension.rb +9 -0
- data/lib/pione/test-helper/lang-helper.rb +196 -0
- data/lib/pione/test-helper/location-helper.rb +27 -0
- data/lib/pione/test-helper/package-helper.rb +11 -0
- data/lib/pione/test-helper/parser-helper.rb +45 -0
- data/lib/pione/test-helper/transformer-helper.rb +136 -0
- data/lib/pione/test-helper/tuple-helper.rb +13 -0
- data/lib/pione/test-helper/tuple-space-helper.rb +31 -0
- data/lib/pione/test-helper/webserver.rb +50 -0
- data/lib/pione/tuple-space.rb +4 -6
- data/lib/pione/{tuple → tuple-space}/basic-tuple.rb +63 -50
- data/lib/pione/tuple-space/tuple-definition.yml +165 -0
- data/lib/pione/tuple-space/tuple-space-exception.rb +25 -0
- data/lib/pione/tuple-space/tuple-space-interface.rb +123 -0
- data/lib/pione/tuple-space/tuple-space-server.rb +15 -26
- data/lib/pione/util.rb +16 -11
- data/lib/pione/util/backslash-notation.rb +11 -0
- data/lib/pione/util/digest.rb +71 -0
- data/lib/pione/util/embeded-expr-expander.rb +23 -0
- data/lib/pione/util/evaluatable.rb +9 -6
- data/lib/pione/util/free-thread-generator.rb +46 -0
- data/lib/pione/util/ftp-server.rb +3 -4
- data/lib/pione/util/id.rb +28 -23
- data/lib/pione/util/misc.rb +22 -4
- data/lib/pione/util/package-parameters-list.rb +12 -9
- data/lib/pione/{parser → util}/parslet-extension.rb +75 -64
- data/lib/pione/util/positionable.rb +65 -0
- data/lib/pione/util/zip.rb +12 -11
- data/lib/pione/version.rb +1 -1
- data/{test → misc}/endurance-test/graph.plt +0 -0
- data/{test → misc}/endurance-test/run.sh +0 -0
- data/pione.gemspec +45 -37
- data/test/agent/spec_basic-agent.rb +116 -99
- data/test/agent/spec_broker.rb +41 -25
- data/test/agent/spec_input-generator.rb +66 -57
- data/test/agent/spec_job-terminator.rb +27 -0
- data/test/agent/spec_logger.rb +28 -25
- data/test/agent/spec_messenger.rb +6 -6
- data/test/agent/spec_task-worker.rb +97 -246
- data/test/agent/spec_tuple-space-client.rb +19 -15
- data/test/agent/spec_tuple-space-provider.rb +26 -0
- data/test/agent/spec_tuple-space-receiver.rb +47 -0
- data/test/command/command-behavior.rb +2 -2
- data/test/command/data/PionePackageP1/P1.pione +9 -0
- data/test/command/data/PionePackageP1/pione-package.json +15 -0
- data/test/command/data/PionePackageP2/P2.pione +10 -0
- data/test/command/data/PionePackageP2/pione-package.json +16 -0
- data/test/command/data/PionePackageP3/P3.pione +10 -0
- data/test/command/data/PionePackageP3/pione-package.json +16 -0
- data/test/command/data/PionePackageP4/P4.pione +10 -0
- data/test/command/data/PionePackageP4/pione-package.json +17 -0
- data/test/command/data/pione-process.log +471 -0
- data/test/command/data/pione-val.domain.dump +0 -0
- data/test/command/spec_pione-clean.rb +12 -0
- data/test/command/spec_pione-client.rb +6 -6
- data/test/command/spec_pione-log.rb +28 -0
- data/test/command/spec_pione-package.rb +111 -12
- data/test/command/spec_pione-val.rb +4 -4
- data/test/lang/data/boolean.yml +134 -0
- data/test/lang/data/common-parser.yml +187 -0
- data/test/{parser/spec_flow-element-parser.yml → lang/data/conditional-branch-parser.yml} +12 -50
- data/test/lang/data/context-parser.yml +148 -0
- data/test/lang/data/data-expr.yml +93 -0
- data/test/lang/data/data-expr_match.yml +59 -0
- data/test/lang/data/declaration-parser.yml +279 -0
- data/test/lang/data/document-parser.yml +29 -0
- data/test/{parser/spec_expr-parser.yml → lang/data/expr-parser.yml} +9 -11
- data/test/lang/data/feature-expr.yml +148 -0
- data/test/lang/data/float.yml +30 -0
- data/test/lang/data/integer.yml +80 -0
- data/test/lang/data/interpolator-parser.yml +61 -0
- data/test/lang/data/keyed-sequence.yml +27 -0
- data/test/lang/data/literal-parser.yml +207 -0
- data/test/lang/data/parameter-set.yml +14 -0
- data/test/lang/data/rule-expr.yml +27 -0
- data/test/lang/data/sequence.yml +66 -0
- data/test/lang/data/string.yml +92 -0
- data/test/{model/spec_ticket-expr.yml → lang/data/ticket-expr.yml} +0 -0
- data/test/lang/spec_boolean.rb +5 -0
- data/test/{parser → lang}/spec_common-parser.rb +10 -32
- data/test/lang/spec_conditional-branch-parser.rb +5 -0
- data/test/lang/spec_conditional-branch-transformer.rb +97 -0
- data/test/lang/spec_conditional-branch.rb +176 -0
- data/test/lang/spec_context-parser.rb +5 -0
- data/test/lang/spec_context-transformer.rb +206 -0
- data/test/lang/spec_context.rb +283 -0
- data/test/lang/spec_data-expr.rb +198 -0
- data/test/lang/spec_declaration-parser.rb +5 -0
- data/test/lang/spec_declaration-transformer.rb +272 -0
- data/test/lang/spec_declaration.rb +550 -0
- data/test/lang/spec_document-parser.rb +5 -0
- data/test/lang/spec_document-transformer.rb +10 -0
- data/test/lang/spec_environment.rb +129 -0
- data/test/lang/spec_expr-parser.rb +6 -0
- data/test/lang/spec_expr-transformer.rb +149 -0
- data/test/lang/spec_feature-expr.rb +5 -0
- data/test/lang/spec_float.rb +23 -0
- data/test/lang/spec_integer.rb +29 -0
- data/test/lang/spec_interpolator-parser.rb +5 -0
- data/test/lang/spec_interpolator-transformer.rb +15 -0
- data/test/lang/spec_keyed-sequence.rb +5 -0
- data/test/lang/spec_literal-parser.rb +5 -0
- data/test/lang/spec_literal-transformer.rb +111 -0
- data/test/lang/spec_message.rb +22 -0
- data/test/lang/spec_package-expr.rb +19 -0
- data/test/lang/spec_parameter-set.rb +64 -0
- data/test/lang/spec_pione-method.rb +57 -0
- data/test/lang/spec_rule-expr.rb +18 -0
- data/test/lang/spec_sequence.rb +5 -0
- data/test/lang/spec_string.rb +5 -0
- data/test/lang/spec_ticket-expr.rb +39 -0
- data/test/lang/spec_variable.rb +29 -0
- data/test/{uri-scheme/spec_myftp-scheme.yml → location/data/myftp-scheme.yml} +0 -0
- data/test/location/location-behavior.rb +2 -2
- data/test/location/spec_basic-location.rb +5 -1
- data/test/{uri-scheme → location}/spec_broadcast-scheme.rb +4 -4
- data/test/{uri-scheme → location}/spec_dropbox-scheme.rb +3 -3
- data/test/location/spec_ftp-location.rb +3 -2
- data/test/location/spec_git-repository-location.rb +19 -19
- data/test/{uri-scheme → location}/spec_git-scheme.rb +2 -2
- data/test/location/spec_http-location.rb +4 -12
- data/test/location/spec_https-location.rb +1 -3
- data/test/location/spec_local-location.rb +1 -1
- data/test/{uri-scheme → location}/spec_local-scheme.rb +3 -3
- data/test/{uri-scheme → location}/spec_myftp-scheme.rb +8 -10
- data/test/log/spec_debug.rb +53 -0
- data/test/log/spec_domain-log.rb +4 -5
- data/test/log/spec_message-log.rb +39 -33
- data/test/log/spec_process-log.rb +4 -2
- data/test/log/spec_process-record.rb +12 -10
- data/test/log/spec_system-log.rb +29 -11
- data/test/log/spec_xes-log.rb +6 -4
- data/test/package/data/HelloWorld+v0.1.1.ppg +0 -0
- data/test/package/data/HelloWorld-gitrepos.zip +0 -0
- data/test/{test-data/package → package/data}/HelloWorld/HelloWorld.pione +3 -0
- data/test/package/data/HelloWorld/pione-package.json +16 -0
- data/test/package/data/HelloWorld/scenario/Scenario.pione +2 -0
- data/test/{test-data/package → package/data}/HelloWorld/scenario/output/message.txt +0 -0
- data/test/package/data/HelloWorld/scenario/pione-scenario.json +10 -0
- data/test/{test-data/package → package/data}/HelloWorld/scenario/scenario.yml +0 -0
- data/test/package/data/PackageScannerP1/P1.pione +11 -0
- data/test/package/data/PackageScannerP2/P2.pione +9 -0
- data/test/package/data/PackageScannerP3/P3.pione +17 -0
- data/test/package/data/PackageScannerP4/.Ignore.pione +1 -0
- data/test/package/data/PackageScannerP4/Doc1.pione +8 -0
- data/test/package/data/PackageScannerP4/Doc2.pione +6 -0
- data/test/package/data/PackageScannerP4/Doc3.pione +6 -0
- data/test/package/data/PackageScannerP4/P4.pione +8 -0
- data/test/package/data/PackageScannerP4/sub1/.Ignore.pione +1 -0
- data/test/package/data/PackageScannerP4/sub1/Doc4.pione +6 -0
- data/test/package/data/PackageScannerP4/sub1/sub1-1/.Ignore.pione +1 -0
- data/test/package/data/PackageScannerP4/sub1/sub1-1/Doc5.pione +6 -0
- data/test/package/data/PackageScannerP4/sub2/.Ignore.pione +1 -0
- data/test/package/data/PackageScannerP4/sub2/sub2-1/.Ignore.pione +1 -0
- data/test/package/data/PackageScannerP4/sub2/sub2-1/sub2-1-1/.Ignore.pione +1 -0
- data/test/package/data/PackageScannerP4/sub2/sub2-1/sub2-1-1/Doc6.pione +6 -0
- data/test/package/data/PackageScannerP4/sub2/sub2-1/sub2-1-2/.Ignore.pione +1 -0
- data/test/package/data/PackageScannerP4/sub2/sub2-1/sub2-1-2/Doc7.pione +6 -0
- data/test/package/data/PackageScannerP5/P5.pione +8 -0
- data/test/{model/spec_feature-expr.yml → package/data/PackageScannerP5/scenario1/Scenario.pione} +0 -0
- data/test/package/data/PackageScannerP5/scenario2/Scenario.pione +0 -0
- data/test/package/data/PackageScannerP5/scenario3/Scenario.pione +0 -0
- data/test/package/data/PackageScannerP5/sub1/scenario4/Scenario.pione +0 -0
- data/test/package/data/PackageScannerP5/sub1/sub1-1/scenario5/Scenario.pione +0 -0
- data/test/package/data/PackageScannerP5/sub2/sub2-1/sub2-1-1/scenario6/Scenario.pione +0 -0
- data/test/package/data/PackageScannerP5/sub2/sub2-1/sub2-1-2/scenario7/Scenario.pione +0 -0
- data/test/package/data/ScenarioScannerS1/Scenario.pione +1 -0
- data/test/package/data/ScenarioScannerS1/input/i1 +0 -0
- data/test/package/data/ScenarioScannerS1/input/i2 +0 -0
- data/test/package/data/ScenarioScannerS1/input/i3 +0 -0
- data/test/package/data/ScenarioScannerS1/output/o1 +0 -0
- data/test/package/data/ScenarioScannerS1/output/o2 +0 -0
- data/test/package/data/ScenarioScannerS1/output/o3 +0 -0
- data/test/package/data/ScenarioScannerS2/Scenario.pione +1 -0
- data/test/package/data/ScenarioScannerS2/output/o1 +0 -0
- data/test/package/data/ScenarioScannerS3/Scenario.pione +2 -0
- data/test/package/data/ScenarioScannerS4/Scenario.pione +0 -0
- data/test/package/data/ScenarioScannerS5/Scenario.pione +2 -0
- data/test/package/data/ScenarioScannerS6/Scenario.pione +5 -0
- data/test/package/data/ScenarioScannerS8/Scenario.pione +1 -0
- data/test/{test-data/package → package/data}/TestPackage1+v0.1.0.ppg +0 -0
- data/test/{test-data/package → package/data}/TestPackage1/Test.pione +3 -0
- data/test/{test-data/package → package/data}/TestPackage1/bin/count +0 -0
- data/test/{test-data/package → package/data}/TestPackage1/package.yml +0 -0
- data/test/package/data/TestPackage1/pione-package.json +18 -0
- data/test/package/data/TestPackage1/scenario/case1/Scenario.pione +1 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case1/input/1.txt +0 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case1/output/1.count +0 -0
- data/test/package/data/TestPackage1/scenario/case1/pione-scenario.json +10 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case1/scenario.yml +0 -0
- data/test/package/data/TestPackage1/scenario/case2/Scenario.pione +1 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case2/input/1.txt +0 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case2/input/2.txt +0 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case2/input/3.txt +0 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case2/output/1.count +0 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case2/output/2.count +0 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case2/output/3.count +0 -0
- data/test/package/data/TestPackage1/scenario/case2/pione-scenario.json +14 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case2/scenario.yml +0 -0
- data/test/package/data/TestPackage1/scenario/case3/Scenario.pione +1 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case3/input/a.txt +0 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case3/input/b.txt +0 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case3/output/a.count +0 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case3/output/b.count +0 -0
- data/test/package/data/TestPackage1/scenario/case3/pione-scenario.json +12 -0
- data/test/{test-data/package → package/data}/TestPackage1/scenario/case3/scenario.yml +0 -0
- data/test/{component → package}/spec_document.pione +0 -0
- data/test/package/spec_document.rb +52 -0
- data/test/package/spec_package-archiver.rb +31 -0
- data/test/package/spec_package-database.rb +42 -0
- data/test/package/spec_package-expander.rb +14 -0
- data/test/package/spec_package-filename.rb +56 -0
- data/test/package/spec_package-handler.rb +50 -0
- data/test/package/spec_package-info.rb +22 -0
- data/test/package/spec_package-reader.rb +85 -0
- data/test/package/spec_package-scanner.rb +68 -0
- data/test/package/spec_scenario-handler.rb +46 -0
- data/test/package/spec_scenario-info.rb +16 -0
- data/test/package/spec_scenario-scanner.rb +92 -0
- data/test/patch/spec_rinda-patch.rb +1 -1
- data/test/patch/spec_uri-patch.rb +1 -1
- data/test/{rule-handler → rule-engine}/spec_action-handler.pione +0 -0
- data/test/rule-engine/spec_action-handler.rb +94 -0
- data/test/rule-engine/spec_data-finder.rb +94 -0
- data/test/{tuple-space → rule-engine}/spec_data-finder.yml +39 -28
- data/test/rule-engine/spec_empty-handler.rb +170 -0
- data/test/{rule-handler → rule-engine}/spec_flow-handler.pione +0 -0
- data/test/rule-engine/spec_flow-handler.rb +421 -0
- data/test/{rule-handler → rule-engine}/spec_update-criteria.pione +0 -0
- data/test/{rule-handler → rule-engine}/spec_update-criteria.rb +16 -12
- data/test/{rule-handler → rule-engine}/spec_update-criteria.yml +0 -0
- data/test/system/spec_domain-info.rb +13 -9
- data/test/system/spec_file-cache.rb +9 -9
- data/test/tuple-space/spec_tuple-space-server.rb +42 -40
- data/test/tuple/spec_basic-tuple.rb +77 -75
- data/test/tuple/spec_data-tuple.rb +4 -4
- data/test/tuple/spec_finished-tuple.rb +5 -6
- data/test/tuple/spec_message-tuple.rb +3 -3
- data/test/tuple/spec_task-tuple.rb +11 -9
- data/test/tuple/spec_touch-tuple.rb +3 -3
- data/test/tuple/spec_working-tuple.rb +8 -12
- data/test/tuple/tuple-behavior.rb +1 -1
- data/test/util/data/HelloWorld+v0.1.1.ppg +0 -0
- data/test/util/spec_cpu.rb +1 -1
- data/test/util/spec_digest.rb +15 -0
- data/test/util/spec_evaluatable.rb +3 -3
- data/test/util/spec_free-thread-generator.rb +42 -0
- data/test/util/spec_ftp-server.rb +4 -9
- data/test/util/spec_id.rb +53 -36
- data/test/util/spec_indentation.rb +1 -1
- data/test/util/spec_ip-address.rb +1 -1
- data/test/util/spec_package-parameters-list.rb +10 -9
- data/test/util/spec_process-info.rb +2 -2
- data/test/util/spec_uuid.rb +1 -1
- data/test/util/spec_variable-holdable.rb +1 -1
- data/test/util/spec_zip.rb +1 -1
- metadata +508 -364
- data/example/SerialProcessing/package.yml +0 -5
- data/example/SerialProcessing/scenario/scenario.yml +0 -10
- data/lib/pione/agent/command-listener.rb +0 -47
- data/lib/pione/agent/rule-provider.rb +0 -59
- data/lib/pione/agent/trivial-routine-worker.rb +0 -29
- data/lib/pione/agent/tuple-space-server-client-life-checker.rb +0 -31
- data/lib/pione/command/child-process.rb +0 -56
- data/lib/pione/command/daemon-process.rb +0 -10
- data/lib/pione/command/front-owner-command.rb +0 -25
- data/lib/pione/component.rb +0 -13
- data/lib/pione/component/document.rb +0 -88
- data/lib/pione/component/package-archiver.rb +0 -92
- data/lib/pione/component/package-filename.rb +0 -38
- data/lib/pione/component/package-reader.rb +0 -276
- data/lib/pione/component/package.rb +0 -199
- data/lib/pione/component/rule.rb +0 -206
- data/lib/pione/front/task-worker-owner.rb +0 -43
- data/lib/pione/front/tuple-space-provider-owner.rb +0 -11
- data/lib/pione/model.rb +0 -32
- data/lib/pione/model/assignment.rb +0 -120
- data/lib/pione/model/basic-model.rb +0 -228
- data/lib/pione/model/block.rb +0 -262
- data/lib/pione/model/boolean.rb +0 -168
- data/lib/pione/model/call-rule.rb +0 -86
- data/lib/pione/model/constraints.rb +0 -46
- data/lib/pione/model/data-expr.rb +0 -548
- data/lib/pione/model/feature-expr.rb +0 -875
- data/lib/pione/model/float.rb +0 -105
- data/lib/pione/model/integer.rb +0 -166
- data/lib/pione/model/keyed-sequence.rb +0 -150
- data/lib/pione/model/message.rb +0 -95
- data/lib/pione/model/ordinal-sequence.rb +0 -73
- data/lib/pione/model/package-expr.rb +0 -53
- data/lib/pione/model/parameters.rb +0 -374
- data/lib/pione/model/rule-expr.rb +0 -234
- data/lib/pione/model/sequence.rb +0 -273
- data/lib/pione/model/string.rb +0 -127
- data/lib/pione/model/ticket-expr.rb +0 -71
- data/lib/pione/model/variable-table.rb +0 -344
- data/lib/pione/model/variable.rb +0 -116
- data/lib/pione/parser.rb +0 -14
- data/lib/pione/parser/block-parser.rb +0 -107
- data/lib/pione/parser/common-parser.rb +0 -173
- data/lib/pione/parser/document-parser.rb +0 -141
- data/lib/pione/parser/expr-parser.rb +0 -354
- data/lib/pione/parser/feature-expr-parser.rb +0 -105
- data/lib/pione/parser/flow-element-parser.rb +0 -181
- data/lib/pione/parser/literal-parser.rb +0 -196
- data/lib/pione/parser/rule-definition-parser.rb +0 -158
- data/lib/pione/patch/monitor-patch.rb +0 -16
- data/lib/pione/rule-handler.rb +0 -14
- data/lib/pione/rule-handler/basic-handler.rb +0 -326
- data/lib/pione/rule-handler/flow-handler.rb +0 -414
- data/lib/pione/rule-handler/update-criteria.rb +0 -175
- data/lib/pione/system/global.rb +0 -433
- data/lib/pione/transformer.rb +0 -24
- data/lib/pione/transformer/block-transformer.rb +0 -28
- data/lib/pione/transformer/document-transformer.rb +0 -58
- data/lib/pione/transformer/feature-expr-transformer.rb +0 -60
- data/lib/pione/transformer/flow-element-transformer.rb +0 -66
- data/lib/pione/transformer/literal-transformer.rb +0 -91
- data/lib/pione/transformer/rule-definition-transformer.rb +0 -80
- data/lib/pione/transformer/transformer-module.rb +0 -39
- data/lib/pione/tuple-space/data-finder.rb +0 -155
- data/lib/pione/tuple-space/presence-notifier.rb +0 -84
- data/lib/pione/tuple-space/tuple-space-provider.rb +0 -85
- data/lib/pione/tuple-space/tuple-space-receiver.rb +0 -141
- data/lib/pione/tuple-space/tuple-space-server-interface.rb +0 -123
- data/lib/pione/tuple.rb +0 -30
- data/lib/pione/tuple/agent-tuple.rb +0 -10
- data/lib/pione/tuple/attribute-tuple.rb +0 -7
- data/lib/pione/tuple/base-location-tuple.rb +0 -9
- data/lib/pione/tuple/bye-tuple.rb +0 -9
- data/lib/pione/tuple/command-tuple.rb +0 -9
- data/lib/pione/tuple/data-null-tuple.rb +0 -14
- data/lib/pione/tuple/data-tuple.rb +0 -21
- data/lib/pione/tuple/dry-run-tuple.rb +0 -8
- data/lib/pione/tuple/exception-tuple.rb +0 -11
- data/lib/pione/tuple/finished-tuple.rb +0 -17
- data/lib/pione/tuple/foreground-tuple.rb +0 -7
- data/lib/pione/tuple/lift-tuple.rb +0 -14
- data/lib/pione/tuple/message-tuple.rb +0 -7
- data/lib/pione/tuple/process-info-tuple.rb +0 -9
- data/lib/pione/tuple/process-log-tuple.rb +0 -13
- data/lib/pione/tuple/request-rule-tuple.rb +0 -9
- data/lib/pione/tuple/rule-tuple.rb +0 -10
- data/lib/pione/tuple/task-tuple.rb +0 -40
- data/lib/pione/tuple/task-worker-resource-tuple.rb +0 -9
- data/lib/pione/tuple/ticket-tuple.rb +0 -8
- data/lib/pione/tuple/touch-tuple.rb +0 -14
- data/lib/pione/tuple/working-tuple.rb +0 -13
- data/lib/pione/uri-scheme.rb +0 -11
- data/lib/pione/util/error-report.rb +0 -27
- data/test/agent/spec_command-listener.rb +0 -30
- data/test/agent/spec_rule-provider.rb +0 -78
- data/test/command/spec_pione-val.domain.dump +0 -0
- data/test/component/spec_document.rb +0 -67
- data/test/component/spec_package-archiver.rb +0 -27
- data/test/component/spec_package-expander.rb +0 -11
- data/test/component/spec_package-filename.rb +0 -79
- data/test/component/spec_package-reader.rb +0 -100
- data/test/component/spec_package.rb +0 -109
- data/test/component/spec_rule.rb +0 -140
- data/test/model/spec_assignment.rb +0 -52
- data/test/model/spec_block.rb +0 -108
- data/test/model/spec_boolean.rb +0 -39
- data/test/model/spec_boolean.yml +0 -134
- data/test/model/spec_call-rule.rb +0 -23
- data/test/model/spec_data-expr.rb +0 -361
- data/test/model/spec_data-expr.yml +0 -24
- data/test/model/spec_data-expr_match.yml +0 -45
- data/test/model/spec_feature-expr.rb +0 -333
- data/test/model/spec_feature-expr_decide.yml +0 -28
- data/test/model/spec_float.rb +0 -23
- data/test/model/spec_float.yml +0 -30
- data/test/model/spec_integer.rb +0 -23
- data/test/model/spec_integer.yml +0 -68
- data/test/model/spec_keyed-sequence.rb +0 -5
- data/test/model/spec_keyed-sequence.yml +0 -27
- data/test/model/spec_message.rb +0 -40
- data/test/model/spec_package-expr.rb +0 -19
- data/test/model/spec_parameters.rb +0 -103
- data/test/model/spec_pione-method.rb +0 -57
- data/test/model/spec_rule-expr.rb +0 -28
- data/test/model/spec_rule-expr.yml +0 -11
- data/test/model/spec_sequence.rb +0 -5
- data/test/model/spec_sequence.yml +0 -66
- data/test/model/spec_string.rb +0 -47
- data/test/model/spec_string.yml +0 -91
- data/test/model/spec_ticket-expr.rb +0 -39
- data/test/model/spec_variable-table.rb +0 -116
- data/test/model/spec_variable.rb +0 -82
- data/test/parser/spec_block-parser.rb +0 -5
- data/test/parser/spec_block-parser.yml +0 -94
- data/test/parser/spec_document-parser.rb +0 -5
- data/test/parser/spec_document-parser.yml +0 -77
- data/test/parser/spec_expr-parser.rb +0 -6
- data/test/parser/spec_feature-expr-parser.rb +0 -32
- data/test/parser/spec_feature-expr-parser.yml +0 -25
- data/test/parser/spec_flow-element-parser.rb +0 -5
- data/test/parser/spec_literal-parser.rb +0 -5
- data/test/parser/spec_literal-parser.yml +0 -134
- data/test/parser/spec_rule-definition-parser.rb +0 -5
- data/test/parser/spec_rule-definition-parser.yml +0 -94
- data/test/rule-handler/spec_action-handler.rb +0 -79
- data/test/rule-handler/spec_flow-handler.rb +0 -61
- data/test/spec_common.rb +0 -14
- data/test/spec_object.rb +0 -20
- data/test/test-data/package/HelloWorld+v0.1.0.ppg +0 -0
- data/test/test-data/package/HelloWorld-gitrepos.zip +0 -0
- data/test/test-data/package/HelloWorld/package.yml +0 -6
- data/test/test-util.rb +0 -211
- data/test/test-util/command.rb +0 -53
- data/test/test-util/package.rb +0 -9
- data/test/test-util/parser.rb +0 -45
- data/test/test-util/transformer.rb +0 -50
- data/test/test-util/webserver.rb +0 -43
- data/test/transformer/spec_block-transformer.rb +0 -33
- data/test/transformer/spec_document-transformer.rb +0 -50
- data/test/transformer/spec_expr-transformer.rb +0 -126
- data/test/transformer/spec_feature-expr-transformer.rb +0 -21
- data/test/transformer/spec_flow-element-transformer.rb +0 -154
- data/test/transformer/spec_literal-transformer.rb +0 -64
- data/test/transformer/spec_rule-definition-transformer.rb +0 -172
- data/test/tuple-space/spec_data-finder.rb +0 -94
- data/test/tuple-space/spec_tuple-space-provider.rb +0 -36
- data/test/tuple-space/spec_tuple-space-receiver.rb +0 -32
- data/test/util/spec_error-report.rb +0 -51
@@ -0,0 +1,97 @@
|
|
1
|
+
module Pione
|
2
|
+
module RuleEngine
|
3
|
+
# DataFinder finds data tuples from tuple space server.
|
4
|
+
class DataFinder
|
5
|
+
include TupleSpace::TupleSpaceInterface
|
6
|
+
|
7
|
+
# Creates a new finder.
|
8
|
+
def initialize(space, domain_id)
|
9
|
+
set_tuple_space(space)
|
10
|
+
@domain_id = domain_id
|
11
|
+
end
|
12
|
+
|
13
|
+
# Find data tuple combinations from tuple space server. This method calls
|
14
|
+
# the block when the combination found.
|
15
|
+
def find(type, conditions, env, &b)
|
16
|
+
find_next(type, 1, conditions, env, [], &b)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Find input tuple combinatioins recursively.
|
22
|
+
def find_next(type, index, conditions, env, combination, &b)
|
23
|
+
# call block when we reach the recuirsion end
|
24
|
+
return yield(env, combination) if conditions.empty?
|
25
|
+
|
26
|
+
# expand variables and compile to regular expression
|
27
|
+
head = conditions.first.eval(env)
|
28
|
+
tail = conditions.drop(1)
|
29
|
+
|
30
|
+
# find data tuples by head condition from tuple space server
|
31
|
+
tuples = find_tuples_by_condition(head)
|
32
|
+
|
33
|
+
# no tuples
|
34
|
+
if tuples.empty?
|
35
|
+
if head.accept_nonexistence?
|
36
|
+
# accept noexistance data, find next tuples
|
37
|
+
return find_next(type, index+1, tail, env.layer, combination + [[]], &b)
|
38
|
+
else
|
39
|
+
return # failed to find tuples
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# make combination results
|
44
|
+
case head.distribution
|
45
|
+
when :all
|
46
|
+
_env = make_io_variables(type, index, :all, head, env, tuples)
|
47
|
+
find_next(type, index+1, tail, _env, combination + [tuples], &b)
|
48
|
+
when :each
|
49
|
+
tuples.each do |tuple|
|
50
|
+
_env = make_io_variables(type, index, :each, head, env, [tuple])
|
51
|
+
find_next(type, index+1, tail, _env, combination + [[tuple]], &b)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Find all matched data tuples by the rule expression condition from tuple space.
|
57
|
+
def find_tuples_by_condition(condition)
|
58
|
+
return read_all(TupleSpace::DataTuple.new(name: condition, domain: @domain_id))
|
59
|
+
end
|
60
|
+
|
61
|
+
# Make input/output variables by data expression with all distribution.
|
62
|
+
def make_io_variables(type, index, distribution, condition, env, tuples)
|
63
|
+
_env = env.layer
|
64
|
+
asterisk = []
|
65
|
+
|
66
|
+
# variable and value
|
67
|
+
var = Lang::Variable.new(type == :input ? "I" : "O")
|
68
|
+
val = env.variable_get!(var) || Lang::KeyedSequence.new
|
69
|
+
|
70
|
+
# update value
|
71
|
+
_val = tuples.inject(val) do |_val, tuple|
|
72
|
+
# matched data
|
73
|
+
md = condition.match(tuple.name).to_a
|
74
|
+
asterisk << md[1]
|
75
|
+
|
76
|
+
# make a date expression
|
77
|
+
data = Lang::DataExpr.new(pattern: tuple.name, location: tuple.location, matched_data: md)
|
78
|
+
|
79
|
+
# update value
|
80
|
+
_val.put(Lang::IntegerSequence.of(index), Lang::DataExprSequence.of(data))
|
81
|
+
end
|
82
|
+
_env.variable_set!(var, _val)
|
83
|
+
|
84
|
+
# set special variable if index equals 1
|
85
|
+
if type == :input && index == 1
|
86
|
+
strs = asterisk.map{|str| Lang::PioneString.new(str)}
|
87
|
+
_env.variable_set(
|
88
|
+
Lang::Variable.new("*"),
|
89
|
+
Lang::StringSequence.new(strs).set(distribution: distribution)
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
return _env
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Pione
|
2
|
+
module RuleEngine
|
3
|
+
# Exception class for rule execution failure.
|
4
|
+
class RuleExecutionError < StandardError
|
5
|
+
def initialize(handler)
|
6
|
+
@handler = handler
|
7
|
+
end
|
8
|
+
|
9
|
+
def message
|
10
|
+
"Execution error when handling the rule '%s': inputs=%s, output=%s, params=%s" % [
|
11
|
+
@handler.rule.path,
|
12
|
+
@handler.inputs,
|
13
|
+
@handler.outputs,
|
14
|
+
@handler.params.inspect
|
15
|
+
]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class InvalidOutputError < RuleExecutionError
|
20
|
+
def initialize(handler, outputs)
|
21
|
+
super(handler)
|
22
|
+
@outputs = outputs
|
23
|
+
end
|
24
|
+
|
25
|
+
def message
|
26
|
+
args = [@handler.rule_name, @handler.package_id, @outputs]
|
27
|
+
"Outputs of rule '%s' in package &%s are invalid: %s" % args
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class UnknownRule < StandardError; end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,490 @@
|
|
1
|
+
module Pione
|
2
|
+
module RuleEngine
|
3
|
+
# FlowHandler is a rule handler for flow elements.
|
4
|
+
class FlowHandler < BasicHandler
|
5
|
+
# Start to process flow elements.
|
6
|
+
#
|
7
|
+
# @return [void]
|
8
|
+
def execute
|
9
|
+
# restore data tuples from domain_location
|
10
|
+
restore_data_tuples_from_domain_location
|
11
|
+
|
12
|
+
# start rule application
|
13
|
+
rule_set = @rule_definition.flow_context.eval(@env)
|
14
|
+
RuleApplication.new(self).apply(rule_set.rules.pieces)
|
15
|
+
|
16
|
+
# find outputs
|
17
|
+
outputs = find_outputs_from_space
|
18
|
+
|
19
|
+
# lift output data from child domains to this domain
|
20
|
+
lift_output_data(outputs)
|
21
|
+
|
22
|
+
# check output validation
|
23
|
+
validate_outputs(outputs)
|
24
|
+
|
25
|
+
return outputs
|
26
|
+
end
|
27
|
+
|
28
|
+
# Restore data tuples from the domain location. This reads files in the
|
29
|
+
# location and write it as data tuples.
|
30
|
+
def restore_data_tuples_from_domain_location
|
31
|
+
if @domain_location.exist?
|
32
|
+
@domain_location.file_entries.each do |file|
|
33
|
+
# ignore dot files
|
34
|
+
unless file.basename[0] == "."
|
35
|
+
write(TupleSpace::DataTuple.new(@domain_id, file.basename, file, file.mtime))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Lift output data from this domains to parent domain.
|
42
|
+
#
|
43
|
+
# @return [void]
|
44
|
+
def lift_output_data(outputs)
|
45
|
+
# we cannot lift up if caller id is unknown
|
46
|
+
# NOTE: this is the case that we process root rule
|
47
|
+
return if @caller_id.nil?
|
48
|
+
|
49
|
+
outputs.flatten.compact.inject([]) do |lifted, output|
|
50
|
+
old_location = output.location
|
51
|
+
new_location = make_output_location(output.name)
|
52
|
+
unless new_location == old_location or lifted.include?(old_location)
|
53
|
+
if old_location.exist?
|
54
|
+
# move data from old to new
|
55
|
+
old_location.move(new_location)
|
56
|
+
# sync cache if the old is cached in this machine
|
57
|
+
System::FileCache.sync(old_location, new_location)
|
58
|
+
# write lift tuple
|
59
|
+
write(TupleSpace::LiftTuple.new(old_location, new_location))
|
60
|
+
# push history
|
61
|
+
lifted << old_location
|
62
|
+
end
|
63
|
+
end
|
64
|
+
lifted
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Validate outputs.
|
69
|
+
def validate_outputs(outputs)
|
70
|
+
_outputs = outputs.flatten.compact
|
71
|
+
@rule_condition.outputs.each do |condition|
|
72
|
+
_condition = condition.eval(@env)
|
73
|
+
c1 = _condition.accept_nonexistence?
|
74
|
+
c2 = _outputs.any?{|output| _condition.match?(output.name)}
|
75
|
+
unless c1 or c2
|
76
|
+
raise InvalidOutputError.new(self, outputs)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Remove finished tuple.
|
82
|
+
#
|
83
|
+
# @param domain [String]
|
84
|
+
# domain of the finished tuple
|
85
|
+
# @return [void]
|
86
|
+
def remove_finished_tuple(domain)
|
87
|
+
take!(TupleSpace::FinishedTuple.new(domain: domain))
|
88
|
+
end
|
89
|
+
|
90
|
+
# Copy the data tuple with the specified domain and return the tuple list.
|
91
|
+
#
|
92
|
+
# @param data [DataTuple]
|
93
|
+
# target data tuple
|
94
|
+
# @param domain [String]
|
95
|
+
# new domain of the copied data tuple
|
96
|
+
# @return [DataTuple]
|
97
|
+
# new data tuple with the domain or nil
|
98
|
+
def copy_data_into_domain(data, domain)
|
99
|
+
return nil unless data
|
100
|
+
new_data = data.clone.tap {|x| x.domain = domain}
|
101
|
+
write(new_data)
|
102
|
+
return new_data
|
103
|
+
end
|
104
|
+
|
105
|
+
# Remove the data from the domain.
|
106
|
+
def remove_data_from_domain(data, domain)
|
107
|
+
take!(TupleSpace::DataTuple.new(name: data.name, domain: domain))
|
108
|
+
end
|
109
|
+
|
110
|
+
def touch_data_in_domain(data, domain)
|
111
|
+
if target = read!(TupleSpace::DataTuple.new(name: data.name, domain: domain))
|
112
|
+
data = target
|
113
|
+
end
|
114
|
+
new_data = data.clone.tap {|x| x.domain = domain; x.time = Time.now}
|
115
|
+
write(new_data)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class Task < StructX
|
120
|
+
member :env # execution enviornment of this application
|
121
|
+
member :domain_id # domain id
|
122
|
+
member :rule # rule expression
|
123
|
+
member :rule_definition # definition of the task's rule
|
124
|
+
member :rule_condition # rule condition
|
125
|
+
member :inputs # inputs
|
126
|
+
member :param_set # task parameters
|
127
|
+
member :order # week or force
|
128
|
+
|
129
|
+
# Make a task tuple from the application.
|
130
|
+
def make_tuple(caller_id)
|
131
|
+
features = rule_condition.features.inject(Lang::FeatureSequence.new) do |f, expr|
|
132
|
+
f + f.eval(env)
|
133
|
+
end
|
134
|
+
TupleSpace::TaskTuple.new(
|
135
|
+
digest,
|
136
|
+
rule.package_id,
|
137
|
+
rule.name,
|
138
|
+
inputs,
|
139
|
+
param_set,
|
140
|
+
features,
|
141
|
+
domain_id,
|
142
|
+
caller_id
|
143
|
+
)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Return digest string of the task.
|
147
|
+
def digest
|
148
|
+
@__digest__ ||= Util::TaskDigest.generate(rule.package_id, rule.name, inputs, param_set)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Return task process record of the task.
|
152
|
+
def make_task_process_record
|
153
|
+
Log::TaskProcessRecord.new.tap do |record|
|
154
|
+
record.name = digest
|
155
|
+
record.package_id = rule.package_id
|
156
|
+
record.rule_name = rule.name
|
157
|
+
record.rule_type = rule_definition.rule_type
|
158
|
+
record.inputs = inputs.flatten.map{|input| input.name}.join(",")
|
159
|
+
record.parameters = param_set.textize
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def inspect
|
164
|
+
args = [self.class, rule.package_id, rule.name, inputs, param_set, order]
|
165
|
+
"#<%s package_id=%s, name=%s, inputs=%s, param_set=%s, order=%s>" % args
|
166
|
+
end
|
167
|
+
alias :to_s :inspect
|
168
|
+
end
|
169
|
+
|
170
|
+
class RuleApplication < SimpleDelegator
|
171
|
+
def initialize(handler)
|
172
|
+
super(handler)
|
173
|
+
@data_finder = DataFinder.new(tuple_space_server, domain_id)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Apply input data to rules.
|
177
|
+
def apply(rules)
|
178
|
+
# start message
|
179
|
+
user_message_begin("Rule Application: %s" % digest, 1)
|
180
|
+
|
181
|
+
# rule application loop
|
182
|
+
while tasks = find_tasks(rules) do
|
183
|
+
distribute_tasks(tasks)
|
184
|
+
end
|
185
|
+
|
186
|
+
# end message
|
187
|
+
user_message_end("Rule Application: %s" % digest, 1)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Find applicable and updatable rule applications.
|
191
|
+
def find_tasks(rules)
|
192
|
+
# select applicable rules
|
193
|
+
applicable_rules = find_applicable_rules(rules)
|
194
|
+
|
195
|
+
# make task
|
196
|
+
tasks = make_tasks(applicable_rules)
|
197
|
+
|
198
|
+
# be careful that returns nil when tasks are empty
|
199
|
+
tasks.empty? ? nil : tasks
|
200
|
+
end
|
201
|
+
|
202
|
+
# Find applicable rules. The criterion of applicable rule is that the rule
|
203
|
+
# satisfies ticket conditions or not.
|
204
|
+
def find_applicable_rules(rules)
|
205
|
+
# select rules which ticktes exist in this domain
|
206
|
+
rules.select do |rule|
|
207
|
+
rule.input_tickets.pieces.all? do |ticket|
|
208
|
+
read!(TupleSpace::TicketTuple.new(domain_id, ticket.name))
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
# Make tasks from rules.
|
214
|
+
def make_tasks(rules)
|
215
|
+
rules.each_with_object([]) do |rule, tasks|
|
216
|
+
# set handler's package id if rule's package id is implicit
|
217
|
+
rule = rule.set(package_id: package_id) unless rule.package_id
|
218
|
+
|
219
|
+
# get rule definition
|
220
|
+
rule_definition = env.rule_get(rule)
|
221
|
+
|
222
|
+
# handle parameter sequence
|
223
|
+
pieces = rule.param_sets.pieces
|
224
|
+
if not(pieces.empty?)
|
225
|
+
pieces.each do |param_set|
|
226
|
+
### merge default parameter values ####
|
227
|
+
# setup task's environment by parameter set
|
228
|
+
_env = plain_env.layer.merge(param_set)
|
229
|
+
_env.set(current_package_id: rule.package_id || env.current_package_id)
|
230
|
+
|
231
|
+
# get task's condition
|
232
|
+
rule_condition = rule_definition.rule_condition_context.eval(_env)
|
233
|
+
|
234
|
+
# merge default values
|
235
|
+
_param_set = param_set.merge_default_values(rule_condition)
|
236
|
+
|
237
|
+
# handle parameter distribution
|
238
|
+
_param_set.expand do |expanded_param_set|
|
239
|
+
# rebuild environment by expanded param set
|
240
|
+
_env = plain_env.layer.merge(expanded_param_set)
|
241
|
+
_env.set(current_package_id: rule.package_id || env.current_package_id)
|
242
|
+
|
243
|
+
# get task's condition
|
244
|
+
rule_condition = rule_definition.rule_condition_context.eval(_env)
|
245
|
+
|
246
|
+
tasks.concat find_tasks_by_rule_condition(_env, rule, rule_definition, rule_condition, expanded_param_set).uniq
|
247
|
+
end
|
248
|
+
end
|
249
|
+
else
|
250
|
+
_env = plain_env.layer
|
251
|
+
# get task's condition
|
252
|
+
rule_condition = rule_definition.rule_condition_context.eval(_env)
|
253
|
+
this_tasks = find_tasks_by_rule_condition(
|
254
|
+
_env, rule, rule_definition, rule_condition, Lang::ParameterSet.new
|
255
|
+
).uniq
|
256
|
+
tasks.concat(this_tasks)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
# Handle parameter distribution. Rule parameters with each modifier are
|
262
|
+
# distributed tasks by each element.
|
263
|
+
def find_tasks_by_rule_condition(env, rule, rule_definition, rule_condition, param_set)
|
264
|
+
tasks = []
|
265
|
+
|
266
|
+
# find input data combinations
|
267
|
+
@data_finder.find(:input, rule_condition.inputs, env) do |task_env, inputs|
|
268
|
+
# make parameter set for the task
|
269
|
+
table = Hash.new
|
270
|
+
|
271
|
+
if val_i = task_env.variable_get!(Lang::Variable.new("I"))
|
272
|
+
table["INPUT"] = Lang::Variable.new(name: "I", package_id: rule.package_id)
|
273
|
+
table["I"] = val_i
|
274
|
+
end
|
275
|
+
|
276
|
+
if val_star = task_env.variable_get!(Lang::Variable.new("*"))
|
277
|
+
table["*"] = val_star
|
278
|
+
end
|
279
|
+
|
280
|
+
task_param_set = param_set.set(table: param_set.table.merge(table))
|
281
|
+
|
282
|
+
# check constraint conditions
|
283
|
+
next unless rule_condition.constraints.all? do |constraint|
|
284
|
+
res = constraint.eval(task_env)
|
285
|
+
if res.is_a?(Lang::BooleanSequence)
|
286
|
+
res.value
|
287
|
+
else
|
288
|
+
raise Lang::StructuralError.new(Lang::BooleanSequence, constraint.pos)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
# make task
|
293
|
+
domain_id = Util::DomainID.generate(rule.package_id, rule.name, inputs, task_param_set)
|
294
|
+
task = Task.new(task_env, domain_id, rule, rule_definition, rule_condition, inputs, task_param_set)
|
295
|
+
|
296
|
+
# check updatability
|
297
|
+
if _task = check_updatability(task)
|
298
|
+
tasks << _task
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
return tasks
|
303
|
+
end
|
304
|
+
|
305
|
+
# Check updatability of the task and get update order.
|
306
|
+
def check_updatability(task)
|
307
|
+
# read all tuples of data-null
|
308
|
+
data_null_tuples = read_all(TupleSpace::DataNullTuple.new(domain: task.domain_id))
|
309
|
+
|
310
|
+
res = []
|
311
|
+
|
312
|
+
f = lambda do |task_env, outputs|
|
313
|
+
# make parameter set for the task
|
314
|
+
table = Hash.new
|
315
|
+
|
316
|
+
if val_i = task_env.variable_get!(Lang::Variable.new("O"))
|
317
|
+
table["OUTPUT"] = Lang::Variable.new("O")
|
318
|
+
table["O"] = val_i
|
319
|
+
end
|
320
|
+
|
321
|
+
task_param_set = task.param_set.set(table: task.param_set.table.merge(table))
|
322
|
+
|
323
|
+
# check update criterias
|
324
|
+
order = UpdateCriteria.order(task_env, task.rule_condition, task.inputs, outputs, data_null_tuples)
|
325
|
+
res << [order, task_env, task_param_set]
|
326
|
+
end
|
327
|
+
|
328
|
+
# find output data combination
|
329
|
+
@data_finder.find(:output, task.rule_condition.outputs, task.env, &f)
|
330
|
+
f.call(task.env, []) if res.empty?
|
331
|
+
|
332
|
+
# evaluate the result
|
333
|
+
groups = res.group_by {|(order, _, _)| order}
|
334
|
+
if f = groups[:force] or f = groups[:weak]
|
335
|
+
order, env, param_set = f.first
|
336
|
+
|
337
|
+
# setup output variables
|
338
|
+
var_o = Lang::Variable.new("O")
|
339
|
+
task.env.variable_set(Lang::Variable.new("OUTPUT"), var_o)
|
340
|
+
o = find_output_variables(task, inputs, Lang::KeyedSequence.new)
|
341
|
+
task.env.variable_set(var_o, o)
|
342
|
+
param_set = param_set.set(table: param_set.table.merge({"O" => o}))
|
343
|
+
|
344
|
+
return task.set(order: order, env: env, param_set: param_set)
|
345
|
+
else
|
346
|
+
return nil
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def find_output_variables(task, inputs, o)
|
351
|
+
_o = o
|
352
|
+
task.rule_condition.outputs.each_with_index do |condition, i|
|
353
|
+
begin
|
354
|
+
data = condition.eval(task.env)
|
355
|
+
_o = o.put(Lang::IntegerSequence.of(i+1), data)
|
356
|
+
rescue Lang::UnboundError
|
357
|
+
next
|
358
|
+
end
|
359
|
+
end
|
360
|
+
return _o
|
361
|
+
end
|
362
|
+
|
363
|
+
# Distribute tasks.
|
364
|
+
def distribute_tasks(tasks)
|
365
|
+
# log and message
|
366
|
+
process_log(make_task_process_record.merge(transition: "suspend"))
|
367
|
+
process_log(make_rule_process_record.merge(transition: "suspend"))
|
368
|
+
user_message_begin("Distribution: %s" % digest, 2)
|
369
|
+
|
370
|
+
# distribute tasks
|
371
|
+
tasks.each do |task|
|
372
|
+
tuple = task.make_tuple(domain_id)
|
373
|
+
|
374
|
+
# publish tasks
|
375
|
+
if need_to_publish_task?(task, tuple)
|
376
|
+
# clear finished tuple and data tuples from the domain
|
377
|
+
take!(TupleSpace::FinishedTuple.new(domain: task.domain_id))
|
378
|
+
take_all!(TupleSpace::DataTuple.new(domain: task.domain_id))
|
379
|
+
|
380
|
+
# copy input data from this domain to the task domain
|
381
|
+
task.inputs.flatten.each {|input| copy_data_into_domain(input, task.domain_id)}
|
382
|
+
|
383
|
+
# write the task
|
384
|
+
write(tuple)
|
385
|
+
|
386
|
+
# log and message
|
387
|
+
process_log(task.make_task_process_record.merge(transition: "schedule"))
|
388
|
+
user_message(">>> %s".color(:yellow) % task.digest, 3, "", :blue)
|
389
|
+
else
|
390
|
+
# cancel the task
|
391
|
+
Log::Debug.rule_engine "task %s canceled at %s" % [task.digest, digest]
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
# wait an end of distributed tasks
|
396
|
+
wait_task_completion(tasks)
|
397
|
+
|
398
|
+
# turn foreground if the task is background
|
399
|
+
unless read!(TupleSpace::ForegroundTuple.new(domain_id, digest))
|
400
|
+
write(TupleSpace::ForegroundTuple.new(domain_id, digest))
|
401
|
+
end
|
402
|
+
|
403
|
+
# log and message
|
404
|
+
process_log(make_rule_process_record.merge(transition: "resume"))
|
405
|
+
process_log(make_task_process_record.merge(transition: "resume"))
|
406
|
+
user_message_end("Distribution: %s" % digest, 2)
|
407
|
+
end
|
408
|
+
|
409
|
+
# Return true if we need to publish the task.
|
410
|
+
def need_to_publish_task?(task, tuple)
|
411
|
+
# reuse task finished result if order is weak update
|
412
|
+
if task.order == :weak
|
413
|
+
if read!(TupleSpace::FinishedTuple.new(domain: task.domain_id, status: :succeeded))
|
414
|
+
return false
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
# the task exists in space already, so we don't need to publish
|
419
|
+
return false if read!(tuple)
|
420
|
+
|
421
|
+
# another worker is working now, so we don't need to publish
|
422
|
+
return false if read!(TupleSpace::WorkingTuple.new(domain: task.domain_id))
|
423
|
+
|
424
|
+
# we need to publish the task
|
425
|
+
return true
|
426
|
+
end
|
427
|
+
|
428
|
+
# Wait until tasks completed.
|
429
|
+
def wait_task_completion(tasks)
|
430
|
+
tasks.each do |task|
|
431
|
+
# wait to finish the work
|
432
|
+
finished = read(TupleSpace::FinishedTuple.new(domain: task.domain_id))
|
433
|
+
|
434
|
+
### task completion processing ###
|
435
|
+
# copy write operation data tuple from the task domain to this domain
|
436
|
+
import_outputs_of_task(task, finished)
|
437
|
+
|
438
|
+
# touch tuple
|
439
|
+
lift_touch_tuple(task)
|
440
|
+
|
441
|
+
# publish output tickets
|
442
|
+
task.rule.output_tickets.pieces.each do |piece|
|
443
|
+
write(TupleSpace::TicketTuple.new(domain_id, piece.name))
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
# Import finished tuple's outputs from the domain.
|
449
|
+
def import_outputs_of_task(task, finished)
|
450
|
+
finished.outputs.each_with_index do |output, i|
|
451
|
+
data_expr = task.rule_condition.outputs[i].eval(task.env)
|
452
|
+
case data_expr.operation
|
453
|
+
when :write
|
454
|
+
if output.kind_of?(Array)
|
455
|
+
output.each {|o| copy_data_into_domain(o, domain_id)}
|
456
|
+
else
|
457
|
+
copy_data_into_domain(output, domain_id)
|
458
|
+
end
|
459
|
+
when :remove
|
460
|
+
if output.kind_of?(Array)
|
461
|
+
output.each {|o| remove_data_from_domain(o, domain_id)}
|
462
|
+
else
|
463
|
+
remove_data_from_domain(output, domain_id)
|
464
|
+
end
|
465
|
+
when :touch
|
466
|
+
if output.kind_of?(Array)
|
467
|
+
output.each {|o| touch_data_in_domain(o, domain_id)}
|
468
|
+
else
|
469
|
+
touch_data_in_domain(output, domain_id)
|
470
|
+
end
|
471
|
+
end
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
# Lift effects of touch operations from the task domain to this domain.
|
476
|
+
def lift_touch_tuple(task)
|
477
|
+
read_all(TupleSpace::TouchTuple.new(domain: task.domain_id)).each do |touch|
|
478
|
+
if target = read!(TupleSpace::DataTuple.new(name: touch.name, domain: domain_id))
|
479
|
+
# update time of data tuple
|
480
|
+
write(target.tap {|x| x.time = touch.time}) unless target.time > touch.time
|
481
|
+
|
482
|
+
# lift touch tuple to upper domain
|
483
|
+
write(touch.tap{|x| x.domain = domain_id})
|
484
|
+
end
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|