def PrepareGCDDataDir(data_dir): """Prepares the given directory using gcd create. Raises: UnableToPrepareDataDir: If the gcd create execution fails. Args: data_dir: str, Path of data directy to be prepared. """ if os.path.isdir(data_dir) and os.listdir(data_dir): log.warn('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) log.status.Print('Executing: {0}'.format(' '.join(exec_args))) process = util.Exec(exec_args) util.PrefixOutput(process, DATASTORE) failed = process.poll() if failed: raise UnableToPrepareDataDir()
def Start(args): pubsub_args = BuildStartArgs(ToArgsList(args), platforms.OperatingSystem.Current()) log.status.Print('Executing: {0}'.format(' '.join(pubsub_args))) pubsub_process = util.Exec(pubsub_args) util.WriteEnvYaml(GetEnv(args), args.data_dir) util.PrefixOutput(pubsub_process, PUBSUB)
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.warn('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()
def Run(self, args): if not args.host_port: args.host_port = arg_parsers.HostPort.Parse( util.GetHostPort(pubsub_util.PUBSUB)) with pubsub_util.Start(args) as pubsub_process: util.WriteEnvYaml(pubsub_util.GetEnv(args), args.data_dir) util.PrefixOutput(pubsub_process, pubsub_util.PUBSUB)
def Run(self, args): if not args.host_port: args.host_port = arg_parsers.HostPort.Parse(datastore_util.GetHostPort()) args.host_port.host = args.host_port.host or 'localhost' datastore_util.PrepareGCDDataDir(args) datastore_process = datastore_util.StartGCDEmulator(args) datastore_util.WriteGCDEnvYaml(args) util.PrefixOutput(datastore_process, 'datastore')
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)
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 config.EMULATORS.iteritems(): title = emulator.emulator_title component = emulator.emulator_component if (args.emulators is not None and (flag in args.emulators or 'all' in args.emulators)): util.CheckIfJava7IsInstalled(title) util.EnsureComponentIsInstalled(component, title) local_emulator_ports = {} contexts = [] for emulator in args.emulators: port = portpicker.pick_unused_port() local_emulator_ports[emulator] = port contexts.append(config.EMULATORS[emulator].Start(port)) # Once we're in python3, can use contextlib.ExitStack() with contextlib.nested(*contexts): _, 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')