You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2019/01/31 17:44:11 UTC

[trafficcontrol] branch master updated: Records.config ds profile parameters (#3279)

This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new dd32ff0  Records.config ds profile parameters (#3279)
dd32ff0 is described below

commit dd32ff0c7a87160890a148d2a064261fafdfd483
Author: Evan Zelkowitz <ev...@comcast.com>
AuthorDate: Thu Jan 31 09:44:06 2019 -0800

    Records.config ds profile parameters (#3279)
    
    * Allow DS profile to create records config overrides
    
    These changes allow you to put records.config parameters in to a DS profile and have them appear as remap overrides.  This is similar to how cachekey works in the DS profile. If the file given is for records.config then
    options are generated for the remaps from the DS in this manner:
    @plugin=conf_remap.so @pparam=param_name=value
    
    This way you can do parameter overrides without having to use raw remap.
    
    The parameters are expected to match the existing usages of records.config parameters in the scheme of:
    CONFIG paramater_name INT/STRING/FLOAT value
    
    outside of this the parameter will be rejected
    
    * Change param splitting to only 2 entries, allows for strings with spaces in case for some strange reason thats a thing
---
 .../app/lib/API/Configs/ApacheTrafficServer.pm     | 46 +++++++++++++++++++++-
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/traffic_ops/app/lib/API/Configs/ApacheTrafficServer.pm b/traffic_ops/app/lib/API/Configs/ApacheTrafficServer.pm
index d82ba50..212fab6 100755
--- a/traffic_ops/app/lib/API/Configs/ApacheTrafficServer.pm
+++ b/traffic_ops/app/lib/API/Configs/ApacheTrafficServer.pm
@@ -2636,7 +2636,7 @@ sub remap_dot_config {
 	my $server_obj = shift;
 	my $data;
 	my @text_array;
-
+	my %ats_var_types = map { $_ => 1 } qw(INT FLOAT STRING);
 
 	my $pdata = $self->param_data( $server_obj, 'package' );
 	my $header = $self->header_comment( $server_obj->host_name );
@@ -2671,6 +2671,27 @@ sub remap_dot_config {
 			if ( $ds->{range_request_handling} == RRH_CACHE_RANGE_REQUEST ) {
 				$mid_remap{ $ds->{org} } .= " \@plugin=cache_range_requests.so";
 			}
+
+			#Add DS profile records.config entries as overrided ATS parameters
+			if ( defined( $ds->{'param'}->{'records.config'} ) ) {
+				foreach my $rc_entry ( keys %{ $ds->{'param'}->{'records.config'} } ) {
+					my @rec_params = split(' ', $rc_entry, 3);
+
+					#Check that the parameter name matches the records.config syntax
+					if ( $rec_params[0] eq 'CONFIG') {
+						my @rec_values = split(' ', $ds->{'param'}->{'records.config'}->{$rc_entry}, 2);
+
+						#Check parameter value matches records.config syntax
+						if ( $ats_var_types{$rec_values[0]}) {
+							$mid_remap{ $ds->{org} } .= ' @plugin=conf_remap.so @pparam=' . $rec_params[1] . '=' . $rec_values[1];
+						} else {
+							$self->app->log->debug(" mid ds records.config entry did not match the known syntax for values");
+						}
+					} else {
+						$self->app->log->debug(" mid ds records.config entry did not match the known syntax for parameter names");
+					}
+				}
+			}		
 		}
 		foreach my $key ( keys %mid_remap ) {
 			my $remap_text .= "map " . $key . " " . $key . $mid_remap{$key} . "\n";
@@ -2717,7 +2738,7 @@ sub build_remap_line {
 	my $remap       = shift;
 	my $map_from    = shift;
 	my $map_to      = shift;
-
+	my %ats_var_types = map { $_ => 1 } qw(INT FLOAT STRING);
 
 
 	my $dscp      = $remap->{dscp};
@@ -2769,6 +2790,27 @@ sub build_remap_line {
 		}
 	}
 
+	#Add DS profile records.config entries as overrided ATS parameters
+	if ( defined( $remap->{'param'}->{'records.config'} ) ) {
+		foreach my $rc_entry ( keys %{ $remap->{'param'}->{'records.config'} } ) {
+			my @rec_params = split(' ', $rc_entry, 3);
+
+			#Check that the parameter name matches the records.config syntax
+			if ( $rec_params[0] eq 'CONFIG') {
+				my @rec_values = split(' ', $remap->{'param'}->{'records.config'}->{$rc_entry}, 2);
+
+				#Check parameter value matches records.config syntax
+				if ( $ats_var_types{$rec_values[0]}) {
+					$text .= ' @plugin=conf_remap.so @pparam=' . $rec_params[1] . '=' . $rec_values[1];
+				} else {
+					$self->app->log->debug(" ds records.config entry did not match the known syntax for values");
+				}
+			}  else {
+				$self->app->log->debug(" ds records.config entry did not match the known syntax for parameter names");
+			}
+		}
+	}	
+
 	# Note: should use full path here?
 	if ( defined( $remap->{regex_remap} ) && $remap->{regex_remap} ne "" ) {
 		$text .= " \@plugin=regex_remap.so \@pparam=regex_remap_" . $remap->{ds_xml_id} . ".config";