public Cluster(ClientPolicy policy, Host[] hosts)
        {
            this.seeds = hosts;

            if (policy.user != null && policy.user.Length > 0)
            {
                this.user = ByteUtil.StringToUtf8(policy.user);

                string pass = policy.password;

                if (pass == null)
                {
                    pass = "";
                }

                if (!(pass.Length == 60 && pass.StartsWith("$2a$")))
                {
                    pass = AdminCommand.HashPassword(pass);
                }
                this.password = ByteUtil.StringToUtf8(pass);
            }

            connectionQueueSize = policy.maxConnsPerNode;
            connectionTimeout   = policy.timeout;
            maxSocketIdleMillis = 1000 * ((policy.maxSocketIdle <= MaxSocketIdleSecondLimit) ? policy.maxSocketIdle : MaxSocketIdleSecondLimit);
            tendInterval        = policy.tendInterval;
            ipMap = policy.ipMap;
            requestProleReplicas = policy.requestProleReplicas;
            useServicesAlternate = policy.useServicesAlternate;

            aliases      = new Dictionary <Host, Node>();
            nodes        = new Node[0];
            partitionMap = new Dictionary <string, Node[][]>();
        }
 /// <summary>
 /// Copy client policy from another client policy.
 /// </summary>
 public ClientPolicy(ClientPolicy other)
 {
     this.user                 = other.user;
     this.password             = other.password;
     this.clusterName          = other.clusterName;
     this.authMode             = other.authMode;
     this.timeout              = other.timeout;
     this.loginTimeout         = other.loginTimeout;
     this.maxConnsPerNode      = other.maxConnsPerNode;
     this.connPoolsPerNode     = other.connPoolsPerNode;
     this.maxSocketIdle        = other.maxSocketIdle;
     this.tendInterval         = other.tendInterval;
     this.failIfNotConnected   = other.failIfNotConnected;
     this.readPolicyDefault    = new Policy(other.readPolicyDefault);
     this.writePolicyDefault   = new WritePolicy(other.writePolicyDefault);
     this.scanPolicyDefault    = new ScanPolicy(other.scanPolicyDefault);
     this.queryPolicyDefault   = new QueryPolicy(other.queryPolicyDefault);
     this.batchPolicyDefault   = new BatchPolicy(other.batchPolicyDefault);
     this.infoPolicyDefault    = new InfoPolicy(other.infoPolicyDefault);
     this.tlsPolicy            = (other.tlsPolicy != null) ? new TlsPolicy(other.tlsPolicy) : null;
     this.ipMap                = other.ipMap;
     this.useServicesAlternate = other.useServicesAlternate;
     this.rackAware            = other.rackAware;
     this.rackId               = other.rackId;
 }
        public Cluster(ClientPolicy policy, Host[] hosts)
        {
            this.seeds = hosts;

            if (policy.user != null && policy.user.Length > 0)
            {
                this.user = ByteUtil.StringToUtf8(policy.user);

                string pass = policy.password;

                if (pass == null)
                {
                    pass = "";
                }

                if (!(pass.Length == 60 && pass.StartsWith("$2a$")))
                {
                    pass = AdminCommand.HashPassword(pass);
                }
                this.password = ByteUtil.StringToUtf8(pass);
            }

            connectionQueueSize = policy.maxThreads + 1;             // Add one connection for tend thread.
            connectionTimeout   = policy.timeout;
            maxSocketIdle       = policy.maxSocketIdle;
            tendInterval        = policy.tendInterval;
            ipMap = policy.ipMap;
            requestProleReplicas = policy.requestProleReplicas;

            aliases      = new Dictionary <Host, Node>();
            nodes        = new Node[0];
            partitionMap = new Dictionary <string, Node[][]>();
        }
