This is an automated email from the ASF dual-hosted git repository.
wuzhiguo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/bigtop-manager.git
The following commit(s) were added to refs/heads/main by this push:
new a07bc6d6 BIGTOP-4318: Support service check command (#140)
a07bc6d6 is described below
commit a07bc6d646b69f3e366155aa0a466907cfe5f60d
Author: Zhiguo Wu <[email protected]>
AuthorDate: Sat Jan 4 10:58:50 2025 +0800
BIGTOP-4318: Support service check command (#140)
---
.../bigtop/manager/common/enums/Command.java | 8 ++-
.../factory/service/ServiceCheckJobFactory.java | 48 ++++++++++++++
.../server/command/job/ServiceCheckJob.java | 73 ++++++++++++++++++++++
.../server/command/job/ServiceRestartJob.java | 37 +++++++++++
.../server/command/job/ServiceStartJob.java | 22 +++++++
.../manager/server/command/job/ServiceStopJob.java | 22 +++++++
.../server/command/task/ComponentCheckTask.java | 29 +++++++++
7 files changed, 237 insertions(+), 2 deletions(-)
diff --git
a/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/enums/Command.java
b/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/enums/Command.java
index 6f9457af..1bf036be 100644
---
a/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/enums/Command.java
+++
b/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/enums/Command.java
@@ -36,10 +36,14 @@ public enum Command {
RESTART("restart", "Restart"),
// Available for: Service, Component
- STATUS("status", "Status"),
CHECK("check", "Check"),
- CUSTOM("custom", "Custom"),
+
+ // Available for: Service
CONFIGURE("configure", "Configure"),
+ CUSTOM("custom", "Custom"),
+
+ // Internal use only, not available for job creation
+ STATUS("status", "Status"),
;
private final String code;
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/factory/service/ServiceCheckJobFactory.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/factory/service/ServiceCheckJobFactory.java
new file mode 100644
index 00000000..3335ef18
--- /dev/null
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/factory/service/ServiceCheckJobFactory.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * https://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 org.apache.bigtop.manager.server.command.factory.service;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.CommandIdentifier;
+import org.apache.bigtop.manager.server.command.job.Job;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.job.ServiceCheckJob;
+import org.apache.bigtop.manager.server.enums.CommandLevel;
+
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@Component
+@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public class ServiceCheckJobFactory extends AbstractServiceJobFactory {
+
+ @Override
+ public CommandIdentifier getCommandIdentifier() {
+ return new CommandIdentifier(CommandLevel.SERVICE, Command.CHECK);
+ }
+
+ @Override
+ public Job createJob(JobContext jobContext) {
+ return new ServiceCheckJob(jobContext);
+ }
+}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceCheckJob.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceCheckJob.java
new file mode 100644
index 00000000..34f798e0
--- /dev/null
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceCheckJob.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * https://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 org.apache.bigtop.manager.server.command.job;
+
+import org.apache.bigtop.manager.dao.po.ServicePO;
+import org.apache.bigtop.manager.server.enums.HealthyStatusEnum;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+import org.apache.bigtop.manager.server.model.dto.command.ServiceCommandDTO;
+
+import java.util.List;
+
+public class ServiceCheckJob extends AbstractServiceJob {
+
+ public ServiceCheckJob(JobContext jobContext) {
+ super(jobContext);
+ }
+
+ @Override
+ protected void createStages() {
+ super.createCheckStages();
+ }
+
+ @Override
+ public void onSuccess() {
+ super.onSuccess();
+
+ CommandDTO commandDTO = jobContext.getCommandDTO();
+ List<ServiceCommandDTO> serviceCommands =
commandDTO.getServiceCommands();
+ for (ServiceCommandDTO serviceCommand : serviceCommands) {
+ Long clusterId = commandDTO.getClusterId();
+ String serviceName = serviceCommand.getServiceName();
+ ServicePO servicePO = serviceDao.findByClusterIdAndName(clusterId,
serviceName);
+ servicePO.setStatus(HealthyStatusEnum.HEALTHY.getCode());
+ serviceDao.partialUpdateById(servicePO);
+ }
+ }
+
+ @Override
+ public void onFailure() {
+ super.onFailure();
+
+ CommandDTO commandDTO = jobContext.getCommandDTO();
+ List<ServiceCommandDTO> serviceCommands =
commandDTO.getServiceCommands();
+ for (ServiceCommandDTO serviceCommand : serviceCommands) {
+ Long clusterId = commandDTO.getClusterId();
+ String serviceName = serviceCommand.getServiceName();
+ ServicePO servicePO = serviceDao.findByClusterIdAndName(clusterId,
serviceName);
+ servicePO.setStatus(HealthyStatusEnum.UNHEALTHY.getCode());
+ serviceDao.partialUpdateById(servicePO);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return "Check services";
+ }
+}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceRestartJob.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceRestartJob.java
index 53215d06..87ccb90a 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceRestartJob.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceRestartJob.java
@@ -18,6 +18,13 @@
*/
package org.apache.bigtop.manager.server.command.job;
+import org.apache.bigtop.manager.dao.po.ServicePO;
+import org.apache.bigtop.manager.server.enums.HealthyStatusEnum;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+import org.apache.bigtop.manager.server.model.dto.command.ServiceCommandDTO;
+
+import java.util.List;
+
public class ServiceRestartJob extends AbstractServiceJob {
public ServiceRestartJob(JobContext jobContext) {
@@ -31,6 +38,36 @@ public class ServiceRestartJob extends AbstractServiceJob {
super.createStartStages();
}
+ @Override
+ public void onSuccess() {
+ super.onSuccess();
+
+ CommandDTO commandDTO = jobContext.getCommandDTO();
+ List<ServiceCommandDTO> serviceCommands =
commandDTO.getServiceCommands();
+ for (ServiceCommandDTO serviceCommand : serviceCommands) {
+ Long clusterId = commandDTO.getClusterId();
+ String serviceName = serviceCommand.getServiceName();
+ ServicePO servicePO = serviceDao.findByClusterIdAndName(clusterId,
serviceName);
+ servicePO.setStatus(HealthyStatusEnum.HEALTHY.getCode());
+ serviceDao.partialUpdateById(servicePO);
+ }
+ }
+
+ @Override
+ public void onFailure() {
+ super.onFailure();
+
+ CommandDTO commandDTO = jobContext.getCommandDTO();
+ List<ServiceCommandDTO> serviceCommands =
commandDTO.getServiceCommands();
+ for (ServiceCommandDTO serviceCommand : serviceCommands) {
+ Long clusterId = commandDTO.getClusterId();
+ String serviceName = serviceCommand.getServiceName();
+ ServicePO servicePO = serviceDao.findByClusterIdAndName(clusterId,
serviceName);
+ servicePO.setStatus(HealthyStatusEnum.UNHEALTHY.getCode());
+ serviceDao.partialUpdateById(servicePO);
+ }
+ }
+
@Override
public String getName() {
return "Restart services";
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceStartJob.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceStartJob.java
index 38e7a4cf..85b4959c 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceStartJob.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceStartJob.java
@@ -18,6 +18,13 @@
*/
package org.apache.bigtop.manager.server.command.job;
+import org.apache.bigtop.manager.dao.po.ServicePO;
+import org.apache.bigtop.manager.server.enums.HealthyStatusEnum;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+import org.apache.bigtop.manager.server.model.dto.command.ServiceCommandDTO;
+
+import java.util.List;
+
public class ServiceStartJob extends AbstractServiceJob {
public ServiceStartJob(JobContext jobContext) {
@@ -29,6 +36,21 @@ public class ServiceStartJob extends AbstractServiceJob {
super.createStartStages();
}
+ @Override
+ public void onSuccess() {
+ super.onSuccess();
+
+ CommandDTO commandDTO = jobContext.getCommandDTO();
+ List<ServiceCommandDTO> serviceCommands =
commandDTO.getServiceCommands();
+ for (ServiceCommandDTO serviceCommand : serviceCommands) {
+ Long clusterId = commandDTO.getClusterId();
+ String serviceName = serviceCommand.getServiceName();
+ ServicePO servicePO = serviceDao.findByClusterIdAndName(clusterId,
serviceName);
+ servicePO.setStatus(HealthyStatusEnum.HEALTHY.getCode());
+ serviceDao.partialUpdateById(servicePO);
+ }
+ }
+
@Override
public String getName() {
return "Start services";
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceStopJob.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceStopJob.java
index 13f9dbd4..9919769e 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceStopJob.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceStopJob.java
@@ -18,6 +18,13 @@
*/
package org.apache.bigtop.manager.server.command.job;
+import org.apache.bigtop.manager.dao.po.ServicePO;
+import org.apache.bigtop.manager.server.enums.HealthyStatusEnum;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+import org.apache.bigtop.manager.server.model.dto.command.ServiceCommandDTO;
+
+import java.util.List;
+
public class ServiceStopJob extends AbstractServiceJob {
public ServiceStopJob(JobContext jobContext) {
@@ -29,6 +36,21 @@ public class ServiceStopJob extends AbstractServiceJob {
super.createStopStages();
}
+ @Override
+ public void onSuccess() {
+ super.onSuccess();
+
+ CommandDTO commandDTO = jobContext.getCommandDTO();
+ List<ServiceCommandDTO> serviceCommands =
commandDTO.getServiceCommands();
+ for (ServiceCommandDTO serviceCommand : serviceCommands) {
+ Long clusterId = commandDTO.getClusterId();
+ String serviceName = serviceCommand.getServiceName();
+ ServicePO servicePO = serviceDao.findByClusterIdAndName(clusterId,
serviceName);
+ servicePO.setStatus(HealthyStatusEnum.UNHEALTHY.getCode());
+ serviceDao.partialUpdateById(servicePO);
+ }
+ }
+
@Override
public String getName() {
return "Stop services";
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/ComponentCheckTask.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/ComponentCheckTask.java
index 121b5b92..66a74283 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/ComponentCheckTask.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/ComponentCheckTask.java
@@ -19,6 +19,9 @@
package org.apache.bigtop.manager.server.command.task;
import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.dao.po.ComponentPO;
+import org.apache.bigtop.manager.dao.query.ComponentQuery;
+import org.apache.bigtop.manager.server.enums.HealthyStatusEnum;
public class ComponentCheckTask extends AbstractComponentTask {
@@ -31,6 +34,32 @@ public class ComponentCheckTask extends
AbstractComponentTask {
return Command.CHECK;
}
+ @Override
+ public void onSuccess() {
+ super.onSuccess();
+
+ String componentName = taskContext.getComponentName();
+ String hostname = taskContext.getHostname();
+ ComponentQuery componentQuery =
+
ComponentQuery.builder().hostname(hostname).name(componentName).build();
+ ComponentPO componentPO =
componentDao.findByQuery(componentQuery).get(0);
+ componentPO.setStatus(HealthyStatusEnum.HEALTHY.getCode());
+ componentDao.partialUpdateById(componentPO);
+ }
+
+ @Override
+ public void onFailure() {
+ super.onFailure();
+
+ String componentName = taskContext.getComponentName();
+ String hostname = taskContext.getHostname();
+ ComponentQuery componentQuery =
+
ComponentQuery.builder().hostname(hostname).name(componentName).build();
+ ComponentPO componentPO =
componentDao.findByQuery(componentQuery).get(0);
+ componentPO.setStatus(HealthyStatusEnum.UNHEALTHY.getCode());
+ componentDao.partialUpdateById(componentPO);
+ }
+
@Override
public String getName() {
return "Check " + taskContext.getComponentDisplayName() + " on " +
taskContext.getHostname();