コード例 #1
0
        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));
        }
コード例 #2
0
        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}");
        }
コード例 #3
0
        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));
        }
コード例 #4
0
ファイル: ThriftUtility.cs プロジェクト: mehtarakesh/Nector
        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);
        }
コード例 #5
0
        public KsDef Describe(Server server)
        {
            if (_cachedKeyspaceDescription == null)
            {
                _cachedKeyspaceDescription = CassandraSession.GetKeyspace(server, KeyspaceName);
            }

            return(_cachedKeyspaceDescription);
        }
コード例 #6
0
        public CassandraKeyspace(KsDef definition)
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            _keyspaceName = definition.Name;
            _cachedKeyspaceDescription = definition;
        }
コード例 #7
0
        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;
        }
コード例 #8
0
ファイル: Client.cs プロジェクト: mehtarakesh/Nector
        /// <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);
        }
コード例 #9
0
ファイル: Client.cs プロジェクト: mehtarakesh/Nector
        /// <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));
        }
コード例 #10
0
ファイル: Client.cs プロジェクト: mehtarakesh/Nector
        /// <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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: Client.cs プロジェクト: mehtarakesh/Nector
        /// <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);
        }
コード例 #13
0
 public string UpdateKeyspace(KsDef definition)
 {
     return(ExecuteOperation(new SimpleOperation <string>(ctx => {
         return ctx.Session.GetClient(setKeyspace: false).system_update_keyspace(definition);
     })));
 }
コード例 #14
0
 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));
 }