Skip to content

Commit

Permalink
updated deployment and container health status and update process
Browse files Browse the repository at this point in the history
  • Loading branch information
hahahannes committed Nov 20, 2023
1 parent bb1f993 commit 8127c13
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 249 deletions.
29 changes: 7 additions & 22 deletions src/app/container/models/container.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
export interface ContainerInfo {
image_id: string;
state: string;
}
export interface Container {
id: string;
ref: string;
alias: string;
order: number;
info: null | ContainerInfo;
srv_ref: string;
}

export interface Instance {
id: string;
created: Date;
containers: Container[]
}

/*
export interface Instances {
[depoyment_id: string]: Instance
}*/

export interface ContainerHealth {
id: string;
ref: string;
state: string;
}

export interface ContainerWithHealth extends Container {
state: string;
}
20 changes: 17 additions & 3 deletions src/app/container/pages/list/list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
<div class="mat-elevation-z1" [hidden]="(!ready && init) || dataSource.data.length === 0">
<div class="table-container table-container-with-button">
<table mat-table [dataSource]="dataSource" matSort matSortActive="status" matSortDirection="desc">
<ng-container matColumnDef="status">
<th mat-header-cell mat-sort-header *matHeaderCellDef class="button-column">Health</th>
<td mat-cell *matCellDef="let deployment">
<div class="circle red" *ngIf="deployment.info.state != 'running'"></div>
<div class="circle green" *ngIf="deployment.info.state == 'running'"></div>
</td>
</ng-container>

<ng-container matColumnDef="id">
<th mat-header-cell mat-sort-header *matHeaderCellDef>ID</th>
<td mat-cell *matCellDef="let container">
Expand All @@ -34,15 +42,21 @@
<ng-container matColumnDef="ref">
<th mat-header-cell mat-sort-header *matHeaderCellDef>Reference</th>
<td mat-cell *matCellDef="let container">
{{container.ref}}
{{container.srv_ref}}
</td>
</ng-container>

<ng-container matColumnDef="alias">
<th mat-header-cell mat-sort-header *matHeaderCellDef>Alias</th>
<td mat-cell *matCellDef="let container">
{{container.alias}}
</td>
</ng-container>


<ng-container matColumnDef="state">
<th mat-header-cell mat-sort-header *matHeaderCellDef>State</th>
<td mat-cell *matCellDef="let container">
{{container.state}}
{{container.info.state}}
</td>
</ng-container>

Expand Down
69 changes: 15 additions & 54 deletions src/app/container/pages/list/list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ import { ActivatedRoute, Router } from '@angular/router';
import { ModuleManagerService } from 'src/app/core/services/module-manager/module-manager-service.service';
import { ErrorService } from 'src/app/core/services/util/error.service';
import { UtilService } from 'src/app/core/services/util/util.service';
import { DeploymentHealth } from 'src/app/deployments/models/deployment_models';
import { Container, ContainerHealth, ContainerWithHealth } from '../../models/container';
import { Container } from '../../models/container';

