summaryrefslogtreecommitdiffstats
path: root/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/ControllerDb.java
blob: fb6608ea6439c34299630b33c25a67376bf056b3 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.persistence;

import com.google.common.base.Joiner;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.vespa.hosted.controller.Application;
import com.yahoo.vespa.hosted.controller.api.Tenant;
import com.yahoo.vespa.hosted.controller.api.identifiers.Identifier;
import com.yahoo.vespa.hosted.controller.api.identifiers.TenantId;

import java.util.List;
import java.util.Optional;

/**
 * Used to store the permanent data of the controller.
 * 
 * @author Stian Kristoffersen
 * @author bratseth
 */
public interface ControllerDb {

    // --------- Tenants

    void createTenant(Tenant tenant);

    // TODO: Remove exception from all signatures
    void updateTenant(Tenant tenant) throws PersistenceException;

    void deleteTenant(TenantId tenantId) throws PersistenceException;

    Optional<Tenant> getTenant(TenantId tenantId) throws PersistenceException;

    List<Tenant> listTenants();

    // --------- Applications

    // ONLY call this from ApplicationController.store()
    void store(Application application);

    void deleteApplication(ApplicationId applicationId);

    Optional<Application> getApplication(ApplicationId applicationId);

    /** Returns all applications */
    List<Application> listApplications();

    /** Returns all applications of a tenant */
    List<Application> listApplications(TenantId tenantId);

    /** Returns the given elements joined by dot "." */
    default String path(Identifier... elements) {
        return Joiner.on(".").join(elements);
    }

    default String path(String... elements) {
        return Joiner.on(".").join(elements);
    }
    
    default String path(ApplicationId applicationId) {
        return applicationId.tenant().value() + "." + applicationId.application().value() + "." + applicationId.instance().value();
    }

}