Exemplo n.º 1
0
 private static void AssertServerListForClientStats(LoadBalanceResponse response)
 {
     Assert.Equal(LoadBalanceResponseTypeOneofCase.ServerList, response.LoadBalanceResponseTypeCase);
     Assert.NotNull(response.ServerList);
     Assert.Equal(3, response.ServerList.Servers.Count);
     Assert.All(response.ServerList.Servers, server =>
     {
         Assert.StartsWith("10.1.6.", new IPAddress(server.IpAddress.ToByteArray()).ToString());
         Assert.Equal(80, server.Port);
         Assert.False(string.IsNullOrWhiteSpace(server.LoadBalanceToken));
     });
 }
Exemplo n.º 2
0
    /// <summary>
    /// Forces synchronization of load balanced servers. If privileges are
    /// insufficient for this activity, response data will indicate that
    /// the request has failed.
    /// </summary>
    /// <returns>Response structured serialized to JSON format</returns>
    public LoadBalanceResponse ForceLoadBalancedSync()
    {
        LoadBalanceResponse response = new LoadBalanceResponse();

        // Clear any existing sync status information prior
        // to starting synchronization.

        _loadBalanceSyncManager.ResetSyncStatus(
            _context.Request.PhysicalApplicationPath,
            System.Net.Dns.GetHostName());

        if (CanForceLoadBalancedSync)
        {
            if (TargetsAvailable)
            {
                try
                {
                    // Begin load balance synchronization (synchronous call).

                    _loadBalanceSyncManager.MakeLoadBalanceCall(
                        _siteApi.RequestInformationRef.ConnectionStringSettings.ConnectionString,
                        _context.Request.PhysicalApplicationPath.Trim(new char[] { '\\' }));

                    // Retrieve the final sync status information to verify
                    // whether or not the activity succeeded.

                    SyncStatusInfoList statusInfoList = _loadBalanceSyncManager.GetCurrentSyncStatus(
                        _context.Request.PhysicalApplicationPath,
                        System.Net.Dns.GetHostName());

                    if (statusInfoList.Count > 0)
                    {
                        // Load balance sync completed and status information
                        // is available.

                        if (VerifySyncSuccess(statusInfoList))
                        {
                            // If the operation completed with no "SyncFailed"
                            // message in the status, mark the request a success.

                            response.Success = true;
                            response.Message = _siteApi.EkMsgRef.GetMessage("force load balance success");
                        }
                        else
                        {
                            // Operation completed but "SyncFailed" appeared
                            // in the status.

                            response.Success = false;
                            response.Message = _siteApi.EkMsgRef.GetMessage("force load balance failed");
                        }
                    }
                    else
                    {
                        // If sync completed with no status information
                        // the user's server is most likely not configured
                        // for load balancing.

                        response.Success = false;
                        response.Message = _siteApi.EkMsgRef.GetMessage("force load balance no status");
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteError(ex);

                    response.Success = false;
                    response.Message = string.Format(
                        SyncErrorFormat,
                        _siteApi.EkMsgRef.GetMessage("force load balance failed"),
                        ex.Message);
                }
            }
            else
            {
                // Load balance synchronization is in progress on another server
                // in the configuration.

                response.Success = false;
                response.Message = _siteApi.EkMsgRef.GetMessage("force load balance servers in progress");
            }
        }
        else
        {
            // The current user is not authorized to initiate load balanced
            // synchronization (and/or the site is not configured for LB.

            response.Success = false;
            response.IsAuthorized = false;
            response.Message = _siteApi.EkMsgRef.GetMessage("force load balance auth");
        }

        return response;
    }