From 213744d50e007be6d1df19dcf883c54e0d25c88b Mon Sep 17 00:00:00 2001 From: Denisas Date: Fri, 28 Jan 2022 16:20:01 +0200 Subject: [PATCH] minor fix (#16) * minor fix * removed unused * temporary swallow Yarn app killing error Co-authored-by: Denisas --- .../application/sessions/SessionService.java | 4 ---- .../lighter/backend/yarn/YarnBackend.java | 16 +++++++++++----- .../lighter/backend/yarn/resources/Token.java | 8 +++++++- .../lighter/rest/SessionController.java | 5 ----- .../sessions/SessionServiceTest.groovy | 6 ------ .../lighter/rest/SessionControllerTest.groovy | 2 +- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/server/src/main/java/com/exacaster/lighter/application/sessions/SessionService.java b/server/src/main/java/com/exacaster/lighter/application/sessions/SessionService.java index 80aadd0d..2123b95f 100644 --- a/server/src/main/java/com/exacaster/lighter/application/sessions/SessionService.java +++ b/server/src/main/java/com/exacaster/lighter/application/sessions/SessionService.java @@ -111,8 +111,4 @@ public Statement getStatement(String id, String statementId) { public Statement cancelStatement(String id, String statementId) { return statementHandler.cancelStatement(id, statementId); } - - public Optional fetchPermanentSession() { - return Optional.ofNullable(sessionConfiguration.getPermanentSessionId()).flatMap(this::fetchOne); - } } diff --git a/server/src/main/java/com/exacaster/lighter/backend/yarn/YarnBackend.java b/server/src/main/java/com/exacaster/lighter/backend/yarn/YarnBackend.java index 8d9b28fe..cf820a30 100644 --- a/server/src/main/java/com/exacaster/lighter/backend/yarn/YarnBackend.java +++ b/server/src/main/java/com/exacaster/lighter/backend/yarn/YarnBackend.java @@ -1,6 +1,7 @@ package com.exacaster.lighter.backend.yarn; import static java.util.stream.Stream.of; +import static org.slf4j.LoggerFactory.getLogger; import com.exacaster.lighter.application.Application; import com.exacaster.lighter.application.ApplicationInfo; @@ -22,11 +23,12 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; -import org.springframework.http.HttpEntity; +import org.slf4j.Logger; import org.springframework.security.kerberos.client.KerberosRestTemplate; public class YarnBackend implements Backend { + private static final Logger LOG = getLogger(YarnBackend.class); private static final String TOKEN_ENDPOINT = "/ws/v1/cluster/delegation-token"; private final YarnProperties yarnProperties; @@ -82,16 +84,20 @@ public String getSessionJobResources() { @Override public void kill(Application application) { var state = new State("KILLED"); - getYarnApplicationId(application).ifPresent( - id -> getToken().ifPresentOrElse(t -> client.setState(id, state, t), () -> client.setState(id, state))); + // TODO remove after fixed + try { + getYarnApplicationId(application).ifPresent(id -> getToken() + .ifPresentOrElse(t -> client.setState(id, state, t), () -> client.setState(id, state))); + } catch (Exception e) { + LOG.error("Can't kill Yarn app: {}", application, e); + } } private Optional getToken() { var url = yarnProperties.getUrl() + TOKEN_ENDPOINT; var body = Map.of("renewer", "lighter"); return kerberosRestTemplate - .map(it -> it.postForEntity(url, body, Token.class)) - .map(HttpEntity::getBody) + .map(it -> it.postForObject(url, body, Token.class)) .map(Token::getToken); } diff --git a/server/src/main/java/com/exacaster/lighter/backend/yarn/resources/Token.java b/server/src/main/java/com/exacaster/lighter/backend/yarn/resources/Token.java index 16c08e90..e092c700 100644 --- a/server/src/main/java/com/exacaster/lighter/backend/yarn/resources/Token.java +++ b/server/src/main/java/com/exacaster/lighter/backend/yarn/resources/Token.java @@ -1,12 +1,18 @@ package com.exacaster.lighter.backend.yarn.resources; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import io.micronaut.core.annotation.Introspected; +import io.micronaut.core.annotation.Nullable; @Introspected +@JsonIgnoreProperties(ignoreUnknown = true) public class Token { private final String token; - public Token(String token) { + @JsonCreator + public Token(@Nullable @JsonProperty("token") String token) { this.token = token; } diff --git a/server/src/main/java/com/exacaster/lighter/rest/SessionController.java b/server/src/main/java/com/exacaster/lighter/rest/SessionController.java index 018e3d8b..350a1ffb 100644 --- a/server/src/main/java/com/exacaster/lighter/rest/SessionController.java +++ b/server/src/main/java/com/exacaster/lighter/rest/SessionController.java @@ -62,11 +62,6 @@ public Optional get(@PathVariable String id) { return sessionService.fetchOne(id, true); } - @Get("/permanent") - public Optional getPermanent() { - return sessionService.fetchPermanentSession(); - } - @Delete("/{id}") public void delete(@PathVariable String id) { sessionService.deleteOne(id); diff --git a/server/src/test/groovy/com/exacaster/lighter/application/sessions/SessionServiceTest.groovy b/server/src/test/groovy/com/exacaster/lighter/application/sessions/SessionServiceTest.groovy index 46e55c59..a8af5f21 100644 --- a/server/src/test/groovy/com/exacaster/lighter/application/sessions/SessionServiceTest.groovy +++ b/server/src/test/groovy/com/exacaster/lighter/application/sessions/SessionServiceTest.groovy @@ -66,11 +66,5 @@ class SessionServiceTest extends Specification { then: "returns empty" session.isEmpty() - - when: "fetch permanent" - session = service.fetchPermanentSession() - - then: "returns empty" - session.isEmpty() } } diff --git a/server/src/test/groovy/com/exacaster/lighter/rest/SessionControllerTest.groovy b/server/src/test/groovy/com/exacaster/lighter/rest/SessionControllerTest.groovy index 38cede61..7ca4b3f3 100644 --- a/server/src/test/groovy/com/exacaster/lighter/rest/SessionControllerTest.groovy +++ b/server/src/test/groovy/com/exacaster/lighter/rest/SessionControllerTest.groovy @@ -47,7 +47,7 @@ class SessionControllerTest extends Specification { def "returns permanent session"() { when: def result = client.toBlocking() - .exchange(HttpRequest.GET("/sessions/permanent"), Map.class).body() + .exchange(HttpRequest.GET("/sessions/permanentSessionId"), Map.class).body() then: result.id == "permanentSessionId"