Merge pull request 'feat: viya deploy context' (#163) from deploy-context into main
Release / Build-production-and-ng-test (push) Successful in 4m3s
Release / Build-and-test-development (push) Successful in 8m39s
Release / release (push) Successful in 8m30s

Reviewed-on: #163
This commit was merged in pull request #163.
This commit is contained in:
2025-06-04 09:09:28 +00:00
6 changed files with 307 additions and 41 deletions
@@ -98,14 +98,14 @@
<label for="dcloc" class="mt-20 clr-control-label">DC Loc</label>
<div class="mb-10 clr-control-container dc-loc-input-wrapper">
<div class="clr-input-wrapper">
<div class="clr-input-wrapper small-mt">
<input clrInput name="dcloc" [(ngModel)]="dcPath" />
</div>
</div>
<label for="dcloc" class="mt-20 clr-control-label">SAS Admin group</label>
<div class="mb-10 clr-control-container">
<div class="clr-input-wrapper">
<div class="clr-input-wrapper small-mt">
<select
*ngIf="!adminGroupsLoading"
clrSelect
@@ -124,6 +124,42 @@
</div>
</div>
<label for="computeContext" class="mt-20 clr-control-label"
>Compute Context</label
>
<div class="mb-10 clr-control-container">
<div class="clr-input-wrapper small-mt">
<select
*ngIf="!computeContextsLoading"
clrSelect
name="options"
(ngModelChange)="onComputeContextChange($event)"
[(ngModel)]="selectedComputeContext"
>
<option
*ngFor="let computeContext of computeContexts"
[value]="computeContext.id"
>
{{ computeContext.name }}
</option>
</select>
<clr-spinner
clrInline
class="spinner-sm"
*ngIf="computeContextsLoading"
></clr-spinner>
</div>
</div>
<ng-container *ngIf="runningAsUser">
<label for="dcloc" class="mt-20 clr-control-label">Running as user:</label>
<div class="mb-10 clr-control-container">
<div class="clr-input-wrapper">
<p class="mt-0">{{ runningAsUser }}</p>
</div>
</div>
</ng-container>
<!-- Keeping this for a reference in case future VIYA changes and starts allowing separate backend and frontend) -->
<!-- <clr-checkbox-wrapper>
@@ -18,6 +18,11 @@ import {
Item,
ViyaApiIdentities
} from 'src/app/viya-api-explorer/models/viya-api-identities.model'
import { ComputeContextDetails } from 'src/app/viya-api-explorer/models/viya-compute-context-details.model'
import {
ViyaComputeContexts,
Item as ComputeContextItem
} from 'src/app/viya-api-explorer/models/viya-compute-contexts.model'
@Component({
selector: 'app-automatic-deploy',
@@ -35,6 +40,7 @@ export class AutomaticComponent implements OnInit {
@Output() onNavigateToHome: EventEmitter<any> = new EventEmitter<any>()
public selectedComputeContext: string = ''
public makeDataResponse: string = ''
public jsonFile: any = null
public autodeploying: boolean = false
@@ -50,8 +56,11 @@ export class AutomaticComponent implements OnInit {
public createDatabaseLoading: boolean = false
public adminGroupsLoading: boolean = false
public currentUserInfoLoading: boolean = false
public computeContextsLoading: boolean = false
public adminGroups: { id: string; name: string }[] = []
public runningAsUser: string | undefined
public currentUserInfo: ViyaApiCurrentUser | null = null
public computeContexts: ComputeContextItem[] = []
/** autoDeployStatus
* This object presents the status for two steps that we have for deploy.
@@ -77,42 +86,108 @@ export class AutomaticComponent implements OnInit {
) {}
ngOnInit(): void {
this.getAdminGroups()
this.getCurrentUser()
const promiseGetAadminGroups = this.getAdminGroups()
const getCurrentUser = this.getCurrentUser()
const getComputeContexts = this.getComputeContexts()
Promise.all([
promiseGetAadminGroups,
getCurrentUser,
getComputeContexts
]).then(() => {
if (this.selectedComputeContext) {
this.onComputeContextChange(this.selectedComputeContext)
}
})
}
public async getComputeContexts() {
return new Promise<void>((resolve, reject) => {
this.computeContextsLoading = true
this.sasViyaService.getComputeContexts().subscribe(
(res: ViyaComputeContexts) => {
this.computeContextsLoading = false
const defaultContext = res.items.find(
(item: ComputeContextItem) =>
item.name === 'SAS Job Execution compute context'
)
if (defaultContext) {
this.selectedComputeContext = defaultContext.id
}
this.computeContexts = res.items
resolve()
},
(err) => {
reject(err)
}
)
})
}
public async getCurrentUser() {
this.currentUserInfoLoading = true
return new Promise<void>((resolve, reject) => {
this.currentUserInfoLoading = true
this.sasViyaService
.getCurrentUser()
.subscribe((res: ViyaApiCurrentUser) => {
this.currentUserInfoLoading = false
this.sasViyaService.getCurrentUser().subscribe(
(res: ViyaApiCurrentUser) => {
this.currentUserInfoLoading = false
this.currentUserInfo = res
this.currentUserInfo = res
this.dcPath = `/export/viya/homes/${res.id}`
})
this.dcPath = `/export/viya/homes/${res.id}`
resolve()
},
(err) => {
reject(err)
}
)
})
}
public async getAdminGroups() {
this.adminGroupsLoading = true
return new Promise<void>((resolve, reject) => {
this.adminGroupsLoading = true
this.sasViyaService.getAdminGroups().subscribe((res: ViyaApiIdentities) => {
this.adminGroupsLoading = false
// Map admin groups with only needed fields
this.adminGroups = res.items.map((item: Item) => {
return {
id: item.id,
name: item.name
this.sasViyaService
.getAdminGroups()
.subscribe((res: ViyaApiIdentities) => {
this.adminGroupsLoading = false
// Map admin groups with only needed fields
this.adminGroups = res.items.map((item: Item) => {
return {
id: item.id,
name: item.name
}
})
resolve()
}),
(err: any) => {
this.adminGroupsLoading = false
this.loggerService.error('Error while getting admin groups', err)
this.eventService.showAbortModal('admin groups', err)
reject(err)
}
})
}
public async onComputeContextChange(computeContextId: string) {
this.sasViyaService
.getComputeContextById(computeContextId)
.subscribe((res: ComputeContextDetails) => {
if (res.attributes && res.attributes.runServerAs) {
this.runningAsUser = res.attributes.runServerAs
} else {
this.runningAsUser = this.currentUserInfo?.id || 'unknown'
}
})
}),
(err: any) => {
this.adminGroupsLoading = false
this.loggerService.error('Error while getting admin groups', err)
this.eventService.showAbortModal('admin groups', err)
}
}
/**
@@ -186,6 +261,20 @@ export class AutomaticComponent implements OnInit {
]
}
// Get and run service using the selected context name
let selectedComputeContextName = this.sasJsConfig.contextName
if (this.selectedComputeContext.length && this.computeContexts.length) {
const computeContext = this.computeContexts.find(
(context: ComputeContextItem) =>
context.id === this.selectedComputeContext
)
if (computeContext) {
selectedComputeContextName = computeContext.name
}
}
/**
* We are overriding default `sasjsConfig` object fields with this object fields.
* Here we want to run this request using original WEB method.
@@ -193,14 +282,19 @@ export class AutomaticComponent implements OnInit {
*/
let overrideConfig = {
useComputeApi: null,
contextName: this.sasJsConfig.contextName,
contextName: selectedComputeContextName,
debug: true
}
this.sasJs
.request(`services/admin/makedata`, data, overrideConfig, () => {
this.sasService.shouldLogin.next(true)
})
.request(
`services/admin/makedata&_contextname=${selectedComputeContextName}`,
data,
overrideConfig,
() => {
this.sasService.shouldLogin.next(true)
}
)
.then((res: any) => {
this.autodeployDone = true
+71 -11
View File
@@ -1,6 +1,12 @@
import { HttpClient } from '@angular/common/http'
import {
HttpClient,
HttpContext,
HttpErrorResponse,
HttpHeaders,
HttpParams
} from '@angular/common/http'
import { Injectable } from '@angular/core'
import { Observable } from 'rxjs'
import { catchError, Observable, throwError } from 'rxjs'
import { Collection } from '../viya-api-explorer/models/collection.model'
import { AppStoreService } from './app-store.service'
import { ViyaApis } from '../viya-api-explorer/models/viya-apis.models'
@@ -8,6 +14,8 @@ import { ViyaApiFolderMembers } from '../viya-api-explorer/models/viya-api-folde
import { ViyaApiFolder } from '../viya-api-explorer/models/viya-api-folder.model'
import { ViyaApiIdentities } from '../viya-api-explorer/models/viya-api-identities.model'
import { ViyaApiCurrentUser } from '../viya-api-explorer/models/viya-api-current-user.model'
import { ViyaComputeContexts } from '../viya-api-explorer/models/viya-compute-contexts.model'
import { ComputeContextDetails } from '../viya-api-explorer/models/viya-compute-context-details.model'
@Injectable({
providedIn: 'root'
@@ -75,7 +83,7 @@ export class SasViyaService {
this.serverUrl = adapterConfig?.serverUrl || ''
//example collection request
// example collection request
// this.getByCollection('jobs').subscribe((res) => {
// console.log('res', res)
// })
@@ -95,7 +103,7 @@ export class SasViyaService {
* @returns
*/
getByUrl(url: string): Observable<Collection> {
return this.http.get<Collection>(`${this.serverUrl}${url}`, {
return this.get<Collection>(`${this.serverUrl}${url}`, {
withCredentials: true
})
}
@@ -106,23 +114,32 @@ export class SasViyaService {
* @returns
*/
getByCollection(apiCollection: string): Observable<Collection> {
return this.http.get<Collection>(`${this.serverUrl}${apiCollection}`, {
return this.get<Collection>(`${this.serverUrl}${apiCollection}`, {
withCredentials: true
})
}
getComputeContexts(): Observable<any> {
return this.http.get<any>(`${this.serverUrl}/compute/contexts`, {
getComputeContexts(): Observable<ViyaComputeContexts> {
return this.get<ViyaComputeContexts>(`${this.serverUrl}/compute/contexts`, {
withCredentials: true
})
}
getComputeContextById(id: string): Observable<ComputeContextDetails> {
return this.get<ComputeContextDetails>(
`${this.serverUrl}/compute/contexts/${id}`,
{
withCredentials: true
}
)
}
/**
* @param path Path to the folder
* @returns The folder info object
*/
getFolderByPath(path: string): Observable<ViyaApiFolder> {
return this.http.get<ViyaApiFolder>(
return this.get<ViyaApiFolder>(
`${this.serverUrl}/folders/folders/@item?path=${path}`,
{
withCredentials: true
@@ -131,7 +148,7 @@ export class SasViyaService {
}
getFolderMembers(folderId: string): Observable<ViyaApiFolderMembers> {
return this.http.get<ViyaApiFolderMembers>(
return this.get<ViyaApiFolderMembers>(
`${this.serverUrl}/folders/folders/${folderId}/members`,
{
withCredentials: true
@@ -140,7 +157,7 @@ export class SasViyaService {
}
getAdminGroups(limit: number = 5000): Observable<ViyaApiIdentities> {
return this.http.get<ViyaApiIdentities>(
return this.get<ViyaApiIdentities>(
`${this.serverUrl}/identities/groups?sortBy=name&limit=${limit}`,
{
withCredentials: true
@@ -149,11 +166,54 @@ export class SasViyaService {
}
getCurrentUser(): Observable<ViyaApiCurrentUser> {
return this.http.get<ViyaApiCurrentUser>(
return this.get<ViyaApiCurrentUser>(
`${this.serverUrl}/identities/users/@currentUser`,
{
withCredentials: true
}
)
}
get<T>(
url: string,
options?: {
headers?:
| HttpHeaders
| {
[header: string]: string | string[]
}
context?: HttpContext
observe?: 'body'
params?:
| HttpParams
| {
[param: string]:
| string
| number
| boolean
| ReadonlyArray<string | number | boolean>
}
reportProgress?: boolean
responseType?: 'json'
withCredentials?: boolean
transferCache?:
| {
includeHeaders?: string[]
}
| boolean
}
): Observable<T> {
return this.http.get<T>(url, options).pipe(
catchError((err: HttpErrorResponse) => {
console.log('url', url)
console.log('err.status', err.status)
if (err.status === 449 || err.status === 401) {
// Retry once if we got a 449
return this.http.get<T>(url, options)
}
// Otherwise propagate the error
return throwError(() => err)
})
)
}
}
@@ -0,0 +1,34 @@
export interface ComputeContextDetails {
attributes?: Attributes
createdBy: string
creationTimeStamp: string
description: string
id: string
launchContext: LaunchContext
launchType: string
links: Link[]
modifiedBy: string
modifiedTimeStamp: string
name: string
version: number
}
export interface Link {
method: string
rel: string
href: string
uri: string
type?: string
responseType?: string
itemType?: string
}
export interface LaunchContext {
contextId: string
}
export interface Attributes {
reuseServerProcesses: string
runServerAs: string
serverMinAvailable: string
}
@@ -0,0 +1,36 @@
export interface ViyaComputeContexts {
accept: string
count: number
items: Item[]
limit: number
links: Link2[]
name: string
start: number
version: number
}
export interface Link2 {
method: string
rel: string
href: string
uri: string
type: string
itemType: string
}
export interface Item {
createdBy: string
id: string
links: Link[]
name: string
version: number
}
export interface Link {
method: string
rel: string
href: string
uri: string
type?: string
responseType?: string
}
+6
View File
@@ -3884,6 +3884,12 @@ app-header-actions {
// END OF CSP WORKAROUND
.clr-input-wrapper.small-mt {
.clr-form-control {
margin-top: 5px !important;
}
}
body[cds-theme="dark"] {
scrollbar-width: thin;
scrollbar-color: $trackColor $thumbColor;