Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaboud committed Jun 7, 2024
1 parent 59e656c commit c24c69c
Show file tree
Hide file tree
Showing 20 changed files with 249 additions and 698 deletions.
8 changes: 8 additions & 0 deletions houston-common-lib/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": true,
"tabWidth": 2,
"singleQuote": false,
"printWidth": 100,
"trailingComma": "es5"
}
3 changes: 2 additions & 1 deletion houston-common-lib/lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export namespace Download {
type: "application/octet-stream",
});
const url = URL.createObjectURL(object);
if (Object.hasOwnProperty.call(window, "chrome")) { // chromium based
if (Object.hasOwnProperty.call(window, "chrome")) {
// chromium based
Download.url(url, filename);
} else {
window.open(url, "filename")?.focus(); // non-chromium based
Expand Down
71 changes: 31 additions & 40 deletions houston-common-lib/lib/houston.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export * from "@/user";
export * from "@/group";
export * from "@/filesystem";

export function getServer(
host: string = "localhost"
): ResultAsync<Server, ProcessError> {
export function getServer(host: string = "localhost"): ResultAsync<Server, ProcessError> {
const server = new Server(host);
return server.isAccessible().map(() => server);
}
Expand All @@ -25,19 +23,17 @@ export namespace _internal {
nodes: { name: string; addrs: { addr: string }[] }[];
};
export const pcsNodesParseAddrs = (commandOutput: string) =>
safeJsonParse<PcsClusterConfigOutput>(commandOutput).andThen(
(clusterConfig) => {
const addrs =
clusterConfig.nodes
?.map((node) => node.addrs[0]?.addr)
.filter((addr): addr is string => addr !== undefined) ?? [];
if (addrs.length === 0) {
console.warn("pcs cluster config output:", clusterConfig);
return err(new ParsingError("no nodes found in output"));
}
return ok(addrs);
safeJsonParse<PcsClusterConfigOutput>(commandOutput).andThen((clusterConfig) => {
const addrs =
clusterConfig.nodes
?.map((node) => node.addrs[0]?.addr)
.filter((addr): addr is string => addr !== undefined) ?? [];
if (addrs.length === 0) {
console.warn("pcs cluster config output:", clusterConfig);
return err(new ParsingError("no nodes found in output"));
}
);
return ok(addrs);
});
}

export function getServerCluster(
Expand All @@ -53,25 +49,23 @@ export function getServerCluster(
const ctdbNodesFile = new File(server, "/etc/ctdb/nodes");
return ctdbNodesFile.exists().andThen((ctdbNodesFileExists) => {
if (ctdbNodesFileExists) {
return ctdbNodesFile
.read({ superuser: "try" })
.andThen((nodesString) =>
ResultAsync.combine(
nodesString
.split(RegexSnippets.newlineSplitter)
.map((n) => n.trim())
.filter((n) => n)
.map((node) => getServer(node))
).map((servers) => {
if (servers.length < 1) {
console.warn(
"getServerCluster('ctdb'): Found /etc/ctdb/nodes file, but contained no hosts. Assuming single-server."
);
return [server] as [Server, ...Server[]];
}
return servers as [Server, ...Server[]];
})
);
return ctdbNodesFile.read({ superuser: "try" }).andThen((nodesString) =>
ResultAsync.combine(
nodesString
.split(RegexSnippets.newlineSplitter)
.map((n) => n.trim())
.filter((n) => n)
.map((node) => getServer(node))
).map((servers) => {
if (servers.length < 1) {
console.warn(
"getServerCluster('ctdb'): Found /etc/ctdb/nodes file, but contained no hosts. Assuming single-server."
);
return [server] as [Server, ...Server[]];
}
return servers as [Server, ...Server[]];
})
);
} else {
console.warn(
"getServerCluster('ctdb'): File not found: /etc/ctdb/nodes. Assuming single-server."
Expand All @@ -84,12 +78,9 @@ export function getServerCluster(
return localServerResult.andThen((localServer) =>
localServer
.execute(
new Command(
["pcs", "cluster", "config", "--output-format", "json"],
{
superuser: "try",
}
)
new Command(["pcs", "cluster", "config", "--output-format", "json"], {
superuser: "try",
})
)
.map((proc) => proc.getStdout())
.andThen(_internal.pcsNodesParseAddrs)
Expand Down
Loading

0 comments on commit c24c69c

Please sign in to comment.