Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/implement status command #65

Merged
merged 23 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.2
0.3.3
68 changes: 52 additions & 16 deletions config/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.EngineParameters",
"name":"io.titandata.remote.engine.EngineParameters",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -27,7 +27,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.EngineParameters[]",
"name":"io.titandata.remote.engine.EngineParameters[]",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -36,7 +36,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.EngineRemote",
"name":"io.titandata.remote.engine.EngineRemote",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -45,7 +45,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.EngineRemote[]",
"name":"io.titandata.remote.engine.EngineRemote[]",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -72,7 +72,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.NopParameters",
"name":"io.titandata.remote.nop.NopParameters",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -81,7 +81,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.NopParameters[]",
"name":"io.titandata.remote.nop.NopParameters[]",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -90,7 +90,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.NopRemote",
"name":"io.titandata.remote.nop.NopRemote",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -99,7 +99,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.NopRemote[]",
"name":"io.titandata.remote.nop.NopRemote[]",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand Down Expand Up @@ -245,7 +245,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.S3Parameters",
"name":"io.titandata.remote.s3.S3Parameters",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -254,7 +254,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.S3Parameters[]",
"name":"io.titandata.remote.s3.S3Parameters[]",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -263,7 +263,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.S3Remote",
"name":"io.titandata.remote.s3.S3Remote",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -272,7 +272,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.S3Remote[]",
"name":"io.titandata.remote.s3.S3Remote[]",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -281,7 +281,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.SshParameters",
"name":"io.titandata.remote.s3web.S3WebParameters",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -290,7 +290,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.SshParameters[]",
"name":"io.titandata.remote.s3web.S3WebParameters[]",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -299,7 +299,7 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.SshRemote",
"name":"io.titandata.remote.s3web.S3WebRemote",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand All @@ -308,7 +308,43 @@
"allPublicClasses":true
},
{
"name":"io.titandata.models.SshRemote[]",
"name":"io.titandata.remote.s3web.S3WebRemote[]",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
"allPublicConstructors":true,
"allDeclaredClasses":true,
"allPublicClasses":true
},
{
"name":"io.titandata.remote.ssh.SshParameters",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
"allPublicConstructors":true,
"allDeclaredClasses":true,
"allPublicClasses":true
},
{
"name":"io.titandata.remote.ssh.SshParameters[]",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
"allPublicConstructors":true,
"allDeclaredClasses":true,
"allPublicClasses":true
},
{
"name":"io.titandata.remote.ssh.SshRemote",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
"allPublicConstructors":true,
"allDeclaredClasses":true,
"allPublicClasses":true
},
{
"name":"io.titandata.remote.ssh.SshRemote[]",
"allDeclaredFields":true,
"allPublicMethods":true,
"allDeclaredConstructors":true,
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>titan</artifactId>
<name>Titan CLI</name>
<description></description>
<version>0.3.2</version>
<version>0.3.3</version>

<properties>
<java.version>1.8</java.version>
Expand Down Expand Up @@ -123,7 +123,7 @@
<dependency>
<groupId>io.titandata</groupId>
<artifactId>titan-client</artifactId>
<version>0.4.4</version>
<version>0.4.5</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/titandata/titan/providers/Local.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class Container (
)

class Local: Provider {
private val titanServerVersion = "0.4.4"
private val titanServerVersion = "0.4.5"
private val dockerRegistryUrl = "titandata"

private val httpHandler = HttpHandler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ class Commit (
"email" to email,
"message" to message!!,
"container" to repoMetadata["container"]!!,
"repoTags" to repoMetadata["repoTags"]!!,
"image" to repoMetadata["image"]!!,
"tag" to repoMetadata["tag"]!!,
"digest" to repoMetadata["digest"]!!,
"runtime" to repoMetadata["runtime"]!!
)
val commit = Commit(uuid, metadata)
val response = commitsApi.createCommit(container, commit)
val hash = response.id
println("Commit $hash")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package io.titandata.titan.providers.local
import io.titandata.client.apis.RemotesApi
import io.titandata.client.infrastructure.ClientException
import io.titandata.serialization.RemoteUtil
import io.titandata.models.NopRemote
import io.titandata.remote.nop.NopRemote
import io.titandata.models.Remote

class RemoteLog (
Expand Down
35 changes: 24 additions & 11 deletions src/main/kotlin/io/titandata/titan/providers/local/Run.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package io.titandata.titan.providers.local

import com.google.gson.JsonObject
import io.titandata.client.apis.RepositoriesApi
import io.titandata.titan.clients.Docker
import io.titandata.titan.clients.Docker.Companion.fetchName
Expand All @@ -28,14 +27,20 @@ class Run (
if(containerName.contains("/")) {
exit("Container name cannot contain a slash",1)
}
val image = arguments.last()
val imageArray = arguments.last().split(":")
val image = imageArray[0]
val tag = if (imageArray[1].isNullOrEmpty()) {
"latest"
} else {
imageArray[1]
}

var imageInfo: JSONObject? = null
try {
imageInfo = docker.inspectImage(image)
imageInfo = docker.inspectImage("$image:$tag")
} catch (e: CommandException) {
docker.pull(image)
imageInfo = docker.inspectImage(image)
docker.pull("$image:$tag")
imageInfo = docker.inspectImage("$image:$tag")
}

if (imageInfo == null) {
Expand Down Expand Up @@ -65,21 +70,29 @@ class Run (
argumentEdit.removeAt((argumentEdit.indexOf("--name") + 1))
argumentEdit.removeAt(argumentEdit.indexOf("--name"))
}
if (argumentEdit.contains(image)) {
argumentEdit.removeAt(argumentEdit.indexOf(image))
if (argumentEdit.contains("$image:$tag")) {
argumentEdit.removeAt(argumentEdit.indexOf("$image:$tag"))
}
argList.add("--name")
argList.add(containerName)
argList.addAll(argumentEdit)
val imageSHA = imageInfo.getJSONObject("Config").getString("Image")
val repoDigest = imageInfo.optJSONArray("RepoDigests")[0] as String
val dockerRunCommand = if(repoDigest.isNullOrEmpty()) {
"$image:$tag"
} else {
repoDigest
}
val metadata = mapOf(
"container" to imageSHA,
"repoTags" to imageInfo.getJSONArray("RepoTags")[0],
"container" to dockerRunCommand,
"image" to image,
"tag" to tag,
"digest" to repoDigest,
"runtime" to argList.toString()
)

val updateRepo = Repository(containerName, metadata)
repositoriesApi.updateRepository(containerName, updateRepo)
docker.run(imageSHA, "", argList)
docker.run(dockerRunCommand, "", argList)
println("Running controlled container $containerName")
}
}
36 changes: 27 additions & 9 deletions src/main/kotlin/io/titandata/titan/providers/local/Status.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,40 @@
package io.titandata.titan.providers.local

import io.titandata.titan.providers.Container
import io.titandata.client.apis.RepositoriesApi
import java.text.DecimalFormat
import kotlin.math.log10

class Status (
private val getContainersStatus: () -> List<Container>
private val getContainersStatus: () -> List<Container>,
private val repositoriesApi: RepositoriesApi = RepositoriesApi()
){
private val n = System.lineSeparator()

/**
* https://stackoverflow.com/a/5599842
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, you may want to compare the output of this with RsyncExecutor::numberToString() in titan-server. The latter is based on the ZFS implementation, which pays special attention to behavior near boundaries (e.g. 1023MiB instead of 0.99GiB).

*/
private fun readableFileSize(size: Long): String {
if (size <= 0) return "0"
val units = arrayOf("Bi", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB")
val digitGroups = (log10(size.toDouble()) / log10(1024.0)).toInt()
return DecimalFormat("#,##0.#").format(size / Math.pow(1024.0, digitGroups.toDouble())) + " " + units[digitGroups]
}

fun status(container: String) {
val status = repositoriesApi.getRepositoryStatus(container)
for(cont in getContainersStatus()) {
if(container == cont.name) {
println("Status: ${cont.status}")
System.out.printf("%15s %s${n}", "Status: ", cont.status)
}
}
println("*** SAMPLE STATUS ***")
println("Size: 5.4GiB")
println("Current Head: d3f4c1")
println("Volumes:")
println(" 1.23GiB /var/lib/postgres/data")
println("Operations: None")
println("*** SAMPLE STATUS ***")
System.out.printf("%15s %s${n}", "Logical Size: ", readableFileSize(status.logicalSize))
System.out.printf("%15s %s${n}", "Actual Size: ", readableFileSize(status.actualSize))
System.out.printf("%15s %s${n}", "Last Commit: ", status.lastCommit)
println()
System.out.printf("%-30s %-10s %s${n}", "Volume", "Logical", "Actual")
for (volume in status.volumeStatus) {
System.out.printf("%-30s %-10s %s${n}", volume.properties["path"], readableFileSize(volume.logicalSize), readableFileSize(volume.actualSize))
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.2
0.3.3