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());
}
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;
}
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);
}
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));
}
}
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);
}
Aggregations