private static String PollTaskForResult(IXenConnection connection, ref Session session, HTTP.FuncBool cancellingDelegate, XenRef <Task> task) { //Program.AssertOffEventThread(); task_status_type status; do { if (cancellingDelegate != null && cancellingDelegate()) { throw new XenAdmin.CancelledException(); } System.Threading.Thread.Sleep(500); status = (task_status_type)Task.DoWithSessionRetry(connection, ref session, (Task.TaskStatusOp)Task.get_status, task.opaque_ref); }while (status == task_status_type.pending || status == task_status_type.cancelling); if (cancellingDelegate != null && cancellingDelegate()) { throw new XenAdmin.CancelledException(); } if (status == task_status_type.failure) { throw new Failure(Task.get_error_info(session, task)); } else { return(Task.get_result(session, task)); } }
private static String PollTaskForResult(IXenConnection connection, ref Session session, HTTP.FuncBool cancellingDelegate, XenRef<Task> task, bool timeout = false) { //Program.AssertOffEventThread(); task_status_type status; int tries = POLL_FOR_TASK_RESULT_TIMEOUT / POLL_FOR_TASK_RESULT_SLEEP_INTERVAL; do { if (cancellingDelegate != null && cancellingDelegate()) throw new XenAdmin.CancelledException(); System.Threading.Thread.Sleep(POLL_FOR_TASK_RESULT_SLEEP_INTERVAL); tries--; status = (task_status_type)Task.DoWithSessionRetry(connection, ref session, (Task.TaskStatusOp)Task.get_status, task.opaque_ref); } while ((status == task_status_type.pending || status == task_status_type.cancelling) && (!timeout || tries > 0)); if (cancellingDelegate != null && cancellingDelegate()) throw new XenAdmin.CancelledException(); if (status == task_status_type.failure) { throw new Failure(Task.get_error_info(session, task)); } else { return Task.get_result(session, task); } }
public static String Put(HTTP.UpdateProgressDelegate progressDelegate, int timeout, XenRef <Task> taskRef, ref Session session, string path, string hostname, Delegate f, params object[] p) { HTTP.FuncBool cancellingDelegate = (HTTP.FuncBool) delegate() { return(false); }; log.InfoFormat("HTTP导入文件从[{0}]到主机[{1}]", path, hostname); try { List <object> args = new List <object>(); args.Add(progressDelegate); args.Add(cancellingDelegate); args.Add(timeout); args.Add(hostname); args.Add(null); //IWebProxy args.Add(path); args.Add(taskRef.opaque_ref); // task_id args.AddRange(p); f.DynamicInvoke(args.ToArray()); } catch (Failure failure) { log.InfoFormat("HTTP导入文件失败:{0}", failure.ErrorDescription.ToString()); } catch (Exception ex) { log.InfoFormat("HTTP导入文件失败:{0}", ex.Message); } return(PollTaskForResult(ref ConnectManager.session, taskRef)); }
/// <summary> /// A general HttpPut method, with delegates for progress and cancelling /// </summary> /// <param name="progressDelegate">Delegate called periodically (500ms) with percent complete</param> /// <param name="cancellingDelegate">Delegate called periodically to see if need to cancel</param> /// <param name="timeout">Timeout value in ms</param> /// <param name="task">The task used to track this http get</param> /// <param name="session">Session used to make api calls (may be replaced if logged out, hence ref)</param> /// <param name="path">Path to file to put</param> /// <returns>The result of the task passed in</returns> public static String Put(XenAPI.HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout, IXenConnection connection, XenRef <Task> task, ref Session session, string path, string hostname, Delegate f, params object[] p) { log.DebugFormat("HTTP PUTTING file from {0} to {1}", path, hostname); HTTP.FuncBool cancellingDelegate2 = (HTTP.FuncBool) delegate() { return(XenAdminConfigManager.Provider.ForcedExiting || cancellingDelegate != null && cancellingDelegate()); }; try { List <object> args = new List <object>(); args.Add(progressDelegate); args.Add(cancellingDelegate2); args.Add(timeout); args.Add(hostname); args.Add(XenAdminConfigManager.Provider.GetProxyFromSettings(connection)); args.Add(path); args.Add(task.opaque_ref); // task_id args.AddRange(p); f.DynamicInvoke(args.ToArray()); } catch (Exception e) { log.DebugFormat("Caught exception doing HTTP PUT from {0} to {1}", path, hostname); log.Debug(e, e); PollTaskForResult(connection, ref session, cancellingDelegate2, task); if (e is CancelledException || e.InnerException is CancelledException) { throw new XenAdmin.CancelledException(); } else { throw; } } return(PollTaskForResult(connection, ref session, cancellingDelegate2, task)); }
public static void get_wlb_diagnostics(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id) { Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/wlb_diagnostics", proxy, path, new object[] { "task_id", task_id, "session_id", session_id }); }
public static void get_system_status(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id, string entries, string output) { Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/system-status", proxy, path, new object[] { "task_id", task_id, "session_id", session_id, "entries", entries, "output", output }); }
public static void get_pool_xml_db_sync(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id) { Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/pool/xmldbdump", proxy, path, new object[] { "task_id", task_id, "session_id", session_id }); }
public static void host_rrd(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id, bool json) { Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/host_rrd", proxy, path, new object[] { "task_id", task_id, "session_id", session_id, "json", json }); }
public static void put_host_restore(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id) { Put(progressDelegate, cancellingDelegate, timeout_ms, hostname, "/host_restore", proxy, path, new object[] { "task_id", task_id, "session_id", session_id }); }
/// <summary> /// Blocks until events are sent on the session, then processes any received events and adds them /// to eventQueue. Will always add at least one event to eventQueue. /// This function should be used with XenServer up to version 6.0. For XenServer higher than 6.0, GetEvents() should be used instead. /// </summary> /// <param name="session"></param> /// <param name="eventQueue"></param> /// <param name="cancelled"></param> public static void GetNextEvents(Session session, LockFreeQueue <ObjectChange> eventQueue, HTTP.FuncBool cancelled) { Proxy_Event[] proxyEvents; try { proxyEvents = Event.next(session); } catch (WebException e) { // Catch timeout, and turn it into an EventNextBlockedException so we can recognise it later (CA-33145) if (e.Status == WebExceptionStatus.Timeout) { throw new EventNextBlockedException(); } else { throw; } } if (proxyEvents.Length == 0) { throw new IOException("Event.next() returned no events; the server is misbehaving."); } if (cancelled()) { return; } //We want to do the marshalling on this bg thread so as not to block the gui thread foreach (Proxy_Event proxyEvent in proxyEvents) { ObjectChange objectChange = ProcessEvent(proxyEvent); if (objectChange != null) { eventQueue.Enqueue(objectChange); } } }
/// <sumary> /// Gets all objects from the server. Used in order to fill the cache. /// This function implements the new event system, available from in API version 1.9. /// In the new event system, (GetAllRecords + GetEvents) sequence will replace (RegisterForEvents + DownloadObjects + GetNextEvents). /// </summary> /// <param name="session">The session over which to download the objects. Must not be null.</param> /// <param name="changes">The queue that the ObjectChanges will be put into. Must not be null.</param> /// <param name="cancelled">Used by GetEvents().</param> /// <param name="legacyEventSystem">True if legacy event system (event.next) should to be used.</param> /// <param name="token">Used by GetEvents().</param> public static void GetAllObjects(Session session, LockFreeQueue <ObjectChange> changes, HTTP.FuncBool cancelled, bool legacyEventSystem, ref string token) { if (legacyEventSystem) { DownloadObjects(session, changes); return; } // download objects that are not covered by event.from(), e.g. Roles List <ObjectChange> list = new List <ObjectChange>(); Download_Role(session, list); foreach (ObjectChange o in list) { changes.Enqueue(o); } // get all objects with event.from() token = ""; GetEvents(session, changes, cancelled, false, ref token); }
public static void get_export_metadata(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id, string uuid) { Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/export_metadata", proxy, path, "task_id", task_id, "session_id", session_id, "uuid", uuid); }
/// <summary> /// Blocks until events are sent on the session, or timeout is reached, then processes any received events and adds them /// to eventQueue. This function implements the new event system, available in API version 1.9. /// In the new event system, (GetAllRecords + GetEvents) sequence will replace (RegisterForEvents + DownloadObjects + GetNextEvents). /// </summary> /// <param name="session"></param> /// <param name="eventQueue"></param> /// <param name="cancelled"></param> /// <param name="legacyEventSystem">True if legacy event system (event.next) should be used.</param> /// <param name="token">A token used by event.from(). /// It should be the empty string when event.from is first called, which is the replacement of get_all_records. /// </param> public static void GetEvents(Session session, LockFreeQueue <ObjectChange> eventQueue, HTTP.FuncBool cancelled, bool legacyEventSystem, ref string token) { if (legacyEventSystem) { GetNextEvents(session, eventQueue, cancelled); return; } Proxy_Event[] proxyEvents; try { var classes = new [] { "*" }; // classes that we are interested in receiving events from var eventResult = Event.from(session, classes, token, EVENT_FROM_TIMEOUT); token = eventResult.token; proxyEvents = eventResult.events; } catch (WebException e) { // Catch timeout, and turn it into an EventNextBlockedException so we can recognise it later (CA-33145) if (e.Status == WebExceptionStatus.Timeout) { throw new EventNextBlockedException(); } else { throw; } } if (cancelled()) { return; } //We want to do the marshalling on this bg thread so as not to block the gui thread foreach (Proxy_Event proxyEvent in proxyEvents) { ObjectChange objectChange = ProcessEvent(proxyEvent); if (objectChange != null) { eventQueue.Enqueue(objectChange); } } }
public static void put_blob(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id, string reff) { Put(progressDelegate, cancellingDelegate, timeout_ms, hostname, "/blob", proxy, path, "task_id", task_id, "session_id", session_id, "ref", reff); }
public static void put_oem_patch_stream(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id) { Put(progressDelegate, cancellingDelegate, timeout_ms, hostname, "/oem_patch_stream", proxy, path, "task_id", task_id, "session_id", session_id); }
public static void get_host_logs_download(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id) { Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/host_logs_download", proxy, path, "task_id", task_id, "session_id", session_id); }
private static void Get(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, string remotePath, IWebProxy proxy, string localPath, params object[] args) { HTTP.Get(dataCopiedDelegate, cancellingDelegate, HTTP.BuildUri(hostname, remotePath, args), proxy, localPath, timeout_ms); }
public static void put_import_raw_vdi(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id, string vdi) { Put(progressDelegate, cancellingDelegate, timeout_ms, hostname, "/import_raw_vdi", proxy, path, new object[] { "task_id", task_id, "session_id", session_id, "vdi", vdi }); }
public static void get_wlb_report(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id, string report, params string[] args) { Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/wlb_report", proxy, path, new object[] { "task_id", task_id, "session_id", session_id, "report", report, args }); }
public static void rrd_updates(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id, long start, string cf, long interval, bool host, string uuid, bool json) { Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/rrd_updates", proxy, path, new object[] { "task_id", task_id, "session_id", session_id, "start", start, "cf", cf, "interval", interval, "host", host, "uuid", uuid, "json", json }); }
private static void Put(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, string remotePath, IWebProxy proxy, string localPath, params object[] args) { HTTP.Put(progressDelegate, cancellingDelegate, HTTP.BuildUri(hostname, remotePath, args), proxy, localPath, timeout_ms); }
/// <summary> /// A general HttpPut method, with delegates for progress and cancelling /// </summary> /// <param name="progressDelegate">Delegate called periodically (500ms) with percent complete</param> /// <param name="cancellingDelegate">Delegate called periodically to see if need to cancel</param> /// <param name="timeout">Whether to apply a timeout</param> /// <param name="task">The task used to track this http get</param> /// <param name="session">Session used to make api calls (may be replaced if logged out, hence ref)</param> /// <param name="path">Path to file to put</param> /// <returns>The result of the task passed in</returns> public static String Put(XenAPI.HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, bool timeout, IXenConnection connection, XenRef <Task> task, ref Session session, string path, string hostname, Delegate f, params object[] p) { return(Put(progressDelegate, cancellingDelegate, XenAdminConfigManager.Provider.GetProxyTimeout(timeout), connection, task, ref session, path, hostname, f, p)); }
public static void put_import(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id, bool restore, bool force, string sr_id) { Put(progressDelegate, cancellingDelegate, timeout_ms, hostname, "/import", proxy, path, new object[] { "task_id", task_id, "session_id", session_id, "restore", restore, "force", force, "sr_id", sr_id }); }
/// <summary> /// Blocks until events are sent on the session, or timeout is reached, then processes any received events and adds them /// to eventQueue. This function implements the new event system, available in API version 1.9. /// In the new event system, (GetAllRecords + GetEvents) sequence will replace (RegisterForEvents + DownloadObjects + GetNextEvents). /// </summary> /// <param name="session"></param> /// <param name="eventQueue"></param> /// <param name="cancelled"></param> /// <param name="token">A token used by event.from(). /// It should be the empty string when event.from is first called, which is the replacement of get_all_records. /// </param> public static void GetEvents(Session session, LockFreeQueue <ObjectChange> eventQueue, HTTP.FuncBool cancelled, ref string token) { Proxy_Event[] proxyEvents = {}; Event[] events = {}; try { var classes = new [] { "*" }; // classes that we are interested in receiving events from var eventResult = Event.from(session, classes, token, EVENT_FROM_TIMEOUT); if (session.JsonRpcClient != null) { var batch = (EventBatch)eventResult; events = batch.events; token = batch.token; } else { var evts = (Events)eventResult; proxyEvents = evts.events; token = evts.token; } } catch (WebException e) { // Catch timeout, and turn it into an EventFromBlockedException so we can recognise it later (CA-33145) if (e.Status == WebExceptionStatus.Timeout) { throw new EventFromBlockedException(); } else { throw; } } if (cancelled()) { return; } //We want to do the marshalling on this background thread so as not to block the gui thread if (session.JsonRpcClient != null) { foreach (Event evt in events) { var objectChange = ProcessEvent(evt.class_, evt.operation, evt.opaqueRef, evt.snapshot, false); if (objectChange != null) { eventQueue.Enqueue(objectChange); } } } else { foreach (Proxy_Event proxyEvent in proxyEvents) { var objectChange = ProcessEvent(proxyEvent.class_, proxyEvent.operation, proxyEvent.opaqueRef, proxyEvent.snapshot, true); if (objectChange != null) { eventQueue.Enqueue(objectChange); } } } }
public static void get_export_raw_vdi(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id, string vdi) { Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/export_raw_vdi", proxy, path, new object[] { "task_id", task_id, "session_id", session_id, "vdi", vdi }); }
private const double EVENT_FROM_TIMEOUT = 30; // 30 seconds /// <summary> /// Gets all objects from the server. Used in order to fill the cache. /// This function implements the new event system, available from in API version 1.9. /// In the new event system, (GetAllRecords + GetEvents) sequence will replace (RegisterForEvents + DownloadObjects + GetNextEvents). /// </summary> /// <param name="session">The session over which to download the objects. Must not be null.</param> /// <param name="changes">The queue that the ObjectChanges will be put into. Must not be null.</param> /// <param name="cancelled">Used by GetEvents().</param> /// <param name="token">Used by GetEvents().</param> public static void GetAllObjects(Session session, LockFreeQueue <ObjectChange> changes, HTTP.FuncBool cancelled, ref string token) { // download objects that are not covered by event.from(), e.g. Roles var roleRecords = Role.get_all_records(session); foreach (KeyValuePair <XenRef <Role>, Role> entry in roleRecords) { changes.Enqueue(new ObjectChange(typeof(Role), entry.Key.opaque_ref, entry.Value)); } // get all objects with event.from() token = ""; GetEvents(session, changes, cancelled, ref token); }
public static String Get(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, bool timeout, HTTP.DataCopiedDelegate dataRxDelegate, IXenConnection connection, XenRef <Task> task, ref Session session, string path, string hostname, Delegate f, params object[] p) { log.DebugFormat("HTTP GETTING file from {0} to {1}", hostname, path); // Cannot use ref param in anonymous method, so save it here and restore it later Session _session = session; HTTP.DataCopiedDelegate dataCopiedDelegate = delegate(long bytes) { if (progressDelegate != null) { int progress = (int)(100 * (double)Task.DoWithSessionRetry(connection, ref _session, (Task.TaskProgressOp)Task.get_progress, task.opaque_ref)); progressDelegate(progress); } if (dataRxDelegate != null) { dataRxDelegate(bytes); } }; HTTP.FuncBool cancellingDelegate2 = (HTTP.FuncBool) delegate() { return(XenAdminConfigManager.Provider.ForcedExiting || cancellingDelegate != null && cancellingDelegate()); }; try { List <object> args = new List <object>(); args.Add(dataCopiedDelegate); args.Add(cancellingDelegate2); args.Add(XenAdminConfigManager.Provider.GetProxyTimeout(timeout)); args.Add(hostname); args.Add(XenAdminConfigManager.Provider.GetProxyFromSettings(connection)); args.Add(path); args.Add(task.opaque_ref); // task_id args.AddRange(p); f.DynamicInvoke(args.ToArray()); } catch (Exception e) { log.Debug($"Caught exception doing HTTP GET from {hostname} to {path}", e); if (e is WebException && e.InnerException is IOException && Win32.GetHResult(e.InnerException as IOException) == Win32.ERROR_DISK_FULL) { throw e.InnerException; } else if (e is CancelledException || e.InnerException is CancelledException) { throw new XenAdmin.CancelledException(); } else if (e.InnerException.Message == "Received error code HTTP/1.1 403 Forbidden\r\n from the server") { // RBAC Failure List <Role> roles = connection.Session.Roles; roles.Sort(); throw new Exception(String.Format(Messages.RBAC_HTTP_FAILURE, roles[0].FriendlyName()), e); } else { throw e.InnerException; } } return(PollTaskForResult(connection, ref session, cancellingDelegate2, task)); }
public static void get_pool_patch_download(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms, string hostname, IWebProxy proxy, string path, string task_id, string session_id, string uuid) { Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/pool_patch_download", proxy, path, new object[] { "task_id", task_id, "session_id", session_id, "uuid", uuid }); }