Skip to content

Commit 6e55fa7

Browse files
committed
Support to get kyuubi server event
1 parent 3b205a3 commit 6e55fa7

File tree

4 files changed

+179
-4
lines changed

4 files changed

+179
-4
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.kyuubi.client.api.v1.dto;
19+
20+
import java.util.Collections;
21+
import java.util.Map;
22+
import java.util.Objects;
23+
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
24+
import org.apache.commons.lang3.builder.ToStringStyle;
25+
26+
public class KyuubiServerEvent {
27+
private String serverName;
28+
private Long startTime;
29+
private Long eventTime;
30+
private String state;
31+
private String serverIp;
32+
private Map<String, String> serverConf;
33+
private Map<String, String> serverEnv;
34+
35+
public KyuubiServerEvent() {}
36+
37+
public KyuubiServerEvent(
38+
String serverName,
39+
Long startTime,
40+
Long eventTime,
41+
String state,
42+
String serverIp,
43+
Map<String, String> serverConf,
44+
Map<String, String> serverEnv) {
45+
this.serverName = serverName;
46+
this.startTime = startTime;
47+
this.eventTime = eventTime;
48+
this.state = state;
49+
this.serverIp = serverIp;
50+
this.serverConf = serverConf;
51+
this.serverEnv = serverEnv;
52+
}
53+
54+
public String getServerName() {
55+
return serverName;
56+
}
57+
58+
public void setServerName(String serverName) {
59+
this.serverName = serverName;
60+
}
61+
62+
public Long getStartTime() {
63+
return startTime;
64+
}
65+
66+
public void setStartTime(Long startTime) {
67+
this.startTime = startTime;
68+
}
69+
70+
public Long getEventTime() {
71+
return eventTime;
72+
}
73+
74+
public void setEventTime(Long eventTime) {
75+
this.eventTime = eventTime;
76+
}
77+
78+
public String getState() {
79+
return state;
80+
}
81+
82+
public void setState(String state) {
83+
this.state = state;
84+
}
85+
86+
public String getServerIp() {
87+
return serverIp;
88+
}
89+
90+
public void setServerIp(String serverIp) {
91+
this.serverIp = serverIp;
92+
}
93+
94+
public Map<String, String> getServerConf() {
95+
if (null == serverConf) {
96+
return Collections.emptyMap();
97+
}
98+
return serverConf;
99+
}
100+
101+
public void setServerConf(Map<String, String> serverConf) {
102+
this.serverConf = serverConf;
103+
}
104+
105+
public Map<String, String> getServerEnv() {
106+
if (null == serverEnv) {
107+
return Collections.emptyMap();
108+
}
109+
return serverEnv;
110+
}
111+
112+
public void setServerEnv(Map<String, String> serverEnv) {
113+
this.serverEnv = serverEnv;
114+
}
115+
116+
@Override
117+
public boolean equals(Object o) {
118+
if (this == o) return true;
119+
if (o == null || getClass() != o.getClass()) return false;
120+
KyuubiServerEvent that = (KyuubiServerEvent) o;
121+
return Objects.equals(getServerName(), that.getServerName())
122+
&& Objects.equals(getStartTime(), that.getStartTime())
123+
&& Objects.equals(getEventTime(), that.getEventTime())
124+
&& Objects.equals(getState(), that.getState())
125+
&& Objects.equals(getServerIp(), that.getServerIp())
126+
&& Objects.equals(getServerConf(), that.getServerConf())
127+
&& Objects.equals(getServerEnv(), that.getServerEnv());
128+
}
129+
130+
@Override
131+
public int hashCode() {
132+
return Objects.hash(
133+
getServerName(),
134+
getStartTime(),
135+
getEventTime(),
136+
getState(),
137+
getServerIp(),
138+
getServerConf(),
139+
getServerEnv());
140+
}
141+
142+
@Override
143+
public String toString() {
144+
return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE);
145+
}
146+
}

kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiServer.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ class KyuubiServer(name: String) extends Serverable(name) {
184184

185185
def this() = this(classOf[KyuubiServer].getSimpleName)
186186

187+
private[kyuubi] var kyuubiServerInfoEvent: Option[KyuubiServerInfoEvent] = None
187188
override val backendService: AbstractBackendService =
188189
new KyuubiBackendService() with BackendServiceMetric
189190

@@ -223,11 +224,13 @@ class KyuubiServer(name: String) extends Serverable(name) {
223224
override def start(): Unit = {
224225
super.start()
225226
KyuubiServer.kyuubiServer = this
226-
KyuubiServerInfoEvent(this, ServiceState.STARTED).foreach(EventBus.post)
227+
kyuubiServerInfoEvent = KyuubiServerInfoEvent(this, ServiceState.STARTED)
228+
kyuubiServerInfoEvent.foreach(EventBus.post)
227229
}
228230

229231
override def stop(): Unit = {
230-
KyuubiServerInfoEvent(this, ServiceState.STOPPED).foreach(EventBus.post)
232+
kyuubiServerInfoEvent = KyuubiServerInfoEvent(this, ServiceState.STOPPED)
233+
kyuubiServerInfoEvent.foreach(EventBus.post)
231234
super.stop()
232235
}
233236

kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/ApiUtils.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import scala.collection.JavaConverters._
2121

2222
import org.apache.kyuubi.{Logging, Utils}
2323
import org.apache.kyuubi.client.api.v1.dto
24-
import org.apache.kyuubi.client.api.v1.dto.{OperationData, OperationProgress, ServerData, SessionData}
24+
import org.apache.kyuubi.client.api.v1.dto.{KyuubiServerEvent, OperationData, OperationProgress, ServerData, SessionData}
25+
import org.apache.kyuubi.events.KyuubiServerInfoEvent
2526
import org.apache.kyuubi.ha.client.ServiceNodeInfo
2627
import org.apache.kyuubi.operation.KyuubiOperation
2728
import org.apache.kyuubi.session.KyuubiSession
@@ -136,6 +137,17 @@ object ApiUtils extends Logging {
136137
"Running")
137138
}
138139

140+
def serverEvent(serverEvent: KyuubiServerInfoEvent): KyuubiServerEvent = {
141+
new KyuubiServerEvent(
142+
serverEvent.serverName,
143+
serverEvent.startTime,
144+
serverEvent.eventTime,
145+
serverEvent.state,
146+
serverEvent.serverIP,
147+
serverEvent.serverConf.asJava,
148+
serverEvent.serverEnv.asJava)
149+
}
150+
139151
def logAndRefineErrorMsg(errorMsg: String, throwable: Throwable): String = {
140152
error(errorMsg, throwable)
141153
s"$errorMsg: ${Utils.prettyPrint(throwable)}"

kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/AdminResource.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private[v1] class AdminResource extends ApiRequestContext with Logging {
378378
new Content(
379379
mediaType = MediaType.APPLICATION_JSON,
380380
array = new ArraySchema(schema = new Schema(implementation =
381-
classOf[OperationData])))),
381+
classOf[ServerData])))),
382382
description = "list all live kyuubi servers")
383383
@GET
384384
@Path("server")
@@ -401,6 +401,20 @@ private[v1] class AdminResource extends ApiRequestContext with Logging {
401401
servers.toSeq
402402
}
403403

404+
@ApiResponse(
405+
responseCode = "200",
406+
content = Array(
407+
new Content(
408+
mediaType = MediaType.APPLICATION_JSON,
409+
array = new ArraySchema(schema = new Schema(implementation =
410+
classOf[KyuubiServerEvent])))),
411+
description = "Get the server event")
412+
@GET
413+
@Path("server/event")
414+
def getServerEvent(): Seq[KyuubiServerEvent] = {
415+
KyuubiServer.kyuubiServer.kyuubiServerInfoEvent.map(ApiUtils.serverEvent).toSeq
416+
}
417+
404418
private def normalizeEngineInfo(
405419
userName: String,
406420
engineType: String,

0 commit comments

Comments
 (0)