Exemplo n.º 1
0
 /// <inheritdoc />
 protected Statement(QueryProtocolOptions queryProtocolOptions)
 {
     _pagingState = queryProtocolOptions.PagingState;
     _values = queryProtocolOptions.Values;
     _consistency = queryProtocolOptions.Consistency;
     _pageSize = queryProtocolOptions.PageSize;
     _serialConsistency = queryProtocolOptions.SerialConsistency;
 }
Exemplo n.º 2
0
        public BatchRequest(int protocolVersion, BatchStatement statement, ConsistencyLevel consistency)
        {
            ProtocolVersion = protocolVersion;
            if (ProtocolVersion < 2)
            {
                throw new NotSupportedException("Batch request is supported in C* >= 2.0.x");
            }

            var subRequests = new List<IQueryRequest>();
            foreach (var q in statement.Queries)
            {
                subRequests.Add(q.CreateBatchRequest(ProtocolVersion));
            }
            _type = statement.BatchType;
            _requests = subRequests;
            Consistency = consistency;
            _timestamp = statement.Timestamp;
            if (statement.IsTracing)
            {
                _headerFlags = 0x02;
            }
            if (statement.SerialConsistencyLevel != ConsistencyLevel.Any)
            {
                if (protocolVersion < 3)
                {
                    throw new NotSupportedException("Serial consistency level for BATCH request is supported in Cassandra 2.1 or above.");
                }
                if (statement.SerialConsistencyLevel < ConsistencyLevel.Serial)
                {
                    throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
                }
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithSerialConsistency;
                _serialConsistency = statement.SerialConsistencyLevel;
            }
            if (_timestamp != null)
            {
                if (protocolVersion < 3)
                {
                    throw new NotSupportedException("Timestamp for BATCH request is supported in Cassandra 2.1 or above.");
                }
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp;
            }
        }
Exemplo n.º 3
0
 public BatchRequest(int protocolVersion, BatchStatement statement, ConsistencyLevel consistency)
 {
     if (protocolVersion < 2)
     {
         throw new NotSupportedException("Batch request is supported in C* >= 2.0.x");
     }
     _type = statement.BatchType;
     _requests = statement.Queries
         .Select(q => q.CreateBatchRequest(protocolVersion))
         .ToArray();
     Consistency = consistency;
     _timestamp = statement.Timestamp;
     if (statement.IsTracing)
     {
         _headerFlags = FrameHeader.HeaderFlag.Tracing;
     }
     if (statement.SerialConsistencyLevel != ConsistencyLevel.Any)
     {
         if (protocolVersion < 3)
         {
             throw new NotSupportedException("Serial consistency level for BATCH request is supported in Cassandra 2.1 or above.");
         }
         if (statement.SerialConsistencyLevel < ConsistencyLevel.Serial)
         {
             throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
         }
         _batchFlags |= QueryProtocolOptions.QueryFlags.WithSerialConsistency;
         _serialConsistency = statement.SerialConsistencyLevel;
     }
     if (_timestamp != null)
     {
         if (protocolVersion < 3)
         {
             throw new NotSupportedException("Timestamp for BATCH request is supported in Cassandra 2.1 or above.");
         }
         _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp;
     }
 }
Exemplo n.º 4
0
 public new CqlScalar <TEntity> SetConsistencyLevel(ConsistencyLevel?consistencyLevel)
 {
     base.SetConsistencyLevel(consistencyLevel);
     return(this);
 }
Exemplo n.º 5
0
 public IExecutionProfileBuilder WithSerialConsistencyLevel(ConsistencyLevel serialConsistencyLevel)
 {
     _serialConsistencyLevel = serialConsistencyLevel;
     return(this);
 }
Exemplo n.º 6
0
 private RetryDecision(RetryDecisionType type, ConsistencyLevel? retryCL)
 {
     _type = type;
     _retryCl = retryCL;
 }
Exemplo n.º 7
0
 public ICqlCommand WithConsistencyLevel(ConsistencyLevel cl)
 {
     _consistencyLevel = cl;
     return(this);
 }
Exemplo n.º 8
0
 /// <inheritdoc />
 public IStatement SetConsistencyLevel(ConsistencyLevel? consistency)
 {
     _consistency = consistency;
     return this;
 }
