Skip to content

Commit

Permalink
wip add: job pinned & pinned_time
Browse files Browse the repository at this point in the history
  • Loading branch information
waynelwz committed Jun 15, 2023
1 parent 610ca2b commit a7b137d
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,17 @@ ResponseEntity<ResponseMessage<String>> modifyJobComment(
schema = @Schema())
@PathVariable("jobUrl")
String jobUrl,
@Valid @RequestBody JobModifyRequest jobRequest);
@Valid @RequestBody JobModifyRequest jobRequest);

@Operation(summary = "Pin Job")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "ok") })
@PostMapping(value = "/project/{projectUrl}/job/{jobUrl}/pin", produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAnyRole('OWNER', 'MAINTAINER')")
ResponseEntity<ResponseMessage<String>> modifyJobPinStatus(
@Parameter(in = ParameterIn.PATH, description = "Project url", schema = @Schema())
@PathVariable("projectUrl") String projectUrl,
@Parameter(in = ParameterIn.PATH, description = "Job id or uuid", required = true, schema = @Schema())
@PathVariable("jobUrl") String jobUrl);

@Operation(summary = "DAG of Job")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "ok")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ public ResponseEntity<ResponseMessage<String>> modifyJobComment(
return ResponseEntity.ok(Code.success.asResponse("success"));
}

@Override
public ResponseEntity<ResponseMessage<String>> modifyJobPinStatus(
String projectUrl,
String jobUrl,
JobRequest jobRequest
) {
Boolean res = jobService.updateJobPinStatus(projectUrl, jobUrl, jobRequest.getPinned());

if (!res) {
throw new StarwhaleApiException(new SwProcessException(ErrorType.DB, "Update job pin status failed."),
HttpStatus.INTERNAL_SERVER_ERROR);
}
return ResponseEntity.ok(Code.success.asResponse("success"));
}

@Override
public ResponseEntity<ResponseMessage<Graph>> getJobDag(String projectUrl, String jobUrl) {
return ResponseEntity.ok(Code.success.asResponse(dagQuerier.dagOfJob(jobUrl)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ public class JobRequest implements Serializable {
private DevWay devWay = DevWay.VS_CODE;

private Long timeToLiveInSec;

@JsonProperty("pinned")
private boolean pinned = false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import ai.starwhale.mlops.domain.job.storage.JobRepo;
import ai.starwhale.mlops.exception.SwValidationException;
import ai.starwhale.mlops.exception.api.StarwhaleApiException;

import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -176,6 +178,14 @@ public Job findJob(String jobUrl) {
}
}

public boolean updateJobPinStatus(String jobUrl, boolean pinned) {
if (idConvertor.isId(jobUrl)) {
return jobMapper.updateJobPinStatus(idConvertor.revert(jobUrl), pinned, Date.from(Instant.now())) > 0;
} else {
return jobMapper.updateJobPinStatusByUuid(jobUrl, pinned, Date.from(Instant.now())) > 0;
}
}

@Override
public BundleEntity findById(Long id) {
return jobMapper.findJobById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ void updateJobFinishedTime(
int recoverJob(@Param("id") Long id);

int recoverJobByUuid(@Param("uuid") String uuid);

int updateJobPinStatus(@Param("id") Long id, @Param("pinned") Boolean pinned, @Param("pinnedTime") Date pinnedTime);

int updateJobPinStatusByUuid(@Param("uuid") String uuid, @Param("pinned") Boolean pinned, @Param("pinnedTime") Date pinnedTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public class JobEntity extends BaseEntity implements BundleEntity {
private String devPassword;
private Date autoReleaseTime;

private boolean pinned;

private Date pinnedTime;

@Override
public String getName() {
return jobUuid;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/


ALTER TABLE job_info
ADD pinned TINYINT NOT NULL DEFAULT 0,
ADD pinned_time DATETIME NULL;
12 changes: 12 additions & 0 deletions server/controller/src/main/resources/mapper/JobMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@
where job_uuid = #{uuid}
</update>

<update id="updateJobPinStatus">
update job_info set pinned = #{pinned}, pinned_time = #{pinnedTime}
where id = #{id}
</update>

<update id="updateJobPinStatusByUuid">
update job_info set pinned = #{pinned}, pinned_time = #{pinnedTime}
where job_uuid = #{uuid}
</update>

<insert id="addJob" parameterType="ai.starwhale.mlops.domain.job.po.JobEntity"
useGeneratedKeys="true" keyProperty="id">
insert into job_info(job_uuid,
Expand Down Expand Up @@ -206,6 +216,8 @@
<result property="devWay" column="dev_way"/>
<result property="devPassword" column="dev_password"/>
<result property="autoReleaseTime" column="auto_release_time"/>
<result property="pinned" column="pinned"/>
<result property="pinnedTime" column="pinned_time"/>
<association property="project" resultMap="projectResultMap"/>
<association property="modelVersion" resultMap="modelVersionResultMap"/>
<association property="owner" resultMap="userResultMap"/>
Expand Down

0 comments on commit a7b137d

Please sign in to comment.