-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(controller): add list api for run (#2815)
- Loading branch information
Showing
8 changed files
with
231 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
server/controller/src/main/java/ai/starwhale/mlops/api/protocol/run/RunVo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2022 Starwhale, Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package ai.starwhale.mlops.api.protocol.run; | ||
|
||
import ai.starwhale.mlops.domain.run.bo.Run; | ||
import ai.starwhale.mlops.domain.run.bo.RunStatus; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class RunVo { | ||
|
||
private Long id; | ||
private Long taskId; | ||
private RunStatus status; | ||
private String ip; | ||
private Long startTime; | ||
private Long finishTime; | ||
private String failedReason; | ||
|
||
public RunVo(Run run) { | ||
if (null == run) { | ||
return; | ||
} | ||
this.id = run.getId(); | ||
this.taskId = run.getTaskId(); | ||
this.status = run.getStatus(); | ||
this.ip = run.getIp(); | ||
this.startTime = run.getStartTime(); | ||
this.finishTime = run.getFinishTime(); | ||
this.failedReason = run.getFailedReason(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
server/controller/src/main/java/ai/starwhale/mlops/domain/run/RunService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2022 Starwhale, Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package ai.starwhale.mlops.domain.run; | ||
|
||
import ai.starwhale.mlops.api.protocol.run.RunVo; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class RunService { | ||
|
||
private final RunDao runDao; | ||
|
||
public RunService(RunDao runDao) { | ||
this.runDao = runDao; | ||
} | ||
|
||
public List<RunVo> runOfTask(Long taskId) { | ||
return runDao.findByTaskId(taskId).stream().map(r -> new RunVo(r)).collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
server/controller/src/test/java/ai/starwhale/mlops/domain/run/RunServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2022 Starwhale, Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package ai.starwhale.mlops.domain.run; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import ai.starwhale.mlops.api.protocol.run.RunVo; | ||
import ai.starwhale.mlops.domain.run.bo.Run; | ||
import ai.starwhale.mlops.domain.run.bo.RunSpec; | ||
import ai.starwhale.mlops.domain.run.bo.RunStatus; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class RunServiceTest { | ||
|
||
private RunDao runDao; | ||
|
||
private RunService runService; | ||
|
||
@BeforeEach | ||
void init() { | ||
runDao = mock(RunDao.class); | ||
runService = new RunService(runDao); | ||
when(runDao.findByTaskId(any())).thenReturn(List.of( | ||
Run.builder() | ||
.id(1L) | ||
.status(RunStatus.RUNNING) | ||
.logDir("anu") | ||
.runSpec(RunSpec.builder().build()) | ||
.ip("ip") | ||
.taskId(1L) | ||
.startTime(122334455L) | ||
.finishTime(122334456L) | ||
.failedReason("fr") | ||
.build() | ||
)); | ||
} | ||
|
||
@Test | ||
void runOfTask() { | ||
List<RunVo> runVos = runService.runOfTask(1L); | ||
Assertions.assertEquals(1, runVos.size()); | ||
Assertions.assertEquals(1L, runVos.get(0).getId()); | ||
Assertions.assertEquals(RunStatus.RUNNING, runVos.get(0).getStatus()); | ||
Assertions.assertEquals("ip", runVos.get(0).getIp()); | ||
Assertions.assertEquals(122334455L, runVos.get(0).getStartTime()); | ||
Assertions.assertEquals(122334456L, runVos.get(0).getFinishTime()); | ||
Assertions.assertEquals("fr", runVos.get(0).getFailedReason()); | ||
} | ||
} |