Search in sources :

Example 6 with Version

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

the class VersionStateTest method serverdbfile.

@Test
public void serverdbfile() throws IOException {
    File dbDir = tempDir.newFolder();
    VersionState state = new VersionState(new ConfigserverConfig(new ConfigserverConfig.Builder().configServerDBDir(dbDir.getAbsolutePath())));
    state.saveNewVersion();
    File versionFile = new File(dbDir, "vespa_version");
    assertTrue(versionFile.exists());
    Version stored = Version.fromString(IOUtils.readFile(versionFile));
    assertThat(stored, is(state.currentVersion()));
}
Also used : ConfigserverConfig(com.yahoo.cloud.config.ConfigserverConfig) Version(com.yahoo.config.provision.Version) File(java.io.File) Test(org.junit.Test)

Example 7 with Version

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

the class ZKApplicationPackageTest method testBasicZKFeed.

@Test
public void testBasicZKFeed() throws IOException {
    feed(configCurator, new File(APP));
    ZKApplicationPackage zkApp = new ZKApplicationPackage(configCurator, Path.fromString("/0"), Optional.of(new MockNodeFlavors()));
    assertTrue(Pattern.compile(".*<slobroks>.*", Pattern.MULTILINE + Pattern.DOTALL).matcher(IOUtils.readAll(zkApp.getServices())).matches());
    assertTrue(Pattern.compile(".*<alias>.*", Pattern.MULTILINE + Pattern.DOTALL).matcher(IOUtils.readAll(zkApp.getHosts())).matches());
    assertTrue(Pattern.compile(".*<slobroks>.*", Pattern.MULTILINE + Pattern.DOTALL).matcher(IOUtils.readAll(zkApp.getFile(Path.fromString("services.xml")).createReader())).matches());
    DeployState deployState = new DeployState.Builder().applicationPackage(zkApp).build(true);
    assertEquals(deployState.getSearchDefinitions().size(), 5);
    assertEquals(zkApp.searchDefinitionContents().size(), 5);
    assertEquals(IOUtils.readAll(zkApp.getRankingExpression("foo.expression")), "foo()+1\n");
    assertEquals(zkApp.getFiles(Path.fromString(""), "xml").size(), 3);
    assertEquals(zkApp.getFileReference(Path.fromString("components/file.txt")).getAbsolutePath(), "/home/vespa/test/file.txt");
    try (Reader foo = zkApp.getFile(Path.fromString("files/foo.json")).createReader()) {
        assertEquals(IOUtils.readAll(foo), "foo : foo\n");
    }
    try (Reader bar = zkApp.getFile(Path.fromString("files/sub/bar.json")).createReader()) {
        assertEquals(IOUtils.readAll(bar), "bar : bar\n");
    }
    assertTrue(zkApp.getFile(Path.createRoot()).exists());
    assertTrue(zkApp.getFile(Path.createRoot()).isDirectory());
    Version goodVersion = Version.fromIntValues(3, 0, 0);
    assertTrue(zkApp.getFileRegistryMap().containsKey(goodVersion));
    assertFalse(zkApp.getFileRegistryMap().containsKey(Version.fromIntValues(0, 0, 0)));
    assertThat(zkApp.getFileRegistryMap().get(goodVersion).fileSourceHost(), is("dummyfiles"));
    AllocatedHosts readInfo = zkApp.getAllocatedHosts().get();
    assertThat(Utf8.toString(readInfo.toJson()), is(Utf8.toString(ALLOCATED_HOSTS.toJson())));
    assertThat(readInfo.getHosts().iterator().next().flavor(), is(TEST_FLAVOR));
    assertTrue(zkApp.getDeployment().isPresent());
    assertThat(DeploymentSpec.fromXml(zkApp.getDeployment().get()).globalServiceId().get(), is("mydisc"));
}
Also used : AllocatedHosts(com.yahoo.config.provision.AllocatedHosts) DeployState(com.yahoo.config.model.deploy.DeployState) Version(com.yahoo.config.provision.Version) Reader(java.io.Reader) File(java.io.File) Test(org.junit.Test)

Example 8 with Version

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

the class GetConfigProcessor method run.