Example #4
0
        public Cluster(ClientPolicy policy, Host[] hosts)
        {
            this.seeds = hosts;

            if (policy.user != null && policy.user.Length > 0)
            {
                this.user = ByteUtil.StringToUtf8(policy.user);

                string pass = policy.password;

                if (pass == null)
                {
                    pass = "";
                }

                if (! (pass.Length == 60 && pass.StartsWith("$2a$")))
                {
                    pass = AdminCommand.HashPassword(pass);
                }
                this.password = ByteUtil.StringToUtf8(pass);
            }

            connectionQueueSize = policy.maxThreads + 1; // Add one connection for tend thread.
            connectionTimeout = policy.timeout;
            maxSocketIdleMillis = 1000 * ((policy.maxSocketIdle <= MaxSocketIdleSecondLimit) ? policy.maxSocketIdle : MaxSocketIdleSecondLimit);
            tendInterval = policy.tendInterval;
            ipMap = policy.ipMap;
            requestProleReplicas = policy.requestProleReplicas;

            aliases = new Dictionary<Host, Node>();
            nodes = new Node[0];
            partitionMap = new Dictionary<string, Node[][]>();
        }
        public override void RunExample(Arguments a)
        {
            this.args = (BenchmarkArguments)a;
            shared = new BenchmarkShared(args);

            if (args.sync)
            {
                ClientPolicy policy = new ClientPolicy();
                policy.user = args.user;
                policy.password = args.password;
                policy.failIfNotConnected = true;
                client = new AerospikeClient(policy, args.host, args.port);

                try
                {
                    args.SetServerSpecific(client);
                    threads = new BenchmarkThreadSync[args.threadMax];
                    for (int i = 0; i < args.threadMax; i++)
                    {
                        threads[i] = new BenchmarkThreadSync(console, args, shared, this, client);
                    }
                    RunThreads();
                }
                finally
                {
                    client.Close();
                }
            }
            else
            {
                console.Info("Maximum concurrent commands: " + args.commandMax);

                AsyncClientPolicy policy = new AsyncClientPolicy();
                policy.user = args.user;
                policy.password = args.password;
                policy.failIfNotConnected = true;
                policy.asyncMaxCommands = args.commandMax;

                AsyncClient client = new AsyncClient(policy, args.host, args.port);
                this.client = client;

                try
                {
                    args.SetServerSpecific(client);
                    threads = new BenchmarkThreadAsync[args.threadMax];
                    for (int i = 0; i < args.threadMax; i++)
                    {
                        threads[i] = new BenchmarkThreadAsync(console, args, shared, this, client);
                    }
                    RunThreads();
                }
                finally
                {
                    client.Close();
                }
            }
        }
Example #6
0
        public Cluster(ClientPolicy policy, Host[] hosts)
        {
            this.clusterName = policy.clusterName;

            // Default TLS names when TLS enabled.
            if (policy.tlsPolicy != null)
            {
                bool useClusterName = HasClusterName;

                for (int i = 0; i < hosts.Length; i++)
                {
                    Host host = hosts[i];

                    if (host.tlsName == null)
                    {
                        string tlsName = useClusterName ? clusterName : host.name;
                        hosts[i] = new Host(host.name, tlsName, host.port);
                    }
                }
            }
            this.seeds = hosts;

            if (policy.user != null && policy.user.Length > 0)
            {
                this.user = ByteUtil.StringToUtf8(policy.user);

                string pass = policy.password;

                if (pass == null)
                {
                    pass = "";
                }

                if (!(pass.Length == 60 && pass.StartsWith("$2a$")))
                {
                    pass = AdminCommand.HashPassword(pass);
                }
                this.password = ByteUtil.StringToUtf8(pass);
            }

            tlsPolicy           = policy.tlsPolicy;
            connectionQueueSize = policy.maxConnsPerNode;
            connPoolsPerNode    = policy.connPoolsPerNode;
            connectionTimeout   = policy.timeout;
            maxSocketIdleMillis = 1000 * ((policy.maxSocketIdle <= MaxSocketIdleSecondLimit) ? policy.maxSocketIdle : MaxSocketIdleSecondLimit);
            tendInterval        = policy.tendInterval;
            ipMap = policy.ipMap;
            requestProleReplicas = policy.requestProleReplicas;
            useServicesAlternate = policy.useServicesAlternate;

            aliases      = new Dictionary <Host, Node>();
            nodesMap     = new Dictionary <string, Node>();
            nodes        = new Node[0];
            partitionMap = new Dictionary <string, Partitions>();
            cancel       = new CancellationTokenSource();
            cancelToken  = cancel.Token;
        }
        public override void RunExample(Arguments args)
        {
            ClientPolicy policy = new ClientPolicy();
            policy.user = args.user;
            policy.password = args.password;
            policy.failIfNotConnected = true;

            AerospikeClient client = new AerospikeClient(policy, args.host, args.port);

            try
            {
                args.SetServerSpecific(client);
                RunExample(client, args);
            }
            finally
            {
                client.Close();
            }
        }
