-
Notifications
You must be signed in to change notification settings - Fork 244
Use devstats.PID.json as devstate #6713
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
Merged
openshift-merge-robot
merged 13 commits into
redhat-developer:main
from
feloy:feature-6494/multiple-dev-sessions
Apr 19, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0ec9353
Use devstate.PID.json
feloy 9c2edf7
odo describe component gets forwarded ports from devstate.json
feloy 085ead3
Pass pid in context
feloy d664236
Add platform to state
feloy 26b2849
Overwrite devstate.json if PId not exists
feloy 88ea70f
odo describe component displays forwarded ports from podman/cluster
feloy 444adfd
Start only one session on platform
feloy f75c4b8
Fix integration test
feloy 0832f7b
Review
feloy 16314e2
Fix
feloy fa4aac6
Update pkg/state/errors.go
feloy ecebe78
Integration tests
feloy 0877169
Fix integration test
feloy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| package state | ||
|
|
||
| const _dirpath = "./.odo" | ||
| const _filepath = "./.odo/devstate.json" | ||
| const _filepathPid = "./.odo/devstate.%d.json" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| // Package state gives access to the state of the odo process stored in a local file | ||
| // The state of an instance is stored in a file .odo/devstate.${PID}.json. | ||
| // For compatibility with previous versions of odo, the `devstate.json` file contains | ||
| // the state of the first instance of odo. | ||
| package state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package state | ||
|
|
||
| import "fmt" | ||
|
|
||
| type ErrAlreadyRunningOnPlatform struct { | ||
| platform string | ||
| pid int | ||
| } | ||
|
|
||
| func NewErrAlreadyRunningOnPlatform(platform string, pid int) ErrAlreadyRunningOnPlatform { | ||
| return ErrAlreadyRunningOnPlatform{ | ||
| platform: platform, | ||
| pid: pid, | ||
| } | ||
| } | ||
|
|
||
| func (e ErrAlreadyRunningOnPlatform) Error() string { | ||
| return fmt.Sprintf("a session with PID %d is already running on platform %q", e.pid, e.platform) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,21 @@ | ||
| package state | ||
|
|
||
| import "github.com/redhat-developer/odo/pkg/api" | ||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/redhat-developer/odo/pkg/api" | ||
| ) | ||
|
|
||
| type Client interface { | ||
| // Init creates a devstate file for the process | ||
| Init(ctx context.Context) error | ||
|
|
||
| // SetForwardedPorts sets the forwarded ports in the state file and saves it to the file, updating the metadata | ||
| SetForwardedPorts(fwPorts []api.ForwardedPort) error | ||
| SetForwardedPorts(ctx context.Context, fwPorts []api.ForwardedPort) error | ||
|
|
||
| // GetForwardedPorts returns the ports forwarded by the current odo dev session | ||
| GetForwardedPorts() ([]api.ForwardedPort, error) | ||
| GetForwardedPorts(ctx context.Context) ([]api.ForwardedPort, error) | ||
|
|
||
| // SaveExit resets the state file to indicate odo is not running | ||
| SaveExit() error | ||
| SaveExit(ctx context.Context) error | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos | ||
| // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zos | ||
|
|
||
| package state | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "syscall" | ||
| ) | ||
|
|
||
| func pidExists(pid int) (bool, error) { | ||
| if pid <= 0 { | ||
| return false, fmt.Errorf("invalid pid %v", pid) | ||
| } | ||
| proc, err := os.FindProcess(pid) | ||
rm3l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return false, nil | ||
| } | ||
| err = proc.Signal(syscall.Signal(0)) | ||
| if err == nil { | ||
| return true, nil | ||
| } | ||
| if err.Error() == "os: process already finished" { | ||
| return false, nil | ||
| } | ||
| errno, ok := err.(syscall.Errno) | ||
| if !ok { | ||
| return false, err | ||
| } | ||
| switch errno { | ||
| case syscall.ESRCH: | ||
| return false, nil | ||
| case syscall.EPERM: | ||
| return true, nil | ||
| } | ||
| return false, err | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package state | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| ) | ||
|
|
||
| func pidExists(pid int) (bool, error) { | ||
| if pid <= 0 { | ||
| return false, fmt.Errorf("invalid pid %v", pid) | ||
| } | ||
| _, err := os.FindProcess(pid) | ||
| if err != nil { | ||
| return false, nil | ||
| } | ||
| return true, nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.