summaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/http/SessionContentStatusListResponse.java
blob: caf38517b6ad6a5dc8878dd4ad09a5ac79599e66 (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.http;

import com.yahoo.config.application.api.ApplicationFile;
import com.yahoo.log.LogLevel;
import com.yahoo.slime.Cursor;
import com.yahoo.slime.JsonFormat;
import com.yahoo.slime.Slime;

import java.io.IOException;
import java.io.OutputStream;
import java.util.*;

/**
 * Status and md5sum for files within an application package.
 *
 * @author musum
 * @since 5.1.15
 */
class SessionContentStatusListResponse extends SessionResponse {
    private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger("SessionContentStatusListResponse");

    private final Slime slime = new Slime();

    public SessionContentStatusListResponse(String urlBase, List<ApplicationFile> files) {
        super();
        Cursor array = slime.setArray();
        for (ApplicationFile f : files) {
            Cursor element = array.addObject();
            element.setString("status", f.getMetaData().getStatus());
            element.setString("md5", f.getMetaData().getMd5());
            element.setString("name", urlBase + f.getPath());
            log.log(LogLevel.DEBUG, "Adding file " + urlBase + f.getPath());
        }
    }

    @Override
    public void render(OutputStream outputStream) throws IOException {
        new JsonFormat(true).encode(outputStream, slime);
    }
}