Skip to content

Commit

Permalink
Consistent names in user interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed May 11, 2020
1 parent dcf3a63 commit a7c0f67
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1063,10 +1063,10 @@ public void tooling_supports_replicate_process_from_remote_host()
using (var replicaHost = replicaSetup.StartWebHost())
{
elm_fullstack.Program.replicateProcess(
destinationAdminInterface: replicaAdminInterfaceUrl,
destinationAdminRootPassword: replicaAdminPassword,
sourceAdminInterface: testSetup.AdminWebHostUrl,
sourceAdminRootPassword: originalHostAdminPassword);
site: replicaAdminInterfaceUrl,
sitePassword: replicaAdminPassword,
sourceSite: testSetup.AdminWebHostUrl,
sourceSitePassword: originalHostAdminPassword);
}
}
}
Expand Down
83 changes: 43 additions & 40 deletions implement/elm-fullstack/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,40 +151,47 @@ CommandOption verboseLogOptionFromCommand(CommandLineApplication command) =>
*/

deployAppConfig(
adminInterface: "http://localhost:" + adminInterfaceHttpPort,
adminRootPassword: adminRootPasswordOption.Value(),
site: "http://localhost:" + adminInterfaceHttpPort,
sitePassword: adminRootPasswordOption.Value(),
initElmAppState: deletePreviousBackendStateOption.HasValue() && !replicateProcessFromOption.HasValue());
}

Microsoft.AspNetCore.Hosting.WebHostExtensions.WaitForShutdown(webHost);
});
});

CommandOption adminInterfaceOptionFromCmd(CommandLineApplication cmd) =>
cmd.Option("--admin-interface", "Address to the admin interface of the server to deploy to.", CommandOptionType.SingleValue).IsRequired();
Func<(string site, string sitePassword)> siteAndSitePasswordOptionsOnCommand(CommandLineApplication cmd)
{
var siteOption = cmd.Option("--site", "Site where to apply the changes. Usually an URL to the admin interface of a server.", CommandOptionType.SingleValue).IsRequired();
var sitePasswordOption = cmd.Option("--site-password", "Password to access the site where to apply the changes.", CommandOptionType.SingleValue);

return () =>
{
var site = siteOption.Value();

CommandOption adminRootPasswordOptionFromCmd(CommandLineApplication cmd) =>
cmd.Option("--admin-root-password", "Password to access the admin interface with the username 'root'.", CommandOptionType.SingleValue);
var sitePassword =
sitePasswordOption.Value() ?? UserSecrets.LoadPasswordForSite(site);

return (site, sitePassword);
};
}

app.Command("deploy-app-config", deployAppConfigCmd =>
{
deployAppConfigCmd.Description = "Deploy an app to a server that was started with the `run-server` command. By default, migrates from the previous Elm app state using the `migrate` function in the Elm app code.";

var adminInterfaceOption = adminInterfaceOptionFromCmd(deployAppConfigCmd);
var adminRootPasswordOption = adminRootPasswordOptionFromCmd(deployAppConfigCmd);
var siteAndPasswordFromCmd = siteAndSitePasswordOptionsOnCommand(deployAppConfigCmd);

var initElmAppStateOption = deployAppConfigCmd.Option("--init-elm-app-state", "Do not attempt to migrate the Elm app state but use the state from the init function. Defaults to false.", CommandOptionType.NoValue);

deployAppConfigCmd.OnExecute(() =>
{
var adminInterface = adminInterfaceOption.Value();

var adminRootPassword =
adminRootPasswordOption.Value() ?? UserSecrets.LoadPasswordForSite(adminInterface);
var (site, sitePassword) = siteAndPasswordFromCmd();

var deployReport =
deployAppConfig(
adminInterface: adminInterface,
adminRootPassword: adminRootPassword,
site: site,
sitePassword: sitePassword,
initElmAppState: initElmAppStateOption.HasValue());

writeReportToFileInReportDirectory(
Expand All @@ -195,20 +202,16 @@ CommandOption adminRootPasswordOptionFromCmd(CommandLineApplication cmd) =>

app.Command("truncate-process-history", truncateProcessHistoryCmd =>
{
var adminInterfaceOption = adminInterfaceOptionFromCmd(truncateProcessHistoryCmd);
var adminRootPasswordOption = adminRootPasswordOptionFromCmd(truncateProcessHistoryCmd);
var siteAndPasswordFromCmd = siteAndSitePasswordOptionsOnCommand(truncateProcessHistoryCmd);

truncateProcessHistoryCmd.OnExecute(() =>
{
var adminInterface = adminInterfaceOption.Value();

var adminRootPassword =
adminRootPasswordOption.Value() ?? UserSecrets.LoadPasswordForSite(adminInterface);
var (site, sitePassword) = siteAndPasswordFromCmd();

var report =
truncateProcessHistory(
adminInterface: adminInterface,
adminRootPassword: adminRootPassword);
site: site,
sitePassword: sitePassword);

writeReportToFileInReportDirectory(
reportContent: Newtonsoft.Json.JsonConvert.SerializeObject(report, Newtonsoft.Json.Formatting.Indented),
Expand Down Expand Up @@ -267,7 +270,7 @@ public class ResponseFromServerStruct
}
}

static DeployAppConfigReport deployAppConfig(string adminInterface, string adminRootPassword, bool initElmAppState)
static DeployAppConfigReport deployAppConfig(string site, string sitePassword, bool initElmAppState)
{
var beginTime = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH-mm-ss");

Expand Down Expand Up @@ -301,10 +304,10 @@ static DeployAppConfigReport deployAppConfig(string adminInterface, string admin
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(
Kalmit.PersistentProcess.WebHost.Configuration.BasicAuthenticationForAdminRoot(adminRootPassword))));
Kalmit.PersistentProcess.WebHost.Configuration.BasicAuthenticationForAdminRoot(sitePassword))));

var deployAddress =
(adminInterface.TrimEnd('/')) +
(site.TrimEnd('/')) +
(initElmAppState
?
StartupAdminInterface.PathApiDeployAppConfigAndInitElmAppState
Expand Down Expand Up @@ -349,7 +352,7 @@ static DeployAppConfigReport deployAppConfig(string adminInterface, string admin
appConfigSource = "current-directory",
appConfigId = appConfigId,
initElmAppState = initElmAppState,
site = adminInterface,
site = site,
responseFromServer = responseFromServer,
totalTimeSpentMilli = (int)totalStopwatch.ElapsedMilliseconds,
};
Expand All @@ -371,7 +374,7 @@ public class ResponseFromServerStruct
}
}

static TruncateProcessHistoryReport truncateProcessHistory(string adminInterface, string adminRootPassword)
static TruncateProcessHistoryReport truncateProcessHistory(string site, string sitePassword)
{
var totalStopwatch = System.Diagnostics.Stopwatch.StartNew();

Expand All @@ -380,12 +383,12 @@ static TruncateProcessHistoryReport truncateProcessHistory(string adminInterface
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(
Kalmit.PersistentProcess.WebHost.Configuration.BasicAuthenticationForAdminRoot(adminRootPassword))));
Kalmit.PersistentProcess.WebHost.Configuration.BasicAuthenticationForAdminRoot(sitePassword))));

