Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
22c42a39
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
22c42a39
编写于
3月 28, 2013
作者:
J
Jesse Glick
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:jenkinsci/jenkins
上级
a4d43051
ebccaa33
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
139 addition
and
9 deletion
+139
-9
core/src/main/java/hudson/model/AbstractCIBase.java
core/src/main/java/hudson/model/AbstractCIBase.java
+1
-0
core/src/main/java/hudson/model/Computer.java
core/src/main/java/hudson/model/Computer.java
+30
-7
core/src/main/java/hudson/model/Node.java
core/src/main/java/hudson/model/Node.java
+1
-1
core/src/main/java/hudson/slaves/AbstractCloudComputer.java
core/src/main/java/hudson/slaves/AbstractCloudComputer.java
+1
-1
core/src/main/java/hudson/slaves/AbstractCloudImpl.java
core/src/main/java/hudson/slaves/AbstractCloudImpl.java
+1
-0
core/src/main/java/hudson/slaves/Cloud.java
core/src/main/java/hudson/slaves/Cloud.java
+30
-0
core/src/main/java/hudson/slaves/CloudSlaveRetentionstrategy.java
.../main/java/hudson/slaves/CloudSlaveRetentionstrategy.java
+75
-0
未找到文件。
core/src/main/java/hudson/model/AbstractCIBase.java
浏览文件 @
22c42a39
...
...
@@ -140,6 +140,7 @@ public abstract class AbstractCIBase extends Node implements ItemGroup<TopLevelI
for
(
Map
.
Entry
<
Node
,
Computer
>
e
:
computers
.
entrySet
())
{
if
(
e
.
getValue
()
==
computer
)
{
computers
.
remove
(
e
.
getKey
());
computer
.
onRemoved
();
return
;
}
}
...
...
core/src/main/java/hudson/model/Computer.java
浏览文件 @
22c42a39
...
...
@@ -663,23 +663,46 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
/**
* Called by {@link Jenkins#updateComputerList()} to notify {@link Computer} that it will be discarded.
*
* <p>
* Note that at this point {@link #getNode()} returns null.
*
* @see #onRemoved()
*/
protected
void
kill
()
{
setNumExecutors
(
0
);
}
private
synchronized
void
setNumExecutors
(
int
n
)
{
if
(
numExecutors
==
n
)
return
;
// no-op
/**
* Called by {@link Jenkins} when this computer is removed.
*
* <p>
* This happens when list of nodes are updated (for example by {@link Jenkins#setNodes(List)} and
* the computer becomes redundant. Such {@link Computer}s get {@linkplain #kill() killed}, then
* after all its executors are finished, this method is called.
*
* <p>
* Note that at this point {@link #getNode()} returns null.
*
* @see #kill()
* @since 1.510
*/
protected
void
onRemoved
(){
}
int
diff
=
n
-
numExecutors
;
private
synchronized
void
setNumExecutors
(
int
n
)
{
this
.
numExecutors
=
n
;
int
diff
=
executors
.
size
()-
n
;
if
(
diff
<
0
)
{
if
(
diff
>
0
)
{
// we have too many executors
// send signal to all idle executors to potentially kill them off
for
(
Executor
e
:
executors
)
if
(
e
.
isIdle
())
e
.
interrupt
();
}
else
{
}
if
(
diff
<
0
)
{
// if the number is increased, add new ones
addNewExecutorIfNecessary
();
}
...
...
@@ -1076,8 +1099,8 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
offlineMessage
=
Util
.
fixEmptyAndTrim
(
offlineMessage
);
setTemporarilyOffline
(
true
,
OfflineCause
.
create
(
hudson
.
slaves
.
Messages
.
_SlaveComputer_DisconnectedBy
(
Jenkins
.
getAuthentication
().
getName
(),
offlineMessage
!=
null
?
" : "
+
offlineMessage
:
""
)));
Jenkins
.
getAuthentication
().
getName
(),
offlineMessage
!=
null
?
" : "
+
offlineMessage
:
""
)));
return
HttpResponses
.
redirectToDot
();
}
...
...
core/src/main/java/hudson/model/Node.java
浏览文件 @
22c42a39
...
...
@@ -84,7 +84,7 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
Node
.
class
.
getName
());
/**
* Newly copied slaves get this flag set, so that
Hudson doesn't try to start
this node until its configuration
* Newly copied slaves get this flag set, so that
Jenkins doesn't try to start/remove
this node until its configuration
* is saved once.
*/
protected
volatile
transient
boolean
holdOffLaunchUntilSave
;
...
...
core/src/main/java/hudson/slaves/AbstractCloudComputer.java
浏览文件 @
22c42a39
...
...
@@ -48,7 +48,7 @@ public class AbstractCloudComputer<T extends AbstractCloudSlave> extends SlaveCo
}
/**
* When the slave is deleted, free the node.
* When the slave is deleted, free the node
right away
.
*/
@Override
public
HttpResponse
doDoDelete
()
throws
IOException
{
...
...
core/src/main/java/hudson/slaves/AbstractCloudImpl.java
浏览文件 @
22c42a39
...
...
@@ -10,6 +10,7 @@ package hudson.slaves;
* a new cloud to Jenkins.
*
* @author Kohsuke Kawaguchi
* @see AbstractCloudSlave
*/
public
abstract
class
AbstractCloudImpl
extends
Cloud
{
/**
...
...
core/src/main/java/hudson/slaves/Cloud.java
浏览文件 @
22c42a39
...
...
@@ -26,6 +26,8 @@ package hudson.slaves;
import
hudson.ExtensionPoint
;
import
hudson.Extension
;
import
hudson.DescriptorExtensionList
;
import
hudson.model.Computer
;
import
hudson.model.Slave
;
import
hudson.slaves.NodeProvisioner.PlannedNode
;
import
hudson.model.Describable
;
import
jenkins.model.Jenkins
;
...
...
@@ -37,6 +39,7 @@ import hudson.security.ACL;
import
hudson.security.AccessControlled
;
import
hudson.security.Permission
;
import
hudson.util.DescriptorList
;
import
org.kohsuke.stapler.DataBoundConstructor
;
import
java.util.Collection
;
...
...
@@ -47,6 +50,33 @@ import java.util.Collection;
* Put another way, this class encapsulates different communication protocols
* needed to start a new slave programmatically.
*
* <h2>Notes for implementers</h2>
* <h4>Automatically delete idle slaves</h4>
* <p>
* Nodes provisioned from a cloud do not automatically get released just because it's created from {@link Cloud}.
* Doing so requires a use of {@link RetentionStrategy}. Instantiate your {@link Slave} subtype with something
* like {@link CloudSlaveRetentionstrategy} so that it gets automatically deleted after some idle time.
*
* <h4>Freeing an external resource when a slave is removed</h4>
* <p>
* Whether you do auto scale-down or not, you often want to release an external resource tied to a cloud-allocated
* slave when it is removed.
*
* <p>
* To do this, have your {@link Slave} subtype remember the necessary handle (such as EC2 instance ID)
* as a field. Such fields need to survive the user-initiated re-configuration of {@link Slave}, so you'll need to
* expose it in your {@link Slave} <tt>configure-entries.jelly</tt> and read it back in through {@link DataBoundConstructor}.
*
* <p>
* You then implement your own {@link Computer} subtype, override {@link Slave#createComputer()}, and instantiate
* your own {@link Computer} subtype with this handle information.
*
* <p>
* Finally, override {@link Computer#onRemoved()} and use the handle to talk to the "cloud" and de-allocate
* the resource (such as shutting down a virtual machine.) {@link Computer} needs to own this handle information
* because by the time this happens, a {@link Slave} object is already long gone.
*
*
* @author Kohsuke Kawaguchi
* @see NodeProvisioner
* @see AbstractCloudImpl
...
...
core/src/main/java/hudson/slaves/CloudSlaveRetentionstrategy.java
0 → 100644
浏览文件 @
22c42a39
package
hudson.slaves
;
import
hudson.model.Computer
;
import
hudson.model.Node
;
import
hudson.util.TimeUnit2
;
import
jenkins.model.Jenkins
;
import
java.io.IOException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
/**
* Default convenience implementation of {@link RetentionStrategy} for slaves provisioned from {@link Cloud}.
*
* If a slave is idle for 10 mins, this retention strategy will remove the slave. This can be used as-is for
* a {@link Node} provisioned by cloud to implement the auto-scaling semantics, it can be subtyped to twaeak
* the behaviour, or it can be used as an example.
*
* @author Kohsuke Kawaguchi
* @since 1.510
*/
public
class
CloudSlaveRetentionstrategy
<
T
extends
Computer
>
extends
RetentionStrategy
<
T
>
{
@Override
public
long
check
(
T
c
)
{
if
(!
c
.
isConnecting
()
&&
c
.
isAcceptingTasks
())
{
if
(
isIdleForTooLong
(
c
))
{
try
{
Node
n
=
c
.
getNode
();
if
(
n
!=
null
)
// rare, but n==null if the node is deleted and being checked roughly at the same time
kill
(
n
);
}
catch
(
IOException
e
)
{
LOGGER
.
log
(
Level
.
WARNING
,
"Failed to remove "
+
c
.
getDisplayName
(),
e
);
}
}
}
return
checkCycle
();
}
/**
* Remove the node.
*
* <p>
* To actually deallocate the resource tied to this {@link Node}, implement {@link Computer#onRemoved()}.
*/
protected
void
kill
(
Node
n
)
throws
IOException
{
Jenkins
.
getInstance
().
removeNode
(
n
);
}
/**
* When do we check again next time?
*/
protected
long
checkCycle
()
{
return
getIdleMaxTime
()/
10
;
}
/**
* Has this computer been idle for too long?
*/
protected
boolean
isIdleForTooLong
(
T
c
)
{
return
System
.
currentTimeMillis
()-
c
.
getIdleStartMilliseconds
()
>
getIdleMaxTime
();
}
/**
* If the computer has been idle longer than this time, we'll kill the slave.
*/
protected
long
getIdleMaxTime
()
{
return
TIMEOUT
;
}
// for debugging, it's convenient to be able to reduce this time
public
static
long
TIMEOUT
=
Long
.
getLong
(
CloudSlaveRetentionstrategy
.
class
.
getName
()+
".timeout"
,
TimeUnit2
.
MINUTES
.
toMillis
(
10
));
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
CloudSlaveRetentionstrategy
.
class
.
getName
());
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录