Skip to content

Commit

Permalink
minor fix (#16)
Browse files Browse the repository at this point in the history
* minor fix

* removed unused

* temporary swallow Yarn app killing error

Co-authored-by: Denisas <[email protected]>
  • Loading branch information
hynix and Denisas authored Jan 28, 2022
1 parent 5afc5a7 commit 213744d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Application> fetchPermanentSession() {
return Optional.ofNullable(sessionConfiguration.getPermanentSessionId()).flatMap(this::fetchOne);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> 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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ public Optional<Application> get(@PathVariable String id) {
return sessionService.fetchOne(id, true);
}

@Get("/permanent")
public Optional<Application> getPermanent() {
return sessionService.fetchPermanentSession();
}

@Delete("/{id}")
public void delete(@PathVariable String id) {
sessionService.deleteOne(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,5 @@ class SessionServiceTest extends Specification {

then: "returns empty"
session.isEmpty()

when: "fetch permanent"
session = service.fetchPermanentSession()

then: "returns empty"
session.isEmpty()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 213744d

Please sign in to comment.