Search in sources :

Example 1 with ApplicationLockException

use of com.yahoo.config.provision.ApplicationLockException 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 2 with ApplicationLockException

use of com.yahoo.config.provision.ApplicationLockException in project vespa by vespa-engine.

the class SessionPrepareHandlerTest method test_application_lock_failure.

@Test
public void test_application_lock_failure() throws InterruptedException, IOException {
    String message = "Timed out after waiting PT1M to acquire lock '/provision/v1/locks/foo/bar/default'";
    SessionThrowingException session = new SessionThrowingException(new ApplicationLockException(new UncheckedTimeoutException(message)));
    localRepo.addSession(session);
    HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L));
    assertEquals(500, response.getStatus());
    Slime data = getData(response);
    assertThat(data.get().field("error-code").asString(), is(HttpErrorResponse.errorCodes.APPLICATION_LOCK_FAILURE.name()));
    assertThat(data.get().field("message").asString(), is(message));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) Matchers.containsString(org.hamcrest.Matchers.containsString) Slime(com.yahoo.slime.Slime) ApplicationLockException(com.yahoo.config.provision.ApplicationLockException) Test(org.junit.Test)

Aggregations

ApplicationLockException (com.yahoo.config.provision.ApplicationLockException)2 UncheckedTimeoutException (com.google.common.util.concurrent.UncheckedTimeoutException)1 OutOfCapacityException (com.yahoo.config.provision.OutOfCapacityException)1 Version (com.yahoo.config.provision.Version)1 HttpResponse (com.yahoo.container.jdisc.HttpResponse)1 Slime (com.yahoo.slime.Slime)1 InternalServerException (com.yahoo.vespa.config.server.http.InternalServerException)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1