예제 #1
0
 def test_target_no_host(self):
     node_count = 4
     hosts = list(range(node_count))
     policy = DSELoadBalancingPolicy(RoundRobinPolicy())
     policy.populate(Mock(metadata=ClusterMetaMock()), hosts)
     query_plan = list(policy.make_query_plan(None, Mock(target_host='127.0.0.1')))
     self.assertEqual(sorted(query_plan), hosts)
예제 #2
0
 def test_target_no_host(self):
     node_count = 4
     hosts = list(range(node_count))
     policy = DSELoadBalancingPolicy(RoundRobinPolicy())
     policy.populate(Mock(metadata=ClusterMetaMock()), hosts)
     query_plan = list(policy.make_query_plan(None, Mock(target_host='127.0.0.1')))
     self.assertEqual(sorted(query_plan), hosts)
예제 #3
0
    def test_target_host_nominal(self):
        node_count = 4
        hosts = [Host(i, Mock()) for i in range(node_count)]
        target_host = hosts[1]
        target_host.is_up = True

        policy = DSELoadBalancingPolicy(RoundRobinPolicy())
        policy.populate(Mock(metadata=ClusterMetaMock({'127.0.0.1': target_host})), hosts)
        for _ in range(10):
            query_plan = list(policy.make_query_plan(None, Mock(target_host='127.0.0.1')))
            self.assertEqual(sorted(query_plan), hosts)
            self.assertEqual(query_plan[0], target_host)
예제 #4
0
    def test_target_host_nominal(self):
        node_count = 4
        hosts = [Host(i, Mock()) for i in range(node_count)]
        target_host = hosts[1]
        target_host.is_up = True

        policy = DSELoadBalancingPolicy(RoundRobinPolicy())
        policy.populate(Mock(metadata=ClusterMetaMock({'127.0.0.1': target_host})), hosts)
        for _ in range(10):
            query_plan = list(policy.make_query_plan(None, Mock(target_host='127.0.0.1')))
            self.assertEqual(sorted(query_plan), hosts)
            self.assertEqual(query_plan[0], target_host)
예제 #5
0
    def __init__(self,
                 load_balancing_policy=None,
                 retry_policy=None,
                 consistency_level=ConsistencyLevel.LOCAL_ONE,
                 serial_consistency_level=None,
                 request_timeout=3600. * 24. * 7.,
                 row_factory=graph_object_row_factory,
                 graph_options=None):
        """
        Execution profile with timeout and load balancing appropriate for graph analytics queries.

        See also :class:`~.GraphExecutionPolicy`.

        In addition to default parameters shown in the signature, this profile also defaults ``retry_policy`` to
        :class:`dse.policies.NeverRetryPolicy`, and ``load_balancing_policy`` to one that targets the current Spark
        master.
        """
        load_balancing_policy = load_balancing_policy or DSELoadBalancingPolicy(
            default_lbp_factory())
        graph_options = graph_options or GraphOptions(
            graph_source=b'a', graph_language=b'gremlin-groovy')
        super(GraphAnalyticsExecutionProfile,
              self).__init__(load_balancing_policy, retry_policy,
                             consistency_level, serial_consistency_level,
                             request_timeout, row_factory, graph_options)
예제 #6
0
    def test_target_host_down(self):
        node_count = 4
        hosts = [Host(i, Mock()) for i in range(node_count)]
        target_host = hosts[1]

        policy = DSELoadBalancingPolicy(RoundRobinPolicy())
        policy.populate(Mock(metadata=ClusterMetaMock({'127.0.0.1': target_host})), hosts)
        query_plan = list(policy.make_query_plan(None, Mock(target_host='127.0.0.1')))
        self.assertEqual(sorted(query_plan), hosts)

        target_host.is_up = False
        policy.on_down(target_host)
        query_plan = list(policy.make_query_plan(None, Mock(target_host='127.0.0.1')))
        self.assertNotIn(target_host, query_plan)
예제 #7
0
    def test_target_host_down(self):
        node_count = 4
        hosts = [Host(i, Mock()) for i in range(node_count)]
        target_host = hosts[1]

        policy = DSELoadBalancingPolicy(RoundRobinPolicy())
        policy.populate(Mock(metadata=ClusterMetaMock({'127.0.0.1': target_host})), hosts)
        query_plan = list(policy.make_query_plan(None, Mock(target_host='127.0.0.1')))
        self.assertEqual(sorted(query_plan), hosts)

        target_host.is_up = False
        policy.on_down(target_host)
        query_plan = list(policy.make_query_plan(None, Mock(target_host='127.0.0.1')))
        self.assertNotIn(target_host, query_plan)
예제 #8
0
    def __init__(self, *args, **kwargs):
        self._validate_core_version()

        super(Cluster, self).__init__(*args, **kwargs)

        if self._config_mode == _ConfigMode.LEGACY:
            raise ValueError(
                "DSE Cluster uses execution profiles and should not specify legacy parameters "
                "load_balancing_policy or default_retry_policy. Configure this in a profile instead."
            )

        lbp = DSELoadBalancingPolicy(default_lbp_factory())
        self.profile_manager.profiles.setdefault(
            EXEC_PROFILE_GRAPH_DEFAULT,
            GraphExecutionProfile(load_balancing_policy=lbp))
        self.profile_manager.profiles.setdefault(
            EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT,
            GraphExecutionProfile(load_balancing_policy=lbp,
                                  request_timeout=60. * 3.))
        self.profile_manager.profiles.setdefault(
            EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT,
            GraphAnalyticsExecutionProfile(load_balancing_policy=lbp))
        self._config_mode = _ConfigMode.PROFILES
예제 #9
0
 def test_status_updates(self):
     node_count = 4
     hosts = list(range(node_count))
     policy = DSELoadBalancingPolicy(RoundRobinPolicy())
     policy.populate(Mock(metadata=ClusterMetaMock()), hosts)
     policy.on_down(0)
     policy.on_remove(1)
     policy.on_up(4)
     policy.on_add(5)
     query_plan = list(policy.make_query_plan())
     self.assertEqual(sorted(query_plan), [2, 3, 4, 5])
예제 #10
0
 def test_status_updates(self):
     node_count = 4
     hosts = list(range(node_count))
     policy = DSELoadBalancingPolicy(RoundRobinPolicy())
     policy.populate(Mock(metadata=ClusterMetaMock()), hosts)
     policy.on_down(0)
     policy.on_remove(1)
     policy.on_up(4)
     policy.on_add(5)
     query_plan = list(policy.make_query_plan())
     self.assertEqual(sorted(query_plan), [2, 3, 4, 5])