コード例 #1
0
 def test_create_config_file(self):
   flexmock(file_io)\
     .should_receive('write')\
     .and_return()
   temp_file = god_app_configuration.create_config_file("mywatch",
                                                    "start_cmd",
                                                    "stop_cmd",
                                                    [1,2,3],
                                                    {'ENV1':"VALUE1",
                                                     'ENV2':"VALUE2"})
   self.assertNotEqual(None, temp_file)
コード例 #2
0
ファイル: distributed_tq.py プロジェクト: yoshimov/appscale
               "--app=" + \
                    TaskQueueConfig.get_celery_worker_module_name(app_id),
               #"--autoscale=" + self.MIN_MAX_CONCURRENCY,
               "--hostname=" + hostname + "." + app_id,
               "--workdir=" + TaskQueueConfig.CELERY_WORKER_DIR,
               "--logfile=" + log_file,
               "--time-limit=" + str(self.HARD_TIME_LIMIT),
               "--soft-time-limit=" + str(self.TASK_SOFT_TIME_LIMIT),
               "--pidfile=" + self.PID_FILE_LOC + 'celery___' + \
                             app_id + ".pid",
               "--autoreload"]
    start_command = str(' '.join(command))
    stop_command = self.get_worker_stop_command(app_id)
    watch = "celery-" + str(app_id)
    god_config = god_app_configuration.create_config_file(watch,
                                                      start_command, 
                                                      stop_command, 
                                                      [self.CELERY_PORT])
    if god_interface.start(god_config, watch):
      json_response = {'error': False}
    else:
      json_response = {'error': True, 
                       'reason': "Start of god watch for %s failed" % watch}
    return json.dumps(json_response)

  def fetch_queue_stats(self, app_id, http_data):
    """ 

    Args:
      app_id: The application ID.
      http_data: The payload containing the protocol buffer request.
    Returns:
コード例 #3
0
def start_app(config):
    """ Starts a Google App Engine application on this machine. It 
      will start it up and then proceed to fetch the main page.
  
  Args:
    config: a dictionary that contains 
       app_name: Name of the application to start
       app_port: Port to start on 
       language: What language the app is written in
       load_balancer_ip: Public ip of load balancer
       load_balancer_port: Port of load balancer
       xmpp_ip: IP of XMPP service 
       dblocations: List of database locations 
       env_vars: A dict of environment variables that should be passed to the
        app.
  Returns:
    PID of process on success, -1 otherwise
  """
    config = convert_config_from_json(config)
    if config == None:
        logging.error("Invalid configuration for application")
        return BAD_PID

    if not misc.is_app_name_valid(config['app_name']):
        logging.error("Invalid app name for application: " +\
                      config['app_name'])
        return BAD_PID
    logging.info("Starting %s application %s" %
                 (config['language'], config['app_name']))

    start_cmd = ""
    stop_cmd = ""
    env_vars = config['env_vars']
    watch = "app___" + config['app_name']

    if config['language'] == constants.PYTHON or \
          config['language'] == constants.PYTHON27 or \
          config['language'] == constants.GO:
        start_cmd = create_python_start_cmd(
            config['app_name'], config['load_balancer_ip'], config['app_port'],
            config['load_balancer_ip'], config['load_balancer_port'],
            config['xmpp_ip'], config['dblocations'], config['language'])
        logging.info(start_cmd)
        stop_cmd = create_python_stop_cmd(config['app_port'],
                                          config['language'])
        env_vars.update(
            create_python_app_env(config['load_balancer_ip'],
                                  config['load_balancer_port'],
                                  config['app_name']))
    elif config['language'] == constants.JAVA:
        copy_successful = copy_modified_jars(config['app_name'])
        if not copy_successful:
            return BAD_PID
        start_cmd = create_java_start_cmd(config['app_name'],
                                          config['app_port'],
                                          config['load_balancer_ip'],
                                          config['load_balancer_port'],
                                          config['dblocations'])
        stop_cmd = create_java_stop_cmd(config['app_port'])
        env_vars.update(create_java_app_env())
    else:
        logging.error("Unknown application language %s for appname %s"\
                      %(config['language'], config['app_name']))
        return BAD_PID

    logging.info("Start command: " + str(start_cmd))
    logging.info("Stop command: " + str(stop_cmd))
    logging.info("Environment variables: " + str(env_vars))

    config_file_loc = god_app_configuration.create_config_file(
        str(watch), str(start_cmd), str(stop_cmd), [config['app_port']],
        env_vars)

    if not god_interface.start(config_file_loc, watch):
        logging.error("Unable to start application server with god")
        return BAD_PID

    if not wait_on_app(int(config['app_port'])):
        logging.error("Application server did not come up in time, " + \
                       "removing god watch")
        god_interface.stop(watch)
        return BAD_PID

    pid = get_pid_from_port(config['app_port'])
    pid_file = constants.APP_PID_DIR + config['app_name'] + '-' +\
               str(config['app_port'])
    file_io.write(pid_file, str(pid))

    return pid
コード例 #4
0
def start_app(config):
  """ Starts a Google App Engine application on this machine. It 
      will start it up and then proceed to fetch the main page.
  
  Args:
    config: a dictionary that contains 
       app_name: Name of the application to start
       app_port: Port to start on 
       language: What language the app is written in
       load_balancer_ip: Public ip of load balancer
       load_balancer_port: Port of load balancer
       xmpp_ip: IP of XMPP service 
       dblocations: List of database locations 
       env_vars: A dict of environment variables that should be passed to the
        app.
  Returns:
    PID of process on success, -1 otherwise
  """
  config = convert_config_from_json(config)
  if config == None:
    logging.error("Invalid configuration for application")
    return BAD_PID 
  
  if not misc.is_app_name_valid(config['app_name']):
    logging.error("Invalid app name for application: " +\
                  config['app_name'])
    return BAD_PID
  logging.info("Starting %s application %s"%(config['language'], 
                                             config['app_name']))

  start_cmd = ""
  stop_cmd = ""
  env_vars = config['env_vars']
  watch = "app___" + config['app_name']
 
  if config['language'] == constants.PYTHON or \
        config['language'] == constants.PYTHON27 or \
        config['language'] == constants.GO:
    start_cmd = create_python_start_cmd(config['app_name'],
                            config['load_balancer_ip'],
                            config['app_port'],
                            config['load_balancer_ip'],
                            config['load_balancer_port'],
                            config['xmpp_ip'],
                            config['dblocations'],
                            config['language'])
    logging.info(start_cmd)
    stop_cmd = create_python_stop_cmd(config['app_port'], config['language'])
    env_vars.update(create_python_app_env(config['load_balancer_ip'],
                            config['load_balancer_port'], 
                            config['app_name']))
  elif config['language'] == constants.JAVA:
    copy_successful = copy_modified_jars(config['app_name'])
    if not copy_successful:
      return BAD_PID
    start_cmd = create_java_start_cmd(config['app_name'],
                            config['app_port'],
                            config['load_balancer_ip'],
                            config['load_balancer_port'],
                            config['dblocations'])
    stop_cmd = create_java_stop_cmd(config['app_port'])
    env_vars.update(create_java_app_env())
  else:
    logging.error("Unknown application language %s for appname %s"\
                  %(config['language'], config['app_name'])) 
    return BAD_PID

  logging.info("Start command: " + str(start_cmd))
  logging.info("Stop command: " + str(stop_cmd))
  logging.info("Environment variables: " +str(env_vars))

  config_file_loc = god_app_configuration.create_config_file(str(watch),
                                                     str(start_cmd), 
                                                     str(stop_cmd), 
                                                     [config['app_port']],
                                                     env_vars)

  if not god_interface.start(config_file_loc, watch):
    logging.error("Unable to start application server with god")
    return BAD_PID

  if not wait_on_app(int(config['app_port'])):
    logging.error("Application server did not come up in time, " + \
                   "removing god watch")
    god_interface.stop(watch)
    return BAD_PID

  pid = get_pid_from_port(config['app_port'])
  pid_file = constants.APP_PID_DIR + config['app_name'] + '-' +\
             str(config['app_port'])
  file_io.write(pid_file, str(pid))
      
  return pid
コード例 #5
0
ファイル: distributed_tq.py プロジェクト: AppScale/scale-safe
                   "worker",
                   "--app=" + \
                        TaskQueueConfig.get_celery_worker_module_name(app_id),
                   #"--autoscale=" + self.MIN_MAX_CONCURRENCY,
                   "--hostname=" + hostname + "." + app_id,
                   "--workdir=" + TaskQueueConfig.CELERY_WORKER_DIR,
                   "--logfile=" + log_file,
                   "--time-limit=" + str(self.HARD_TIME_LIMIT),
                   "--soft-time-limit=" + str(self.TASK_SOFT_TIME_LIMIT),
                   "--pidfile=" + self.PID_FILE_LOC + 'celery___' + \
                                 app_id + ".pid",
                   "--autoreload"]
        start_command = str(' '.join(command))
        stop_command = self.get_worker_stop_command(app_id)
        watch = "celery-" + str(app_id)
        god_config = god_app_configuration.create_config_file(
            watch, start_command, stop_command, [self.CELERY_PORT])
        if god_interface.start(god_config, watch):
            json_response = {'error': False}
        else:
            json_response = {
                'error': True,
                'reason': "Start of god watch for %s failed" % watch
            }
        return json.dumps(json_response)

    def fetch_queue_stats(self, app_id, http_data):
        """ 

    Args:
      app_id: The application ID.
      http_data: The payload containing the protocol buffer request.