Skip to content

Commit

Permalink
fixato errore che non permetteva di gestire correttamente lo stato di…
Browse files Browse the repository at this point in the history
… Timeout
  • Loading branch information
leonidus96 committed Mar 20, 2024
1 parent 16d8ed3 commit 43c939f
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 44 deletions.
20 changes: 16 additions & 4 deletions src/app/plugins/actions-manager/actions-manager.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export class ActionsManagerComponent extends WidgetBaseComponent implements OnIn
nodeColors = {
INACTIVE: 'white',
ACTIVE: 'white',
RUNNING: 'yellow',
RUNNING: 'greenyellow',
FAILED: 'red',
DONE: 'green'
DONE: 'green',
TIMEOUT: 'yellow'
}

get filteredActions(): Action[] {
Expand Down Expand Up @@ -106,7 +107,17 @@ export class ActionsManagerComponent extends WidgetBaseComponent implements OnIn
}, 2000)
}

this.checkAsyncRequestStatus(reqID, undefined, onRunning, onDone, onFailed)
const onTimeout = () => {

this.updateActionState(selectedAction, ActionState.TIMEOUT)
setTimeout(() => {
this.actions.forEach(action => {
this.updateActionState(action, ActionState.ACTIVE)
})
}, 2000)
}

this.checkAsyncRequestStatus(reqID, undefined, onRunning, onDone, onFailed,onTimeout)

})
}
Expand Down Expand Up @@ -144,5 +155,6 @@ enum ActionState {
INACTIVE = "INACTIVE",
RUNNING = "RUNNING",
DONE = "DONE",
FAILED = "FAILED"
FAILED = "FAILED",
TIMEOUT = "TIMEOUT"
}
2 changes: 1 addition & 1 deletion src/app/plugins/fsm/fsm.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

.edge {
stroke: black;
stroke-width: 2;
stroke-width: 1;
}

.arrow {
Expand Down
2 changes: 1 addition & 1 deletion src/app/plugins/fsm/fsm.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<ng-container *defsTemplate>
<svg>
<marker id="arrow" viewBox="0 -5 10 10" refX="9" refY="0" markerWidth="6" markerHeight="6" orient="auto">
<marker id="arrow" viewBox="0 -5 10 10" refX="8" refY="0" markerWidth="6" markerHeight="6" orient="auto">
<path d="M0,-5L10,0L0,5 z"></path>
</marker>
</svg>
Expand Down
66 changes: 59 additions & 7 deletions src/app/plugins/fsm/fsm.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ export class FsmComponent extends WidgetBaseComponent implements OnInit {
nodeColors = {
INACTIVE: 'white',
ACTIVE: 'white',
RUNNING: 'yellow',
RUNNING: 'greenyellow',
FAILED: 'red',
CURRENT: 'white',
DONE: 'green'
DONE: 'green',
TIMEOUT: 'yellow'
}

isLoading = true
Expand Down Expand Up @@ -217,10 +218,7 @@ export class FsmComponent extends WidgetBaseComponent implements OnInit {

this.updateNodeState(selectedNode,NodeStatus.DONE)
const reachableNodes = this.findReachableNodes(selectedNode.id)
//console.log(`Reachable nodes from ${selectedNode.id}:`)
//console.log(reachableNodes)
for(let reachableNode of reachableNodes){
//console.log(reachableNode.id, " ATTIVATO")
this.updateNodeState(reachableNode,NodeStatus.ACTIVE)
}
this.graphy.setFocusToNode(selectedNode.id)
Expand All @@ -229,10 +227,64 @@ export class FsmComponent extends WidgetBaseComponent implements OnInit {
}

const onFailed = () => {
this.updateNodeState(selectedNode,NodeStatus.FAILED)

//se è un nodo collegato ad "init" invia il trigger di restart
const terminalNode = this.terminalNodes.find(node => node.nodeID === selectedNode.id)
if(terminalNode){
this.fsmRunStep(terminalNode.restartTrigger).subscribe(reqID => {

const onRestartDone = () => {
this.updateNodeState(selectedNode,NodeStatus.FAILED)
const reachableNodes = this.findReachableNodes(selectedNode.id)
for(let reachableNode of reachableNodes){
this.updateNodeState(reachableNode,NodeStatus.ACTIVE)
}
}
this.checkAsyncRequestStatus(reqID,undefined,undefined,onRestartDone)
})

} else {

this.updateNodeState(selectedNode,NodeStatus.FAILED)
const reachableNodes = this.findReachableNodes(selectedNode.id)
for(let reachableNode of reachableNodes){
this.updateNodeState(reachableNode,NodeStatus.ACTIVE)
}
this.graphy.setFocusToNode(selectedNode.id)
}

}

const onTimeout = () => {

//se è un nodo collegato ad "init" invia il trigger di restart
const terminalNode = this.terminalNodes.find(node => node.nodeID === selectedNode.id)
if(terminalNode){
this.fsmRunStep(terminalNode.restartTrigger).subscribe(reqID => {

const onRestartDone = () => {
this.updateNodeState(selectedNode,NodeStatus.TIMEOUT)
const reachableNodes = this.findReachableNodes(selectedNode.id)
for(let reachableNode of reachableNodes){
this.updateNodeState(reachableNode,NodeStatus.ACTIVE)
}
}
this.checkAsyncRequestStatus(reqID,undefined,undefined,onRestartDone)
})

} else {

this.updateNodeState(selectedNode,NodeStatus.TIMEOUT)
const reachableNodes = this.findReachableNodes(selectedNode.id)
for(let reachableNode of reachableNodes){
this.updateNodeState(reachableNode,NodeStatus.ACTIVE)
}
this.graphy.setFocusToNode(selectedNode.id)
}

}

this.checkAsyncRequestStatus(reqID,undefined,onRunning,onDone,onFailed)
this.checkAsyncRequestStatus(reqID,undefined,onRunning,onDone,onFailed,onTimeout)

})

Expand Down
15 changes: 13 additions & 2 deletions src/app/plugins/services-manager/services-manager.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class ServicesManagerComponent extends WidgetBaseComponent implements OnI
ACTIVE: 'white',
RUNNING: 'yellow',
FAILED: 'red',
DONE: 'green'
DONE: 'green',
TIMEOUT: 'red'
}

