Skip to content

Commit

Permalink
Minor clean-ups and javadoc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Jun 7, 2023
1 parent 8ac1024 commit d01808f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DeploymentUtil {

/**
* Get the available deployers.
* The list is obtained by checking for properties `quarkus.xxx.deploy`.
* The list is obtained by checking for properties {@code quarkus.xxx.deploy}.
* These properties have a default value and thus they will be found regardless of the
* actual user configuration, so we check for property names instead.
*
Expand All @@ -28,14 +28,14 @@ public class DeploymentUtil {
public static List<String> getDeployers() {
Config config = ConfigProvider.getConfig();
return StreamSupport.stream(config.getPropertyNames().spliterator(), false)
.map(p -> QUARKUS_DEPLOY_PATTERN.matcher(p))
.map(QUARKUS_DEPLOY_PATTERN::matcher)
.filter(Matcher::matches)
.map(m -> m.group(1))
.collect(Collectors.toList());
}

/**
* @return a {@link Predicate} that tests if deploye is enabled.
* @return a {@link Predicate} that tests if deployer is enabled.
*/
public static Predicate<String> isDeployExplicitlyEnabled() {
return deployer -> ConfigProvider.getConfig().getOptionalValue(String.format(DEPLOY, deployer), Boolean.class)
Expand All @@ -50,17 +50,20 @@ public static Optional<String> getEnabledDeployer() {
}

/**
* Check if any of the specified deployers is enabled.
* Check if any of the specified deployers are enabled.
*
* @param the name of the speicifed deployers.
* @return true if the specified deploy is explicitly enabled, fasle otherwise.
* @param deployers name of the specified deployers.
* @return {@code true} if the specified deployer is explicitly enabled, {@code false} otherwise.
*/
public static boolean isDeploymentEnabled(String... deployer) {
return getDeployers().stream().filter(isDeployExplicitlyEnabled()).anyMatch(d -> Arrays.asList(deployer).contains(d));
public static boolean isDeploymentEnabled(String... deployers) {
if (deployers == null) {
return false;
}
return getDeployers().stream().filter(isDeployExplicitlyEnabled()).anyMatch(d -> Arrays.asList(deployers).contains(d));
}

/**
* @return true if deployment is explicitly enabled using: `quarkus.<deployment target>.deploy=true`.
* @return true if deployment is explicitly enabled using: {@code quarkus.<deployment target>.deploy=true}.
*/
public static boolean isDeploymentEnabled() {
return getEnabledDeployer().isPresent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class KnativeProcessor {
public void checkKnative(ApplicationInfoBuildItem applicationInfo, KnativeConfig config,
BuildProducer<KubernetesDeploymentTargetBuildItem> deploymentTargets,
BuildProducer<KubernetesResourceMetadataBuildItem> resourceMeta) {
List<String> targets = KubernetesConfigUtil.getConfiguratedDeploymentTargets();
List<String> targets = KubernetesConfigUtil.getConfiguredDeploymentTargets();
boolean knativeEnabled = targets.contains(KNATIVE);
deploymentTargets.produce(
new KubernetesDeploymentTargetBuildItem(KNATIVE, KNATIVE_SERVICE, KNATIVE_SERVICE_GROUP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.eclipse.microprofile.config.Config;
Expand All @@ -28,60 +27,70 @@ public class KubernetesConfigUtil {
public static final String MANAGEMENT_PORT_NAME = "management";

private static final String DEKORATE_PREFIX = "dekorate.";
private static final Pattern QUARKUS_DEPLOY_PATTERN = Pattern.compile("quarkus\\.([^\\.]+)\\.deploy");

/**
* Get the explicit configured deployment target, if any.
* The explicit deployment target is determined using: `quarkus.kubernetes.deployment-target=<deployment-target>`
* Get the explicitly configured deployment target, if any.
* The explicit deployment target is determined using: {@code quarkus.kubernetes.deployment-target=<deployment-target>}
*/
public static Optional<String> getExplicitlyConfiguredDeploymentTarget() {
Config config = ConfigProvider.getConfig();
return config.getOptionalValue(DEPLOYMENT_TARGET, String.class);
}

/**
* The the explicitly configured deployment target list.
* The configured deployment targets are determined using: `quarkus.kubernetes.deployment-target=<deployment-target>`
* @deprecated Use {@link #getExplicitlyConfiguredDeploymentTargets()} instead
*/
@Deprecated(forRemoval = true)
public static List<String> getExplictilyDeploymentTargets() {
String deploymentTargets = getExplicitlyConfiguredDeploymentTarget().orElse("");
if (deploymentTargets.isEmpty()) {
return Collections.emptyList();
}
return Arrays.stream(deploymentTargets
.split(Pattern.quote(",")))
.map(String::trim)
.map(String::toLowerCase)
.collect(Collectors.toList());
return getExplicitlyConfiguredDeploymentTargets();
}

/**
* The explicitly configured deployment target list.
* The configured deployment targets are determined using: {@code quarkus.kubernetes.deployment-target=<deployment-target>}
*/
public static List<String> getExplicitlyConfiguredDeploymentTargets() {
return splitDeploymentTargets(getExplicitlyConfiguredDeploymentTarget());
}

private static List<String> splitDeploymentTargets(Optional<String> commaSeparatedDeploymentTargets) {
return commaSeparatedDeploymentTargets
.map(s -> Arrays.stream(s.split(","))
.map(String::trim)
.map(String::toLowerCase)
.collect(Collectors.toList()))
.orElse(Collections.emptyList());
}

/**
* Get the user configured deployment target, if any.
* The configured deployment target is determined using:
* 1. the value of `quarkus.kubernetes.deployment-target=<deployment-target>`
* 2. the presence of `quarkus.<deployment-target>.deploy=true`
* <ol>
* <li>the value of {@code quarkus.kubernetes.deployment-target=<deployment-target>}</li>
* <li>the presence of {@code quarkus.<deployment-target>.deploy=true}</li>
* </ol>
*/
public static Optional<String> getConfiguredDeploymentTarget() {
Config config = ConfigProvider.getConfig();
return getExplicitlyConfiguredDeploymentTarget().or(() -> DeploymentUtil.getEnabledDeployer());
return getExplicitlyConfiguredDeploymentTarget().or(DeploymentUtil::getEnabledDeployer);
}

/**
* The the configured deployment target list.
* The configured deployment targets are determined using:
* 1. the value of `quarkus.kubernetes.deployment-target=<deployment-target>`
* 2. the presenve of `quarkus.<deployment-target>.deploy=true`
* @deprecated Use {@link #getConfiguredDeploymentTargets()} instead
*/
@Deprecated(forRemoval = true)
public static List<String> getConfiguratedDeploymentTargets() {
String deploymentTargets = getConfiguredDeploymentTarget().orElse("");
if (deploymentTargets.isEmpty()) {
return Collections.emptyList();
}
return Arrays.stream(deploymentTargets
.split(","))
.map(String::trim)
.map(String::toLowerCase)
.collect(Collectors.toList());
return getConfiguredDeploymentTargets();
}

/**
* Get the configured deployment target list as determined by:
* <ol>
* <li>the value of {@code quarkus.kubernetes.deployment-target=<deployment-target>}</li>
* <li>the presence of {@code quarkus.<deployment-target>.deploy=true}</li>
* </ol>
*/
public static List<String> getConfiguredDeploymentTargets() {
return splitDeploymentTargets(getConfiguredDeploymentTarget());
}

public static boolean isDeploymentEnabled() {
Expand All @@ -91,8 +100,7 @@ public static boolean isDeploymentEnabled() {
/*
* Collects configuration properties for Kubernetes. Reads all properties and
* matches properties that match known Dekorate generators. These properties may
* or may not be prefixed with `quarkus.` though the prefixed ones take
* precedence.
* or may not be prefixed with {@code quarkus.} though the prefixed ones take precedence.
*
* @return A map containing the properties.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private DeploymentTargetEntry determineDeploymentTarget(
ContainerImageConfig containerImageConfig) {
final DeploymentTargetEntry selectedTarget;

List<String> userSpecifiedDeploymentTargets = KubernetesConfigUtil.getExplictilyDeploymentTargets();
List<String> userSpecifiedDeploymentTargets = KubernetesConfigUtil.getExplicitlyConfiguredDeploymentTargets();
if (userSpecifiedDeploymentTargets.isEmpty()) {
selectedTarget = targets.getEntriesSortedByPriority().get(0);
if (targets.getEntriesSortedByPriority().size() > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ public void build(ApplicationInfoBuildItem applicationInfo,
optionalProject.ifPresent(project -> {
Set<String> targets = new HashSet<>();
targets.add(COMMON);
targets.addAll(kubernetesDeploymentTargets.getEntriesSortedByPriority()
.stream()
.map(DeploymentTargetEntry::getName)
.collect(Collectors.toSet()));
targets.addAll(deploymentTargets);
final Map<String, String> generatedResourcesMap;
final SessionWriter sessionWriter = new QuarkusFileWriter(project);
final SessionReader sessionReader = new SimpleFileReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class OpenshiftProcessor {
public void checkOpenshift(ApplicationInfoBuildItem applicationInfo, Capabilities capabilities, OpenshiftConfig config,
BuildProducer<KubernetesDeploymentTargetBuildItem> deploymentTargets,
BuildProducer<KubernetesResourceMetadataBuildItem> resourceMeta) {
List<String> targets = KubernetesConfigUtil.getConfiguratedDeploymentTargets();
List<String> targets = KubernetesConfigUtil.getConfiguredDeploymentTargets();
boolean openshiftEnabled = targets.contains(OPENSHIFT);

DeploymentResourceKind deploymentResourceKind = config.getDeploymentResourceKind(capabilities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,11 @@ public void checkVanillaKubernetes(ApplicationInfoBuildItem applicationInfo, Cap
BuildProducer<KubernetesResourceMetadataBuildItem> resourceMeta) {
String kind = config.getDeploymentResourceKind(capabilities).kind;

List<String> userSpecifiedDeploymentTargets = KubernetesConfigUtil.getConfiguratedDeploymentTargets();
List<String> userSpecifiedDeploymentTargets = KubernetesConfigUtil.getConfiguredDeploymentTargets();
if (userSpecifiedDeploymentTargets.isEmpty() || userSpecifiedDeploymentTargets.contains(KUBERNETES)) {
// when nothing was selected by the user, we enable vanilla Kubernetes by
// default
deploymentTargets
.produce(
new KubernetesDeploymentTargetBuildItem(KUBERNETES, kind, DEPLOYMENT_GROUP,
DEPLOYMENT_VERSION, VANILLA_KUBERNETES_PRIORITY, true, config.deployStrategy));
// when nothing was selected by the user, we enable vanilla Kubernetes by default
deploymentTargets.produce(new KubernetesDeploymentTargetBuildItem(KUBERNETES, kind, DEPLOYMENT_GROUP,
DEPLOYMENT_VERSION, VANILLA_KUBERNETES_PRIORITY, true, config.deployStrategy));

String name = ResourceNameUtil.getResourceName(config, applicationInfo);
resourceMeta.produce(new KubernetesResourceMetadataBuildItem(KUBERNETES, DEPLOYMENT_GROUP, DEPLOYMENT_VERSION,
Expand Down

0 comments on commit d01808f

Please sign in to comment.