Example #8
0
        public Cluster(ClientPolicy policy, Host[] hosts)
        {
            this.clusterName = policy.clusterName;
            tlsPolicy        = policy.tlsPolicy;
            this.authMode    = policy.authMode;

            // Default TLS names when TLS enabled.
            if (tlsPolicy != null)
            {
                bool useClusterName = HasClusterName;

                for (int i = 0; i < hosts.Length; i++)
                {
                    Host host = hosts[i];

                    if (host.tlsName == null)
                    {
                        string tlsName = useClusterName ? clusterName : host.name;
                        hosts[i] = new Host(host.name, tlsName, host.port);
                    }
                }
            }
            else
            {
                if (authMode == AuthMode.EXTERNAL)
                {
                    throw new AerospikeException("TLS is required for authentication mode: " + authMode);
                }
            }

            this.seeds = hosts;

            if (policy.user != null && policy.user.Length > 0)
            {
                this.user = ByteUtil.StringToUtf8(policy.user);

                // Only store clear text password if external authentication is used.
                if (authMode != AuthMode.INTERNAL)
                {
                    this.password = ByteUtil.StringToUtf8(policy.password);
                }

                string pass = policy.password;

                if (pass == null)
                {
                    pass = "";
                }

                if (!(pass.Length == 60 && pass.StartsWith("$2a$")))
                {
                    pass = AdminCommand.HashPassword(pass);
                }
                this.passwordHash = ByteUtil.StringToUtf8(pass);
            }

            connectionQueueSize = policy.maxConnsPerNode;
            connPoolsPerNode    = policy.connPoolsPerNode;
            connectionTimeout   = policy.timeout;
            loginTimeout        = policy.loginTimeout;
            maxSocketIdleMillis = 1000 * ((policy.maxSocketIdle <= MaxSocketIdleSecondLimit) ? policy.maxSocketIdle : MaxSocketIdleSecondLimit);
            tendInterval        = policy.tendInterval;
            ipMap = policy.ipMap;
            useServicesAlternate = policy.useServicesAlternate;
            rackAware            = policy.rackAware;
            rackId = policy.rackId;

            aliases      = new Dictionary <Host, Node>();
            nodesMap     = new Dictionary <string, Node>();
            nodes        = new Node[0];
            partitionMap = new Dictionary <string, Partitions>();
            cancel       = new CancellationTokenSource();
            cancelToken  = cancel.Token;
        }
        private void Login()
        {
            string server = hostBox.Text.Trim();
            int port = int.Parse(portBox.Text.Trim());
            string userName = userBox.Text.Trim();
            string password = passwordBox.Text.Trim();

            ClientPolicy policy = new ClientPolicy();
            policy.user = userName;
            policy.password = password;
            policy.failIfNotConnected = true;
            policy.timeout = 600000;

            AerospikeClient client = new AerospikeClient(policy, server, port);

            try
            {
                if (userName.Equals("admin") && password.Equals("admin"))
                {
                    Form form = new PasswordForm(client, userName);
                    form.ShowDialog();
                }

                // Query own user.
                User user = client.QueryUser(null, userName);

                if (user != null)
                {
                    bool admin = user.roles.Contains("user-admin");

                    // Initialize Global Data
                    Globals.RefreshRoles(client, user, admin);

                    Form form = new AdminForm(client, user, admin);
                    form.Show();
                }
                else
                {
                    throw new Exception("Failed to find user: " + userName);
                }
            }
            catch (Exception)
            {
                client.Close();
                throw;
            }
        }
