Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature][scaleph-ui-react] update scaleph-ui-react2 module #681

Merged
merged 16 commits into from
Jan 5, 2024
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.api.controller.ws;

import cn.sliew.scaleph.api.annotation.Logging;
import cn.sliew.scaleph.common.dict.seatunnel.SeaTunnelEngineType;
import cn.sliew.scaleph.dag.xflow.dnd.DndDTO;
import cn.sliew.scaleph.engine.seatunnel.service.SeaTunnelDagService;
import cn.sliew.scaleph.plugin.framework.exception.PluginException;
import cn.sliew.scaleph.system.model.ResponseVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "SeaTunnel")
@RestController
@RequestMapping(path = {"/api/seatunnel", "/api/seatunnel"})
public class WsSeaTunnelController {

@Autowired
private SeaTunnelDagService seaTunnelDagService;

@Logging
@GetMapping("/dag/dnd/{type}")
@Operation(summary = "查询DAG节点元信息", description = "后端统一返回节点信息")
public ResponseEntity<ResponseVO<List<DndDTO>>> loadNodeMeta(@PathVariable("type") SeaTunnelEngineType type) throws PluginException {
List<DndDTO> dnds = seaTunnelDagService.getDnds(type);
return new ResponseEntity<>(ResponseVO.success(dnds), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.seatunnel.dag.dnd;

import cn.sliew.scaleph.common.dict.seatunnel.SeaTunnelConnectorFeature;
import cn.sliew.scaleph.common.dict.seatunnel.SeaTunnelConnectorHealth;
import cn.sliew.scaleph.dag.xflow.dnd.DndDTO;
import lombok.Data;

@Data
public class SeaTunnelDagDndDTO extends DndDTO {

private SeaTunnelConnectorHealth health;

private SeaTunnelConnectorFeature[] features;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.seatunnel.dag.dnd;

import cn.sliew.scaleph.dag.xflow.dnd.DndMeta;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@Schema(name = "SeaTunnel 节点元数据", description = "SeaTunnel 节点元数据")
public class SeaTunnelDagDndMeta extends DndMeta {

/**
* @see cn.sliew.scaleph.common.dict.seatunnel.SeaTunnelPluginName
*/
@Schema(description = "connector name")
private String name;

/**
* @see cn.sliew.scaleph.common.dict.seatunnel.SeaTunnelPluginType
*/
@Schema(description = "connector type")
private String type;

/**
* @see cn.sliew.scaleph.common.dict.seatunnel.SeaTunnelEngineType
*/
@Schema(description = "engine type")
private String engine;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.seatunnel.service;

import cn.sliew.scaleph.common.dict.seatunnel.SeaTunnelEngineType;
import cn.sliew.scaleph.dag.service.DagDndService;
import cn.sliew.scaleph.dag.xflow.dnd.DndDTO;

import java.util.List;

public interface SeaTunnelDagService extends DagDndService {

List<DndDTO> getDnds(SeaTunnelEngineType engineType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* 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.seatunnel.service.impl;

import cn.sliew.scaleph.common.dict.seatunnel.SeaTunnelEngineType;
import cn.sliew.scaleph.common.dict.seatunnel.SeaTunnelPluginType;
import cn.sliew.scaleph.dag.xflow.dnd.DndDTO;
import cn.sliew.scaleph.dag.xflow.dnd.DndPortDTO;
import cn.sliew.scaleph.dag.xflow.dnd.DndPortGroupEnum;
import cn.sliew.scaleph.engine.seatunnel.dag.dnd.SeaTunnelDagDndDTO;
import cn.sliew.scaleph.engine.seatunnel.dag.dnd.SeaTunnelDagDndMeta;
import cn.sliew.scaleph.engine.seatunnel.service.SeaTunnelDagService;
import cn.sliew.scaleph.engine.seatunnel.service.SeatunnelConnectorService;
import cn.sliew.scaleph.plugin.framework.core.PluginInfo;
import cn.sliew.scaleph.plugin.seatunnel.flink.SeaTunnelConnectorPlugin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import static cn.sliew.scaleph.common.dict.seatunnel.SeaTunnelEngineType.SEATUNNEL;

@Service
public class SeaTunnelDagServiceImpl implements SeaTunnelDagService {

@Autowired
private SeatunnelConnectorService seatunnelConnectorService;

@Override
public List<DndDTO> getDnds() {
return getDnds(SEATUNNEL);
}

@Override
public List<DndDTO> getDnds(SeaTunnelEngineType engineType) {
switch (engineType) {
case SEATUNNEL:
return loadSeaTunnelPanel();
default:
return Collections.emptyList();
}
}

private List<DndDTO> loadSeaTunnelPanel() {
List<DndDTO> dnds = new ArrayList();
for (SeaTunnelPluginType pluginType : SeaTunnelPluginType.values()) {
dnds.add(buildSeaTunnelPluginType(pluginType));
}
return dnds;
}

private SeaTunnelDagDndDTO buildSeaTunnelPluginType(SeaTunnelPluginType pluginType) {
SeaTunnelDagDndDTO category = new SeaTunnelDagDndDTO();
category.setKey(pluginType.getValue());
category.setTitle(pluginType.getLabel());
category.setDocString(pluginType.getRemark());
category.setIsLeaf(false);
List<DndDTO> children = new ArrayList();
Set<SeaTunnelConnectorPlugin> plugins = seatunnelConnectorService.getAvailableConnectors(pluginType);
for (SeaTunnelConnectorPlugin plugin : plugins) {
SeaTunnelDagDndDTO child = buildSeaTunnelConnector(category, plugin);
SeaTunnelDagDndMeta meta = buildPluginInfo(plugin);
child.setMeta(meta);
List<DndPortDTO> ports;
switch (pluginType) {
case SOURCE:
ports = getSourcePorts(child.getKey());
break;
case SINK:
ports = getSinkPorts(child.getKey());
break;
case TRANSFORM:
ports = getTransformPorts(child.getKey());
break;
default:
ports = Collections.emptyList();
}
child.setPorts(ports);
children.add(child);
}
category.setChildren(children);
return category;
}

private SeaTunnelDagDndDTO buildSeaTunnelConnector(SeaTunnelDagDndDTO category, SeaTunnelConnectorPlugin plugin) {
PluginInfo pluginInfo = plugin.getPluginInfo();
SeaTunnelDagDndDTO node = new SeaTunnelDagDndDTO();
node.setCategory(category.getKey());
node.setKey(pluginInfo.getName());
node.setTitle(plugin.getPluginName().getLabel());
node.setDocString(pluginInfo.getDescription());
node.setIsLeaf(true);
node.setHealth(plugin.getPluginHealth());
node.setFeatures(plugin.getPluginFeatures());
return node;
}

private SeaTunnelDagDndMeta buildPluginInfo(SeaTunnelConnectorPlugin connector) {
SeaTunnelDagDndMeta meta = new SeaTunnelDagDndMeta();
meta.setName(connector.getPluginName().getValue());
meta.setType(connector.getPluginType().getValue());
meta.setEngine(connector.getEngineType().getValue());
return meta;
}


private List<DndPortDTO> getSourcePorts(String key) {
List<DndPortDTO> ports = new ArrayList<>();
DndPortDTO portDTO = new DndPortDTO();
portDTO.setId(key + "-" + DndPortGroupEnum.bottom.name());
portDTO.setGroup(DndPortGroupEnum.bottom.name());
ports.add(portDTO);
return ports;
}

private List<DndPortDTO> getSinkPorts(String key) {
List<DndPortDTO> ports = new ArrayList<>();
DndPortDTO portDTO = new DndPortDTO();
portDTO.setId(key + "-" + DndPortGroupEnum.top.name());
portDTO.setGroup(DndPortGroupEnum.top.name());
ports.add(portDTO);
return ports;
}

private List<DndPortDTO> getTransformPorts(String key) {
List<DndPortDTO> ports = new ArrayList<>();
DndPortDTO sourcePort = new DndPortDTO();
sourcePort.setId(key + "-" + DndPortGroupEnum.top.name());
sourcePort.setGroup(DndPortGroupEnum.top.name());
ports.add(sourcePort);

DndPortDTO sinkPort = new DndPortDTO();
sinkPort.setId(key + "-" + DndPortGroupEnum.bottom.name());
sinkPort.setGroup(DndPortGroupEnum.bottom.name());
ports.add(sinkPort);
return ports;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.dag.service;

import cn.sliew.scaleph.dag.xflow.dnd.DndDTO;

import java.util.List;

public interface DagDndService {

List<DndDTO> getDnds();
}
Loading