def test_default_exec_parameters(self): cluster = Cluster() self.assertEqual(cluster._config_mode, _ConfigMode.UNCOMMITTED) self.assertEqual(cluster.load_balancing_policy.__class__, default_lbp_factory().__class__) self.assertEqual( cluster.profile_manager.default.load_balancing_policy.__class__, default_lbp_factory().__class__) self.assertEqual(cluster.default_retry_policy.__class__, RetryPolicy) self.assertEqual( cluster.profile_manager.default.retry_policy.__class__, RetryPolicy) session = Session(cluster, hosts=[Host("127.0.0.1", SimpleConvictionPolicy)]) self.assertEqual(session.default_timeout, 10.0) self.assertEqual(cluster.profile_manager.default.request_timeout, 10.0) self.assertEqual(session.default_consistency_level, ConsistencyLevel.LOCAL_ONE) self.assertEqual(cluster.profile_manager.default.consistency_level, ConsistencyLevel.LOCAL_ONE) self.assertEqual(session.default_serial_consistency_level, None) self.assertEqual( cluster.profile_manager.default.serial_consistency_level, None) self.assertEqual(session.row_factory, named_tuple_factory) self.assertEqual(cluster.profile_manager.default.row_factory, named_tuple_factory)
def test_exec_profile_clone(self): cluster = Cluster(execution_profiles={EXEC_PROFILE_DEFAULT: ExecutionProfile(), 'one': ExecutionProfile()}) session = Session(cluster, hosts=[Host("127.0.0.1", SimpleConvictionPolicy)]) profile_attrs = {'request_timeout': 1, 'consistency_level': ConsistencyLevel.ANY, 'serial_consistency_level': ConsistencyLevel.SERIAL, 'row_factory': tuple_factory, 'retry_policy': RetryPolicy(), 'load_balancing_policy': default_lbp_factory()} reference_attributes = ('retry_policy', 'load_balancing_policy') # default and one named for profile in (EXEC_PROFILE_DEFAULT, 'one'): active = session.get_execution_profile(profile) clone = session.execution_profile_clone_update(profile) self.assertIsNot(clone, active) all_updated = session.execution_profile_clone_update(clone, **profile_attrs) self.assertIsNot(all_updated, clone) for attr, value in profile_attrs.items(): self.assertEqual(getattr(clone, attr), getattr(active, attr)) if attr in reference_attributes: self.assertIs(getattr(clone, attr), getattr(active, attr)) self.assertNotEqual(getattr(all_updated, attr), getattr(active, attr)) # cannot clone nonexistent profile self.assertRaises(ValueError, session.execution_profile_clone_update, 'DOES NOT EXIST', **profile_attrs)
def session_setup(self): lbp = DSELoadBalancingPolicy(default_lbp_factory()) ep_graphson2 = GraphExecutionProfile( request_timeout=60, load_balancing_policy=lbp, graph_options=GraphOptions( graph_name=self.graph_name, graph_protocol=GraphProtocol.GRAPHSON_2_0), row_factory=graph_graphson2_row_factory) ep_graphson1 = GraphExecutionProfile( request_timeout=60, load_balancing_policy=lbp, graph_options=GraphOptions(graph_name=self.graph_name)) ep_analytics = GraphAnalyticsExecutionProfile( request_timeout=60, load_balancing_policy=lbp, graph_options=GraphOptions(graph_language=b'gremlin-groovy', graph_name=self.graph_name)) self.cluster = Cluster(protocol_version=PROTOCOL_VERSION, execution_profiles={ EXEC_PROFILE_GRAPH_DEFAULT: ep_graphson1, EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT: ep_analytics, "graphson2": ep_graphson2 }) self.session = self.cluster.connect() self.ks_name = self._testMethodName.lower() self.cass_version, self.cql_version = get_server_versions()
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)
def with_cluster(cluster_fn, hosts, port, username=None, password=None): ep = ExecutionProfile(load_balancing_policy=default_lbp_factory()) cluster = Cluster(hosts, port=port, auth_provider=build_auth_provider(username, password), execution_profiles={EXEC_PROFILE_DEFAULT: ep}) cluster.connect() rv = cluster_fn(cluster) cluster.shutdown() return rv
def test_default_exec_parameters(self): cluster = Cluster() self.assertEqual(cluster._config_mode, _ConfigMode.UNCOMMITTED) self.assertEqual(cluster.load_balancing_policy.__class__, default_lbp_factory().__class__) self.assertEqual(cluster.default_retry_policy.__class__, RetryPolicy) session = Session(cluster, hosts=[Host("127.0.0.1", SimpleConvictionPolicy)]) self.assertEqual(session.default_timeout, 10.0) self.assertEqual(session.default_consistency_level, ConsistencyLevel.LOCAL_ONE) self.assertEqual(session.default_serial_consistency_level, None) self.assertEqual(session.row_factory, named_tuple_factory)
def connect(self, *args, **kwargs): auth = PlainTextAuthProvider(username=self.user, password=self.password) cluster = Cluster(contact_points=self.host, auth_provider=auth, protocol_version=3, load_balancing_policy=default_lbp_factory(), default_retry_policy=RetryPolicy(), reconnection_policy=ConstantReconnectionPolicy( delay=1, max_attempts=10), *args, **kwargs) return cluster
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
def test_no_legacy_with_profile(self): cluster_init = Cluster(execution_profiles={'name': ExecutionProfile()}) cluster_add = Cluster() cluster_add.add_execution_profile('name', ExecutionProfile()) # for clusters with profiles added either way... for cluster in (cluster_init, cluster_init): # don't allow legacy parameters set for attr, value in (('default_retry_policy', RetryPolicy()), ('load_balancing_policy', default_lbp_factory())): self.assertRaises(ValueError, setattr, cluster, attr, value) session = Session(cluster, hosts=[Host("127.0.0.1", SimpleConvictionPolicy)]) for attr, value in (('default_timeout', 1), ('default_consistency_level', ConsistencyLevel.ANY), ('default_serial_consistency_level', ConsistencyLevel.SERIAL), ('row_factory', tuple_factory)): self.assertRaises(ValueError, setattr, session, attr, value)
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)
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