Exemplo n.º 9
0
 public IOutput ExecuteQuery(int streamId, byte[] id, string cql, RowSetMetadata metadata,
                             bool isTracing, QueryProtocolOptions queryPrtclOptions, ConsistencyLevel?consistency)
 {
     return(EndExecuteQuery(BeginExecuteQuery(streamId, id, cql, metadata, null, null, this, isTracing, queryPrtclOptions, consistency),
                            this));
 }
Exemplo n.º 10
0
        internal static DocumentClient CreateClient(Uri serviceEndpoint, string authKeyOrResourceToken, JsonSerializerSettings serializerSettings = null, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?consistencyLevel = null)
        {
            serializerSettings = serializerSettings ?? new JsonSerializerSettings();
            serializerSettings.Converters.Add(new JsonClaimConverter());
            serializerSettings.Converters.Add(new JsonClaimsPrincipalConverter());
            serializerSettings.Converters.Add(new JsonClaimsIdentityConverter());

#if NETSTANDARD2
            return(new DocumentClient(serviceEndpoint, authKeyOrResourceToken, serializerSettings, connectionPolicy, consistencyLevel));
#else
            // DocumentDB SDK only supports setting the JsonSerializerSettings on versions after NetStandard 2.0
            JsonConvert.DefaultSettings = () => serializerSettings;
            return(new DocumentClient(serviceEndpoint, authKeyOrResourceToken, connectionPolicy, consistencyLevel));
#endif
        }
