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

v1alpha2 api server implementation #456

Merged
merged 5 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 83 additions & 33 deletions cmd/manager/v1alpha2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"errors"
"flag"
"log"
"net"
Expand All @@ -24,93 +25,142 @@ type server struct {
}

// Register a Experiment to DB.
func (s *server) RegisterExperiment(context.Context, *api_pb.RegisterExperimentRequest) (*api_pb.RegisterExperimentReply, error) {
return nil, nil
func (s *server) RegisterExperiment(ctx context.Context, in *api_pb.RegisterExperimentRequest) (*api_pb.RegisterExperimentReply, error) {
err := dbIf.RegisterExperiment(in.Experiment)
return &api_pb.RegisterExperimentReply{}, err
}

// Delete a Experiment from DB by name.
func (s *server) DeleteExperiment(context.Context, *api_pb.DeleteExperimentRequest) (*api_pb.DeleteExperimentReply, error) {
return nil, nil
func (s *server) DeleteExperiment(ctx context.Context, in *api_pb.DeleteExperimentRequest) (*api_pb.DeleteExperimentReply, error) {
err := dbIf.DeleteExperiment(in.ExperimentName)
return &api_pb.DeleteExperimentReply{}, err
}

// Get a Experiment from DB by name.
func (s *server) GetExperiment(context.Context, *api_pb.GetExperimentRequest) (*api_pb.GetExperimentReply, error) {
return nil, nil
func (s *server) GetExperiment(ctx context.Context, in *api_pb.GetExperimentRequest) (*api_pb.GetExperimentReply, error) {
exp, err := dbIf.GetExperiment(in.ExperimentName)
return &api_pb.GetExperimentReply{
Experiment: exp,
}, err
}

// Get a summary list of Experiment from DB.
// The summary includes name and condition.
func (s *server) GetExperimentList(context.Context, *api_pb.GetExperimentListRequest) (*api_pb.GetExperimentListReply, error) {
return nil, nil
func (s *server) GetExperimentList(ctx context.Context, in *api_pb.GetExperimentListRequest) (*api_pb.GetExperimentListReply, error) {
expList, err := dbIf.GetExperimentList()
return &api_pb.GetExperimentListReply{
ExperimentSummaries: expList,
}, err
}

// Update Status of a experiment.
func (s *server) UpdateExperimentStatus(context.Context, *api_pb.UpdateExperimentStatusRequest) (*api_pb.UpdateExperimentStatusReply, error) {
return nil, nil
func (s *server) UpdateExperimentStatus(ctx context.Context, in *api_pb.UpdateExperimentStatusRequest) (*api_pb.UpdateExperimentStatusReply, error) {
err := dbIf.UpdateExperimentStatus(in.ExperimentName, in.NewStatus)
return &api_pb.UpdateExperimentStatusReply{}, err
}

// Update AlgorithmExtraSettings.
// The ExtraSetting is created if it does not exist, otherwise it is overwrited.
func (s *server) UpdateAlgorithmExtraSettings(context.Context, *api_pb.UpdateAlgorithmExtraSettingsRequest) (*api_pb.UpdateAlgorithmExtraSettingsReply, error) {
return nil, nil
func (s *server) UpdateAlgorithmExtraSettings(ctx context.Context, in *api_pb.UpdateAlgorithmExtraSettingsRequest) (*api_pb.UpdateAlgorithmExtraSettingsReply, error) {
err := dbIf.UpdateAlgorithmExtraSettings(in.ExperimentName, in.ExtraAlgorithmSettings)
return &api_pb.UpdateAlgorithmExtraSettingsReply{}, err
}

// Get all AlgorithmExtraSettings.
func (s *server) GetAlgorithmExtraSettings(context.Context, *api_pb.GetAlgorithmExtraSettingsRequest) (*api_pb.GetAlgorithmExtraSettingsReply, error) {
return nil, nil
func (s *server) GetAlgorithmExtraSettings(ctx context.Context, in *api_pb.GetAlgorithmExtraSettingsRequest) (*api_pb.GetAlgorithmExtraSettingsReply, error) {
eas, err := dbIf.GetAlgorithmExtraSettings(in.ExperimentName)
return &api_pb.GetAlgorithmExtraSettingsReply{
ExtraAlgorithmSettings: eas,
}, err
}

// Register a Trial to DB.
// ID will be filled by manager automatically.
func (s *server) RegisterTrial(context.Context, *api_pb.RegisterTrialRequest) (*api_pb.RegisterTrialReply, error) {
return nil, nil
func (s *server) RegisterTrial(ctx context.Context, in *api_pb.RegisterTrialRequest) (*api_pb.RegisterTrialReply, error) {
err := dbIf.RegisterTrial(in.Trial)
return &api_pb.RegisterTrialReply{}, err
}

// Delete a Trial from DB by ID.
func (s *server) DeleteTrial(context.Context, *api_pb.DeleteTrialRequest) (*api_pb.DeleteTrialReply, error) {
return nil, nil
func (s *server) DeleteTrial(ctx context.Context, in *api_pb.DeleteTrialRequest) (*api_pb.DeleteTrialReply, error) {
err := dbIf.DeleteTrial(in.TrialName)
return &api_pb.DeleteTrialReply{}, err
}

// Get a list of Trial from DB by name of a Experiment.
func (s *server) GetTrialList(context.Context, *api_pb.GetTrialListRequest) (*api_pb.GetTrialListReply, error) {
return nil, nil
func (s *server) GetTrialList(ctx context.Context, in *api_pb.GetTrialListRequest) (*api_pb.GetTrialListReply, error) {
trList, err := dbIf.GetTrialList(in.ExperimentName)
return &api_pb.GetTrialListReply{
Trials: trList,
}, err
}

// Get a Trial from DB by ID of Trial.
func (s *server) GetTrial(context.Context, *api_pb.GetTrialRequest) (*api_pb.GetTrialReply, error) {
return nil, nil
func (s *server) GetTrial(ctx context.Context, in *api_pb.GetTrialRequest) (*api_pb.GetTrialReply, error) {
tr, err := dbIf.GetTrial(in.TrialName)
return &api_pb.GetTrialReply{
Trial: tr,
}, err
}

// Update Status of a trial.
func (s *server) UpdateTrialStatus(context.Context, *api_pb.UpdateTrialStatusRequest) (*api_pb.UpdateTrialStatusReply, error) {
return nil, nil
func (s *server) UpdateTrialStatus(ctx context.Context, in *api_pb.UpdateTrialStatusRequest) (*api_pb.UpdateTrialStatusReply, error) {
err := dbIf.UpdateTrialStatus(in.TrialName, in.NewStatus)
return &api_pb.UpdateTrialStatusReply{}, err
}

// Report a log of Observations for a Trial.
// The log consists of timestamp and value of metric.
// Katib store every log of metrics.
// You can see accuracy curve or other metric logs on UI.
func (s *server) ReportObservationLog(context.Context, *api_pb.ReportObservationLogRequest) (*api_pb.ReportObservationLogReply, error) {
return nil, nil
func (s *server) ReportObservationLog(ctx context.Context, in *api_pb.ReportObservationLogRequest) (*api_pb.ReportObservationLogReply, error) {
err := dbIf.RegisterObservationLog(in.TrialName, in.ObservationLog)
return &api_pb.ReportObservationLogReply{}, err
}

// Get all log of Observations for a Trial.
func (s *server) GetObservationLog(context.Context, *api_pb.GetObservationLogRequest) (*api_pb.GetObservationLogReply, error) {
return nil, nil
func (s *server) GetObservationLog(ctx context.Context, in *api_pb.GetObservationLogRequest) (*api_pb.GetObservationLogReply, error) {
ol, err := dbIf.GetObservationLog(in.TrialName, in.StartTime, in.EndTime)
return &api_pb.GetObservationLogReply{
ObservationLog: ol,
}, err
}

// Get Suggestions from a Suggestion service.
func (s *server) GetSuggestions(context.Context, *api_pb.GetSuggestionsRequest) (*api_pb.GetSuggestionsReply, error) {
return nil, nil
func (s *server) GetSuggestions(ctx context.Context, in *api_pb.GetSuggestionsRequest) (*api_pb.GetSuggestionsReply, error) {
if in.AlgorithmName == "" {
return &api_pb.GetSuggestionsReply{Trials: []*api_pb.Trial{}}, errors.New("No algorithm name is specified")
}
conn, err := grpc.Dial("vizier-suggestion-"+in.AlgorithmName+":6789", grpc.WithInsecure())
Copy link
Contributor

Choose a reason for hiding this comment

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

One question: should we still use vizier-* names internally or should we start renaming them to katib? See #136.

Copy link
Member

Choose a reason for hiding this comment

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

i think, we should start renaming to katib. i had renamed studyjobcontroller to katib-controller

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree. I will change them.

if err != nil {
return &api_pb.GetSuggestionsReply{Trials: []*api_pb.Trial{}}, err
}

defer conn.Close()
c := api_pb.NewSuggestionClient(conn)
r, err := c.GetSuggestions(ctx, in)
if err != nil {
return &api_pb.GetSuggestionsReply{Trials: []*api_pb.Trial{}}, err
}
return r, nil
}

// Validate AlgorithmSettings in an Experiment.
// Suggestion service should return INVALID_ARGUMENT Error when the parameter is invalid
func (s *server) ValidateAlgorithmSettings(context.Context, *api_pb.ValidateAlgorithmSettingsRequest) (*api_pb.ValidateAlgorithmSettingsReply, error) {
return nil, nil
func (s *server) ValidateAlgorithmSettings(ctx context.Context, in *api_pb.ValidateAlgorithmSettingsRequest) (*api_pb.ValidateAlgorithmSettingsReply, error) {
if in.AlgorithmName == "" {
return &api_pb.ValidateAlgorithmSettingsReply{}, errors.New("No algorithm name is specified")
}
conn, err := grpc.Dial("vizier-suggestion-"+in.AlgorithmName+":6789", grpc.WithInsecure())
Copy link
Member

Choose a reason for hiding this comment

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

we can add a function like getSuggestionServiceUrl(name String) string or even a function like getSuggestionServiceConnection(name String)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if err != nil {
return &api_pb.ValidateAlgorithmSettingsReply{}, err
}
defer conn.Close()
c := api_pb.NewSuggestionClient(conn)
return c.ValidateAlgorithmSettings(ctx, in)
}

func (s *server) Check(context.Context, *health_pb.HealthCheckRequest) (*health_pb.HealthCheckResponse, error) {
func (s *server) Check(ctx context.Context, in *health_pb.HealthCheckRequest) (*health_pb.HealthCheckResponse, error) {
return nil, nil
}

Expand Down
Loading