35
35
import org .kohsuke .stapler .QueryParameter ;
36
36
import org .kohsuke .stapler .StaplerRequest ;
37
37
38
+ import javax .annotation .Nonnull ;
38
39
import java .io .IOException ;
39
40
import java .util .ArrayList ;
40
41
import java .util .Collection ;
@@ -292,9 +293,10 @@ public synchronized boolean hasExcessCapacity() {
292
293
// }
293
294
294
295
@ Override
295
- public synchronized Collection <NodeProvisioner .PlannedNode > provision (final Label label , int excessWorkload ) {
296
+ public synchronized Collection <NodeProvisioner .PlannedNode > provision (@ Nonnull final Cloud . CloudState cloudState , int excessWorkload ) {
296
297
info ("excessWorkload %s" , excessWorkload );
297
298
299
+ final Label label = cloudState .getLabel ();
298
300
List <NodeProvisioner .PlannedNode > r = new ArrayList <>();
299
301
300
302
for (Map .Entry <String , State > state : states .entrySet ()) {
@@ -421,7 +423,7 @@ public void update() {
421
423
}
422
424
423
425
private void updateByState (final Map <String , State > states ) {
424
- final Jenkins jenkins = Jenkins .getActiveInstance ();
426
+ final Jenkins jenkins = Jenkins .get ();
425
427
426
428
final AmazonEC2 ec2 = Registry .getEc2Api ().connect (getAwsCredentialsId (), region , endpoint );
427
429
@@ -563,7 +565,7 @@ public void run() {
563
565
public synchronized boolean scheduleToTerminate (final String instanceId , boolean force ) {
564
566
info ("Attempting to terminate instance: %s" , instanceId );
565
567
566
- final Node node = Jenkins .getActiveInstance ().getNode (instanceId );
568
+ final Node node = Jenkins .get ().getNode (instanceId );
567
569
if (node == null ) return false ;
568
570
569
571
final State state = states .get (node .getLabelString ());
@@ -586,7 +588,8 @@ public synchronized boolean scheduleToTerminate(final String instanceId, boolean
586
588
587
589
// sync as we are using modifyable state
588
590
@ Override
589
- public synchronized boolean canProvision (final Label label ) {
591
+ public synchronized boolean canProvision (final Cloud .CloudState cloudState ) {
592
+ final Label label = cloudState .getLabel ();
590
593
for (String labelString : states .keySet ()) {
591
594
final boolean r = label == null || Label .parse (labelString ).containsAll (label .listAtoms ());
592
595
fine ("CanProvision called on fleet: \" " + labelString + "\" wanting: \" " + (label == null ? "(unspecified)" : label .getName ()) + "\" . Returning " + r + "." );
@@ -713,14 +716,14 @@ public void updateStacks() {
713
716
// ec2KeyPairName = result.getKeyPair().getKeyName();
714
717
// }
715
718
716
- final Jenkins jenkins = Jenkins .getActiveInstance ();
719
+ final Jenkins jenkins = Jenkins .get ();
717
720
final CloudFormationApi cloudFormationApi = Registry .getCloudFormationApi ();
718
721
final AmazonCloudFormation client = cloudFormationApi .connect (awsCredentialsId , region , endpoint );
719
722
final Map <String , CloudFormationApi .StackInfo > allStacks = cloudFormationApi .describe (client , name );
720
723
721
724
// labels
722
725
final Set <String > labels = new HashSet <>();
723
- for (final Item item : Jenkins .getActiveInstance ().getAllItems ()) {
726
+ for (final Item item : Jenkins .get ().getAllItems ()) {
724
727
if (!(item instanceof AbstractProject )) continue ;
725
728
final AbstractProject abstractProject = (AbstractProject ) item ;
726
729
// assinged label could be null
0 commit comments