1 |
joko |
1.1 |
## ------------------------------------------------------------------------- |
2 |
joko |
1.8 |
## $Id: Rap.pm,v 1.7 2003/05/13 05:52:58 joko Exp $ |
3 |
joko |
1.1 |
## ------------------------------------------------------------------------- |
4 |
joko |
1.2 |
## $Log: Rap.pm,v $ |
5 |
joko |
1.8 |
## Revision 1.7 2003/05/13 05:52:58 joko |
6 |
|
|
## minor update: modified description printing logic |
7 |
|
|
## |
8 |
joko |
1.7 |
## Revision 1.6 2003/03/29 07:08:56 joko |
9 |
|
|
## rap goes global: |
10 |
|
|
## + distinguish between running in global- or project-mode |
11 |
|
|
## + some comments in pod |
12 |
|
|
## |
13 |
joko |
1.6 |
## Revision 1.5 2003/03/28 16:52:41 jonen |
14 |
|
|
## now using env-var 'RAPBIN' |
15 |
|
|
## |
16 |
jonen |
1.5 |
## Revision 1.4 2003/03/27 15:31:01 joko |
17 |
|
|
## fixes to modules regarding new namespace(s) below Data::Mungle::* |
18 |
|
|
## |
19 |
joko |
1.4 |
## Revision 1.3 2003/02/20 18:44:26 joko |
20 |
|
|
## renamed modules |
21 |
|
|
## + sub find_rules: attempts to find 'rap.xml' |
22 |
|
|
## + updated documentation: added SYNOPSIS |
23 |
|
|
## |
24 |
joko |
1.3 |
## Revision 1.2 2003/02/18 16:02:04 joko |
25 |
|
|
## +- renamed module |
26 |
|
|
## |
27 |
joko |
1.2 |
## Revision 1.1 2003/02/18 15:34:26 joko |
28 |
|
|
## + initial commit |
29 |
|
|
## |
30 |
joko |
1.1 |
## ------------------------------------------------------------------------- |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
=pod |
34 |
|
|
|
35 |
|
|
=head1 Preface |
36 |
|
|
|
37 |
|
|
=head2 hmm..... |
38 |
|
|
|
39 |
|
|
A Command is a Request. |
40 |
|
|
A Task is a Process. |
41 |
|
|
A Request is a Command. |
42 |
|
|
A Process is a Task. |
43 |
|
|
There are just details. |
44 |
|
|
|
45 |
joko |
1.6 |
|
46 |
joko |
1.1 |
=head2 ahh... |
47 |
|
|
|
48 |
joko |
1.6 |
rap means 'Request And Process'. |
49 |
|
|
rap is contained in 'wrapped'. |
50 |
|
|
dot is the 'Database Of Targets', by default '/etc/rap.xml'. (rename to 'dot.xml'?) |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
CPAN already *has got* all required tools starting an attempt to do this. |
54 |
joko |
1.1 |
|
55 |
joko |
1.6 |
Will this work out? |
56 |
joko |
1.1 |
But still, Hmmm...... |
57 |
|
|
And: lots of work, i believe.... |
58 |
joko |
1.6 |
Let's start... |
59 |
joko |
1.1 |
|
60 |
|
|
Okay: |
61 |
joko |
1.4 |
Look at DesignPattern:: and Data::Mungle::Transform::Deep & Co. (lowlevel stuff) |
62 |
joko |
1.1 |
or OEF::, Data::Storage and Data::Transfer::Sync (highlevel stuff). |
63 |
|
|
|
64 |
|
|
And then: |
65 |
|
|
|
66 |
|
|
|
67 |
joko |
1.3 |
=head1 SYNOPSIS |
68 |
|
|
|
69 |
|
|
my $rap = Data::Rap->new( target => 'sync-core' ); |
70 |
|
|
$rap->start(); |
71 |
|
|
|
72 |
|
|
print Dumper($rap); |
73 |
|
|
|
74 |
|
|
print Dumper($rap->get_property('/')); |
75 |
|
|
|
76 |
|
|
print Dumper($rap->get_property('.')); |
77 |
|
|
print Dumper($rap->get_property('global')); |
78 |
|
|
print Dumper($rap->get_property('app')); |
79 |
|
|
print Dumper($rap->get_property('app.config')); |
80 |
|
|
print Dumper($rap->get_property('app.config.preboot')); |
81 |
|
|
print Dumper($rap->get_property('app.config.databases.oefcore')); |
82 |
|
|
|
83 |
|
|
|
84 |
joko |
1.1 |
=head1 Overview |
85 |
|
|
|
86 |
|
|
=head2 Rap - Request And Process |
87 |
|
|
|
88 |
joko |
1.6 |
=head3 Rap's Features |
89 |
|
|
- have targets (like make) declared in xml (like ant) |
90 |
|
|
- run these targets... |
91 |
|
|
- ... from a multitude of possible human interaction devices (HIDs), e.g. |
92 |
|
|
- cli (console mode) |
93 |
|
|
- gui |
94 |
|
|
- web |
95 |
|
|
- speech |
96 |
|
|
- scribe |
97 |
|
|
- ... from a different location (non-local - for remote administration purposes) |
98 |
|
|
- the remote wrapper is 'rapd' - the rap-daemon.... |
99 |
|
|
- rapd can run in command-mode (like apache, sendmail and related) |
100 |
|
|
and/or web-service mode (commands are wrapped into request-/response- |
101 |
|
|
xml-payload-communication) |
102 |
|
|
- rap is self contained on various levels |
103 |
|
|
- runtime-layer |
104 |
|
|
- pass arguments between targets |
105 |
|
|
- core targets are declared in xml (rap-lingo) as well |
106 |
|
|
these exist by now: (look at Data/Rap/targets/default.xml) |
107 |
|
|
- core.os.win32 |
108 |
|
|
- core.os.linux |
109 |
|
|
- core.rap.mode |
110 |
|
|
- core.rap.daemon |
111 |
|
|
- declaration-layer |
112 |
|
|
- the xml-file in rap-lingo can contain descriptions associated with each target |
113 |
|
|
- rap can make report on its guis about these |
114 |
|
|
- rap can use this declaration as an api for the rap-daemon 'rapd' |
115 |
|
|
- rap itself can run in "global"- or "project"-mode |
116 |
|
|
- FIXME: write something about this (by now: read the source, luke.....) |
117 |
|
|
|
118 |
|
|
|
119 |
|
|
=head3 Rap's Future |
120 |
|
|
- rapd |
121 |
|
|
- rapd can also run in apache mode for non-root purposes |
122 |
|
|
- many rapd's can talk to each other - first example application would be: |
123 |
|
|
- one rapd is running as apache-mod-perl-handler (non-root) |
124 |
|
|
- one rapd is running locally as root |
125 |
|
|
- remark: the way to go (by now) is via org.netfrag.glib's DataSource-libraries, |
126 |
|
|
which wrap the innards of rpc-communication via xml (XMLRPC) (lingo: php) |
127 |
|
|
an example application is caesar.rapweb and (maybe) caesar.ums |
128 |
joko |
1.1 |
|
129 |
|
|
=head3 Rap's aims are directed to get some of this together |
130 |
|
|
|
131 |
|
|
- some concepts of make (->targets) |
132 |
|
|
- some concepts of ant (->tasks) |
133 |
|
|
- some code written while developing a custom application with Perl: |
134 |
|
|
- libraries/modules (CPAN proposals) |
135 |
|
|
- Data::Storage::Container |
136 |
|
|
- Data::Storage |
137 |
|
|
- Data::Transfer::Sync |
138 |
|
|
- OEF::Component::Task |
139 |
|
|
- make "old" shortcut programs like "feed.pl", "tell.pl" and such obsolete |
140 |
|
|
- add more targets in order to make "setup.pl" & Co. obsolete as well |
141 |
joko |
1.3 |
- some new concepts (perly): |
142 |
|
|
- namespaces |
143 |
|
|
- plugins |
144 |
|
|
- contexts |
145 |
joko |
1.1 |
|
146 |
|
|
|
147 |
|
|
=head3 It's using these fine modules from CPAN |
148 |
|
|
|
149 |
|
|
- xml, xpath and such (XML::Parser, XML::XPath) |
150 |
|
|
- local os native (background) process execution (IPC::Run) |
151 |
|
|
- remote procedure calls with xml payloads: XMLRPC, SOAP and such (RPC::XML, SOAP::Lite) |
152 |
|
|
- configuration- and property-data inheritance: Hash::Merge |
153 |
|
|
|
154 |
|
|
- under the hood: |
155 |
|
|
- logging: Log::Dispatch |
156 |
|
|
- data-access: DBI & Co., Tangram |
157 |
|
|
- data-manipulation: Data::Dumper, Iterate |
158 |
|
|
- in other words: all modules already included in some declaration inside 'setup.pl' |
159 |
|
|
|
160 |
|
|
|
161 |
|
|
=head3 Rap does networking |
162 |
|
|
|
163 |
joko |
1.3 |
x It's a client. (cli program, standalone) |
164 |
|
|
(->Command-Frontends: rap.pl) |
165 |
|
|
o It's a server/daemon as well. (cli interacts with daemonized engine via tcp-socket) |
166 |
|
|
(->Command-Frontends: rap.pl --remote|--host=<hostname>) |
167 |
joko |
1.1 |
|
168 |
|
|
|
169 |
|
|
=head3 Rap is open for enhancements and/or integration into/with other stuff |
170 |
|
|
|
171 |
|
|
=head4 Command-Frontends (local and/or remote) |
172 |
|
|
|
173 |
joko |
1.3 |
x rap.pl |
174 |
joko |
1.1 |
o Commands can be sent via psh (The Perl Shell) or similar frontends (via rap.pl or Rap.pm) |
175 |
|
|
o Commands can be issued from a php-frontend (via RPC using Rap::) |
176 |
|
|
|
177 |
|
|
=head4 Target-Registry (local and/or remote) |
178 |
|
|
|
179 |
|
|
x Targets can be defined inside a rap.xml or similar |
180 |
|
|
o Targets can be stored in arbitrary data structures (e.g. read from an rdbms or ldap-storage) |
181 |
|
|
|
182 |
|
|
=head4 Task-Backends (local and/or remote) |
183 |
|
|
|
184 |
|
|
x Tasks can run as local native processes (attached and/or background) |
185 |
|
|
o Tasks can be triggered by issuing RPC-calls to arbitrary multiple hosts |
186 |
|
|
|
187 |
|
|
=head4 TODO |
188 |
|
|
o look at Maven's POM (Project Object Model): |
189 |
|
|
- http://jakarta.apache.org/turbine/maven/reference/project-descriptor.html |
190 |
|
|
- http://jakarta.apache.org/turbine/maven/images/project-descriptor.gif |
191 |
|
|
- http://jakarta.apache.org/turbine/maven/start/integrate.html |
192 |
|
|
- http://jakarta.apache.org/turbine/maven/reference/dirlayout.html |
193 |
|
|
o integrate with: |
194 |
|
|
o POE |
195 |
|
|
o PP5E |
196 |
|
|
o integrate with pod (for reporting purposes) |
197 |
|
|
o look at: |
198 |
|
|
btw: "expand": look at scripts@CPAN (System Administration): |
199 |
|
|
there is a perl make with perl |
200 |
|
|
o refactore child-modules using code from Data::Code only! |
201 |
|
|
|
202 |
|
|
|
203 |
|
|
=cut |
204 |
|
|
|
205 |
|
|
|
206 |
|
|
package Data::Rap; |
207 |
|
|
|
208 |
|
|
use strict; |
209 |
|
|
use warnings; |
210 |
|
|
|
211 |
|
|
use base qw( |
212 |
|
|
DesignPattern::Object |
213 |
|
|
DesignPattern::Bridge |
214 |
joko |
1.3 |
DesignPattern::Logger |
215 |
|
|
DesignPattern::Exception |
216 |
joko |
1.1 |
); |
217 |
|
|
|
218 |
|
|
|
219 |
|
|
use Data::Dumper; |
220 |
joko |
1.3 |
use Cwd; |
221 |
|
|
use File::Spec::Functions qw( splitpath splitdir catpath catdir ); |
222 |
joko |
1.1 |
|
223 |
|
|
|
224 |
joko |
1.7 |
# a package global topic registry |
225 |
|
|
our $registry; |
226 |
|
|
|
227 |
|
|
|
228 |
joko |
1.1 |
sub constructor { |
229 |
|
|
my $self = shift; |
230 |
joko |
1.3 |
|
231 |
|
|
# patch |
232 |
|
|
$self->{__rap}->{filename} = $self->{filename}; |
233 |
|
|
delete $self->{filename}; |
234 |
|
|
|
235 |
|
|
# check |
236 |
|
|
if (!$self->{__rap}->{filename}) { |
237 |
|
|
$self->{__rap}->{filename} = $self->find_rules(); |
238 |
|
|
} |
239 |
|
|
|
240 |
|
|
$self->load([qw( Metadata Engine Command Context Property )]); |
241 |
joko |
1.1 |
#$self->load("Command"); |
242 |
|
|
#$self->load("Metadata"); |
243 |
|
|
#$self->load("Engine"); |
244 |
jonen |
1.5 |
|
245 |
joko |
1.1 |
} |
246 |
|
|
|
247 |
|
|
sub start { |
248 |
|
|
my $self = shift; |
249 |
joko |
1.8 |
#$self->log("starting", 'info'); |
250 |
joko |
1.1 |
|
251 |
|
|
$self->loadGlobalProperties(); |
252 |
|
|
|
253 |
|
|
#print Dumper($self); |
254 |
|
|
if (my $target = $self->{target}) { |
255 |
|
|
#$self->{targets}->{$target} = Data::Rap::Target->new( name => $target ); |
256 |
joko |
1.8 |
#$self->log("target: $target", 'info'); |
257 |
joko |
1.1 |
$self->performTarget($target); |
258 |
|
|
} else { |
259 |
joko |
1.3 |
my $meta_raw = $self->getTargetList(); |
260 |
|
|
|
261 |
joko |
1.7 |
my $maxlength = 0; |
262 |
|
|
map { |
263 |
|
|
my $len = length($_->{name}); |
264 |
|
|
$maxlength = $len if $len > $maxlength; |
265 |
|
|
} @$meta_raw; |
266 |
|
|
|
267 |
|
|
my $program = splitpath($0); |
268 |
joko |
1.3 |
foreach my $entry (@$meta_raw) { |
269 |
joko |
1.7 |
my $len = length($entry->{name}); |
270 |
|
|
#$len = ((1 / ($len / 8)) * 1.9); |
271 |
|
|
#$len = ((1 / ($maxlength - $len / 8)) * 1.9); |
272 |
|
|
$len = $maxlength - $len + 5; |
273 |
|
|
#print "len: $len", "\n"; |
274 |
|
|
# one line per target |
275 |
|
|
print "$program $entry->{name}", " " x $len; |
276 |
|
|
print $entry->{description} if $entry->{description}; |
277 |
|
|
print "\n"; |
278 |
|
|
# more lines per target |
279 |
|
|
#print "$program $entry->{name}", "\n"; |
280 |
|
|
#print " ", $entry->{description}, "\n" if $entry->{description}; |
281 |
joko |
1.3 |
} |
282 |
|
|
|
283 |
|
|
return; |
284 |
|
|
|
285 |
|
|
print Dumper($meta_raw); |
286 |
|
|
exit; |
287 |
|
|
|
288 |
joko |
1.1 |
foreach my $key (keys %{$meta_raw->{target}}) { |
289 |
|
|
my $target = $meta_raw->{target}->{$key}; |
290 |
|
|
print " - rap.pl $key", "\n"; |
291 |
|
|
my $description = $target->{description}; |
292 |
|
|
if ($description) { |
293 |
|
|
#chomp($description); |
294 |
|
|
$description =~ s/^\n+//; |
295 |
|
|
$description =~ s/\n+$//; |
296 |
|
|
#print "\n" if $description !~ /^\n/; |
297 |
|
|
print $description, "\n" if !ref $description; |
298 |
|
|
} |
299 |
|
|
#print "\n"; |
300 |
|
|
} |
301 |
|
|
} |
302 |
|
|
|
303 |
|
|
} |
304 |
joko |
1.3 |
|
305 |
|
|
sub find_rules { |
306 |
|
|
my $self = shift; |
307 |
|
|
|
308 |
joko |
1.6 |
my $rapfile = 'etc/rap.xml'; |
309 |
|
|
my $rapfile_found = ''; |
310 |
|
|
|
311 |
|
|
my $basedir = ''; |
312 |
|
|
|
313 |
|
|
# directly from env-var? |
314 |
jonen |
1.5 |
if (my $rapdir = $ENV{RAPDIR}) { |
315 |
|
|
$basedir = $rapdir; |
316 |
joko |
1.6 |
|
317 |
|
|
# relative? |
318 |
|
|
} else { |
319 |
jonen |
1.5 |
my $cwd = cwd(); |
320 |
|
|
|
321 |
|
|
(my $volume, my $directory, my $file) = splitpath( $cwd ); |
322 |
joko |
1.6 |
|
323 |
jonen |
1.5 |
my @dir = splitdir($directory); |
324 |
|
|
pop @dir; |
325 |
|
|
#pop @dir; |
326 |
|
|
$basedir = catpath($volume, catdir(@dir)); |
327 |
joko |
1.6 |
|
328 |
|
|
} |
329 |
|
|
|
330 |
|
|
#print "basedir: '$basedir'", "\n"; |
331 |
jonen |
1.5 |
|
332 |
joko |
1.6 |
# check for $basedir/PROJECT |
333 |
|
|
if (! -d "$basedir/PROJECT") { |
334 |
|
|
$basedir = ''; |
335 |
|
|
} |
336 |
|
|
|
337 |
|
|
if ($basedir) { |
338 |
|
|
# TODO: review this! handle relative ./etc/rap.xml here!!! |
339 |
|
|
$rapfile_found = "$basedir/$rapfile"; |
340 |
|
|
|
341 |
|
|
} else { |
342 |
|
|
#if (! -e $rapfile_found) { $rapfile_found = "/$rapfile"; } |
343 |
|
|
$rapfile_found = "/$rapfile"; |
344 |
jonen |
1.5 |
} |
345 |
joko |
1.6 |
|
346 |
|
|
#print "rapfile_found: $rapfile_found", "\n"; |
347 |
|
|
|
348 |
|
|
|
349 |
|
|
# if rapfile doesn't exists, try to fall back to absolute (global) mode (/etc/rap.xml) |
350 |
|
|
#if (! -e $rapfile_found) { $rapfile_found = catpath($volume, "/", $rapfile); } |
351 |
|
|
#if (! -e $rapfile_found) { $rapfile_found = "/$rapfile"; } |
352 |
|
|
|
353 |
|
|
$self->log( "Using rapfile $rapfile_found.", 'info' ); |
354 |
joko |
1.3 |
|
355 |
joko |
1.6 |
return $rapfile_found; |
356 |
joko |
1.3 |
} |
357 |
|
|
|
358 |
joko |
1.1 |
|
359 |
|
|
1; |
360 |
|
|
__END__ |