aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java
blob: 503dcdea6296aef7c77f3aff95ba893b6c7e6dd5 (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
package ai.vespa.hosted.plugin;

import ai.vespa.hosted.api.Deployment;
import ai.vespa.hosted.api.DeploymentLog;
import ai.vespa.hosted.api.DeploymentResult;
import com.yahoo.config.provision.zone.ZoneId;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.nio.file.Paths;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

/**
 * Deploys a Vespa application package to the hosted Vespa API.
 *
 * @author jonmv
 */
@Mojo(name = "deploy")
public class DeployMojo extends AbstractVespaMojo {

    @Parameter(property = "applicationZip")
    private String applicationZip;

    @Parameter(property = "vespaVersion")
    private String vespaVersion;

    @Parameter(property = "ignoreValidationErrors")
    private String ignoreValidationErrors;

    @Parameter(property = "environment")
    private String environment;

    @Parameter(property = "region")
    private String region;

    @Parameter(property = "repository")
    private String repository;

    @Parameter(property = "branch")
    private String branch;

    @Parameter(property = "commit")
    private String commit;

    @Parameter(property = "build")
    private Long build;

    @Parameter(property = "follow", defaultValue = "true")
    private boolean follow;

    @Override
    protected void doExecute() {
        Deployment deployment = build == null
                ? Deployment.ofPackage(Paths.get(firstNonBlank(applicationZip, projectPathOf("target", "application.zip"))))
                : Deployment.ofReference(repository, branch, commit, build);
        if ("true".equalsIgnoreCase(ignoreValidationErrors)) deployment = deployment.ignoringValidationErrors(); // TODO unused, GC or fix.
        if (vespaVersion != null) deployment = deployment.atVersion(vespaVersion);

        ZoneId zone = environment == null || region == null ? controller.devZone() : ZoneId.from(environment, region);

        DeploymentResult result = controller.deploy(deployment, id, zone);
        System.out.println(result.message());

        if (follow) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss").withZone(ZoneOffset.UTC);
            DeploymentLog log = controller.deploymentLog(id, zone, result.run());
            do {
                for (DeploymentLog.Entry entry : log.entries())
                    System.out.printf("[%10s%10s]   %s\n",
                                      entry.level().toUpperCase(),
                                      formatter.format(entry.at()),
                                      entry.message());
                log = controller.deploymentLog(id, zone, result.run(), log.last());
            }
            while (log.isActive());
        }
    }

}