From 413ed3d1d134d2d82c681ae441e3c6993ac442c2 Mon Sep 17 00:00:00 2001 From: Xinyuan Lin Date: Sun, 16 Aug 2026 19:21:29 -0700 Subject: [PATCH] chore(amber): remove the unused DeployStrategy family --- .../deploystrategy/DeployStrategy.scala | 30 ---- .../deploystrategy/OneOnEach.scala | 45 ------ .../deploystrategy/RandomDeployment.scala | 41 ------ .../deploystrategy/RoundRobinDeployment.scala | 44 ------ .../deploystrategy/DeployStrategiesSpec.scala | 133 ------------------ 5 files changed, 293 deletions(-) delete mode 100644 amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategy.scala delete mode 100644 amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/OneOnEach.scala delete mode 100644 amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/RandomDeployment.scala delete mode 100644 amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/RoundRobinDeployment.scala delete mode 100644 amber/src/test/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategiesSpec.scala diff --git a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategy.scala b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategy.scala deleted file mode 100644 index 079d253c848..00000000000 --- a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategy.scala +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.texera.amber.engine.architecture.deploysemantics.deploystrategy - -import org.apache.pekko.actor.Address - -trait DeployStrategy extends Serializable { - - def initialize(available: Array[Address]): Unit - - def next(): Address - -} diff --git a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/OneOnEach.scala b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/OneOnEach.scala deleted file mode 100644 index f35a1348118..00000000000 --- a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/OneOnEach.scala +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.texera.amber.engine.architecture.deploysemantics.deploystrategy - -import org.apache.pekko.actor.Address - -object OneOnEach { - def apply() = new OneOnEach() -} - -class OneOnEach extends DeployStrategy { - var available: Array[Address] = _ - var index = 0 - - override def initialize(available: Array[Address]): Unit = { - this.available = available - this.index = 0 - } - - override def next(): Address = { - val i = index - if (i >= available.length) { - throw new NoSuchElementException("no available addresses") - } - index += 1 - available(i) - } -} diff --git a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/RandomDeployment.scala b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/RandomDeployment.scala deleted file mode 100644 index 5e3ebfa972c..00000000000 --- a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/RandomDeployment.scala +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.texera.amber.engine.architecture.deploysemantics.deploystrategy - -import org.apache.pekko.actor.Address - -object RandomDeployment { - def apply() = new RandomDeployment() -} - -class RandomDeployment extends DeployStrategy { - var available: Array[Address] = _ - - override def initialize(available: Array[Address]): Unit = { - this.available = available - } - - override def next(): Address = { - if (available.isEmpty) { - throw new NoSuchElementException("no available addresses") - } - available(util.Random.nextInt(available.length)) - } -} diff --git a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/RoundRobinDeployment.scala b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/RoundRobinDeployment.scala deleted file mode 100644 index 70472974937..00000000000 --- a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/RoundRobinDeployment.scala +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.texera.amber.engine.architecture.deploysemantics.deploystrategy - -import org.apache.pekko.actor.Address - -object RoundRobinDeployment { - def apply() = new RoundRobinDeployment() -} - -class RoundRobinDeployment extends DeployStrategy { - var available: Array[Address] = _ - var index = 0 - - override def initialize(available: Array[Address]): Unit = { - this.available = available - } - - override def next(): Address = { - if (available.isEmpty) { - throw new NoSuchElementException("no available addresses") - } - val i = index - index = (index + 1) % available.length - available(i) - } -} diff --git a/amber/src/test/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategiesSpec.scala b/amber/src/test/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategiesSpec.scala deleted file mode 100644 index 568f58e36fc..00000000000 --- a/amber/src/test/scala/org/apache/texera/amber/engine/architecture/deploysemantics/deploystrategy/DeployStrategiesSpec.scala +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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.texera.amber.engine.architecture.deploysemantics.deploystrategy - -import org.apache.pekko.actor.Address -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers - -class DeployStrategiesSpec extends AnyFlatSpec with Matchers { - - // Use the "pekko" protocol to match Amber's real node addresses - // (e.g. AmberConfig.masterNodeAddr); "akka" diverges from production and - // can mislead anyone who debugs a failure by comparing addresses. - private val nodeA = Address("pekko", "sys", "host-a", 2552) - private val nodeB = Address("pekko", "sys", "host-b", 2552) - private val nodeC = Address("pekko", "sys", "host-c", 2552) - - // ----- OneOnEach ----- - - "OneOnEach" should "hand out each address exactly once in array order" in { - val strategy = OneOnEach() - strategy.initialize(Array(nodeA, nodeB, nodeC)) - strategy.next() shouldBe nodeA - strategy.next() shouldBe nodeB - strategy.next() shouldBe nodeC - } - - it should "raise NoSuchElementException once the array is exhausted" in { - val strategy = OneOnEach() - strategy.initialize(Array(nodeA)) - strategy.next() shouldBe nodeA - assertThrows[NoSuchElementException](strategy.next()) - } - - it should "raise NoSuchElementException immediately when initialized with an empty array" in { - val strategy = OneOnEach() - strategy.initialize(Array.empty[Address]) - assertThrows[NoSuchElementException](strategy.next()) - } - - it should "reset its iteration cursor on re-initialization" in { - val strategy = OneOnEach() - strategy.initialize(Array(nodeA, nodeB)) - strategy.next() shouldBe nodeA - strategy.next() shouldBe nodeB - strategy.initialize(Array(nodeC)) - strategy.next() shouldBe nodeC - assertThrows[NoSuchElementException](strategy.next()) - } - - "OneOnEach.apply" should "produce a fresh, independent instance" in { - val s1 = OneOnEach() - val s2 = OneOnEach() - s1 should not be theSameInstanceAs(s2) - } - - // ----- RoundRobinDeployment ----- - - "RoundRobinDeployment" should "rotate addresses in a repeating cycle" in { - val strategy = RoundRobinDeployment() - strategy.initialize(Array(nodeA, nodeB, nodeC)) - strategy.next() shouldBe nodeA - strategy.next() shouldBe nodeB - strategy.next() shouldBe nodeC - strategy.next() shouldBe nodeA - strategy.next() shouldBe nodeB - } - - it should "always return the only address when the array has length 1" in { - val strategy = RoundRobinDeployment() - strategy.initialize(Array(nodeA)) - for (_ <- 1 to 5) strategy.next() shouldBe nodeA - } - - it should "raise NoSuchElementException on next() with an empty array" in { - val strategy = RoundRobinDeployment() - strategy.initialize(Array.empty[Address]) - assertThrows[NoSuchElementException](strategy.next()) - } - - "RoundRobinDeployment.apply" should "produce a fresh, independent instance" in { - val s1 = RoundRobinDeployment() - val s2 = RoundRobinDeployment() - s1 should not be theSameInstanceAs(s2) - } - - // ----- RandomDeployment ----- - - "RandomDeployment" should "always return one of the available addresses" in { - val strategy = RandomDeployment() - val pool = Array(nodeA, nodeB, nodeC) - strategy.initialize(pool) - val poolSet = pool.toSet - for (_ <- 1 to 50) { - poolSet should contain(strategy.next()) - } - } - - it should "always return the only address when the array has length 1" in { - val strategy = RandomDeployment() - strategy.initialize(Array(nodeA)) - for (_ <- 1 to 5) strategy.next() shouldBe nodeA - } - - it should "raise NoSuchElementException on next() with an empty array" in { - val strategy = RandomDeployment() - strategy.initialize(Array.empty[Address]) - assertThrows[NoSuchElementException](strategy.next()) - } - - "RandomDeployment.apply" should "produce a fresh, independent instance" in { - val s1 = RandomDeployment() - val s2 = RandomDeployment() - s1 should not be theSameInstanceAs(s2) - } -}