minor cleanup and changed version.imageName to version.deployedImageName, so we can find it easier.

This commit is contained in:
Kasra Bigdeli
2018-12-02 16:18:58 -08:00
parent c8d9d0f3bf
commit ff351aac6c
8 changed files with 41 additions and 64 deletions
+6 -17
View File
@@ -2,7 +2,6 @@
const uuid = require("uuid/v4");
const ApiStatusCodes = require("../api/ApiStatusCodes");
const CaptainConstants = require("../utils/CaptainConstants");
const Logger = require("../utils/Logger");
const isValidPath = require('is-valid-path');
const APP_DEFINITIONS = 'appDefinitions';
function isNameAllowed(name) {
@@ -236,15 +235,18 @@ class AppsDataStore {
if (!appName) {
throw new Error('App Name should not be empty');
}
if (!imageName) {
throw new Error('ImageName Name should not be empty');
}
const self = this;
return this.getAppDefinition(appName).then(function (app) {
return this.getAppDefinition(appName) //
.then(function (app) {
const versions = app.versions;
const newVersionIndex = versions.length;
let found = false;
for (let i = 0; i < versions.length; i++) {
const element = versions[i];
if (element.version === deployedVersion) {
element.imageName = imageName;
element.deployedImageName = imageName;
found = true;
break;
}
@@ -374,19 +376,6 @@ class AppsDataStore {
return self.saveApp(appName, appObj);
});
}
setGitHash(appName, newVersion, gitHashToSave) {
const self = this;
return this.getAppDefinition(appName).then(function (app) {
app.versions = app.versions || [];
for (let i = 0; i < app.versions.length; i++) {
if (app.versions[i].version === newVersion) {
app.versions[i].gitHash = gitHashToSave;
return self.saveApp(appName, app);
}
}
Logger.e('Failed to set the git hash on the deployed version');
});
}
deleteAppDefinition(appName) {
const self = this;
return new Promise(function (resolve, reject) {
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
{"version":3,"file":"AppDefinition.js","sourceRoot":"","sources":["../../src/models/AppDefinition.ts"],"names":[],"mappings":"AAsCA,MAAe,kBAAkB;CA6BhC;AAED,MAAM,OAAQ,SAAQ,kBAAkB;CAQvC;AAED,MAAM,YAAa,SAAQ,kBAAkB;CAQ5C"}
{"version":3,"file":"AppDefinition.js","sourceRoot":"","sources":["../../src/models/AppDefinition.ts"],"names":[],"mappings":"AAsCA,MAAe,kBAAkB;CA4BhC;AAED,MAAM,OAAQ,SAAQ,kBAAkB;CAQvC;AAED,MAAM,YAAa,SAAQ,kBAAkB;CAQ5C"}
+2 -2
View File
@@ -429,12 +429,12 @@ class ServiceManager {
for (let i = 0; i < app.versions.length; i++) {
const element = app.versions[i];
if (element.version == app.deployedVersion) {
imageName = element.imageName;
imageName = element.deployedImageName;
break;
}
}
if (!imageName) {
throw new Error('ImageName for deployed version is not available, this is impossible!');
throw ApiStatusCodes.createError(ApiStatusCodes.ILLEGAL_PARAMETER, 'ImageName for deployed version is not available, this version was probably failed due to an unsuccessful build!');
}
Logger.d(`Creating service ${serviceName} with default image, we will update image later`);
// if we pass in networks here. Almost always it results in a delayed update which causes
File diff suppressed because one or more lines are too long
+24 -36
View File
@@ -338,33 +338,38 @@ class AppsDataStore {
if (!appName) {
throw new Error('App Name should not be empty')
}
if (!imageName) {
throw new Error('ImageName Name should not be empty')
}
const self = this
return this.getAppDefinition(appName).then(function(app) {
const versions = app.versions
const newVersionIndex = versions.length
return this.getAppDefinition(appName) //
.then(function(app) {
const versions = app.versions
let found = false
let found = false
for (let i = 0; i < versions.length; i++) {
const element = versions[i]
if (element.version === deployedVersion) {
element.imageName = imageName
found = true
break
for (let i = 0; i < versions.length; i++) {
const element = versions[i]
if (element.version === deployedVersion) {
element.deployedImageName = imageName
found = true
break
}
}
}
if (!found) {
throw new Error(
`Version trying to deploy not found ${deployedVersion}`
)
}
if (!found) {
throw new Error(
`Version trying to deploy not found ${deployedVersion}`
)
}
app.deployedVersion = deployedVersion
app.deployedVersion = deployedVersion
return self.saveApp(appName, app)
})
return self.saveApp(appName, app)
})
}
createNewVersion(appName: string) {
@@ -520,23 +525,6 @@ class AppsDataStore {
})
}
setGitHash(appName: string, newVersion: number, gitHashToSave: string) {
const self = this
return this.getAppDefinition(appName).then(function(app) {
app.versions = app.versions || []
for (let i = 0; i < app.versions.length; i++) {
if (app.versions[i].version === newVersion) {
app.versions[i].gitHash = gitHashToSave
return self.saveApp(appName, app)
}
}
Logger.e('Failed to set the git hash on the deployed version')
})
}
deleteAppDefinition(appName: string) {
const self = this
+2 -3
View File
@@ -60,10 +60,9 @@ abstract class IAppDefinitionBase {
public versions: {
version: number
imageName?: string // empty if the deploy is not completed
deployedImageName?: string // empty if the deploy is not completed
timeStamp: string
/// imageName: string,
gitHash: string | undefined
gitHash: string | undefined // TODO make sure we are capturing the right git hash
}[]
}
+4 -3
View File
@@ -590,14 +590,15 @@ class ServiceManager {
for (let i = 0; i < app.versions.length; i++) {
const element = app.versions[i]
if (element.version == app.deployedVersion) {
imageName = element.imageName
imageName = element.deployedImageName
break
}
}
if (!imageName) {
throw new Error(
'ImageName for deployed version is not available, this is impossible!'
throw ApiStatusCodes.createError(
ApiStatusCodes.ILLEGAL_PARAMETER,
'ImageName for deployed version is not available, this version was probably failed due to an unsuccessful build!'
)
}