Skip to content

Commit 884767d

Browse files
author
Marcin Przepiorowski
committed
Merge branch 'template_issue' into develop
2 parents 6ecc735 + 72eff0f commit 884767d

File tree

1 file changed

+56
-52
lines changed

1 file changed

+56
-52
lines changed

lib/Template_obj.pm

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#
1+
#
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
5-
#
5+
#
66
# http://www.apache.org/licenses/LICENSE-2.0
7-
#
7+
#
88
# Unless required by applicable law or agreed to in writing, software
99
# distributed under the License is distributed on an "AS IS" BASIS,
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,7 +32,7 @@ use JSON;
3232
use Toolkit_helpers qw (logger);
3333

3434
# constructor
35-
# parameters
35+
# parameters
3636
# - dlpxObject - connection to DE
3737
# - debug - debug flag (debug on if defined)
3838

@@ -48,81 +48,81 @@ sub new {
4848
_dlpxObject => $dlpxObject,
4949
_debug => $debug
5050
};
51-
51+
5252
bless($self,$classname);
53-
53+
5454
$self->loadTemplateList($debug);
5555
return $self;
5656
}
5757

5858

5959
# Procedure getTemplateByName
60-
# parameters:
61-
# - name
60+
# parameters:
61+
# - name
6262
# Return template reference for particular name
6363

6464
sub getTemplateByName {
6565
my $self = shift;
6666
my $name = shift;
67-
logger($self->{_debug}, "Entering Template_obj::getTemplateByName",1);
67+
logger($self->{_debug}, "Entering Template_obj::getTemplateByName",1);
6868
my $ret;
6969

7070
#print Dumper $$config;
7171

7272
for my $templateitem ( sort ( keys %{$self->{_templates}} ) ) {
7373

7474
if ( $self->getName($templateitem) eq $name) {
75-
$ret = $templateitem;
75+
$ret = $templateitem;
7676
}
7777
}
7878

7979
return $ret;
8080
}
8181

8282
# Procedure getTemplate
83-
# parameters:
83+
# parameters:
8484
# - reference
8585
# Return template hash for specific template reference
8686

8787
sub getTemplate {
8888
my $self = shift;
8989
my $reference = shift;
90-
91-
logger($self->{_debug}, "Entering Template_obj::getTemplate",1);
90+
91+
logger($self->{_debug}, "Entering Template_obj::getTemplate",1);
9292

9393
my $templates = $self->{_templates};
9494
return $templates->{$reference};
9595
}
9696

9797

9898
# Procedure getTemplateParameters
99-
# parameters:
99+
# parameters:
100100
# - reference
101101
# Return template parmeters for specific template reference
102102

103103
sub getTemplateParameters {
104104
my $self = shift;
105105
my $reference = shift;
106-
107-
logger($self->{_debug}, "Entering Template_obj::getTemplateParameters",1);
106+
107+
logger($self->{_debug}, "Entering Template_obj::getTemplateParameters",1);
108108

109109
my $templates = $self->{_templates};
110110
return $templates->{$reference}->{parameters};
111111
}
112112

113113
# Procedure compare
114-
# parameters:
114+
# parameters:
115115
# - reference
116116
# - hash with init.ora
117-
# Return three sets - array existing in template but not in VDB and
117+
# Return three sets - array existing in template but not in VDB and
118118
# array existing in VDB but not in template, hash differences
119119

