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