Skip to content
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

CHE-4097: Refactor go agents package structure #4344

Merged
merged 2 commits into from
Mar 9, 2017

Conversation

garagatyi
Copy link

What does this PR do?

Refactor terminal+exec agent to separate common components. This allows to reuse them for creation of install agent and separation of terminal and exec agents.

What issues does this PR fix or reference?

Fixes #4097

Changelog

Refactor golang agents for re-usage of components for creation of other agents.

Release Notes

Not needed, this PR is technical debt and doesn't change anything from user POV.

Docs PR

Also add comments and cleanup code.
Signed-off-by: Alexander Garagatyi <agaragatyi@codenvy.com>
@garagatyi garagatyi added the kind/task Internal things, technical debt, and to-do tasks to be performed. label Mar 7, 2017
@@ -0,0 +1,2 @@
src/main/go/exec-agent/exec-agent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that you should add this to gitignore?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is executable of go program. It may be created in development if user manually builds go sources.
Is something wrong with this exclusion?

@codenvy-ci
Copy link

Build finished.
Build # 2128 - FAILED

Please check console output at $BUILD_URL to view the results.

@codenvy-ci
Copy link

Build # 2128 - FAILED

Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/2128/ to view the results.

// Checks on workspace master if provided by request token is valid and calls ServerHTTP on delegate.
// Otherwise if UnauthorizedHandler is configured calls ServerHTTP on it.
// If it is not configured returns 401 with appropriate error message.
type Handler struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we change it to an internal implementation of http.Handler which can be created by constructing functions like

func NewHandler(endpont, delegate, unauthorizedHandler) http.Handler { ... };
func NewCachingHandler(endpont, delegate, unauthorizedHandler, cache) http.Handler { ... }

or event handler builder.

So you can be sure that all the data required for handler is provided + you're be able to pick one of caching or non-caching handler and avoid checks like handler.Cache != nil in runtime.

@skabashnyuk skabashnyuk added this to the 5.5.0 milestone Mar 9, 2017
Signed-off-by: Alexander Garagatyi <agaragatyi@codenvy.com>
@garagatyi
Copy link
Author

@evoevodin I added improvements you've asked

@voievodin
Copy link
Contributor

Thx, it looks good to me!
Well done!

@garagatyi garagatyi merged commit 2ac7b44 into eclipse-che:master Mar 9, 2017
@garagatyi garagatyi deleted the gorefactoring branch March 9, 2017 13:05
@benoitf
Copy link
Contributor

benoitf commented Mar 9, 2017

could we ensure golint is not reporting any errors on go source code ?
https://github.com/golang/lint

@benoitf
Copy link
Contributor

benoitf commented Mar 9, 2017

