private void RetrieveKeySpaces() { RetrieveKeySpacesCommand retrieveKeySpaceCommand = new RetrieveKeySpacesCommand(); DescribeKeySpaceCommand describeKeySpaceCommand = new DescribeKeySpaceCommand(); using (DefaultAquilesConnection connection = new DefaultAquilesConnection(this)) { // i open the conection myself in order not to let the DefaultConnection change the endpoint connection.Open(); connection.Execute(retrieveKeySpaceCommand); HashSet<string>.Enumerator keySpaceIterator = retrieveKeySpaceCommand.KeySpaces.GetEnumerator(); while (keySpaceIterator.MoveNext()) { describeKeySpaceCommand.KeySpace = keySpaceIterator.Current; connection.Execute(describeKeySpaceCommand); this.AddKeySpaceDescription(this.BuildKeySpace(keySpaceIterator.Current, describeKeySpaceCommand.ColumnFamilies)); } connection.Close(); } }
/// <summary> /// Retrieve a connection for cluster associated with the given clusterName. In case there is no cluster configured with the friendly name given, a null is returned. /// <remarks>can throw <see cref="Aquiles.Exceptions.AquilesException"/> in case something went wrong</remarks> /// </summary> /// <param name="clusterName">friendly names chosen in the configuration section on the .config file</param> /// <returns>it returns a connection to work against the cluster.</returns> private IAquilesConnection InstanceRetrieveConnection(String clusterName) { if (clusterName != null) { IAquilesCluster cluster = null; DefaultAquilesConnection connection = null; if (clusters.TryGetValue(clusterName, out cluster)) { connection = new DefaultAquilesConnection(cluster); } else { throw new AquilesException(String.Format(CultureInfo.CurrentCulture, "No cluster found with name '{0}'", clusterName)); } return connection; } else { throw new ArgumentNullException("clusterName"); } }
private void CheckNodesPointsToSameCluster() { CassandraClient client = null; HashSet<CassandraEndpoint> usedEndpoints = new HashSet<CassandraEndpoint>(); FakedConnectionPool fakedConnectionPool = new FakedConnectionPool() { EndpointManager = this.endpointManager }; FakedCluster fakedCluster = new FakedCluster() { FriendlyName = this.FriendlyName, ConnectionPool = fakedConnectionPool }; CassandraEndpoint endpoint = this.endpointManager.Retrieve(); while (endpoint != null && !usedEndpoints.Contains(endpoint)) { client = this.connectionFactory.Create(endpoint); fakedConnectionPool.InjectedClient = client; RetrieveClusterNameCommand cmd = new RetrieveClusterNameCommand(); using (DefaultAquilesConnection connection = new DefaultAquilesConnection(fakedCluster)) { // i open the conection myself in order not to let the DefaultConnection change the endpoint connection.Open(); connection.Execute(cmd); connection.Close(); } if (String.IsNullOrEmpty(this.ClusterName)) { this.ClusterName = cmd.ClusterName; } else if (this.ClusterName.CompareTo(cmd.ClusterName) != 0) { throw new AquilesException(String.Format(CultureInfo.CurrentCulture, "Endpoint '{0}' points to '{1}' instead of '{2}'.", endpoint.ToString(), cmd.ClusterName, this.ClusterName)); } usedEndpoints.Add(endpoint); endpoint = this.endpointManager.Retrieve(); } }