Skip to content

Commit 4bfa4d5

Browse files
author
李浩
committed
[ADD] 重置deploy-key时重启agent
1 parent 2bb6ebf commit 4bfa4d5

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/main/java/io/choerodon/devops/app/service/AgentCommandService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,6 @@ void startOrStopInstance(String payload, String name,
110110
* @param configVO 配置信息
111111
*/
112112
void sendChartMuseumAuthentication(Long clusterId, ConfigVO configVO);
113+
114+
void sendRestartAgent(Long clusterId);
113115
}

src/main/java/io/choerodon/devops/app/service/impl/AgentCommandServiceImpl.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
import com.google.gson.Gson;
99
import io.codearte.props2yaml.Props2YAML;
10-
import org.hzero.websocket.constant.ClientWebSocketConstant;
11-
import org.hzero.websocket.helper.KeySocketSendHelper;
12-
import org.hzero.websocket.vo.MsgVO;
1310
import org.slf4j.Logger;
1411
import org.slf4j.LoggerFactory;
1512
import org.springframework.beans.factory.annotation.Autowired;
@@ -44,6 +41,10 @@
4441
import io.choerodon.devops.infra.mapper.DevopsClusterMapper;
4542
import io.choerodon.devops.infra.util.*;
4643

44+
import org.hzero.websocket.constant.ClientWebSocketConstant;
45+
import org.hzero.websocket.helper.KeySocketSendHelper;
46+
import org.hzero.websocket.vo.MsgVO;
47+
4748

4849
/**
4950
* Created by younger on 2018/4/18.
@@ -65,7 +66,7 @@ public class AgentCommandServiceImpl implements AgentCommandService {
6566
private static final String OPERATE_POD_COUNT = "operate_pod_count";
6667
private static final String OPERATE_DOCKER_REGISTRY_SECRET = "operate_docker_registry_secret";
6768
private static final String CLUSTER_AGENT = "choerodon-cluster-agent-";
68-
69+
private static final String RESTART_AGENT = "restart_agent";
6970

7071
private static final Pattern PATTERN = Pattern.compile("^[-+]?[\\d]*$");
7172
private static final Gson gson = new Gson();
@@ -446,4 +447,12 @@ public void sendChartMuseumAuthentication(Long clusterId, ConfigVO configVO) {
446447
sendToWebSocket(clusterId, msg);
447448
LOGGER.debug("Finished to sendChartMuseumAuthentication. cluster id {}", clusterId);
448449
}
450+
451+
@Override
452+
public void sendRestartAgent(Long clusterId) {
453+
AgentMsgVO msg = new AgentMsgVO();
454+
msg.setType(RESTART_AGENT);
455+
msg.setKey(String.format(CLUSTER_FORMAT, clusterId));
456+
sendToWebSocket(clusterId, msg);
457+
}
449458
}

src/main/java/io/choerodon/devops/infra/util/GitUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import io.choerodon.devops.api.vo.GitConfigVO;
3838
import io.choerodon.devops.api.vo.GitEnvConfigVO;
3939
import io.choerodon.devops.api.vo.GitlabRepositoryInfo;
40+
import io.choerodon.devops.app.service.AgentCommandService;
4041
import io.choerodon.devops.app.service.DevopsClusterResourceService;
4142
import io.choerodon.devops.app.service.DevopsEnvironmentService;
4243
import io.choerodon.devops.infra.dto.DevopsClusterDTO;
@@ -80,6 +81,8 @@ public class GitUtil {
8081
private String gitlabInternalsshUrl;
8182
@Autowired
8283
private GitlabServiceClientOperator gitlabServiceClientOperator;
84+
@Autowired
85+
private AgentCommandService agentCommandService;
8386

8487
public String getSshUrl() {
8588
if (org.apache.commons.lang3.StringUtils.isNotBlank(gitlabInternalsshUrl)) {
@@ -771,6 +774,8 @@ public static void refreshDeployKey(DevopsEnvironmentDTO devopsEnvironmentDTO) {
771774
true,
772775
GitUserNameUtil.getAdminId()
773776
);
777+
// 通知agent进行重启
778+
ApplicationContextHelper.getContext().getBean(AgentCommandService.class).sendRestartAgent(devopsEnvironmentDTO.getClusterId());
774779
}
775780

776781

0 commit comments

Comments
 (0)