View Javadoc

1   package org.apache.continuum.distributed.transport.master;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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.Map;
29  
30  import org.slf4j.Logger;
31  import org.slf4j.LoggerFactory;
32  
33  /**
34   * MasterBuildAgentTransportClient
35   */
36  public class MasterBuildAgentTransportClient
37      implements MasterBuildAgentTransportService
38  {
39      private static final Logger log = LoggerFactory.getLogger( MasterBuildAgentTransportClient.class );
40  
41      MasterBuildAgentTransportService master;
42  
43      public MasterBuildAgentTransportClient( URL serviceUrl )
44          throws Exception
45      {
46          this( serviceUrl, null, null );
47      }
48  
49      public MasterBuildAgentTransportClient( URL serviceUrl, String login, String password )
50          throws Exception
51      {
52          Binder binder = new DefaultBinder();
53          AuthenticationInfo authnInfo = new AuthenticationInfo( login, password );
54  
55          try
56          {
57              master = binder.bind( MasterBuildAgentTransportService.class, serviceUrl, authnInfo );
58          }
59          catch ( BindingException e )
60          {
61              log.error( "Can't bind service interface " + MasterBuildAgentTransportService.class.getName() + " to " +
62                  serviceUrl.toExternalForm() + " using " + authnInfo.getUsername() + ", " + authnInfo.getPassword(), e );
63              throw new Exception(
64                  "Can't bind service interface " + MasterBuildAgentTransportService.class.getName() + " to " +
65                      serviceUrl.toExternalForm() + " using " + authnInfo.getUsername() + ", " + authnInfo.getPassword(),
66                  e );
67          }
68      }
69  
70      public Boolean returnBuildResult( Map<String, Object> buildResult )
71          throws Exception
72      {
73          Boolean result;
74  
75          try
76          {
77              result = master.returnBuildResult( buildResult );
78              log.info( "Returning the build result." );
79          }
80          catch ( Exception e )
81          {
82              log.error( "Failed to return the build result.", e );
83              throw new Exception( "Failed to return the build result", e );
84          }
85  
86          return result;
87      }
88  
89      public Boolean ping()
90          throws Exception
91      {
92          Boolean result;
93  
94          try
95          {
96              result = master.ping();
97              log.info( "Ping " + ( result ? "ok" : "failed" ) );
98          }
99          catch ( Exception e )
100         {
101             log.info( "Ping error" );
102             throw new Exception( "Ping error", e );
103         }
104 
105         return result;
106     }
107 
108     public Boolean prepareBuildFinished( Map<String, Object> prepareBuildResult )
109         throws Exception
110     {
111         Boolean result;
112 
113         try
114         {
115             result = master.prepareBuildFinished( prepareBuildResult );
116             log.info( "Prepare build finished." );
117         }
118         catch ( Exception e )
119         {
120             log.error( "Failed to finish prepare build" );
121             throw new Exception( "Failed to finish prepare build", e );
122         }
123 
124         return result;
125     }
126 
127     public Boolean startProjectBuild( Integer projectId )
128         throws Exception
129     {
130         Boolean result;
131 
132         try
133         {
134             result = master.startProjectBuild( projectId );
135             log.info( "Return project currently building" );
136         }
137         catch ( Exception e )
138         {
139             log.error( "Failed to return project currently building", e );
140             throw new Exception( "Failed to return project currently building", e );
141         }
142 
143         return result;
144     }
145 
146     public Boolean startPrepareBuild( Map<String, Object> prepareBuildResult )
147         throws Exception
148     {
149         Boolean result;
150 
151         try
152         {
153             result = master.startPrepareBuild( prepareBuildResult );
154             log.info( "Started prepare build" );
155         }
156         catch ( Exception e )
157         {
158             log.error( "Failed to start prepare build", e );
159             throw new Exception( "Failed to start prepare build", e );
160         }
161 
162         return result;
163     }
164 
165     public Map<String, String> getEnvironments( Integer buildDefinitionId, String installationType )
166         throws Exception
167     {
168         Map<String, String> result;
169         try
170         {
171             result = master.getEnvironments( buildDefinitionId, installationType );
172             log.info( "Retrieved environments" );
173         }
174         catch ( Exception e )
175         {
176             log.error( "Failed to retrieve environments", e );
177             throw new Exception( "Failed to retrieve environments", e );
178         }
179 
180         return result;
181     }
182 
183     public Boolean updateProject( Map<String, Object> project )
184         throws Exception
185     {
186         Boolean result;
187 
188         try
189         {
190             result = master.updateProject( project );
191             log.info( "Updating project" );
192         }
193         catch ( Exception e )
194         {
195             log.error( "Failed to update project", e );
196             throw new Exception( "Failed to update project", e );
197         }
198 
199         return result;
200     }
201 
202     public Boolean shouldBuild( Map<String, Object> context )
203         throws Exception
204     {
205         Boolean result;
206 
207         try
208         {
209             result = master.shouldBuild( context );
210             log.info( "Checking if project should build" );
211         }
212         catch ( Exception e )
213         {
214             log.error( "Failed to determine if project should build", e );
215             throw new Exception( "Failed to determine if project should build", e );
216         }
217 
218         return result;
219     }
220 }