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