Search in sources :

Example 1 with UlimitConfig

use of io.fabric8.maven.docker.config.UlimitConfig in project docker-maven-plugin by fabric8io.

the class ContainerHostConfig method ulimits.

public ContainerHostConfig ulimits(List<UlimitConfig> ulimitsConfig) {
    if (ulimitsConfig != null && ulimitsConfig.size() > 0) {
        JSONArray ulimits = new JSONArray();
        for (UlimitConfig ulimit : ulimitsConfig) {
            JSONObject ulimitConfigJson = new JSONObject();
            ulimitConfigJson.put("Name", ulimit.getName());
            addIfNotNull(ulimitConfigJson, "Hard", ulimit.getHard());
            addIfNotNull(ulimitConfigJson, "Soft", ulimit.getSoft());
            ulimits.put(ulimitConfigJson);
        }
        startConfig.put("Ulimits", ulimits);
    }
    return this;
}
Also used : UlimitConfig(io.fabric8.maven.docker.config.UlimitConfig) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 2 with UlimitConfig

use of io.fabric8.maven.docker.config.UlimitConfig in project docker-maven-plugin by fabric8io.

the class ContainerHostConfigTest method testUlimits.

@Test
public void testUlimits() {
    Object[] data = { "{Ulimits: [{Name:bla, Hard:2048, Soft: 1024}]}", "bla", 2048, 1024, "{Ulimits: [{Name:bla, Soft: 1024}]}", "bla", null, 1024, "{Ulimits: [{Name:bla, Hard: 2048}]}", "bla", 2048, null, "{Ulimits: [{Name:bla, Hard: 2048}]}", "bla=2048", null, null, "{Ulimits: [{Name:bla, Soft: 1024}]}", "bla=:1024", null, null, "{Ulimits: [{Name:bla, Hard: 2048, Soft: 1024}]}", "bla=2048:1024", null, null, "{Ulimits: [{Name:bla, Hard: 2048}]}", "bla=2048:", null, null };
    for (int i = 0; i < data.length; i += 4) {
        ContainerHostConfig hc = new ContainerHostConfig();
        hc.ulimits(Collections.singletonList(data[1].toString().contains("=") ? new UlimitConfig((String) data[1]) : new UlimitConfig((String) data[1], (Integer) data[2], (Integer) data[3])));
        JSONAssert.assertEquals((JSONObject) JSONParser.parseJSON((String) data[0]), (JSONObject) hc.toJsonObject(), false);
    }
}
Also used : UlimitConfig(io.fabric8.maven.docker.config.UlimitConfig) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Aggregations

UlimitConfig (io.fabric8.maven.docker.config.UlimitConfig)2 JSONObject (org.json.JSONObject)2 JSONArray (org.json.JSONArray)1 Test (org.junit.Test)1