2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Wlb;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Actions.Wlb
|
|
|
|
|
{
|
|
|
|
|
[Flags]
|
2023-07-14 16:30:04 +02:00
|
|
|
|
public enum SendWlbConfigurationKind
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
None = 0,
|
|
|
|
|
SetPoolConfiguration = 1,
|
|
|
|
|
SetScheduledTask = 2,
|
|
|
|
|
DeleteScheduledTask = 4,
|
|
|
|
|
SetReportSubscription = 8,
|
|
|
|
|
DeleteReportSubscription = 16,
|
|
|
|
|
SetHostConfiguration = 32
|
2023-07-14 16:30:04 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public class SendWlbConfigurationAction : AsyncAction
|
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
private const string SET_HOST_CONFIGURATION = "set_host_configuration";
|
|
|
|
|
private const string SET_SCHEDULED_TASK = "set_scheduled_task";
|
|
|
|
|
private const string DELETE_SCHEDULED_TASK = "delete_scheduled_task";
|
|
|
|
|
private const string SET_REPORT_SUBSCRIPTIONS = "set_report_subscription";
|
|
|
|
|
private const string DELETE_REPORT_SUBSCRIPTIONS = "delete_report_subscription";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
private readonly SendWlbConfigurationKind _kind;
|
2023-07-14 16:30:04 +02:00
|
|
|
|
private readonly Dictionary<string, string> _wlbConfiguration;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public SendWlbConfigurationAction(Pool pool, Dictionary<string, string> configuration, SendWlbConfigurationKind kind)
|
|
|
|
|
: base(pool.Connection, string.Format(Messages.SAVING_WLB_CONFIGURATION_FOR, Helpers.GetName(pool).Ellipsise(50)), Messages.SAVING_WLB_CONFIGURATION, false)
|
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
Pool = pool;
|
|
|
|
|
_wlbConfiguration = configuration;
|
|
|
|
|
_kind = kind;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
#region RBAC Dependencies
|
|
|
|
|
ApiMethodsToRoleCheck.Add("pool.send_wlb_configuration");
|
|
|
|
|
ApiMethodsToRoleCheck.AddRange(Role.CommonTaskApiList);
|
|
|
|
|
ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList);
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Run()
|
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
log.Debug("Sending Workload Balancing configuration for pool " + Pool.Name());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
ClearKeys();
|
|
|
|
|
|
2023-07-14 16:30:04 +02:00
|
|
|
|
if (_kind.HasFlag(SendWlbConfigurationKind.SetHostConfiguration))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
_wlbConfiguration.Add(SET_HOST_CONFIGURATION, "true");
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2023-07-14 16:30:04 +02:00
|
|
|
|
if (_kind.HasFlag(SendWlbConfigurationKind.SetScheduledTask))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
_wlbConfiguration.Add(SET_SCHEDULED_TASK, "true");
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2023-07-14 16:30:04 +02:00
|
|
|
|
if (_kind.HasFlag(SendWlbConfigurationKind.DeleteScheduledTask))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
_wlbConfiguration.Add(DELETE_SCHEDULED_TASK, "true");
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2023-07-14 16:30:04 +02:00
|
|
|
|
if (_kind.HasFlag(SendWlbConfigurationKind.SetReportSubscription))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
_wlbConfiguration.Add(SET_REPORT_SUBSCRIPTIONS, "true");
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2023-07-14 16:30:04 +02:00
|
|
|
|
if (_kind.HasFlag(SendWlbConfigurationKind.DeleteReportSubscription))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
_wlbConfiguration.Add(DELETE_REPORT_SUBSCRIPTIONS, "true");
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
Pool.send_wlb_configuration(Session, _wlbConfiguration);
|
2017-09-03 04:33:29 +02:00
|
|
|
|
log.Debug("Successfully sent Workload Balancing configuration on pool " + Pool.Name());
|
2023-07-14 16:30:04 +02:00
|
|
|
|
Description = Messages.COMPLETED;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
if (ex is Failure f)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, f);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-07-14 16:30:04 +02:00
|
|
|
|
if (f.Message == FriendlyErrorNames.WLB_INTERNAL_ERROR)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
var wlbError = WlbServerState.ConvertWlbError(f.ErrorDescription[1]);
|
|
|
|
|
|
|
|
|
|
if (wlbError != null)
|
|
|
|
|
throw new Failure(wlbError);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-14 16:30:04 +02:00
|
|
|
|
|
|
|
|
|
throw;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ClearKeys()
|
|
|
|
|
{
|
2023-07-14 16:30:04 +02:00
|
|
|
|
_wlbConfiguration.Remove(SET_HOST_CONFIGURATION);
|
|
|
|
|
_wlbConfiguration.Remove(SET_SCHEDULED_TASK);
|
|
|
|
|
_wlbConfiguration.Remove(DELETE_SCHEDULED_TASK);
|
|
|
|
|
_wlbConfiguration.Remove(SET_REPORT_SUBSCRIPTIONS);
|
|
|
|
|
_wlbConfiguration.Remove(DELETE_REPORT_SUBSCRIPTIONS);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|