feat: viya deploy, update the index.html contextname

This commit is contained in:
Mihajlo Medjedovic
2025-06-04 17:35:15 +02:00
parent d0f453d291
commit 72239558af
2 changed files with 55 additions and 7 deletions
@@ -144,6 +144,7 @@ export class AutomaticComponent implements OnInit {
resolve()
},
(err) => {
console.error('Error while getting current user', err)
reject(err)
}
)
@@ -190,6 +191,12 @@ 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 +272,10 @@ 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
}
}
@@ -288,7 +292,7 @@ export class AutomaticComponent implements OnInit {
this.sasJs
.request(
`services/admin/makedata&_contextname=${selectedComputeContextName}`,
`services/admin/makedata`,
data,
overrideConfig,
() => {
@@ -321,6 +325,8 @@ export class AutomaticComponent implements OnInit {
MAC: macMsg
})
}
this.updateIndexHtmlComputeContext()
})
.catch((err: any) => {
this.eventService.showAbortModal('makedata', JSON.stringify(err))
@@ -335,6 +341,39 @@ 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,
+9
View File
@@ -657,4 +657,13 @@ 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)
}
}