Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/gtf-notebook-runtime-fix' into u…
Browse files Browse the repository at this point in the history
…pdate-brick-141
  • Loading branch information
gtfierro committed Sep 13, 2024
2 parents bc677e3 + 62b95f4 commit c4ca75f
Show file tree
Hide file tree
Showing 20 changed files with 441 additions and 79 deletions.
69 changes: 65 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
poetry run isort . --check
poetry run black . --check
# The "testing" job verifies the base SDK functionality across
# all supported Python versions.
testing:
needs: styling
runs-on: ubuntu-latest
Expand Down Expand Up @@ -62,19 +64,78 @@ jobs:
run: poetry run mypy --ignore-missing-imports
- name: unit tests
run: poetry run pytest tests/unit --cov=./ --cov-report=xml
- name: build tests
run: poetry build

# We only run "integration" tests on the latest Python version.
# These tests detect if changes to ontologies, libraries, models and BuildingMOTIF
# affect correct operation of notebooks and BACnet scans. Library integration testing
# is a separate job
integration:
needs: styling
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-java@v4 # for topquadrant shacl support
with:
distribution: 'temurin'
java-version: '21'
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: install-poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0
virtualenvs-in-project: false
virtualenvs-path: ~/.virtualenvs
- name: poetry install
run: poetry install --all-extras
- name: integration tests
run: poetry run pytest tests/integration
- name: library tests
run: poetry run pytest tests/library
- name: bacnet tests
run: |
cd tests/integration/fixtures/bacnet
docker compose build device buildingmotif
docker compose run -d device
docker compose run buildingmotif poetry run pytest -m bacnet
docker compose down
- name: build tests
run: poetry build
# We only run "library" tests on the latest Python version.
# These tests detect if changes to ontologies, libraries, models and BuildingMOTIF
# affect correct operation of templates, shapes, and validation
libraries:
needs: styling
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-java@v4 # for topquadrant shacl support
with:
distribution: 'temurin'
java-version: '21'
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: install-poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0
virtualenvs-in-project: false
virtualenvs-path: ~/.virtualenvs
- name: poetry install
run: poetry install --all-extras
- name: library tests
run: poetry run pytest tests/library

coverage:
needs: testing
Expand Down
16 changes: 16 additions & 0 deletions buildingmotif-app/src/app/handle-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HttpErrorResponse } from '@angular/common/http';
import { throwError } from 'rxjs';

export function handleError(error: HttpErrorResponse) {
if (error.status === 0) {
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred:', error.error);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong.
console.error(
`Backend returned code ${error.status}, body was: `, error.error);
}
// Return an observable with a user-facing error message.
return throwError(() => new Error(`${error.status}: ${error.error}`));
}
32 changes: 10 additions & 22 deletions buildingmotif-app/src/app/library/library.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { HttpErrorResponse, HttpResponse } from '@angular/common/http';

import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { environment } from '../../environments/environment';
import { handleError } from '../handle-error';

const API_URL = environment.API_URL;

export interface Library {
name: string;
Expand Down Expand Up @@ -35,42 +39,26 @@ export class LibraryService {
constructor(private http: HttpClient) { }

getAllLibraries() {
return this.http.get<Library[]>("http://localhost:5000/libraries")
return this.http.get<Library[]>(API_URL + `/libraries`)
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);
}

getAllShapes() {
return this.http.get<{[definition_type: string]: Shape[]}>("http://localhost:5000/libraries/shapes")
return this.http.get<{[definition_type: string]: Shape[]}>(API_URL + `/libraries/shapes`)
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);
}

getLibrarysTemplates(library_id: number) {
return this.http.get<Library>(`http://localhost:5000/libraries/${library_id}?expand_templates=True`)
return this.http.get<Library>(API_URL + `/libraries/${library_id}?expand_templates=True`)
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError), // then handle the error
catchError(handleError), // then handle the error
);
}


private handleError(error: HttpErrorResponse) {
if (error.status === 0) {
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred:', error.error);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong.
console.error(
`Backend returned code ${error.status}, body was: `, error.error);
}
// Return an observable with a user-facing error message.
return throwError(() => new Error(`${error.status}: ${error.error}`));
}

}
20 changes: 12 additions & 8 deletions buildingmotif-app/src/app/model-detail/model-detail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Model } from '../types'
import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { environment } from '../../environments/environment';
import { handleError } from '../handle-error';

const API_URL = environment.API_URL;

@Injectable({
providedIn: 'root'
Expand All @@ -13,36 +17,36 @@ export class ModelDetailService {
constructor(private http: HttpClient) { }

getModel(id: number) {
return this.http.get<Model>(`http://localhost:5000/models/${id}`)
return this.http.get<Model>(API_URL + `/models/${id}`)
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);
}

getModelGraph(id: number) {
return this.http.get(`http://localhost:5000/models/${id}/graph`, {responseType: 'text'})
return this.http.get(API_URL + `/models/${id}/graph`, {responseType: 'text'})
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);
}

getTargetNodes(id: number) {
return this.http.get<string[]>(`http://localhost:5000/models/${id}/target_nodes`)
return this.http.get<string[]>(API_URL + `/models/${id}/target_nodes`)
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);
}

