Search in sources :

Example 1 with TaskSpec

use of com.spotify.docker.client.messages.swarm.TaskSpec 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;
}
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)

Example 2 with TaskSpec

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

the class DockerBasedService method scaleService.

@Override
public CompletableFuture<Void> scaleService(final int instanceCount) {
    try {
        Preconditions.checkArgument(instanceCount >= 0, "negative value: %s", instanceCount);
        Service.Criteria criteria = Service.Criteria.builder().serviceName(this.serviceName).build();
        TaskSpec taskSpec = Exceptions.handleInterrupted(() -> dockerClient.listServices(criteria).get(0).spec().taskTemplate());
        String serviceId = Exceptions.handleInterrupted(() -> dockerClient.listServices(criteria).get(0).id());
        EndpointSpec endpointSpec = Exceptions.handleInterrupted(() -> dockerClient.inspectService(serviceId).spec().endpointSpec());
        Service service = Exceptions.handleInterrupted(() -> dockerClient.inspectService(serviceId));
        Exceptions.handleInterrupted(() -> dockerClient.updateService(serviceId, service.version().index(), ServiceSpec.builder().endpointSpec(endpointSpec).mode(ServiceMode.withReplicas(instanceCount)).taskTemplate(taskSpec).name(serviceName).build()));
        return Exceptions.handleInterrupted(() -> waitUntilServiceRunning());
    } catch (DockerException e) {
        throw new TestFrameworkException(TestFrameworkException.Type.RequestFailed, "Test failure: Unable to scale service to given instances=" + instanceCount, e);
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) TaskSpec(com.spotify.docker.client.messages.swarm.TaskSpec) EndpointSpec(com.spotify.docker.client.messages.swarm.EndpointSpec) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.spotify.docker.client.messages.swarm.Service)

Example 3 with TaskSpec

use of com.spotify.docker.client.messages.swarm.TaskSpec 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;
}
Also used : HashMap(java.util.HashMap) TaskSpec(com.spotify.docker.client.messages.swarm.TaskSpec) ServiceSpec(com.spotify.docker.client.messages.swarm.ServiceSpec)

Example 4 with TaskSpec

use of com.spotify.docker.client.messages.swarm.TaskSpec 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;
}
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) PortConfig(com.spotify.docker.client.messages.swarm.PortConfig)

Example 5 with TaskSpec

use of com.spotify.docker.client.messages.swarm.TaskSpec 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;
}
Also used : HashMap(java.util.HashMap) TaskSpec(com.spotify.docker.client.messages.swarm.TaskSpec) Mount(com.spotify.docker.client.messages.mount.Mount) 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