// TODO: Increment statistics (Metrics) failed counters when requests fail
public void run() {
    // Request has already been detached
    if (!request.validateParameters()) {
        // Error code is set in verifyParameters if parameters are not OK.
        log.log(LogLevel.WARNING, "Parameters for request " + request + " did not validate: " + request.errorCode() + " : " + request.errorMessage());
        respond(request);
        return;
    }
    Trace trace = request.getRequestTrace();
    if (logDebug(trace)) {
        debugLog(trace, "GetConfigProcessor.run() on " + localHostName);
    }
    Optional<TenantName> tenant = rpcServer.resolveTenant(request, trace);
    // fabricate an empty request to cause the sentinel to stop all running services
    if (rpcServer.isHostedVespa() && rpcServer.allTenantsLoaded() && !tenant.isPresent() && isSentinelConfigRequest(request)) {
        returnEmpty(request);
        return;
    }
    GetConfigContext context = rpcServer.createGetConfigContext(tenant, request, trace);
    if (context == null || !context.requestHandler().hasApplication(context.applicationId(), Optional.<Version>empty())) {
        handleError(request, ErrorCode.APPLICATION_NOT_LOADED, "No application exists");
        return;
    }
    Optional<Version> vespaVersion = rpcServer.useRequestVersion() ? request.getVespaVersion().map(VespaVersion::toString).map(Version::fromString) : Optional.empty();
    if (logDebug(trace)) {
        debugLog(trace, "Using version " + getPrintableVespaVersion(vespaVersion));
    }
    if (!context.requestHandler().hasApplication(context.applicationId(), vespaVersion)) {
        handleError(request, ErrorCode.UNKNOWN_VESPA_VERSION, "Unknown Vespa version in request: " + getPrintableVespaVersion(vespaVersion));
        return;
    }
    this.logPre = Tenants.logPre(context.applicationId());
    ConfigResponse config;
    try {
        config = rpcServer.resolveConfig(request, context, vespaVersion);
    } catch (UnknownConfigDefinitionException e) {
        handleError(request, ErrorCode.UNKNOWN_DEFINITION, "Unknown config definition " + request.getConfigKey());
        return;
    } catch (UnknownConfigIdException e) {
        handleError(request, ErrorCode.ILLEGAL_CONFIGID, "Illegal config id " + request.getConfigKey().getConfigId());
        return;
    } catch (Throwable e) {
        log.log(Level.SEVERE, "Unexpected error handling config request", e);
        handleError(request, ErrorCode.INTERNAL_ERROR, "Internal error " + e.getMessage());
        return;
    }
    // config == null is not an error, but indicates that the config will be returned later.
    if ((config != null) && (!config.hasEqualConfig(request) || config.hasNewerGeneration(request) || forceResponse)) {
        // debugLog(trace, "config response before encoding:" + config.toString());
        request.addOkResponse(request.payloadFromResponse(config), config.getGeneration(), config.getConfigMd5());
        if (logDebug(trace)) {
            debugLog(trace, "return response: " + request.getShortDescription());
        }
        respond(request);
    } else {
        if (logDebug(trace)) {
            debugLog(trace, "delaying response " + request.getShortDescription());
        }
        rpcServer.delayResponse(request, context);
    }
}
Also used : UnknownConfigIdException(com.yahoo.vespa.config.UnknownConfigIdException) Version(com.yahoo.config.provision.Version) TenantName(com.yahoo.config.provision.TenantName) UnknownConfigDefinitionException(com.yahoo.vespa.config.server.UnknownConfigDefinitionException) GetConfigContext(com.yahoo.vespa.config.server.GetConfigContext)

Example 9 with Version

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

the class SuperModelControllerTest method test_lb_config_multiple_apps.

@Test
public void test_lb_config_multiple_apps() throws IOException, SAXException {
    Map<TenantName, Map<ApplicationId, ApplicationInfo>> models = new LinkedHashMap<>();
    models.put(TenantName.from("t1"), new LinkedHashMap<>());
    models.put(TenantName.from("t2"), new LinkedHashMap<>());
    File testApp1 = new File("src/test/resources/deploy/app");
    File testApp2 = new File("src/test/resources/deploy/advancedapp");
    File testApp3 = new File("src/test/resources/deploy/advancedapp");
    // TODO must fix equals, hashCode on Tenant
    Version vespaVersion = Version.fromIntValues(1, 2, 3);
    models.get(TenantName.from("t1")).put(applicationId("mysimpleapp"), new ApplicationInfo(applicationId("mysimpleapp"), 4l, new VespaModel(FilesApplicationPackage.fromFile(testApp1))));
    models.get(TenantName.from("t1")).put(applicationId("myadvancedapp"), new ApplicationInfo(applicationId("myadvancedapp"), 4l, new VespaModel(FilesApplicationPackage.fromFile(testApp2))));
    models.get(TenantName.from("t2")).put(applicationId("minetooadvancedapp"), new ApplicationInfo(applicationId("minetooadvancedapp"), 4l, new VespaModel(FilesApplicationPackage.fromFile(testApp3))));
    SuperModel superModel = new SuperModel(models);
    SuperModelController han = new SuperModelController(new SuperModelConfigProvider(superModel, Zone.defaultZone()), new TestConfigDefinitionRepo(), 2, new UncompressedConfigResponseFactory());
    LbServicesConfig.Builder lb = new LbServicesConfig.Builder();
    han.getSuperModel().getConfig(lb);
    LbServicesConfig lbc = new LbServicesConfig(lb);
    assertThat(lbc.tenants().size(), is(2));
    assertThat(lbc.tenants("t1").applications().size(), is(2));
    assertThat(lbc.tenants("t2").applications().size(), is(1));
    assertThat(lbc.tenants("t2").applications("minetooadvancedapp:prod:default:default").hosts().size(), is(1));
    assertQrServer(lbc.tenants("t2").applications("minetooadvancedapp:prod:default:default"));
}
Also used : TenantName(com.yahoo.config.provision.TenantName) SuperModel(com.yahoo.config.model.api.SuperModel) SuperModelConfigProvider(com.yahoo.vespa.config.server.model.SuperModelConfigProvider) ApplicationInfo(com.yahoo.config.model.api.ApplicationInfo) LinkedHashMap(java.util.LinkedHashMap) Version(com.yahoo.config.provision.Version) VespaModel(com.yahoo.vespa.model.VespaModel) UncompressedConfigResponseFactory(com.yahoo.vespa.config.server.rpc.UncompressedConfigResponseFactory) LbServicesConfig(com.yahoo.cloud.config.LbServicesConfig) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File) Test(org.junit.Test)

