-
Notifications
You must be signed in to change notification settings - Fork 344
/
t3c-update.go
94 lines (84 loc) · 3.5 KB
/
t3c-update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import (
"fmt"
"os"
"time"
"github.com/apache/trafficcontrol/cache-config/t3c-update/config"
"github.com/apache/trafficcontrol/cache-config/t3cutil"
"github.com/apache/trafficcontrol/cache-config/t3cutil/toreq"
"github.com/apache/trafficcontrol/cache-config/t3cutil/toreq/torequtil"
"github.com/apache/trafficcontrol/lib/go-log"
"github.com/apache/trafficcontrol/lib/go-tc"
)
// Version is the application version.
// This is overwritten by the build with the current project version.
var Version = "0.4"
// GitRevision is the git revision the application was built from.
// This is overwritten by the build with the current project version.
var GitRevision = "nogit"
func main() {
cfg, err := config.InitConfig(Version, GitRevision)
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %s\n", err.Error())
os.Exit(1)
} else {
log.Infoln("configuration initialized")
}
cfg.TCCfg.TOClient, err = toreq.New(
cfg.TOURL,
cfg.TOUser,
cfg.TOPass,
cfg.TOInsecure,
cfg.TOTimeoutMS,
cfg.UserAgent(),
)
if err != nil {
log.Errorf("%s\n", err)
os.Exit(2)
}
if cfg.TCCfg.TOClient.FellBack() {
log.Warnln("Traffic Ops does not support the latest version supported by this app! Falling back to previous major Traffic Ops API version!")
}
// *** Compatability requirement until ATC (v7.0+) is deployed with the timestamp features
// Use SetUpdateStatus is preferred
err = t3cutil.SetUpdateStatusCompat(cfg.TCCfg, tc.CacheName(cfg.TCCfg.CacheHostName), cfg.ConfigApplyTime, cfg.RevalApplyTime, cfg.ConfigApplyBool, cfg.RevalApplyBool)
if err != nil {
log.Errorf("%s, %s\n", err, cfg.TCCfg.CacheHostName)
os.Exit(3)
}
cur_status, err := t3cutil.GetServerUpdateStatus(cfg.TCCfg)
if err != nil {
log.Errorf("%s, %s\n", err, cfg.TCCfg.CacheHostName)
os.Exit(4)
}
// When comparing equality, it must be done with microsecond precision (Round not Truncate).
// This is because Postgres stores Microsecond precision. Round also drops the monotonic
// clock reading.
// t3c (Nano) -> client (Nano) -> TO (Nano) -> Postgres (Micro)
// Postgres (Micro) -> TO (Micro) -> client (Micro) -> here / t3c (Micro)
if cfg.ConfigApplyTime != nil && !(*cfg.ConfigApplyTime).Round(time.Microsecond).Equal((*cur_status.ConfigApplyTime).Round(time.Microsecond)) {
log.Errorf("Failed to set config_apply_time.\nSent: %v\nRecv: %v", *cfg.ConfigApplyTime, *cur_status.ConfigApplyTime)
}
if cfg.RevalApplyTime != nil && !(*cfg.RevalApplyTime).Round(time.Microsecond).Equal((*cur_status.RevalidateApplyTime).Round(time.Microsecond)) {
log.Errorf("Failed to set reval_apply_time.\nSent: %v\nRecv: %v", *cfg.RevalApplyTime, *cur_status.RevalidateApplyTime)
}
cfg.TCCfg.TOClient.WriteFsCookie(torequtil.CookieCachePath(cfg.TOUser))
}