use of com.spotify.docker.client.messages.swarm.ServiceSpec in project pravega by pravega.
the class BookkeeperDockerService method setServiceSpec.
private ServiceSpec setServiceSpec() {
Map<String, String> labels = new HashMap<>();
labels.put("com.docker.swarm.service.name", serviceName);
Mount mount1 = Mount.builder().type("volume").source("index-volume").target("/bk/index").build();
Mount mount2 = Mount.builder().type("volume").source("logs-volume").target("/opt/dl_all/distributedlog-service/logs/").build();
String zk = zkUri.getHost() + ":" + ZKSERVICE_ZKPORT;
List<String> stringList = new ArrayList<>();
String env1 = "ZK_URL=" + zk;
String env2 = "ZK=" + zk;
String env3 = "bookiePort=" + String.valueOf(BK_PORT);
String env4 = "DLOG_EXTRA_OPTS=-Xms512m";
stringList.add(env1);
stringList.add(env2);
stringList.add(env3);
stringList.add(env4);
final TaskSpec taskSpec = TaskSpec.builder().restartPolicy(RestartPolicy.builder().maxAttempts(0).condition("none").build()).containerSpec(ContainerSpec.builder().hostname(serviceName).labels(labels).image(IMAGE_PATH + "nautilus/bookkeeper:" + PRAVEGA_VERSION).healthcheck(ContainerConfig.Healthcheck.create(null, Duration.ofSeconds(10).toNanos(), Duration.ofSeconds(10).toNanos(), 3)).mounts(Arrays.asList(mount1, mount2)).env(stringList).build()).networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build()).resources(ResourceRequirements.builder().reservations(Resources.builder().memoryBytes(setMemInBytes(mem)).nanoCpus(setNanoCpus(cpu)).build()).build()).build();
ServiceSpec spec = ServiceSpec.builder().name(serviceName).mode(ServiceMode.withReplicas(instances)).networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build()).endpointSpec(EndpointSpec.builder().ports(PortConfig.builder().publishedPort(BK_PORT).build()).build()).taskTemplate(taskSpec).build();
return spec;
}
use of com.spotify.docker.client.messages.swarm.ServiceSpec in project pravega by pravega.
the class ZookeeperDockerService method setServiceSpec.
private ServiceSpec setServiceSpec() {
Map<String, String> labels = new HashMap<>();
labels.put("com.docker.swarm.service.name", serviceName);
final TaskSpec taskSpec = TaskSpec.builder().containerSpec(ContainerSpec.builder().image(ZK_IMAGE).hostname(serviceName).labels(labels).healthcheck(ContainerConfig.Healthcheck.create(null, Duration.ofSeconds(10).toNanos(), Duration.ofSeconds(10).toNanos(), 3)).build()).networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build()).resources(ResourceRequirements.builder().limits(Resources.builder().memoryBytes(mem).nanoCpus((long) cpu).build()).build()).build();
ServiceSpec spec = ServiceSpec.builder().name(serviceName).mode(ServiceMode.withReplicas(instances)).networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build()).endpointSpec(EndpointSpec.builder().ports(PortConfig.builder().publishedPort(ZKSERVICE_ZKPORT).targetPort(ZKSERVICE_ZKPORT).publishMode(PortConfig.PortConfigPublishMode.HOST).build()).build()).taskTemplate(taskSpec).build();
return spec;
}
use of com.spotify.docker.client.messages.swarm.ServiceSpec in project pravega by pravega.
the class HDFSDockerService 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("hadoop-logs-volume").target("/opt/hadoop/logs").build();
String env1 = "SSH_PORT=2222";
String env2 = "HDFS_HOST=" + serviceName;
final TaskSpec taskSpec = TaskSpec.builder().networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build()).containerSpec(ContainerSpec.builder().image(hdfsimage).env(Arrays.asList(env1, env2)).healthcheck(ContainerConfig.Healthcheck.create(null, Duration.ofSeconds(10).toNanos(), Duration.ofSeconds(10).toNanos(), 3)).mounts(mount).labels(labels).hostname(serviceName).build()).resources(ResourceRequirements.builder().reservations(Resources.builder().memoryBytes(setMemInBytes(mem)).nanoCpus(setNanoCpus(cpu)).build()).build()).build();
List<PortConfig> portConfigs = new ArrayList<>();
PortConfig port1 = PortConfig.builder().publishedPort(8020).targetPort(8020).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs").build();
PortConfig port2 = PortConfig.builder().publishedPort(50090).targetPort(50090).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-secondary").build();
PortConfig port3 = PortConfig.builder().publishedPort(50010).targetPort(50010).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-datanode").build();
PortConfig port4 = PortConfig.builder().publishedPort(50020).targetPort(50020).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-datanode-ipc").build();
PortConfig port5 = PortConfig.builder().publishedPort(50075).targetPort(50075).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-datanode-http").build();
PortConfig port6 = PortConfig.builder().publishedPort(50070).targetPort(50070).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-web").build();
PortConfig port7 = PortConfig.builder().publishedPort(2222).targetPort(2222).publishMode(PortConfig.PortConfigPublishMode.HOST).name("hdfs-ssh").build();
portConfigs.add(port1);
portConfigs.add(port2);
portConfigs.add(port3);
portConfigs.add(port4);
portConfigs.add(port5);
portConfigs.add(port6);
portConfigs.add(port7);
ServiceSpec spec = ServiceSpec.builder().name(serviceName).taskTemplate(taskSpec).mode(ServiceMode.withReplicas(instances)).networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build()).endpointSpec(EndpointSpec.builder().ports(portConfigs).build()).build();
return spec;
}
use of com.spotify.docker.client.messages.swarm.ServiceSpec in project pravega by pravega.
the class PravegaControllerDockerService method setServiceSpec.
private ServiceSpec setServiceSpec() {
Mount mount = Mount.builder().type("Volume").source("volume-logs").target("/tmp/logs").build();
String zk = zkUri.getHost() + ":" + ZKSERVICE_ZKPORT;
Map<String, String> stringBuilderMap = new HashMap<>();
stringBuilderMap.put("ZK_URL", zk);
stringBuilderMap.put("CONTROLLER_RPC_PUBLISHED_HOST", serviceName);
stringBuilderMap.put("CONTROLLER_RPC_PUBLISHED_PORT", String.valueOf(DOCKER_CONTROLLER_PORT));
stringBuilderMap.put("CONTROLLER_SERVER_PORT", String.valueOf(DOCKER_CONTROLLER_PORT));
stringBuilderMap.put("REST_SERVER_PORT", String.valueOf(REST_PORT));
stringBuilderMap.put("log.level", "DEBUG");
stringBuilderMap.put("curator-default-session-timeout", String.valueOf(10 * 1000));
stringBuilderMap.put("ZK_SESSION_TIMEOUT_MS", String.valueOf(30 * 1000));
stringBuilderMap.put("MAX_LEASE_VALUE", String.valueOf(60 * 1000));
stringBuilderMap.put("MAX_SCALE_GRACE_PERIOD", String.valueOf(60 * 1000));
stringBuilderMap.put("RETENTION_FREQUENCY_MINUTES", String.valueOf(2));
StringBuilder systemPropertyBuilder = new StringBuilder();
for (Map.Entry<String, String> entry : stringBuilderMap.entrySet()) {
systemPropertyBuilder.append("-D").append(entry.getKey()).append("=").append(entry.getValue()).append(" ");
}
String controllerSystemProperties = systemPropertyBuilder.toString();
String env1 = "PRAVEGA_CONTROLLER_OPTS=" + controllerSystemProperties;
String env2 = "JAVA_OPTS=-Xmx512m";
Map<String, String> labels = new HashMap<>();
labels.put("com.docker.swarm.task.name", serviceName);
final TaskSpec taskSpec = TaskSpec.builder().networks(NetworkAttachmentConfig.builder().target(DOCKER_NETWORK).aliases(serviceName).build()).containerSpec(ContainerSpec.builder().image(IMAGE_PATH + "nautilus/pravega:" + PRAVEGA_VERSION).healthcheck(ContainerConfig.Healthcheck.create(null, Duration.ofSeconds(10).toNanos(), Duration.ofSeconds(10).toNanos(), 3)).mounts(Arrays.asList(mount)).hostname(serviceName).labels(labels).env(Arrays.asList(env1, env2)).args("controller").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(Arrays.asList(PortConfig.builder().publishedPort(DOCKER_CONTROLLER_PORT).targetPort(DOCKER_CONTROLLER_PORT).publishMode(PortConfig.PortConfigPublishMode.HOST).build(), PortConfig.builder().publishedPort(REST_PORT).targetPort(REST_PORT).publishMode(PortConfig.PortConfigPublishMode.HOST).build())).build()).build();
return spec;
}
use of com.spotify.docker.client.messages.swarm.ServiceSpec 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