Skip to content

Commit

Permalink
BIGTOP-4318: Support service check command (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinw66 authored Jan 4, 2025
1 parent a97a4da commit a07bc6d
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -31,6 +38,36 @@ protected void createStages() {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -29,6 +36,21 @@ protected void createStages() {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -29,6 +36,21 @@ protected void createStages() {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -31,6 +34,32 @@ protected Command getCommand() {
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();
Expand Down

0 comments on commit a07bc6d

Please sign in to comment.