Exemple #1
0
def main():
    """Launches the Schema Conversion Tool."""
    bootstrapping.CommandStart(_COMPONENT_ID, component_id=_COMPONENT_ID)
    bootstrapping.CheckUpdates(_COMPONENT_ID)
    update_manager.UpdateManager.EnsureInstalledAndRestart([_COMPONENT_ID],
                                                           command=__file__)
    try:
        java_bin = java.RequireJavaInstalled('Schema Conversion Tool',
                                             min_version=9)
        java_9plus = True
    except java.JavaVersionError:
        java_bin = java.RequireJavaInstalled('Schema Conversion Tool',
                                             min_version=8)
        java_9plus = False

    os.environ.setdefault('SCT_UPDATE_CHECK', 'false')
    jar_name = 'schema_conversion_gui.jar'
    main_jar = os.path.join(_JAR_DIR, jar_name)

    # Accept a platform-appropriate default added as 1st arg in sct.sh/sct.cmd.
    working_dir_default = bootstrapping.GetDecodedArgv()[1]

    flags = [
        '-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager',
        '-Dspring.profiles.active=production',
        '-Dgcloud.component.dir={}'.format(_COMPONENT_DIR),
        '-Dsct.working.dir.default={}'.format(working_dir_default),
        '-jar',
        main_jar,
    ]

    if java_9plus:
        # Open modules to reflection explicitly to avoid Java 9+ warnings.
        flags = [
            '--add-opens',
            'java.base/java.io=ALL-UNNAMED',
            '--add-opens',
            'java.base/java.lang=ALL-UNNAMED',
            '--add-opens',
            'java.base/java.net=ALL-UNNAMED',
            '--add-opens',
            'java.rmi/sun.rmi.transport=ALL-UNNAMED',
        ] + flags

    bootstrapping.ExecuteJarTool(
        java_bin,
        _JAR_DIR,
        jar_name,
        None,  # No main classname for Springboot JAR. Use -jar flag instead.
        flags,
        '--server.address=127.0.0.1')
Exemple #2
0
    def testJavaExecutableNotJava7(self):
        find_exec_mock = self.StartObjectPatch(files, 'FindExecutableOnPath')
        find_exec_mock.return_value = '/path/to/java'

        check_out_mock = self.StartObjectPatch(subprocess, 'check_output')
        check_out_mock.return_value = 'version "not1.7'

        with self.assertRaises(java.JavaError):
            java.RequireJavaInstalled('foo')

        check_out_mock.return_value = 'version "1.6'

        with self.assertRaises(java.JavaError):
            java.RequireJavaInstalled('foo')
Exemple #3
0
    def testJava7InstalledAndOnPath(self):
        find_exec_mock = self.StartObjectPatch(files, 'FindExecutableOnPath')
        find_exec_mock.return_value = '/path/to/java'

        check_out_mock = self.StartObjectPatch(subprocess, 'check_output')
        check_out_mock.return_value = 'version "1.7.'

        try:
            java.RequireJavaInstalled('foo')
        except java.JavaError:
            self.fail('JavaError should not be thrown here')

        check_out_mock.return_value = 'version "1.8.'

        self.assertEqual(java.RequireJavaInstalled('foo'), '/path/to/java')
def main():
    """Launches the Java dev_appserver 1."""
    update_manager.UpdateManager.EnsureInstalledAndRestart(['app-engine-java'],
                                                           command=__file__)
    java_bin = java.RequireJavaInstalled('Java local development server')
    bootstrapping.ExecuteJarTool(java_bin, _JAR_DIR, _JAR_NAME, _CLASSNAME,
                                 _FLAGS, *_ARGS)
Exemple #5
0
    def Filter(self, context, args):
        java.RequireJavaInstalled(pubsub_util.PUBSUB_TITLE)
        util.EnsureComponentIsInstalled('pubsub-emulator',
                                        pubsub_util.PUBSUB_TITLE)

        if not args.data_dir:
            args.data_dir = pubsub_util.GetDataDir()
 def Filter(self, context, args):
     java.RequireJavaInstalled(datastore_util.DATASTORE_TITLE,
                               min_version=8)
     util.EnsureComponentIsInstalled('cloud-datastore-emulator',
                                     datastore_util.DATASTORE_TITLE)
     if not args.data_dir:
         args.data_dir = datastore_util.GetDataDir()
Exemple #7
0
    def testJava9InstalledAndOnPath_JustMajorVersion(self):
        find_exec_mock = self.StartObjectPatch(files, 'FindExecutableOnPath')
        find_exec_mock.return_value = '/path/to/java'

        check_out_mock = self.StartObjectPatch(subprocess, 'check_output')
        check_out_mock.return_value = 'version "9"'

        self.assertEqual(java.RequireJavaInstalled('foo', min_version=7),
                         '/path/to/java')
