aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/TenantFileSystemDirs.java
blob: c9fe59ad6a3c6dc54c500935b37114bba396801d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.deploy;

import com.yahoo.config.provision.TenantName;
import com.yahoo.io.IOUtils;
import com.yahoo.path.Path;
import com.yahoo.vespa.config.server.ConfigServerDB;

import java.io.File;

/*
 * Holds file system directories for a tenant
 *
 * @author Tony Vaagenes
 */
public class TenantFileSystemDirs {

    private final File serverDB;
    private final TenantName tenant;

    public TenantFileSystemDirs(ConfigServerDB configServerDB, TenantName tenant) {
        this(configServerDB.path(), tenant);
    }

    // For testing
    public TenantFileSystemDirs(File dir, TenantName tenant) {
        this.serverDB = dir;
        this.tenant = tenant;
        ConfigServerDB.createDirectory(sessionsPath());
    }

    public File sessionsPath() {
        return new File(serverDB, Path.fromString("tenants").append(tenant.value()).append("sessions").getRelative());
    }

    public File getUserApplicationDir(long generation) {
        return new File(sessionsPath(), String.valueOf(generation));
    }

    public void delete() {
        IOUtils.recursiveDeleteDir(new File(serverDB, Path.fromString("tenants").append(tenant.value()).getRelative()));
    }
}