public SiteExtensionInfo InstallExtension(string id, SiteExtensionInfo requestInfo) { if (requestInfo == null) { requestInfo = new SiteExtensionInfo(); } SiteExtensionInfo extension; try { extension = _manager.InstallExtension(id, requestInfo.Version, requestInfo.FeedUrl); } catch (WebException e) { // This can happen for example if a bad feed URL is passed throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Site extension download failure", e)); } catch (Exception e) { // This can happen for example if the exception package is corrupted throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Site extension install exception. The package might be invalid.", e)); } if (extension == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Could not find " + id)); } return(extension); }
public SiteExtensionInfo InstallExtension(string id, string version = null) { SiteExtensionInfo extension = _manager.InstallExtension(id, version); if (extension == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, id)); } return(extension); }
public SiteExtensionInfo InstallExtension(SiteExtensionInfo info) { SiteExtensionInfo extension = _manager.InstallExtension(info); if (extension == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, info.ToString())); } return(extension); }
public async Task <HttpResponseMessage> InstallExtension(string id, SiteExtensionInfo requestInfo) { var startTime = DateTime.UtcNow; if (requestInfo == null) { requestInfo = new SiteExtensionInfo(); } SiteExtensionInfo result; try { result = await _manager.InstallExtension(id, requestInfo.Version, requestInfo.FeedUrl); } catch (WebException e) { // This can happen for example if a bad feed URL is passed throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Site extension download failure", e)); } catch (Exception e) { // This can happen for example if the exception package is corrupted throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Site extension install exception. The package might be invalid.", e)); } if (result == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Could not find " + id)); } // TODO: xiaowu, when update to real csm async, should return "Accepted" instead of "OK" var responseMessage = Request.CreateResponse(HttpStatusCode.OK, ArmUtils.AddEnvelopeOnArmRequest <SiteExtensionInfo>(result, Request)); if (result != null && // result not null indicate instalation success, when move to async operation, will relying on provisionState instead result.InstalledDateTime.HasValue && result.InstalledDateTime.Value > startTime && ArmUtils.IsArmRequest(Request)) { // Populate this header if // Request is from ARM // Installation action is performed responseMessage.Headers.Add("X-MS-SITE-OPERATION", Constants.SiteOperationRestart); } return(responseMessage); }
public async Task <HttpResponseMessage> InstallExtension(string id, SiteExtensionInfo requestInfo) { var startTime = DateTime.UtcNow; var tracer = _traceFactory.GetTracer(); if (IsInstallationLockHeldSafeCheck(id)) { tracer.Trace("{0} is installing with another request, reject current request with Conflict status.", id); throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, id)); } if (requestInfo == null) { requestInfo = new SiteExtensionInfo(); } tracer.Trace("Installing {0}, version: {1} from feed: {2}", id, requestInfo.Version, requestInfo.FeedUrl); SiteExtensionInfo result = await InitInstallSiteExtension(id, requestInfo.Type); if (ArmUtils.IsArmRequest(Request)) { // create a context free tracer ITracer backgroundTracer = NullTracer.Instance; IDictionary <string, string> traceAttributes = new Dictionary <string, string>(); if (tracer.TraceLevel == TraceLevel.Off) { backgroundTracer = NullTracer.Instance; } if (tracer.TraceLevel > TraceLevel.Off) { backgroundTracer = new XmlTracer(_environment.TracePath, tracer.TraceLevel); traceAttributes = new Dictionary <string, string>() { { "url", Request.RequestUri.AbsolutePath }, { "method", Request.Method.Method } }; foreach (var item in Request.Headers) { if (!traceAttributes.ContainsKey(item.Key)) { traceAttributes.Add(item.Key, string.Join(",", item.Value)); } } } AutoResetEvent installationSignal = new AutoResetEvent(false); // trigger installation, but do not wait. Expecting poll for status ThreadPool.QueueUserWorkItem((object stateInfo) => { using (backgroundTracer.Step(XmlTracer.BackgroundTrace, attributes: traceAttributes)) { try { using (backgroundTracer.Step("Background thread started for {0} installation", id)) { _manager.InstallExtension(id, requestInfo.Version, requestInfo.FeedUrl, requestInfo.Type, backgroundTracer).Wait(); } } finally { installationSignal.Set(); // will be a few millionseconds off if task finshed within 15 seconds. LogEndEvent(id, (DateTime.UtcNow - startTime), backgroundTracer); } } }); SiteExtensionStatus armSettings = new SiteExtensionStatus(_environment.SiteExtensionSettingsPath, id, tracer); if (installationSignal.WaitOne(TimeSpan.FromSeconds(15))) { if (!armSettings.IsRestartRequired(_siteExtensionRoot)) { // only skip polling if current installation doesn`t require restart, to avoid making race condition common // TODO: re-visit if we want to skip polling for case that need to restart tracer.Trace("Installation finish quick and not require restart, skip async polling, invoking GET to return actual status to caller."); return(await GetLocalExtension(id)); } } // do not log end event here, since it is not done yet return(Request.CreateResponse(HttpStatusCode.Created, ArmUtils.AddEnvelopeOnArmRequest <SiteExtensionInfo>(result, Request))); } else { result = await _manager.InstallExtension(id, requestInfo.Version, requestInfo.FeedUrl, requestInfo.Type, tracer); if (string.Equals(Constants.SiteExtensionProvisioningStateFailed, result.ProvisioningState, StringComparison.OrdinalIgnoreCase)) { SiteExtensionStatus armSettings = new SiteExtensionStatus(_environment.SiteExtensionSettingsPath, id, tracer); throw new HttpResponseException(Request.CreateErrorResponse(armSettings.Status, result.Comment)); } var response = Request.CreateResponse(HttpStatusCode.OK, result); LogEndEvent(id, (DateTime.UtcNow - startTime), tracer); return(response); } }
public async Task <SiteExtensionInfo> InstallExtension(SiteExtensionInfo info) { return(await _manager.InstallExtension(info)); }