You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/07/16 18:41:19 UTC

[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #4861: Add ORT Inferring Location Parameters

ocket8888 commented on a change in pull request #4861:
URL: https://github.com/apache/trafficcontrol/pull/4861#discussion_r455986929



##########
File path: lib/go-atscfg/meta.go
##########
@@ -63,6 +87,146 @@ func MetaObjToMetaConfig(atsData tc.ATSConfigMetaData) string {
 	return string(bts)
 }
 
+// AddMetaObjConfigDir takes the Meta Object generated from TO data, and the ATS config directory
+// and prepends the config directory to all relative paths,
+// and creates MetaObj entries for all required config files which have no location parameter.
+// If configDir is empty and any location Parameters have relative paths, returns an error.
+func AddMetaObjConfigDir(
+	metaObj tc.ATSConfigMetaData,
+	configDir string,
+	serverHostName tc.CacheName,
+	server *ServerInfo,
+	tmURL string, // global tm.url Parameter
+	tmReverseProxyURL string, // global tm.rev_proxy.url Parameter
+	locationParams map[string]ConfigProfileParams, // map[configFile]params; 'location' and 'URL' Parameters on serverHostName's Profile
+	uriSignedDSes []tc.DeliveryServiceName,
+	scopeParams map[string]string, // map[configFileName]scopeParam
+	dses map[tc.DeliveryServiceName]tc.DeliveryServiceNullable,
+) (tc.ATSConfigMetaData, error) {
+
+	// Note there may be multiple files with the same name in different directories.
+	configFilesM := map[string][]tc.ATSConfigMetaDataConfigFile{} // map[fileShortName]tc.ATSConfigMetaDataConfigFile
+	for _, fi := range metaObj.ConfigFiles {
+		configFilesM[fi.FileNameOnDisk] = append(configFilesM[fi.FileNameOnDisk], fi)
+	}
+
+	// add all strictly required files, all of which should be in the base config directory.
+	// If they don't exist, create them.
+	// If they exist with a relative path, prepend configDir.
+	// If any exist with a relative path, or don't exist, and configDir is empty, return an error.
+	for _, fileName := range requiredFiles() {
+		if _, ok := configFilesM[fileName]; ok {
+			continue
+		}
+		if configDir == "" {
+			return metaObj, errors.New("required file '" + fileName + "' has no location Parameter, and ATS config directory not found.")
+		}
+		configFilesM[fileName] = []tc.ATSConfigMetaDataConfigFile{{
+			FileNameOnDisk: fileName,
+			Location:       configDir,
+			Scope:          string(getServerScope(fileName, server.Type, nil)),
+		}}
+	}
+
+	for fileName, fis := range configFilesM {
+		newFis := []tc.ATSConfigMetaDataConfigFile{}

Review comment:
       Since you know ahead of time what the size of this needs to be, you can allocate: `newFis := make([]tc.ATSConfigMetaDataConfigFile, 0, len(fis))` to avoid possible multiple reallocations.

##########
File path: lib/go-atscfg/meta.go
##########
@@ -40,6 +41,23 @@ type ConfigProfileParams struct {
 // TODO change the config system to not use old API paths, and remove this.
 const APIVersion = "2.0"
 
+// RequiredFiles is a constant (because Go doesn't allow const slices).

Review comment:
       nit, but it's `requiredFiles`, not `RequiredFiles`.

##########
File path: traffic_ops_ort/traffic_ops_ort.pl
##########
@@ -1583,7 +1605,7 @@ sub get_cfg_file_list {
 		$atstccfg_reval_arg = '--revalidate-only';
 	}
 
-	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 $result = `$atstccfg_cmd --dir='$ats_config_dir' $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`;

Review comment:
       Am I missing something? It doesn't look like you added this option-argument to `traffic_ops_ort/atstccfg/config/config.go`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org