Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.kyuubi.client.api.v1.dto.Engine;
import org.apache.kyuubi.client.api.v1.dto.KyuubiServerEvent;
import org.apache.kyuubi.client.api.v1.dto.OperationData;
import org.apache.kyuubi.client.api.v1.dto.ServerData;
import org.apache.kyuubi.client.api.v1.dto.SessionData;
Expand Down Expand Up @@ -165,6 +166,12 @@ public List<ServerData> listServers() {
return Arrays.asList(result);
}

public KyuubiServerEvent getServerEvent() {
return this.getClient()
.get(
API_BASE_PATH + "/server/event", null, KyuubiServerEvent.class, client.getAuthHeader());
}

private IRestClient getClient() {
return this.client.getHttpClient();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* 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.kyuubi.client.api.v1.dto;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class KyuubiServerEvent {
private String serverName;
private Long startTime;
private Long eventTime;
private String state;
private String serverIP;
private Map<String, String> serverConf;
private Map<String, String> serverEnv;
private Map<String, String> buildInfo;

public KyuubiServerEvent() {}

public KyuubiServerEvent(
String serverName,
Long startTime,
Long eventTime,
String state,
String serverIP,
Map<String, String> serverConf,
Map<String, String> serverEnv,
Map<String, String> buildInfo) {
this.serverName = serverName;
this.startTime = startTime;
this.eventTime = eventTime;
this.state = state;
this.serverIP = serverIP;
this.serverConf = serverConf;
this.serverEnv = serverEnv;
this.buildInfo = buildInfo;
}

public String getServerName() {
return serverName;
}

public void setServerName(String serverName) {
this.serverName = serverName;
}

public Long getStartTime() {
return startTime;
}

public void setStartTime(Long startTime) {
this.startTime = startTime;
}

public Long getEventTime() {
return eventTime;
}

public void setEventTime(Long eventTime) {
this.eventTime = eventTime;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public String getServerIP() {
return serverIP;
}

public void setServerIP(String serverIP) {
this.serverIP = serverIP;
}

public Map<String, String> getServerConf() {
if (null == serverConf) {
return Collections.emptyMap();
}
return serverConf;
}

public void setServerConf(Map<String, String> serverConf) {
this.serverConf = serverConf;
}

public Map<String, String> getServerEnv() {
if (null == serverEnv) {
return Collections.emptyMap();
}
return serverEnv;
}

public void setServerEnv(Map<String, String> serverEnv) {
this.serverEnv = serverEnv;
}

public Map<String, String> getBuildInfo() {
if (null == buildInfo) {
return Collections.emptyMap();
}
return buildInfo;
}

public void setBuildInfo(Map<String, String> buildInfo) {
this.buildInfo = buildInfo;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
KyuubiServerEvent that = (KyuubiServerEvent) o;
return Objects.equals(getServerName(), that.getServerName())
&& Objects.equals(getStartTime(), that.getStartTime())
&& Objects.equals(getEventTime(), that.getEventTime())
&& Objects.equals(getState(), that.getState())
&& Objects.equals(getServerIP(), that.getServerIP())
&& Objects.equals(getServerConf(), that.getServerConf())
&& Objects.equals(getServerEnv(), that.getServerEnv())
&& Objects.equals(getBuildInfo(), that.getBuildInfo());
}

@Override
public int hashCode() {
return Objects.hash(
getServerName(),
getStartTime(),
getEventTime(),
getState(),
getServerIP(),
getServerConf(),
getServerEnv(),
getBuildInfo());
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ class KyuubiServer(name: String) extends Serverable(name) {
super.stop()
}

def getServerEvent(): Option[KyuubiServerInfoEvent] = {
KyuubiServerInfoEvent(this, state)
}

private def initLoggerEventHandler(conf: KyuubiConf): Unit = {
ServerEventHandlerRegister.registerEventLoggers(conf)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import scala.collection.JavaConverters._

import org.apache.kyuubi.{Logging, Utils}
import org.apache.kyuubi.client.api.v1.dto
import org.apache.kyuubi.client.api.v1.dto.{OperationData, OperationProgress, ServerData, SessionData}
import org.apache.kyuubi.client.api.v1.dto.{KyuubiServerEvent, OperationData, OperationProgress, ServerData, SessionData}
import org.apache.kyuubi.events.KyuubiServerInfoEvent
import org.apache.kyuubi.ha.client.ServiceNodeInfo
import org.apache.kyuubi.operation.KyuubiOperation
import org.apache.kyuubi.session.KyuubiSession
Expand Down Expand Up @@ -136,6 +137,22 @@ object ApiUtils extends Logging {
"Running")
}

def serverEvent(serverEvent: KyuubiServerInfoEvent): KyuubiServerEvent = {
if (serverEvent == null) return new KyuubiServerEvent()
new KyuubiServerEvent(
serverEvent.serverName,
serverEvent.startTime,
serverEvent.eventTime,
serverEvent.state,
serverEvent.serverIP,
serverEvent.serverConf.asJava,
serverEvent.serverEnv.asJava,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for a security perspective, we should redact sensitive info by default, maybe we can have a server side config to control the behavior, the candidate value can be ORIGINAL, REDACTED, NONE

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I remember there was a similar discussion about retrieving batch info

(Map(
"BUILD_USER" -> serverEvent.BUILD_USER,
"BUILD_DATE" -> serverEvent.BUILD_DATE,
"REPO_URL" -> serverEvent.REPO_URL) ++ serverEvent.VERSION_INFO).asJava)
}

def logAndRefineErrorMsg(errorMsg: String, throwable: Throwable): String = {
error(errorMsg, throwable)
s"$errorMsg: ${Utils.prettyPrint(throwable)}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private[v1] class AdminResource extends ApiRequestContext with Logging {
new Content(
mediaType = MediaType.APPLICATION_JSON,
array = new ArraySchema(schema = new Schema(implementation =
classOf[OperationData])))),
classOf[ServerData])))),
description = "list all live kyuubi servers")
@GET
@Path("server")
Expand All @@ -401,6 +401,19 @@ private[v1] class AdminResource extends ApiRequestContext with Logging {
servers.toSeq
}

@ApiResponse(
responseCode = "200",
content = Array(
new Content(
mediaType = MediaType.APPLICATION_JSON,
schema = new Schema(implementation = classOf[KyuubiServerEvent]))),
description = "Get the server event")
@GET
@Path("server/event")
def getServerEvent(): KyuubiServerEvent = {
ApiUtils.serverEvent(KyuubiServer.kyuubiServer.getServerEvent().orNull)
}

private def normalizeEngineInfo(
userName: String,
engineType: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,4 +841,15 @@ class AdminResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
assert("Running".equals(testServer.getStatus))
}
}

test("get server event") {
val response = webTarget.path("api/v1/admin/server/event")
.request()
.header(AUTHORIZATION_HEADER, HttpAuthUtils.basicAuthorizationHeader(Utils.currentUser))
.get

assert(response.getStatus === 200)
val serverEvent = response.readEntity(classOf[KyuubiServerEvent])
assert(serverEvent.getStartTime > 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,14 @@ class AdminRestApiSuite extends RestClientTestHelper {
assert(servers.map(s => s.getInstance()).contains(server.frontendServices.last.connectionUrl))
}
}

test("get server event") {
val spnegoKyuubiRestClient: KyuubiRestClient =
KyuubiRestClient.builder(baseUri.toString)
.authHeaderMethod(KyuubiRestClient.AuthHeaderMethod.SPNEGO)
.spnegoHost("localhost")
.build()
val adminRestApi = new AdminRestApi(spnegoKyuubiRestClient)
assert(adminRestApi.getServerEvent.getStartTime > 0)
}
}
Loading