Example #10
0
        private void ConnectSync()
        {
            ClientPolicy policy = new ClientPolicy();
            policy.failIfNotConnected = true;

            if (!user.Equals(""))
            {
                policy.user = user;
                policy.password = password;
            }

            client = new AerospikeClient(policy, host, port);

            try
            {
                SetServerSpecific();
            }
            catch (Exception e)
            {
                client.Close();
                client = null;
                throw e;
            }
        }
Example #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("User event data grouped by day\n");
            Program p = null;
            try
            {
                ClientPolicy policy = new ClientPolicy();

            //				policy.user = "******";
            //				policy.password = "******";
            //				policy.failIfNotConnected = true;
            //				p = new Program(new AerospikeClient(policy, "C-9a8d04af83.aerospike.io", 3200));
                p = new Program(new AerospikeClient(policy, "127.0.0.1", 3000));

                int feature;
                do {

                    // Present options
                    Console.WriteLine("What would you like to do:");
                    Console.WriteLine("1> Generate data");
                    Console.WriteLine("2> Simulate daily events");
                    Console.WriteLine("3> Get a day range of events for a user");
                    Console.WriteLine("0> Exit");
                    Console.Write("\nSelect 1-3 and hit enter:");
                    feature = int.Parse(Console.ReadLine());

                    if (feature != 0)
                    {
                        switch (feature)
                        {
                            case 1:
                                Console.WriteLine("********** Generate Data");
                                p.GenerateData();
                                break;
                            case 2:
                                Console.WriteLine("********** Simulate daily events");
                                p.SimulateDailyEvents();
                                break;
                            case 3:
                                Console.WriteLine("********** Get a day range of events for a user");
                                p.DayRangeForUser();
                                break;
                            case 0:
                                Console.WriteLine("Goodbye");
                                break;
                            default:
                                Console.WriteLine("********** Invalid Selection ");
                                break;
                        }
                    }
                } while (feature != 0);
            }
            catch (AerospikeException e)
            {
                Console.WriteLine("AerospikeException - Message: " + e.Message);
                Console.WriteLine("AerospikeException - StackTrace: " + e.StackTrace);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception - Message: " + e.Message);
                Console.WriteLine("Exception - StackTrace: " + e.StackTrace);
            }
            finally
            {
                if (p.client != null && p.client.Connected)
                {
                    // Close Aerospike server connection
                    p.client.Close();
                }
            }
        }
        public virtual void SetUp()
        {
            try
            {
                Console.WriteLine("Creating AerospikeClient");
                ClientPolicy clientPolicy = new ClientPolicy();
                clientPolicy.timeout = TIMEOUT;
                client = new AerospikeClient(clientPolicy, HOST, PORT);
                client.writePolicyDefault.expiration = EXPIRY;
                //client.writePolicyDefault.recordExistsAction = RecordExistsAction.REPLACE;

                Key key = new Key (NS, SET, "CDT-list-test-key");
                client.Delete(null, key);
                key = new Key(NS, SET, "setkey");
                client.Delete(null, key);
                key = new Key(NS, SET, "accountId");
                client.Delete(null, key);

            } catch (Exception ex)
            {
                caughtException = ex;
                Console.WriteLine(string.Format("TestFixtureSetUp failed in {0} - {1} {2}", this.GetType(), caughtException.GetType(), caughtException.Message));
                Console.WriteLine (caughtException.StackTrace);
            }
        }
 /// <summary>
 /// Construct client without initialization.
 /// Should only be used by classes inheriting from this client.
 /// </summary>
 protected internal AerospikeClient(ClientPolicy policy)
 {
     if (policy != null)
     {
         this.readPolicyDefault = policy.readPolicyDefault;
         this.writePolicyDefault = policy.writePolicyDefault;
         this.scanPolicyDefault = policy.scanPolicyDefault;
         this.queryPolicyDefault = policy.queryPolicyDefault;
         this.batchPolicyDefault = policy.batchPolicyDefault;
         this.infoPolicyDefault = policy.infoPolicyDefault;
     }
     else
     {
         this.readPolicyDefault = new Policy();
         this.writePolicyDefault = new WritePolicy();
         this.scanPolicyDefault = new ScanPolicy();
         this.queryPolicyDefault = new QueryPolicy();
         this.batchPolicyDefault = new BatchPolicy();
         this.infoPolicyDefault = new InfoPolicy();
     }
 }
        /// <summary>
        /// Initialize Aerospike client with suitable hosts to seed the cluster map.
        /// The client policy is used to set defaults and size internal data structures.
        /// For each host connection that succeeds, the client will:
        /// <list type="bullet">
        /// <item>Add host to the cluster map</item>
        /// <item>Request host's list of other nodes in cluster</item>
        /// <item>Add these nodes to cluster map</item>
        /// </list>
        /// <para>
        /// In most cases, only one host is necessary to seed the cluster. The remaining hosts 
        /// are added as future seeds in case of a complete network failure.
        /// </para>
        /// <para>
        /// If one connection succeeds, the client is ready to process database requests.
        /// If all connections fail and the policy's failIfNotConnected is true, a connection 
        /// exception will be thrown. Otherwise, the cluster will remain in a disconnected state
        /// until the server is activated.
        /// </para>
        /// </summary>
        /// <param name="policy">client configuration parameters, pass in null for defaults</param>
        /// <param name="hosts">array of potential hosts to seed the cluster</param>
        /// <exception cref="AerospikeException">if all host connections fail</exception>
        public AerospikeClient(ClientPolicy policy, params Host[] hosts)
        {
            if (policy == null)
            {
                policy = new ClientPolicy();
            }
            this.readPolicyDefault = policy.readPolicyDefault;
            this.writePolicyDefault = policy.writePolicyDefault;
            this.scanPolicyDefault = policy.scanPolicyDefault;
            this.queryPolicyDefault = policy.queryPolicyDefault;
            this.batchPolicyDefault = policy.batchPolicyDefault;
            this.infoPolicyDefault = policy.infoPolicyDefault;

            cluster = new Cluster(policy, hosts);
            cluster.InitTendThread(policy.failIfNotConnected);
        }
 /// <summary>
 /// Initialize Aerospike client.
 /// The client policy is used to set defaults and size internal data structures.
 /// If the host connection succeeds, the client will:
 /// <list type="bullet">
 /// <item>Add host to the cluster map</item>
 /// <item>Request host's list of other nodes in cluster</item>
 /// <item>Add these nodes to cluster map</item>
 /// </list>
 /// <para>
 /// If the connection succeeds, the client is ready to process database requests.
 /// If the connection fails and the policy's failOnInvalidHosts is true, a connection 
 /// exception will be thrown. Otherwise, the cluster will remain in a disconnected state
 /// until the server is activated.
 /// </para>
 /// </summary>
 /// <param name="policy">client configuration parameters, pass in null for defaults</param>
 /// <param name="hostname">host name</param>
 /// <param name="port">host port</param>
 /// <exception cref="AerospikeException">if host connection fails</exception>
 public AerospikeClient(ClientPolicy policy, string hostname, int port)
     : this(policy, new Host(hostname, port))
 {
 }
 public HelperTests()
 {
     clientPolicy = new ClientPolicy();
     clientPolicy.timeout = TestQueryEngine.TIME_OUT;
 }