main.go:34:2: exported var AppHttpRoutes should have comment or be unexported
main.go:34:2: var AppHttpRoutes should be AppHTTPRoutes
auth/auth.go:25:2: exported const DefaultTokensExpirationTimeoutInMinutes should have comment (or a comment on this block) or be unexported
auth/auth.go:28:1: comment on exported type Handler should be of the form "Handler ..." (with optional leading article)
auth/auth.go:34:2: struct field ApiEndpoint should be APIEndpoint
auth/auth.go:53:1: comment on exported type TokenCache should be of the form "TokenCache ..." (with optional leading article)
auth/auth.go:61:1: exported function NewCache should have comment or be unexported
auth/auth.go:72:1: comment on exported method TokenCache.Put should be of the form "Put ..."
auth/auth.go:79:1: comment on exported method TokenCache.Expire should be of the form "Expire ..."
auth/auth.go:86:1: comment on exported method TokenCache.Contains should be of the form "Contains ..."
auth/auth.go:125:28: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
process/common.go:22:2: exported const DefaultLogsPerPageLimit should have comment (or a comment on this block) or be unexported
process/events.go:20:2: exported const StartedEventType should have comment (or a comment on this block) or be unexported
process/events.go:26:6: exported type ProcessStatusEventBody should have comment or be unexported
process/events.go:26:6: type name will be used as process.ProcessStatusEventBody by other packages, and that stutters; consider calling this StatusEventBody
process/events.go:34:6: exported type ProcessOutputEventBody should have comment or be unexported
process/events.go:34:6: type name will be used as process.ProcessOutputEventBody by other packages, and that stutters; consider calling this OutputEventBody
process/file_logger.go:27:6: exported type FileLogger should have comment or be unexported
process/file_logger.go:34:1: exported function NewLogger should have comment or be unexported
process/file_logger.go:49:1: exported method FileLogger.Flush should have comment or be unexported
process/file_logger.go:55:1: exported method FileLogger.OnStdout should have comment or be unexported
process/file_logger.go:59:1: exported method FileLogger.OnStderr should have comment or be unexported
process/file_logger.go:63:1: exported method FileLogger.Close should have comment or be unexported
process/logs_distributor.go:21:2: exported const DefaultMaxDirsCount should have comment (or a comment on this block) or be unexported
process/logs_distributor.go:24:1: comment on exported type LogsDistributor should be of the form "LogsDistributor ..." (with optional leading article)
process/logs_distributor.go:34:6: exported type DefaultLogsDistributor should have comment or be unexported
process/logs_distributor.go:38:1: exported function NewLogsDistributor should have comment or be unexported
process/logs_distributor.go:44:1: exported method DefaultLogsDistributor.DirForPid should have comment or be unexported
process/logs_reader.go:22:6: exported type LogsReader should have comment or be unexported
process/logs_reader.go:28:1: exported function NewLogsReader should have comment or be unexported
process/logs_reader.go:32:1: comment on exported method LogsReader.From should be of the form "From ..."
process/logs_reader.go:39:1: comment on exported method LogsReader.Till should be of the form "Till ..."
process/logs_reader.go:45:1: comment on exported method LogsReader.ReadLogs should be of the form "ReadLogs ..."
process/process.go:28:2: exported const StdoutBit should have comment (or a comment on this block) or be unexported
process/process.go:42:28: should drop = 0 from declaration of var prevPid; it is the zero value
process/process.go:45:2: exported var LogsDir should have comment or be unexported
process/process.go:46:19: should omit type string from declaration of var ShellInterpreter; it will be inferred from the right-hand side
process/process.go:49:6: exported type Command should have comment or be unexported
process/process.go:55:1: comment on exported type MachineProcess should be of the form "MachineProcess ..." (with optional leading article)
process/process.go:114:6: exported type Subscriber should have comment or be unexported
process/process.go:115:2: struct field Id should be ID
process/process.go:120:6: exported type LogMessage should have comment or be unexported
process/process.go:126:6: exported type NoProcessError should have comment or be unexported
process/process.go:131:6: exported type NotAliveError should have comment or be unexported
process/process.go:142:1: exported function Start should have comment or be unexported
process/process.go:217:1: comment on exported function Get should be of the form "Get ..."
process/process.go:227:1: exported function GetProcesses should have comment or be unexported
process/process.go:246:1: comment on exported function Kill should be of the form "Kill ..."
process/process.go:261:1: comment on exported function ReadLogs should be of the form "ReadLogs ..."
process/process.go:276:1: comment on exported function ReadAllLogs should be of the form "ReadAllLogs ..."
process/process.go:283:1: comment on exported function RemoveSubscriber should be of the form "RemoveSubscriber ..."
process/process.go:304:1: comment on exported function AddSubscriber should be of the form "AddSubscriber ..."
process/process.go:328:1: comment on exported function RestoreSubscriber should be of the form "RestoreSubscriber ..."
process/process.go:380:1: comment on exported function UpdateSubscriber should be of the form "UpdateSubscriber ..."
process/process.go:400:9: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
process/process.go:403:1: exported method MachineProcess.OnStdout should have comment or be unexported
process/process.go:407:1: exported method MachineProcess.OnStderr should have comment or be unexported
process/process.go:411:1: exported method MachineProcess.Close should have comment or be unexported
process/process.go:411:1: receiver name mp should be consistent with previous receiver name process for MachineProcess
process/process.go:430:1: receiver name p should be consistent with previous receiver name process for MachineProcess
process/process.go:444:1: receiver name mp should be consistent with previous receiver name process for MachineProcess
process/process.go:475:10: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
process/process.go:483:10: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
process/process_builder.go:14:6: exported type ProcessBuilder should have comment or be unexported
process/process_builder.go:14:6: type name will be used as process.ProcessBuilder by other packages, and that stutters; consider calling this Builder
process/process_builder.go:20:1: exported function NewBuilder should have comment or be unexported
process/process_builder.go:24:1: exported method ProcessBuilder.Cmd should have comment or be unexported
process/process_builder.go:29:1: exported method ProcessBuilder.CmdLine should have comment or be unexported
process/process_builder.go:34:1: exported method ProcessBuilder.CmdType should have comment or be unexported
process/process_builder.go:39:1: exported method ProcessBuilder.CmdName should have comment or be unexported
process/process_builder.go:44:1: comment on exported method ProcessBuilder.BeforeEventsHook should be of the form "BeforeEventsHook ..."
process/process_builder.go:52:1: exported method ProcessBuilder.FirstSubscriber should have comment or be unexported
process/process_builder.go:57:1: exported method ProcessBuilder.Build should have comment or be unexported
process/process_builder.go:70:1: exported method ProcessBuilder.Start should have comment or be unexported
process/process_cleaner.go:20:6: exported type Cleaner should have comment or be unexported
process/process_cleaner.go:25:1: exported function NewCleaner should have comment or be unexported
process/process_cleaner.go:32:1: exported method Cleaner.CleanPeriodically should have comment or be unexported
process/process_cleaner.go:40:1: exported method Cleaner.CleanOnce should have comment or be unexported
process/process_cleaner.go:40:1: receiver name pc should be consistent with previous receiver name c for Cleaner
process/pumper.go:24:1: comment on exported type LogsConsumer should be of the form "LogsConsumer ..." (with optional leading article)
process/pumper.go:37:1: comment on exported type LogsPumper should be of the form "LogsPumper ..." (with optional leading article)
process/pumper.go:45:1: exported function NewPumper should have comment or be unexported
process/pumper.go:52:1: exported method LogsPumper.AddConsumer should have comment or be unexported
process/pumper.go:56:1: comment on exported method LogsPumper.Pump should be of the form "Pump ..."
process/rest_service.go:28:5: exported var HttpRoutes should have comment or be unexported
process/rest_service.go:28:5: var HttpRoutes should be HTTPRoutes
process/rest_service.go:76:2: var channelId should be channelID
process/rest_service.go:189:6: func asHttpError should be asHTTPError
process/ws_service.go:23:2: exported const StartMethod should have comment (or a comment on this block) or be unexported
process/ws_service.go:36:5: exported var RpcRoutes should have comment or be unexported
process/ws_service.go:36:5: var RpcRoutes should be RPCRoutes
process/ws_service.go:114:6: exported type ProcessResult should have comment or be unexported
process/ws_service.go:114:6: type name will be used as process.ProcessResult by other packages, and that stutters; consider calling this Result
process/ws_service.go:119:1: comment on exported type StartParams should be of the form "StartParams ..." (with optional leading article)
process/ws_service.go:152:1: comment on exported type KillParams should be of the form "KillParams ..." (with optional leading article)
process/ws_service.go:170:1: comment on exported type SubscribeResult should be of the form "SubscribeResult ..." (with optional leading article)
process/ws_service.go:177:6: exported type SubscribeParams should have comment or be unexported
process/ws_service.go:218:1: comment on exported type UnsubscribeParams should be of the form "UnsubscribeParams ..." (with optional leading article)
process/ws_service.go:235:1: comment on exported type UpdateSubscriberParams should be of the form "UpdateSubscriberParams ..." (with optional leading article)
process/ws_service.go:257:1: comment on exported type GetLogsParams should be of the form "GetLogsParams ..." (with optional leading article)
process/ws_service.go:315:1: comment on exported type GetProcessParams should be of the form "GetProcessParams ..." (with optional leading article)
process/ws_service.go:330:1: comment on exported type GetProcessesParams should be of the form "GetProcessesParams ..." (with optional leading article)
process/ws_service.go:341:6: func asRpcError should be asRPCError
rest/errors.go:18:6: exported type ApiError should have comment or be unexported
rest/errors.go:18:6: type ApiError should be APIError
rest/errors.go:23:1: exported function BadRequest should have comment or be unexported
rest/errors.go:27:1: exported function NotFound should have comment or be unexported
rest/errors.go:31:1: exported function Conflict should have comment or be unexported
rest/errors.go:35:1: exported function Forbidden should have comment or be unexported
rest/errors.go:39:1: exported function Unauthorized should have comment or be unexported
rest/route.go:25:1: comment on exported type HttpRouteHandlerFunc should be of the form "HttpRouteHandlerFunc ..." (with optional leading article)
rest/route.go:27:6: type HttpRouteHandlerFunc should be HTTPRouteHandlerFunc
rest/route.go:29:1: comment on exported type Params should be of the form "Params ..." (with optional leading article)
rest/route.go:38:1: comment on exported type Route should be of the form "Route ..." (with optional leading article)
rest/route.go:57:1: comment on exported type RoutesGroup should be of the form "RoutesGroup ..." (with optional leading article)
rest/route.go:74:1: exported function WriteError should have comment or be unexported
rest/restutil/util.go:20:1: comment on exported function WriteJson should be of the form "WriteJson ..."
rest/restutil/util.go:21:6: func WriteJson should be WriteJSON
rest/restutil/util.go:26:1: comment on exported function ReadJson should be of the form "ReadJson ..."
rest/restutil/util.go:27:6: func ReadJson should be ReadJSON
rest/restutil/util.go:31:1: exported function IntQueryParam should have comment or be unexported
rest/restutil/util.go:35:9: if block ends with a return statement, so drop this else and outdent its block
rpc/channels.go:31:2: exported const ConnectedEventType should have comment (or a comment on this block) or be unexported
rpc/channels.go:43:2: var prevChanId should be prevChanID
rpc/channels.go:43:22: should drop = 0 from declaration of var prevChanId; it is the zero value
rpc/channels.go:47:2: exported var HttpRoutes should have comment or be unexported
rpc/channels.go:47:2: var HttpRoutes should be HTTPRoutes
rpc/channels.go:62:1: comment on exported type ChannelConnected should be of the form "ChannelConnected ..." (with optional leading article)
rpc/channels.go:66:2: struct field ChannelId should be ChannelID
rpc/channels.go:70:1: comment on exported type Channel should be of the form "Channel ..." (with optional leading article)
rpc/channels.go:74:2: struct field Id should be ID
rpc/channels.go:100:1: comment on exported type WsMessage should be of the form "WsMessage ..." (with optional leading article)
rpc/channels.go:106:1: comment on exported type MessageHandler should be of the form "MessageHandler ..." (with optional leading article)
rpc/channels.go:118:1: comment on exported function GetChannel should be of the form "GetChannel ..."
rpc/channels.go:120:17: func parameter chanId should be chanID
rpc/channels.go:127:1: comment on exported function GetChannels should be of the form "GetChannels ..."
rpc/channels.go:140:1: comment on exported function DropChannel should be of the form "DropChannel ..."
rpc/channels.go:263:6: func transferAsJson should be transferAsJSON
rpc/model.go:12:1: package comment should be of the form "Package rpc ..."
rpc/model.go:52:2: comment on exported const ParseErrorCode should be of the form "ParseErrorCode ..."
rpc/model.go:55:2: comment on exported const InvalidRequestErrorCode should be of the form "InvalidRequestErrorCode ..."
rpc/model.go:59:2: comment on exported const MethodNotFoundErrorCode should be of the form "MethodNotFoundErrorCode ..."
rpc/model.go:62:2: comment on exported const InvalidParamsErrorCode should be of the form "InvalidParamsErrorCode ..."
rpc/model.go:66:2: comment on exported const InternalErrorCode should be of the form "InternalErrorCode ..."
rpc/model.go:72:1: comment on exported type Request should be of the form "Request ..." (with optional leading article)
rpc/model.go:95:2: struct field Id should be ID
rpc/model.go:101:1: comment on exported type Response should be of the form "Response ..." (with optional leading article)
rpc/model.go:111:2: struct field Id should be ID
rpc/model.go:121:1: comment on exported type Event should be of the form "Event ..." (with optional leading article)
rpc/model.go:140:1: comment on exported type Error should be of the form "Error ..." (with optional leading article)
rpc/model.go:151:6: exported type Timed should have comment or be unexported
rpc/model.go:155:1: exported function NewEvent should have comment or be unexported
rpc/model.go:163:1: exported function NewArgsError should have comment or be unexported
rpc/model.go:167:1: exported function NewError should have comment or be unexported
rpc/route.go:23:1: comment on exported type Route should be of the form "Route ..." (with optional leading article)
rpc/route.go:47:1: comment on exported type RoutesGroup should be of the form "RoutesGroup ..." (with optional leading article)
rpc/route.go:72:1: receiver name or should be consistent with previous receiver name routes for routesMap
rpc/route.go:83:1: comment on exported function RegisterRoute should be of the form "RegisterRoute ..."
rpc/transmitter.go:25:1: comment on exported method Transmitter.Send should be of the form "Send ..."
rpc/transmitter.go:34:1: comment on exported method Transmitter.SendError should be of the form "SendError ..."
term/activity.go:25:2: exported var ActivityTrackingEnabled should have comment or be unexported
term/activity.go:27:2: var workspaceId should be workspaceID
term/activity.go:28:2: var ApiEndpoint should be APIEndpoint
term/activity.go:31:6: exported type WorkspaceActivity should have comment or be unexported
term/activity.go:36:1: exported method WorkspaceActivity.Notify should have comment or be unexported
term/activity.go:46:1: exported method WorkspaceActivity.StartTracking should have comment or be unexported
term/server.go:1:1: package comment should be of the form "Package term ..."
term/server.go:72:6: exported type WebSocketMessage should have comment or be unexported
term/server.go:77:6: exported type ReadWriteRoutingFinalizer should have comment or be unexported
term/server.go:91:2: exported var Cmd should have comment or be unexported
term/server.go:93:2: var HttpRoutes should be HTTPRoutes
term/server.go:106:1: exported function StartPty should have comment or be unexported
term/server.go:106:18: exported func StartPty returns unexported type *term.wsPty, which can be annoying to use
term/server.go:366:1: exported function ConnectToPtyHF should have comment or be unexported

@garagatyi
Copy link
Author

This PR was merged before you commented. So now I can't add fixes until next PR in this area.
Also we didn't consider passing golint as a rule neither official nor non-official or good practice. It is also not included in our build.
I used golint and other go tooling to find issue with the code and fixed a lot of really minor things that have no impact on code quality but rather not aligned with go community practices. I ran out of time and did what was expected so fixing all of the warning was out of scope.
I do not think that we must follow all these checks to merge PR but agree that it would be nice to eliminate them.

@codenvy-ci
Copy link

Build finished.
Build success. $BUILD_URL

@codenvy-ci
Copy link

@JamesDrummond JamesDrummond mentioned this pull request Mar 17, 2017
9 tasks
JPinkney pushed a commit to JPinkney/che that referenced this pull request Aug 17, 2017
Also add comments and cleanup code.
Signed-off-by: Alexander Garagatyi <agaragatyi@codenvy.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/task Internal things, technical debt, and to-do tasks to be performed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor exec + terminal agent to separate components
6 participants