120120
sub compare {
121121
my $self = shift;
122122
my $reference = shift;
123123
my $init = shift;
124-
125-
logger($self->{_debug}, "Entering Template_obj::compare",1);
124+
125+
logger($self->{_debug}, "Entering Template_obj::compare",1);
126126

127127
my %restricted = (
128128
active_instance_count => 1,
@@ -172,7 +172,7 @@ sub compare {
172172
__streams_pool_size => 1,
173173
_omf => 1
174174
);
175-
175+
176176
my %settodefault = (
177177
filesystemio_options => 1,
178178
audit_file_dest => 1,
@@ -192,7 +192,7 @@ sub compare {
192192
log_archive_dest_6 => 1,
193193
log_archive_dest_7 => 1,
194194
log_archive_dest_8 => 1,
195-
log_archive_dest_9 => 1,
195+
log_archive_dest_9 => 1,
196196
log_archive_dest_10 => 1,
197197
log_archive_dest_11 => 1,
198198
log_archive_dest_12 => 1,
@@ -249,13 +249,13 @@ sub compare {
249249
remote_listener => 1,
250250
user_dump_dest => 1,
251251
);
252-
252+
253253
my %notintemplate;
254254
my %notininit;
255255
my %different;
256-
256+
257257
my $templatepar = $self->getTemplateParameters($reference);
258-
258+
259259
for my $par (sort keys %{$templatepar}) {
260260
if (defined($init->{$par})) {
261261
$init->{$par} =~ s/['|"]//g;
@@ -269,9 +269,9 @@ sub compare {
269269
} else {
270270
$notininit{$par} = $templatepar->{$par};
271271
}
272-
272+
273273
}
274-
274+
275275
for my $par (sort keys %{$init}) {
276276
if (!defined($restricted{$par})) {
277277
if (!defined($templatepar->{$par})) {
@@ -280,46 +280,46 @@ sub compare {
280280
}
281281
}
282282
}
283-
283+
284284
}
285-
285+
286286
return (\%notininit, \%notintemplate, \%different);
287-
288-
287+
288+
289289
}
290290

291291

292292
# Procedure getTemplateList
293-
# parameters:
293+
# parameters:
294294
# Return template list
295295

296296
sub getTemplateList {
297297
my $self = shift;
298298
my $reference = shift;
299-
300-
logger($self->{_debug}, "Entering Template_obj::getTemplateList",1);
299+
300+
logger($self->{_debug}, "Entering Template_obj::getTemplateList",1);
301301

302302
return keys %{$self->{_templates}};
303303
}
304304

305305

306306
# Procedure getName
307-
# parameters:
307+
# parameters:
308308
# - reference
309309
# Return template name for specific template reference
310310

311311
sub getName {
312312
my $self = shift;
313313
my $reference = shift;
314-
315-
logger($self->{_debug}, "Entering Template_obj::getName",1);
314+
315+
logger($self->{_debug}, "Entering Template_obj::getName",1);
316316

317317
my $templates = $self->{_templates};
318318
return $templates->{$reference}->{name};
319319
}
320320

321321
# Procedure exportTemplate
322-
# parameters:
322+
# parameters:
323323
# - reference
324324
# - location - directory
325325
# Return 0 if no errors
@@ -329,7 +329,7 @@ sub exportTemplate {
329329
my $reference = shift;
330330
my $location = shift;
331331

332-
logger($self->{_debug}, "Entering Template_obj::exportTemplate",1);
332+
logger($self->{_debug}, "Entering Template_obj::exportTemplate",1);
333333

334334
my $filename = $location . "/" . $self->getName($reference) . ".template";
335335

@@ -347,15 +347,15 @@ sub exportTemplate {
347347
}
348348

349349
# Procedure importTemplate
350-
# parameters:
350+
# parameters:
351351
# - location - file name
352352
# Return 0 if no errors
353353

354354
sub importTemplate {
355355
my $self = shift;
356356
my $location = shift;
357357

358-
logger($self->{_debug}, "Entering Template_obj::importTemplate",1);
358+
logger($self->{_debug}, "Entering Template_obj::importTemplate",1);
359359

360360
my $filename = $location;
361361

@@ -366,14 +366,18 @@ sub importTemplate {
366366
local $/ = undef;
367367
my $json = JSON->new();
368368
$loadedTemplate = $json->decode(<$FD>);
369-
369+
370370
close $FD;
371371

372372

373373

374374
delete $loadedTemplate->{reference};
375375
delete $loadedTemplate->{namespace};
376376

377+
if (!defined($loadedTemplate->{description})) {
378+
delete $loadedTemplate->{description};
379+
};
380+
377381
$self->loadTemplateList();
378382

379383
if (defined($self->getTemplateByName($loadedTemplate->{name}))) {
@@ -387,7 +391,7 @@ sub importTemplate {
387391

388392
my $operation = 'resources/json/delphix/database/template';
389393

390-
my ($result, $result_fmt, $retcode) = $self->{_dlpxObject}->postJSONData($operation, $json_data);
394+
my ($result, $result_fmt, $retcode) = $self->{_dlpxObject}->postJSONData($operation, $json_data);
391395

392396
if ($result->{status} eq 'OK') {
393397
print " Import completed\n";
@@ -400,15 +404,15 @@ sub importTemplate {
400404

401405

402406
# Procedure updateTemplate
403-
# parameters:
407+
# parameters:
404408
# - location - file name
405409
# Return 0 if no errors
406410

407411
sub updateTemplate {
408412
my $self = shift;
409413
my $location = shift;
410414

411-
logger($self->{_debug}, "Entering Template_obj::updateTemplate",1);
415+
logger($self->{_debug}, "Entering Template_obj::updateTemplate",1);
412416

413417
my $filename = $location;
414418

@@ -419,7 +423,7 @@ sub updateTemplate {
419423
local $/ = undef;
420424
my $json = JSON->new();
421425
$loadedTemplate = $json->decode(<$FD>);
422-
426+
423427
close $FD;
424428

425429
delete $loadedTemplate->{reference};
@@ -432,7 +436,7 @@ sub updateTemplate {
432436
if (! defined($self->getTemplateByName($loadedTemplate->{name}))) {
433437
print "Template " . $loadedTemplate->{name} . " from file $filename doesn't exist. Can't update.\n";
434438
return 1;
435-
}
439+
}
436440

437441
my $reference = $self->getTemplateByName($loadedTemplate->{name});
438442

@@ -442,7 +446,7 @@ sub updateTemplate {
442446

443447
my $operation = 'resources/json/delphix/database/template/' . $reference;
444448

445-
my ($result, $result_fmt, $retcode) = $self->{_dlpxObject}->postJSONData($operation, $json_data);
449+
my ($result, $result_fmt, $retcode) = $self->{_dlpxObject}->postJSONData($operation, $json_data);
446450

447451
if ($result->{status} eq 'OK') {
448452
print " Update completed\n";
@@ -458,10 +462,10 @@ sub updateTemplate {
458462
# parameters: none
459463
# Load a list of template objects from Delphix Engine
460464

461-
sub loadTemplateList
465+
sub loadTemplateList
462466
{
463467
my $self = shift;
464-
logger($self->{_debug}, "Entering Template_obj::loadTemplateList",1);
468+
logger($self->{_debug}, "Entering Template_obj::loadTemplateList",1);
465469

466470
my $operation = "resources/json/delphix/database/template";
467471
my ($result, $result_fmt) = $self->{_dlpxObject}->getJSONResult($operation);
@@ -473,10 +477,10 @@ sub loadTemplateList
473477

474478
for my $templateitem (@res) {
475479
$templates->{$templateitem->{reference}} = $templateitem;
476-
}
480+
}
477481
} else {
478482
print "No data returned for $operation. Try to increase timeout \n";
479483
}
480484
}
481485

482-
1;
486+
1;

0 commit comments

Comments
 (0)