Skip to content

Commit

Permalink
Merge pull request aerokube#8 in ALAT/mesos-selenoid from balancing t…
Browse files Browse the repository at this point in the history
…o master

Squashed commit of the following:

commit f5b0ceb
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Wed Mar 21 15:43:13 2018 +0300

    reformat with go fmt

commit a1c420c
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Wed Mar 21 15:40:59 2018 +0300

    reformat

commit 9fb93f0
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Wed Mar 21 15:38:47 2018 +0300

    refactoring (now getTotalOffersCapacity return tasksCanRun + slice of ResourcesForOneTas)

commit 098ece3
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Wed Mar 21 09:50:48 2018 +0300

    reformat code

commit 6f025cc
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Wed Mar 21 09:46:40 2018 +0300

    fix ports ranges (ports gets from begin to end)

commit 2d17f2e
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Fri Mar 16 20:59:33 2018 +0300

    fix ports ranges

commit 8d5078f
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Fri Mar 16 20:39:36 2018 +0300

    added ports ranges for offers

commit 1f51a62
Merge: 099b23b 44e64ab
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Fri Mar 16 15:33:02 2018 +0300

    Merge remote-tracking branch 'origin/balancing' into balancing

    # Conflicts:
    #	main.go
    #	mesos/scheduler/scheduler.go

commit 099b23b
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Fri Mar 16 15:29:31 2018 +0300

    added cpus and mems limits flags

commit 44e64ab
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Fri Mar 16 15:29:31 2018 +0300

    added cpus and mems limits flags

commit 4517277
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Thu Mar 15 18:27:56 2018 +0300

    added current offers capacity calculation

commit eafd0cc
Merge: 33311b5 b6b8eea
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Thu Mar 15 10:24:05 2018 +0300

    Merge remote-tracking branch 'remotes/origin/master'

commit 33311b5
Merge: 069c41d 5bfd8f1
Author: dimaprokop <DProkop@alfabank.ru>
Date:   Mon Feb 26 09:27:26 2018 +0300

    Merge remote-tracking branch 'remotes/origin/master'

commit 069c41d
Merge: 44017f8 c6606ae
Author: Alexander Andryashin <aandryashin@gmail.com>
Date:   Sun Feb 25 18:36:02 2018 +0300

    Merge pull request aerokube#360 from vania-pooh/master

    Returning correct Content-Type for /ping and /status API

commit c6606ae
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Sun Feb 25 17:45:59 2018 +0300

    Returning correct Content-Type for /ping and /status API

commit 44017f8
Merge: 2759a27 5584edd
Author: Ivan Krutov <vania-pooh@aerokube.com>
Date:   Fri Feb 23 13:31:20 2018 +0300

    Merge pull request aerokube#359 from vania-pooh/master

    Fixed broken docs

commit 5584edd
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Fri Feb 23 13:26:54 2018 +0300

    Fixed broken docs

commit 2759a27
Merge: 4b908b8 e31ecfd
Author: Alexander Andryashin <aandryashin@gmail.com>
Date:   Thu Feb 22 20:14:14 2018 +0300

    Merge pull request aerokube#358 from vania-pooh/master

    Added note about enableVideo capability

commit e31ecfd
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Thu Feb 22 19:48:46 2018 +0300

    Added note about enableVideo capability

commit 4b908b8
Merge: 9618642 a84550d
Author: Ivan Krutov <vania-pooh@aerokube.com>
Date:   Tue Feb 20 20:01:13 2018 +0300

    Merge pull request aerokube#355 from vania-pooh/master

    Removed useless quotes from logs

commit a84550d
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Tue Feb 20 19:56:29 2018 +0300

    Removed useless quotes from logs

commit 9618642
Merge: c80d939 b457aa1
Author: Ivan Krutov <vania-pooh@aerokube.com>
Date:   Mon Feb 19 06:54:18 2018 +0300

    Merge pull request aerokube#353 from vania-pooh/master

    Added missing comma to docs

commit b457aa1
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Mon Feb 19 06:32:13 2018 +0300

    Added missing comma to docs

commit c80d939
Merge: 4cbf6cb b0ffb83
Author: Alexander Andryashin <aandryashin@gmail.com>
Date:   Sat Feb 17 11:58:00 2018 +0300

    Merge pull request aerokube#352 from vania-pooh/master

    Added note about correctly setting browser images locale

