Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright 2017 gRPC authors.
|
|
|
|
*
|
|
|
|
* Licensed 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2019-12-03 08:18:49 -05:00
|
|
|
"sync"
|
|
|
|
"time"
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
|
2019-12-03 08:18:49 -05:00
|
|
|
"google.golang.org/grpc/balancer"
|
|
|
|
"google.golang.org/grpc/credentials"
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
"google.golang.org/grpc/internal/channelz"
|
2019-12-03 08:18:49 -05:00
|
|
|
"google.golang.org/grpc/internal/grpcsync"
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
"google.golang.org/grpc/resolver"
|
2019-12-03 08:18:49 -05:00
|
|
|
"google.golang.org/grpc/serviceconfig"
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// ccResolverWrapper is a wrapper on top of cc for resolvers.
|
2020-03-25 15:15:46 -04:00
|
|
|
// It implements resolver.ClientConn interface.
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
type ccResolverWrapper struct {
|
2019-12-03 08:18:49 -05:00
|
|
|
cc *ClientConn
|
|
|
|
resolverMu sync.Mutex
|
|
|
|
resolver resolver.Resolver
|
|
|
|
done *grpcsync.Event
|
|
|
|
curState resolver.State
|
|
|
|
|
|
|
|
pollingMu sync.Mutex
|
|
|
|
polling chan struct{}
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
}
|
|
|
|
|
2020-03-25 15:15:46 -04:00
|
|
|
// newCCResolverWrapper uses the resolver.Builder to build a Resolver and
|
|
|
|
// returns a ccResolverWrapper object which wraps the newly built resolver.
|
|
|
|
func newCCResolverWrapper(cc *ClientConn, rb resolver.Builder) (*ccResolverWrapper, error) {
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
ccr := &ccResolverWrapper{
|
2019-12-03 08:18:49 -05:00
|
|
|
cc: cc,
|
|
|
|
done: grpcsync.NewEvent(),
|
|
|
|
}
|
|
|
|
|
|
|
|
var credsClone credentials.TransportCredentials
|
|
|
|
if creds := cc.dopts.copts.TransportCredentials; creds != nil {
|
|
|
|
credsClone = creds.Clone()
|
|
|
|
}
|
2020-03-25 15:15:46 -04:00
|
|
|
rbo := resolver.BuildOptions{
|
2019-12-03 08:18:49 -05:00
|
|
|
DisableServiceConfig: cc.dopts.disableServiceConfig,
|
|
|
|
DialCreds: credsClone,
|
|
|
|
CredsBundle: cc.dopts.copts.CredsBundle,
|
|
|
|
Dialer: cc.dopts.copts.Dialer,
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
2019-12-03 08:18:49 -05:00
|
|
|
// We need to hold the lock here while we assign to the ccr.resolver field
|
|
|
|
// to guard against a data race caused by the following code path,
|
|
|
|
// rb.Build-->ccr.ReportError-->ccr.poll-->ccr.resolveNow, would end up
|
|
|
|
// accessing ccr.resolver which is being assigned here.
|
|
|
|
ccr.resolverMu.Lock()
|
2020-03-25 15:15:46 -04:00
|
|
|
defer ccr.resolverMu.Unlock()
|
2019-12-03 08:18:49 -05:00
|
|
|
ccr.resolver, err = rb.Build(cc.parsedTarget, ccr, rbo)
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return ccr, nil
|
|
|
|
}
|
|
|
|
|
2020-03-25 15:15:46 -04:00
|
|
|
func (ccr *ccResolverWrapper) resolveNow(o resolver.ResolveNowOptions) {
|
2019-12-03 08:18:49 -05:00
|
|
|
ccr.resolverMu.Lock()
|
|
|
|
if !ccr.done.HasFired() {
|
|
|
|
ccr.resolver.ResolveNow(o)
|
|
|
|
}
|
|
|
|
ccr.resolverMu.Unlock()
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ccr *ccResolverWrapper) close() {
|
2019-12-03 08:18:49 -05:00
|
|
|
ccr.resolverMu.Lock()
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
ccr.resolver.Close()
|
2019-12-03 08:18:49 -05:00
|
|
|
ccr.done.Fire()
|
|
|
|
ccr.resolverMu.Unlock()
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
}
|
|
|
|
|
2019-12-03 08:18:49 -05:00
|
|
|
// poll begins or ends asynchronous polling of the resolver based on whether
|
|
|
|
// err is ErrBadResolverState.
|
|
|
|
func (ccr *ccResolverWrapper) poll(err error) {
|
|
|
|
ccr.pollingMu.Lock()
|
|
|
|
defer ccr.pollingMu.Unlock()
|
|
|
|
if err != balancer.ErrBadResolverState {
|
|
|
|
// stop polling
|
|
|
|
if ccr.polling != nil {
|
|
|
|
close(ccr.polling)
|
|
|
|
ccr.polling = nil
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ccr.polling != nil {
|
|
|
|
// already polling
|
|
|
|
return
|
|
|
|
}
|
|
|
|
p := make(chan struct{})
|
|
|
|
ccr.polling = p
|
|
|
|
go func() {
|
|
|
|
for i := 0; ; i++ {
|
2020-03-25 15:15:46 -04:00
|
|
|
ccr.resolveNow(resolver.ResolveNowOptions{})
|
2019-12-03 08:18:49 -05:00
|
|
|
t := time.NewTimer(ccr.cc.dopts.resolveNowBackoff(i))
|
|
|
|
select {
|
|
|
|
case <-p:
|
|
|
|
t.Stop()
|
|
|
|
return
|
|
|
|
case <-ccr.done.Done():
|
|
|
|
// Resolver has been closed.
|
|
|
|
t.Stop()
|
|
|
|
return
|
|
|
|
case <-t.C:
|
|
|
|
select {
|
|
|
|
case <-p:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
// Timer expired; re-resolve.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2019-05-30 17:25:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ccr *ccResolverWrapper) UpdateState(s resolver.State) {
|
2019-12-03 08:18:49 -05:00
|
|
|
if ccr.done.HasFired() {
|
2019-05-30 17:25:43 -04:00
|
|
|
return
|
|
|
|
}
|
2020-03-25 15:15:46 -04:00
|
|
|
channelz.Infof(ccr.cc.channelzID, "ccResolverWrapper: sending update to cc: %v", s)
|
2019-05-30 17:25:43 -04:00
|
|
|
if channelz.IsOn() {
|
|
|
|
ccr.addChannelzTraceEvent(s)
|
|
|
|
}
|
|
|
|
ccr.curState = s
|
2019-12-03 08:18:49 -05:00
|
|
|
ccr.poll(ccr.cc.updateResolverState(ccr.curState, nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ccr *ccResolverWrapper) ReportError(err error) {
|
|
|
|
if ccr.done.HasFired() {
|
|
|
|
return
|
|
|
|
}
|
2020-03-25 15:15:46 -04:00
|
|
|
channelz.Warningf(ccr.cc.channelzID, "ccResolverWrapper: reporting error to cc: %v", err)
|
2019-12-03 08:18:49 -05:00
|
|
|
ccr.poll(ccr.cc.updateResolverState(resolver.State{}, err))
|
2019-05-30 17:25:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAddress is called by the resolver implementation to send addresses to gRPC.
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
func (ccr *ccResolverWrapper) NewAddress(addrs []resolver.Address) {
|
2019-12-03 08:18:49 -05:00
|
|
|
if ccr.done.HasFired() {
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
return
|
|
|
|
}
|
2020-03-25 15:15:46 -04:00
|
|
|
channelz.Infof(ccr.cc.channelzID, "ccResolverWrapper: sending new addresses to cc: %v", addrs)
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
if channelz.IsOn() {
|
2019-05-30 17:25:43 -04:00
|
|
|
ccr.addChannelzTraceEvent(resolver.State{Addresses: addrs, ServiceConfig: ccr.curState.ServiceConfig})
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
}
|
2019-05-30 17:25:43 -04:00
|
|
|
ccr.curState.Addresses = addrs
|
2019-12-03 08:18:49 -05:00
|
|
|
ccr.poll(ccr.cc.updateResolverState(ccr.curState, nil))
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:25:43 -04:00
|
|
|
// NewServiceConfig is called by the resolver implementation to send service
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
// configs to gRPC.
|
|
|
|
func (ccr *ccResolverWrapper) NewServiceConfig(sc string) {
|
2019-12-03 08:18:49 -05:00
|
|
|
if ccr.done.HasFired() {
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
return
|
|
|
|
}
|
2020-03-25 15:15:46 -04:00
|
|
|
channelz.Infof(ccr.cc.channelzID, "ccResolverWrapper: got new service config: %v", sc)
|
|
|
|
if ccr.cc.dopts.disableServiceConfig {
|
|
|
|
channelz.Info(ccr.cc.channelzID, "Service config lookups disabled; ignoring config")
|
|
|
|
return
|
|
|
|
}
|
2019-12-03 08:18:49 -05:00
|
|
|
scpr := parseServiceConfig(sc)
|
|
|
|
if scpr.Err != nil {
|
2020-03-25 15:15:46 -04:00
|
|
|
channelz.Warningf(ccr.cc.channelzID, "ccResolverWrapper: error parsing service config: %v", scpr.Err)
|
2019-12-03 08:18:49 -05:00
|
|
|
ccr.poll(balancer.ErrBadResolverState)
|
|
|
|
return
|
|
|
|
}
|
2019-05-30 17:25:43 -04:00
|
|
|
if channelz.IsOn() {
|
2019-12-03 08:18:49 -05:00
|
|
|
ccr.addChannelzTraceEvent(resolver.State{Addresses: ccr.curState.Addresses, ServiceConfig: scpr})
|
2019-05-30 17:25:43 -04:00
|
|
|
}
|
2019-12-03 08:18:49 -05:00
|
|
|
ccr.curState.ServiceConfig = scpr
|
|
|
|
ccr.poll(ccr.cc.updateResolverState(ccr.curState, nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ccr *ccResolverWrapper) ParseServiceConfig(scJSON string) *serviceconfig.ParseResult {
|
|
|
|
return parseServiceConfig(scJSON)
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:25:43 -04:00
|
|
|
func (ccr *ccResolverWrapper) addChannelzTraceEvent(s resolver.State) {
|
|
|
|
var updates []string
|
2019-12-03 08:18:49 -05:00
|
|
|
var oldSC, newSC *ServiceConfig
|
|
|
|
var oldOK, newOK bool
|
|
|
|
if ccr.curState.ServiceConfig != nil {
|
|
|
|
oldSC, oldOK = ccr.curState.ServiceConfig.Config.(*ServiceConfig)
|
|
|
|
}
|
|
|
|
if s.ServiceConfig != nil {
|
|
|
|
newSC, newOK = s.ServiceConfig.Config.(*ServiceConfig)
|
|
|
|
}
|
|
|
|
if oldOK != newOK || (oldOK && newOK && oldSC.rawJSONString != newSC.rawJSONString) {
|
2019-05-30 17:25:43 -04:00
|
|
|
updates = append(updates, "service config updated")
|
|
|
|
}
|
|
|
|
if len(ccr.curState.Addresses) > 0 && len(s.Addresses) == 0 {
|
|
|
|
updates = append(updates, "resolver returned an empty address list")
|
|
|
|
} else if len(ccr.curState.Addresses) == 0 && len(s.Addresses) > 0 {
|
|
|
|
updates = append(updates, "resolver returned new addresses")
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
}
|
2020-03-25 15:15:46 -04:00
|
|
|
channelz.AddTraceEvent(ccr.cc.channelzID, 0, &channelz.TraceEventDesc{
|
2019-05-30 17:25:43 -04:00
|
|
|
Desc: fmt.Sprintf("Resolver state updated: %+v (%v)", s, strings.Join(updates, "; ")),
|
|
|
|
Severity: channelz.CtINFO,
|
|
|
|
})
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
}
|