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

Multiple services #541

Merged
merged 7 commits into from
Nov 20, 2018
Merged

Multiple services #541

merged 7 commits into from
Nov 20, 2018

Conversation

vkuznecovas
Copy link
Contributor

myst service now runs all the supported services(openvpn, noop). Adjusted the cli accordingly, we're now able to connect to a provider by specifying the service type as well. It's also possible to start a single service via myst service openvpn or myst service noop

@vkuznecovas
Copy link
Contributor Author

closes #483

}

// Manager represents entrypoint for Noop service
type Manager struct {
fakeProcess sync.WaitGroup
fakeProcess sync.WaitGroup
locationResolver location.Resolver
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need locationResolver here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess to lookup country in which service is provided. But country is hardcoded below :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct, somehow forgot it - implemented.

}

// Manager represents entrypoint for Noop service
type Manager struct {
fakeProcess sync.WaitGroup
fakeProcess sync.WaitGroup
locationResolver location.Resolver
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess to lookup country in which service is provided. But country is hardcoded below :(

os.Exit(2)
}

errorChannel := make(chan error, 2+len(serviceTypes))
Copy link
Contributor

@zolia zolia Nov 15, 2018

Choose a reason for hiding this comment

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

Why we need 2+len here? Short comment would be good here.

@@ -46,10 +46,11 @@ type Service interface {
Start(providerID identity.Identity) (dto_discovery.ServiceProposal, session.ConfigProvider, error)
Wait() error
Stop() error
GetType() string
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks artificial. Maybe its better to get type from serviceProposal returned by manager.service.Start(providerID) if needed? We should know what we are running.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would like this manager to manage multiple services instead of one. This way it can have method Register(Service, serviceType), Start(list of services), or maybe I don't get the purpose of this component. It can also hide a map from di, which is leaky details

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I see it, we'll still need the manager(maybe the naming needs a change, but naming is hard). I like that it's responsible for

  1. Registering/pinging the proposal
  2. Starting the service it's given
  3. Starting to listen for the relevant dialogs

We'll need these for every service, so in my head the component makes perfect sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case yes - better naming is needed. I didn't expect to see multiple managers :)

return nil
}

// KillAll kills all the service managers
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// KillAll kills all the service managers
// KillAll kills all service managers

if filterMatched {
var serviceMatched = true
if serviceType != "" {
serviceMatched = serviceMatched && (serviceType == proposal.ServiceType)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
serviceMatched = serviceMatched && (serviceType == proposal.ServiceType)
serviceMatched = (serviceType == proposal.ServiceType)

}

if manager.isStarted {
return dto_discovery.ServiceProposal{}, sessionConfigProvider, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be "ErrAlreadyStarted" or return the same instance?

if manager.isStarted {
return dto_discovery.ServiceProposal{}, sessionConfigProvider, nil
}

manager.fakeProcess.Add(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

We prob should not use 'fake' wording anymore here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed

// service type
// required: false
// default: openvpn
// example: openvpn
Copy link
Contributor

Choose a reason for hiding this comment

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

We should see somewhere what available options there are: openvpn, noop

zolia
zolia previously requested changes Nov 15, 2018
Copy link
Contributor

@zolia zolia left a comment

Choose a reason for hiding this comment

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

small issues

if err != nil {
return err
}
err = di.ServiceRunner.StartServiceByType(serviceType, options, errorChannel)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of error channel here? method it self returns error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the error here tells us if the startup of services was successful. The channel is then used to report runtime errors that occur in the underlying service.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. Do we really need to report those errors upstairs? Startup errors are pretty much ok, but runtime errors - well I am not sure, what happens in case of that error - we shutdown whole node? What if other services run perfectly? Maybe some kind of retry mechanism is needed? Don't forget that service will be managed through api in the future - not only by args on startup.

cmd/di.go Outdated
if err := di.ServiceManager.Kill(); err != nil {
errs = append(errs, err)
if di.ServiceRunner != nil {
if runnerErrs := di.ServiceRunner.KillAll(); len(runnerErrs) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you really need a len > 0 here ? Append of empty slice elements shouldn't append anything

cmd/di.go Outdated
discoveryService,
)
if len(nodeOptions.ServiceTypes) > 0 {
serviceManagerMap := make(map[string]service.RunnableService, len(nodeOptions.ServiceTypes))
Copy link
Contributor

Choose a reason for hiding this comment

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

Interface should be defined by caller or user. Anyway this block looks very complicated and hard to understand. I guess we can maintain a map of self registered services provides always ready, and runner only picks which ones to start according to options.

@@ -49,7 +49,7 @@ type PromiseIssuerCreator func(issuerID identity.Identity, dialog communication.
// Manager interface provides methods to manage connection
type Manager interface {
// Connect creates new connection from given consumer to provider, reports error if connection already exists
Connect(consumerID identity.Identity, providerID identity.Identity, params ConnectParams) error
Connect(consumerID identity.Identity, providerID identity.Identity, serviceType string, params ConnectParams) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's time to gather proposal related information in it's own params structure. In the long term connection manager shouldn't do a proposal lookup but get one as a parameter from outside.

@@ -141,7 +141,7 @@ func (manager *connectionManager) startConnection(consumerID, providerID identit
}
}()

proposal, err := manager.findProposalByProviderID(providerID)
proposal, err := manager.findProposalByProviderID(providerID, serviceType)
Copy link
Contributor

Choose a reason for hiding this comment

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

This parameter leaks from Connect only to be passed as a filter to discovery

@@ -46,10 +46,11 @@ type Service interface {
Start(providerID identity.Identity) (dto_discovery.ServiceProposal, session.ConfigProvider, error)
Wait() error
Stop() error
GetType() string
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like this manager to manage multiple services instead of one. This way it can have method Register(Service, serviceType), Start(list of services), or maybe I don't get the purpose of this component. It can also hide a map from di, which is leaky details

@vkuznecovas vkuznecovas dismissed stale reviews from tadovas and zolia November 16, 2018 12:11

new one please

@vkuznecovas vkuznecovas requested review from tadovas and zolia November 16, 2018 12:12
@vkuznecovas
Copy link
Contributor Author

Did a rework where a proposal is now passed to the connect method, and the manager no longer fetches it. Fixed most of the comments.

@@ -114,7 +114,7 @@ func consumerConnectFlow(t *testing.T, tequilapi *tequilapi_client.Client, consu
})
assert.NoError(t, err)

connectionStatus, err = tequilapi.Connect(consumerID, proposal.ProviderID, endpoints.ConnectOptions{true})
connectionStatus, err = tequilapi.Connect(consumerID, proposal.ProviderID, "openvpn", endpoints.ConnectOptions{true})
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we pass here a proposal too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

out of scope, we'll need to fix the api part though, to avoid having to query for the service type in general. I've created #549 for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome 👍

@vkuznecovas
Copy link
Contributor Author

The runners "startServiceByType" now blocks.

@vkuznecovas vkuznecovas requested a review from soffokl November 19, 2018 08:49
@@ -28,7 +28,7 @@ import (
type Client interface {
RegisterIdentity(id identity.Identity, signer identity.Signer) (err error)

FindProposals(providerID string) (proposals []dto_discovery.ServiceProposal, err error)
FindProposals(providerID string, serviceType string) (proposals []dto_discovery.ServiceProposal, err error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's time to add method for single proposal fetch by it's identification

Copy link
Contributor

@tadovas tadovas left a comment

Choose a reason for hiding this comment

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

Looks OK. Lets move on

@tadovas tadovas merged commit 52942b3 into master Nov 20, 2018
@tadovas tadovas deleted the multiple-services branch November 20, 2018 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants