Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile warnings in mantis-control-plane-server #417

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -25,8 +25,8 @@
import java.util.Map;
import java.util.TreeMap;
import javax.annotation.Nullable;
import javax.xml.bind.DatatypeConverter;
import lombok.Value;
import org.apache.flink.shaded.guava30.com.google.common.io.BaseEncoding;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it's a good idea to use the Flink-shaded version of guava. There is a mantis-shaded version.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks i will make this change.


@Value
public class DisableTaskExecutorsRequest {
Expand Down Expand Up @@ -57,7 +57,7 @@ public String getHash() {
messageDigest.update(key.getBytes(StandardCharsets.UTF_8));
messageDigest.update(value.getBytes(StandardCharsets.UTF_8));
});
return DatatypeConverter.printHexBinary(messageDigest.digest());
return BaseEncoding.base16().encode(messageDigest.digest());
} catch (NoSuchAlgorithmException exception) {
// don't expect this to happen
// let's just throw a runtime exception in this case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public void onInitialize(InitializeAgentsErrorMonitor initializeAgentsErrorMonit
slaveDisabler = hostName -> mantisSchedulerOptional.get().disableVM(hostName,disableDurationMillis);
slaveEnabler = hostName -> mantisSchedulerOptional.get().enableVM(hostName);
getContext().become(initializedBehavior);
getTimers().startPeriodicTimer(CHECK_HOST_TIMER_KEY, new CheckHostHealthMessage(), scala.concurrent.duration.Duration.create(error_check_window_millis, TimeUnit.MILLISECONDS));
getTimers().startTimerAtFixedRate(CHECK_HOST_TIMER_KEY, new CheckHostHealthMessage(),
scala.concurrent.duration.Duration.create(error_check_window_millis, TimeUnit.MILLISECONDS));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ public void testDeser4() throws IOException {
mwm.setCluster(Optional.of("test"));

final String out = objectMapper.writer(Jackson.DEFAULT_FILTER_PROVIDER).writeValueAsString(mwm);
assertTrue(out.contains("\"cluster\":{\"present\":true},"));
assertTrue(out.contains("\"cluster\":{\"empty\":false,\"present\":true}"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

where and why is this "empty" key introduced?

Copy link
Author

@itsharis itsharis Apr 17, 2023

Choose a reason for hiding this comment

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

Had to do some digging into this.

This is a difference with jakson on JDK 8 vs JDK 11 (JDK i am using on M1: https://adoptium.net/download/).
I thought setting the (inteliJ IDEA) File -> Project Structure- > Language level to 8 would be sufficient, however it dosent seem that way.
JDK 8 evaluates:
objectMapper.writeValueAsString(Optional.empty()) as {"present":false}
JDK 11 evaluates:
objectMapper.writeValueAsString(Optional.empty()) as {empty":true,"present":false}

Similarly:
objectMapper.writeValueAsString(Optional.of("test")) evaluates to {"empty":false,"present":true}
I will undo this change since sourceCompatibility is set Java 8

final String serializeAgain = objectMapper.writeValueAsString(objectMapper.readValue(out, MantisWorkerMetadataWritable.class));
assertFalse(serializeAgain.contains("\"cluster\":{\"present\":true},"));
assertTrue(serializeAgain.contains("\"cluster\":{\"present\":false},"));
assertFalse(serializeAgain.contains("\"cluster\":{\"empty\":false,\"present\":true},"));
assertTrue(serializeAgain.contains("\"cluster\":{\"empty\":true,\"present\":false},"));
}

@Test
public void testOptionalSerialization() throws JsonProcessingException {
assertEquals("{\"present\":false}", objectMapper.writeValueAsString(Optional.empty()));
assertEquals("{\"present\":true}", objectMapper.writeValueAsString(Optional.of("test")));
assertEquals("{\"empty\":true,\"present\":false}", objectMapper.writeValueAsString(Optional.empty()));
assertEquals("{\"empty\":false,\"present\":true}", objectMapper.writeValueAsString(Optional.of("empty")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,19 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import akka.NotUsed;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.http.javadsl.ConnectHttp;
import akka.http.javadsl.Http;
import akka.http.javadsl.ServerBinding;
import akka.http.javadsl.model.HttpEntity;
import akka.http.javadsl.model.HttpRequest;
import akka.http.javadsl.model.HttpResponse;
import akka.stream.ActorMaterializer;
import akka.stream.javadsl.Flow;
import akka.http.javadsl.server.Route;
import akka.stream.Materializer;
import akka.util.ByteString;
import com.netflix.fenzo.AutoScaleAction;
import com.netflix.fenzo.AutoScaleRule;
Expand Down Expand Up @@ -77,7 +75,7 @@

public class AgentClusterRouteTest {
private final static Logger logger = LoggerFactory.getLogger(AgentClusterRouteTest.class);
private final ActorMaterializer materializer = ActorMaterializer.create(system);
private final Materializer materializer = Materializer.createMaterializer(system);
private final Http http = Http.get(system);
private static Thread t;
private static final int serverPort = 8209;
Expand Down Expand Up @@ -119,7 +117,6 @@ public static void setup() throws InterruptedException {
// boot up server using the route as defined below
TestHelpers.setupMasterConfig();
final Http http = Http.get(system);
final ActorMaterializer materializer = ActorMaterializer.create(system);
IMantisPersistenceProvider storageProvider = new FileBasedPersistenceProvider(true);
final LifecycleEventPublisher lifecycleEventPublisher = new LifecycleEventPublisherImpl(new AuditEventSubscriberLoggingImpl(), new StatusEventSubscriberLoggingImpl(), new WorkerEventSubscriberLoggingImpl());

Expand All @@ -140,10 +137,11 @@ public static void setup() throws InterruptedException {
"cluster"),
system);

final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = v0AgentClusterRoute.createRoute(Function.identity()).flow(system, materializer);
final Route route = v0AgentClusterRoute.createRoute(Function.identity());
logger.info("test server starting on port {}", serverPort);
binding = http.bindAndHandle(routeFlow,
ConnectHttp.toHost("localhost", serverPort), materializer);
binding = http
.newServerAt("localhost", serverPort)
.bind(route);
latch.countDown();
} catch (Exception e) {
logger.info("caught exception", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import akka.NotUsed;
import akka.http.javadsl.ConnectHttp;
import akka.http.javadsl.Http;
import akka.http.javadsl.ServerBinding;
import akka.http.javadsl.model.HttpRequest;
import akka.http.javadsl.model.HttpResponse;
import akka.stream.Materializer;
import akka.stream.javadsl.Flow;
import akka.http.javadsl.server.Route;
import com.netflix.mantis.master.scheduler.TestHelpers;
import io.mantisrx.master.api.akka.route.Jackson;
import io.mantisrx.master.jobcluster.job.JobTestHelper;
Expand Down Expand Up @@ -80,12 +77,12 @@ public static void setup() throws Exception {
try {
// boot up server using the route as defined below
final Http http = Http.get(system);
final Materializer materializer = Materializer.createMaterializer(system);

final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = masterDescRoute.createRoute(Function.identity()).flow(system, materializer);
final Route route = masterDescRoute.createRoute(Function.identity());
logger.info("starting test server on port {}", ADMIN_MASTER_PORT);
binding = http.bindAndHandle(routeFlow,
ConnectHttp.toHost("localhost", ADMIN_MASTER_PORT), materializer);
binding = http
.newServerAt("localhost", ADMIN_MASTER_PORT)
.bind(route);
latch.countDown();
} catch (Exception e) {
logger.info("caught exception", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import akka.NotUsed;
import akka.actor.ActorRef;
import akka.http.javadsl.ConnectHttp;
import akka.http.javadsl.Http;
import akka.http.javadsl.ServerBinding;
import akka.http.javadsl.model.ContentTypes;
import akka.http.javadsl.model.HttpEntities;
import akka.http.javadsl.model.HttpRequest;
import akka.http.javadsl.model.HttpResponse;
import akka.stream.ActorMaterializer;
import akka.stream.javadsl.Flow;
import akka.http.javadsl.server.Route;
import com.netflix.fenzo.AutoScaleAction;
import com.netflix.fenzo.AutoScaleRule;
import com.netflix.fenzo.VirtualMachineLease;
Expand Down Expand Up @@ -100,7 +97,6 @@ public static void setup() throws InterruptedException {
try {
// boot up server using the route as defined below
final Http http = Http.get(system);
final ActorMaterializer materializer = ActorMaterializer.create(system);
IMantisPersistenceProvider storageProvider = new FileBasedPersistenceProvider(true);
final LifecycleEventPublisher lifecycleEventPublisher = new LifecycleEventPublisherImpl(
new AuditEventSubscriberLoggingImpl(),
Expand Down Expand Up @@ -132,12 +128,11 @@ public static void setup() throws InterruptedException {
lifecycleEventPublisher,
"cluster"));

final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = agentClusterV2Route.createRoute(
Function.identity()).flow(system, materializer);
final Route route = agentClusterV2Route.createRoute(Function.identity());
logger.info("test server starting on port {}", serverPort);
binding = http.bindAndHandle(routeFlow,
ConnectHttp.toHost("localhost", serverPort),
materializer);
binding = http
.newServerAt("localhost", serverPort)
.bind(route);;
latch.countDown();
} catch (Exception e) {
logger.info("caught exception", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
Expand Down