Search in sources :

Example 1 with KubernetesContext

use of org.ballerinax.kubernetes.models.KubernetesContext 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)

Example 2 with KubernetesContext

use of org.ballerinax.kubernetes.models.KubernetesContext in project kubernetes by ballerinax.

the class HelmChartGeneratorTests method testHelmGenerate.

@Test
public void testHelmGenerate() throws KubernetesPluginException {
    DockerModel dockerModel = new DockerModel();
    Set<Integer> ports = new HashSet<>();
    ports.add(9090);
    ports.add(9091);
    ports.add(9092);
    dockerModel.setPorts(ports);
    dockerModel.setService(true);
    dockerModel.setJarFileName("hello.jar");
    dockerModel.setEnableDebug(true);
    dockerModel.setBaseImage(OPENJDK_11_JRE_SLIM_BASE);
    dockerModel.setDebugPort(5005);
    dockerModel.setBuildImage(false);
    KubernetesContext context = KubernetesContext.getInstance();
    KubernetesDataHolder dataHolder = context.getDataHolder();
    dataHolder.setDockerModel(dockerModel);
    new DockerHandler().createArtifacts();
    new HelmChartHandler().createArtifacts();
    File charYaml = dataHolder.getK8sArtifactOutputPath().resolve(module.name.toString()).resolve("hello-deployment").resolve("Chart.yaml").toFile();
    Assert.assertTrue(charYaml.exists());
    charYaml.deleteOnExit();
}
Also used : DockerModel(org.ballerinax.docker.generator.models.DockerModel) KubernetesDataHolder(org.ballerinax.kubernetes.models.KubernetesDataHolder) KubernetesContext(org.ballerinax.kubernetes.models.KubernetesContext) File(java.io.File) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 3 with KubernetesContext

use of org.ballerinax.kubernetes.models.KubernetesContext in project kubernetes by ballerinax.

the class HandlerTestSuite method setUp.

@BeforeSuite
public void setUp() {
    KubernetesContext context = KubernetesContext.getInstance();
    context.addDataHolder(module, Paths.get("build"));
    dataHolder = context.getDataHolder();
    Path buildDir = Paths.get(System.getProperty("buildDir"));
    dataHolder.setK8sArtifactOutputPath(buildDir.resolve(KUBERNETES).resolve(module.name.toString()));
    dataHolder.setDockerArtifactOutputPath(buildDir.resolve(DOCKER).resolve(module.name.toString()));
    Path resourcesDirectory = Paths.get("src").resolve("test").resolve("resources");
    DeploymentModel deploymentModel = new DeploymentModel();
    deploymentModel.setSingleYAML(false);
    dataHolder.setDeploymentModel(deploymentModel);
    dataHolder.setUberJarPath(resourcesDirectory.toAbsolutePath().resolve("hello.jar"));
}
Also used : Path(java.nio.file.Path) DeploymentModel(org.ballerinax.kubernetes.models.DeploymentModel) KubernetesContext(org.ballerinax.kubernetes.models.KubernetesContext) BeforeSuite(org.testng.annotations.BeforeSuite)

Aggregations

KubernetesContext (org.ballerinax.kubernetes.models.KubernetesContext)3 KubernetesDataHolder (org.ballerinax.kubernetes.models.KubernetesDataHolder)2 File (java.io.File)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 PackageID (org.ballerinalang.model.elements.PackageID)1 DockerModel (org.ballerinax.docker.generator.models.DockerModel)1 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)1 DeploymentModel (org.ballerinax.kubernetes.models.DeploymentModel)1 DependencyValidator (org.ballerinax.kubernetes.utils.DependencyValidator)1 BeforeSuite (org.testng.annotations.BeforeSuite)1 Test (org.testng.annotations.Test)1