/[cvs]/nfo/perl/libs/Data/Rap.pm
ViewVC logotype

Annotation of /nfo/perl/libs/Data/Rap.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations)
Sun Jun 20 16:06:57 2004 UTC (19 years, 11 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +5 -1 lines
sub start: little modification, now using targets-cache if available

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed