This is an automated email from the ASF dual-hosted git repository. shenlin pushed a commit to branch feat/runtime-manager in repository https://gitbox.apache.org/repos/asf/rocketmq-eventbridge.git
The following commit(s) were added to refs/heads/feat/runtime-manager by this push: new 4e4b4c0 feat:upgrade the runtime manager api. 4e4b4c0 is described below commit 4e4b4c0f3d355ab140145883f2ee8c63d96bd5d7 Author: 2011shenlin <2011shen...@gmail.com> AuthorDate: Sun Nov 19 16:07:06 2023 +0800 feat:upgrade the runtime manager api. --- .../runtime/manager/cluster/ClusterService.java | 5 +++- .../manager/repository/ClusterRepository.java | 28 ++++++++++++++++++ .../repository/WorkerInstanceRepository.java | 3 +- .../manager/repository/WorkerRepository.java} | 34 +++++++--------------- .../adapter/runtime/manager/watch/WatchWorker.java | 4 ++- .../runtime/manager/worker/WorkerResource.java | 26 +++++++++++++++++ .../repository/WorkerInstanceRepositoryOnK8S.java | 3 +- scan.py | 0 8 files changed, 75 insertions(+), 28 deletions(-) diff --git a/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/cluster/ClusterService.java b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/cluster/ClusterService.java index 057a8db..4e51c3b 100644 --- a/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/cluster/ClusterService.java +++ b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/cluster/ClusterService.java @@ -20,9 +20,12 @@ package org.apache.rocketmq.eventbridge.adapter.runtime.manager.cluster; import com.google.common.base.Strings; import java.util.List; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.rocketmq.eventbridge.adapter.runtime.manager.repository.ClusterRepository; public class ClusterService { + private ClusterRepository clusterRepository; + public boolean createCluster() { return true; } @@ -36,7 +39,7 @@ public class ClusterService { } public List<Cluster> listCluster() { - return null; + return clusterRepository.listCluster(); } public String calMD5(Cluster cluster) { diff --git a/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/repository/ClusterRepository.java b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/repository/ClusterRepository.java new file mode 100644 index 0000000..38c1c58 --- /dev/null +++ b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/repository/ClusterRepository.java @@ -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 org.apache.rocketmq.eventbridge.adapter.runtime.manager.repository; + +import java.util.List; +import org.apache.rocketmq.eventbridge.adapter.runtime.manager.cluster.Cluster; + +public interface ClusterRepository { + + List<Cluster> listCluster(); + + boolean updateCluster(Cluster cluster); +} diff --git a/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/repository/WorkerInstanceRepository.java b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/repository/WorkerInstanceRepository.java index a1fd579..1c74a3b 100644 --- a/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/repository/WorkerInstanceRepository.java +++ b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/repository/WorkerInstanceRepository.java @@ -18,6 +18,7 @@ package org.apache.rocketmq.eventbridge.adapter.runtime.manager.repository; import java.util.Map; +import org.apache.rocketmq.eventbridge.adapter.runtime.manager.worker.WorkerResource; import org.apache.rocketmq.eventbridge.adapter.runtime.manager.worker.WorkerStatusEnum; public interface WorkerInstanceRepository { @@ -31,7 +32,7 @@ public interface WorkerInstanceRepository { * @param environments * @return */ - boolean applyWorkerInstance(String name, String image, String resources, Map<String, Object> environments); + boolean applyWorkerInstance(String name, String image, WorkerResource resources, Map<String, Object> environments); /** * Delete the worker diff --git a/adapter/runtime-on-k8s/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/k8s/repository/WorkerInstanceRepositoryOnK8S.java b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/repository/WorkerRepository.java similarity index 52% copy from adapter/runtime-on-k8s/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/k8s/repository/WorkerInstanceRepositoryOnK8S.java copy to adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/repository/WorkerRepository.java index 0299ddb..c35fefb 100644 --- a/adapter/runtime-on-k8s/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/k8s/repository/WorkerInstanceRepositoryOnK8S.java +++ b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/repository/WorkerRepository.java @@ -15,35 +15,21 @@ * limitations under the License. */ -package org.apache.rocketmq.eventbridge.adapter.runtime.manager.k8s.repository; +package org.apache.rocketmq.eventbridge.adapter.runtime.manager.repository; -import java.util.Map; -import org.apache.rocketmq.eventbridge.adapter.runtime.manager.repository.WorkerInstanceRepository; -import org.apache.rocketmq.eventbridge.adapter.runtime.manager.worker.WorkerStatusEnum; +import java.util.List; +import org.apache.rocketmq.eventbridge.adapter.runtime.manager.worker.Worker; -public class WorkerInstanceRepositoryOnK8S implements WorkerInstanceRepository { +public interface WorkerRepository { + List<Worker> listWorkers(int clusterId); - @Override - public boolean applyWorkerInstance(String name, String image, String resources, Map<String, Object> environments) { - return false; - } + boolean createWorker(Worker worker); - @Override - public boolean deleteWorkerInstance(String name) { - return false; - } + boolean updateWorker(Worker worker); - @Override public WorkerStatusEnum getWorkerInstanceStatus(String name) { - return null; - } + boolean deleteWorker(int workerId); - @Override public boolean applyWorkerInstanceConfigFile(String name, String filePath, String config) { - return false; - } + boolean deleteWorkers(int clusterId); - @Override public boolean getWorkerInstanceConfigFile(String name, String filePath) { - return false; - } - -} \ No newline at end of file +} diff --git a/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/watch/WatchWorker.java b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/watch/WatchWorker.java index a2e26de..c7c2dc8 100644 --- a/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/watch/WatchWorker.java +++ b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/watch/WatchWorker.java @@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit; import org.apache.rocketmq.common.ThreadFactoryImpl; import org.apache.rocketmq.eventbridge.adapter.runtime.manager.repository.WorkerInstanceRepository; import org.apache.rocketmq.eventbridge.adapter.runtime.manager.worker.Worker; +import org.apache.rocketmq.eventbridge.adapter.runtime.manager.worker.WorkerResource; import org.apache.rocketmq.eventbridge.adapter.runtime.manager.worker.WorkerService; import org.springframework.beans.factory.annotation.Autowired; @@ -49,7 +50,8 @@ public class WatchWorker { if (!workerService.isFinalState(worker)) { Map<String, Object> environments = new Gson().fromJson(worker.getConfig(), new TypeToken<Map<String, Object>>() { }.getType()); - workerInstanceRepository.applyWorkerInstance(worker.getName(), worker.getImageTag(), worker.getResources(), environments); + WorkerResource workerResource = new Gson().fromJson(worker.getResources(), WorkerResource.class); + workerInstanceRepository.applyWorkerInstance(worker.getName(), worker.getImageTag(), workerResource, environments); workerService.refreshMD5(worker); } diff --git a/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/worker/WorkerResource.java b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/worker/WorkerResource.java new file mode 100644 index 0000000..4d48fbf --- /dev/null +++ b/adapter/runtime-manager/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/worker/WorkerResource.java @@ -0,0 +1,26 @@ +/* + * 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.rocketmq.eventbridge.adapter.runtime.manager.worker; + +import lombok.Data; + +@Data +public class WorkerResource { + Double cpu; + Double memory; +} \ No newline at end of file diff --git a/adapter/runtime-on-k8s/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/k8s/repository/WorkerInstanceRepositoryOnK8S.java b/adapter/runtime-on-k8s/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/k8s/repository/WorkerInstanceRepositoryOnK8S.java index 0299ddb..20a95e9 100644 --- a/adapter/runtime-on-k8s/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/k8s/repository/WorkerInstanceRepositoryOnK8S.java +++ b/adapter/runtime-on-k8s/src/main/java/org/apache/rocketmq/eventbridge/adapter/runtime/manager/k8s/repository/WorkerInstanceRepositoryOnK8S.java @@ -19,13 +19,14 @@ package org.apache.rocketmq.eventbridge.adapter.runtime.manager.k8s.repository; import java.util.Map; import org.apache.rocketmq.eventbridge.adapter.runtime.manager.repository.WorkerInstanceRepository; +import org.apache.rocketmq.eventbridge.adapter.runtime.manager.worker.WorkerResource; import org.apache.rocketmq.eventbridge.adapter.runtime.manager.worker.WorkerStatusEnum; public class WorkerInstanceRepositoryOnK8S implements WorkerInstanceRepository { @Override - public boolean applyWorkerInstance(String name, String image, String resources, Map<String, Object> environments) { + public boolean applyWorkerInstance(String name, String image, WorkerResource resources, Map<String, Object> environments) { return false; } diff --git a/scan.py b/scan.py new file mode 100644 index 0000000..e69de29