public string DropColumnFamily(Server server, string columnFamily) { _cachedKeyspaceDescription = null; using (var session = new CassandraSession(new ConnectionBuilder(KeyspaceName, server.Host, server.Port))) return(session.GetClient().system_drop_column_family(columnFamily)); }
public IReplicationStrategy Create(KsDef ksDef) { if (ksDef.Strategy_options == null) { throw new InvalidOperationException($"ksDef.Strategy_options == null for: {ksDef}"); } if (ksDef.Strategy_class == ReplicaPlacementStrategy.Simple.ToStringValue()) { if (!ksDef.Strategy_options.ContainsKey(SimpleReplicationStrategy.ReplicationFactorKey)) { throw new InvalidOperationException($"Replication factor should be specified for strategy {ksDef.Strategy_class} in: {ksDef}"); } return(SimpleReplicationStrategy.Create(int.Parse(ksDef.Strategy_options[SimpleReplicationStrategy.ReplicationFactorKey]))); } if (ksDef.Strategy_class == ReplicaPlacementStrategy.NetworkTopology.ToStringValue()) { var dataCenterReplicationFactors = ksDef.Strategy_options.Select(x => new DataCenterReplicationFactor(x.Key, int.Parse(x.Value))).ToArray(); return(NetworkTopologyReplicationStrategy.Create(dataCenterReplicationFactors)); } throw new InvalidOperationException($"Strategy {ksDef.Strategy_class} is not implemented for: {ksDef}"); }
public string UpdateColumnFamily(Server server, CfDef definition) { _cachedKeyspaceDescription = null; using (var session = new CassandraSession(new ConnectionBuilder(KeyspaceName, server.Host, server.Port))) return(session.GetClient().system_update_column_family(definition)); }
public static Keyspace ToKeyspaceFromKsDef(KsDef ksdef) { Keyspace ks = new Keyspace(); ks.Name = ksdef.Name; ks.StrategyClass = ksdef.Strategy_class; ks.CfDefs = ToColumnFamilyListFromCfDefList(ksdef.Cf_defs); return(ks); }
public KsDef Describe(Server server) { if (_cachedKeyspaceDescription == null) { _cachedKeyspaceDescription = CassandraSession.GetKeyspace(server, KeyspaceName); } return(_cachedKeyspaceDescription); }
public CassandraKeyspace(KsDef definition) { if (definition == null) { throw new ArgumentNullException("definition"); } _keyspaceName = definition.Name; _cachedKeyspaceDescription = definition; }
public CassandraKeyspaceSchema(KsDef def) { #if DEBUG _def = def; #endif Name = def.Name; Strategy = def.Strategy_class; StrategyOptions = def.Strategy_options ?? new Dictionary <string, string>(); ColumnFamilies = def.Cf_defs.Select(family => new CassandraColumnFamilySchema(family)).ToList(); DurableWrites = def.Durable_writes; }
/// <summary> /// Create the keyspace /// </summary> /// <param name="keyspace"></param> public void createKeySpace(String keyspace) { KsDef keyspaceDefinition = new KsDef(); keyspaceDefinition.Name = keyspace; keyspaceDefinition.Replication_factor = 1; keyspaceDefinition.Strategy_class = "org.apache.cassandra.locator.SimpleStrategy"; keyspaceDefinition.Strategy_options = new Dictionary <string, string>(); keyspaceDefinition.Strategy_options.Add("replication_factor", "1"); keyspaceDefinition.Cf_defs = new List <CfDef>(); client.system_add_keyspace(keyspaceDefinition); waitForCreation(keyspace); }
/// <summary> /// Returns the Keyspace with given name /// </summary> /// <param name="keyspace"></param> /// <returns></returns> public Keyspace getKeyspace(String keyspace) { KsDef ks = null; try { ks = client.describe_keyspace(keyspace); } catch (InvalidRequestException e) { } return(ThriftUtility.ToKeyspaceFromKsDef(ks)); }
/// <summary> /// Check if the keyspace exsts /// </summary> /// <param name="keyspace"></param> /// <returns></returns> public Boolean keySpaceExists(String keyspace) { KsDef ksDef = null; try { ksDef = client.describe_keyspace(keyspace); } catch (NotFoundException) { return(false); } return(ksDef != null); }
public static Keyspace FromCassandraKsDef(this KsDef ksDef) { if (ksDef == null) { return(null); } var keyspace = new Keyspace { Name = ksDef.Name, DurableWrites = ksDef.Durable_writes, ReplicationStrategy = replicationStrategyFactory.Create(ksDef), ColumnFamilies = (ksDef.Cf_defs ?? new List <CfDef>()).ToDictionary(def => def.Name, def => def.FromCassandraCfDef()), }; return(keyspace); }
/// <summary> /// Return true if the column family exists /// </summary> /// <param name="keyspace"></param> /// <param name="cfName"></param> /// <returns></returns> public Boolean cfExists(String keyspace, String cfName) { KsDef ksDef = client.describe_keyspace(keyspace); if (ksDef == null) { return(false); } foreach (CfDef cf in ksDef.Cf_defs) { if (cfName.Equals(cf.Name)) { return(true); } } return(false); }
public string UpdateKeyspace(KsDef definition) { return(ExecuteOperation(new SimpleOperation <string>(ctx => { return ctx.Session.GetClient(setKeyspace: false).system_update_keyspace(definition); }))); }
public static string UpdateKeyspace(Server server, KsDef definition) { using (var session = new CassandraSession(new ConnectionBuilder(null, server.Host, server.Port))) return(session.GetClient(setKeyspace: false).system_update_keyspace(definition)); }