-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WOR-1410] add regional default parameters for landing zones (#378)
- Loading branch information
1 parent
1f30f38
commit 075ac01
Showing
65 changed files
with
556 additions
and
497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...java/bio/terra/landingzone/library/configuration/LandingZoneAzureRegionConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package bio.terra.landingzone.library.configuration; | ||
|
||
import java.util.Map; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableConfigurationProperties | ||
@ConfigurationProperties(prefix = "landingzone.regions") | ||
public class LandingZoneAzureRegionConfiguration { | ||
|
||
private Map<String, Map<String, String>> defaultParameters; | ||
|
||
public Map<String, Map<String, String>> getDefaultParameters() { | ||
return defaultParameters; | ||
} | ||
|
||
public void setDefaultParameters(Map<String, Map<String, String>> defaultParameters) { | ||
this.defaultParameters = defaultParameters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 2 additions & 20 deletions
22
...a/bio/terra/landingzone/library/landingzones/definition/factories/ParametersResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,10 @@ | ||
package bio.terra.landingzone.library.landingzones.definition.factories; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ParametersResolver { | ||
private final Map<String, String> defaultParameters; | ||
private final Map<String, String> parameters; | ||
|
||
public ParametersResolver(Map<String, String> parameters, Map<String, String> defaultParameters) { | ||
if (defaultParameters == null) { | ||
this.defaultParameters = new HashMap<>(); | ||
} else { | ||
this.defaultParameters = defaultParameters; | ||
} | ||
|
||
this.parameters = parameters; | ||
} | ||
public record ParametersResolver(Map<String, String> parameters) { | ||
|
||
public String getValue(String parameterName) { | ||
if (parameters == null) { | ||
return defaultParameters.getOrDefault(parameterName, ""); | ||
} | ||
|
||
return parameters.getOrDefault( | ||
parameterName, defaultParameters.getOrDefault(parameterName, "")); | ||
return parameters.getOrDefault(parameterName, ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
library/src/main/java/bio/terra/landingzone/stairway/flight/ParametersResolverProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package bio.terra.landingzone.stairway.flight; | ||
|
||
import bio.terra.landingzone.library.configuration.LandingZoneAzureRegionConfiguration; | ||
import bio.terra.landingzone.library.landingzones.definition.factories.ParametersResolver; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ParametersResolverProvider { | ||
|
||
private final LandingZoneAzureRegionConfiguration landingZoneAzureRegionConfiguration; | ||
|
||
@Autowired | ||
public ParametersResolverProvider( | ||
LandingZoneAzureRegionConfiguration landingZoneAzureRegionConfiguration) { | ||
this.landingZoneAzureRegionConfiguration = landingZoneAzureRegionConfiguration; | ||
} | ||
|
||
/** | ||
* Returns a ParametersResolver for a set of input parameters and Azure region. Input parameters | ||
* take precedence over regional default parameters, which in turn take precedence over default | ||
* landing zone parameters defined in `LandingZoneDefaultParameters`. | ||
*/ | ||
public ParametersResolver create(Map<String, String> inputParameters, String region) { | ||
var parameters = new HashMap<>(LandingZoneDefaultParameters.get()); | ||
|
||
var regionalParameters = landingZoneAzureRegionConfiguration.getDefaultParameters(); | ||
|
||
if (regionalParameters != null) { | ||
if (region == null) { | ||
throw new IllegalArgumentException("Region must not be null."); | ||
} else { | ||
parameters.putAll(regionalParameters.getOrDefault(region, new HashMap<>())); | ||
} | ||
} | ||
if (inputParameters != null) { | ||
parameters.putAll(inputParameters); | ||
} | ||
|
||
return new ParametersResolver(parameters); | ||
} | ||
} |
Oops, something went wrong.