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 org.apache.continuum.builder.distributed.DistributedBuildService;
23  import org.apache.continuum.distributed.commons.utils.ContinuumDistributedUtil;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  import java.util.Map;
28  
29  /**
30   * MasterBuildAgentTransportServer
31   */
32  public class MasterBuildAgentTransportServer
33      implements MasterBuildAgentTransportService
34  {
35      private static final Logger log = LoggerFactory.getLogger( MasterBuildAgentTransportServer.class );
36  
37      private final DistributedBuildService distributedBuildService;
38  
39      public MasterBuildAgentTransportServer( DistributedBuildService distributedBuildService )
40      {
41          this.distributedBuildService = distributedBuildService;
42      }
43  
44      public Boolean returnBuildResult( Map<String, Object> buildResult, String buildAgentUrl )
45          throws Exception
46      {
47          distributedBuildService.updateBuildResult( buildResult );
48          log.info( "Project {} build finished in build agent {}. Returned build result.",
49                    ContinuumDistributedUtil.getProjectNameAndId( buildResult ), buildAgentUrl );
50          return Boolean.TRUE;
51      }
52  
53      public Boolean ping()
54          throws Exception
55      {
56          log.debug( "Ping master ok" );
57  
58          return Boolean.TRUE;
59      }
60  
61      public Boolean prepareBuildFinished( Map<String, Object> prepareBuildResult, String buildAgentUrl )
62          throws Exception
63      {
64          distributedBuildService.prepareBuildFinished( prepareBuildResult );
65          log.info( "Prepare build finished for project {} in build agent {}",
66                    ContinuumDistributedUtil.getProjectNameAndId( prepareBuildResult ), buildAgentUrl );
67          return Boolean.TRUE;
68      }
69  
70      public Boolean startProjectBuild( Integer projectId, String buildAgentUrl )
71          throws Exception
72      {
73          distributedBuildService.startProjectBuild( projectId );
74          log.info( "Start building project (projectId={}) in build agent {}.", projectId, buildAgentUrl );
75          return Boolean.TRUE;
76      }
77  
78      public Boolean startPrepareBuild( Map<String, Object> prepareBuildResult, String buildAgentUrl )
79          throws Exception
80      {
81          distributedBuildService.startPrepareBuild( prepareBuildResult );
82          log.info( "Start preparing build of project {} in build agent {}", ContinuumDistributedUtil.getProjectNameAndId(
83              prepareBuildResult ), buildAgentUrl );
84          return Boolean.TRUE;
85      }
86  
87      public Map<String, String> getEnvironments( Integer buildDefinitionId, String installationType )
88          throws Exception
89      {
90          Map<String, String> envs = distributedBuildService.getEnvironments( buildDefinitionId, installationType );
91          log.debug( "Retrieving environments buildDefinitionId={}, installationType={}",
92                     new Object[]{buildDefinitionId, installationType} );
93          return envs;
94      }
95  
96      public Boolean updateProject( Map<String, Object> project )
97          throws Exception
98      {
99          distributedBuildService.updateProject( project );
100         log.debug( "Start updating project {}", ContinuumDistributedUtil.getProjectNameAndId( project ) );
101         return Boolean.TRUE;
102     }
103 
104     public Boolean shouldBuild( Map<String, Object> context, String buildAgentUrl )
105         throws Exception
106     {
107         log.debug( "Checking if project {} should build in build agent {}",
108                    ContinuumDistributedUtil.getProjectNameAndId( context ), buildAgentUrl );
109         return distributedBuildService.shouldBuild( context );
110     }
111 }