def create(cfg, metrics_store, single_machine=True, sources=False, build=False, distribution=False, external=False, docker=False): challenge_root_path = paths.race_root(cfg) install_dir = "%s/install" % challenge_root_path log_dir = "%s/logs" % challenge_root_path io.ensure_dir(log_dir) if sources: try: src_dir = cfg.opts("source", "local.src.dir") except config.ConfigError: logger.exception("Cannot determine source directory") raise exceptions.SystemSetupError( "You cannot benchmark Elasticsearch from sources. Are you missing Gradle 2.13? Please install" " all prerequisites and reconfigure Rally with %s configure" % PROGRAM_NAME) remote_url = cfg.opts("source", "remote.repo.url") revision = cfg.opts("mechanic", "source.revision") gradle = cfg.opts("build", "gradle.bin") java_home = cfg.opts("runtime", "java8.home") s = lambda: supplier.from_sources(remote_url, src_dir, revision, gradle, java_home, log_dir, build) p = provisioner.local_provisioner(cfg, install_dir, single_machine) l = launcher.InProcessLauncher(cfg, metrics_store, challenge_root_path, log_dir) elif distribution: version = cfg.opts("mechanic", "distribution.version") repo_name = cfg.opts("mechanic", "distribution.repository") distributions_root = "%s/%s" % (cfg.opts( "node", "root.dir"), cfg.opts("source", "distribution.dir")) s = lambda: supplier.from_distribution(version=version, repo_name=repo_name, distributions_root= distributions_root) p = provisioner.local_provisioner(cfg, install_dir, single_machine) l = launcher.InProcessLauncher(cfg, metrics_store, challenge_root_path, log_dir) elif external: s = lambda: None p = provisioner.no_op_provisioner(cfg) l = launcher.ExternalLauncher(cfg, metrics_store) elif docker: s = lambda: None p = provisioner.docker_provisioner(cfg, install_dir) l = launcher.DockerLauncher(cfg, metrics_store) else: # It is a programmer error (and not a user error) if this function is called with wrong parameters raise RuntimeError( "One of sources, distribution, docker or external must be True") return Mechanic(s, p, l)
def create(cfg, metrics_store, sources=False, build=False, distribution=False, external=False, docker=False): if sources: s = lambda: supplier.from_sources(cfg, build) p = provisioner.local_provisioner(cfg) l = launcher.InProcessLauncher(cfg, metrics_store) elif distribution: s = lambda: supplier.from_distribution(cfg) p = provisioner.local_provisioner(cfg) l = launcher.InProcessLauncher(cfg, metrics_store) elif external: s = lambda: None p = provisioner.no_op_provisioner(cfg) l = launcher.ExternalLauncher(cfg, metrics_store) elif docker: s = lambda: None p = provisioner.no_op_provisioner(cfg) l = launcher.DockerLauncher(cfg, metrics_store) else: # It is a programmer error (and not a user error) if this function is called with wrong parameters raise RuntimeError( "One of sources, distribution, docker or external must be True") return Mechanic(cfg, s, p, l)
def test_setup_external_cluster_single_node(self): cfg = config.Config() cfg.add(config.Scope.application, "telemetry", "devices", []) m = launcher.ExternalLauncher(cfg) m.start(MockClient(), MockMetricsStore()) # automatically determined by launcher on attach self.assertEqual(cfg.opts("source", "distribution.version"), "5.0.0")
def create(cfg, metrics_store, all_node_ips, cluster_settings=None, sources=False, build=False, distribution=False, external=False, docker=False): races_root = paths.races_root(cfg) challenge_root_path = paths.race_root(cfg) node_ids = cfg.opts("provisioning", "node.ids", mandatory=False) car, plugins = load_team(cfg, external) if sources or distribution: s = supplier.create(cfg, sources, distribution, build, challenge_root_path, car, plugins) p = [] for node_id in node_ids: p.append( provisioner.local_provisioner(cfg, car, plugins, cluster_settings, all_node_ips, challenge_root_path, node_id)) l = launcher.InProcessLauncher(cfg, metrics_store, races_root) elif external: if cluster_settings: logging.getLogger(__name__).warning( "Cannot apply challenge-specific cluster settings [%s] for an externally provisioned cluster. Please ensure that the cluster " "settings are present or the benchmark may fail or behave unexpectedly." % cluster_settings) if len(plugins) > 0: raise exceptions.SystemSetupError( "You cannot specify any plugins for externally provisioned clusters. Please remove " "\"--elasticsearch-plugins\" and try again.") s = lambda: None p = [provisioner.no_op_provisioner()] l = launcher.ExternalLauncher(cfg, metrics_store) elif docker: if len(plugins) > 0: raise exceptions.SystemSetupError( "You cannot specify any plugins for Docker clusters. Please remove " "\"--elasticsearch-plugins\" and try again.") s = lambda: None p = [] for node_id in node_ids: p.append( provisioner.docker_provisioner(cfg, car, cluster_settings, challenge_root_path, node_id)) l = launcher.DockerLauncher(cfg, metrics_store) else: # It is a programmer error (and not a user error) if this function is called with wrong parameters raise RuntimeError( "One of sources, distribution, docker or external must be True") return Mechanic(s, p, l)
def test_setup_external_cluster_multiple_nodes(self): cfg = config.Config() cfg.add(config.Scope.application, "telemetry", "devices", []) cfg.add(config.Scope.application, "source", "distribution.version", "2.3.3") m = launcher.ExternalLauncher(cfg) m.start(MockClient(), MockMetricsStore()) # did not change user defined value self.assertEqual(cfg.opts("source", "distribution.version"), "2.3.3")
def test_setup_external_cluster_multiple_nodes(self): cfg = config.Config() cfg.add(config.Scope.application, "mechanic", "telemetry.devices", []) cfg.add(config.Scope.application, "client", "hosts", self.test_host) cfg.add(config.Scope.application, "client", "options", self.client_options) cfg.add(config.Scope.application, "mechanic", "distribution.version", "2.3.3") m = launcher.ExternalLauncher(cfg, MockMetricsStore(), client_factory_class=MockClientFactory) m.start() # did not change user defined value self.assertEqual(cfg.opts("mechanic", "distribution.version"), "2.3.3")
def test_setup_external_cluster_single_node(self): cfg = config.Config() cfg.add(config.Scope.application, "mechanic", "telemetry.devices", []) cfg.add(config.Scope.application, "client", "hosts", self.test_host) cfg.add(config.Scope.application, "client", "options",self.client_options) m = launcher.ExternalLauncher(cfg, MockMetricsStore(), client_factory_class=MockClientFactory) m.start() # automatically determined by launcher on attach self.assertEqual(cfg.opts("mechanic", "distribution.version"), "5.0.0")
def test_setup_external_cluster_cannot_determine_version(self): client_options = opts.ClientOptions("timeout:60,raise-error-on-info:true") cfg = config.Config() cfg.add(config.Scope.application, "mechanic", "telemetry.devices", []) cfg.add(config.Scope.application, "client", "hosts", self.test_host) cfg.add(config.Scope.application, "client", "options", client_options) m = launcher.ExternalLauncher(cfg, MockMetricsStore(), client_factory_class=MockClientFactory) m.start() # automatically determined by launcher on attach self.assertIsNone(cfg.opts("mechanic", "distribution.version"))
def test_setup_external_cluster_single_node(self): cfg = config.Config() cfg.add(config.Scope.application, "telemetry", "devices", []) cfg.add(config.Scope.application, "launcher", "external.target.hosts", ["localhost:9200"]) m = launcher.ExternalLauncher(cfg, cluster_factory_class=MockClusterFactory) cluster = m.start(None, MockTrackSetup(), MockMetricsStore()) self.assertEqual(cluster.hosts, [{ "host": "localhost", "port": "9200" }])
def test_setup_external_cluster_single_node(self): cfg = config.Config() cfg.add(config.Scope.application, "telemetry", "devices", []) cfg.add(config.Scope.application, "launcher", "external.target.hosts", ["10.0.0.10:9200", "10.0.0.11:9200"]) cfg.add(config.Scope.application, "launcher", "client.options", []) m = launcher.ExternalLauncher(cfg, MockMetricsStore(), client_factory_class=MockClientFactory) m.start() # automatically determined by launcher on attach self.assertEqual(cfg.opts("source", "distribution.version"), "5.0.0")
def test_raise_system_setup_exception_on_invalid_list(self): cfg = config.Config() cfg.add(config.Scope.application, "telemetry", "devices", []) cfg.add(config.Scope.application, "launcher", "external.target.hosts", ["search.host-a.internal", "search.host-b.internal:9200"]) m = launcher.ExternalLauncher(cfg, cluster_factory_class=MockClusterFactory) with self.assertRaises(exceptions.SystemSetupError) as ctx: m.start(None, MockTrackSetup(), MockMetricsStore()) self.assertTrue( "Could not initialize external cluster. Invalid format for [search.host-a.internal, " "search.host-b.internal:9200]. Expected a comma-separated list of host:port pairs, " "e.g. host1:9200,host2:9200." in ctx.exception)
def test_setup_external_cluster_multiple_nodes(self): cfg = config.Config() cfg.add(config.Scope.application, "telemetry", "devices", []) cfg.add(config.Scope.application, "launcher", "external.target.hosts", ["10.0.0.10:9200", "10.0.0.11:9200"]) cfg.add(config.Scope.application, "launcher", "client.options", []) cfg.add(config.Scope.application, "source", "distribution.version", "2.3.3") m = launcher.ExternalLauncher(cfg, MockMetricsStore(), client_factory_class=MockClientFactory) m.start() # did not change user defined value self.assertEqual(cfg.opts("source", "distribution.version"), "2.3.3")
def test_setup_external_cluster_single_node(self): cfg = config.Config() cfg.add(config.Scope.application, "telemetry", "devices", []) cfg.add(config.Scope.application, "launcher", "external.target.hosts", ["localhost:9200"]) cfg.add(config.Scope.application, "launcher", "client.options", {}) m = launcher.ExternalLauncher(cfg, cluster_factory_class=MockClusterFactory) cluster = m.start(MockMetricsStore()) self.assertEqual(cluster.hosts, [{ "host": "localhost", "port": "9200" }]) # automatically determined by launcher on attach self.assertEqual(cfg.opts("source", "distribution.version"), "5.0.0")
def test_setup_external_cluster_multiple_nodes(self): cfg = config.Config() cfg.add(config.Scope.application, "telemetry", "devices", []) cfg.add(config.Scope.application, "source", "distribution.version", "2.3.3") cfg.add(config.Scope.application, "launcher", "external.target.hosts", ["search.host-a.internal:9200", "search.host-b.internal:9200"]) cfg.add(config.Scope.application, "launcher", "client.options", {}) m = launcher.ExternalLauncher(cfg, cluster_factory_class=MockClusterFactory) cluster = m.start(MockMetricsStore()) self.assertEqual(cluster.hosts, [{ "host": "search.host-a.internal", "port": "9200" }, { "host": "search.host-b.internal", "port": "9200" }]) # did not change user defined value self.assertEqual(cfg.opts("source", "distribution.version"), "2.3.3")
def create(cfg, metrics_store, all_node_ips, cluster_settings=None, sources=False, build=False, distribution=False, external=False, docker=False): races_root = paths.races_root(cfg) challenge_root_path = paths.race_root(cfg) node_ids = cfg.opts("provisioning", "node.ids", mandatory=False) repo = team.team_repo(cfg) # externally provisioned clusters do not support cars / plugins if external: car = None plugins = [] else: car = team.load_car(repo, cfg.opts("mechanic", "car.names")) plugins = team.load_plugins(repo, cfg.opts("mechanic", "car.plugins")) if sources: try: src_dir = cfg.opts("node", "src.root.dir") except config.ConfigError: logger.exception("Cannot determine source directory") raise exceptions.SystemSetupError( "You cannot benchmark Elasticsearch from sources. Did you install Gradle? Please install" " all prerequisites and reconfigure Rally with %s configure" % PROGRAM_NAME) remote_url = cfg.opts("source", "remote.repo.url") revision = cfg.opts("mechanic", "source.revision") gradle = cfg.opts("build", "gradle.bin") java_home = cfg.opts("runtime", "java.home") src_config = cfg.all_opts("source") s = lambda: supplier.from_sources( remote_url, src_dir, revision, gradle, java_home, challenge_root_path, plugins, src_config, build) p = [] for node_id in node_ids: p.append( provisioner.local_provisioner(cfg, car, plugins, cluster_settings, all_node_ips, challenge_root_path, node_id)) l = launcher.InProcessLauncher(cfg, metrics_store, races_root) elif distribution: version = cfg.opts("mechanic", "distribution.version") repo_name = cfg.opts("mechanic", "distribution.repository") distributions_root = "%s/%s" % (cfg.opts( "node", "root.dir"), cfg.opts("source", "distribution.dir")) distribution_cfg = cfg.all_opts("distributions") s = lambda: supplier.from_distribution( version=version, repo_name=repo_name, distribution_config=distribution_cfg, distributions_root=distributions_root, plugins=plugins) p = [] for node_id in node_ids: p.append( provisioner.local_provisioner(cfg, car, plugins, cluster_settings, all_node_ips, challenge_root_path, node_id)) l = launcher.InProcessLauncher(cfg, metrics_store, races_root) elif external: if cluster_settings: logger.warning( "Cannot apply challenge-specific cluster settings [%s] for an externally provisioned cluster. Please ensure " "that the cluster settings are present or the benchmark may fail or behave unexpectedly." % cluster_settings) if len(plugins) > 0: raise exceptions.SystemSetupError( "You cannot specify any plugins for externally provisioned clusters. Please remove " "\"--elasticsearch-plugins\" and try again.") s = lambda: None p = [provisioner.no_op_provisioner()] l = launcher.ExternalLauncher(cfg, metrics_store) elif docker: if len(plugins) > 0: raise exceptions.SystemSetupError( "You cannot specify any plugins for Docker clusters. Please remove " "\"--elasticsearch-plugins\" and try again.") s = lambda: None p = [] for node_id in node_ids: p.append( provisioner.docker_provisioner(cfg, car, cluster_settings, challenge_root_path, node_id)) l = launcher.DockerLauncher(cfg, metrics_store) else: # It is a programmer error (and not a user error) if this function is called with wrong parameters raise RuntimeError( "One of sources, distribution, docker or external must be True") return Mechanic(s, p, l)
def start_engine_external(self, track, setup): external_launcher = launcher.ExternalLauncher(self._config) return external_launcher.start(track, setup, self._metrics_store)
def start_engine_external(self, client): external_launcher = launcher.ExternalLauncher(self._config) return external_launcher.start(client, self._metrics_store)