PageRenderTime 24ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/_Sandbox/WordpressAzure/AdminWebSite/Controllers/AdminController.cs

#
C# | 749 lines | 612 code | 60 blank | 77 comment | 70 complexity | 3e8d748913bad8103b41e819ca12ce05 MD5 | raw file
Possible License(s): LGPL-2.1, CC-BY-SA-3.0, BSD-3-Clause, GPL-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Microsoft.WindowsAzure;
  7. using Microsoft.WindowsAzure.ServiceRuntime;
  8. using System.Diagnostics;
  9. using WindowsAzureCompanion.AdminWebSite.Models;
  10. using WindowsAzureCompanion.VMManagerService;
  11. using System.IO;
  12. using System.Drawing;
  13. using System.Collections.Specialized;
  14. using System.Data.Services.Client;
  15. namespace WindowsAzureCompanion.AdminWebSite.Controllers
  16. {
  17. public class AdminController : BaseController
  18. {
  19. public AdminController()
  20. {
  21. ViewData["CurrentTab"] = "Admin";
  22. }
  23. //
  24. // GET: /Admin/
  25. [Authorize]
  26. public ActionResult Admin()
  27. {
  28. // Check for error message
  29. string errorMessage = ViewData["ErrorMessage"] as string;
  30. if (!string.IsNullOrEmpty(errorMessage))
  31. {
  32. return RedirectToAction("Error", "Home", new { ErrorMessage = errorMessage });
  33. }
  34. if (Request.QueryString["Subtab"] == null)
  35. {
  36. ViewData["Subtab"] = "WindowsAzureLogs";
  37. }
  38. else
  39. {
  40. ViewData["Subtab"] = Request.QueryString["Subtab"];
  41. }
  42. try
  43. {
  44. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  45. if (ViewData["Subtab"].ToString().Equals("WindowsAzureLogs"))
  46. {
  47. try
  48. {
  49. CloudStorageAccount storageAccount = WindowsAzureVMManager.GetStorageAccount(true);
  50. WindowsAzureLogDataServiceContext context = new WindowsAzureLogDataServiceContext(
  51. storageAccount.TableEndpoint.ToString(), storageAccount.Credentials);
  52. ViewData["WindowsAzureLogs"] = context.WindowsAzureLogs;
  53. }
  54. catch (Exception ex)
  55. {
  56. Trace.TraceError("Unable to create storage credetials and account: {0}", ex.Message);
  57. return RedirectToAction("Error", "Home", new { ErrorMessage = "Unable to create storage credetials and account." });
  58. }
  59. }
  60. else if (ViewData["Subtab"].ToString().Equals("PHPLogs"))
  61. {
  62. try
  63. {
  64. // Set php log file name
  65. ViewData["PHPLogFileName"] = vmManager.GetPHPLogFileName();
  66. }
  67. catch (Exception ex)
  68. {
  69. Trace.TraceError("Unable to get PHP log file: {0}", ex.Message);
  70. return RedirectToAction("Error", "Home", new { ErrorMessage = "Unable to get PHP log file." });
  71. }
  72. }
  73. else if (ViewData["Subtab"].ToString().Equals("PerformanceMonitor"))
  74. {
  75. try
  76. {
  77. CloudStorageAccount storageAccount = WindowsAzureVMManager.GetStorageAccount(true);
  78. WindowsAzurePerformanceCounterDataServiceContext context = new WindowsAzurePerformanceCounterDataServiceContext(
  79. storageAccount.TableEndpoint.ToString(), storageAccount.Credentials);
  80. // TODO: Currently used while loop, need to use LINQ
  81. long cpuUsageCount = 0;
  82. double maxCPUUsage = Double.NaN;
  83. double minCPUUsage = Double.NaN;
  84. double cpuUsageSum = 0;
  85. long availableMemoryCount = 0;
  86. double maxAvailableMemory = Double.NaN;
  87. double minAvailableMemory = Double.NaN;
  88. double availableMemorySum = 0;
  89. foreach (WindowsAzurePerformanceCounter counter in context.WindowsAzurePerformanceCounters)
  90. {
  91. if (counter.CounterName.Equals(@"\Processor(_Total)\% Processor Time"))
  92. {
  93. if ((maxCPUUsage.Equals(Double.NaN)) || (counter.CounterValue > maxCPUUsage))
  94. {
  95. maxCPUUsage = counter.CounterValue;
  96. }
  97. if ((minCPUUsage.Equals(Double.NaN)) || (counter.CounterValue < minCPUUsage))
  98. {
  99. minCPUUsage = counter.CounterValue;
  100. }
  101. cpuUsageSum += counter.CounterValue;
  102. cpuUsageCount++;
  103. }
  104. else if (counter.CounterName.Equals(@"\Memory\Available Mbytes"))
  105. {
  106. if ((maxAvailableMemory.Equals(Double.NaN)) || (counter.CounterValue > maxAvailableMemory))
  107. {
  108. maxAvailableMemory = counter.CounterValue;
  109. }
  110. if ((minAvailableMemory.Equals(Double.NaN)) || (counter.CounterValue < minAvailableMemory))
  111. {
  112. minAvailableMemory = counter.CounterValue;
  113. }
  114. availableMemorySum += counter.CounterValue;
  115. availableMemoryCount++;
  116. }
  117. }
  118. if ((cpuUsageCount != 0) && (availableMemoryCount != 0))
  119. {
  120. double avgCpuUsage = Math.Round(cpuUsageSum / cpuUsageCount, 2);
  121. double avgAvailableMemory = Math.Round(availableMemorySum / availableMemoryCount, 2);
  122. ViewData["CPUUsageCount"] = cpuUsageCount.ToString();
  123. ViewData["AvailableMemoryCount"] = availableMemoryCount.ToString();
  124. ViewData["MaxCPUUsage"] = Math.Round(maxCPUUsage, 2).ToString();
  125. ViewData["MaxAvailableMemory"] = Math.Round(maxAvailableMemory, 2).ToString();
  126. ViewData["MinCPUUsage"] = Math.Round(minCPUUsage, 2).ToString();
  127. ViewData["MinAvailableMemory"] = Math.Round(minAvailableMemory, 2).ToString();
  128. ViewData["AvgCPUUsage"] = avgCpuUsage.ToString();
  129. ViewData["AvgAvailableMemory"] = avgAvailableMemory.ToString();
  130. ViewData["DiagnosticsAndPerformanceCounterCaptureFrequencyInMinutes"] =
  131. RoleEnvironment.GetConfigurationSettingValue("DiagnosticsAndPerformanceCounterCaptureFrequencyInMinutes");
  132. }
  133. }
  134. catch (DataServiceQueryException ex)
  135. {
  136. Trace.TraceError("Error fetching Performance. Error: {0}", ex.Message);
  137. Trace.TraceInformation("Performance Counters not yet available.");
  138. }
  139. catch (Exception ex)
  140. {
  141. Trace.TraceError("Unable to create storage credetials and account: {0}", ex.Message);
  142. return RedirectToAction("Error", "Home", new { ErrorMessage = "Unable to create storage credetials and account." });
  143. }
  144. }
  145. else if (ViewData["Subtab"].ToString().Equals("ConfigureRuntime"))
  146. {
  147. // Set MySQL based server status
  148. string isMySQLBasedDBInstalled = vmManager.IsMySQLServerInstalled().ToString();
  149. ViewData["IsMySQLBasedDBInstalled"] = isMySQLBasedDBInstalled;
  150. if (isMySQLBasedDBInstalled.ToLower().Equals("true"))
  151. {
  152. ViewData["MySQLBasedDBName"] = vmManager.GetMySQLBasedDBName().ToString();
  153. ViewData["IsMySQLBasedDBStarted"] = vmManager.IsMySQLServerStarted().ToString();
  154. ViewData["MySQLBasedDBServerPortNumber"] = vmManager.GetMySQLBasedDBServerPortNumber();
  155. ViewData["MySQLBasedDBServerIPAddress"] = vmManager.GetMySQLBasedDBServerIPAddress();
  156. }
  157. // Set php.ini file name
  158. ViewData["PHPIniFileName"] = vmManager.GetPHPIniFileName();
  159. // Set PHP Web Site status
  160. if (vmManager.IsPHPWebSiteStarted())
  161. {
  162. ViewData["PHPWebSiteStatus"] = "Started";
  163. }
  164. else
  165. {
  166. ViewData["PHPWebSiteStatus"] = "Stopped";
  167. }
  168. // Set php log file name
  169. ViewData["PHPLogFileName"] = vmManager.GetPHPLogFileName();
  170. }
  171. else if (ViewData["Subtab"].ToString().Equals("CronJobs"))
  172. {
  173. try
  174. {
  175. // Set php cron jobs
  176. ViewData["CronJobs"] = vmManager.GetCronJobs();
  177. }
  178. catch (Exception ex)
  179. {
  180. Trace.TraceError("Unable to get PHP Cron Jobs: {0}", ex.Message);
  181. return RedirectToAction("Error", "Home", new { ErrorMessage = "Unable to get PHP Cron Jobs." });
  182. }
  183. }
  184. else if (ViewData["Subtab"].ToString().Equals("BackupAndCleanup"))
  185. {
  186. string message = Request.QueryString["Message"];
  187. if (!string.IsNullOrEmpty(message))
  188. {
  189. ViewData["Message"] = message;
  190. }
  191. string resetWindowsAzureDrive = Request.QueryString["ResetWindowsAzureDrive"];
  192. if (!string.IsNullOrEmpty(resetWindowsAzureDrive))
  193. {
  194. ViewData["ResetWindowsAzureDrive"] = resetWindowsAzureDrive;
  195. }
  196. // Get list of Windows Azure Drive Snapshots
  197. try
  198. {
  199. List<string> snapshotUris = vmManager.GetWindowsAzureDriveSnapshots();
  200. ViewData["WindowsAzureDriveSnapshots"] = snapshotUris;
  201. }
  202. catch (Exception ex)
  203. {
  204. Trace.TraceError("Unable to list Windows Azure Drive Snapshots: {0}", ex.Message);
  205. return RedirectToAction("Error", "Home", new { ErrorMessage = "Unable to list Windows Azure Drive Snapshots." });
  206. }
  207. }
  208. else if (ViewData["Subtab"].ToString().Equals("ProgressInformation"))
  209. {
  210. // Get progress information of current activity
  211. IDictionary<string, string> progressInformation = vmManager.GetProgressInformation();
  212. if (progressInformation == null || progressInformation.Count == 0)
  213. {
  214. // No progress information, redirect to caller if possible
  215. string actionName = Request.QueryString["ActionName"];
  216. string controllerName = Request.QueryString["ControllerName"];
  217. string actionSubtabName = Request.QueryString["ActionSubtabName"];
  218. string currentTab = Request.QueryString["CurrentTab"];
  219. if ((actionName != null) && (controllerName != null) && (actionSubtabName != null))
  220. {
  221. return RedirectToAction(
  222. actionName,
  223. controllerName,
  224. new
  225. {
  226. Subtab = actionSubtabName,
  227. CurrentTab = currentTab
  228. });
  229. }
  230. else
  231. {
  232. return RedirectToAction("Error", "Home", new { ErrorMessage = "No progress information available." });
  233. }
  234. }
  235. else
  236. {
  237. // Get first entry as title and remove it
  238. string titleKey = progressInformation.Keys.First();
  239. string[] messageInfo = progressInformation[titleKey].Split('|');
  240. string progressInformationTitle = messageInfo[1];
  241. progressInformation.Remove(titleKey);
  242. ViewData["ProgressInformation"] = progressInformation;
  243. ViewData["ProgressInformationTitle"] = progressInformationTitle;
  244. // Check if last message is an error
  245. if (progressInformation.Count > 0)
  246. {
  247. string lastKey = progressInformation.Keys.Last();
  248. messageInfo = progressInformation[lastKey].Split('|');
  249. if (messageInfo[2].ToLower().Equals("true"))
  250. {
  251. // Error found indicating async operation failed, do not refresh page
  252. ViewData["ErrorMessage"] = messageInfo[1];
  253. }
  254. else
  255. {
  256. // No error, refresh the page after 5 second
  257. Response.AppendHeader("Refresh", "5; URL=" + Request.Url.PathAndQuery);
  258. }
  259. }
  260. else
  261. {
  262. // No progress info yet, refresh the page after 5 second
  263. Response.AppendHeader("Refresh", "5; URL=" + Request.Url.PathAndQuery);
  264. }
  265. }
  266. }
  267. else if (ViewData["Subtab"].ToString().Equals("ManageInstances"))
  268. {
  269. // TODO for v2
  270. }
  271. }
  272. catch (Exception ex)
  273. {
  274. Trace.TraceError("Unknown error: {0}", ex.Message);
  275. return RedirectToAction("Error", "Home", new { ErrorMessage = string.Format("Unknown error: {0}", ex.Message) });
  276. }
  277. return View();
  278. }
  279. // GET: /Admin/WindowsAzureLogs
  280. [Authorize]
  281. public ActionResult WindowsAzureLogs()
  282. {
  283. return RedirectToAction("Admin", "Admin", new { Subtab = "WindowsAzureLogs" });
  284. }
  285. // GET: /Admin/PHPLogs
  286. [Authorize]
  287. public ActionResult PHPLogs()
  288. {
  289. return RedirectToAction("Admin", "Admin", new { Subtab = "PHPLogs" });
  290. }
  291. // GET: /Admin/PerformanceMonitor
  292. [Authorize]
  293. public ActionResult PerformanceMonitor()
  294. {
  295. return RedirectToAction("Admin", "Admin", new { Subtab = "PerformanceMonitor" });
  296. }
  297. // GET: /Admin/ConfigureRuntime
  298. [Authorize]
  299. public ActionResult ConfigureRuntime()
  300. {
  301. return RedirectToAction("Admin", "Admin", new { Subtab = "ConfigureRuntime" });
  302. }
  303. // GET: /Admin/CronJobs
  304. [Authorize]
  305. public ActionResult CronJobs()
  306. {
  307. return RedirectToAction("Admin", "Admin", new { Subtab = "CronJobs" });
  308. }
  309. // GET: /Admin/ConfigureRuntime
  310. [Authorize, ValidateInput(false)]
  311. public ActionResult UpdatePHPRuntime(FormCollection form)
  312. {
  313. // Update php.ini content
  314. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  315. string phpIniFileName = vmManager.GetPHPIniFileName();
  316. if (System.IO.File.Exists(phpIniFileName))
  317. {
  318. // Get new ini file content
  319. string content = form.Get("PHPIniContent");
  320. // Update php.ini file
  321. StreamWriter streamWriter = System.IO.File.CreateText(phpIniFileName);
  322. streamWriter.Write(content);
  323. streamWriter.Close();
  324. // Now restart the PHP web site (required by FastCGI/IIS)
  325. vmManager.RestartPHPWebSite();
  326. }
  327. // Redirect to same ConfigureRuntime subtab
  328. return RedirectToAction("Admin", "Admin", new { Subtab = "ConfigureRuntime" });
  329. }
  330. // GET: /Admin/BackupAndCleanup
  331. [Authorize]
  332. public ActionResult CreateSnapshot(FormCollection form)
  333. {
  334. try
  335. {
  336. // Create Windows Azure Drive Snapshot
  337. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  338. string uristring = vmManager.CreateWindowsAzureDriveSnapshot(form.Get("SnapshotComment"));
  339. if (string.IsNullOrEmpty(uristring))
  340. {
  341. Trace.TraceError("Unable to Create Windows Azure Drive Snapshot.");
  342. return RedirectToAction("Error", "Home", new { ErrorMessage = "Unable to Create Windows Azure Drive Snapshot." });
  343. }
  344. else
  345. {
  346. // Redirect to same BackupAndCleanup subtab
  347. return RedirectToAction("Admin", "Admin",
  348. new {
  349. Subtab = "BackupAndCleanup",
  350. Message = "Created new Windows Azure Drive Snapshot: " + uristring
  351. });
  352. }
  353. }
  354. catch (Exception ex)
  355. {
  356. Trace.TraceError("Unable to create Windows Azure Drive Snapshot: {0}", ex.Message);
  357. return RedirectToAction("Error", "Home", new { ErrorMessage = "Unable to create Windows Azure Drive Snapshot." });
  358. }
  359. }
  360. // GET: /Admin/BackupAndCleanup
  361. [Authorize]
  362. public ActionResult PromoteSnapshot(FormCollection form)
  363. {
  364. try
  365. {
  366. // Promote Windows Azure Drive Snapshot
  367. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  368. bool result = vmManager.PromoteWindowsAzureDriveSnapshot(form.Get("snapshotUri"));
  369. if (!result)
  370. {
  371. Trace.TraceError("Unable to promote Windows Azure Drive Snapshot.");
  372. return RedirectToAction("Error", "Home", new { ErrorMessage = "Unable to promote Windows Azure Drive Snapshot." });
  373. }
  374. else
  375. {
  376. return RedirectToAction(
  377. "ProgressInformation",
  378. "Admin",
  379. new
  380. {
  381. ActionName = "Admin",
  382. ControllerName = "Admin",
  383. ActionSubtabName = "BackupAndCleanup",
  384. CurrentTab = "Admin"
  385. }
  386. );
  387. }
  388. }
  389. catch (Exception ex)
  390. {
  391. Trace.TraceError("Unable to propote Windows Azure Drive Snapshot: {0}", ex.Message);
  392. return RedirectToAction("Error", "Home", new { ErrorMessage = "Unable to create Windows Azure Drive Snapshot." });
  393. }
  394. }
  395. // GET: /Admin/BackupAndCleanup
  396. [Authorize]
  397. public ActionResult DeleteSnapshot(FormCollection form)
  398. {
  399. try
  400. {
  401. // Delete Windows Azure Drive Snapshot
  402. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  403. bool result = vmManager.DeleteWindowsAzureDriveSnapshot(form.Get("snapshotUri"));
  404. if (!result)
  405. {
  406. Trace.TraceError("Unable to delete Windows Azure Drive Snapshot.");
  407. return RedirectToAction("Error", "Home", new { ErrorMessage = "Unable to delete Windows Azure Drive Snapshot." });
  408. }
  409. else
  410. {
  411. // Redirect to same BackupAndCleanup subtab
  412. return RedirectToAction("Admin", "Admin",
  413. new
  414. {
  415. Subtab = "BackupAndCleanup",
  416. Message = "Deleted Windows Azure Drive snapshot " + form.Get("snapshotUri")
  417. });
  418. }
  419. }
  420. catch (Exception ex)
  421. {
  422. Trace.TraceError("Unable to delete Windows Azure Drive Snapshot: {0}", ex.Message);
  423. return RedirectToAction("Error", "Home", new { ErrorMessage = "Unable to delete Windows Azure Drive Snapshot." });
  424. }
  425. }
  426. // GET: /Admin/BackupAndCleanup
  427. [Authorize]
  428. public ActionResult ResetWindowsAzureDrive()
  429. {
  430. // Create Windows Azure Drive Snapshot
  431. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  432. if (vmManager.ResetWindowsAzureDrive())
  433. {
  434. return RedirectToAction(
  435. "ProgressInformation",
  436. "Admin",
  437. new
  438. {
  439. ActionName = "Admin",
  440. ControllerName = "Admin",
  441. ActionSubtabName = "BackupAndCleanup",
  442. CurrentTab = "Admin"
  443. }
  444. );
  445. }
  446. else
  447. {
  448. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to Reset Windows Azure Drive." });
  449. }
  450. }
  451. // GET: /Admin/ConfigureRuntime
  452. [Authorize]
  453. public ActionResult StopPHPRuntime()
  454. {
  455. try
  456. {
  457. // Stop PHP Web Site
  458. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  459. vmManager.StopPHPWebSite();
  460. }
  461. catch (Exception ex)
  462. {
  463. Trace.TraceError("Failed to stop PHP web site. Error: {0}", ex.Message);
  464. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to stop PHP web site." });
  465. }
  466. // Redirect to same ConfigureRuntime page
  467. return RedirectToAction("Admin", "Admin", new { Subtab = "ConfigureRuntime" });
  468. }
  469. // GET: /Admin/ConfigureRuntime
  470. [Authorize]
  471. public ActionResult StartPHPRuntime()
  472. {
  473. try
  474. {
  475. // Start PHP Web Site
  476. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  477. vmManager.StartPHPWebSite();
  478. }
  479. catch (Exception ex)
  480. {
  481. Trace.TraceError("Failed to start PHP web site. Error: {0}", ex.Message);
  482. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to start PHP web site." });
  483. }
  484. // Check is PHP web site startup is requested from applications tab
  485. string actionName = Request.QueryString["ActionName"];
  486. string controllerName = Request.QueryString["ControllerName"];
  487. string actionSubtabName = Request.QueryString["ActionSubtabName"];
  488. string currentTab = Request.QueryString["CurrentTab"];
  489. if ((actionName != null) && (controllerName != null) && (actionSubtabName != null) && (currentTab != null))
  490. {
  491. return RedirectToAction(
  492. actionName,
  493. controllerName,
  494. new
  495. {
  496. Subtab = actionSubtabName,
  497. CurrentTab = currentTab
  498. });
  499. }
  500. else
  501. {
  502. // Redirect to same ConfigureRuntime page
  503. return RedirectToAction("Admin", "Admin", new { Subtab = "ConfigureRuntime" });
  504. }
  505. }
  506. // GET: /Admin/ConfigureRuntime
  507. [Authorize]
  508. public ActionResult RestartPHPRuntime()
  509. {
  510. try
  511. {
  512. // Restart PHP Web Site
  513. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  514. vmManager.RestartPHPWebSite();
  515. }
  516. catch (Exception ex)
  517. {
  518. Trace.TraceError("Failed to restart PHP web site. Error: {0}", ex.Message);
  519. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to restart PHP web site." });
  520. }
  521. // Redirect to same ConfigureRuntime page
  522. return RedirectToAction("Admin", "Admin", new { Subtab = "ConfigureRuntime" });
  523. }
  524. // GET: /Admin/ConfigureRuntime
  525. [Authorize]
  526. public ActionResult StopMySQLServer()
  527. {
  528. try
  529. {
  530. // Stop MySQL Server
  531. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  532. vmManager.StopMySQLServer();
  533. }
  534. catch (Exception ex)
  535. {
  536. Trace.TraceError("Failed to stop MySQL based server. Error: {0}", ex.Message);
  537. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to stop MySQL based server." });
  538. }
  539. // Redirect to same ConfigureRuntime page
  540. return RedirectToAction("Admin", "Admin", new { Subtab = "ConfigureRuntime" });
  541. }
  542. // GET: /Admin/ConfigureRuntime
  543. [Authorize]
  544. public ActionResult StartMySQLServer()
  545. {
  546. try
  547. {
  548. // Start MySQL based server
  549. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  550. vmManager.StartMySQLServer();
  551. }
  552. catch (Exception ex)
  553. {
  554. Trace.TraceError("Failed to start MySQL based server. Error: {0}", ex.Message);
  555. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to start MySQL based server." });
  556. }
  557. // Redirect to same ConfigureRuntime page
  558. return RedirectToAction("Admin", "Admin", new { Subtab = "ConfigureRuntime" });
  559. }
  560. // GET: /Admin/ConfigureRuntime
  561. [Authorize]
  562. public ActionResult RestartMySQLServer()
  563. {
  564. try
  565. {
  566. // Restart MySQL based server
  567. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  568. vmManager.RestartMySQLServer();
  569. }
  570. catch (Exception ex)
  571. {
  572. Trace.TraceError("Failed to restart MySQL based server. Error: {0}", ex.Message);
  573. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to restart MySQL based server." });
  574. }
  575. // Redirect to same ConfigureRuntime page
  576. return RedirectToAction("Admin", "Admin", new { Subtab = "ConfigureRuntime" });
  577. }
  578. /// <summary>
  579. /// Start the Cron Job
  580. /// </summary>
  581. /// <param name="form">The form.</param>
  582. /// <returns></returns>
  583. [AcceptVerbs(HttpVerbs.Post)]
  584. public ActionResult StartCronJob(FormCollection form)
  585. {
  586. try
  587. {
  588. string productId = form.Get("productId");
  589. int cronJobIndex = int.Parse(form.Get("cronJobIndex"));
  590. // Start cron job
  591. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  592. if (!vmManager.StartCronJob(productId, cronJobIndex))
  593. {
  594. Trace.TraceError("Failed to start cron job.");
  595. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to start cron job." });
  596. }
  597. }
  598. catch (Exception ex)
  599. {
  600. Trace.TraceError("Failed to start cron job. Error: {0}", ex.Message);
  601. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to start cron job." });
  602. }
  603. return RedirectToAction("Admin", "Admin", new { Subtab = "CronJobs" });
  604. }
  605. /// <summary>
  606. /// Stop the Cron Job
  607. /// </summary>
  608. /// <param name="form">The form.</param>
  609. /// <returns></returns>
  610. [AcceptVerbs(HttpVerbs.Post)]
  611. public ActionResult StopCronJob(FormCollection form)
  612. {
  613. try
  614. {
  615. string productId = form.Get("productId");
  616. int cronJobIndex = int.Parse(form.Get("cronJobIndex"));
  617. // Stop cron job
  618. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  619. if (!vmManager.StopCronJob(productId, cronJobIndex))
  620. {
  621. Trace.TraceError("Failed to stop cron job.");
  622. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to stop cron job." });
  623. }
  624. }
  625. catch (Exception ex)
  626. {
  627. Trace.TraceError("Failed to stop cron job. Error: {0}", ex.Message);
  628. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to stop cron job." });
  629. }
  630. return RedirectToAction("Admin", "Admin", new { Subtab = "CronJobs" });
  631. }
  632. // GET: /Admin/ProgressInformation
  633. [Authorize]
  634. public ActionResult ClearProgressInformation()
  635. {
  636. try
  637. {
  638. // Clear Progress Information
  639. IVMManager vmManager = WindowsAzureVMManager.GetVMManager();
  640. vmManager.ClearProgressInformation();
  641. return RedirectToAction("Admin", "Admin");
  642. }
  643. catch (Exception ex)
  644. {
  645. Trace.TraceError("Failed to clear profress information. Error: {0}", ex.Message);
  646. return RedirectToAction("Error", "Home", new { ErrorMessage = "Failed to clear progress information." });
  647. }
  648. }
  649. // GET: /Admin/BackupAndCleanup
  650. [Authorize]
  651. public ActionResult BackupAndCleanup()
  652. {
  653. return RedirectToAction("Admin", "Admin", new { Subtab = "BackupAndCleanup" });
  654. }
  655. // GET: /Admin/ManageInstances
  656. [Authorize]
  657. public ActionResult ManageInstances()
  658. {
  659. return RedirectToAction("Admin", "Admin", new { Subtab = "ManageInstances" });
  660. }
  661. // GET: /Admin/ProgressInformation
  662. public ActionResult ProgressInformation()
  663. {
  664. // Passon caller information, if any
  665. string actionName = Request.QueryString["ActionName"];
  666. string controllerName = Request.QueryString["ControllerName"];
  667. string actionSubtabName = Request.QueryString["ActionSubtabName"];
  668. string currentTab = Request.QueryString["CurrentTab"];
  669. if ((actionName != null) && (controllerName != null) && (actionSubtabName != null))
  670. {
  671. return RedirectToAction(
  672. "Admin",
  673. "Admin",
  674. new
  675. {
  676. Subtab = "ProgressInformation",
  677. ActionName = actionName,
  678. ControllerName = controllerName,
  679. ActionSubtabName = actionSubtabName,
  680. CurrentTab = currentTab
  681. });
  682. }
  683. else
  684. {
  685. return RedirectToAction("Admin", "Admin", new { Subtab = "ProgressInformation" });
  686. }
  687. }
  688. }
  689. }