var requestUrl =
adminInterface.TrimEnd('/') + StartupAdminInterface.PathApiTruncateProcessHistory;
site.TrimEnd('/') + StartupAdminInterface.PathApiTruncateProcessHistory;

Console.WriteLine("Beginning to truncate process history at '" + adminInterface + "'...");
Console.WriteLine("Beginning to truncate process history at '" + site + "'...");

var httpResponse = httpClient.PostAsync(requestUrl, null).Result;

Expand All @@ -412,7 +415,7 @@ static TruncateProcessHistoryReport truncateProcessHistory(string adminInterface

return new TruncateProcessHistoryReport
{
site = adminInterface,
site = site,
responseFromServer = responseFromServer,
totalTimeSpentMilli = (int)totalStopwatch.ElapsedMilliseconds,
};
Expand Down Expand Up @@ -455,17 +458,17 @@ static IImmutableDictionary<IImmutableList<string>, IImmutableList<byte>> readFi
}

static public void replicateProcess(
string destinationAdminInterface,
string destinationAdminRootPassword,
string sourceAdminInterface,
string sourceAdminRootPassword)
string site,
string sitePassword,
string sourceSite,
string sourceSitePassword)
{
Console.WriteLine("Begin reading process history from '" + sourceAdminInterface + "' ...");
Console.WriteLine("Begin reading process history from '" + sourceSite + "' ...");

var processHistoryfilesFromRemoteHost =
readFilesForRestoreProcessFromAdminInterface(sourceAdminInterface, sourceAdminRootPassword);
readFilesForRestoreProcessFromAdminInterface(sourceSite, sourceSitePassword);

Console.WriteLine("Completed reading part of process history for restore. Read " + processHistoryfilesFromRemoteHost.Count + " files from " + sourceAdminInterface + " during restore.");
Console.WriteLine("Completed reading part of process history for restore. Read " + processHistoryfilesFromRemoteHost.Count + " files from " + sourceSite + " during restore.");

var processHistoryTree =
Composition.TreeFromSetOfBlobsWithStringPath(processHistoryfilesFromRemoteHost);
Expand All @@ -480,10 +483,10 @@ static public void replicateProcess(
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(
Kalmit.PersistentProcess.WebHost.Configuration.BasicAuthenticationForAdminRoot(destinationAdminRootPassword))));
Kalmit.PersistentProcess.WebHost.Configuration.BasicAuthenticationForAdminRoot(sitePassword))));

var deployAddress =
destinationAdminInterface.TrimEnd('/') +
site.TrimEnd('/') +
Kalmit.PersistentProcess.WebHost.StartupAdminInterface.PathApiReplaceProcessHistory;

Console.WriteLine("Beginning to place process history '" + processHistoryComponentHashBase16 + "' at '" + deployAddress + "'...");
Expand Down

0 comments on commit a7c0f67

Please sign in to comment.