Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
S
server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
monticore
EmbeddedMontiArc
simulators
server
Commits
3364585a
Commit
3364585a
authored
May 19, 2019
by
hengwen
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add endpoint for checking status of specific simulation task
parent
261e17c7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
15 deletions
+57
-15
restful/openapi.yml
restful/openapi.yml
+1
-1
restful/src/main/java/server/restful/view/SimulationView.java
...ful/src/main/java/server/restful/view/SimulationView.java
+34
-11
restful/src/test/java/server/restful/view/SimulationViewTest.java
...src/test/java/server/restful/view/SimulationViewTest.java
+22
-3
No files found.
restful/openapi.yml
View file @
3364585a
...
...
@@ -139,7 +139,7 @@ paths:
description
:
"
success"
schema
:
type
:
string
enum
:
[
running
,
finished
,
not_found
]
enum
:
[
READY
,
RUNNING
,
FINISHED
,
FAILED
]
/simulation/{id}/map-data/{sectorIdx}
:
get
:
tags
:
...
...
restful/src/main/java/server/restful/view/SimulationView.java
View file @
3364585a
package
server.restful.view
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.server.ResponseStatusException
;
import
server.restful.dao.SimulationDAO
;
import
server.restful.model.MapModel
;
import
server.restful.model.SimulationModel
;
...
...
@@ -11,7 +13,9 @@ import server.restful.service.MapService;
import
server.restful.service.SimulationService
;
import
java.io.FileNotFoundException
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"/simulation"
)
...
...
@@ -20,9 +24,9 @@ public class SimulationView {
public
SimulationModel
createSimulation
(
@RequestParam
(
"scenario_id"
)
int
scenarioID
,
@RequestParam
(
"num_sectors"
)
int
numSectors
){
)
{
int
simID
=
SimulationDAO
.
create
(
scenarioID
,
numSectors
);
return
new
SimulationModel
(){{
return
new
SimulationModel
()
{{
setId
(
simID
);
setScenarioID
(
scenarioID
);
setNumSectors
(
numSectors
);
...
...
@@ -30,30 +34,47 @@ public class SimulationView {
}};
}
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
GET
)
public
List
<
SimulationModel
>
getSimulation
(){
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
GET
)
public
List
<
SimulationModel
>
getSimulation
()
{
return
SimulationDAO
.
getAll
();
}
@PostMapping
(
"/{id}/start"
)
public
String
startSimulation
(
@PathVariable
(
"id"
)
int
simulationID
){
ServiceRegistry
registry
=
RegistryFactory
.
get
Zookeeper
Registry
();
public
String
startSimulation
(
@PathVariable
(
"id"
)
int
simulationID
)
{
ServiceRegistry
registry
=
RegistryFactory
.
get
Default
Registry
();
try
{
Thread
thread
=
new
Thread
(
new
SimulationService
(
simulationID
,
registry
)
new
SimulationService
(
simulationID
,
registry
)
);
thread
.
start
();
return
"ok"
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
}
finally
{
registry
.
releaseAll
();
}
return
"simulation failed"
;
}
@GetMapping
(
"/{id}/status"
)
public
Map
<
String
,
SimulationService
.
SimulationStatus
>
getStatus
(
@PathVariable
(
"id"
)
int
simulationID
)
{
if
(
SimulationService
.
getInstances
()!=
null
&&
SimulationService
.
getInstances
().
containsKey
(
simulationID
))
{
return
new
HashMap
<
String
,
SimulationService
.
SimulationStatus
>()
{{
put
(
"status"
,
SimulationService
.
getInstances
().
get
(
simulationID
).
getStatus
());
}};
}
throw
new
ResponseStatusException
(
HttpStatus
.
NOT_FOUND
,
String
.
format
(
"Simulation instance %d not started yet. Please start it using POST /simulation/%d"
,
simulationID
,
simulationID
)
);
}
@GetMapping
(
"/{id}/result"
)
public
List
<
VehicleModel
>
getResult
(
@PathVariable
(
"id"
)
int
simulationID
){
public
List
<
VehicleModel
>
getResult
(
@PathVariable
(
"id"
)
int
simulationID
)
{
return
SimulationDAO
.
getSimulationResultByID
(
simulationID
);
}
...
...
@@ -61,7 +82,7 @@ public class SimulationView {
public
MapModel
getResult
(
@PathVariable
(
"id"
)
int
simulationID
,
@PathVariable
(
"sectorIdx"
)
int
sectorIdx
){
)
{
SimulationModel
simulationModel
=
SimulationDAO
.
getByID
(
simulationID
);
SimulationService
simulationService
=
new
SimulationService
(
simulationID
);
try
{
...
...
@@ -73,5 +94,7 @@ public class SimulationView {
e
.
printStackTrace
();
}
return
null
;
};
}
;
}
restful/src/test/java/server/restful/view/SimulationViewTest.java
View file @
3364585a
...
...
@@ -5,6 +5,8 @@ import org.junit.Test;
import
org.springframework.test.web.servlet.MvcResult
;
import
org.springframework.test.web.servlet.RequestBuilder
;
import
org.springframework.test.web.servlet.request.MockMvcRequestBuilders
;
import
server.restful.registry.RegistryFactory
;
import
server.restful.service.SimulationService
;
public
class
SimulationViewTest
extends
AbstractViewTest
{
...
...
@@ -24,8 +26,25 @@ public class SimulationViewTest extends AbstractViewTest{
}
@Test
public
void
testStartSimulation
()
throws
Exception
{
// TODO mock simulation.start
// RequestBuilder builder = MockMvcRequestBuilders.post("/simulation/1/start");
public
void
testSimulationStatus
()
throws
Exception
{
// simulation 1 not exist
RequestBuilder
builder
=
MockMvcRequestBuilders
.
get
(
"/simulation/1/status"
);
MvcResult
result
=
null
;
result
=
mvc
.
perform
(
builder
).
andReturn
();
Assert
.
assertEquals
(
404
,
result
.
getResponse
().
getStatus
());
// simulation 2 should be ready after we initialized its simulation service instance
new
SimulationService
(
2
,
RegistryFactory
.
getZookeeperRegistry
());
builder
=
MockMvcRequestBuilders
.
get
(
"/simulation/2/status"
);
result
=
mvc
.
perform
(
builder
).
andReturn
();
Assert
.
assertEquals
(
200
,
result
.
getResponse
().
getStatus
());
Assert
.
assertTrue
(
result
.
getResponse
().
getContentAsString
().
contains
(
"READY"
));
// simulation 2 should failed, since there are no available sub-simulators and rmi servers
SimulationService
.
getInstances
().
get
(
2
).
run
();
builder
=
MockMvcRequestBuilders
.
get
(
"/simulation/2/status"
);
result
=
mvc
.
perform
(
builder
).
andReturn
();
Assert
.
assertEquals
(
200
,
result
.
getResponse
().
getStatus
());
Assert
.
assertTrue
(
result
.
getResponse
().
getContentAsString
().
contains
(
"FAILED"
));
}
}
\ No newline at end of file
Hengwen Zhang
@hengwen.zhang
mentioned in commit
3ca63f88
·
May 19, 2019
mentioned in commit
3ca63f88
mentioned in commit 3ca63f888dbc50d687a0eedb7516351508f05e6b
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment