Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 2f1e553
Author: Zhiguo Wu <[email protected]>
Date:   Thu Oct 31 10:10:06 2024 +0800

    BIGTOP-4253: Refactor APIs for Stack (#96)
  • Loading branch information
lhpqaq committed Oct 31, 2024
1 parent 123cf31 commit c36b1fe
Show file tree
Hide file tree
Showing 33 changed files with 160 additions and 959 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ public class ClusterPO extends BasePO implements Serializable {
@Column(name = "selected")
private Boolean selected;

@Column(name = "stack_id")
private Long stackId;

@Transient
@Column(name = "stack_name")
private String stackName;
Expand Down

This file was deleted.

This file was deleted.

46 changes: 0 additions & 46 deletions bigtop-manager-dao/src/main/resources/mapper/mysql/StackMapper.xml

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.bigtop.manager.dao.po.TaskPO;
import org.apache.bigtop.manager.dao.repository.ClusterDao;
import org.apache.bigtop.manager.dao.repository.JobDao;
import org.apache.bigtop.manager.dao.repository.StackDao;
import org.apache.bigtop.manager.dao.repository.StageDao;
import org.apache.bigtop.manager.dao.repository.TaskDao;
import org.apache.bigtop.manager.server.command.stage.Stage;
Expand All @@ -42,7 +41,6 @@
@Slf4j
public abstract class AbstractJob implements Job {

protected StackDao stackDao;
protected ClusterDao clusterDao;
protected JobDao jobDao;
protected StageDao stageDao;
Expand Down Expand Up @@ -70,7 +68,6 @@ public AbstractJob(JobContext jobContext) {
}

protected void injectBeans() {
this.stackDao = SpringContextHolder.getBean(StackDao.class);
this.clusterDao = SpringContextHolder.getBean(ClusterDao.class);

this.jobDao = SpringContextHolder.getBean(JobDao.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.bigtop.manager.dao.po.ComponentPO;
import org.apache.bigtop.manager.dao.po.HostComponentPO;
import org.apache.bigtop.manager.dao.po.HostPO;
import org.apache.bigtop.manager.dao.po.StackPO;
import org.apache.bigtop.manager.dao.repository.ComponentDao;
import org.apache.bigtop.manager.dao.repository.HostComponentDao;
import org.apache.bigtop.manager.dao.repository.HostDao;
Expand All @@ -40,6 +39,7 @@
import org.apache.bigtop.manager.server.model.dto.ComponentDTO;
import org.apache.bigtop.manager.server.model.dto.ComponentHostDTO;
import org.apache.bigtop.manager.server.model.dto.ServiceDTO;
import org.apache.bigtop.manager.server.model.dto.StackDTO;
import org.apache.bigtop.manager.server.model.dto.command.ServiceCommandDTO;
import org.apache.bigtop.manager.server.stack.dag.ComponentCommandWrapper;
import org.apache.bigtop.manager.server.stack.dag.DAG;
Expand All @@ -57,9 +57,10 @@ public abstract class AbstractServiceJob extends AbstractJob {
protected HostComponentDao hostComponentDao;
protected HostDao hostDao;

protected String stackName;
protected String stackVersion;
protected DAG<String, ComponentCommandWrapper, DagGraphEdge> dag;
// TODO: temp code
protected String stackName = "bigtop";
protected String stackVersion = "3.3.0";
protected DAG<String, ComponentCommandWrapper, DagGraphEdge> dag = StackUtils.DAG;

public AbstractServiceJob(JobContext jobContext) {
super(jobContext);
Expand All @@ -77,18 +78,13 @@ protected void injectBeans() {
@Override
protected void beforeCreateStages() {
super.beforeCreateStages();
StackPO stackPO = stackDao.findById(clusterPO.getStackId());

stackName = stackPO.getStackName();
stackVersion = stackPO.getStackVersion();
dag = StackUtils.getStackDagMap().get(StackUtils.fullStackName(stackName, stackVersion));
}

protected StageContext createStageContext(String serviceName, String componentName, List<String> hostnames) {
StageContext stageContext = StageContext.fromCommandDTO(jobContext.getCommandDTO());

ServiceDTO serviceDTO = StackUtils.getServiceDTO(stackName, stackVersion, serviceName);
ComponentDTO componentDTO = StackUtils.getComponentDTO(stackName, stackVersion, componentName);
ServiceDTO serviceDTO = StackUtils.getServiceDTO(serviceName);
ComponentDTO componentDTO = StackUtils.getComponentDTO(componentName);

stageContext.setServiceDTO(serviceDTO);
stageContext.setComponentDTO(componentDTO);
Expand Down Expand Up @@ -126,7 +122,7 @@ protected List<String> getComponentNames() {
}

protected String findServiceNameByComponentName(String componentName) {
for (ServiceDTO serviceDTO : StackUtils.getServiceDTOList(stackName, stackVersion)) {
for (ServiceDTO serviceDTO : StackUtils.getServiceDTOList(new StackDTO(stackName, stackVersion))) {
for (ComponentDTO componentDTO : serviceDTO.getComponents()) {
if (componentDTO.getComponentName().equals(componentName)) {
return serviceDTO.getServiceName();
Expand All @@ -138,17 +134,17 @@ protected String findServiceNameByComponentName(String componentName) {
}

protected Boolean isMasterComponent(String componentName) {
ComponentDTO componentDTO = StackUtils.getComponentDTO(stackName, stackVersion, componentName);
ComponentDTO componentDTO = StackUtils.getComponentDTO(componentName);
return componentDTO.getCategory().equalsIgnoreCase(ComponentCategories.MASTER);
}

protected Boolean isSlaveComponent(String componentName) {
ComponentDTO componentDTO = StackUtils.getComponentDTO(stackName, stackVersion, componentName);
ComponentDTO componentDTO = StackUtils.getComponentDTO(componentName);
return componentDTO.getCategory().equalsIgnoreCase(ComponentCategories.SLAVE);
}

protected Boolean isClientComponent(String componentName) {
ComponentDTO componentDTO = StackUtils.getComponentDTO(stackName, stackVersion, componentName);
ComponentDTO componentDTO = StackUtils.getComponentDTO(componentName);
return componentDTO.getCategory().equalsIgnoreCase(ComponentCategories.CLIENT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void upsertService(ServicePO servicePO, ServiceCommandDTO serviceCommand

// 1. Persist service and components
if (servicePO == null) {
ServiceDTO serviceDTO = StackUtils.getServiceDTO(stackName, stackVersion, serviceName);
ServiceDTO serviceDTO = StackUtils.getServiceDTO(serviceName);
servicePO = ServiceConverter.INSTANCE.fromDTO2PO(serviceDTO, clusterPO);
serviceDao.save(servicePO);
}
Expand All @@ -158,7 +158,7 @@ private void upsertService(ServicePO servicePO, ServiceCommandDTO serviceCommand
// 3. Persist component
ComponentPO componentPO = componentDao.findByClusterIdAndComponentName(clusterId, componentName);
if (componentPO == null) {
ComponentDTO componentDTO = StackUtils.getComponentDTO(stackName, stackVersion, componentName);
ComponentDTO componentDTO = StackUtils.getComponentDTO(componentName);
componentPO = ComponentConverter.INSTANCE.fromDTO2PO(componentDTO, servicePO, clusterPO);
componentDao.save(componentPO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@
import org.apache.bigtop.manager.server.model.converter.RepoConverter;
import org.apache.bigtop.manager.server.model.dto.PropertyDTO;
import org.apache.bigtop.manager.server.model.dto.RepoDTO;
import org.apache.bigtop.manager.server.model.dto.ServiceDTO;
import org.apache.bigtop.manager.server.model.dto.StackDTO;
import org.apache.bigtop.manager.server.utils.StackConfigUtils;
import org.apache.bigtop.manager.server.utils.StackUtils;

import org.apache.commons.lang3.tuple.ImmutablePair;

import com.fasterxml.jackson.core.type.TypeReference;

Expand Down Expand Up @@ -213,22 +208,13 @@ private void genEmptyCaches() {
userMap = new HashMap<>();
settingsMap = new HashMap<>();

String fullStackName = StackUtils.fullStackName(taskContext.getStackName(), taskContext.getStackVersion());
ImmutablePair<StackDTO, List<ServiceDTO>> immutablePair =
StackUtils.getStackKeyMap().get(fullStackName);
StackDTO stackDTO = immutablePair.getLeft();

Map<String, Object> properties = taskContext.getProperties();

repoList = RepoConverter.INSTANCE.fromDTO2Message((List<RepoDTO>) properties.get("repoInfoList"));
clusterInfo = new ClusterInfo();
clusterInfo.setClusterName(taskContext.getClusterName());
clusterInfo.setStackName(taskContext.getStackName());
clusterInfo.setStackVersion(taskContext.getStackVersion());
clusterInfo.setUserGroup(stackDTO.getUserGroup());
clusterInfo.setRepoTemplate(stackDTO.getRepoTemplate());
clusterInfo.setRoot(stackDTO.getRoot());
clusterInfo.setPackages(List.of(stackDTO.getPackages().split(",")));

List<String> hostnames = (List<String>) properties.get("hostnames");
hostMap.put(Constants.ALL_HOST_KEY, new HashSet<>(hostnames));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.bigtop.manager.server.command.validator;

import org.apache.bigtop.manager.common.enums.Command;
import org.apache.bigtop.manager.dao.po.ClusterPO;
import org.apache.bigtop.manager.dao.po.ServicePO;
import org.apache.bigtop.manager.dao.repository.ClusterDao;
import org.apache.bigtop.manager.dao.repository.ServiceDao;
Expand All @@ -37,6 +36,7 @@
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;
import java.util.HashSet;
import java.util.List;

@Component
Expand All @@ -59,15 +59,12 @@ public void validate(ValidatorContext context) {
List<ServiceCommandDTO> serviceCommands = commandDTO.getServiceCommands();

Long clusterId = commandDTO.getClusterId();
ClusterPO clusterPO = clusterDao.findByIdJoin(clusterId);
String stackName = clusterPO.getStackName();
String stackVersion = clusterPO.getStackVersion();

List<String> serviceNames =
serviceCommands.stream().map(ServiceCommandDTO::getServiceName).toList();
for (ServiceCommandDTO serviceCommand : serviceCommands) {
String serviceName = serviceCommand.getServiceName();
ServiceDTO serviceDTO = StackUtils.getServiceDTO(stackName, stackVersion, serviceName);
ServiceDTO serviceDTO = StackUtils.getServiceDTO(serviceName);
List<String> requiredServices = serviceDTO.getRequiredServices();
if (CollectionUtils.isEmpty(requiredServices)) {
return;
Expand All @@ -79,7 +76,7 @@ public void validate(ValidatorContext context) {

requiredServices.removeAll(list);

if (!serviceNames.containsAll(requiredServices)) {
if (!new HashSet<>(serviceNames).containsAll(requiredServices)) {
throw new ApiException(ApiExceptionEnum.SERVICE_REQUIRED_NOT_FOUND, String.join(",", requiredServices));
}
}
Expand Down
Loading

0 comments on commit c36b1fe

Please sign in to comment.