aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/test/SimpleService.java
blob: 850c05545ee47779d82220e0c76c113466203deb (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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.test;

import com.yahoo.test.StandardConfig.Builder;
import com.yahoo.config.model.producer.TreeConfigProducer;
import com.yahoo.vespa.model.AbstractService;
import com.yahoo.vespa.model.PortAllocBridge;

import java.util.HashMap;
import java.util.Optional;

/**
 * This service has a desired default port and returns the actual
 * baseport from getConfig().
 *
 * @author  gjoranv
 */
public class SimpleService extends AbstractService implements com.yahoo.test.StandardConfig.Producer {

    /**
     * Creates a new SimpleService instance
     *
     * @param parent     The parent ConfigProducer.
     * @param name       Service name
     */
    public SimpleService(TreeConfigProducer parent, String name) {
        super(parent, name);
        portsMeta.on(0).tag("base")
            .on(1).tag("base")
            .on(2).tag("base")
            .on(3).tag("base")
            .on(4).tag("base");
    }

    @Override
    public void getConfig(Builder builder) {
        builder.astring("simpleservice").baseport(getRelativePort(0));
    }
    
    public int getWantedPort(){ return 10000; }
    public int getPortCount() { return 5; }

    @Override
    public void allocatePorts(int start, PortAllocBridge from) {
        if (start == 0) start = getWantedPort();
        from.wantPort(start++, "a");
        from.wantPort(start++, "b");
        from.wantPort(start++, "c");
        from.wantPort(start++, "d");
        from.wantPort(start++, "e");
    }

    // Make sure this service is listed in the sentinel config
    public Optional<String> getStartupCommand()   { return Optional.of("sleep 0"); }

    @Override
       public HashMap<String,String> getDefaultMetricDimensions(){
        HashMap<String, String> dimensions = new HashMap<>();
        dimensions.put("clustername", "testClusterName");
        return dimensions;
    }

}