Search in sources :

Example 1 with DependencyValidator

use of org.ballerinax.kubernetes.utils.DependencyValidator 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)

Example 2 with DependencyValidator

use of org.ballerinax.kubernetes.utils.DependencyValidator in project kubernetes by ballerinax.

the class KubernetesPlugin method validateDeploymentDependencies.

private void validateDeploymentDependencies() throws KubernetesPluginException {
    KubernetesContext context = KubernetesContext.getInstance();
    Map<PackageID, KubernetesDataHolder> packageToDataHolderMap = context.getPackageIDtoDataHolderMap();
    DependencyValidator dependencyValidator = new DependencyValidator();
    for (KubernetesDataHolder dataHolder : packageToDataHolderMap.values()) {
        // add other dependent deployments
        List<String> dependencies = new ArrayList<>();
        // add the current deployment as 0th element
        String currentDeployment = dataHolder.getDeploymentModel().getName();
        if (currentDeployment == null) {
            return;
        }
        dependencies.add(currentDeployment);
        Set<String> dependsOn = dataHolder.getDeploymentModel().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 : DependencyValidator(org.ballerinax.kubernetes.utils.DependencyValidator) KubernetesDataHolder(org.ballerinax.kubernetes.models.KubernetesDataHolder) ArrayList(java.util.ArrayList) PackageID(org.ballerinalang.model.elements.PackageID) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) KubernetesContext(org.ballerinax.kubernetes.models.KubernetesContext)

Aggregations

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