All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.vespa.model.application.validation.DeploymentSpecValidator Maven / Gradle / Ivy

There is a newer version: 8.441.21
Show newest version
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.application.validation;

import com.yahoo.config.application.api.DeploymentInstanceSpec;
import com.yahoo.config.application.api.DeploymentSpec;
import com.yahoo.config.provision.InstanceName;
import com.yahoo.vespa.model.application.validation.Validation.Context;
import com.yahoo.vespa.model.container.ContainerModel;

import java.io.Reader;
import java.util.List;
import java.util.Optional;

/**
 * Validate deployment spec (deployment.xml).
 *
 * @author hmusum
 * @author bratseth
 */
public class DeploymentSpecValidator implements Validator {

    @Override
    public void validate(Context context) {
        Optional deployment = context.deployState().getApplicationPackage().getDeployment();
        if ( deployment.isEmpty()) return;

        Reader deploymentReader = deployment.get();
        DeploymentSpec deploymentSpec = DeploymentSpec.fromXml(deploymentReader);
        List containers = context.model().getRoot().configModelRepo().getModels(ContainerModel.class);
        for (DeploymentInstanceSpec instance : deploymentSpec.instances()) {
            instance.endpoints().forEach(endpoint -> {
                requireClusterId(context, containers, instance.name(),
                                 "Endpoint '" + endpoint.endpointId() + "'", endpoint.containerId());
            });
        }
    }

    private static void requireClusterId(Context context, List containers, InstanceName instanceName,
                                         String endpoint, String id) {
        if (containers.stream().noneMatch(container -> container.getCluster().getName().equals(id)))
            context.illegal(endpoint + " in instance " + instanceName + ": '" + id +
                            "' specified in deployment.xml does not match any container cluster ID");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy