Skip to content

Commit

Permalink
chore: add importId deploy status and timestamps to the ask states co…
Browse files Browse the repository at this point in the history
…nfig file
  • Loading branch information
Mario Doiron committed Nov 21, 2023
1 parent 56dd1fb commit 64f5639
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/commands/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export default class DeployCommand extends AbstractCommand {
try {
profile = profileHelper.runtimeProfile(cmd.profile);
new ResourcesConfig(path.join(process.cwd(), CONSTANTS.FILE_PATH.ASK_RESOURCES_JSON_CONFIG));
ResourcesConfig.getInstance().setDeploymentStatus(profile, "IN_PROGRESS");
ResourcesConfig.getInstance().write();
Messenger.getInstance().info(`Deploy configuration loaded from ${CONSTANTS.FILE_PATH.ASK_RESOURCES_JSON_CONFIG}`);
helper.confirmProfile(profile);
this._filterAlexaHostedSkill(profile);
Expand Down Expand Up @@ -80,7 +82,7 @@ export default class DeployCommand extends AbstractCommand {

// Save the deployment type to ask states
ResourcesConfig.getInstance().setSkillMetaLastDeployType(profile, deploymentType);

ResourcesConfig.getInstance().setDeploymentStatus(profile, "COMPLETE");
// Write updates back to resources file
ResourcesConfig.getInstance().write();
Manifest.getInstance().write();
Expand All @@ -105,6 +107,9 @@ export default class DeployCommand extends AbstractCommand {
});
})
.catch((err) => {
ResourcesConfig.getInstance().setDeploymentStatus(profile, "COMPLETE");
// Write updates back to resources file
ResourcesConfig.getInstance().write();
Messenger.getInstance().error(err);
return reject(err);
});
Expand Down
7 changes: 5 additions & 2 deletions lib/controllers/skill-infrastructure-controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module.exports = class SkillInfrastructureController {
if (error) {
// update partial successful deploy results to resources config
if (result && !R.isEmpty(R.keys(result))) {
this._updateResourcesConfig(regionsList, result);
this._updateResourcesConfig(regionsList, result, error);
}
return callback(error);
}
Expand Down Expand Up @@ -296,7 +296,7 @@ module.exports = class SkillInfrastructureController {
*
* @param {Object} rawDeployResult deploy result from invoke: { $region: deploy-delegate's response }
*/
_updateResourcesConfig(regionsList, rawDeployResult) {
_updateResourcesConfig(regionsList, rawDeployResult, error) {
const curDeployState = ResourcesConfig.getInstance().getSkillInfraDeployState(this.profile) || {};
const newDeployState = {};
regionsList.forEach((alexaRegion) => {
Expand All @@ -307,6 +307,9 @@ module.exports = class SkillInfrastructureController {
}
});
ResourcesConfig.getInstance().setSkillInfraDeployState(this.profile, newDeployState);
if (!error) {
ResourcesConfig.getInstance().setCodeLastDeployTimestamp(this.profile, `${(new Date()).toISOString()}`);
}
ResourcesConfig.getInstance().write();
}

Expand Down
3 changes: 3 additions & 0 deletions lib/controllers/skill-metadata-controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ module.exports = class SkillMetadataController {
const importId = path.basename(importResponse.headers.location);
if (importId) {
this.getImportStatusPollView().displayImportId(importId);
ResourcesConfig.getInstance().setLastImportId(this.profile, importId);
ResourcesConfig.getInstance().setLastImportTimestamp(this.profile, `${(new Date()).toISOString()}`);
ResourcesConfig.getInstance().write();
}
// 3.poll for the skill package import status
this._pollImportStatus(importId, (pollErr, pollResponse) => {
Expand Down
32 changes: 32 additions & 0 deletions lib/model/resources-config/ask-states.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ module.exports = class AskStates extends ConfigFile {
this.setProperty(["profiles", profile, "skillId"], skillId);
}

getDeploymentStatus(profile) {
return this.getProperty(["profiles", profile, "deploymentStatus"]);
}

setDeploymentStatus(profile, status) {
this.setProperty(["profiles", profile, "deploymentStatus"], status);
}

getLastImportId(profile) {
return this.getProperty(["profiles", profile, "skillMetadata", "lastImportId"]);
}

setLastImportId(profile, lastImportId) {
this.setProperty(["profiles", profile, "skillMetadata", "lastImportId"], lastImportId);
}

getLastImportTimestamp(profile) {
return this.getProperty(["profiles", profile, "skillMetadata", "lastImportTimestamp"]);
}

setLastImportTimestamp(profile, dateTimeStamp) {
this.setProperty(["profiles", profile, "skillMetadata", "lastImportTimestamp"], dateTimeStamp);
}

// Group for the "skillMetadata"
getSkillMetaLastDeployHash(profile) {
return this.getProperty(["profiles", profile, "skillMetadata", "lastDeployHash"]);
Expand Down Expand Up @@ -92,6 +116,14 @@ module.exports = class AskStates extends ConfigFile {
this.setProperty(["profiles", profile, "code", region, "lastDeployHash"], hash);
}

getCodeLastDeployTimestamp(profile) {
return this.getProperty(["profiles", profile, "code", "lastDeployTimestamp"]);
}

setCodeLastDeployTimestamp(profile, dateTimestamp) {
this.setProperty(["profiles", profile, "code", "lastDeployTimestamp"], dateTimestamp);
}

getCodeBuildByRegion(projRoot, codeSrc) {
if (!codeSrc) {
return null;
Expand Down
32 changes: 32 additions & 0 deletions lib/model/resources-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ module.exports = class ResourcesConfig {
AskStates.getInstance().setSkillId(profile, skillId);
}

getDeploymentStatus(profile) {
return AskStates.getInstance().getDeploymentStatus(profile);
}

setDeploymentStatus(profile, status) {
AskStates.getInstance().setDeploymentStatus(profile, status);
}

getLastImportId(profile) {
return AskStates.getInstance().getLastImportId(profile);
}

setLastImportId(profile, importId) {
AskStates.getInstance().setLastImportId(profile, importId);
}

getLastImportTimestamp(profile) {
return AskStates.getInstance().getLastImportTimestamp(profile);
}

setLastImportTimestamp(profile, dateTimestamp) {
AskStates.getInstance().setLastImportTimestamp(profile, dateTimestamp);
}

// Group for the "skillMetadata"
getSkillMetaSrc(profile) {
return AskResources.getInstance().getSkillMetaSrc(profile);
Expand Down Expand Up @@ -123,6 +147,14 @@ module.exports = class ResourcesConfig {
AskStates.getInstance().setCodeLastDeployHashByRegion(profile, region, hash);
}

getCodeLastDeployTimestamp(profile) {
return AskStates.getInstance().getCodeLastDeployTimestamp(profile);
}

setCodeLastDeployTimestamp(profile, dateTimestamp) {
AskStates.getInstance().setCodeLastDeployTimestamp(profile, dateTimestamp);
}

getCodeRegions(profile) {
return AskResources.getInstance().getCodeRegions(profile);
}
Expand Down
1 change: 1 addition & 0 deletions test/unit/controller/skill-metadata-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ describe("Controller test - skill metadata controller test", () => {

beforeEach(() => {
skillMetaController = new SkillMetadataController(TEST_CONFIGURATION);
sinon.stub(ResourcesConfig.prototype, "write").returns("");
});


Expand Down
10 changes: 7 additions & 3 deletions test/unit/fixture/model/regular-proj/.ask/ask-states.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"skillId": "amzn1.ask.skill.1234567890",
"skillMetadata": {
"lastDeployHash": "hash==",
"lastDeployType": "interaction-model"
"lastDeployType": "interaction-model",
"lastImportId": "amzn1.ask-package.import.123abc",
"lastImportTimestamp": "2023-11-21T04:01:31.047Z"
},
"code": {
"default": {
Expand All @@ -16,7 +18,8 @@
},
"NA": {
"lastDeployHash": "hash=="
}
},
"lastDeployTimestamp": "2023-11-21T03:07:07.820Z"
},
"skillInfrastructure": {
"@ask-cli/cfn-deployer": {
Expand Down Expand Up @@ -47,7 +50,8 @@
}
}
}
}
},
"deploymentStatus": "COMPLETE"
}
}
}
24 changes: 24 additions & 0 deletions test/unit/model/resources-config/resources-config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ describe("Model test - resources config test", () => {
newValue: "skillId new",
oldValue: TEST_ASK_STATES.profiles[TEST_PROFILE].skillId,
},
{
field: "LastImportId",
params: [TEST_PROFILE],
newValue: "LastImportId new",
oldValue: TEST_ASK_STATES.profiles[TEST_PROFILE].skillMetadata.lastImportId,
},
{
field: "LastImportTimestamp",
params: [TEST_PROFILE],
newValue: "LastImportTimestamp new",
oldValue: TEST_ASK_STATES.profiles[TEST_PROFILE].skillMetadata.lastImportTimestamp,
},
{
field: "SkillMetaSrc",
params: [TEST_PROFILE],
Expand All @@ -167,6 +179,18 @@ describe("Model test - resources config test", () => {
newValue: "==hash",
oldValue: TEST_ASK_STATES.profiles[TEST_PROFILE].skillMetadata.lastDeployHash,
},
{
field: "CodeLastDeployTimestamp",
params: [TEST_PROFILE],
newValue: "CodeLastDeployTimestamp new",
oldValue: TEST_ASK_STATES.profiles[TEST_PROFILE].code.lastDeployTimestamp,
},
{
field: "DeploymentStatus",
params: [TEST_PROFILE],
newValue: "deploymentStatus new",
oldValue: TEST_ASK_STATES.profiles[TEST_PROFILE].deploymentStatus,
},
].forEach(({field, params, newValue, oldValue}) => {
it(`| test get${field} function successfully`, () => {
expect(ResourcesConfig.getInstance()[`get${field}`](...params)).deep.equal(oldValue);
Expand Down

0 comments on commit 64f5639

Please sign in to comment.