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;
}
Aggregations