Merge pull request 'Viya smooth deploy' (#166) from deploy-context into main
Reviewed-on: #166
This commit was merged in pull request #166.
This commit is contained in:
@@ -86,19 +86,19 @@ export class AutomaticComponent implements OnInit {
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
const promiseGetAadminGroups = this.getAdminGroups()
|
||||
const getCurrentUser = this.getCurrentUser()
|
||||
const getComputeContexts = this.getComputeContexts()
|
||||
this.loadData()
|
||||
}
|
||||
|
||||
Promise.all([
|
||||
promiseGetAadminGroups,
|
||||
getCurrentUser,
|
||||
getComputeContexts
|
||||
]).then(() => {
|
||||
public async loadData() {
|
||||
await this.getAdminGroups()
|
||||
await this.getComputeContexts()
|
||||
await this.getCurrentUser()
|
||||
|
||||
setTimeout(() => {
|
||||
if (this.selectedComputeContext) {
|
||||
this.onComputeContextChange(this.selectedComputeContext)
|
||||
}
|
||||
})
|
||||
}, 500)
|
||||
}
|
||||
|
||||
public async getComputeContexts() {
|
||||
@@ -144,6 +144,7 @@ export class AutomaticComponent implements OnInit {
|
||||
resolve()
|
||||
},
|
||||
(err) => {
|
||||
console.error('Error while getting current user', err)
|
||||
reject(err)
|
||||
}
|
||||
)
|
||||
@@ -190,6 +191,14 @@ export class AutomaticComponent implements OnInit {
|
||||
})
|
||||
}
|
||||
|
||||
public getComputeContextName(id: string): string | undefined {
|
||||
return (
|
||||
this.computeContexts.find(
|
||||
(context: ComputeContextItem) => context.id === id
|
||||
)?.name || undefined
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes sas.json file to deploy the backend
|
||||
* Method will first try to run the `auto deploy`
|
||||
@@ -265,13 +274,12 @@ export class AutomaticComponent implements OnInit {
|
||||
let selectedComputeContextName = this.sasJsConfig.contextName
|
||||
|
||||
if (this.selectedComputeContext.length && this.computeContexts.length) {
|
||||
const computeContext = this.computeContexts.find(
|
||||
(context: ComputeContextItem) =>
|
||||
context.id === this.selectedComputeContext
|
||||
const computeContextName = this.getComputeContextName(
|
||||
this.selectedComputeContext
|
||||
)
|
||||
|
||||
if (computeContext) {
|
||||
selectedComputeContextName = computeContext.name
|
||||
if (computeContextName) {
|
||||
selectedComputeContextName = computeContextName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,14 +295,9 @@ export class AutomaticComponent implements OnInit {
|
||||
}
|
||||
|
||||
this.sasJs
|
||||
.request(
|
||||
`services/admin/makedata&_contextname=${selectedComputeContextName}`,
|
||||
data,
|
||||
overrideConfig,
|
||||
() => {
|
||||
this.sasService.shouldLogin.next(true)
|
||||
}
|
||||
)
|
||||
.request(`services/admin/makedata`, data, overrideConfig, () => {
|
||||
this.sasService.shouldLogin.next(true)
|
||||
})
|
||||
.then((res: any) => {
|
||||
this.autodeployDone = true
|
||||
|
||||
@@ -321,6 +324,8 @@ export class AutomaticComponent implements OnInit {
|
||||
MAC: macMsg
|
||||
})
|
||||
}
|
||||
|
||||
this.updateIndexHtmlComputeContext()
|
||||
})
|
||||
.catch((err: any) => {
|
||||
this.eventService.showAbortModal('makedata', JSON.stringify(err))
|
||||
@@ -335,6 +340,50 @@ export class AutomaticComponent implements OnInit {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Only when on Viya, this method will update the `contextname` in the `DataController.html` on the SAS drive
|
||||
* This is needed to ensure that the DC will use the same compute context `makedata` service used to run against.
|
||||
*/
|
||||
public async updateIndexHtmlComputeContext() {
|
||||
const indexHtmlContent = await this.sasService.getFileContent(
|
||||
`${this.appLoc}/services`,
|
||||
'DataController.html'
|
||||
)
|
||||
|
||||
if (!indexHtmlContent) {
|
||||
this.loggerService.error(
|
||||
`Failed to get DataController.html at ${this.appLoc}/services`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const computeContextName = this.getComputeContextName(
|
||||
this.selectedComputeContext
|
||||
)
|
||||
|
||||
if (!computeContextName) {
|
||||
this.loggerService.error(
|
||||
`Compute context name not found for ID: ${this.selectedComputeContext} | List: ${JSON.stringify(this.computeContexts)}`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const updatedContent = indexHtmlContent.replace(
|
||||
/contextname="[^"]*"/g,
|
||||
`contextname="${computeContextName}"`
|
||||
)
|
||||
|
||||
await this.sasService
|
||||
.updateFileContent(
|
||||
`${this.appLoc}/services`,
|
||||
'DataController.html',
|
||||
updatedContent
|
||||
)
|
||||
.catch((err: any) => {
|
||||
this.loggerService.error(`Failed to update DataController.html: ${err}`)
|
||||
})
|
||||
}
|
||||
|
||||
public downloadFile(
|
||||
content: any,
|
||||
filename: string,
|
||||
|
||||
@@ -657,4 +657,17 @@ export class SasService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Viya specific functions
|
||||
public getFileContent(folderPath: string, fileName: string) {
|
||||
return this.sasjsAdapter.getFileContent(folderPath, fileName)
|
||||
}
|
||||
|
||||
public updateFileContent(
|
||||
folderPath: string,
|
||||
fileName: string,
|
||||
content: string
|
||||
) {
|
||||
return this.sasjsAdapter.updateFileContent(folderPath, fileName, content)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user