use of org.ballerinax.kubernetes.models.knative.KnativeContext in project kubernetes by ballerinax.
the class KnativePlugin method validateDeploymentDependencies.
private void validateDeploymentDependencies() throws KubernetesPluginException {
KnativeContext context = KnativeContext.getInstance();
Map<PackageID, KnativeDataHolder> packageToDataHolderMap = context.getPackageIDtoDataHolderMap();
DependencyValidator dependencyValidator = new DependencyValidator();
for (KnativeDataHolder dataHolder : packageToDataHolderMap.values()) {
// add other dependent deployments
List<String> dependencies = new ArrayList<>();
// add the current deployment as 0th element
String currentDeployment = dataHolder.getServiceModel().getName();
if (currentDeployment == null) {
return;
}
dependencies.add(currentDeployment);
Set<String> dependsOn = dataHolder.getServiceModel().getDependsOn();
for (String listenerName : dependsOn) {
String dependentDeployment = context.getDeploymentNameFromListener(listenerName);
if (dependentDeployment == null) {
return;
}
if (!dependentDeployment.equals(currentDeployment)) {
dependencies.add(dependentDeployment);
} else {
// Listener is in the same package.
throw new KubernetesPluginException("@kubernetes:Deployment{} contains cyclic dependencies");
}
}
String[] array = dependencies.toArray(new String[0]);
if (!dependencyValidator.validateDependency(array)) {
throw new KubernetesPluginException("@kubernetes:Deployment{} contains cyclic dependencies");
}
}
}
Aggregations