Search in sources :

Example 11 with ZoneId

use of com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId in project vespa by vespa-engine.

the class ZoneApiHandler method proxy.

private HttpResponse proxy(HttpRequest request) {
    Path path = new Path(request.getUri().getPath());
    if (!path.matches("/zone/v2/{environment}/{region}/{*}")) {
        return notFound(path);
    }
    ZoneId zoneId = ZoneId.from(path.get("environment"), path.get("region"));
    if (!zoneRegistry.hasZone(zoneId)) {
        throw new IllegalArgumentException("No such zone: " + zoneId.value());
    }
    try {
        return proxy.handle(new ProxyRequest(request, "/zone/v2/"));
    } catch (ProxyException | IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(com.yahoo.vespa.hosted.controller.restapi.Path) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) ProxyException(com.yahoo.vespa.hosted.controller.proxy.ProxyException) IOException(java.io.IOException) ProxyRequest(com.yahoo.vespa.hosted.controller.proxy.ProxyRequest)

Example 12 with ZoneId

use of com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId in project vespa by vespa-engine.

the class ConfigServerRestExecutorImpl method handle.

@Override
public ProxyResponse handle(ProxyRequest proxyRequest) throws ProxyException {
    if (proxyRequest.isDiscoveryRequest()) {
        return createDiscoveryResponse(proxyRequest);
    }
    ZoneId zoneId = ZoneId.from(proxyRequest.getEnvironment(), proxyRequest.getRegion());
    // Make a local copy of the list as we want to manipulate it in case of ping problems.
    List<URI> allServers = new ArrayList<>(zoneRegistry.getConfigServerUris(zoneId));
    StringBuilder errorBuilder = new StringBuilder();
    if (queueFirstServerIfDown(allServers, proxyRequest)) {
        errorBuilder.append("Change ordering due to failed ping.");
    }
    for (URI uri : allServers) {
        Optional<ProxyResponse> proxyResponse = proxyCall(uri, proxyRequest, errorBuilder);
        if (proxyResponse.isPresent()) {
            return proxyResponse.get();
        }
    }
    // TODO Add logging, for now, experimental and we want to not add more noise.
    throw new ProxyException(ErrorResponse.internalServerError("Failed talking to config servers: " + errorBuilder.toString()));
}
Also used : ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 13 with ZoneId

use of com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId in project vespa by vespa-engine.

the class ApplicationController method deployApplication.

/**
 * Deploys an application. If the application does not exist it is created.
 */
// TODO: Get rid of the options arg
public ActivateResult deployApplication(ApplicationId applicationId, ZoneId zone, Optional<ApplicationPackage> applicationPackageFromDeployer, DeployOptions options) {
    try (Lock lock = lock(applicationId)) {
        LockedApplication application = get(applicationId).map(app -> new LockedApplication(app, lock)).orElseGet(() -> new LockedApplication(createApplication(applicationId, Optional.empty()), lock));
        final boolean canDeployDirectly = canDeployDirectlyTo(zone, options);
        // Determine Vespa version to use
        Version version;
        if (options.deployCurrentVersion) {
            version = application.versionIn(zone, controller);
        } else if (canDeployDirectlyTo(zone, options)) {
            version = options.vespaVersion.map(Version::new).orElse(controller.systemVersion());
        } else if (!application.change().isPresent() && !zone.environment().isManuallyDeployed()) {
            return unexpectedDeployment(applicationId, zone, applicationPackageFromDeployer);
        } else {
            version = application.deployVersionIn(zone, controller);
        }
        // Determine application package to use
        Pair<ApplicationPackage, ApplicationVersion> artifact = artifactFor(zone, application, applicationPackageFromDeployer, canDeployDirectly, options.deployCurrentVersion);
        ApplicationPackage applicationPackage = artifact.getFirst();
        ApplicationVersion applicationVersion = artifact.getSecond();
        validate(applicationPackage.deploymentSpec());
        // Update application with information from application package
        if (!options.deployCurrentVersion) {
            // Store information about application package
            application = application.with(applicationPackage.deploymentSpec());
            application = application.with(applicationPackage.validationOverrides());
            // Delete zones not listed in DeploymentSpec, if allowed
            // We do this at deployment time to be able to return a validation failure message when necessary
            application = deleteRemovedDeployments(application);
            // Clean up deployment jobs that are no longer referenced by deployment spec
            application = deleteUnreferencedDeploymentJobs(application);
            // TODO jvenstad: Store triggering information here, including versions, when job status is read from the build service.
            // store missing information even if we fail deployment below
            store(application);
        }
        // Validate the change being deployed
        if (!canDeployDirectly) {
            validateChange(application, zone, version);
        }
        // Assign global rotation
        application = withRotation(application, zone);
        Set<String> rotationNames = new HashSet<>();
        Set<String> cnames = new HashSet<>();
        application.rotation().ifPresent(applicationRotation -> {
            rotationNames.add(applicationRotation.id().asString());
            cnames.add(applicationRotation.dnsName());
            cnames.add(applicationRotation.secureDnsName());
        });
        // Carry out deployment
        options = withVersion(version, options);
        ConfigServerClient.PreparedApplication preparedApplication = configServer.prepare(new DeploymentId(applicationId, zone), options, cnames, rotationNames, applicationPackage.zippedContent());
        preparedApplication.activate();
        application = application.withNewDeployment(zone, applicationVersion, version, clock.instant());
        store(application);
        return new ActivateResult(new RevisionId(applicationPackage.hash()), preparedApplication.prepareResponse(), applicationPackage.zippedContent().length);
    }
}
Also used : ArtifactRepository(com.yahoo.vespa.hosted.controller.api.integration.deployment.ArtifactRepository) ZmsClient(com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsClient) EndpointStatus(com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus) DeploymentTrigger(com.yahoo.vespa.hosted.controller.deployment.DeploymentTrigger) URISyntaxException(java.net.URISyntaxException) DeploymentJobs(com.yahoo.vespa.hosted.controller.application.DeploymentJobs) ValidationId(com.yahoo.config.application.api.ValidationId) JobReport(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobReport) TenantName(com.yahoo.config.provision.TenantName) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) DeploymentExpirer(com.yahoo.vespa.hosted.controller.maintenance.DeploymentExpirer) RevisionId(com.yahoo.vespa.hosted.controller.api.identifiers.RevisionId) Duration(java.time.Duration) Map(java.util.Map) DeployOptions(com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions) URI(java.net.URI) Rotation(com.yahoo.vespa.hosted.controller.rotation.Rotation) Exceptions(com.yahoo.yolean.Exceptions) RotationRepository(com.yahoo.vespa.hosted.controller.rotation.RotationRepository) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) Set(java.util.Set) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) List(java.util.List) Optional(java.util.Optional) Deployment(com.yahoo.vespa.hosted.controller.application.Deployment) RotationsConfig(com.yahoo.vespa.hosted.rotation.config.RotationsConfig) Log(com.yahoo.vespa.hosted.controller.api.integration.configserver.Log) AthenzClientFactory(com.yahoo.vespa.hosted.controller.api.integration.athenz.AthenzClientFactory) Version(com.yahoo.component.Version) ApplicationId(com.yahoo.config.provision.ApplicationId) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) RecordId(com.yahoo.vespa.hosted.controller.api.integration.dns.RecordId) ConfigServerClient(com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerClient) HashMap(java.util.HashMap) NToken(com.yahoo.vespa.athenz.api.NToken) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) ConfigChangeActions(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.ConfigChangeActions) ImmutableList(com.google.common.collect.ImmutableList) TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) RecordData(com.yahoo.vespa.hosted.controller.api.integration.dns.RecordData) RoutingEndpoint(com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingEndpoint) RoutingGenerator(com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingGenerator) ActivateResult(com.yahoo.vespa.hosted.controller.api.ActivateResult) NoInstanceException(com.yahoo.vespa.hosted.controller.api.integration.configserver.NoInstanceException) Lock(com.yahoo.vespa.curator.Lock) Hostname(com.yahoo.vespa.hosted.controller.api.identifiers.Hostname) Environment(com.yahoo.config.provision.Environment) ControllerDb(com.yahoo.vespa.hosted.controller.persistence.ControllerDb) CuratorDb(com.yahoo.vespa.hosted.controller.persistence.CuratorDb) IOException(java.io.IOException) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) Consumer(java.util.function.Consumer) Pair(com.yahoo.collections.Pair) DeploymentSpec(com.yahoo.config.application.api.DeploymentSpec) RecordName(com.yahoo.vespa.hosted.controller.api.integration.dns.RecordName) Clock(java.time.Clock) NameService(com.yahoo.vespa.hosted.controller.api.integration.dns.NameService) PrepareResponse(com.yahoo.vespa.hosted.controller.api.integration.configserver.PrepareResponse) Collections(java.util.Collections) Record(com.yahoo.vespa.hosted.controller.api.integration.dns.Record) RotationLock(com.yahoo.vespa.hosted.controller.rotation.RotationLock) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) RevisionId(com.yahoo.vespa.hosted.controller.api.identifiers.RevisionId) Lock(com.yahoo.vespa.curator.Lock) RotationLock(com.yahoo.vespa.hosted.controller.rotation.RotationLock) ActivateResult(com.yahoo.vespa.hosted.controller.api.ActivateResult) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) Version(com.yahoo.component.Version) ConfigServerClient(com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerClient) HashSet(java.util.HashSet)

Aggregations

ZoneId (com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId)13 ApplicationId (com.yahoo.config.provision.ApplicationId)4 DeployOptions (com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions)4 Application (com.yahoo.vespa.hosted.controller.Application)3 DeploymentId (com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId)3 Deployment (com.yahoo.vespa.hosted.controller.application.Deployment)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ImmutableList (com.google.common.collect.ImmutableList)2 Version (com.yahoo.component.Version)2 ClusterSpec (com.yahoo.config.provision.ClusterSpec)2 Controller (com.yahoo.vespa.hosted.controller.Controller)2 ActivateResult (com.yahoo.vespa.hosted.controller.api.ActivateResult)2 EndpointStatus (com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus)2 ApplicationList (com.yahoo.vespa.hosted.controller.application.ApplicationList)2 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)2 JobType.stagingTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)2 JobType.systemTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest)2 IOException (java.io.IOException)2 URI (java.net.URI)2