本文整理汇总了Java中hudson.slaves.NodeProvisioner类的典型用法代码示例。如果您正苦于以下问题:Java NodeProvisioner类的具体用法?Java NodeProvisioner怎么用?Java NodeProvisioner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NodeProvisioner类属于hudson.slaves包,在下文中一共展示了NodeProvisioner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onStarted
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
@Override @Restricted(DoNotUse.class)
public void onStarted(Cloud cloud, Label label, Collection<NodeProvisioner.PlannedNode> plannedNodes) {
BulkChange change = new BulkChange(stats);
try {
boolean changed = false;
for (NodeProvisioner.PlannedNode plannedNode : plannedNodes) {
ProvisioningActivity.Id id = getIdFor(plannedNode);
if (id != null) {
onStarted(id);
changed = true;
}
}
if (changed) {
// Not using change.commit() here as persist handles exceptions already
stats.persist();
}
} finally {
change.abort();
}
}
示例2: provision
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
@Override
public Collection<NodeProvisioner.PlannedNode> provision(Label label, int excessWorkload) {
try {
List<NodeProvisioner.PlannedNode> r = new ArrayList<NodeProvisioner.PlannedNode>();
final ECSTaskTemplate template = getTemplate(label);
for (int i = 1; i <= excessWorkload; i++) {
r.add(new NodeProvisioner.PlannedNode(template.getDisplayName(), Computer.threadPoolForRemoting
.submit(new ProvisioningCallback(template, label)), 1));
}
return r;
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to provision ECS slave", e);
return Collections.emptyList();
}
}
示例3: setEnabled
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
/**
* For groovy.
*/
public void setEnabled(boolean enabled) {
final ExtensionList<NodeProvisioner.Strategy> strategies = lookup(NodeProvisioner.Strategy.class);
DockerProvisioningStrategy strategy = strategies.get(DockerProvisioningStrategy.class);
if (isNull(strategy)) {
LOG.debug("YAD strategy was null, creating new.");
strategy = new DockerProvisioningStrategy();
} else {
LOG.debug("Removing YAD strategy.");
strategies.remove(strategy);
}
LOG.debug("Inserting YAD strategy at position 0");
strategies.add(0, strategy);
}
示例4: apply
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
@Nonnull
@Override
public StrategyDecision apply(@Nonnull NodeProvisioner.StrategyState state) {
if (Jenkins.getInstance().isQuietingDown()) {
return CONSULT_REMAINING_STRATEGIES;
}
for (Cloud cloud : Jenkins.getInstance().clouds) {
if (cloud instanceof DockerCloud) {
final StrategyDecision decision = applyFoCloud(state, (DockerCloud) cloud);
if (decision == PROVISIONING_COMPLETED) return decision;
}
}
return CONSULT_REMAINING_STRATEGIES;
}
示例5: testProvision
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
@Test
public void testProvision() {
int workload = 3;
Collection<NodeProvisioner.PlannedNode> plannedNodes = nomadCloud.provision(label, workload);
Assert.assertEquals(plannedNodes.size(), workload);
}
示例6: provision
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
@Override public synchronized Collection<NodeProvisioner.PlannedNode> provision(
final Label label, final int excessWorkload) {
final FleetStateStats stats=updateStatus();
final int maxAllowed = this.getMaxSize();
if (stats.getNumDesired() >= maxAllowed || !"active".equals(stats.getState()))
return Collections.emptyList();
int targetCapacity = stats.getNumDesired() + excessWorkload;
if (targetCapacity > maxAllowed)
targetCapacity = maxAllowed;
int toProvision = targetCapacity - stats.getNumDesired();
LOGGER.log(Level.INFO, "Provisioning nodes. Excess workload: " + Integer.toString(excessWorkload) + ", Provisioning: " + Integer.toString(toProvision));
final ModifySpotFleetRequestRequest request=new ModifySpotFleetRequestRequest();
request.setSpotFleetRequestId(fleet);
request.setTargetCapacity(targetCapacity);
final AmazonEC2 ec2=connect(credentialsId, region);
ec2.modifySpotFleetRequest(request);
final List<NodeProvisioner.PlannedNode> resultList =
new ArrayList<NodeProvisioner.PlannedNode>();
for(int f=0;f<toProvision; ++f)
{
final SettableFuture<Node> futureNode=SettableFuture.create();
final NodeProvisioner.PlannedNode plannedNode=
new NodeProvisioner.PlannedNode("FleetNode-"+f, futureNode, 1);
resultList.add(plannedNode);
this.plannedNodes.add(plannedNode);
}
return resultList;
}
示例7: onComplete
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
@Override @Restricted(DoNotUse.class)
public void onComplete(NodeProvisioner.PlannedNode plannedNode, Node node) {
ProvisioningActivity.Id id = getIdFor(plannedNode);
if (id != null) {
onComplete(id, node);
}
}
示例8: onFailure
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
@Override @Restricted(DoNotUse.class)
public void onFailure(NodeProvisioner.PlannedNode plannedNode, Throwable t) {
ProvisioningActivity.Id id = getIdFor(plannedNode);
if (id != null) {
onFailure(id, t);
}
}
示例9: getIdFor
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
private static @CheckForNull ProvisioningActivity.Id getIdFor(NodeProvisioner.PlannedNode plannedNode) {
if (!(plannedNode instanceof TrackedItem)) {
logTypeNotSupported(plannedNode.getClass());
return null;
}
return ((TrackedItem) plannedNode).getId();
}
示例10: provision
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
@Override
public Collection<NodeProvisioner.PlannedNode> provision(Label label, int excessWorkload) {
assert provision != null;
provision.j = j;
int i = seq.getAndIncrement();
provision.id = new ProvisioningActivity.Id(name, null, name + "-slave-" + i);
return Collections.<NodeProvisioner.PlannedNode>singletonList(new TrackedPlannedNode(
provision.id, 1, Computer.threadPoolForRemoting.submit(provision)
));
}
示例11: before
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
@Before
public void before() throws Exception {
// Pretend we are out of slaves
j.jenkins.setNumExecutors(0);
j.jenkins.setNodes(Collections.<Node>emptyList());
// Do not provision when not expected
ExtensionList<NodeProvisioner.NodeProvisionerInvoker> extensionList = j.jenkins.getExtensionList(NodeProvisioner.NodeProvisionerInvoker.class);
provisionerInvoker = extensionList.get(0);
}
示例12: provision
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
@Override
public Collection<NodeProvisioner.PlannedNode> provision(Label label, int excessWorkload)
{
LOGGER.log(Level.SEVERE, "Going to provision " + excessWorkload + " executors");
Collection<NodeProvisioner.PlannedNode> result = new ArrayList<NodeProvisioner.PlannedNode>();
final ParallelsDesktopConnectorSlaveComputer connector = getConnector();
for (int i = 0; (i < vms.size()) && (excessWorkload > 0); i++)
{
final ParallelsDesktopVM vm = vms.get(i);
if (vm.isProvisioned())
continue;
if (!label.matches(Label.parse(vm.getLabels())))
continue;
final String vmId = vm.getVmid();
final String slaveName = name + " " + vmId;
vm.setSlaveName(slaveName);
vm.setProvisioned(true);
--excessWorkload;
result.add(new NodeProvisioner.PlannedNode(slaveName,
Computer.threadPoolForRemoting.submit(new Callable<Node>()
{
@Override
public Node call() throws Exception
{
connector.checkVmExists(vmId);
return connector.createSlaveOnVM(vm);
}
}), 1));
}
return result;
}
示例13: applyFoCloud
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
private StrategyDecision applyFoCloud(@Nonnull NodeProvisioner.StrategyState state, DockerCloud cloud) {
final Label label = state.getLabel();
if (!cloud.canProvision(label)) {
return CONSULT_REMAINING_STRATEGIES;
}
LoadStatistics.LoadStatisticsSnapshot snapshot = state.getSnapshot();
LOGGER.log(FINEST, "Available executors={0}, connecting={1}, planned={2}",
new Object[]{snapshot.getAvailableExecutors(), snapshot.getConnectingExecutors(), state.getPlannedCapacitySnapshot()});
int availableCapacity =
snapshot.getAvailableExecutors()
+ snapshot.getConnectingExecutors()
+ state.getPlannedCapacitySnapshot();
int currentDemand = snapshot.getQueueLength();
LOGGER.log(FINE, "Available capacity={0}, currentDemand={1}",
new Object[]{availableCapacity, currentDemand});
if (availableCapacity < currentDemand) {
Collection<NodeProvisioner.PlannedNode> plannedNodes = cloud.provision(label, currentDemand - availableCapacity);
LOGGER.log(FINE, "Planned {0} new nodes", plannedNodes.size());
state.recordPendingLaunches(plannedNodes);
availableCapacity += plannedNodes.size();
LOGGER.log(FINE, "After provisioning, available capacity={0}, currentDemand={1}",
new Object[]{availableCapacity, currentDemand});
}
if (availableCapacity >= currentDemand) {
LOGGER.log(FINE, "Provisioning completed");
return PROVISIONING_COMPLETED;
} else {
LOGGER.log(FINE, "Provisioning not complete, consulting remaining strategies");
return CONSULT_REMAINING_STRATEGIES;
}
}
示例14: onEnterBuildable
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
@Override
public void onEnterBuildable(Queue.BuildableItem item) {
final Jenkins jenkins = Jenkins.getInstance();
final Label label = item.getAssignedLabel();
for (Cloud cloud : Jenkins.getInstance().clouds) {
if (cloud instanceof DockerCloud && cloud.canProvision(label)) {
final NodeProvisioner provisioner = (label == null
? jenkins.unlabeledNodeProvisioner
: label.nodeProvisioner);
provisioner.suggestReviewNow();
}
}
}
示例15: addNewSlave
import hudson.slaves.NodeProvisioner; //导入依赖的package包/类
private void addNewSlave(final AmazonEC2 ec2, final String instanceId) throws Exception {
// Generate a random FS root if one isn't specified
String fsRoot = this.fsRoot;
if (fsRoot == null || fsRoot.equals("")) {
fsRoot = "/tmp/jenkins-"+UUID.randomUUID().toString().substring(0, 8);
}
final DescribeInstancesResult result=ec2.describeInstances(
new DescribeInstancesRequest().withInstanceIds(instanceId));
if (result.getReservations().isEmpty()) //Can't find this instance, skip it
return;
final Instance instance=result.getReservations().get(0).getInstances().get(0);
final String address = isPrivateIpUsed() ?
instance.getPrivateIpAddress() : instance.getPublicIpAddress();
// Check if we have the address to use. Nodes don't get it immediately.
if (address == null)
return; // Wait some more...
final FleetNode slave = new FleetNode(instanceId, "Fleet slave for" + instanceId,
fsRoot, this.numExecutors.toString(), Node.Mode.NORMAL, this.labelString, new ArrayList<NodeProperty<?>>(),
FLEET_CLOUD_ID, computerConnector.launch(address, TaskListener.NULL));
// Initialize our retention strategy
if (getIdleMinutes() != null)
slave.setRetentionStrategy(new IdleRetentionStrategy(getIdleMinutes(), this));
final Jenkins jenkins=Jenkins.getInstance();
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (jenkins) {
// Try to avoid duplicate nodes
final Node n = jenkins.getNode(instanceId);
if (n != null)
jenkins.removeNode(n);
jenkins.addNode(slave);
}
//A new node, wheee!
instancesSeen.add(instanceId);
if (!plannedNodes.isEmpty())
{
//If we're waiting for a new node - mark it as ready
final NodeProvisioner.PlannedNode curNode=plannedNodes.iterator().next();
plannedNodes.remove(curNode);
((SettableFuture<Node>)curNode.future).set(slave);
}
}