Skip to content

Commit eada24b

Browse files
committed
o Added OfflineCause as a real object in ComputerWithDetails
1 parent 7a2c13d commit eada24b

6 files changed

Lines changed: 180 additions & 68 deletions

File tree

src/main/java/com/offbytwo/jenkins/JenkinsServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public String apply(Computer computer) {
421421
* @throws IOException
422422
*/
423423
public ComputerSet getComputerSet() throws IOException {
424-
return client.get("computer/", ComputerSet.class);
424+
return client.get("computer/?depth=2", ComputerSet.class);
425425
}
426426

427427
/**

src/main/java/com/offbytwo/jenkins/model/Computer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public ComputerWithDetails details() throws IOException {
4444
} else {
4545
name = UrlEscapers.urlPathSegmentEscaper().escape(displayName);
4646
}
47-
return client.get("/computer/" + name, ComputerWithDetails.class);
47+
//TODO: Check if depth=2 is a good idea or if it could be solved
48+
// better.
49+
ComputerWithDetails computerWithDetails = client.get("/computer/" + name + "/?depth=2", ComputerWithDetails.class);
50+
computerWithDetails.setClient( client );
51+
return computerWithDetails;
4852
}
4953

5054
@Override

src/main/java/com/offbytwo/jenkins/model/ComputerWithDetails.java

Lines changed: 96 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public class ComputerWithDetails extends Computer {
2525
Map monitorData;
2626
Integer numExecutors;
2727
Boolean offline;
28-
Object offlineCause;
29-
String offlineReason;
28+
OfflineCause offlineCause;
29+
String offlineCauseReason;
3030
List oneOffExecutors;
3131
Boolean temporarilyOffline;
3232

@@ -91,12 +91,12 @@ public Boolean getOffline() {
9191
return offline;
9292
}
9393

94-
public Object getOfflineCause() {
94+
public OfflineCause getOfflineCause() throws IOException {
9595
return offlineCause;
9696
}
9797

98-
public String getOfflineReason() {
99-
return offlineReason;
98+
public String getOfflineCauseReason() {
99+
return offlineCauseReason;
100100
}
101101

102102
public List<Map> getOneOffExecutors() {
@@ -108,105 +108,135 @@ public Boolean getTemporarilyOffline() {
108108
}
109109

110110
@Override
111-
public boolean equals(Object obj) {
112-
if (this == obj)
111+
public boolean equals( Object obj )
112+
{
113+
if ( this == obj )
113114
return true;
114-
if (!super.equals(obj))
115+
if ( !super.equals( obj ) )
115116
return false;
116-
if (getClass() != obj.getClass())
117+
if ( getClass() != obj.getClass() )
117118
return false;
118119
ComputerWithDetails other = (ComputerWithDetails) obj;
119-
if (actions == null) {
120-
if (other.actions != null)
120+
if ( actions == null )
121+
{
122+
if ( other.actions != null )
121123
return false;
122-
} else if (!actions.equals(other.actions))
124+
}
125+
else if ( !actions.equals( other.actions ) )
123126
return false;
124-
if (displayName == null) {
125-
if (other.displayName != null)
127+
if ( displayName == null )
128+
{
129+
if ( other.displayName != null )
126130
return false;
127-
} else if (!displayName.equals(other.displayName))
131+
}
132+
else if ( !displayName.equals( other.displayName ) )
128133
return false;
129-
if (executors == null) {
130-
if (other.executors != null)
134+
if ( executors == null )
135+
{
136+
if ( other.executors != null )
131137
return false;
132-
} else if (!executors.equals(other.executors))
138+
}
139+
else if ( !executors.equals( other.executors ) )
133140
return false;
134-
if (idle == null) {
135-
if (other.idle != null)
141+
if ( idle == null )
142+
{
143+
if ( other.idle != null )
136144
return false;
137-
} else if (!idle.equals(other.idle))
145+
}
146+
else if ( !idle.equals( other.idle ) )
138147
return false;
139-
if (jnlp == null) {
140-
if (other.jnlp != null)
148+
if ( jnlp == null )
149+
{
150+
if ( other.jnlp != null )
141151
return false;
142-
} else if (!jnlp.equals(other.jnlp))
152+
}
153+
else if ( !jnlp.equals( other.jnlp ) )
143154
return false;
144-
if (launchSupported == null) {
145-
if (other.launchSupported != null)
155+
if ( launchSupported == null )
156+
{
157+
if ( other.launchSupported != null )
146158
return false;
147-
} else if (!launchSupported.equals(other.launchSupported))
159+
}
160+
else if ( !launchSupported.equals( other.launchSupported ) )
148161
return false;
149-
if (manualLaunchAllowed == null) {
150-
if (other.manualLaunchAllowed != null)
162+
if ( manualLaunchAllowed == null )
163+
{
164+
if ( other.manualLaunchAllowed != null )
151165
return false;
152-
} else if (!manualLaunchAllowed.equals(other.manualLaunchAllowed))
166+
}
167+
else if ( !manualLaunchAllowed.equals( other.manualLaunchAllowed ) )
153168
return false;
154-
if (monitorData == null) {
155-
if (other.monitorData != null)
169+
if ( monitorData == null )
170+
{
171+
if ( other.monitorData != null )
156172
return false;
157-
} else if (!monitorData.equals(other.monitorData))
173+
}
174+
else if ( !monitorData.equals( other.monitorData ) )
158175
return false;
159-
if (numExecutors == null) {
160-
if (other.numExecutors != null)
176+
if ( numExecutors == null )
177+
{
178+
if ( other.numExecutors != null )
161179
return false;
162-
} else if (!numExecutors.equals(other.numExecutors))
180+
}
181+
else if ( !numExecutors.equals( other.numExecutors ) )
163182
return false;
164-
if (offline == null) {
165-
if (other.offline != null)
183+
if ( offline == null )
184+
{
185+
if ( other.offline != null )
166186
return false;
167-
} else if (!offline.equals(other.offline))
187+
}
188+
else if ( !offline.equals( other.offline ) )
168189
return false;
169-
if (offlineCause == null) {
170-
if (other.offlineCause != null)
190+
if ( offlineCause == null )
191+
{
192+
if ( other.offlineCause != null )
171193
return false;
172-
} else if (!offlineCause.equals(other.offlineCause))
194+
}
195+
else if ( !offlineCause.equals( other.offlineCause ) )
173196
return false;
174-
if (offlineReason == null) {
175-
if (other.offlineReason != null)
197+
if ( offlineCauseReason == null )
198+
{
199+
if ( other.offlineCauseReason != null )
176200
return false;
177-
} else if (!offlineReason.equals(other.offlineReason))
201+
}
202+
else if ( !offlineCauseReason.equals( other.offlineCauseReason ) )
178203
return false;
179-
if (oneOffExecutors == null) {
180-
if (other.oneOffExecutors != null)
204+
if ( oneOffExecutors == null )
205+
{
206+
if ( other.oneOffExecutors != null )
181207
return false;
182-
} else if (!oneOffExecutors.equals(other.oneOffExecutors))
208+
}
209+
else if ( !oneOffExecutors.equals( other.oneOffExecutors ) )
183210
return false;
184-
if (temporarilyOffline == null) {
185-
if (other.temporarilyOffline != null)
211+
if ( temporarilyOffline == null )
212+
{
213+
if ( other.temporarilyOffline != null )
186214
return false;
187-
} else if (!temporarilyOffline.equals(other.temporarilyOffline))
215+
}
216+
else if ( !temporarilyOffline.equals( other.temporarilyOffline ) )
188217
return false;
189218
return true;
190219
}
191220

192221
@Override
193-
public int hashCode() {
222+
public int hashCode()
223+
{
194224
final int prime = 31;
195225
int result = super.hashCode();
196-
result = prime * result + ((actions == null) ? 0 : actions.hashCode());
197-
result = prime * result + ((displayName == null) ? 0 : displayName.hashCode());
198-
result = prime * result + ((executors == null) ? 0 : executors.hashCode());
199-
result = prime * result + ((idle == null) ? 0 : idle.hashCode());
200-
result = prime * result + ((jnlp == null) ? 0 : jnlp.hashCode());
201-
result = prime * result + ((launchSupported == null) ? 0 : launchSupported.hashCode());
202-
result = prime * result + ((manualLaunchAllowed == null) ? 0 : manualLaunchAllowed.hashCode());
203-
result = prime * result + ((monitorData == null) ? 0 : monitorData.hashCode());
204-
result = prime * result + ((numExecutors == null) ? 0 : numExecutors.hashCode());
205-
result = prime * result + ((offline == null) ? 0 : offline.hashCode());
206-
result = prime * result + ((offlineCause == null) ? 0 : offlineCause.hashCode());
207-
result = prime * result + ((offlineReason == null) ? 0 : offlineReason.hashCode());
208-
result = prime * result + ((oneOffExecutors == null) ? 0 : oneOffExecutors.hashCode());
209-
result = prime * result + ((temporarilyOffline == null) ? 0 : temporarilyOffline.hashCode());
226+
result = prime * result + ( ( actions == null ) ? 0 : actions.hashCode() );
227+
result = prime * result + ( ( displayName == null ) ? 0 : displayName.hashCode() );
228+
result = prime * result + ( ( executors == null ) ? 0 : executors.hashCode() );
229+
result = prime * result + ( ( idle == null ) ? 0 : idle.hashCode() );
230+
result = prime * result + ( ( jnlp == null ) ? 0 : jnlp.hashCode() );
231+
result = prime * result + ( ( launchSupported == null ) ? 0 : launchSupported.hashCode() );
232+
result = prime * result + ( ( manualLaunchAllowed == null ) ? 0 : manualLaunchAllowed.hashCode() );
233+
result = prime * result + ( ( monitorData == null ) ? 0 : monitorData.hashCode() );
234+
result = prime * result + ( ( numExecutors == null ) ? 0 : numExecutors.hashCode() );
235+
result = prime * result + ( ( offline == null ) ? 0 : offline.hashCode() );
236+
result = prime * result + ( ( offlineCause == null ) ? 0 : offlineCause.hashCode() );
237+
result = prime * result + ( ( offlineCauseReason == null ) ? 0 : offlineCauseReason.hashCode() );
238+
result = prime * result + ( ( oneOffExecutors == null ) ? 0 : oneOffExecutors.hashCode() );
239+
result = prime * result + ( ( temporarilyOffline == null ) ? 0 : temporarilyOffline.hashCode() );
210240
return result;
211241
}
212242

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.offbytwo.jenkins.model;
2+
3+
/**
4+
* @author Karl Heinz Marbaise
5+
*/
6+
public class OfflineCause
7+
extends BaseModel
8+
{
9+
10+
private Long timestamp;
11+
12+
private String description;
13+
14+
public Long getTimestamp()
15+
{
16+
return timestamp;
17+
}
18+
19+
public String getDescription()
20+
{
21+
return description;
22+
}
23+
24+
@Override
25+
public int hashCode()
26+
{
27+
final int prime = 31;
28+
int result = 1;
29+
result = prime * result + ( ( description == null ) ? 0 : description.hashCode() );
30+
result = prime * result + ( ( timestamp == null ) ? 0 : timestamp.hashCode() );
31+
return result;
32+
}
33+
34+
@Override
35+
public boolean equals( Object obj )
36+
{
37+
if ( this == obj )
38+
return true;
39+
if ( obj == null )
40+
return false;
41+
if ( getClass() != obj.getClass() )
42+
return false;
43+
OfflineCause other = (OfflineCause) obj;
44+
if ( description == null )
45+
{
46+
if ( other.description != null )
47+
return false;
48+
}
49+
else if ( !description.equals( other.description ) )
50+
return false;
51+
if ( timestamp == null )
52+
{
53+
if ( other.timestamp != null )
54+
return false;
55+
}
56+
else if ( !timestamp.equals( other.timestamp ) )
57+
return false;
58+
return true;
59+
}
60+
61+
public void setTimestamp( Long timestamp )
62+
{
63+
this.timestamp = timestamp;
64+
}
65+
66+
public void setDescription( String description )
67+
{
68+
this.description = description;
69+
}
70+
71+
}

src/main/java/com/offbytwo/jenkins/model/Statis.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* Copyright (c) 2013 Rising Oak LLC.
3+
*
4+
* Distributed under the MIT license: http://opensource.org/licenses/MIT
5+
*/
6+
17
package com.offbytwo.jenkins.model;
28

39
import java.util.List;

src/test/java/com/offbytwo/jenkins/integration/ComputerSetIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ public void shouldGetComputerWithDetailsAndExecutors() throws IOException {
3636
ComputerWithDetails computerWithDetails = computerSet.get(0);
3737
assertThat(computerWithDetails.getExecutors()).isNotNull();
3838
assertThat(computerWithDetails.getNumExecutors()).isEqualTo(ji.getNumExecutors());
39+
assertThat(computerWithDetails.getOfflineCause()).isNull();
3940
}
4041
}

0 commit comments

Comments
 (0)