Subversion Repositories DevTools

Rev

Rev 4123 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4123 Rev 4285
Line 1... Line 1...
1
package com.erggroup.buildtool.daemon;
1
package com.erggroup.buildtool.daemon;
2
 
2
 
3
import com.erggroup.buildtool.ripple.MutableChar;
-
 
4
import com.erggroup.buildtool.ripple.MutableInt;
-
 
5
import com.erggroup.buildtool.ripple.Package;
3
import com.erggroup.buildtool.ripple.Package;
-
 
4
import com.erggroup.buildtool.ripple.ReleaseConfig;
6
import com.erggroup.buildtool.ripple.ReleaseManager;
5
import com.erggroup.buildtool.ripple.ReleaseManager;
7
import com.erggroup.buildtool.daemon.NagiosThread;
6
import com.erggroup.buildtool.daemon.NagiosThread;
8
 
7
 
9
import java.io.File;
8
import java.io.File;
10
import java.io.IOException;
9
import java.io.IOException;
11
 
-
 
12
import java.net.InetAddress;
10
import java.net.InetAddress;
13
import java.net.UnknownHostException;
11
import java.net.UnknownHostException;
14
import java.net.ServerSocket;
12
import java.net.ServerSocket;
15
 
-
 
16
import java.sql.SQLException;
13
import java.sql.SQLException;
17
 
-
 
18
import java.util.Iterator;
14
import java.util.Iterator;
19
import java.util.Vector;
15
import java.util.Vector;
20
 
16
 
21
import org.apache.log4j.Logger;
17
import org.apache.log4j.Logger;
22
import org.apache.log4j.xml.DOMConfigurator;
18
import org.apache.log4j.xml.DOMConfigurator;
Line 181... Line 177...
181
   */
177
   */
182
  public BuildDaemon(String connectionString, String username, 
178
  public BuildDaemon(String connectionString, String username, 
183
                     String password)
179
                     String password)
184
  {
180
  {
185
    mLogger.warn("BuildDaemon");
181
    mLogger.warn("BuildDaemon");
186
    ReleaseManager releaseManager = 
-
 
187
      new ReleaseManager(connectionString, username + "[release_manager]", password);
182
    ReleaseManager releaseManager = new ReleaseManager(connectionString, username + "[release_manager]", password);
188
    boolean run = true;
183
    boolean run = true;
189
    MutableInt rtag_id = new MutableInt();
-
 
190
    MutableInt rcon_id = new MutableInt();
-
 
191
    MutableChar daemon_mode = new MutableChar();
-
 
192
    String hostname = new String("");
184
    String utf = null;
193
    
185
    
194
    try
186
    try
195
    {
187
    {
196
      InetAddress local = InetAddress.getLocalHost();
188
      InetAddress local = InetAddress.getLocalHost();
197
      hostname = local.getHostName();
189
      mHostname = local.getHostName();
198
      mHostname = hostname;
-
 
199
      mLogger.info("BuildDaemon set hostname " + mHostname);
190
      mLogger.info("BuildDaemon set hostname " + mHostname);
200
 
191
 
-
 
192
      // Flag UTF in progress
-
 
193
      if ( connectionString.compareTo("unit test spawn thread") == 0 )
-
 
194
      {
-
 
195
        utf = connectionString;
-
 
196
      }
-
 
197
      
201
      if ( Package.mGenericMachtype == null )
198
      if ( Package.mGenericMachtype == null )
202
      {
199
      {
203
        mLogger.fatal("run GBE_MACHTYPE not set");
200
        mLogger.fatal("run GBE_MACHTYPE not set");
204
        throw new Exception("run GBE_MACHTYPE not set");
201
        throw new Exception("run GBE_MACHTYPE not set");
205
      }
202
      }
Line 208... Line 205...
208
      {
205
      {
209
        mLogger.fatal("run GBE_DPKG not set");
206
        mLogger.fatal("run GBE_DPKG not set");
210
        throw new Exception("run GBE_DPKG not set");
207
        throw new Exception("run GBE_DPKG not set");
211
      }
208
      }
212
 
209
 
213
      //Set the default handler invoked when a thread abruptly terminates due to an
210
      //	Set the default handler invoked when a thread abruptly terminates due to an
214
      //uncaught exception, and no other handler has been defined for that thread.
211
      //	uncaught exception, and no other handler has been defined for that thread.
-
 
212
      //
215
      Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
213
      Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
216
 
214
 
217
      //
215
      //
218
      //  Start the Nagios Interface Thread
216
      //  Start the Nagios Interface Thread
219
      //
217
      //
Line 226... Line 224...
226
        } catch ( IOException e ) {
224
        } catch ( IOException e ) {
227
              mLogger.fatal("Failed to start Nagios Service. Port already in use");
225
              mLogger.fatal("Failed to start Nagios Service. Port already in use");
228
              throw new Exception("Nagios port in use");
226
              throw new Exception("Nagios port in use");
229
        }
227
        }
230
      }
228
      }
231
 
229
 
232
      boolean firstTime = true;
230
      //	Discover new build daemons to be started on the current host
233
      
231
      //
234
      while (run)
232
      while (run)
