コード例 #1
0
def PrepareGCDDataDir(args):
    """Prepares the given directory using gcd create.

  Raises:
    UnableToPrepareDataDir: If the gcd create execution fails.

  Args:
    args: The arguments passed to the command.
  """
    data_dir = args.data_dir
    if os.path.isdir(data_dir) and os.listdir(data_dir):
        log.warning('Reusing existing data in [{0}].'.format(data_dir))
        return

    gcd_create_args = ['create']
    project = properties.VALUES.core.project.Get(required=True)
    gcd_create_args.append('--project_id={0}'.format(project))
    gcd_create_args.append(data_dir)
    exec_args = ArgsForGCDEmulator(gcd_create_args, args)

    log.status.Print('Executing: {0}'.format(' '.join(exec_args)))
    with util.Exec(exec_args) as process:
        util.PrefixOutput(process, DATASTORE)
        failed = process.poll()
        if failed:
            raise UnableToPrepareDataDir()
コード例 #2
0
 def Run(self, args):
     if not args.host_port:
         args.host_port = arg_parsers.HostPort.Parse(
             firestore_util.GetHostPort(), ipv6_enabled=socket.has_ipv6)
     args.host_port.host = args.host_port.host or 'localhost'
     firestore_util.ValidateStartArgs(args)
     with firestore_util.StartFirestoreEmulator(args) as proc:
         util.PrefixOutput(proc, 'firestore')
コード例 #3
0
  def Run(self, args):
    if not args.host_port:
      args.host_port = arg_parsers.HostPort.Parse(util.GetHostPort(
          pubsub_util.PUBSUB), ipv6_enabled=True)

    with pubsub_util.Start(args) as pubsub_process:
      util.WriteEnvYaml(pubsub_util.GetEnv(args), args.data_dir)
      util.PrefixOutput(pubsub_process, pubsub_util.PUBSUB)
コード例 #4
0
    def Run(self, args):
        if not args.host_port:
            args.host_port = arg_parsers.HostPort.Parse(
                datastore_util.GetHostPort(), ipv6_enabled=socket.has_ipv6)
        args.host_port.host = args.host_port.host or 'localhost'

        datastore_util.PrepareGCDDataDir(args)
        with datastore_util.StartGCDEmulator(args) as proc:
            datastore_util.WriteGCDEnvYaml(args)
            util.PrefixOutput(proc, 'datastore')
コード例 #5
0
  def Run(self, args):
    if 'all' in args.emulators:
      if len(args.emulators) > 1:
        raise util.EmulatorArgumentsError(
            "Cannot specify 'all' with other emulators")
      if args.route_to_public:
        raise util.EmulatorArgumentsError(
            'Cannot specify --route-to-public and --emulators=all')
    else:
      unknown_emulators = [x for x in args.emulators
                           if x not in config.EMULATORS]
      if unknown_emulators:
        raise util.EmulatorArgumentsError('Specified unrecognized emulators: '
                                          ','.join(unknown_emulators))

    proxy_port = args.proxy_port
    if args.proxy_port is None:
      proxy_port = util.DefaultPortIfAvailable()

    if not portpicker.is_port_free(proxy_port):
      raise util.EmulatorArgumentsError(
          'Specified proxy port [{}] is not available'.format(proxy_port))

    util.EnsureComponentIsInstalled('emulator-reverse-proxy',
                                    'gcloud emulators start')
    for flag, emulator in six.iteritems(config.EMULATORS):
      title = emulator.emulator_title
      component = emulator.emulator_component
      if (args.emulators is not None and
          (flag in args.emulators or 'all' in args.emulators)):
        java.RequireJavaInstalled(title)
        util.EnsureComponentIsInstalled(component, title)

    with contextlib.ExitStack() as stack:

      local_emulator_ports = {}
      for emulator in args.emulators:
        port = portpicker.pick_unused_port()
        local_emulator_ports[emulator] = port
        stack.enter_context(config.EMULATORS[emulator].Start(port))

      _, routes_config_file = tempfile.mkstemp()
      config.WriteRoutesConfig(config.EMULATORS, routes_config_file)
      log.status.Print(
          'routes configuration written to file: {}'.format(routes_config_file))

      proxy_config = config.ProxyConfiguration(local_emulator_ports,
                                               args.route_to_public,
                                               proxy_port)

      _, proxy_config_file = tempfile.mkstemp()
      proxy_config.WriteJsonToFile(proxy_config_file)
      log.status.Print(
          'proxy configuration written to file: {}'.format(proxy_config_file))

      # TODO(b/35872500) for some reason, in this case, this will block. Maybe
      #   we need to flush something, maybe not. Regardless, this is fine for
      #   now, but would be nice for it to not block like everything else
      with proxy_util.StartEmulatorProxy(
          args=[routes_config_file, proxy_config_file]) as proxy_process:
        # This will block the console
        util.PrefixOutput(proxy_process, 'emulator-reverse-proxy')
コード例 #6
0
def Start(args):
    spanner_args = _BuildStartArgs(args)
    log.status.Print('Executing: {0}'.format(' '.join(spanner_args)))
    with util.Exec(spanner_args) as spanner_process:
        util.WriteEnvYaml(GetEnv(args), GetDataDir())
        util.PrefixOutput(spanner_process, SPANNER_EMULATOR_COMPONENT_ID)
コード例 #7
0
def Start(args):
    bigtable_args = BuildStartArgs(util.BuildArgsList(args))
    log.status.Print('Executing: {0}'.format(' '.join(bigtable_args)))
    with util.Exec(bigtable_args) as bigtable_process:
        util.WriteEnvYaml(GetEnv(args), GetDataDir())
        util.PrefixOutput(bigtable_process, BIGTABLE)