Holds a representation of the cluster schema and topology.
| 96 | |
| 97 | |
| 98 | class Metadata(object): |
| 99 | """ |
| 100 | Holds a representation of the cluster schema and topology. |
| 101 | """ |
| 102 | |
| 103 | cluster_name = None |
| 104 | """ The string name of the cluster. """ |
| 105 | |
| 106 | keyspaces = None |
| 107 | """ |
| 108 | A map from keyspace names to matching :class:`~.KeyspaceMetadata` instances. |
| 109 | """ |
| 110 | |
| 111 | partitioner = None |
| 112 | """ |
| 113 | The string name of the partitioner for the cluster. |
| 114 | """ |
| 115 | |
| 116 | token_map = None |
| 117 | """ A :class:`~.TokenMap` instance describing the ring topology. """ |
| 118 | |
| 119 | dbaas = False |
| 120 | """ A boolean indicating if connected to a DBaaS cluster """ |
| 121 | |
| 122 | def __init__(self): |
| 123 | self.keyspaces = {} |
| 124 | self.dbaas = False |
| 125 | self._hosts = {} |
| 126 | self._hosts_lock = RLock() |
| 127 | |
| 128 | def export_schema_as_string(self): |
| 129 | """ |
| 130 | Returns a string that can be executed as a query in order to recreate |
| 131 | the entire schema. The string is formatted to be human readable. |
| 132 | """ |
| 133 | return "\n\n".join(ks.export_as_string() for ks in self.keyspaces.values()) |
| 134 | |
| 135 | def refresh(self, connection, timeout, target_type=None, change_type=None, **kwargs): |
| 136 | |
| 137 | server_version = self.get_host(connection.endpoint).release_version |
| 138 | dse_version = self.get_host(connection.endpoint).dse_version |
| 139 | parser = get_schema_parser(connection, server_version, dse_version, timeout) |
| 140 | |
| 141 | if not target_type: |
| 142 | self._rebuild_all(parser) |
| 143 | return |
| 144 | |
| 145 | tt_lower = target_type.lower() |
| 146 | try: |
| 147 | parse_method = getattr(parser, 'get_' + tt_lower) |
| 148 | meta = parse_method(self.keyspaces, **kwargs) |
| 149 | if meta: |
| 150 | update_method = getattr(self, '_update_' + tt_lower) |
| 151 | if tt_lower == 'keyspace' and connection.protocol_version < 3: |
| 152 | # we didn't have 'type' target in legacy protocol versions, so we need to query those too |
| 153 | user_types = parser.get_types_map(self.keyspaces, **kwargs) |
| 154 | self._update_keyspace(meta, user_types) |
| 155 | else: |
no outgoing calls