Skip to content

Commit

Permalink
test: 完成从controller添加注册中心,启动同步服务和健康检查的流程
Browse files Browse the repository at this point in the history
  • Loading branch information
Lambert-Rao committed Apr 8, 2024
1 parent 03a6a00 commit 642ca79
Show file tree
Hide file tree
Showing 40 changed files with 205 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 org.apache.eventmesh.dashboard.console.controller;

import java.sql.Timestamp;

import org.apache.eventmesh.dashboard.common.enums.RecordStatus;

import org.apache.eventmesh.dashboard.console.entity.meta.MetaEntity;
import org.apache.eventmesh.dashboard.console.modle.dto.meta.NewMetaDTO;
import org.apache.eventmesh.dashboard.console.service.registry.RegistryDataService;

import org.apache.kafka.common.protocol.types.Field.Str;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MetaController {

@Autowired
private RegistryDataService metaService;

@PostMapping("/meta/newMeta")
public String addRegistry(@Validated @RequestBody NewMetaDTO newMetaDTO) {
MetaEntity query = new MetaEntity();
query.setName("");
query.setType("");
query.setVersion("");
query.setClusterId(0L);
query.setHost(newMetaDTO.getMetaHost());
query.setPort(newMetaDTO.getMetaPort());
query.setRole("");
query.setUsername("");
query.setParams("");
query.setClusterId(0L);

metaService.insert(query);

return "success";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,4 @@ public Object druidStat() {
public Result<String> hello() {
return Result.success("Hello, EventMesh Dashboard!");
}

@GetMapping("/hello2")
public String hello2() {
return "Hello, EventMesh Dashboard!";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = "status")
public class ClientEntity extends BaseEntity {

private static final long serialVersionUID = 8204133370609215856L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true, exclude = "status")
public class ClusterEntity extends BaseEntity {

private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = {"endTime"})
@EqualsAndHashCode(callSuper = true, exclude = {"status", "endTime"})
public class ConnectionEntity extends BaseEntity {

private static final long serialVersionUID = 6565578252656944905L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode(callSuper = true, exclude = "status")
@Builder
public class ConnectorEntity extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Data
@EqualsAndHashCode(callSuper = true, exclude = "status")
public class GroupEntity extends BaseEntity {

private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = "status")
public class GroupMemberEntity extends BaseEntity {

private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = "resultDesc")
@Schema(name = "HealthCheckResultEntity", description = "Health check result entity")
public class HealthCheckResultEntity extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = {"endTime", "operationUser", "result"})
public class LogEntity extends BaseEntity {

private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = "status")
public class MetaEntity extends BaseEntity {

private static final long serialVersionUID = 7176263169716424469L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor

@EqualsAndHashCode(callSuper = true, exclude = "status")
public class RuntimeEntity extends BaseEntity {
private Long clusterId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = "status")
public class StoreEntity extends BaseEntity {

private Long clusterId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = "status")
public class TopicEntity extends BaseEntity {

private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ public void insertCheckService(HealthCheckObjectConfig config) {
Class<?> clazz = entry.getValue();
HealthCheckType annotation = clazz.getAnnotation(HealthCheckType.class);
if (Objects.isNull(annotation)) {
throw new IllegalStateException(
"HealthCheckService must be annotated with HealthCheckType, class is {}" + clazz.getSimpleName());
continue;
}
if (annotation.value().equals(config.getHealthCheckResourceType()) || annotation.value()
if (annotation.type().equals(config.getHealthCheckResourceType()) && annotation.subType()
.equals(config.getHealthCheckResourceSubType())) {
healthCheckService = createCheckService(clazz, config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
public @interface HealthCheckType {
/**
* type of resource. runtime, topic etc.
* if resource have a subtype, '-' is used to connect type and subtype.
* such as rocketmq4-broker
*/
String value();
String type();

/**
* subtype of resource. For resource storage, it can be redis, rocketmq etc.
*/
String subType() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.eventmesh.dashboard.console.function.health.check.impl.meta;

import static org.apache.eventmesh.dashboard.common.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_NACOS_CONFIG;
import static org.apache.eventmesh.dashboard.common.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_TYPE_META;
import static org.apache.eventmesh.dashboard.common.constant.health.HealthConstant.NACOS_CHECK_CONTENT;
import static org.apache.eventmesh.dashboard.common.constant.health.HealthConstant.NACOS_CHECK_DATA_ID;
import static org.apache.eventmesh.dashboard.common.constant.health.HealthConstant.NACOS_CHECK_GROUP;
Expand All @@ -40,7 +41,7 @@
*
*/
@Slf4j
@HealthCheckType(value = HEALTH_CHECK_SUBTYPE_NACOS_CONFIG)
@HealthCheckType(type = HEALTH_CHECK_TYPE_META, subType = HEALTH_CHECK_SUBTYPE_NACOS_CONFIG)
public class NacosConfigCheck extends AbstractHealthCheckService {

private ConfigService configService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.eventmesh.dashboard.console.function.health.check.impl.meta;

import static org.apache.eventmesh.dashboard.common.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_NACOS_REGISTRY;
import static org.apache.eventmesh.dashboard.common.constant.health.HealthCheckTypeConstant.HEALTH_CHECK_TYPE_META;
import static org.apache.eventmesh.dashboard.common.constant.health.HealthConstant.NACOS_CHECK_SERVICE_CLUSTER_NAME;
import static org.apache.eventmesh.dashboard.common.constant.health.HealthConstant.NACOS_CHECK_SERVICE_NAME;

Expand All @@ -41,7 +42,7 @@
*/

@Slf4j
@HealthCheckType(value = HEALTH_CHECK_SUBTYPE_NACOS_REGISTRY)
@HealthCheckType(type = HEALTH_CHECK_TYPE_META, subType = HEALTH_CHECK_SUBTYPE_NACOS_REGISTRY)
public class NacosNamingServiceCheck extends AbstractHealthCheckService {

private NamingService namingService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@HealthCheckType(value = HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_REDIS)
@HealthCheckType(type = HealthCheckTypeConstant.HEALTH_CHECK_TYPE_STORAGE, subType = HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_REDIS)
public class RedisCheck extends AbstractHealthCheckService {

private RedisClient redisClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@HealthCheckType(HealthCheckTypeConstant.HEALTH_CHECK_TYPE_STORAGE)
@HealthCheckType(type = HealthCheckTypeConstant.HEALTH_CHECK_TYPE_STORAGE, subType = HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_ROCKETMQ)
public class Rocketmq4NameServerCheck extends AbstractHealthCheckService {

private RemotingClient remotingClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public class GroupMetadataHandlerToDbImpl implements MetadataHandler<GroupMetada
@Override
public void addMetadata(GroupMetadata meta) {
meta.setMemberCount(0);
groupService.addGroup(converter.convert(meta));
GroupEntity groupEntity = converter.convert(meta);
groupService.addGroup(groupEntity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public GroupEntity convert(GroupMetadata source) {

@Override
public String getUnique(GroupMetadata source) {
return null;
return source.getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public TopicEntity convert(TopicMetadata source) {
topicEntity.setDescription(source.getDescription());
topicEntity.setStatus(1);
topicEntity.setClusterId(source.getClusterId());
topicEntity.setCreateProgress(1);

return topicEntity;
}
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
*
* 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 org.apache.eventmesh.dashboard.console.modle.dto.meta;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class NewMetaDTO {

String metaHost;
Integer metaPort;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface GroupService {

List<GroupEntity> getGroupByClusterId(GroupEntity groupEntity);

GroupEntity addGroup(GroupEntity groupEntity);
void addGroup(GroupEntity groupEntity);

void updateGroup(GroupEntity groupEntity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ public List<GroupEntity> getGroupByClusterId(GroupEntity groupEntity) {

@EmLog(OprType = "add", OprTarget = "Group")
@Override
public GroupEntity addGroup(GroupEntity groupEntity) {
public void addGroup(GroupEntity groupEntity) {
oprGroupMapper.addGroup(groupEntity);
return groupEntity;
}

@Override
Expand Down
Loading

0 comments on commit 642ca79

Please sign in to comment.