Exemple #8
0
 def Filter(self, context, args):
     java.RequireJavaInstalled(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()
Exemple #9
0
    def testJavaExecutableNotExecutable(self):
        find_exec_mock = self.StartObjectPatch(files, 'FindExecutableOnPath')
        find_exec_mock.return_value = '/path/to/java'

        check_out_mock = self.StartObjectPatch(subprocess, 'check_output')
        called_process_err = subprocess.CalledProcessError(1, 'cmd', 'output')
        check_out_mock.side_effect = called_process_err

        with self.assertRaises(java.JavaError):
            java.RequireJavaInstalled('foo')
def main():
  """Launches the Dataflow SQL shell."""
  bootstrapping.CommandStart('dataflow-sql', component_id='dataflow-sql')
  bootstrapping.CheckUpdates('dataflow-sql')
  update_manager.UpdateManager.EnsureInstalledAndRestart(
      ['dataflow-sql'], command=__file__)
  java_bin = java.RequireJavaInstalled('Dataflow SQL')
  bootstrapping.ExecuteJavaClass(
      java_bin,
      jar_dir=_JAR_DIR,
      main_jar=_MAIN_JAR,
      main_class=_CLASSNAME,
      main_args=['-nn', 'DFSQL', '-u', 'jdbc:beam:userAgent=DataflowSQL'])
  def LogJavaVersionWarning(self):
    """Log a warning message notifying users about Java version change.

    Log the warning when the installed JRE has an earlier version than Java 11.
    """
    try:
      java.RequireJavaInstalled(firestore_util.FIRESTORE_TITLE, min_version=11)
    except java.JavaVersionError:
      log.warning(
          'Cloud Firestore Emulator support for Java JRE version 8 will be '
          'dropped after gcloud command-line tool release 392.0.0. Please '
          'upgrade to Java JRE version 11 or higher to continue using the '
          'latest Cloud Firestore Emulator.')
    except java.JavaError:
      # A JRE could not be found. Not logging the warning since the user will
      # not be able to start an emulator anyways.
      pass
Exemple #12
0
def _JavaStagingMapper(command_path, descriptor, app_dir, staging_dir):
    """Map a java staging request to the right args.

  Args:
    command_path: str, path to the jar tool file.
    descriptor: str, path to the `appengine-web.xml`
    app_dir: str, path to the unstaged app directory
    staging_dir: str, path to the empty staging dir

  Raises:
    java.JavaError, if Java is not installed.

  Returns:
    [str], args for executable invocation.
  """
    del descriptor  # Unused, app_dir is sufficient
    java_bin = java.RequireJavaInstalled('local staging for java')
    args = ([java_bin, '-classpath', command_path, _JAVA_APPCFG_ENTRY_POINT] +
            _JAVA_APPCFG_STAGE_FLAGS + ['stage', app_dir, staging_dir])
    return args
Exemple #13
0
def main():
  """Launches dev_appserver.py."""
  argv = bootstrapping.GetDecodedArgv()
  runtimes = wrapper_util.GetRuntimes(argv[1:])
  options = wrapper_util.ParseDevAppserverFlags(sys.argv[1:])
  if options.support_datastore_emulator:
    java.RequireJavaInstalled(datastore_util.DATASTORE_TITLE, min_version=8)
  components = wrapper_util.GetComponents(runtimes)
  components.append('cloud-datastore-emulator')
  if (platforms.OperatingSystem.Current() == platforms.OperatingSystem.LINUX
      and 'app-engine-php' in components):
    components.remove('app-engine-php')
  update_manager.UpdateManager.EnsureInstalledAndRestart(
      components,
      command=__file__)

  args = [
      '--skip_sdk_update_check=True'
  ]

  google_analytics_client_id = metrics.GetCIDIfMetricsEnabled()
  google_analytics_user_agent = metrics.GetUserAgentIfMetricsEnabled()
  if google_analytics_client_id:
    args.extend([
        '--google_analytics_client_id={}'.format(google_analytics_client_id),
        '--google_analytics_user_agent={}'.format(google_analytics_user_agent)
    ])

  # Pass the path to cloud datastore emulator to dev_appserver.
  # realpath is needed in the case where __file__ is a path containing symlinks.
  sdk_root = os.path.dirname(
      os.path.dirname(os.path.abspath(os.path.realpath(__file__))))
  emulator_dir = os.path.join(sdk_root, 'platform', 'cloud-datastore-emulator')
  emulator_script = (
      'cloud_datastore_emulator.cmd' if platforms.OperatingSystem.IsWindows()
      else 'cloud_datastore_emulator')
  args.append('--datastore_emulator_cmd={}'.format(
      os.path.join(emulator_dir, emulator_script)))

  bootstrapping.ExecutePythonTool(
      os.path.join('platform', 'google_appengine'), 'dev_appserver.py', *args)
 def Filter(self, context, args):
     java.RequireJavaInstalled(firestore_util.FIRESTORE_TITLE,
                               min_version=8)
     util.EnsureComponentIsInstalled('cloud-firestore-emulator',
                                     firestore_util.FIRESTORE_TITLE)
Exemple #15
0
    def testJava8Error(self):
        check_out_mock = self.StartObjectPatch(subprocess, 'check_output')
        check_out_mock.return_value = 'version "1.7.'

        with self.assertRaises(java.JavaError):
            java.RequireJavaInstalled('foo', min_version=8)
Exemple #16
0
 def SetUp(self):
   # Verify that Java is installed or skip these tests
   with self.SkipTestIfRaises(java.JavaError):
     java.RequireJavaInstalled('test')
Exemple #17
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')
Exemple #18
0
    def testJavaExecutableNotFound(self):
        find_exec_mock = self.StartObjectPatch(files, 'FindExecutableOnPath')
        find_exec_mock.return_value = None

        with self.assertRaises(java.JavaError):
            java.RequireJavaInstalled('foo')