Skip to content
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
13 changes: 7 additions & 6 deletions cf_cli_java_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,13 @@ func (c *JavaPlugin) execute(commandExecutor cmd.CommandExecutor, uuidGenerator
return "cf " + strings.Join(cfSSHArguments, " "), nil
}

cfSSHArguments = append(cfSSHArguments, remoteCommand)
fullCommand := append(cfSSHArguments, remoteCommand)

output, err := commandExecutor.Execute(fullCommand)

output, err := commandExecutor.Execute(cfSSHArguments)
if command == heapDumpCommand {

finalFile, err := util.FindDumpFile(applicationName, heapdumpFileName, fspath)
finalFile, err := util.FindDumpFile(cfSSHArguments, heapdumpFileName, fspath)
if err == nil && finalFile != "" {
heapdumpFileName = finalFile
fmt.Println("Successfully created heap dump in application container at: " + heapdumpFileName)
Expand All @@ -263,7 +264,7 @@ func (c *JavaPlugin) execute(commandExecutor cmd.CommandExecutor, uuidGenerator

if copyToLocal {
localFileFullPath := localDir + "/" + applicationName + "-heapdump-" + uuidGenerator.Generate() + ".hprof"
err = util.CopyOverCat(applicationName, heapdumpFileName, localFileFullPath)
err = util.CopyOverCat(cfSSHArguments, heapdumpFileName, localFileFullPath)
if err == nil {
fmt.Println("Heap dump file saved to: " + localFileFullPath)
} else {
Expand All @@ -274,7 +275,7 @@ func (c *JavaPlugin) execute(commandExecutor cmd.CommandExecutor, uuidGenerator
}

if !keepAfterDownload {
err = util.DeleteRemoteFile(applicationName, heapdumpFileName)
err = util.DeleteRemoteFile(cfSSHArguments, heapdumpFileName)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -303,7 +304,7 @@ func (c *JavaPlugin) GetMetadata() plugin.PluginMetadata {
Version: plugin.VersionType{
Major: 3,
Minor: 0,
Build: 2,
Build: 3,
},
MinCliVersion: plugin.VersionType{
Major: 6,
Expand Down
6 changes: 3 additions & 3 deletions utils/cf_java_plugin_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package utils
type CfJavaPluginUtil interface {
CheckRequiredTools(app string) (bool, error)
GetAvailablePath(data string, userpath string) (string, error)
CopyOverCat(app string, src string, dest string) error
DeleteRemoteFile(app string, path string) error
FindDumpFile(app string, fullpath string, fspath string) (string, error)
CopyOverCat(args []string, src string, dest string) error
DeleteRemoteFile(args []string, path string) error
FindDumpFile(args []string, fullpath string, fspath string) (string, error)
}
16 changes: 10 additions & 6 deletions utils/cfutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,15 @@ func (checker CfJavaPluginUtilImpl) GetAvailablePath(data string, userpath strin
return "/tmp", nil
}

func (checker CfJavaPluginUtilImpl) CopyOverCat(app string, src string, dest string) error {
func (checker CfJavaPluginUtilImpl) CopyOverCat(args []string, src string, dest string) error {
f, err := os.OpenFile(dest, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
return errors.New("Error creating local file at " + dest + ". Please check that you are allowed to create files at the given local path.")
}
defer f.Close()
cat := exec.Command("cf", "ssh", app, "-c", "cat "+src)

args = append(args, "cat "+src)
cat := exec.Command("cf", args...)

cat.Stdout = f

Expand All @@ -183,8 +185,9 @@ func (checker CfJavaPluginUtilImpl) CopyOverCat(app string, src string, dest str
return nil
}

func (checker CfJavaPluginUtilImpl) DeleteRemoteFile(app string, path string) error {
_, err := exec.Command("cf", "ssh", app, "-c", "rm "+path).Output()
func (checker CfJavaPluginUtilImpl) DeleteRemoteFile(args []string, path string) error {
args = append(args, "rm "+path)
_, err := exec.Command("cf", args...).Output()

if err != nil {
return errors.New("error occured while removing dump file generated")
Expand All @@ -194,10 +197,11 @@ func (checker CfJavaPluginUtilImpl) DeleteRemoteFile(app string, path string) er
return nil
}

func (checker CfJavaPluginUtilImpl) FindDumpFile(app string, fullpath string, fspath string) (string, error) {
func (checker CfJavaPluginUtilImpl) FindDumpFile(args []string, fullpath string, fspath string) (string, error) {
cmd := " [ -f '" + fullpath + "' ] && echo '" + fullpath + "' || find " + fspath + " -name 'java_pid*.hprof' -printf '%T@ %p\\0' | sort -zk 1nr | sed -z 's/^[^ ]* //' | tr '\\0' '\\n' | head -n 1 "

output, err := exec.Command("cf", "ssh", app, "-c", cmd).Output()
args = append(args, cmd)
output, err := exec.Command("cf", args...).Output()

if err != nil {
return "", errors.New("error while checking the generated file")
Expand Down
8 changes: 4 additions & 4 deletions utils/fakes/fake_utils_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (fake FakeCfJavaPluginUtil) GetAvailablePath(data string, userpath string)
return "/tmp", nil
}

func (fake FakeCfJavaPluginUtil) CopyOverCat(app string, src string, dest string) error {
func (fake FakeCfJavaPluginUtil) CopyOverCat(args []string, src string, dest string) error {

if !fake.LocalPathValid {
return errors.New("Error occured during create desination file: " + dest + ", please check you are allowed to create file in the path.")
Expand All @@ -59,7 +59,7 @@ func (fake FakeCfJavaPluginUtil) CopyOverCat(app string, src string, dest string
return nil
}

func (fake FakeCfJavaPluginUtil) DeleteRemoteFile(app string, path string) error {
func (fake FakeCfJavaPluginUtil) DeleteRemoteFile(args []string, path string) error {
if path != fake.Fspath+"/"+fake.OutputFileName {
return errors.New("error occured while removing dump file generated")

Expand All @@ -68,9 +68,9 @@ func (fake FakeCfJavaPluginUtil) DeleteRemoteFile(app string, path string) error
return nil
}

func (fake FakeCfJavaPluginUtil) FindDumpFile(app string, fullpath string, fspath string) (string, error) {
func (fake FakeCfJavaPluginUtil) FindDumpFile(args []string, fullpath string, fspath string) (string, error) {

expectedFullPath := fake.Fspath + "/" + app + "-heapdump-" + fake.UUID + ".hprof"
expectedFullPath := fake.Fspath + "/" + args[1] + "-heapdump-" + fake.UUID + ".hprof"
if fspath != fake.Fspath || fullpath != expectedFullPath {
return "", errors.New("error while checking the generated file")
}
Expand Down