From 347a06afd410dea5d6743a91015b58113a67d9a3 Mon Sep 17 00:00:00 2001 From: haris Date: Tue, 11 Apr 2023 23:22:19 -0400 Subject: [PATCH 1/2] Fix compile warnings in mantis-control-plane-server * Remove deprecated bindAndHandle * Remove deprecated Mockito.Matchers and replace with ArgumentMatchers * Remove deprecated ActorMaterializer and replace with Materializer * Remove deprecated startPeriodicTimer and replace with startTimerAtFixedRate * Fix serialization of Optional in unit tests * Replace DatatypeConverter with BaseEncoding --- .../DisableTaskExecutorsRequest.java | 4 ++-- .../scheduler/AgentsErrorMonitorActor.java | 3 ++- .../master/api/akka/route/JacksonTest.java | 10 +++++----- .../akka/route/v0/AgentClusterRouteTest.java | 18 ++++++++---------- .../akka/route/v1/AdminMasterRouteTest.java | 13 +++++-------- .../akka/route/v1/AgentClustersRouteTest.java | 17 ++++++----------- .../jobcluster/job/JobClusterManagerTest.java | 4 ++-- 7 files changed, 30 insertions(+), 39 deletions(-) diff --git a/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/resourcecluster/DisableTaskExecutorsRequest.java b/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/resourcecluster/DisableTaskExecutorsRequest.java index f4f12551a..de1068191 100644 --- a/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/resourcecluster/DisableTaskExecutorsRequest.java +++ b/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/resourcecluster/DisableTaskExecutorsRequest.java @@ -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; @Value public class DisableTaskExecutorsRequest { @@ -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 diff --git a/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/scheduler/AgentsErrorMonitorActor.java b/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/scheduler/AgentsErrorMonitorActor.java index 719897a30..631bde900 100644 --- a/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/scheduler/AgentsErrorMonitorActor.java +++ b/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/scheduler/AgentsErrorMonitorActor.java @@ -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 diff --git a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/JacksonTest.java b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/JacksonTest.java index 2586fb4ed..5694115d8 100644 --- a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/JacksonTest.java +++ b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/JacksonTest.java @@ -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}")); 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 diff --git a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v0/AgentClusterRouteTest.java b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v0/AgentClusterRouteTest.java index 518465f0c..ccbafaf7e 100644 --- a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v0/AgentClusterRouteTest.java +++ b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v0/AgentClusterRouteTest.java @@ -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; @@ -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; @@ -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()); @@ -140,10 +137,11 @@ public static void setup() throws InterruptedException { "cluster"), system); - final Flow 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); diff --git a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v1/AdminMasterRouteTest.java b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v1/AdminMasterRouteTest.java index b35e12eff..75f6459c9 100644 --- a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v1/AdminMasterRouteTest.java +++ b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v1/AdminMasterRouteTest.java @@ -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; @@ -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 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); diff --git a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v1/AgentClustersRouteTest.java b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v1/AgentClustersRouteTest.java index 2bee8e84f..54373c039 100644 --- a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v1/AgentClustersRouteTest.java +++ b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/v1/AgentClustersRouteTest.java @@ -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; @@ -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(), @@ -132,12 +128,11 @@ public static void setup() throws InterruptedException { lifecycleEventPublisher, "cluster")); - final Flow 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); diff --git a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/jobcluster/job/JobClusterManagerTest.java b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/jobcluster/job/JobClusterManagerTest.java index aff29817d..2c731fb28 100644 --- a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/jobcluster/job/JobClusterManagerTest.java +++ b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/jobcluster/job/JobClusterManagerTest.java @@ -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; From 9e754ac934e79830e1c7a3637e56d65a25e51796 Mon Sep 17 00:00:00 2001 From: haris Date: Mon, 17 Apr 2023 00:51:19 -0400 Subject: [PATCH 2/2] * Undo unit JacksonTest Optional serialization changes. * Switch BaseEncoding.base16 to use mantisrx.shaded import --- .../resourcecluster/DisableTaskExecutorsRequest.java | 2 +- .../io/mantisrx/master/api/akka/route/JacksonTest.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/resourcecluster/DisableTaskExecutorsRequest.java b/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/resourcecluster/DisableTaskExecutorsRequest.java index de1068191..17b03a7ea 100644 --- a/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/resourcecluster/DisableTaskExecutorsRequest.java +++ b/mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/resourcecluster/DisableTaskExecutorsRequest.java @@ -18,6 +18,7 @@ import io.mantisrx.server.master.resourcecluster.ClusterID; import io.mantisrx.server.master.resourcecluster.TaskExecutorRegistration; +import io.mantisrx.shaded.com.google.common.io.BaseEncoding; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -26,7 +27,6 @@ import java.util.TreeMap; import javax.annotation.Nullable; import lombok.Value; -import org.apache.flink.shaded.guava30.com.google.common.io.BaseEncoding; @Value public class DisableTaskExecutorsRequest { diff --git a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/JacksonTest.java b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/JacksonTest.java index 5694115d8..2586fb4ed 100644 --- a/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/JacksonTest.java +++ b/mantis-control-plane/mantis-control-plane-server/src/test/java/io/mantisrx/master/api/akka/route/JacksonTest.java @@ -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\":{\"empty\":false,\"present\":true}")); + assertTrue(out.contains("\"cluster\":{\"present\":true},")); final String serializeAgain = objectMapper.writeValueAsString(objectMapper.readValue(out, MantisWorkerMetadataWritable.class)); - assertFalse(serializeAgain.contains("\"cluster\":{\"empty\":false,\"present\":true},")); - assertTrue(serializeAgain.contains("\"cluster\":{\"empty\":true,\"present\":false},")); + assertFalse(serializeAgain.contains("\"cluster\":{\"present\":true},")); + assertTrue(serializeAgain.contains("\"cluster\":{\"present\":false},")); } @Test public void testOptionalSerialization() throws JsonProcessingException { - assertEquals("{\"empty\":true,\"present\":false}", objectMapper.writeValueAsString(Optional.empty())); - assertEquals("{\"empty\":false,\"present\":true}", objectMapper.writeValueAsString(Optional.of("empty"))); + assertEquals("{\"present\":false}", objectMapper.writeValueAsString(Optional.empty())); + assertEquals("{\"present\":true}", objectMapper.writeValueAsString(Optional.of("test"))); } @Test