in bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/service/ServiceAddJob.java [148:206]
private void saveService(ServiceCommandDTO serviceCommand) {
if (serviceCommand.getInstalled()) {
return;
}
CommandDTO commandDTO = jobContext.getCommandDTO();
Long clusterId = commandDTO.getClusterId();
String serviceName = serviceCommand.getServiceName();
// Persist services
StackDTO stackDTO = StackUtils.getServiceStack(serviceName);
ServiceDTO serviceDTO = StackUtils.getServiceDTO(serviceName);
ServicePO servicePO = ServiceConverter.INSTANCE.fromDTO2PO(serviceDTO);
servicePO.setClusterId(clusterId);
servicePO.setStack(StackUtils.getFullStackName(stackDTO));
servicePO.setStatus(HealthyStatusEnum.UNHEALTHY.getCode());
serviceDao.save(servicePO);
// Persist components
List<ComponentPO> componentPOList = new ArrayList<>();
for (ComponentHostDTO componentHostDTO : serviceCommand.getComponentHosts()) {
String componentName = componentHostDTO.getComponentName();
List<HostPO> hostPOList = hostDao.findAllByHostnames(componentHostDTO.getHostnames());
for (HostPO hostPO : hostPOList) {
ComponentDTO componentDTO = StackUtils.getComponentDTO(componentName);
ComponentPO componentPO = ComponentConverter.INSTANCE.fromDTO2PO(componentDTO);
componentPO.setClusterId(clusterId);
componentPO.setHostId(hostPO.getId());
componentPO.setServiceId(servicePO.getId());
componentPO.setStatus(HealthyStatusEnum.UNKNOWN.getCode());
componentPOList.add(componentPO);
}
}
componentDao.saveAll(componentPOList);
// Persist current configs
Map<String, String> confMap = new HashMap<>();
List<ServiceConfigDTO> oriConfigs = StackUtils.SERVICE_CONFIG_MAP.get(serviceName);
List<ServiceConfigDTO> newConfigs = serviceCommand.getConfigs();
List<ServiceConfigDTO> mergedConfigs = StackConfigUtils.mergeServiceConfigs(oriConfigs, newConfigs);
List<ServiceConfigPO> serviceConfigPOList = ServiceConfigConverter.INSTANCE.fromDTO2PO(mergedConfigs);
for (ServiceConfigPO serviceConfigPO : serviceConfigPOList) {
serviceConfigPO.setClusterId(clusterId);
serviceConfigPO.setServiceId(servicePO.getId());
confMap.put(serviceConfigPO.getName(), serviceConfigPO.getPropertiesJson());
}
serviceConfigDao.saveAll(serviceConfigPOList);
// Create initial config snapshot
ServiceConfigSnapshotPO serviceConfigSnapshotPO = new ServiceConfigSnapshotPO();
serviceConfigSnapshotPO.setName("initial");
serviceConfigSnapshotPO.setDesc("Initial config snapshot");
serviceConfigSnapshotPO.setConfigJson(JsonUtils.writeAsString(confMap));
serviceConfigSnapshotPO.setServiceId(servicePO.getId());
serviceConfigSnapshotDao.save(serviceConfigSnapshotPO);
}