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

feat: switch TransferProcessService to connector-client #128

Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@angular/platform-browser": "~15.2.10",
"@angular/platform-browser-dynamic": "~15.2.10",
"@angular/router": "~15.2.10",
"@think-it-labs/edc-connector-client": "^0.2.0-beta-6",
"@think-it-labs/edc-connector-client": "^0.2.0-beta-7",
"rxjs": "~7.8.1",
"zone.js": "~0.11.8"
},
Expand Down
janpmeyer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ describe('ContractViewerComponent', () => {
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {Component, Inject, OnInit} from '@angular/core';
import {
AssetService,
ContractAgreementService, IdResponseDto,
TransferProcessService,
TransferRequestDto
ContractAgreementService,
TransferProcessService
} from "../../../mgmt-api-client";
import {from, Observable, of} from "rxjs";
import { Asset, ContractAgreement } from "@think-it-labs/edc-connector-client";
import { Asset, ContractAgreement, TransferProcessInput, IdResponse } from "../../../mgmt-api-client/model";
import {ContractOffer} from "../../models/contract-offer";
import {filter, first, map, switchMap, tap} from "rxjs/operators";
import {NotificationService} from "../../services/notification.service";
Expand Down Expand Up @@ -65,10 +64,6 @@ export class ContractViewerComponent implements OnInit {
return '';
}

getAsset(assetId?: string): Observable<Asset> {
return assetId ? this.assetService.getAsset(assetId): of();
}

onTransferClicked(contract: ContractAgreement) {
const dialogRef = this.dialog.open(CatalogBrowserTransferDialog);

Expand All @@ -93,25 +88,23 @@ export class ContractViewerComponent implements OnInit {
return !!this.runningTransfers.find(rt => rt.contractId === contractId);
}

private createTransferRequest(contract: ContractAgreement, storageTypeId: string): Observable<TransferRequestDto> {
return this.getContractOfferForAssetId(contract["edc:assetId"]!).pipe(map(contractOffer => {
return {
private createTransferRequest(contract: ContractAgreement, storageTypeId: string): Observable<TransferProcessInput> {
return this.getContractOfferForAssetId(contract.assetId!).pipe(map(contractOffer => {

const iniateTransfer : TransferProcessInput = {
assetId: contractOffer.assetId,
contractId: contract.id,
connectorAddress: contractOffer.originator,

connectorId: "consumer", //doesn't matter, but cannot be null
contractId: contract.id,
dataDestination: {
"type": storageTypeId,
account: this.homeConnectorStorageAccount, // CAUTION: hardcoded value for AzureBlob
// container: omitted, so it will be auto-assigned by the EDC runtime
},
managedResources: true,
transferType: {isFinite: true}, //must be there, otherwise NPE on backend
connectorAddress: contractOffer.originator,
protocol: 'dataspace-protocol-http',
"@context": {
"edc": "https://w3id.org/edc/v0.0.1/ns/"
}
};

return iniateTransfer;
}));

}
Expand All @@ -132,10 +125,10 @@ export class ContractViewerComponent implements OnInit {
}))
}

private startPolling(transferProcessId: IdResponseDto, contractId: string) {
private startPolling(transferProcessId: IdResponse, contractId: string) {
// track this transfer process
this.runningTransfers.push({
processId: transferProcessId["@id"]!,
processId: transferProcessId.id!,
state: TransferProcessStates.REQUESTED,
contractId: contractId
});
Expand All @@ -149,12 +142,12 @@ export class ContractViewerComponent implements OnInit {
private pollRunningTransfers() {
return () => {
from(this.runningTransfers) //create from array
.pipe(switchMap(t => this.catalogService.getTransferProcessesById(t.processId)), // fetch from API
filter(tpDto => ContractViewerComponent.isFinishedState(tpDto["edc:state"]!)), // only use finished ones
tap(tpDto => {
.pipe(switchMap(runningTransferProcess => this.catalogService.getTransferProcessesById(runningTransferProcess.processId)), // fetch from API
filter(transferprocess => ContractViewerComponent.isFinishedState(transferprocess.state!)), // only use finished ones
tap(transferProcess => {
// remove from in-progress
this.runningTransfers = this.runningTransfers.filter(rtp => rtp.processId !== tpDto["@id"])
this.notificationService.showInfo(`Transfer [${tpDto["@id"]}] complete!`, "Show me!", () => {
this.runningTransfers = this.runningTransfers.filter(rtp => rtp.processId !== transferProcess.id)
this.notificationService.showInfo(`Transfer [${transferProcess.id}] complete!`, "Show me!", () => {
this.router.navigate(['/transfer-history'])
})
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,32 @@
</button>
<mat-paginator [length]="transferProcesses.length" pageSize="transferProcesses.length" hidePageSize="true"></mat-paginator>
</div>

<table mat-table [dataSource]="transferProcesses" class="transfer-history-table">

<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef scope="col">Id</th>
<td mat-cell *matCellDef="let item">{{item['@id']}}</td>
<td mat-cell *matCellDef="let item">{{item.id}}</td>
</ng-container>

<ng-container matColumnDef="state">
<th mat-header-cell *matHeaderCellDef scope="col">State</th>
<td mat-cell *matCellDef="let item">{{item['edc:state']}}</td>
</ng-container>

<ng-container matColumnDef="lastUpdated">
<th mat-header-cell *matHeaderCellDef scope="col">Last updated</th>
<td mat-cell *matCellDef="let item">{{asDate(item['edc:stateTimestamp'])}}</td>
<td mat-cell *matCellDef="let item">{{item.state}}</td>
</ng-container>

<ng-container matColumnDef="connectorId">
<th mat-header-cell *matHeaderCellDef scope="col">ConnectorId</th>
<td mat-cell *matCellDef="let item">{{item['edc:connectorId']}}</td>
<td mat-cell *matCellDef="let item">{{item.connectorId}}</td>
</ng-container>

<ng-container matColumnDef="assetId">
<th mat-header-cell *matHeaderCellDef scope="col">AssetId</th>
<td mat-cell *matCellDef="let item">{{item['edc:assetId']}}</td>
<td mat-cell *matCellDef="let item">{{item.assetId}}</td>
</ng-container>

<ng-container matColumnDef="contractId">
<th mat-header-cell *matHeaderCellDef scope="col">ContractId</th>
<td mat-cell *matCellDef="let item">{{item['edc:contractId']}}</td>
<td mat-cell *matCellDef="let item">{{item.contractId}}</td>
</ng-container>

<ng-container matColumnDef="action">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Component, OnInit} from '@angular/core';
import {Observable, of} from 'rxjs';
import {TransferProcessDto, TransferProcessService} from "../../../mgmt-api-client";
import {TransferProcessService} from "../../../mgmt-api-client";
import {TransferProcess} from "../../../mgmt-api-client/model";
import {AppConfigService} from "../../../app/app-config.service";
import {ConfirmationDialogComponent, ConfirmDialogModel} from "../confirmation-dialog/confirmation-dialog.component";
import {MatDialog} from "@angular/material/dialog";
Expand All @@ -13,7 +14,7 @@ import {MatDialog} from "@angular/material/dialog";
export class TransferHistoryViewerComponent implements OnInit {

columns: string[] = ['id', 'state', 'lastUpdated', 'connectorId', 'assetId', 'contractId', 'action'];
transferProcesses$: Observable<TransferProcessDto[]> = of([]);
transferProcesses$: Observable<TransferProcess[]> = of([]);
storageExplorerLinkTemplate: string | undefined;

constructor(private transferProcessService: TransferProcessService,
Expand All @@ -26,7 +27,7 @@ export class TransferHistoryViewerComponent implements OnInit {
this.storageExplorerLinkTemplate = this.appConfigService.getConfig()?.storageExplorerLinkTemplate
}

onDeprovision(transferProcess: TransferProcessDto): void {
onDeprovision(transferProcess: TransferProcess): void {

const dialogData = new ConfirmDialogModel("Confirm deprovision", `Deprovisioning resources for transfer [${transferProcess["@id"]}] will take some time and once started, it cannot be stopped.`)
dialogData.confirmColor = "warn";
Expand All @@ -36,21 +37,21 @@ export class TransferHistoryViewerComponent implements OnInit {

ref.afterClosed().subscribe(res => {
if (res) {
this.transferProcessService.deprovisionTransferProcess(transferProcess["@id"]!).subscribe(() => this.loadTransferProcesses());
this.transferProcessService.deprovisionTransferProcess(transferProcess["@id"]!).subscribe(() => this.loadTransferProcesses());
}
});
}

showStorageExplorerLink(transferProcess: TransferProcessDto) {
return transferProcess["edc:dataDestination"]?.properties?.type === 'AzureStorage' && transferProcess["edc:state"] === 'COMPLETED';
showStorageExplorerLink(transferProcess: TransferProcess) {
return transferProcess.dataDestination?.properties?.type === 'AzureStorage' && transferProcess.state === 'COMPLETED';
}

showDeprovisionButton(transferProcess: TransferProcessDto) {
return ['COMPLETED', 'PROVISIONED', 'REQUESTED', 'REQUESTED_ACK', 'IN_PROGRESS', 'STREAMING'].includes(transferProcess["edc:state"]!);
showDeprovisionButton(transferProcess: TransferProcess) {
return ['COMPLETED', 'PROVISIONED', 'REQUESTED', 'REQUESTED_ACK', 'IN_PROGRESS', 'STREAMING'].includes(transferProcess.state!);
}

loadTransferProcesses() {
this.transferProcesses$ = this.transferProcessService.queryAllTransferProcesses();
this.transferProcesses$ = this.transferProcessService.queryAllTransferProcesses();
}

asDate(epochMillis?: number) {
Expand Down
14 changes: 7 additions & 7 deletions src/modules/edc-demo/services/catalog-browser.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import {Catalog} from '../models/catalog';
import {ContractOffer} from '../models/contract-offer';
import {
ContractNegotiationService,
TransferProcessDto,
TransferProcessService,
TransferRequestDto,
} from "../../mgmt-api-client";
import {CONNECTOR_CATALOG_API, CONNECTOR_MANAGEMENT_API} from "../../app/variables";
// import TypeEnum = Policy.TypeEnum; //TODO Use TypeEnum https://github.com/Think-iT-Labs/edc-connector-client/issues/103
import {
ContractNegotiationRequest,
ContractNegotiation,
PolicyInput
PolicyInput,
TransferProcess,
TransferProcessInput
} from "../../mgmt-api-client/model";


Expand Down Expand Up @@ -93,16 +93,16 @@ export class CatalogBrowserService {
}, new Array<ContractOffer>()));
}

initiateTransfer(transferRequest: TransferRequestDto): Observable<string> {
return this.transferProcessService.initiateTransfer(transferRequest).pipe(map(t => t["@id"]!))
initiateTransfer(transferRequest: TransferProcessInput): Observable<string> {
return this.transferProcessService.initiateTransfer(transferRequest).pipe(map(t => t.id!))
}

getTransferProcessesById(id: string): Observable<TransferProcessDto> {
getTransferProcessesById(id: string): Observable<TransferProcess> {
return this.transferProcessService.getTransferProcess(id);
}

initiateNegotiation(initiate: ContractNegotiationRequest): Observable<string> {
return this.negotiationService.initiateContractNegotiation(initiate).pipe(map(t => t["@id"]!))
return this.negotiationService.initiateContractNegotiation(initiate).pipe(map(t => t.id!))
}

getNegotiationState(id: string): Observable<ContractNegotiation> {
Expand Down
Loading
Loading