File tree Expand file tree Collapse file tree
main/java/com/offbytwo/jenkins/model
test/java/com/offbytwo/jenkins/integration Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66### API Changes
77
8+ [ Added toggleOffline Node] [ issue-157 ]
9+ Added toggleOffline to ` ComputerWithDetails ` class.
10+
11+ ``` java
12+ public class ComputerWithDetails {
13+ public void toggleOffline (boolean crumbFlag ) throws IOException ;
14+ public void toggleOffline () throws IOException ;
15+ }
16+ ```
17+
818 [ deleteJob throws exception but works anyway] [ issue-154 ]
919 [ Some HTTP calls to jenkins result in a 302, which currently throws an HttpResponseException #7 [ issue-7]
1020 [ Create Job is failing - any idea on this error] [ issue-121 ]
Original file line number Diff line number Diff line change 22
33import java .util .List ;
44
5+ import com .google .common .base .Function ;
6+ import com .google .common .collect .Collections2 ;
7+ import com .google .common .collect .Lists ;
8+ import com .google .common .collect .Maps ;
9+
510public class ComputerSet extends BaseModel {
611 private int busyExecutors ;
712 List <ComputerWithDetails > computer ;
813 private String displayName ;
914 private int totalExecutors ;
1015
16+ public ComputerSet ()
17+ {
18+ }
19+
20+
1121 public int getBusyExecutors () {
1222 return busyExecutors ;
1323 }
@@ -33,7 +43,13 @@ public void setTotalExecutors(int totalExecutors) {
3343 }
3444
3545 public List <ComputerWithDetails > getComputer () {
36- return computer ;
46+ return Lists .transform ( computer , new Function <ComputerWithDetails , ComputerWithDetails >() {
47+ @ Override
48+ public ComputerWithDetails apply (ComputerWithDetails computerWithDetails ) {
49+ computerWithDetails .setClient (client );
50+ return computerWithDetails ;
51+ }
52+ });
3753 }
3854
3955 public void setComputer (List <ComputerWithDetails > computers ) {
Original file line number Diff line number Diff line change 77package com .offbytwo .jenkins .model ;
88
99import java .io .IOException ;
10+ import java .util .HashMap ;
1011import java .util .List ;
1112import java .util .Map ;
1213
@@ -30,6 +31,9 @@ public class ComputerWithDetails extends Computer {
3031 List oneOffExecutors ;
3132 Boolean temporarilyOffline ;
3233
34+ public ComputerWithDetails ()
35+ {
36+ }
3337 public String getDisplayName () {
3438 return displayName ;
3539 }
@@ -75,6 +79,24 @@ public LoadStatistics getLoadStatistics() throws IOException {
7579 return client .get ("/computer/" + name + "/" + "loadStatistics/?depth=2" , LoadStatistics .class );
7680 }
7781
82+ public void toggleOffline (boolean crumbFlag ) throws IOException {
83+ // curl --data "json=init" -X POST "http://192.168.99.100:8080/computer/(master)/toggleOffline"
84+ String name ;
85+ if ("master" .equals (displayName )) {
86+ name = "(master)" ;
87+ } else {
88+ name = UrlEscapers .urlPathSegmentEscaper ().escape (displayName );
89+ }
90+
91+ Map <String , String > data = new HashMap <String , String >();
92+ data .put ( "json" , "init" );
93+ client .post ( "/computer/" + name + "/toggleOffline" , crumbFlag );
94+ }
95+
96+ public void toggleOffline () throws IOException {
97+ toggleOffline ( false );
98+ }
99+
78100 public Boolean getManualLaunchAllowed () {
79101 return manualLaunchAllowed ;
80102 }
Original file line number Diff line number Diff line change @@ -38,4 +38,14 @@ public void shouldGetComputerWithDetailsAndExecutors() throws IOException {
3838 assertThat (computerWithDetails .getNumExecutors ()).isEqualTo (ji .getNumExecutors ());
3939 assertThat (computerWithDetails .getOfflineCause ()).isNull ();
4040 }
41+
42+ @ Test
43+ public void shouldTrunFromOnlineToOffline () throws IOException {
44+ ComputerWithDetails computerWithDetails = jenkinsServer .getComputerSet ().getComputer ().get ( 0 );
45+ computerWithDetails .toggleOffline (true );
46+
47+ ComputerWithDetails computerWithDetailsAfterStarting = jenkinsServer .getComputerSet ().getComputer ().get ( 0 );
48+
49+ assertThat ( computerWithDetailsAfterStarting .getOffline () ).isTrue ();
50+ }
4151}
Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ public void shouldBuildAJob() throws Exception {
158158 assertTrue (jenkinsRule .getInstance ().getJobNames ().contains (jobName ));
159159
160160 JobWithDetails job = server .getJob (jobName );
161- job .build ();
161+ job .build (true );
162162
163163 while (project .isInQueue () || project .isBuilding ()) {
164164 }
You can’t perform that action at this time.
0 commit comments