Пример #1
0
 /// <summary>
 ///     Called when the actor is stopped.
 /// </summary>
 protected override void PostStop()
 {
     if (DatabaseProxyClient != null)
     {
         DatabaseProxyClient.Dispose();
         DatabaseProxyClient = null;
     }
 }
Пример #2
0
        /// <summary>
        ///     Initialise the server's configuration.
        /// </summary>
        /// <returns>
        ///     A <see cref="Task"/> representing the operation.
        /// </returns>
        public async Task InitialiseServerConfiguration()
        {
            RequireCurrentState();

            Log.LogInformation("Initialising configuration for server {ServerId}...", State.Id);

            switch (State.Kind)
            {
            case DatabaseServerKind.SqlServer:
            {
                CommandResult commandResult = await DatabaseProxyClient.ExecuteCommand(
                    serverId : State.Id,
                    databaseId : DatabaseProxyApiClient.MasterDatabaseId,
                    sql : ManagementSql.ConfigureServerMemory(maxMemoryMB: 500 * 1024),
                    executeAsAdminUser : true
                    );

                for (int messageIndex = 0; messageIndex < commandResult.Messages.Count; messageIndex++)
                {
                    Log.LogInformation("T-SQL message [{MessageIndex}] from server {ServerId}: {TSqlMessage}",
                                       messageIndex,
                                       State.Id,
                                       commandResult.Messages[messageIndex]
                                       );
                }

                if (!commandResult.Success)
                {
                    foreach (SqlError error in commandResult.Errors)
                    {
                        Log.LogWarning("Error encountered while initialising configuration for server {ServerId} ({ErrorKind}: {ErrorMessage})",
                                       State.Id,
                                       error.Kind,
                                       error.Message
                                       );
                    }

                    throw new SqlExecutionException($"One or more errors were encountered while configuring server (Id: {State.Id}).",
                                                    serverId: State.Id,
                                                    databaseId: DatabaseProxyApiClient.MasterDatabaseId,
                                                    sqlMessages: commandResult.Messages,
                                                    sqlErrors: commandResult.Errors
                                                    );
                }

                break;
            }

            case DatabaseServerKind.RavenDB:
            {
                if (State.Action == ProvisioningAction.Provision)     // For now, we don't attempt this during a Reconfigure (not sure if RavenDB allows running it more than once).
                {
                    await DatabaseProxyClient.InitializeRavenServerConfiguration(State.Id);
                }

                break;
            }

            default:
            {
                Log.LogInformation("Skipping initialisation of configuration for server {ServerId} (initialisation not supported for servers of kind {ServerKind}).", State.Id, State.Kind);

                return;
            }
            }

            Log.LogInformation("Configuration initialised for server {ServerId}.", State.Id);
        }