get filteredServices(): Service[] {
Expand Down Expand Up @@ -90,7 +91,17 @@ export class ServicesManagerComponent extends WidgetBaseComponent implements OnI
}, 2000)
}

this.checkAsyncRequestStatus(reqID, undefined, onRunning, onDone, onFailed)
const onTimeout = () => {

this.updateServiceState(selectedService, ServiceState.TIMEOUT)
setTimeout(() => {
this.services.forEach(action => {
this.updateServiceState(action, ServiceState.ACTIVE)
})
}, 2000)
}

this.checkAsyncRequestStatus(reqID, undefined, onRunning, onDone, onFailed,onTimeout)

})
}
Expand Down
58 changes: 32 additions & 26 deletions src/app/services/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ApiService implements IApiService {

private asyncRequestsStatus: { [key: string]: ICubRequestStatus } = {}

constructor(private http: HttpClient,private localStorageService:LocalStorageService, private sessionStorageService:SessionStorageService) {
constructor(private http: HttpClient, private localStorageService: LocalStorageService, private sessionStorageService: SessionStorageService) {
}

getRobots() {
Expand Down Expand Up @@ -79,8 +79,8 @@ export class ApiService implements IApiService {
}),
map(argsTemplate => {
application.argsTemplate = argsTemplate;
application.args = this.sessionStorageService.getApplicationArgs(robotName,application.name) || {}
application.isConfigured = this.sessionStorageService.getIsApplicationConfigured(robotName,application.name)
application.args = this.sessionStorageService.getApplicationArgs(robotName, application.name) || {}
application.isConfigured = this.sessionStorageService.getIsApplicationConfigured(robotName, application.name)
const savedDashboard = this.localStorageService.getDashboardConfig(application)
for (const [pluginName, componentName] of Object.entries(pluginIndex)) {
const pluginDefaultData = (savedDashboard && savedDashboard[pluginName]) ? savedDashboard[pluginName] : defaultDashboardConfig[pluginName];
Expand Down Expand Up @@ -156,28 +156,28 @@ export class ApiService implements IApiService {
}

getApplicationFSM(robotName: string, appName: string, appPort: string) {
return this.runService<getApplicationFSMResponse>(robotName,appName,appPort,"fsm.toJSON").pipe(
return this.runService<getApplicationFSMResponse>(robotName, appName, appPort, "fsm.toJSON").pipe(
map(response => {

let nodes: FSMNode[] = response.states.map(state => {
let node:FSMNode = {
name:state.name,
id:state.name,
description:state.description
let node: FSMNode = {
name: state.name,
id: state.name,
description: state.description
}
return node
})

let edges: FSMEdge[] = response.transitions.map(transition => {
let edge:FSMEdge = {
let edge: FSMEdge = {
sourceID: transition.source,
targetID:transition.dest,
trigger:transition.trigger
targetID: transition.dest,
trigger: transition.trigger
}
return edge
})

let initState:FSMNode = {
let initState: FSMNode = {
name: response.initial_state,
id: response.initial_state,
description: ""
Expand All @@ -201,13 +201,13 @@ export class ApiService implements IApiService {
const path = `${this.scheme}://${this.hostname}:${this.port}/pyicub/${robotName}/${appName}`;
return this.http.get<GetApplicationsServicesResponse>(path).pipe(
map(response => {
let services:Service[] = Object.entries(response).map(([name, service]) =>{
let services: Service[] = Object.entries(response).map(([name, service]) => {
const argsTemplate = this.getArgsTemplate(service.signature);
const newService:Service = {
name:name,
argsTemplate:argsTemplate,
args:{},
state:ServiceState.ACTIVE
const newService: Service = {
name: name,
argsTemplate: argsTemplate,
args: {},
state: ServiceState.ACTIVE
}
return newService
})
Expand All @@ -218,10 +218,12 @@ export class ApiService implements IApiService {
}

checkAsyncRequestStatus(requestID: string, initCallback: () => void = () => {
}, runningCallback: () => void = () => {
}, doneCallback: (retval: any) => void = () => {
}, failedCallback: () => void = () => {
}) {
}, runningCallback: () => void = () => {
}, doneCallback: (retval: any) => void = () => {
}, failedCallback: () => void = () => {
},
timeoutCallback: () => void = () => {
}) {
const url = new URL(requestID);
const requestStatusPath = `${this.scheme}://${this.hostname}:${url.port}${url.pathname}`;
this.asyncRequestsStatus[requestID] = ICubRequestStatus.INIT
Expand All @@ -248,6 +250,10 @@ export class ApiService implements IApiService {
this.asyncRequestsStatus[requestID] = ICubRequestStatus.FAILED;
failedCallback();
break;
case ICubRequestStatus.TIMEOUT:
this.asyncRequestsStatus[requestID] = ICubRequestStatus.TIMEOUT;
timeoutCallback();
break;
default:
console.log("unknown response status:")
console.log(response.status)
Expand Down Expand Up @@ -493,12 +499,12 @@ export class ApiService implements IApiService {
return this.runService<GetRobotActionsResponse>(robotName, "helper", this.port, "actions.getActions")
}

playActionSync(robotName:string,actionID:string){
return this.runService<void>(robotName,"helper",this.port,"actions.playAction",{action_id:actionID})
playActionSync(robotName: string, actionID: string) {
return this.runService<void>(robotName, "helper", this.port, "actions.playAction", {action_id: actionID})
}

playActionAsync(robotName:string,actionID:string){
return this.runServiceAsync(robotName,"helper",this.port,"actions.playAction",{action_id:actionID})
playActionAsync(robotName: string, actionID: string) {
return this.runServiceAsync(robotName, "helper", this.port, "actions.playAction", {action_id: actionID})
}

}
Expand Down
3 changes: 2 additions & 1 deletion src/app/types/FSM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export enum NodeStatus{
ACTIVE = "ACTIVE",
RUNNING = "RUNNING",
DONE = "DONE" ,
FAILED = "FAILED"
FAILED = "FAILED",
TIMEOUT = "TIMEOUT"
}

export interface FSMNode {
Expand Down
3 changes: 2 additions & 1 deletion src/app/types/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export enum ServiceState {
INACTIVE = "INACTIVE",
RUNNING = "RUNNING",
DONE = "DONE",
FAILED = "FAILED"
FAILED = "FAILED",
TIMEOUT = "TIMEOUT"
}

export interface Service{
Expand Down
3 changes: 2 additions & 1 deletion src/app/widget-base/widget-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export class WidgetBaseComponent {
}, runningCallback: () => void = () => {
}, doneCallback: (retval: any) => void = () => {
}, failedCallback: () => void = () => {
},timeoutCallback: () => void = () => {
}) {
return this.apiService.checkAsyncRequestStatus(requestID, initCallback, runningCallback, doneCallback, failedCallback)
return this.apiService.checkAsyncRequestStatus(requestID, initCallback, runningCallback, doneCallback, failedCallback,timeoutCallback)
}

runService(serviceName: string, body: any) {
Expand Down

0 comments on commit 43c939f

Please sign in to comment.