Search in sources :

Example 1 with InternalServerException

use of com.yahoo.vespa.config.server.http.InternalServerException in project vespa by vespa-engine.

the class Deployment method activate.

/**
 * Activates this. If it is not already prepared, this will call prepare first.
 */
@Override
public void activate() {
    if (!prepared)
        prepare();
    TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout);
    long sessionId = session.getSessionId();
    validateSessionStatus(session);
    ActivateLock activateLock = tenant.getActivateLock();
    boolean activateLockAcquired = false;
    try {
        log.log(LogLevel.DEBUG, "Trying to acquire lock " + activateLock + " for session " + sessionId);
        activateLockAcquired = activateLock.acquire(timeoutBudget, ignoreLockFailure);
        if (!activateLockAcquired) {
            throw new ActivationConflictException("Did not get activate lock for session " + sessionId + " within " + timeout);
        }
        log.log(LogLevel.DEBUG, "Lock acquired " + activateLock + " for session " + sessionId);
        NestedTransaction transaction = new NestedTransaction();
        transaction.add(deactivateCurrentActivateNew(applicationRepository.getActiveSession(session.getApplicationId()), session, ignoreSessionStaleFailure));
        if (hostProvisioner.isPresent()) {
            hostProvisioner.get().activate(transaction, session.getApplicationId(), session.getAllocatedHosts().getHosts());
        }
        transaction.commit();
        session.waitUntilActivated(timeoutBudget);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new InternalServerException("Error activating application", e);
    } finally {
        if (activateLockAcquired) {
            log.log(LogLevel.DEBUG, "Trying to release lock " + activateLock + " for session " + sessionId);
            activateLock.release();
            log.log(LogLevel.DEBUG, "Lock released " + activateLock + " for session " + sessionId);
        }
    }
    log.log(LogLevel.INFO, session.logPre() + "Session " + sessionId + " activated successfully using " + (hostProvisioner.isPresent() ? hostProvisioner.get() : "no host provisioner") + ". Config generation " + session.getMetaData().getGeneration());
}
Also used : ActivationConflictException(com.yahoo.vespa.config.server.ActivationConflictException) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) NestedTransaction(com.yahoo.transaction.NestedTransaction) TimeoutBudget(com.yahoo.vespa.config.server.TimeoutBudget) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) ActivationConflictException(com.yahoo.vespa.config.server.ActivationConflictException) ActivateLock(com.yahoo.vespa.config.server.tenant.ActivateLock)

Example 2 with InternalServerException

use of com.yahoo.vespa.config.server.http.InternalServerException in project vespa by vespa-engine.

the class ModelsBuilder method buildModels.

/**
 * Builds all applicable model versions
 *
 * @param allocatedHosts the newest version (major and minor) (which is loaded first) decides the allocated hosts
 *                       and assigns to this SettableOptional such that it can be used after this method returns
 */
public List<MODELRESULT> buildModels(ApplicationId applicationId, com.yahoo.component.Version wantedNodeVespaVersion, ApplicationPackage applicationPackage, SettableOptional<AllocatedHosts> allocatedHosts, Instant now) {
    Set<Version> versions = modelFactoryRegistry.allVersions();
    // If the application specifies a major, load models only for that
    Optional<Integer> requestedMajorVersion = applicationPackage.getMajorVersion();
    if (requestedMajorVersion.isPresent())
        versions = filterByMajorVersion(requestedMajorVersion.get(), versions);
    // Load models by one major version at the time as new major versions are allowed to be non-loadable
    // in the case where an existing application is incompatible with a new major version
    // (which is possible by the definition of major)
    List<Integer> majorVersions = versions.stream().map(Version::getMajor).distinct().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
    List<MODELRESULT> allApplicationModels = new ArrayList<>();
    for (int i = 0; i < majorVersions.size(); i++) {
        try {
            allApplicationModels.addAll(buildModelVersion(filterByMajorVersion(majorVersions.get(i), versions), applicationId, wantedNodeVespaVersion, applicationPackage, allocatedHosts, now));
            // skip old config models if requested after we have found a major version which works
            if (allApplicationModels.size() > 0 && allApplicationModels.get(0).getModel().skipOldConfigModels(now))
                break;
        } catch (OutOfCapacityException | ApplicationLockException e) {
            // caused by the state of the system, not the model version/application combination
            throw e;
        } catch (RuntimeException e) {
            boolean isOldestMajor = i == majorVersions.size() - 1;
            if (isOldestMajor) {
                if (e instanceof NullPointerException || e instanceof NoSuchElementException) {
                    log.log(LogLevel.WARNING, "Unexpected error when building model ", e);
                    throw new InternalServerException(applicationId + ": Error loading model", e);
                } else {
                    log.log(LogLevel.WARNING, "Input error when building model ", e);
                    throw new IllegalArgumentException(applicationId + ": Error loading model", e);
                }
            } else {
                log.log(Level.INFO, applicationId + ": Skipping major version " + majorVersions.get(i), e);
            }
        }
    }
    return allApplicationModels;
}
Also used : InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) ArrayList(java.util.ArrayList) OutOfCapacityException(com.yahoo.config.provision.OutOfCapacityException) ApplicationLockException(com.yahoo.config.provision.ApplicationLockException) Version(com.yahoo.config.provision.Version) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with InternalServerException

