Skip to content

Commit

Permalink
BIGTOP-4332: Add templates to service metainfo indicates user unmodif…
Browse files Browse the repository at this point in the history
…iable files (#152)
  • Loading branch information
kevinw66 authored Jan 23, 2025
1 parent df09bd0 commit 26c8897
Show file tree
Hide file tree
Showing 55 changed files with 297 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.bigtop.manager.grpc.payload;

import org.apache.bigtop.manager.grpc.pojo.PackageSpecificInfo;
import org.apache.bigtop.manager.grpc.pojo.TemplateInfo;

import lombok.Data;

Expand All @@ -44,6 +45,8 @@ public class ComponentCommandPayload {

private List<PackageSpecificInfo> packageSpecifics;

private List<TemplateInfo> templates;

/**
* This field is exclusively used for Prometheus and Grafana within the infra services.
* Includes cluster and corresponding hostname.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.grpc.pojo;

import lombok.Data;

@Data
public class TemplateInfo {

private String src;

private String dest;

private String content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.bigtop.manager.server.command.task.Task;
import org.apache.bigtop.manager.server.exception.ServerException;
import org.apache.bigtop.manager.server.model.dto.CommandDTO;
import org.apache.bigtop.manager.server.model.dto.ComponentDTO;
import org.apache.bigtop.manager.server.model.dto.ServiceDTO;
import org.apache.bigtop.manager.server.utils.StackUtils;

Expand Down Expand Up @@ -121,11 +120,10 @@ private static StageContext createStageContext(
StageContext stageContext = StageContext.fromCommandDTO(commandDTO);

ServiceDTO serviceDTO = StackUtils.getServiceDTOByComponentName(componentName);
ComponentDTO componentDTO = StackUtils.getComponentDTO(componentName);

stageContext.setHostnames(hostnames);
stageContext.setServiceDTO(serviceDTO);
stageContext.setComponentDTO(componentDTO);
stageContext.setServiceName(serviceDTO.getName());
stageContext.setComponentName(componentName);

return stageContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.bigtop.manager.server.holder.SpringContextHolder;
import org.apache.bigtop.manager.server.model.dto.ComponentDTO;
import org.apache.bigtop.manager.server.model.dto.ServiceDTO;
import org.apache.bigtop.manager.server.utils.StackUtils;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -55,17 +56,17 @@ protected void beforeCreateTasks() {

@Override
protected String getServiceName() {
return stageContext.getServiceDTO().getName();
return stageContext.getServiceName();
}

@Override
protected String getComponentName() {
return stageContext.getComponentDTO().getName();
return stageContext.getComponentName();
}

protected TaskContext createTaskContext(String hostname) {
ServiceDTO serviceDTO = stageContext.getServiceDTO();
ComponentDTO componentDTO = stageContext.getComponentDTO();
ServiceDTO serviceDTO = StackUtils.getServiceDTO(stageContext.getServiceName());
ComponentDTO componentDTO = StackUtils.getComponentDTO(stageContext.getComponentName());

TaskContext taskContext = new TaskContext();
taskContext.setHostname(hostname);
Expand All @@ -79,7 +80,6 @@ protected TaskContext createTaskContext(String hostname) {
taskContext.setRootDir(clusterPO.getRootDir());

Map<String, Object> properties = new HashMap<>();
properties.put("packageSpecifics", serviceDTO.getPackageSpecifics());
properties.put("clusterHosts", getClusterHosts());
taskContext.setProperties(properties);
return taskContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.bigtop.manager.server.command.task.ComponentAddTask;
import org.apache.bigtop.manager.server.command.task.Task;
import org.apache.bigtop.manager.server.utils.StackUtils;

public class ComponentAddStage extends AbstractComponentStage {

Expand All @@ -34,6 +35,7 @@ protected Task createTask(String hostname) {

@Override
public String getName() {
return "Add " + stageContext.getComponentDTO().getDisplayName();
return "Add "
+ StackUtils.getComponentDTO(stageContext.getComponentName()).getDisplayName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.bigtop.manager.server.command.task.ComponentCheckTask;
import org.apache.bigtop.manager.server.command.task.Task;
import org.apache.bigtop.manager.server.utils.StackUtils;

public class ComponentCheckStage extends AbstractComponentStage {

Expand All @@ -34,6 +35,7 @@ protected Task createTask(String hostname) {

@Override
public String getName() {
return "Check " + stageContext.getComponentDTO().getDisplayName();
return "Check "
+ StackUtils.getComponentDTO(stageContext.getComponentName()).getDisplayName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.bigtop.manager.server.command.task.ComponentConfigureTask;
import org.apache.bigtop.manager.server.command.task.Task;
import org.apache.bigtop.manager.server.utils.StackUtils;

public class ComponentConfigureStage extends AbstractComponentStage {

Expand All @@ -34,6 +35,7 @@ protected Task createTask(String hostname) {

@Override
public String getName() {
return "Configure " + stageContext.getComponentDTO().getDisplayName();
return "Configure "
+ StackUtils.getComponentDTO(stageContext.getComponentName()).getDisplayName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.bigtop.manager.server.command.task.ComponentInitTask;
import org.apache.bigtop.manager.server.command.task.Task;
import org.apache.bigtop.manager.server.utils.StackUtils;

public class ComponentInitStage extends AbstractComponentStage {

Expand All @@ -34,6 +35,7 @@ protected Task createTask(String hostname) {

@Override
public String getName() {
return "Init " + stageContext.getComponentDTO().getDisplayName();
return "Init "
+ StackUtils.getComponentDTO(stageContext.getComponentName()).getDisplayName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.bigtop.manager.server.command.task.ComponentPrepareTask;
import org.apache.bigtop.manager.server.command.task.Task;
import org.apache.bigtop.manager.server.utils.StackUtils;

public class ComponentPrepareStage extends AbstractComponentStage {

Expand All @@ -34,6 +35,7 @@ protected Task createTask(String hostname) {

@Override
public String getName() {
return "Prepare " + stageContext.getComponentDTO().getDisplayName();
return "Prepare "
+ StackUtils.getComponentDTO(stageContext.getComponentName()).getDisplayName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.bigtop.manager.server.command.task.ComponentStartTask;
import org.apache.bigtop.manager.server.command.task.Task;
import org.apache.bigtop.manager.server.utils.StackUtils;

public class ComponentStartStage extends AbstractComponentStage {

Expand All @@ -34,6 +35,7 @@ protected Task createTask(String hostname) {

@Override
public String getName() {
return "Start " + stageContext.getComponentDTO().getDisplayName();
return "Start "
+ StackUtils.getComponentDTO(stageContext.getComponentName()).getDisplayName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.bigtop.manager.server.command.task.ComponentStopTask;
import org.apache.bigtop.manager.server.command.task.Task;
import org.apache.bigtop.manager.server.utils.StackUtils;

public class ComponentStopStage extends AbstractComponentStage {

Expand All @@ -34,6 +35,7 @@ protected Task createTask(String hostname) {

@Override
public String getName() {
return "Stop " + stageContext.getComponentDTO().getDisplayName();
return "Stop "
+ StackUtils.getComponentDTO(stageContext.getComponentName()).getDisplayName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.apache.bigtop.manager.dao.repository.ClusterDao;
import org.apache.bigtop.manager.server.holder.SpringContextHolder;
import org.apache.bigtop.manager.server.model.dto.CommandDTO;
import org.apache.bigtop.manager.server.model.dto.ComponentDTO;
import org.apache.bigtop.manager.server.model.dto.ServiceDTO;
import org.apache.bigtop.manager.server.model.dto.command.ClusterCommandDTO;

import lombok.Data;
Expand All @@ -43,9 +41,9 @@ public class StageContext {

private List<String> hostnames;

private ServiceDTO serviceDTO;
private String serviceName;

private ComponentDTO componentDTO;
private String componentName;

public static StageContext fromCommandDTO(CommandDTO commandDTO) {
StageContext context = new StageContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
import org.apache.bigtop.manager.grpc.payload.ComponentCommandPayload;
import org.apache.bigtop.manager.grpc.pojo.PackageInfo;
import org.apache.bigtop.manager.grpc.pojo.PackageSpecificInfo;
import org.apache.bigtop.manager.grpc.pojo.TemplateInfo;
import org.apache.bigtop.manager.server.grpc.GrpcClient;
import org.apache.bigtop.manager.server.holder.SpringContextHolder;
import org.apache.bigtop.manager.server.model.dto.PackageDTO;
import org.apache.bigtop.manager.server.model.dto.PackageSpecificDTO;
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.TemplateDTO;
import org.apache.bigtop.manager.server.utils.StackUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -66,6 +69,8 @@ protected Boolean doRun(String hostname, Integer grpcPort) {
@SuppressWarnings("unchecked")
protected ComponentCommandRequest getComponentCommandRequest() {
StackDTO stackDTO = StackUtils.getServiceStack(taskContext.getServiceName());
ServiceDTO serviceDTO = StackUtils.getServiceDTO(taskContext.getServiceName());

ComponentCommandPayload payload = new ComponentCommandPayload();
payload.setServiceName(taskContext.getServiceName());
payload.setComponentName(taskContext.getComponentName());
Expand All @@ -75,10 +80,10 @@ protected ComponentCommandRequest getComponentCommandRequest() {
payload.setCommand(getCommand().getCode());
payload.setCustomCommand(getCustomCommand());

Map<String, Object> properties = taskContext.getProperties();
payload.setTemplates(convertTemplateInfo(serviceDTO.getName(), serviceDTO.getTemplates()));
payload.setPackageSpecifics(convertPackageSpecificInfo(serviceDTO.getPackageSpecifics()));

payload.setPackageSpecifics(
convertPackageSpecificInfo((List<PackageSpecificDTO>) properties.get("packageSpecifics")));
Map<String, Object> properties = taskContext.getProperties();
if (stackDTO.getStackName().equals("infra")) {
Map<String, List<String>> clusterHosts = (Map<String, List<String>>) properties.get("clusterHosts");
payload.setClusterHosts(clusterHosts);
Expand All @@ -91,6 +96,25 @@ protected ComponentCommandRequest getComponentCommandRequest() {
return requestBuilder.build();
}

private List<TemplateInfo> convertTemplateInfo(String serviceName, List<TemplateDTO> templateDTOList) {
if (templateDTOList == null) {
return new ArrayList<>();
}

List<TemplateInfo> templateInfos = new ArrayList<>();
for (TemplateDTO templateDTO : templateDTOList) {
String content = StackUtils.SERVICE_TEMPLATE_MAP.get(serviceName).get(templateDTO.getSrc());

TemplateInfo templateInfo = new TemplateInfo();
templateInfo.setSrc(templateDTO.getSrc());
templateInfo.setDest(templateDTO.getDest());
templateInfo.setContent(content);
templateInfos.add(templateInfo);
}

return templateInfos;
}

private List<PackageSpecificInfo> convertPackageSpecificInfo(List<PackageSpecificDTO> packageSpecificDTOList) {
if (packageSpecificDTOList == null) {
return new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class ServiceDTO {

private List<PackageSpecificDTO> packageSpecifics;

private List<TemplateDTO> templates;

private List<ComponentDTO> components;

private List<ServiceConfigDTO> configs;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.model.dto;

import lombok.Data;

@Data
public class TemplateDTO {

private String src;

private String dest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public class ServiceModel {
@XmlElements(@XmlElement(name = "component"))
private List<ComponentModel> components;

@XmlElementWrapper(name = "templates")
@XmlElements(@XmlElement(name = "template"))
private List<TemplateModel> templates;

@XmlElementWrapper(name = "required-services")
@XmlElements(@XmlElement(name = "service"))
private List<String> requiredServices;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.stack.model;

import lombok.Data;

import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;

@Data
@XmlAccessorType(XmlAccessType.FIELD)
public class TemplateModel {

private String src;

private String dest;
}
Loading

0 comments on commit 26c8897

Please sign in to comment.