public SessionSettings(Config config)
        {
            if (config == null) throw new ArgumentNullException("config");

            Builder = Cluster.Builder();
            
            // Get IP and port configuration
            int port = config.GetInt("port", 9042);
            IPEndPoint[] contactPoints = ParseContactPoints(config.GetStringList("contact-points"), port);
            Builder.AddContactPoints(contactPoints);

            // Support user/pass authentication
            if (config.HasPath("credentials"))
                Builder.WithCredentials(config.GetString("credentials.username"), config.GetString("credentials.password"));

            // Support SSL
            if (config.GetBoolean("ssl"))
                Builder.WithSSL();

            // Support compression
            string compressionTypeConfig = config.GetString("compression");
            if (compressionTypeConfig != null)
            {
                var compressionType = (CompressionType) Enum.Parse(typeof (CompressionType), compressionTypeConfig, true);
                Builder.WithCompression(compressionType);
            }
        }
Ejemplo n.º 2
0
            public static void Build(Builder builder)
            {
                if (Options.Default.USE_COMPRESSION)
                {
                    builder.WithCompression(CompressionType.Snappy);
                    Console.WriteLine("Using Compression");
                }
                if (Options.Default.USE_NOBUFFERING)
                {
                    builder.WithoutRowSetBuffering();
                    Console.WriteLine("No buffering");
                }

                Cluster = builder.AddContactPoints(Options.Default.IP_PREFIX + "1").Build();
            }
Ejemplo n.º 3
0
            private CCMCluster(CCMBridge ccmBridge, Builder builder)
            {
                int tryNo = 0;
                builder.AddContactPoints(Options.Default.IP_PREFIX + "1");
                if (Options.Default.USE_COMPRESSION)
                {
                    builder.WithCompression(CompressionType.Snappy);
                    Console.WriteLine("Using Compression");
                }
                if (Options.Default.USE_NOBUFFERING)
                {
                    builder.WithoutRowSetBuffering();
                    Console.WriteLine("No buffering");
                }

                this.Cluster = builder.Build();
                RETRY:
                this.CCMBridge = ccmBridge;
                try
                {
                    this.Session = Cluster.Connect();
                    if(tryNo>0)
                        Cluster.RefreshSchema();
                }
                catch (NoHostAvailableException e)
                {
                    if (tryNo < 10)
                    {
                        Console.WriteLine("CannotConnect to CCM node - give another try");
                        tryNo++;
                        Thread.Sleep(1000);
                        goto RETRY;
                    }
                    foreach (var entry in e.Errors)
                        Trace.TraceError("Error connecting to " + entry.Key + ": " + entry.Value);
                    throw new InvalidOperationException(null, e);
                }
            }
Ejemplo n.º 4
0
            public static CCMCluster Create(int nbNodesDC1, int nbNodesDC2, Builder builder)
            {
                #if !MYTEST
                if (nbNodesDC1 + nbNodesDC2 > 4)
                    throw new InvalidOperationException();
                #endif
                if (nbNodesDC1 == 0)
                    throw new ArgumentException();

                return new CCMCluster(CCMBridge.Create("test", nbNodesDC1, nbNodesDC2), builder);
            }
Ejemplo n.º 5
0
            public static CCMCluster Create(int nbNodesDC1, int nbNodesDC2, Builder builder)
            {
                if (nbNodesDC1 == 0)
                    throw new ArgumentException();

                return new CCMCluster(CCMBridge.Create("test", nbNodesDC1, nbNodesDC2), builder);
            }
Ejemplo n.º 6
0
            private CCMCluster(CCMBridge cassandraCluster, Builder builder)
            {
                this.CassandraCluster = cassandraCluster;
                try
                {
                    this.Cluster = builder.AddContactPoints(IP_PREFIX + "1").Build();
                    this.Session = Cluster.Connect();

                }
                catch (NoHostAvailableException e)
                {
                    foreach (var entry in e.Errors)
                        Trace.TraceError("Error connecting to " + entry.Key + ": " + entry.Value);
                    throw new InvalidOperationException(null, e);
                }
            }
 public Builder ApplyToBuilder(Builder builder)
 {
     return(builder.AddContactPoints(ContactPoints).WithPort(Port).WithDefaultKeyspace(DefaultKeyspace).WithAuthInfoProvider(new SimpleAuthInfoProvider().Add("username", Username).Add("password", Password)));
 }
Ejemplo n.º 8
0
            public static Cluster Build(Builder builder)
            {
                if (Options.Default.USE_COMPRESSION)
                {
                    builder.WithCompression(CompressionType.Snappy);
                    Trace.TraceInformation("Using Compression");
                }
                if (Options.Default.USE_NOBUFFERING)
                {
                    builder.WithoutRowSetBuffering();
                    Trace.TraceInformation("No buffering");
                }

                Cluster = builder.AddContactPoints(Options.Default.IP_PREFIX + "1").Build();
                return Cluster;
            }
Ejemplo n.º 9
0
 public CCMCluster(CCMBridge cassandraCluster, Builder builder)
 {
     int tryNo = 0;
     this.Cluster = builder.AddContactPoints(IP_PREFIX + "1").Build();
     RETRY:
     this.CassandraCluster = cassandraCluster;
     try
     {
         this.Session = Cluster.Connect();
         if(tryNo>0)
             Cluster.RefreshSchema();
     }
     catch (NoHostAvailableException e)
     {
         if (tryNo < 10)
         {
             Console.WriteLine("CannotConnect to CCM node - give another try");
             tryNo++;
             Thread.Sleep(1000);
             goto RETRY;
         }
         foreach (var entry in e.Errors)
             Trace.TraceError("Error connecting to " + entry.Key + ": " + entry.Value);
         throw new InvalidOperationException(null, e);
     }
 }