Skip to content

Commit

Permalink
[Feature][scaleph-engine-doris] add doris template detail web (#650)
Browse files Browse the repository at this point in the history
* fix: doris template step form item error

* feature: add doris template yaml step

* feature: add doris template yaml step

* feature: add createStatus for doris template

* feature: add yaml step for doris template steps

* feature: add yaml step for doris template steps

* feature: add yaml step for doris template steps

* feature: remove doris template createStatus field

* feature: refactor doris template step model

* feature: add yaml area for doris template detail web

* feature: add yaml area for doris template detail web
  • Loading branch information
kalencaya authored Nov 27, 2023
1 parent 2895ca0 commit 5edd3a7
Show file tree
Hide file tree
Showing 26 changed files with 802 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import cn.sliew.scaleph.engine.doris.service.param.WsDorisTemplateAddParam;
import cn.sliew.scaleph.engine.doris.service.param.WsDorisTemplateListParam;
import cn.sliew.scaleph.engine.doris.service.param.WsDorisTemplateUpdateParam;
import cn.sliew.scaleph.engine.doris.service.resource.template.DorisTemplate;
import cn.sliew.scaleph.system.model.ResponseVO;
import cn.sliew.scaleph.system.snowflake.exception.UidGenerateException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
Expand Down Expand Up @@ -61,6 +62,14 @@ public ResponseEntity<ResponseVO<WsDorisTemplateDTO>> selectOne(@PathVariable("i
return new ResponseEntity(ResponseVO.success(dto), HttpStatus.OK);
}

@Logging
@PostMapping("asYaml")
@Operation(summary = "转换模板信息", description = "转换模板信息")
public ResponseEntity<ResponseVO<DorisTemplate>> asYaml(@RequestBody WsDorisTemplateDTO dto) {
DorisTemplate template = wsDorisTemplateService.asYaml(dto);
return new ResponseEntity(ResponseVO.success(template), HttpStatus.OK);
}

@Logging
@PutMapping
@Operation(summary = "新增模板", description = "新增模板")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class WsDorisTemplate extends BaseDO {

private static final long serialVersionUID = 1L;

@Schema(description = "项目id")
@TableField("project_id")
private Long projectId;

Expand All @@ -47,23 +46,18 @@ public class WsDorisTemplate extends BaseDO {
@TableField("namespace")
private String namespace;

@Schema(description = "session handler")
@TableField("`admin`")
private String admin;

@Schema(description = "fe spec")
@TableField("fe_spec")
private String feSpec;

@Schema(description = "be spec")
@TableField("be_spec")
private String beSpec;

@Schema(description = "cn spec")
@TableField("cn_spec")
private String cnSpec;

@Schema(description = "broker spec")
@TableField("broker_spec")
private String brokerSpec;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* AdminUser describe administrator for manage components in specified cluster.
*/
@Data
public class AdminUser extends BaseSpec {
public class AdminUser {

/**
* the user name for admin service’s node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import cn.sliew.scaleph.engine.doris.service.param.WsDorisTemplateAddParam;
import cn.sliew.scaleph.engine.doris.service.param.WsDorisTemplateListParam;
import cn.sliew.scaleph.engine.doris.service.param.WsDorisTemplateUpdateParam;
import cn.sliew.scaleph.engine.doris.service.resource.DorisTemplate;
import cn.sliew.scaleph.engine.doris.service.resource.template.DorisTemplate;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;
Expand All @@ -33,7 +33,7 @@ public interface WsDorisTemplateService {

WsDorisTemplateDTO selectOne(Long id);

DorisTemplate asYaml(Long id);
DorisTemplate asYaml(WsDorisTemplateDTO dto);

int insert(WsDorisTemplateAddParam param);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class WsDorisTemplateDTO extends BaseDTO {

private String namespace;

@Schema(description = "session handler")
@Schema(description = "admin user")
private AdminUser admin;

@Schema(description = "fe spec")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package cn.sliew.scaleph.engine.doris.service.impl;

import cn.sliew.milky.common.util.JacksonUtil;
import cn.sliew.scaleph.common.util.UUIDUtil;
import cn.sliew.scaleph.dao.entity.master.ws.WsDorisTemplate;
import cn.sliew.scaleph.dao.mapper.master.ws.WsDorisTemplateMapper;
Expand All @@ -27,7 +28,8 @@
import cn.sliew.scaleph.engine.doris.service.param.WsDorisTemplateAddParam;
import cn.sliew.scaleph.engine.doris.service.param.WsDorisTemplateListParam;
import cn.sliew.scaleph.engine.doris.service.param.WsDorisTemplateUpdateParam;
import cn.sliew.scaleph.engine.doris.service.resource.DorisTemplate;
import cn.sliew.scaleph.engine.doris.service.resource.template.DorisTemplate;
import cn.sliew.scaleph.engine.doris.service.resource.template.DorisTemplateConverter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
Expand Down Expand Up @@ -68,22 +70,52 @@ public WsDorisTemplateDTO selectOne(Long id) {
}

@Override
public DorisTemplate asYaml(Long id) {
return null;
public DorisTemplate asYaml(WsDorisTemplateDTO dto) {
return DorisTemplateConverter.INSTANCE.convertTo(dto);
}

@Override
public int insert(WsDorisTemplateAddParam param) {
WsDorisTemplate record = new WsDorisTemplate();
BeanUtils.copyProperties(param, record);
record.setTemplateId(UUIDUtil.randomUUId());
if (param.getAdmin() != null) {
record.setAdmin(JacksonUtil.toJsonString(param.getAdmin()));
}
if (param.getFeSpec() != null) {
record.setFeSpec(JacksonUtil.toJsonString(param.getFeSpec()));
}
if (param.getBeSpec() != null) {
record.setBeSpec(JacksonUtil.toJsonString(param.getBeSpec()));
}
if (param.getCnSpec() != null) {
record.setCnSpec(JacksonUtil.toJsonString(param.getCnSpec()));
}
if (param.getBrokerSpec() != null) {
record.setBrokerSpec(JacksonUtil.toJsonString(param.getBrokerSpec()));
}
return wsDorisTemplateMapper.insert(record);
}

@Override
public int update(WsDorisTemplateUpdateParam param) {
WsDorisTemplate record = new WsDorisTemplate();
BeanUtils.copyProperties(param, record);
if (param.getAdmin() != null) {
record.setAdmin(JacksonUtil.toJsonString(param.getAdmin()));
}
if (param.getFeSpec() != null) {
record.setFeSpec(JacksonUtil.toJsonString(param.getFeSpec()));
}
if (param.getBeSpec() != null) {
record.setBeSpec(JacksonUtil.toJsonString(param.getBeSpec()));
}
if (param.getCnSpec() != null) {
record.setCnSpec(JacksonUtil.toJsonString(param.getCnSpec()));
}
if (param.getBrokerSpec() != null) {
record.setBrokerSpec(JacksonUtil.toJsonString(param.getBrokerSpec()));
}
return wsDorisTemplateMapper.updateById(record);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package cn.sliew.scaleph.engine.doris.service.param;

import cn.sliew.scaleph.engine.doris.operator.spec.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

Expand All @@ -39,6 +40,23 @@ public class WsDorisTemplateAddParam {
@Schema(description = "namespace")
private String namespace;

@NotNull
@Schema(description = "admin user")
private AdminUser admin;

@NotNull
@Schema(description = "fe spec")
private FeSpec feSpec;

@Schema(description = "be spec")
private BeSpec beSpec;

@Schema(description = "cn spec")
private CnSpec cnSpec;

@Schema(description = "broker spec")
private BrokerSpec brokerSpec;

@Schema(description = "remark")
private String remark;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package cn.sliew.scaleph.engine.doris.service.param;

import cn.sliew.scaleph.engine.doris.operator.spec.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

Expand All @@ -39,6 +40,23 @@ public class WsDorisTemplateUpdateParam {
@Schema(description = "namespace")
private String namespace;

@NotNull
@Schema(description = "admin user")
private AdminUser admin;

@NotNull
@Schema(description = "fe spec")
private FeSpec feSpec;

@Schema(description = "be spec")
private BeSpec beSpec;

@Schema(description = "cn spec")
private CnSpec cnSpec;

@Schema(description = "broker spec")
private BrokerSpec brokerSpec;

@Schema(description = "remark")
private String remark;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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
*
* http://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 cn.sliew.scaleph.engine.doris.service.resource.template;

import cn.sliew.scaleph.engine.doris.operator.spec.DorisClusterSpec;
import cn.sliew.scaleph.engine.doris.operator.status.DorisClusterStatus;
import cn.sliew.scaleph.kubernetes.Constant;
import cn.sliew.scaleph.kubernetes.resource.Resource;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Version;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@Group(Constant.SCALEPH_GROUP)
@Version(Constant.SCALEPH_VERSION)
@EqualsAndHashCode
@JsonPropertyOrder({"apiVersion", "kind", "metadata", "spec", "status"})
public class DorisTemplate extends CustomResource<DorisClusterSpec, DorisClusterStatus> implements Resource {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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
*
* http://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 cn.sliew.scaleph.engine.doris.service.resource.template;

import cn.sliew.scaleph.config.resource.ResourceLabels;
import cn.sliew.scaleph.engine.doris.operator.spec.DorisClusterSpec;
import cn.sliew.scaleph.engine.doris.service.dto.WsDorisTemplateDTO;
import cn.sliew.scaleph.kubernetes.resource.ResourceConverter;
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import org.springframework.util.StringUtils;

import java.util.Map;

public enum DorisTemplateConverter implements ResourceConverter<WsDorisTemplateDTO, DorisTemplate> {
INSTANCE;

@Override
public DorisTemplate convertTo(WsDorisTemplateDTO source) {
DorisTemplate template = new DorisTemplate();
ObjectMetaBuilder builder = new ObjectMetaBuilder(true);
String name = StringUtils.hasText(source.getTemplateId()) ? source.getTemplateId() : source.getName();
builder.withName(name);
builder.withNamespace(source.getNamespace());
builder.withLabels(Map.of(ResourceLabels.SCALEPH_LABEL_NAME, source.getName()));
template.setMetadata(builder.build());
DorisClusterSpec spec = new DorisClusterSpec();
spec.setFeSpec(source.getFeSpec());
spec.setBeSpec(source.getBeSpec());
spec.setCnSpec(source.getCnSpec());
spec.setBrokerSpec(source.getBrokerSpec());
spec.setAdminUser(source.getAdmin());
template.setSpec(spec);
return template;
}

@Override
public WsDorisTemplateDTO convertFrom(DorisTemplate target) {
WsDorisTemplateDTO dto = new WsDorisTemplateDTO();
String name = target.getMetadata().getName();
if (target.getMetadata().getLabels() != null) {
Map<String, String> labels = target.getMetadata().getLabels();
name = labels.computeIfAbsent(ResourceLabels.SCALEPH_LABEL_NAME, key -> target.getMetadata().getName());
}
dto.setName(name);
dto.setTemplateId(target.getMetadata().getName());
dto.setNamespace(target.getMetadata().getNamespace());

DorisClusterSpec spec = target.getSpec();
dto.setFeSpec(spec.getFeSpec());
dto.setBeSpec(spec.getBeSpec());
dto.setCnSpec(spec.getCnSpec());
dto.setBrokerSpec(spec.getBrokerSpec());
dto.setAdmin(spec.getAdminUser());
return dto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public interface ResourceConverter<S, T> {

T convertTo(S source) throws Exception;
T convertTo(S source);

S convertFrom(T target);
}
4 changes: 4 additions & 0 deletions scaleph-ui-react/src/locales/zh-CN/pages/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,10 @@ export default {
'pages.project.doris.template.steps.component.base.requests.memory': '内存',
'pages.project.doris.template.steps.component.base.limits.cpu': '最大CPU',
'pages.project.doris.template.steps.component.base.limits.memory': '最大内存',
'pages.project.doris.template.steps.yaml': 'YAML',
'pages.project.doris.template.detail': '模版详情',
'pages.project.doris.template.detail.component': '集群组件',
'pages.project.doris.template.detail.yaml': 'YAML',


'Run': '运行',
Expand Down
Loading

0 comments on commit 5edd3a7

Please sign in to comment.