1 |
joko |
1.1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
## -------------------------------------------------------------------------------- |
4 |
joko |
1.2 |
## $Id: feed.pl,v 1.1 2003/01/18 18:20:45 joko Exp $ |
5 |
joko |
1.1 |
## -------------------------------------------------------------------------------- |
6 |
joko |
1.2 |
## $Log: feed.pl,v $ |
7 |
|
|
## Revision 1.1 2003/01/18 18:20:45 joko |
8 |
|
|
## + initial check-in |
9 |
|
|
## |
10 |
joko |
1.1 |
## -------------------------------------------------------------------------------- |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
package main; |
14 |
|
|
|
15 |
|
|
use strict; |
16 |
|
|
use warnings; |
17 |
|
|
|
18 |
|
|
BEGIN { |
19 |
|
|
use FindBin qw($Bin); |
20 |
|
|
#require "$Bin/use_libs.pl"; |
21 |
|
|
} |
22 |
|
|
|
23 |
joko |
1.2 |
use Tie::IxHash; |
24 |
|
|
|
25 |
joko |
1.1 |
|
26 |
|
|
use lib qw( ../libs ../etc C:\home\amo\develop\netfrag.org\nfo\perl\libs ); |
27 |
|
|
use Torus::Logger; |
28 |
|
|
use Torus::Core; |
29 |
|
|
|
30 |
|
|
my $logger = Log::Dispatch::Config->instance; |
31 |
|
|
|
32 |
|
|
#use BizWorks::Script::Feed; |
33 |
|
|
|
34 |
|
|
#=pod |
35 |
|
|
#my $context = BizWorks::RunMe->new( app => $bizWorks, process => $bizProcess, logger => $logger ); |
36 |
|
|
#my $context = BizWorks::RunMe->new(); |
37 |
|
|
my $context = BizWorks::Script::Feed->new(); |
38 |
|
|
$context->getoptions(); |
39 |
|
|
$context->{opt}->{mapping_module} = $context->{opt}->{mapping}; |
40 |
|
|
#$context->verifyoptions(); |
41 |
|
|
#$context->options2actions(); |
42 |
|
|
#$context->run(); |
43 |
|
|
#$context->suspend(); |
44 |
|
|
#$context->set( app => $bizWorks, process => $bizProcess, logger => $logger ); |
45 |
|
|
my $bizWorks; |
46 |
|
|
$context->set( |
47 |
|
|
app => $bizWorks, |
48 |
|
|
process => Torus::Core->new(), |
49 |
|
|
logger => $logger, |
50 |
|
|
config => { mappings => { 'LdapAddress' => 'xyz' } }, |
51 |
|
|
); |
52 |
|
|
#print Dumper($context); |
53 |
|
|
#print Dumper($context->{process}->{bizWorks}->{backend}); |
54 |
|
|
$context->run(); |
55 |
|
|
#exit; |
56 |
|
|
#print Dumper($context); |
57 |
|
|
#$context->suspend(); |
58 |
|
|
#=cut |
59 |
|
|
|
60 |
|
|
|
61 |
|
|
#=pod |
62 |
|
|
#my $context = OEF::Component::Task->new( guid => 'ac65ea820a263948af8b4947f33f7719' ); |
63 |
|
|
#my $context = OEF::Component::Task->new( guid => '767ee9ab030bb4163e67ab26ab9a8894' ); |
64 |
|
|
#my $context = OEF::Component::Task->new( guid => '3a5c85995270ee8b17a8701c6f709ecf' ); |
65 |
|
|
#my $context2 = OEF::Component::Task->new( guid => $context->getGuid() ); |
66 |
|
|
#my $context2 = OEF::Component::Task->new( guid => '79d69fa4308d88181b882ef8d3433534' ); |
67 |
|
|
|
68 |
|
|
#$context2->resume(); |
69 |
|
|
#print Dumper($context2); |
70 |
|
|
#print Dumper($context2->{process}->{bizWorks}->{backend}); |
71 |
|
|
#$context2->{process}->{bizWorks}->{backend}->connect(); |
72 |
|
|
#$context2->run(); |
73 |
|
|
#=cut |
74 |
|
|
|
75 |
|
|
|
76 |
|
|
package BizWorks::Script::Feed; |
77 |
|
|
|
78 |
|
|
use strict; |
79 |
|
|
use warnings; |
80 |
|
|
|
81 |
|
|
use Data::Dumper; |
82 |
|
|
use Getopt::Long; |
83 |
|
|
|
84 |
|
|
#use base 'OEF::Component::Task'; |
85 |
|
|
use base qw( |
86 |
|
|
DesignPattern::Object |
87 |
|
|
DesignPattern::Object::Logger |
88 |
|
|
); |
89 |
|
|
|
90 |
|
|
sub usage { |
91 |
|
|
my $self = shift; |
92 |
|
|
print "\n"; |
93 |
|
|
print <<EOU; |
94 |
|
|
usage: |
95 |
|
|
feed.pl --source=<dbkey> --node=<node> --target=<dbkey> --action=<action> [--mapping=] |
96 |
|
|
|
97 |
|
|
source: dbkey links to a configuration resource representing a storage (~= database) |
98 |
|
|
node: the name of a node on the first level below the source storage |
99 |
|
|
target: dbkey links to a configuration resource representing a storage |
100 |
|
|
action: <action> is issued on given dbkey as source node |
101 |
|
|
sync FULL sync (PULL & PUSH) |
102 |
|
|
load|save PULL or PUSH syncs |
103 |
|
|
import|export IMPORT and EXPORT syncs |
104 |
|
|
mapping: future use: specify name of a perl module / xml file which describes/outlines the mapping |
105 |
|
|
EOU |
106 |
|
|
exit; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
sub getoptions { |
110 |
|
|
my $self = shift; |
111 |
|
|
|
112 |
|
|
GetOptions( |
113 |
|
|
'source=s' => \$self->{opt}->{source}, |
114 |
joko |
1.2 |
'source-type=s' => \$self->{opt}->{'source-type'}, |
115 |
|
|
'source-node=s' => \$self->{opt}->{'source-node'}, |
116 |
joko |
1.1 |
'target=s' => \$self->{opt}->{target}, |
117 |
joko |
1.2 |
'target-node=s' => \$self->{opt}->{'target-node'}, |
118 |
joko |
1.1 |
'action=s' => \$self->{opt}->{action}, |
119 |
joko |
1.2 |
'mapping-module=s' => \$self->{opt}->{'mapping-module'}, |
120 |
joko |
1.1 |
'prepare' => \$self->{opt}->{prepare}, |
121 |
|
|
'fresh' => \$self->{opt}->{fresh}, |
122 |
|
|
'help' => \&usage, |
123 |
|
|
); |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
sub set { |
127 |
|
|
my $self = shift; |
128 |
|
|
my $data = { @_ }; |
129 |
|
|
#return bless $self, $class; |
130 |
|
|
foreach (keys %$data) { |
131 |
|
|
#print $_, "\n"; |
132 |
|
|
$self->{$_} = $data->{$_}; |
133 |
|
|
} |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
=pod |
137 |
|
|
sub run { |
138 |
|
|
my $self = shift; |
139 |
|
|
$self->{var} ||= 0; |
140 |
|
|
print __PACKAGE__, "\n"; |
141 |
|
|
print "var: ", $self->{var}, "\n"; |
142 |
|
|
$self->{var}++; |
143 |
|
|
} |
144 |
|
|
=cut |
145 |
|
|
|
146 |
|
|
sub run { |
147 |
|
|
|
148 |
|
|
my $self = shift; |
149 |
|
|
|
150 |
|
|
#print Dumper($self->{opt}); |
151 |
|
|
|
152 |
|
|
# TODO: move this to the synchronization (startup) somehow... (one level towards the core - just one....) |
153 |
|
|
if ($self->{opt}->{target} eq 'testdata') { |
154 |
|
|
#print Dumper($self->{opt}); |
155 |
|
|
$self->{logger}->info( __PACKAGE__ . "->run: Running (special handler code - no generic sync!) on '$self->{opt}->{target}' with action $self->{opt}->{action} - no NODE"); |
156 |
|
|
$self->{process}->load('Setup/Data/Test'); |
157 |
|
|
#print "2", "\n"; |
158 |
|
|
return $self->{process}->handler(); |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
#print Dumper($self->{opt}); |
162 |
|
|
|
163 |
|
|
#$self->{process}->load('Setup'); |
164 |
|
|
|
165 |
|
|
# TODO: |
166 |
|
|
# - move this to Data::Transfer::Sync::checkOptions!!! |
167 |
|
|
# - remove the tail of this "if" at the bottom of this block! |
168 |
|
|
#if ($self->{app}->{config}->{databases}->{$self->{opt}->{target}}->{syncable}) { |
169 |
|
|
my $mode = ''; |
170 |
|
|
my $erase = 0; |
171 |
|
|
my $import = 0; |
172 |
|
|
$mode = 'PUSH' if $self->{opt}->{action} eq 'save'; |
173 |
|
|
$mode = 'PULL' if $self->{opt}->{action} eq 'load'; |
174 |
|
|
if ($self->{opt}->{action} eq 'import') { |
175 |
|
|
$mode = 'PULL'; |
176 |
|
|
$erase = 1; |
177 |
|
|
$import = 1; |
178 |
|
|
} |
179 |
|
|
if ($self->{opt}->{action} eq 'export') { |
180 |
|
|
$mode = 'PUSH'; |
181 |
|
|
$erase = 1; |
182 |
|
|
#$import = 1; |
183 |
|
|
} |
184 |
joko |
1.2 |
|
185 |
|
|
|
186 |
|
|
#print Dumper($self->{opt}); |
187 |
|
|
#exit; |
188 |
|
|
|
189 |
|
|
my %syncConfig; |
190 |
|
|
tie %syncConfig, 'Tie::IxHash'; |
191 |
|
|
%syncConfig = ( |
192 |
|
|
map => { |
193 |
|
|
moduleName => $self->{opt}->{'mapping-module'}, |
194 |
|
|
}, |
195 |
|
|
source => { |
196 |
|
|
dbKey => $self->{opt}->{source}, |
197 |
|
|
nodeType => $self->{opt}->{'source-type'}, |
198 |
|
|
nodeName => $self->{opt}->{'source-node'}, |
199 |
|
|
}, |
200 |
|
|
target => { |
201 |
|
|
dbKey => $self->{opt}->{target}, |
202 |
|
|
nodeName => $self->{opt}->{'target-node'}, |
203 |
|
|
}, |
204 |
|
|
process => { |
205 |
|
|
mode => $mode, |
206 |
|
|
erase => $erase, |
207 |
|
|
import => $import, |
208 |
|
|
prepare => $self->{opt}->{prepare}, |
209 |
|
|
}, |
210 |
|
|
); |
211 |
|
|
|
212 |
|
|
#print Dumper(\%syncConfig); |
213 |
|
|
|
214 |
|
|
$self->{process}->startSync( \%syncConfig ); |
215 |
joko |
1.1 |
|
216 |
|
|
=pod |
217 |
|
|
} else { |
218 |
|
|
#print "\n", "Target is not syncable", "\n"; |
219 |
|
|
print "\n", "Target is not syncable", "\n"; |
220 |
|
|
$self->usage(); |
221 |
|
|
} |
222 |
|
|
=cut |
223 |
|
|
|
224 |
|
|
#$self->{process}->{outlook}->disconnect(); |
225 |
|
|
return; |
226 |
|
|
|
227 |
|
|
if ($self->{opt}->{action} eq 'load') { |
228 |
|
|
if ($self->{opt}->{target} eq 'resources') { |
229 |
|
|
fillResources(); |
230 |
|
|
} elsif ($self->{opt}->{target} eq 'testdata') { |
231 |
|
|
fillTestData(); |
232 |
|
|
} else { |
233 |
|
|
$self->usage(); |
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
} elsif ($self->{opt}->{action} eq 'save') { |
237 |
|
|
if ($self->{opt}->{target} eq 'resources') { |
238 |
|
|
$self->{process}->backupResources(); |
239 |
|
|
} elsif ($self->{opt}->{target} eq 'testdata') { |
240 |
|
|
print "could not save $self->{opt}->{resource}, it's stored inside a perl module", "\n"; |
241 |
|
|
} else { |
242 |
|
|
$self->usage(); |
243 |
|
|
} |
244 |
|
|
|
245 |
|
|
} elsif ($self->{opt}->{action} eq 'import') { |
246 |
|
|
if (!$self->{opt}->{node}) { print "option \"--action=import\" requires option \"--node\"", "\n"; $self->usage(); } |
247 |
|
|
|
248 |
|
|
} else { |
249 |
|
|
$self->usage(); |
250 |
|
|
} |
251 |
|
|
|
252 |
|
|
$self->{process}->{storage}->disconnect(); |
253 |
|
|
|
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
1; |
257 |
|
|
|
258 |
|
|
|
259 |
|
|
package BizWorks::RunMe; |
260 |
|
|
|
261 |
|
|
use strict; |
262 |
|
|
use warnings; |
263 |
|
|
|
264 |
|
|
#use base 'OEF::Component::Task'; |
265 |
|
|
use base qw( |
266 |
|
|
DesignPattern::Object |
267 |
|
|
DesignPattern::Object::Logger |
268 |
|
|
); |
269 |
|
|
|
270 |
|
|
use Getopt::Long; |
271 |
|
|
#use BizWorks::Boot qw( $bizWorks $bizProcess ); |
272 |
|
|
use Data::Dumper; |
273 |
|
|
use Getopt::Long; |
274 |
|
|
use Carp; |
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
|
|
sub getoptions { |
280 |
|
|
my $self = shift; |
281 |
|
|
|
282 |
|
|
$self->{'opt'}->{'source'} = 'backend'; |
283 |
|
|
$self->{'opt'}->{'target'} = 'testdata'; |
284 |
|
|
$self->{'opt'}->{'action'} = 'load'; |
285 |
|
|
|
286 |
|
|
# TODO: use some core function/method (e.g. 'init_hash($hashref, $value, $force = 0)') |
287 |
|
|
$self->{opt}->{source} ||= ''; |
288 |
|
|
$self->{opt}->{node} ||= ''; |
289 |
|
|
$self->{opt}->{target} ||= ''; |
290 |
|
|
$self->{opt}->{action} ||= ''; |
291 |
|
|
$self->{opt}->{mapping} ||= ''; |
292 |
|
|
$self->{opt}->{prepare} ||= ''; |
293 |
|
|
$self->{opt}->{fresh} ||= ''; |
294 |
|
|
|
295 |
|
|
} |
296 |
|
|
|
297 |
|
|
|
298 |
|
|
sub run { |
299 |
|
|
|
300 |
|
|
my $self = shift; |
301 |
|
|
|
302 |
|
|
#print Dumper($self->{opt}); |
303 |
|
|
|
304 |
|
|
# TODO: move this to the synchroninzation (startup) somehow... (one level towards the core - just one....) |
305 |
|
|
if ($self->{opt}->{target} eq 'testdata') { |
306 |
|
|
#print Dumper($self->{opt}); |
307 |
|
|
$self->{logger}->info( __PACKAGE__ . "->run: Running (special handler code - no generic sync!) on '$self->{opt}->{target}' with action $self->{opt}->{action} - no NODE"); |
308 |
|
|
$self->{process}->load('Setup/Data/Test'); |
309 |
|
|
#print "2", "\n"; |
310 |
|
|
return $self->{process}->handler(); |
311 |
|
|
} |
312 |
|
|
|
313 |
|
|
#print Dumper($self->{opt}); |
314 |
|
|
|
315 |
|
|
#$self->{process}->load('Setup'); |
316 |
|
|
|
317 |
|
|
# TODO: |
318 |
|
|
# - move this to Data::Transfer::Sync::checkOptions!!! |
319 |
|
|
# - remove the tail of this "if" at the bottom of this block! |
320 |
|
|
#if ($self->{app}->{config}->{databases}->{$self->{opt}->{target}}->{syncable}) { |
321 |
|
|
my $mode = ''; |
322 |
|
|
my $erase = 0; |
323 |
|
|
my $import = 0; |
324 |
|
|
$mode = 'PUSH' if $self->{opt}->{action} eq 'save'; |
325 |
|
|
$mode = 'PULL' if $self->{opt}->{action} eq 'load'; |
326 |
|
|
if ($self->{opt}->{action} eq 'import') { |
327 |
|
|
$mode = 'PULL'; |
328 |
|
|
$erase = 1; |
329 |
|
|
$import = 1; |
330 |
|
|
} |
331 |
|
|
if ($self->{opt}->{action} eq 'export') { |
332 |
|
|
$mode = 'PUSH'; |
333 |
|
|
$erase = 1; |
334 |
|
|
#$import = 1; |
335 |
|
|
} |
336 |
|
|
$self->{process}->startSync({ |
337 |
|
|
source => $self->{opt}->{source}, |
338 |
|
|
source_node => $self->{opt}->{node}, |
339 |
|
|
target => $self->{opt}->{target}, |
340 |
|
|
mode => $mode, |
341 |
|
|
erase => $erase, |
342 |
|
|
import => $import, |
343 |
|
|
mapping => $self->{opt}->{mapping}, |
344 |
|
|
prepare => $self->{opt}->{prepare}, |
345 |
|
|
}); |
346 |
|
|
|
347 |
|
|
=pod |
348 |
|
|
} else { |
349 |
|
|
#print "\n", "Target is not syncable", "\n"; |
350 |
|
|
print "\n", "Target is not syncable", "\n"; |
351 |
|
|
$self->usage(); |
352 |
|
|
} |
353 |
|
|
=cut |
354 |
|
|
|
355 |
|
|
$self->{process}->{storage}->disconnect(); |
356 |
|
|
return; |
357 |
|
|
|
358 |
|
|
if ($self->{opt}->{action} eq 'load') { |
359 |
|
|
if ($self->{opt}->{target} eq 'resources') { |
360 |
|
|
fillResources(); |
361 |
|
|
} elsif ($self->{opt}->{target} eq 'testdata') { |
362 |
|
|
fillTestData(); |
363 |
|
|
} else { |
364 |
|
|
$self->usage(); |
365 |
|
|
} |
366 |
|
|
|
367 |
|
|
} elsif ($self->{opt}->{action} eq 'save') { |
368 |
|
|
if ($self->{opt}->{target} eq 'resources') { |
369 |
|
|
$self->{process}->backupResources(); |
370 |
|
|
} elsif ($self->{opt}->{target} eq 'testdata') { |
371 |
|
|
print "could not save $self->{opt}->{resource}, it's stored inside a perl module", "\n"; |
372 |
|
|
} else { |
373 |
|
|
$self->usage(); |
374 |
|
|
} |
375 |
|
|
|
376 |
|
|
} elsif ($self->{opt}->{action} eq 'import') { |
377 |
|
|
if (!$self->{opt}->{node}) { print "option \"--action=import\" requires option \"--node\"", "\n"; $self->usage(); } |
378 |
|
|
|
379 |
|
|
} else { |
380 |
|
|
$self->usage(); |
381 |
|
|
} |
382 |
|
|
|
383 |
|
|
$self->{process}->{storage}->disconnect(); |
384 |
|
|
|
385 |
|
|
} |
386 |
|
|
|
387 |
|
|
|
388 |
|
|
1; |