Skip to content

Commit 21ee941

Browse files
author
Marcin Przepiorowski
committed
issue #219 plus file mapping support for MS SQL
1 parent bf675ca commit 21ee941

File tree

5 files changed

+74
-25
lines changed

5 files changed

+74
-25
lines changed

bin/dx_v2p.pl

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@
108108
}
109109

110110

111-
if ( ( ( $type eq 'oracle') || ( $type eq 'mssql') ) && (! defined($targetDirectory)) ) {
112-
print "Option targetDirectory is required. \n";
113-
pod2usage(-verbose => 1, -input=>\*DATA);
114-
exit (1);
115-
}
116-
117111

118112
# this array will have all engines to go through (if -d is specified it will be only one engine)
119113
my $engine_list = Toolkit_helpers::get_engine_list($all, $dx_host, $engine_obj);
@@ -199,7 +193,7 @@
199193
}
200194

201195
if ( defined($map_file) ) {
202-
my $filemap_obj = new FileMap($engine_obj,$debug);
196+
my $filemap_obj = new FileMap($engine_obj,$type,$debug);
203197
$filemap_obj->loadMapFile($map_file);
204198
$filemap_obj->setSource($source);
205199
if ($filemap_obj->validate()) {
@@ -228,10 +222,24 @@
228222
elsif ($type eq 'mssql') {
229223

230224
if ( $db->setFileSystemLayout($targetDirectory,$archiveDirectory,$dataDirectory,$externalDirectory,$scriptDirectory,$tempDirectory) ) {
225+
print Dumper "ale tu";
231226
print "Problem with export file system layout. Is targetDiretory and dataDirectory set ?\n";
232227
exit(1);
233228
}
234229

230+
if ( defined($map_file) ) {
231+
my $filemap_obj = new FileMap($engine_obj,$type,$debug);
232+
$filemap_obj->loadMapFile($map_file);
233+
$filemap_obj->setSource($source);
234+
if ($filemap_obj->validate($db->{"NEWDB"}->{"filesystemLayout"})) {
235+
die ("Problem with mapping file. V2P process won't be created.")
236+
}
237+
238+
$db->setMapFileV2P($filemap_obj->GetMapping_rule());
239+
240+
}
241+
242+
235243
if (defined($norecovery)) {
236244
$db->setNoRecovery();
237245
}
@@ -341,7 +349,20 @@ =head2 V2P arguments
341349
Target VDB template name (for Oracle)
342350
343351
=item B<-mapfile>
344-
Target VDB mapping file (for Oracle)
352+
Target VDB mapping file. Use colon as separator for both MS SQL and Oracle
353+
Dxtoolkit will use a proper separator for API call.
354+
355+
356+
Oracle mapfile example:
357+
358+
# this is comment
359+
/u01:/u02
360+
361+
MS SQL mapfile example:
362+
363+
# this is comment
364+
Biscuit_Data_1.ndf : c:\\tmp\\los1\\slon_Data_1.ndf
365+
Biscuit_Bogus_1_data.ndf : c:\\tmp\\los2\\slon_Bogus_1_data.ndf
345366
346367
=item B<-instname>
347368
Target VDB instance name (for Oracle)

lib/FileMap.pm

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ use Toolkit_helpers qw (logger);
3838
sub new {
3939
my $classname = shift;
4040
my $dlpxObject = shift;
41+
my $type = shift;
4142
my $debug = shift;
4243
logger($debug, "Entering FileMap::constructor",1);
4344

4445
my %hosts;
4546
my $self = {
4647
_hosts => \%hosts,
48+
_type => $type,
4749
_dlpxObject => $dlpxObject,
4850
_debug => $debug
4951
};
@@ -66,13 +68,20 @@ sub setMapFile {
6668

6769
$self->{_mapping_rule_hash} = $mapfile;
6870

71+
my $join_char;
72+
if (lc $self->{_type} eq 'mssql') {
73+
$join_char = "?";
74+
} else {
75+
$join_char = ":";
76+
}
77+
6978
my $mapping_rule_de = '';
7079

7180
while ( my ($key,$value) = each %{$mapfile} ) {
7281
if ($mapping_rule_de eq '') {
73-
$mapping_rule_de = $key . ":" . $value;
82+
$mapping_rule_de = $key . $join_char . $value;
7483
} else {
75-
$mapping_rule_de = $mapping_rule_de . "\n" . $key . ":" . $value;
84+
$mapping_rule_de = $mapping_rule_de . "\n" . $key . $join_char . $value;
7685
}
7786
}
7887

@@ -94,12 +103,26 @@ sub loadMapFile {
94103

95104
open (my $FD, $file) or die ("Can't open file $file : $!");
96105

106+
my $split_char;
107+
108+
if (lc $self->{_type} eq 'mssql') {
109+
$split_char = ":";
110+
} else {
111+
$split_char = ":";
112+
}
113+
97114
while(my $line = <$FD>) {
98115
chomp $line;
99116
if ($line =~ m/^#/ ) {
100117
next;
101118
}
102-
my @line_split = split (":",$line);
119+
if ($line =~ m/^$/ ) {
120+
next;
121+
}
122+
my @line_split = split ($split_char,$line, 2);
123+
124+
$line_split[0] =~ s/^\s+|\s+$//g;
125+
$line_split[1] =~ s/^\s+|\s+$//g;
103126

104127
if (! defined($line_split[0])) {
105128
die ("Line $line in file $file has an error. Check if there is colon sign. Can't continue");
@@ -114,7 +137,6 @@ sub loadMapFile {
114137
}
115138

116139
close $FD;
117-
118140
$self->setMapFile(\%map_hash);
119141

120142
}
@@ -140,16 +162,22 @@ sub setSource {
140162

141163
sub validate {
142164
my $self = shift;
165+
my $filesystemLayout = shift;
143166
my %fileMapping_request;
144167
logger($self->{_debug}, "Entering FileMap::validate",1);
145168

169+
if (lc $self->{_type} eq 'mssql') {
170+
$fileMapping_request{"type"} = "MSSqlFileMappingParameters";
171+
$fileMapping_request{"filesystemLayout"} = $filesystemLayout;
172+
} else {
173+
$fileMapping_request{"type"} = "FileMappingParameters";
174+
}
175+
146176
if (version->parse($self->{_dlpxObject}->getApi()) < version->parse(1.9.0)) {
147-
$fileMapping_request{"type"} = "FileMappingParameters";
148177
$fileMapping_request{"mappingRules"} = $self->{_mapping_rule};
149178
$fileMapping_request{"timeflowPointParameters"}{"type"} = "TimeflowPointSemantic";
150179
$fileMapping_request{"timeflowPointParameters"}{"container"} = $self->{_source_ref};
151180
} else {
152-
$fileMapping_request{"type"} = "FileMappingParameters";
153181
$fileMapping_request{"mappingRules"} = $self->{_mapping_rule};
154182
my %timeflowhash = (
155183
"type"=>"TimeflowPointSemantic",

lib/MSSQLVDB_obj.pm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,10 @@ sub setFileSystemLayout {
326326
$self->{"NEWDB"}->{"filesystemLayout"}->{"type"} = "MSSqlTimeflowFilesystemLayout";
327327
}
328328

329-
if (! defined($targetDirectory)) {
330-
return 1;
329+
if (defined($targetDirectory)) {
330+
$self->{"NEWDB"}->{"filesystemLayout"}->{"targetDirectory"} = $targetDirectory;
331331
}
332332

333-
$self->{"NEWDB"}->{"filesystemLayout"}->{"targetDirectory"} = $targetDirectory;
334-
335333
if (defined($dataDirectory)) {
336334
$self->{"NEWDB"}->{"filesystemLayout"}->{"dataDirectory"} = $dataDirectory;
337335
} else {
@@ -357,8 +355,12 @@ sub setFileSystemLayout {
357355

358356
if ( defined($externalDirectory)) {
359357
$self->{"NEWDB"}->{"filesystemLayout"}->{"externalDirectory"} = $externalDirectory;
358+
} else {
359+
$self->{"NEWDB"}->{"filesystemLayout"}->{"scriptDirectory"} = "external";
360360
}
361361

362+
return undef;
363+
362364
}
363365

364366

lib/OracleVDB_obj.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,11 +2505,11 @@ sub setFileSystemLayout {
25052505
$self->{"NEWDB"}->{"filesystemLayout"}->{"type"} = "OracleExportTimeflowFilesystemLayout";
25062506
}
25072507

2508-
if (! defined($targetDirectory)) {
2509-
return 1;
2508+
if (defined($targetDirectory)) {
2509+
$self->{"NEWDB"}->{"filesystemLayout"}->{"targetDirectory"} = $targetDirectory;
25102510
}
25112511

2512-
$self->{"NEWDB"}->{"filesystemLayout"}->{"targetDirectory"} = $targetDirectory;
2512+
25132513

25142514
if ( defined($archiveDirectory)) {
25152515
$self->{"NEWDB"}->{"filesystemLayout"}->{"archiveDirectory"} = $archiveDirectory;

lib/VDB_obj.pm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,12 +1963,10 @@ sub setFileSystemLayout {
19631963

19641964
$self->{"NEWDB"}->{"filesystemLayout"}->{"type"} = "TimeflowFilesystemLayout";
19651965

1966-
if (! defined($targetDirectory)) {
1967-
return 1;
1966+
if (defined($targetDirectory)) {
1967+
$self->{"NEWDB"}->{"filesystemLayout"}->{"targetDirectory"} = $targetDirectory;
19681968
}
19691969

1970-
$self->{"NEWDB"}->{"filesystemLayout"}->{"targetDirectory"} = $targetDirectory;
1971-
19721970
if ( defined($archiveDirectory)) {
19731971
$self->{"NEWDB"}->{"filesystemLayout"}->{"archiveDirectory"} = $archiveDirectory;
19741972
}

0 commit comments

Comments
 (0)