Search in sources :

Example 1 with KnativeContext

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");
        }
    }
}
Also used : KnativeContext(org.ballerinax.kubernetes.models.knative.KnativeContext) DependencyValidator(org.ballerinax.kubernetes.utils.DependencyValidator) KnativeDataHolder(org.ballerinax.kubernetes.models.knative.KnativeDataHolder) ArrayList(java.util.ArrayList) PackageID(org.ballerinalang.model.elements.PackageID) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException)

Aggregations

ArrayList (java.util.ArrayList)1 PackageID (org.ballerinalang.model.elements.PackageID)1 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)1 KnativeContext (org.ballerinax.kubernetes.models.knative.KnativeContext)1 KnativeDataHolder (org.ballerinax.kubernetes.models.knative.KnativeDataHolder)1 DependencyValidator (org.ballerinax.kubernetes.utils.DependencyValidator)1