235
      {
233
      {
236
        try
234
        try
237
        {
235
        {
238
          if ( !firstTime )
236
        	// Create a list of all machines that are configured to run on this machine
239
          {
237
        	//
240
            mLogger.warn("BuildDaemon sleep for 10 mins");
-
 
241
            Thread.sleep(600000);
-
 
242
            mLogger.info("BuildDaemon sleep returned");
238
        	releaseManager.queryReleaseConfig(mHostname);
243
          }
-
 
244
          else
-
 
245
          {
239
          
246
            firstTime = false;    
-
 
247
          }
240
          //
248
 
-
 
249
          releaseManager.queryReleaseConfig(hostname);
-
 
250
  
-
 
251
          rtag_id.value = 0;
-
 
252
          rcon_id.value = 0;
-
 
253
          daemon_mode.value = 'X';
-
 
254
  
-
 
255
          boolean moreReleasesConfigured = 
241
          //  Iterate over all the configured machines
256
            releaseManager.getFirstReleaseConfig(rtag_id, rcon_id, 
-
 
257
                                                 daemon_mode);
242
          //	Start up new build threads for new machines
258
  
-
 
259
          do
243
          //
-
 
244
          for (Iterator<ReleaseConfig> it = releaseManager.mReleaseConfigCollection.iterator(); it.hasNext(); )
260
          {
245
          {
261
            if (moreReleasesConfigured)
246
            ReleaseConfig rc = it.next();
-
 
247
            
-
 
248
            if (!isActive(rc.get_rcon_id()))
262
            {
249
            {
-
 
250
              mLogger.warn("BuildDaemon activating " + rc.get_rtag_id() + " " + rc.get_rcon_id() + " " + rc.get_daemon_mode());
-
 
251
              
-
 
252
         
-
 
253
              // spawn and run the BuildThread
263
              if (!isActive(rcon_id.value))
254
              if (rc.get_daemon_mode() == 'M')
-
 
255
              {
-
 
256
                MasterThread thread = new MasterThread(rc.get_rtag_id(), rc.get_rcon_id(), utf);
-
 
257
                ThreadIdentifier threadIdentifier =  new ThreadIdentifier(rc.get_rcon_id(), thread);
-
 
258
                mThreadCollection.add(threadIdentifier);
-
 
259
                // begin thread execution and invoke thread.run();
-
 
260
                thread.start();
-
 
261
              }
-
 
262
              else if (rc.get_daemon_mode() == 'S')
264
              {
263
              {
265
                mLogger.warn("BuildDaemon activating " + rtag_id.value + " " + rcon_id.value + " " + daemon_mode.value);
-
 
266
                
-
 
267
                String utf = null;
-
 
268
                
-
 
269
                if ( connectionString.compareTo("unit test spawn thread") == 0 )
-
 
270
                {
-
 
271
                  utf = connectionString;
-
 
272
                }
-
 
273
                
-
 
274
                // spawn and run the BuildThread
-
 
275
                if (daemon_mode.value == 'M')
-
 
276
                {
-
 
277
                  MasterThread thread = new MasterThread(rtag_id.value, rcon_id.value, utf);
-
 
278
                  ThreadIdentifier threadIdentifier = 
-
 
279
                    new ThreadIdentifier(rcon_id.value, thread);
-
 
280
                  mThreadCollection.add(threadIdentifier);
-
 
281
                  // begin thread execution and invoke thread.run();
-
 
282
                  thread.start();
-
 
283
                }
-
 
284
                else if (daemon_mode.value == 'S')
-
 
285
                {
-
 
286
                  SlaveThread thread = new SlaveThread(rtag_id.value, rcon_id.value, utf);
264
                SlaveThread thread = new SlaveThread(rc.get_rtag_id(), rc.get_rcon_id(), utf);
287
                  ThreadIdentifier threadIdentifier = 
-
 
288
                    new ThreadIdentifier(rcon_id.value, thread);
265
                ThreadIdentifier threadIdentifier = new ThreadIdentifier(rc.get_rcon_id(), thread);
289
                  mThreadCollection.add(threadIdentifier);
266
                mThreadCollection.add(threadIdentifier);
290
                  // begin thread execution and invoke thread.run();
267
                // begin thread execution and invoke thread.run();
291
                  thread.start();
268
                thread.start();
292
                }
-
 
293
              }
269
              }
294
  
-
 
295
              moreReleasesConfigured = 
-
 
296
                  releaseManager.getNextReleaseConfig(rtag_id, rcon_id, 
-
 
297
                                                      daemon_mode);
-
 
298
            }
270
            }
-
 
271
            
299
          }
272
          }
-
 
273
          
300
          while (moreReleasesConfigured);
274
          //	In UTF mode we only execute the loop once
301
  
-
 
302
          if ( connectionString.compareTo("unit test spawn thread") == 0)
275
          if ( utf != null )
303
          {
276
          {
304
            run = false;
277
            run = false;
-
 
278
            continue;
305
          }
279
          }
-
 
280
         
-
 
281
          // Wait 10 minutes before we try to discover new machines
306
          
282
          
-
 
283
          mLogger.warn("BuildDaemon sleep for 10 mins");
-
 
284
          Thread.sleep(600000);
-
 
285
          mLogger.info("BuildDaemon sleep returned");
-
 
286
                   
307
        }
287
        }
308
        catch (SQLException e)
288
        catch (SQLException e)
309
        {
289
        {
310
          mLogger.warn("BuildDaemon caught SQLException");
290
          mLogger.warn("BuildDaemon caught SQLException");
311
        }
291
        }