Skip to content

Commit 15b5359

Browse files
committed
fix: support import skill/worker from nacos
1 parent 4ea9529 commit 15b5359

File tree

24 files changed

+786
-182
lines changed

24 files changed

+786
-182
lines changed

himarket-dal/src/main/java/com/alibaba/himarket/support/product/SkillConfig.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,27 @@
3232
public class SkillConfig {
3333

3434
/**
35-
* 技能标签列表
35+
* List of skill tags
3636
*/
3737
private List<String> skillTags;
3838

3939
/**
40-
* 下载次数
40+
* Download count
4141
*/
4242
private Long downloadCount;
4343

4444
/**
45-
* 关联的 Nacos 实例 IDnacos_instance.nacos_id
45+
* Associated Nacos instance ID (nacos_instance.nacos_id)
4646
*/
4747
private String nacosId;
4848

4949
/**
50-
* Nacos 命名空间,默认 "public"
50+
* Nacos namespace, defaults to "public"
5151
*/
5252
private String namespace;
5353

5454
/**
55-
* Nacos Skill name(唯一标识)
55+
* Nacos Skill name (unique identifier)
5656
*/
5757
private String skillName;
58-
59-
/**
60-
* Last published version in Nacos (e.g. v3)
61-
*/
62-
private String currentVersion;
6358
}

himarket-dal/src/main/java/com/alibaba/himarket/support/product/WorkerConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ public class WorkerConfig {
5050
* Worker tags for categorization and search
5151
*/
5252
private List<String> tags;
53+
54+
/**
55+
* Worker download count
56+
*/
57+
private long downloadCount;
5358
}

himarket-server/src/main/java/com/alibaba/himarket/controller/DeveloperController.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.alibaba.himarket.core.annotation.AdminAuth;
2323
import com.alibaba.himarket.core.annotation.DeveloperAuth;
24+
import com.alibaba.himarket.core.annotation.PublicAccess;
2425
import com.alibaba.himarket.dto.params.admin.ResetPasswordParam;
2526
import com.alibaba.himarket.dto.params.developer.*;
2627
import com.alibaba.himarket.dto.params.login.LoginParam;
@@ -73,20 +74,18 @@ public PageResult<DeveloperResult> listDevelopers(
7374
return developerService.listDevelopers(param, pageable);
7475
}
7576

76-
@Operation(summary = "获取当前开发者信息", description = "开发者功能:获取当前登录开发者的个人信息")
77+
@Operation(summary = "获取当前开发者信息", description = "获取当前登录开发者的个人信息,未登录返回 null")
7778
@GetMapping("/profile")
78-
@DeveloperAuth
79+
@PublicAccess
7980
public DeveloperResult getCurrentDeveloperInfo() {
8081
return developerService.getCurrentDeveloperInfo();
8182
}
8283

