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

neuman 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 5693451  Change ORT/atstccfg to use TO Proxy (#4609)
5693451 is described below

commit 5693451bb898f62d0e14afa60a9af9824d3c8e06
Author: Robert O Butts <[email protected]>
AuthorDate: Fri Apr 10 13:37:13 2020 -0600

    Change ORT/atstccfg to use TO Proxy (#4609)
---
 traffic_ops/ort/atstccfg/cfgfile/cfgfile.go | 44 +++++++++++++++++++++--------
 traffic_ops/ort/atstccfg/config/config.go   |  4 +++
 traffic_ops/ort/traffic_ops_ort.pl          | 27 ++++++++++--------
 3 files changed, 52 insertions(+), 23 deletions(-)

diff --git a/traffic_ops/ort/atstccfg/cfgfile/cfgfile.go 
b/traffic_ops/ort/atstccfg/cfgfile/cfgfile.go
index 40b1aaa..a3f554f 100644
--- a/traffic_ops/ort/atstccfg/cfgfile/cfgfile.go
+++ b/traffic_ops/ort/atstccfg/cfgfile/cfgfile.go
@@ -34,6 +34,8 @@ import (
        "github.com/apache/trafficcontrol/traffic_ops/ort/atstccfg/toreq"
 )
 
+const TrafficOpsProxyParameterName = `tm.rev_proxy.url`
+
 // TODO: validate all "profile scope" files are the server's profile.
 //       If they ever weren't, we'll send bad data, because we're only getting 
the server's profile data.
 //       Getting all data for all profiles in TOData isn't reasonable.
@@ -44,6 +46,36 @@ func GetTOData(cfg config.TCCfg) (*config.TOData, error) {
 
        toData := &config.TOData{}
 
+       globalParams, err := cfg.TOClient.GetGlobalParameters()
+       if err != nil {
+               return nil, errors.New("getting global parameters: " + 
err.Error())
+       }
+       toData.GlobalParams = globalParams
+       toData.TOToolName, toData.TOURL = 
toreq.GetTOToolNameAndURL(globalParams)
+
+       if !cfg.DisableProxy {
+               toProxyURLStr := ""
+               for _, param := range globalParams {
+                       if param.Name == TrafficOpsProxyParameterName {
+                               toProxyURLStr = param.Value
+                               break
+                       }
+               }
+               if toProxyURLStr != "" {
+                       realTOURL := cfg.TOClient.C.URL
+                       cfg.TOClient.C.URL = toProxyURLStr
+                       log.Infoln("using Traffic Ops proxy '" + toProxyURLStr 
+ "'")
+                       if _, _, err := cfg.TOClient.C.GetCDNs(); err != nil {
+                               log.Warnln("Traffic Ops proxy '" + 
toProxyURLStr + "' failed to get CDNs, falling back to real Traffic Ops")
+                               cfg.TOClient.C.URL = realTOURL
+                       }
+               } else {
+                       log.Infoln("Traffic Ops proxy enabled, but GLOBAL 
Parameter '" + TrafficOpsProxyParameterName + "' missing or empty, not using 
proxy")
+               }
+       } else {
+               log.Infoln("Traffic Ops proxy is disabled, not checking or 
using GLOBAL Parameter '" + TrafficOpsProxyParameterName)
+       }
+
        serversF := func() error {
                defer func(start time.Time) { log.Infof("serversF took %v\n", 
time.Since(start)) }(time.Now())
                // TODO TOAPI add /servers?cdn=1 query param
@@ -192,16 +224,6 @@ func GetTOData(cfg config.TCCfg) (*config.TOData, error) {
                toData.CacheGroups = cacheGroups
                return nil
        }
-       globalParamsF := func() error {
-               defer func(start time.Time) { log.Infof("globalParamsF took 
%v\n", time.Since(start)) }(time.Now())
-               globalParams, err := cfg.TOClient.GetGlobalParameters()
-               if err != nil {
-                       return errors.New("getting global parameters: " + 
err.Error())
-               }
-               toData.GlobalParams = globalParams
-               toData.TOToolName, toData.TOURL = 
toreq.GetTOToolNameAndURL(globalParams)
-               return nil
-       }
        scopeParamsF := func() error {
                defer func(start time.Time) { log.Infof("scopeParamsF took 
%v\n", time.Since(start)) }(time.Now())
                scopeParams, err := cfg.TOClient.GetParametersByName("scope")
@@ -279,7 +301,7 @@ func GetTOData(cfg config.TCCfg) (*config.TOData, error) {
                return nil
        }
 
-       fs := []func() error{dssF, serversF, cgF, globalParamsF, scopeParamsF, 
jobsF}
+       fs := []func() error{dssF, serversF, cgF, scopeParamsF, jobsF}
        if !cfg.RevalOnly {
                // skip data not needed for reval, if we're reval-only
                fs = append([]func() error{dsrF, cacheKeyParamsF, 
parentConfigParamsF, capsF, dsCapsF}, fs...)
diff --git a/traffic_ops/ort/atstccfg/config/config.go 
b/traffic_ops/ort/atstccfg/config/config.go
index de841d1..f8303cc 100644
--- a/traffic_ops/ort/atstccfg/config/config.go
+++ b/traffic_ops/ort/atstccfg/config/config.go
@@ -50,6 +50,7 @@ var ErrBadRequest = errors.New("bad request")
 
 type Cfg struct {
        CacheHostName   string
+       DisableProxy    bool
        GetData         string
        ListPlugins     bool
        LogLocationErr  string
@@ -97,6 +98,7 @@ func GetCfg() (Cfg, error) {
        setQueueStatusPtr := flag.StringP("set-queue-status", "q", "", "POSTs 
to Traffic Ops setting the queue status of the server. Must be 'true' or 
'false'. Requires --set-reval-status also be set")
        setRevalStatusPtr := flag.StringP("set-reval-status", "a", "", "POSTs 
to Traffic Ops setting the revaliate status of the server. Must be 'true' or 
'false'. Requires --set-queue-status also be set")
        revalOnlyPtr := flag.BoolP("revalidate-only", "y", false, "Whether to 
exclude files not named 'regex_revalidate.config'")
+       disableProxyPtr := flag.BoolP("traffic-ops-disable-proxy", "p", false, 
"Whether to not use the Traffic Ops proxy specified in the GLOBAL Parameter 
tm.rev_proxy.url")
 
        flag.Parse()
 
@@ -125,6 +127,7 @@ func GetCfg() (Cfg, error) {
        setQueueStatus := *setQueueStatusPtr
        setRevalStatus := *setRevalStatusPtr
        revalOnly := *revalOnlyPtr
+       disableProxy := *disableProxyPtr
 
        urlSourceStr := "argument" // for error messages
        if toURL == "" {
@@ -175,6 +178,7 @@ func GetCfg() (Cfg, error) {
                SetRevalStatus:  setRevalStatus,
                SetQueueStatus:  setQueueStatus,
                RevalOnly:       revalOnly,
+               DisableProxy:    disableProxy,
        }
        if err := log.InitCfg(cfg); err != nil {
                return Cfg{}, errors.New("Initializing loggers: " + err.Error() 
+ "\n")
diff --git a/traffic_ops/ort/traffic_ops_ort.pl 
b/traffic_ops/ort/traffic_ops_ort.pl
index 51711ef..8a353bb 100755
--- a/traffic_ops/ort/traffic_ops_ort.pl
+++ b/traffic_ops/ort/traffic_ops_ort.pl
@@ -158,6 +158,11 @@ if (length $to_timeout_ms > 0) {
 
 my $atstccfg_cmd = '/opt/ort/atstccfg';
 
+my $atstccfg_arg_disable_proxy = '';
+if ($rev_proxy_disable != 0) {
+       $atstccfg_arg_disable_proxy = '--traffic-ops-disable-proxy';
+}
+
 my $TMP_BASE  = "/tmp/ort";
 my $atstccfg_log_path = $TMP_BASE . '/atstccfg.log';
 
@@ -741,7 +746,7 @@ sub send_update_to_trops {
                $reval_str='true';
        }
 
-       my $response = `$atstccfg_cmd $atstccfg_timeout_arg 
--traffic-ops-user='$TO_USER' --traffic-ops-password='$TO_PASS' 
--traffic-ops-url='$TO_URL' --cache-host-name='$hostname_short' 
--log-location-error=stderr --log-location-warning=stderr 
--log-location-info=null --set-queue-status=$upd_str 
--set-reval-status=$reval_str 2>$atstccfg_log_path`;
+       my $response = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null 
--set-queue-status=$upd_str --set-reval-status=$reval_str 2>$atstccfg_log_path`;
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {
                ( $log_level >> $ERROR ) && printf("ERROR sending update status 
with atstccfg (via Traffic Ops). See $atstccfg_log_path.\n");
@@ -751,7 +756,7 @@ sub send_update_to_trops {
 }
 
 sub get_update_status {
-       my $upd_ref = `$atstccfg_cmd $atstccfg_timeout_arg 
--traffic-ops-user='$TO_USER' --traffic-ops-password='$TO_PASS' 
--traffic-ops-url='$TO_URL' --cache-host-name='$hostname_short' 
--log-location-error=stderr --log-location-warning=stderr 
--log-location-info=null --get-data=update-status 2>$atstccfg_log_path`;
+       my $upd_ref = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=update-status 
2>$atstccfg_log_path`;
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {
                ( $log_level >> $ERROR ) && printf("ERROR getting update status 
from atstccfg (via Traffic Ops). See $atstccfg_log_path.\n");
@@ -762,7 +767,7 @@ sub get_update_status {
 
        ##Some versions of Traffic Ops had the 1.3 API but did not have the 
use_reval_pending field.  If this field is not present, exit.
        if ( !defined( $upd_json->{'use_reval_pending'} ) ) {
-               my $info_ref = `$atstccfg_cmd $atstccfg_timeout_arg 
--traffic-ops-user='$TO_USER' --traffic-ops-password='$TO_PASS' 
--traffic-ops-url='$TO_URL' --cache-host-name='$hostname_short' 
--log-location-error=stderr --log-location-warning=stderr 
--log-location-info=null --get-data=system-info 2>$atstccfg_log_path`;
+               my $info_ref = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=system-info 
2>$atstccfg_log_path`;
                my $atstccfg_exit_code = $?;
                if ($atstccfg_exit_code != 0) {
                        ( $log_level >> $ERROR ) && printf("ERROR Unable to get 
status of use_reval_pending parameter.  Stopping.\n");
@@ -817,7 +822,7 @@ sub check_revalidate_state {
                        ( $log_level >> $ERROR ) && print "ERROR Traffic Ops is 
signaling that no revalidations are waiting to be applied.\n";
                }
 
-               my $stj = `$atstccfg_cmd $atstccfg_timeout_arg 
--traffic-ops-user='$TO_USER' --traffic-ops-password='$TO_PASS' 
--traffic-ops-url='$TO_URL' --cache-host-name='$hostname_short' 
--log-location-error=stderr --log-location-warning=stderr 
--log-location-info=null --get-data=statuses 2>$atstccfg_log_path`;
+               my $stj = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=statuses 
2>$atstccfg_log_path`;
                my $atstccfg_exit_code = $?;
                if ( $atstccfg_exit_code != 0 ) {
                        ( $log_level >> $ERROR ) && print "Statuses URL: 
returned $stj! Skipping creation of status file.\n";
@@ -936,7 +941,7 @@ sub check_syncds_state {
                        ( $log_level >> $ERROR ) && print "ERROR Traffic Ops is 
signaling that no update is waiting to be applied.\n";
                }
 
-               my $stj = `$atstccfg_cmd $atstccfg_timeout_arg 
--traffic-ops-user='$TO_USER' --traffic-ops-password='$TO_PASS' 
--traffic-ops-url='$TO_URL' --cache-host-name='$hostname_short' 
--log-location-error=stderr --log-location-warning=stderr 
--log-location-info=null --get-data=statuses 2>$atstccfg_log_path`;
+               my $stj = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=statuses 
2>$atstccfg_log_path`;
                my $atstccfg_exit_code = $?;
                if ( $atstccfg_exit_code != 0 ) {
                        ( $log_level >> $ERROR ) && print "Statuses URL: 
returned $stj! Skipping creation of status file.\n";
@@ -1578,7 +1583,7 @@ sub get_cfg_file_list {
                $atstccfg_reval_arg = '--revalidate-only';
        }
 
-       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
--traffic-ops-user='$TO_USER' --traffic-ops-password='$TO_PASS' 
--traffic-ops-url='$TO_URL' --cache-host-name='$host_name' $atstccfg_reval_arg 
--log-location-error=stderr --log-location-warning=stderr 
--log-location-info=null 2>$atstccfg_log_path`;
+       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$host_name' $atstccfg_reval_arg --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null 2>$atstccfg_log_path`;
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {
                ( $log_level >> $ERROR ) && printf("ERROR getting config files 
from atstccfg via Traffic Ops. See $atstccfg_log_path for details\n");
@@ -1654,7 +1659,7 @@ sub parse_multipart_config_files {
 sub get_header_comment {
        my $toolname;
 
-       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
--traffic-ops-user='$TO_USER' --traffic-ops-password='$TO_PASS' 
--traffic-ops-url='$TO_URL' --cache-host-name='$hostname_short' 
--log-location-error=stderr --log-location-warning=stderr 
--log-location-info=null --get-data=system-info 2>$atstccfg_log_path`;
+       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=system-info 
2>$atstccfg_log_path`;
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {
                        ( $log_level >> $ERROR ) && printf("ERROR Unable to get 
system info. Stopping.\n");
@@ -1762,12 +1767,9 @@ sub package_installed {
        }
 
        if ( exists( $packages_installed{$package_name} ) ) {
-               print("package_installed $package_name (cached)\n");
                return ($packages_installed{$package_name});
        }
 
-       print("package_installed $package_name (uncached)\n");
-
        my $out = `/bin/rpm -q $package_name 2>&1`;
 
        # rpm returns 0 if installed, 1 if not installed
@@ -1832,7 +1834,7 @@ sub process_packages {
 
        my $proceed = 0;
 
-       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
--traffic-ops-user='$TO_USER' --traffic-ops-password='$TO_PASS' 
--traffic-ops-url='$TO_URL' --cache-host-name='$hostname_short' 
--log-location-error=stderr --log-location-warning=stderr 
--log-location-info=null --get-data=packages 2>$atstccfg_log_path`;
+       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=packages 
2>$atstccfg_log_path`;
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {
                ( $log_level >> $FATAL ) && print "FATAL Error getting package 
list from Traffic Ops!\n";
@@ -2078,7 +2080,8 @@ sub process_chkconfig {
 
        my $proceed = 0;
 
-       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
--traffic-ops-user='$TO_USER' --traffic-ops-password='$TO_PASS' 
--traffic-ops-url='$TO_URL' --cache-host-name='$hostname_short' 
--log-location-error=stderr --log-location-warning=stderr 
--log-location-info=null --get-data=chkconfig 2>$atstccfg_log_path`;
+       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=chkconfig 
2>$atstccfg_log_path`;
+
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {
                ( $log_level >> $FATAL ) && print "FATAL Error getting package 
list from Traffic Ops!\n";

Reply via email to