Module: Dse

Defined in:
lib/dse/util.rb,
lib/dse.rb,
lib/dse/cluster.rb,
lib/dse/session.rb,
lib/dse/version.rb,
lib/dse/graph/edge.rb,
lib/dse/graph/path.rb,
lib/dse/statements.rb,
lib/dse/graph/result.rb,
lib/dse/graph/vertex.rb,
lib/dse/graph/options.rb,
lib/dse/geometry/point.rb,
lib/dse/graph/duration.rb,
lib/dse/graph/statement.rb,
lib/dse/geometry/polygon.rb,
lib/dse/graph/result_set.rb,
lib/dse/util/endian_buffer.rb,
lib/dse/geometry/line_string.rb,
lib/dse/graph/vertex_property.rb,
lib/dse/auth/providers/gss_api.rb,
lib/dse/auth/providers/password.rb,
lib/dse/graph/execution_profile.rb,
lib/dse/statements/host_targeting.rb,
lib/dse/load_balancing/policies/host_targeting.rb

Overview

-- Copyright DataStax, Inc.

 This software can be used solely with DataStax Enterprise. Please consult the license at
 http://www.datastax.com/terms/datastax-dse-driver-license-terms

++

Defined Under Namespace

Modules: Auth, Geometry, Graph, LoadBalancing Classes: Cluster, Session

Constant Summary collapse

VERSION =
'2.1.3'.freeze

Class Method Summary collapse

Class Method Details

.cluster(options = {}) ⇒ Dse::Cluster

Creates a Cluster instance, which extends Cassandra::Cluster. The API is identical, except that it returns a Dse::Session (see below). It takes all of the same options as Cassandra.cluster and the following extra options.

Examples:

Connecting to localhost

cluster = Dse.cluster

Configuring Cluster

cluster = Dse.cluster(
            username: username,
            password: password,
            hosts: ['10.0.1.1', '10.0.1.2', '10.0.1.3']
          )

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :graph_name (String)

    name of graph to use in graph statements

  • :graph_source (String)

    graph traversal source

  • :graph_language (String)

    language used in graph queries

  • :graph_read_consistency (Cassandra::CONSISTENCIES)

    read consistency level for graph statements. Overrides the standard statement consistency level

  • :graph_write_consistency (Cassandra::CONSISTENCIES)

    write consistency level for graph statements. Overrides the standard statement consistency level

Returns:



44
45
46
# File 'lib/dse.rb', line 44

def self.cluster(options = {})
  cluster_async(options).get
end

.cluster_async(options = {}) ⇒ Cassandra::Future<Dse::Cluster>

Creates a Cluster instance.

Returns:

  • (Cassandra::Future<Dse::Cluster>)

    a future resolving to the cluster instance.

See Also:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/dse.rb', line 54

def self.cluster_async(options = {})
  if options.key?(:execution_profiles)
    [:graph_name, :graph_source, :graph_language, :graph_read_consistency, :graph_write_consistency].each do |opt|
      raise ::ArgumentError, "#{opt} is not allowed when execution profiles are used" if options.key?(opt)
    end
  end

  username = options[:username]
  password = options[:password]
  options[:custom_types] ||= []
  options[:custom_types] << Dse::Geometry::Point << Dse::Geometry::LineString << Dse::Geometry::Polygon

  # validate_and_massage will return a new options hash, with non-C* options removed. Hold onto the original hash
  # for attributes we still need later.
  full_options = options
  options, hosts = Cassandra.validate_and_massage_options(options)

  # Use the DSE plain text authenticator if we have a username and password. The above validation already
  # raises an error if one is given without the other.
  options[:auth_provider] = Auth::Providers::Password.new(username, password) if username && password
rescue => e
  futures = options.fetch(:futures_factory) { return Cassandra::Future::Error.new(e) }
  futures.error(e)
else
  options[:cluster_klass] = Dse::Cluster
  driver = ::Cassandra::Driver.new(options)
  system_defaults = ::Cassandra::Driver.new
  profile_manager = driver.profile_manager
  unless profile_manager.profiles.key?(:default_graph)
    # full_options has the graph options. But we don't want to use other attributes like load_balancing_policy, etc.
    # in defining our default graph profile. So make a new hash that explicitly sets core profile attributes to
    # system defaults.
    graph_profile = Dse::Graph::ExecutionProfile.new(
        full_options.merge(timeout: 30,
                           load_balancing_policy: system_defaults.load_balancing_policy,
                           retry_policy: system_defaults.retry_policy,
                           consistency: system_defaults.consistency
        ))
    profile_manager.add_profile(:default_graph, graph_profile)
  end
  unless profile_manager.profiles.key?(:default_graph_system)
    graph_profile = Dse::Graph::ExecutionProfile.new(graph_read_consistency: full_options[:graph_read_consistency],
                                                     graph_write_consistency: full_options[:graph_write_consistency],
                                                     timeout: 180)
    profile_manager.add_profile(:default_graph_system, graph_profile)
  end
  unless profile_manager.profiles.key?(:default_graph_analytics)
    # Wrap the system default load-balancing policy that we'd otherwise run, with a host-targeting policy, for the
    # analytics profile.

    # We do this before driver.connect because driver.connect saves off the policy in the cluster
    # registry and does a few other things.
    graph_profile = Dse::Graph::ExecutionProfile.new(
      graph_source: 'a',
      graph_name: full_options[:graph_name],
      graph_read_consistency: full_options[:graph_read_consistency],
      graph_write_consistency: full_options[:graph_write_consistency],
      load_balancing_policy: Dse::LoadBalancing::Policies::HostTargeting.new(
          system_defaults.load_balancing_policy
      ),
      timeout: (3600 * 24 * 7)
    )
    profile_manager.add_profile(:default_graph_analytics, graph_profile)
  end
  driver.connect(hosts)
end