1 package org.apache.continuum.buildagent.manager;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.net.MalformedURLException;
23 import java.net.URL;
24 import java.util.Map;
25
26 import org.apache.continuum.buildagent.configuration.BuildAgentConfigurationService;
27 import org.apache.continuum.distributed.transport.master.MasterBuildAgentTransportClient;
28 import org.apache.maven.continuum.ContinuumException;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35 public class DefaultBuildAgentManager
36 implements BuildAgentManager
37 {
38 private static final Logger log = LoggerFactory.getLogger( DefaultBuildAgentManager.class );
39
40
41
42
43 private BuildAgentConfigurationService buildAgentConfigurationService;
44
45 public void startProjectBuild( int projectId )
46 throws ContinuumException
47 {
48 try
49 {
50 MasterBuildAgentTransportClient client =
51 new MasterBuildAgentTransportClient( new URL( buildAgentConfigurationService.getContinuumServerUrl() ) )
52 ;
53 client.startProjectBuild( projectId );
54 }
55 catch ( MalformedURLException e )
56 {
57 log.error(
58 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
59 throw new ContinuumException(
60 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
61 }
62 catch ( Exception e )
63 {
64 log.error( "Error starting project build", e );
65 throw new ContinuumException( "Error starting project build", e );
66 }
67 }
68
69 public void returnBuildResult( Map buildResult )
70 throws ContinuumException
71 {
72 try
73 {
74 MasterBuildAgentTransportClient client =
75 new MasterBuildAgentTransportClient( new URL( buildAgentConfigurationService.getContinuumServerUrl() ) )
76 ;
77 client.returnBuildResult( buildResult );
78 }
79 catch ( MalformedURLException e )
80 {
81 log.error(
82 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
83 throw new ContinuumException(
84 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
85 }
86 catch ( Exception e )
87 {
88 log.error( "Error while returning build result to the continuum server", e );
89 throw new ContinuumException( e.getMessage(), e );
90 }
91 }
92
93 public Map<String, String> getEnvironments( int buildDefinitionId, String installationType )
94 throws ContinuumException
95 {
96 try
97 {
98 MasterBuildAgentTransportClient client =
99 new MasterBuildAgentTransportClient( new URL( buildAgentConfigurationService.getContinuumServerUrl() ) )
100 ;
101 return client.getEnvironments( buildDefinitionId, installationType );
102 }
103 catch ( MalformedURLException e )
104 {
105 log.error(
106 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
107 throw new ContinuumException(
108 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
109 }
110 catch ( Exception e )
111 {
112 log.error( "Error while retrieving environments for build definition " + buildDefinitionId, e );
113 throw new ContinuumException( e.getMessage(), e );
114 }
115 }
116
117 public void updateProject( Map project )
118 throws ContinuumException
119 {
120 try
121 {
122 MasterBuildAgentTransportClient client =
123 new MasterBuildAgentTransportClient( new URL( buildAgentConfigurationService.getContinuumServerUrl() ) )
124 ;
125 client.updateProject( project );
126 }
127 catch ( MalformedURLException e )
128 {
129 log.error(
130 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
131 throw new ContinuumException(
132 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
133 }
134 catch ( Exception e )
135 {
136 log.error( "Error while updating project", e );
137 throw new ContinuumException( e.getMessage(), e );
138 }
139 }
140
141 public boolean shouldBuild( Map<String, Object> context )
142 throws ContinuumException
143 {
144 try
145 {
146 MasterBuildAgentTransportClient client =
147 new MasterBuildAgentTransportClient( new URL( buildAgentConfigurationService.getContinuumServerUrl() ) )
148 ;
149 return client.shouldBuild( context );
150 }
151 catch ( MalformedURLException e )
152 {
153 log.error(
154 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
155 throw new ContinuumException(
156 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
157 }
158 catch ( Exception e )
159 {
160 log.error( "Failed to determine if project should build", e );
161 throw new ContinuumException( "Failed to determine if project should build", e );
162 }
163 }
164
165 public void startPrepareBuild( Map<String, Object> context )
166 throws ContinuumException
167 {
168 try
169 {
170 MasterBuildAgentTransportClient client =
171 new MasterBuildAgentTransportClient( new URL( buildAgentConfigurationService.getContinuumServerUrl() ) )
172 ;
173 client.startPrepareBuild( context );
174 }
175 catch ( MalformedURLException e )
176 {
177 log.error(
178 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
179 throw new ContinuumException(
180 "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'", e );
181 }
182 catch ( Exception e )
183 {
184 log.error( "Error starting prepare build", e );
185 throw new ContinuumException( "Error starting prepare build", e );
186 }
187 }
188
189 public void endPrepareBuild( Map<String, Object> context )
190 throws ContinuumException
191 {
192 try
193 {
194 MasterBuildAgentTransportClient client =
195 new MasterBuildAgentTransportClient( new URL( buildAgentConfigurationService.getContinuumServerUrl() ) )
196 ;
197 client.prepareBuildFinished( context );
198 }
199 catch ( MalformedURLException e )
200 {
201 throw new ContinuumException(
202 "Invalid Continuum Server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
203 }
204 catch ( Exception e )
205 {
206 throw new ContinuumException( "Error while finishing prepare build", e );
207 }
208 }
209 }