2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* 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;
|
2018-12-20 13:19:44 +01:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAPI;
|
2017-11-17 02:04:45 +01:00
|
|
|
|
using XenCenterLib;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Actions
|
|
|
|
|
{
|
2018-12-20 13:19:44 +01:00
|
|
|
|
public class SingleHostStatusAction : StatusReportAction
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
private readonly Host host;
|
|
|
|
|
private readonly string[] capabilityKeys;
|
|
|
|
|
private readonly long size;
|
|
|
|
|
private readonly string[] RBAC_FAIL_STRINGS = {"HTTP", "403", "Forbidden"};
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
public SingleHostStatusAction(Host host, long size, List<string> capabilityKeys, string path, string time)
|
|
|
|
|
: base(host.Connection, string.Format(Messages.ACTION_SYSTEM_STATUS_COMPILING, Helpers.GetName(host)), path, time)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-12-20 13:19:44 +01:00
|
|
|
|
this.host = host;
|
|
|
|
|
this.capabilityKeys = capabilityKeys.ToArray();
|
|
|
|
|
this.size = size;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
public long DataTransferred;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
protected override void Run()
|
|
|
|
|
{
|
2018-12-20 13:19:44 +01:00
|
|
|
|
Status = ReportStatus.compiling;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
string hostname = Helpers.GetName(host);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
hostname = ZipStatusReportAction.SanitizeTarPathMember(hostname);
|
|
|
|
|
if (hostname.Length > 20)
|
|
|
|
|
hostname = hostname.Truncate(20);
|
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
string filename = string.Format("{1}\\{2}-bugtool-{0}.tar", hostname, filePath, timeString);
|
|
|
|
|
|
|
|
|
|
string entries_string = string.Join(",", capabilityKeys);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
log.DebugFormat("Getting system status for {0} on {1}", entries_string, hostname);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (Session == null)
|
|
|
|
|
throw new Exception(Messages.CONNECTION_IO_EXCEPTION);
|
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
HTTPHelper.Get(this, false, dataRxDelegate, filename, host.address,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
(HTTP_actions.get_ssss)HTTP_actions.get_system_status,
|
2018-02-12 12:54:27 +01:00
|
|
|
|
Session.opaque_ref, entries_string, "tar");
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
log.DebugFormat("Getting system status from {0} successful", hostname);
|
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
Status = ReportStatus.succeeded;
|
|
|
|
|
Description = Messages.COMPLETED;
|
|
|
|
|
PercentComplete = 100;
|
|
|
|
|
}
|
|
|
|
|
catch (HTTP.CancelledException)
|
|
|
|
|
{
|
|
|
|
|
throw new CancelledException();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
catch (CancelledException ce)
|
|
|
|
|
{
|
|
|
|
|
log.Info("Getting system status cancelled");
|
2018-12-20 13:19:44 +01:00
|
|
|
|
Status = ReportStatus.cancelled;
|
|
|
|
|
Error = ce;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Description = Messages.ACTION_SYSTEM_STATUS_CANCELLED;
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2018-12-20 13:19:44 +01:00
|
|
|
|
log.Error(string.Format("Getting system status from {0} failed", hostname), e);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
Status = ReportStatus.failed;
|
|
|
|
|
Error = e;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
if (Win32.GetHResult(e) == Win32.ERROR_DISK_FULL)
|
|
|
|
|
{
|
|
|
|
|
Description = Messages.ACTION_SYSTEM_STATUS_DISK_FULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
if (!string.IsNullOrEmpty(Error.Message) && RBAC_FAIL_STRINGS.All(s => Error.Message.Contains(s)))
|
|
|
|
|
{
|
|
|
|
|
var roles = Host.Connection.Session.Roles;
|
|
|
|
|
roles.Sort();
|
|
|
|
|
Description = string.Format(Messages.BUGTOOL_RBAC_FAILURE, roles[0].FriendlyName());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Description = Messages.BUGTOOL_REPORTSTATUS_FAILED;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dataRxDelegate(long rxd)
|
|
|
|
|
{
|
2018-12-20 13:19:44 +01:00
|
|
|
|
Status = ReportStatus.downloading;
|
|
|
|
|
DataTransferred = rxd;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
if (Cancelling)
|
|
|
|
|
throw new CancelledException();
|
|
|
|
|
|
2018-12-20 13:19:44 +01:00
|
|
|
|
//although the parent class's PercentComplete setter does correct out of range values,
|
|
|
|
|
//it throws an assertion to catch potentially erroneous percentage calculations;
|
|
|
|
|
//here, however, the error is expected because the MaxSize is only an estimate,
|
|
|
|
|
//hence the assertion is pointless, hence correct the value before assigning it to PercentComplete
|
|
|
|
|
|
|
|
|
|
PercentComplete = rxd < size ? (int)(rxd * 100L / size) : 100;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void RecomputeCanCancel()
|
|
|
|
|
{
|
|
|
|
|
CanCancel = !Cancelling;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|