Exemplo n.º 11
0
 /// <summary>
 /// Returns a Direct TCP DocumentClient from a connection.
 /// </summary>
 /// <param name="conn">The documentDB connection.</param>
 /// <param name="policy">The policy.</param>
 /// <param name="level">The consistency level.></param>
 /// <returns></returns>
 public static DocumentClient ToDocumentClient(this DocumentDbConnection conn, ConnectionPolicy policy = null, ConsistencyLevel?level = null)
 {
     return(new DocumentClient(conn.Account, conn.AccountKey, policy ?? new ConnectionPolicy
     {
         ConnectionMode = ConnectionMode.Direct,
         ConnectionProtocol = Protocol.Tcp
     }, level));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Sets the default consistency level to use for queries.
 ///
 /// The consistency level set through this method will be use for queries
 /// that don't explicitely have a consistency level.
 /// </summary>
 /// <param name="consistencyLevel">the new consistency level to set as default.</param>
 /// <returns>this QueryOptions instance</returns>
 public QueryOptions SetConsistencyLevel(ConsistencyLevel consistencyLevel)
 {
     _consistency = consistencyLevel;
     return(this);
 }
Exemplo n.º 13
0
 public DocumentClientFactory(Uri endpoint, SecureString authKeyWrite, SecureString authKeyRead, IList <string> preferredLocations, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?consistencyLevel = null)
 {
     _endpoint         = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
     _authKeyWrite     = authKeyWrite ?? throw new ArgumentNullException(nameof(authKeyWrite));
     _authKeyRead      = authKeyRead ?? throw new ArgumentNullException(nameof(authKeyRead));
     _connectionPolicy = connectionPolicy ?? new ConnectionPolicy()
     {
         ConnectionProtocol = Protocol.Tcp, ConnectionMode = ConnectionMode.Direct
     };
     _consistencyLevel   = consistencyLevel ?? ConsistencyLevel.Session;
     _serializerSettings = new JsonSerializerSettings()
     {
         NullValueHandling = NullValueHandling.Ignore
     };
     if (preferredLocations == null | preferredLocations.Count == 0)
     {
         throw new InvalidOperationException($"{nameof(preferredLocations)} must have at least one location");
     }
     _preferredLocations = (List <string>)preferredLocations;
 }
 internal MultigetQueryHelper(string commandName, string keyspace, string columnFamily, ConsistencyLevel?consistencyLevel)
 {
     this.commandName      = commandName;
     this.keyspace         = keyspace;
     this.columnFamily     = columnFamily;
     this.consistencyLevel = consistencyLevel;
 }
Exemplo n.º 15
0
        public static DocumentClient AddDefaultDocumentClientForIdentity(this IServiceCollection services, Uri serviceEndpoint, string authKeyOrResourceToken, JsonSerializerSettings serializerSettings = null, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?consistencyLevel = null, Action <DocumentClient> afterCreation = null)
        {
            var documentClient = DocumentClientFactory.CreateClient(serviceEndpoint, authKeyOrResourceToken, serializerSettings, connectionPolicy, consistencyLevel);

            afterCreation?.Invoke(documentClient);
            services.AddSingleton <IDocumentClient>(documentClient);
            return(documentClient);
        }
Exemplo n.º 16
0
 /// <summary>
 ///  Creates a Retry retry decision using the provided consistency level.
 /// </summary>
 /// <param name="consistency"> the consistency level to use for the retry.
 ///  </param>
 ///
 /// <returns>a Retry with consistency level <c>consistency</c> retry
 ///  decision.</returns>
 public static RetryDecision Retry(ConsistencyLevel?consistency)
 {
     return(new RetryDecision(RetryDecisionType.Retry, consistency));
 }
Exemplo n.º 17
0
 /// <summary>
 ///  Creates a decision to retry using the provided consistency level on the same host.
 /// </summary>
 /// <param name="consistency"> the consistency level to use for the retry.</param>
 /// <returns>a Retry with consistency level <c>consistency</c> retry decision.</returns>
 public static RetryDecision Retry(ConsistencyLevel?consistency)
 {
     return(Retry(consistency, true));
 }
Exemplo n.º 18
0
 /// <summary>
 ///  Sets a default consistency level for all <c>BoundStatement</c> created
 ///  from this object. <p> If no consistency level is set through this method, the
 ///  BoundStatement created from this object will use the default consistency
 ///  level (One). </p><p> Changing the default consistency level is not retroactive,
 ///  it only applies to BoundStatement created after the change.</p>
 /// </summary>
 /// <param name="consistency"> the default consistency level to set. </param>
 /// <returns>this <c>PreparedStatement</c> object.</returns>
 public PreparedStatement SetConsistencyLevel(ConsistencyLevel consistency)
 {
     ConsistencyLevel = consistency;
     return this;
 }
Exemplo n.º 19
0
 private RetryDecision(RetryDecisionType type, ConsistencyLevel?retryConsistencyLevel, bool useCurrentHost)
 {
     DecisionType          = type;
     RetryConsistencyLevel = retryConsistencyLevel;
     UseCurrentHost        = useCurrentHost;
 }
Exemplo n.º 20
0
        public IAsyncResult BeginExecuteQuery(int streamId, byte[] id, string cql, RowSetMetadata metadata,
                                              AsyncCallback callback, object state, object owner,
                                              bool isTracing, QueryProtocolOptions queryProtocolOptions, ConsistencyLevel?consistency = null)
        {
            AsyncResult <IOutput> jar = SetupJob(streamId, callback, state, owner, "EXECUTE");

            BeginJob(jar, SetupKeyspace(jar, SetupPreparedQuery(jar, id, cql, () =>
            {
                Evaluate(new ExecuteRequest(jar.StreamId, id, metadata, isTracing, queryProtocolOptions, consistency), jar.StreamId,
                         frame2 =>
                {
                    AbstractResponse response = FrameParser.Parse(frame2);
                    if (response is ResultResponse)
                    {
                        JobFinished(jar, (response as ResultResponse).Output);
                    }
                    else
                    {
                        _protocolErrorHandlerAction(new ErrorActionParam
                        {
                            AbstractResponse = response,
                            Jar = jar
                        });
                    }
                });
            })));

            return(jar);
        }
Exemplo n.º 21
0
 /// <summary>
 ///  Creates a decision to retry using the provided consistency level.
 /// </summary>
 /// <param name="consistency"> the consistency level to use for the retry.</param>
 /// <param name="useCurrentHost">Determines if the retry is made using the current host.</param>
 /// <returns>a Retry with consistency level <c>consistency</c> retry
 ///  decision.</returns>
 public static RetryDecision Retry(ConsistencyLevel?consistency, bool useCurrentHost)
 {
     return(new RetryDecision(RetryDecisionType.Retry, consistency, useCurrentHost));
 }
Exemplo n.º 22
0
 public new Batch SetConsistencyLevel(ConsistencyLevel?consistencyLevel)
 {
     base.SetConsistencyLevel(consistencyLevel);
     return(this);
 }
Exemplo n.º 23
0
 public new CqlCommand SetConsistencyLevel(ConsistencyLevel?consistencyLevel)
 {
     base.SetConsistencyLevel(consistencyLevel);
     return(this);
 }
Exemplo n.º 24
0
 /// <inheritdoc />
 public IStatement SetConsistencyLevel(ConsistencyLevel?consistency)
 {
     ConsistencyLevel = consistency;
     return(this);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Cloud client provider.
 /// </summary>
 /// <param name="serviceEndpoint">The service endpoint URL.</param>
 /// <param name="permissionFeed">Permission feed list.</param>
 /// <param name="connectionPolicy">Connection policy.</param>
 /// <param name="desiredConsistencyLevel">Consistency level.</param>
 public CloudClient(Uri serviceEndpoint, IList <Permission> permissionFeed,
                    ConnectionPolicy connectionPolicy        = null,
                    ConsistencyLevel?desiredConsistencyLevel = default(ConsistencyLevel?))
 {
     _client = new DocumentClient(serviceEndpoint, permissionFeed, connectionPolicy, desiredConsistencyLevel);
 }
Exemplo n.º 26
0
        ///// <summary>
        ///// Changes the replication mode to sync for server.
        ///// </summary>
        ///// <param name="fabricClient"></param>
        //internal static void SwitchServerToSyncReplication(COMMONNAMESPACE.IFabricClient fabricClient, string callingComponent)
        //{
        //    if (!IsCurrentReplicationModeAsync(fabricClient)["Server"])
        //    {
        //        return;
        //    }

        //    NamingServiceConfig.NamingServiceConfigurationWriter namingServiceWriter =
        //            new NamingServiceConfig.NamingServiceConfigurationWriter(fabricClient);

        //    NamingServiceConfig.DocumentServiceConfiguration config = new NamingServiceConfig.DocumentServiceConfiguration();
        //    config.DocumentServiceName = ConfigurationManager.AppSettings["DatabaseAccountId"];
        //    config.IsServerReplicationAsync = false;

        //    namingServiceWriter.UpdateDatabaseAccountConfigurationAsync(config).Wait();

        //    Task.Delay(TimeSpan.FromSeconds(ReplicationTests.ConfigurationRefreshIntervalInSec)).Wait();
        //    TestCommon.ForceRefreshNamingServiceConfigs(callingComponent, FabricServiceType.ServerService).Wait();
        //}

        ///// <summary>
        ///// Changes the replication mode to async for server.
        ///// </summary>
        ///// <param name="fabricClient"></param>
        //internal static void SwitchServerToAsyncReplication(COMMONNAMESPACE.IFabricClient fabricClient, string callingComponent)
        //{
        //    if (IsCurrentReplicationModeAsync(fabricClient)["Server"])
        //    {
        //        return;
        //    }

        //    NamingServiceConfig.NamingServiceConfigurationWriter namingServiceWriter =
        //        new NamingServiceConfig.NamingServiceConfigurationWriter(fabricClient);

        //    NamingServiceConfig.DocumentServiceConfiguration config = new NamingServiceConfig.DocumentServiceConfiguration();
        //    config.DocumentServiceName = ConfigurationManager.AppSettings["DatabaseAccountId"];
        //    config.IsServerReplicationAsync = true;

        //    namingServiceWriter.UpdateDatabaseAccountConfigurationAsync(config).Wait();

        //    Task.Delay(TimeSpan.FromSeconds(ReplicationTests.ConfigurationRefreshIntervalInSec)).Wait();
        //    TestCommon.ForceRefreshNamingServiceConfigs(callingComponent, FabricServiceType.ServerService).Wait();
        //}

        #endregion

        #region Environment Configuration Helpers

        internal static DocumentClient[] GetClientsLocked(bool useGateway = false, Protocol protocol = Protocol.Tcp, int timeoutInSeconds = 10, ConsistencyLevel?defaultConsistencyLevel = null, AuthorizationTokenType tokenType = AuthorizationTokenType.PrimaryMasterKey)
        {
            var toReturn = new DocumentClient[TestCommon.ReplicationFactor];

            for (uint i = 0; i < toReturn.Length; i++)
            {
                toReturn[i] = TestCommon.CreateClient(useGateway, protocol, timeoutInSeconds, defaultConsistencyLevel, tokenType);
                toReturn[i].LockClient(i);
            }

            return(toReturn);
        }
Exemplo n.º 27
0
 /// <summary>
 /// Cloud client provider.
 /// </summary>
 /// <param name="serviceEndpoint">The service endpoint URL.</param>
 /// <param name="authKey">Authentication key.</param>
 /// <param name="connectionPolicy">Connection policy.</param>
 /// <param name="desiredConsistencyLevel">Consistency level.</param>
 public CloudClient(Uri serviceEndpoint, SecureString authKey,
                    ConnectionPolicy connectionPolicy        = null,
                    ConsistencyLevel?desiredConsistencyLevel = default(ConsistencyLevel?))
 {
     _client = new DocumentClient(serviceEndpoint, authKey, connectionPolicy, desiredConsistencyLevel);
 }
Exemplo n.º 28
0
 public IExecutionProfileBuilder WithConsistencyLevel(ConsistencyLevel consistencyLevel)
 {
     _consistencyLevel = consistencyLevel;
     return(this);
 }
Exemplo n.º 29
0
 /// <summary>
 /// Cloud client provider.
 /// </summary>
 /// <param name="serviceEndpoint">The service endpoint URL.</param>
 /// <param name="resourceTokens">Resource tokens.</param>
 /// <param name="connectionPolicy">Connection policy.</param>
 /// <param name="desiredConsistencyLevel">Consistency level.</param>
 public CloudClient(Uri serviceEndpoint, IDictionary <string, string> resourceTokens,
                    ConnectionPolicy connectionPolicy        = null,
                    ConsistencyLevel?desiredConsistencyLevel = default(ConsistencyLevel?))
 {
     _client = new DocumentClient(serviceEndpoint, resourceTokens, connectionPolicy, desiredConsistencyLevel);
 }
Exemplo n.º 30
0
 public new CqlQuerySingleElement <TEntity> SetConsistencyLevel(ConsistencyLevel?consistencyLevel)
 {
     base.SetConsistencyLevel(consistencyLevel);
     return(this);
 }
Exemplo n.º 31
0
 public new CqlConditionalCommand <TEntity> SetConsistencyLevel(ConsistencyLevel?consistencyLevel)
 {
     base.SetConsistencyLevel(consistencyLevel);
     return(this);
 }
Exemplo n.º 32
0
 private RetryDecision(RetryDecisionType type, ConsistencyLevel?retryCL)
 {
     _type    = type;
     _retryCl = retryCL;
 }
 internal MockDocumentClient(Uri serviceEndpoint, IList <ResourceToken> resourceTokens, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?desiredConsistencyLevel = null)
     : base(serviceEndpoint, resourceTokens, connectionPolicy, desiredConsistencyLevel)
 {
     this.Init();
 }
Exemplo n.º 34
0
 internal static IDocumentClient CreateDocumentClient(Uri endpoint, string authKeyOrResourceToken, JsonSerializerSettings jsonSerializerSettings, ConnectionPolicy connectionPolicy = null, ConsistencyLevel?desiredConsistencyLevel = null)
 {
     return(new DocumentClient(endpoint, authKeyOrResourceToken, jsonSerializerSettings, connectionPolicy ?? ConnectionPolicy.Default, desiredConsistencyLevel));
 }
Exemplo n.º 35
0
 public IOutput Query(int streamId, string cqlQuery, bool tracingEnabled, QueryProtocolOptions queryPrtclOptions,
                      ConsistencyLevel?consistency = null)
 {
     return(EndQuery(BeginQuery(streamId, cqlQuery, null, null, this, tracingEnabled, queryPrtclOptions, consistency), this));
 }
 /// <summary>
 /// Sets the serial consistency level for execution of the query.  (NOTE: This only applies to queries using lightweight
 /// transactions -- LWT).
 /// </summary>
 public CqlQueryOptions SetSerialConsistencyLevel(ConsistencyLevel consistencyLevel)
 {
     _serialConsistencyLevel = consistencyLevel;
     return(this);
 }
Exemplo n.º 37
0
 /// <summary>
 /// Sets the serial consistency level for execution of the query.  (NOTE: This only applies to queries using lightweight
 /// transactions -- LWT).
 /// </summary>
 public CqlQueryOptions SetSerialConsistencyLevel(ConsistencyLevel consistencyLevel)
 {
     _serialConsistencyLevel = consistencyLevel;
     return this;
 }