@Component({
selector: 'app-list',
templateUrl: './list.component.html',
styleUrls: ['./list.component.css']
})
export class ListComponent implements OnDestroy {
dataSource = new MatTableDataSource<ContainerWithHealth>();
dataSource = new MatTableDataSource<Container>();
ready: Boolean = false;
init: Boolean = true;
interval: any
@ViewChild(MatSort) sort!: MatSort;
displayColumns = ['id', 'ref', 'state', 'logs']
displayColumns = ['id', 'ref', 'status', 'alias', 'state', 'logs']
deploymentID!: string

constructor(
Expand All @@ -34,9 +33,9 @@ export class ListComponent implements OnDestroy {
) {
this.route.params.subscribe(params => {
this.deploymentID = params['id']
this.loadInstances(this.deploymentID);
this.loadContainer(this.deploymentID);
this.interval = setInterval(() => {
this.loadInstances(this.deploymentID);
this.loadContainer(this.deploymentID);
}, 5000);
this.init = false
})
Expand All @@ -46,65 +45,27 @@ export class ListComponent implements OnDestroy {
clearTimeout(this.interval)
}

loadInstances(deploymentID: string): void {
loadContainer(deploymentID: string): void {
// Get containers from deployment info, then merge with container healths
this.moduleService.loadDeployment(deploymentID).subscribe(
this.moduleService.loadDeployment(deploymentID, true).subscribe(
{
next: (deployment) => {
var containers = deployment.instance.containers
this.loadContainerHealth(containers, deploymentID)
},
error: (err) => {
this.errorService.handleError(ListComponent.name, "loadInstances", err)
this.ready = true
}
}
)
}

loadContainerHealth(containers: Container[], deploymentID: string) {
var containersWithHealth: ContainerWithHealth[] = []

this.moduleService.getDeploymentHealth(deploymentID).subscribe(
{
next: (deploymentHealth) => {
var containerIDToStatus: Record<string, string> = {}
deploymentHealth.containers.forEach(container => {
var containerID = container.id
containerIDToStatus[containerID] = container.state
});

containers.forEach(container => {
var containerWithHealth: ContainerWithHealth = {
...container,
...{"state": containerIDToStatus[container.id]}
var containers = []
if(!!deployment.containers) {
for(const [_, container] of Object.entries(deployment.containers)) {
containers.push(container)
}
containersWithHealth.push(containerWithHealth)
});
}

this.dataSource.data = containersWithHealth
this.dataSource.data = containers
this.ready = true
},
},
error: (err) => {
if(err instanceof HttpErrorResponse && err.status == 400) {
containers.forEach(container => {
var containerWithHealth: ContainerWithHealth = {
...container,
...{"state": "N/A"}
}
containersWithHealth.push(containerWithHealth)
});

this.dataSource.data = containersWithHealth
} else {
this.errorService.handleError(ListComponent.name, "loadContainerHealth", err)
}

this.errorService.handleError(ListComponent.name, "loadInstances", err)
this.ready = true
}
}
)

}

showLogs(containerID: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class JobLoaderModalComponent implements OnInit {
if(jobResponse.completed && !jobResponse.error) {
this.close(true, undefined)
} else if (jobResponse.error) {
this.errorService.handleError(JobLoaderModalComponent.name, "ngOnInit", new Error(jobResponse.error))
this.close(false, jobResponse.error)
this.errorService.handleError(JobLoaderModalComponent.name, "ngOnInit", new Error(jobResponse.error.message))
this.close(false, jobResponse.error.message)
}
});
}, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { ApiService } from '../api/api.service';
import { AddModule, Module, ModuleUpdate, ModuleUpdatePrepare, ModuleUpdates } from '../../../modules/models/module_models';
import { Deployment, DeploymentHealth, DeploymentHealths, DeploymentRequest, DeploymentTemplate } from 'src/app/deployments/models/deployment_models';
import { Deployment, DeploymentRequest, DeploymentTemplate } from 'src/app/deployments/models/deployment_models';
import { ErrorService } from '../util/error.service';
import { Job } from 'src/app/jobs/models/job.model';
import { delay } from "rxjs/operators";
Expand Down Expand Up @@ -251,7 +251,6 @@ export class ModuleManagerMockService {
"license": "license",
"tags": ["tag1", "tag2", "tag3"],
"type": "type",
"indirect": false,
"added": new Date(),
"updated": new Date()
})
Expand Down Expand Up @@ -341,7 +340,7 @@ cancelModuleUpdate(moduleID: string): Observable<string> {
return of("done").pipe(delay(1000));
}

public loadDeployments(): Observable<Deployment[]> {
public loadDeployments(withContainerInfo: boolean): Observable<Deployment[]> {
var deployments = [
{
"module": {
Expand All @@ -351,27 +350,22 @@ cancelModuleUpdate(moduleID: string): Observable<string> {
"name": "Deployment1",
"enabled": true,
"id": "id",
'indirect': true,
'created': new Date(),
'updated': new Date(),
'secrets': {},
'host_resources': {},
'configs': {},
'dep_requiring': [],
'required_dep': [],
'instance': {
"id": "id",
"created": new Date(),
"containers": []
}
'state': null,
'containers': null,
},
{
"id": "id2",
"module": {
"id": "github.com/SENERGY-Platform/mgw-test-module-a",
"version": ""
},
'indirect': true,
'created': new Date(),
'updated': new Date(),
"name": "Deployment2",
Expand All @@ -381,16 +375,13 @@ cancelModuleUpdate(moduleID: string): Observable<string> {
'configs': {},
'dep_requiring': [],
'required_dep': [],
'instance': {
"id": "id",
"created": new Date(),
"containers": []
}
'state': null,
'containers': null,
}]
return of(deployments).pipe(delay(1000));
}

public loadDeployment(deploymentID: string): Observable<Deployment> {
public loadDeployment(deploymentID: string, withContainerInfo: boolean): Observable<Deployment> {
return new Observable((subscriber) => {
var template = {
"module": {
Expand All @@ -400,7 +391,6 @@ cancelModuleUpdate(moduleID: string): Observable<string> {
"name": "Deployment1",
"enabled": true,
"id": "id",
'indirect': true,
'created': new Date(),
'updated': new Date(),
'secrets': {"cert": {"id": "cert", "variants": []}, "login": {"id": "login", "variants": []}},
Expand All @@ -414,11 +404,8 @@ cancelModuleUpdate(moduleID: string): Observable<string> {
},
'dep_requiring': [],
'required_dep': [],
"instance": {
"id": "id",
"created": new Date(),
"containers": []
}
'state': null,
'containers': null,
}
subscriber.next(template)
subscriber.complete()
Expand Down Expand Up @@ -504,32 +491,4 @@ cancelModuleUpdate(moduleID: string): Observable<string> {
obs.next(true)
})
}


// Health
getDeploymentsHealth(): Observable<DeploymentHealths> {
var health = {
"id": {
"status": "unknown",
"containers": [{
"id": "id2",
"ref": "Ref",
"state": "running"
}]
}
}
return of(health).pipe(delay(500))
}

getDeploymentHealth(deploymentID: string): Observable<DeploymentHealth> {
var health = {
"status": "unknown",
"containers": [{
"id": "id2",
"ref": "Ref",
"state": "running"
}]
}
return of(health).pipe(delay(500))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ApiService } from '../api/api.service';
import { AddModule, Module, ModuleUpdate, ModuleUpdatePrepare, ModuleUpdateRequest, ModuleUpdates } from '../../../modules/models/module_models';
import { Deployment, DeploymentHealth, DeploymentHealths, DeploymentRequest, DeploymentTemplate, ModuleUpdateTemplate } from 'src/app/deployments/models/deployment_models';
import { AddModule, Module, ModuleResponse, ModuleUpdate, ModuleUpdatePrepare, ModuleUpdateRequest, ModuleUpdates } from '../../../modules/models/module_models';
import { Deployment, DeploymentRequest, DeploymentResponse, DeploymentTemplate, ModuleUpdateTemplate } from 'src/app/deployments/models/deployment_models';
import { Job } from 'src/app/jobs/models/job.model';

@Injectable({
Expand All @@ -26,9 +26,9 @@ export class ModuleManagerService {
return <Observable<DeploymentTemplate>>this.http.get(url)
}

loadModules(): Observable<Module[]> {
loadModules(): Observable<ModuleResponse> {
var url = this.moduleManagerPath + "/modules"
return <Observable<Module[]>>this.http.get(url)
return <Observable<ModuleResponse>>this.http.get(url)
}

addModule(module: AddModule): Observable<string> {
Expand Down Expand Up @@ -89,14 +89,22 @@ export class ModuleManagerService {
return <Observable<string>>this.http.post(path, deploymentRequest, undefined, 'text');
}

loadDeployments(): Observable<Deployment[]> {
var url = this.moduleManagerPath + "/deployments"
return <Observable<Deployment[]>>this.http.get<Deployment[]>(url);
loadDeployments(withContainerInfo: boolean): Observable<DeploymentResponse> {
var url = this.moduleManagerPath + "/deployments"
let queryParams = new HttpParams()
if(withContainerInfo) {
queryParams = queryParams.set("container_info", "true")
}
return <Observable<DeploymentResponse>>this.http.get<Deployment[]>(url, queryParams);
}

loadDeployment(deploymentID: string): Observable<Deployment> {
var url = this.moduleManagerPath + "/deployments/" + deploymentID
return <Observable<Deployment>>this.http.get(url);
loadDeployment(deploymentID: string, withContainerInfo: boolean): Observable<Deployment> {
var url = this.moduleManagerPath + "/deployments/" + deploymentID
let queryParams = new HttpParams()
if(withContainerInfo) {
queryParams = queryParams.set("container_info", "true")
}
return <Observable<Deployment>>this.http.get(url, queryParams);
}

updateDeployment(deploymentID: string, update: any): Observable<string> {
Expand Down Expand Up @@ -190,15 +198,4 @@ export class ModuleManagerService {
var url = this.moduleManagerPath + "/jobs"
return <Observable<Job[]>>this.http.get(url)
}

// Health
getDeploymentsHealth(): Observable<DeploymentHealths> {
var url = this.moduleManagerPath + "/health"
return <Observable<DeploymentHealths>>this.http.get(url)
}

getDeploymentHealth(deploymentID: string): Observable<DeploymentHealth> {
var url = this.moduleManagerPath + "/health/" + deploymentID
return <Observable<DeploymentHealth>>this.http.get(url)
}
}
Loading

0 comments on commit 8127c13

Please sign in to comment.