use of com.yahoo.vespa.config.server.http.InternalServerException in project vespa by vespa-engine.

the class LogServerLogGrabber method findLogserverConnectionInfo.

private LogServerInfo findLogserverConnectionInfo(Application application) {
    List<LogServerInfo> logServerConnectionInfos = new ArrayList<>();
    application.getModel().getHosts().forEach(host -> host.getServices().stream().filter(service -> service.getServiceType().equals("logserver")).forEach(logService -> {
        Optional<Integer> logPort = getErrorLogPort(logService);
        logPort.ifPresent(port -> logServerConnectionInfos.add(new LogServerInfo(host.getHostname(), port)));
    }));
    if (logServerConnectionInfos.size() > 1)
        throw new RuntimeException("Found several log server ports");
    if (logServerConnectionInfos.size() == 0)
        throw new InternalServerException("Did not find any log server in config model");
    return logServerConnectionInfos.get(0);
}
Also used : Exceptions(com.yahoo.yolean.Exceptions) Socket(java.net.Socket) PortInfo(com.yahoo.config.model.api.PortInfo) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) List(java.util.List) LogLevel(com.yahoo.log.LogLevel) AbstractComponent(com.yahoo.component.AbstractComponent) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) ServiceInfo(com.yahoo.config.model.api.ServiceInfo) Optional(java.util.Optional) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) ArrayList(java.util.ArrayList)

Example 4 with InternalServerException

use of com.yahoo.vespa.config.server.http.InternalServerException in project vespa by vespa-engine.

the class LogServerLogGrabber method grabLog.

public String grabLog(Application application) {
    LogServerInfo logServerConnectionInfo = findLogserverConnectionInfo(application);
    log.log(LogLevel.DEBUG, "Requested error logs, pulling from logserver on " + logServerConnectionInfo);
    try {
        return readLog(logServerConnectionInfo.hostName, logServerConnectionInfo.port);
    } catch (IOException e) {
        throw new InternalServerException(Exceptions.toMessageString(e));
    }
}
Also used : InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) IOException(java.io.IOException)

Example 5 with InternalServerException

use of com.yahoo.vespa.config.server.http.InternalServerException in project vespa by vespa-engine.

the class TenantHandler method handleDELETE.

@Override
protected HttpResponse handleDELETE(HttpRequest request) {
    final TenantName tenantName = getTenantNameFromRequest(request);
    Utils.checkThatTenantExists(tenants, tenantName);
    // TODO: Move logic to ApplicationRepository
    Tenant tenant = tenants.getTenant(tenantName);
    TenantApplications applicationRepo = tenant.getApplicationRepo();
    final List<ApplicationId> activeApplications = applicationRepo.listApplications();
    if (activeApplications.isEmpty()) {
        try {
            tenants.deleteTenant(tenantName);
        } catch (IllegalArgumentException e) {
            throw e;
        } catch (Exception e) {
            throw new InternalServerException(Exceptions.toMessageString(e));
        }
    } else {
        throw new BadRequestException("Cannot delete tenant '" + tenantName + "', as it has active applications: " + activeApplications);
    }
    return new TenantDeleteResponse(tenantName);
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantName(com.yahoo.config.provision.TenantName) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) BadRequestException(com.yahoo.vespa.config.server.http.BadRequestException) TenantApplications(com.yahoo.vespa.config.server.application.TenantApplications) ApplicationId(com.yahoo.config.provision.ApplicationId) BadRequestException(com.yahoo.vespa.config.server.http.BadRequestException) InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException)

Aggregations

InternalServerException (com.yahoo.vespa.config.server.http.InternalServerException)5 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AbstractComponent (com.yahoo.component.AbstractComponent)1 PortInfo (com.yahoo.config.model.api.PortInfo)1 ServiceInfo (com.yahoo.config.model.api.ServiceInfo)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1 ApplicationLockException (com.yahoo.config.provision.ApplicationLockException)1 OutOfCapacityException (com.yahoo.config.provision.OutOfCapacityException)1 TenantName (com.yahoo.config.provision.TenantName)1 Version (com.yahoo.config.provision.Version)1 LogLevel (com.yahoo.log.LogLevel)1 NestedTransaction (com.yahoo.transaction.NestedTransaction)1 ActivationConflictException (com.yahoo.vespa.config.server.ActivationConflictException)1 TimeoutBudget (com.yahoo.vespa.config.server.TimeoutBudget)1 TenantApplications (com.yahoo.vespa.config.server.application.TenantApplications)1 BadRequestException (com.yahoo.vespa.config.server.http.BadRequestException)1 ActivateLock (com.yahoo.vespa.config.server.tenant.ActivateLock)1 Tenant (com.yahoo.vespa.config.server.tenant.Tenant)1 Exceptions (com.yahoo.yolean.Exceptions)1