1 package org.apache.continuum.distributed.transport.slave;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import com.atlassian.xmlrpc.AuthenticationInfo;
23 import com.atlassian.xmlrpc.Binder;
24 import com.atlassian.xmlrpc.BindingException;
25 import com.atlassian.xmlrpc.DefaultBinder;
26
27 import java.net.URL;
28 import java.util.List;
29 import java.util.Map;
30
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34
35
36
37 public class SlaveBuildAgentTransportClient
38 implements SlaveBuildAgentTransportService
39 {
40 private static final Logger log = LoggerFactory.getLogger( SlaveBuildAgentTransportClient.class );
41
42 private SlaveBuildAgentTransportService slave;
43
44 public SlaveBuildAgentTransportClient( URL serviceUrl )
45 throws Exception
46 {
47 this( serviceUrl, null, null );
48 }
49
50 public SlaveBuildAgentTransportClient( URL serviceUrl, String login, String password )
51 throws Exception
52 {
53 Binder binder = new DefaultBinder();
54 AuthenticationInfo authnInfo = new AuthenticationInfo( login, password );
55
56 try
57 {
58 slave = binder.bind( SlaveBuildAgentTransportService.class, serviceUrl, authnInfo );
59 }
60 catch ( BindingException e )
61 {
62 log.error( "Can't bind service interface " + SlaveBuildAgentTransportService.class.getName() + " to " +
63 serviceUrl.toExternalForm() + " using " + authnInfo.getUsername() + ", " + authnInfo.getPassword(), e );
64 throw new Exception(
65 "Can't bind service interface " + SlaveBuildAgentTransportService.class.getName() + " to " +
66 serviceUrl.toExternalForm() + " using " + authnInfo.getUsername() + ", " + authnInfo.getPassword(),
67 e );
68 }
69 }
70
71 public Boolean buildProjects( List<Map<String, Object>> projectsBuildContext )
72 throws Exception
73 {
74 Boolean result;
75
76 try
77 {
78 result = slave.buildProjects( projectsBuildContext );
79 log.info( "Building projects." );
80 }
81 catch ( Exception e )
82 {
83 log.error( "Failed to build projects.", e );
84 throw new Exception( "Failed to build projects.", e );
85 }
86
87 return result;
88 }
89
90 public List<Map<String, String>> getAvailableInstallations()
91 throws Exception
92 {
93 List<Map<String, String>> installations;
94
95 try
96 {
97 installations = slave.getAvailableInstallations();
98 log.info( "Available installations: " + installations.size() );
99 }
100 catch ( Exception e )
101 {
102 log.error( "Failed to get available installations.", e );
103 throw new Exception( "Failed to get available installations.", e );
104 }
105
106 return installations;
107 }
108
109 public Map<String, Object> getBuildResult( int projectId )
110 throws Exception
111 {
112 Map<String, Object> buildResult;
113
114 try
115 {
116 buildResult = slave.getBuildResult( projectId );
117 log.info( "Build result for project " + projectId + " acquired." );
118 }
119 catch ( Exception e )
120 {
121 log.error( "Failed to get build result for project " + projectId, e );
122 throw new Exception( "Failed to get build result for project " + projectId, e );
123 }
124
125 return buildResult;
126 }
127
128 public Map<String, Object> getProjectCurrentlyBuilding()
129 throws Exception
130 {
131 Map map;
132
133 try
134 {
135 map = slave.getProjectCurrentlyBuilding();
136 log.info( "Retrieving currently building project" );
137 }
138 catch ( Exception e )
139 {
140 log.error( "Failed to get the currently building project", e );
141 throw new Exception( "Failed to get the currently building project", e );
142 }
143
144 return map;
145 }
146
147 public Boolean ping()
148 throws Exception
149 {
150 Boolean result;
151
152 try
153 {
154 result = slave.ping();
155 log.info( "Ping " + ( result ? "ok" : "failed" ) );
156 }
157 catch ( Exception e )
158 {
159 log.info( "Ping error" );
160 throw new Exception( "Ping error", e );
161 }
162
163 return result;
164 }
165
166 public Boolean cancelBuild()
167 throws Exception
168 {
169 Boolean result;
170
171 try
172 {
173 result = slave.cancelBuild();
174 log.info( "Cancelled build" );
175 }
176 catch ( Exception e )
177 {
178 log.error( "Error cancelling build" );
179 throw new Exception( "Error cancelling build", e );
180 }
181
182 return result;
183 }
184
185 public String generateWorkingCopyContent( int projectId, String directory, String baseUrl, String imagesBaseUrl )
186 throws Exception
187 {
188 String result;
189
190 try
191 {
192 result = slave.generateWorkingCopyContent( projectId, directory, baseUrl, imagesBaseUrl );
193 log.info( "Generated working copy content" );
194 }
195 catch ( Exception e )
196 {
197 log.error( "Error generating working copy content", e );
198 throw new Exception( "Error generating working copy content", e );
199 }
200
201 return result;
202 }
203
204 public String getProjectFileContent( int projectId, String directory, String filename )
205 throws Exception
206 {
207 String result;
208
209 try
210 {
211 result = slave.getProjectFileContent( projectId, directory, filename );
212 log.info( "Retrived project file content" );
213 }
214 catch ( Exception e )
215 {
216 log.error( "Error retrieving project file content", e );
217 throw new Exception( "Error retrieving project file content", e );
218 }
219
220 return result;
221 }
222
223 public Map getReleasePluginParameters( int projectId, String pomFilename )
224 throws Exception
225 {
226 Map result;
227
228 try
229 {
230 result = slave.getReleasePluginParameters( projectId, pomFilename );
231 log.info( "Retrieving release plugin parameters" );
232 }
233 catch ( Exception e )
234 {
235 log.error( "Error retrieving release plugin parameters", e );
236 throw new Exception( "Error retrieving release plugin parameters", e );
237 }
238
239 return result;
240 }
241
242 public List<Map<String, String>> processProject( int projectId, String pomFilename, boolean autoVersionSubmodules )
243 throws Exception
244 {
245 List<Map<String, String>> result;
246
247 try
248 {
249 result = slave.processProject( projectId, pomFilename, autoVersionSubmodules );
250 log.info( "Processing project" );
251 }
252 catch ( Exception e )
253 {
254 log.error( "Error processing project", e );
255 throw new Exception( "Error processing project", e );
256 }
257
258 return result;
259 }
260
261 public String releasePrepare( Map project, Map properties, Map releaseVersion, Map developmentVersion,
262 Map environments )
263 throws Exception
264 {
265 String releaseId;
266
267 try
268 {
269 releaseId = slave.releasePrepare( project, properties, releaseVersion, developmentVersion, environments );
270 log.info( "Preparing release" );
271 }
272 catch ( Exception e )
273 {
274 log.error( "Error while preparing release", e );
275 throw new Exception( "Error while preparing release", e );
276 }
277
278 return releaseId;
279 }
280
281 public Map<String, Object> getReleaseResult( String releaseId )
282 throws Exception
283 {
284 Map result;
285
286 try
287 {
288 result = slave.getReleaseResult( releaseId );
289 log.info( "Retrieving release result for " + releaseId );
290 }
291 catch ( Exception e )
292 {
293 log.error( "Error retrieving release result for " + releaseId, e );
294 throw new Exception( "Error retrieving release result for " + releaseId, e );
295 }
296
297 return result;
298 }
299
300 public Map getListener( String releaseId )
301 throws Exception
302 {
303 Map result;
304
305 try
306 {
307 result = slave.getListener( releaseId );
308 log.info( "Retrieving listener for " + releaseId );
309 }
310 catch ( Exception e )
311 {
312 log.error( "Error retrieving listener for " + releaseId, e );
313 throw new Exception( "Error retrieving listener for " + releaseId, e );
314 }
315
316 return result;
317 }
318
319 public Boolean removeListener( String releaseId )
320 throws Exception
321 {
322 Boolean result;
323
324 try
325 {
326 slave.removeListener( releaseId );
327 result = Boolean.FALSE;
328 log.info( "Removing listener for " + releaseId );
329 }
330 catch ( Exception e )
331 {
332 log.error( "Error removing listener for " + releaseId, e );
333 throw new Exception( "Error removing listener for " + releaseId, e );
334 }
335
336 return result;
337 }
338
339 public String getPreparedReleaseName( String releaseId )
340 throws Exception
341 {
342 String result;
343
344 try
345 {
346 result = slave.getPreparedReleaseName( releaseId );
347 log.info( "Retrieving prepared release name for " + releaseId );
348 }
349 catch ( Exception e )
350 {
351 log.error( "Error while retrieving prepared release name for " + releaseId );
352 throw new Exception( "Error while retrieving prepared release name for " + releaseId );
353 }
354
355 return result;
356 }
357
358 public Boolean releasePerform( String releaseId, String goals, String arguments, boolean useReleaseProfile,
359 Map repository )
360 throws Exception
361 {
362 Boolean result;
363
364 try
365 {
366 slave.releasePerform( releaseId, goals, arguments, useReleaseProfile, repository );
367 result = Boolean.FALSE;
368 log.info( "Performing release" );
369 }
370 catch ( Exception e )
371 {
372 log.error( "Error performing release", e );
373 throw new Exception( "Error performing release", e );
374 }
375
376 return result;
377 }
378
379 public String releasePerformFromScm( String goals, String arguments, boolean useReleaseProfile, Map repository,
380 String scmUrl, String scmUsername, String scmPassword, String scmTag,
381 String scmTagBase, Map environments )
382 throws Exception
383 {
384 String result;
385
386 try
387 {
388 result = slave.releasePerformFromScm( goals, arguments, useReleaseProfile, repository, scmUrl, scmUsername,
389 scmPassword, scmTag, scmTagBase, environments );
390 log.info( "Performing release" );
391 }
392 catch ( Exception e )
393 {
394 log.error( "Error performing release from scm", e );
395 throw new Exception( "Error performing release from scm", e );
396 }
397
398 return result;
399 }
400
401 public String releaseCleanup( String releaseId )
402 throws Exception
403 {
404 String result;
405
406 try
407 {
408 result = slave.releaseCleanup( releaseId );
409 log.info( "Cleanup release of " + releaseId );
410 }
411 catch ( Exception e )
412 {
413 log.error( "Error cleaning up release of " + releaseId, e );
414 throw new Exception( "Error cleaning up release of " + releaseId, e );
415 }
416
417 return result;
418 }
419
420 public Boolean releaseRollback( String releaseId, int projectId )
421 throws Exception
422 {
423 Boolean result;
424
425 try
426 {
427 slave.releaseRollback( releaseId, projectId );
428 result = Boolean.TRUE;
429 log.info( "Rollback release " + releaseId );
430 }
431 catch ( Exception e )
432 {
433 log.error( "Failed to rollback release " + releaseId );
434 throw new Exception( "Failed to rollback release " + releaseId );
435 }
436
437 return result;
438 }
439
440 public Integer getBuildSizeOfAgent()
441 throws Exception
442 {
443 Integer size;
444
445 try
446 {
447 size = slave.getBuildSizeOfAgent();
448 log.info( "Retrieving build size of agent" );
449 }
450 catch ( Exception e )
451 {
452 log.error( "Failed to retrieve build size of agent", e );
453 throw new Exception( "Failed to retrieve build size of agent", e );
454 }
455
456 return size;
457 }
458
459 public Map<String, Object> getProjectCurrentlyPreparingBuild()
460 throws Exception
461 {
462 Map<String, Object> projects;
463
464 try
465 {
466 projects = slave.getProjectCurrentlyPreparingBuild();
467 log.info( "Retrieving projects currently preparing build" );
468 }
469 catch ( Exception e )
470 {
471 log.error( "Failed to retrieve projects currently preparing build", e );
472 throw new Exception( "Failed to retrieve projects currently preparing build", e );
473 }
474
475 return projects;
476 }
477
478 public List<Map<String, Object>> getProjectsInBuildQueue()
479 throws Exception
480 {
481 List<Map<String, Object>> projects;
482
483 try
484 {
485 projects = slave.getProjectsInBuildQueue();
486 log.info( "Retrieving projects in build queue" );
487 }
488 catch ( Exception e )
489 {
490 log.error( "Failed to retrieve projects in build queue", e );
491 throw new Exception( "Failed to retrieve projects in build queue", e );
492 }
493
494 return projects;
495 }
496
497 public List<Map<String, Object>> getProjectsInPrepareBuildQueue()
498 throws Exception
499 {
500 List<Map<String, Object>> projects;
501
502 try
503 {
504 projects = slave.getProjectsInPrepareBuildQueue();
505 log.info( "Retrieving projects in prepare build queue" );
506 }
507 catch ( Exception e )
508 {
509 log.error( "Failed to retrieve projects in prepare build queue", e );
510 throw new Exception( "Failed to retrieve projects in prepare build queue", e );
511 }
512
513 return projects;
514 }
515
516 public Boolean isProjectGroupInQueue( int projectGroupId )
517 throws Exception
518 {
519 Boolean result;
520
521 try
522 {
523 result = slave.isProjectGroupInQueue( projectGroupId );
524 log.info( "Checking if project group is in queue" );
525 }
526 catch ( Exception e )
527 {
528 log.error( "Failed to check if project group is in queue", e );
529 throw new Exception( "Failed to check if project group is in queue", e );
530 }
531
532 return result;
533 }
534
535 public Boolean isProjectCurrentlyBuilding( int projectId )
536 throws Exception
537 {
538 Boolean result;
539
540 try
541 {
542 result = slave.isProjectCurrentlyBuilding( projectId );
543 log.info( "Checking if project " + projectId + " is currently building in agent" );
544 }
545 catch ( Exception e )
546 {
547 log.error( "Failed to check if project " + projectId + " is currently building in agent", e );
548 throw new Exception( "Failed to check if project " + projectId + " is currently building in agent", e );
549 }
550
551 return result;
552 }
553
554 public Boolean isProjectInBuildQueue( int projectId )
555 throws Exception
556 {
557 Boolean result;
558
559 try
560 {
561 result = slave.isProjectInBuildQueue( projectId );
562 log.info( "Checking if project " + projectId + "is in build queue of agent" );
563 }
564 catch ( Exception e )
565 {
566 log.error( "Failed to check if project " + projectId + " is in build queue of agent", e );
567 throw new Exception( "Failed to check if project " + projectId + " is in build queue of agent", e );
568 }
569
570 return result;
571 }
572
573 public Boolean removeFromPrepareBuildQueue( int projectGroupId, int scmRootId )
574 throws Exception
575 {
576 Boolean result;
577
578 try
579 {
580 result = slave.removeFromPrepareBuildQueue( projectGroupId, scmRootId );
581 log.info( "Removing projectGroupId=" + projectGroupId + " scmRootId=" + scmRootId +
582 " from prepare build queue of agent" );
583 }
584 catch ( Exception e )
585 {
586 log.error( "Failed to remove projectGroupId=" + projectGroupId + " scmRootId=" + scmRootId +
587 " from prepare build queue of agent", e );
588 throw new Exception( "Failed to remove projectGroupId=" + projectGroupId + " scmRootId=" + scmRootId +
589 " from prepare build queue of agent", e );
590 }
591
592 return result;
593 }
594
595 public Boolean removeFromPrepareBuildQueue( List<String> hashCodes )
596 throws Exception
597 {
598 Boolean result;
599
600 try
601 {
602 result = slave.removeFromPrepareBuildQueue( hashCodes );
603 log.info( "Removing projects from prepare build queue of agent" );
604 }
605 catch ( Exception e )
606 {
607 log.error( "Failed to remove projects from prepare build queue of agent", e );
608 throw new Exception( "Failed to remove projects from prepare build queue of agent", e );
609 }
610
611 return result;
612 }
613
614 public Boolean removeFromBuildQueue( int projectId, int buildDefinitionId )
615 throws Exception
616 {
617 Boolean result;
618
619 try
620 {
621 result = slave.removeFromBuildQueue( projectId, buildDefinitionId );
622 log.info( "Removing project " + projectId + " from build queue of agent" );
623 }
624 catch ( Exception e )
625 {
626 log.error( "Failed to remove project " + projectId + " from build queue of agent", e );
627 throw new Exception( "Failed to remove project " + projectId + " from build queue of agent", e );
628 }
629
630 return result;
631 }
632
633 public Boolean removeFromBuildQueue( List<String> hashCodes )
634 throws Exception
635 {
636 Boolean result;
637
638 try
639 {
640 result = slave.removeFromBuildQueue( hashCodes );
641 log.info( "Removing projects from build queue of agent" );
642 }
643 catch ( Exception e )
644 {
645 log.error( "Failed to remove projects from build queue of agent", e );
646 throw new Exception( "Failed to remove projects from build queue of agent", e );
647 }
648
649 return result;
650 }
651 }