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
30 changes: 22 additions & 8 deletions src/commands/deployment/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { build as buildCmd, exit as exitCmd } from "../../lib/commandBuilder";
import { hasValue } from "../../lib/validator";
import { logger } from "../../logger";
import decorator from "./create.decorator.json";
import { build as buildError, log as logError } from "../../lib/errorBuilder";
import { errorStatusCode } from "../../lib/errorStatusCode";

/**
* Command Line values from the commander
Expand Down Expand Up @@ -51,8 +53,9 @@ export const validateValues = (opts: CommandOptions): CreateConfig => {
!hasValue(opts.partitionKey) ||
!hasValue(opts.tableName)
) {
throw new Error(
"Access key, storage account name, partition key and/or table name are not provided"
throw buildError(
errorStatusCode.VALIDATION_ERR,
"introspect-create-cmd-missing-values"
);
}

Expand All @@ -74,8 +77,9 @@ export const handlePipeline1 = async (
!hasValue(opts.commitId) ||
!hasValue(opts.service)
) {
throw new Error(
"For updating the details of source pipeline, you must specify --image-tag, --commit-id and --service"
throw buildError(
errorStatusCode.VALIDATION_ERR,
"introspect-create-cmd-cmd-p1-missing-values"
);
}
await addSrcToACRPipeline(
Expand All @@ -98,8 +102,9 @@ export const handlePipeline2 = async (
!hasValue(opts.env) ||
!hasValue(opts.imageTag)
) {
throw new Error(
"For updating the details of image tag release pipeline, you must specify --p2, --hld-commit-id, --image-tag and --env"
throw buildError(
errorStatusCode.VALIDATION_ERR,
"introspect-create-cmd-cmd-p2-missing-values"
);
}
await updateACRToHLDPipeline(
Expand Down Expand Up @@ -155,11 +160,20 @@ export const execute = async (
opts.repository
);
} else {
throw new Error("No action could be performed for specified arguments.");
throw buildError(
errorStatusCode.VALIDATION_ERR,
"introspect-create-cmd-no-ops"
);
}
await exitFn(0);
} catch (err) {
logger.error(err);
logError(
buildError(
errorStatusCode.CMD_EXE_ERR,
"introspect-create-cmd-failed",
err
)
);
await exitFn(1);
}
};
Expand Down
96 changes: 58 additions & 38 deletions src/lib/azure/deploymenttable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import * as azure from "azure-storage";
import uuid from "uuid/v4";
import { logger } from "../../logger";
import { build as buildError } from "../errorBuilder";
import { errorStatusCode } from "../errorStatusCode";

/**
* Deployment Table interface to hold necessary information about a table for deployments
*/
Expand Down Expand Up @@ -400,30 +403,38 @@ export const updateHLDToManifestPipeline = async (
pr?: string,
repository?: string
): Promise<RowHLDToManifestPipeline> => {
let entries = await findMatchingDeployments<EntryHLDToManifestPipeline>(
tableInfo,
"hldCommitId",
hldCommitId
);
try {
let entries = await findMatchingDeployments<EntryHLDToManifestPipeline>(
tableInfo,
"hldCommitId",
hldCommitId
);

// cannot find entries by hldCommitId.
// attempt to find entries by pr
if ((!entries || entries.length === 0) && pr) {
entries = await findMatchingDeployments<EntryHLDToManifestPipeline>(
// cannot find entries by hldCommitId.
// attempt to find entries by pr
if ((!entries || entries.length === 0) && pr) {
entries = await findMatchingDeployments<EntryHLDToManifestPipeline>(
tableInfo,
"pr",
pr
);
}
return updateHLDtoManifestHelper(
entries,
tableInfo,
"pr",
pr
hldCommitId,
pipelineId,
manifestCommitId,
pr,
repository
);
} catch (err) {
throw buildError(
errorStatusCode.AZURE_STORAGE_OP_ERR,
"deployment-table-update-hld-manifest-pipeline-failed",
err
);
}
return updateHLDtoManifestHelper(
entries,
tableInfo,
hldCommitId,
pipelineId,
manifestCommitId,
pr,
repository
);
};

/**
Expand Down Expand Up @@ -664,27 +675,36 @@ export const updateManifestCommitId = async (
manifestCommitId: string,
repository?: string
): Promise<RowManifest> => {
const entries = await findMatchingDeployments<RowManifest>(
tableInfo,
"p3",
pipelineId
);
// Ideally there should only be one entry for every pipeline id
if (entries.length > 0) {
const entry = entries[0];
entry.manifestCommitId = manifestCommitId;
if (repository) {
entry.manifestRepo = repository.toLowerCase();
try {
const entries = await findMatchingDeployments<RowManifest>(
tableInfo,
"p3",
pipelineId
);
// Ideally there should only be one entry for every pipeline id
if (entries.length > 0) {
const entry = entries[0];
entry.manifestCommitId = manifestCommitId;
if (repository) {
entry.manifestRepo = repository.toLowerCase();
}
await updateEntryInTable(tableInfo, entry);
logger.info(
`Update manifest commit Id ${manifestCommitId} for pipeline Id ${pipelineId}`
);
return entry;
}
await updateEntryInTable(tableInfo, entry);
logger.info(
`Update manifest commit Id ${manifestCommitId} for pipeline Id ${pipelineId}`
} catch (err) {
throw buildError(
errorStatusCode.AZURE_STORAGE_OP_ERR,
"deployment-table-update-manifest-commit-id-failed",
err
);
return entry;
}
throw new Error(
`No manifest generation found to update manifest commit ${manifestCommitId}`
);
throw buildError(errorStatusCode.AZURE_STORAGE_OP_ERR, {
errorKey: "deployment-table-update-manifest-commit-id-failed-no-generation",
values: [manifestCommitId],
});
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/lib/errorStatusCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export enum errorStatusCode {
FILE_IO_ERR = 1011,
INCORRECT_DEFINITION = 1012,
GIT_OPS_ERR = 1100,
AZURE_STORAGE_OP_ERR = 2000,
}
18 changes: 14 additions & 4 deletions src/lib/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"storageKeVaultName": "Enter key vault name (have the value as empty and hit enter key to skip)"
},
"errors": {
"infra-scaffold-cmd-failed": "Infra scaffold Command was not successfully executed.",
"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.",

"infra-generate-cmd-failed": "Infra generate Command was not successfully executed.",
"infra-generate-cmd-failed": "Infra generate command was not successfully executed.",

"infra-defn-yaml-not-found": "{0} was not found in {1}",
"infra-defn-yaml-invalid": "The {0} file is invalid. There are missing fields. template: {1} source: {2} version: {3}.",
Expand All @@ -34,9 +34,19 @@
"infra-err-git-clone-failed": "Could not clone the source remote repository. The remote repo might not exist or you did not have the rights to access it",
"infra-git-source-no-exist": "Source path, {0} did not exist.",

"hld-append-var-group-cmd-failed": "HLD Append Variable Group Command was not successfully executed.",
"hld-append-var-group-cmd-failed": "HLD Append Variable Group command was not successfully executed.",
"hld-append-var-group-name-missing": "Variable group name was not provided. Provide variable group.",

"fileutils-append-variable-group-to-pipeline-yaml": "Could not append variable group name to manifest-generation.yaml file in HLD repo. Check this is file exist and if it is YAML format."
"fileutils-append-variable-group-to-pipeline-yaml": "Could not append variable group name to manifest-generation.yaml file in HLD repo. Check this is file exist and if it is YAML format.",

"introspect-create-cmd-failed": "Deployment create command was not successfully executed.",
"introspect-create-cmd-no-ops": "No action could be performed for specified arguments.",
"introspect-create-cmd-missing-values": "Access key, storage account name, partition key and/or table name were not provided. Provide them.",
"introspect-create-cmd-cmd-p1-missing-values": "Values for image-tag, commit-id and service options were missing. They are required for updating the details of source pipeline. Provide them.",
"introspect-create-cmd-cmd-p2-missing-values": "Values for p2, hld-commit-id, image-tag and env options were missing. They are required For updating the details of image tag release pipeline. Provide them.",

"deployment-table-update-hld-manifest-pipeline-failed": "Could not update HLD to manifest pipeline.",
"deployment-table-update-manifest-commit-id-failed": "Could not update manifest commit Id.",
"deployment-table-update-manifest-commit-id-failed-no-generation": "No manifest generation found to update manifest commit {0}."
}
}