Skip to content

Commit

Permalink
update reset implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
raronpxcsw committed Jun 25, 2024
1 parent dae52d1 commit eebc561
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ASSETS": "projects/aas-server/src/assets",
// "USER_STORAGE": "mongodb://localhost:27017/aasportal-users",
// "TEMPLATE_STORAGE": "http://localhost:8080/templates",
"AAS_INDEX": "mysql://localhost:3306",
// "AAS_INDEX": "mysql://localhost:3306",
"ENDPOINTS": "[\"file:///endpoints/samples?name=Samples\"]",
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ <h5 class="modal-title text-info">
placeholder="name">
<label for="inputLoginPassword" translate>LABEL_PASSWORD</label>
</div>
@if (!passwordPerEMail) {
<div class="form-check mb-3">
<label class="form-check-label" for="stayLoggedIn" translate>LABEL_STAY_LOGGED_IN</label>
<input class="form-check-input" type="checkbox" id="stayLoggedIn" [(ngModel)]="stayLoggedIn"
name="stayLoggedIn">
</div>
}
@else {
@if (passwordPerEMail()) {
<div class="mb-3">
<a href="javascript:void(0);" (click)="resetPassword()" translate>CMD_RESET_PASSWORD</a>
</div>
Expand Down
2 changes: 2 additions & 0 deletions projects/aas-server/src/app/aas-index/aas-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export abstract class AASIndex {

public abstract remove(endpoint?: string, id?: string): Promise<boolean>;

public abstract clear(): Promise<void>;

public abstract reset(): Promise<void>;

protected toAbbreviation(referable: aas.Referable): string {
Expand Down
8 changes: 6 additions & 2 deletions projects/aas-server/src/app/aas-index/lowdb/lowdb-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,15 @@ export class LowDbIndex extends AASIndex {
return true;
}

public async reset(): Promise<void> {
public override async clear(): Promise<void> {
this.db.data.documents = [];
this.db.data.elements = [];
this.db.data.endpoints = this.variable.ENDPOINTS.map(endpoint => urlToEndpoint(endpoint));
this.db.data.endpoints = [];
await this.db.write();
}

public override async reset(): Promise<void> {
this.db.data.endpoints = this.variable.ENDPOINTS.map(endpoint => urlToEndpoint(endpoint));
await this.db.write();
}

Expand Down
22 changes: 20 additions & 2 deletions projects/aas-server/src/app/aas-index/mysql/mysql-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,24 @@ export class MySqlIndex extends AASIndex {
}
}

public override async reset(): Promise<void> {
public override async clear(): Promise<void> {
const connection = await this.connection;
try {
await connection.beginTransaction();
await connection.query<ResultSetHeader>('DELETE FROM `elements`;');
await connection.query<ResultSetHeader>('DELETE FROM `documents`;');
await connection.query<ResultSetHeader>('DELETE FROM `endpoints`;');
await connection.commit();
} catch (error) {
await connection.rollback();
throw error;
}
}

public override async reset(): Promise<void> {
const connection = await this.connection;
try {
await connection.beginTransaction();
await this.addDefaultEndpoints(connection);
await connection.commit();
} catch (error) {
Expand Down Expand Up @@ -463,7 +474,14 @@ export class MySqlIndex extends AASIndex {

const result = await connection.query<MySqlEndpoint[]>('SELECT * FROM `endpoints`');
if (result[0].length === 0) {
await this.addDefaultEndpoints(connection);
try {
connection.beginTransaction();
await this.addDefaultEndpoints(connection);
connection.commit();
} catch (error) {
connection.rollback();
throw error;
}
}

return connection;
Expand Down
35 changes: 17 additions & 18 deletions projects/aas-server/src/app/aas-provider/aas-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,16 @@ export class AASProvider {
}

this.resetRequested = true;
await this.index.clear();
this.wsServer.notify('IndexChange', {
type: 'AASServerMessage',
data: {
type: 'Reset',
} as AASServerMessage,
});

if (this.taskHandler.empty(this)) {
await this.doResetAsync();
await this.restart();
}
}

Expand Down Expand Up @@ -367,18 +374,10 @@ export class AASProvider {
return nodes;
}

private async doResetAsync(): Promise<void> {
await this.index.reset();

this.wsServer.notify('IndexChange', {
type: 'AASServerMessage',
data: {
type: 'Reset',
} as AASServerMessage,
});

private async restart(): Promise<void> {
this.resetRequested = false;
this.startScan();
await this.index.reset();
await this.startScan();
this.logger.info('AAS Server configuration restored.');
}

Expand Down Expand Up @@ -444,19 +443,19 @@ export class AASProvider {
}

this.taskHandler.delete(result.taskId);
const endpoint = await this.index.getEndpoint(task.name);
setTimeout(this.scanContainer, this.timeout, result.taskId, endpoint);
if ((await await this.index.hasEndpoint(task.name)) === true) {
const endpoint = await this.index.getEndpoint(task.name);
setTimeout(this.scanContainer, this.timeout, result.taskId, endpoint);
}

if (result.messages) {
this.logger.start(`scan ${task.name ?? 'undefined'}`);
result.messages.forEach(message => this.logger.log(message));
this.logger.stop();
}

if (this.resetRequested) {
if (this.taskHandler.empty(this)) {
await this.doResetAsync();
}
if (this.resetRequested && this.taskHandler.empty(this)) {
await this.restart();
}
};

Expand Down

0 comments on commit eebc561

Please sign in to comment.