예제 #1
0
 def Filter(self, context, args):
     util.CheckIfJava7IsInstalled(datastore_util.DATASTORE_TITLE)
     if args.legacy:
         util.EnsureComponentIsInstalled('gcd-emulator',
                                         datastore_util.DATASTORE_TITLE)
     else:
         util.EnsureComponentIsInstalled('cloud-datastore-emulator',
                                         datastore_util.DATASTORE_TITLE)
     if not args.data_dir:
         args.data_dir = datastore_util.GetDataDir()
예제 #2
0
    def Filter(self, context, args):
        util.CheckIfJava7IsInstalled(pubsub_util.PUBSUB_TITLE)
        util.EnsureComponentIsInstalled('pubsub-emulator',
                                        pubsub_util.PUBSUB_TITLE)

        if not args.data_dir:
            args.data_dir = pubsub_util.GetDataDir()
예제 #3
0
    def Filter(self, context, args):
        current_os = platforms.OperatingSystem.Current()
        if current_os is platforms.OperatingSystem.WINDOWS:
            raise UnsupportedPlatformError(
                'The Bigtable emulator is currently not supported on Windows.')

        util.EnsureComponentIsInstalled(bigtable_util.BIGTABLE,
                                        bigtable_util.BIGTABLE_TITLE)
예제 #4
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 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')