Compare commits
2 Commits
da16ea9afe
...
16e954101f
Author | SHA1 | Date | |
---|---|---|---|
16e954101f | |||
61369fc2bf |
@ -1,11 +1,29 @@
|
|||||||
package com.cubetiqs.demo.axon
|
package com.cubetiqs.demo.axon
|
||||||
|
|
||||||
|
import com.cubetiqs.demo.axon.util.ExecUtils
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
import org.springframework.boot.runApplication
|
import org.springframework.boot.runApplication
|
||||||
|
import org.springframework.http.MediaType
|
||||||
|
import org.springframework.util.FileCopyUtils
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
import javax.servlet.http.HttpServletResponse
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
class AxonApplication
|
class AxonApplication
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
runApplication<AxonApplication>(*args)
|
runApplication<AxonApplication>(*args)
|
||||||
|
}
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
class MyDumper {
|
||||||
|
@GetMapping("/dump")
|
||||||
|
fun dumper(
|
||||||
|
response: HttpServletResponse
|
||||||
|
) {
|
||||||
|
response.contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE
|
||||||
|
val data = ExecUtils.execMySqlDump()
|
||||||
|
FileCopyUtils.copy(data ?: ByteArray(0), response.outputStream)
|
||||||
|
}
|
||||||
}
|
}
|
17
src/main/kotlin/com/cubetiqs/demo/axon/config/WebConfig.kt
Normal file
17
src/main/kotlin/com/cubetiqs/demo/axon/config/WebConfig.kt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.cubetiqs.demo.axon.config
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebMvc
|
||||||
|
class WebConfig : WebMvcConfigurer {
|
||||||
|
override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
|
||||||
|
registry.addResourceHandler("swagger-ui.html")
|
||||||
|
.addResourceLocations("classpath:/META-INF/resources/")
|
||||||
|
registry.addResourceHandler("/webjars/**")
|
||||||
|
.addResourceLocations("classpath:/META-INF/resources/webjars/")
|
||||||
|
}
|
||||||
|
}
|
43
src/main/kotlin/com/cubetiqs/demo/axon/util/ExecUtils.kt
Normal file
43
src/main/kotlin/com/cubetiqs/demo/axon/util/ExecUtils.kt
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package com.cubetiqs.demo.axon.util
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
|
||||||
|
object ExecUtils {
|
||||||
|
private const val MYSQLDUMP_FILE = "mysqldump"
|
||||||
|
|
||||||
|
fun execMySqlDump(): ByteArray? {
|
||||||
|
var results: ByteArray?
|
||||||
|
try {
|
||||||
|
val command: MutableList<String> = mutableListOf()
|
||||||
|
command.add(MYSQLDUMP_FILE)
|
||||||
|
command.add("--databases")
|
||||||
|
command.add("orderwebapp")
|
||||||
|
command.add("--host")
|
||||||
|
command.add("192.168.0.204")
|
||||||
|
command.add("-usombochea")
|
||||||
|
command.add("-p@Csb632612")
|
||||||
|
|
||||||
|
val builder = ProcessBuilder(*command.toTypedArray())
|
||||||
|
.redirectErrorStream(false)
|
||||||
|
val process = builder.start()
|
||||||
|
BufferedInputStream(process.inputStream).use {
|
||||||
|
ByteArrayOutputStream().use { stdout ->
|
||||||
|
while (true) {
|
||||||
|
val x = it.read()
|
||||||
|
if (x == -1) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
stdout.write(x)
|
||||||
|
}
|
||||||
|
results = stdout.toByteArray()
|
||||||
|
process.waitFor()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
println(e.message)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
}
|
10
src/test/kotlin/TestExecUtils.kt
Normal file
10
src/test/kotlin/TestExecUtils.kt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import com.cubetiqs.demo.axon.util.ExecUtils
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class TestExecUtils {
|
||||||
|
@Test
|
||||||
|
fun dump() {
|
||||||
|
val dump = ExecUtils.execMySqlDump()
|
||||||
|
println("Dump size: ${dump?.size}")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user