commit b0ffb83
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Sat Feb 17 11:53:17 2018 +0300

    Added note about correctly setting browser images locale

commit 4cbf6cb
Merge: f262404 a9a7955
Author: Alexander Andryashin <aandryashin@gmail.com>
Date:   Wed Feb 14 21:30:39 2018 +0300

    Merge pull request aerokube#351 from vania-pooh/master

    Added ability to pass custom labels to containers (fixes aerokube#350)

commit a9a7955
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Wed Feb 14 19:50:07 2018 +0300

    Added ability to pass custom labels to containers (fixes aerokube#350)

commit f262404
Merge: 3e67bba 5aa84af
Author: Alexander Andryashin <aandryashin@gmail.com>
Date:   Wed Feb 14 09:41:21 2018 +0300

    Merge pull request aerokube#349 from vania-pooh/master

    Aligned logging messages (fixes aerokube#347)

commit 5aa84af
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Wed Feb 14 06:42:11 2018 +0300

    Aligned logging messages (fixes aerokube#347)

commit 3e67bba
Merge: 2aea6b9 20eed41
Author: Alexander Andryashin <aandryashin@gmail.com>
Date:   Sun Feb 11 11:29:44 2018 +0300

    Merge pull request aerokube#346 from vania-pooh/master

    Always stripping binaries

commit 20eed41
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Sun Feb 11 11:15:50 2018 +0300

    Always stripping binaries

commit 2aea6b9
Merge: 6ab8b2a ef5a241
Author: Ivan Krutov <vania-pooh@aerokube.com>
Date:   Thu Feb 8 09:06:24 2018 +0300

    Merge pull request aerokube#345 from vania-pooh/master

    Added Opera 51.0 image information

commit ef5a241
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Thu Feb 8 09:01:55 2018 +0300

    Added Opera 51.0 image information

commit 6ab8b2a
Merge: e5648f5 ff1e0fc
Author: Ivan Krutov <vania-pooh@aerokube.com>
Date:   Tue Jan 30 12:00:19 2018 +0300

    Merge pull request aerokube#343 from vania-pooh/master

    Automatically creating video directory for Docker only

commit ff1e0fc
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Mon Jan 29 18:02:47 2018 +0300

    Automatically creating video directory for Docker only

commit e5648f5
Merge: 6bbd2f5 8f66cc7
Author: Ivan Krutov <vania-pooh@aerokube.com>
Date:   Mon Jan 29 17:59:19 2018 +0300

    Merge pull request aerokube#342 from vania-pooh/master

    Added Firefox 58 image information

commit 8f66cc7
Author: Ivan Krutov <vania-pooh@vania-pooh.com>
Date:   Mon Jan 29 17:50:05 2018 +0300

    Added Firefox 58 image information
  • Loading branch information
Прокоп Дмитрий Александрович authored and Прокоп Дмитрий Александрович committed Mar 21, 2018
1 parent b6b8eea commit b224c3c
Show file tree
Hide file tree
Showing 21 changed files with 319 additions and 123 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ services:

script:
- go test -v -race -coverprofile=coverage.txt -covermode=atomic -coverpkg .,github.com/aerokube/selenoid/session,github.com/aerokube/selenoid/config,github.com/aerokube/selenoid/protect,github.com/aerokube/selenoid/service
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD`"
- gox -os "linux darwin windows" -arch "amd64" -osarch="windows/386" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD`"
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD` -s -w"
- gox -os "linux darwin windows" -arch "amd64" -osarch="windows/386" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD` -s -w"

before_install:
- go get -u github.com/golang/dep/cmd/dep
Expand Down
11 changes: 6 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Browser struct {
Env []string `json:"env,omitempty"`
Hosts []string `json:"hosts,omitempty"`
ShmSize int64 `json:"shmSize,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}

// Versions configuration
Expand Down Expand Up @@ -92,20 +93,20 @@ func loadJSON(filename string, v interface{}) error {

// Load loads config from file
func (config *Config) Load(browsers, containerLogs string) error {
log.Println("Loading configuration files...")
log.Println("[-] [INIT] [Loading configuration files...]")
br := make(map[string]Versions)
err := loadJSON(browsers, &br)
if err != nil {
return fmt.Errorf("browsers config: %v", err)
}
log.Printf("Loaded configuration from [%s]\n", browsers)
log.Printf("[-] [INIT] [Loaded configuration from %s]", browsers)
var cl *container.LogConfig
err = loadJSON(containerLogs, &cl)
if err != nil {
log.Printf("Using default containers log configuration because of: %v\n", err)
log.Printf("[-] [INIT] [Using default containers log configuration because of: %v]", err)
cl = &container.LogConfig{}
} else {
log.Printf("Loaded configuration from [%s]\n", containerLogs)
log.Printf("[-] [INIT] [Loaded log configuration from %s]", containerLogs)
}
config.lock.Lock()
defer config.lock.Unlock()
Expand All @@ -123,7 +124,7 @@ func (config *Config) Find(name string, version string) (*Browser, string, bool)
return nil, "", false
}
if version == "" {
log.Println("Using default version:", browser.Default)
log.Printf("[-] [DEFAULT_VERSION] [Using default version: %s]", browser.Default)
version = browser.Default
if version == "" {
return nil, "", false
Expand Down
1 change: 0 additions & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestConfigError(t *testing.T) {
os.Remove(confFile)
conf := config.NewConfig()
err := conf.Load(confFile, logConfPath)
log.Println(err)
AssertThat(t, err.Error(), EqualTo{fmt.Sprintf("browsers config: read error: open %s: no such file or directory", confFile)})
}

Expand Down
4 changes: 3 additions & 1 deletion docs/browser-image-information.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ WARNING: Firefox 53.0+ images require Selenium client 3.4.0 or newer.
|===
| Image | VNC Image | Selenoid Version | Geckodriver Version | Firefox Version | Client Version

| selenoid/firefox:48.0 | selenoid/vnc:firefox_48.0 | 1.3.9 | 0.13.0 | 48.0.2 (page load timeout, native events and proxies don't work) .10+<.^|
| selenoid/firefox:48.0 | selenoid/vnc:firefox_48.0 | 1.3.9 | 0.13.0 | 48.0.2 (page load timeout, native events and proxies don't work) .11+<.^|
**Java, selenium-webdriver.js**: 3.4.0 and above
**Python**: 3.5.0 and above
| selenoid/firefox:49.0 | selenoid/vnc:firefox_49.0 | 1.3.9 | 0.13.0 | 49.0.2 (page load timeout, native events and switching between windows don't work)
Expand All @@ -76,6 +76,7 @@ WARNING: Firefox 53.0+ images require Selenium client 3.4.0 or newer.
| selenoid/firefox:55.0 | selenoid/vnc:firefox_55.0 | 1.3.9 | 0.18.0 | 55.0.1 (switching windows may not work)
| selenoid/firefox:56.0 | selenoid/vnc:firefox_56.0 | 1.3.9 | 0.19.1 | 56.0.1
| selenoid/firefox:57.0 | selenoid/vnc:firefox_57.0 | 1.3.9 | 0.19.1 | 57.0
| selenoid/firefox:58.0 | selenoid/vnc:firefox_58.0 | 1.3.9 | 0.19.1 | 58.0
|===


Expand Down Expand Up @@ -150,6 +151,7 @@ We do not consider these images really stable. Many of base operations like work
| selenoid/opera:48.0 | selenoid/vnc:opera_48.0 | 2.30 | 48.0.2685.35
| selenoid/opera:49.0 | selenoid/vnc:opera_49.0 | 2.32 | 49.0.2725.39
| selenoid/opera:50.0 | selenoid/vnc:opera_50.0 | 2.32 | 50.0.2762.45
| selenoid/opera:51.0 | selenoid/vnc:opera_51.0 | 2.33 | 51.0.2830.26
|===

[NOTE]
Expand Down
21 changes: 20 additions & 1 deletion docs/browser-images.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,23 @@ We maintain a set of prebuilt Docker container images for different browsers inc
All these images are free to use. See image tags for a list of supported versions. Build files are stored in http://github.com/aerokube/selenoid-images[selenoid-images] repository.
Feel free to create issues or request images for new versions.

NOTE: Complete list of browser images can be found in <<Browser Image information>>
[NOTE]
====
. Complete list of browser images can be found in <<Browser Image information>>
. These images support all UTF-8 locales. This can be important if you want to save files using national alphabet symbols. You can enable your preferred locale in browsers configuration file by setting respective environment variables:
```
{
"chrome": {
"default": "64.0",
"versions": {
"64.0": {
"image": "selenoid/vnc:chrome_64.0",
//...
"env" : ["LANG=ru_RU.UTF-8", "LANGUAGE=ru:en", "LC_ALL=ru_RU.UTF-8"]
}
}
}
}
```
====

9 changes: 6 additions & 3 deletions docs/browsers-configuration-file.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Selenoid requires a simple JSON configuration file of the following format:
"port": "4444", <6>
"tmpfs": {"/tmp": "size=512m"}, <7>
"path" : "/wd/hub", <8>
"volumes" : ["/to:/from:ro"], <9>
"volumes" : ["/from:/to:ro"], <9>
"env" : ["TZ=Europe/Moscow"], <10>
"hosts" : ["example.com:192.168.0.1"], <11>
"shmSize" : 268435456, <12>
Expand Down Expand Up @@ -113,12 +113,13 @@ Selenoid proxies connections to either Selenium server or standalone driver bina
----
"46.0": {
//...
"port": ""
"port": "",
"tmpfs": {"/tmp": "size=512m", "/var": "size=128m"},
"path" : "",
"volumes": ["/to:/from", "/another:/one:ro"],
"volumes": ["/from:/to", "/another:/one:ro"],
"env" : ["TZ=Europe/Moscow", "ONE_MORE_VARIABLE=itsValue"],
"hosts" : ["one.example.com:192.168.0.1", "two.example.com:192.168.0.2"],
"labels" : {"component": "frontend", "project": "my-project"},
"shmSize" : 268435456,
},
----
Expand All @@ -142,6 +143,8 @@ We recommend to use our https://github.com/aerokube/cm[configuration tool] to av

* *hosts* (_optional_) - This field allows to add custom `/etc/hosts` entries to running container. Specified as an array of `hostname:ip` pairs.

* *labels* (_optional_) - This field allows to add custom labels to running container. Specified as an object of `"key": "value"` pairs.

* *shmSize* (_optional_) - Use it to override shared memory size for browser container.

=== Syncing Browser Images from Existing File
Expand Down
2 changes: 1 addition & 1 deletion docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:source-highlighter: coderay
:docinfo: shared

This reference for version: _{revnumber}_
This reference covers version: _{revnumber}_

Selenoid is a powerful http://golang.org/[Go] implementation of original http://github.com/SeleniumHQ/selenium[Selenium] hub code.
It is using Docker to launch browsers. Please refer to https://github.com/aerokube/selenoid[GitHub repository] if you need sources.
Expand Down
12 changes: 7 additions & 5 deletions docs/log-files.adoc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
== Log Files
A typical log file looks like the following:
```
2017/11/01 19:12:38 [NEW_REQUEST]
2017/11/01 19:12:38 [NEW_REQUEST_ACCEPTED]
2017/11/01 19:12:38 [-] [NEW_REQUEST]
2017/11/01 19:12:38 [-] [NEW_REQUEST_ACCEPTED]
2017/11/01 19:12:38 [41301] [LOCATING_SERVICE] [firefox-45.0]
2017/11/01 19:12:38 [41301] [USING_DOCKER] [firefox-45.0]
2017/11/01 19:12:38 [41301] [CREATING_CONTAINER] [selenoid/firefox:45.0]
Expand All @@ -24,11 +24,10 @@ Every line contains:
| Time | 2017/11/01 19:12:42 | -
| Request counter | [41301] | So far as session ID is unknown when doing attempts this counter is used to find all session attempts for each new session request.
| Status | [SESSION_ATTEMPTED] | See table below for complete list of statuses.
| Quota name | [my_quota] | Extracted from basic HTTP auth headers.
| Browser | [firefox-45.0] | Name and version. Only present for new session requests.
| Attempt number | [1] | For SESSION_ATTEMPTED entries means current attempt number. For SESSION_CREATED entries means total number of attempts to create this session.
| Session ID | [345bb886-7026-46d7-82d4-4788c0460110] | This value is unique for every browser session
| Session start time | [4.155712239s] | -
| Session start time | [4.15s] | -
|===

The following statuses are available:
Expand All @@ -50,10 +49,12 @@ The following statuses are available:
| CONTAINER_REMOVED | Docker container was successfully removed
| CONTAINER_STARTED | Docker container has successfully started
| CREATING_CONTAINER | Docker container with browser is creating
| DEFAULT_VERSION | Selenoid is using default browser version
| DELETED_VIDEO_FILE | Video file was deleted by user
| ENVIRONMENT_NOT_AVAILABLE | Browser with desired name and version does not exist
| FAILED_TO_REMOVE_CONTAINER | Failed to remove Docker container
| FAILED_TO_TERMINATE_PROCESS | An error occurred while terminating driver process
| INIT | Server is starting
| PROCESS_STARTED | Driver process successfully started
| PROXY_TO | Starting to proxy requests to running container or driver process
| REMOVING_CONTAINER | Docker container with browser or video recorder is being removed
Expand All @@ -66,7 +67,8 @@ The following statuses are available:
| SESSION_FAILED | An attempt to create a new session failed - user receives an error
| SESSION_NOT_FOUND | Requested VNC or logs for unknown session.
| STARTING_CONTAINER | Docker container with browser was created and is starting
| STARTING_PROCESS | Starting driver process
| STARTING_PROCESS | Starting driver process
| SHUTTING_DOWN | Server is stopping
| TERMINATING_PROCESS | Stopping driver process
| TERMINATED_PROCESS | Driver process was successfully stopped
| VNC_ENABLED | User requested VNC traffic
Expand Down
13 changes: 12 additions & 1 deletion docs/special-capabilities.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ You need to use `setSize` method instead.

=== Video Recording: enableVideo, videoName, videoScreenSize, videoFrameRate

NOTE: This feature requires some preparation. Please refer <<Video Recording>> section for details.
NOTE: This feature requires some preparation. Please refer to <<Video Recording>> section for details.

To enable video recording for session, add:

Expand Down Expand Up @@ -124,6 +124,17 @@ hostsEntries: "example.com:192.168.0.1,test.com:192.168.0.2"
Entries will be inserted to `/etc/hosts` before entries from browsers configuration file.
Thus entries from capabilities override entries from configuration file if some hosts are equal.

=== Container Labels: labels

In big clusters you may want to pass additional metadata to every browser session: environment, VCS revision, build number and so on. These labels can be then used to enrich session logs and send them to a centralized log storage. Later this metadata can be used for more efficient search through logs.

.Type: string, format: <key>:<value> (comma-separated)
----
labels: "environment:testing,build-number:14353"
----

Labels from this capability override labels from browsers configuration file. When `name` capability is specified - it is automatically added as a label to container.

=== Specifying Capabilities via Protocol Extensions

Some Selenium clients allow passing only a limited number of capabilities specified in https://w3c.github.io/webdriver/webdriver-spec.html[WebDriver specification]. For such cases Selenoid supports reading capabilities using https://w3c.github.io/webdriver/webdriver-spec.html#protocol-extensions[WebDriver protocol extensions] feature. The following two examples deliver the same result. Usually capabilities are passed like this:
Expand Down
10 changes: 8 additions & 2 deletions docs/video.adoc
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
== Video Recording
NOTE: This feature only works when browsers are run in containers. This can be both vnc or non-vnc containers.

[NOTE]
====
. This feature only works when browsers are run in containers.
. Video can be recorded with both vnc or non-vnc browser images.
. An additional `enableVideo` capability should be added to tests. See <<Special Capabilities>> section for more details.
====

Selenoid can capture browser screen and save it to https://en.wikipedia.org/wiki/MPEG-4[MPEG-4] video file using https://en.wikipedia.org/wiki/H.264/MPEG-4_AVC[H264] codec.
Video recording works by attaching a separate container with https://www.ffmpeg.org/[video capturing software] to running browser container.

To setup this feature you should:
To use this feature you should:

. Pull video recorder image once:
+
Expand Down
46 changes: 26 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,18 @@ func init() {
var err error
hostname, err = os.Hostname()
if err != nil {
log.Fatalf("%s: %v", os.Args[0], err)
log.Fatalf("[-] [INIT] [%s: %v]", os.Args[0], err)
}
queue = protect.New(limit, disableQueue)
conf = config.NewConfig()
err = conf.Load(confPath, logConfPath)
if err != nil {
log.Fatalf("%s: %v", os.Args[0], err)
log.Fatalf("[-] [INIT] [%s: %v]", os.Args[0], err)
}
onSIGHUP(func() {
err := conf.Load(confPath, logConfPath)
if err != nil {
log.Printf("%s: %v", os.Args[0], err)
log.Printf("[-] [INIT] [%s: %v]", os.Args[0], err)
}
})
cancelOnSignal()
Expand All @@ -145,14 +145,18 @@ func init() {
if err == nil {
inDocker = true
}
videoOutputDir, err = filepath.Abs(videoOutputDir)
if err != nil {
log.Fatalf("Invalid video output dir %s: %v", videoOutputDir, err)
}
err = os.MkdirAll(videoOutputDir, os.FileMode(0644))
if err != nil {
log.Fatalf("Failed to create video output dir %s: %v", videoOutputDir, err)

if !disableDocker {
videoOutputDir, err = filepath.Abs(videoOutputDir)
if err != nil {
log.Fatalf("[-] [INIT] [Invalid video output dir %s: %v]", videoOutputDir, err)
}
err = os.MkdirAll(videoOutputDir, os.FileMode(0644))
if err != nil {
log.Fatalf("[-] [INIT] [Failed to create video output dir %s: %v]", videoOutputDir, err)
}
}

environment := service.Environment{
InDocker: inDocker,
CPU: int64(cpu),
Expand All @@ -173,21 +177,21 @@ func init() {
if dockerHost == "" {
dockerHost = client.DefaultDockerHost
}
_, addr, _, err := client.ParseHost(dockerHost)
u, err := client.ParseHostURL(dockerHost)
if err != nil {
log.Fatal(err)
log.Fatalf("[-] [INIT] [%v]", err)
}
ip, _, _ := net.SplitHostPort(addr)
ip, _, _ := net.SplitHostPort(u.Host)
environment.IP = ip
cli, err = client.NewEnvClient()
if err != nil {
log.Fatalf("new docker client: %v\n", err)
log.Fatalf("[-] [INIT] [New docker client: %v]", err)
}
manager = &service.DefaultManager{Environment: &environment, Client: cli, Config: conf}

if mesosMasterURL != "" {
log.Printf("[TRY TO REGISTER ON MESOS MASTER] [%s]", mesosMasterURL)
go scheduler.Run(mesosMasterURL)
go scheduler.Run(mesosMasterURL, float64(cpu), float64(mem))
}

}
Expand All @@ -206,7 +210,7 @@ func cancelOnSignal() {
if !disableDocker {
err := cli.Close()
if err != nil {
log.Fatalf("close docker client: %v", err)
log.Fatalf("[-] [SHUTTING_DOWN] [Error closing docker client: %v]", err)
os.Exit(1)
}
}
Expand Down Expand Up @@ -243,6 +247,7 @@ func post(next http.HandlerFunc) http.HandlerFunc {
}

func ping(w http.ResponseWriter, _ *http.Request) {
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(struct {
Uptime string `json:"uptime"`
LastReloadTime string `json:"lastReloadTime"`
Expand Down Expand Up @@ -275,7 +280,7 @@ func deleteFileIfExists(w http.ResponseWriter, r *http.Request) {
http.Error(w, fmt.Sprintf("Failed to delete file %s: %v", filePath, err), http.StatusInternalServerError)
return
}
log.Printf("[%d] [DELETED_VIDEO_FILE] [%s]\n", serial(), fileName)
log.Printf("[%d] [DELETED_VIDEO_FILE] [%s]", serial(), fileName)
}

func handler() http.Handler {
Expand All @@ -291,6 +296,7 @@ func handler() http.Handler {
jsonError(w, "Session timed out or not found", http.StatusNotFound)
})
root.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(conf.State(sessions, limit, queue.Queued(), queue.Pending()))
})
root.HandleFunc("/ping", ping)
Expand All @@ -309,8 +315,8 @@ func showVersion() {
}

func main() {
log.Printf("Timezone: %s\n", time.Local)
log.Printf("Video Dir: %s\n", videoOutputDir)
log.Printf("Listening on %s\n", listen)
log.Printf("[-] [INIT] [Timezone: %s]", time.Local)
log.Printf("[-] [INIT] [Video Dir: %s]", videoOutputDir)
log.Printf("[-] [INIT] [Listening on %s]", listen)
log.Fatal(http.ListenAndServe(listen, handler()))
}
4 changes: 2 additions & 2 deletions mesos/scheduler/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ func NewLaunchTaskInfo(offer Offer, taskId string) *Launch {
Container: NewContainer(portRange),
Resources: []Resource{
NewResourcePorts(portRange),
NewResourcesContainer("cpus", 1.0),
NewResourcesContainer("mem", 128.0),
NewResourcesContainer("cpus", CpuLimit),
NewResourcesContainer("mem", MemLimit),
},
}

Expand Down
Loading

0 comments on commit b224c3c

Please sign in to comment.