From b1ddbc26dc7645e355712a946af87204defa60a1 Mon Sep 17 00:00:00 2001 From: Eric Schrock Date: Mon, 2 Dec 2019 09:43:14 -0500 Subject: [PATCH] implement clone (#120) --- .../kotlin/io/titandata/titan/clients/Docker.kt | 14 ++++++++++++-- .../io/titandata/titan/providers/Kubernetes.kt | 8 ++++++-- .../kotlin/io/titandata/titan/providers/Local.kt | 2 +- .../titan/providers/{local => generic}/Clone.kt | 2 +- .../io/titandata/titan/providers/generic/Pull.kt | 2 +- .../io/titandata/titan/providers/generic/Push.kt | 2 +- .../titan/providers/kubernetes/Install.kt | 2 +- .../providers/{local => generic}/CloneTest.kt | 2 +- 8 files changed, 24 insertions(+), 10 deletions(-) rename src/main/kotlin/io/titandata/titan/providers/{local => generic}/Clone.kt (98%) rename src/test/kotlin/io/titandata/titan/providers/{local => generic}/CloneTest.kt (95%) diff --git a/src/main/kotlin/io/titandata/titan/clients/Docker.kt b/src/main/kotlin/io/titandata/titan/clients/Docker.kt index 1ab510b7..d9e6e9cf 100644 --- a/src/main/kotlin/io/titandata/titan/clients/Docker.kt +++ b/src/main/kotlin/io/titandata/titan/clients/Docker.kt @@ -106,8 +106,18 @@ class Docker(private val executor: CommandExecutor, val identity: String = "tita return run("titan:latest", "/bin/bash /titan/teardown", titanLaunchArgs) } - fun launchTitanKubernetesServers(): String { - return run("titan:latest", "/bin/bash /titan/run", titanLaunchKubernetesArgs) + fun launchTitanKubernetesServers(titanServerVersion: String): String { + var config = System.getenv("TITAN_CONFIG") ?: "" + if (!config.contains("titanImage")) { + if (config != "") { + config += "," + } + config += "titanImage=titandata/titan:$titanServerVersion" + } + val launchArgs = titanLaunchKubernetesArgs.toMutableList() + launchArgs.add("-e") + launchArgs.add("TITAN_CONFIG=$config") + return run("titan:latest", "/bin/bash /titan/run", launchArgs) } fun pull(image: String): String { diff --git a/src/main/kotlin/io/titandata/titan/providers/Kubernetes.kt b/src/main/kotlin/io/titandata/titan/providers/Kubernetes.kt index 367b7ecd..454cc47f 100644 --- a/src/main/kotlin/io/titandata/titan/providers/Kubernetes.kt +++ b/src/main/kotlin/io/titandata/titan/providers/Kubernetes.kt @@ -13,6 +13,7 @@ import io.titandata.serialization.RemoteUtil import io.titandata.titan.clients.Docker import io.titandata.titan.exceptions.CommandException import io.titandata.titan.providers.generic.Abort +import io.titandata.titan.providers.generic.Clone import io.titandata.titan.providers.generic.Commit import io.titandata.titan.providers.generic.Delete import io.titandata.titan.providers.generic.Log @@ -221,10 +222,13 @@ class Kubernetes : Provider { } override fun cp(container: String, driver: String, source: String, path: String) { - throw NotImplementedError("cp is not supported in kuberentes context") + throw NotImplementedError("cp is not supported in kubernetes context") } override fun clone(uri: String, container: String?, commit: String?, params: Map, arguments: List, disablePortMapping: Boolean) { - TODO("not implemented") + val runCommand = Run(::exit, commandExecutor, docker, kubernetes, repositoriesApi, volumesApi) + val cloneCommand = Clone(::remoteAdd, ::pull, ::checkout, runCommand::run, ::remove, commandExecutor, docker, + remotesApi, repositoriesApi) + return cloneCommand.clone(uri, container, commit, params, arguments, disablePortMapping) } } diff --git a/src/main/kotlin/io/titandata/titan/providers/Local.kt b/src/main/kotlin/io/titandata/titan/providers/Local.kt index 6ce312d1..c59ea63a 100644 --- a/src/main/kotlin/io/titandata/titan/providers/Local.kt +++ b/src/main/kotlin/io/titandata/titan/providers/Local.kt @@ -8,6 +8,7 @@ import io.titandata.client.apis.RepositoriesApi import io.titandata.titan.clients.Docker import io.titandata.titan.exceptions.CommandException import io.titandata.titan.providers.generic.Abort +import io.titandata.titan.providers.generic.Clone import io.titandata.titan.providers.generic.Commit import io.titandata.titan.providers.generic.Delete import io.titandata.titan.providers.generic.Log @@ -23,7 +24,6 @@ import io.titandata.titan.providers.generic.Tag import io.titandata.titan.providers.generic.Upgrade import io.titandata.titan.providers.local.CheckInstall import io.titandata.titan.providers.local.Checkout -import io.titandata.titan.providers.local.Clone import io.titandata.titan.providers.local.Cp import io.titandata.titan.providers.local.Install import io.titandata.titan.providers.local.Migrate diff --git a/src/main/kotlin/io/titandata/titan/providers/local/Clone.kt b/src/main/kotlin/io/titandata/titan/providers/generic/Clone.kt similarity index 98% rename from src/main/kotlin/io/titandata/titan/providers/local/Clone.kt rename to src/main/kotlin/io/titandata/titan/providers/generic/Clone.kt index d2beae0e..d1aa5219 100644 --- a/src/main/kotlin/io/titandata/titan/providers/local/Clone.kt +++ b/src/main/kotlin/io/titandata/titan/providers/generic/Clone.kt @@ -2,7 +2,7 @@ * Copyright (c) 2019 by Delphix. All rights reserved. */ -package io.titandata.titan.providers.local +package io.titandata.titan.providers.generic import io.titandata.client.apis.RemotesApi import io.titandata.client.apis.RepositoriesApi diff --git a/src/main/kotlin/io/titandata/titan/providers/generic/Pull.kt b/src/main/kotlin/io/titandata/titan/providers/generic/Pull.kt index 38d57a16..23498a29 100644 --- a/src/main/kotlin/io/titandata/titan/providers/generic/Pull.kt +++ b/src/main/kotlin/io/titandata/titan/providers/generic/Pull.kt @@ -43,7 +43,7 @@ class Pull( } var operation = operationsApi.pull(container, remote.name, commit.id, remoteUtil.getParameters(remote), metadataOnly) - if (!OperationMonitor(container, operation).monitor()) { + if (!OperationMonitor(container, operation, operationsApi).monitor()) { exit("", 1) } } diff --git a/src/main/kotlin/io/titandata/titan/providers/generic/Push.kt b/src/main/kotlin/io/titandata/titan/providers/generic/Push.kt index 20226b9e..cfd8659d 100644 --- a/src/main/kotlin/io/titandata/titan/providers/generic/Push.kt +++ b/src/main/kotlin/io/titandata/titan/providers/generic/Push.kt @@ -51,7 +51,7 @@ class Push( val remote = remotesApi.getRemote(container, name) var operation = operationsApi.push(container, remote.name, commit, remoteUtil.getParameters(remote), metadataOnly) - if (!OperationMonitor(container, operation).monitor()) { + if (!OperationMonitor(container, operation, operationsApi).monitor()) { exit("", 1) } } diff --git a/src/main/kotlin/io/titandata/titan/providers/kubernetes/Install.kt b/src/main/kotlin/io/titandata/titan/providers/kubernetes/Install.kt index 6157cc38..acf7e7d5 100644 --- a/src/main/kotlin/io/titandata/titan/providers/kubernetes/Install.kt +++ b/src/main/kotlin/io/titandata/titan/providers/kubernetes/Install.kt @@ -34,7 +34,7 @@ class Install( } } track("Starting titan server docker containers") { - docker.launchTitanKubernetesServers() + docker.launchTitanKubernetesServers(titanServerVersion) } println("Titan cli successfully installed, happy data versioning :)") diff --git a/src/test/kotlin/io/titandata/titan/providers/local/CloneTest.kt b/src/test/kotlin/io/titandata/titan/providers/generic/CloneTest.kt similarity index 95% rename from src/test/kotlin/io/titandata/titan/providers/local/CloneTest.kt rename to src/test/kotlin/io/titandata/titan/providers/generic/CloneTest.kt index 42025971..c053cfa2 100644 --- a/src/test/kotlin/io/titandata/titan/providers/local/CloneTest.kt +++ b/src/test/kotlin/io/titandata/titan/providers/generic/CloneTest.kt @@ -1,4 +1,4 @@ -package io.titandata.titan.providers.local +package io.titandata.titan.providers.generic import org.hamcrest.CoreMatchers.instanceOf import org.junit.Assert.assertThat