/[cvs]/nfo/perl/libs/OEF/Script/AbstractFeeder.pm
ViewVC logotype

Contents of /nfo/perl/libs/OEF/Script/AbstractFeeder.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Sun Feb 9 16:27:06 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
+ initial commit

1 #!/usr/bin/perl
2
3 ## --------------------------------------------------------------------------------
4 ## $Id: feed.pl,v 1.4 2003/01/23 14:44:35 janosch Exp $
5 ## --------------------------------------------------------------------------------
6 ## $Log: feed.pl,v $
7 ## --------------------------------------------------------------------------------
8
9
10 package OEF::Script::AbstractFeeder;
11
12 use strict;
13 use warnings;
14
15 #use base 'OEF::Component::Task';
16 use base qw(
17 DesignPattern::Object
18 DesignPattern::Object::Logger
19 );
20
21
22 use Data::Dumper;
23 use Getopt::Long;
24
25
26 # get logger instance
27 my $logger = Log::Dispatch::Config->instance;
28
29 sub usage {
30 my $self = shift;
31 print "\n";
32 print <<EOU;
33 usage:
34 feed.pl --source=<dbkey> --node=<node> --target=<dbkey> --action=<action> [--mapping=]
35
36 source: dbkey links to a configuration resource representing a storage (~= database)
37 node: the name of a node on the first level below the source storage
38 target: dbkey links to a configuration resource representing a storage
39 action: <action> is issued on given dbkey as source node
40 sync FULL sync (PULL & PUSH)
41 load|save PULL or PUSH syncs
42 import|export IMPORT and EXPORT syncs
43 mapping: future use: specify name of a perl module / xml file which describes/outlines the mapping
44 EOU
45 exit;
46 }
47
48 sub getoptions {
49 my $self = shift;
50
51 GetOptions(
52 'source=s' => \$self->{opt}->{source},
53 'source-type=s' => \$self->{opt}->{'source-type'},
54 'source-node=s' => \$self->{opt}->{'source-node'},
55 'target=s' => \$self->{opt}->{target},
56 'target-node=s' => \$self->{opt}->{'target-node'},
57 'action=s' => \$self->{opt}->{action},
58 'mapping-module=s' => \$self->{opt}->{'mapping-module'},
59 'prepare' => \$self->{opt}->{prepare},
60 'fresh' => \$self->{opt}->{fresh},
61 'help' => \&usage,
62 # v1-API-spec backward compatibility
63 'node=s' => \$self->{opt}->{'node'},
64 );
65 }
66
67 sub getoptions_old {
68 my $self = shift;
69 GetOptions(
70 'source=s' => \$self->{opt}->{source},
71 'node=s' => \$self->{opt}->{node},
72 'target=s' => \$self->{opt}->{target},
73 'action=s' => \$self->{opt}->{action},
74 'mapping=s' => \$self->{opt}->{mapping},
75 'prepare' => \$self->{opt}->{prepare},
76 'fresh' => \$self->{opt}->{fresh},
77 );
78
79 # TODO: use some core function/method (e.g. 'init_hash($hashref, $value, $force = 0)')
80 $self->{opt}->{source} ||= '';
81 $self->{opt}->{node} ||= '';
82 $self->{opt}->{target} ||= '';
83 $self->{opt}->{action} ||= '';
84 $self->{opt}->{mapping} ||= '';
85 $self->{opt}->{prepare} ||= '';
86 $self->{opt}->{fresh} ||= '';
87
88 }
89
90
91 sub set {
92 my $self = shift;
93 my $data = { @_ };
94 #return bless $self, $class;
95 foreach (keys %$data) {
96 #print $_, "\n";
97 $self->{$_} = $data->{$_};
98 }
99 }
100
101 sub run {
102 my $self = shift;
103 $self->_before_run();
104 $self->prepare();
105 $self->tellWhatIAmDoing();
106 $self->sync();
107 }
108
109 my $c_string_default = '';
110 sub c_string {
111 my $value = shift;
112 $value ||= "[$c_string_default]";
113 return $value;
114 }
115
116 sub tellWhatIAmDoing {
117 my $self = shift;
118
119 $c_string_default = 'n/a';
120 my $source = c_string($self->{opt}->{'source'});
121 my $source_node = c_string($self->{opt}->{'source-node'});
122 my $source_type = c_string($self->{opt}->{'source-type'});
123 my $target = c_string($self->{opt}->{'target'});
124 my $target_node = c_string($self->{opt}->{'target-node'});
125 my $target_type = c_string($self->{opt}->{'target-type'});
126
127 my $mapping_module = c_string($self->{opt}->{'mapping-module'});
128 my $mode = uc c_string($self->{opt}->{'mode'});
129
130 my $ql = "$mode INTO $source NODE $source_node TYPE $source_type SELECT NODE $target_node TYPE $target_type FROM $target USING MODULE $mapping_module;";
131 #$logger->notice( __PACKAGE__ . ": $ql" );
132 $logger->notice( $ql );
133
134 return;
135
136 my $actioning = ucfirst $self->{opt}->{'action'} . 'ing';
137
138 # FIXME: this is weird!
139 my $long = <<EOT;
140
141 - $actioning data of type $target_type and
142 filtered by $target_node from the storage named $target
143 to the storage named $source - filtered by $source_node.
144 - Will attempt to convert the data to $source_type.
145 EOT
146 chomp($long);
147 $logger->notice( __PACKAGE__ . ": $long" );
148
149 }
150
151 sub prepare {
152 my $self = shift;
153
154 # TODO:
155 # - move this to Data::Transfer::Sync::checkOptions!!!
156 # - use 'syncable'???
157
158 #if ($self->{app}->{config}->{databases}->{$self->{opt}->{target}}->{syncable}) {
159
160 my $mode = '';
161 my $erase = 0;
162 my $import = 0;
163 $mode = 'PUSH' if $self->{opt}->{action} eq 'save';
164 $mode = 'PULL' if $self->{opt}->{action} eq 'load';
165 if ($self->{opt}->{action} eq 'import') {
166 $mode = 'PULL';
167 $erase = 1;
168 $import = 1;
169 }
170 if ($self->{opt}->{action} eq 'export') {
171 $mode = 'PUSH';
172 $erase = 1;
173 #$import = 1;
174 }
175 $self->{opt}->{mode} = $mode;
176 $self->{opt}->{erase} = $erase;
177 $self->{opt}->{import} = $import;
178
179 }
180
181 sub sync {
182 my $self = shift;
183
184 # trace
185 #print Dumper($self);
186 #print Dumper($self->{opt});
187 #exit;
188
189 # proposal to introduce full backward-compatibility mechanism
190 # "just" have many APIs with different versions accessing the very same core ...
191 # is api-version specified?
192 my $sync_version = $self->{opt}->{sv};
193 $sync_version ||= 'V1';
194
195 # create a new synchronization object
196 my $sync = Data::Transfer::Sync->new( 'sync_version' => $sync_version );
197
198 # trace
199 #print Dumper($self);
200
201 # configure the synchronization-object
202 $sync->configure(
203 source => {
204 storage => {
205 #handle => $mapiStorage,
206 handle => $self->{app}->{$self->{opt}->{source}},
207 writeProtected => 1,
208 },
209 },
210 target => {
211 storage => {
212 #handle => $ldapStorage,
213 handle => $self->{app}->{$self->{opt}->{target}},
214 idAuthority => 1,
215 isChecksumAuthority => 1,
216 writeProtected => 0,
217 },
218 },
219 verbose => 1,
220 );
221
222 # trace
223 #print Dumper($sync);
224 #exit;
225
226 # read, mungle & check the options
227 $sync->setArguments($self->{opt});
228 $sync->readArguments();
229
230 # trace
231 #print Dumper($sync);
232
233 # finally, run the sync ...
234 $sync->syncNodes();
235
236 }
237
238
239 1;

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