diff --git a/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index c5ab4ce9f..7f15b3496 100755 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -1255,9 +1255,11 @@ passed as argument rather than by table value', " FQDNfirst: Fully Qualified Domain Name first. If set to 1/yes/enable, the /etc/hosts \n" . " entries generated by 'makehosts' will put the FQDN before the PQDN(Partially \n" . " Qualified Domain Name). Otherwise, the original behavior will be performed.\n\n" . -" hierarchicalattrs: Table attributes(e.g. postscripts, postbootscripts) that will be\n" . -" included hierarchically. Attribute values for all the node's groups\n" . +" hierarchicalattrs: A comma delimited list of table attributes(e.g. postscripts, postbootscripts)\n" . +" that will be included hierarchically. Attribute values for all the node's groups\n" . " will be applied to the node in the groups' order except the repeat one.\n" . +" By default, comma is used to combine the values. But some columns use different \n" . +" delimiter, to specify delimiter for those columns as format of 'column:delimiter'.\n\n" . " dbtracelevel: The trace level for the database access log. To activate this setting, please. \n". " restart xcatd or send HUP signal to the 'xcatd: DB Access' process, Like: .\n". " ps -ef | grep 'xcatd: DB Access' | grep -v grep | awk '{print \$2}' | xargs kill -HUP \n". diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 103f8a09a..36ecc10fa 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -2324,12 +2324,8 @@ sub getNodesAttribs { } if (!exists($options{hierarchy_attrs})) { - my @hierarchy_attrs = (); - my $hierarchy_field = xCAT::TableUtils->get_site_attribute("hierarchicalattrs"); - if ($hierarchy_field) { - @hierarchy_attrs = split(/,/, $hierarchy_field); - } - $options{hierarchy_attrs} = \@hierarchy_attrs; + my $hierarchy_field = xCAT::TableUtils->getHierarchyAttrs(); + $options{hierarchy_attrs} = $hierarchy_field; } if ($dbworkerpid > 0) { @@ -2359,12 +2355,6 @@ sub getNodesAttribs { $self->{nodelist}->{_use_cache} = 1; } my $rethash; - #my @hierarchy_attrs = (); - #my $hierarchy_field = xCAT::TableUtils->get_site_attribute("hierarchicalattrs"); - #if ($hierarchy_field) { - # @hierarchy_attrs = split(/,/, $hierarchy_field); - #} - #$options{hierarchy_attrs} = \@hierarchy_attrs; foreach (@$nodelist) { my @nodeentries = $self->getNodeAttribs($_, \@realattribs, %options); $rethash->{$_} = \@nodeentries; #$self->getNodeAttribs($_,\@attribs); @@ -2755,12 +2745,8 @@ sub getNodeAttribs } if (!exists($options{hierarchy_attrs})) { - my @hierarchy_attrs = (); - my $hierarchy_field = xCAT::TableUtils->get_site_attribute("hierarchicalattrs"); - if ($hierarchy_field) { - @hierarchy_attrs = split(/,/, $hierarchy_field); - } - $options{hierarchy_attrs} = \@hierarchy_attrs; + my $hierarchy_field = xCAT::TableUtils->getHierarchyAttrs(); + $options{hierarchy_attrs} = $hierarchy_field; } if ($dbworkerpid > 0) { #TODO: should this be moved outside of the DB worker entirely? I'm thinking so, but I don't dare do so right now... #the benefit would be the potentially computationally intensive substitution logic would be moved out and less time inside limited @@ -3005,14 +2991,15 @@ sub getNodeAttribs_nosub_returnany my $attrib; my $result; - my @hierarchy_attrs = @{ $options{hierarchy_attrs} }; + my $hierarchy_attrs = $options{hierarchy_attrs}; my $data = $results[0]; if (defined {$data}) { #if there was some data for the node, loop through and check it foreach $result (@results) { foreach $attrib (keys %attribsToDo) { if (defined($result) && defined($result->{$attrib}) && $self->{tabname} ne 'nodelist' - && @hierarchy_attrs && grep (/^$attrib$/, @hierarchy_attrs)) { - $result->{$attrib} .= ',+=NEXTRECORD'; + && ref($hierarchy_attrs) eq "HASH" && exists $hierarchy_attrs->{$attrib}) { + $result->{$attrib} .= $hierarchy_attrs->{$attrib}; + $result->{$attrib} .= '+=NEXTRECORD'; } #check each item in the results to see which attributes were satisfied @@ -3072,8 +3059,9 @@ sub getNodeAttribs_nosub_returnany $attribsDone{$attrib} = 0; # for hierarchy attribute, append attributes from all the node's group - if (@hierarchy_attrs && grep (/^$attrib$/, @hierarchy_attrs)) { - $groupResult->{$attrib} .= ',+=NEXTRECORD'; + if (ref($hierarchy_attrs) eq "HASH" && exists $hierarchy_attrs->{$attrib}) { + $groupResult->{$attrib} .= $hierarchy_attrs->{$attrib}; + $groupResult->{$attrib} .= '+=NEXTRECORD'; } foreach $result (@results) { #loop through our existing results to add or modify the value for this attribute if (defined($result)) { @@ -3160,13 +3148,13 @@ sub getNodeAttribs_nosub_returnany for $result (@results) { for my $key (keys %$result) { $result->{$key} =~ s/\+=NEXTRECORD//g; - if (@hierarchy_attrs && grep (/^$key$/, @hierarchy_attrs)) { - my @attribs = split(/,/, $result->{$key}); + if (ref($hierarchy_attrs) eq "HASH" && exists $hierarchy_attrs->{$key}) { + my @attribs = split(/\Q$hierarchy_attrs->{$key}/, $result->{$key}); my %count; # remove the repeat value @attribs = grep { ++$count{$_} < 2; } @attribs; - $result->{$key} = join(',', @attribs); + $result->{$key} = join($hierarchy_attrs->{$key}, @attribs); } } } @@ -3430,11 +3418,7 @@ sub getAllNodeAttribs $self->{_use_cache} = 1; $self->{nodelist}->{_use_cache} = 1; - my @hierarchy_attrs = (); - my $hierarchy_field = xCAT::TableUtils->get_site_attribute("hierarchicalattrs"); - if ($hierarchy_field) { - @hierarchy_attrs = split(/,/, $hierarchy_field); - } + my $hierarchy_field = xCAT::TableUtils->getHierarchyAttrs(); while (my $data = $query->fetchrow_hashref()) { @@ -3462,7 +3446,7 @@ sub getAllNodeAttribs # @hierarchy_attrs = split(/,/, $hierarchy_field); #} my %options = (); - $options{hierarchy_attrs} = \@hierarchy_attrs; + $options{hierarchy_attrs} = $hierarchy_field; foreach (@nodes) { if ($donenodes{$_}) { next; } diff --git a/perl-xCAT/xCAT/TableUtils.pm b/perl-xCAT/xCAT/TableUtils.pm index 472a2aedc..dc18128da 100755 --- a/perl-xCAT/xCAT/TableUtils.pm +++ b/perl-xCAT/xCAT/TableUtils.pm @@ -1533,6 +1533,51 @@ sub get_site_Master } +#-------------------------------------------------------------------------------- + +=head3 getHierarchyAttrs + + Get the global hierarchy attributes in site table, and parse the corresponding delimiter. + + Arguments: + none + Returns: + Hash reference of hierarchy attributes defined at site.hierarchicalattrs. + { + 'begin' => '|', + 'postscripts' => ',' + } + Globals: + none + Error: + none + Example: + $attrs = xCAT::TableUtils->getHierarchyAttrs(); + Comments: + none + +=cut + +#-------------------------------------------------------------------------------- + +sub getHierarchyAttrs +{ + my %hierarchy_attrs = (); + my $hierarchy_field = xCAT::TableUtils->get_site_attribute("hierarchicalattrs"); + if ($hierarchy_field) { + # $hierarchy_field should be `attr1_name:delimiter1,attr2,attr3:delimiter2` + foreach my $item (split(/,/, $hierarchy_field)) { + $item = xCAT::Utils->strim($item); + next unless ($item); + my ($attr, $del) = split(/\s*:\s*/, $item, 2); + $del = ',' unless ($del); + $hierarchy_attrs{$attr} = $del if ($attr); + } + } + + return \%hierarchy_attrs; +} + #------------------------------------------------------------------------------- =head3 checkCredFiles