updateModelGraph(id: number, newGraph: string | File, append: boolean = false) {
const headers = {'Content-Type': "application/xml"}

return this.http[append? "patch": "put"](`http://localhost:5000/models/${id}/graph`, newGraph, {headers, responseType: 'text'})
return this.http[append? "patch": "put"](API_URL + `/models/${id}/graph`, newGraph, {headers, responseType: 'text'})
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);
}

Expand Down
8 changes: 6 additions & 2 deletions buildingmotif-app/src/app/model-new/model-new.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Model } from '../types'
import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { environment } from '../../environments/environment';
import { handleError } from '../handle-error';

const API_URL = environment.API_URL;

@Injectable({
providedIn: 'root'
Expand All @@ -15,10 +19,10 @@ export class ModelNewService {
createModel(name: string, description: string): Observable<Model | any> {
const headers = {'Content-Type': "application/json"}

return this.http.post(`http://localhost:5000/models`, {name: name, description: description}, {headers, responseType: 'json'})
return this.http.post(API_URL + `/models`, {name: name, description: description}, {headers, responseType: 'json'})
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { HttpErrorResponse } from '@angular/common/http';
import { Model } from '../types'
import { throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { environment } from '../../environments/environment';
import { handleError } from '../handle-error';

const API_URL = environment.API_URL;
@Injectable({
providedIn: 'root'
})
Expand All @@ -15,13 +18,13 @@ export class ModelValidateService {
validateModel(modelId: number, args: number[]) {
const headers = {'Content-Type': "application/json"}

return this.http.post<ValidationResponse>(`http://localhost:5000/models/${modelId}/validate`,
return this.http.post<ValidationResponse>(API_URL + `/models/${modelId}/validate`,
{"library_ids": args},
{headers, responseType: 'json'}
)
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Model } from '../types'
import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { environment } from '../../environments/environment';
import { handleError } from '../handle-error';

const API_URL = environment.API_URL;

@Injectable({
providedIn: 'root'
Expand All @@ -15,10 +19,10 @@ export class PointlabelParserService {
parse(pointlabels: string, parsers: string): Observable<Model | any> {
const headers = {'Content-Type': "application/json"}

return this.http.post(`http://localhost:5000/parsers`, {point_labels: pointlabels, parsers}, {headers, responseType: 'json'})
return this.http.post(API_URL + `/parsers`, {point_labels: pointlabels, parsers}, {headers, responseType: 'json'})
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { HttpErrorResponse } from '@angular/common/http';
import { Model } from '../types'
import { throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { environment } from '../../environments/environment';
import { handleError } from '../handle-error';

const API_URL = environment.API_URL;

@Injectable({
providedIn: 'root'
Expand All @@ -15,13 +19,13 @@ export class ShapeValidationService {
validateModelShape(modelId: number, shape_collection_ids: number[], shape_uris: string[], target_class: string) {
const headers = {'Content-Type': "application/json"}

return this.http.post<Record<string, string[]>>(`http://localhost:5000/models/${modelId}/validate_shape`,
return this.http.post<Record<string, string[]>>(API_URL + `/models/${modelId}/validate_shape`,
{shape_collection_ids, shape_uris, target_class},
{headers, responseType: 'json'}
)
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { HttpErrorResponse, HttpResponse } from '@angular/common/http';

import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { environment } from '../../environments/environment';
import { handleError } from '../handle-error';

const API_URL = environment.API_URL;

export interface Template {
name: string;
Expand All @@ -20,10 +24,10 @@ export class TemplateDetailService {
constructor(private http: HttpClient) { }

getTemplate(id: number, includeParameters: boolean =false) {
return this.http.get<Template>(`http://localhost:5000/templates/${id}?parameters=${includeParameters}`)
return this.http.get<Template>(API_URL + `/templates/${id}?parameters=${includeParameters}`)
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { HttpErrorResponse, HttpResponse } from '@angular/common/http';

import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { environment } from '../../environments/environment';
import { handleError } from '../handle-error';

const API_URL = environment.API_URL;

export interface Template {
name: string;
Expand All @@ -25,26 +29,26 @@ export class TemplateEvaluateService {
}, {})

return this.http.post(
`http://localhost:5000/templates/${templateId}/evaluate/bindings`,
API_URL + `/templates/${templateId}/evaluate/bindings`,
{model_id: modelId, bindings},
{responseType: 'text'}
)
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);

}

evaluateTemplateIngress(templateId: number, modelId: number, file: File) {
return this.http.post(
`http://localhost:5000/templates/${templateId}/evaluate/ingress?model_id=${modelId}`,
API_URL + `/templates/${templateId}/evaluate/ingress?model_id=${modelId}`,
file,
{responseType: 'text'}
)
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
catchError(handleError) // then handle the error
);

}
Expand Down
Loading

0 comments on commit c4ca75f

Please sign in to comment.