-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add cluster status check interface and scheduled tasks (#453)
- Loading branch information
1 parent
1fd762d
commit ece930e
Showing
12 changed files
with
533 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...ommon/src/main/java/org/apache/paimon/web/engine/flink/common/status/HeartbeatStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.paimon.web.engine.flink.common.status; | ||
|
||
/** This enum represents the status of a cluster heartbeat. */ | ||
public enum HeartbeatStatus { | ||
/** * The cluster is active. */ | ||
ACTIVE, | ||
/** Unable to connect to the target machine, usually due to network anomalies. */ | ||
UNREACHABLE, | ||
/** | ||
* The cluster is in an unknown state, usually due to a cluster don't result heartbeat | ||
* information, but its network is normal. | ||
*/ | ||
UNKNOWN, | ||
/** | ||
* The cluster is dead, usually due to a cluster don't obtain heartbeat information for a long | ||
* time. | ||
*/ | ||
DEAD; | ||
} |
47 changes: 47 additions & 0 deletions
47
.../src/main/java/org/apache/paimon/web/engine/flink/sql/gateway/client/HeartbeatAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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.paimon.web.engine.flink.sql.gateway.client; | ||
|
||
import org.apache.paimon.web.engine.flink.common.status.HeartbeatStatus; | ||
import org.apache.paimon.web.engine.flink.sql.gateway.model.HeartbeatEntity; | ||
|
||
/** Using to execute cluster heartbeat action. */ | ||
public interface HeartbeatAction { | ||
|
||
/** | ||
* Execute cluster action to obtain cluster status. | ||
* | ||
* @return cluster heartbeat entity. | ||
*/ | ||
HeartbeatEntity checkClusterHeartbeat(); | ||
|
||
/** | ||
* Build a heartbeat entity representing an error based on the cluster status. This method is | ||
* used to generate a heartbeat object when the cluster status is abnormal, recording the | ||
* current time and the error status of the cluster. | ||
* | ||
* @param status The current status of the cluster, used to set the status field of the | ||
* heartbeat entity. | ||
* @return Returns a completed heartbeat entity, including the current timestamp and status | ||
* information. | ||
*/ | ||
default HeartbeatEntity buildResulHeartbeatEntity(HeartbeatStatus status) { | ||
return HeartbeatEntity.builder().status(status.name()).build(); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...main/java/org/apache/paimon/web/engine/flink/sql/gateway/client/SessionClusterClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.paimon.web.engine.flink.sql.gateway.client; | ||
|
||
import org.apache.paimon.web.engine.flink.common.status.HeartbeatStatus; | ||
import org.apache.paimon.web.engine.flink.sql.gateway.model.HeartbeatEntity; | ||
import org.apache.paimon.web.engine.flink.sql.gateway.utils.SqlGateWayRestClient; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.flink.runtime.rest.handler.legacy.messages.ClusterOverviewWithVersion; | ||
import org.apache.flink.runtime.rest.messages.ClusterOverviewHeaders; | ||
import org.apache.flink.runtime.rest.messages.EmptyMessageParameters; | ||
import org.apache.flink.runtime.rest.messages.EmptyRequestBody; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* The flink session client provides some operations on the flink session cluster, such as obtaining | ||
* the cluster status. etc. The flink client implementation of the {@link HeartbeatAction}. | ||
*/ | ||
@Slf4j | ||
public class SessionClusterClient implements HeartbeatAction { | ||
|
||
private final SqlGateWayRestClient restClient; | ||
|
||
public SessionClusterClient(String sessionClusterHost, int sessionClusterPort) | ||
throws Exception { | ||
this.restClient = new SqlGateWayRestClient(sessionClusterHost, sessionClusterPort); | ||
} | ||
|
||
@Override | ||
public HeartbeatEntity checkClusterHeartbeat() { | ||
try { | ||
ClusterOverviewWithVersion heartbeat = | ||
restClient | ||
.sendRequest( | ||
ClusterOverviewHeaders.getInstance(), | ||
EmptyMessageParameters.getInstance(), | ||
EmptyRequestBody.getInstance()) | ||
.get(); | ||
if (Objects.nonNull(heartbeat)) { | ||
return HeartbeatEntity.builder() | ||
.lastHeartbeat(System.currentTimeMillis()) | ||
.status(HeartbeatStatus.ACTIVE.name()) | ||
.clusterVersion(heartbeat.getVersion()) | ||
.build(); | ||
} | ||
} catch (Exception ex) { | ||
log.error( | ||
"An exception occurred while obtaining the cluster status :{}", | ||
ex.getMessage(), | ||
ex); | ||
return this.buildResulHeartbeatEntity(HeartbeatStatus.UNREACHABLE); | ||
} | ||
return this.buildResulHeartbeatEntity(HeartbeatStatus.UNKNOWN); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...y/src/main/java/org/apache/paimon/web/engine/flink/sql/gateway/model/HeartbeatEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.paimon.web.engine.flink.sql.gateway.model; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
/** This is a heartbeat entity of the cluster. */ | ||
@Builder | ||
@Getter | ||
public class HeartbeatEntity { | ||
private String status; | ||
private Long lastHeartbeat; | ||
private String clusterVersion; | ||
} |
47 changes: 47 additions & 0 deletions
47
paimon-web-gateway/src/main/java/org/apache/paimon/web/gateway/enums/DeploymentMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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.paimon.web.gateway.enums; | ||
|
||
/** | ||
* The {@code DeploymentMode} enum defines the types of cluster deployment mode that can be | ||
* supported. | ||
*/ | ||
public enum DeploymentMode { | ||
YARN_SESSION("yarn-session"), | ||
FLINK_SQL_GATEWAY("flink-sql-gateway"); | ||
|
||
private final String type; | ||
|
||
DeploymentMode(String type) { | ||
this.type = type; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public static DeploymentMode fromName(String name) { | ||
for (DeploymentMode type : values()) { | ||
if (type.getType().equals(name)) { | ||
return type; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown deployment mode type value: " + name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.