Skip to content

Commit

Permalink
Move exec-agent/process -> core/process
Browse files Browse the repository at this point in the history
  • Loading branch information
Yevhenii Voevodin committed May 24, 2017
1 parent 6a427e3 commit 189ca04
Show file tree
Hide file tree
Showing 17 changed files with 575 additions and 436 deletions.
2 changes: 0 additions & 2 deletions agents/go-agents/core/activity/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
const threshold int64 = 60

var (
// ActivityTrackingEnabled defines whether activity tracking should be used
ActivityTrackingEnabled = false
// Tracker provides workspace activity notification client
Tracker WorkspaceActivityTracker = &NoOpActivityTracker{}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Codenvy, S.A. - initial API and implementation
//

package exec
package process

import (
"time"
Expand Down
16 changes: 9 additions & 7 deletions agents/go-agents/core/process/file_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ func (fl *FileLogger) writeLine(message *LogMessage) {
}

func (fl *FileLogger) doFlush() {
f, err := os.OpenFile(fl.filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err != nil {
log.Printf("Couldn't open file '%s' for flushing the buffer. %s \n", fl.filename, err.Error())
} else {
defer closeFile(f)
_, err = fl.buffer.WriteTo(f)
if fl.buffer.Len() > 0 {
f, err := os.OpenFile(fl.filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err != nil {
log.Printf("Error appears on flushing data to file '%s'. %s \n", fl.filename, err.Error())
log.Printf("Couldn't open file '%s' for flushing the buffer. %s \n", fl.filename, err.Error())
} else {
defer closeFile(f)
_, err = fl.buffer.WriteTo(f)
if err != nil {
log.Printf("Error appears on flushing data to file '%s'. %s \n", fl.filename, err.Error())
}
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions agents/go-agents/core/process/file_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ import (
"encoding/json"
"io/ioutil"
"log"
"math/rand"
"os"
"testing"
"time"

"github.com/eclipse/che/agents/go-agents/core/process"
)

var alphabet = []byte("abcdefgh123456789")

func TestFileLoggerCreatesFileWhenFileDoesNotExist(t *testing.T) {
filename := os.TempDir() + string(os.PathSeparator) + randomName(10)
defer removeFile(filename)
Expand Down Expand Up @@ -113,15 +110,6 @@ func TestLogsAreFlushedOnClose(t *testing.T) {
failIfDifferent(t, expectedStderr, stderr)
}

func randomName(length int) string {
rand.Seed(time.Now().UnixNano())
bytes := make([]byte, length)
for i := 0; i < length; i++ {
bytes[i] = alphabet[rand.Intn(len(alphabet))]
}
return string(bytes)
}

func removeFile(path string) {
if err := os.Remove(path); err != nil {
log.Printf("Can't remove file %s. Error: %s", path, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Codenvy, S.A. - initial API and implementation
//

package exec
package process

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Codenvy, S.A. - initial API and implementation
//

package exec_test
package process_test

import (
"fmt"
Expand All @@ -18,14 +18,14 @@ import (
"os"
"testing"

"github.com/eclipse/che/agents/go-agents/exec-agent/exec"
"github.com/eclipse/che/agents/go-agents/core/process"
)

func TestLogsDistributorCreatesSubdirectories(t *testing.T) {
baseDir := os.TempDir() + string(os.PathSeparator) + randomName(10)
defer removeAll(baseDir)

distributor := exec.DefaultLogsDistributor{
distributor := process.DefaultLogsDistributor{
MaxDirsCount: 4,
}

Expand All @@ -45,7 +45,7 @@ func TestLogsDistribution(t *testing.T) {
baseDir := os.TempDir() + string(os.PathSeparator) + randomName(10)
defer removeAll(baseDir)

distributor := exec.DefaultLogsDistributor{
distributor := process.DefaultLogsDistributor{
MaxDirsCount: 4,
}

Expand Down
Loading

0 comments on commit 189ca04

Please sign in to comment.