Skip to content

Commit

Permalink
Add migration concept for old ctr app properties
Browse files Browse the repository at this point in the history
- Add Some UI fu to let user to automatically migrate
  from old ctr app properties(given in 2.7.x line) and
  migrate those to new expected ctr options.
- For this work correctly also #1721 needs to be fixed which
  is a bigger topic and will get done in a separate commit.
- Fixes #1715

Fix typo
  • Loading branch information
jvalkeal authored and Glenn Renfro committed May 26, 2021
1 parent a86d553 commit 328e796
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
<div *ngIf="builder$ | async as builder; else loading">

<clr-alert *ngIf="task.composed && hasMigrations()" [clrAlertType]="info" [clrAlertClosable]="false">
<clr-alert-item>
<span class="alert-text">
There are properties which can be migrated.
</span>
<div class="alert-actions">
<clr-dropdown>
<button class="dropdown-toggle" clrDropdownTrigger>
Actions
<cds-icon shape="caret" direction="down"></cds-icon>
</button>
<clr-dropdown-menu clrPosition="bottom-right">
<a (click)="migrate()" class="dropdown-item" clrDropdownItem>Migrate</a>
</clr-dropdown-menu>
</clr-dropdown>
</div>
</clr-alert-item>
</clr-alert>

<form class="form-horizontal" novalidate (ngSubmit)="launchTask()">
<div>
<div class="tab-pane">
Expand Down Expand Up @@ -244,7 +264,7 @@

<!-- 10 Ctr Properties options -->
<div class="line-body"
*ngIf="state.ctr && task.composed">
*ngIf="state.ctr && task.composed && builder.ctrProperties.length > 0">
<div class="form-control form-control-label"
*ngIf="!builder.ctrPropertiesState.isLoading && !builder.ctrPropertiesState.isOnError">
<strong>{{getCtrProperties(builder.ctrProperties).length}}</strong>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,27 @@ describe('tasks-jobs/tasks/launch/builder/builder.component.ts', () => {
'app.t1.timestamp.format=yyyy'
]));
});

it('should have migrations', async () => {
component.task = TASK_2;
component.properties = [
'app.composed-task-runner.composed-task-properties=app.composedtask-t2.app.timestamp.timestamp.format=YYYY',
'app.t1.timestamp.format=YYYY'
];
fixture.detectChanges();
expect(component['calculateMigrations']().migratedMatch.length).toBe(1);
expect(component['calculateMigrations']().migratedNomatch.length).toBe(0);
expect(component['hasMigrations']()).toBeTruthy();
});

it('should not have migrations', async () => {
component.task = TASK_2;
component.properties = [
'app.t1.timestamp.format=YYYY'
];
fixture.detectChanges();
expect(component['calculateMigrations']().migratedMatch.length).toBe(0);
expect(component['calculateMigrations']().migratedNomatch.length).toBe(0);
expect(component['hasMigrations']()).toBeFalsy();
});
});
57 changes: 57 additions & 0 deletions ui/src/app/tasks-jobs/tasks/launch/builder/builder.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ export interface Builder {
};
}

export interface Migrations {
migratedNomatch: string[];
migratedMatch: RegExpExecArray[];
}

@Component({
selector: 'app-task-launch-builder',
templateUrl: 'builder.component.html',
Expand Down Expand Up @@ -142,6 +147,8 @@ export class BuilderComponent implements OnInit, OnDestroy {
arguments: true
};

private migrations: Migrations;

constructor(
private taskLaunchService: TaskLaunchService,
private changeDetector: ChangeDetectorRef,
Expand Down Expand Up @@ -183,6 +190,7 @@ export class BuilderComponent implements OnInit, OnDestroy {
});
}
});
this.migrations = this.calculateMigrations();
},
() => {
this.refBuilder.ctrPropertiesState.isOnError = true;
Expand Down Expand Up @@ -1022,4 +1030,53 @@ export class BuilderComponent implements OnInit, OnDestroy {
this.launch.emit({props: this.getProperties(), args: this.getArguments()});
}
}

hasMigrations(): boolean {
return this.migrations && this.migrations.migratedMatch && this.migrations.migratedMatch.length > 0;
}

migrate() {
if (this.migrations) {
const ctp = this.refBuilder.ctrProperties.find(prop => prop.id === 'composed-task-properties' && prop.value);
if (ctp) {
this.migrations.migratedMatch.forEach(m => {
if (m[1]) {
const prop: ValuedConfigurationMetadataProperty[] = this.refBuilder.builderAppsProperties[m[1]];
if (prop) {
prop.forEach(v => {
if (v.id === m[3]) {
v.value = m[4];
}
});
}
}
});
ctp.value = this.migrations.migratedNomatch.join(',');
}
}
this.migrations = this.calculateMigrations();
}

private calculateMigrations(): Migrations {
const migratedNomatch: string[] = [];
const migratedMatch: RegExpExecArray[] = [];
if (this.task.composed) {
const ctp = this.refBuilder.ctrProperties.find(prop => prop.id === 'composed-task-properties' && prop.value);
if (ctp) {
ctp.value.split(',').forEach(p => {
const r = new RegExp(`app\\.${this.task.name}-(\\w*)\\.app\\.(\\w*)\\.(.*)=(.*)`);
const match = r.exec(p);
if (match) {
migratedMatch.push(match);
} else {
migratedNomatch.push(p);
}
});
}
}
return {
migratedMatch,
migratedNomatch
};
}
}
4 changes: 2 additions & 2 deletions ui/src/app/tests/data/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export const SIMPLE_TASK_DEFAULT = {
'description': 'simpledescription',
'dslText': 'timestamp',
'lastTaskExecution': null,
' name': 'simpletask',
'name': 'simpletask',
'status': 'UNKNOWN'
};

Expand All @@ -281,7 +281,7 @@ export const COMPOSED_TASK_DEFAULT = {
'description': 'composeddescription',
'dslText': 't1:timestamp && t2:timestamp',
'lastTaskExecution': null,
' name': 'composedtask',
'name': 'composedtask',
'status': 'UNKNOWN'
};

Expand Down
12 changes: 12 additions & 0 deletions ui/src/app/tests/service/task-launch.service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ export class TaskLaunchServiceMock {
sourceType: '',
isDeprecated: false,
value: ''
},
{
id: 'composed-task-properties',
name: 'composed-task-properties',
type: 'java.lang.Integer',
description: 'The properties to be used for each of the tasks as well as their deployments.',
shortDescription: 'The properties to be used for each of the tasks as well as their deployments.',
defaultValue: null,
deprecation: null,
sourceType: '',
isDeprecated: false,
value: ''
}
]);
}
Expand Down

0 comments on commit 328e796

Please sign in to comment.