Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for the update procedure #453

Merged
merged 5 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Hypervisor struct {
updater *updater.Updater
mu *sync.RWMutex
visorMu sync.Mutex
visorChanMux *chanMux
visorChanMux map[cipher.PubKey]*chanMux
hypervisorMu sync.Mutex
hypervisorChanMux *chanMux
}
Expand All @@ -87,15 +87,16 @@ func New(config Config, assets http.FileSystem, restartCtx *restart.Context, dms
u := updater.New(log, restartCtx, "")

hv := &Hypervisor{
c: config,
dmsgC: dmsgC,
assets: assets,
visors: make(map[cipher.PubKey]VisorConn),
trackers: NewDmsgTrackerManager(nil, dmsgC, 0, 0),
users: NewUserManager(singleUserDB, config.Cookies),
restartCtx: restartCtx,
updater: u,
mu: new(sync.RWMutex),
c: config,
dmsgC: dmsgC,
assets: assets,
visors: make(map[cipher.PubKey]VisorConn),
trackers: NewDmsgTrackerManager(nil, dmsgC, 0, 0),
users: NewUserManager(singleUserDB, config.Cookies),
restartCtx: restartCtx,
updater: u,
mu: new(sync.RWMutex),
visorChanMux: make(map[cipher.PubKey]*chanMux),
}

return hv, nil
Expand Down Expand Up @@ -351,17 +352,17 @@ func (hv *Hypervisor) updateHypervisorWS() http.HandlerFunc {

consumer := make(chan visor.StatusMessage, 512)
hv.hypervisorMu.Lock()
if hv.visorChanMux == nil {
if hv.hypervisorChanMux == nil {
ch := hv.updateHVWithStatus(updateConfig)
hv.visorChanMux = newChanMux(ch, []chan<- visor.StatusMessage{consumer})
hv.hypervisorChanMux = newChanMux(ch, []chan<- visor.StatusMessage{consumer})
} else {
hv.visorChanMux.addConsumer(consumer)
hv.hypervisorChanMux.addConsumer(consumer)
}
hv.hypervisorMu.Unlock()

defer func() {
hv.hypervisorMu.Lock()
hv.visorChanMux = nil
hv.hypervisorChanMux = nil
hv.hypervisorMu.Unlock()
}()

Expand Down Expand Up @@ -1105,17 +1106,17 @@ func (hv *Hypervisor) updateVisorWS() http.HandlerFunc {

consumer := make(chan visor.StatusMessage, 512)
hv.visorMu.Lock()
if hv.visorChanMux == nil {
if mux := hv.visorChanMux[ctx.Addr.PK]; mux == nil {
ch := ctx.RPC.UpdateWithStatus(updateConfig)
hv.visorChanMux = newChanMux(ch, []chan<- visor.StatusMessage{consumer})
hv.visorChanMux[ctx.Addr.PK] = newChanMux(ch, []chan<- visor.StatusMessage{consumer})
} else {
hv.visorChanMux.addConsumer(consumer)
hv.visorChanMux[ctx.Addr.PK].addConsumer(consumer)
}
hv.visorMu.Unlock()

defer func() {
hv.visorMu.Lock()
hv.visorChanMux = nil
delete(hv.visorChanMux, ctx.Addr.PK)
hv.visorMu.Unlock()
}()

Expand Down Expand Up @@ -1152,7 +1153,7 @@ func (hv *Hypervisor) isVisorWSUpdateRunning() http.HandlerFunc {
return hv.withCtx(hv.visorCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) {
running := false
hv.visorMu.Lock()
running = hv.visorChanMux != nil
running = hv.visorChanMux != nil && hv.visorChanMux[ctx.Addr.PK] != nil
hv.visorMu.Unlock()

resp := struct {
Expand Down
18 changes: 18 additions & 0 deletions static/skywire-manager-src/proxy.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,23 @@
"pathRewrite": {
"^/http-api" : "/api"
}
},
"/wss-api": {
"target": "wss://127.0.0.1:8000",
"secure": false,
"ws": true,
"headers": {"host":"127.0.0.1:8000", "origin":"wss://127.0.0.1:8000", "referer":"wss://127.0.0.1:8000"},
"pathRewrite": {
"^/wss-api" : "/api"
}
},
"/ws-api": {
"target": "ws://127.0.0.1:8000",
"secure": false,
"ws": true,
"headers": {"host":"127.0.0.1:8000", "origin":"ws://127.0.0.1:8000", "referer":"ws://127.0.0.1:8000"},
"pathRewrite": {
"^/ws-api" : "/api"
}
}
}
2 changes: 2 additions & 0 deletions static/skywire-manager-src/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import { FiltersSelectionComponent } from './components/layout/filters-selection
import { LabeledElementTextComponent } from './components/layout/labeled-element-text/labeled-element-text.component';
import { AllLabelsComponent } from './components/pages/settings/all-labels/all-labels.component';
import { LabelListComponent } from './components/pages/settings/all-labels/label-list/label-list.component';
import { UpdateComponent } from './components/layout/update/update.component';

const globalRippleConfig: RippleGlobalOptions = {
disabled: true,
Expand Down Expand Up @@ -136,6 +137,7 @@ const globalRippleConfig: RippleGlobalOptions = {
LabeledElementTextComponent,
AllLabelsComponent,
LabelListComponent,
UpdateComponent,
],
imports: [
BrowserModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<app-dialog [headline]="(state !== updatingStates.Error ? 'update.title' : 'update.error-title') | translate">
<!-- Main black text area. -->
<div class="text-container">
<ng-container *ngIf="state === updatingStates.InitialProcessing">
<mat-spinner class="loading-indicator" [diameter]="12"></mat-spinner>
{{ 'update.processing' | translate }}
</ng-container>
<ng-container *ngIf="state === updatingStates.Error">
{{ errorText | translate }}
</ng-container>
<ng-container *ngIf="state === updatingStates.NoUpdatesFound">
{{ (data.length === 1 ? 'update.no-update' : 'update.no-updates') | translate }}
</ng-container>
</div>

<!-- Current version, shown if no update was found and only one node was going to be updated. -->
<div *ngIf="state === updatingStates.NoUpdatesFound && data.length === 1" class="list-container">
- {{ currentNodeVersion ? currentNodeVersion : ('common.unknown' | translate) }}
</div>

<!-- List with the nodes currently being updated, shown while asking for confirmation before installing the updates. -->
<ng-container *ngIf="state === updatingStates.Asking && indexesAlreadyBeingUpdated.length > 0">
<div class="text-container">
{{ 'update.already-updating' | translate }}
</div>
<div class="list-container">
<div *ngFor="let index of indexesAlreadyBeingUpdated">
- {{ nodesToUpdate[index].label }}
</div>
</div>
</ng-container>
<!-- Text asking for confirmation before installing the updates. -->
<ng-container *ngIf="state === updatingStates.Asking">
<div class="text-container">
{{ updateAvailableText | translate:{number: nodesForUpdatesFound} }}
</div>
<div class="list-container">
<div *ngFor="let update of updatesFound">
- {{ 'update.version-change' | translate:update }}
</div>
</div>
<div class="text-container">
{{ 'update.update-instructions' | translate }}
</div>
</ng-container>

<!-- Content shown while updating. -->
<ng-container *ngIf="state === updatingStates.Updating">
<!-- Indications. -->
<div class="text-container">
{{ 'update.updating' | translate }}
</div>
<div>
<ng-container *ngFor="let node of nodesToUpdate">
<ng-container *ngIf="node.update">
<!-- Raw progress text shown if it was not possible to parse it for showing the progrss bar. -->
<div *ngIf="!node.updateProgressInfo.errorMsg && !node.updateProgressInfo.dataParsed" class="list-container">
- <mat-spinner class="loading-indicator" [diameter]="12" *ngIf="!node.updateProgressInfo.closed"></mat-spinner> {{ node.label }}
: <span class="details">{{ node.updateProgressInfo.rawMsg }}</span>
<span *ngIf="node.updateProgressInfo.closed" class="closed-indication">&nbsp;({{ 'update.finished' | translate }})</span>
</div>
<!-- Progress bar. -->
<div *ngIf="!node.updateProgressInfo.errorMsg && node.updateProgressInfo.dataParsed" class="progress-container">
<!-- Node label. -->
<div class="name">
<mat-spinner class="loading-indicator" [diameter]="12" *ngIf="!node.updateProgressInfo.closed"></mat-spinner>
{{ node.label }}
</div>
<!-- Bar. -->
<mat-progress-bar
color="accent"
[mode]="'determinate'"
[value]="node.updateProgressInfo.progress">
</mat-progress-bar>
<!-- Details. -->
<div class="details">
{{ 'update.downloaded-file-name-prefix' | translate }} {{ node.updateProgressInfo.fileName }}
({{ node.updateProgressInfo.progress }}%)
<br/>
{{ 'update.speed-prefix' | translate }} {{ node.updateProgressInfo.speed }}
<br/>
{{ 'update.time-downloading-prefix' | translate }} {{ node.updateProgressInfo.elapsedTime }}
/
{{ 'update.time-left-prefix' | translate }} {{ node.updateProgressInfo.remainingTime }}
<ng-container *ngIf="node.updateProgressInfo.closed">
<br/>
<span class="closed-indication">{{ 'update.finished' | translate }}</span>
</ng-container>
</div>
</div>
<!-- Msg shown if there was an error during the operation. -->
<div *ngIf="node.updateProgressInfo.errorMsg" class="list-container">
- {{ node.label }}: <span class="red-text">{{ node.updateProgressInfo.errorMsg }}</span>
</div>
</ng-container>
</ng-container>
</div>
</ng-container>

<!-- Buttons. -->
<div class="buttons">
<app-button
#cancelButton
type="mat-raised-button"
color="accent"
(action)="closeModal()"
*ngIf="cancelButtonText">
{{ cancelButtonText | translate }}
</app-button>
<app-button
#confirmButton
type="mat-raised-button"
color="primary"
(action)="state === updatingStates.Asking ? update() : closeModal()"
*ngIf="confirmButtonText">
{{ confirmButtonText | translate }}
</app-button>
</div>
</app-dialog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@import 'variables';

.text-container {
word-break: break-word;
}

.list-container {
font-size: 14px;
margin: 10px;
color: $blue-medium;
word-break: break-word;

.details {
color: $light-gray;
}
}

.buttons {
margin-top: 15px;
text-align: right;

app-button {
margin-left: 5px;
}
}

.progress-container {
margin: 10px 0;

.name {
font-size: $font-size-mini;
color: $blue-medium;
}

::ng-deep {
.mat-progress-bar-fill::after {
background-color: $blue-medium !important;
}
}

.details {
font-size: $font-size-mini;
text-align: right;
color: $light-gray;
}
}

.closed-indication {
color: $yellow;
}

.loading-indicator {
display: inline-block;
position: relative;
top: 2px;
}
Loading