diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/AbstractSDKOperation.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/AbstractSDKOperation.java new file mode 100644 index 00000000..c2e5b964 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/AbstractSDKOperation.java @@ -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 + * + * 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.function.SDK; + +public abstract class AbstractSDKOperation implements SDKOperation { + + protected T castClient(Object client) { + try { + return (T) client; + } catch (ClassCastException e) { + throw new IllegalArgumentException("Client is not of the expected type", e); + } + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKManager.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKManager.java new file mode 100644 index 00000000..9ac4dbdc --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKManager.java @@ -0,0 +1,116 @@ +/* + * 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.function.SDK; + +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateSDKConfig; +import org.apache.eventmesh.dashboard.console.function.SDK.operation.NacosConfigSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.operation.NacosNamingSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.operation.NacosSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.operation.RedisSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.operation.RocketMQProduceSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.operation.RocketMQPushConsumerSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.operation.RocketMQRemotingSDKOperation; + +import java.util.AbstractMap.SimpleEntry; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + + + +/** + * SDK manager is a singleton to manage all SDK clients, it is a facade to create, delete and get a client. + + */ +public class SDKManager { + + private static final SDKManager INSTANCE = new SDKManager(); + + + public static SDKManager getInstance() { + return INSTANCE; + } + + /** + * inner key is the unique key of a client, such as (ip + port) they are defined in CreateClientConfig + * + * @see CreateSDKConfig#getUniqueKey() + */ + + private final Map> clientMap = new ConcurrentHashMap<>(); + + private final Map> clientCreateOperationMap = new ConcurrentHashMap<>(); + + // register all client create operation + { + for (SDKTypeEnum clientTypeEnum : SDKTypeEnum.values()) { + clientMap.put(clientTypeEnum, new ConcurrentHashMap<>()); + } + + clientCreateOperationMap.put(SDKTypeEnum.STORAGE_REDIS, new RedisSDKOperation()); + + clientCreateOperationMap.put(SDKTypeEnum.STORAGE_ROCKETMQ_REMOTING, new RocketMQRemotingSDKOperation()); + clientCreateOperationMap.put(SDKTypeEnum.STORAGE_ROCKETMQ_PRODUCER, new RocketMQProduceSDKOperation()); + clientCreateOperationMap.put(SDKTypeEnum.STORAGE_ROCKETMQ_CONSUMER, new RocketMQPushConsumerSDKOperation()); + + clientCreateOperationMap.put(SDKTypeEnum.META_NACOS, new NacosSDKOperation()); + clientCreateOperationMap.put(SDKTypeEnum.META_NACOS_CONFIG, new NacosConfigSDKOperation()); + clientCreateOperationMap.put(SDKTypeEnum.META_NACOS_NAMING, new NacosNamingSDKOperation()); + + } + + private SDKManager() { + } + + public SimpleEntry createClient(SDKTypeEnum clientTypeEnum, CreateSDKConfig config) { + return createClient(clientTypeEnum, config.getUniqueKey(), config); + } + + public SimpleEntry createClient(SDKTypeEnum clientTypeEnum, String uniqueKey, CreateSDKConfig config) { + + Map clients = this.clientMap.get(clientTypeEnum); + + Object client = clients.get(uniqueKey); + SimpleEntry result = new SimpleEntry<>(uniqueKey, client); + if (Objects.isNull(client)) { + SDKOperation clientCreateOperation = this.clientCreateOperationMap.get(clientTypeEnum); + result = clientCreateOperation.createClient(config); + clients.put(result.getKey(), result.getValue()); + } + try { + return (SimpleEntry) result; + } catch (Exception e) { + throw new RuntimeException("create client error", e); + } + } + + public void deleteClient(SDKTypeEnum clientTypeEnum, String uniqueKey) { + Map clients = this.clientMap.get(clientTypeEnum); + SDKOperation operation = this.clientCreateOperationMap.get(clientTypeEnum); + try { + operation.close(clients.get(uniqueKey)); + } catch (Exception e) { + throw new RuntimeException("close client error", e); + } + clients.remove(uniqueKey); + } + + public Object getClient(SDKTypeEnum clientTypeEnum, String uniqueKey) { + return this.clientMap.get(clientTypeEnum).get(uniqueKey); + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKOperation.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKOperation.java new file mode 100644 index 00000000..19d264c5 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKOperation.java @@ -0,0 +1,36 @@ +/* + * 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.function.SDK; + +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; + +/** + * Operation to create and close a client, the operations will be store in the SDKManager + * + * @param SDK client + */ +public interface SDKOperation { + + public SimpleEntry createClient(CreateSDKConfig clientConfig); + + + public void close(Object client); + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKTypeEnum.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKTypeEnum.java new file mode 100644 index 00000000..9a44873d --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKTypeEnum.java @@ -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 org.apache.eventmesh.dashboard.console.function.SDK; + +public enum SDKTypeEnum { + + RUNTIME, + + STORAGE_ROCKETMQ_REMOTING, + + STORAGE_ROCKETMQ_PRODUCER, + + STORAGE_ROCKETMQ_CONSUMER, + + STORAGE_REDIS, + + META_NACOS, + META_NACOS_CONFIG, + + META_NACOS_NAMING, + + +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateNacosConfig.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateNacosConfig.java new file mode 100644 index 00000000..856d4de5 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateNacosConfig.java @@ -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 + * + * 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.function.SDK.config; + +import lombok.Data; + +@Data +public class CreateNacosConfig implements CreateSDKConfig { + + private String serverAddress; + + @Override + public String getUniqueKey() { + return serverAddress; + } +} + + diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateRedisConfig.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateRedisConfig.java new file mode 100644 index 00000000..30c53b89 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateRedisConfig.java @@ -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.function.SDK.config; + +import lombok.Data; + +@Data +public class CreateRedisConfig implements CreateSDKConfig { + + private String redisUrl; + + @Override + public String getUniqueKey() { + return redisUrl; + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateRocketmqConfig.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateRocketmqConfig.java new file mode 100644 index 00000000..89424e70 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateRocketmqConfig.java @@ -0,0 +1,55 @@ +/* + * 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.function.SDK.config; + +import org.apache.rocketmq.client.consumer.listener.MessageListener; +import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; + +import lombok.Data; + +@Data +public class CreateRocketmqConfig implements CreateSDKConfig { + + // common + private String nameServerUrl; + private String brokerUrl; + + //consumer + private String consumerGroup; + private MessageModel messageModel = MessageModel.CLUSTERING; + + //producer + private String producerGroup; + + //topic + private String topic; + private String subExpression = "*"; + + private MessageListener messageListener; + + + @Override + public String getUniqueKey() { + if (nameServerUrl != null) { + return nameServerUrl; + } else if (brokerUrl != null) { + return brokerUrl; + } + return null; + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRocketmqCheck.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateSDKConfig.java similarity index 79% rename from eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRocketmqCheck.java rename to eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateSDKConfig.java index c200f076..9a404f2e 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/StorageRocketmqCheck.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/config/CreateSDKConfig.java @@ -15,8 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.dashboard.console.function.health.check.impl; +package org.apache.eventmesh.dashboard.console.function.SDK.config; -public class StorageRocketmqCheck { +/** + * Config to create an SDK client, usually contains an address url. + */ +public interface CreateSDKConfig { + String getUniqueKey(); } diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/EtcdSDKOperation.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/EtcdSDKOperation.java new file mode 100644 index 00000000..75beaf69 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/EtcdSDKOperation.java @@ -0,0 +1,35 @@ +/* + * 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.function.SDK.operation; + +import org.apache.eventmesh.dashboard.console.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; + +public class EtcdSDKOperation extends AbstractSDKOperation { + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + return null; + } + + @Override + public void close(Object client) { + + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/NacosConfigSDKOperation.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/NacosConfigSDKOperation.java new file mode 100644 index 00000000..0757f7bc --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/NacosConfigSDKOperation.java @@ -0,0 +1,58 @@ +/* + * 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.function.SDK.operation; + +import org.apache.eventmesh.dashboard.console.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateNacosConfig; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; +import java.util.Properties; + +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.exception.NacosException; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class NacosConfigSDKOperation extends AbstractSDKOperation { + + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + ConfigService configService = null; + CreateNacosConfig config = (CreateNacosConfig) clientConfig; + try { + Properties properties = new Properties(); + properties.put("serverAddr", config.getServerAddress()); + configService = NacosFactory.createConfigService(properties); + } catch (NacosException e) { + log.error("NacosCheck init failed caused by {}", e.getErrMsg()); + } + return new SimpleEntry<>(config.getServerAddress(), configService); + } + + @Override + public void close(Object client) { + try { + castClient(client).shutDown(); + } catch (NacosException e) { + log.error("NacosCheck close failed caused by {}", e.getErrMsg()); + } + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/NacosNamingSDKOperation.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/NacosNamingSDKOperation.java new file mode 100644 index 00000000..54fcd05b --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/NacosNamingSDKOperation.java @@ -0,0 +1,59 @@ +/* + * 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.function.SDK.operation; + +import org.apache.eventmesh.dashboard.console.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateNacosConfig; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; +import java.util.Properties; + +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.api.naming.NamingService; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class NacosNamingSDKOperation extends AbstractSDKOperation { + + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + NamingService namingService = null; + CreateNacosConfig config = (CreateNacosConfig) clientConfig; + try { + Properties properties = new Properties(); + properties.put("serverAddr", config.getServerAddress()); + namingService = NacosFactory.createNamingService(properties); + } catch (NacosException e) { + log.error("NacosCheck init failed caused by {}", e.getErrMsg()); + } + return new SimpleEntry<>(config.getUniqueKey(), namingService); + } + + @Override + public void close(Object client) { + try { + ((ConfigService) client).shutDown(); + } catch (NacosException e) { + log.error("NacosCheck close failed caused by {}", e.getErrMsg()); + } + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/NacosSDKOperation.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/NacosSDKOperation.java new file mode 100644 index 00000000..e0b326e7 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/NacosSDKOperation.java @@ -0,0 +1,55 @@ +/* + * 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.function.SDK.operation; + +import org.apache.eventmesh.dashboard.console.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateSDKConfig; +import org.apache.eventmesh.dashboard.console.function.SDK.wrapper.NacosSDKWrapper; + +import java.util.AbstractMap.SimpleEntry; + +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.naming.NamingService; + +public class NacosSDKOperation extends AbstractSDKOperation { + + private final NacosConfigSDKOperation nacosConfigClientCreateOperation = new NacosConfigSDKOperation(); + private final NacosNamingSDKOperation nacosNamingClientCreateOperation = new NacosNamingSDKOperation(); + + @Override + public SimpleEntry createClient(CreateSDKConfig createClientConfig) { + SimpleEntry configSimpleEntry = nacosConfigClientCreateOperation.createClient(createClientConfig); + SimpleEntry namingSimpleEntry = nacosNamingClientCreateOperation.createClient(createClientConfig); + if (configSimpleEntry.getKey() != namingSimpleEntry.getKey()) { + throw new RuntimeException("Nacos config and naming server address not match"); + } + NacosSDKWrapper nacosClient = new NacosSDKWrapper( + (ConfigService) configSimpleEntry.getValue(), (NamingService) namingSimpleEntry.getValue() + ); + return new SimpleEntry<>(configSimpleEntry.getKey(), nacosClient); + } + + @Override + public void close(Object client) { + try { + castClient(client).shutdown(); + } catch (Exception e) { + throw new RuntimeException("Nacos client close failed", e); + } + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RedisSDKOperation.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RedisSDKOperation.java new file mode 100644 index 00000000..ec50d422 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RedisSDKOperation.java @@ -0,0 +1,42 @@ +/* + * 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.function.SDK.operation; + +import org.apache.eventmesh.dashboard.console.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateRedisConfig; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; + +import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulRedisConnection; + +public class RedisSDKOperation extends AbstractSDKOperation> { + + @Override + public SimpleEntry> createClient(CreateSDKConfig clientConfig) { + String redisUrl = ((CreateRedisConfig) clientConfig).getRedisUrl(); + RedisClient redisClient = RedisClient.create(redisUrl); + return new SimpleEntry<>(clientConfig.getUniqueKey(), redisClient.connect()); + } + + @Override + public void close(Object client) { + castClient(client).close(); + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RocketMQProduceSDKOperation.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RocketMQProduceSDKOperation.java new file mode 100644 index 00000000..2dde6c30 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RocketMQProduceSDKOperation.java @@ -0,0 +1,53 @@ +/* + * 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.function.SDK.operation; + +import org.apache.eventmesh.dashboard.console.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateRocketmqConfig; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateSDKConfig; + +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.client.producer.DefaultMQProducer; + +import java.util.AbstractMap.SimpleEntry; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RocketMQProduceSDKOperation extends AbstractSDKOperation { + + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + DefaultMQProducer producer = null; + try { + CreateRocketmqConfig config = (CreateRocketmqConfig) clientConfig; + producer = new DefaultMQProducer(config.getProducerGroup()); + producer.setNamesrvAddr(config.getNameServerUrl()); + producer.setCompressMsgBodyOverHowmuch(16); + producer.start(); + } catch (MQClientException e) { + log.error("create rocketmq producer failed", e); + } + return new SimpleEntry<>(clientConfig.getUniqueKey(), producer); + } + + @Override + public void close(Object client) { + ((DefaultMQProducer) client).shutdown(); + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RocketMQPushConsumerSDKOperation.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RocketMQPushConsumerSDKOperation.java new file mode 100644 index 00000000..f25d4df0 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RocketMQPushConsumerSDKOperation.java @@ -0,0 +1,55 @@ +/* + * 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.function.SDK.operation; + +import org.apache.eventmesh.dashboard.console.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateRocketmqConfig; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateSDKConfig; + +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.exception.MQClientException; + +import java.util.AbstractMap.SimpleEntry; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RocketMQPushConsumerSDKOperation extends AbstractSDKOperation { + + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + DefaultMQPushConsumer consumer = null; + try { + CreateRocketmqConfig config = (CreateRocketmqConfig) clientConfig; + consumer = new DefaultMQPushConsumer(config.getConsumerGroup()); + consumer.setMessageModel(config.getMessageModel()); + consumer.setNamesrvAddr(config.getNameServerUrl()); + consumer.subscribe(config.getTopic(), config.getSubExpression()); + consumer.registerMessageListener(config.getMessageListener()); + consumer.start(); + } catch (MQClientException e) { + log.error("create rocketmq push consumer failed", e); + } + return new SimpleEntry(((CreateRocketmqConfig) clientConfig).getNameServerUrl(), consumer); + } + + @Override + public void close(Object client) { + ((DefaultMQPushConsumer) client).shutdown(); + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RocketMQRemotingSDKOperation.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RocketMQRemotingSDKOperation.java new file mode 100644 index 00000000..3c88ff4e --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RocketMQRemotingSDKOperation.java @@ -0,0 +1,44 @@ +/* + * 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.function.SDK.operation; + +import org.apache.eventmesh.dashboard.console.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateSDKConfig; + +import org.apache.rocketmq.remoting.RemotingClient; +import org.apache.rocketmq.remoting.netty.NettyClientConfig; +import org.apache.rocketmq.remoting.netty.NettyRemotingClient; + +import java.util.AbstractMap.SimpleEntry; + +public class RocketMQRemotingSDKOperation extends AbstractSDKOperation { + + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + NettyClientConfig config = new NettyClientConfig(); + config.setUseTLS(false); + RemotingClient remotingClient = new NettyRemotingClient(config); + remotingClient.start(); + return new SimpleEntry<>(clientConfig.getUniqueKey(), remotingClient); + } + + @Override + public void close(Object client) { + ((RemotingClient) client).shutdown(); + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RuntimeSDKOperation.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RuntimeSDKOperation.java new file mode 100644 index 00000000..65d358c8 --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RuntimeSDKOperation.java @@ -0,0 +1,35 @@ +/* + * 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.function.SDK.operation; + +import org.apache.eventmesh.dashboard.console.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; + +public class RuntimeSDKOperation extends AbstractSDKOperation { + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + return null; + } + + @Override + public void close(Object client) { + + } +} diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/wrapper/NacosSDKWrapper.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/wrapper/NacosSDKWrapper.java new file mode 100644 index 00000000..7f9e3ffa --- /dev/null +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/SDK/wrapper/NacosSDKWrapper.java @@ -0,0 +1,36 @@ +/* + * 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.function.SDK.wrapper; + +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.api.naming.NamingService; + +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public class NacosSDKWrapper { + + public void shutdown() throws NacosException { + configService.shutDown(); + namingService.shutDown(); + } + + private ConfigService configService; + private NamingService namingService; +} diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKManagerTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKManagerTest.java new file mode 100644 index 00000000..4eccdb0f --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/SDK/SDKManagerTest.java @@ -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 org.apache.eventmesh.dashboard.console.function.SDK; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateRedisConfig; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +class SDKManagerTest { + + private final CreateRedisConfig createRedisConfig = new CreateRedisConfig(); + private String redisKey; + + @BeforeEach + void setUp() { + try { + createRedisConfig.setRedisUrl("redis://localhost:6379"); + redisKey = SDKManager.getInstance().createClient(SDKTypeEnum.STORAGE_REDIS, createRedisConfig).getKey(); + } catch (Exception e) { + log.warn("SDK manager test init failed, possible reason: redis-server is offline. {}", this.getClass().getSimpleName(), e); + } + } + + @Test + public void testGetClient() { + try { + Object redisClient = SDKManager.getInstance().getClient(SDKTypeEnum.STORAGE_REDIS, redisKey); + assertNotNull(redisClient); + } catch (Exception e) { + log.warn("SDK manager test failed, possible reason: redis-server is offline. {}", this.getClass().getSimpleName(), e); + } + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RedisSDKCreateOperationTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RedisSDKCreateOperationTest.java new file mode 100644 index 00000000..33a06b8e --- /dev/null +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/SDK/operation/RedisSDKCreateOperationTest.java @@ -0,0 +1,53 @@ +/* + * 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.function.SDK.operation; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.apache.eventmesh.dashboard.console.function.SDK.config.CreateRedisConfig; + +import java.util.AbstractMap.SimpleEntry; + +import org.junit.jupiter.api.Test; + +import io.lettuce.core.api.StatefulRedisConnection; + +import lombok.extern.slf4j.Slf4j; + + + +@Slf4j +class RedisSDKCreateOperationTest { + + private RedisSDKOperation redisClientCreateOperation = new RedisSDKOperation(); + + @Test + void testCreateClient() { + CreateRedisConfig createClientConfig = new CreateRedisConfig(); + createClientConfig.setRedisUrl("redis://localhost:6379"); + try { + SimpleEntry> simpleEntry = redisClientCreateOperation.createClient(createClientConfig); + assertEquals("redis://localhost:6379", simpleEntry.getKey()); + String response = simpleEntry.getValue().sync().ping(); + log.info("response:{}", response); + } catch (Exception e) { + log.error("create redis client failed", e); + } + + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/cluster/TestClusterMapper.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/cluster/TestClusterMapper.java index c8625aae..0cad435f 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/cluster/TestClusterMapper.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/cluster/TestClusterMapper.java @@ -1,3 +1,20 @@ +/* + * 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.unit.cluster; import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/config/TestConfigMapper.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/config/TestConfigMapper.java index 417d75e8..97f5e118 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/config/TestConfigMapper.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/config/TestConfigMapper.java @@ -1,3 +1,20 @@ +/* + * 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.unit.config; @@ -5,12 +22,9 @@ import org.apache.eventmesh.dashboard.console.entity.config.ConfigEntity; import org.apache.eventmesh.dashboard.console.mapper.config.ConfigMapper; - import java.util.ArrayList; - import java.util.List; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/runtime/TestRuntimeMapper.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/runtime/TestRuntimeMapper.java index ad99e091..3baa57d4 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/runtime/TestRuntimeMapper.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/runtime/TestRuntimeMapper.java @@ -1,3 +1,20 @@ +/* + * 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.unit.runtime; import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; @@ -23,7 +40,7 @@ public class TestRuntimeMapper { @Test public void testAddRuntimeMapper() { - RuntimeEntity runtimeEntity = new RuntimeEntity(null, 1l, "runtime1", 2l, 1019, 1099, 1L, "null", 1, null, null, "null"); + RuntimeEntity runtimeEntity = new RuntimeEntity(null, 1L, "runtime1", 2L, 1019, 1099, 1L, "null", 1, null, null, "null"); runtimeMapper.addRuntime(runtimeEntity); List runtimeEntities = runtimeMapper.selectRuntimeByCluster(runtimeEntity); RuntimeEntity runtimeEntity1 = runtimeEntities.get(0); @@ -34,7 +51,7 @@ public void testAddRuntimeMapper() { @Test public void testUpdateRuntimeByCluster() { - RuntimeEntity runtimeEntity = new RuntimeEntity(null, 1l, "runtime1", 2l, 1019, 1099, 1L, "null", 1, null, null, "null"); + RuntimeEntity runtimeEntity = new RuntimeEntity(null, 1L, "runtime1", 2L, 1019, 1099, 1L, "null", 1, null, null, "null"); runtimeMapper.addRuntime(runtimeEntity); runtimeEntity.setPort(1000); runtimeEntity.setJmxPort(1099); @@ -49,7 +66,7 @@ public void testUpdateRuntimeByCluster() { @Test public void testDeleteRuntime() { - RuntimeEntity runtimeEntity = new RuntimeEntity(null, 1l, "runtime1", 2l, 1019, 1099, 1L, "null", 1, null, null, "null"); + RuntimeEntity runtimeEntity = new RuntimeEntity(null, 1L, "runtime1", 2L, 1019, 1099, 1L, "null", 1, null, null, "null"); runtimeMapper.addRuntime(runtimeEntity); runtimeMapper.deleteRuntimeByCluster(runtimeEntity); List runtimeEntities = runtimeMapper.selectRuntimeByCluster(runtimeEntity); diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/store/TestStoreMapper.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/store/TestStoreMapper.java index 5876f828..45355472 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/store/TestStoreMapper.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/unit/store/TestStoreMapper.java @@ -1,3 +1,20 @@ +/* + * 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.unit.store; import org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication; @@ -24,9 +41,9 @@ public class TestStoreMapper { @Test public void testAddStore() { StoreEntity storeEntity = - new StoreEntity(null, 1l, 2, "rocketmq", "run1", 1l, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1l); + new StoreEntity(null, 1L, 2, "rocketmq", "run1", 1L, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1L); StoreEntity storeEntity1 = - new StoreEntity(null, 1l, 1, "rocketmq", "run1", 1l, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1l); + new StoreEntity(null, 1L, 1, "rocketmq", "run1", 1L, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1L); storeMapper.addStore(storeEntity); storeMapper.addStore(storeEntity1); List storeEntities = storeMapper.selectStoreByCluster(storeEntity); @@ -41,7 +58,7 @@ public void testAddStore() { @Test public void testDeleteStoreByUnique() { StoreEntity storeEntity = - new StoreEntity(null, 1l, 2, "rocketmq", "run1", 1l, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1l); + new StoreEntity(null, 1L, 2, "rocketmq", "run1", 1L, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1L); storeMapper.addStore(storeEntity); storeMapper.deleteStoreByUnique(storeEntity); List storeEntities = storeMapper.selectStoreByCluster(storeEntity); @@ -51,7 +68,7 @@ public void testDeleteStoreByUnique() { @Test public void testUpdateStoreByUnique() { StoreEntity storeEntity = - new StoreEntity(null, 1l, 2, "rocketmq", "run1", 1l, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1l); + new StoreEntity(null, 1L, 2, "rocketmq", "run1", 1L, "n,j", (short) -1, 1098, 1099, "nothing", (short) 1, null, null, "nothing", 1L); storeMapper.addStore(storeEntity); storeEntity.setStatus((short) 5); storeMapper.updateStoreByUnique(storeEntity);