Skip to content

Commit

Permalink
Config loader always loads configs for all the available roles (#2021)
Browse files Browse the repository at this point in the history
This fixes issues with ConfigWriter and run-all meta-roles caused by axis defined in role-local configs
  • Loading branch information
pshirshov authored Oct 7, 2023
1 parent ba70be8 commit 820717c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import java.io.{File, FileNotFoundException}
import scala.jdk.CollectionConverters.*
import scala.util.{Failure, Success, Try}



/**
* Default config resources:
* - `\${roleName}.conf`
Expand Down Expand Up @@ -51,9 +49,7 @@ import scala.util.{Failure, Success, Try}
* @see [[ConfigLoader.ConfigLocation]]
* @see [[ConfigLoader.LocalFSImpl]]
*/
trait ConfigLoader extends AbstractConfigLoader {

}
trait ConfigLoader extends AbstractConfigLoader {}

object ConfigLoader {
def empty: ConfigLoader = () => AppConfig(ConfigFactory.empty())
Expand Down Expand Up @@ -89,11 +85,11 @@ object ConfigLoader {
rolesInfo: RolesInfo,
): ConfigLoader.Args = {
val maybeGlobalConfig = parameters.globalParameters.findValue(RoleAppMain.Options.configParam).asFile
val emptyRoleConfigs = rolesInfo.requiredRoleNames.map(_ -> None).toMap
val emptyRoleConfigs = rolesInfo.availableRoleNames.map(_ -> None).toMap
val specifiedRoleConfigs = parameters.roles.iterator
.map(roleParams => roleParams.role -> roleParams.roleParameters.findValue(RoleAppMain.Options.configParam).asFile)
.toMap
ConfigLoader.Args(maybeGlobalConfig, (emptyRoleConfigs ++ specifiedRoleConfigs).view.filterKeys(rolesInfo.requiredRoleNames).toMap)
ConfigLoader.Args(maybeGlobalConfig, (emptyRoleConfigs ++ specifiedRoleConfigs).view.toMap)
}

def empty: ConfigLoader.Args = ConfigLoader.Args(None, Map.empty)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
activation {
role05localaxis = rolelocal1
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TestPluginBase[F[_]: TagK] extends PluginDef with ConfigModuleDef with Rol
makeRole[TestRole03[F]]
makeRole[TestRole04[F]]

include(new TestRole05.Role05Module[F])
makeRole[FailingRole01[F]]
makeRole[FailingRole02[F]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,4 @@ class FailingRole02[F[_]: QuasiIO](
object FailingRole02 extends RoleDescriptor {
override final val id = "failingrole02"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package izumi.distage.roles.test.fixtures

import distage.{Axis, ModuleDef}
import izumi.distage.config.ConfigModuleDef
import izumi.distage.model.definition.Lifecycle
import izumi.distage.roles.model.{RoleDescriptor, RoleService}
import izumi.distage.roles.model.definition.RoleModuleDef
import izumi.distage.roles.test.fixtures.TestRole05.{TestRole05Dependency, TestRole05DependencyImpl1}
import izumi.functional.quasi.QuasiIO
import izumi.fundamentals.platform.cli.model.raw.RawEntrypointParams
import izumi.reflect.TagK

class TestRole05[F[_] : QuasiIO](
dependency: TestRole05Dependency
) extends RoleService[F] {
override def start(roleParameters: RawEntrypointParams, freeArgs: Vector[String]): Lifecycle[F, Unit] = Lifecycle.make(QuasiIO[F].maybeSuspend {
assert(dependency.isInstanceOf[TestRole05DependencyImpl1])
}) {
_ =>
QuasiIO[F].unit
}
}

object TestRole05 extends RoleDescriptor {
override final val id = "testrole05"

trait TestRole05Dependency

class TestRole05DependencyImpl1 extends TestRole05Dependency

class TestRole05DependencyImpl2 extends TestRole05Dependency

object Role05LocalAxis extends Axis {
case object Rolelocal2 extends AxisChoiceDef

case object Rolelocal1 extends AxisChoiceDef
}

class Role05Module[F[_] : TagK] extends ModuleDef with ConfigModuleDef with RoleModuleDef {
makeRole[TestRole05[F]]
make[TestRole05Dependency].from[TestRole05DependencyImpl1].tagged(Role05LocalAxis.Rolelocal1)
make[TestRole05Dependency].from[TestRole05DependencyImpl2].tagged(Role05LocalAxis.Rolelocal2)
}

}

0 comments on commit 820717c

Please sign in to comment.