appswarm 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +124 -0
- data/History.txt +7 -0
- data/Manifest.txt +304 -0
- data/README.txt +373 -0
- data/Rakefile +153 -0
- data/TODO +7 -0
- data/apps/README.txt +17 -0
- data/apps/admin/admin.rb +79 -0
- data/apps/admin/controllers/admin.rb +81 -0
- data/apps/admin/controllers/settings.rb +63 -0
- data/apps/admin/controllers/users.rb +3 -0
- data/apps/admin/features/access.feature +21 -0
- data/apps/admin/features/mountLocal.feature +12 -0
- data/apps/admin/features/settings.feature +68 -0
- data/apps/admin/features/startApps.feature +27 -0
- data/apps/admin/layouts/main.rhtml +10 -0
- data/apps/admin/lib/settings.rb +52 -0
- data/apps/admin/static/admin.css +23 -0
- data/apps/admin/views/_log.rhtml +21 -0
- data/apps/admin/views/index.rhtml +43 -0
- data/apps/admin/views/info.rhtml +7 -0
- data/apps/admin/views/settings.rhtml +9 -0
- data/apps/admin/views/settings/_http_app.rhtml +15 -0
- data/apps/admin/views/settings/_web_server.rhtml +32 -0
- data/apps/admin/views/settings/index.rhtml +3 -0
- data/apps/admin/views/users/index.rhtml +6 -0
- data/apps/application_provider/application_provider.rb +11 -0
- data/apps/blog/blog.rb +27 -0
- data/apps/blog/controllers/blog.rb +29 -0
- data/apps/blog/views/index.rhtml +27 -0
- data/apps/browser_starter/browser_starter.rb +32 -0
- data/apps/crypto/crypto.rb +47 -0
- data/apps/crypto/crypto_rsa.rb +102 -0
- data/apps/crypto/spec/crypto_spec.rb +10 -0
- data/apps/directory_service/directory_service.rb +107 -0
- data/apps/directory_service/net_application.rb +92 -0
- data/apps/directory_service/spec/directory_service_spec.rb +36 -0
- data/apps/directory_service/spec/net_application_spec.rb +3 -0
- data/apps/global_application_interface/global_application.rb +52 -0
- data/apps/global_application_interface/global_application_interface.rb +84 -0
- data/apps/global_application_interface/spec/app_api_spec.rb +5 -0
- data/apps/global_tuple_space/global_tuple_space.rb +27 -0
- data/apps/global_web_proxy/features/session_handling.feature +7 -0
- data/apps/global_web_proxy/global_web_proxy.rb +221 -0
- data/apps/global_web_proxy/proxy/HTTPProxyServer-Dateien/rdoc-style.css +208 -0
- data/apps/global_web_proxy/proxy/HTTPProxyServer.html +566 -0
- data/apps/global_web_proxy/proxy/dnstest.rb +30 -0
- data/apps/global_web_proxy/proxy/proxy.rb +86 -0
- data/apps/global_web_proxy/proxy/wiki.html +267 -0
- data/apps/global_web_proxy/proxy/wiki.rb +115 -0
- data/apps/global_web_proxy/spec/res1 +112 -0
- data/apps/global_web_proxy/spec/res2 +125 -0
- data/apps/global_web_proxy/spec/web_proxy_spec.rb +88 -0
- data/apps/global_web_server/global_web_server.rb +120 -0
- data/apps/global_web_server/global_web_servlet.rb +6 -0
- data/apps/hello_world/controllers/hello_world.rb +11 -0
- data/apps/hello_world/features/show_on_local_web_server.feature +44 -0
- data/apps/hello_world/features/starting_apps.feature +6 -0
- data/apps/hello_world/features/through_global.feature +12 -0
- data/apps/hello_world/hello_world.rb +3 -0
- data/apps/hello_world/views/get.rhtml +10 -0
- data/apps/hello_world/views/index.rhtml +9 -0
- data/apps/hello_world/views/post.rhtml +10 -0
- data/apps/home/controllers/home.rb +11 -0
- data/apps/home/home.rb +12 -0
- data/apps/home/layouts/main.rhtml +16 -0
- data/apps/home/static/Zeichnung.svg +240 -0
- data/apps/home/static/home.css +134 -0
- data/apps/home/static/menu.css +99 -0
- data/apps/home/views/_appInfo.rhtml +22 -0
- data/apps/home/views/_dummy_fill.rhtml +3 -0
- data/apps/home/views/_info.rhtml +6 -0
- data/apps/home/views/_menu.rhtml +17 -0
- data/apps/home/views/index.rhtml +4 -0
- data/apps/home/views/overview.rhtml +2 -0
- data/apps/local_chunk_store/chunk_store.rb +15 -0
- data/apps/local_chunk_store/local_chunk_store.rb +123 -0
- data/apps/local_chunk_store/spec/local_chunk_store_spec.rb +30 -0
- data/apps/local_file_store/app_configuration.rb +78 -0
- data/apps/local_file_store/app_file_store.rb +32 -0
- data/apps/local_file_store/cached_file_store.rb +94 -0
- data/apps/local_file_store/features/testbed_handling_of_directories.feature +20 -0
- data/apps/local_file_store/local_file_store.rb +47 -0
- data/apps/local_file_store/spec/app_configuration_spec.rb +30 -0
- data/apps/local_file_store/spec/local_file_store_spec.rb +54 -0
- data/apps/local_object_storage/lib/cell.rb +29 -0
- data/apps/local_object_storage/lib/cellmgr.rb +57 -0
- data/apps/local_object_storage/lib/index.rb +43 -0
- data/apps/local_object_storage/lib/marshal.rb +96 -0
- data/apps/local_object_storage/lib/pagefile.rb +6 -0
- data/apps/local_object_storage/lib/persistent_object.rb +126 -0
- data/apps/local_object_storage/local_object_storage.rb +148 -0
- data/apps/local_object_storage/spec/local_object_storage_spec.rb +123 -0
- data/apps/local_secure_file_store/local_secure_file_store.rb +64 -0
- data/apps/local_secure_file_store/spec/local_secure_file_store_spec.rb +23 -0
- data/apps/local_tuple_space/local_tuple_space.rb +92 -0
- data/apps/local_tuple_space/spec/tuple_space_spec.rb +25 -0
- data/apps/local_web_server/features/parsing_args.feature +18 -0
- data/apps/local_web_server/local_web_server.rb +166 -0
- data/apps/logger/logger.rb +27 -0
- data/apps/master/master.rb +46 -0
- data/apps/master/spec/master_spec.rb +31 -0
- data/apps/my_spec_spec.rb +15 -0
- data/apps/name_service/name_service.rb +75 -0
- data/apps/name_service/spec/name_service_spec.rb +51 -0
- data/apps/network_discovery/network_discovery.rb +45 -0
- data/apps/network_discovery_localstore/network_discovery_localstore.rb +20 -0
- data/apps/network_discovery_udp/network_discovery_udp.rb +51 -0
- data/apps/network_lookup/network_lookup.rb +61 -0
- data/apps/network_node/abstract_node.rb +104 -0
- data/apps/network_node/drb_node.rb +90 -0
- data/apps/network_node/network_app.rb +9 -0
- data/apps/network_node/network_node.rb +471 -0
- data/apps/network_node/remote_service.rb +45 -0
- data/apps/network_node/secure_node.rb +125 -0
- data/apps/network_node/spec/drb_spec.rb +41 -0
- data/apps/network_node/spec/network_node_spec_not.rb +264 -0
- data/apps/new_network_node/new_network_node.rb +427 -0
- data/apps/new_network_node/spec/new_network_node_spec.rb +186 -0
- data/apps/node_broadcast/node_broadcast.rb +167 -0
- data/apps/node_broadcast/spec/node_broadcast_spec.rb +59 -0
- data/apps/permaspace/permaspace.rb +47 -0
- data/apps/plaindb/lib/btree.rb +38 -0
- data/apps/plaindb/plaindb.rb +199 -0
- data/apps/plaindb/spec/table_write_spec.rb +36 -0
- data/apps/routed_network/routed_network.rb +23 -0
- data/apps/routed_network/spec/routed_network_spec.rb +17 -0
- data/apps/session_manager/session_manager.rb +18 -0
- data/apps/spec_output.html +222 -0
- data/apps/todo/controllers/todo.rb +87 -0
- data/apps/todo/model/comment.rb +10 -0
- data/apps/todo/model/project.rb +20 -0
- data/apps/todo/model/todo.rb +16 -0
- data/apps/todo/model/user.rb +5 -0
- data/apps/todo/todo.rb +21 -0
- data/apps/todo/views/_commentList.rhtml +7 -0
- data/apps/todo/views/_createProject.rhtml +5 -0
- data/apps/todo/views/_partList.rhtml +12 -0
- data/apps/todo/views/_projectList.rhtml +16 -0
- data/apps/todo/views/edit.rhtml +11 -0
- data/apps/todo/views/editPart.rhtml +10 -0
- data/apps/todo/views/index.rhtml +2 -0
- data/apps/todo/views/question.rhtml +4 -0
- data/apps/transparent_network/transparent_network.rb +7 -0
- data/apps/udp_network/big_transfer.rb +97 -0
- data/apps/udp_network/features/information.feature +7 -0
- data/apps/udp_network/message_queue.rb +84 -0
- data/apps/udp_network/network_interface_api.rb +39 -0
- data/apps/udp_network/qos_queue.rb +186 -0
- data/apps/udp_network/simple_api.rb +180 -0
- data/apps/udp_network/spec/big_transfer_spec.rb +0 -0
- data/apps/udp_network/spec/qos_queue_spec.rb +99 -0
- data/apps/udp_network/spec/simple_api_spec.rb +35 -0
- data/apps/udp_network/spec/udp_network_spec.rb +115 -0
- data/apps/udp_network/spec/udp_transceiver_spec.rb +90 -0
- data/apps/udp_network/udp_network.rb +196 -0
- data/apps/udp_network/udp_transceiver.rb +329 -0
- data/apps/wiki/controllers/wiki.rb +56 -0
- data/apps/wiki/features/editing.feature +21 -0
- data/apps/wiki/layouts/main.rhtml +18 -0
- data/apps/wiki/lib/media_wiki_html.rb +35 -0
- data/apps/wiki/lib/wikicreole.rb +2147 -0
- data/apps/wiki/lib/wikicreole.tt +135 -0
- data/apps/wiki/lib/wikitest.rb +158 -0
- data/apps/wiki/lib/wikitest.tt +17 -0
- data/apps/wiki/model/menu.rb +15 -0
- data/apps/wiki/model/page.rb +31 -0
- data/apps/wiki/spec/wiki_creole_spec.rb +20 -0
- data/apps/wiki/spec/wiki_spec.rb +19 -0
- data/apps/wiki/static/Zeichnung.svg +240 -0
- data/apps/wiki/static/home.css +134 -0
- data/apps/wiki/static/mainMenu.css +32 -0
- data/apps/wiki/static/menu.css +99 -0
- data/apps/wiki/views/_mainMenu.rhtml +3 -0
- data/apps/wiki/views/_menu.rhtml +13 -0
- data/apps/wiki/views/edit.rhtml +13 -0
- data/apps/wiki/views/index.rhtml +2 -0
- data/apps/wiki/views/save.rhtml +1 -0
- data/apps/wiki/wiki.rb +17 -0
- data/bin/appswarm +47 -0
- data/cucumber.yml +2 -0
- data/data/PermaspaceApp/AFS_WikiApp_wiki_config +6 -0
- data/data/draft.txt +63 -0
- data/docs/appswarm_motivation.graffle +0 -0
- data/docs/appswarm_pics.graffle/QuickLook/Preview.pdf +0 -0
- data/docs/appswarm_pics.graffle/QuickLook/Thumbnail.tiff +0 -0
- data/docs/appswarm_pics.graffle/data.plist +63494 -0
- data/docs/appswarm_pics.graffle/image1.tiff +0 -0
- data/docs/appswarm_pics.graffle/image2.tif +0 -0
- data/docs/appswarm_pics.graffle/image3.tif +0 -0
- data/docs/appswarm_pics.graffle/image4.tif +0 -0
- data/docs/appswarm_pics.graffle/image5.tiff +0 -0
- data/docs/routing.graffle +0 -0
- data/features/step_definitions/appstart_steps.rb +28 -0
- data/features/step_definitions/cluster_steps.rb +18 -0
- data/features/step_definitions/testbed_steps.rb +64 -0
- data/features/step_definitions/webapp_steps.rb +257 -0
- data/features/support/env.rb +7 -0
- data/lib/appswarm.rb +127 -0
- data/lib/appswarm/README.txt +67 -0
- data/lib/appswarm/app_config.rb +19 -0
- data/lib/appswarm/application.rb +267 -0
- data/lib/appswarm/breaking_mutex.rb +41 -0
- data/lib/appswarm/cluster_funcs.rb +157 -0
- data/lib/appswarm/cross_spectool.rb +153 -0
- data/lib/appswarm/crypt.rb +10 -0
- data/lib/appswarm/crypt/crypto.rb +90 -0
- data/lib/appswarm/crypt/rsa_key +15 -0
- data/lib/appswarm/crypt/rsa_key.pub +5 -0
- data/lib/appswarm/crypt/test.rb +27 -0
- data/lib/appswarm/dir_tool.rb +41 -0
- data/lib/appswarm/event_api.rb +7 -0
- data/lib/appswarm/features_helper.rb +44 -0
- data/lib/appswarm/global_service.rb +38 -0
- data/lib/appswarm/http.rb +1 -0
- data/lib/appswarm/http/http_app.rb +257 -0
- data/lib/appswarm/http/http_controller.rb +267 -0
- data/lib/appswarm/http/http_provider.rb +80 -0
- data/lib/appswarm/http/static/favicon.ico +0 -0
- data/lib/appswarm/http/static/javascript/._prototype.js +0 -0
- data/lib/appswarm/http/static/javascript/prototype.js +2515 -0
- data/lib/appswarm/http/webrick_logger.rb +12 -0
- data/lib/appswarm/net_service.rb +69 -0
- data/lib/appswarm/package.rb +88 -0
- data/lib/appswarm/parallel_each.rb +46 -0
- data/lib/appswarm/protocols/protocol_dice.rb +25 -0
- data/lib/appswarm/proxy_testing.rb +48 -0
- data/lib/appswarm/public_api.rb +35 -0
- data/lib/appswarm/routing/matrix_math.rb +57 -0
- data/lib/appswarm/routing/pca.rb +211 -0
- data/lib/appswarm/routing/routetest.rb +85 -0
- data/lib/appswarm/routing/routing.rb +326 -0
- data/lib/appswarm/routing/spec/nods_spec.rb +23 -0
- data/lib/appswarm/routing/spec/pca_spec.rb +27 -0
- data/lib/appswarm/routing/spec/routing_spec.rb +91 -0
- data/lib/appswarm/secure_con.rb +437 -0
- data/lib/appswarm/secure_connection.rb +79 -0
- data/lib/appswarm/secure_marshal.rb +137 -0
- data/lib/appswarm/service.rb +76 -0
- data/lib/appswarm/simple_marshal.rb +96 -0
- data/lib/appswarm/simple_marshal_parser.rb +1243 -0
- data/lib/appswarm/simple_marshal_parser.tt +158 -0
- data/lib/appswarm/spec/application_spec.rb +50 -0
- data/lib/appswarm/spec/cluster_spec.rb +2 -0
- data/lib/appswarm/spec/hexdist_spec.rb +13 -0
- data/lib/appswarm/spec/http_controller_spec.rb +18 -0
- data/lib/appswarm/spec/main_spec.rb +6 -0
- data/lib/appswarm/spec/parallel_each_spec.rb +30 -0
- data/lib/appswarm/spec/secure_connection_spec.rb +108 -0
- data/lib/appswarm/spec/secure_marshal_spec.rb +93 -0
- data/lib/appswarm/spec/simple_marshal_spec.rb +87 -0
- data/lib/appswarm/spec/tools_spec.rb +13 -0
- data/lib/appswarm/spec/whiteboard_spec.rb +20 -0
- data/lib/appswarm/spec_helper.rb +18 -0
- data/lib/appswarm/test_bed.rb +207 -0
- data/lib/appswarm/tools.rb +284 -0
- data/lib/appswarm/tools/http_tunnel_client.rb +139 -0
- data/lib/appswarm/tools/http_tunnel_common.rb +8 -0
- data/lib/appswarm/tools/http_tunnel_server.rb +78 -0
- data/lib/appswarm/tools/parser/example_data.simple +102 -0
- data/lib/appswarm/tools/parser/match_test.rb +14 -0
- data/lib/appswarm/tools/parser/parser_lib.rb +165 -0
- data/lib/appswarm/tools/parser/parser_test.rb +104 -0
- data/lib/appswarm/tools/parser/spec/parser_spec.rb +44 -0
- data/lib/appswarm/tools/pipes.rb +95 -0
- data/lib/appswarm/tools/spec/tracing_spec.rb +16 -0
- data/lib/appswarm/tools/spec/waiting_queue_spec.rb +15 -0
- data/lib/appswarm/tools/thread_tool.rb +61 -0
- data/lib/appswarm/tools/tracing.rb +84 -0
- data/lib/appswarm/tools/treetop_test.rb +20 -0
- data/lib/appswarm/tools/treetop_test_grammar.rb +114 -0
- data/lib/appswarm/tools/treetop_test_grammar.tt +7 -0
- data/lib/appswarm/tools/waiting_prio_queue.rb +47 -0
- data/lib/appswarm/tools/waiting_queue.rb +34 -0
- data/lib/appswarm/whiteboard.rb +73 -0
- data/nettest.rb +50 -0
- data/packages/README.txt +1 -0
- data/packages/msandbox/data/packages/store/my.txt +1 -0
- data/packages/msandbox/interfaces.rb +172 -0
- data/packages/msandbox/old/defa.rb +3 -0
- data/packages/msandbox/old/test.rb +14 -0
- data/packages/msandbox/old/test2.rb +56 -0
- data/packages/msandbox/package.rb +67 -0
- data/packages/msandbox/packages/store/config.yml +1 -0
- data/packages/msandbox/packages/store/main.rb +27 -0
- data/packages/msandbox/packages/store/myinclude.rb +7 -0
- data/packages/msandbox/packages/store_test/config.yml +1 -0
- data/packages/msandbox/packages/store_test/main.rb +9 -0
- data/packages/msandbox/server.rb +146 -0
- data/packages/msandbox/test.rb +13 -0
- data/packages/msandbox/test2.rb +29 -0
- data/templates/web/appswarm/controllers/appswarm.rb +41 -0
- data/templates/web/appswarm/layouts/main.rhtml +20 -0
- data/templates/web/appswarm/models/asmenu.rb +14 -0
- data/templates/web/appswarm/models/asuser.rb +30 -0
- data/templates/web/appswarm/static/custom.css +15 -0
- data/templates/web/appswarm/static/home.css +134 -0
- data/templates/web/appswarm/static/mainMenu.css +32 -0
- data/templates/web/appswarm/static/menu.css +99 -0
- data/templates/web/appswarm/views/_mainMenu.rhtml +5 -0
- data/templates/web/appswarm/views/_menu.rhtml +13 -0
- data/templates/web/appswarm/views/_userInfo.rhtml +7 -0
- data/templates/web/appswarm/views/login.rhtml +9 -0
- data/tools/checkPort.rb +11 -0
- metadata +379 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
== Gettin started
|
|
2
|
+
First run
|
|
3
|
+
> rake rdoc
|
|
4
|
+
and get reading
|
|
5
|
+
|
|
6
|
+
== What this project is
|
|
7
|
+
* it's a proof-of-concept for a framework for distributed applications
|
|
8
|
+
|
|
9
|
+
== What is will/can be
|
|
10
|
+
|
|
11
|
+
Possible Applications:
|
|
12
|
+
* Wiki (that cannot be shut down)
|
|
13
|
+
* XSLT
|
|
14
|
+
* DB-Server
|
|
15
|
+
* Searchengine
|
|
16
|
+
* DNS
|
|
17
|
+
* Forum
|
|
18
|
+
* computation credits
|
|
19
|
+
* different network-systems (Network gateways: make gnutella available where it can't be reached, e.g. a firewall )
|
|
20
|
+
* appsharer
|
|
21
|
+
* temp-space
|
|
22
|
+
* perma-space
|
|
23
|
+
|
|
24
|
+
"bittorrent" for applications
|
|
25
|
+
* the faster your pc - the faster your internet
|
|
26
|
+
|
|
27
|
+
== How Appswarm works
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
== Running the main app
|
|
31
|
+
> ruby main.rb
|
|
32
|
+
Will start a single appswarm-node with all applications within app/*
|
|
33
|
+
You'll find a simple admin-interface on http://localhost:2000/admin and a *very simplified* blog on http://localhost:2000/blog
|
|
34
|
+
|
|
35
|
+
== Running a small swarm
|
|
36
|
+
>ruby nettest.rb --count 4
|
|
37
|
+
This will start a small swarm of nodes on your localhost. You can access them via http on ports 2000 to 2003.
|
|
38
|
+
|
|
39
|
+
== Running specs
|
|
40
|
+
>rake spec
|
|
41
|
+
Runs all the specs defined.
|
|
42
|
+
|
|
43
|
+
>rake spec:network_node
|
|
44
|
+
Searches for **/spec_network_node.rb and runs it, if it exists
|
|
45
|
+
|
|
46
|
+
>rake "spec:network_node:should process routes correctly"
|
|
47
|
+
Will run this example only.
|
|
48
|
+
|
|
49
|
+
== Plain Overview of current state
|
|
50
|
+
Directories:
|
|
51
|
+
* apps - hold all the applications currently installed
|
|
52
|
+
* data - holds the data of the applications
|
|
53
|
+
* lib - basic classes and functions to be used within applications
|
|
54
|
+
|
|
55
|
+
== Where appswarm should go
|
|
56
|
+
|
|
57
|
+
=== Data
|
|
58
|
+
there are several forms of data:
|
|
59
|
+
* 1) data that's used frequently and needed all over the net for basic functionality
|
|
60
|
+
* 2) app-dependent data, that's used strongly by single applications
|
|
61
|
+
* 3) data that's used infrequently and may be very large (mp3,movies, etc)
|
|
62
|
+
|
|
63
|
+
Then there are different levels of high-availability needed for this data
|
|
64
|
+
|
|
65
|
+
For these different kinds of data, we need different data-stores:
|
|
66
|
+
* 1) these should be spread as wide as possible over the net, maybe in a built-in directory-service.
|
|
67
|
+
* 2) may be stored in distributed databases (or tuplespaces)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class AppConfig
|
|
2
|
+
def initialize()
|
|
3
|
+
@values={}
|
|
4
|
+
file=File.open("config.properties","r")
|
|
5
|
+
file.each_line{|line|
|
|
6
|
+
line.gsub!(/#.*/,"")
|
|
7
|
+
k,v=line.split("=")
|
|
8
|
+
if k and v
|
|
9
|
+
@values[k]=v
|
|
10
|
+
end
|
|
11
|
+
}
|
|
12
|
+
file.close
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def [](name)
|
|
16
|
+
@values[name]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
require 'drb/drb'
|
|
2
|
+
require 'public_api.rb'
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# application.rb contains the definition of Application
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Application is the basic class for all applications and services within appswarm.
|
|
9
|
+
class Application
|
|
10
|
+
include DRbUndumped
|
|
11
|
+
publicAPI
|
|
12
|
+
|
|
13
|
+
attr_reader :cluster
|
|
14
|
+
attr_accessor :running
|
|
15
|
+
def initialize(cluster,options)
|
|
16
|
+
@running=false
|
|
17
|
+
@threads=[]
|
|
18
|
+
@cluster=cluster
|
|
19
|
+
@options=options
|
|
20
|
+
@provides={}
|
|
21
|
+
@appName=shortName.downcase
|
|
22
|
+
|
|
23
|
+
@appId=@options[:appId]
|
|
24
|
+
@appId||=createAppId
|
|
25
|
+
if @options[:appName]
|
|
26
|
+
@appName=@options[:appName]
|
|
27
|
+
elsif @options[@appName]
|
|
28
|
+
@appName=@options[@appName]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@quit=false
|
|
33
|
+
@quitMutex=Mutex.new
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def quit?
|
|
37
|
+
@quit
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def quit
|
|
41
|
+
@quitMutex.synchronize {
|
|
42
|
+
@quit=true
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def provides?(xy)
|
|
47
|
+
return true if self.class.providing.member?(xy)
|
|
48
|
+
|
|
49
|
+
@provides[xy]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def getService(name)
|
|
53
|
+
@cluster.getApp(name)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def startup
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def run
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def config
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def quit
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def stop
|
|
73
|
+
@threads.each{|thread|thread.kill}
|
|
74
|
+
@threads.each{|thread|
|
|
75
|
+
log "KILL THREAD #{thread}"
|
|
76
|
+
thread.kill!
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
@threads=[]
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# get a shorter name for the current application.
|
|
83
|
+
#
|
|
84
|
+
def shortName
|
|
85
|
+
self.class.to_s.gsub(/App$/,"")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# instanceName
|
|
89
|
+
def getAppName
|
|
90
|
+
@appName
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def getAppId
|
|
94
|
+
@appId
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def info
|
|
98
|
+
{}
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def appswarmBaseDir
|
|
102
|
+
cluster.appswarmBaseDir
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def getAppDataWritePath
|
|
106
|
+
path=File.join(appswarmBaseDir,getAppName)
|
|
107
|
+
Dir.mkdir_save(path)
|
|
108
|
+
path
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def getAppDataPaths
|
|
112
|
+
[getAppDataWritePath,getAppDataPath].flatten
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def getAppDataPath
|
|
116
|
+
dir=File.expand_path("../../data/#{self.class.to_s}",__FILE__)
|
|
117
|
+
|
|
118
|
+
unless File.exist?(dir)
|
|
119
|
+
return []
|
|
120
|
+
end
|
|
121
|
+
dir
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def withApp(name,&block)
|
|
125
|
+
app=@cluster.getApp(name)
|
|
126
|
+
if app
|
|
127
|
+
app.instance_eval{block.call}
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
def withAppFork(name,&block)
|
|
131
|
+
@threads << Thread.new(name){|name|
|
|
132
|
+
loop do
|
|
133
|
+
a=@cluster.getApp(name)
|
|
134
|
+
if a
|
|
135
|
+
puts name,a
|
|
136
|
+
#exit
|
|
137
|
+
a.instance_eval(&block)
|
|
138
|
+
break
|
|
139
|
+
end
|
|
140
|
+
sleep 5
|
|
141
|
+
end
|
|
142
|
+
}
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def getAppDir
|
|
147
|
+
Application.getAppDir(self.class.to_s)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# gets the (absolute) application-directory for the given class(-name)
|
|
151
|
+
def self.getAppDir(name)
|
|
152
|
+
File.expand_path("../../../apps/#{name.to_s.gsub(/App$/,'').dirName}",__FILE__)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def warning(*x)
|
|
156
|
+
log "WARNING",*x
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# logs any objects to the logger-app or if such does not exist to the console
|
|
160
|
+
def log(*s)
|
|
161
|
+
logger=getApp(:logger)
|
|
162
|
+
if logger
|
|
163
|
+
# puts "[#{Time.new}][#{self}][#{place}] "+s.map{|v|v.to_s}.join(" ")
|
|
164
|
+
logger.log(self.class,getAppName,*s) if logger
|
|
165
|
+
else
|
|
166
|
+
place=caller[0]
|
|
167
|
+
if cluster
|
|
168
|
+
cluster.log_direct(place,nil,s.to_s)
|
|
169
|
+
else
|
|
170
|
+
pp s
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def getApp(*s)
|
|
176
|
+
return cluster.getApp(*s) if cluster
|
|
177
|
+
nil
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def monitor(&b)
|
|
181
|
+
log "start monitor"
|
|
182
|
+
begin
|
|
183
|
+
b.call
|
|
184
|
+
rescue Object=>e
|
|
185
|
+
log "Monitor error #{e}"
|
|
186
|
+
log e.to_s+"\n"+e.backtrace.join("\n")
|
|
187
|
+
#rescue Error=>e
|
|
188
|
+
# log e.toString+"\n"+e.backtrace.join("\n")
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def retrieveConfig
|
|
193
|
+
app=nil
|
|
194
|
+
trials=0
|
|
195
|
+
loop do
|
|
196
|
+
app=getApp(:localFileStore)
|
|
197
|
+
if app.nil?
|
|
198
|
+
cluster.run("LocalFileStore")
|
|
199
|
+
else
|
|
200
|
+
break
|
|
201
|
+
end
|
|
202
|
+
trials+=1
|
|
203
|
+
log "First trial failed to get LocalFileStore"
|
|
204
|
+
if trials>2
|
|
205
|
+
puts "ERROR: NO LocalFileStore found!"
|
|
206
|
+
log "ERROR: NO LocalFileStore found!"
|
|
207
|
+
return nil
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
app.config(self)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def providingAPIs
|
|
214
|
+
@provides.keys
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def self.requires(*x)
|
|
218
|
+
@@requires||={}
|
|
219
|
+
@@requires[self]||=[]
|
|
220
|
+
@@requires[self]<<x
|
|
221
|
+
end
|
|
222
|
+
def self.requirements
|
|
223
|
+
@@requires||={}
|
|
224
|
+
rs=ancestors.map{|a|@@requires[a]}.flatten.select{|x|x}
|
|
225
|
+
|
|
226
|
+
#pp "RS",rs
|
|
227
|
+
return rs
|
|
228
|
+
a=ancestors[1]
|
|
229
|
+
if a.ancestors.member?(Application)
|
|
230
|
+
p=a.requirements
|
|
231
|
+
else
|
|
232
|
+
p=[]
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
((@@requires[self]||[])+p).flatten
|
|
236
|
+
end
|
|
237
|
+
def self.providing
|
|
238
|
+
@@providings[self]||[]
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def self.provides(*x)
|
|
242
|
+
@@providings||={}
|
|
243
|
+
@@providings[self]||=[]
|
|
244
|
+
@@providings[self]+=x
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def self.protect(funcName)
|
|
248
|
+
newName="_"+funcName.to_s
|
|
249
|
+
self.send(:alias_method,newName,funcName)
|
|
250
|
+
self.send(:define_method,funcName){|*args|
|
|
251
|
+
@quitMutex.synchronize {
|
|
252
|
+
raise "#{self} has quit!" if quit?
|
|
253
|
+
self.send(newName,*args)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
protected
|
|
259
|
+
def provides(xy)
|
|
260
|
+
@provides[xy]=true
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
private
|
|
264
|
+
def createAppId
|
|
265
|
+
Crypt.digest(Time.now.to_s+rand.to_s).to_base64
|
|
266
|
+
end
|
|
267
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#BreakingMutex=Mutex
|
|
2
|
+
class BreakingMutex
|
|
3
|
+
GRANULARITY=20
|
|
4
|
+
TRIES=10
|
|
5
|
+
def initialize(timeout=2)
|
|
6
|
+
@timeout=timeout
|
|
7
|
+
#@mutex=Mutex.new
|
|
8
|
+
@mutex=false
|
|
9
|
+
end
|
|
10
|
+
def synchronize(&b)
|
|
11
|
+
done=false
|
|
12
|
+
start=Time.now
|
|
13
|
+
while not done and (Time.now-start)<@timeout
|
|
14
|
+
puts "enter critical"
|
|
15
|
+
Thread.critical=true
|
|
16
|
+
ok=false
|
|
17
|
+
if @mutex==false
|
|
18
|
+
@mutex=true
|
|
19
|
+
ok=true
|
|
20
|
+
end
|
|
21
|
+
puts "leaving critical"
|
|
22
|
+
Thread.critical=false
|
|
23
|
+
if ok==true
|
|
24
|
+
puts "running"
|
|
25
|
+
b.call
|
|
26
|
+
done=true
|
|
27
|
+
end
|
|
28
|
+
if ok==true
|
|
29
|
+
puts "enter critical"
|
|
30
|
+
Thread.critical=true
|
|
31
|
+
@mutex=false
|
|
32
|
+
Thread.critical=false
|
|
33
|
+
puts "leaving critical"
|
|
34
|
+
end
|
|
35
|
+
time=(@timeout/TRIES.to_f)*rand(GRANULARITY)/GRANULARITY.to_f
|
|
36
|
+
puts "SLEEP #{time}"
|
|
37
|
+
sleep time unless done
|
|
38
|
+
end
|
|
39
|
+
puts "DONE"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
module ClusterFuncs
|
|
2
|
+
|
|
3
|
+
def getNewInstanceName(klass)
|
|
4
|
+
@instanceId||=0
|
|
5
|
+
@instanceId+=1
|
|
6
|
+
klass.to_s+@instanceId.to_s
|
|
7
|
+
end
|
|
8
|
+
def checkRequirements(appClass)
|
|
9
|
+
reqs=appClass.requirements
|
|
10
|
+
reqs.each{|req|
|
|
11
|
+
if getApp(req).nil?
|
|
12
|
+
f=@appClasses.select{|klass|klass.providing.member?(req)}
|
|
13
|
+
if f.length==0
|
|
14
|
+
raise "PROBLEM: #{req} not found!"
|
|
15
|
+
else
|
|
16
|
+
debug "STARTING REQUIRED #{f[0]}"
|
|
17
|
+
run(f[0].to_s.gsub(/App$/,""))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def getLocalApplications
|
|
25
|
+
@apps
|
|
26
|
+
end
|
|
27
|
+
def getApps(type)
|
|
28
|
+
if type.is_a?(Class)
|
|
29
|
+
return @apps.select{|app|app.is_a?(type)}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if type.is_a?(String)
|
|
33
|
+
type+="App" unless type=~/App$/
|
|
34
|
+
return @apps.select{|app|app.class.to_s==type}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
@apps.select{|app|
|
|
38
|
+
app.provides?(type)
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def getApplicationTypes
|
|
43
|
+
@appClasses
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def getOrCreate(appName)
|
|
47
|
+
a=getApp(appName)
|
|
48
|
+
a=run(appName) unless a
|
|
49
|
+
a
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def allUpAndRunning
|
|
53
|
+
@apps.select{|a|a.running==false}.length==0
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def waitUntilAllUpAndRunning
|
|
57
|
+
while not allUpAndRunning
|
|
58
|
+
sleep 0.1
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def runAndWait(appName,*params)
|
|
63
|
+
app=run(appName,*params)
|
|
64
|
+
while app.running==false
|
|
65
|
+
sleep 0.1
|
|
66
|
+
log "WAIT for #{app} to startup"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def run(appName,*params)
|
|
71
|
+
return nil if @stopping
|
|
72
|
+
log "Starting #{appName}"
|
|
73
|
+
appClass=@appClasses.select{|appClass|
|
|
74
|
+
appName.to_s+"App"==appClass.to_s
|
|
75
|
+
}[0]
|
|
76
|
+
raise "Class #{appName} not Found" unless appClass
|
|
77
|
+
checkRequirements(appClass)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
log "NAME:",appName,params
|
|
81
|
+
a=nil
|
|
82
|
+
|
|
83
|
+
@stopMutex.synchronize {
|
|
84
|
+
return if @stopped
|
|
85
|
+
if params.is_a?(Array)
|
|
86
|
+
params=params[0]
|
|
87
|
+
end
|
|
88
|
+
if params.is_a?(Hash)
|
|
89
|
+
return if @apps.select{|app|app.getAppId==params[:appId]}.length>0
|
|
90
|
+
|
|
91
|
+
# FIXME: support multiple apps of same type running
|
|
92
|
+
return if @apps.select{|app|
|
|
93
|
+
app.class==appClass
|
|
94
|
+
}.length>0
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
#return if getAppById()
|
|
98
|
+
log "Running Testbed #{self}"
|
|
99
|
+
options=@options
|
|
100
|
+
if params
|
|
101
|
+
if params.length>0
|
|
102
|
+
if params[-1].is_a?(Hash)
|
|
103
|
+
options=params[-1]
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
a=appClass.new(self,options)
|
|
108
|
+
i=a.object_id
|
|
109
|
+
y=Thread.new(a) {|a|
|
|
110
|
+
Thread.current[:appName2]=appName
|
|
111
|
+
begin
|
|
112
|
+
@apps<<a
|
|
113
|
+
log "TRYING TO START #{a}"
|
|
114
|
+
|
|
115
|
+
a.startup
|
|
116
|
+
a.running=true
|
|
117
|
+
a.run
|
|
118
|
+
debug "FINISHED #{a}"
|
|
119
|
+
rescue Exception=>e
|
|
120
|
+
log e,e.backtrace
|
|
121
|
+
end
|
|
122
|
+
}
|
|
123
|
+
loop do
|
|
124
|
+
sleep 0.01
|
|
125
|
+
break if @apps.member?(a)
|
|
126
|
+
end
|
|
127
|
+
y[:appName]=appName
|
|
128
|
+
@tbedThreads||={}
|
|
129
|
+
@tbedThreads[i]=y
|
|
130
|
+
a
|
|
131
|
+
}
|
|
132
|
+
a
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def log_line(line)
|
|
136
|
+
puts line
|
|
137
|
+
end
|
|
138
|
+
def debug(*p)
|
|
139
|
+
log_direct(caller[0],nil,p.map{|x|x.to_s}.join(" "))
|
|
140
|
+
end
|
|
141
|
+
def log_direct(place,instance,what)
|
|
142
|
+
place.gsub!(/\/.*\//,'/..../')
|
|
143
|
+
i=""
|
|
144
|
+
i="[#{instance}]" if instance
|
|
145
|
+
|
|
146
|
+
t=Time.new.strftime("%Y-%m-%d %H:%M:%S")
|
|
147
|
+
what.split("\n").each{|line|
|
|
148
|
+
log_line "[#{t}][#{place}]#{i} "+line
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def createInstanceId
|
|
154
|
+
Crypt::hexdigest(rand.to_s+Time.new.to_s)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
end
|