Example 10 with Version

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

the class PreparedModelsBuilder method buildModelVersion.

@Override
protected PreparedModelResult buildModelVersion(ModelFactory modelFactory, ApplicationPackage applicationPackage, ApplicationId applicationId, com.yahoo.component.Version wantedNodeVespaVersion, Optional<AllocatedHosts> allocatedHosts, Instant now) {
    Version modelVersion = modelFactory.getVersion();
    log.log(LogLevel.DEBUG, "Building model " + modelVersion + " for " + applicationId);
    FileDistributionProvider fileDistributionProvider = fileDistributionFactory.createProvider(context.getServerDBSessionDir());
    // Use empty on non-hosted systems, use already allocated hosts if available, create connection to a host provisioner otherwise
    Optional<HostProvisioner> hostProvisioner = createHostProvisioner(allocatedHosts);
    Optional<Model> previousModel = currentActiveApplicationSet.map(set -> set.getForVersionOrLatest(Optional.of(modelVersion), now).getModel());
    ModelContext modelContext = new ModelContextImpl(applicationPackage, previousModel, permanentApplicationPackage.applicationPackage(), logger, configDefinitionRepo, fileDistributionProvider.getFileRegistry(), hostProvisioner, properties, getAppDir(applicationPackage), new com.yahoo.component.Version(modelVersion.toString()), wantedNodeVespaVersion);
    log.log(LogLevel.DEBUG, "Create and validate model " + modelVersion + " for " + applicationId);
    ModelCreateResult result = modelFactory.createAndValidateModel(modelContext, params.ignoreValidationErrors());
    validateModelHosts(context.getHostValidator(), applicationId, result.getModel());
    log.log(LogLevel.DEBUG, "Done building model " + modelVersion + " for " + applicationId);
    return new PreparedModelsBuilder.PreparedModelResult(modelVersion, result.getModel(), fileDistributionProvider, result.getConfigChangeActions());
}
Also used : ModelCreateResult(com.yahoo.config.model.api.ModelCreateResult) ModelContextImpl(com.yahoo.vespa.config.server.deploy.ModelContextImpl) ModelContext(com.yahoo.config.model.api.ModelContext) Version(com.yahoo.config.provision.Version) Model(com.yahoo.config.model.api.Model) FileDistributionProvider(com.yahoo.vespa.config.server.filedistribution.FileDistributionProvider) HostProvisioner(com.yahoo.config.model.api.HostProvisioner)

Aggregations

Version (com.yahoo.config.provision.Version)11 Test (org.junit.Test)7 File (java.io.File)5 ModelContext (com.yahoo.config.model.api.ModelContext)2 ApplicationId (com.yahoo.config.provision.ApplicationId)2 TenantName (com.yahoo.config.provision.TenantName)2 ModelFactoryRegistry (com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry)2 ArrayList (java.util.ArrayList)2 ConfigserverConfig (com.yahoo.cloud.config.ConfigserverConfig)1 LbServicesConfig (com.yahoo.cloud.config.LbServicesConfig)1 ApplicationInfo (com.yahoo.config.model.api.ApplicationInfo)1 HostProvisioner (com.yahoo.config.model.api.HostProvisioner)1 Model (com.yahoo.config.model.api.Model)1 ModelCreateResult (com.yahoo.config.model.api.ModelCreateResult)1 ModelFactory (com.yahoo.config.model.api.ModelFactory)1 SuperModel (com.yahoo.config.model.api.SuperModel)1 DeployState (com.yahoo.config.model.deploy.DeployState)1 AllocatedHosts (com.yahoo.config.provision.AllocatedHosts)1 ApplicationLockException (com.yahoo.config.provision.ApplicationLockException)1 OutOfCapacityException (com.yahoo.config.provision.OutOfCapacityException)1