本文整理汇总了Golang中github.com/jkellerer/jenkins-client-launcher/launcher/util.GOut函数的典型用法代码示例。如果您正苦于以下问题:Golang GOut函数的具体用法?Golang GOut怎么用?Golang GOut使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GOut函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: forwardLocalConnectionsTo
// Forwards the local server listener to the specified target address (format host:port) using the SSH connection as tunnel.
// What this method does is the same as "ssh -L $ANY-PORT:jenkins-host:$TARGET-PORT" jenkins-host.
func (self *SSHTunnelEstablisher) forwardLocalConnectionsTo(config *util.Config, ssh *ssh.Client, listener net.Listener, targetAddress string) {
transfer := func(source io.ReadCloser, target io.Writer) {
defer source.Close()
_, _ = io.Copy(target, source)
}
establishBIDITransport := func(source net.Conn, target net.Conn) {
go transfer(source, target)
go transfer(target, source)
}
sshAddress := ssh.Conn.RemoteAddr().String()
localAddress := listener.Addr().String()
util.GOut("ssh-tunnel", "Forwarding local connections on '%v' to '%v' via '%v'.", localAddress, targetAddress, sshAddress)
for {
if sourceConnection, err := listener.Accept(); err == nil {
if targetConnection, err := ssh.Dial("tcp", targetAddress); err == nil {
establishBIDITransport(sourceConnection, targetConnection)
} else {
util.GOut("ssh-tunnel", "ERROR: Failed forwarding incoming local connection on '%v' to '%v' via '%v'.", localAddress, targetAddress, sshAddress)
}
} else {
util.GOut("ssh-tunnel", "Stop forwarding local connections on '%v' to '%v'.", localAddress, targetAddress)
return
}
}
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:31,代码来源:sshtunnel.go
示例2: cleanupLocations
func (self *LocationCleaner) cleanupLocations(dirsToKeepClean, exclusions []string, mode string, maxTTL time.Duration) {
for _, rootDir := range dirsToKeepClean {
rootDir = filepath.Clean(rootDir)
dirToEmptyMap := map[string]bool{}
expiredTimeOffset := time.Now().Add(-maxTTL)
if mode == ModeTTLPerLocation {
util.GOut("cleanup", "Checking %v for expiration.", rootDir)
exclusionCount := self.cleanupFiles(rootDir, expiredTimeOffset, true, exclusions, dirToEmptyMap)
if exclusionCount > 0 {
return
}
util.GOut("cleanup", "Cleaning %v", rootDir)
} else {
util.GOut("cleanup", "Cleaning expired files in %v", rootDir)
}
// Handling outdated temporary files
_ = self.cleanupFiles(rootDir, expiredTimeOffset, false, exclusions, dirToEmptyMap)
// Handling all directories that are known to be empty
for dirPath, emptyDir := range dirToEmptyMap {
// Root-Dir is only cleaned for "TTLPerLocation".
if mode != ModeTTLPerLocation && rootDir == dirPath {
continue
}
if emptyDir {
if err := os.Remove(dirPath); err == nil {
util.GOut("cleanup", "\x1b[39mRemoved empty directory: %v", dirPath)
}
}
}
}
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:35,代码来源:cleanup.go
示例3: execute
func (self *ServerMode) execute(privateKey ssh.Signer) {
// An SSH server is represented by a ServerConfig, which holds
// certificate details and handles authentication of ServerConns.
config := &ssh.ServerConfig{
PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
// Slowing down password check to make BF attacks more difficult.
time.Sleep(time.Second * 1)
if c.User() == self.config.SSHUsername && string(pass) == self.config.SSHPassword {
return nil, nil
} else {
return nil, fmt.Errorf("SSH: Password rejected for %q", c.User())
}
},
AuthLogCallback: func(c ssh.ConnMetadata, method string, err error) {
if err == nil {
util.GOut("SSH", "Authentication succeeded '%v' using '%v'", c.User(), method)
} else {
util.GOut("SSH", "Failed attempt to authenticate '%v' using '%v' ; Caused by: %v", c.User(), method, err)
}
},
}
config.AddHostKey(privateKey)
// Once a ServerConfig has been configured, connections can be
// accepted.
address := fmt.Sprintf("%v:%v", self.config.SSHListenAddress, self.config.SSHListenPort)
util.GOut("SSH", "Starting to listen @ %v", address)
listener, err := net.Listen("tcp", address)
if err != nil {
panic("SSH: Failed to listen @ " + address)
} else {
defer func() {
listener.Close()
self.status.Set(ModeStopped)
}()
}
go func() {
for {
connection, err := listener.Accept()
if err != nil {
util.GOut("SSH", "Failed to accept next incoming SSH connection, assuming connection was closed.")
return
}
// Handling only one connection at a time should be enough.
self.handleSSHRequest(&connection, config)
}
}()
// Entering main loop and remain there until the terminal is stopped and the deferred channel close is triggered.
self.status.Set(ModeStarted)
for self.status.Get() == ModeStarted {
time.Sleep(time.Millisecond * 100)
}
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:60,代码来源:server.go
示例4: InstallJava
// Implements Java installation for Windows
func (self *JavaDownloader) InstallJava(config *util.Config) error {
util.GOut("DOWNLOAD", "Getting %v", config.CIHostURI)
util.GOut("INSTALL", "Installing %v", config.CIHostURI)
// TODO: Implement like done here:
// TODO: https://github.com/jenkinsci/jenkins/blob/main/core/src/main/java/hudson/tools/JDKInstaller.java
return fmt.Errorf("Installing Java is not implemented yet. Install it manually.")
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:10,代码来源:java_windows.go
示例5: downloadJar
func (self *JenkinsClientDownloader) downloadJar(config *util.Config) error {
util.GOut("DOWNLOAD", "Getting latest Jenkins client %v", (config.CIHostURI + "/" + ClientJarURL))
// Create the HTTP request.
request, err := config.CIRequest("GET", ClientJarURL, nil)
if err != nil {
return err
}
if fi, err := os.Stat(ClientJarName); err == nil {
request.Header.Add("If-Modified-Since", fi.ModTime().Format(http.TimeFormat))
}
// Perform the HTTP request.
var source io.ReadCloser
sourceTime := time.Now()
if response, err := config.CIClient().Do(request); err == nil {
defer response.Body.Close()
source = response.Body
if response.StatusCode == 304 {
util.GOut("DOWNLOAD", "Jenkins client is up-to-date, no need to download.")
return nil
} else if response.StatusCode != 200 {
return fmt.Errorf("Failed downloading jenkins client. Cause: HTTP-%v %v", response.StatusCode, response.Status)
}
if value := response.Header.Get("Last-Modified"); value != "" {
if time, err := http.ParseTime(value); err == nil {
sourceTime = time
}
}
} else {
return fmt.Errorf("Failed downloading jenkins client. Connect failed. Cause: %v", err)
}
target, err := os.Create(ClientJarDownloadName)
defer target.Close()
if err != nil {
return fmt.Errorf("Failed downloading jenkins client. Cannot create local file. Cause: %v", err)
}
if _, err = io.Copy(target, source); err == nil {
target.Close()
if err = os.Remove(ClientJarName); err == nil || os.IsNotExist(err) {
if err = os.Rename(ClientJarDownloadName, ClientJarName); err == nil {
os.Chtimes(ClientJarName, sourceTime, sourceTime)
}
}
return err
} else {
return fmt.Errorf("Failed downloading jenkins client. Transfer failed. Cause: %v", err)
}
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:56,代码来源:clientjar.go
示例6: newLocalServerListener
// Opens a new local server socket.
func (self *SSHTunnelEstablisher) newLocalServerListener() (serverListener net.Listener, err error) {
serverListener, err = net.Listen("tcp", "localhost:0")
if err == nil {
self.closables = append(self.closables, serverListener)
util.GOut("ssh-tunnel", "Opened local listener on '%v'.", serverListener.Addr())
} else {
util.GOut("ssh-tunnel", "ERROR: Failed opening local listener. Cause: %v", err)
}
return
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:11,代码来源:sshtunnel.go
示例7: IsConfigAcceptable
func (self *SSHTunnelEstablisher) IsConfigAcceptable(config *util.Config) bool {
if config.CITunnelSSHEnabled && config.CITunnelSSHAddress == "" {
util.GOut("ssh-tunnel", "WARN: SSH tunnel is enabled but SSH server address is empty.")
return false
}
if config.CITunnelSSHAddress != "" && !config.HasCIConnection() {
util.GOut("ssh-tunnel", "WARN: No Jenkins URI defined. SSH tunnel settings are not enough to connect to Jenkins.")
return false
}
return true
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:11,代码来源:sshtunnel.go
示例8: invokeSystemGC
func (self *FullGCInvoker) invokeSystemGC(config *util.Config) {
// curl -d "script=System.gc()" -X POST http://user:[email protected]/ci/computer/%s/scriptText
postBody := strings.NewReader(fmt.Sprintf(FullGCPostBody, url.QueryEscape(FullGCScript)))
request, err := config.CIRequest("POST", fmt.Sprintf(FullGCURL, config.ClientName), postBody)
if err == nil {
if response, err := config.CIClient().Do(request); err == nil {
response.Body.Close()
if response.StatusCode != 200 {
util.GOut("gc", "ERROR: Failed invoking full GC as node request in Jenkins failed with %s", response.Status)
}
} else {
util.GOut("gc", "ERROR: Failed invoking full GC as Jenkins cannot be contacted. Cause: %v", err)
}
}
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:15,代码来源:gc.go
示例9: IsConfigAcceptable
func (self *ClientMode) IsConfigAcceptable(config *util.Config) bool {
if !config.HasCIConnection() {
util.GOut(self.Name(), "ERROR: No Jenkins URI defined. Cannot connect to the CI server.")
return false
}
if config.SecretKey == "" && !self.isAuthCredentialsPassedViaCommandline(config) {
if config.SecretKey = self.getSecretFromJenkins(config); config.SecretKey == "" {
util.GOut(self.Name(), "ERROR: No secret key set for node %v and the attempt to fetch it from Jenkins failed.", config.ClientName)
return false
}
}
return true
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:15,代码来源:client.go
示例10: startAliveStateMonitoring
// Monitors that the tunnel is alive by periodically querying the node status off Jenkins.
// Timeout, hanging connections or connection errors lead to a restart of the current execution mode (which implicitly closes SSH tunnel as well).
func (self *SSHTunnelEstablisher) startAliveStateMonitoring(config *util.Config) {
// Periodically check the node status and increment lastAliveTick on success
go func() {
for _ = range self.aliveTicker.C {
if !self.tunnelConnected.Get() {
continue
}
if _, err := GetJenkinsNodeStatus(config); err == nil {
self.lastAliveTick.Set(self.expectedAliveTick.Get())
}
}
}()
// Periodically check that lastAliveTick was incremented.
go func() {
for _ = range self.aliveTickEvaluator.C {
if !self.tunnelConnected.Get() {
continue
}
if math.Abs(float64(self.expectedAliveTick.Get()-self.lastAliveTick.Get())) > 1 {
util.GOut("ssh-tunnel", "WARN: The SSH tunnel appears to be dead or Jenkins is gone. Forcing restart of client and SSH tunnel.")
modes.GetConfiguredMode(config).Stop()
} else {
self.expectedAliveTick.AddAndGet(1)
}
}
}()
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:32,代码来源:sshtunnel.go
示例11: NewSSHTunnelEstablisher
// Creates a new tunnel establisher.
func NewSSHTunnelEstablisher(registerInMode bool) *SSHTunnelEstablisher {
self := new(SSHTunnelEstablisher)
self.closables = []io.Closer{}
self.ciHostURL = nil
self.aliveTicker, self.aliveTickEvaluator = time.NewTicker(nodeSshTunnelAliveMonitoringInterval), time.NewTicker(nodeSshTunnelAliveMonitoringInterval)
self.expectedAliveTick, self.lastAliveTick = util.NewAtomicInt32(), util.NewAtomicInt32()
self.tunnelConnected = util.NewAtomicBoolean()
if registerInMode {
modes.RegisterModeListener(func(mode modes.ExecutableMode, nextStatus int32, config *util.Config) {
if !config.CITunnelSSHEnabled || config.CITunnelSSHAddress == "" || mode.Name() != "client" || !config.HasCIConnection() {
return
}
if nextStatus == modes.ModeStarting {
var err error
if self.ciHostURL, err = url.Parse(config.CIHostURI); err != nil {
util.GOut("ssh-tunnel", "ERROR: Failed parsing Jenkins URI. Cannot tunnel connections to Jenkins. Cause: %v", err)
return
}
self.setupSSHTunnel(config)
} else if nextStatus == modes.ModeStopped {
self.tearDownSSHTunnel(config)
}
})
}
return self
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:33,代码来源:sshtunnel.go
示例12: IsConfigAcceptable
func (self *JenkinsNodeMonitor) IsConfigAcceptable(config *util.Config) bool {
if config.ClientMonitorStateOnServer && !config.HasCIConnection() {
util.GOut("monitor", "No Jenkins URI defined. Cannot monitor this node within Jenkins.")
return false
}
return true
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:7,代码来源:monitor.go
示例13: IsConfigAcceptable
func (self *FullGCInvoker) IsConfigAcceptable(config *util.Config) bool {
if config.ForceFullGC && !config.HasCIConnection() {
util.GOut("gc", "WARN: No Jenkins URI defined. System.GC() cannot be called inside the Jenkins client.")
return false
}
return true
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:7,代码来源:gc.go
示例14: waitForIdleIfRequired
func (self *PeriodicRestarter) waitForIdleIfRequired(config *util.Config) {
if config.PeriodicClientRestartOnlyWhenIDLE {
for !util.NodeIsIdle.Get() {
util.GOut("periodic", "Waiting for node to become IDLE before triggering a restart.")
time.Sleep(time.Minute * 5)
}
}
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:8,代码来源:periodic.go
示例15: isServerSideConnected
// Checks if Jenkins shows this node as connected and returns the node's IDLE state as second return value.
func (self *JenkinsNodeMonitor) isServerSideConnected(config *util.Config) (connected bool, idle bool, serverReachable bool) {
if status, err := GetJenkinsNodeStatus(config); err == nil {
return !status.Offline, status.Idle, true
} else {
util.GOut("monitor", "ERROR: Failed to monitor node %v using %v. Cause: %v", config.ClientName, config.CIHostURI, err)
return false, true, false
}
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:9,代码来源:monitor.go
示例16: Prepare
// Performs registration & deregistration for autostart on windows.
func (self *AutostartHandler) Prepare(config *util.Config) {
cwd, _ := os.Getwd()
self.commandline = fmt.Sprintf("\"%s\" \"-directory=%s\"", os.Args[0], cwd)
if config.Autostart {
util.GOut("autostart", "Registering %v for autostart.", self.commandline)
err := self.register()
if err != nil {
util.GOut("autostart", "ERROR: FAILED to register for autostart. Cause: %v", err)
}
} else {
if self.isRegistered() {
util.GOut("autostart", "Unregistering %v from autostart.", self.commandline)
err := self.unregister()
if err != nil {
util.GOut("autostart", "ERROR: FAILED to unregister from autostart. Cause: %v", err)
}
}
}
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:21,代码来源:autostart_windows.go
示例17: getSecretFromJenkins
func (self *ClientMode) getSecretFromJenkins(config *util.Config) string {
response, err := config.CIGet(fmt.Sprintf("computer/%s/", config.ClientName))
if err == nil {
defer response.Body.Close()
if response.StatusCode == 200 {
var content []byte
if content, err = ioutil.ReadAll(response.Body); err == nil {
return self.extractSecret(content)
}
} else {
util.GOut("client", "ERROR: Failed fetching secret key from Jenkins. Cause: %v", response.Status)
}
}
if err != nil {
util.GOut("client", "ERROR: Failed fetching secret key from Jenkins. Cause: %v", err)
}
return ""
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:21,代码来源:client.go
示例18: getCustomizedAgentJnlp
func (self *ClientMode) getCustomizedAgentJnlp(config *util.Config) []byte {
response, err := config.CIGet(fmt.Sprintf("computer/%s/slave-agent.jnlp", config.ClientName))
if err == nil {
defer response.Body.Close()
if response.StatusCode == 200 {
var content []byte
if content, err = ioutil.ReadAll(response.Body); err == nil {
return self.applyCustomJnlpArgs(config, content)
}
} else {
util.GOut("client", "ERROR: Failed JNLP config from Jenkins. Cause: %v", response.Status)
}
}
if err != nil {
util.GOut("client", "ERROR: Failed JNLP config from Jenkins. Cause: %v", err)
}
return nil
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:21,代码来源:client.go
示例19: javaIsInstalled
// Checks if java is installed and if the java version is greater or equals the required version.
func (self *JavaDownloader) javaIsInstalled() bool {
if java, err := exec.LookPath("java"); err == nil {
// Set absolute path to java
util.Java = java
// Check the version
if output, err := exec.Command(java, "-version").CombinedOutput(); err == nil {
if pattern, err := regexp.Compile(`(?i)java version "([^"]+)"`); err == nil {
if matches := pattern.FindSubmatch(output); matches != nil && len(matches) == 2 {
javaVersion := string(matches[1])
if version.Compare(javaVersion, MinJavaVersion, ">=") {
util.GOut("java", "Found java version %v, no need to install a newer version.", javaVersion)
return true
}
util.GOut("java", "Found java version %v. A newer version is required to run the Jenkins client.", javaVersion)
}
}
}
}
return false
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:22,代码来源:java.go
示例20: Prepare
func (self *NodeNameHandler) Prepare(config *util.Config) {
if !config.HasCIConnection() {
return
}
if foundNode, err := self.verifyNodeName(config); err == nil {
if !foundNode {
if config.CreateClientIfMissing {
if err := self.createNode(config); err == nil {
util.GOut("naming", "Created node '%s' in Jenkins.", config.ClientName)
} else {
util.GOut("naming", "ERROR: Failed to create node '%s' in Jenkins. Cause: %v", config.ClientName, err)
}
foundNode, _ = self.verifyNodeName(config)
} else {
util.GOut("naming", "Will not attempt to auto generate node '%s' in Jenkins. Enable this with '-create' or within the configuration.", config.ClientName)
}
}
if foundNode {
util.GOut("naming", "Found client node name in Jenkins, using '%v'.", config.ClientName)
} else {
util.GOut("naming", "WARN: Client node name '%v' was %s in Jenkins. Likely the next operations will fail.", config.ClientName, "NOT FOUND")
}
} else {
util.GOut("nameing", "ERROR: Failed to verify the client node name in Jenkins. Cause: %v", err)
}
}
开发者ID:jkellerer,项目名称:jenkins-client-launcher,代码行数:29,代码来源:naming.go
注:本文中的github.com/jkellerer/jenkins-client-launcher/launcher/util.GOut函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论