Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -674,4 +674,4 @@
}
]
}
}
}
85 changes: 59 additions & 26 deletions src/commands/hld/reconcile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import * as middleware from "../../lib/traefik/middleware";
import { logger } from "../../logger";
import { BedrockFile, BedrockServiceConfig } from "../../types";
import decorator from "./reconcile.decorator.json";
import { build as buildError, log as logError } from "../../lib/errorBuilder";
import { errorStatusCode } from "../../lib/errorStatusCode";

/**
* IExecResult represents the possible return value of a Promise based wrapper
Expand Down Expand Up @@ -70,8 +72,14 @@ export const execAndLog = async (commandToRun: string): Promise<ExecResult> => {
const pipeOutputToCurrentShell = true;
const result = await exec(commandToRun, pipeOutputToCurrentShell);
if (result.error) {
logger.error(`an error occurred executing command: \`${commandToRun}\``);
throw result.error;
throw buildError(
errorStatusCode.CMD_EXE_ERR,
{
errorKey: "hld-reconcile-err-cmd-failed",
values: [commandToRun],
},
result.error
);
}
return result;
};
Expand Down Expand Up @@ -107,10 +115,14 @@ export const createRepositoryComponent = async (
return execCmd(
`cd ${absHldPath} && mkdir -p ${repositoryName} && fab add ${repositoryName} --path ./${repositoryName} --method local`
).catch((err) => {
logger.error(
`error creating repository component '${repositoryName}' in path '${absHldPath}'`
throw buildError(
errorStatusCode.EXE_FLOW_ERR,
{
errorKey: "hld-reconcile-err-repo-create",
values: [repositoryName, absHldPath],
},
err
);
throw err;
});
};

Expand Down Expand Up @@ -142,8 +154,11 @@ export const configureChartForRing = async (
const fabConfigureCommand = `cd ${normalizedRingPathInHld} && fab set --subcomponent "chart" serviceName="${k8sSvcBackendAndName}"`;

return execCmd(fabConfigureCommand).catch((err) => {
logger.error(`error configuring helm chart for service `);
throw err;
throw buildError(
errorStatusCode.EXE_FLOW_ERR,
"hld-reconcile-err-helm-config",
err
);
});
};

Expand All @@ -160,10 +175,14 @@ export const createServiceComponent = async (
return execCmd(
`cd ${absRepositoryInHldPath} && mkdir -p ${serviceName} config && fab add ${serviceName} --path ./${serviceName} --method local --type component && touch ./config/common.yaml`
).catch((err) => {
logger.error(
`error creating service component '${serviceName}' in path '${absRepositoryInHldPath}'`
throw buildError(
errorStatusCode.EXE_FLOW_ERR,
{
errorKey: "hld-reconcile-err-service-create",
values: [serviceName, absRepositoryInHldPath],
},
err
);
throw err;
});
};

Expand All @@ -177,10 +196,14 @@ export const createRingComponent = async (
const createRingInSvcCommand = `cd ${svcPathInHld} && mkdir -p ${normalizedRingName} config && fab add ${normalizedRingName} --path ./${normalizedRingName} --method local --type component && touch ./config/common.yaml`;

return execCmd(createRingInSvcCommand).catch((err) => {
logger.error(
`error creating ring component '${normalizedRingName}' in path '${svcPathInHld}'`
throw buildError(
errorStatusCode.EXE_FLOW_ERR,
{
errorKey: "hld-reconcile-err-ring-create",
values: [normalizedRingName, svcPathInHld],
},
err
);
throw err;
});
};

Expand Down Expand Up @@ -211,12 +234,14 @@ export const addChartToRing = async (

return execCmd(`cd ${ringPathInHld} && ${addHelmChartCommand}`).catch(
(err) => {
logger.error(
`error adding helm chart for service-config ${JSON.stringify(
serviceConfig
)} to ring path '${ringPathInHld}'`
throw buildError(
errorStatusCode.EXE_FLOW_ERR,
{
errorKey: "hld-reconcile-err-helm-add",
values: [JSON.stringify(serviceConfig), ringPathInHld],
},
err
);
throw err;
}
);
};
Expand All @@ -229,8 +254,14 @@ export const createStaticComponent = async (
const createConfigAndStaticComponentCommand = `cd ${ringPathInHld} && mkdir -p config static && fab add static --path ./static --method local --type static && touch ./config/common.yaml`;

return execCmd(createConfigAndStaticComponentCommand).catch((err) => {
logger.error(`error creating static component in path '${ringPathInHld}'`);
throw err;
throw buildError(
errorStatusCode.EXE_FLOW_ERR,
{
errorKey: "hld-reconcile-err-static-create",
values: [ringPathInHld],
},
err
);
});
};

Expand Down Expand Up @@ -379,9 +410,7 @@ export const validateInputs = (
export const checkForFabrikate = (which: (path: string) => string): void => {
const fabrikateInstalled = which("fab");
if (fabrikateInstalled === "") {
throw ReferenceError(
`Fabrikate not installed. Please fetch and install the latest version: https://github.com/microsoft/fabrikate/releases`
);
throw buildError(errorStatusCode.VALIDATION_ERR, "hld-reconcile-err-fab");
}
};

Expand All @@ -393,7 +422,10 @@ export const testAndGetAbsPath = (
): string => {
const absPath = path.resolve(possiblyRelativePath);
if (!test("-e", absPath) && !test("-d", absPath)) {
throw Error(`Could not validate ${pathType} path.`);
throw buildError(errorStatusCode.VALIDATION_ERR, {
errorKey: "hld-reconcile-err-path",
values: [pathType],
});
}
log(`Found ${pathType} at ${absPath}`);
return absPath;
Expand Down Expand Up @@ -632,8 +664,9 @@ export const execute = async (
);
await exitFn(0);
} catch (err) {
logger.error(`An error occurred while reconciling HLD`);
logger.error(err);
logError(
buildError(errorStatusCode.CMD_EXE_ERR, "hld-reconcile-err-cmd-exe", err)
);
await exitFn(1);
}
};
Expand Down
11 changes: 11 additions & 0 deletions src/lib/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
"hld-init-cmd-failed": "Hld init command was not successfully executed.",
"hld-init-cmd-project-path-missing": "Value for project path was not provided. Provide it.",

"hld-reconcile-err-repo-create": "Error creating repository component '{0}' in path '{1}'.",
"hld-reconcile-err-helm-config": "Error configuring helm chart for service.",
"hld-reconcile-err-service-create": "Error creating service component '{0}' in path '{1}'.",
"hld-reconcile-err-ring-create": "`error creating ring component '{0}' in path '{1}'.",
"hld-reconcile-err-helm-add": "Error adding helm chart for service-config {0} to ring path '{1}'.",
"hld-reconcile-err-static-create": "Error creating static component in path '{0}'.",
"hld-reconcile-err-fab": "Fabrikate not installed. Please fetch and install the latest version: https://github.com/microsoft/fabrikate/releases",
"hld-reconcile-err-path": "Could not validate {0} path.",
"hld-reconcile-err-cmd-failed": "An error occurred executing command: {0}",
"hld-reconcile-err-cmd-exe": "An error occurred while reconciling HLD.",

"infra-scaffold-cmd-failed": "Infra scaffold command was not successfully executed.",
"infra-scaffold-cmd-src-missing": "Value for source is required because it cannot be constructed with properties in spk-config.yaml. Provide value for source.",
"infra-scaffold-cmd-values-missing": "Values for name, version and/or 'template were missing. Provide value for values for them.",
Expand Down