Search in sources :

Example 6 with TaskSpec

use of com.spotify.docker.client.messages.swarm.TaskSpec in project pravega by pravega.

the class PravegaSegmentStoreDockerService method setServiceSpec.

private ServiceSpec setServiceSpec() {
    Map<String, String> labels = new HashMap<>();
    labels.put("com.docker.swarm.task.name", serviceName);
    Mount mount = Mount.builder().type("volume").source("logs-volume").target("/tmp/logs").build();
    String zk = zkUri.getHost() + ":" + ZKSERVICE_ZKPORT;
    // System properties to configure SS service.
    Map<String, String> stringBuilderMap = new HashMap<>();
    StringBuilder systemPropertyBuilder = new StringBuilder();
    stringBuilderMap.put("autoScale.muteInSeconds", "120");
    stringBuilderMap.put("autoScale.cooldownInSeconds", "120");
    stringBuilderMap.put("autoScale.cacheExpiryInSeconds", "120");
    stringBuilderMap.put("autoScale.cacheCleanUpInSeconds", "120");
    stringBuilderMap.put("log.level", "DEBUG");
    stringBuilderMap.put("curator-default-session-timeout", String.valueOf(30 * 1000));
    stringBuilderMap.put("hdfs.replaceDataNodesOnFailure", "false");
    for (Map.Entry<String, String> entry : stringBuilderMap.entrySet()) {
        systemPropertyBuilder.append("-D").append(entry.getKey()).append("=").append(entry.getValue()).append(" ");
    }
    String hostSystemProperties = systemPropertyBuilder.toString();
    // set env
    String env1 = "PRAVEGA_SEGMENTSTORE_OPTS=" + hostSystemProperties;
    String env2 = "JAVA_OPTS=-Xmx900m";
    List<String> envList = new ArrayList<>();
    envList.add(env1);
    envList.add(env2);
    getCustomEnvVars(envList, SEGMENTSTORE_EXTRA_ENV, hdfsUri);
    String env3 = "ZK_URL=" + zk;
    String env4 = "BK_ZK_URL=" + zk;
    String env5 = "CONTROLLER_URL=" + conUri.toString();
    envList.add(env3);
    envList.add(env4);
    envList.add(env5);
    final TaskSpec taskSpec = TaskSpec.builder().networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).build()).containerSpec(ContainerSpec.builder().image(IMAGE_PATH + "nautilus/pravega:" + PRAVEGA_VERSION).hostname(serviceName).labels(labels).healthcheck(ContainerConfig.Healthcheck.create(null, Duration.ofSeconds(10).toNanos(), Duration.ofSeconds(10).toNanos(), 3)).mounts(Arrays.asList(mount)).env(envList).args("segmentstore").build()).resources(ResourceRequirements.builder().reservations(Resources.builder().memoryBytes(setMemInBytes(mem)).nanoCpus(setNanoCpus(cpu)).build()).build()).build();
    ServiceSpec spec = ServiceSpec.builder().name(serviceName).taskTemplate(taskSpec).mode(ServiceMode.withReplicas(instances)).endpointSpec(EndpointSpec.builder().ports(PortConfig.builder().publishedPort(SEGMENTSTORE_PORT).targetPort(SEGMENTSTORE_PORT).publishMode(PortConfig.PortConfigPublishMode.HOST).build()).build()).build();
    return spec;
}
Also used : HashMap(java.util.HashMap) TaskSpec(com.spotify.docker.client.messages.swarm.TaskSpec) Mount(com.spotify.docker.client.messages.mount.Mount) ArrayList(java.util.ArrayList) ServiceSpec(com.spotify.docker.client.messages.swarm.ServiceSpec) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TaskSpec (com.spotify.docker.client.messages.swarm.TaskSpec)6 ServiceSpec (com.spotify.docker.client.messages.swarm.ServiceSpec)5 HashMap (java.util.HashMap)5 Mount (com.spotify.docker.client.messages.mount.Mount)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)2 DockerException (com.spotify.docker.client.exceptions.DockerException)1 EndpointSpec (com.spotify.docker.client.messages.swarm.EndpointSpec)1 PortConfig (com.spotify.docker.client.messages.swarm.PortConfig)1 Service (com.spotify.docker.client.messages.swarm.Service)1 TestFrameworkException (io.pravega.test.system.framework.TestFrameworkException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1