aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java
blob: 301ae63fb8cf299c31fc6cf36ce432bdc8fc6e24 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 2017 Yahoo Holdings. 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.google.common.io.Files;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.config.model.api.ModelFactory;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Version;
import com.yahoo.test.ManualClock;
import org.junit.Ignore;
import org.junit.Test;

import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
 * @author bratseth
 */
public class HostedDeployTest {

    private static final String dockerRegistry = "foo.com:4443";
    private static final String dockerVespaBaseImage = "/vespa/ci";

    @Test
    public void testRedeployWithVersion() throws InterruptedException, IOException {
        DeployTester tester = new DeployTester("src/test/apps/hosted/", createConfigserverConfig());
        tester.deployApp("myApp", "4.5.6", Instant.now());

        Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive();
        assertTrue(deployment.isPresent());
        deployment.get().prepare();
        deployment.get().activate();
        assertEquals("4.5.6", ((Deployment)deployment.get()).session().getVespaVersion().toString());
    }

    @Test
    public void testRedeploy() throws InterruptedException, IOException {
        DeployTester tester = new DeployTester("src/test/apps/hosted/", createConfigserverConfig());
        tester.deployApp("myApp", Instant.now());

        Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive();
        assertTrue(deployment.isPresent());
        deployment.get().prepare();
        deployment.get().activate();
    }

    @Test
    public void testDeployMultipleVersions() throws InterruptedException, IOException {
        ManualClock clock = new ManualClock("2016-10-09T00:00:00");
        List<ModelFactory> modelFactories = new ArrayList<>();
        modelFactories.add(DeployTester.createModelFactory(Version.fromString("6.1.0"), clock));
        modelFactories.add(DeployTester.createModelFactory(Version.fromString("6.2.0"), clock));
        modelFactories.add(DeployTester.createModelFactory(Version.fromString("7.0.0"), clock));
        DeployTester tester = new DeployTester("src/test/apps/hosted/", modelFactories, createConfigserverConfig());
        ApplicationId app = tester.deployApp("myApp", Instant.now());
        assertEquals(3, tester.getAllocatedHostsOf(app).getHosts().size());
    }

    @Test
    public void testRedeployAfterExpiredValidationOverride() throws InterruptedException, IOException {
        // Old version of model fails, but application disables loading old models until 2016-10-10, so deployment works
        ManualClock clock = new ManualClock("2016-10-09T00:00:00");
        List<ModelFactory> modelFactories = new ArrayList<>();
        modelFactories.add(DeployTester.createModelFactory(clock));
        modelFactories.add(DeployTester.createFailingModelFactory(Version.fromIntValues(1, 0, 0))); // older than default
        DeployTester tester = new DeployTester("src/test/apps/validationOverride/", modelFactories, createConfigserverConfig());
        tester.deployApp("myApp", clock.instant());

        // Redeployment from local active works
        {
            Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive();
            assertTrue(deployment.isPresent());
            deployment.get().prepare();
            deployment.get().activate();
        }

        clock.advance(Duration.ofDays(2)); // validation override expires

        // Redeployment from local active also works after the validation override expires
        {
            Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive();
            assertTrue(deployment.isPresent());
            deployment.get().prepare();
            deployment.get().activate();
        }

        // However, redeployment from the outside fails after this date
        {
            try {
                tester.deployApp("myApp", Instant.now());
                fail("Expected redeployment to fail");
            }
            catch (Exception expected) {
                // success
            }
        }
    }

    @Test
    @Ignore //WIP
    public void testDeployWithDockerImage() throws InterruptedException, IOException {
        final String vespaVersion = "6.51.1";
        DeployTester tester = new DeployTester("src/test/apps/hosted/", createConfigserverConfig());
        ApplicationId applicationId = tester.deployApp("myApp", vespaVersion, Instant.now());
        assertAllocatedHosts(vespaVersion, tester, applicationId);

        System.out.println("Redeploy");
        Optional<com.yahoo.config.provision.Deployment> deployment = tester.redeployFromLocalActive();
        assertTrue(deployment.isPresent());
        deployment.get().prepare();
        deployment.get().activate();
        //assertAllocatedHosts(vespaVersion, tester, applicationId);
    }

    private void assertAllocatedHosts(String vespaVersion, DeployTester tester, ApplicationId applicationId) {
        tester.getAllocatedHostsOf(applicationId).getHosts().stream()
              .forEach(h -> assertEquals(vespaVersion, h.membership().get().cluster().vespaVersion()));
    }

    private static ConfigserverConfig createConfigserverConfig() {
        return new ConfigserverConfig(new ConfigserverConfig.Builder()
                                              .configServerDBDir(Files.createTempDir()
                                                                      .getAbsolutePath())
                                              .dockerRegistry(dockerRegistry)
                                              .dockerVespaBaseImage(dockerVespaBaseImage)
                                              .hostedVespa(true)
                                              .multitenant(true));
    }

}