hailin0 commented on code in PR #2472:
URL: 
https://github.com/apache/incubator-seatunnel/pull/2472#discussion_r959137415


##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/service/slot/DefaultSlotService.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.seatunnel.engine.server.service.slot;
+
+import org.apache.seatunnel.common.utils.RetryUtils;
+import org.apache.seatunnel.engine.common.utils.IdGenerator;
+import org.apache.seatunnel.engine.server.SeaTunnelServer;
+import org.apache.seatunnel.engine.server.TaskExecutionService;
+import 
org.apache.seatunnel.engine.server.resourcemanager.opeartion.WorkerHeartbeatOperation;
+import org.apache.seatunnel.engine.server.resourcemanager.resource.CPU;
+import org.apache.seatunnel.engine.server.resourcemanager.resource.Memory;
+import 
org.apache.seatunnel.engine.server.resourcemanager.resource.ResourceProfile;
+import org.apache.seatunnel.engine.server.resourcemanager.resource.SlotProfile;
+import org.apache.seatunnel.engine.server.resourcemanager.worker.WorkerProfile;
+
+import com.hazelcast.logging.ILogger;
+import com.hazelcast.logging.Logger;
+import com.hazelcast.spi.impl.NodeEngineImpl;
+import com.hazelcast.spi.impl.operationservice.InvocationBuilder;
+import com.hazelcast.spi.impl.operationservice.Operation;
+import com.hazelcast.spi.impl.operationservice.impl.InvocationFuture;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * The slot service of seatunnel server, used for manage slot in worker.
+ */
+public class DefaultSlotService implements SlotService {
+
+    private static final ILogger LOGGER = 
Logger.getLogger(DefaultSlotService.class);
+    private static final long DEFAULT_HEARTBEAT_TIMEOUT = 2000;
+    private static final int HEARTBEAT_RETRY_TIME = 5;
+    private final NodeEngineImpl nodeEngine;
+
+    private AtomicReference<ResourceProfile> unassignedResource;
+
+    private AtomicReference<ResourceProfile> assignedResource;
+
+    private Map<Integer, SlotProfile> assignedSlots;
+
+    private Map<Integer, SlotProfile> unassignedSlots;
+    private ScheduledExecutorService scheduledExecutorService;
+    private final String serviceID;
+    private final boolean dynamicSlot;
+    private final int slotNumber;
+    private final IdGenerator idGenerator;
+    private final TaskExecutionService taskExecutionService;
+    private Map<Integer, SlotContext> contexts;
+
+    public DefaultSlotService(NodeEngineImpl nodeEngine, TaskExecutionService 
taskExecutionService, boolean dynamicSlot, int slotNumber) {
+        this.nodeEngine = nodeEngine;
+        this.dynamicSlot = dynamicSlot;
+        this.taskExecutionService = taskExecutionService;
+        this.slotNumber = slotNumber;
+        this.serviceID = nodeEngine.getThisAddress().toString();
+        this.idGenerator = new IdGenerator();
+    }
+
+    @Override
+    public void init() {
+        contexts = new ConcurrentHashMap<>();
+        assignedSlots = new ConcurrentHashMap<>();
+        unassignedSlots = new ConcurrentHashMap<>();
+        unassignedResource = new AtomicReference<>(new ResourceProfile());
+        assignedResource = new AtomicReference<>(new ResourceProfile());
+        scheduledExecutorService = 
Executors.newSingleThreadScheduledExecutor();
+        if (!dynamicSlot) {
+            initFixedSlots();
+        }
+        unassignedResource.set(getNodeResource());
+        scheduledExecutorService.scheduleAtFixedRate(() -> {
+            try {
+                RetryUtils.retryWithException(() -> {
+                    sendToMaster(new 
WorkerHeartbeatOperation(toWorkerProfile())).join();
+                    return null;
+                }, new RetryUtils.RetryMaterial(HEARTBEAT_RETRY_TIME, true, e 
-> true, DEFAULT_HEARTBEAT_TIMEOUT));
+            } catch (Exception e) {
+                throw new RuntimeException(e);

Review Comment:
   Don't throw exception and log exception message?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to