8384
@Operation(summary = "开发者修改密码", description = "修改当前登录开发者的密码")
8485
@PatchMapping("/password")
8586
@DeveloperAuth
86-
public String changePassword(@RequestBody ResetPasswordParam param) {
87-
developerService.changeCurrentDeveloperPassword(
88-
param.getOldPassword(), param.getNewPassword());
89-
return "修改密码成功";
87+
public void changePassword(@RequestBody ResetPasswordParam param) {
88+
developerService.resetDeveloperPassword(param.getOldPassword(), param.getNewPassword());
9089
}
9190

9291
@Operation(summary = "开发者更新个人信息", description = "开发者功能:更新当前登录开发者的个人信息")

himarket-server/src/main/java/com/alibaba/himarket/controller/SkillController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.alibaba.himarket.dto.result.cli.CliDownloadInfo;
99
import com.alibaba.himarket.dto.result.common.FileContentResult;
1010
import com.alibaba.himarket.dto.result.common.FileTreeNode;
11+
import com.alibaba.himarket.dto.result.common.ImportResult;
1112
import com.alibaba.himarket.dto.result.common.VersionResult;
1213
import com.alibaba.himarket.service.SkillService;
1314
import io.swagger.v3.oas.annotations.Operation;
@@ -122,4 +123,12 @@ public void downloadPackage(
122123
public CliDownloadInfo getCliDownloadInfo(@PathVariable String productId) {
123124
return skillService.getCliDownloadInfo(productId);
124125
}
126+
127+
@Operation(summary = "Import Skills from Nacos")
128+
@PostMapping("/import")
129+
@AdminAuth
130+
public ImportResult importFromNacos(
131+
@RequestParam String nacosId, @RequestParam(required = false) String namespace) {
132+
return skillService.importFromNacos(nacosId, namespace);
133+
}
125134
}

himarket-server/src/main/java/com/alibaba/himarket/controller/WorkerController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.alibaba.himarket.dto.result.cli.CliDownloadInfo;
99
import com.alibaba.himarket.dto.result.common.FileContentResult;
1010
import com.alibaba.himarket.dto.result.common.FileTreeNode;
11+
import com.alibaba.himarket.dto.result.common.ImportResult;
1112
import com.alibaba.himarket.dto.result.common.VersionResult;
1213
import com.alibaba.himarket.service.WorkerService;
1314
import io.swagger.v3.oas.annotations.Operation;
@@ -122,4 +123,12 @@ public void downloadPackage(
122123
public CliDownloadInfo getCliDownloadInfo(@PathVariable String productId) {
123124
return workerService.getCliDownloadInfo(productId);
124125
}
126+
127+
@Operation(summary = "Import Workers from Nacos")
128+
@PostMapping("/import")
129+
@AdminAuth
130+
public ImportResult importFromNacos(
131+
@RequestParam String nacosId, @RequestParam(required = false) String namespace) {
132+
return workerService.importFromNacos(nacosId, namespace);
133+
}
125134
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package com.alibaba.himarket.core.event;
21+
22+
import java.util.List;
23+
import lombok.AllArgsConstructor;
24+
import lombok.Data;
25+
import lombok.NoArgsConstructor;
26+
27+
/**
28+
* Event triggered when products are queried (list or get). Used to trigger async sync of download
29+
* counts from Nacos.
30+
*/
31+
@Data
32+
@NoArgsConstructor
33+
@AllArgsConstructor
34+
public class ProductQueriedEvent {
35+
36+
/** List of product IDs that were queried */
37+
private List<String> productIds;
38+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package com.alibaba.himarket.dto.result.common;
21+
22+
import lombok.AllArgsConstructor;
23+
import lombok.Builder;
24+
import lombok.Data;
25+
import lombok.NoArgsConstructor;
26+
27+
/**
28+
* Result of importing resources from Nacos.
29+
*/
30+
@Data
31+
@Builder
32+
@NoArgsConstructor
33+
@AllArgsConstructor
34+
public class ImportResult {
35+
36+
/** Resource type: "skill" or "worker" */
37+
private String resourceType;
38+
39+
/** Number of successfully imported resources */
40+
private int successCount;
41+
42+
/** Number of skipped resources (already exist) */
43+
private int skippedCount;
44+
}

himarket-server/src/main/java/com/alibaba/himarket/service/DeveloperService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ public interface DeveloperService {
150150
*
151151
* @param oldPassword 旧密码
152152
* @param newPassword 新密码
153-
* @return 是否成功
154153
*/
155-
boolean changeCurrentDeveloperPassword(String oldPassword, String newPassword);
154+
void resetDeveloperPassword(String oldPassword, String newPassword);
156155
}

himarket-server/src/main/java/com/alibaba/himarket/service/SkillService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.alibaba.himarket.dto.result.cli.CliDownloadInfo;
44
import com.alibaba.himarket.dto.result.common.FileContentResult;
55
import com.alibaba.himarket.dto.result.common.FileTreeNode;
6+
import com.alibaba.himarket.dto.result.common.ImportResult;
67
import com.alibaba.himarket.dto.result.common.VersionResult;
78
import com.alibaba.nacos.api.ai.model.skills.Skill;
89
import jakarta.servlet.http.HttpServletResponse;
@@ -146,4 +147,13 @@ void downloadPackage(String productId, String version, HttpServletResponse respo
146147
* @return the CLI download info containing nacosHost and resource name
147148
*/
148149
CliDownloadInfo getCliDownloadInfo(String productId);
150+
151+
/**
152+
* Import skills from Nacos
153+
*
154+
* @param nacosId Nacos instance ID
155+
* @param namespace Nacos namespace
156+
* @return import result with success and skipped counts
157+
*/
158+
ImportResult importFromNacos(String nacosId, String namespace);
149159
}

himarket-server/src/main/java/com/alibaba/himarket/service/WorkerService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.alibaba.himarket.dto.result.cli.CliDownloadInfo;
44
import com.alibaba.himarket.dto.result.common.FileContentResult;
55
import com.alibaba.himarket.dto.result.common.FileTreeNode;
6+
import com.alibaba.himarket.dto.result.common.ImportResult;
67
import com.alibaba.himarket.dto.result.common.VersionResult;
78
import jakarta.servlet.http.HttpServletResponse;
89
import java.io.IOException;
@@ -102,4 +103,13 @@ void downloadPackage(String productId, String version, HttpServletResponse respo
102103
* @return the CLI download info containing nacosHost and resource name
103104
*/
104105
CliDownloadInfo getCliDownloadInfo(String productId);
106+
107+
/**
108+
* Import workers from Nacos
109+
*
110+
* @param nacosId Nacos instance ID
111+
* @param namespace Nacos namespace
112+
* @return import result with success and skipped counts
113+
*/
114+
ImportResult importFromNacos(String nacosId, String namespace);
105115
}

0 commit comments

Comments
 (0)