From cdf8c917188c76efc9546a81c60061826bdf28b8 Mon Sep 17 00:00:00 2001 From: Tangjiafeng <1282141182@qq.com> Date: Fri, 12 Mar 2021 13:22:28 +0800 Subject: [PATCH] Add Prophecis-DI Rest Module. --- di/restapi/Dockerfile | 34 + di/restapi/Makefile | 2 + di/restapi/api_v1/client/dlaas_client.go | 129 + .../create_event_endpoint_parameters.go | 205 ++ .../events/create_event_endpoint_responses.go | 176 ++ .../delete_event_endpoint_parameters.go | 179 ++ .../events/delete_event_endpoint_responses.go | 176 ++ .../api_v1/client/events/events_client.go | 155 ++ .../events/get_event_endpoint_parameters.go | 179 ++ .../events/get_event_endpoint_responses.go | 175 ++ .../get_event_type_endpoints_parameters.go | 158 ++ .../get_event_type_endpoints_responses.go | 175 ++ .../client/models/delete_model_parameters.go | 174 ++ .../client/models/delete_model_responses.go | 139 + .../download_model_definition_parameters.go | 174 ++ .../download_model_definition_responses.go | 140 + .../download_trained_model_parameters.go | 174 ++ .../download_trained_model_responses.go | 176 ++ .../client/models/get_logs_parameters.go | 255 ++ .../client/models/get_logs_responses.go | 140 + .../client/models/get_metrics_parameters.go | 255 ++ .../client/models/get_metrics_responses.go | 140 + .../client/models/get_model_parameters.go | 174 ++ .../client/models/get_model_responses.go | 139 + .../client/models/list_models_parameters.go | 312 +++ .../client/models/list_models_responses.go | 103 + .../api_v1/client/models/models_client.go | 314 +++ .../client/models/patch_model_parameters.go | 200 ++ .../client/models/patch_model_responses.go | 175 ++ .../client/models/post_model_parameters.go | 204 ++ .../client/models/post_model_responses.go | 146 + .../operations/get_dashboards_parameters.go | 113 + .../operations/get_dashboards_responses.go | 139 + .../client/operations/operations_client.go | 61 + .../training_data/get_loglines_parameters.go | 323 +++ .../training_data/get_loglines_responses.go | 103 + .../training_data/training_data_client.go | 88 + di/restapi/api_v1/restmodels/basic_model.go | 43 + .../api_v1/restmodels/basic_new_model.go | 102 + .../api_v1/restmodels/code_upload_response.go | 43 + di/restapi/api_v1/restmodels/datastore.go | 49 + di/restapi/api_v1/restmodels/endpoint.go | 46 + di/restapi/api_v1/restmodels/endpoint_list.go | 80 + di/restapi/api_v1/restmodels/error.go | 49 + .../restmodels/event_endpoint_registration.go | 46 + di/restapi/api_v1/restmodels/fields.go | 49 + di/restapi/api_v1/restmodels/framework.go | 46 + .../restmodels/get_dashboards_response.go | 49 + di/restapi/api_v1/restmodels/metric_data.go | 53 + di/restapi/api_v1/restmodels/model.go | 408 +++ di/restapi/api_v1/restmodels/model_list.go | 86 + .../api_v1/restmodels/query_search_type.go | 69 + di/restapi/api_v1/restmodels/t_fos_request.go | 180 ++ di/restapi/api_v1/restmodels/training.go | 156 ++ .../api_v1/restmodels/training_status.go | 60 + .../api_v1/restmodels/training_update.go | 43 + di/restapi/api_v1/restmodels/user.go | 70 + di/restapi/api_v1/restmodels/v1_log_line.go | 74 + .../api_v1/restmodels/v1_log_lines_list.go | 80 + di/restapi/api_v1/restmodels/v1_meta_info.go | 52 + di/restapi/api_v1/server/configure_di.go | 117 + di/restapi/api_v1/server/doc.go | 25 + di/restapi/api_v1/server/embedded_spec.go | 2346 +++++++++++++++++ di/restapi/api_v1/server/operations/di_api.go | 453 ++++ .../operations/experiments/code_upload.go | 60 + .../experiments/code_upload_parameters.go | 79 + .../experiments/code_upload_responses.go | 146 + .../experiments/code_upload_urlbuilder.go | 87 + .../server/operations/get_dashboards.go | 60 + .../operations/get_dashboards_parameters.go | 88 + .../operations/get_dashboards_responses.go | 146 + .../operations/get_dashboards_urlbuilder.go | 103 + .../server/operations/models/delete_model.go | 61 + .../models/delete_model_parameters.go | 117 + .../models/delete_model_responses.go | 146 + .../models/delete_model_urlbuilder.go | 110 + .../models/download_model_definition.go | 60 + .../download_model_definition_parameters.go | 117 + .../download_model_definition_responses.go | 145 + .../download_model_definition_urlbuilder.go | 110 + .../models/download_trained_model.go | 60 + .../download_trained_model_parameters.go | 117 + .../download_trained_model_responses.go | 189 ++ .../download_trained_model_urlbuilder.go | 110 + .../server/operations/models/export_model.go | 60 + .../models/export_model_parameters.go | 73 + .../models/export_model_responses.go | 145 + .../models/export_model_urlbuilder.go | 99 + .../server/operations/models/get_logs.go | 62 + .../operations/models/get_logs_parameters.go | 187 ++ .../operations/models/get_logs_responses.go | 145 + .../operations/models/get_logs_urlbuilder.go | 130 + .../server/operations/models/get_model.go | 61 + .../operations/models/get_model_parameters.go | 117 + .../operations/models/get_model_responses.go | 146 + .../operations/models/get_model_urlbuilder.go | 110 + .../server/operations/models/list_models.go | 61 + .../models/list_models_parameters.go | 316 +++ .../models/list_models_responses.go | 102 + .../models/list_models_urlbuilder.go | 163 ++ .../server/operations/models/patch_model.go | 60 + .../models/patch_model_parameters.go | 147 ++ .../models/patch_model_responses.go | 190 ++ .../models/patch_model_urlbuilder.go | 110 + .../server/operations/models/post_model.go | 61 + .../models/post_model_parameters.go | 146 + .../operations/models/post_model_responses.go | 168 ++ .../models/post_model_urlbuilder.go | 100 + .../operations/training_data/get_loglines.go | 58 + .../training_data/get_loglines_parameters.go | 255 ++ .../training_data/get_loglines_responses.go | 102 + .../training_data/get_loglines_urlbuilder.go | 151 ++ .../server/rest_impl/experiment_impl.go | 54 + .../api_v1/server/rest_impl/health_impl.go | 25 + di/restapi/api_v1/server/rest_impl/logging.go | 106 + .../api_v1/server/rest_impl/manifest.go | 374 +++ .../api_v1/server/rest_impl/manifest_test.go | 45 + .../api_v1/server/rest_impl/models_impl.go | 2323 ++++++++++++++++ di/restapi/api_v1/server/server.go | 507 ++++ di/restapi/api_v1/swagger/swagger.yml | 863 ++++++ di/restapi/certs/ca.crt | 32 + di/restapi/certs/ca.key | 54 + di/restapi/certs/client.crt | 30 + di/restapi/certs/client.csr | 27 + di/restapi/certs/client.key | 51 + di/restapi/certs/server.crt | 30 + di/restapi/certs/server.csr | 27 + di/restapi/certs/server.key | 51 + di/restapi/main.go | 73 + di/restapi/middleware/logging.go | 167 ++ di/restapi/middleware/response_writer.go | 110 + di/restapi/service/experiment_service.go | 141 + 132 files changed, 21704 insertions(+) create mode 100644 di/restapi/Dockerfile create mode 100644 di/restapi/Makefile create mode 100644 di/restapi/api_v1/client/dlaas_client.go create mode 100644 di/restapi/api_v1/client/events/create_event_endpoint_parameters.go create mode 100644 di/restapi/api_v1/client/events/create_event_endpoint_responses.go create mode 100644 di/restapi/api_v1/client/events/delete_event_endpoint_parameters.go create mode 100644 di/restapi/api_v1/client/events/delete_event_endpoint_responses.go create mode 100644 di/restapi/api_v1/client/events/events_client.go create mode 100644 di/restapi/api_v1/client/events/get_event_endpoint_parameters.go create mode 100644 di/restapi/api_v1/client/events/get_event_endpoint_responses.go create mode 100644 di/restapi/api_v1/client/events/get_event_type_endpoints_parameters.go create mode 100644 di/restapi/api_v1/client/events/get_event_type_endpoints_responses.go create mode 100644 di/restapi/api_v1/client/models/delete_model_parameters.go create mode 100644 di/restapi/api_v1/client/models/delete_model_responses.go create mode 100644 di/restapi/api_v1/client/models/download_model_definition_parameters.go create mode 100644 di/restapi/api_v1/client/models/download_model_definition_responses.go create mode 100644 di/restapi/api_v1/client/models/download_trained_model_parameters.go create mode 100644 di/restapi/api_v1/client/models/download_trained_model_responses.go create mode 100644 di/restapi/api_v1/client/models/get_logs_parameters.go create mode 100644 di/restapi/api_v1/client/models/get_logs_responses.go create mode 100644 di/restapi/api_v1/client/models/get_metrics_parameters.go create mode 100644 di/restapi/api_v1/client/models/get_metrics_responses.go create mode 100644 di/restapi/api_v1/client/models/get_model_parameters.go create mode 100644 di/restapi/api_v1/client/models/get_model_responses.go create mode 100644 di/restapi/api_v1/client/models/list_models_parameters.go create mode 100644 di/restapi/api_v1/client/models/list_models_responses.go create mode 100644 di/restapi/api_v1/client/models/models_client.go create mode 100644 di/restapi/api_v1/client/models/patch_model_parameters.go create mode 100644 di/restapi/api_v1/client/models/patch_model_responses.go create mode 100644 di/restapi/api_v1/client/models/post_model_parameters.go create mode 100644 di/restapi/api_v1/client/models/post_model_responses.go create mode 100644 di/restapi/api_v1/client/operations/get_dashboards_parameters.go create mode 100644 di/restapi/api_v1/client/operations/get_dashboards_responses.go create mode 100644 di/restapi/api_v1/client/operations/operations_client.go create mode 100644 di/restapi/api_v1/client/training_data/get_loglines_parameters.go create mode 100644 di/restapi/api_v1/client/training_data/get_loglines_responses.go create mode 100644 di/restapi/api_v1/client/training_data/training_data_client.go create mode 100644 di/restapi/api_v1/restmodels/basic_model.go create mode 100644 di/restapi/api_v1/restmodels/basic_new_model.go create mode 100644 di/restapi/api_v1/restmodels/code_upload_response.go create mode 100644 di/restapi/api_v1/restmodels/datastore.go create mode 100644 di/restapi/api_v1/restmodels/endpoint.go create mode 100644 di/restapi/api_v1/restmodels/endpoint_list.go create mode 100644 di/restapi/api_v1/restmodels/error.go create mode 100644 di/restapi/api_v1/restmodels/event_endpoint_registration.go create mode 100644 di/restapi/api_v1/restmodels/fields.go create mode 100644 di/restapi/api_v1/restmodels/framework.go create mode 100644 di/restapi/api_v1/restmodels/get_dashboards_response.go create mode 100644 di/restapi/api_v1/restmodels/metric_data.go create mode 100644 di/restapi/api_v1/restmodels/model.go create mode 100644 di/restapi/api_v1/restmodels/model_list.go create mode 100644 di/restapi/api_v1/restmodels/query_search_type.go create mode 100644 di/restapi/api_v1/restmodels/t_fos_request.go create mode 100644 di/restapi/api_v1/restmodels/training.go create mode 100644 di/restapi/api_v1/restmodels/training_status.go create mode 100644 di/restapi/api_v1/restmodels/training_update.go create mode 100644 di/restapi/api_v1/restmodels/user.go create mode 100644 di/restapi/api_v1/restmodels/v1_log_line.go create mode 100644 di/restapi/api_v1/restmodels/v1_log_lines_list.go create mode 100644 di/restapi/api_v1/restmodels/v1_meta_info.go create mode 100644 di/restapi/api_v1/server/configure_di.go create mode 100644 di/restapi/api_v1/server/doc.go create mode 100644 di/restapi/api_v1/server/embedded_spec.go create mode 100644 di/restapi/api_v1/server/operations/di_api.go create mode 100644 di/restapi/api_v1/server/operations/experiments/code_upload.go create mode 100644 di/restapi/api_v1/server/operations/experiments/code_upload_parameters.go create mode 100644 di/restapi/api_v1/server/operations/experiments/code_upload_responses.go create mode 100644 di/restapi/api_v1/server/operations/experiments/code_upload_urlbuilder.go create mode 100644 di/restapi/api_v1/server/operations/get_dashboards.go create mode 100644 di/restapi/api_v1/server/operations/get_dashboards_parameters.go create mode 100644 di/restapi/api_v1/server/operations/get_dashboards_responses.go create mode 100644 di/restapi/api_v1/server/operations/get_dashboards_urlbuilder.go create mode 100644 di/restapi/api_v1/server/operations/models/delete_model.go create mode 100644 di/restapi/api_v1/server/operations/models/delete_model_parameters.go create mode 100644 di/restapi/api_v1/server/operations/models/delete_model_responses.go create mode 100644 di/restapi/api_v1/server/operations/models/delete_model_urlbuilder.go create mode 100644 di/restapi/api_v1/server/operations/models/download_model_definition.go create mode 100644 di/restapi/api_v1/server/operations/models/download_model_definition_parameters.go create mode 100644 di/restapi/api_v1/server/operations/models/download_model_definition_responses.go create mode 100644 di/restapi/api_v1/server/operations/models/download_model_definition_urlbuilder.go create mode 100644 di/restapi/api_v1/server/operations/models/download_trained_model.go create mode 100644 di/restapi/api_v1/server/operations/models/download_trained_model_parameters.go create mode 100644 di/restapi/api_v1/server/operations/models/download_trained_model_responses.go create mode 100644 di/restapi/api_v1/server/operations/models/download_trained_model_urlbuilder.go create mode 100644 di/restapi/api_v1/server/operations/models/export_model.go create mode 100644 di/restapi/api_v1/server/operations/models/export_model_parameters.go create mode 100644 di/restapi/api_v1/server/operations/models/export_model_responses.go create mode 100644 di/restapi/api_v1/server/operations/models/export_model_urlbuilder.go create mode 100644 di/restapi/api_v1/server/operations/models/get_logs.go create mode 100644 di/restapi/api_v1/server/operations/models/get_logs_parameters.go create mode 100644 di/restapi/api_v1/server/operations/models/get_logs_responses.go create mode 100644 di/restapi/api_v1/server/operations/models/get_logs_urlbuilder.go create mode 100644 di/restapi/api_v1/server/operations/models/get_model.go create mode 100644 di/restapi/api_v1/server/operations/models/get_model_parameters.go create mode 100644 di/restapi/api_v1/server/operations/models/get_model_responses.go create mode 100644 di/restapi/api_v1/server/operations/models/get_model_urlbuilder.go create mode 100644 di/restapi/api_v1/server/operations/models/list_models.go create mode 100644 di/restapi/api_v1/server/operations/models/list_models_parameters.go create mode 100644 di/restapi/api_v1/server/operations/models/list_models_responses.go create mode 100644 di/restapi/api_v1/server/operations/models/list_models_urlbuilder.go create mode 100644 di/restapi/api_v1/server/operations/models/patch_model.go create mode 100644 di/restapi/api_v1/server/operations/models/patch_model_parameters.go create mode 100644 di/restapi/api_v1/server/operations/models/patch_model_responses.go create mode 100644 di/restapi/api_v1/server/operations/models/patch_model_urlbuilder.go create mode 100644 di/restapi/api_v1/server/operations/models/post_model.go create mode 100644 di/restapi/api_v1/server/operations/models/post_model_parameters.go create mode 100644 di/restapi/api_v1/server/operations/models/post_model_responses.go create mode 100644 di/restapi/api_v1/server/operations/models/post_model_urlbuilder.go create mode 100644 di/restapi/api_v1/server/operations/training_data/get_loglines.go create mode 100644 di/restapi/api_v1/server/operations/training_data/get_loglines_parameters.go create mode 100644 di/restapi/api_v1/server/operations/training_data/get_loglines_responses.go create mode 100644 di/restapi/api_v1/server/operations/training_data/get_loglines_urlbuilder.go create mode 100644 di/restapi/api_v1/server/rest_impl/experiment_impl.go create mode 100644 di/restapi/api_v1/server/rest_impl/health_impl.go create mode 100644 di/restapi/api_v1/server/rest_impl/logging.go create mode 100644 di/restapi/api_v1/server/rest_impl/manifest.go create mode 100644 di/restapi/api_v1/server/rest_impl/manifest_test.go create mode 100644 di/restapi/api_v1/server/rest_impl/models_impl.go create mode 100644 di/restapi/api_v1/server/server.go create mode 100644 di/restapi/api_v1/swagger/swagger.yml create mode 100644 di/restapi/certs/ca.crt create mode 100644 di/restapi/certs/ca.key create mode 100644 di/restapi/certs/client.crt create mode 100644 di/restapi/certs/client.csr create mode 100644 di/restapi/certs/client.key create mode 100644 di/restapi/certs/server.crt create mode 100644 di/restapi/certs/server.csr create mode 100644 di/restapi/certs/server.key create mode 100644 di/restapi/main.go create mode 100644 di/restapi/middleware/logging.go create mode 100644 di/restapi/middleware/response_writer.go create mode 100644 di/restapi/service/experiment_service.go diff --git a/di/restapi/Dockerfile b/di/restapi/Dockerfile new file mode 100644 index 0000000..21993d3 --- /dev/null +++ b/di/restapi/Dockerfile @@ -0,0 +1,34 @@ +# +# Copyright 2017-2018 IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +# FROM dlaas-service-base:ubuntu16.04 +#FROM ffdl/ffdl-restapi:v0.1.1 +#FROM ubuntu:latest +FROM golang-dlv:latest + +# switch to root +USER root + +ADD bin/main / +ADD certs/* /etc/ssl/dlaas/ +ADD ./* /MLSS-DI-GPU/restapi/ +RUN chmod 755 /main + +# assign "random" non-root user id +#USER 6342627 + +ENTRYPOINT ["/main"] diff --git a/di/restapi/Makefile b/di/restapi/Makefile new file mode 100644 index 0000000..56369de --- /dev/null +++ b/di/restapi/Makefile @@ -0,0 +1,2 @@ +gen-swagger: + swagger generate server -m restmodels -f restapi/api_v1/swagger/swagger.yml -t restapi/api_v1/ -A dlaas -s server --exclude-main \ No newline at end of file diff --git a/di/restapi/api_v1/client/dlaas_client.go b/di/restapi/api_v1/client/dlaas_client.go new file mode 100644 index 0000000..3ee8d32 --- /dev/null +++ b/di/restapi/api_v1/client/dlaas_client.go @@ -0,0 +1,129 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package client + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/runtime" + httptransport "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/client/events" + "webank/DI/restapi/api_v1/client/models" + "webank/DI/restapi/api_v1/client/training_data" +) + +// Default dlaas HTTP client. +var Default = NewHTTPClient(nil) + +const ( + // DefaultHost is the default Host + // found in Meta (info) section of spec file + DefaultHost string = "gateway.watsonplatform.net" + // DefaultBasePath is the default BasePath + // found in Meta (info) section of spec file + DefaultBasePath string = "/di" +) + +// DefaultSchemes are the default schemes found in Meta (info) section of spec file +var DefaultSchemes = []string{"https"} + +// NewHTTPClient creates a new dlaas HTTP client. +func NewHTTPClient(formats strfmt.Registry) *Dlaas { + return NewHTTPClientWithConfig(formats, nil) +} + +// NewHTTPClientWithConfig creates a new dlaas HTTP client, +// using a customizable transport config. +func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *Dlaas { + // ensure nullable parameters have default + if formats == nil { + formats = strfmt.Default + } + if cfg == nil { + cfg = DefaultTransportConfig() + } + + // create transport and client + transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes) + return New(transport, formats) +} + +// New creates a new dlaas client +func New(transport runtime.ClientTransport, formats strfmt.Registry) *Dlaas { + cli := new(Dlaas) + cli.Transport = transport + + cli.Events = events.New(transport, formats) + + cli.Models = models.New(transport, formats) + + cli.TrainingData = training_data.New(transport, formats) + + return cli +} + +// DefaultTransportConfig creates a TransportConfig with the +// default settings taken from the meta section of the spec file. +func DefaultTransportConfig() *TransportConfig { + return &TransportConfig{ + Host: DefaultHost, + BasePath: DefaultBasePath, + Schemes: DefaultSchemes, + } +} + +// TransportConfig contains the transport related info, +// found in the meta section of the spec file. +type TransportConfig struct { + Host string + BasePath string + Schemes []string +} + +// WithHost overrides the default host, +// provided by the meta section of the spec file. +func (cfg *TransportConfig) WithHost(host string) *TransportConfig { + cfg.Host = host + return cfg +} + +// WithBasePath overrides the default basePath, +// provided by the meta section of the spec file. +func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig { + cfg.BasePath = basePath + return cfg +} + +// WithSchemes overrides the default schemes, +// provided by the meta section of the spec file. +func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig { + cfg.Schemes = schemes + return cfg +} + +// Dlaas is a client for dlaas +type Dlaas struct { + Events *events.Client + + Models *models.Client + + TrainingData *training_data.Client + + Transport runtime.ClientTransport +} + +// SetTransport changes the transport on the client and all its subresources +func (c *Dlaas) SetTransport(transport runtime.ClientTransport) { + c.Transport = transport + + c.Events.SetTransport(transport) + + c.Models.SetTransport(transport) + + c.TrainingData.SetTransport(transport) + +} diff --git a/di/restapi/api_v1/client/events/create_event_endpoint_parameters.go b/di/restapi/api_v1/client/events/create_event_endpoint_parameters.go new file mode 100644 index 0000000..3fe33da --- /dev/null +++ b/di/restapi/api_v1/client/events/create_event_endpoint_parameters.go @@ -0,0 +1,205 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package events + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// NewCreateEventEndpointParams creates a new CreateEventEndpointParams object +// with the default values initialized. +func NewCreateEventEndpointParams() *CreateEventEndpointParams { + var () + return &CreateEventEndpointParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewCreateEventEndpointParamsWithTimeout creates a new CreateEventEndpointParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewCreateEventEndpointParamsWithTimeout(timeout time.Duration) *CreateEventEndpointParams { + var () + return &CreateEventEndpointParams{ + + timeout: timeout, + } +} + +// NewCreateEventEndpointParamsWithContext creates a new CreateEventEndpointParams object +// with the default values initialized, and the ability to set a context for a request +func NewCreateEventEndpointParamsWithContext(ctx context.Context) *CreateEventEndpointParams { + var () + return &CreateEventEndpointParams{ + + Context: ctx, + } +} + +// NewCreateEventEndpointParamsWithHTTPClient creates a new CreateEventEndpointParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewCreateEventEndpointParamsWithHTTPClient(client *http.Client) *CreateEventEndpointParams { + var () + return &CreateEventEndpointParams{ + HTTPClient: client, + } +} + +/*CreateEventEndpointParams contains all the parameters to send to the API endpoint +for the create event endpoint operation typically these are written to a http.Request +*/ +type CreateEventEndpointParams struct { + + /*CallbackURL + The URL that should be notified when an event triggers. + + */ + CallbackURL *restmodels.EventEndpointRegistration + /*EndpointID + The id of the endpoint. + + */ + EndpointID string + /*EventType + The type of event. + + */ + EventType string + /*ModelID + The id of the model. + + */ + ModelID string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the create event endpoint params +func (o *CreateEventEndpointParams) WithTimeout(timeout time.Duration) *CreateEventEndpointParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the create event endpoint params +func (o *CreateEventEndpointParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the create event endpoint params +func (o *CreateEventEndpointParams) WithContext(ctx context.Context) *CreateEventEndpointParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the create event endpoint params +func (o *CreateEventEndpointParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the create event endpoint params +func (o *CreateEventEndpointParams) WithHTTPClient(client *http.Client) *CreateEventEndpointParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the create event endpoint params +func (o *CreateEventEndpointParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithCallbackURL adds the callbackURL to the create event endpoint params +func (o *CreateEventEndpointParams) WithCallbackURL(callbackURL *restmodels.EventEndpointRegistration) *CreateEventEndpointParams { + o.SetCallbackURL(callbackURL) + return o +} + +// SetCallbackURL adds the callbackUrl to the create event endpoint params +func (o *CreateEventEndpointParams) SetCallbackURL(callbackURL *restmodels.EventEndpointRegistration) { + o.CallbackURL = callbackURL +} + +// WithEndpointID adds the endpointID to the create event endpoint params +func (o *CreateEventEndpointParams) WithEndpointID(endpointID string) *CreateEventEndpointParams { + o.SetEndpointID(endpointID) + return o +} + +// SetEndpointID adds the endpointId to the create event endpoint params +func (o *CreateEventEndpointParams) SetEndpointID(endpointID string) { + o.EndpointID = endpointID +} + +// WithEventType adds the eventType to the create event endpoint params +func (o *CreateEventEndpointParams) WithEventType(eventType string) *CreateEventEndpointParams { + o.SetEventType(eventType) + return o +} + +// SetEventType adds the eventType to the create event endpoint params +func (o *CreateEventEndpointParams) SetEventType(eventType string) { + o.EventType = eventType +} + +// WithModelID adds the modelID to the create event endpoint params +func (o *CreateEventEndpointParams) WithModelID(modelID string) *CreateEventEndpointParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the create event endpoint params +func (o *CreateEventEndpointParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WriteToRequest writes these params to a swagger request +func (o *CreateEventEndpointParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if o.CallbackURL == nil { + o.CallbackURL = new(restmodels.EventEndpointRegistration) + } + + if err := r.SetBodyParam(o.CallbackURL); err != nil { + return err + } + + // path param endpoint_id + if err := r.SetPathParam("endpoint_id", o.EndpointID); err != nil { + return err + } + + // path param event_type + if err := r.SetPathParam("event_type", o.EventType); err != nil { + return err + } + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/events/create_event_endpoint_responses.go b/di/restapi/api_v1/client/events/create_event_endpoint_responses.go new file mode 100644 index 0000000..05a844c --- /dev/null +++ b/di/restapi/api_v1/client/events/create_event_endpoint_responses.go @@ -0,0 +1,176 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package events + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// CreateEventEndpointReader is a Reader for the CreateEventEndpoint structure. +type CreateEventEndpointReader struct { + formats strfmt.Registry + writer io.Writer +} + +// ReadResponse reads a server response into the received o. +func (o *CreateEventEndpointReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewCreateEventEndpointOK(o.writer) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewCreateEventEndpointUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewCreateEventEndpointNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 410: + result := NewCreateEventEndpointGone() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewCreateEventEndpointOK creates a CreateEventEndpointOK with default headers values +func NewCreateEventEndpointOK(writer io.Writer) *CreateEventEndpointOK { + return &CreateEventEndpointOK{ + Payload: writer, + } +} + +/*CreateEventEndpointOK handles this case with default header values. + +Event updated successfully +*/ +type CreateEventEndpointOK struct { + Payload io.Writer +} + +func (o *CreateEventEndpointOK) Error() string { + return fmt.Sprintf("[POST /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] createEventEndpointOK %+v", 200, o.Payload) +} + +func (o *CreateEventEndpointOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewCreateEventEndpointUnauthorized creates a CreateEventEndpointUnauthorized with default headers values +func NewCreateEventEndpointUnauthorized() *CreateEventEndpointUnauthorized { + return &CreateEventEndpointUnauthorized{} +} + +/*CreateEventEndpointUnauthorized handles this case with default header values. + +Unauthorized +*/ +type CreateEventEndpointUnauthorized struct { + Payload *restmodels.Error +} + +func (o *CreateEventEndpointUnauthorized) Error() string { + return fmt.Sprintf("[POST /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] createEventEndpointUnauthorized %+v", 401, o.Payload) +} + +func (o *CreateEventEndpointUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewCreateEventEndpointNotFound creates a CreateEventEndpointNotFound with default headers values +func NewCreateEventEndpointNotFound() *CreateEventEndpointNotFound { + return &CreateEventEndpointNotFound{} +} + +/*CreateEventEndpointNotFound handles this case with default header values. + +The model or event type cannot be found. +*/ +type CreateEventEndpointNotFound struct { + Payload *restmodels.Error +} + +func (o *CreateEventEndpointNotFound) Error() string { + return fmt.Sprintf("[POST /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] createEventEndpointNotFound %+v", 404, o.Payload) +} + +func (o *CreateEventEndpointNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewCreateEventEndpointGone creates a CreateEventEndpointGone with default headers values +func NewCreateEventEndpointGone() *CreateEventEndpointGone { + return &CreateEventEndpointGone{} +} + +/*CreateEventEndpointGone handles this case with default header values. + +If the trained model storage time has expired and it has been deleted. It only gets deleted if it not stored on an external data store. +*/ +type CreateEventEndpointGone struct { + Payload *restmodels.Error +} + +func (o *CreateEventEndpointGone) Error() string { + return fmt.Sprintf("[POST /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] createEventEndpointGone %+v", 410, o.Payload) +} + +func (o *CreateEventEndpointGone) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/events/delete_event_endpoint_parameters.go b/di/restapi/api_v1/client/events/delete_event_endpoint_parameters.go new file mode 100644 index 0000000..9e0e36c --- /dev/null +++ b/di/restapi/api_v1/client/events/delete_event_endpoint_parameters.go @@ -0,0 +1,179 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package events + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewDeleteEventEndpointParams creates a new DeleteEventEndpointParams object +// with the default values initialized. +func NewDeleteEventEndpointParams() *DeleteEventEndpointParams { + var () + return &DeleteEventEndpointParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewDeleteEventEndpointParamsWithTimeout creates a new DeleteEventEndpointParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewDeleteEventEndpointParamsWithTimeout(timeout time.Duration) *DeleteEventEndpointParams { + var () + return &DeleteEventEndpointParams{ + + timeout: timeout, + } +} + +// NewDeleteEventEndpointParamsWithContext creates a new DeleteEventEndpointParams object +// with the default values initialized, and the ability to set a context for a request +func NewDeleteEventEndpointParamsWithContext(ctx context.Context) *DeleteEventEndpointParams { + var () + return &DeleteEventEndpointParams{ + + Context: ctx, + } +} + +// NewDeleteEventEndpointParamsWithHTTPClient creates a new DeleteEventEndpointParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewDeleteEventEndpointParamsWithHTTPClient(client *http.Client) *DeleteEventEndpointParams { + var () + return &DeleteEventEndpointParams{ + HTTPClient: client, + } +} + +/*DeleteEventEndpointParams contains all the parameters to send to the API endpoint +for the delete event endpoint operation typically these are written to a http.Request +*/ +type DeleteEventEndpointParams struct { + + /*EndpointID + The id of the endpoint. + + */ + EndpointID string + /*EventType + The type of event. + + */ + EventType string + /*ModelID + The id of the model. + + */ + ModelID string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the delete event endpoint params +func (o *DeleteEventEndpointParams) WithTimeout(timeout time.Duration) *DeleteEventEndpointParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the delete event endpoint params +func (o *DeleteEventEndpointParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the delete event endpoint params +func (o *DeleteEventEndpointParams) WithContext(ctx context.Context) *DeleteEventEndpointParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the delete event endpoint params +func (o *DeleteEventEndpointParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the delete event endpoint params +func (o *DeleteEventEndpointParams) WithHTTPClient(client *http.Client) *DeleteEventEndpointParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the delete event endpoint params +func (o *DeleteEventEndpointParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithEndpointID adds the endpointID to the delete event endpoint params +func (o *DeleteEventEndpointParams) WithEndpointID(endpointID string) *DeleteEventEndpointParams { + o.SetEndpointID(endpointID) + return o +} + +// SetEndpointID adds the endpointId to the delete event endpoint params +func (o *DeleteEventEndpointParams) SetEndpointID(endpointID string) { + o.EndpointID = endpointID +} + +// WithEventType adds the eventType to the delete event endpoint params +func (o *DeleteEventEndpointParams) WithEventType(eventType string) *DeleteEventEndpointParams { + o.SetEventType(eventType) + return o +} + +// SetEventType adds the eventType to the delete event endpoint params +func (o *DeleteEventEndpointParams) SetEventType(eventType string) { + o.EventType = eventType +} + +// WithModelID adds the modelID to the delete event endpoint params +func (o *DeleteEventEndpointParams) WithModelID(modelID string) *DeleteEventEndpointParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the delete event endpoint params +func (o *DeleteEventEndpointParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WriteToRequest writes these params to a swagger request +func (o *DeleteEventEndpointParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param endpoint_id + if err := r.SetPathParam("endpoint_id", o.EndpointID); err != nil { + return err + } + + // path param event_type + if err := r.SetPathParam("event_type", o.EventType); err != nil { + return err + } + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/events/delete_event_endpoint_responses.go b/di/restapi/api_v1/client/events/delete_event_endpoint_responses.go new file mode 100644 index 0000000..bee1ca5 --- /dev/null +++ b/di/restapi/api_v1/client/events/delete_event_endpoint_responses.go @@ -0,0 +1,176 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package events + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// DeleteEventEndpointReader is a Reader for the DeleteEventEndpoint structure. +type DeleteEventEndpointReader struct { + formats strfmt.Registry + writer io.Writer +} + +// ReadResponse reads a server response into the received o. +func (o *DeleteEventEndpointReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewDeleteEventEndpointOK(o.writer) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewDeleteEventEndpointUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewDeleteEventEndpointNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 410: + result := NewDeleteEventEndpointGone() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewDeleteEventEndpointOK creates a DeleteEventEndpointOK with default headers values +func NewDeleteEventEndpointOK(writer io.Writer) *DeleteEventEndpointOK { + return &DeleteEventEndpointOK{ + Payload: writer, + } +} + +/*DeleteEventEndpointOK handles this case with default header values. + +Event updated successfully +*/ +type DeleteEventEndpointOK struct { + Payload io.Writer +} + +func (o *DeleteEventEndpointOK) Error() string { + return fmt.Sprintf("[DELETE /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] deleteEventEndpointOK %+v", 200, o.Payload) +} + +func (o *DeleteEventEndpointOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDeleteEventEndpointUnauthorized creates a DeleteEventEndpointUnauthorized with default headers values +func NewDeleteEventEndpointUnauthorized() *DeleteEventEndpointUnauthorized { + return &DeleteEventEndpointUnauthorized{} +} + +/*DeleteEventEndpointUnauthorized handles this case with default header values. + +Unauthorized +*/ +type DeleteEventEndpointUnauthorized struct { + Payload *restmodels.Error +} + +func (o *DeleteEventEndpointUnauthorized) Error() string { + return fmt.Sprintf("[DELETE /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] deleteEventEndpointUnauthorized %+v", 401, o.Payload) +} + +func (o *DeleteEventEndpointUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDeleteEventEndpointNotFound creates a DeleteEventEndpointNotFound with default headers values +func NewDeleteEventEndpointNotFound() *DeleteEventEndpointNotFound { + return &DeleteEventEndpointNotFound{} +} + +/*DeleteEventEndpointNotFound handles this case with default header values. + +The model or event type cannot be found. +*/ +type DeleteEventEndpointNotFound struct { + Payload *restmodels.Error +} + +func (o *DeleteEventEndpointNotFound) Error() string { + return fmt.Sprintf("[DELETE /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] deleteEventEndpointNotFound %+v", 404, o.Payload) +} + +func (o *DeleteEventEndpointNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDeleteEventEndpointGone creates a DeleteEventEndpointGone with default headers values +func NewDeleteEventEndpointGone() *DeleteEventEndpointGone { + return &DeleteEventEndpointGone{} +} + +/*DeleteEventEndpointGone handles this case with default header values. + +If the trained model storage time has expired and it has been deleted. It only gets deleted if it not stored on an external data store. +*/ +type DeleteEventEndpointGone struct { + Payload *restmodels.Error +} + +func (o *DeleteEventEndpointGone) Error() string { + return fmt.Sprintf("[DELETE /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] deleteEventEndpointGone %+v", 410, o.Payload) +} + +func (o *DeleteEventEndpointGone) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/events/events_client.go b/di/restapi/api_v1/client/events/events_client.go new file mode 100644 index 0000000..e186b1a --- /dev/null +++ b/di/restapi/api_v1/client/events/events_client.go @@ -0,0 +1,155 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package events + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" +) + +// New creates a new events API client. +func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client { + return &Client{transport: transport, formats: formats} +} + +/* +Client for events API +*/ +type Client struct { + transport runtime.ClientTransport + formats strfmt.Registry +} + +/* +CreateEventEndpoint creates an event notification endpoint + +Creates a specific event type's URL notification endpoint. +*/ +func (a *Client) CreateEventEndpoint(params *CreateEventEndpointParams, authInfo runtime.ClientAuthInfoWriter, writer io.Writer) (*CreateEventEndpointOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewCreateEventEndpointParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "createEventEndpoint", + Method: "POST", + PathPattern: "/v1/models/{model_id}/events/{event_type}/{endpoint_id}", + ProducesMediaTypes: []string{"application/octet-stream"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &CreateEventEndpointReader{formats: a.formats, writer: writer}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*CreateEventEndpointOK), nil + +} + +/* +DeleteEventEndpoint deletes an event notification endpoint + +Deletes a specific event type's URL notification endpoint. +*/ +func (a *Client) DeleteEventEndpoint(params *DeleteEventEndpointParams, authInfo runtime.ClientAuthInfoWriter, writer io.Writer) (*DeleteEventEndpointOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewDeleteEventEndpointParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "deleteEventEndpoint", + Method: "DELETE", + PathPattern: "/v1/models/{model_id}/events/{event_type}/{endpoint_id}", + ProducesMediaTypes: []string{"application/octet-stream"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &DeleteEventEndpointReader{formats: a.formats, writer: writer}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*DeleteEventEndpointOK), nil + +} + +/* +GetEventEndpoint gets endpoint description + +Get a specific endpoint description. +*/ +func (a *Client) GetEventEndpoint(params *GetEventEndpointParams, authInfo runtime.ClientAuthInfoWriter) (*GetEventEndpointOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetEventEndpointParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "getEventEndpoint", + Method: "GET", + PathPattern: "/v1/models/{model_id}/events/{event_type}/{endpoint_id}", + ProducesMediaTypes: []string{"application/octet-stream"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &GetEventEndpointReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*GetEventEndpointOK), nil + +} + +/* +GetEventTypeEndpoints gets all notification endpoints for this event type + +Get all notification endpoint URLs for this event type. +*/ +func (a *Client) GetEventTypeEndpoints(params *GetEventTypeEndpointsParams) (*GetEventTypeEndpointsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetEventTypeEndpointsParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "getEventTypeEndpoints", + Method: "GET", + PathPattern: "/v1/models/{model_id}/events/{event_type}", + ProducesMediaTypes: []string{"application/octet-stream"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &GetEventTypeEndpointsReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*GetEventTypeEndpointsOK), nil + +} + +// SetTransport changes the transport on the client +func (a *Client) SetTransport(transport runtime.ClientTransport) { + a.transport = transport +} diff --git a/di/restapi/api_v1/client/events/get_event_endpoint_parameters.go b/di/restapi/api_v1/client/events/get_event_endpoint_parameters.go new file mode 100644 index 0000000..29916e0 --- /dev/null +++ b/di/restapi/api_v1/client/events/get_event_endpoint_parameters.go @@ -0,0 +1,179 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package events + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetEventEndpointParams creates a new GetEventEndpointParams object +// with the default values initialized. +func NewGetEventEndpointParams() *GetEventEndpointParams { + var () + return &GetEventEndpointParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewGetEventEndpointParamsWithTimeout creates a new GetEventEndpointParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetEventEndpointParamsWithTimeout(timeout time.Duration) *GetEventEndpointParams { + var () + return &GetEventEndpointParams{ + + timeout: timeout, + } +} + +// NewGetEventEndpointParamsWithContext creates a new GetEventEndpointParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetEventEndpointParamsWithContext(ctx context.Context) *GetEventEndpointParams { + var () + return &GetEventEndpointParams{ + + Context: ctx, + } +} + +// NewGetEventEndpointParamsWithHTTPClient creates a new GetEventEndpointParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetEventEndpointParamsWithHTTPClient(client *http.Client) *GetEventEndpointParams { + var () + return &GetEventEndpointParams{ + HTTPClient: client, + } +} + +/*GetEventEndpointParams contains all the parameters to send to the API endpoint +for the get event endpoint operation typically these are written to a http.Request +*/ +type GetEventEndpointParams struct { + + /*EndpointID + The id of the endpoint. + + */ + EndpointID string + /*EventType + The type of event. + + */ + EventType string + /*ModelID + The id of the model. + + */ + ModelID string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get event endpoint params +func (o *GetEventEndpointParams) WithTimeout(timeout time.Duration) *GetEventEndpointParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get event endpoint params +func (o *GetEventEndpointParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get event endpoint params +func (o *GetEventEndpointParams) WithContext(ctx context.Context) *GetEventEndpointParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get event endpoint params +func (o *GetEventEndpointParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get event endpoint params +func (o *GetEventEndpointParams) WithHTTPClient(client *http.Client) *GetEventEndpointParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get event endpoint params +func (o *GetEventEndpointParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithEndpointID adds the endpointID to the get event endpoint params +func (o *GetEventEndpointParams) WithEndpointID(endpointID string) *GetEventEndpointParams { + o.SetEndpointID(endpointID) + return o +} + +// SetEndpointID adds the endpointId to the get event endpoint params +func (o *GetEventEndpointParams) SetEndpointID(endpointID string) { + o.EndpointID = endpointID +} + +// WithEventType adds the eventType to the get event endpoint params +func (o *GetEventEndpointParams) WithEventType(eventType string) *GetEventEndpointParams { + o.SetEventType(eventType) + return o +} + +// SetEventType adds the eventType to the get event endpoint params +func (o *GetEventEndpointParams) SetEventType(eventType string) { + o.EventType = eventType +} + +// WithModelID adds the modelID to the get event endpoint params +func (o *GetEventEndpointParams) WithModelID(modelID string) *GetEventEndpointParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the get event endpoint params +func (o *GetEventEndpointParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WriteToRequest writes these params to a swagger request +func (o *GetEventEndpointParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param endpoint_id + if err := r.SetPathParam("endpoint_id", o.EndpointID); err != nil { + return err + } + + // path param event_type + if err := r.SetPathParam("event_type", o.EventType); err != nil { + return err + } + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/events/get_event_endpoint_responses.go b/di/restapi/api_v1/client/events/get_event_endpoint_responses.go new file mode 100644 index 0000000..455d1a7 --- /dev/null +++ b/di/restapi/api_v1/client/events/get_event_endpoint_responses.go @@ -0,0 +1,175 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package events + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// GetEventEndpointReader is a Reader for the GetEventEndpoint structure. +type GetEventEndpointReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetEventEndpointReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewGetEventEndpointOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewGetEventEndpointUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewGetEventEndpointNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 410: + result := NewGetEventEndpointGone() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewGetEventEndpointOK creates a GetEventEndpointOK with default headers values +func NewGetEventEndpointOK() *GetEventEndpointOK { + return &GetEventEndpointOK{} +} + +/*GetEventEndpointOK handles this case with default header values. + +Event description +*/ +type GetEventEndpointOK struct { + Payload *restmodels.Endpoint +} + +func (o *GetEventEndpointOK) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] getEventEndpointOK %+v", 200, o.Payload) +} + +func (o *GetEventEndpointOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Endpoint) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetEventEndpointUnauthorized creates a GetEventEndpointUnauthorized with default headers values +func NewGetEventEndpointUnauthorized() *GetEventEndpointUnauthorized { + return &GetEventEndpointUnauthorized{} +} + +/*GetEventEndpointUnauthorized handles this case with default header values. + +Unauthorized +*/ +type GetEventEndpointUnauthorized struct { + Payload *restmodels.Error +} + +func (o *GetEventEndpointUnauthorized) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] getEventEndpointUnauthorized %+v", 401, o.Payload) +} + +func (o *GetEventEndpointUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetEventEndpointNotFound creates a GetEventEndpointNotFound with default headers values +func NewGetEventEndpointNotFound() *GetEventEndpointNotFound { + return &GetEventEndpointNotFound{} +} + +/*GetEventEndpointNotFound handles this case with default header values. + +The model or event type cannot be found. +*/ +type GetEventEndpointNotFound struct { + Payload *restmodels.Error +} + +func (o *GetEventEndpointNotFound) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] getEventEndpointNotFound %+v", 404, o.Payload) +} + +func (o *GetEventEndpointNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetEventEndpointGone creates a GetEventEndpointGone with default headers values +func NewGetEventEndpointGone() *GetEventEndpointGone { + return &GetEventEndpointGone{} +} + +/*GetEventEndpointGone handles this case with default header values. + +If the trained model storage time has expired and it has been deleted. It only gets deleted if it not stored on an external data store. +*/ +type GetEventEndpointGone struct { + Payload *restmodels.Error +} + +func (o *GetEventEndpointGone) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/events/{event_type}/{endpoint_id}][%d] getEventEndpointGone %+v", 410, o.Payload) +} + +func (o *GetEventEndpointGone) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/events/get_event_type_endpoints_parameters.go b/di/restapi/api_v1/client/events/get_event_type_endpoints_parameters.go new file mode 100644 index 0000000..d773364 --- /dev/null +++ b/di/restapi/api_v1/client/events/get_event_type_endpoints_parameters.go @@ -0,0 +1,158 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package events + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetEventTypeEndpointsParams creates a new GetEventTypeEndpointsParams object +// with the default values initialized. +func NewGetEventTypeEndpointsParams() *GetEventTypeEndpointsParams { + var () + return &GetEventTypeEndpointsParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewGetEventTypeEndpointsParamsWithTimeout creates a new GetEventTypeEndpointsParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetEventTypeEndpointsParamsWithTimeout(timeout time.Duration) *GetEventTypeEndpointsParams { + var () + return &GetEventTypeEndpointsParams{ + + timeout: timeout, + } +} + +// NewGetEventTypeEndpointsParamsWithContext creates a new GetEventTypeEndpointsParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetEventTypeEndpointsParamsWithContext(ctx context.Context) *GetEventTypeEndpointsParams { + var () + return &GetEventTypeEndpointsParams{ + + Context: ctx, + } +} + +// NewGetEventTypeEndpointsParamsWithHTTPClient creates a new GetEventTypeEndpointsParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetEventTypeEndpointsParamsWithHTTPClient(client *http.Client) *GetEventTypeEndpointsParams { + var () + return &GetEventTypeEndpointsParams{ + HTTPClient: client, + } +} + +/*GetEventTypeEndpointsParams contains all the parameters to send to the API endpoint +for the get event type endpoints operation typically these are written to a http.Request +*/ +type GetEventTypeEndpointsParams struct { + + /*EventType + The type of event. + + */ + EventType string + /*ModelID + The id of the model. + + */ + ModelID string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get event type endpoints params +func (o *GetEventTypeEndpointsParams) WithTimeout(timeout time.Duration) *GetEventTypeEndpointsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get event type endpoints params +func (o *GetEventTypeEndpointsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get event type endpoints params +func (o *GetEventTypeEndpointsParams) WithContext(ctx context.Context) *GetEventTypeEndpointsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get event type endpoints params +func (o *GetEventTypeEndpointsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get event type endpoints params +func (o *GetEventTypeEndpointsParams) WithHTTPClient(client *http.Client) *GetEventTypeEndpointsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get event type endpoints params +func (o *GetEventTypeEndpointsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithEventType adds the eventType to the get event type endpoints params +func (o *GetEventTypeEndpointsParams) WithEventType(eventType string) *GetEventTypeEndpointsParams { + o.SetEventType(eventType) + return o +} + +// SetEventType adds the eventType to the get event type endpoints params +func (o *GetEventTypeEndpointsParams) SetEventType(eventType string) { + o.EventType = eventType +} + +// WithModelID adds the modelID to the get event type endpoints params +func (o *GetEventTypeEndpointsParams) WithModelID(modelID string) *GetEventTypeEndpointsParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the get event type endpoints params +func (o *GetEventTypeEndpointsParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WriteToRequest writes these params to a swagger request +func (o *GetEventTypeEndpointsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param event_type + if err := r.SetPathParam("event_type", o.EventType); err != nil { + return err + } + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/events/get_event_type_endpoints_responses.go b/di/restapi/api_v1/client/events/get_event_type_endpoints_responses.go new file mode 100644 index 0000000..e32fd00 --- /dev/null +++ b/di/restapi/api_v1/client/events/get_event_type_endpoints_responses.go @@ -0,0 +1,175 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package events + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// GetEventTypeEndpointsReader is a Reader for the GetEventTypeEndpoints structure. +type GetEventTypeEndpointsReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetEventTypeEndpointsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewGetEventTypeEndpointsOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewGetEventTypeEndpointsUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewGetEventTypeEndpointsNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 410: + result := NewGetEventTypeEndpointsGone() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewGetEventTypeEndpointsOK creates a GetEventTypeEndpointsOK with default headers values +func NewGetEventTypeEndpointsOK() *GetEventTypeEndpointsOK { + return &GetEventTypeEndpointsOK{} +} + +/*GetEventTypeEndpointsOK handles this case with default header values. + +Event endpoints +*/ +type GetEventTypeEndpointsOK struct { + Payload *restmodels.EndpointList +} + +func (o *GetEventTypeEndpointsOK) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/events/{event_type}][%d] getEventTypeEndpointsOK %+v", 200, o.Payload) +} + +func (o *GetEventTypeEndpointsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.EndpointList) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetEventTypeEndpointsUnauthorized creates a GetEventTypeEndpointsUnauthorized with default headers values +func NewGetEventTypeEndpointsUnauthorized() *GetEventTypeEndpointsUnauthorized { + return &GetEventTypeEndpointsUnauthorized{} +} + +/*GetEventTypeEndpointsUnauthorized handles this case with default header values. + +Unauthorized +*/ +type GetEventTypeEndpointsUnauthorized struct { + Payload *restmodels.Error +} + +func (o *GetEventTypeEndpointsUnauthorized) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/events/{event_type}][%d] getEventTypeEndpointsUnauthorized %+v", 401, o.Payload) +} + +func (o *GetEventTypeEndpointsUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetEventTypeEndpointsNotFound creates a GetEventTypeEndpointsNotFound with default headers values +func NewGetEventTypeEndpointsNotFound() *GetEventTypeEndpointsNotFound { + return &GetEventTypeEndpointsNotFound{} +} + +/*GetEventTypeEndpointsNotFound handles this case with default header values. + +The model or event type cannot be found. +*/ +type GetEventTypeEndpointsNotFound struct { + Payload *restmodels.Error +} + +func (o *GetEventTypeEndpointsNotFound) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/events/{event_type}][%d] getEventTypeEndpointsNotFound %+v", 404, o.Payload) +} + +func (o *GetEventTypeEndpointsNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetEventTypeEndpointsGone creates a GetEventTypeEndpointsGone with default headers values +func NewGetEventTypeEndpointsGone() *GetEventTypeEndpointsGone { + return &GetEventTypeEndpointsGone{} +} + +/*GetEventTypeEndpointsGone handles this case with default header values. + +If the trained model storage time has expired and it has been deleted. It only gets deleted if it not stored on an external data store. +*/ +type GetEventTypeEndpointsGone struct { + Payload *restmodels.Error +} + +func (o *GetEventTypeEndpointsGone) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/events/{event_type}][%d] getEventTypeEndpointsGone %+v", 410, o.Payload) +} + +func (o *GetEventTypeEndpointsGone) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/models/delete_model_parameters.go b/di/restapi/api_v1/client/models/delete_model_parameters.go new file mode 100644 index 0000000..3df795a --- /dev/null +++ b/di/restapi/api_v1/client/models/delete_model_parameters.go @@ -0,0 +1,174 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewDeleteModelParams creates a new DeleteModelParams object +// with the default values initialized. +func NewDeleteModelParams() *DeleteModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DeleteModelParams{ + Version: versionDefault, + + timeout: cr.DefaultTimeout, + } +} + +// NewDeleteModelParamsWithTimeout creates a new DeleteModelParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewDeleteModelParamsWithTimeout(timeout time.Duration) *DeleteModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DeleteModelParams{ + Version: versionDefault, + + timeout: timeout, + } +} + +// NewDeleteModelParamsWithContext creates a new DeleteModelParams object +// with the default values initialized, and the ability to set a context for a request +func NewDeleteModelParamsWithContext(ctx context.Context) *DeleteModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DeleteModelParams{ + Version: versionDefault, + + Context: ctx, + } +} + +// NewDeleteModelParamsWithHTTPClient creates a new DeleteModelParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewDeleteModelParamsWithHTTPClient(client *http.Client) *DeleteModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DeleteModelParams{ + Version: versionDefault, + HTTPClient: client, + } +} + +/*DeleteModelParams contains all the parameters to send to the API endpoint +for the delete model operation typically these are written to a http.Request +*/ +type DeleteModelParams struct { + + /*ModelID + The id of the model. + + */ + ModelID string + /*Version + The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + + */ + Version string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the delete model params +func (o *DeleteModelParams) WithTimeout(timeout time.Duration) *DeleteModelParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the delete model params +func (o *DeleteModelParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the delete model params +func (o *DeleteModelParams) WithContext(ctx context.Context) *DeleteModelParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the delete model params +func (o *DeleteModelParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the delete model params +func (o *DeleteModelParams) WithHTTPClient(client *http.Client) *DeleteModelParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the delete model params +func (o *DeleteModelParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithModelID adds the modelID to the delete model params +func (o *DeleteModelParams) WithModelID(modelID string) *DeleteModelParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the delete model params +func (o *DeleteModelParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WithVersion adds the version to the delete model params +func (o *DeleteModelParams) WithVersion(version string) *DeleteModelParams { + o.SetVersion(version) + return o +} + +// SetVersion adds the version to the delete model params +func (o *DeleteModelParams) SetVersion(version string) { + o.Version = version +} + +// WriteToRequest writes these params to a swagger request +func (o *DeleteModelParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + // query param version + qrVersion := o.Version + qVersion := qrVersion + if qVersion != "" { + if err := r.SetQueryParam("version", qVersion); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/models/delete_model_responses.go b/di/restapi/api_v1/client/models/delete_model_responses.go new file mode 100644 index 0000000..2e808e4 --- /dev/null +++ b/di/restapi/api_v1/client/models/delete_model_responses.go @@ -0,0 +1,139 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// DeleteModelReader is a Reader for the DeleteModel structure. +type DeleteModelReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *DeleteModelReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewDeleteModelOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewDeleteModelUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewDeleteModelNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewDeleteModelOK creates a DeleteModelOK with default headers values +func NewDeleteModelOK() *DeleteModelOK { + return &DeleteModelOK{} +} + +/*DeleteModelOK handles this case with default header values. + +Model deleted successfully. +*/ +type DeleteModelOK struct { + Payload *restmodels.BasicModel +} + +func (o *DeleteModelOK) Error() string { + return fmt.Sprintf("[DELETE /v1/models/{model_id}][%d] deleteModelOK %+v", 200, o.Payload) +} + +func (o *DeleteModelOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.BasicModel) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDeleteModelUnauthorized creates a DeleteModelUnauthorized with default headers values +func NewDeleteModelUnauthorized() *DeleteModelUnauthorized { + return &DeleteModelUnauthorized{} +} + +/*DeleteModelUnauthorized handles this case with default header values. + +Unauthorized +*/ +type DeleteModelUnauthorized struct { + Payload *restmodels.Error +} + +func (o *DeleteModelUnauthorized) Error() string { + return fmt.Sprintf("[DELETE /v1/models/{model_id}][%d] deleteModelUnauthorized %+v", 401, o.Payload) +} + +func (o *DeleteModelUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDeleteModelNotFound creates a DeleteModelNotFound with default headers values +func NewDeleteModelNotFound() *DeleteModelNotFound { + return &DeleteModelNotFound{} +} + +/*DeleteModelNotFound handles this case with default header values. + +The model cannot be found. +*/ +type DeleteModelNotFound struct { + Payload *restmodels.Error +} + +func (o *DeleteModelNotFound) Error() string { + return fmt.Sprintf("[DELETE /v1/models/{model_id}][%d] deleteModelNotFound %+v", 404, o.Payload) +} + +func (o *DeleteModelNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/models/download_model_definition_parameters.go b/di/restapi/api_v1/client/models/download_model_definition_parameters.go new file mode 100644 index 0000000..48744b3 --- /dev/null +++ b/di/restapi/api_v1/client/models/download_model_definition_parameters.go @@ -0,0 +1,174 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewDownloadModelDefinitionParams creates a new DownloadModelDefinitionParams object +// with the default values initialized. +func NewDownloadModelDefinitionParams() *DownloadModelDefinitionParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DownloadModelDefinitionParams{ + Version: versionDefault, + + timeout: cr.DefaultTimeout, + } +} + +// NewDownloadModelDefinitionParamsWithTimeout creates a new DownloadModelDefinitionParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewDownloadModelDefinitionParamsWithTimeout(timeout time.Duration) *DownloadModelDefinitionParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DownloadModelDefinitionParams{ + Version: versionDefault, + + timeout: timeout, + } +} + +// NewDownloadModelDefinitionParamsWithContext creates a new DownloadModelDefinitionParams object +// with the default values initialized, and the ability to set a context for a request +func NewDownloadModelDefinitionParamsWithContext(ctx context.Context) *DownloadModelDefinitionParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DownloadModelDefinitionParams{ + Version: versionDefault, + + Context: ctx, + } +} + +// NewDownloadModelDefinitionParamsWithHTTPClient creates a new DownloadModelDefinitionParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewDownloadModelDefinitionParamsWithHTTPClient(client *http.Client) *DownloadModelDefinitionParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DownloadModelDefinitionParams{ + Version: versionDefault, + HTTPClient: client, + } +} + +/*DownloadModelDefinitionParams contains all the parameters to send to the API endpoint +for the download model definition operation typically these are written to a http.Request +*/ +type DownloadModelDefinitionParams struct { + + /*ModelID + The id of the model. + + */ + ModelID string + /*Version + The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + + */ + Version string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the download model definition params +func (o *DownloadModelDefinitionParams) WithTimeout(timeout time.Duration) *DownloadModelDefinitionParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the download model definition params +func (o *DownloadModelDefinitionParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the download model definition params +func (o *DownloadModelDefinitionParams) WithContext(ctx context.Context) *DownloadModelDefinitionParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the download model definition params +func (o *DownloadModelDefinitionParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the download model definition params +func (o *DownloadModelDefinitionParams) WithHTTPClient(client *http.Client) *DownloadModelDefinitionParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the download model definition params +func (o *DownloadModelDefinitionParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithModelID adds the modelID to the download model definition params +func (o *DownloadModelDefinitionParams) WithModelID(modelID string) *DownloadModelDefinitionParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the download model definition params +func (o *DownloadModelDefinitionParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WithVersion adds the version to the download model definition params +func (o *DownloadModelDefinitionParams) WithVersion(version string) *DownloadModelDefinitionParams { + o.SetVersion(version) + return o +} + +// SetVersion adds the version to the download model definition params +func (o *DownloadModelDefinitionParams) SetVersion(version string) { + o.Version = version +} + +// WriteToRequest writes these params to a swagger request +func (o *DownloadModelDefinitionParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + // query param version + qrVersion := o.Version + qVersion := qrVersion + if qVersion != "" { + if err := r.SetQueryParam("version", qVersion); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/models/download_model_definition_responses.go b/di/restapi/api_v1/client/models/download_model_definition_responses.go new file mode 100644 index 0000000..19d6e14 --- /dev/null +++ b/di/restapi/api_v1/client/models/download_model_definition_responses.go @@ -0,0 +1,140 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// DownloadModelDefinitionReader is a Reader for the DownloadModelDefinition structure. +type DownloadModelDefinitionReader struct { + formats strfmt.Registry + writer io.Writer +} + +// ReadResponse reads a server response into the received o. +func (o *DownloadModelDefinitionReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewDownloadModelDefinitionOK(o.writer) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewDownloadModelDefinitionUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewDownloadModelDefinitionNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewDownloadModelDefinitionOK creates a DownloadModelDefinitionOK with default headers values +func NewDownloadModelDefinitionOK(writer io.Writer) *DownloadModelDefinitionOK { + return &DownloadModelDefinitionOK{ + Payload: writer, + } +} + +/*DownloadModelDefinitionOK handles this case with default header values. + +Model definition +*/ +type DownloadModelDefinitionOK struct { + Payload io.Writer +} + +func (o *DownloadModelDefinitionOK) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/definition][%d] downloadModelDefinitionOK %+v", 200, o.Payload) +} + +func (o *DownloadModelDefinitionOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDownloadModelDefinitionUnauthorized creates a DownloadModelDefinitionUnauthorized with default headers values +func NewDownloadModelDefinitionUnauthorized() *DownloadModelDefinitionUnauthorized { + return &DownloadModelDefinitionUnauthorized{} +} + +/*DownloadModelDefinitionUnauthorized handles this case with default header values. + +Unauthorized +*/ +type DownloadModelDefinitionUnauthorized struct { + Payload *restmodels.Error +} + +func (o *DownloadModelDefinitionUnauthorized) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/definition][%d] downloadModelDefinitionUnauthorized %+v", 401, o.Payload) +} + +func (o *DownloadModelDefinitionUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDownloadModelDefinitionNotFound creates a DownloadModelDefinitionNotFound with default headers values +func NewDownloadModelDefinitionNotFound() *DownloadModelDefinitionNotFound { + return &DownloadModelDefinitionNotFound{} +} + +/*DownloadModelDefinitionNotFound handles this case with default header values. + +The model cannot be found. +*/ +type DownloadModelDefinitionNotFound struct { + Payload *restmodels.Error +} + +func (o *DownloadModelDefinitionNotFound) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/definition][%d] downloadModelDefinitionNotFound %+v", 404, o.Payload) +} + +func (o *DownloadModelDefinitionNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/models/download_trained_model_parameters.go b/di/restapi/api_v1/client/models/download_trained_model_parameters.go new file mode 100644 index 0000000..ac829be --- /dev/null +++ b/di/restapi/api_v1/client/models/download_trained_model_parameters.go @@ -0,0 +1,174 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewDownloadTrainedModelParams creates a new DownloadTrainedModelParams object +// with the default values initialized. +func NewDownloadTrainedModelParams() *DownloadTrainedModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DownloadTrainedModelParams{ + Version: versionDefault, + + timeout: cr.DefaultTimeout, + } +} + +// NewDownloadTrainedModelParamsWithTimeout creates a new DownloadTrainedModelParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewDownloadTrainedModelParamsWithTimeout(timeout time.Duration) *DownloadTrainedModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DownloadTrainedModelParams{ + Version: versionDefault, + + timeout: timeout, + } +} + +// NewDownloadTrainedModelParamsWithContext creates a new DownloadTrainedModelParams object +// with the default values initialized, and the ability to set a context for a request +func NewDownloadTrainedModelParamsWithContext(ctx context.Context) *DownloadTrainedModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DownloadTrainedModelParams{ + Version: versionDefault, + + Context: ctx, + } +} + +// NewDownloadTrainedModelParamsWithHTTPClient creates a new DownloadTrainedModelParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewDownloadTrainedModelParamsWithHTTPClient(client *http.Client) *DownloadTrainedModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &DownloadTrainedModelParams{ + Version: versionDefault, + HTTPClient: client, + } +} + +/*DownloadTrainedModelParams contains all the parameters to send to the API endpoint +for the download trained model operation typically these are written to a http.Request +*/ +type DownloadTrainedModelParams struct { + + /*ModelID + The id of the model. + + */ + ModelID string + /*Version + The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + + */ + Version string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the download trained model params +func (o *DownloadTrainedModelParams) WithTimeout(timeout time.Duration) *DownloadTrainedModelParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the download trained model params +func (o *DownloadTrainedModelParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the download trained model params +func (o *DownloadTrainedModelParams) WithContext(ctx context.Context) *DownloadTrainedModelParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the download trained model params +func (o *DownloadTrainedModelParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the download trained model params +func (o *DownloadTrainedModelParams) WithHTTPClient(client *http.Client) *DownloadTrainedModelParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the download trained model params +func (o *DownloadTrainedModelParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithModelID adds the modelID to the download trained model params +func (o *DownloadTrainedModelParams) WithModelID(modelID string) *DownloadTrainedModelParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the download trained model params +func (o *DownloadTrainedModelParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WithVersion adds the version to the download trained model params +func (o *DownloadTrainedModelParams) WithVersion(version string) *DownloadTrainedModelParams { + o.SetVersion(version) + return o +} + +// SetVersion adds the version to the download trained model params +func (o *DownloadTrainedModelParams) SetVersion(version string) { + o.Version = version +} + +// WriteToRequest writes these params to a swagger request +func (o *DownloadTrainedModelParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + // query param version + qrVersion := o.Version + qVersion := qrVersion + if qVersion != "" { + if err := r.SetQueryParam("version", qVersion); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/models/download_trained_model_responses.go b/di/restapi/api_v1/client/models/download_trained_model_responses.go new file mode 100644 index 0000000..4abacbb --- /dev/null +++ b/di/restapi/api_v1/client/models/download_trained_model_responses.go @@ -0,0 +1,176 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// DownloadTrainedModelReader is a Reader for the DownloadTrainedModel structure. +type DownloadTrainedModelReader struct { + formats strfmt.Registry + writer io.Writer +} + +// ReadResponse reads a server response into the received o. +func (o *DownloadTrainedModelReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewDownloadTrainedModelOK(o.writer) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewDownloadTrainedModelUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewDownloadTrainedModelNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 410: + result := NewDownloadTrainedModelGone() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewDownloadTrainedModelOK creates a DownloadTrainedModelOK with default headers values +func NewDownloadTrainedModelOK(writer io.Writer) *DownloadTrainedModelOK { + return &DownloadTrainedModelOK{ + Payload: writer, + } +} + +/*DownloadTrainedModelOK handles this case with default header values. + +Model definition +*/ +type DownloadTrainedModelOK struct { + Payload io.Writer +} + +func (o *DownloadTrainedModelOK) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/trained_model][%d] downloadTrainedModelOK %+v", 200, o.Payload) +} + +func (o *DownloadTrainedModelOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDownloadTrainedModelUnauthorized creates a DownloadTrainedModelUnauthorized with default headers values +func NewDownloadTrainedModelUnauthorized() *DownloadTrainedModelUnauthorized { + return &DownloadTrainedModelUnauthorized{} +} + +/*DownloadTrainedModelUnauthorized handles this case with default header values. + +Unauthorized +*/ +type DownloadTrainedModelUnauthorized struct { + Payload *restmodels.Error +} + +func (o *DownloadTrainedModelUnauthorized) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/trained_model][%d] downloadTrainedModelUnauthorized %+v", 401, o.Payload) +} + +func (o *DownloadTrainedModelUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDownloadTrainedModelNotFound creates a DownloadTrainedModelNotFound with default headers values +func NewDownloadTrainedModelNotFound() *DownloadTrainedModelNotFound { + return &DownloadTrainedModelNotFound{} +} + +/*DownloadTrainedModelNotFound handles this case with default header values. + +The trained model cannot be found. +*/ +type DownloadTrainedModelNotFound struct { + Payload *restmodels.Error +} + +func (o *DownloadTrainedModelNotFound) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/trained_model][%d] downloadTrainedModelNotFound %+v", 404, o.Payload) +} + +func (o *DownloadTrainedModelNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDownloadTrainedModelGone creates a DownloadTrainedModelGone with default headers values +func NewDownloadTrainedModelGone() *DownloadTrainedModelGone { + return &DownloadTrainedModelGone{} +} + +/*DownloadTrainedModelGone handles this case with default header values. + +If the trained model storage time has expired and it has been deleted. It only gets deleted if it not stored on an external data store. +*/ +type DownloadTrainedModelGone struct { + Payload *restmodels.Error +} + +func (o *DownloadTrainedModelGone) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/trained_model][%d] downloadTrainedModelGone %+v", 410, o.Payload) +} + +func (o *DownloadTrainedModelGone) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/models/get_logs_parameters.go b/di/restapi/api_v1/client/models/get_logs_parameters.go new file mode 100644 index 0000000..95c4949 --- /dev/null +++ b/di/restapi/api_v1/client/models/get_logs_parameters.go @@ -0,0 +1,255 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/swag" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetLogsParams creates a new GetLogsParams object +// with the default values initialized. +func NewGetLogsParams() *GetLogsParams { + var ( + followDefault = bool(false) + sinceTimeDefault = string("") + versionDefault = string("2017-02-13") + ) + return &GetLogsParams{ + Follow: &followDefault, + SinceTime: &sinceTimeDefault, + Version: versionDefault, + + timeout: cr.DefaultTimeout, + } +} + +// NewGetLogsParamsWithTimeout creates a new GetLogsParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetLogsParamsWithTimeout(timeout time.Duration) *GetLogsParams { + var ( + followDefault = bool(false) + sinceTimeDefault = string("") + versionDefault = string("2017-02-13") + ) + return &GetLogsParams{ + Follow: &followDefault, + SinceTime: &sinceTimeDefault, + Version: versionDefault, + + timeout: timeout, + } +} + +// NewGetLogsParamsWithContext creates a new GetLogsParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetLogsParamsWithContext(ctx context.Context) *GetLogsParams { + var ( + followDefault = bool(false) + sinceTimeDefault = string("") + versionDefault = string("2017-02-13") + ) + return &GetLogsParams{ + Follow: &followDefault, + SinceTime: &sinceTimeDefault, + Version: versionDefault, + + Context: ctx, + } +} + +// NewGetLogsParamsWithHTTPClient creates a new GetLogsParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetLogsParamsWithHTTPClient(client *http.Client) *GetLogsParams { + var ( + followDefault = bool(false) + sinceTimeDefault = string("") + versionDefault = string("2017-02-13") + ) + return &GetLogsParams{ + Follow: &followDefault, + SinceTime: &sinceTimeDefault, + Version: versionDefault, + HTTPClient: client, + } +} + +/*GetLogsParams contains all the parameters to send to the API endpoint +for the get logs operation typically these are written to a http.Request +*/ +type GetLogsParams struct { + + /*Follow + Follow the log stream if true. Default false. + + */ + Follow *bool + /*ModelID + The id of the model. + + */ + ModelID string + /*SinceTime + An RFC3339 timestamp from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will be returned. + + */ + SinceTime *string + /*Version + The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + + */ + Version string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get logs params +func (o *GetLogsParams) WithTimeout(timeout time.Duration) *GetLogsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get logs params +func (o *GetLogsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get logs params +func (o *GetLogsParams) WithContext(ctx context.Context) *GetLogsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get logs params +func (o *GetLogsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get logs params +func (o *GetLogsParams) WithHTTPClient(client *http.Client) *GetLogsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get logs params +func (o *GetLogsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithFollow adds the follow to the get logs params +func (o *GetLogsParams) WithFollow(follow *bool) *GetLogsParams { + o.SetFollow(follow) + return o +} + +// SetFollow adds the follow to the get logs params +func (o *GetLogsParams) SetFollow(follow *bool) { + o.Follow = follow +} + +// WithModelID adds the modelID to the get logs params +func (o *GetLogsParams) WithModelID(modelID string) *GetLogsParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the get logs params +func (o *GetLogsParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WithSinceTime adds the sinceTime to the get logs params +func (o *GetLogsParams) WithSinceTime(sinceTime *string) *GetLogsParams { + o.SetSinceTime(sinceTime) + return o +} + +// SetSinceTime adds the sinceTime to the get logs params +func (o *GetLogsParams) SetSinceTime(sinceTime *string) { + o.SinceTime = sinceTime +} + +// WithVersion adds the version to the get logs params +func (o *GetLogsParams) WithVersion(version string) *GetLogsParams { + o.SetVersion(version) + return o +} + +// SetVersion adds the version to the get logs params +func (o *GetLogsParams) SetVersion(version string) { + o.Version = version +} + +// WriteToRequest writes these params to a swagger request +func (o *GetLogsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if o.Follow != nil { + + // query param follow + var qrFollow bool + if o.Follow != nil { + qrFollow = *o.Follow + } + qFollow := swag.FormatBool(qrFollow) + if qFollow != "" { + if err := r.SetQueryParam("follow", qFollow); err != nil { + return err + } + } + + } + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + if o.SinceTime != nil { + + // query param since_time + var qrSinceTime string + if o.SinceTime != nil { + qrSinceTime = *o.SinceTime + } + qSinceTime := qrSinceTime + if qSinceTime != "" { + if err := r.SetQueryParam("since_time", qSinceTime); err != nil { + return err + } + } + + } + + // query param version + qrVersion := o.Version + qVersion := qrVersion + if qVersion != "" { + if err := r.SetQueryParam("version", qVersion); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/models/get_logs_responses.go b/di/restapi/api_v1/client/models/get_logs_responses.go new file mode 100644 index 0000000..996a32d --- /dev/null +++ b/di/restapi/api_v1/client/models/get_logs_responses.go @@ -0,0 +1,140 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// GetLogsReader is a Reader for the GetLogs structure. +type GetLogsReader struct { + formats strfmt.Registry + writer io.Writer +} + +// ReadResponse reads a server response into the received o. +func (o *GetLogsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewGetLogsOK(o.writer) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewGetLogsUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewGetLogsNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewGetLogsOK creates a GetLogsOK with default headers values +func NewGetLogsOK(writer io.Writer) *GetLogsOK { + return &GetLogsOK{ + Payload: writer, + } +} + +/*GetLogsOK handles this case with default header values. + +Dump of the training log to-date +*/ +type GetLogsOK struct { + Payload io.Writer +} + +func (o *GetLogsOK) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/logs][%d] getLogsOK %+v", 200, o.Payload) +} + +func (o *GetLogsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetLogsUnauthorized creates a GetLogsUnauthorized with default headers values +func NewGetLogsUnauthorized() *GetLogsUnauthorized { + return &GetLogsUnauthorized{} +} + +/*GetLogsUnauthorized handles this case with default header values. + +Unauthorized +*/ +type GetLogsUnauthorized struct { + Payload *restmodels.Error +} + +func (o *GetLogsUnauthorized) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/logs][%d] getLogsUnauthorized %+v", 401, o.Payload) +} + +func (o *GetLogsUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetLogsNotFound creates a GetLogsNotFound with default headers values +func NewGetLogsNotFound() *GetLogsNotFound { + return &GetLogsNotFound{} +} + +/*GetLogsNotFound handles this case with default header values. + +The model cannot be found. +*/ +type GetLogsNotFound struct { + Payload *restmodels.Error +} + +func (o *GetLogsNotFound) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/logs][%d] getLogsNotFound %+v", 404, o.Payload) +} + +func (o *GetLogsNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/models/get_metrics_parameters.go b/di/restapi/api_v1/client/models/get_metrics_parameters.go new file mode 100644 index 0000000..9f3d9e5 --- /dev/null +++ b/di/restapi/api_v1/client/models/get_metrics_parameters.go @@ -0,0 +1,255 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/swag" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetMetricsParams creates a new GetMetricsParams object +// with the default values initialized. +func NewGetMetricsParams() *GetMetricsParams { + var ( + followDefault = bool(false) + sinceTimeDefault = string("") + versionDefault = string("2017-06-07") + ) + return &GetMetricsParams{ + Follow: &followDefault, + SinceTime: &sinceTimeDefault, + Version: versionDefault, + + timeout: cr.DefaultTimeout, + } +} + +// NewGetMetricsParamsWithTimeout creates a new GetMetricsParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetMetricsParamsWithTimeout(timeout time.Duration) *GetMetricsParams { + var ( + followDefault = bool(false) + sinceTimeDefault = string("") + versionDefault = string("2017-06-07") + ) + return &GetMetricsParams{ + Follow: &followDefault, + SinceTime: &sinceTimeDefault, + Version: versionDefault, + + timeout: timeout, + } +} + +// NewGetMetricsParamsWithContext creates a new GetMetricsParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetMetricsParamsWithContext(ctx context.Context) *GetMetricsParams { + var ( + followDefault = bool(false) + sinceTimeDefault = string("") + versionDefault = string("2017-06-07") + ) + return &GetMetricsParams{ + Follow: &followDefault, + SinceTime: &sinceTimeDefault, + Version: versionDefault, + + Context: ctx, + } +} + +// NewGetMetricsParamsWithHTTPClient creates a new GetMetricsParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetMetricsParamsWithHTTPClient(client *http.Client) *GetMetricsParams { + var ( + followDefault = bool(false) + sinceTimeDefault = string("") + versionDefault = string("2017-06-07") + ) + return &GetMetricsParams{ + Follow: &followDefault, + SinceTime: &sinceTimeDefault, + Version: versionDefault, + HTTPClient: client, + } +} + +/*GetMetricsParams contains all the parameters to send to the API endpoint +for the get metrics operation typically these are written to a http.Request +*/ +type GetMetricsParams struct { + + /*Follow + Follow the log stream if true. Default false. + + */ + Follow *bool + /*ModelID + The id of the model. + + */ + ModelID string + /*SinceTime + An RFC3339 timestamp from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned. If this value is in the future, no metrics will be returned. + + */ + SinceTime *string + /*Version + The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + + */ + Version string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get metrics params +func (o *GetMetricsParams) WithTimeout(timeout time.Duration) *GetMetricsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get metrics params +func (o *GetMetricsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get metrics params +func (o *GetMetricsParams) WithContext(ctx context.Context) *GetMetricsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get metrics params +func (o *GetMetricsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get metrics params +func (o *GetMetricsParams) WithHTTPClient(client *http.Client) *GetMetricsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get metrics params +func (o *GetMetricsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithFollow adds the follow to the get metrics params +func (o *GetMetricsParams) WithFollow(follow *bool) *GetMetricsParams { + o.SetFollow(follow) + return o +} + +// SetFollow adds the follow to the get metrics params +func (o *GetMetricsParams) SetFollow(follow *bool) { + o.Follow = follow +} + +// WithModelID adds the modelID to the get metrics params +func (o *GetMetricsParams) WithModelID(modelID string) *GetMetricsParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the get metrics params +func (o *GetMetricsParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WithSinceTime adds the sinceTime to the get metrics params +func (o *GetMetricsParams) WithSinceTime(sinceTime *string) *GetMetricsParams { + o.SetSinceTime(sinceTime) + return o +} + +// SetSinceTime adds the sinceTime to the get metrics params +func (o *GetMetricsParams) SetSinceTime(sinceTime *string) { + o.SinceTime = sinceTime +} + +// WithVersion adds the version to the get metrics params +func (o *GetMetricsParams) WithVersion(version string) *GetMetricsParams { + o.SetVersion(version) + return o +} + +// SetVersion adds the version to the get metrics params +func (o *GetMetricsParams) SetVersion(version string) { + o.Version = version +} + +// WriteToRequest writes these params to a swagger request +func (o *GetMetricsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if o.Follow != nil { + + // query param follow + var qrFollow bool + if o.Follow != nil { + qrFollow = *o.Follow + } + qFollow := swag.FormatBool(qrFollow) + if qFollow != "" { + if err := r.SetQueryParam("follow", qFollow); err != nil { + return err + } + } + + } + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + if o.SinceTime != nil { + + // query param since_time + var qrSinceTime string + if o.SinceTime != nil { + qrSinceTime = *o.SinceTime + } + qSinceTime := qrSinceTime + if qSinceTime != "" { + if err := r.SetQueryParam("since_time", qSinceTime); err != nil { + return err + } + } + + } + + // query param version + qrVersion := o.Version + qVersion := qrVersion + if qVersion != "" { + if err := r.SetQueryParam("version", qVersion); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/models/get_metrics_responses.go b/di/restapi/api_v1/client/models/get_metrics_responses.go new file mode 100644 index 0000000..611cac0 --- /dev/null +++ b/di/restapi/api_v1/client/models/get_metrics_responses.go @@ -0,0 +1,140 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// GetMetricsReader is a Reader for the GetMetrics structure. +type GetMetricsReader struct { + formats strfmt.Registry + writer io.Writer +} + +// ReadResponse reads a server response into the received o. +func (o *GetMetricsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewGetMetricsOK(o.writer) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewGetMetricsUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewGetMetricsNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewGetMetricsOK creates a GetMetricsOK with default headers values +func NewGetMetricsOK(writer io.Writer) *GetMetricsOK { + return &GetMetricsOK{ + Payload: writer, + } +} + +/*GetMetricsOK handles this case with default header values. + +Dump of the training log to-date +*/ +type GetMetricsOK struct { + Payload io.Writer +} + +func (o *GetMetricsOK) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/metrics][%d] getMetricsOK %+v", 200, o.Payload) +} + +func (o *GetMetricsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetMetricsUnauthorized creates a GetMetricsUnauthorized with default headers values +func NewGetMetricsUnauthorized() *GetMetricsUnauthorized { + return &GetMetricsUnauthorized{} +} + +/*GetMetricsUnauthorized handles this case with default header values. + +Unauthorized +*/ +type GetMetricsUnauthorized struct { + Payload *restmodels.Error +} + +func (o *GetMetricsUnauthorized) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/metrics][%d] getMetricsUnauthorized %+v", 401, o.Payload) +} + +func (o *GetMetricsUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetMetricsNotFound creates a GetMetricsNotFound with default headers values +func NewGetMetricsNotFound() *GetMetricsNotFound { + return &GetMetricsNotFound{} +} + +/*GetMetricsNotFound handles this case with default header values. + +The training job cannot be found. +*/ +type GetMetricsNotFound struct { + Payload *restmodels.Error +} + +func (o *GetMetricsNotFound) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}/metrics][%d] getMetricsNotFound %+v", 404, o.Payload) +} + +func (o *GetMetricsNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/models/get_model_parameters.go b/di/restapi/api_v1/client/models/get_model_parameters.go new file mode 100644 index 0000000..b4fc810 --- /dev/null +++ b/di/restapi/api_v1/client/models/get_model_parameters.go @@ -0,0 +1,174 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetModelParams creates a new GetModelParams object +// with the default values initialized. +func NewGetModelParams() *GetModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &GetModelParams{ + Version: versionDefault, + + timeout: cr.DefaultTimeout, + } +} + +// NewGetModelParamsWithTimeout creates a new GetModelParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetModelParamsWithTimeout(timeout time.Duration) *GetModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &GetModelParams{ + Version: versionDefault, + + timeout: timeout, + } +} + +// NewGetModelParamsWithContext creates a new GetModelParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetModelParamsWithContext(ctx context.Context) *GetModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &GetModelParams{ + Version: versionDefault, + + Context: ctx, + } +} + +// NewGetModelParamsWithHTTPClient creates a new GetModelParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetModelParamsWithHTTPClient(client *http.Client) *GetModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &GetModelParams{ + Version: versionDefault, + HTTPClient: client, + } +} + +/*GetModelParams contains all the parameters to send to the API endpoint +for the get model operation typically these are written to a http.Request +*/ +type GetModelParams struct { + + /*ModelID + The id of the model. + + */ + ModelID string + /*Version + The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + + */ + Version string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get model params +func (o *GetModelParams) WithTimeout(timeout time.Duration) *GetModelParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get model params +func (o *GetModelParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get model params +func (o *GetModelParams) WithContext(ctx context.Context) *GetModelParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get model params +func (o *GetModelParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get model params +func (o *GetModelParams) WithHTTPClient(client *http.Client) *GetModelParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get model params +func (o *GetModelParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithModelID adds the modelID to the get model params +func (o *GetModelParams) WithModelID(modelID string) *GetModelParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the get model params +func (o *GetModelParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WithVersion adds the version to the get model params +func (o *GetModelParams) WithVersion(version string) *GetModelParams { + o.SetVersion(version) + return o +} + +// SetVersion adds the version to the get model params +func (o *GetModelParams) SetVersion(version string) { + o.Version = version +} + +// WriteToRequest writes these params to a swagger request +func (o *GetModelParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + // query param version + qrVersion := o.Version + qVersion := qrVersion + if qVersion != "" { + if err := r.SetQueryParam("version", qVersion); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/models/get_model_responses.go b/di/restapi/api_v1/client/models/get_model_responses.go new file mode 100644 index 0000000..5df5747 --- /dev/null +++ b/di/restapi/api_v1/client/models/get_model_responses.go @@ -0,0 +1,139 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// GetModelReader is a Reader for the GetModel structure. +type GetModelReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetModelReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewGetModelOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewGetModelUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewGetModelNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewGetModelOK creates a GetModelOK with default headers values +func NewGetModelOK() *GetModelOK { + return &GetModelOK{} +} + +/*GetModelOK handles this case with default header values. + +Detailed model and training information. +*/ +type GetModelOK struct { + Payload *restmodels.Model +} + +func (o *GetModelOK) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}][%d] getModelOK %+v", 200, o.Payload) +} + +func (o *GetModelOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Model) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetModelUnauthorized creates a GetModelUnauthorized with default headers values +func NewGetModelUnauthorized() *GetModelUnauthorized { + return &GetModelUnauthorized{} +} + +/*GetModelUnauthorized handles this case with default header values. + +Unauthorized +*/ +type GetModelUnauthorized struct { + Payload *restmodels.Error +} + +func (o *GetModelUnauthorized) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}][%d] getModelUnauthorized %+v", 401, o.Payload) +} + +func (o *GetModelUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetModelNotFound creates a GetModelNotFound with default headers values +func NewGetModelNotFound() *GetModelNotFound { + return &GetModelNotFound{} +} + +/*GetModelNotFound handles this case with default header values. + +Model with the given ID not found. +*/ +type GetModelNotFound struct { + Payload *restmodels.Error +} + +func (o *GetModelNotFound) Error() string { + return fmt.Sprintf("[GET /v1/models/{model_id}][%d] getModelNotFound %+v", 404, o.Payload) +} + +func (o *GetModelNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/models/list_models_parameters.go b/di/restapi/api_v1/client/models/list_models_parameters.go new file mode 100644 index 0000000..112d043 --- /dev/null +++ b/di/restapi/api_v1/client/models/list_models_parameters.go @@ -0,0 +1,312 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewListModelsParams creates a new ListModelsParams object +// with the default values initialized. +func NewListModelsParams() *ListModelsParams { + var ( + namespaceDefault = string("") + pageDefault = string("") + sizeDefault = string("") + useridDefault = string("") + versionDefault = string("2017-02-13") + ) + return &ListModelsParams{ + Namespace: &namespaceDefault, + Page: &pageDefault, + Size: &sizeDefault, + Userid: &useridDefault, + Version: versionDefault, + + timeout: cr.DefaultTimeout, + } +} + +// NewListModelsParamsWithTimeout creates a new ListModelsParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewListModelsParamsWithTimeout(timeout time.Duration) *ListModelsParams { + var ( + namespaceDefault = string("") + pageDefault = string("") + sizeDefault = string("") + useridDefault = string("") + versionDefault = string("2017-02-13") + ) + return &ListModelsParams{ + Namespace: &namespaceDefault, + Page: &pageDefault, + Size: &sizeDefault, + Userid: &useridDefault, + Version: versionDefault, + + timeout: timeout, + } +} + +// NewListModelsParamsWithContext creates a new ListModelsParams object +// with the default values initialized, and the ability to set a context for a request +func NewListModelsParamsWithContext(ctx context.Context) *ListModelsParams { + var ( + namespaceDefault = string("") + pageDefault = string("") + sizeDefault = string("") + useridDefault = string("") + versionDefault = string("2017-02-13") + ) + return &ListModelsParams{ + Namespace: &namespaceDefault, + Page: &pageDefault, + Size: &sizeDefault, + Userid: &useridDefault, + Version: versionDefault, + + Context: ctx, + } +} + +// NewListModelsParamsWithHTTPClient creates a new ListModelsParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewListModelsParamsWithHTTPClient(client *http.Client) *ListModelsParams { + var ( + namespaceDefault = string("") + pageDefault = string("") + sizeDefault = string("") + useridDefault = string("") + versionDefault = string("2017-02-13") + ) + return &ListModelsParams{ + Namespace: &namespaceDefault, + Page: &pageDefault, + Size: &sizeDefault, + Userid: &useridDefault, + Version: versionDefault, + HTTPClient: client, + } +} + +/*ListModelsParams contains all the parameters to send to the API endpoint +for the list models operation typically these are written to a http.Request +*/ +type ListModelsParams struct { + + /*Namespace + job's namespace. + + */ + Namespace *string + /*Page + page number. + + */ + Page *string + /*Size + entity number per page. + + */ + Size *string + /*Userid + owner's userid. + + */ + Userid *string + /*Version + The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + + */ + Version string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the list models params +func (o *ListModelsParams) WithTimeout(timeout time.Duration) *ListModelsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the list models params +func (o *ListModelsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the list models params +func (o *ListModelsParams) WithContext(ctx context.Context) *ListModelsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the list models params +func (o *ListModelsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the list models params +func (o *ListModelsParams) WithHTTPClient(client *http.Client) *ListModelsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the list models params +func (o *ListModelsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithNamespace adds the namespace to the list models params +func (o *ListModelsParams) WithNamespace(namespace *string) *ListModelsParams { + o.SetNamespace(namespace) + return o +} + +// SetNamespace adds the namespace to the list models params +func (o *ListModelsParams) SetNamespace(namespace *string) { + o.Namespace = namespace +} + +// WithPage adds the page to the list models params +func (o *ListModelsParams) WithPage(page *string) *ListModelsParams { + o.SetPage(page) + return o +} + +// SetPage adds the page to the list models params +func (o *ListModelsParams) SetPage(page *string) { + o.Page = page +} + +// WithSize adds the size to the list models params +func (o *ListModelsParams) WithSize(size *string) *ListModelsParams { + o.SetSize(size) + return o +} + +// SetSize adds the size to the list models params +func (o *ListModelsParams) SetSize(size *string) { + o.Size = size +} + +// WithUserid adds the userid to the list models params +func (o *ListModelsParams) WithUserid(userid *string) *ListModelsParams { + o.SetUserid(userid) + return o +} + +// SetUserid adds the userid to the list models params +func (o *ListModelsParams) SetUserid(userid *string) { + o.Userid = userid +} + +// WithVersion adds the version to the list models params +func (o *ListModelsParams) WithVersion(version string) *ListModelsParams { + o.SetVersion(version) + return o +} + +// SetVersion adds the version to the list models params +func (o *ListModelsParams) SetVersion(version string) { + o.Version = version +} + +// WriteToRequest writes these params to a swagger request +func (o *ListModelsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if o.Namespace != nil { + + // query param namespace + var qrNamespace string + if o.Namespace != nil { + qrNamespace = *o.Namespace + } + qNamespace := qrNamespace + if qNamespace != "" { + if err := r.SetQueryParam("namespace", qNamespace); err != nil { + return err + } + } + + } + + if o.Page != nil { + + // query param page + var qrPage string + if o.Page != nil { + qrPage = *o.Page + } + qPage := qrPage + if qPage != "" { + if err := r.SetQueryParam("page", qPage); err != nil { + return err + } + } + + } + + if o.Size != nil { + + // query param size + var qrSize string + if o.Size != nil { + qrSize = *o.Size + } + qSize := qrSize + if qSize != "" { + if err := r.SetQueryParam("size", qSize); err != nil { + return err + } + } + + } + + if o.Userid != nil { + + // query param userid + var qrUserid string + if o.Userid != nil { + qrUserid = *o.Userid + } + qUserid := qrUserid + if qUserid != "" { + if err := r.SetQueryParam("userid", qUserid); err != nil { + return err + } + } + + } + + // query param version + qrVersion := o.Version + qVersion := qrVersion + if qVersion != "" { + if err := r.SetQueryParam("version", qVersion); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/models/list_models_responses.go b/di/restapi/api_v1/client/models/list_models_responses.go new file mode 100644 index 0000000..e6af28a --- /dev/null +++ b/di/restapi/api_v1/client/models/list_models_responses.go @@ -0,0 +1,103 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// ListModelsReader is a Reader for the ListModels structure. +type ListModelsReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *ListModelsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewListModelsOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewListModelsUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewListModelsOK creates a ListModelsOK with default headers values +func NewListModelsOK() *ListModelsOK { + return &ListModelsOK{} +} + +/*ListModelsOK handles this case with default header values. + +List of deep learning models. +*/ +type ListModelsOK struct { + Payload *restmodels.ModelList +} + +func (o *ListModelsOK) Error() string { + return fmt.Sprintf("[GET /v1/models][%d] listModelsOK %+v", 200, o.Payload) +} + +func (o *ListModelsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.ModelList) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewListModelsUnauthorized creates a ListModelsUnauthorized with default headers values +func NewListModelsUnauthorized() *ListModelsUnauthorized { + return &ListModelsUnauthorized{} +} + +/*ListModelsUnauthorized handles this case with default header values. + +Unauthorized +*/ +type ListModelsUnauthorized struct { + Payload *restmodels.Error +} + +func (o *ListModelsUnauthorized) Error() string { + return fmt.Sprintf("[GET /v1/models][%d] listModelsUnauthorized %+v", 401, o.Payload) +} + +func (o *ListModelsUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/models/models_client.go b/di/restapi/api_v1/client/models/models_client.go new file mode 100644 index 0000000..5d17477 --- /dev/null +++ b/di/restapi/api_v1/client/models/models_client.go @@ -0,0 +1,314 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" +) + +// New creates a new models API client. +func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client { + return &Client{transport: transport, formats: formats} +} + +/* +Client for models API +*/ +type Client struct { + transport runtime.ClientTransport + formats strfmt.Registry +} + +/* +DeleteModel deletes an existing model + +Deletes an existing model. It does not delete any data in the user's data store. + +*/ +func (a *Client) DeleteModel(params *DeleteModelParams, authInfo runtime.ClientAuthInfoWriter) (*DeleteModelOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewDeleteModelParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "deleteModel", + Method: "DELETE", + PathPattern: "/v1/models/{model_id}", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &DeleteModelReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*DeleteModelOK), nil + +} + +/* +DownloadModelDefinition downloads the model definition + +Downloads the model definition that was initial used for training as ZIP archive. +*/ +func (a *Client) DownloadModelDefinition(params *DownloadModelDefinitionParams, authInfo runtime.ClientAuthInfoWriter, writer io.Writer) (*DownloadModelDefinitionOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewDownloadModelDefinitionParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "downloadModelDefinition", + Method: "GET", + PathPattern: "/v1/models/{model_id}/definition", + ProducesMediaTypes: []string{"application/octet-stream"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &DownloadModelDefinitionReader{formats: a.formats, writer: writer}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*DownloadModelDefinitionOK), nil + +} + +/* +DownloadTrainedModel downloads the trained model + +Downloads the trained model as ZIP archive. +*/ +func (a *Client) DownloadTrainedModel(params *DownloadTrainedModelParams, authInfo runtime.ClientAuthInfoWriter, writer io.Writer) (*DownloadTrainedModelOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewDownloadTrainedModelParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "downloadTrainedModel", + Method: "GET", + PathPattern: "/v1/models/{model_id}/trained_model", + ProducesMediaTypes: []string{"application/octet-stream"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &DownloadTrainedModelReader{formats: a.formats, writer: writer}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*DownloadTrainedModelOK), nil + +} + +/* +GetLogs gets training logs as websocket stream + +Get training logs for the given model as websocket stream. Each message can contain one or more log lines. + +*/ +func (a *Client) GetLogs(params *GetLogsParams, writer io.Writer) (*GetLogsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetLogsParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "getLogs", + Method: "GET", + PathPattern: "/v1/models/{model_id}/logs", + ProducesMediaTypes: []string{"application/octet-stream"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &GetLogsReader{formats: a.formats, writer: writer}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*GetLogsOK), nil + +} + +/* +GetMetrics gets training metrics from a model training as websocket + +Get training metrics such as learning rate, accurarcy, loss from a model training via a websocket. It returns one or more JSON payloads at a time with the following schema. + +*/ +func (a *Client) GetMetrics(params *GetMetricsParams, writer io.Writer) (*GetMetricsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetMetricsParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "getMetrics", + Method: "GET", + PathPattern: "/v1/models/{model_id}/metrics", + ProducesMediaTypes: []string{"application/octet-stream"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &GetMetricsReader{formats: a.formats, writer: writer}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*GetMetricsOK), nil + +} + +/* +GetModel gets detailed information about a model + +Get detailed information about a model such as training status. + +*/ +func (a *Client) GetModel(params *GetModelParams, authInfo runtime.ClientAuthInfoWriter) (*GetModelOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetModelParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "getModel", + Method: "GET", + PathPattern: "/v1/models/{model_id}", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &GetModelReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*GetModelOK), nil + +} + +/* +ListModels gets a list of available deep learning models + +Get a list of all available deep learning models and their configuration that a user can see. + +*/ +func (a *Client) ListModels(params *ListModelsParams, authInfo runtime.ClientAuthInfoWriter) (*ListModelsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewListModelsParams() + } + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "listModels", + Method: "GET", + PathPattern: "/v1/models", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &ListModelsReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*ListModelsOK), nil + +} + +/* +PatchModel changes the status of the training progress + +Changes the status of the training progress to the given `status` value (currently `halt` only). Halt means the training will be stopped and the last snapshot will be stored and can be retrieved. +*/ +func (a *Client) PatchModel(params *PatchModelParams, authInfo runtime.ClientAuthInfoWriter) (*PatchModelAccepted, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewPatchModelParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "patchModel", + Method: "PATCH", + PathPattern: "/v1/models/{model_id}", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &PatchModelReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*PatchModelAccepted), nil + +} + +/* +PostModel trains a new deep learning model + +Trains a deep neural network written in a DL framework supported by the DLaaS platform (such as Caffe, Tensorflow, etc.). The model code has to be uploaded and configuration parameters have to be provided. + +*/ +func (a *Client) PostModel(params *PostModelParams, authInfo runtime.ClientAuthInfoWriter) (*PostModelCreated, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewPostModelParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "postModel", + Method: "POST", + PathPattern: "/v1/models", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"multipart/form-data"}, + Schemes: []string{"https"}, + Params: params, + Reader: &PostModelReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*PostModelCreated), nil + +} + +// SetTransport changes the transport on the client +func (a *Client) SetTransport(transport runtime.ClientTransport) { + a.transport = transport +} diff --git a/di/restapi/api_v1/client/models/patch_model_parameters.go b/di/restapi/api_v1/client/models/patch_model_parameters.go new file mode 100644 index 0000000..f9b9257 --- /dev/null +++ b/di/restapi/api_v1/client/models/patch_model_parameters.go @@ -0,0 +1,200 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// NewPatchModelParams creates a new PatchModelParams object +// with the default values initialized. +func NewPatchModelParams() *PatchModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &PatchModelParams{ + Version: versionDefault, + + timeout: cr.DefaultTimeout, + } +} + +// NewPatchModelParamsWithTimeout creates a new PatchModelParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewPatchModelParamsWithTimeout(timeout time.Duration) *PatchModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &PatchModelParams{ + Version: versionDefault, + + timeout: timeout, + } +} + +// NewPatchModelParamsWithContext creates a new PatchModelParams object +// with the default values initialized, and the ability to set a context for a request +func NewPatchModelParamsWithContext(ctx context.Context) *PatchModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &PatchModelParams{ + Version: versionDefault, + + Context: ctx, + } +} + +// NewPatchModelParamsWithHTTPClient creates a new PatchModelParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewPatchModelParamsWithHTTPClient(client *http.Client) *PatchModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &PatchModelParams{ + Version: versionDefault, + HTTPClient: client, + } +} + +/*PatchModelParams contains all the parameters to send to the API endpoint +for the patch model operation typically these are written to a http.Request +*/ +type PatchModelParams struct { + + /*ModelID + The id of the model. + + */ + ModelID string + /*Payload + Currently accepts "halt" as the only valid value. + + */ + Payload *restmodels.TrainingUpdate + /*Version + The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + + */ + Version string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the patch model params +func (o *PatchModelParams) WithTimeout(timeout time.Duration) *PatchModelParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the patch model params +func (o *PatchModelParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the patch model params +func (o *PatchModelParams) WithContext(ctx context.Context) *PatchModelParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the patch model params +func (o *PatchModelParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the patch model params +func (o *PatchModelParams) WithHTTPClient(client *http.Client) *PatchModelParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the patch model params +func (o *PatchModelParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithModelID adds the modelID to the patch model params +func (o *PatchModelParams) WithModelID(modelID string) *PatchModelParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the patch model params +func (o *PatchModelParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WithPayload adds the payload to the patch model params +func (o *PatchModelParams) WithPayload(payload *restmodels.TrainingUpdate) *PatchModelParams { + o.SetPayload(payload) + return o +} + +// SetPayload adds the payload to the patch model params +func (o *PatchModelParams) SetPayload(payload *restmodels.TrainingUpdate) { + o.Payload = payload +} + +// WithVersion adds the version to the patch model params +func (o *PatchModelParams) WithVersion(version string) *PatchModelParams { + o.SetVersion(version) + return o +} + +// SetVersion adds the version to the patch model params +func (o *PatchModelParams) SetVersion(version string) { + o.Version = version +} + +// WriteToRequest writes these params to a swagger request +func (o *PatchModelParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + if o.Payload == nil { + o.Payload = new(restmodels.TrainingUpdate) + } + + if err := r.SetBodyParam(o.Payload); err != nil { + return err + } + + // query param version + qrVersion := o.Version + qVersion := qrVersion + if qVersion != "" { + if err := r.SetQueryParam("version", qVersion); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/models/patch_model_responses.go b/di/restapi/api_v1/client/models/patch_model_responses.go new file mode 100644 index 0000000..c62c00b --- /dev/null +++ b/di/restapi/api_v1/client/models/patch_model_responses.go @@ -0,0 +1,175 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// PatchModelReader is a Reader for the PatchModel structure. +type PatchModelReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *PatchModelReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 202: + result := NewPatchModelAccepted() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 400: + result := NewPatchModelBadRequest() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 401: + result := NewPatchModelUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewPatchModelNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewPatchModelAccepted creates a PatchModelAccepted with default headers values +func NewPatchModelAccepted() *PatchModelAccepted { + return &PatchModelAccepted{} +} + +/*PatchModelAccepted handles this case with default header values. + +Training successfully halted. +*/ +type PatchModelAccepted struct { + Payload *restmodels.BasicModel +} + +func (o *PatchModelAccepted) Error() string { + return fmt.Sprintf("[PATCH /v1/models/{model_id}][%d] patchModelAccepted %+v", 202, o.Payload) +} + +func (o *PatchModelAccepted) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.BasicModel) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewPatchModelBadRequest creates a PatchModelBadRequest with default headers values +func NewPatchModelBadRequest() *PatchModelBadRequest { + return &PatchModelBadRequest{} +} + +/*PatchModelBadRequest handles this case with default header values. + +Incorrect status specified. +*/ +type PatchModelBadRequest struct { + Payload *restmodels.Error +} + +func (o *PatchModelBadRequest) Error() string { + return fmt.Sprintf("[PATCH /v1/models/{model_id}][%d] patchModelBadRequest %+v", 400, o.Payload) +} + +func (o *PatchModelBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewPatchModelUnauthorized creates a PatchModelUnauthorized with default headers values +func NewPatchModelUnauthorized() *PatchModelUnauthorized { + return &PatchModelUnauthorized{} +} + +/*PatchModelUnauthorized handles this case with default header values. + +Unauthorized +*/ +type PatchModelUnauthorized struct { + Payload *restmodels.Error +} + +func (o *PatchModelUnauthorized) Error() string { + return fmt.Sprintf("[PATCH /v1/models/{model_id}][%d] patchModelUnauthorized %+v", 401, o.Payload) +} + +func (o *PatchModelUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewPatchModelNotFound creates a PatchModelNotFound with default headers values +func NewPatchModelNotFound() *PatchModelNotFound { + return &PatchModelNotFound{} +} + +/*PatchModelNotFound handles this case with default header values. + +Model with the given ID not found. +*/ +type PatchModelNotFound struct { + Payload *restmodels.Error +} + +func (o *PatchModelNotFound) Error() string { + return fmt.Sprintf("[PATCH /v1/models/{model_id}][%d] patchModelNotFound %+v", 404, o.Payload) +} + +func (o *PatchModelNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/models/post_model_parameters.go b/di/restapi/api_v1/client/models/post_model_parameters.go new file mode 100644 index 0000000..4f4f1ec --- /dev/null +++ b/di/restapi/api_v1/client/models/post_model_parameters.go @@ -0,0 +1,204 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "os" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewPostModelParams creates a new PostModelParams object +// with the default values initialized. +func NewPostModelParams() *PostModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &PostModelParams{ + Version: versionDefault, + + timeout: cr.DefaultTimeout, + } +} + +// NewPostModelParamsWithTimeout creates a new PostModelParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewPostModelParamsWithTimeout(timeout time.Duration) *PostModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &PostModelParams{ + Version: versionDefault, + + timeout: timeout, + } +} + +// NewPostModelParamsWithContext creates a new PostModelParams object +// with the default values initialized, and the ability to set a context for a request +func NewPostModelParamsWithContext(ctx context.Context) *PostModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &PostModelParams{ + Version: versionDefault, + + Context: ctx, + } +} + +// NewPostModelParamsWithHTTPClient creates a new PostModelParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewPostModelParamsWithHTTPClient(client *http.Client) *PostModelParams { + var ( + versionDefault = string("2017-02-13") + ) + return &PostModelParams{ + Version: versionDefault, + HTTPClient: client, + } +} + +/*PostModelParams contains all the parameters to send to the API endpoint +for the post model operation typically these are written to a http.Request +*/ +type PostModelParams struct { + + /*Manifest + The manifest providing configuration for the deep learning model, the training data and the training execution. + + */ + Manifest os.File + /*ModelDefinition + The deep learning model code as compressed archive (ZIP). + + */ + ModelDefinition *os.File + /*Version + The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + + */ + Version string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the post model params +func (o *PostModelParams) WithTimeout(timeout time.Duration) *PostModelParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the post model params +func (o *PostModelParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the post model params +func (o *PostModelParams) WithContext(ctx context.Context) *PostModelParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the post model params +func (o *PostModelParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the post model params +func (o *PostModelParams) WithHTTPClient(client *http.Client) *PostModelParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the post model params +func (o *PostModelParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithManifest adds the manifest to the post model params +func (o *PostModelParams) WithManifest(manifest os.File) *PostModelParams { + o.SetManifest(manifest) + return o +} + +// SetManifest adds the manifest to the post model params +func (o *PostModelParams) SetManifest(manifest os.File) { + o.Manifest = manifest +} + +// WithModelDefinition adds the modelDefinition to the post model params +func (o *PostModelParams) WithModelDefinition(modelDefinition *os.File) *PostModelParams { + o.SetModelDefinition(modelDefinition) + return o +} + +// SetModelDefinition adds the modelDefinition to the post model params +func (o *PostModelParams) SetModelDefinition(modelDefinition *os.File) { + o.ModelDefinition = modelDefinition +} + +// WithVersion adds the version to the post model params +func (o *PostModelParams) WithVersion(version string) *PostModelParams { + o.SetVersion(version) + return o +} + +// SetVersion adds the version to the post model params +func (o *PostModelParams) SetVersion(version string) { + o.Version = version +} + +// WriteToRequest writes these params to a swagger request +func (o *PostModelParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // form file param manifest + if err := r.SetFileParam("manifest", &o.Manifest); err != nil { + return err + } + + if o.ModelDefinition != nil { + + if o.ModelDefinition != nil { + + // form file param model_definition + if err := r.SetFileParam("model_definition", o.ModelDefinition); err != nil { + return err + } + + } + + } + + // query param version + qrVersion := o.Version + qVersion := qrVersion + if qVersion != "" { + if err := r.SetQueryParam("version", qVersion); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/models/post_model_responses.go b/di/restapi/api_v1/client/models/post_model_responses.go new file mode 100644 index 0000000..c7e6ba1 --- /dev/null +++ b/di/restapi/api_v1/client/models/post_model_responses.go @@ -0,0 +1,146 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// PostModelReader is a Reader for the PostModel structure. +type PostModelReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *PostModelReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 201: + result := NewPostModelCreated() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 400: + result := NewPostModelBadRequest() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 401: + result := NewPostModelUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewPostModelCreated creates a PostModelCreated with default headers values +func NewPostModelCreated() *PostModelCreated { + return &PostModelCreated{} +} + +/*PostModelCreated handles this case with default header values. + +Deep learning model successfully accepted. +*/ +type PostModelCreated struct { + /*Location header containing the model id. + */ + Location string + + Payload *restmodels.BasicNewModel +} + +func (o *PostModelCreated) Error() string { + return fmt.Sprintf("[POST /v1/models][%d] postModelCreated %+v", 201, o.Payload) +} + +func (o *PostModelCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response header Location + o.Location = response.GetHeader("Location") + + o.Payload = new(restmodels.BasicNewModel) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewPostModelBadRequest creates a PostModelBadRequest with default headers values +func NewPostModelBadRequest() *PostModelBadRequest { + return &PostModelBadRequest{} +} + +/*PostModelBadRequest handles this case with default header values. + +Error in the the model_definition or manifest. +*/ +type PostModelBadRequest struct { + Payload *restmodels.Error +} + +func (o *PostModelBadRequest) Error() string { + return fmt.Sprintf("[POST /v1/models][%d] postModelBadRequest %+v", 400, o.Payload) +} + +func (o *PostModelBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewPostModelUnauthorized creates a PostModelUnauthorized with default headers values +func NewPostModelUnauthorized() *PostModelUnauthorized { + return &PostModelUnauthorized{} +} + +/*PostModelUnauthorized handles this case with default header values. + +Unauthorized +*/ +type PostModelUnauthorized struct { + Payload *restmodels.Error +} + +func (o *PostModelUnauthorized) Error() string { + return fmt.Sprintf("[POST /v1/models][%d] postModelUnauthorized %+v", 401, o.Payload) +} + +func (o *PostModelUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/operations/get_dashboards_parameters.go b/di/restapi/api_v1/client/operations/get_dashboards_parameters.go new file mode 100644 index 0000000..f020839 --- /dev/null +++ b/di/restapi/api_v1/client/operations/get_dashboards_parameters.go @@ -0,0 +1,113 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetDashboardsParams creates a new GetDashboardsParams object +// with the default values initialized. +func NewGetDashboardsParams() *GetDashboardsParams { + + return &GetDashboardsParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewGetDashboardsParamsWithTimeout creates a new GetDashboardsParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetDashboardsParamsWithTimeout(timeout time.Duration) *GetDashboardsParams { + + return &GetDashboardsParams{ + + timeout: timeout, + } +} + +// NewGetDashboardsParamsWithContext creates a new GetDashboardsParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetDashboardsParamsWithContext(ctx context.Context) *GetDashboardsParams { + + return &GetDashboardsParams{ + + Context: ctx, + } +} + +// NewGetDashboardsParamsWithHTTPClient creates a new GetDashboardsParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetDashboardsParamsWithHTTPClient(client *http.Client) *GetDashboardsParams { + + return &GetDashboardsParams{ + HTTPClient: client, + } +} + +/*GetDashboardsParams contains all the parameters to send to the API endpoint +for the get dashboards operation typically these are written to a http.Request +*/ +type GetDashboardsParams struct { + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get dashboards params +func (o *GetDashboardsParams) WithTimeout(timeout time.Duration) *GetDashboardsParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get dashboards params +func (o *GetDashboardsParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get dashboards params +func (o *GetDashboardsParams) WithContext(ctx context.Context) *GetDashboardsParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get dashboards params +func (o *GetDashboardsParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get dashboards params +func (o *GetDashboardsParams) WithHTTPClient(client *http.Client) *GetDashboardsParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get dashboards params +func (o *GetDashboardsParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WriteToRequest writes these params to a swagger request +func (o *GetDashboardsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/operations/get_dashboards_responses.go b/di/restapi/api_v1/client/operations/get_dashboards_responses.go new file mode 100644 index 0000000..9a43b68 --- /dev/null +++ b/di/restapi/api_v1/client/operations/get_dashboards_responses.go @@ -0,0 +1,139 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// GetDashboardsReader is a Reader for the GetDashboards structure. +type GetDashboardsReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetDashboardsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewGetDashboardsOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 403: + result := NewGetDashboardsForbidden() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + case 404: + result := NewGetDashboardsNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewGetDashboardsOK creates a GetDashboardsOK with default headers values +func NewGetDashboardsOK() *GetDashboardsOK { + return &GetDashboardsOK{} +} + +/*GetDashboardsOK handles this case with default header values. + +OK +*/ +type GetDashboardsOK struct { + Payload *restmodels.GetDashboardsResponse +} + +func (o *GetDashboardsOK) Error() string { + return fmt.Sprintf("[GET /v1/dashboards][%d] getDashboardsOK %+v", 200, o.Payload) +} + +func (o *GetDashboardsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.GetDashboardsResponse) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetDashboardsForbidden creates a GetDashboardsForbidden with default headers values +func NewGetDashboardsForbidden() *GetDashboardsForbidden { + return &GetDashboardsForbidden{} +} + +/*GetDashboardsForbidden handles this case with default header values. + +Forbidden +*/ +type GetDashboardsForbidden struct { + Payload *restmodels.Error +} + +func (o *GetDashboardsForbidden) Error() string { + return fmt.Sprintf("[GET /v1/dashboards][%d] getDashboardsForbidden %+v", 403, o.Payload) +} + +func (o *GetDashboardsForbidden) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetDashboardsNotFound creates a GetDashboardsNotFound with default headers values +func NewGetDashboardsNotFound() *GetDashboardsNotFound { + return &GetDashboardsNotFound{} +} + +/*GetDashboardsNotFound handles this case with default header values. + +The dashboard cannot be found +*/ +type GetDashboardsNotFound struct { + Payload *restmodels.Error +} + +func (o *GetDashboardsNotFound) Error() string { + return fmt.Sprintf("[GET /v1/dashboards][%d] getDashboardsNotFound %+v", 404, o.Payload) +} + +func (o *GetDashboardsNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/operations/operations_client.go b/di/restapi/api_v1/client/operations/operations_client.go new file mode 100644 index 0000000..c68f458 --- /dev/null +++ b/di/restapi/api_v1/client/operations/operations_client.go @@ -0,0 +1,61 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" +) + +// New creates a new operations API client. +func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client { + return &Client{transport: transport, formats: formats} +} + +/* +Client for operations API +*/ +type Client struct { + transport runtime.ClientTransport + formats strfmt.Registry +} + +/* +GetDashboards gets the dashboard belongs to a user + +Get dashboard. +*/ +func (a *Client) GetDashboards(params *GetDashboardsParams, authInfo runtime.ClientAuthInfoWriter) (*GetDashboardsOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetDashboardsParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "getDashboards", + Method: "GET", + PathPattern: "/v1/dashboards", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &GetDashboardsReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*GetDashboardsOK), nil + +} + +// SetTransport changes the transport on the client +func (a *Client) SetTransport(transport runtime.ClientTransport) { + a.transport = transport +} diff --git a/di/restapi/api_v1/client/training_data/get_loglines_parameters.go b/di/restapi/api_v1/client/training_data/get_loglines_parameters.go new file mode 100644 index 0000000..2c375d2 --- /dev/null +++ b/di/restapi/api_v1/client/training_data/get_loglines_parameters.go @@ -0,0 +1,323 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package training_data + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/swag" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetLoglinesParams creates a new GetLoglinesParams object +// with the default values initialized. +func NewGetLoglinesParams() *GetLoglinesParams { + var ( + searchTypeDefault = string("TERM") + sinceTimeDefault = string("") + versionDefault = string("2017-10-01") + ) + return &GetLoglinesParams{ + SearchType: &searchTypeDefault, + SinceTime: &sinceTimeDefault, + Version: &versionDefault, + + timeout: cr.DefaultTimeout, + } +} + +// NewGetLoglinesParamsWithTimeout creates a new GetLoglinesParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetLoglinesParamsWithTimeout(timeout time.Duration) *GetLoglinesParams { + var ( + searchTypeDefault = string("TERM") + sinceTimeDefault = string("") + versionDefault = string("2017-10-01") + ) + return &GetLoglinesParams{ + SearchType: &searchTypeDefault, + SinceTime: &sinceTimeDefault, + Version: &versionDefault, + + timeout: timeout, + } +} + +// NewGetLoglinesParamsWithContext creates a new GetLoglinesParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetLoglinesParamsWithContext(ctx context.Context) *GetLoglinesParams { + var ( + searchTypeDefault = string("TERM") + sinceTimeDefault = string("") + versionDefault = string("2017-10-01") + ) + return &GetLoglinesParams{ + SearchType: &searchTypeDefault, + SinceTime: &sinceTimeDefault, + Version: &versionDefault, + + Context: ctx, + } +} + +// NewGetLoglinesParamsWithHTTPClient creates a new GetLoglinesParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetLoglinesParamsWithHTTPClient(client *http.Client) *GetLoglinesParams { + var ( + searchTypeDefault = string("TERM") + sinceTimeDefault = string("") + versionDefault = string("2017-10-01") + ) + return &GetLoglinesParams{ + SearchType: &searchTypeDefault, + SinceTime: &sinceTimeDefault, + Version: &versionDefault, + HTTPClient: client, + } +} + +/*GetLoglinesParams contains all the parameters to send to the API endpoint +for the get loglines operation typically these are written to a http.Request +*/ +type GetLoglinesParams struct { + + /*ModelID + The id of the model. + + */ + ModelID string + /*Pagesize + Number of lines to output. + + */ + Pagesize *int32 + /*Pos + If positive, line number from start, if negative line counting from end + + */ + Pos *int64 + /*SearchType*/ + SearchType *string + /*SinceTime + Time from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will be returned. If this value is a raw integer, it represents the time that the metric occured: representing the number of milliseconds since midnight January 1, 1970. If this value is a negative integer, it represents the number of lines to count backwards. If this value is empty, the logs since the beginning of the job will be returned + + */ + SinceTime *string + /*Version + The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + + */ + Version *string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get loglines params +func (o *GetLoglinesParams) WithTimeout(timeout time.Duration) *GetLoglinesParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get loglines params +func (o *GetLoglinesParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get loglines params +func (o *GetLoglinesParams) WithContext(ctx context.Context) *GetLoglinesParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get loglines params +func (o *GetLoglinesParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get loglines params +func (o *GetLoglinesParams) WithHTTPClient(client *http.Client) *GetLoglinesParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get loglines params +func (o *GetLoglinesParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithModelID adds the modelID to the get loglines params +func (o *GetLoglinesParams) WithModelID(modelID string) *GetLoglinesParams { + o.SetModelID(modelID) + return o +} + +// SetModelID adds the modelId to the get loglines params +func (o *GetLoglinesParams) SetModelID(modelID string) { + o.ModelID = modelID +} + +// WithPagesize adds the pagesize to the get loglines params +func (o *GetLoglinesParams) WithPagesize(pagesize *int32) *GetLoglinesParams { + o.SetPagesize(pagesize) + return o +} + +// SetPagesize adds the pagesize to the get loglines params +func (o *GetLoglinesParams) SetPagesize(pagesize *int32) { + o.Pagesize = pagesize +} + +// WithPos adds the pos to the get loglines params +func (o *GetLoglinesParams) WithPos(pos *int64) *GetLoglinesParams { + o.SetPos(pos) + return o +} + +// SetPos adds the pos to the get loglines params +func (o *GetLoglinesParams) SetPos(pos *int64) { + o.Pos = pos +} + +// WithSearchType adds the searchType to the get loglines params +func (o *GetLoglinesParams) WithSearchType(searchType *string) *GetLoglinesParams { + o.SetSearchType(searchType) + return o +} + +// SetSearchType adds the searchType to the get loglines params +func (o *GetLoglinesParams) SetSearchType(searchType *string) { + o.SearchType = searchType +} + +// WithSinceTime adds the sinceTime to the get loglines params +func (o *GetLoglinesParams) WithSinceTime(sinceTime *string) *GetLoglinesParams { + o.SetSinceTime(sinceTime) + return o +} + +// SetSinceTime adds the sinceTime to the get loglines params +func (o *GetLoglinesParams) SetSinceTime(sinceTime *string) { + o.SinceTime = sinceTime +} + +// WithVersion adds the version to the get loglines params +func (o *GetLoglinesParams) WithVersion(version *string) *GetLoglinesParams { + o.SetVersion(version) + return o +} + +// SetVersion adds the version to the get loglines params +func (o *GetLoglinesParams) SetVersion(version *string) { + o.Version = version +} + +// WriteToRequest writes these params to a swagger request +func (o *GetLoglinesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param model_id + if err := r.SetPathParam("model_id", o.ModelID); err != nil { + return err + } + + if o.Pagesize != nil { + + // query param pagesize + var qrPagesize int32 + if o.Pagesize != nil { + qrPagesize = *o.Pagesize + } + qPagesize := swag.FormatInt32(qrPagesize) + if qPagesize != "" { + if err := r.SetQueryParam("pagesize", qPagesize); err != nil { + return err + } + } + + } + + if o.Pos != nil { + + // query param pos + var qrPos int64 + if o.Pos != nil { + qrPos = *o.Pos + } + qPos := swag.FormatInt64(qrPos) + if qPos != "" { + if err := r.SetQueryParam("pos", qPos); err != nil { + return err + } + } + + } + + if o.SearchType != nil { + + // query param searchType + var qrSearchType string + if o.SearchType != nil { + qrSearchType = *o.SearchType + } + qSearchType := qrSearchType + if qSearchType != "" { + if err := r.SetQueryParam("searchType", qSearchType); err != nil { + return err + } + } + + } + + if o.SinceTime != nil { + + // query param since_time + var qrSinceTime string + if o.SinceTime != nil { + qrSinceTime = *o.SinceTime + } + qSinceTime := qrSinceTime + if qSinceTime != "" { + if err := r.SetQueryParam("since_time", qSinceTime); err != nil { + return err + } + } + + } + + if o.Version != nil { + + // query param version + var qrVersion string + if o.Version != nil { + qrVersion = *o.Version + } + qVersion := qrVersion + if qVersion != "" { + if err := r.SetQueryParam("version", qVersion); err != nil { + return err + } + } + + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/client/training_data/get_loglines_responses.go b/di/restapi/api_v1/client/training_data/get_loglines_responses.go new file mode 100644 index 0000000..0265fb5 --- /dev/null +++ b/di/restapi/api_v1/client/training_data/get_loglines_responses.go @@ -0,0 +1,103 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package training_data + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + "webank/DI/restapi/api_v1/restmodels" +) + +// GetLoglinesReader is a Reader for the GetLoglines structure. +type GetLoglinesReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetLoglinesReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 200: + result := NewGetLoglinesOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 401: + result := NewGetLoglinesUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + return nil, runtime.NewAPIError("unknown error", response, response.Code()) + } +} + +// NewGetLoglinesOK creates a GetLoglinesOK with default headers values +func NewGetLoglinesOK() *GetLoglinesOK { + return &GetLoglinesOK{} +} + +/*GetLoglinesOK handles this case with default header values. + +(streaming responses) +*/ +type GetLoglinesOK struct { + Payload *restmodels.V1LogLinesList +} + +func (o *GetLoglinesOK) Error() string { + return fmt.Sprintf("[GET /di/v1/logs/{model_id}/loglines][%d] getLoglinesOK %+v", 200, o.Payload) +} + +func (o *GetLoglinesOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.V1LogLinesList) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetLoglinesUnauthorized creates a GetLoglinesUnauthorized with default headers values +func NewGetLoglinesUnauthorized() *GetLoglinesUnauthorized { + return &GetLoglinesUnauthorized{} +} + +/*GetLoglinesUnauthorized handles this case with default header values. + +Unauthorized +*/ +type GetLoglinesUnauthorized struct { + Payload *restmodels.Error +} + +func (o *GetLoglinesUnauthorized) Error() string { + return fmt.Sprintf("[GET /di/v1/logs/{model_id}/loglines][%d] getLoglinesUnauthorized %+v", 401, o.Payload) +} + +func (o *GetLoglinesUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(restmodels.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/di/restapi/api_v1/client/training_data/training_data_client.go b/di/restapi/api_v1/client/training_data/training_data_client.go new file mode 100644 index 0000000..2bf4a0e --- /dev/null +++ b/di/restapi/api_v1/client/training_data/training_data_client.go @@ -0,0 +1,88 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package training_data + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" +) + +// New creates a new training data API client. +func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client { + return &Client{transport: transport, formats: formats} +} + +/* +Client for training data API +*/ +type Client struct { + transport runtime.ClientTransport + formats strfmt.Registry +} +// +///* +//GetEMetrics gets evaluation metrics records based on query +//*/ +//func (a *Client) GetEMetrics(params *GetEMetricsParams, authInfo runtime.ClientAuthInfoWriter) (*GetEMetricsOK, error) { +// // TODO: Validate the params before sending +// if params == nil { +// params = NewGetEMetricsParams() +// } +// +// result, err := a.transport.Submit(&runtime.ClientOperation{ +// ID: "getEMetrics", +// Method: "GET", +// PathPattern: "/di/v1/logs/{model_id}/emetrics", +// ProducesMediaTypes: []string{"application/json"}, +// ConsumesMediaTypes: []string{"application/json"}, +// Schemes: []string{"https"}, +// Params: params, +// Reader: &GetEMetricsReader{formats: a.formats}, +// AuthInfo: authInfo, +// Context: params.Context, +// Client: params.HTTPClient, +// }) +// if err != nil { +// return nil, err +// } +// return result.(*GetEMetricsOK), nil +// +//} + +/* +GetLoglines gets loglines based on query +*/ +func (a *Client) GetLoglines(params *GetLoglinesParams, authInfo runtime.ClientAuthInfoWriter) (*GetLoglinesOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetLoglinesParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "getLoglines", + Method: "GET", + PathPattern: "/di/v1/logs/{model_id}/loglines", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &GetLoglinesReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*GetLoglinesOK), nil + +} + +// SetTransport changes the transport on the client +func (a *Client) SetTransport(transport runtime.ClientTransport) { + a.transport = transport +} diff --git a/di/restapi/api_v1/restmodels/basic_model.go b/di/restapi/api_v1/restmodels/basic_model.go new file mode 100644 index 0000000..046a448 --- /dev/null +++ b/di/restapi/api_v1/restmodels/basic_model.go @@ -0,0 +1,43 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// BasicModel basic model +// swagger:model BasicModel +type BasicModel struct { + + // A unique id of the deep learning model. + ModelID string `json:"model_id,omitempty"` +} + +// Validate validates this basic model +func (m *BasicModel) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *BasicModel) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *BasicModel) UnmarshalBinary(b []byte) error { + var res BasicModel + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/basic_new_model.go b/di/restapi/api_v1/restmodels/basic_new_model.go new file mode 100644 index 0000000..933fcfe --- /dev/null +++ b/di/restapi/api_v1/restmodels/basic_new_model.go @@ -0,0 +1,102 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" +) + +// BasicNewModel basic new model +// swagger:model BasicNewModel +type BasicNewModel struct { + BasicModel + + // Location of the model to retrieve it. + Location string `json:"location,omitempty"` +} + +// UnmarshalJSON unmarshals this object from a JSON structure +func (m *BasicNewModel) UnmarshalJSON(raw []byte) error { + // AO0 + var aO0 BasicModel + if err := swag.ReadJSON(raw, &aO0); err != nil { + return err + } + m.BasicModel = aO0 + + // AO1 + var dataAO1 struct { + Location string `json:"location,omitempty"` + } + if err := swag.ReadJSON(raw, &dataAO1); err != nil { + return err + } + + m.Location = dataAO1.Location + + return nil +} + +// MarshalJSON marshals this object to a JSON structure +func (m BasicNewModel) MarshalJSON() ([]byte, error) { + _parts := make([][]byte, 0, 2) + + aO0, err := swag.WriteJSON(m.BasicModel) + if err != nil { + return nil, err + } + _parts = append(_parts, aO0) + + var dataAO1 struct { + Location string `json:"location,omitempty"` + } + + dataAO1.Location = m.Location + + jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1) + if errAO1 != nil { + return nil, errAO1 + } + _parts = append(_parts, jsonDataAO1) + + return swag.ConcatJSON(_parts...), nil +} + +// Validate validates this basic new model +func (m *BasicNewModel) Validate(formats strfmt.Registry) error { + var res []error + + // validation for a type composition with BasicModel + if err := m.BasicModel.Validate(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// MarshalBinary interface implementation +func (m *BasicNewModel) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *BasicNewModel) UnmarshalBinary(b []byte) error { + var res BasicNewModel + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/code_upload_response.go b/di/restapi/api_v1/restmodels/code_upload_response.go new file mode 100644 index 0000000..0c90c80 --- /dev/null +++ b/di/restapi/api_v1/restmodels/code_upload_response.go @@ -0,0 +1,43 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// CodeUploadResponse code upload response +// swagger:model CodeUploadResponse +type CodeUploadResponse struct { + + // S3 Path + S3Path string `json:"s3Path,omitempty"` +} + +// Validate validates this code upload response +func (m *CodeUploadResponse) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *CodeUploadResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *CodeUploadResponse) UnmarshalBinary(b []byte) error { + var res CodeUploadResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/datastore.go b/di/restapi/api_v1/restmodels/datastore.go new file mode 100644 index 0000000..d8fa232 --- /dev/null +++ b/di/restapi/api_v1/restmodels/datastore.go @@ -0,0 +1,49 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// Datastore datastore +// swagger:model Datastore +type Datastore struct { + + // connection + Connection map[string]string `json:"connection,omitempty"` + + // the id of the data store as defined in the manifest. + DataStoreID string `json:"data_store_id,omitempty"` + + // the type of the data store as defined in the manifest. + Type string `json:"type,omitempty"` +} + +// Validate validates this datastore +func (m *Datastore) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *Datastore) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Datastore) UnmarshalBinary(b []byte) error { + var res Datastore + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/endpoint.go b/di/restapi/api_v1/restmodels/endpoint.go new file mode 100644 index 0000000..d7051a7 --- /dev/null +++ b/di/restapi/api_v1/restmodels/endpoint.go @@ -0,0 +1,46 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// Endpoint endpoint +// swagger:model Endpoint +type Endpoint struct { + + // the id of the endpoint + ID string `json:"id,omitempty"` + + // the url of the endpoint + URL string `json:"url,omitempty"` +} + +// Validate validates this endpoint +func (m *Endpoint) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *Endpoint) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Endpoint) UnmarshalBinary(b []byte) error { + var res Endpoint + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/endpoint_list.go b/di/restapi/api_v1/restmodels/endpoint_list.go new file mode 100644 index 0000000..1714f1b --- /dev/null +++ b/di/restapi/api_v1/restmodels/endpoint_list.go @@ -0,0 +1,80 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "strconv" + + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" +) + +// EndpointList endpoint list +// swagger:model EndpointList +type EndpointList struct { + + // endpoints + Endpoints []*Endpoint `json:"endpoints"` +} + +// Validate validates this endpoint list +func (m *EndpointList) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateEndpoints(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *EndpointList) validateEndpoints(formats strfmt.Registry) error { + + if swag.IsZero(m.Endpoints) { // not required + return nil + } + + for i := 0; i < len(m.Endpoints); i++ { + if swag.IsZero(m.Endpoints[i]) { // not required + continue + } + + if m.Endpoints[i] != nil { + if err := m.Endpoints[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("endpoints" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *EndpointList) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *EndpointList) UnmarshalBinary(b []byte) error { + var res EndpointList + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/error.go b/di/restapi/api_v1/restmodels/error.go new file mode 100644 index 0000000..79bb6d5 --- /dev/null +++ b/di/restapi/api_v1/restmodels/error.go @@ -0,0 +1,49 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// Error error +// swagger:model Error +type Error struct { + + // code + Code int32 `json:"code,omitempty"` + + // error + Error string `json:"error,omitempty"` + + // msg + Msg string `json:"msg,omitempty"` +} + +// Validate validates this error +func (m *Error) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *Error) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Error) UnmarshalBinary(b []byte) error { + var res Error + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/event_endpoint_registration.go b/di/restapi/api_v1/restmodels/event_endpoint_registration.go new file mode 100644 index 0000000..64fff06 --- /dev/null +++ b/di/restapi/api_v1/restmodels/event_endpoint_registration.go @@ -0,0 +1,46 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// EventEndpointRegistration event endpoint registration +// swagger:model EventEndpointRegistration +type EventEndpointRegistration struct { + + // The type of event this URL should be notified of. + Type string `json:"type,omitempty"` + + // The URL to notify on events. + URL string `json:"url,omitempty"` +} + +// Validate validates this event endpoint registration +func (m *EventEndpointRegistration) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *EventEndpointRegistration) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *EventEndpointRegistration) UnmarshalBinary(b []byte) error { + var res EventEndpointRegistration + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/fields.go b/di/restapi/api_v1/restmodels/fields.go new file mode 100644 index 0000000..0b562c0 --- /dev/null +++ b/di/restapi/api_v1/restmodels/fields.go @@ -0,0 +1,49 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// Fields TFOS Archives & PyFile Fields +// swagger:model Fields +type Fields struct { + + // HDFS Path. + Hdfs string `json:"hdfs,omitempty"` + + // BML Resource ID. + ResourceID string `json:"resource_id,omitempty"` + + // BML Resource Version. + Version string `json:"version,omitempty"` +} + +// Validate validates this fields +func (m *Fields) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *Fields) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Fields) UnmarshalBinary(b []byte) error { + var res Fields + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/framework.go b/di/restapi/api_v1/restmodels/framework.go new file mode 100644 index 0000000..f18c4d2 --- /dev/null +++ b/di/restapi/api_v1/restmodels/framework.go @@ -0,0 +1,46 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// Framework framework +// swagger:model Framework +type Framework struct { + + // the name of the deep learning framework (e.g. caffe, torch, tensorflow) + Name string `json:"name,omitempty"` + + // the version of the specific framework to use. + Version string `json:"version,omitempty"` +} + +// Validate validates this framework +func (m *Framework) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *Framework) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Framework) UnmarshalBinary(b []byte) error { + var res Framework + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/get_dashboards_response.go b/di/restapi/api_v1/restmodels/get_dashboards_response.go new file mode 100644 index 0000000..8596a8b --- /dev/null +++ b/di/restapi/api_v1/restmodels/get_dashboards_response.go @@ -0,0 +1,49 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// GetDashboardsResponse get dashboards response +// swagger:model GetDashboardsResponse +type GetDashboardsResponse struct { + + // number of cpu. + Cpus string `json:"cpus,omitempty"` + + // number of running instances. + RunningInstances string `json:"runningInstances,omitempty"` + + // total number of instances. + TotalInstances string `json:"totalInstances,omitempty"` +} + +// Validate validates this get dashboards response +func (m *GetDashboardsResponse) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *GetDashboardsResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *GetDashboardsResponse) UnmarshalBinary(b []byte) error { + var res GetDashboardsResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/metric_data.go b/di/restapi/api_v1/restmodels/metric_data.go new file mode 100644 index 0000000..d27779d --- /dev/null +++ b/di/restapi/api_v1/restmodels/metric_data.go @@ -0,0 +1,53 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// MetricData metric data +// swagger:model MetricData +type MetricData struct { + + // map of key/values, that describe evaluation metrics + Values map[string]interface{} `json:"Values,omitempty"` + + // Current iteration number be processed. + Iteration int32 `json:"iteration,omitempty"` + + // Timestamp of the metric. Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' + // + Timestamp string `json:"timestamp,omitempty"` + + // The type of metrics data + Type string `json:"type,omitempty"` +} + +// Validate validates this metric data +func (m *MetricData) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *MetricData) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *MetricData) UnmarshalBinary(b []byte) error { + var res MetricData + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/model.go b/di/restapi/api_v1/restmodels/model.go new file mode 100644 index 0000000..3afdf5b --- /dev/null +++ b/di/restapi/api_v1/restmodels/model.go @@ -0,0 +1,408 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "strconv" + + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" +) + +// Model model +// swagger:model Model +type Model struct { + BasicNewModel + + // Job Alert String. + JobAlert string `json:"JobAlert,omitempty"` + + // Job Type. + JobType string `json:"JobType,omitempty"` + + // TFosRequest + TFosRequest *TFosRequest `json:"TFosRequest,omitempty"` + + // completed timestamp of the job + CompletedTimestamp string `json:"completed_timestamp,omitempty"` + + // data stores + DataStores []*Datastore `json:"data_stores"` + + // Detailed description of deep learning model. + Description string `json:"description,omitempty"` + + // Experiment Name + ExpName string `json:"expName,omitempty"` + + // Experiment Run Id + ExpRunID string `json:"expRunId,omitempty"` + + // Code File's Name + FileName string `json:"fileName,omitempty"` + + // Code File's Path + FilePath string `json:"filePath,omitempty"` + + // framework + Framework *Framework `json:"framework,omitempty"` + + // job's namespace. + JobNamespace string `json:"job_namespace,omitempty"` + + // The name of the deep learning model. + Name string `json:"name,omitempty"` + + // Count of Param Server + PsCPU string `json:"ps_cpu,omitempty"` + + // Count of Param Server + PsImage string `json:"ps_image,omitempty"` + + // Count of Param Server + PsMemory string `json:"ps_memory,omitempty"` + + // Count of Param Server + Pss string `json:"pss,omitempty"` + + // submission timestamp of the job. + SubmissionTimestamp string `json:"submission_timestamp,omitempty"` + + // training + Training *Training `json:"training,omitempty"` + + // user name. + UserID string `json:"user_id,omitempty"` +} + +// UnmarshalJSON unmarshals this object from a JSON structure +func (m *Model) UnmarshalJSON(raw []byte) error { + // AO0 + var aO0 BasicNewModel + if err := swag.ReadJSON(raw, &aO0); err != nil { + return err + } + m.BasicNewModel = aO0 + + // AO1 + var dataAO1 struct { + JobAlert string `json:"JobAlert,omitempty"` + + JobType string `json:"JobType,omitempty"` + + TFosRequest *TFosRequest `json:"TFosRequest,omitempty"` + + CompletedTimestamp string `json:"completed_timestamp,omitempty"` + + DataStores []*Datastore `json:"data_stores"` + + Description string `json:"description,omitempty"` + + ExpName string `json:"expName,omitempty"` + + ExpRunID string `json:"expRunId,omitempty"` + + FileName string `json:"fileName,omitempty"` + + FilePath string `json:"filePath,omitempty"` + + Framework *Framework `json:"framework,omitempty"` + + JobNamespace string `json:"job_namespace,omitempty"` + + Name string `json:"name,omitempty"` + + PsCPU string `json:"ps_cpu,omitempty"` + + PsImage string `json:"ps_image,omitempty"` + + PsMemory string `json:"ps_memory,omitempty"` + + Pss string `json:"pss,omitempty"` + + SubmissionTimestamp string `json:"submission_timestamp,omitempty"` + + Training *Training `json:"training,omitempty"` + + UserID string `json:"user_id,omitempty"` + } + if err := swag.ReadJSON(raw, &dataAO1); err != nil { + return err + } + + m.JobAlert = dataAO1.JobAlert + + m.JobType = dataAO1.JobType + + m.TFosRequest = dataAO1.TFosRequest + + m.CompletedTimestamp = dataAO1.CompletedTimestamp + + m.DataStores = dataAO1.DataStores + + m.Description = dataAO1.Description + + m.ExpName = dataAO1.ExpName + + m.ExpRunID = dataAO1.ExpRunID + + m.FileName = dataAO1.FileName + + m.FilePath = dataAO1.FilePath + + m.Framework = dataAO1.Framework + + m.JobNamespace = dataAO1.JobNamespace + + m.Name = dataAO1.Name + + m.PsCPU = dataAO1.PsCPU + + m.PsImage = dataAO1.PsImage + + m.PsMemory = dataAO1.PsMemory + + m.Pss = dataAO1.Pss + + m.SubmissionTimestamp = dataAO1.SubmissionTimestamp + + m.Training = dataAO1.Training + + m.UserID = dataAO1.UserID + + return nil +} + +// MarshalJSON marshals this object to a JSON structure +func (m Model) MarshalJSON() ([]byte, error) { + _parts := make([][]byte, 0, 2) + + aO0, err := swag.WriteJSON(m.BasicNewModel) + if err != nil { + return nil, err + } + _parts = append(_parts, aO0) + + var dataAO1 struct { + JobAlert string `json:"JobAlert,omitempty"` + + JobType string `json:"JobType,omitempty"` + + TFosRequest *TFosRequest `json:"TFosRequest,omitempty"` + + CompletedTimestamp string `json:"completed_timestamp,omitempty"` + + DataStores []*Datastore `json:"data_stores"` + + Description string `json:"description,omitempty"` + + ExpName string `json:"expName,omitempty"` + + ExpRunID string `json:"expRunId,omitempty"` + + FileName string `json:"fileName,omitempty"` + + FilePath string `json:"filePath,omitempty"` + + Framework *Framework `json:"framework,omitempty"` + + JobNamespace string `json:"job_namespace,omitempty"` + + Name string `json:"name,omitempty"` + + PsCPU string `json:"ps_cpu,omitempty"` + + PsImage string `json:"ps_image,omitempty"` + + PsMemory string `json:"ps_memory,omitempty"` + + Pss string `json:"pss,omitempty"` + + SubmissionTimestamp string `json:"submission_timestamp,omitempty"` + + Training *Training `json:"training,omitempty"` + + UserID string `json:"user_id,omitempty"` + } + + dataAO1.JobAlert = m.JobAlert + + dataAO1.JobType = m.JobType + + dataAO1.TFosRequest = m.TFosRequest + + dataAO1.CompletedTimestamp = m.CompletedTimestamp + + dataAO1.DataStores = m.DataStores + + dataAO1.Description = m.Description + + dataAO1.ExpName = m.ExpName + + dataAO1.ExpRunID = m.ExpRunID + + dataAO1.FileName = m.FileName + + dataAO1.FilePath = m.FilePath + + dataAO1.Framework = m.Framework + + dataAO1.JobNamespace = m.JobNamespace + + dataAO1.Name = m.Name + + dataAO1.PsCPU = m.PsCPU + + dataAO1.PsImage = m.PsImage + + dataAO1.PsMemory = m.PsMemory + + dataAO1.Pss = m.Pss + + dataAO1.SubmissionTimestamp = m.SubmissionTimestamp + + dataAO1.Training = m.Training + + dataAO1.UserID = m.UserID + + jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1) + if errAO1 != nil { + return nil, errAO1 + } + _parts = append(_parts, jsonDataAO1) + + return swag.ConcatJSON(_parts...), nil +} + +// Validate validates this model +func (m *Model) Validate(formats strfmt.Registry) error { + var res []error + + // validation for a type composition with BasicNewModel + if err := m.BasicNewModel.Validate(formats); err != nil { + res = append(res, err) + } + + if err := m.validateTFosRequest(formats); err != nil { + res = append(res, err) + } + + if err := m.validateDataStores(formats); err != nil { + res = append(res, err) + } + + if err := m.validateFramework(formats); err != nil { + res = append(res, err) + } + + if err := m.validateTraining(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Model) validateTFosRequest(formats strfmt.Registry) error { + + if swag.IsZero(m.TFosRequest) { // not required + return nil + } + + if m.TFosRequest != nil { + if err := m.TFosRequest.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("TFosRequest") + } + return err + } + } + + return nil +} + +func (m *Model) validateDataStores(formats strfmt.Registry) error { + + if swag.IsZero(m.DataStores) { // not required + return nil + } + + for i := 0; i < len(m.DataStores); i++ { + if swag.IsZero(m.DataStores[i]) { // not required + continue + } + + if m.DataStores[i] != nil { + if err := m.DataStores[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("data_stores" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *Model) validateFramework(formats strfmt.Registry) error { + + if swag.IsZero(m.Framework) { // not required + return nil + } + + if m.Framework != nil { + if err := m.Framework.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("framework") + } + return err + } + } + + return nil +} + +func (m *Model) validateTraining(formats strfmt.Registry) error { + + if swag.IsZero(m.Training) { // not required + return nil + } + + if m.Training != nil { + if err := m.Training.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("training") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *Model) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Model) UnmarshalBinary(b []byte) error { + var res Model + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/model_list.go b/di/restapi/api_v1/restmodels/model_list.go new file mode 100644 index 0000000..732e015 --- /dev/null +++ b/di/restapi/api_v1/restmodels/model_list.go @@ -0,0 +1,86 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "strconv" + + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" +) + +// ModelList model list +// swagger:model ModelList +type ModelList struct { + + // models + Models []*Model `json:"models"` + + // pages + Pages int64 `json:"pages,omitempty"` + + // total + Total int64 `json:"total,omitempty"` +} + +// Validate validates this model list +func (m *ModelList) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateModels(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *ModelList) validateModels(formats strfmt.Registry) error { + + if swag.IsZero(m.Models) { // not required + return nil + } + + for i := 0; i < len(m.Models); i++ { + if swag.IsZero(m.Models[i]) { // not required + continue + } + + if m.Models[i] != nil { + if err := m.Models[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("models" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *ModelList) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *ModelList) UnmarshalBinary(b []byte) error { + var res ModelList + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/query_search_type.go b/di/restapi/api_v1/restmodels/query_search_type.go new file mode 100644 index 0000000..08873bf --- /dev/null +++ b/di/restapi/api_v1/restmodels/query_search_type.go @@ -0,0 +1,69 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "encoding/json" + + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/validate" +) + +// QuerySearchType query search type +// swagger:model QuerySearchType +type QuerySearchType string + +const ( + + // QuerySearchTypeTERM captures enum value "TERM" + QuerySearchTypeTERM QuerySearchType = "TERM" + + // QuerySearchTypeNESTED captures enum value "NESTED" + QuerySearchTypeNESTED QuerySearchType = "NESTED" + + // QuerySearchTypeMATCH captures enum value "MATCH" + QuerySearchTypeMATCH QuerySearchType = "MATCH" + + // QuerySearchTypeALL captures enum value "ALL" + QuerySearchTypeALL QuerySearchType = "ALL" +) + +// for schema +var querySearchTypeEnum []interface{} + +func init() { + var res []QuerySearchType + if err := json.Unmarshal([]byte(`["TERM","NESTED","MATCH","ALL"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + querySearchTypeEnum = append(querySearchTypeEnum, v) + } +} + +func (m QuerySearchType) validateQuerySearchTypeEnum(path, location string, value QuerySearchType) error { + if err := validate.Enum(path, location, value, querySearchTypeEnum); err != nil { + return err + } + return nil +} + +// Validate validates this query search type +func (m QuerySearchType) Validate(formats strfmt.Registry) error { + var res []error + + // value enum + if err := m.validateQuerySearchTypeEnum("", "body", m); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/di/restapi/api_v1/restmodels/t_fos_request.go b/di/restapi/api_v1/restmodels/t_fos_request.go new file mode 100644 index 0000000..2e0b2a2 --- /dev/null +++ b/di/restapi/api_v1/restmodels/t_fos_request.go @@ -0,0 +1,180 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "strconv" + + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" +) + +// TFosRequest t fos request +// swagger:model TFosRequest +type TFosRequest struct { + + // Archives Fields. + Archives []*Fields `json:"Archives"` + + // Experiment Description. + Command string `json:"Command,omitempty"` + + // Queue Setting Driver Memory. + DriverMemory string `json:"DriverMemory,omitempty"` + + // EntryPoint Fields. + EntryPoint *Fields `json:"EntryPoint,omitempty"` + + // Queue Setting Executor Cores. + ExecutorCores string `json:"ExecutorCores,omitempty"` + + // Queue Setting Executor Memory. + ExecutorMemory string `json:"ExecutorMemory,omitempty"` + + // Queue Setting Executor Number. + Executors string `json:"Executors,omitempty"` + + // Queue Setting. + Queue string `json:"Queue,omitempty"` + + // Tensorflow Env Files. + TensorflowEnv *Fields `json:"TensorflowEnv,omitempty"` + + // PyFiles Fields. + PyFile []*Fields `json:"py_file"` +} + +// Validate validates this t fos request +func (m *TFosRequest) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateArchives(formats); err != nil { + res = append(res, err) + } + + if err := m.validateEntryPoint(formats); err != nil { + res = append(res, err) + } + + if err := m.validateTensorflowEnv(formats); err != nil { + res = append(res, err) + } + + if err := m.validatePyFile(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *TFosRequest) validateArchives(formats strfmt.Registry) error { + + if swag.IsZero(m.Archives) { // not required + return nil + } + + for i := 0; i < len(m.Archives); i++ { + if swag.IsZero(m.Archives[i]) { // not required + continue + } + + if m.Archives[i] != nil { + if err := m.Archives[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Archives" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *TFosRequest) validateEntryPoint(formats strfmt.Registry) error { + + if swag.IsZero(m.EntryPoint) { // not required + return nil + } + + if m.EntryPoint != nil { + if err := m.EntryPoint.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("EntryPoint") + } + return err + } + } + + return nil +} + +func (m *TFosRequest) validateTensorflowEnv(formats strfmt.Registry) error { + + if swag.IsZero(m.TensorflowEnv) { // not required + return nil + } + + if m.TensorflowEnv != nil { + if err := m.TensorflowEnv.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("TensorflowEnv") + } + return err + } + } + + return nil +} + +func (m *TFosRequest) validatePyFile(formats strfmt.Registry) error { + + if swag.IsZero(m.PyFile) { // not required + return nil + } + + for i := 0; i < len(m.PyFile); i++ { + if swag.IsZero(m.PyFile[i]) { // not required + continue + } + + if m.PyFile[i] != nil { + if err := m.PyFile[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("py_file" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *TFosRequest) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *TFosRequest) UnmarshalBinary(b []byte) error { + var res TFosRequest + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/training.go b/di/restapi/api_v1/restmodels/training.go new file mode 100644 index 0000000..a31dd5a --- /dev/null +++ b/di/restapi/api_v1/restmodels/training.go @@ -0,0 +1,156 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "encoding/json" + + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// Training training +// swagger:model Training +type Training struct { + + // the command invoked for running the training. This is specific to the DL framework + Command string `json:"command,omitempty"` + + // Number of CPUs required + Cpus float64 `json:"cpus,omitempty"` + + // Number of CPUs required + Gpus float64 `json:"gpus,omitempty"` + + // Input data to the training, such as training data, pre-trained model. The input is specified as references to the data_store ids that contain the data. + InputData []string `json:"input_data"` + + // Number of learners required. + Learners int32 `json:"learners,omitempty"` + + // Amount of memory required + Memory float64 `json:"memory,omitempty"` + + // Memory unit (default: MiB) + // + // Enum: [MiB MB GiB GB] + MemoryUnit *string `json:"memory_unit,omitempty"` + + // Output data of the training, such as trained models. The output is specified as references to the data_store ids that contain the data. + OutputData []string `json:"output_data"` + + // the pre-configured deployment size to used for training. The is used instead of directly specifying CPU, GPU, memory and learners. + Size string `json:"size,omitempty"` + + // training status + TrainingStatus *TrainingStatus `json:"training_status,omitempty"` +} + +// Validate validates this training +func (m *Training) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateMemoryUnit(formats); err != nil { + res = append(res, err) + } + + if err := m.validateTrainingStatus(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +var trainingTypeMemoryUnitPropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["MiB","MB","GiB","GB"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + trainingTypeMemoryUnitPropEnum = append(trainingTypeMemoryUnitPropEnum, v) + } +} + +const ( + + // TrainingMemoryUnitMiB captures enum value "MiB" + TrainingMemoryUnitMiB string = "MiB" + + // TrainingMemoryUnitMB captures enum value "MB" + TrainingMemoryUnitMB string = "MB" + + // TrainingMemoryUnitGiB captures enum value "GiB" + TrainingMemoryUnitGiB string = "GiB" + + // TrainingMemoryUnitGB captures enum value "GB" + TrainingMemoryUnitGB string = "GB" +) + +// prop value enum +func (m *Training) validateMemoryUnitEnum(path, location string, value string) error { + if err := validate.Enum(path, location, value, trainingTypeMemoryUnitPropEnum); err != nil { + return err + } + return nil +} + +func (m *Training) validateMemoryUnit(formats strfmt.Registry) error { + + if swag.IsZero(m.MemoryUnit) { // not required + return nil + } + + // value enum + if err := m.validateMemoryUnitEnum("memory_unit", "body", *m.MemoryUnit); err != nil { + return err + } + + return nil +} + +func (m *Training) validateTrainingStatus(formats strfmt.Registry) error { + + if swag.IsZero(m.TrainingStatus) { // not required + return nil + } + + if m.TrainingStatus != nil { + if err := m.TrainingStatus.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("training_status") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *Training) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Training) UnmarshalBinary(b []byte) error { + var res Training + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/training_status.go b/di/restapi/api_v1/restmodels/training_status.go new file mode 100644 index 0000000..d834e22 --- /dev/null +++ b/di/restapi/api_v1/restmodels/training_status.go @@ -0,0 +1,60 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// TrainingStatus training status +// swagger:model TrainingStatus +type TrainingStatus struct { + + // Training completion timestamp (Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z') + // + Completed string `json:"completed,omitempty"` + + // A code identifying the cause of a status message. + ErrorCode string `json:"error_code,omitempty"` + + // Status of the training. + Status string `json:"status,omitempty"` + + // Description of the training status. + StatusDescription string `json:"status_description,omitempty"` + + // A human readable message description of the training status. + StatusMessage string `json:"status_message,omitempty"` + + // Training submission timestamp (Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z') + // + Submitted string `json:"submitted,omitempty"` +} + +// Validate validates this training status +func (m *TrainingStatus) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *TrainingStatus) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *TrainingStatus) UnmarshalBinary(b []byte) error { + var res TrainingStatus + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/training_update.go b/di/restapi/api_v1/restmodels/training_update.go new file mode 100644 index 0000000..b3c6ca3 --- /dev/null +++ b/di/restapi/api_v1/restmodels/training_update.go @@ -0,0 +1,43 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// TrainingUpdate training update +// swagger:model TrainingUpdate +type TrainingUpdate struct { + + // The status action to be executed on the training job. (Currently only `halt` is supported.) + Status string `json:"status,omitempty"` +} + +// Validate validates this training update +func (m *TrainingUpdate) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *TrainingUpdate) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *TrainingUpdate) UnmarshalBinary(b []byte) error { + var res TrainingUpdate + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/user.go b/di/restapi/api_v1/restmodels/user.go new file mode 100644 index 0000000..43ac806 --- /dev/null +++ b/di/restapi/api_v1/restmodels/user.go @@ -0,0 +1,70 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// User user +// swagger:model User +type User struct { + + // Flag of Delete. + Name string `json:"Name,omitempty"` + + // Flag of Delete. + Remarks string `json:"Remarks,omitempty"` + + // Flag of Delete. + // Required: true + ID *int64 `json:"id"` +} + +// Validate validates this user +func (m *User) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateID(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *User) validateID(formats strfmt.Registry) error { + + if err := validate.Required("id", "body", m.ID); err != nil { + return err + } + + return nil +} + +// MarshalBinary interface implementation +func (m *User) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *User) UnmarshalBinary(b []byte) error { + var res User + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/v1_log_line.go b/di/restapi/api_v1/restmodels/v1_log_line.go new file mode 100644 index 0000000..e526174 --- /dev/null +++ b/di/restapi/api_v1/restmodels/v1_log_line.go @@ -0,0 +1,74 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" +) + +// V1LogLine v1 log line +// swagger:model v1LogLine +type V1LogLine struct { + + // line + Line string `json:"line,omitempty"` + + // meta + Meta *V1MetaInfo `json:"meta,omitempty"` +} + +// Validate validates this v1 log line +func (m *V1LogLine) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateMeta(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *V1LogLine) validateMeta(formats strfmt.Registry) error { + + if swag.IsZero(m.Meta) { // not required + return nil + } + + if m.Meta != nil { + if err := m.Meta.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("meta") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *V1LogLine) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *V1LogLine) UnmarshalBinary(b []byte) error { + var res V1LogLine + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/v1_log_lines_list.go b/di/restapi/api_v1/restmodels/v1_log_lines_list.go new file mode 100644 index 0000000..9a55e15 --- /dev/null +++ b/di/restapi/api_v1/restmodels/v1_log_lines_list.go @@ -0,0 +1,80 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "strconv" + + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" +) + +// V1LogLinesList v1 log lines list +// swagger:model v1LogLinesList +type V1LogLinesList struct { + + // models + Models []*V1LogLine `json:"models"` +} + +// Validate validates this v1 log lines list +func (m *V1LogLinesList) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateModels(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *V1LogLinesList) validateModels(formats strfmt.Registry) error { + + if swag.IsZero(m.Models) { // not required + return nil + } + + for i := 0; i < len(m.Models); i++ { + if swag.IsZero(m.Models[i]) { // not required + continue + } + + if m.Models[i] != nil { + if err := m.Models[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("models" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *V1LogLinesList) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *V1LogLinesList) UnmarshalBinary(b []byte) error { + var res V1LogLinesList + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/restmodels/v1_meta_info.go b/di/restapi/api_v1/restmodels/v1_meta_info.go new file mode 100644 index 0000000..f7b283b --- /dev/null +++ b/di/restapi/api_v1/restmodels/v1_meta_info.go @@ -0,0 +1,52 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restmodels + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// V1MetaInfo v1 meta info +// swagger:model v1MetaInfo +type V1MetaInfo struct { + + // sequential index + Rindex int64 `json:"rindex,omitempty"` + + // Time that the metric occured: representing the number of millisecond since midnight January 1, 1970. + Time int64 `json:"time,omitempty"` + + // Unique id identifying the training job + TrainingID string `json:"training_id,omitempty"` + + // Unique id identifying the user + UserID string `json:"user_id,omitempty"` +} + +// Validate validates this v1 meta info +func (m *V1MetaInfo) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *V1MetaInfo) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *V1MetaInfo) UnmarshalBinary(b []byte) error { + var res V1MetaInfo + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/di/restapi/api_v1/server/configure_di.go b/di/restapi/api_v1/server/configure_di.go new file mode 100644 index 0000000..516efc3 --- /dev/null +++ b/di/restapi/api_v1/server/configure_di.go @@ -0,0 +1,117 @@ +// This file is safe to edit. Once it exists it will not be overwritten + +package server + +import ( + "crypto/tls" + "net/http" + "webank/DI/restapi/api_v1/server/rest_impl" + + errors "github.com/go-openapi/errors" + runtime "github.com/go-openapi/runtime" + middleware "github.com/go-openapi/runtime/middleware" + + "webank/DI/restapi/api_v1/server/operations" + "webank/DI/restapi/api_v1/server/operations/experiments" + "webank/DI/restapi/api_v1/server/operations/models" + "webank/DI/restapi/api_v1/server/operations/training_data" +) + +//go:generate swagger generate server --target ..\..\api_v1 --name Di --spec ..\swagger\swagger.yml --model-package restmodels --server-package server --exclude-main + +func configureFlags(api *operations.DiAPI) { + // api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... } +} + +func configureAPI(api *operations.DiAPI) http.Handler { + // configure the api here + api.ServeError = errors.ServeError + + // Set your custom logger if needed. Default one is log.Printf + // Expected interface func(string, ...interface{}) + // + // Example: + // s.api.Logger = log.Printf + + api.JSONConsumer = runtime.JSONConsumer() + + api.MultipartformConsumer = runtime.DiscardConsumer + + api.JSONProducer = runtime.JSONProducer() + + api.BinProducer = runtime.ByteStreamProducer() + + // Applies when the Authorization header is set with the Basic scheme + //api.BasicAuthAuth = func(user string, pass string) (interface{}, error) { + // // We can assume that the basic authentication is handled by the frontend + // // gateway. We don't need any checks here anymore. + // if user == "" || pass == "" { + // return nil, errors.Unauthenticated("user/password missing") + // } + // return user, nil + //} + + api.ExperimentsCodeUploadHandler = experiments.CodeUploadHandlerFunc(func(params experiments.CodeUploadParams) middleware.Responder { + return rest_impl.CodeUpload(params) + }) + api.ModelsDeleteModelHandler = models.DeleteModelHandlerFunc(func(params models.DeleteModelParams) middleware.Responder { + return rest_impl.DeleteModel(params) + }) + api.ModelsDownloadModelDefinitionHandler = models.DownloadModelDefinitionHandlerFunc(func(params models.DownloadModelDefinitionParams) middleware.Responder { + return rest_impl.DownloadModelDefinition(params) + }) + api.ModelsDownloadTrainedModelHandler = models.DownloadTrainedModelHandlerFunc(func(params models.DownloadTrainedModelParams) middleware.Responder { + return rest_impl.DownloadTrainedModel(params) + }) + api.ModelsExportModelHandler = models.ExportModelHandlerFunc(func(params models.ExportModelParams) middleware.Responder { + return rest_impl.ExportModel(params) + }) + api.ModelsGetLogsHandler = models.GetLogsHandlerFunc(func(params models.GetLogsParams) middleware.Responder { + return rest_impl.GetLogs(params) + }) + api.ModelsGetModelHandler = models.GetModelHandlerFunc(func(params models.GetModelParams) middleware.Responder { + return rest_impl.GetModel(params) + }) + api.ModelsListModelsHandler = models.ListModelsHandlerFunc(func(params models.ListModelsParams) middleware.Responder { + return rest_impl.ListModels(params) + }) + api.ModelsPostModelHandler = models.PostModelHandlerFunc(func(params models.PostModelParams) middleware.Responder { + return rest_impl.PostModel(params) + }) + api.ModelsPatchModelHandler = models.PatchModelHandlerFunc(func(params models.PatchModelParams) middleware.Responder { + return rest_impl.PatchModel(params) + }) + api.TrainingDataGetLoglinesHandler = training_data.GetLoglinesHandlerFunc(func(params training_data.GetLoglinesParams) middleware.Responder { + return rest_impl.GetLoglines(params) + }) + api.GetDashboardsHandler = operations.GetDashboardsHandlerFunc(func(params operations.GetDashboardsParams) middleware.Responder { + return rest_impl.GetDashboards(params) + }) + api.ServerShutdown = func() {} + // return setupGlobalMiddleware(api.Serve(setupMiddlewares)) + return api.Serve(setupMiddlewares) +} + +// The TLS configuration before HTTPS server starts. +func configureTLS(tlsConfig *tls.Config) { + // Make all necessary changes to the TLS configuration here. +} + +// As soon as server is initialized but not run yet, this function will be called. +// If you need to modify a config, store server instance to stop it individually later, this is the place. +// This function can be called multiple times, depending on the number of serving schemes. +// scheme value will be set accordingly: "http", "https" or "unix" +func configureServer(s *http.Server, scheme, addr string) { +} + +// The middleware configuration is for the handler executors. These do not apply to the swagger.json document. +// The middleware executes after routing but before authentication, binding and validation +func setupMiddlewares(handler http.Handler) http.Handler { + return handler +} + +// The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document. +// So this is a good place to plug in a panic handling middleware, logging and metrics +func setupGlobalMiddleware(handler http.Handler) http.Handler { + return handler +} diff --git a/di/restapi/api_v1/server/doc.go b/di/restapi/api_v1/server/doc.go new file mode 100644 index 0000000..b68a563 --- /dev/null +++ b/di/restapi/api_v1/server/doc.go @@ -0,0 +1,25 @@ +// Code generated by go-swagger; DO NOT EDIT. + +/* +Package server Prophecis Rest Service +Prophecis Rest Service + + + + Schemes: + https + Host: di.prophecis.com + BasePath: / + Version: 1.0.0 + + Consumes: + - application/json + - multipart/form-data + + Produces: + - application/json + - application/octet-stream + +swagger:meta +*/ +package server diff --git a/di/restapi/api_v1/server/embedded_spec.go b/di/restapi/api_v1/server/embedded_spec.go new file mode 100644 index 0000000..c9e3f60 --- /dev/null +++ b/di/restapi/api_v1/server/embedded_spec.go @@ -0,0 +1,2346 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package server + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "encoding/json" +) + +var ( + // SwaggerJSON embedded version of the swagger document used at generation time + SwaggerJSON json.RawMessage + // FlatSwaggerJSON embedded flattened version of the swagger document used at generation time + FlatSwaggerJSON json.RawMessage +) + +func init() { + SwaggerJSON = json.RawMessage([]byte(`{ + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "schemes": [ + "https" + ], + "swagger": "2.0", + "info": { + "description": "Prophecis Rest Service\n", + "title": "Prophecis Rest Service", + "version": "1.0.0" + }, + "host": "di.prophecis.com", + "basePath": "/", + "paths": { + "/di/v1/codeUpload": { + "post": { + "description": "upload code.zip to s3", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Experiments" + ], + "summary": "upload code to s3", + "operationId": "codeUpload", + "parameters": [ + { + "type": "file", + "name": "file", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/CodeUploadResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Code ZIP upload failed", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/dashboards": { + "get": { + "description": "Get dashboard.", + "summary": "Get the dashboard belongs to a User", + "operationId": "getDashboards", + "parameters": [ + { + "type": "string", + "default": "", + "description": "entity clusterName", + "name": "clusterName", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/GetDashboardsResponse" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The dashboard cannot be found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/logs/{model_id}/loglines": { + "get": { + "tags": [ + "TrainingData" + ], + "summary": "Get loglines, based on query", + "operationId": "getLoglines", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "enum": [ + "TERM", + "NESTED", + "MATCH" + ], + "type": "string", + "default": "TERM", + "name": "searchType", + "in": "query" + }, + { + "type": "string", + "format": "string", + "default": "", + "description": "Time from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will be returned. If this value is a raw integer, it represents the time that the metric occured: representing the number of milliseconds since midnight January 1, 1970. If this value is a negative integer, it represents the number of lines to count backwards. If this value is empty, the logs since the beginning of the job will be returned", + "name": "since_time", + "in": "query" + }, + { + "type": "integer", + "format": "int32", + "description": "Number of lines to output.", + "name": "pagesize", + "in": "query" + }, + { + "type": "integer", + "format": "int64", + "description": "If positive, line number from start, if negative line counting from end", + "name": "pos", + "in": "query" + }, + { + "type": "string", + "default": "2017-10-01", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query" + } + ], + "responses": { + "200": { + "description": "(streaming responses)", + "schema": { + "$ref": "#/definitions/v1LogLinesList" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models": { + "get": { + "description": "Get a list of all available deep learning models and their configuration that a user can see.\n", + "tags": [ + "Models" + ], + "summary": "Get a list of available deep learning models.", + "operationId": "listModels", + "parameters": [ + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + }, + { + "type": "string", + "default": "", + "description": "owner's userid.", + "name": "userid", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "job's namespace.", + "name": "namespace", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "page number.", + "name": "page", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "entity number per page.", + "name": "size", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "entity clusterName", + "name": "clusterName", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "experiment's id.", + "name": "exp_id", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "experiment run's id.", + "name": "exp_run_id", + "in": "query" + } + ], + "responses": { + "200": { + "description": "List of deep learning models.", + "schema": { + "$ref": "#/definitions/ModelList" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "description": "Trains a deep neural network written in a DL framework supported by the DLaaS platform (such as Caffe, Tensorflow, etc.). The model code has to be uploaded and configuration parameters have to be provided.\n", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Models" + ], + "summary": "Trains a new deep learning model.", + "operationId": "postModel", + "parameters": [ + { + "type": "file", + "description": "The deep learning model code as compressed archive (ZIP).", + "name": "model_definition", + "in": "formData" + }, + { + "type": "file", + "description": "The manifest providing configuration for the deep learning model, the training data and the training execution.", + "name": "manifest", + "in": "formData", + "required": true + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "201": { + "description": "Deep learning model successfully accepted.", + "schema": { + "$ref": "#/definitions/BasicNewModel" + }, + "headers": { + "Location": { + "type": "string", + "description": "Location header containing the model id." + } + } + }, + "400": { + "description": "Error in the the model_definition or manifest.", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models/{model_id}": { + "get": { + "description": "Get detailed information about a model such as training status.\n", + "tags": [ + "Models" + ], + "summary": "Get detailed information about a model.", + "operationId": "getModel", + "parameters": [ + { + "type": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Detailed model and training information.", + "schema": { + "$ref": "#/definitions/Model" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Model with the given ID not found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "delete": { + "description": "Deletes an existing model. It does not delete any data in the user's data store.\n", + "tags": [ + "Models" + ], + "summary": "Deletes an existing model", + "operationId": "deleteModel", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Model deleted successfully.", + "schema": { + "$ref": "#/definitions/BasicModel" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The model cannot be found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "patch": { + "description": "Changes the status of the training progress to the given ` + "`" + `status` + "`" + ` value (currently ` + "`" + `halt` + "`" + ` only). Halt means the training will be stopped and the last snapshot will be stored and can be retrieved.", + "tags": [ + "Models" + ], + "summary": "Changes the status of the training progress.", + "operationId": "patchModel", + "parameters": [ + { + "type": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "description": "Currently accepts \"halt\" as the only valid value.", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/TrainingUpdate" + } + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "202": { + "description": "Training successfully halted.", + "schema": { + "$ref": "#/definitions/BasicModel" + } + }, + "400": { + "description": "Incorrect status specified.", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Model with the given ID not found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models/{model_id}/definition": { + "get": { + "description": "Downloads the model definition that was initial used for training as ZIP archive.", + "produces": [ + "application/octet-stream" + ], + "tags": [ + "Models" + ], + "summary": "Downloads the model definition.", + "operationId": "downloadModelDefinition", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Model definition", + "schema": { + "type": "string", + "format": "binary" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The model cannot be found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models/{model_id}/export": { + "get": { + "description": "Export the model definition", + "produces": [ + "application/octet-stream" + ], + "tags": [ + "Models" + ], + "summary": "Export the model definition.", + "operationId": "exportModel", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Model definition", + "schema": { + "type": "string", + "format": "binary" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The model cannot be found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models/{model_id}/logs": { + "get": { + "security": [], + "description": "Get training logs for the given model as websocket stream. Each message can contain one or more log lines.\n", + "produces": [ + "application/octet-stream" + ], + "tags": [ + "Models" + ], + "summary": "Get training logs as websocket stream.\n", + "operationId": "getLogs", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "type": "boolean", + "format": "boolean", + "default": false, + "description": "Follow the log stream if true. Default false.", + "name": "follow", + "in": "query" + }, + { + "type": "string", + "format": "string", + "default": "", + "description": "An RFC3339 timestamp from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will be returned.", + "name": "since_time", + "in": "query" + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Dump of the training log to-date", + "schema": { + "type": "string", + "format": "binary" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The model cannot be found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models/{model_id}/trained_model": { + "get": { + "description": "Downloads the trained model as ZIP archive.", + "produces": [ + "application/octet-stream" + ], + "tags": [ + "Models" + ], + "summary": "Downloads the trained model.", + "operationId": "downloadTrainedModel", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Model definition", + "schema": { + "type": "string", + "format": "binary" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The trained model cannot be found.", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "410": { + "description": "If the trained model storage time has expired and it has been deleted. It only gets deleted if it not stored on an external data store.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + } + }, + "definitions": { + "BasicModel": { + "type": "object", + "properties": { + "model_id": { + "description": "A unique id of the deep learning model.", + "type": "string" + } + } + }, + "BasicNewModel": { + "allOf": [ + { + "$ref": "#/definitions/BasicModel" + }, + { + "properties": { + "location": { + "description": "Location of the model to retrieve it.", + "type": "string" + } + } + } + ] + }, + "CodeUploadResponse": { + "type": "object", + "properties": { + "s3Path": { + "description": "S3 Path", + "type": "string", + "format": "int64" + } + } + }, + "Datastore": { + "type": "object", + "properties": { + "connection": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "data_store_id": { + "description": "the id of the data store as defined in the manifest.", + "type": "string" + }, + "type": { + "description": "the type of the data store as defined in the manifest.", + "type": "string" + } + } + }, + "Endpoint": { + "type": "object", + "properties": { + "id": { + "description": "the id of the endpoint", + "type": "string" + }, + "url": { + "description": "the url of the endpoint", + "type": "string" + } + } + }, + "EndpointList": { + "type": "object", + "properties": { + "endpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/Endpoint" + } + } + } + }, + "Error": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "error": { + "type": "string" + }, + "msg": { + "type": "string" + } + } + }, + "Fields": { + "description": "TFOS Archives \u0026 PyFile Fields", + "type": "object", + "properties": { + "hdfs": { + "description": "HDFS Path.", + "type": "string" + }, + "resource_id": { + "description": "BML Resource ID.", + "type": "string" + }, + "version": { + "description": "BML Resource Version.", + "type": "string" + } + } + }, + "Framework": { + "type": "object", + "properties": { + "name": { + "description": "the name of the deep learning framework (e.g. caffe, torch, tensorflow)", + "type": "string" + }, + "version": { + "description": "the version of the specific framework to use.", + "type": "string" + } + } + }, + "GetDashboardsResponse": { + "type": "object", + "properties": { + "cpus": { + "description": "number of cpu.", + "type": "string" + }, + "runningInstances": { + "description": "number of running instances.", + "type": "string" + }, + "totalInstances": { + "description": "total number of instances.", + "type": "string" + } + } + }, + "Model": { + "allOf": [ + { + "$ref": "#/definitions/BasicNewModel" + }, + { + "properties": { + "JobAlert": { + "description": "Job Alert String.", + "type": "string" + }, + "JobType": { + "description": "Job Type.", + "type": "string" + }, + "TFosRequest": { + "description": "TFosRequest", + "$ref": "#/definitions/TFosRequest" + }, + "completed_timestamp": { + "description": "completed timestamp of the job", + "type": "string" + }, + "data_stores": { + "type": "array", + "items": { + "$ref": "#/definitions/Datastore" + } + }, + "description": { + "description": "Detailed description of deep learning model.", + "type": "string" + }, + "expName": { + "description": "Experiment Name", + "type": "string" + }, + "expRunId": { + "description": "Experiment Run Id", + "type": "string" + }, + "fileName": { + "description": "Code File's Name", + "type": "string" + }, + "filePath": { + "description": "Code File's Path", + "type": "string" + }, + "framework": { + "$ref": "#/definitions/Framework" + }, + "job_namespace": { + "description": "job's namespace.", + "type": "string" + }, + "name": { + "description": "The name of the deep learning model.", + "type": "string" + }, + "ps_cpu": { + "description": "Count of Param Server", + "type": "string" + }, + "ps_image": { + "description": "Count of Param Server", + "type": "string" + }, + "ps_memory": { + "description": "Count of Param Server", + "type": "string" + }, + "pss": { + "description": "Count of Param Server", + "type": "string" + }, + "submission_timestamp": { + "description": "submission timestamp of the job.", + "type": "string" + }, + "training": { + "$ref": "#/definitions/Training" + }, + "user_id": { + "description": "user name.", + "type": "string" + } + } + } + ] + }, + "ModelList": { + "type": "object", + "properties": { + "models": { + "type": "array", + "items": { + "$ref": "#/definitions/Model" + } + }, + "pages": { + "type": "integer" + }, + "total": { + "type": "integer" + } + } + }, + "TFosRequest": { + "type": "object", + "properties": { + "Archives": { + "description": "Archives Fields.", + "type": "array", + "items": { + "$ref": "#/definitions/Fields" + } + }, + "Command": { + "description": "Experiment Description.", + "type": "string" + }, + "DriverMemory": { + "description": "Queue Setting Driver Memory.", + "type": "string" + }, + "EntryPoint": { + "description": "EntryPoint Fields.", + "$ref": "#/definitions/Fields" + }, + "ExecutorCores": { + "description": "Queue Setting Executor Cores.", + "type": "string" + }, + "ExecutorMemory": { + "description": "Queue Setting Executor Memory.", + "type": "string" + }, + "Executors": { + "description": "Queue Setting Executor Number.", + "type": "string" + }, + "Queue": { + "description": "Queue Setting.", + "type": "string" + }, + "TensorflowEnv": { + "description": "Tensorflow Env Files.", + "$ref": "#/definitions/Fields" + }, + "py_file": { + "description": "PyFiles Fields.", + "type": "array", + "items": { + "$ref": "#/definitions/Fields" + } + } + } + }, + "Training": { + "type": "object", + "properties": { + "command": { + "description": "the command invoked for running the training. This is specific to the DL framework", + "type": "string" + }, + "cpus": { + "description": "Number of CPUs required", + "type": "number", + "format": "double" + }, + "gpus": { + "description": "Number of CPUs required", + "type": "number", + "format": "double" + }, + "input_data": { + "description": "Input data to the training, such as training data, pre-trained model. The input is specified as references to the data_store ids that contain the data.", + "type": "array", + "items": { + "description": "Reference to a data store id.", + "type": "string" + } + }, + "learners": { + "description": "Number of learners required.", + "type": "integer", + "format": "int32" + }, + "memory": { + "description": "Amount of memory required", + "type": "number", + "format": "double" + }, + "memory_unit": { + "description": "Memory unit (default: MiB)\n", + "type": "string", + "default": "MiB", + "enum": [ + "MiB", + "MB", + "GiB", + "GB" + ] + }, + "output_data": { + "description": "Output data of the training, such as trained models. The output is specified as references to the data_store ids that contain the data.", + "type": "array", + "items": { + "description": "Reference to a data store id.", + "type": "string" + } + }, + "size": { + "description": "the pre-configured deployment size to used for training. The is used instead of directly specifying CPU, GPU, memory and learners.", + "type": "string" + }, + "training_status": { + "$ref": "#/definitions/TrainingStatus" + } + } + }, + "TrainingStatus": { + "type": "object", + "properties": { + "completed": { + "description": "Training completion timestamp (Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z')\n", + "type": "string" + }, + "error_code": { + "description": "A code identifying the cause of a status message.", + "type": "string" + }, + "status": { + "description": "Status of the training.", + "type": "string" + }, + "status_description": { + "description": "Description of the training status.", + "type": "string" + }, + "status_message": { + "description": "A human readable message description of the training status.", + "type": "string" + }, + "submitted": { + "description": "Training submission timestamp (Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z')\n", + "type": "string" + } + } + }, + "TrainingUpdate": { + "type": "object", + "properties": { + "status": { + "description": "The status action to be executed on the training job. (Currently only ` + "`" + `halt` + "`" + ` is supported.)", + "type": "string" + } + } + }, + "User": { + "required": [ + "id" + ], + "properties": { + "Name": { + "description": "Flag of Delete.", + "type": "string" + }, + "Remarks": { + "description": "Flag of Delete.", + "type": "string" + }, + "id": { + "description": "Flag of Delete.", + "type": "number", + "format": "int64" + } + } + }, + "v1LogLine": { + "type": "object", + "properties": { + "line": { + "type": "string" + }, + "meta": { + "$ref": "#/definitions/v1MetaInfo" + } + } + }, + "v1LogLinesList": { + "type": "object", + "properties": { + "models": { + "type": "array", + "items": { + "$ref": "#/definitions/v1LogLine" + } + } + } + }, + "v1MetaInfo": { + "type": "object", + "properties": { + "rindex": { + "type": "number", + "format": "int64", + "title": "sequential index" + }, + "time": { + "description": "Time that the metric occured: representing the number of millisecond since midnight January 1, 1970.", + "type": "number", + "format": "int64" + }, + "training_id": { + "type": "string", + "title": "Unique id identifying the training job" + }, + "user_id": { + "type": "string", + "title": "Unique id identifying the user" + } + } + } + } +}`)) + FlatSwaggerJSON = json.RawMessage([]byte(`{ + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "schemes": [ + "https" + ], + "swagger": "2.0", + "info": { + "description": "Prophecis Rest Service\n", + "title": "Prophecis Rest Service", + "version": "1.0.0" + }, + "host": "di.prophecis.com", + "basePath": "/", + "paths": { + "/di/v1/codeUpload": { + "post": { + "description": "upload code.zip to s3", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Experiments" + ], + "summary": "upload code to s3", + "operationId": "codeUpload", + "parameters": [ + { + "type": "file", + "name": "file", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/CodeUploadResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Code ZIP upload failed", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/dashboards": { + "get": { + "description": "Get dashboard.", + "summary": "Get the dashboard belongs to a User", + "operationId": "getDashboards", + "parameters": [ + { + "type": "string", + "default": "", + "description": "entity clusterName", + "name": "clusterName", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/GetDashboardsResponse" + } + }, + "403": { + "description": "Forbidden", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The dashboard cannot be found", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/logs/{model_id}/loglines": { + "get": { + "tags": [ + "TrainingData" + ], + "summary": "Get loglines, based on query", + "operationId": "getLoglines", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "enum": [ + "TERM", + "NESTED", + "MATCH" + ], + "type": "string", + "default": "TERM", + "name": "searchType", + "in": "query" + }, + { + "type": "string", + "format": "string", + "default": "", + "description": "Time from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will be returned. If this value is a raw integer, it represents the time that the metric occured: representing the number of milliseconds since midnight January 1, 1970. If this value is a negative integer, it represents the number of lines to count backwards. If this value is empty, the logs since the beginning of the job will be returned", + "name": "since_time", + "in": "query" + }, + { + "type": "integer", + "format": "int32", + "description": "Number of lines to output.", + "name": "pagesize", + "in": "query" + }, + { + "type": "integer", + "format": "int64", + "description": "If positive, line number from start, if negative line counting from end", + "name": "pos", + "in": "query" + }, + { + "type": "string", + "default": "2017-10-01", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query" + } + ], + "responses": { + "200": { + "description": "(streaming responses)", + "schema": { + "$ref": "#/definitions/v1LogLinesList" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models": { + "get": { + "description": "Get a list of all available deep learning models and their configuration that a user can see.\n", + "tags": [ + "Models" + ], + "summary": "Get a list of available deep learning models.", + "operationId": "listModels", + "parameters": [ + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + }, + { + "type": "string", + "default": "", + "description": "owner's userid.", + "name": "userid", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "job's namespace.", + "name": "namespace", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "page number.", + "name": "page", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "entity number per page.", + "name": "size", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "entity clusterName", + "name": "clusterName", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "experiment's id.", + "name": "exp_id", + "in": "query" + }, + { + "type": "string", + "default": "", + "description": "experiment run's id.", + "name": "exp_run_id", + "in": "query" + } + ], + "responses": { + "200": { + "description": "List of deep learning models.", + "schema": { + "$ref": "#/definitions/ModelList" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "description": "Trains a deep neural network written in a DL framework supported by the DLaaS platform (such as Caffe, Tensorflow, etc.). The model code has to be uploaded and configuration parameters have to be provided.\n", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Models" + ], + "summary": "Trains a new deep learning model.", + "operationId": "postModel", + "parameters": [ + { + "type": "file", + "description": "The deep learning model code as compressed archive (ZIP).", + "name": "model_definition", + "in": "formData" + }, + { + "type": "file", + "description": "The manifest providing configuration for the deep learning model, the training data and the training execution.", + "name": "manifest", + "in": "formData", + "required": true + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "201": { + "description": "Deep learning model successfully accepted.", + "schema": { + "$ref": "#/definitions/BasicNewModel" + }, + "headers": { + "Location": { + "type": "string", + "description": "Location header containing the model id." + } + } + }, + "400": { + "description": "Error in the the model_definition or manifest.", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models/{model_id}": { + "get": { + "description": "Get detailed information about a model such as training status.\n", + "tags": [ + "Models" + ], + "summary": "Get detailed information about a model.", + "operationId": "getModel", + "parameters": [ + { + "type": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Detailed model and training information.", + "schema": { + "$ref": "#/definitions/Model" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Model with the given ID not found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "delete": { + "description": "Deletes an existing model. It does not delete any data in the user's data store.\n", + "tags": [ + "Models" + ], + "summary": "Deletes an existing model", + "operationId": "deleteModel", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Model deleted successfully.", + "schema": { + "$ref": "#/definitions/BasicModel" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The model cannot be found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "patch": { + "description": "Changes the status of the training progress to the given ` + "`" + `status` + "`" + ` value (currently ` + "`" + `halt` + "`" + ` only). Halt means the training will be stopped and the last snapshot will be stored and can be retrieved.", + "tags": [ + "Models" + ], + "summary": "Changes the status of the training progress.", + "operationId": "patchModel", + "parameters": [ + { + "type": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "description": "Currently accepts \"halt\" as the only valid value.", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/TrainingUpdate" + } + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "202": { + "description": "Training successfully halted.", + "schema": { + "$ref": "#/definitions/BasicModel" + } + }, + "400": { + "description": "Incorrect status specified.", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Model with the given ID not found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models/{model_id}/definition": { + "get": { + "description": "Downloads the model definition that was initial used for training as ZIP archive.", + "produces": [ + "application/octet-stream" + ], + "tags": [ + "Models" + ], + "summary": "Downloads the model definition.", + "operationId": "downloadModelDefinition", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Model definition", + "schema": { + "type": "string", + "format": "binary" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The model cannot be found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models/{model_id}/export": { + "get": { + "description": "Export the model definition", + "produces": [ + "application/octet-stream" + ], + "tags": [ + "Models" + ], + "summary": "Export the model definition.", + "operationId": "exportModel", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Model definition", + "schema": { + "type": "string", + "format": "binary" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The model cannot be found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models/{model_id}/logs": { + "get": { + "security": [], + "description": "Get training logs for the given model as websocket stream. Each message can contain one or more log lines.\n", + "produces": [ + "application/octet-stream" + ], + "tags": [ + "Models" + ], + "summary": "Get training logs as websocket stream.\n", + "operationId": "getLogs", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "type": "boolean", + "format": "boolean", + "default": false, + "description": "Follow the log stream if true. Default false.", + "name": "follow", + "in": "query" + }, + { + "type": "string", + "format": "string", + "default": "", + "description": "An RFC3339 timestamp from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will be returned.", + "name": "since_time", + "in": "query" + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Dump of the training log to-date", + "schema": { + "type": "string", + "format": "binary" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The model cannot be found.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/di/v1/models/{model_id}/trained_model": { + "get": { + "description": "Downloads the trained model as ZIP archive.", + "produces": [ + "application/octet-stream" + ], + "tags": [ + "Models" + ], + "summary": "Downloads the trained model.", + "operationId": "downloadTrainedModel", + "parameters": [ + { + "type": "string", + "format": "string", + "description": "The id of the model.", + "name": "model_id", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "2017-02-13", + "description": "The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "name": "version", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Model definition", + "schema": { + "type": "string", + "format": "binary" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "The trained model cannot be found.", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "410": { + "description": "If the trained model storage time has expired and it has been deleted. It only gets deleted if it not stored on an external data store.", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + } + }, + "definitions": { + "BasicModel": { + "type": "object", + "properties": { + "model_id": { + "description": "A unique id of the deep learning model.", + "type": "string" + } + } + }, + "BasicNewModel": { + "allOf": [ + { + "$ref": "#/definitions/BasicModel" + }, + { + "properties": { + "location": { + "description": "Location of the model to retrieve it.", + "type": "string" + } + } + } + ] + }, + "CodeUploadResponse": { + "type": "object", + "properties": { + "s3Path": { + "description": "S3 Path", + "type": "string", + "format": "int64" + } + } + }, + "Datastore": { + "type": "object", + "properties": { + "connection": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "data_store_id": { + "description": "the id of the data store as defined in the manifest.", + "type": "string" + }, + "type": { + "description": "the type of the data store as defined in the manifest.", + "type": "string" + } + } + }, + "Endpoint": { + "type": "object", + "properties": { + "id": { + "description": "the id of the endpoint", + "type": "string" + }, + "url": { + "description": "the url of the endpoint", + "type": "string" + } + } + }, + "EndpointList": { + "type": "object", + "properties": { + "endpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/Endpoint" + } + } + } + }, + "Error": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "error": { + "type": "string" + }, + "msg": { + "type": "string" + } + } + }, + "Fields": { + "description": "TFOS Archives \u0026 PyFile Fields", + "type": "object", + "properties": { + "hdfs": { + "description": "HDFS Path.", + "type": "string" + }, + "resource_id": { + "description": "BML Resource ID.", + "type": "string" + }, + "version": { + "description": "BML Resource Version.", + "type": "string" + } + } + }, + "Framework": { + "type": "object", + "properties": { + "name": { + "description": "the name of the deep learning framework (e.g. caffe, torch, tensorflow)", + "type": "string" + }, + "version": { + "description": "the version of the specific framework to use.", + "type": "string" + } + } + }, + "GetDashboardsResponse": { + "type": "object", + "properties": { + "cpus": { + "description": "number of cpu.", + "type": "string" + }, + "runningInstances": { + "description": "number of running instances.", + "type": "string" + }, + "totalInstances": { + "description": "total number of instances.", + "type": "string" + } + } + }, + "Model": { + "allOf": [ + { + "$ref": "#/definitions/BasicNewModel" + }, + { + "properties": { + "JobAlert": { + "description": "Job Alert String.", + "type": "string" + }, + "JobType": { + "description": "Job Type.", + "type": "string" + }, + "TFosRequest": { + "description": "TFosRequest", + "$ref": "#/definitions/TFosRequest" + }, + "completed_timestamp": { + "description": "completed timestamp of the job", + "type": "string" + }, + "data_stores": { + "type": "array", + "items": { + "$ref": "#/definitions/Datastore" + } + }, + "description": { + "description": "Detailed description of deep learning model.", + "type": "string" + }, + "expName": { + "description": "Experiment Name", + "type": "string" + }, + "expRunId": { + "description": "Experiment Run Id", + "type": "string" + }, + "fileName": { + "description": "Code File's Name", + "type": "string" + }, + "filePath": { + "description": "Code File's Path", + "type": "string" + }, + "framework": { + "$ref": "#/definitions/Framework" + }, + "job_namespace": { + "description": "job's namespace.", + "type": "string" + }, + "name": { + "description": "The name of the deep learning model.", + "type": "string" + }, + "ps_cpu": { + "description": "Count of Param Server", + "type": "string" + }, + "ps_image": { + "description": "Count of Param Server", + "type": "string" + }, + "ps_memory": { + "description": "Count of Param Server", + "type": "string" + }, + "pss": { + "description": "Count of Param Server", + "type": "string" + }, + "submission_timestamp": { + "description": "submission timestamp of the job.", + "type": "string" + }, + "training": { + "$ref": "#/definitions/Training" + }, + "user_id": { + "description": "user name.", + "type": "string" + } + } + } + ] + }, + "ModelList": { + "type": "object", + "properties": { + "models": { + "type": "array", + "items": { + "$ref": "#/definitions/Model" + } + }, + "pages": { + "type": "integer" + }, + "total": { + "type": "integer" + } + } + }, + "TFosRequest": { + "type": "object", + "properties": { + "Archives": { + "description": "Archives Fields.", + "type": "array", + "items": { + "$ref": "#/definitions/Fields" + } + }, + "Command": { + "description": "Experiment Description.", + "type": "string" + }, + "DriverMemory": { + "description": "Queue Setting Driver Memory.", + "type": "string" + }, + "EntryPoint": { + "description": "EntryPoint Fields.", + "$ref": "#/definitions/Fields" + }, + "ExecutorCores": { + "description": "Queue Setting Executor Cores.", + "type": "string" + }, + "ExecutorMemory": { + "description": "Queue Setting Executor Memory.", + "type": "string" + }, + "Executors": { + "description": "Queue Setting Executor Number.", + "type": "string" + }, + "Queue": { + "description": "Queue Setting.", + "type": "string" + }, + "TensorflowEnv": { + "description": "Tensorflow Env Files.", + "$ref": "#/definitions/Fields" + }, + "py_file": { + "description": "PyFiles Fields.", + "type": "array", + "items": { + "$ref": "#/definitions/Fields" + } + } + } + }, + "Training": { + "type": "object", + "properties": { + "command": { + "description": "the command invoked for running the training. This is specific to the DL framework", + "type": "string" + }, + "cpus": { + "description": "Number of CPUs required", + "type": "number", + "format": "double" + }, + "gpus": { + "description": "Number of CPUs required", + "type": "number", + "format": "double" + }, + "input_data": { + "description": "Input data to the training, such as training data, pre-trained model. The input is specified as references to the data_store ids that contain the data.", + "type": "array", + "items": { + "description": "Reference to a data store id.", + "type": "string" + } + }, + "learners": { + "description": "Number of learners required.", + "type": "integer", + "format": "int32" + }, + "memory": { + "description": "Amount of memory required", + "type": "number", + "format": "double" + }, + "memory_unit": { + "description": "Memory unit (default: MiB)\n", + "type": "string", + "default": "MiB", + "enum": [ + "MiB", + "MB", + "GiB", + "GB" + ] + }, + "output_data": { + "description": "Output data of the training, such as trained models. The output is specified as references to the data_store ids that contain the data.", + "type": "array", + "items": { + "description": "Reference to a data store id.", + "type": "string" + } + }, + "size": { + "description": "the pre-configured deployment size to used for training. The is used instead of directly specifying CPU, GPU, memory and learners.", + "type": "string" + }, + "training_status": { + "$ref": "#/definitions/TrainingStatus" + } + } + }, + "TrainingStatus": { + "type": "object", + "properties": { + "completed": { + "description": "Training completion timestamp (Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z')\n", + "type": "string" + }, + "error_code": { + "description": "A code identifying the cause of a status message.", + "type": "string" + }, + "status": { + "description": "Status of the training.", + "type": "string" + }, + "status_description": { + "description": "Description of the training status.", + "type": "string" + }, + "status_message": { + "description": "A human readable message description of the training status.", + "type": "string" + }, + "submitted": { + "description": "Training submission timestamp (Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z')\n", + "type": "string" + } + } + }, + "TrainingUpdate": { + "type": "object", + "properties": { + "status": { + "description": "The status action to be executed on the training job. (Currently only ` + "`" + `halt` + "`" + ` is supported.)", + "type": "string" + } + } + }, + "User": { + "required": [ + "id" + ], + "properties": { + "Name": { + "description": "Flag of Delete.", + "type": "string" + }, + "Remarks": { + "description": "Flag of Delete.", + "type": "string" + }, + "id": { + "description": "Flag of Delete.", + "type": "number", + "format": "int64" + } + } + }, + "v1LogLine": { + "type": "object", + "properties": { + "line": { + "type": "string" + }, + "meta": { + "$ref": "#/definitions/v1MetaInfo" + } + } + }, + "v1LogLinesList": { + "type": "object", + "properties": { + "models": { + "type": "array", + "items": { + "$ref": "#/definitions/v1LogLine" + } + } + } + }, + "v1MetaInfo": { + "type": "object", + "properties": { + "rindex": { + "type": "number", + "format": "int64", + "title": "sequential index" + }, + "time": { + "description": "Time that the metric occured: representing the number of millisecond since midnight January 1, 1970.", + "type": "number", + "format": "int64" + }, + "training_id": { + "type": "string", + "title": "Unique id identifying the training job" + }, + "user_id": { + "type": "string", + "title": "Unique id identifying the user" + } + } + } + } +}`)) +} diff --git a/di/restapi/api_v1/server/operations/di_api.go b/di/restapi/api_v1/server/operations/di_api.go new file mode 100644 index 0000000..1883ec9 --- /dev/null +++ b/di/restapi/api_v1/server/operations/di_api.go @@ -0,0 +1,453 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "net/http" + "strings" + + errors "github.com/go-openapi/errors" + loads "github.com/go-openapi/loads" + runtime "github.com/go-openapi/runtime" + middleware "github.com/go-openapi/runtime/middleware" + security "github.com/go-openapi/runtime/security" + spec "github.com/go-openapi/spec" + strfmt "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + + "webank/DI/restapi/api_v1/server/operations/experiments" + "webank/DI/restapi/api_v1/server/operations/models" + "webank/DI/restapi/api_v1/server/operations/training_data" +) + +// NewDiAPI creates a new Di instance +func NewDiAPI(spec *loads.Document) *DiAPI { + return &DiAPI{ + handlers: make(map[string]map[string]http.Handler), + formats: strfmt.Default, + defaultConsumes: "application/json", + defaultProduces: "application/json", + customConsumers: make(map[string]runtime.Consumer), + customProducers: make(map[string]runtime.Producer), + ServerShutdown: func() {}, + spec: spec, + ServeError: errors.ServeError, + BasicAuthenticator: security.BasicAuth, + APIKeyAuthenticator: security.APIKeyAuth, + BearerAuthenticator: security.BearerAuth, + JSONConsumer: runtime.JSONConsumer(), + MultipartformConsumer: runtime.DiscardConsumer, + JSONProducer: runtime.JSONProducer(), + BinProducer: runtime.ByteStreamProducer(), + ExperimentsCodeUploadHandler: experiments.CodeUploadHandlerFunc(func(params experiments.CodeUploadParams) middleware.Responder { + return middleware.NotImplemented("operation ExperimentsCodeUpload has not yet been implemented") + }), + ModelsDeleteModelHandler: models.DeleteModelHandlerFunc(func(params models.DeleteModelParams) middleware.Responder { + return middleware.NotImplemented("operation ModelsDeleteModel has not yet been implemented") + }), + ModelsDownloadModelDefinitionHandler: models.DownloadModelDefinitionHandlerFunc(func(params models.DownloadModelDefinitionParams) middleware.Responder { + return middleware.NotImplemented("operation ModelsDownloadModelDefinition has not yet been implemented") + }), + ModelsDownloadTrainedModelHandler: models.DownloadTrainedModelHandlerFunc(func(params models.DownloadTrainedModelParams) middleware.Responder { + return middleware.NotImplemented("operation ModelsDownloadTrainedModel has not yet been implemented") + }), + ModelsExportModelHandler: models.ExportModelHandlerFunc(func(params models.ExportModelParams) middleware.Responder { + return middleware.NotImplemented("operation ModelsExportModel has not yet been implemented") + }), + GetDashboardsHandler: GetDashboardsHandlerFunc(func(params GetDashboardsParams) middleware.Responder { + return middleware.NotImplemented("operation GetDashboards has not yet been implemented") + }), + TrainingDataGetLoglinesHandler: training_data.GetLoglinesHandlerFunc(func(params training_data.GetLoglinesParams) middleware.Responder { + return middleware.NotImplemented("operation TrainingDataGetLoglines has not yet been implemented") + }), + ModelsGetLogsHandler: models.GetLogsHandlerFunc(func(params models.GetLogsParams) middleware.Responder { + return middleware.NotImplemented("operation ModelsGetLogs has not yet been implemented") + }), + ModelsGetModelHandler: models.GetModelHandlerFunc(func(params models.GetModelParams) middleware.Responder { + return middleware.NotImplemented("operation ModelsGetModel has not yet been implemented") + }), + ModelsListModelsHandler: models.ListModelsHandlerFunc(func(params models.ListModelsParams) middleware.Responder { + return middleware.NotImplemented("operation ModelsListModels has not yet been implemented") + }), + ModelsPatchModelHandler: models.PatchModelHandlerFunc(func(params models.PatchModelParams) middleware.Responder { + return middleware.NotImplemented("operation ModelsPatchModel has not yet been implemented") + }), + ModelsPostModelHandler: models.PostModelHandlerFunc(func(params models.PostModelParams) middleware.Responder { + return middleware.NotImplemented("operation ModelsPostModel has not yet been implemented") + }), + } +} + +/*DiAPI Prophecis Rest Service + */ +type DiAPI struct { + spec *loads.Document + context *middleware.Context + handlers map[string]map[string]http.Handler + formats strfmt.Registry + customConsumers map[string]runtime.Consumer + customProducers map[string]runtime.Producer + defaultConsumes string + defaultProduces string + Middleware func(middleware.Builder) http.Handler + + // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function. + // It has a default implementation in the security package, however you can replace it for your particular usage. + BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator + // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function. + // It has a default implementation in the security package, however you can replace it for your particular usage. + APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator + // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function. + // It has a default implementation in the security package, however you can replace it for your particular usage. + BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator + + // JSONConsumer registers a consumer for a "application/json" mime type + JSONConsumer runtime.Consumer + // MultipartformConsumer registers a consumer for a "multipart/form-data" mime type + MultipartformConsumer runtime.Consumer + + // JSONProducer registers a producer for a "application/json" mime type + JSONProducer runtime.Producer + // BinProducer registers a producer for a "application/octet-stream" mime type + BinProducer runtime.Producer + + // ExperimentsCodeUploadHandler sets the operation handler for the code upload operation + ExperimentsCodeUploadHandler experiments.CodeUploadHandler + // ModelsDeleteModelHandler sets the operation handler for the delete model operation + ModelsDeleteModelHandler models.DeleteModelHandler + // ModelsDownloadModelDefinitionHandler sets the operation handler for the download model definition operation + ModelsDownloadModelDefinitionHandler models.DownloadModelDefinitionHandler + // ModelsDownloadTrainedModelHandler sets the operation handler for the download trained model operation + ModelsDownloadTrainedModelHandler models.DownloadTrainedModelHandler + // ModelsExportModelHandler sets the operation handler for the export model operation + ModelsExportModelHandler models.ExportModelHandler + // GetDashboardsHandler sets the operation handler for the get dashboards operation + GetDashboardsHandler GetDashboardsHandler + // TrainingDataGetLoglinesHandler sets the operation handler for the get loglines operation + TrainingDataGetLoglinesHandler training_data.GetLoglinesHandler + // ModelsGetLogsHandler sets the operation handler for the get logs operation + ModelsGetLogsHandler models.GetLogsHandler + // ModelsGetModelHandler sets the operation handler for the get model operation + ModelsGetModelHandler models.GetModelHandler + // ModelsListModelsHandler sets the operation handler for the list models operation + ModelsListModelsHandler models.ListModelsHandler + // ModelsPatchModelHandler sets the operation handler for the patch model operation + ModelsPatchModelHandler models.PatchModelHandler + // ModelsPostModelHandler sets the operation handler for the post model operation + ModelsPostModelHandler models.PostModelHandler + + // ServeError is called when an error is received, there is a default handler + // but you can set your own with this + ServeError func(http.ResponseWriter, *http.Request, error) + + // ServerShutdown is called when the HTTP(S) server is shut down and done + // handling all active connections and does not accept connections any more + ServerShutdown func() + + // Custom command line argument groups with their descriptions + CommandLineOptionsGroups []swag.CommandLineOptionsGroup + + // User defined logger function. + Logger func(string, ...interface{}) +} + +// SetDefaultProduces sets the default produces media type +func (o *DiAPI) SetDefaultProduces(mediaType string) { + o.defaultProduces = mediaType +} + +// SetDefaultConsumes returns the default consumes media type +func (o *DiAPI) SetDefaultConsumes(mediaType string) { + o.defaultConsumes = mediaType +} + +// SetSpec sets a spec that will be served for the clients. +func (o *DiAPI) SetSpec(spec *loads.Document) { + o.spec = spec +} + +// DefaultProduces returns the default produces media type +func (o *DiAPI) DefaultProduces() string { + return o.defaultProduces +} + +// DefaultConsumes returns the default consumes media type +func (o *DiAPI) DefaultConsumes() string { + return o.defaultConsumes +} + +// Formats returns the registered string formats +func (o *DiAPI) Formats() strfmt.Registry { + return o.formats +} + +// RegisterFormat registers a custom format validator +func (o *DiAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) { + o.formats.Add(name, format, validator) +} + +// Validate validates the registrations in the DiAPI +func (o *DiAPI) Validate() error { + var unregistered []string + + if o.JSONConsumer == nil { + unregistered = append(unregistered, "JSONConsumer") + } + + if o.MultipartformConsumer == nil { + unregistered = append(unregistered, "MultipartformConsumer") + } + + if o.JSONProducer == nil { + unregistered = append(unregistered, "JSONProducer") + } + + if o.BinProducer == nil { + unregistered = append(unregistered, "BinProducer") + } + + if o.ExperimentsCodeUploadHandler == nil { + unregistered = append(unregistered, "experiments.CodeUploadHandler") + } + + if o.ModelsDeleteModelHandler == nil { + unregistered = append(unregistered, "models.DeleteModelHandler") + } + + if o.ModelsDownloadModelDefinitionHandler == nil { + unregistered = append(unregistered, "models.DownloadModelDefinitionHandler") + } + + if o.ModelsDownloadTrainedModelHandler == nil { + unregistered = append(unregistered, "models.DownloadTrainedModelHandler") + } + + if o.ModelsExportModelHandler == nil { + unregistered = append(unregistered, "models.ExportModelHandler") + } + + if o.GetDashboardsHandler == nil { + unregistered = append(unregistered, "GetDashboardsHandler") + } + + if o.TrainingDataGetLoglinesHandler == nil { + unregistered = append(unregistered, "training_data.GetLoglinesHandler") + } + + if o.ModelsGetLogsHandler == nil { + unregistered = append(unregistered, "models.GetLogsHandler") + } + + if o.ModelsGetModelHandler == nil { + unregistered = append(unregistered, "models.GetModelHandler") + } + + if o.ModelsListModelsHandler == nil { + unregistered = append(unregistered, "models.ListModelsHandler") + } + + if o.ModelsPatchModelHandler == nil { + unregistered = append(unregistered, "models.PatchModelHandler") + } + + if o.ModelsPostModelHandler == nil { + unregistered = append(unregistered, "models.PostModelHandler") + } + + if len(unregistered) > 0 { + return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", ")) + } + + return nil +} + +// ServeErrorFor gets a error handler for a given operation id +func (o *DiAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) { + return o.ServeError +} + +// AuthenticatorsFor gets the authenticators for the specified security schemes +func (o *DiAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator { + + return nil + +} + +// Authorizer returns the registered authorizer +func (o *DiAPI) Authorizer() runtime.Authorizer { + + return nil + +} + +// ConsumersFor gets the consumers for the specified media types +func (o *DiAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer { + + result := make(map[string]runtime.Consumer) + for _, mt := range mediaTypes { + switch mt { + + case "application/json": + result["application/json"] = o.JSONConsumer + + case "multipart/form-data": + result["multipart/form-data"] = o.MultipartformConsumer + + } + + if c, ok := o.customConsumers[mt]; ok { + result[mt] = c + } + } + return result + +} + +// ProducersFor gets the producers for the specified media types +func (o *DiAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer { + + result := make(map[string]runtime.Producer) + for _, mt := range mediaTypes { + switch mt { + + case "application/json": + result["application/json"] = o.JSONProducer + + case "application/octet-stream": + result["application/octet-stream"] = o.BinProducer + + } + + if p, ok := o.customProducers[mt]; ok { + result[mt] = p + } + } + return result + +} + +// HandlerFor gets a http.Handler for the provided operation method and path +func (o *DiAPI) HandlerFor(method, path string) (http.Handler, bool) { + if o.handlers == nil { + return nil, false + } + um := strings.ToUpper(method) + if _, ok := o.handlers[um]; !ok { + return nil, false + } + if path == "/" { + path = "" + } + h, ok := o.handlers[um][path] + return h, ok +} + +// Context returns the middleware context for the di API +func (o *DiAPI) Context() *middleware.Context { + if o.context == nil { + o.context = middleware.NewRoutableContext(o.spec, o, nil) + } + + return o.context +} + +func (o *DiAPI) initHandlerCache() { + o.Context() // don't care about the result, just that the initialization happened + + if o.handlers == nil { + o.handlers = make(map[string]map[string]http.Handler) + } + + if o.handlers["POST"] == nil { + o.handlers["POST"] = make(map[string]http.Handler) + } + o.handlers["POST"]["/di/v1/codeUpload"] = experiments.NewCodeUpload(o.context, o.ExperimentsCodeUploadHandler) + + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/di/v1/models/{model_id}"] = models.NewDeleteModel(o.context, o.ModelsDeleteModelHandler) + + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/di/v1/models/{model_id}/definition"] = models.NewDownloadModelDefinition(o.context, o.ModelsDownloadModelDefinitionHandler) + + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/di/v1/models/{model_id}/trained_model"] = models.NewDownloadTrainedModel(o.context, o.ModelsDownloadTrainedModelHandler) + + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/di/v1/models/{model_id}/export"] = models.NewExportModel(o.context, o.ModelsExportModelHandler) + + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/di/v1/dashboards"] = NewGetDashboards(o.context, o.GetDashboardsHandler) + + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/di/v1/logs/{model_id}/loglines"] = training_data.NewGetLoglines(o.context, o.TrainingDataGetLoglinesHandler) + + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/di/v1/models/{model_id}/logs"] = models.NewGetLogs(o.context, o.ModelsGetLogsHandler) + + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/di/v1/models/{model_id}"] = models.NewGetModel(o.context, o.ModelsGetModelHandler) + + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/di/v1/models"] = models.NewListModels(o.context, o.ModelsListModelsHandler) + + if o.handlers["PATCH"] == nil { + o.handlers["PATCH"] = make(map[string]http.Handler) + } + o.handlers["PATCH"]["/di/v1/models/{model_id}"] = models.NewPatchModel(o.context, o.ModelsPatchModelHandler) + + if o.handlers["POST"] == nil { + o.handlers["POST"] = make(map[string]http.Handler) + } + o.handlers["POST"]["/di/v1/models"] = models.NewPostModel(o.context, o.ModelsPostModelHandler) + +} + +// Serve creates a http handler to serve the API over HTTP +// can be used directly in http.ListenAndServe(":8000", api.Serve(nil)) +func (o *DiAPI) Serve(builder middleware.Builder) http.Handler { + o.Init() + + if o.Middleware != nil { + return o.Middleware(builder) + } + return o.context.APIHandler(builder) +} + +// Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit +func (o *DiAPI) Init() { + if len(o.handlers) == 0 { + o.initHandlerCache() + } +} + +// RegisterConsumer allows you to add (or override) a consumer for a media type. +func (o *DiAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) { + o.customConsumers[mediaType] = consumer +} + +// RegisterProducer allows you to add (or override) a producer for a media type. +func (o *DiAPI) RegisterProducer(mediaType string, producer runtime.Producer) { + o.customProducers[mediaType] = producer +} diff --git a/di/restapi/api_v1/server/operations/experiments/code_upload.go b/di/restapi/api_v1/server/operations/experiments/code_upload.go new file mode 100644 index 0000000..23203ac --- /dev/null +++ b/di/restapi/api_v1/server/operations/experiments/code_upload.go @@ -0,0 +1,60 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package experiments + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// CodeUploadHandlerFunc turns a function with the right signature into a code upload handler +type CodeUploadHandlerFunc func(CodeUploadParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn CodeUploadHandlerFunc) Handle(params CodeUploadParams) middleware.Responder { + return fn(params) +} + +// CodeUploadHandler interface for that can handle valid code upload params +type CodeUploadHandler interface { + Handle(CodeUploadParams) middleware.Responder +} + +// NewCodeUpload creates a new http.Handler for the code upload operation +func NewCodeUpload(ctx *middleware.Context, handler CodeUploadHandler) *CodeUpload { + return &CodeUpload{Context: ctx, Handler: handler} +} + +/*CodeUpload swagger:route POST /di/v1/codeUpload Experiments codeUpload + +upload code to s3 + +upload code.zip to s3 + +*/ +type CodeUpload struct { + Context *middleware.Context + Handler CodeUploadHandler +} + +func (o *CodeUpload) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewCodeUploadParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/experiments/code_upload_parameters.go b/di/restapi/api_v1/server/operations/experiments/code_upload_parameters.go new file mode 100644 index 0000000..8bfb043 --- /dev/null +++ b/di/restapi/api_v1/server/operations/experiments/code_upload_parameters.go @@ -0,0 +1,79 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package experiments + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "mime/multipart" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" +) + +// NewCodeUploadParams creates a new CodeUploadParams object +// no default values defined in spec. +func NewCodeUploadParams() CodeUploadParams { + + return CodeUploadParams{} +} + +// CodeUploadParams contains all the bound params for the code upload operation +// typically these are obtained from a http.Request +// +// swagger:parameters codeUpload +type CodeUploadParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: formData + */ + File io.ReadCloser +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewCodeUploadParams() beforehand. +func (o *CodeUploadParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + if err := r.ParseMultipartForm(32 << 20); err != nil { + if err != http.ErrNotMultipart { + return errors.New(400, "%v", err) + } else if err := r.ParseForm(); err != nil { + return errors.New(400, "%v", err) + } + } + + file, fileHeader, err := r.FormFile("file") + if err != nil { + res = append(res, errors.New(400, "reading file %q failed: %v", "file", err)) + } else if err := o.bindFile(file, fileHeader); err != nil { + // Required: true + res = append(res, err) + } else { + o.File = &runtime.File{Data: file, Header: fileHeader} + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindFile binds file parameter File. +// +// The only supported validations on files are MinLength and MaxLength +func (o *CodeUploadParams) bindFile(file multipart.File, header *multipart.FileHeader) error { + return nil +} diff --git a/di/restapi/api_v1/server/operations/experiments/code_upload_responses.go b/di/restapi/api_v1/server/operations/experiments/code_upload_responses.go new file mode 100644 index 0000000..32a3881 --- /dev/null +++ b/di/restapi/api_v1/server/operations/experiments/code_upload_responses.go @@ -0,0 +1,146 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package experiments + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// CodeUploadOKCode is the HTTP code returned for type CodeUploadOK +const CodeUploadOKCode int = 200 + +/*CodeUploadOK OK + +swagger:response codeUploadOK +*/ +type CodeUploadOK struct { + + /* + In: Body + */ + Payload *restmodels.CodeUploadResponse `json:"body,omitempty"` +} + +// NewCodeUploadOK creates CodeUploadOK with default headers values +func NewCodeUploadOK() *CodeUploadOK { + + return &CodeUploadOK{} +} + +// WithPayload adds the payload to the code upload o k response +func (o *CodeUploadOK) WithPayload(payload *restmodels.CodeUploadResponse) *CodeUploadOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the code upload o k response +func (o *CodeUploadOK) SetPayload(payload *restmodels.CodeUploadResponse) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *CodeUploadOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// CodeUploadUnauthorizedCode is the HTTP code returned for type CodeUploadUnauthorized +const CodeUploadUnauthorizedCode int = 401 + +/*CodeUploadUnauthorized Unauthorized + +swagger:response codeUploadUnauthorized +*/ +type CodeUploadUnauthorized struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewCodeUploadUnauthorized creates CodeUploadUnauthorized with default headers values +func NewCodeUploadUnauthorized() *CodeUploadUnauthorized { + + return &CodeUploadUnauthorized{} +} + +// WithPayload adds the payload to the code upload unauthorized response +func (o *CodeUploadUnauthorized) WithPayload(payload *restmodels.Error) *CodeUploadUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the code upload unauthorized response +func (o *CodeUploadUnauthorized) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *CodeUploadUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// CodeUploadNotFoundCode is the HTTP code returned for type CodeUploadNotFound +const CodeUploadNotFoundCode int = 404 + +/*CodeUploadNotFound Code ZIP upload failed + +swagger:response codeUploadNotFound +*/ +type CodeUploadNotFound struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewCodeUploadNotFound creates CodeUploadNotFound with default headers values +func NewCodeUploadNotFound() *CodeUploadNotFound { + + return &CodeUploadNotFound{} +} + +// WithPayload adds the payload to the code upload not found response +func (o *CodeUploadNotFound) WithPayload(payload *restmodels.Error) *CodeUploadNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the code upload not found response +func (o *CodeUploadNotFound) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *CodeUploadNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/experiments/code_upload_urlbuilder.go b/di/restapi/api_v1/server/operations/experiments/code_upload_urlbuilder.go new file mode 100644 index 0000000..15119de --- /dev/null +++ b/di/restapi/api_v1/server/operations/experiments/code_upload_urlbuilder.go @@ -0,0 +1,87 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package experiments + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// CodeUploadURL generates an URL for the code upload operation +type CodeUploadURL struct { + _basePath string +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *CodeUploadURL) WithBasePath(bp string) *CodeUploadURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *CodeUploadURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *CodeUploadURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/codeUpload" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *CodeUploadURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *CodeUploadURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *CodeUploadURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on CodeUploadURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on CodeUploadURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *CodeUploadURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/operations/get_dashboards.go b/di/restapi/api_v1/server/operations/get_dashboards.go new file mode 100644 index 0000000..168173d --- /dev/null +++ b/di/restapi/api_v1/server/operations/get_dashboards.go @@ -0,0 +1,60 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// GetDashboardsHandlerFunc turns a function with the right signature into a get dashboards handler +type GetDashboardsHandlerFunc func(GetDashboardsParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetDashboardsHandlerFunc) Handle(params GetDashboardsParams) middleware.Responder { + return fn(params) +} + +// GetDashboardsHandler interface for that can handle valid get dashboards params +type GetDashboardsHandler interface { + Handle(GetDashboardsParams) middleware.Responder +} + +// NewGetDashboards creates a new http.Handler for the get dashboards operation +func NewGetDashboards(ctx *middleware.Context, handler GetDashboardsHandler) *GetDashboards { + return &GetDashboards{Context: ctx, Handler: handler} +} + +/*GetDashboards swagger:route GET /di/v1/dashboards getDashboards + +Get the dashboard belongs to a User + +Get dashboard. + +*/ +type GetDashboards struct { + Context *middleware.Context + Handler GetDashboardsHandler +} + +func (o *GetDashboards) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewGetDashboardsParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/get_dashboards_parameters.go b/di/restapi/api_v1/server/operations/get_dashboards_parameters.go new file mode 100644 index 0000000..7ae7cb5 --- /dev/null +++ b/di/restapi/api_v1/server/operations/get_dashboards_parameters.go @@ -0,0 +1,88 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetDashboardsParams creates a new GetDashboardsParams object +// with the default values initialized. +func NewGetDashboardsParams() GetDashboardsParams { + + var ( + // initialize parameters with default values + + clusterNameDefault = string("") + ) + + return GetDashboardsParams{ + ClusterName: &clusterNameDefault, + } +} + +// GetDashboardsParams contains all the bound params for the get dashboards operation +// typically these are obtained from a http.Request +// +// swagger:parameters getDashboards +type GetDashboardsParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*entity clusterName + In: query + Default: "" + */ + ClusterName *string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetDashboardsParams() beforehand. +func (o *GetDashboardsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + qClusterName, qhkClusterName, _ := qs.GetOK("clusterName") + if err := o.bindClusterName(qClusterName, qhkClusterName, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindClusterName binds and validates parameter ClusterName from query. +func (o *GetDashboardsParams) bindClusterName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetDashboardsParams() + return nil + } + + o.ClusterName = &raw + + return nil +} diff --git a/di/restapi/api_v1/server/operations/get_dashboards_responses.go b/di/restapi/api_v1/server/operations/get_dashboards_responses.go new file mode 100644 index 0000000..7ffd892 --- /dev/null +++ b/di/restapi/api_v1/server/operations/get_dashboards_responses.go @@ -0,0 +1,146 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// GetDashboardsOKCode is the HTTP code returned for type GetDashboardsOK +const GetDashboardsOKCode int = 200 + +/*GetDashboardsOK OK + +swagger:response getDashboardsOK +*/ +type GetDashboardsOK struct { + + /* + In: Body + */ + Payload *restmodels.GetDashboardsResponse `json:"body,omitempty"` +} + +// NewGetDashboardsOK creates GetDashboardsOK with default headers values +func NewGetDashboardsOK() *GetDashboardsOK { + + return &GetDashboardsOK{} +} + +// WithPayload adds the payload to the get dashboards o k response +func (o *GetDashboardsOK) WithPayload(payload *restmodels.GetDashboardsResponse) *GetDashboardsOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get dashboards o k response +func (o *GetDashboardsOK) SetPayload(payload *restmodels.GetDashboardsResponse) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDashboardsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetDashboardsForbiddenCode is the HTTP code returned for type GetDashboardsForbidden +const GetDashboardsForbiddenCode int = 403 + +/*GetDashboardsForbidden Forbidden + +swagger:response getDashboardsForbidden +*/ +type GetDashboardsForbidden struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewGetDashboardsForbidden creates GetDashboardsForbidden with default headers values +func NewGetDashboardsForbidden() *GetDashboardsForbidden { + + return &GetDashboardsForbidden{} +} + +// WithPayload adds the payload to the get dashboards forbidden response +func (o *GetDashboardsForbidden) WithPayload(payload *restmodels.Error) *GetDashboardsForbidden { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get dashboards forbidden response +func (o *GetDashboardsForbidden) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDashboardsForbidden) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(403) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetDashboardsNotFoundCode is the HTTP code returned for type GetDashboardsNotFound +const GetDashboardsNotFoundCode int = 404 + +/*GetDashboardsNotFound The dashboard cannot be found + +swagger:response getDashboardsNotFound +*/ +type GetDashboardsNotFound struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewGetDashboardsNotFound creates GetDashboardsNotFound with default headers values +func NewGetDashboardsNotFound() *GetDashboardsNotFound { + + return &GetDashboardsNotFound{} +} + +// WithPayload adds the payload to the get dashboards not found response +func (o *GetDashboardsNotFound) WithPayload(payload *restmodels.Error) *GetDashboardsNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get dashboards not found response +func (o *GetDashboardsNotFound) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDashboardsNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/get_dashboards_urlbuilder.go b/di/restapi/api_v1/server/operations/get_dashboards_urlbuilder.go new file mode 100644 index 0000000..64a2e81 --- /dev/null +++ b/di/restapi/api_v1/server/operations/get_dashboards_urlbuilder.go @@ -0,0 +1,103 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// GetDashboardsURL generates an URL for the get dashboards operation +type GetDashboardsURL struct { + ClusterName *string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDashboardsURL) WithBasePath(bp string) *GetDashboardsURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDashboardsURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetDashboardsURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/dashboards" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var clusterNameQ string + if o.ClusterName != nil { + clusterNameQ = *o.ClusterName + } + if clusterNameQ != "" { + qs.Set("clusterName", clusterNameQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetDashboardsURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetDashboardsURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetDashboardsURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetDashboardsURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetDashboardsURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetDashboardsURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/operations/models/delete_model.go b/di/restapi/api_v1/server/operations/models/delete_model.go new file mode 100644 index 0000000..b7e4389 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/delete_model.go @@ -0,0 +1,61 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// DeleteModelHandlerFunc turns a function with the right signature into a delete model handler +type DeleteModelHandlerFunc func(DeleteModelParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteModelHandlerFunc) Handle(params DeleteModelParams) middleware.Responder { + return fn(params) +} + +// DeleteModelHandler interface for that can handle valid delete model params +type DeleteModelHandler interface { + Handle(DeleteModelParams) middleware.Responder +} + +// NewDeleteModel creates a new http.Handler for the delete model operation +func NewDeleteModel(ctx *middleware.Context, handler DeleteModelHandler) *DeleteModel { + return &DeleteModel{Context: ctx, Handler: handler} +} + +/*DeleteModel swagger:route DELETE /di/v1/models/{model_id} Models deleteModel + +Deletes an existing model + +Deletes an existing model. It does not delete any data in the user's data store. + + +*/ +type DeleteModel struct { + Context *middleware.Context + Handler DeleteModelHandler +} + +func (o *DeleteModel) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewDeleteModelParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/models/delete_model_parameters.go b/di/restapi/api_v1/server/operations/models/delete_model_parameters.go new file mode 100644 index 0000000..f6286f5 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/delete_model_parameters.go @@ -0,0 +1,117 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewDeleteModelParams creates a new DeleteModelParams object +// with the default values initialized. +func NewDeleteModelParams() DeleteModelParams { + + var ( + // initialize parameters with default values + + versionDefault = string("2017-02-13") + ) + + return DeleteModelParams{ + Version: versionDefault, + } +} + +// DeleteModelParams contains all the bound params for the delete model operation +// typically these are obtained from a http.Request +// +// swagger:parameters deleteModel +type DeleteModelParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*The id of the model. + Required: true + In: path + */ + ModelID string + /*The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + Required: true + In: query + Default: "2017-02-13" + */ + Version string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteModelParams() beforehand. +func (o *DeleteModelParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rModelID, rhkModelID, _ := route.Params.GetOK("model_id") + if err := o.bindModelID(rModelID, rhkModelID, route.Formats); err != nil { + res = append(res, err) + } + + qVersion, qhkVersion, _ := qs.GetOK("version") + if err := o.bindVersion(qVersion, qhkVersion, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindModelID binds and validates parameter ModelID from path. +func (o *DeleteModelParams) bindModelID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + + o.ModelID = raw + + return nil +} + +// bindVersion binds and validates parameter Version from query. +func (o *DeleteModelParams) bindVersion(rawData []string, hasKey bool, formats strfmt.Registry) error { + if !hasKey { + return errors.Required("version", "query") + } + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // AllowEmptyValue: false + if err := validate.RequiredString("version", "query", raw); err != nil { + return err + } + + o.Version = raw + + return nil +} diff --git a/di/restapi/api_v1/server/operations/models/delete_model_responses.go b/di/restapi/api_v1/server/operations/models/delete_model_responses.go new file mode 100644 index 0000000..99a1ce4 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/delete_model_responses.go @@ -0,0 +1,146 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// DeleteModelOKCode is the HTTP code returned for type DeleteModelOK +const DeleteModelOKCode int = 200 + +/*DeleteModelOK Model deleted successfully. + +swagger:response deleteModelOK +*/ +type DeleteModelOK struct { + + /* + In: Body + */ + Payload *restmodels.BasicModel `json:"body,omitempty"` +} + +// NewDeleteModelOK creates DeleteModelOK with default headers values +func NewDeleteModelOK() *DeleteModelOK { + + return &DeleteModelOK{} +} + +// WithPayload adds the payload to the delete model o k response +func (o *DeleteModelOK) WithPayload(payload *restmodels.BasicModel) *DeleteModelOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete model o k response +func (o *DeleteModelOK) SetPayload(payload *restmodels.BasicModel) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteModelOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteModelUnauthorizedCode is the HTTP code returned for type DeleteModelUnauthorized +const DeleteModelUnauthorizedCode int = 401 + +/*DeleteModelUnauthorized Unauthorized + +swagger:response deleteModelUnauthorized +*/ +type DeleteModelUnauthorized struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewDeleteModelUnauthorized creates DeleteModelUnauthorized with default headers values +func NewDeleteModelUnauthorized() *DeleteModelUnauthorized { + + return &DeleteModelUnauthorized{} +} + +// WithPayload adds the payload to the delete model unauthorized response +func (o *DeleteModelUnauthorized) WithPayload(payload *restmodels.Error) *DeleteModelUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete model unauthorized response +func (o *DeleteModelUnauthorized) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteModelUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteModelNotFoundCode is the HTTP code returned for type DeleteModelNotFound +const DeleteModelNotFoundCode int = 404 + +/*DeleteModelNotFound The model cannot be found. + +swagger:response deleteModelNotFound +*/ +type DeleteModelNotFound struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewDeleteModelNotFound creates DeleteModelNotFound with default headers values +func NewDeleteModelNotFound() *DeleteModelNotFound { + + return &DeleteModelNotFound{} +} + +// WithPayload adds the payload to the delete model not found response +func (o *DeleteModelNotFound) WithPayload(payload *restmodels.Error) *DeleteModelNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete model not found response +func (o *DeleteModelNotFound) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteModelNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/models/delete_model_urlbuilder.go b/di/restapi/api_v1/server/operations/models/delete_model_urlbuilder.go new file mode 100644 index 0000000..750beb3 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/delete_model_urlbuilder.go @@ -0,0 +1,110 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DeleteModelURL generates an URL for the delete model operation +type DeleteModelURL struct { + ModelID string + + Version string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteModelURL) WithBasePath(bp string) *DeleteModelURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteModelURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteModelURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/models/{model_id}" + + modelID := o.ModelID + if modelID != "" { + _path = strings.Replace(_path, "{model_id}", modelID, -1) + } else { + return nil, errors.New("modelId is required on DeleteModelURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + versionQ := o.Version + if versionQ != "" { + qs.Set("version", versionQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteModelURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteModelURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteModelURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteModelURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteModelURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteModelURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/operations/models/download_model_definition.go b/di/restapi/api_v1/server/operations/models/download_model_definition.go new file mode 100644 index 0000000..8fbb909 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/download_model_definition.go @@ -0,0 +1,60 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// DownloadModelDefinitionHandlerFunc turns a function with the right signature into a download model definition handler +type DownloadModelDefinitionHandlerFunc func(DownloadModelDefinitionParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DownloadModelDefinitionHandlerFunc) Handle(params DownloadModelDefinitionParams) middleware.Responder { + return fn(params) +} + +// DownloadModelDefinitionHandler interface for that can handle valid download model definition params +type DownloadModelDefinitionHandler interface { + Handle(DownloadModelDefinitionParams) middleware.Responder +} + +// NewDownloadModelDefinition creates a new http.Handler for the download model definition operation +func NewDownloadModelDefinition(ctx *middleware.Context, handler DownloadModelDefinitionHandler) *DownloadModelDefinition { + return &DownloadModelDefinition{Context: ctx, Handler: handler} +} + +/*DownloadModelDefinition swagger:route GET /di/v1/models/{model_id}/definition Models downloadModelDefinition + +Downloads the model definition. + +Downloads the model definition that was initial used for training as ZIP archive. + +*/ +type DownloadModelDefinition struct { + Context *middleware.Context + Handler DownloadModelDefinitionHandler +} + +func (o *DownloadModelDefinition) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewDownloadModelDefinitionParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/models/download_model_definition_parameters.go b/di/restapi/api_v1/server/operations/models/download_model_definition_parameters.go new file mode 100644 index 0000000..f3ba912 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/download_model_definition_parameters.go @@ -0,0 +1,117 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewDownloadModelDefinitionParams creates a new DownloadModelDefinitionParams object +// with the default values initialized. +func NewDownloadModelDefinitionParams() DownloadModelDefinitionParams { + + var ( + // initialize parameters with default values + + versionDefault = string("2017-02-13") + ) + + return DownloadModelDefinitionParams{ + Version: versionDefault, + } +} + +// DownloadModelDefinitionParams contains all the bound params for the download model definition operation +// typically these are obtained from a http.Request +// +// swagger:parameters downloadModelDefinition +type DownloadModelDefinitionParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*The id of the model. + Required: true + In: path + */ + ModelID string + /*The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + Required: true + In: query + Default: "2017-02-13" + */ + Version string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDownloadModelDefinitionParams() beforehand. +func (o *DownloadModelDefinitionParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rModelID, rhkModelID, _ := route.Params.GetOK("model_id") + if err := o.bindModelID(rModelID, rhkModelID, route.Formats); err != nil { + res = append(res, err) + } + + qVersion, qhkVersion, _ := qs.GetOK("version") + if err := o.bindVersion(qVersion, qhkVersion, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindModelID binds and validates parameter ModelID from path. +func (o *DownloadModelDefinitionParams) bindModelID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + + o.ModelID = raw + + return nil +} + +// bindVersion binds and validates parameter Version from query. +func (o *DownloadModelDefinitionParams) bindVersion(rawData []string, hasKey bool, formats strfmt.Registry) error { + if !hasKey { + return errors.Required("version", "query") + } + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // AllowEmptyValue: false + if err := validate.RequiredString("version", "query", raw); err != nil { + return err + } + + o.Version = raw + + return nil +} diff --git a/di/restapi/api_v1/server/operations/models/download_model_definition_responses.go b/di/restapi/api_v1/server/operations/models/download_model_definition_responses.go new file mode 100644 index 0000000..57d63d8 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/download_model_definition_responses.go @@ -0,0 +1,145 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// DownloadModelDefinitionOKCode is the HTTP code returned for type DownloadModelDefinitionOK +const DownloadModelDefinitionOKCode int = 200 + +/*DownloadModelDefinitionOK Model definition + +swagger:response downloadModelDefinitionOK +*/ +type DownloadModelDefinitionOK struct { + + /* + In: Body + */ + Payload io.ReadCloser `json:"body,omitempty"` +} + +// NewDownloadModelDefinitionOK creates DownloadModelDefinitionOK with default headers values +func NewDownloadModelDefinitionOK() *DownloadModelDefinitionOK { + + return &DownloadModelDefinitionOK{} +} + +// WithPayload adds the payload to the download model definition o k response +func (o *DownloadModelDefinitionOK) WithPayload(payload io.ReadCloser) *DownloadModelDefinitionOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the download model definition o k response +func (o *DownloadModelDefinitionOK) SetPayload(payload io.ReadCloser) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DownloadModelDefinitionOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DownloadModelDefinitionUnauthorizedCode is the HTTP code returned for type DownloadModelDefinitionUnauthorized +const DownloadModelDefinitionUnauthorizedCode int = 401 + +/*DownloadModelDefinitionUnauthorized Unauthorized + +swagger:response downloadModelDefinitionUnauthorized +*/ +type DownloadModelDefinitionUnauthorized struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewDownloadModelDefinitionUnauthorized creates DownloadModelDefinitionUnauthorized with default headers values +func NewDownloadModelDefinitionUnauthorized() *DownloadModelDefinitionUnauthorized { + + return &DownloadModelDefinitionUnauthorized{} +} + +// WithPayload adds the payload to the download model definition unauthorized response +func (o *DownloadModelDefinitionUnauthorized) WithPayload(payload *restmodels.Error) *DownloadModelDefinitionUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the download model definition unauthorized response +func (o *DownloadModelDefinitionUnauthorized) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DownloadModelDefinitionUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DownloadModelDefinitionNotFoundCode is the HTTP code returned for type DownloadModelDefinitionNotFound +const DownloadModelDefinitionNotFoundCode int = 404 + +/*DownloadModelDefinitionNotFound The model cannot be found. + +swagger:response downloadModelDefinitionNotFound +*/ +type DownloadModelDefinitionNotFound struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewDownloadModelDefinitionNotFound creates DownloadModelDefinitionNotFound with default headers values +func NewDownloadModelDefinitionNotFound() *DownloadModelDefinitionNotFound { + + return &DownloadModelDefinitionNotFound{} +} + +// WithPayload adds the payload to the download model definition not found response +func (o *DownloadModelDefinitionNotFound) WithPayload(payload *restmodels.Error) *DownloadModelDefinitionNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the download model definition not found response +func (o *DownloadModelDefinitionNotFound) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DownloadModelDefinitionNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/models/download_model_definition_urlbuilder.go b/di/restapi/api_v1/server/operations/models/download_model_definition_urlbuilder.go new file mode 100644 index 0000000..732925a --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/download_model_definition_urlbuilder.go @@ -0,0 +1,110 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DownloadModelDefinitionURL generates an URL for the download model definition operation +type DownloadModelDefinitionURL struct { + ModelID string + + Version string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DownloadModelDefinitionURL) WithBasePath(bp string) *DownloadModelDefinitionURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DownloadModelDefinitionURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DownloadModelDefinitionURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/models/{model_id}/definition" + + modelID := o.ModelID + if modelID != "" { + _path = strings.Replace(_path, "{model_id}", modelID, -1) + } else { + return nil, errors.New("modelId is required on DownloadModelDefinitionURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + versionQ := o.Version + if versionQ != "" { + qs.Set("version", versionQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DownloadModelDefinitionURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DownloadModelDefinitionURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DownloadModelDefinitionURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DownloadModelDefinitionURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DownloadModelDefinitionURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DownloadModelDefinitionURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/operations/models/download_trained_model.go b/di/restapi/api_v1/server/operations/models/download_trained_model.go new file mode 100644 index 0000000..f2b942b --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/download_trained_model.go @@ -0,0 +1,60 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// DownloadTrainedModelHandlerFunc turns a function with the right signature into a download trained model handler +type DownloadTrainedModelHandlerFunc func(DownloadTrainedModelParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DownloadTrainedModelHandlerFunc) Handle(params DownloadTrainedModelParams) middleware.Responder { + return fn(params) +} + +// DownloadTrainedModelHandler interface for that can handle valid download trained model params +type DownloadTrainedModelHandler interface { + Handle(DownloadTrainedModelParams) middleware.Responder +} + +// NewDownloadTrainedModel creates a new http.Handler for the download trained model operation +func NewDownloadTrainedModel(ctx *middleware.Context, handler DownloadTrainedModelHandler) *DownloadTrainedModel { + return &DownloadTrainedModel{Context: ctx, Handler: handler} +} + +/*DownloadTrainedModel swagger:route GET /di/v1/models/{model_id}/trained_model Models downloadTrainedModel + +Downloads the trained model. + +Downloads the trained model as ZIP archive. + +*/ +type DownloadTrainedModel struct { + Context *middleware.Context + Handler DownloadTrainedModelHandler +} + +func (o *DownloadTrainedModel) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewDownloadTrainedModelParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/models/download_trained_model_parameters.go b/di/restapi/api_v1/server/operations/models/download_trained_model_parameters.go new file mode 100644 index 0000000..0e89b86 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/download_trained_model_parameters.go @@ -0,0 +1,117 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewDownloadTrainedModelParams creates a new DownloadTrainedModelParams object +// with the default values initialized. +func NewDownloadTrainedModelParams() DownloadTrainedModelParams { + + var ( + // initialize parameters with default values + + versionDefault = string("2017-02-13") + ) + + return DownloadTrainedModelParams{ + Version: versionDefault, + } +} + +// DownloadTrainedModelParams contains all the bound params for the download trained model operation +// typically these are obtained from a http.Request +// +// swagger:parameters downloadTrainedModel +type DownloadTrainedModelParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*The id of the model. + Required: true + In: path + */ + ModelID string + /*The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + Required: true + In: query + Default: "2017-02-13" + */ + Version string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDownloadTrainedModelParams() beforehand. +func (o *DownloadTrainedModelParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rModelID, rhkModelID, _ := route.Params.GetOK("model_id") + if err := o.bindModelID(rModelID, rhkModelID, route.Formats); err != nil { + res = append(res, err) + } + + qVersion, qhkVersion, _ := qs.GetOK("version") + if err := o.bindVersion(qVersion, qhkVersion, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindModelID binds and validates parameter ModelID from path. +func (o *DownloadTrainedModelParams) bindModelID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + + o.ModelID = raw + + return nil +} + +// bindVersion binds and validates parameter Version from query. +func (o *DownloadTrainedModelParams) bindVersion(rawData []string, hasKey bool, formats strfmt.Registry) error { + if !hasKey { + return errors.Required("version", "query") + } + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // AllowEmptyValue: false + if err := validate.RequiredString("version", "query", raw); err != nil { + return err + } + + o.Version = raw + + return nil +} diff --git a/di/restapi/api_v1/server/operations/models/download_trained_model_responses.go b/di/restapi/api_v1/server/operations/models/download_trained_model_responses.go new file mode 100644 index 0000000..e198bea --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/download_trained_model_responses.go @@ -0,0 +1,189 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// DownloadTrainedModelOKCode is the HTTP code returned for type DownloadTrainedModelOK +const DownloadTrainedModelOKCode int = 200 + +/*DownloadTrainedModelOK Model definition + +swagger:response downloadTrainedModelOK +*/ +type DownloadTrainedModelOK struct { + + /* + In: Body + */ + Payload io.ReadCloser `json:"body,omitempty"` +} + +// NewDownloadTrainedModelOK creates DownloadTrainedModelOK with default headers values +func NewDownloadTrainedModelOK() *DownloadTrainedModelOK { + + return &DownloadTrainedModelOK{} +} + +// WithPayload adds the payload to the download trained model o k response +func (o *DownloadTrainedModelOK) WithPayload(payload io.ReadCloser) *DownloadTrainedModelOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the download trained model o k response +func (o *DownloadTrainedModelOK) SetPayload(payload io.ReadCloser) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DownloadTrainedModelOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DownloadTrainedModelUnauthorizedCode is the HTTP code returned for type DownloadTrainedModelUnauthorized +const DownloadTrainedModelUnauthorizedCode int = 401 + +/*DownloadTrainedModelUnauthorized Unauthorized + +swagger:response downloadTrainedModelUnauthorized +*/ +type DownloadTrainedModelUnauthorized struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewDownloadTrainedModelUnauthorized creates DownloadTrainedModelUnauthorized with default headers values +func NewDownloadTrainedModelUnauthorized() *DownloadTrainedModelUnauthorized { + + return &DownloadTrainedModelUnauthorized{} +} + +// WithPayload adds the payload to the download trained model unauthorized response +func (o *DownloadTrainedModelUnauthorized) WithPayload(payload *restmodels.Error) *DownloadTrainedModelUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the download trained model unauthorized response +func (o *DownloadTrainedModelUnauthorized) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DownloadTrainedModelUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DownloadTrainedModelNotFoundCode is the HTTP code returned for type DownloadTrainedModelNotFound +const DownloadTrainedModelNotFoundCode int = 404 + +/*DownloadTrainedModelNotFound The trained model cannot be found. + +swagger:response downloadTrainedModelNotFound +*/ +type DownloadTrainedModelNotFound struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewDownloadTrainedModelNotFound creates DownloadTrainedModelNotFound with default headers values +func NewDownloadTrainedModelNotFound() *DownloadTrainedModelNotFound { + + return &DownloadTrainedModelNotFound{} +} + +// WithPayload adds the payload to the download trained model not found response +func (o *DownloadTrainedModelNotFound) WithPayload(payload *restmodels.Error) *DownloadTrainedModelNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the download trained model not found response +func (o *DownloadTrainedModelNotFound) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DownloadTrainedModelNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DownloadTrainedModelGoneCode is the HTTP code returned for type DownloadTrainedModelGone +const DownloadTrainedModelGoneCode int = 410 + +/*DownloadTrainedModelGone If the trained model storage time has expired and it has been deleted. It only gets deleted if it not stored on an external data store. + +swagger:response downloadTrainedModelGone +*/ +type DownloadTrainedModelGone struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewDownloadTrainedModelGone creates DownloadTrainedModelGone with default headers values +func NewDownloadTrainedModelGone() *DownloadTrainedModelGone { + + return &DownloadTrainedModelGone{} +} + +// WithPayload adds the payload to the download trained model gone response +func (o *DownloadTrainedModelGone) WithPayload(payload *restmodels.Error) *DownloadTrainedModelGone { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the download trained model gone response +func (o *DownloadTrainedModelGone) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DownloadTrainedModelGone) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(410) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/models/download_trained_model_urlbuilder.go b/di/restapi/api_v1/server/operations/models/download_trained_model_urlbuilder.go new file mode 100644 index 0000000..b6d8212 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/download_trained_model_urlbuilder.go @@ -0,0 +1,110 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DownloadTrainedModelURL generates an URL for the download trained model operation +type DownloadTrainedModelURL struct { + ModelID string + + Version string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DownloadTrainedModelURL) WithBasePath(bp string) *DownloadTrainedModelURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DownloadTrainedModelURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DownloadTrainedModelURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/models/{model_id}/trained_model" + + modelID := o.ModelID + if modelID != "" { + _path = strings.Replace(_path, "{model_id}", modelID, -1) + } else { + return nil, errors.New("modelId is required on DownloadTrainedModelURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + versionQ := o.Version + if versionQ != "" { + qs.Set("version", versionQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DownloadTrainedModelURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DownloadTrainedModelURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DownloadTrainedModelURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DownloadTrainedModelURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DownloadTrainedModelURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DownloadTrainedModelURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/operations/models/export_model.go b/di/restapi/api_v1/server/operations/models/export_model.go new file mode 100644 index 0000000..72c468b --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/export_model.go @@ -0,0 +1,60 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// ExportModelHandlerFunc turns a function with the right signature into a export model handler +type ExportModelHandlerFunc func(ExportModelParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn ExportModelHandlerFunc) Handle(params ExportModelParams) middleware.Responder { + return fn(params) +} + +// ExportModelHandler interface for that can handle valid export model params +type ExportModelHandler interface { + Handle(ExportModelParams) middleware.Responder +} + +// NewExportModel creates a new http.Handler for the export model operation +func NewExportModel(ctx *middleware.Context, handler ExportModelHandler) *ExportModel { + return &ExportModel{Context: ctx, Handler: handler} +} + +/*ExportModel swagger:route GET /di/v1/models/{model_id}/export Models exportModel + +Export the model definition. + +Export the model definition + +*/ +type ExportModel struct { + Context *middleware.Context + Handler ExportModelHandler +} + +func (o *ExportModel) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewExportModelParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/models/export_model_parameters.go b/di/restapi/api_v1/server/operations/models/export_model_parameters.go new file mode 100644 index 0000000..991a58f --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/export_model_parameters.go @@ -0,0 +1,73 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewExportModelParams creates a new ExportModelParams object +// no default values defined in spec. +func NewExportModelParams() ExportModelParams { + + return ExportModelParams{} +} + +// ExportModelParams contains all the bound params for the export model operation +// typically these are obtained from a http.Request +// +// swagger:parameters exportModel +type ExportModelParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*The id of the model. + Required: true + In: path + */ + ModelID string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewExportModelParams() beforehand. +func (o *ExportModelParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rModelID, rhkModelID, _ := route.Params.GetOK("model_id") + if err := o.bindModelID(rModelID, rhkModelID, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindModelID binds and validates parameter ModelID from path. +func (o *ExportModelParams) bindModelID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + + o.ModelID = raw + + return nil +} diff --git a/di/restapi/api_v1/server/operations/models/export_model_responses.go b/di/restapi/api_v1/server/operations/models/export_model_responses.go new file mode 100644 index 0000000..653ea62 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/export_model_responses.go @@ -0,0 +1,145 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// ExportModelOKCode is the HTTP code returned for type ExportModelOK +const ExportModelOKCode int = 200 + +/*ExportModelOK Model definition + +swagger:response exportModelOK +*/ +type ExportModelOK struct { + + /* + In: Body + */ + Payload io.ReadCloser `json:"body,omitempty"` +} + +// NewExportModelOK creates ExportModelOK with default headers values +func NewExportModelOK() *ExportModelOK { + + return &ExportModelOK{} +} + +// WithPayload adds the payload to the export model o k response +func (o *ExportModelOK) WithPayload(payload io.ReadCloser) *ExportModelOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the export model o k response +func (o *ExportModelOK) SetPayload(payload io.ReadCloser) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *ExportModelOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// ExportModelUnauthorizedCode is the HTTP code returned for type ExportModelUnauthorized +const ExportModelUnauthorizedCode int = 401 + +/*ExportModelUnauthorized Unauthorized + +swagger:response exportModelUnauthorized +*/ +type ExportModelUnauthorized struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewExportModelUnauthorized creates ExportModelUnauthorized with default headers values +func NewExportModelUnauthorized() *ExportModelUnauthorized { + + return &ExportModelUnauthorized{} +} + +// WithPayload adds the payload to the export model unauthorized response +func (o *ExportModelUnauthorized) WithPayload(payload *restmodels.Error) *ExportModelUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the export model unauthorized response +func (o *ExportModelUnauthorized) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *ExportModelUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// ExportModelNotFoundCode is the HTTP code returned for type ExportModelNotFound +const ExportModelNotFoundCode int = 404 + +/*ExportModelNotFound The model cannot be found. + +swagger:response exportModelNotFound +*/ +type ExportModelNotFound struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewExportModelNotFound creates ExportModelNotFound with default headers values +func NewExportModelNotFound() *ExportModelNotFound { + + return &ExportModelNotFound{} +} + +// WithPayload adds the payload to the export model not found response +func (o *ExportModelNotFound) WithPayload(payload *restmodels.Error) *ExportModelNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the export model not found response +func (o *ExportModelNotFound) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *ExportModelNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/models/export_model_urlbuilder.go b/di/restapi/api_v1/server/operations/models/export_model_urlbuilder.go new file mode 100644 index 0000000..08c79f6 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/export_model_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// ExportModelURL generates an URL for the export model operation +type ExportModelURL struct { + ModelID string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *ExportModelURL) WithBasePath(bp string) *ExportModelURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *ExportModelURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *ExportModelURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/models/{model_id}/export" + + modelID := o.ModelID + if modelID != "" { + _path = strings.Replace(_path, "{model_id}", modelID, -1) + } else { + return nil, errors.New("modelId is required on ExportModelURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *ExportModelURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *ExportModelURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *ExportModelURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on ExportModelURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on ExportModelURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *ExportModelURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/operations/models/get_logs.go b/di/restapi/api_v1/server/operations/models/get_logs.go new file mode 100644 index 0000000..1cc89c4 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/get_logs.go @@ -0,0 +1,62 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// GetLogsHandlerFunc turns a function with the right signature into a get logs handler +type GetLogsHandlerFunc func(GetLogsParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetLogsHandlerFunc) Handle(params GetLogsParams) middleware.Responder { + return fn(params) +} + +// GetLogsHandler interface for that can handle valid get logs params +type GetLogsHandler interface { + Handle(GetLogsParams) middleware.Responder +} + +// NewGetLogs creates a new http.Handler for the get logs operation +func NewGetLogs(ctx *middleware.Context, handler GetLogsHandler) *GetLogs { + return &GetLogs{Context: ctx, Handler: handler} +} + +/*GetLogs swagger:route GET /di/v1/models/{model_id}/logs Models getLogs + +Get training logs as websocket stream. + + +Get training logs for the given model as websocket stream. Each message can contain one or more log lines. + + +*/ +type GetLogs struct { + Context *middleware.Context + Handler GetLogsHandler +} + +func (o *GetLogs) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewGetLogsParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/models/get_logs_parameters.go b/di/restapi/api_v1/server/operations/models/get_logs_parameters.go new file mode 100644 index 0000000..ee08ad8 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/get_logs_parameters.go @@ -0,0 +1,187 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetLogsParams creates a new GetLogsParams object +// with the default values initialized. +func NewGetLogsParams() GetLogsParams { + + var ( + // initialize parameters with default values + + followDefault = bool(false) + + sinceTimeDefault = string("") + versionDefault = string("2017-02-13") + ) + + return GetLogsParams{ + Follow: &followDefault, + + SinceTime: &sinceTimeDefault, + + Version: versionDefault, + } +} + +// GetLogsParams contains all the bound params for the get logs operation +// typically these are obtained from a http.Request +// +// swagger:parameters getLogs +type GetLogsParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*Follow the log stream if true. Default false. + In: query + Default: false + */ + Follow *bool + /*The id of the model. + Required: true + In: path + */ + ModelID string + /*An RFC3339 timestamp from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will be returned. + In: query + Default: "" + */ + SinceTime *string + /*The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + Required: true + In: query + Default: "2017-02-13" + */ + Version string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetLogsParams() beforehand. +func (o *GetLogsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + qFollow, qhkFollow, _ := qs.GetOK("follow") + if err := o.bindFollow(qFollow, qhkFollow, route.Formats); err != nil { + res = append(res, err) + } + + rModelID, rhkModelID, _ := route.Params.GetOK("model_id") + if err := o.bindModelID(rModelID, rhkModelID, route.Formats); err != nil { + res = append(res, err) + } + + qSinceTime, qhkSinceTime, _ := qs.GetOK("since_time") + if err := o.bindSinceTime(qSinceTime, qhkSinceTime, route.Formats); err != nil { + res = append(res, err) + } + + qVersion, qhkVersion, _ := qs.GetOK("version") + if err := o.bindVersion(qVersion, qhkVersion, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindFollow binds and validates parameter Follow from query. +func (o *GetLogsParams) bindFollow(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetLogsParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("follow", "query", "bool", raw) + } + o.Follow = &value + + return nil +} + +// bindModelID binds and validates parameter ModelID from path. +func (o *GetLogsParams) bindModelID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + + o.ModelID = raw + + return nil +} + +// bindSinceTime binds and validates parameter SinceTime from query. +func (o *GetLogsParams) bindSinceTime(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetLogsParams() + return nil + } + + o.SinceTime = &raw + + return nil +} + +// bindVersion binds and validates parameter Version from query. +func (o *GetLogsParams) bindVersion(rawData []string, hasKey bool, formats strfmt.Registry) error { + if !hasKey { + return errors.Required("version", "query") + } + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // AllowEmptyValue: false + if err := validate.RequiredString("version", "query", raw); err != nil { + return err + } + + o.Version = raw + + return nil +} diff --git a/di/restapi/api_v1/server/operations/models/get_logs_responses.go b/di/restapi/api_v1/server/operations/models/get_logs_responses.go new file mode 100644 index 0000000..1003bc9 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/get_logs_responses.go @@ -0,0 +1,145 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// GetLogsOKCode is the HTTP code returned for type GetLogsOK +const GetLogsOKCode int = 200 + +/*GetLogsOK Dump of the training log to-date + +swagger:response getLogsOK +*/ +type GetLogsOK struct { + + /* + In: Body + */ + Payload io.ReadCloser `json:"body,omitempty"` +} + +// NewGetLogsOK creates GetLogsOK with default headers values +func NewGetLogsOK() *GetLogsOK { + + return &GetLogsOK{} +} + +// WithPayload adds the payload to the get logs o k response +func (o *GetLogsOK) WithPayload(payload io.ReadCloser) *GetLogsOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get logs o k response +func (o *GetLogsOK) SetPayload(payload io.ReadCloser) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetLogsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// GetLogsUnauthorizedCode is the HTTP code returned for type GetLogsUnauthorized +const GetLogsUnauthorizedCode int = 401 + +/*GetLogsUnauthorized Unauthorized + +swagger:response getLogsUnauthorized +*/ +type GetLogsUnauthorized struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewGetLogsUnauthorized creates GetLogsUnauthorized with default headers values +func NewGetLogsUnauthorized() *GetLogsUnauthorized { + + return &GetLogsUnauthorized{} +} + +// WithPayload adds the payload to the get logs unauthorized response +func (o *GetLogsUnauthorized) WithPayload(payload *restmodels.Error) *GetLogsUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get logs unauthorized response +func (o *GetLogsUnauthorized) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetLogsUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetLogsNotFoundCode is the HTTP code returned for type GetLogsNotFound +const GetLogsNotFoundCode int = 404 + +/*GetLogsNotFound The model cannot be found. + +swagger:response getLogsNotFound +*/ +type GetLogsNotFound struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewGetLogsNotFound creates GetLogsNotFound with default headers values +func NewGetLogsNotFound() *GetLogsNotFound { + + return &GetLogsNotFound{} +} + +// WithPayload adds the payload to the get logs not found response +func (o *GetLogsNotFound) WithPayload(payload *restmodels.Error) *GetLogsNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get logs not found response +func (o *GetLogsNotFound) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetLogsNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/models/get_logs_urlbuilder.go b/di/restapi/api_v1/server/operations/models/get_logs_urlbuilder.go new file mode 100644 index 0000000..2477e94 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/get_logs_urlbuilder.go @@ -0,0 +1,130 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// GetLogsURL generates an URL for the get logs operation +type GetLogsURL struct { + ModelID string + + Follow *bool + SinceTime *string + Version string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetLogsURL) WithBasePath(bp string) *GetLogsURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetLogsURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetLogsURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/models/{model_id}/logs" + + modelID := o.ModelID + if modelID != "" { + _path = strings.Replace(_path, "{model_id}", modelID, -1) + } else { + return nil, errors.New("modelId is required on GetLogsURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var followQ string + if o.Follow != nil { + followQ = swag.FormatBool(*o.Follow) + } + if followQ != "" { + qs.Set("follow", followQ) + } + + var sinceTimeQ string + if o.SinceTime != nil { + sinceTimeQ = *o.SinceTime + } + if sinceTimeQ != "" { + qs.Set("since_time", sinceTimeQ) + } + + versionQ := o.Version + if versionQ != "" { + qs.Set("version", versionQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetLogsURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetLogsURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetLogsURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetLogsURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetLogsURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetLogsURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/operations/models/get_model.go b/di/restapi/api_v1/server/operations/models/get_model.go new file mode 100644 index 0000000..8a49fae --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/get_model.go @@ -0,0 +1,61 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// GetModelHandlerFunc turns a function with the right signature into a get model handler +type GetModelHandlerFunc func(GetModelParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetModelHandlerFunc) Handle(params GetModelParams) middleware.Responder { + return fn(params) +} + +// GetModelHandler interface for that can handle valid get model params +type GetModelHandler interface { + Handle(GetModelParams) middleware.Responder +} + +// NewGetModel creates a new http.Handler for the get model operation +func NewGetModel(ctx *middleware.Context, handler GetModelHandler) *GetModel { + return &GetModel{Context: ctx, Handler: handler} +} + +/*GetModel swagger:route GET /di/v1/models/{model_id} Models getModel + +Get detailed information about a model. + +Get detailed information about a model such as training status. + + +*/ +type GetModel struct { + Context *middleware.Context + Handler GetModelHandler +} + +func (o *GetModel) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewGetModelParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/models/get_model_parameters.go b/di/restapi/api_v1/server/operations/models/get_model_parameters.go new file mode 100644 index 0000000..290f3b1 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/get_model_parameters.go @@ -0,0 +1,117 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetModelParams creates a new GetModelParams object +// with the default values initialized. +func NewGetModelParams() GetModelParams { + + var ( + // initialize parameters with default values + + versionDefault = string("2017-02-13") + ) + + return GetModelParams{ + Version: versionDefault, + } +} + +// GetModelParams contains all the bound params for the get model operation +// typically these are obtained from a http.Request +// +// swagger:parameters getModel +type GetModelParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*The id of the model. + Required: true + In: path + */ + ModelID string + /*The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + Required: true + In: query + Default: "2017-02-13" + */ + Version string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetModelParams() beforehand. +func (o *GetModelParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rModelID, rhkModelID, _ := route.Params.GetOK("model_id") + if err := o.bindModelID(rModelID, rhkModelID, route.Formats); err != nil { + res = append(res, err) + } + + qVersion, qhkVersion, _ := qs.GetOK("version") + if err := o.bindVersion(qVersion, qhkVersion, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindModelID binds and validates parameter ModelID from path. +func (o *GetModelParams) bindModelID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + + o.ModelID = raw + + return nil +} + +// bindVersion binds and validates parameter Version from query. +func (o *GetModelParams) bindVersion(rawData []string, hasKey bool, formats strfmt.Registry) error { + if !hasKey { + return errors.Required("version", "query") + } + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // AllowEmptyValue: false + if err := validate.RequiredString("version", "query", raw); err != nil { + return err + } + + o.Version = raw + + return nil +} diff --git a/di/restapi/api_v1/server/operations/models/get_model_responses.go b/di/restapi/api_v1/server/operations/models/get_model_responses.go new file mode 100644 index 0000000..d4eb62f --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/get_model_responses.go @@ -0,0 +1,146 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// GetModelOKCode is the HTTP code returned for type GetModelOK +const GetModelOKCode int = 200 + +/*GetModelOK Detailed model and training information. + +swagger:response getModelOK +*/ +type GetModelOK struct { + + /* + In: Body + */ + Payload *restmodels.Model `json:"body,omitempty"` +} + +// NewGetModelOK creates GetModelOK with default headers values +func NewGetModelOK() *GetModelOK { + + return &GetModelOK{} +} + +// WithPayload adds the payload to the get model o k response +func (o *GetModelOK) WithPayload(payload *restmodels.Model) *GetModelOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get model o k response +func (o *GetModelOK) SetPayload(payload *restmodels.Model) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetModelOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetModelUnauthorizedCode is the HTTP code returned for type GetModelUnauthorized +const GetModelUnauthorizedCode int = 401 + +/*GetModelUnauthorized Unauthorized + +swagger:response getModelUnauthorized +*/ +type GetModelUnauthorized struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewGetModelUnauthorized creates GetModelUnauthorized with default headers values +func NewGetModelUnauthorized() *GetModelUnauthorized { + + return &GetModelUnauthorized{} +} + +// WithPayload adds the payload to the get model unauthorized response +func (o *GetModelUnauthorized) WithPayload(payload *restmodels.Error) *GetModelUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get model unauthorized response +func (o *GetModelUnauthorized) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetModelUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetModelNotFoundCode is the HTTP code returned for type GetModelNotFound +const GetModelNotFoundCode int = 404 + +/*GetModelNotFound Model with the given ID not found. + +swagger:response getModelNotFound +*/ +type GetModelNotFound struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewGetModelNotFound creates GetModelNotFound with default headers values +func NewGetModelNotFound() *GetModelNotFound { + + return &GetModelNotFound{} +} + +// WithPayload adds the payload to the get model not found response +func (o *GetModelNotFound) WithPayload(payload *restmodels.Error) *GetModelNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get model not found response +func (o *GetModelNotFound) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetModelNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/models/get_model_urlbuilder.go b/di/restapi/api_v1/server/operations/models/get_model_urlbuilder.go new file mode 100644 index 0000000..9531a58 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/get_model_urlbuilder.go @@ -0,0 +1,110 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// GetModelURL generates an URL for the get model operation +type GetModelURL struct { + ModelID string + + Version string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetModelURL) WithBasePath(bp string) *GetModelURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetModelURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetModelURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/models/{model_id}" + + modelID := o.ModelID + if modelID != "" { + _path = strings.Replace(_path, "{model_id}", modelID, -1) + } else { + return nil, errors.New("modelId is required on GetModelURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + versionQ := o.Version + if versionQ != "" { + qs.Set("version", versionQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetModelURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetModelURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetModelURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetModelURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetModelURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetModelURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/operations/models/list_models.go b/di/restapi/api_v1/server/operations/models/list_models.go new file mode 100644 index 0000000..08b6b16 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/list_models.go @@ -0,0 +1,61 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// ListModelsHandlerFunc turns a function with the right signature into a list models handler +type ListModelsHandlerFunc func(ListModelsParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn ListModelsHandlerFunc) Handle(params ListModelsParams) middleware.Responder { + return fn(params) +} + +// ListModelsHandler interface for that can handle valid list models params +type ListModelsHandler interface { + Handle(ListModelsParams) middleware.Responder +} + +// NewListModels creates a new http.Handler for the list models operation +func NewListModels(ctx *middleware.Context, handler ListModelsHandler) *ListModels { + return &ListModels{Context: ctx, Handler: handler} +} + +/*ListModels swagger:route GET /di/v1/models Models listModels + +Get a list of available deep learning models. + +Get a list of all available deep learning models and their configuration that a user can see. + + +*/ +type ListModels struct { + Context *middleware.Context + Handler ListModelsHandler +} + +func (o *ListModels) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewListModelsParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/models/list_models_parameters.go b/di/restapi/api_v1/server/operations/models/list_models_parameters.go new file mode 100644 index 0000000..b4a5064 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/list_models_parameters.go @@ -0,0 +1,316 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewListModelsParams creates a new ListModelsParams object +// with the default values initialized. +func NewListModelsParams() ListModelsParams { + + var ( + // initialize parameters with default values + + clusterNameDefault = string("") + expIDDefault = string("") + expRunIDDefault = string("") + namespaceDefault = string("") + pageDefault = string("") + sizeDefault = string("") + useridDefault = string("") + versionDefault = string("2017-02-13") + ) + + return ListModelsParams{ + ClusterName: &clusterNameDefault, + + ExpID: &expIDDefault, + + ExpRunID: &expRunIDDefault, + + Namespace: &namespaceDefault, + + Page: &pageDefault, + + Size: &sizeDefault, + + Userid: &useridDefault, + + Version: versionDefault, + } +} + +// ListModelsParams contains all the bound params for the list models operation +// typically these are obtained from a http.Request +// +// swagger:parameters listModels +type ListModelsParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*entity clusterName + In: query + Default: "" + */ + ClusterName *string + /*experiment's id. + In: query + Default: "" + */ + ExpID *string + /*experiment run's id. + In: query + Default: "" + */ + ExpRunID *string + /*job's namespace. + In: query + Default: "" + */ + Namespace *string + /*page number. + In: query + Default: "" + */ + Page *string + /*entity number per page. + In: query + Default: "" + */ + Size *string + /*owner's userid. + In: query + Default: "" + */ + Userid *string + /*The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + Required: true + In: query + Default: "2017-02-13" + */ + Version string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewListModelsParams() beforehand. +func (o *ListModelsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + qClusterName, qhkClusterName, _ := qs.GetOK("clusterName") + if err := o.bindClusterName(qClusterName, qhkClusterName, route.Formats); err != nil { + res = append(res, err) + } + + qExpID, qhkExpID, _ := qs.GetOK("exp_id") + if err := o.bindExpID(qExpID, qhkExpID, route.Formats); err != nil { + res = append(res, err) + } + + qExpRunID, qhkExpRunID, _ := qs.GetOK("exp_run_id") + if err := o.bindExpRunID(qExpRunID, qhkExpRunID, route.Formats); err != nil { + res = append(res, err) + } + + qNamespace, qhkNamespace, _ := qs.GetOK("namespace") + if err := o.bindNamespace(qNamespace, qhkNamespace, route.Formats); err != nil { + res = append(res, err) + } + + qPage, qhkPage, _ := qs.GetOK("page") + if err := o.bindPage(qPage, qhkPage, route.Formats); err != nil { + res = append(res, err) + } + + qSize, qhkSize, _ := qs.GetOK("size") + if err := o.bindSize(qSize, qhkSize, route.Formats); err != nil { + res = append(res, err) + } + + qUserid, qhkUserid, _ := qs.GetOK("userid") + if err := o.bindUserid(qUserid, qhkUserid, route.Formats); err != nil { + res = append(res, err) + } + + qVersion, qhkVersion, _ := qs.GetOK("version") + if err := o.bindVersion(qVersion, qhkVersion, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindClusterName binds and validates parameter ClusterName from query. +func (o *ListModelsParams) bindClusterName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewListModelsParams() + return nil + } + + o.ClusterName = &raw + + return nil +} + +// bindExpID binds and validates parameter ExpID from query. +func (o *ListModelsParams) bindExpID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewListModelsParams() + return nil + } + + o.ExpID = &raw + + return nil +} + +// bindExpRunID binds and validates parameter ExpRunID from query. +func (o *ListModelsParams) bindExpRunID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewListModelsParams() + return nil + } + + o.ExpRunID = &raw + + return nil +} + +// bindNamespace binds and validates parameter Namespace from query. +func (o *ListModelsParams) bindNamespace(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewListModelsParams() + return nil + } + + o.Namespace = &raw + + return nil +} + +// bindPage binds and validates parameter Page from query. +func (o *ListModelsParams) bindPage(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewListModelsParams() + return nil + } + + o.Page = &raw + + return nil +} + +// bindSize binds and validates parameter Size from query. +func (o *ListModelsParams) bindSize(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewListModelsParams() + return nil + } + + o.Size = &raw + + return nil +} + +// bindUserid binds and validates parameter Userid from query. +func (o *ListModelsParams) bindUserid(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewListModelsParams() + return nil + } + + o.Userid = &raw + + return nil +} + +// bindVersion binds and validates parameter Version from query. +func (o *ListModelsParams) bindVersion(rawData []string, hasKey bool, formats strfmt.Registry) error { + if !hasKey { + return errors.Required("version", "query") + } + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // AllowEmptyValue: false + if err := validate.RequiredString("version", "query", raw); err != nil { + return err + } + + o.Version = raw + + return nil +} diff --git a/di/restapi/api_v1/server/operations/models/list_models_responses.go b/di/restapi/api_v1/server/operations/models/list_models_responses.go new file mode 100644 index 0000000..cae2add --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/list_models_responses.go @@ -0,0 +1,102 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// ListModelsOKCode is the HTTP code returned for type ListModelsOK +const ListModelsOKCode int = 200 + +/*ListModelsOK List of deep learning models. + +swagger:response listModelsOK +*/ +type ListModelsOK struct { + + /* + In: Body + */ + Payload *restmodels.ModelList `json:"body,omitempty"` +} + +// NewListModelsOK creates ListModelsOK with default headers values +func NewListModelsOK() *ListModelsOK { + + return &ListModelsOK{} +} + +// WithPayload adds the payload to the list models o k response +func (o *ListModelsOK) WithPayload(payload *restmodels.ModelList) *ListModelsOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the list models o k response +func (o *ListModelsOK) SetPayload(payload *restmodels.ModelList) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *ListModelsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// ListModelsUnauthorizedCode is the HTTP code returned for type ListModelsUnauthorized +const ListModelsUnauthorizedCode int = 401 + +/*ListModelsUnauthorized Unauthorized + +swagger:response listModelsUnauthorized +*/ +type ListModelsUnauthorized struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewListModelsUnauthorized creates ListModelsUnauthorized with default headers values +func NewListModelsUnauthorized() *ListModelsUnauthorized { + + return &ListModelsUnauthorized{} +} + +// WithPayload adds the payload to the list models unauthorized response +func (o *ListModelsUnauthorized) WithPayload(payload *restmodels.Error) *ListModelsUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the list models unauthorized response +func (o *ListModelsUnauthorized) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *ListModelsUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/models/list_models_urlbuilder.go b/di/restapi/api_v1/server/operations/models/list_models_urlbuilder.go new file mode 100644 index 0000000..362252a --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/list_models_urlbuilder.go @@ -0,0 +1,163 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// ListModelsURL generates an URL for the list models operation +type ListModelsURL struct { + ClusterName *string + ExpID *string + ExpRunID *string + Namespace *string + Page *string + Size *string + Userid *string + Version string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *ListModelsURL) WithBasePath(bp string) *ListModelsURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *ListModelsURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *ListModelsURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/models" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var clusterNameQ string + if o.ClusterName != nil { + clusterNameQ = *o.ClusterName + } + if clusterNameQ != "" { + qs.Set("clusterName", clusterNameQ) + } + + var expIDQ string + if o.ExpID != nil { + expIDQ = *o.ExpID + } + if expIDQ != "" { + qs.Set("exp_id", expIDQ) + } + + var expRunIDQ string + if o.ExpRunID != nil { + expRunIDQ = *o.ExpRunID + } + if expRunIDQ != "" { + qs.Set("exp_run_id", expRunIDQ) + } + + var namespaceQ string + if o.Namespace != nil { + namespaceQ = *o.Namespace + } + if namespaceQ != "" { + qs.Set("namespace", namespaceQ) + } + + var pageQ string + if o.Page != nil { + pageQ = *o.Page + } + if pageQ != "" { + qs.Set("page", pageQ) + } + + var sizeQ string + if o.Size != nil { + sizeQ = *o.Size + } + if sizeQ != "" { + qs.Set("size", sizeQ) + } + + var useridQ string + if o.Userid != nil { + useridQ = *o.Userid + } + if useridQ != "" { + qs.Set("userid", useridQ) + } + + versionQ := o.Version + if versionQ != "" { + qs.Set("version", versionQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *ListModelsURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *ListModelsURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *ListModelsURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on ListModelsURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on ListModelsURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *ListModelsURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/operations/models/patch_model.go b/di/restapi/api_v1/server/operations/models/patch_model.go new file mode 100644 index 0000000..79b1f40 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/patch_model.go @@ -0,0 +1,60 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// PatchModelHandlerFunc turns a function with the right signature into a patch model handler +type PatchModelHandlerFunc func(PatchModelParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PatchModelHandlerFunc) Handle(params PatchModelParams) middleware.Responder { + return fn(params) +} + +// PatchModelHandler interface for that can handle valid patch model params +type PatchModelHandler interface { + Handle(PatchModelParams) middleware.Responder +} + +// NewPatchModel creates a new http.Handler for the patch model operation +func NewPatchModel(ctx *middleware.Context, handler PatchModelHandler) *PatchModel { + return &PatchModel{Context: ctx, Handler: handler} +} + +/*PatchModel swagger:route PATCH /di/v1/models/{model_id} Models patchModel + +Changes the status of the training progress. + +Changes the status of the training progress to the given `status` value (currently `halt` only). Halt means the training will be stopped and the last snapshot will be stored and can be retrieved. + +*/ +type PatchModel struct { + Context *middleware.Context + Handler PatchModelHandler +} + +func (o *PatchModel) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewPatchModelParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/models/patch_model_parameters.go b/di/restapi/api_v1/server/operations/models/patch_model_parameters.go new file mode 100644 index 0000000..9801d79 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/patch_model_parameters.go @@ -0,0 +1,147 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + strfmt "github.com/go-openapi/strfmt" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// NewPatchModelParams creates a new PatchModelParams object +// with the default values initialized. +func NewPatchModelParams() PatchModelParams { + + var ( + // initialize parameters with default values + + versionDefault = string("2017-02-13") + ) + + return PatchModelParams{ + Version: versionDefault, + } +} + +// PatchModelParams contains all the bound params for the patch model operation +// typically these are obtained from a http.Request +// +// swagger:parameters patchModel +type PatchModelParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*The id of the model. + Required: true + In: path + */ + ModelID string + /*Currently accepts "halt" as the only valid value. + Required: true + In: body + */ + Payload *restmodels.TrainingUpdate + /*The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + Required: true + In: query + Default: "2017-02-13" + */ + Version string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPatchModelParams() beforehand. +func (o *PatchModelParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rModelID, rhkModelID, _ := route.Params.GetOK("model_id") + if err := o.bindModelID(rModelID, rhkModelID, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body restmodels.TrainingUpdate + if err := route.Consumer.Consume(r.Body, &body); err != nil { + if err == io.EOF { + res = append(res, errors.Required("payload", "body")) + } else { + res = append(res, errors.NewParseError("payload", "body", "", err)) + } + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Payload = &body + } + } + } else { + res = append(res, errors.Required("payload", "body")) + } + qVersion, qhkVersion, _ := qs.GetOK("version") + if err := o.bindVersion(qVersion, qhkVersion, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindModelID binds and validates parameter ModelID from path. +func (o *PatchModelParams) bindModelID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + + o.ModelID = raw + + return nil +} + +// bindVersion binds and validates parameter Version from query. +func (o *PatchModelParams) bindVersion(rawData []string, hasKey bool, formats strfmt.Registry) error { + if !hasKey { + return errors.Required("version", "query") + } + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // AllowEmptyValue: false + if err := validate.RequiredString("version", "query", raw); err != nil { + return err + } + + o.Version = raw + + return nil +} diff --git a/di/restapi/api_v1/server/operations/models/patch_model_responses.go b/di/restapi/api_v1/server/operations/models/patch_model_responses.go new file mode 100644 index 0000000..81f61c4 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/patch_model_responses.go @@ -0,0 +1,190 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// PatchModelAcceptedCode is the HTTP code returned for type PatchModelAccepted +const PatchModelAcceptedCode int = 202 + +/*PatchModelAccepted Training successfully halted. + +swagger:response patchModelAccepted +*/ +type PatchModelAccepted struct { + + /* + In: Body + */ + Payload *restmodels.BasicModel `json:"body,omitempty"` +} + +// NewPatchModelAccepted creates PatchModelAccepted with default headers values +func NewPatchModelAccepted() *PatchModelAccepted { + + return &PatchModelAccepted{} +} + +// WithPayload adds the payload to the patch model accepted response +func (o *PatchModelAccepted) WithPayload(payload *restmodels.BasicModel) *PatchModelAccepted { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the patch model accepted response +func (o *PatchModelAccepted) SetPayload(payload *restmodels.BasicModel) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PatchModelAccepted) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(202) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PatchModelBadRequestCode is the HTTP code returned for type PatchModelBadRequest +const PatchModelBadRequestCode int = 400 + +/*PatchModelBadRequest Incorrect status specified. + +swagger:response patchModelBadRequest +*/ +type PatchModelBadRequest struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewPatchModelBadRequest creates PatchModelBadRequest with default headers values +func NewPatchModelBadRequest() *PatchModelBadRequest { + + return &PatchModelBadRequest{} +} + +// WithPayload adds the payload to the patch model bad request response +func (o *PatchModelBadRequest) WithPayload(payload *restmodels.Error) *PatchModelBadRequest { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the patch model bad request response +func (o *PatchModelBadRequest) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PatchModelBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(400) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PatchModelUnauthorizedCode is the HTTP code returned for type PatchModelUnauthorized +const PatchModelUnauthorizedCode int = 401 + +/*PatchModelUnauthorized Unauthorized + +swagger:response patchModelUnauthorized +*/ +type PatchModelUnauthorized struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewPatchModelUnauthorized creates PatchModelUnauthorized with default headers values +func NewPatchModelUnauthorized() *PatchModelUnauthorized { + + return &PatchModelUnauthorized{} +} + +// WithPayload adds the payload to the patch model unauthorized response +func (o *PatchModelUnauthorized) WithPayload(payload *restmodels.Error) *PatchModelUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the patch model unauthorized response +func (o *PatchModelUnauthorized) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PatchModelUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PatchModelNotFoundCode is the HTTP code returned for type PatchModelNotFound +const PatchModelNotFoundCode int = 404 + +/*PatchModelNotFound Model with the given ID not found. + +swagger:response patchModelNotFound +*/ +type PatchModelNotFound struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewPatchModelNotFound creates PatchModelNotFound with default headers values +func NewPatchModelNotFound() *PatchModelNotFound { + + return &PatchModelNotFound{} +} + +// WithPayload adds the payload to the patch model not found response +func (o *PatchModelNotFound) WithPayload(payload *restmodels.Error) *PatchModelNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the patch model not found response +func (o *PatchModelNotFound) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PatchModelNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/models/patch_model_urlbuilder.go b/di/restapi/api_v1/server/operations/models/patch_model_urlbuilder.go new file mode 100644 index 0000000..b0caef9 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/patch_model_urlbuilder.go @@ -0,0 +1,110 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PatchModelURL generates an URL for the patch model operation +type PatchModelURL struct { + ModelID string + + Version string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PatchModelURL) WithBasePath(bp string) *PatchModelURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PatchModelURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PatchModelURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/models/{model_id}" + + modelID := o.ModelID + if modelID != "" { + _path = strings.Replace(_path, "{model_id}", modelID, -1) + } else { + return nil, errors.New("modelId is required on PatchModelURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + versionQ := o.Version + if versionQ != "" { + qs.Set("version", versionQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PatchModelURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PatchModelURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PatchModelURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PatchModelURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PatchModelURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PatchModelURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/operations/models/post_model.go b/di/restapi/api_v1/server/operations/models/post_model.go new file mode 100644 index 0000000..d59ffa4 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/post_model.go @@ -0,0 +1,61 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// PostModelHandlerFunc turns a function with the right signature into a post model handler +type PostModelHandlerFunc func(PostModelParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PostModelHandlerFunc) Handle(params PostModelParams) middleware.Responder { + return fn(params) +} + +// PostModelHandler interface for that can handle valid post model params +type PostModelHandler interface { + Handle(PostModelParams) middleware.Responder +} + +// NewPostModel creates a new http.Handler for the post model operation +func NewPostModel(ctx *middleware.Context, handler PostModelHandler) *PostModel { + return &PostModel{Context: ctx, Handler: handler} +} + +/*PostModel swagger:route POST /di/v1/models Models postModel + +Trains a new deep learning model. + +Trains a deep neural network written in a DL framework supported by the DLaaS platform (such as Caffe, Tensorflow, etc.). The model code has to be uploaded and configuration parameters have to be provided. + + +*/ +type PostModel struct { + Context *middleware.Context + Handler PostModelHandler +} + +func (o *PostModel) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewPostModelParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/models/post_model_parameters.go b/di/restapi/api_v1/server/operations/models/post_model_parameters.go new file mode 100644 index 0000000..76f4d75 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/post_model_parameters.go @@ -0,0 +1,146 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "mime/multipart" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewPostModelParams creates a new PostModelParams object +// with the default values initialized. +func NewPostModelParams() PostModelParams { + + var ( + // initialize parameters with default values + + versionDefault = string("2017-02-13") + ) + + return PostModelParams{ + Version: versionDefault, + } +} + +// PostModelParams contains all the bound params for the post model operation +// typically these are obtained from a http.Request +// +// swagger:parameters postModel +type PostModelParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*The manifest providing configuration for the deep learning model, the training data and the training execution. + Required: true + In: formData + */ + Manifest io.ReadCloser + /*The deep learning model code as compressed archive (ZIP). + In: formData + */ + ModelDefinition io.ReadCloser + /*The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + Required: true + In: query + Default: "2017-02-13" + */ + Version string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPostModelParams() beforehand. +func (o *PostModelParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + if err := r.ParseMultipartForm(32 << 20); err != nil { + if err != http.ErrNotMultipart { + return errors.New(400, "%v", err) + } else if err := r.ParseForm(); err != nil { + return errors.New(400, "%v", err) + } + } + + manifest, manifestHeader, err := r.FormFile("manifest") + if err != nil { + res = append(res, errors.New(400, "reading file %q failed: %v", "manifest", err)) + } else if err := o.bindManifest(manifest, manifestHeader); err != nil { + // Required: true + res = append(res, err) + } else { + o.Manifest = &runtime.File{Data: manifest, Header: manifestHeader} + } + + modelDefinition, modelDefinitionHeader, err := r.FormFile("model_definition") + if err != nil && err != http.ErrMissingFile { + res = append(res, errors.New(400, "reading file %q failed: %v", "modelDefinition", err)) + } else if err == http.ErrMissingFile { + // no-op for missing but optional file parameter + } else if err := o.bindModelDefinition(modelDefinition, modelDefinitionHeader); err != nil { + res = append(res, err) + } else { + o.ModelDefinition = &runtime.File{Data: modelDefinition, Header: modelDefinitionHeader} + } + + qVersion, qhkVersion, _ := qs.GetOK("version") + if err := o.bindVersion(qVersion, qhkVersion, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindManifest binds file parameter Manifest. +// +// The only supported validations on files are MinLength and MaxLength +func (o *PostModelParams) bindManifest(file multipart.File, header *multipart.FileHeader) error { + return nil +} + +// bindModelDefinition binds file parameter ModelDefinition. +// +// The only supported validations on files are MinLength and MaxLength +func (o *PostModelParams) bindModelDefinition(file multipart.File, header *multipart.FileHeader) error { + return nil +} + +// bindVersion binds and validates parameter Version from query. +func (o *PostModelParams) bindVersion(rawData []string, hasKey bool, formats strfmt.Registry) error { + if !hasKey { + return errors.Required("version", "query") + } + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // AllowEmptyValue: false + if err := validate.RequiredString("version", "query", raw); err != nil { + return err + } + + o.Version = raw + + return nil +} diff --git a/di/restapi/api_v1/server/operations/models/post_model_responses.go b/di/restapi/api_v1/server/operations/models/post_model_responses.go new file mode 100644 index 0000000..96d1959 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/post_model_responses.go @@ -0,0 +1,168 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// PostModelCreatedCode is the HTTP code returned for type PostModelCreated +const PostModelCreatedCode int = 201 + +/*PostModelCreated Deep learning model successfully accepted. + +swagger:response postModelCreated +*/ +type PostModelCreated struct { + /*Location header containing the model id. + + */ + Location string `json:"Location"` + + /* + In: Body + */ + Payload *restmodels.BasicNewModel `json:"body,omitempty"` +} + +// NewPostModelCreated creates PostModelCreated with default headers values +func NewPostModelCreated() *PostModelCreated { + + return &PostModelCreated{} +} + +// WithLocation adds the location to the post model created response +func (o *PostModelCreated) WithLocation(location string) *PostModelCreated { + o.Location = location + return o +} + +// SetLocation sets the location to the post model created response +func (o *PostModelCreated) SetLocation(location string) { + o.Location = location +} + +// WithPayload adds the payload to the post model created response +func (o *PostModelCreated) WithPayload(payload *restmodels.BasicNewModel) *PostModelCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post model created response +func (o *PostModelCreated) SetPayload(payload *restmodels.BasicNewModel) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostModelCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + // response header Location + + location := o.Location + if location != "" { + rw.Header().Set("Location", location) + } + + rw.WriteHeader(201) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostModelBadRequestCode is the HTTP code returned for type PostModelBadRequest +const PostModelBadRequestCode int = 400 + +/*PostModelBadRequest Error in the the model_definition or manifest. + +swagger:response postModelBadRequest +*/ +type PostModelBadRequest struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewPostModelBadRequest creates PostModelBadRequest with default headers values +func NewPostModelBadRequest() *PostModelBadRequest { + + return &PostModelBadRequest{} +} + +// WithPayload adds the payload to the post model bad request response +func (o *PostModelBadRequest) WithPayload(payload *restmodels.Error) *PostModelBadRequest { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post model bad request response +func (o *PostModelBadRequest) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostModelBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(400) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostModelUnauthorizedCode is the HTTP code returned for type PostModelUnauthorized +const PostModelUnauthorizedCode int = 401 + +/*PostModelUnauthorized Unauthorized + +swagger:response postModelUnauthorized +*/ +type PostModelUnauthorized struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewPostModelUnauthorized creates PostModelUnauthorized with default headers values +func NewPostModelUnauthorized() *PostModelUnauthorized { + + return &PostModelUnauthorized{} +} + +// WithPayload adds the payload to the post model unauthorized response +func (o *PostModelUnauthorized) WithPayload(payload *restmodels.Error) *PostModelUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post model unauthorized response +func (o *PostModelUnauthorized) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostModelUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/models/post_model_urlbuilder.go b/di/restapi/api_v1/server/operations/models/post_model_urlbuilder.go new file mode 100644 index 0000000..ede4376 --- /dev/null +++ b/di/restapi/api_v1/server/operations/models/post_model_urlbuilder.go @@ -0,0 +1,100 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// PostModelURL generates an URL for the post model operation +type PostModelURL struct { + Version string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostModelURL) WithBasePath(bp string) *PostModelURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostModelURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PostModelURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/models" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + versionQ := o.Version + if versionQ != "" { + qs.Set("version", versionQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PostModelURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PostModelURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PostModelURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PostModelURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PostModelURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PostModelURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/operations/training_data/get_loglines.go b/di/restapi/api_v1/server/operations/training_data/get_loglines.go new file mode 100644 index 0000000..2a92d97 --- /dev/null +++ b/di/restapi/api_v1/server/operations/training_data/get_loglines.go @@ -0,0 +1,58 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package training_data + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// GetLoglinesHandlerFunc turns a function with the right signature into a get loglines handler +type GetLoglinesHandlerFunc func(GetLoglinesParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetLoglinesHandlerFunc) Handle(params GetLoglinesParams) middleware.Responder { + return fn(params) +} + +// GetLoglinesHandler interface for that can handle valid get loglines params +type GetLoglinesHandler interface { + Handle(GetLoglinesParams) middleware.Responder +} + +// NewGetLoglines creates a new http.Handler for the get loglines operation +func NewGetLoglines(ctx *middleware.Context, handler GetLoglinesHandler) *GetLoglines { + return &GetLoglines{Context: ctx, Handler: handler} +} + +/*GetLoglines swagger:route GET /di/v1/logs/{model_id}/loglines TrainingData getLoglines + +Get loglines, based on query + +*/ +type GetLoglines struct { + Context *middleware.Context + Handler GetLoglinesHandler +} + +func (o *GetLoglines) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewGetLoglinesParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/di/restapi/api_v1/server/operations/training_data/get_loglines_parameters.go b/di/restapi/api_v1/server/operations/training_data/get_loglines_parameters.go new file mode 100644 index 0000000..25cdb56 --- /dev/null +++ b/di/restapi/api_v1/server/operations/training_data/get_loglines_parameters.go @@ -0,0 +1,255 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package training_data + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetLoglinesParams creates a new GetLoglinesParams object +// with the default values initialized. +func NewGetLoglinesParams() GetLoglinesParams { + + var ( + // initialize parameters with default values + + searchTypeDefault = string("TERM") + sinceTimeDefault = string("") + versionDefault = string("2017-10-01") + ) + + return GetLoglinesParams{ + SearchType: &searchTypeDefault, + + SinceTime: &sinceTimeDefault, + + Version: &versionDefault, + } +} + +// GetLoglinesParams contains all the bound params for the get loglines operation +// typically these are obtained from a http.Request +// +// swagger:parameters getLoglines +type GetLoglinesParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*The id of the model. + Required: true + In: path + */ + ModelID string + /*Number of lines to output. + In: query + */ + Pagesize *int32 + /*If positive, line number from start, if negative line counting from end + In: query + */ + Pos *int64 + /* + In: query + Default: "TERM" + */ + SearchType *string + /*Time from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will be returned. If this value is a raw integer, it represents the time that the metric occured: representing the number of milliseconds since midnight January 1, 1970. If this value is a negative integer, it represents the number of lines to count backwards. If this value is empty, the logs since the beginning of the job will be returned + In: query + Default: "" + */ + SinceTime *string + /*The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + In: query + Default: "2017-10-01" + */ + Version *string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetLoglinesParams() beforehand. +func (o *GetLoglinesParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rModelID, rhkModelID, _ := route.Params.GetOK("model_id") + if err := o.bindModelID(rModelID, rhkModelID, route.Formats); err != nil { + res = append(res, err) + } + + qPagesize, qhkPagesize, _ := qs.GetOK("pagesize") + if err := o.bindPagesize(qPagesize, qhkPagesize, route.Formats); err != nil { + res = append(res, err) + } + + qPos, qhkPos, _ := qs.GetOK("pos") + if err := o.bindPos(qPos, qhkPos, route.Formats); err != nil { + res = append(res, err) + } + + qSearchType, qhkSearchType, _ := qs.GetOK("searchType") + if err := o.bindSearchType(qSearchType, qhkSearchType, route.Formats); err != nil { + res = append(res, err) + } + + qSinceTime, qhkSinceTime, _ := qs.GetOK("since_time") + if err := o.bindSinceTime(qSinceTime, qhkSinceTime, route.Formats); err != nil { + res = append(res, err) + } + + qVersion, qhkVersion, _ := qs.GetOK("version") + if err := o.bindVersion(qVersion, qhkVersion, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindModelID binds and validates parameter ModelID from path. +func (o *GetLoglinesParams) bindModelID(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + + o.ModelID = raw + + return nil +} + +// bindPagesize binds and validates parameter Pagesize from query. +func (o *GetLoglinesParams) bindPagesize(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + return nil + } + + value, err := swag.ConvertInt32(raw) + if err != nil { + return errors.InvalidType("pagesize", "query", "int32", raw) + } + o.Pagesize = &value + + return nil +} + +// bindPos binds and validates parameter Pos from query. +func (o *GetLoglinesParams) bindPos(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + return nil + } + + value, err := swag.ConvertInt64(raw) + if err != nil { + return errors.InvalidType("pos", "query", "int64", raw) + } + o.Pos = &value + + return nil +} + +// bindSearchType binds and validates parameter SearchType from query. +func (o *GetLoglinesParams) bindSearchType(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetLoglinesParams() + return nil + } + + o.SearchType = &raw + + if err := o.validateSearchType(formats); err != nil { + return err + } + + return nil +} + +// validateSearchType carries on validations for parameter SearchType +func (o *GetLoglinesParams) validateSearchType(formats strfmt.Registry) error { + + if err := validate.Enum("searchType", "query", *o.SearchType, []interface{}{"TERM", "NESTED", "MATCH"}); err != nil { + return err + } + + return nil +} + +// bindSinceTime binds and validates parameter SinceTime from query. +func (o *GetLoglinesParams) bindSinceTime(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetLoglinesParams() + return nil + } + + o.SinceTime = &raw + + return nil +} + +// bindVersion binds and validates parameter Version from query. +func (o *GetLoglinesParams) bindVersion(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetLoglinesParams() + return nil + } + + o.Version = &raw + + return nil +} diff --git a/di/restapi/api_v1/server/operations/training_data/get_loglines_responses.go b/di/restapi/api_v1/server/operations/training_data/get_loglines_responses.go new file mode 100644 index 0000000..ea24ac8 --- /dev/null +++ b/di/restapi/api_v1/server/operations/training_data/get_loglines_responses.go @@ -0,0 +1,102 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package training_data + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + restmodels "webank/DI/restapi/api_v1/restmodels" +) + +// GetLoglinesOKCode is the HTTP code returned for type GetLoglinesOK +const GetLoglinesOKCode int = 200 + +/*GetLoglinesOK (streaming responses) + +swagger:response getLoglinesOK +*/ +type GetLoglinesOK struct { + + /* + In: Body + */ + Payload *restmodels.V1LogLinesList `json:"body,omitempty"` +} + +// NewGetLoglinesOK creates GetLoglinesOK with default headers values +func NewGetLoglinesOK() *GetLoglinesOK { + + return &GetLoglinesOK{} +} + +// WithPayload adds the payload to the get loglines o k response +func (o *GetLoglinesOK) WithPayload(payload *restmodels.V1LogLinesList) *GetLoglinesOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get loglines o k response +func (o *GetLoglinesOK) SetPayload(payload *restmodels.V1LogLinesList) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetLoglinesOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetLoglinesUnauthorizedCode is the HTTP code returned for type GetLoglinesUnauthorized +const GetLoglinesUnauthorizedCode int = 401 + +/*GetLoglinesUnauthorized Unauthorized + +swagger:response getLoglinesUnauthorized +*/ +type GetLoglinesUnauthorized struct { + + /* + In: Body + */ + Payload *restmodels.Error `json:"body,omitempty"` +} + +// NewGetLoglinesUnauthorized creates GetLoglinesUnauthorized with default headers values +func NewGetLoglinesUnauthorized() *GetLoglinesUnauthorized { + + return &GetLoglinesUnauthorized{} +} + +// WithPayload adds the payload to the get loglines unauthorized response +func (o *GetLoglinesUnauthorized) WithPayload(payload *restmodels.Error) *GetLoglinesUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get loglines unauthorized response +func (o *GetLoglinesUnauthorized) SetPayload(payload *restmodels.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetLoglinesUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/di/restapi/api_v1/server/operations/training_data/get_loglines_urlbuilder.go b/di/restapi/api_v1/server/operations/training_data/get_loglines_urlbuilder.go new file mode 100644 index 0000000..1f42db6 --- /dev/null +++ b/di/restapi/api_v1/server/operations/training_data/get_loglines_urlbuilder.go @@ -0,0 +1,151 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package training_data + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// GetLoglinesURL generates an URL for the get loglines operation +type GetLoglinesURL struct { + ModelID string + + Pagesize *int32 + Pos *int64 + SearchType *string + SinceTime *string + Version *string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetLoglinesURL) WithBasePath(bp string) *GetLoglinesURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetLoglinesURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetLoglinesURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/di/v1/logs/{model_id}/loglines" + + modelID := o.ModelID + if modelID != "" { + _path = strings.Replace(_path, "{model_id}", modelID, -1) + } else { + return nil, errors.New("modelId is required on GetLoglinesURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var pagesizeQ string + if o.Pagesize != nil { + pagesizeQ = swag.FormatInt32(*o.Pagesize) + } + if pagesizeQ != "" { + qs.Set("pagesize", pagesizeQ) + } + + var posQ string + if o.Pos != nil { + posQ = swag.FormatInt64(*o.Pos) + } + if posQ != "" { + qs.Set("pos", posQ) + } + + var searchTypeQ string + if o.SearchType != nil { + searchTypeQ = *o.SearchType + } + if searchTypeQ != "" { + qs.Set("searchType", searchTypeQ) + } + + var sinceTimeQ string + if o.SinceTime != nil { + sinceTimeQ = *o.SinceTime + } + if sinceTimeQ != "" { + qs.Set("since_time", sinceTimeQ) + } + + var versionQ string + if o.Version != nil { + versionQ = *o.Version + } + if versionQ != "" { + qs.Set("version", versionQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetLoglinesURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetLoglinesURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetLoglinesURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetLoglinesURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetLoglinesURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetLoglinesURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/di/restapi/api_v1/server/rest_impl/experiment_impl.go b/di/restapi/api_v1/server/rest_impl/experiment_impl.go new file mode 100644 index 0000000..b0d4386 --- /dev/null +++ b/di/restapi/api_v1/server/rest_impl/experiment_impl.go @@ -0,0 +1,54 @@ +/* + * Copyright 2020 WeBank + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package rest_impl + +import ( + "encoding/json" + "net/http" + "webank/DI/commons/logger" + "webank/DI/restapi/api_v1/restmodels" + "webank/DI/restapi/api_v1/server/operations/experiments" + "webank/DI/restapi/service" + + "github.com/go-openapi/runtime/middleware" +) + +var experimentService = service.ExperimentService +var log = logger.GetLogger() + +func CodeUpload(params experiments.CodeUploadParams) middleware.Responder { + operation := "CodeUpload" + log.Info("experimentService") + log.Info(experimentService) + log.Info("File") + log.Info(params.File) + + s3Path, err := experimentService.UploadCode(params.File) + + if err != nil { + log.Error(err.Error()) + return httpResponseHandle(http.StatusInternalServerError, err, operation, nil) + } + res := restmodels.CodeUploadResponse{S3Path: s3Path} + + marshal, err := json.Marshal(&res) + if err != nil { + log.Error("json.Marshal(mp) failed") + return httpResponseHandle(http.StatusInternalServerError, err, operation, nil) + } + return httpResponseHandle(http.StatusOK, err, operation, marshal) + +} \ No newline at end of file diff --git a/di/restapi/api_v1/server/rest_impl/health_impl.go b/di/restapi/api_v1/server/rest_impl/health_impl.go new file mode 100644 index 0000000..0bc6547 --- /dev/null +++ b/di/restapi/api_v1/server/rest_impl/health_impl.go @@ -0,0 +1,25 @@ +/* + * Copyright 2020 WeBank + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rest_impl + +import "net/http" + +// GetHealth returns the health of the service +func GetHealth(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(200) + w.Write([]byte("OK")) +} diff --git a/di/restapi/api_v1/server/rest_impl/logging.go b/di/restapi/api_v1/server/rest_impl/logging.go new file mode 100644 index 0000000..9c1284f --- /dev/null +++ b/di/restapi/api_v1/server/rest_impl/logging.go @@ -0,0 +1,106 @@ +/* + * Copyright 2017-2018 IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package rest_impl + +import ( + "webank/DI/commons/logger" + "webank/DI/restapi/api_v1/server/operations" + "webank/DI/restapi/api_v1/server/operations/models" + "webank/DI/restapi/api_v1/server/operations/training_data" + + logr "github.com/sirupsen/logrus" +) + +func logWithPostModelParams(params models.PostModelParams) *logr.Entry { + data := logger.NewDlaaSLogData(logger.LogkeyRestAPIService) + + data[logger.LogkeyUserID] = getUserID(params.HTTPRequest) + return &logr.Entry{Logger: logr.StandardLogger(), Data: data} +} + +func logWithDeleteModelParams(params models.DeleteModelParams) *logr.Entry { + data := logger.NewDlaaSLogData(logger.LogkeyRestAPIService) + + data[logger.LogkeyUserID] = getUserID(params.HTTPRequest) + data[logger.LogkeyTrainingID] = params.ModelID + + return &logr.Entry{Logger: logr.StandardLogger(), Data: data} +} + +func logWithGetModelParams(params models.GetModelParams) *logr.Entry { + data := logger.NewDlaaSLogData(logger.LogkeyRestAPIService) + + data[logger.LogkeyUserID] = getUserID(params.HTTPRequest) + data[logger.LogkeyTrainingID] = params.ModelID + + return &logr.Entry{Logger: logr.StandardLogger(), Data: data} +} + +func logWithDownloadModelDefinitionParams(params models.DownloadModelDefinitionParams) *logr.Entry { + data := logger.NewDlaaSLogData(logger.LogkeyRestAPIService) + + data[logger.LogkeyUserID] = getUserID(params.HTTPRequest) + data[logger.LogkeyTrainingID] = params.ModelID + + return &logr.Entry{Logger: logr.StandardLogger(), Data: data} +} + +func logWithDownloadTrainedModelParams(params models.DownloadTrainedModelParams) *logr.Entry { + data := logger.NewDlaaSLogData(logger.LogkeyRestAPIService) + + data[logger.LogkeyUserID] = getUserID(params.HTTPRequest) + data[logger.LogkeyTrainingID] = params.ModelID + + return &logr.Entry{Logger: logr.StandardLogger(), Data: data} +} + +func logWithLoglinesParams(params training_data.GetLoglinesParams) *logr.Entry { + data := logger.NewDlaaSLogData(logger.LogkeyRestAPIService) + + data[logger.LogkeyUserID] = getUserID(params.HTTPRequest) + data[logger.LogkeyTrainingID] = params.ModelID + + return &logr.Entry{Logger: logr.StandardLogger(), Data: data} +} + +func logWithGetLogsParams(params models.GetLogsParams) *logr.Entry { + data := logger.NewDlaaSLogData(logger.LogkeyRestAPIService) + data[logger.LogkeyTrainingID] = params.ModelID + data[logger.LogkeyUserID] = getUserID(params.HTTPRequest) + + return &logr.Entry{Logger: logr.StandardLogger(), Data: data} +} + +func logWithGetListModelsParams(params models.ListModelsParams) *logr.Entry { + data := logger.NewDlaaSLogData(logger.LogkeyRestAPIService) + data[logger.LogkeyUserID] = getUserID(params.HTTPRequest) + + return &logr.Entry{Logger: logr.StandardLogger(), Data: data} +} + +func logWithUpdateStatusParams(params models.PatchModelParams) *logr.Entry { + data := logger.NewDlaaSLogData(logger.LogkeyRestAPIService) + data[logger.LogkeyTrainingID] = params.ModelID + data[logger.LogkeyUserID] = getUserID(params.HTTPRequest) + data["status"] = params.Payload.Status + return &logr.Entry{Logger: logr.StandardLogger(), Data: data} +} + +func logWithGetDashboards(params operations.GetDashboardsParams) *logr.Entry { + data := logger.NewDlaaSLogData(logger.LogkeyRestAPIService) + data[logger.LogkeyUserID] = getUserID(params.HTTPRequest) + return &logr.Entry{Logger: logr.StandardLogger(), Data: data} +} diff --git a/di/restapi/api_v1/server/rest_impl/manifest.go b/di/restapi/api_v1/server/rest_impl/manifest.go new file mode 100644 index 0000000..fb8d201 --- /dev/null +++ b/di/restapi/api_v1/server/rest_impl/manifest.go @@ -0,0 +1,374 @@ +/* + * Copyright 2017-2018 IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rest_impl + +import ( + "encoding/json" + "fmt" + "net/http" + "regexp" + "strconv" + "strings" + cc "webank/DI/commons/controlcenter/client" + "webank/DI/commons/logger" + "webank/DI/commons/operators/tf-operator/apis/tensorflow/v1alpha1" + "webank/DI/trainer/trainer/grpc_trainer_v2" + + "webank/DI/commons/config" + + "github.com/spf13/viper" + "gopkg.in/yaml.v2" +) + +// ManifestV1 represents a manifest used to define the configurations for a training job +type ManifestV1 struct { + Name string `yaml:"name,omitempty"` + Description string `yaml:"description,omitempty"` + Version string `yaml:"version,omitempty"` + Cpus float64 `yaml:"cpus,omitempty"` + Gpus float64 `yaml:"gpus,omitempty"` + GpuType string `yaml:"gpu_type,omitempty"` + Learners int32 `yaml:"learners,omitempty"` + Memory string `yaml:"memory,omitempty"` + Storage string `yaml:"storage,omitempty"` + DataStores []*dataStoreRef `yaml:"data_stores,omitempty"` + Framework *frameworkV1 `yaml:"framework,omitempty"` + EvaluationMetrics *EMExtractionSpec `yaml:"evaluation_metrics,omitempty"` + Namespace string `yaml:"namespace,omitempty"` + JobAlert map[string][]map[string]string `yaml:"job_alert,omitempty"` + CodeSelector string `yaml:"code_selector,omitempty"` + CodePath string `yaml:"code_path,omitempty"` + JobType string `yaml:"job_type,omitempty"` + ExpName string `yaml:"exec_type,omitempty"` + ExpRunId int64 `yaml:"exp_run_id,omitempty"` + FileName string `yaml:"fileName,omitempty"` + PSs string `yaml:"pss,omitempty"` + PSCPU string `yaml:"ps_cpu,omitempty"` + PSImage string `yaml:"ps_image,omitempty"` + PSMemory string `yaml:"ps_memory,omitempty"` + TFosRequest *v1alpha1.TFosRequest `yaml:"tfos_request,omitempty"` + DssTaskId int64 `yaml:"dss_task_id,omitempty"` +} + +// EMExtractionSpec specifies which log-collector is run, and how the evaluation metrics are extracted. +type EMExtractionSpec struct { + Type string `yaml:"type,omitempty"` + ImageTag string `yaml:"image_tag,omitempty"` + In string `yaml:"in,omitempty"` + LineLookahead int32 `yaml:"line_lookahead,omitempty"` + EventTypes []string `yaml:"eventTypes,omitempty"` + Groups map[string]*EMGroup `yaml:"groups,omitempty"` +} + +// EMGroup is used by the regex_extractor to specify log line matches, and the corresponding +// evaluation metrics. +type EMGroup struct { + Regex string `yaml:"regex,omitempty"` + Meta *EMMeta `yaml:"meta,omitempty"` + Scalars map[string]*Any `yaml:"scalars,omitempty"` + Etimes map[string]*Any `yaml:"etimes,omitempty"` +} + +// Any is used for typed values. +type Any struct { + Type string `yaml:"type,omitempty"` + Value string `yaml:"value,omitempty"` +} + +// EMMeta is used in the EMGroup record to specify the time occurrence of the evaluation metric. +type EMMeta struct { + // Time that the metric occured: representing the number of millisecond since midnight January 1, 1970. + // (ref, for instance $timestamp). Value will be extracted from timestamps + Time string `yaml:"time,omitempty"` +} + +type dataStoreRef struct { + ID string `yaml:"id,omitempty"` + Type string `yaml:"type,omitempty"` + TrainingData *storageContainerV1 `yaml:"training_data,omitempty"` + TrainingResults *storageContainerV1 `yaml:"training_results,omitempty"` + // FIXME MLSS Change: v_1.5.1 added_de + TrainingWorkspace *storageContainerV1 `yaml:"training_workspace,omitempty"` + Connection map[string]string `yaml:"connection,omitempty"` +} + +type frameworkV1 struct { + Name string `yaml:"name,omitempty"` + Version string `yaml:"version,omitempty"` + ImageTag string `yaml:"image_tag,omitempty"` + Command string `yaml:"command,omitempty"` +} + +type storageContainerV1 struct { + Container string `yaml:"container,omitempty"` +} + +// LoadManifestV1 constructs a manifest object from a byte array +func LoadManifestV1(data []byte) (*ManifestV1, error) { + t := &ManifestV1{} + err := yaml.Unmarshal(data, &t) + if err != nil { + return nil, err + } + return t, nil +} + +// WriteManifestV1 writes a manifest object to a byte array +func WriteManifestV1(t *ManifestV1) ([]byte, error) { + data, err := yaml.Marshal(t) + if err != nil { + return nil, err + } + return data, nil +} + +func validateEvaluationMetricsSpec(m *ManifestV1) error { + if m.EvaluationMetrics != nil { + // TODO: implement evaluation metrics spec validation? + } + return nil +} + + +func marshalToTrainerEvaluationMetricsSpec(em *EMExtractionSpec) *grpc_trainer_v2.EMExtractionSpec { + groups := make(map[string]*grpc_trainer_v2.EMGroup) + + for key, emGroup := range em.Groups { + values := make(map[string]*grpc_trainer_v2.EMAny) + + for scalerKey, typedValue := range emGroup.Scalars { + marshaledValue := &grpc_trainer_v2.EMAny{Type: typedValue.Type, Value: typedValue.Value} + values[scalerKey] = marshaledValue + } + etimes := make(map[string]*grpc_trainer_v2.EMAny) + for etimeKey, typedValue := range emGroup.Etimes { + marshaledValue := &grpc_trainer_v2.EMAny{Type: typedValue.Type, Value: typedValue.Value} + etimes[etimeKey] = marshaledValue + } + group := &grpc_trainer_v2.EMGroup{ + Regex: emGroup.Regex, + Meta: &grpc_trainer_v2.EMMeta{ + Time: emGroup.Meta.Time, + }, + Values: values, + Etimes: etimes, + } + groups[key] = group + } + + return &grpc_trainer_v2.EMExtractionSpec{ + Type: em.Type, + ImageTag: em.ImageTag, + In: em.In, + LineLookahead: em.LineLookahead, + EventTypes: em.EventTypes, + Groups: groups, + } +} + +// manifest2TrainingRequest converts the existing manifest to a training request for the trainer microservice. +func manifest2TrainingRequest(m *ManifestV1, modelDefinition []byte, http *http.Request, + logr *logger.LocLoggingEntry, dataPath string) (*grpc_trainer_v2.CreateRequest, error) { + authToken := http.Header.Get(cc.CcAuthToken) + userId := getUserID(http) + if m.Namespace == "" { + return nil, *new(error) + } + + // FIXME MLSS Change: read cc address from config + //ccClient := cc.GetCcClient("http://controlcenter:7777") + logr.Debugf("debug for ccAddress restApi: %v", viper.GetString(config.CCAddress)) + ccClient := cc.GetCcClient(viper.GetString(config.CCAddress)) + err := ccClient.UserNamespaceCheck(authToken, userId, m.Namespace) + if err != nil { + return nil, err + } + // FIXME MLSS Change: get gid & uid from CC + gid, uid, err := ccClient.GetGUIDFromUserId(authToken, userId) + if err != nil { + return nil, err + } + + if nil != m.DataStores { + path := m.DataStores[0].Connection["path"] + if userId != strings.Split(path[1:], "/")[3] { + groupId := viper.GetString(config.MLSSGroupId) + gid = &groupId + } + } + + logr.Debugf("manifest2TrainingRequest to get gid: %v", gid) + + jobAlert := m.JobAlert + jobString := "" + if nil != jobAlert { + marshal, marErr := json.Marshal(m.JobAlert) + if marErr != nil { + return nil, marErr + } + jobString = string(marshal) + } + + var tFRequest string + if nil != m.TFosRequest { + marshal, marErr := json.Marshal(m.TFosRequest) + if marErr != nil { + return nil, marErr + } + tFRequest = string(marshal) + } + + r := &grpc_trainer_v2.CreateRequest{ + UserId: userId, + ModelDefinition: &grpc_trainer_v2.ModelDefinition{ + Name: m.Name, + Description: m.Description, + Framework: &grpc_trainer_v2.Framework{ + Name: m.Framework.Name, + Version: m.Framework.Version, + ImageTag: m.Framework.ImageTag, + }, + Content: modelDefinition, + }, + Training: &grpc_trainer_v2.Training{ + Command: m.Framework.Command, + InputData: []string{m.DataStores[0].ID + "-input"}, + Profiling: false, + }, + Datastores: []*grpc_trainer_v2.Datastore{ + { + Id: m.DataStores[0].ID + "-input", + Type: m.DataStores[0].Type, + Connection: m.DataStores[0].Connection, + Fields: map[string]string{ + "bucket": m.DataStores[0].TrainingData.Container, + }, + }, + }, + Namespace: m.Namespace, + // FIXME MLSS Change: set gid & uid to training request + Gid: *gid, + Uid: *uid, + // FIXME MLSS Change: added job_alert info + JobAlert: jobString, + CodeSelector: m.CodeSelector, + DataPath: dataPath, + // FIXME MLSS Change: v_1.5.2 added parameters server info + PSs: m.PSs, + PSCpu: m.PSCPU, + PSImage: m.PSImage, + PSMemory: m.PSMemory, + JobType: m.JobType, + TFosRequest: tFRequest, + } + + // FIXME MLSS Change: get alert parms + logr.Infof("manifest, JobAlert connection: %v, type: %v", m.DataStores[0].Connection, m.DataStores[0].Connection["type"]) + logr.Infof("manifest2TrainingRequest, JobType: %v", m.JobType) + logr.Infof("manifest2TrainingRequest, TfosRequest: %v", m.TFosRequest) + + if m.DataStores[0].TrainingResults != nil { + r.Training.OutputData = []string{m.DataStores[0].ID + "-output"} + r.Datastores = append(r.Datastores, &grpc_trainer_v2.Datastore{ + Id: m.DataStores[0].ID + "-output", + Type: m.DataStores[0].Type, + Connection: m.DataStores[0].Connection, + Fields: map[string]string{ + "bucket": m.DataStores[0].TrainingResults.Container, + }, + }) + } + // FIXME MLSS Change: v_1.5.1 get workData when TrainingWork is not null + if m.DataStores[0].TrainingWorkspace != nil { + r.Training.WorkData = []string{m.DataStores[0].ID + "-work"} + r.Datastores = append(r.Datastores, &grpc_trainer_v2.Datastore{ + Id: m.DataStores[0].ID + "-work", + Type: m.DataStores[0].Type, + Connection: m.DataStores[0].Connection, + Fields: map[string]string{ + "codeWork": m.DataStores[0].TrainingWorkspace.Container, + }, + }) + } + + mem, memUnit, err := convertMemoryFromManifest(m.Memory) + if err != nil { + logr.WithError(err).Errorf("Incorrect memory specification in manifest") + } + + storage, storageUnit := float32(0), grpc_trainer_v2.SizeUnit_MB // default to 0 + if m.Storage != "" { + storage, storageUnit, err = convertMemoryFromManifest(m.Storage) + if err != nil { + logr.WithError(err).Errorf("Incorrect storage specification in manifest") + } + } + logr.Debugf("convertMemoryFromManifest reqMem: %v", mem) + r.Training.Resources = &grpc_trainer_v2.ResourceRequirements{ + Gpus: m.Gpus, + GpuType: m.GpuType, + Cpus: m.Cpus, + Memory: mem, + MemoryUnit: memUnit, + Storage: storage, + StorageUnit: storageUnit, + Learners: m.Learners, + // TODO add storage support + } + + if m.EvaluationMetrics != nil { + err = validateEvaluationMetricsSpec(m) + if err != nil { + logr.WithError(err).Errorf("Incorrect evaluation metrics specification in manifest") + } + + r.EvaluationMetrics = marshalToTrainerEvaluationMetricsSpec(m.EvaluationMetrics) + logr.Debugf("EMExtractionSpec ImageTag: %s", r.EvaluationMetrics.ImageTag) + } + + return r, nil +} + +// Converts an incoming memory spec like 4GB or 1024mb into a memory (float64) +// and a unit. +// Rules for conversion: +// 1GB (gigabytes) = 1000MB (megabytes) +// 1Gi (gibibytes) = 1024 Mi (mebibytes) +func convertMemoryFromManifest(memStr string) (float32, grpc_trainer_v2.SizeUnit, error) { + regex, _ := regexp.Compile(`(?i)(?P(\d+)?)\s*(?P(mb|mib|gb|gib|tb|tib)?)`) + match := regex.FindStringSubmatch(memStr) + + // convert to a map + result := make(map[string]string) + for i, name := range regex.SubexpNames() { + if i != 0 && i <= len(match) { + result[name] = match[i] + } + } + mem, err := strconv.ParseFloat(result["memory"], 64) + if err != nil { + return 512, grpc_trainer_v2.SizeUnit_MB, fmt.Errorf("Memory requirements not correctly specified: %s", memStr) + } + unit := strings.ToLower(result["unit"]) + + for k, v := range grpc_trainer_v2.SizeUnit_value { + if strings.ToLower(k) == unit { + return float32(mem), grpc_trainer_v2.SizeUnit(v), nil + } + } + return 512, grpc_trainer_v2.SizeUnit_MB, fmt.Errorf("Memory requirements not correctly specified: %s", memStr) +} diff --git a/di/restapi/api_v1/server/rest_impl/manifest_test.go b/di/restapi/api_v1/server/rest_impl/manifest_test.go new file mode 100644 index 0000000..003a95b --- /dev/null +++ b/di/restapi/api_v1/server/rest_impl/manifest_test.go @@ -0,0 +1,45 @@ +/* + * Copyright 2017-2018 IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rest_impl + +import ( + //"fmt" + "github.com/stretchr/testify/assert" + "io/ioutil" + "testing" + //"webank/DI/restapi" +) + +func TestLoadManifestV1(t *testing.T) { + data, err := ioutil.ReadFile("../../tests/testdata/broken-manifest/manifest.yml") + assert.NoError(t, err) + m, err := LoadManifestV1(data) + assert.Nil(t, m) + assert.Error(t, err) + + data, err = ioutil.ReadFile("../../tests/testdata/caffe-mnist-model/manifest.yml") + assert.NoError(t, err) + m, err = LoadManifestV1(data) + assert.NoError(t, err) + assert.NotNil(t, m) +} +// +//func TestConvertMemoryFromManifest(t *testing.T) { +// +// f, unit, _ := server.convertMemoryFromManifest("256GB") +// fmt.Printf("f:%v , %v ", f, unit.String()) +//} diff --git a/di/restapi/api_v1/server/rest_impl/models_impl.go b/di/restapi/api_v1/server/rest_impl/models_impl.go new file mode 100644 index 0000000..82b1962 --- /dev/null +++ b/di/restapi/api_v1/server/rest_impl/models_impl.go @@ -0,0 +1,2323 @@ +/* + * Copyright 2020 WeBank + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package rest_impl + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "io/ioutil" + "math" + "net/http" + "os" + "strconv" + datasource "webank/DI/commons/datasource/mysql" + "webank/DI/commons/operators/tf-operator/apis/tensorflow/v1alpha1" + "webank/DI/commons/repo" + "webank/DI/jobmonitor/jobmonitor" + "webank/DI/restapi/api_v1/server/operations" + "webank/DI/restapi/service" + "webank/DI/storage/storage/grpc_storage" + + logr "github.com/sirupsen/logrus" + + "github.com/google/uuid" + "github.com/jinzhu/copier" + "github.com/mholt/archiver/v3" + "github.com/modern-go/reflect2" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "gopkg.in/yaml.v2" + + commonModels "webank/DI/commons/models" + "webank/DI/restapi/api_v1/restmodels" + "webank/DI/restapi/api_v1/server/operations/models" + storageClient "webank/DI/storage/client" + trainerClient "webank/DI/trainer/client" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + + "bufio" + "bytes" + "io" + + "webank/DI/commons/logger" + "webank/DI/trainer/trainer/grpc_trainer_v2" + + newWebsocket "github.com/gorilla/websocket" + "golang.org/x/net/websocket" + + stringsUtil "strings" + "time" + + trainingDataClient "webank/DI/metrics/client" + "webank/DI/restapi/api_v1/server/operations/training_data" + + "webank/DI/metrics/service/grpc_training_data_v1" + + cc "webank/DI/commons/controlcenter/client" + + "webank/DI/commons/config" + + "github.com/spf13/viper" +) + +const ( + defaultLogPageSize = 10 + codeFile = "codeFile" + storagePath = "storagePath" + SA = "true" + userSA = "1" + userGA = "1" + userGU = "2" +) + +// postModel posts a model definition and starts the training +func PostModel(params models.PostModelParams) middleware.Responder { + operation := "postModel" + modelFile := params.ModelDefinition + var userID = getUserID(params.HTTPRequest) + // Read MainFest File + logr := logger.LocLogger(logWithPostModelParams(params)) + logr.Debugf("postModel invoked: %v", params.HTTPRequest.Header) + manifestBytes, err := ioutil.ReadAll(params.Manifest) + if err != nil { + logr.Errorf("Cannot read 'manifest' parameter: %s", err.Error()) + return httpResponseHandle(http.StatusUnauthorized, err, operation, []byte("Incorrect parameters")) + } + logr.Debug("Loading Manifest") + manifest, err := LoadManifestV1(manifestBytes) + if err != nil { + logr.WithError(err).Errorf("Parameter 'manifest' contains incorrect YAML") + return httpResponseHandle(http.StatusNotFound, err, operation, []byte("Incorrect manifest")) + } + logr.Info("Loading Manifest: ", manifest.DssTaskId) + var modelDefinition []byte + if modelFile != nil { + modelBytes, err := ioutil.ReadAll(modelFile) + logger.GetLogger().Info("Upload code length: ", len(modelBytes), " to bucket") + var experimentService = service.ExperimentService + reader := bytes.NewReader(modelBytes) + readerCloser := ioutil.NopCloser(reader) + s3Path, err := experimentService.UploadCodeBucket(readerCloser, "di-model") + if err != nil { + logger.GetLogger().Error("UploadCode failed, ", err) + } + if len(s3Path) <= 0 { + logger.GetLogger().Error("UpdateCode failed, s3 path's length is zero") + } + manifest.FileName = "codeFile.zip" + manifest.CodePath = s3Path + params.ModelDefinition = nil + } + // IF Codeath is Not Null, Download Code From Minio + if manifest.CodePath != "" { + modelDefinitionReader, err := codePathToModelDefinition(manifest.CodePath) + params.ModelDefinition = modelDefinitionReader + if err != nil { + logr.Error("Transfer S3 Path to ModelDefinition Byte Error", err.Error()) + return httpResponseHandle(http.StatusBadRequest, err, operation, nil) + } + //log.Info("ModelDefintion is ", modelDefinition) + } + + // Handle TFOS Job ManiFest + // logr.Debugf("postModel, manifest.JobType: %v", manifest.JobType) + // if "tfos" == manifest.JobType { + // err := handleTfosManifest(userID, manifest, logr) + // if err != nil { + // return httpResponseHandle(http.StatusUnauthorized, err, operation, []byte("Incorrect Manifest")) + // } + // } + + // Check Manifest + errForCheckManifest := checkManifest(manifest, logr) + if errForCheckManifest != nil { + logr.Errorf("checkManifest failed: %s", errForCheckManifest.Error()) + return httpResponseHandle(http.StatusNotFound, err, operation, []byte("checkManifest failed: "+errForCheckManifest.Error())) + } + + // Check user match storages + //get first dataStore,if exists + DSs := manifest.DataStores + namespaceFromManifest := manifest.Namespace + dataPath, resultsPath := defineJobPath(DSs, manifest) + logr.Debugf("namespace: %v, dataPath: %v, resultsPath: %v ", namespaceFromManifest, dataPath, resultsPath) + + //check alert params + err = checkAlertParams(manifest, logr) + if err != nil { + logr.Errorf("checkAlertParams failed: %s", err.Error()) + return httpResponseHandle(http.StatusBadRequest, err, operation, []byte("checkAlertParams failed: "+err.Error())) + } + + //Permission Check + ccAddress := viper.GetString(config.CCAddress) + ccClient := cc.GetCcClient(ccAddress) + //Check DataPath,TFOS Job Use HDFS, Not Need to Check Data Path + if manifest.JobType != "tfos" { + err = ccClient.UserStorageCheck(params.HTTPRequest.Header.Get(cc.CcAuthToken), userID, dataPath) + if err != nil { + logr.Errorf("check dataPath failed: %v", err.Error()) + return httpResponseHandle(http.StatusBadRequest, err, operation, []byte("check dataPath failed: ")) + } + } + + //Check ResultsPath + err = ccClient.UserStorageCheck(params.HTTPRequest.Header.Get(cc.CcAuthToken), userID, resultsPath) + if err != nil { + logr.Errorf("check resultsPath failed: %v", err.Error()) + return httpResponseHandle(http.StatusBadRequest, err, operation, []byte("Check ResultsPath Failed "+err.Error())) + + } + + if "tfos" != manifest.JobType { + codeSelector := manifest.CodeSelector + modelDefinitionRes, err := checkForJobParams(manifest, params, codeSelector, logr) + if err != nil { + logr.Errorf("checkForJobParams failed: %v", err.Error()) + return httpResponseHandle(http.StatusBadRequest, err, operation, []byte("Check ResultsPath Failed "+err.Error())) + } + modelDefinition = modelDefinitionRes + } + + // manifest we do not have a way to select the from a list of dataStores so we cap it to only one. + if len(manifest.DataStores) > 1 { + err = errors.New("Please only specify one data_store in the manifest. This constraint will go away with the once the new manifest is in place.") + return httpResponseHandle(http.StatusBadRequest, err, operation, []byte("Check ResultsPath Failed "+err.Error())) + } + + trainer, err := trainerClient.NewTrainer() + if err != nil { + logr.WithError(err).Errorf("Cannot create client for trainer service") + return httpResponseHandle(http.StatusInternalServerError, err, operation, []byte("Cannot create client for trainer service"+err.Error())) + } + defer trainer.Close() + + // TODO do some basic manifest.yml validation to avoid a panic + // Validate the Manifest File to Avoid panic + createRequstParam, err := manifest2TrainingRequest(manifest, modelDefinition, params.HTTPRequest, logr, dataPath) + if err != nil { + logr.WithError(err).Errorf("CreateRequest parameters check or config failed") + return httpResponseHandle(http.StatusBadRequest, err, operation, []byte(err.Error())) + } + + //get client_token from db + userFromDB, err := ccClient.GetUserByName(params.HTTPRequest.Header.Get(cc.CcAuthToken), userID) + if err != nil { + logr.Errorf("check dataPath failed: %v", err.Error()) + return httpResponseHandle(http.StatusBadRequest, err, operation, []byte("GetUserByName failed: "+err.Error())) + } + logr.Debugf("userFromDB.Token: %v", userFromDB.Token) + createRequstParam.Token = userFromDB.Token + + logr.Infof("createRequstParam.TFosRequest: %v", createRequstParam.TFosRequest) + + // Check GPU, CPU and Memory + if createRequstParam.Training.Resources.Cpus <= 0 || createRequstParam.Training.Resources.Gpus < 0 || createRequstParam.Training.Resources.Memory <= 0 { + err = errors.New("gpu, cpu and memory has to be greater than 0") + return httpResponseHandle(http.StatusBadRequest, err, operation, []byte("failed to creatTrainingJob when check for resource")) + } + //Get data + db := datasource.GetDB() + if !reflect2.IsNil(manifest.ExpRunId) && manifest.ExpRunId > 0 { + createRequstParam.ExpRunId = strconv.Itoa(int(manifest.ExpRunId)) + experimentRun, err := repo.ExperimentRunRepo.Get(manifest.ExpRunId, db) + if err != nil { + logger.GetLogger().Error("get experiment run failed, ", err) + } + experiment, err := repo.ExperimentRepo.Get(experimentRun.ExpID, db) + if err != nil { + logger.GetLogger().Error("get experiment failed, ", err) + } + if experiment.ExpName != nil { + createRequstParam.ExpName = *experiment.ExpName + } + } + if !reflect2.IsNil(manifest.FileName) && len(manifest.FileName) > 0 { + createRequstParam.FileName = manifest.FileName + } + if !reflect2.IsNil(manifest.CodePath) && len(manifest.CodePath) > 0 { + createRequstParam.FilePath = manifest.CodePath + } + // SERVICE METHOD + tresp, err := trainer.Client().CreateTrainingJob(params.HTTPRequest.Context(), createRequstParam) + if err != nil { + logr.Println("== CreateTrainingJobError:", err) + logr.WithError(err).Errorf("Trainer service call failed") + + if status.Code(err) == codes.InvalidArgument || grpc.Code(err) == codes.NotFound { + return httpResponseHandle(http.StatusBadRequest, err, operation, nil) + } + + if status.Code(err) == codes.ResourceExhausted { + return httpResponseHandle(http.StatusTooManyRequests, err, operation, nil) + } + logr.Debugf("model_impl CreateTrainingJob errMsg: %s", err.Error()) + return httpResponseHandle(http.StatusInternalServerError, err, operation, []byte("Trainer Interneal Error.")) + } + + loc := params.HTTPRequest.URL.Path + "/" + tresp.TrainingId + return models.NewPostModelCreated(). + WithLocation(loc). + WithPayload(&restmodels.BasicNewModel{ + BasicModel: restmodels.BasicModel{ + ModelID: tresp.TrainingId, + }, + Location: loc, + }) +} + +func GetModel(params models.GetModelParams) middleware.Responder { + logr := logger.LocLogger(logWithGetModelParams(params)) + logr.Debugf("getModel invoked: %v", params.HTTPRequest.Header) + rresp, errFromTrainer := getTrainingJobFromStorage(params) + if rresp == nil { + return errFromTrainer + } + // FIXME MLSS Change: more properties for result + m := createModel(params.HTTPRequest, rresp.Job, logr) + + //logr.Debugf("m: %+v", m) + return models.NewGetModelOK().WithPayload(m) +} + +func ListModels(params models.ListModelsParams) middleware.Responder { + //1.Recv Parmas Init + logr := logger.LocLogger(logWithGetListModelsParams(params)) + userID := getUserID(params.HTTPRequest) + isSA := getSuperadmin(params.HTTPRequest) + queryUser, namespace, page, size, clusterName, expRunId, err := getParamsForListModels(params) + if err != nil { + return handleErrorResponse(logr, err.Error()) + } + //2.Params Check & Perminssion Check + err = checkPageInfo(page, size) + if err != nil { + return handleErrorResponse(logr, err.Error()) + } + //3.Variable Init + //Init Model Storage Client + sClient, err := storageClient.NewStorage() + if err != nil { + logr.WithError(err).Errorf("Cannot create client for storage service") + return handleErrorResponse(logr, "") + } + defer sClient.Close() + + //4.Get Model From Storage Client + var resp *grpc_storage.GetAllResponse = nil + logr.Debugf("get clusterName: %v", clusterName) + var role string + //if not sa + if isSA == SA { + role = userSA + logr.Debugf("pass for SA.") + } else { + role = userGA + if namespace != "" && queryUser != "" { + role, err = getRoleNum(params.HTTPRequest.Header.Get(cc.CcAuthToken), getUserID(params.HTTPRequest), namespace) + if err != nil { + logr.Error("getRoleNum error, ", err) + return handleErrorResponse(logr, err.Error()) + } + } + } + nsList, err := getUserNSList(params.HTTPRequest.Header.Get(cc.CcAuthToken), role, clusterName) + if err != nil { + logger.GetLogger().Info("getUserNSList error, ", err) + return handleErrorResponse(logr, err.Error()) + } + if queryUser == "" && namespace == "" { + if isSA == SA { + // FIXME MLSS Change: v_1.5.0 add logic when get nsList from cc + if nsList != nil && len(nsList) > 0 { + resp, err = sClient.Client().GetAllTrainingsJobsByUserIdAndNamespaceList(params.HTTPRequest.Context(), &grpc_storage.GetAllRequest{ + NamespaceList: nsList, + Page: page, + Size: size, + ExpRunId: expRunId, + }) + if err != nil { + logger.GetLogger().Info("Get storage error, ", err) + } + } + } else { + logr.Debugf("pass nothing for GA/GU.") + //other role + //nsList,user + //CC:getNamespaceWithRole + logr.Debugf("debug_metaUserID: %v", userID) + resp, err = sClient.Client().GetAllTrainingsJobsByUserIdAndNamespaceList(params.HTTPRequest.Context(), &grpc_storage.GetAllRequest{ + Username: getUserID(params.HTTPRequest), + ClusterName: clusterName, + NamespaceList: nsList, + Page: page, + Size: size, + ExpRunId: expRunId, + }) + logr.Debugf("storage.Client().GetAllTrainingsJobsByUserIdAndNamespaceList, page: %v, total %v", resp.Pages, resp.Total) + } + } else if queryUser == "" && namespace != "" { + //pass namespace only + //CC:/access/admin/namespaces/{namespace} + resp, err = sClient.Client().GetAllTrainingsJobsByUserIdAndNamespace(params.HTTPRequest.Context(), &grpc_storage.GetAllRequest{ + UserId: getUserID(params.HTTPRequest), + Namespace: namespace, + Page: page, + Size: size, + ExpRunId: expRunId, + }) + } else if queryUser != "" && namespace != "" { + //pass user and namespace + //CC:/access/admin/namespaces/{namespace}/users/{user} + resp, err = sClient.Client().GetAllTrainingsJobsByUserIdAndNamespace(params.HTTPRequest.Context(), &grpc_storage.GetAllRequest{ + Username: queryUser, + ClusterName: clusterName, + NamespaceList: nsList, + Page: page, + Size: size, + ExpRunId: expRunId, + }) + } else { + return handleErrorResponse(logr, "namespace can't be null, when user exists") + } + + //get trainingJob error handle + if err != nil { + logr.WithError(err).Error("Trainer readAll service call failed") + if grpc.Code(err) == codes.PermissionDenied { + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + w.WriteHeader(http.StatusForbidden) + //FIXME MLSS Change: change Description to Msg + payload, _ := json.Marshal(restmodels.Error{ + Error: "forbidden", + Code: http.StatusForbidden, + Msg: err.Error(), + }) + w.Write(payload) + }) + } + return handleErrorResponse(logr, err.Error()) + } + + // Build Model List Response + pageInt := 0 + totalInt := 0 + marr := make([]*restmodels.Model, 0, len(resp.Jobs)) + if resp != nil { + for _, job := range resp.Jobs { + // use append(); we may have skipped some because they were gone by the time we got to them. + // FIXME MLSS Change: more properties for result + marr = append(marr, createModel(params.HTTPRequest, job, logr)) + } + pageInt, err = strconv.Atoi(resp.Pages) + if err != nil { + logr.Error("resp.Pages parse int failed") + } + totalInt, err = strconv.Atoi(resp.Total) + if err != nil { + logr.Error("resp.Total parse int failed") + } + } + return models.NewListModelsOK().WithPayload(&restmodels.ModelList{ + Models: marr, + Pages: int64(pageInt), + Total: int64(totalInt), + }) +} + +func PatchModel(params models.PatchModelParams) middleware.Responder { + logr := logger.LocLogger(logWithUpdateStatusParams(params)) + logr.Debugf("patchModel invoked: %v", params.HTTPRequest.Header) + + if params.Payload.Status != "halt" { + //FIXME MLSS Change: change Description to Msg + return models.NewPatchModelBadRequest().WithPayload(&restmodels.Error{ + Error: "Bad request", + Code: http.StatusBadRequest, + Msg: "status parameter has incorrect value", + }) + } + + trainer, err := trainerClient.NewTrainer() + + if err != nil { + logr.Errorf("Cannot create client for trainer service: %s", err.Error()) + return handleErrorResponse(logr, "") + } + defer trainer.Close() + + if err != nil { + logr.Errorf("Trainer status update service call failed: %s", err.Error()) + if grpc.Code(err) == codes.NotFound { + //FIXME MLSS Change: change Description to Msg + return models.NewPatchModelNotFound().WithPayload(&restmodels.Error{ + Error: "Not found", + Code: http.StatusNotFound, + Msg: "model_id not found", + }) + } + if grpc.Code(err) == codes.PermissionDenied { + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + w.WriteHeader(http.StatusForbidden) + //FIXME MLSS Change: change Description to Msg + payload, _ := json.Marshal(restmodels.Error{ + Error: "forbidden", + Code: http.StatusForbidden, + Msg: err.Error(), + }) + w.Write(payload) + }) + } + } + return models.NewPatchModelAccepted().WithPayload(&restmodels.BasicModel{ + ModelID: params.ModelID, + }) +} + +func getUserNSList(token string, role string, clusterName string) ([]string, error) { + ccAddress := viper.GetString(config.CCAddress) + ccClient := cc.GetCcClient(ccAddress) + bodyForNS, err := ccClient.GetCurrentUserNamespaceWithRole(token, role, clusterName) + if err != nil { + logr.WithError(err).Errorf("Error when checking namespace from cc, ", err) + return []string{}, errors.New("Error when checking namespace from cc, " + err.Error()) + } + logr.Debugf("ns from cc: %v", string(bodyForNS)) + var nsVOList []commonModels.NamespaceVO + err = commonModels.GetResultData(bodyForNS, &nsVOList) + if err != nil { + logr.WithError(err).Errorf("GetResultData failed") + return []string{}, errors.New("GetResultData failed") + } + nsList := []string{} + for _, v := range nsVOList { + nsList = append(nsList, v.Namespace) + } + return nsList, nil +} + +//get role's number, GA is 1, GU is 2 +func getRoleNum(token string, username string, namespace string) (string, error) { + var role string + var roleNum string + ccAddress := viper.GetString(config.CCAddress) + ccClient := cc.GetCcClient(ccAddress) + err := ccClient.CheckNamespaceUser(token, namespace, username) + if err != nil { + logr.WithError(err).Errorf("CheckNamespaceUser failed, %v", err.Error()) + return "", err + } + bodyForRole, err := ccClient.CheckNamespace(token, namespace) + err = commonModels.GetResultData(bodyForRole, &role) + if err != nil { + logr.WithError(err).Errorf("GetResultData failed") + return "", err + } + if role == "SA" || role == "GA" { + roleNum = "1" + } else { + roleNum = "2" + } + return roleNum, nil +} + +func DeleteModel(params models.DeleteModelParams) middleware.Responder { + //1、Recv Parmas Init + logr := logger.LocLogger(logWithDeleteModelParams(params)) + logr.Debugf("deleteModel invoked: %v", params.HTTPRequest.Header) + storageClient, err := storageClient.NewStorage() + if err != nil { + logr.WithError(err).Errorf("Cannot create client for trainer service") + return handleErrorResponse(logr, err.Error()) + } + defer storageClient.Close() + //2、Params Check & Perminssion Check + // FIXME MLSS Change: auth user in restapi + _, errResp := checkJobVisibility(params.HTTPRequest.Context(), params.ModelID, getUserID(params.HTTPRequest), params.HTTPRequest.Header.Get(cc.CcAuthToken)) + if errResp != nil { + return errResp + } + _, err = storageClient.Client().DeleteTrainingJob(params.HTTPRequest.Context(), &grpc_storage.DeleteRequest{ + TrainingId: params.ModelID, + UserId: getUserID(params.HTTPRequest), + }) + if err != nil { + logr.WithError(err).Errorf("storage.Client().DeleteTrainingJob call failed") + if grpc.Code(err) == codes.PermissionDenied { + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + w.WriteHeader(http.StatusForbidden) + //FIXME MLSS Change: change Description to Msg + payload, _ := json.Marshal(restmodels.Error{ + Error: "forbidden", + Code: http.StatusForbidden, + Msg: err.Error(), + }) + w.Write(payload) + }) + } + if grpc.Code(err) == codes.NotFound { + //FIXME MLSS Change: change Description to Msg + return models.NewDeleteModelNotFound().WithPayload(&restmodels.Error{ + Error: "Not found", + Code: http.StatusNotFound, + Msg: "", + }) + } + return handleErrorResponse(logr, err.Error()) + } + return models.NewDeleteModelOK().WithPayload( + &restmodels.BasicModel{ + ModelID: params.ModelID, + }) +} + +func ExportModel(params models.ExportModelParams) middleware.Responder { + //1、Recv Parmas Init + folderUid := uuid.New().String() + manifestPath := "./exportFolder/" + folderUid + "/model" + manifestDefYml := "manifest.yaml" + yamlFile, err := createYamlFile(manifestPath, manifestDefYml) + if err != nil { + logger.GetLogger().Error("CreateYamlFile error, ", err) + return handleErrorResponse(logger.GetLogger(), err.Error()) + } + storage, err := storageClient.NewStorage() + defer storage.Close() + if err != nil { + logger.GetLogger().Error("Cannot create client for trainer service") + return handleErrorResponse(logger.GetLogger(), "") + } + //2、Get TrainingJob + trainingJob, manifest, err := getTrainingJob(params, storage) + if err != nil { + logger.GetLogger().Error("Get training job err, ", err) + return handleErrorResponse(logger.GetLogger(), "") + } + //3、Write yaml file + yamlBytes, err := yaml.Marshal(&manifest) + if err != nil { + logger.GetLogger().Error("Yaml marshal faild err, ", err) + return handleErrorResponse(logger.GetLogger(), "") + } + yamlFile.Write(yamlBytes) + err = yamlFile.Close() + if err != nil { + logger.GetLogger().Error("Yaml file close err, ", err) + return handleErrorResponse(logger.GetLogger(), "") + } + //4、Check codeFile or storagePath + if trainingJob.Job.FilePath != "" { + s3Client, err := storageClient.NewStorage() + todo := context.TODO() + ctx, _ := context.WithCancel(todo) + downloadReq := grpc_storage.CodeDownloadRequest{ + S3Path: trainingJob.Job.FilePath, + } + res, err := s3Client.Client().DownloadCode(ctx, &downloadReq) + if err != nil { + logger.GetLogger().Error("s3Client download code failed, ", err) + return handleErrorResponse(logger.GetLogger(), "") + } + //5、Write to code zip file + err = writeExportCodeZipFile(manifestPath, trainingJob, res) + if err != nil { + logger.GetLogger().Error("Write export code zip file error, ", err) + return handleErrorResponse(logger.GetLogger(), err.Error()) + } + } + //6、Archive and export + uid := uuid.New().String() + zipName := fmt.Sprintf("%v.zip", uid) + err = archiver.Archive([]string{manifestPath}, zipName) + if err != nil { + logger.GetLogger().Error("zip archiver failed, ", err) + return handleErrorResponse(logger.GetLogger(), "") + } + //read code zip file's binary + zipFileBytes, err := ioutil.ReadFile(fmt.Sprintf("./%v", zipName)) + if err != nil { + logger.GetLogger().Error("ReadFile failed, ", err) + return handleErrorResponse(logger.GetLogger(), "") + } + //clear manifestPath's all file + err = os.RemoveAll(manifestPath) + if err != nil { + logger.GetLogger().Error("clear folder failed, ", err) + return handleErrorResponse(logger.GetLogger(), "") + } + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + w.Write(zipFileBytes) + w.WriteHeader(200) + }) +} + +func GetDashboards(params operations.GetDashboardsParams) middleware.Responder { + //1、Recv Parmas Init + logr := logger.LocLogger(logWithGetDashboards(params)) + var currentUserId = getUserID(params.HTTPRequest) + var isSA = getSuperadmin(params.HTTPRequest) + var resp *grpc_storage.GetAllResponse = nil + var role string + logr.Debugf(">>getDashboards<< metaUserID: %v, superadmin: %v", currentUserId, isSA) + storage, err := storageClient.NewStorage() + defer storage.Close() + if err != nil { + logr.WithError(err).Errorf("Cannot create client for trainer service") + return handleErrorResponse(logr, "") + } + + //2、Get userId and namespace from params + clusterName, err := getParamsForDashboards(params) + logr.Debugf("Calling trainer.Client().GetAllTrainingsJobs(...)") + logr.Debugf("debug") + + //3、Check role + if isSA == SA { + role = userSA + } else { + role = userGA + } + nsList, err := getUserNSList(params.HTTPRequest.Header.Get(cc.CcAuthToken), role, clusterName) + if err != nil { + logr.WithError(err).Errorf("getUserNSList error, ", err) + return handleErrorResponse(logr, err.Error()) + } + + //4、Get nsList by role + if isSA == SA { + logr.Infof("pass nothing for SA.") + //if role == SA + //nil,nil + // FIXME MLSS Change: v_1.5.0 added param clusterName to filter models + if nsList != nil && len(nsList) > 0 { + resp, err = storage.Client().GetAllTrainingsJobsByUserIdAndNamespaceList(params.HTTPRequest.Context(), &grpc_storage.GetAllRequest{ + NamespaceList: nsList, + }) + if err != nil { + logr.WithError(err).Errorf("GetAllTrainingsJobsByUserIdAndNamespaceList failed") + return handleErrorResponse(logr, err.Error()) + } + } + } else { + logr.Debugf("pass nothing for GA/GU.") + //other role + //nsList,user + //CC:getNamespaceWithRole + resp, err = storage.Client().GetAllTrainingsJobsByUserIdAndNamespaceList(params.HTTPRequest.Context(), &grpc_storage.GetAllRequest{ + Username: currentUserId, + NamespaceList: nsList, + ClusterName: clusterName, + }) + if err != nil { + logr.WithError(err).Errorf("GetAllTrainingsJobsByUserIdAndNamespaceList failed") + return handleErrorResponse(logr, err.Error()) + } + } + + //5、Make response + if resp != nil { + jobs := resp.Jobs + //logr.Infof("getDashboards jobs: %v", jobs) + //jobTotal:current user's trainingJobs; jobRunning: number of current user's trainingJobs is 'COMPLETED' or 'FAILED' for status; gpuCount:gpu number of jobRunning + jobTotal := len(jobs) + jobRunning := 0 + var gpuCount float32 = 0 + for _, j := range jobs { + if grpc_storage.Status_COMPLETED != j.Status.Status && grpc_storage.Status_FAILED != j.Status.Status && grpc_storage.Status_PENDING != j.Status.Status && grpc_storage.Status_QUEUED != j.Status.Status { + jobRunning += 1 + if j.GetTraining().GetResources().GetGpus() > 0 { + gpu := j.GetTraining().GetResources().GetGpus() + gpuCount += gpu + //logr.Infof("getDashboards jobs j: %v", j) + } + } + } + mp := map[string]int{"jobTotal": jobTotal, "jobRunning": jobRunning, "gpuCount": int(gpuCount)} + marshal, err := json.Marshal(mp) + if err != nil { + logr.WithError(err).Errorf("json.Marshal(mp) failed") + return handleErrorResponse(logr, err.Error()) + } + var result = commonModels.Result{ + Code: "200", + Msg: "success", + Result: json.RawMessage(marshal), + } + + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + payload, _ := json.Marshal(result) + w.Write(payload) + w.WriteHeader(200) + }) + } else { + mp := map[string]int{"jobTotal": 0, "jobRunning": 0, "gpuCount": int(0)} + marshal, err := json.Marshal(mp) + if err != nil { + logr.WithError(err).Errorf("json.Marshal(mp) failed") + return handleErrorResponse(logr, err.Error()) + } + var result = commonModels.Result{ + Code: "200", + Msg: "success", + Result: json.RawMessage(marshal), + } + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + payload, _ := json.Marshal(result) + w.Write(payload) + w.WriteHeader(200) + }) + } +} + +func GetLogs(params models.GetLogsParams) middleware.Responder { + return getLogsOrMetrics(params, false) +} + +func DownloadModelDefinition(params models.DownloadModelDefinitionParams) middleware.Responder { + logr := logger.LocLogger(logWithDownloadModelDefinitionParams(params)) + logr.Debugf("downloadModelDefinition invoked: %v", params.HTTPRequest.Header) + + //trainer, err := trainerClient.NewTrainer() + storage, err := storageClient.NewStorage() + defer storage.Close() + if err != nil { + logger.GetLogger().Error("Cannot create client for trainer service") + return handleErrorResponse(logr, "") + } + + stream, err := storage.Client().GetModelDefinition(params.HTTPRequest.Context(), &grpc_storage.ModelDefinitionRequest{ + TrainingId: params.ModelID, + UserId: getUserID(params.HTTPRequest), + }) + if err != nil { + logr.WithError(err).Error("Trainer GetModelDefinition service call failed") + if grpc.Code(err) == codes.PermissionDenied { + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + w.WriteHeader(http.StatusForbidden) + //FIXME MLSS Change: change Description to Msg + payload, _ := json.Marshal(restmodels.Error{ + Error: "forbidden", + Code: http.StatusForbidden, + Msg: err.Error(), + }) + w.Write(payload) + }) + } + if grpc.Code(err) == codes.NotFound { + //FIXME MLSS Change: change Description to Msg + return models.NewDownloadModelDefinitionNotFound().WithPayload(&restmodels.Error{ + Error: "Not found", + Code: http.StatusNotFound, + Msg: "", + }) + } + return handleErrorResponse(logr, "") + } + + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + for { + chunk, err := stream.Recv() + if err == io.EOF { + w.WriteHeader(200) + if err = stream.CloseSend(); err != nil { + logr.WithError(err).Error("Closing stream failed") + } + break + } else if err != nil { + logr.WithError(err).Errorf("Cannot read model definition") + // this error handling is a bit of a hack with overriding the content-type + // but the swagger-generated REST client chokes if we leave the content-type + // as application-octet stream + w.WriteHeader(500) + w.Header().Set(runtime.HeaderContentType, runtime.JSONMime) + //FIXME MLSS Change: change Description to Msg + payload, _ := json.Marshal(&restmodels.Error{ + Error: "Internal server error", + Msg: "", + Code: 500, + }) + w.Write(payload) + break + } + w.Write(chunk.Data) + } + }) +} + +func DownloadTrainedModel(params models.DownloadTrainedModelParams) middleware.Responder { + logr := logger.LocLogger(logWithDownloadTrainedModelParams(params)) + logr.Debugf("downloadTrainedModel invoked: %v", params.HTTPRequest.Header) + + //trainer, err := trainerClient.NewTrainer() + storage, err := storageClient.NewStorage() + defer storage.Close() + if err != nil { + logger.GetLogger().Error("Cannot create client for trainer service") + return handleErrorResponse(logr, "") + } + + stream, err := storage.Client().GetTrainedModel(params.HTTPRequest.Context(), &grpc_storage.TrainedModelRequest{ + TrainingId: params.ModelID, + UserId: getUserID(params.HTTPRequest), + }) + if err != nil { + logr.WithError(err).Errorf("Trainer GetTrainedModel service call failed") + if grpc.Code(err) == codes.PermissionDenied { + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + w.WriteHeader(http.StatusForbidden) + //FIXME MLSS Change: change Description to Msg + payload, _ := json.Marshal(restmodels.Error{ + Error: "forbidden", + Code: http.StatusForbidden, + Msg: err.Error(), + }) + w.Write(payload) + }) + } + if grpc.Code(err) == codes.NotFound { + //FIXME MLSS Change: change Description to Msg + return models.NewDownloadTrainedModelNotFound().WithPayload(&restmodels.Error{ + Error: "Not found", + Code: http.StatusNotFound, + Msg: "", + }) + } + return handleErrorResponse(logr, "") + } + + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + for { + chunk, err := stream.Recv() + if err == io.EOF { + w.WriteHeader(200) + if err = stream.CloseSend(); err != nil { + logr.WithError(err).Error("Closing stream failed") + } + break + } else if err != nil { + logr.WithError(err).Error("Cannot read trained model") + // this error handling is a bit of a hack with overriding the content-type + // but the swagger-generated REST client chokes if we leave the content-type + // as application-octet stream + w.WriteHeader(500) + w.Header().Set(runtime.HeaderContentType, runtime.JSONMime) + //FIXME MLSS Change: change Description to Msg + payload, _ := json.Marshal(&restmodels.Error{ + Error: "Internal server error", + Msg: "", + Code: 500, + }) + w.Write(payload) + break + } + w.Write(chunk.Data) + } + }) +} + +func GetLoglines(params training_data.GetLoglinesParams) middleware.Responder { + logr := logger.LocLogger(logWithLoglinesParams(params)) + logr.Debug("function entry") + + trainingData, err := trainingDataClient.NewTrainingDataClient() + if err != nil { + logr.WithError(err).Errorf("Cannot create client for trainer service") + return handleErrorResponse(logr, "") + } + defer trainingData.Close() + + // FIXME MLSS Change: get user id of the training from trainer + //getModelParams := models.NewGetModelParams().WithModelID(params.ModelID).WithTimeout(10*time.Second) + getModelParams := models.GetModelParams{ + HTTPRequest: params.HTTPRequest, + ModelID: params.ModelID, + } + //rresp, errFromTrainer := getTrainingJobFromTrainer(getModelParams) + rresp, errFromTrainer := getTrainingJobFromStorage(getModelParams) + + if rresp == nil { + return errFromTrainer + } + trainingUserID := rresp.Job.UserId + + var metaUserID = getUserID(params.HTTPRequest) + + // FIXME MLSS Change: check if current request user can access the records of the training creator + //ccClient := cc.GetCcClient("http://controlcenter:7777") + // FIXME MLSS Change: read cc address from configmap + ccAddress := viper.GetString(config.CCAddress) + ccClient := cc.GetCcClient(ccAddress) + err = ccClient.AdminUserCheck(params.HTTPRequest.Header.Get(cc.CcAuthToken), metaUserID, trainingUserID) + if err != nil { + logr.WithError(err).Errorf("Error when checking user access from cc") + return handleErrorResponse(logr, "") + } + + var sinceQuery = "" + if params.SinceTime != nil { + sinceQuery = *params.SinceTime + } + var pagesize int32 = defaultLogPageSize + if params.Pagesize != nil { + pagesize = *params.Pagesize + } + var pos int64 + if params.Pos != nil { + pos = *params.Pos + } + var searchType grpc_training_data_v1.Query_SearchType = grpc_training_data_v1.Query_TERM + if params.SearchType != nil { + searchType = makeGrpcSearchTypeFromRestSearchType(*params.SearchType) + } + + query := &grpc_training_data_v1.Query{ + Meta: &grpc_training_data_v1.MetaInfo{ + TrainingId: params.ModelID, + UserId: metaUserID, + Time: 0, + }, + Pagesize: pagesize, + Pos: pos, + Since: sinceQuery, + SearchType: searchType, + } + + // The marshal from the grpc record to the rest record should probably be just a byte stream transfer. + // But for now, I prefer a structural copy, I guess. + + getLogsClient, err := trainingData.Client().GetLogs(params.HTTPRequest.Context(), query) + if err != nil { + trainingData.Close() + logr.WithError(err).Error("GetLogs call failed") + if grpc.Code(err) == codes.PermissionDenied { + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + w.WriteHeader(http.StatusForbidden) + //FIXME MLSS Change: change Description to Msg + payload, _ := json.Marshal(restmodels.Error{ + Error: "forbidden", + Code: http.StatusForbidden, + Msg: err.Error(), + }) + w.Write(payload) + }) + } + return handleErrorResponse(logr, "") + } + + marr := make([]*restmodels.V1LogLine, 0, pagesize) + + err = nil + nRecordsActual := 0 + for ; nRecordsActual < int(pagesize); nRecordsActual++ { + logsRecord, err := getLogsClient.Recv() + if err == io.EOF { + break + } else if err != nil { + logr.WithError(err).Errorf("Cannot read model definition") + break + } + + marr = append(marr, &restmodels.V1LogLine{ + Meta: &restmodels.V1MetaInfo{ + TrainingID: logsRecord.Meta.TrainingId, + UserID: logsRecord.Meta.UserId, + Time: logsRecord.Meta.Time, + Rindex: logsRecord.Meta.Rindex, + }, + Line: logsRecord.Line, + }) + } + trimmedList := marr[0:nRecordsActual] + + response := training_data.NewGetLoglinesOK().WithPayload(&restmodels.V1LogLinesList{ + Models: trimmedList, + }) + logr.Debug("function exit") + return response +} + +func createYamlFile(manifestPath string, manifestDefYml string) (*os.File, error) { + //create yaml's dir + err := os.MkdirAll(manifestPath, os.ModePerm) + if err != nil { + logger.GetLogger().Info("create flowPath failed:", err) + return nil, err + } + //create yaml's file + yamlFile, err := os.Create(fmt.Sprintf("%v/%v", manifestPath, manifestDefYml)) + if err != nil { + logger.GetLogger().Info("yamlFile create failed, ", err) + return nil, err + } + return yamlFile, err +} + +func getTrainingJob(params models.ExportModelParams, storage storageClient.StorageClient) (*grpc_storage.GetResponse, *ManifestV1, error) { + var tfReq v1alpha1.TFosRequest + var framework frameworkV1 + var jobAlert map[string][]map[string]string + dataStores := []*dataStoreRef{} + req := grpc_storage.GetTrainingJobRequest{ + TrainingId: params.ModelID, + } + //get training job + trainingJob, err := storage.Client().GetTrainingJobByTrainingJobId(context.TODO(), &req) + if err != nil { + logger.GetLogger().Error("GetTrainingJobByTrainingJobId faild err, ", err) + return nil, nil, err + } + expRunId, _ := strconv.Atoi(trainingJob.Job.ExpRunId) + copier.Copy(&tfReq, &trainingJob.Job.TfosRequest) + copier.Copy(&framework, &trainingJob.Job.ModelDefinition.Framework) + json.Unmarshal([]byte(trainingJob.Job.JobAlert), &jobAlert) + framework.Command = trainingJob.Job.Training.Command + //make data store + dataStore := &dataStoreRef{ + ID: "hostmount ", + Type: "mount_volume", + Connection: trainingJob.Job.Datastores[0].Connection, + TrainingData: &storageContainerV1{ + Container: trainingJob.Job.Datastores[0].Fields["bucket"], + }, + TrainingResults: &storageContainerV1{ + Container: trainingJob.Job.Datastores[1].Fields["bucket"], + }, + } + //apped data store to training job's data stores + dataStores = append(dataStores, dataStore) + return trainingJob, &ManifestV1{ + Name: trainingJob.Job.ModelDefinition.Name, + Description: trainingJob.Job.ModelDefinition.Description, + Version: "1.0", + Cpus: float64(trainingJob.Job.Training.Resources.Cpus), + Gpus: float64(trainingJob.Job.Training.Resources.Gpus), + Memory: fmt.Sprintf("%vGb", trainingJob.Job.Training.Resources.Memory), + GpuType: trainingJob.Job.Training.Resources.GpuType, + Learners: trainingJob.Job.Training.Resources.Learners, + Storage: fmt.Sprintf("%v", trainingJob.Job.Training.Resources.Storage), + Namespace: trainingJob.Job.JobNamespace, + CodeSelector: trainingJob.Job.CodeSelector, + JobType: trainingJob.Job.JobType, + JobAlert: jobAlert, + ExpName: trainingJob.Job.ExpName, + ExpRunId: int64(expRunId), + CodePath: "", + FileName: "", + PSs: trainingJob.Job.Pss, + PSCPU: trainingJob.Job.PsCpu, + PSImage: trainingJob.Job.PsImage, + PSMemory: trainingJob.Job.PsMemory, + TFosRequest: &tfReq, + DataStores: dataStores, + Framework: &framework, + }, nil +} + +func writeExportCodeZipFile(manifestPath string, trainingJob *grpc_storage.GetResponse, codeDownloadRes *grpc_storage.CodeDownloadResponse) error { + codeZipPath := fmt.Sprintf("%v/%v", manifestPath, trainingJob.Job.FileName) + ///read oss's code zip file + codeFileBytes, err := ioutil.ReadFile(fmt.Sprintf("%v/%v", codeDownloadRes.HostPath, codeDownloadRes.FileName)) + if err != nil { + logger.GetLogger().Error("codeFile read failed, ", err) + return err + } + //create code zip file + codeZipFile, err := os.Create(codeZipPath) + if err != nil { + logger.GetLogger().Error("codeZipFile create failed, ", err) + return err + } + //write to code zip file + codeZipFile.Write(codeFileBytes) + codeZipFile.Close() + return nil +} + +func defineJobPath(DSs []*dataStoreRef, manifest *ManifestV1) (string, string) { + var dataPath string + var resultsPath string + for _, ds := range DSs { + conn := ds.Connection + parentPath := conn["path"] + // Add logic for path when create notebook + if manifest.JobType != "tfos" { + subDataPath := ds.TrainingData.Container + if !stringsUtil.HasPrefix(subDataPath, "/") && !stringsUtil.HasSuffix(parentPath, "/") { + dataPath = parentPath + "/" + subDataPath + } else if stringsUtil.HasPrefix(subDataPath, "/") && stringsUtil.HasSuffix(parentPath, "/") { + dataPath = parentPath + subDataPath[1:] + } else { + dataPath = parentPath + subDataPath + } + } + + subResultsPath := ds.TrainingResults.Container + if !stringsUtil.HasPrefix(subResultsPath, "/") && !stringsUtil.HasSuffix(parentPath, "/") { + resultsPath = parentPath + "/" + subResultsPath + } else if stringsUtil.HasPrefix(subResultsPath, "/") && stringsUtil.HasSuffix(parentPath, "/") { + resultsPath = parentPath + subResultsPath[1:] + } else { + resultsPath = parentPath + subResultsPath + } + break + } + return dataPath, resultsPath +} + +func codePathToModelDefinition(codePath string) (io.ReadCloser, error) { + sClient, err := storageClient.NewStorage() + defer sClient.Close() + if err != nil { + logger.GetLogger().Error("NewStorage Error: ", err.Error()) + return nil, err + } + req := &grpc_storage.CodeDownloadRequest{S3Path: codePath} + ctx := context.TODO() + res, err := sClient.Client().DownloadCode(ctx, req) + if err != nil { + logger.GetLogger().Error("Storage Download Code Error: ", err.Error()) + return nil, err + } + //fileByte, err := ioutil.ReadFile(res.HostPath+"/"+res.FileName) + + file, err := os.Open(res.HostPath + "/" + res.FileName) + fileReader := bufio.NewReader(file) + + return ioutil.NopCloser(fileReader), err +} + +// func handleTfosManifest(userId string, manifest *ManifestV1, logr *logger.LocLoggingEntry) error { +// logr.Debugf("handleTfosManifest start") + +// //fixme: skip loading model in learner +// manifest.CodeSelector = "storagePath" + +// cpuInfloat64, err := strconv.ParseFloat(os.Getenv("LINKIS_EXECUTOR_CPU"), 64) +// if err != nil { +// logr.Debugf("ParseFloat LINKIS_EXECUTOR_CPU failed: %v", err.Error()) +// return err +// } +// manifest.Cpus = cpuInfloat64 +// manifest.Memory = os.Getenv("LINKIS_EXECUTOR_MEM") +// manifest.Gpus = 0 + +// clusterNameForDir, err := getClusterNameForDir(manifest.Namespace) +// if err != nil { +// logr.Debugf("handleTfosManifest, getClusterNameForDir: %v", err.Error()) +// return err +// } + +// var dss = make([]*dataStoreRef, 1) +// manifest.DataStores = dss +// var ds = &dataStoreRef{ +// TrainingData: &storageContainerV1{ +// Container: "data", +// }, +// TrainingResults: &storageContainerV1{ +// Container: "result", +// }, +// ID: "hostmount", +// Type: "mount_volume", +// Connection: map[string]string{ +// "type": "host_mount", +// "name": "host-mount", +// "path": fmt.Sprintf("/data/%v/mlss-data/%v", clusterNameForDir, userId), +// }, +// } +// dss[0] = ds + +// manifest.Framework = &frameworkV1{ +// Name: os.Getenv("LINKIS_EXECUTOR_IMAGE"), +// Version: os.Getenv("LINKIS_EXECUTOR_TAG"), +// } + +// manifest.Framework.Command = "/main" + +// logr.Debugf("after handleTfosManifest: %+v", manifest) + +// return nil +// } + +// FIXME MLSS Change: check manifest.yaml +func checkManifest(manifest *ManifestV1, logr *logger.LocLoggingEntry) error { + if math.IsNaN(manifest.Cpus) { + return errors.New("cpus is NaN") + } + if math.IsNaN(manifest.Gpus) { + return errors.New("gpus is NaN") + } + logr.Debugf("checkManifest for manifest.JobType: %v, manifest.Learners: %v, cpu: %v, gpu: %v, memory: %v", manifest.JobType, manifest.Learners, manifest.Cpus, manifest.Gpus, manifest.Memory) + //FIXME MLSS Change: v_1.5.2 added + if "dist-tf" == manifest.JobType { + if math.IsNaN(float64(manifest.Learners)) { + return errors.New("learners is NaN") + } + if manifest.Learners <= 0 { + return errors.New("learners must be integer greater than 0") + } + } else { + if manifest.Learners > 1 { + return errors.New("if jobType not dist-tf learners can't greater than 1") + } + } + + memory := manifest.Memory + lower := stringsUtil.ToLower(memory) + if stringsUtil.HasSuffix(lower, "mib") { + if _, e := strconv.ParseFloat(stringsUtil.TrimSuffix(lower, "mib"), 64); e != nil { + return errors.New("memory not a number") + } + } else if stringsUtil.HasSuffix(lower, "gb") { + if _, e := strconv.ParseFloat(stringsUtil.TrimSuffix(lower, "gb"), 64); e != nil { + return errors.New("memory not a number") + } + } else { + return errors.New("now only support unit Mib, GB. current memory: " + manifest.Memory) + } + + return nil +} + +func checkPageInfo(page string, size string) error { + if page != "" || size != "" { + pageInt, err := strconv.Atoi(page) + if err != nil { + return errors.New("page parse to int failed") + } + if pageInt <= 0 { + return errors.New("page must be > 0") + } + sizeInt, err := strconv.Atoi(size) + if err != nil { + return errors.New("size parse to int failed") + } + if sizeInt <= 0 { + return errors.New("size must be > 0") + } + } + return nil +} + +func getParamsForListModels(params models.ListModelsParams) (string, string, string, string, string, string, error) { + logr := logger.LocLogger(logWithGetListModelsParams(params)) + query := params.HTTPRequest.URL.Query() + userValue := query["userid"] + + var username string + if len(userValue) != 0 { + logr.Debugf("listModels param user: %v", userValue[0]) + username = userValue[0] + } + namespaceValue := query["namespace"] + + var namespace string + if len(namespaceValue) != 0 { + logr.Debugf("listModels param namespace: %v", namespaceValue[0]) + namespace = namespaceValue[0] + } + pageValue := query["page"] + + var page string + if len(pageValue) != 0 { + logr.Debugf("listModels param page: %v", pageValue[0]) + page = pageValue[0] + } + sizeValue := query["size"] + + var size string + if len(sizeValue) != 0 { + logr.Debugf("listModels param size: %v", sizeValue[0]) + size = sizeValue[0] + } + expRunIdValue := query["expRunId"] + + var expRunId string + if len(expRunIdValue) != 0 { + logr.Debugf("listModels param expRunId: %v", expRunIdValue[0]) + expRunId = expRunIdValue[0] + } + + // FIXME MLSS Change: v_1.5.0 add logic to get clusterName for request + clusterNameValue := query["clusterName"] + var clusterName string + if len(clusterNameValue) != 0 { + logr.Debugf("listModels param clusterName: %v", clusterNameValue[0]) + clusterName = clusterNameValue[0] + } else { + clusterName = "default" + } + + return username, namespace, page, size, clusterName, expRunId, nil +} + +// FIXME MLSS Change: v_1.5.0 add logic to get clusterName for request +func getParamsForDashboards(params operations.GetDashboardsParams) (string, error) { + logr := logger.LocLogger(logWithGetDashboards(params)) + query := params.HTTPRequest.URL.Query() + clusterNameValue := query["clusterName"] + var clusterName string + if len(clusterNameValue) != 0 { + logr.Debugf("getDashboards param clusterName: %v", clusterNameValue[0]) + clusterName = clusterNameValue[0] + } else { + clusterName = "default" + } + return clusterName, nil +} + +// getTrainingLogs establishes a long running http connection and streams the logs of the training container. +func getLogsOrMetrics(params models.GetLogsParams, isMetrics bool) middleware.Responder { + logr := logger.LocLogger(logWithGetLogsParams(params)) + logr.Infof("getLogsOrMetrics, params.ModelID: %v", params.ModelID) + + // FIXME MLSS Change: auth user in restapi + _, errResp := checkJobVisibility(params.HTTPRequest.Context(), params.ModelID, getUserID(params.HTTPRequest), params.HTTPRequest.Header.Get(cc.CcAuthToken)) + if errResp != nil && params.ModelID != "wstest" { + return errResp + } + + ctx := params.HTTPRequest.Context() + + isFollow := (params.HTTPRequest.Header.Get("Sec-Websocket-Key") != "") + + if !isFollow { + isFollow = *params.Follow + } + + logr.Debugf("isFollow: %v, isMetrics: %v", isFollow, isMetrics) + + var timeout time.Duration + + if params.ModelID == "wstest" { + logr.Debug("is wstest") + timeout = 2 * time.Minute + + } else if isFollow { + // Make this a *very* long time out. In the longer run, if we + // push to a message queue, we can hopefully just subscribe to a web + // socket. + timeout = 80 * time.Hour + } else { + timeout = 3 * time.Minute + } + + ctx, cancel := context.WithTimeout(ctx, timeout) + // don't cancel here as we are passing the cancel function to others. + + // HACK FOR WS TEST + if params.ModelID == "wstest" { + //return getTrainingLogsWSTest(ctx, params, cancel) + return getNewTrainingLogsWSTest(ctx, params, cancel) + } + + //trainer, err := trainerClient.NewTrainer() + storage, err := storageClient.NewStorage() + + if err != nil { + logr.WithError(err).Error("Cannot create client for lcm service") + defer cancel() + return handleErrorResponse(logr, "") + } + + //var stream grpc_trainer_v2.Trainer_GetTrainedModelLogsClient + var stream grpc_storage.Storage_GetTrainedModelLogsClient + + if isMetrics { + logr.WithError(err).Errorf("GetTrainedModelMetrics has been removed") + defer cancel() + return handleErrorResponse(logr, "") + } else { + //stream, err = trainer.Client().GetTrainedModelLogs(ctx, &grpc_trainer_v2.TrainedModelLogRequest{ + stream, err = storage.Client().GetTrainedModelLogs(ctx, &grpc_storage.TrainedModelLogRequest{ + TrainingId: params.ModelID, + UserId: getUserID(params.HTTPRequest), + Follow: isFollow, + }) + } + if err != nil { + logr.WithError(err).Errorf("GetTrainedModelLogs failed") + defer cancel() + return handleErrorResponse(logr, "") + } + // _, err = *stream.Header() + // We seem to need this pause, which is somewhat disconcerting. -sb + //time.Sleep(time.Second * 2) + + if params.HTTPRequest.Header.Get("Sec-Websocket-Key") != "" { + //return getTrainingLogsWS(trainer, params, stream, cancel, isMetrics) + //return newGetTrainingLogsWS(trainer, params, stream, cancel, isMetrics) + return newGetTrainingLogsWSForStorage(storage, params, stream, cancel, isMetrics) + } + + return middleware.ResponderFunc(func(w http.ResponseWriter, prod runtime.Producer) { + // The close of the LcmClient should also close the stream, as far as i can tell. + //defer trainer.Close() + defer cancel() + + //logr.Debugln("w.WriteHeader(200)") + w.WriteHeader(200) + // w.Header().Set("Transfer-Encoding", "chunked") + var onelinebytes []byte + for { + var logFrame *grpc_storage.ByteStreamResponse + logFrame, err := stream.Recv() + // time.Sleep(time.Second * 2) + if logFrame == nil { + if err != io.EOF && err != nil { + logr.WithError(err).Errorf("stream.Recv() returned error") + } + break + } + if isMetrics { + var bytesBuf []byte = logFrame.GetData() + if bytesBuf != nil { + + byteReader := bytes.NewReader(bytesBuf) + bufioReader := bufio.NewReader(byteReader) + for { + var lineBytes []byte + lineBytes, err := bufioReader.ReadBytes('\n') + if lineBytes != nil { + lenRead := len(lineBytes) + + if err == nil || (err == io.EOF && lenRead > 0 && lineBytes[lenRead-1] == '}') { + + if onelinebytes != nil { + lineBytes = append(onelinebytes[:], lineBytes[:]...) + onelinebytes = nil + } + + _, err := w.Write(lineBytes) + //logr.Debugf("w.Write(bytes) says %d bytes written", n) + if err != nil && err != io.EOF { + logr.Errorf("getTrainingLogs(2) Write returned error: %s", err.Error()) + } + // logr.Debugln("if f, ok := w.(http.Flusher); ok {") + if f, ok := w.(http.Flusher); ok { + logr.Debugln("f.Flush()") + f.Flush() + } + } else { + if onelinebytes == nil { + onelinebytes = lineBytes + } else { + onelinebytes = append(onelinebytes[:], lineBytes[:]...) + } + } + } + if err == io.EOF { + break + } + } + } + } else { + var bytes []byte = logFrame.GetData() + if bytes != nil { + //logr.Debugln("w.Write(bytes) len = %d", len(bytes)) + _, err := w.Write(bytes) + //logr.Debugf("w.Write(bytes) says %d bytes written", n) + if err != nil && err != io.EOF { + logr.Errorf("getTrainingLogs(2) Write returned error: %s", err.Error()) + } + //logr.Debugln("if f, ok := w.(http.Flusher); ok {") + if f, ok := w.(http.Flusher); ok { + logr.Debugln("f.Flush()") + f.Flush() + } + } + } + //logr.Debugln("bottom of for") + } + }) +} + +func makeGrpcSearchTypeFromRestSearchType(st string) grpc_training_data_v1.Query_SearchType { + var searchType grpc_training_data_v1.Query_SearchType + switch restmodels.QuerySearchType(st) { + case restmodels.QuerySearchTypeTERM: + searchType = grpc_training_data_v1.Query_TERM + break + case restmodels.QuerySearchTypeMATCH: + searchType = grpc_training_data_v1.Query_MATCH + break + case restmodels.QuerySearchTypeNESTED: + searchType = grpc_training_data_v1.Query_NESTED + break + case restmodels.QuerySearchTypeALL: + searchType = grpc_training_data_v1.Query_ALL + break + } + return searchType +} + +func handleErrorResponse(log *logger.LocLoggingEntry, description string) middleware.Responder { + logger.GetLogger().Error("Returning 500 error: %s", description) + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + w.WriteHeader(http.StatusInternalServerError) + //FIXME MLSS Change: change Description to Msg + payload, _ := json.Marshal(&restmodels.Error{ + Error: "Internal server error", + Msg: description, + Code: http.StatusInternalServerError, + }) + w.Write(payload) + }) +} + +func getUserID(r *http.Request) string { + return r.Header.Get(config.CcAuthUser) +} + +func getSuperadmin(r *http.Request) string { + return r.Header.Get(config.CcAuthSuperadmin) +} + +// Echo the data received on the WebSocket. +func serveLogHandler(trainer trainerClient.TrainerClient, stream grpc_trainer_v2.Trainer_GetTrainedModelLogsClient, + logr *logger.LocLoggingEntry, cancel context.CancelFunc, isMetrics bool) websocket.Handler { + + return func(ws *websocket.Conn) { + defer ws.Close() + defer trainer.Close() + defer cancel() + + // TODO: The second param should be log.LogCategoryServeLogHandler, but, for the + // moment, just use the hard coded string, until the code is committed in dlaas-commons. + + logr.Debugf("Going into Recv() loop") + var onelinebytes []byte + for { + var logFrame *grpc_trainer_v2.ByteStreamResponse + logFrame, err := stream.Recv() + if err == io.EOF { + logr.Infof("serveLogHandler stream.Recv() is EOF") + } + if logFrame != nil && len(logFrame.Data) > 0 { + if isMetrics { + + byteReader := bytes.NewReader(logFrame.Data) + bufioReader := bufio.NewReader(byteReader) + for { + lineBytes, err := bufioReader.ReadBytes('\n') + if lineBytes != nil { + lenRead := len(lineBytes) + + if err == nil || (err == io.EOF && lenRead > 0 && lineBytes[lenRead-1] == '}') { + if onelinebytes != nil { + lineBytes = append(onelinebytes[:], lineBytes[:]...) + onelinebytes = nil + } + // We should just scan for the first non-white space. + if len(bytes.TrimSpace(lineBytes)) == 0 { + continue + } + + ws.Write(lineBytes) + // Take a short snooze, just to not take over CPU, etc. + // time.Sleep(time.Millisecond * 250) + } else { + if onelinebytes == nil { + onelinebytes = lineBytes + } else { + onelinebytes = append(onelinebytes[:], lineBytes[:]...) + } + } + } + if err == io.EOF { + break + } + } + logr.Debug("==== done processing logFrame.Data ====") + + } else { + var bytes []byte + bytes = logFrame.Data + n, errWrite := ws.Write(bytes) + if errWrite != nil && errWrite != io.EOF { + logr.WithError(errWrite).Errorf("serveLogHandler Write returned error") + break + } + logr.Debugf("wrote %d bytes", n) + } + } + + // either EOF or error reading from trainer + if err != nil { + logr.WithError(err).Debugf("Breaking from Recv() loop") + break + } + time.Sleep(time.Millisecond * 2) + } + } +} + +// Echo the data received on the WebSocket. +func newServeLogHandler(params models.GetLogsParams, w http.ResponseWriter, trainer trainerClient.TrainerClient, stream grpc_trainer_v2.Trainer_GetTrainedModelLogsClient, + logr *logger.LocLoggingEntry, cancel context.CancelFunc, isMetrics bool) { + r := params.HTTPRequest + upgrader := newWebsocket.Upgrader{ + CheckOrigin: func(r *http.Request) bool { + return true + }} + w.Header().Add("Access-Control-Allow-Origin", "*") + c, err := upgrader.Upgrade(w, r, nil) + if err != nil { + logger.GetLogger().Error("upgrade failed: ", err.Error()) + return + } + defer c.Close() + defer trainer.Close() + defer cancel() + + // TODO: The second param should be log.LogCategoryServeLogHandler, but, for the + // moment, just use the hard coded string, until the code is committed in dlaas-commons. + + logr.Debugf("Going into Recv() loop") + var onelinebytes []byte + for { + var logFrame *grpc_trainer_v2.ByteStreamResponse + logFrame, err := stream.Recv() + if err == io.EOF { + logr.Infof("serveLogHandler stream.Recv() is EOF") + } + if logFrame != nil && len(logFrame.Data) > 0 { + if isMetrics { + + byteReader := bytes.NewReader(logFrame.Data) + bufioReader := bufio.NewReader(byteReader) + for { + lineBytes, err := bufioReader.ReadBytes('\n') + if lineBytes != nil { + lenRead := len(lineBytes) + + if err == nil || (err == io.EOF && lenRead > 0 && lineBytes[lenRead-1] == '}') { + if onelinebytes != nil { + lineBytes = append(onelinebytes[:], lineBytes[:]...) + onelinebytes = nil + } + // We should just scan for the first non-white space. + if len(bytes.TrimSpace(lineBytes)) == 0 { + continue + } + + //ws.Write(lineBytes) + err = c.WriteMessage(newWebsocket.TextMessage, lineBytes) + // Take a short snooze, just to not take over CPU, etc. + // time.Sleep(time.Millisecond * 250) + } else { + if onelinebytes == nil { + onelinebytes = lineBytes + } else { + onelinebytes = append(onelinebytes[:], lineBytes[:]...) + } + } + } + if err == io.EOF { + break + } + } + logr.Debug("==== done processing logFrame.Data ====") + + } else { + var bytes []byte + bytes = logFrame.Data + //n, errWrite := ws.Write(bytes) + errWrite := c.WriteMessage(newWebsocket.TextMessage, bytes) + + if errWrite != nil && errWrite != io.EOF { + logr.WithError(errWrite).Errorf("serveLogHandler Write returned error") + break + } + //logr.Debugf("wrote %d bytes", n) + logr.Debugf("wrote bytes") + } + } + + // either EOF or error reading from trainer + if err != nil { + logr.WithError(err).Debugf("Breaking from Recv() loop") + break + } + time.Sleep(time.Millisecond * 2) + } + //} +} + +func newServeLogHandlerForStorage(params models.GetLogsParams, w http.ResponseWriter, storage storageClient.StorageClient, stream grpc_storage.Storage_GetTrainedModelLogsClient, + logr *logger.LocLoggingEntry, cancel context.CancelFunc, isMetrics bool) { + r := params.HTTPRequest + upgrader := newWebsocket.Upgrader{ + CheckOrigin: func(r *http.Request) bool { + return true + }} + w.Header().Add("Access-Control-Allow-Origin", "*") + c, err := upgrader.Upgrade(w, r, nil) + if err != nil { + logger.GetLogger().Error("upgrade failed: ", err.Error()) + return + } + defer c.Close() + defer cancel() + + // TODO: The second param should be log.LogCategoryServeLogHandler, but, for the + // moment, just use the hard coded string, until the code is committed in dlaas-commons. + + logr.Debugf("Going into Recv() loop") + var onelinebytes []byte + for { + logFrame, err := stream.Recv() + if err != nil { + logr.Error(err.Error()) + } + if err == io.EOF { + logr.Infof("serveLogHandler stream.Recv() is EOF") + break + } + if logFrame != nil && len(logFrame.Data) > 0 { + if isMetrics { + + byteReader := bytes.NewReader(logFrame.Data) + bufioReader := bufio.NewReader(byteReader) + for { + lineBytes, err := bufioReader.ReadBytes('\n') + if lineBytes != nil { + lenRead := len(lineBytes) + + if err == nil || (err == io.EOF && lenRead > 0 && lineBytes[lenRead-1] == '}') { + if onelinebytes != nil { + lineBytes = append(onelinebytes[:], lineBytes[:]...) + onelinebytes = nil + } + // We should just scan for the first non-white space. + if len(bytes.TrimSpace(lineBytes)) == 0 { + continue + } + + //ws.Write(lineBytes) + err = c.WriteMessage(newWebsocket.TextMessage, lineBytes) + // Take a short snooze, just to not take over CPU, etc. + // time.Sleep(time.Millisecond * 250) + } else { + if onelinebytes == nil { + onelinebytes = lineBytes + } else { + onelinebytes = append(onelinebytes[:], lineBytes[:]...) + } + } + } + if err == io.EOF { + break + } + } + logr.Debug("==== done processing logFrame.Data ====") + + } else { + var bytes []byte + bytes = logFrame.Data + //n, errWrite := ws.Write(bytes) + errWrite := c.WriteMessage(newWebsocket.TextMessage, bytes) + + if errWrite != nil && errWrite != io.EOF { + logr.WithError(errWrite).Errorf("serveLogHandler Write returned error") + break + } + //logr.Debugf("wrote %d bytes", n) + logr.Debugf("wrote bytes") + } + } + + // either EOF or error reading from trainer + if err != nil { + logr.WithError(err).Debugf("Breaking from Recv() loop") + break + } + time.Sleep(time.Millisecond * 2) + } + //} +} + +func getTrainingLogsWS(trainer trainerClient.TrainerClient, params models.GetLogsParams, + stream grpc_trainer_v2.Trainer_GetTrainedModelLogsClient, + cancel context.CancelFunc, isMetrics bool) middleware.Responder { + + logr := logger.LocLogger(logWithGetLogsParams(params)) + logr.Debugf("Setting up web socket: %v", params.HTTPRequest.Header) + + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + logr.Debugf("In responderFunc") + handler := serveLogHandler(trainer, stream, logr, cancel, isMetrics) + handler.ServeHTTP(w, params.HTTPRequest) + + }) +} + +func newGetTrainingLogsWS(trainer trainerClient.TrainerClient, params models.GetLogsParams, + stream grpc_trainer_v2.Trainer_GetTrainedModelLogsClient, + cancel context.CancelFunc, isMetrics bool) middleware.Responder { + + logr := logger.LocLogger(logWithGetLogsParams(params)) + logr.Debugf("Setting up web socket: %v", params.HTTPRequest.Header) + + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + logr.Debugf("In responderFunc") + newServeLogHandler(params, w, trainer, stream, logr, cancel, isMetrics) + }) +} + +func newGetTrainingLogsWSForStorage(storage storageClient.StorageClient, params models.GetLogsParams, + stream grpc_storage.Storage_GetTrainedModelLogsClient, + cancel context.CancelFunc, isMetrics bool) middleware.Responder { + + logr := logger.LocLogger(logWithGetLogsParams(params)) + logr.Debugf("Setting up web socket: %v", params.HTTPRequest.Header) + + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + logr.Debugf("In responderFunc") + newServeLogHandlerForStorage(params, w, storage, stream, logr, cancel, isMetrics) + }) +} + +func getNewTrainingLogsWSTest(ctx context.Context, params models.GetLogsParams, + cancel context.CancelFunc) middleware.Responder { + + logr := logger.LocLogger(logWithGetLogsParams(params)) + logr.Debugf("Setting up web socket test: %v", params.HTTPRequest.Header) + + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + //serveLogHandlerTest(logr, cancel).ServeHTTP(w, params.HTTPRequest) + newWebsocketHandler(w, params.HTTPRequest) + }) + +} + +func newWebsocketHandler(w http.ResponseWriter, r *http.Request) { + upgrader := newWebsocket.Upgrader{ + CheckOrigin: func(r *http.Request) bool { + return true + }} + w.Header().Add("Access-Control-Allow-Origin", "*") + c, err := upgrader.Upgrade(w, r, nil) + if err != nil { + logger.GetLogger().Error("upgrade:", err) + return + } + defer c.Close() + for { + s := time.Now().String() + err = c.WriteMessage(newWebsocket.TextMessage, []byte(s)) + if err != nil { + logger.GetLogger().Error("write:", err) + break + } + time.Sleep(1 * time.Second) + } + +} + +func serveLogHandlerTest(logr *logger.LocLoggingEntry, cancel context.CancelFunc) websocket.Handler { + logr.Debugf("In serveLogHandlerTest") + + return func(ws *websocket.Conn) { + defer ws.Close() + defer cancel() + for i := 0; i < 30; i++ { + currentTime := time.Now().Local() + currentTimeString := currentTime.Format(" Sat Mar 7 11:06:39 EST 2015\n") + logr.Debugf("In websocket test function, writing %s", currentTimeString) + _, writeStringError := io.WriteString(ws, currentTimeString) + if writeStringError != nil { + logr.WithError(writeStringError).Debug("WriteString failed") + break + } + time.Sleep(2 * time.Second) + } + } +} + +func getTrainingLogsWSTest(ctx context.Context, params models.GetLogsParams, + cancel context.CancelFunc) middleware.Responder { + + logr := logger.LocLogger(logWithGetLogsParams(params)) + logr.Debugf("Setting up web socket test: %v", params.HTTPRequest.Header) + + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + serveLogHandlerTest(logr, cancel).ServeHTTP(w, params.HTTPRequest) + }) + +} + +// FIXME MLSS Change: more properties for result +func createModel(req *http.Request, job *grpc_storage.Job, logr *logger.LocLoggingEntry) *restmodels.Model { + memUnit := job.Training.Resources.MemoryUnit.String() + + // FIXME MLSS Change: more properties for result + //logr.Infof("createModel job.TrainingId: %v", job.TrainingId) + cpus := float64(job.Training.Resources.Cpus) + gpus := float64(job.Training.Resources.Gpus) + memory := float64(job.Training.Resources.Memory) + if math.IsNaN(cpus) { + logr.Debugf("warning, cpus IsNaN: %v", cpus) + cpus = 0 + } + if math.IsNaN(gpus) { + logr.Debugf("warning, gpus IsNaN: %v", gpus) + gpus = 0 + } + if math.IsNaN(memory) { + logr.Debugf("warning, memory IsNaN: %v", memory) + memory = 0 + } + + psM := "" + if "" != job.PsMemory { + if stringsUtil.Contains(job.PsMemory, "Gi") { + psM = job.PsMemory[0 : len(job.PsMemory)-2] + } + } + + //var tFosRequest *v1alpha1.TFosRequest + var tFosRequest *restmodels.TFosRequest + str := job.TfosRequest + unmarshal := json.Unmarshal([]byte(str), &tFosRequest) + if job.JobType == "tfos" { + if nil != unmarshal { + logr.Errorf("failed format TFosRequest with err: %v", unmarshal.Error()) + } + } + + m := &restmodels.Model{ + BasicNewModel: restmodels.BasicNewModel{ + BasicModel: restmodels.BasicModel{ + ModelID: job.TrainingId, + }, + Location: req.URL.Path + "/" + job.TrainingId, + }, + Pss: job.Pss, + PsCPU: job.PsCpu, + PsImage: job.PsImage, + PsMemory: psM, + JobType: job.JobType, + Name: job.ModelDefinition.Name, + Description: job.ModelDefinition.Description, + Framework: &restmodels.Framework{ + Name: job.ModelDefinition.Framework.Name, + Version: job.ModelDefinition.Framework.Version, + }, + Training: &restmodels.Training{ + Command: job.Training.Command, + Cpus: cpus, + Gpus: gpus, + Memory: memory, + MemoryUnit: &memUnit, + Learners: job.Training.Resources.Learners, + InputData: job.Training.InputData, + OutputData: job.Training.OutputData, + TrainingStatus: &restmodels.TrainingStatus{ + Status: job.Status.Status.String(), + StatusDescription: job.Status.Status.String(), + StatusMessage: job.Status.StatusMessage, + ErrorCode: job.Status.ErrorCode, + Submitted: job.Status.SubmissionTimestamp, + Completed: job.Status.CompletionTimestamp, + }, + }, + + // FIXME MLSS Change: more properties for result + JobNamespace: job.JobNamespace, + UserID: job.UserId, + SubmissionTimestamp: job.Status.SubmissionTimestamp, + CompletedTimestamp: job.Status.CompletionTimestamp, + // FIXME MLSS Change: v_1.4.1 added field JobAlert + JobAlert: job.JobAlert, + ExpRunID: job.ExpRunId, + ExpName: job.ExpName, + FileName: job.FileName, + FilePath: job.FilePath, + TFosRequest: tFosRequest, + } + + // add data stores + for i, v := range job.Datastores { + m.DataStores = append(m.DataStores, &restmodels.Datastore{ + DataStoreID: v.Id, + Type: v.Type, + Connection: v.Connection, + }) + for k, v := range job.Datastores[i].Fields { + m.DataStores[i].Connection[k] = v + } + } + return m +} + +func getTrainingJobFromStorage(params models.GetModelParams) (*grpc_storage.GetResponse, middleware.Responder) { + + getLogger := logger.GetLogger() + // FIXME MLSS Change: auth user in restapi + rresp, errResp := checkJobVisibility(params.HTTPRequest.Context(), params.ModelID, getUserID(params.HTTPRequest), params.HTTPRequest.Header.Get(cc.CcAuthToken)) + if errResp != nil { + getLogger.Errorf("getTrainingJobFromSorage, checkJobVisibility failed.") + return nil, errResp + } + + return rresp, middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + w.WriteHeader(http.StatusOK) + //FIXME MLSS Change: change Description to Msg + payload, _ := json.Marshal(&restmodels.Error{ + Error: "OK", + Msg: "", + Code: http.StatusOK, + }) + w.Write(payload) + }) +} + +func getErrorResultWithPayload(error string, status int32, err error) middleware.Responder { + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + w.WriteHeader(http.StatusForbidden) + //FIXME MLSS Change: change Description to Msg + payload, _ := json.Marshal(restmodels.Error{ + Error: error, + Code: status, + Msg: err.Error(), + }) + w.Write(payload) + }) +} + +func checkJobVisibility(ctx context.Context, modelID string, userId string, ccAuthToken string) (*grpc_storage.GetResponse, middleware.Responder) { + operation := "checkJobVisibility" + //logr := logger.LocLogger(log.StandardLogger().WithField("module", "restapi,models_impl.go,checkJobVisibility")) + //trainer, err := trainerClient.NewTrainer() + storage, err := storageClient.NewStorage() + defer storage.Close() + if err != nil { + logger.GetLogger().Error("New Storage Client Error: " + err.Error()) + return nil, getErrorResultWithPayload("New Client Error", http.StatusInternalServerError, err) + } + + //rresp, err := trainer.Client().GetTrainingJob(ctx, &grpc_trainer_v2.GetRequest{ + rresp, err := storage.Client().GetTrainingJob(ctx, &grpc_storage.GetRequest{ + TrainingId: modelID, + UserId: userId, + }) + if err != nil { + logger.GetLogger().Errorf("Trainer GetTrainingJob service call failed") + if grpc.Code(err) == codes.PermissionDenied { + //return nil, getErrorResultWithPayload("forbidden", http.StatusForbidden, err) + return nil, getErrorResultWithPayload("forbidden", http.StatusForbidden, err) + } + if grpc.Code(err) == codes.NotFound { + //FIXME MLSS Change: change Description to Msg + return nil, models.NewGetModelNotFound().WithPayload(&restmodels.Error{ + Error: "Not found", + Code: http.StatusNotFound, + Msg: "", + }) + } + return nil, httpResponseHandle(http.StatusInternalServerError, err, operation, []byte(err.Error())) + } + + if rresp.Job == nil { + //FIXME MLSS Change: change Description to Msg + return nil, models.NewGetModelNotFound().WithPayload(&restmodels.Error{ + Error: "Not found", + Code: http.StatusNotFound, + Msg: "", + }) + } + + // FIXME MLSS Change: auth user in restapi + userFromJob := rresp.Job.UserId + logger.GetLogger().Debugf("userFromJob: %v and userId: %v", userFromJob, userId) + if userFromJob != userId { + nsFromJob := rresp.Job.JobNamespace + ccAddress := viper.GetString(config.CCAddress) + ccClient := cc.GetCcClient(ccAddress) + bodyForRole, err := ccClient.CheckNamespace(ccAuthToken, nsFromJob) + if err != nil { + logger.GetLogger().Error(err.Error()) + return nil, getErrorResultWithPayload("", http.StatusInternalServerError, err) + } + var role string + err = commonModels.GetResultData(bodyForRole, &role) + if err != nil { + logger.GetLogger().Error("GetResultData failed") + return nil, getErrorResultWithPayload("", http.StatusInternalServerError, err) + } + if role == "GU" { + logger.GetLogger().Error("GU only access his own notebook") + return nil, getErrorResultWithPayload("StatusForbidden", http.StatusForbidden, err) + } + } + return rresp, nil +} + +func checkForJobParams(m *ManifestV1, params models.PostModelParams, codeSelector string, logr *logger.LocLoggingEntry) ([]byte, error) { + var modelDefinition []byte = nil + if codeSelector == codeFile && nil == params.ModelDefinition && m.ExpName != "" { + return nil, errors.New("ModelDefinition can't be empty when codeSelector is codeFile") + } + if codeSelector == codeFile && nil != m.DataStores[0].TrainingWorkspace && "" != m.DataStores[0].TrainingWorkspace.Container { + return nil, errors.New("training_work must be empty when codeSelector is codeFile") + } + if codeSelector == codeFile && nil != params.ModelDefinition { + modelDefinitionData, err := ioutil.ReadAll(params.ModelDefinition) + if err != nil { + logr.Errorf("Cannot read 'model_definition' parameter: %s", err.Error()) + return nil, err + + } + modelDefinition = modelDefinitionData + } + if codeSelector == storagePath && nil != params.ModelDefinition { + return nil, errors.New("ModelDefinition must be empty when codeSelector is storagePath") + } + if codeSelector == storagePath && (nil == m.DataStores[0].TrainingWorkspace || (nil != m.DataStores[0].TrainingWorkspace && "" == m.DataStores[0].TrainingWorkspace.Container)) { + return nil, errors.New("training_work can't be empty when codeSelector is storagePath") + } + return modelDefinition, nil +} + +func checkAlertParams(mannifest *ManifestV1, logr *logger.LocLoggingEntry) error { + //receiver := mannifest.Receiver + jobAlert := mannifest.JobAlert + codeSelector := mannifest.CodeSelector + event := jobAlert["event"] + deadline := jobAlert["deadline"] + overtime := jobAlert["overtime"] + if nil != event && len(event) > 0 { + for _, eMap := range event { + alertLevel := eMap["alert_level"] + receiver := eMap["receiver"] + eventChecker := eMap["event_checker"] + if receiver == "" || eventChecker == "" { + return errors.New("event receiver can't be nil") + } + if eventChecker != jobmonitor.FAILED && eventChecker != jobmonitor.COMPLETED { + return errors.New("event_checker must be FAILED or COMPLETED") + } + if alertLevel != "" && alertLevel != jobmonitor.CRITICAL && alertLevel != jobmonitor.MAJOR && alertLevel != jobmonitor.MINOR && alertLevel != jobmonitor.WARNING && alertLevel != jobmonitor.INFO { + return errors.New("event alert_level must be critical, major, minor, warning, info") + } + } + } + + if nil != deadline && len(deadline) > 0 { + for _, dMap := range deadline { + alertLevel := dMap["alert_level"] + interval, atoErr := strconv.Atoi(dMap["interval"]) + if atoErr != nil { + return errors.New("deadline interval parse int failed") + } + receiver := dMap["receiver"] + deadlineChecker := dMap["deadline_checker"] + if receiver == "" || deadlineChecker == "" { + return errors.New("alertLevel, receiver and deadlineChecker can't be nil") + } + _, err := time.Parse("2006-01-02 15:04:05", deadlineChecker) + if err != nil { + return errors.New("deadline_checker pattern must be 2006-01-02 15:04:05 ") + } + if alertLevel != "" && alertLevel != jobmonitor.CRITICAL && alertLevel != jobmonitor.MAJOR && alertLevel != jobmonitor.MINOR && alertLevel != jobmonitor.WARNING && alertLevel != jobmonitor.INFO { + return errors.New("deadline alert_level must be critical, major, minor, warning, info") + } + if interval < 1 { + return errors.New("deadline interval has to be gretter than 0") + } + } + } + + if nil != overtime && len(overtime) > 0 { + for _, oMap := range overtime { + alertLevel := oMap["alert_level"] + interval, atoErr := strconv.Atoi(oMap["interval"]) + if atoErr != nil { + return errors.New("overtime interval parse int failed") + } + receiver := oMap["receiver"] + overtimeChecker := oMap["overtime_checker"] + + if receiver == "" || overtimeChecker == "" { + return errors.New("alertLevel, receiver and overtimeChecker can't be nil") + } + f, parseErr := strconv.ParseFloat(overtimeChecker, 64) + if parseErr != nil { + return errors.New("overtime_checker must be number") + } + if f <= 0 { + return errors.New("overtime_checker must be greater than 0") + } + if alertLevel != "" && alertLevel != jobmonitor.CRITICAL && alertLevel != jobmonitor.MAJOR && alertLevel != jobmonitor.MINOR && alertLevel != jobmonitor.WARNING && alertLevel != jobmonitor.INFO { + return errors.New("overtime alert_level must be critical, major, minor, warning, info") + } + if interval < 1 { + return errors.New("overtime interval has to be gretter than 0") + } + } + } + if mannifest.JobType != "tfos" { + if codeSelector == "" { + return errors.New("codeSelector is request") + } + if codeSelector != codeFile && codeSelector != storagePath { + return errors.New("the value of codeSelector can only be codeFile or storagePath") + } + } + return nil +} + +func httpResponseHandle(status int, err error, operation string, resultMsg []byte) middleware.Responder { + result := commonModels.Result{ + Code: "200", + Msg: "success", + Result: json.RawMessage(resultMsg), + } + + if resultMsg == nil { + jsonStr, err := json.Marshal(operation + " " + "success") + if err != nil { + logger.GetLogger().Error(err.Error()) + } + result.Result = jsonStr + } + + if status != http.StatusOK { + result.Code = strconv.Itoa(status) + result.Msg = "Error" + jsonStr, _ := json.Marshal(operation + " " + " Error") + result.Result = jsonStr + if err != nil { + logger.GetLogger().Error("Operation: " + operation + ";" + "Error: " + err.Error()) + jsonStr, _ := json.Marshal(operation + " " + " error: " + err.Error()) + result.Result = jsonStr + } + } + + return middleware.ResponderFunc(func(w http.ResponseWriter, _ runtime.Producer) { + w.WriteHeader(status) + response, err := json.Marshal(result) + _, err = w.Write(response) + if err != nil { + logger.GetLogger().Error(err.Error()) + } + }) +} diff --git a/di/restapi/api_v1/server/server.go b/di/restapi/api_v1/server/server.go new file mode 100644 index 0000000..ecb9a52 --- /dev/null +++ b/di/restapi/api_v1/server/server.go @@ -0,0 +1,507 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package server + +import ( + "context" + "crypto/tls" + "crypto/x509" + "errors" + "fmt" + "io/ioutil" + "log" + "net" + "net/http" + "os" + "os/signal" + "strconv" + "sync" + "sync/atomic" + "syscall" + "time" + + "github.com/go-openapi/runtime/flagext" + "github.com/go-openapi/swag" + flags "github.com/jessevdk/go-flags" + "golang.org/x/net/netutil" + + "webank/DI/restapi/api_v1/server/operations" +) + +const ( + schemeHTTP = "http" + schemeHTTPS = "https" + schemeUnix = "unix" +) + +var defaultSchemes []string + +func init() { + defaultSchemes = []string{ + schemeHTTPS, + } +} + +// NewServer creates a new api di server but does not configure it +func NewServer(api *operations.DiAPI) *Server { + s := new(Server) + + s.shutdown = make(chan struct{}) + s.api = api + s.interrupt = make(chan os.Signal, 1) + return s +} + +// ConfigureAPI configures the API and handlers. +func (s *Server) ConfigureAPI() { + if s.api != nil { + s.handler = configureAPI(s.api) + } +} + +// ConfigureFlags configures the additional flags defined by the handlers. Needs to be called before the parser.Parse +func (s *Server) ConfigureFlags() { + if s.api != nil { + configureFlags(s.api) + } +} + +// Server for the di API +type Server struct { + EnabledListeners []string `long:"scheme" description:"the listeners to enable, this can be repeated and defaults to the schemes in the swagger spec"` + CleanupTimeout time.Duration `long:"cleanup-timeout" description:"grace period for which to wait before killing idle connections" default:"10s"` + GracefulTimeout time.Duration `long:"graceful-timeout" description:"grace period for which to wait before shutting down the server" default:"15s"` + MaxHeaderSize flagext.ByteSize `long:"max-header-size" description:"controls the maximum number of bytes the server will read parsing the request header's keys and values, including the request line. It does not limit the size of the request body." default:"1MiB"` + + SocketPath flags.Filename `long:"socket-path" description:"the unix socket to listen on" default:"/var/run/di.sock"` + domainSocketL net.Listener + + Host string `long:"host" description:"the IP to listen on" default:"localhost" env:"HOST"` + Port int `long:"port" description:"the port to listen on for insecure connections, defaults to a random value" env:"PORT"` + ListenLimit int `long:"listen-limit" description:"limit the number of outstanding requests"` + KeepAlive time.Duration `long:"keep-alive" description:"sets the TCP keep-alive timeouts on accepted connections. It prunes dead TCP connections ( e.g. closing laptop mid-download)" default:"3m"` + ReadTimeout time.Duration `long:"read-timeout" description:"maximum duration before timing out read of the request" default:"30s"` + WriteTimeout time.Duration `long:"write-timeout" description:"maximum duration before timing out write of the response" default:"60s"` + httpServerL net.Listener + + TLSHost string `long:"tls-host" description:"the IP to listen on for tls, when not specified it's the same as --host" env:"TLS_HOST"` + TLSPort int `long:"tls-port" description:"the port to listen on for secure connections, defaults to a random value" env:"TLS_PORT"` + TLSCertificate flags.Filename `long:"tls-certificate" description:"the certificate to use for secure connections" env:"TLS_CERTIFICATE"` + TLSCertificateKey flags.Filename `long:"tls-key" description:"the private key to use for secure connections" env:"TLS_PRIVATE_KEY"` + TLSCACertificate flags.Filename `long:"tls-ca" description:"the certificate authority file to be used with mutual tls auth" env:"TLS_CA_CERTIFICATE"` + TLSListenLimit int `long:"tls-listen-limit" description:"limit the number of outstanding requests"` + TLSKeepAlive time.Duration `long:"tls-keep-alive" description:"sets the TCP keep-alive timeouts on accepted connections. It prunes dead TCP connections ( e.g. closing laptop mid-download)"` + TLSReadTimeout time.Duration `long:"tls-read-timeout" description:"maximum duration before timing out read of the request"` + TLSWriteTimeout time.Duration `long:"tls-write-timeout" description:"maximum duration before timing out write of the response"` + httpsServerL net.Listener + + api *operations.DiAPI + handler http.Handler + hasListeners bool + shutdown chan struct{} + shuttingDown int32 + interrupted bool + interrupt chan os.Signal +} + +// Logf logs message either via defined user logger or via system one if no user logger is defined. +func (s *Server) Logf(f string, args ...interface{}) { + if s.api != nil && s.api.Logger != nil { + s.api.Logger(f, args...) + } else { + log.Printf(f, args...) + } +} + +// Fatalf logs message either via defined user logger or via system one if no user logger is defined. +// Exits with non-zero status after printing +func (s *Server) Fatalf(f string, args ...interface{}) { + if s.api != nil && s.api.Logger != nil { + s.api.Logger(f, args...) + os.Exit(1) + } else { + log.Fatalf(f, args...) + } +} + +// SetAPI configures the server with the specified API. Needs to be called before Serve +func (s *Server) SetAPI(api *operations.DiAPI) { + if api == nil { + s.api = nil + s.handler = nil + return + } + + s.api = api + s.handler = configureAPI(api) +} + +func (s *Server) hasScheme(scheme string) bool { + schemes := s.EnabledListeners + if len(schemes) == 0 { + schemes = defaultSchemes + } + + for _, v := range schemes { + if v == scheme { + return true + } + } + return false +} + +// Serve the api +func (s *Server) Serve() (err error) { + if !s.hasListeners { + if err = s.Listen(); err != nil { + return err + } + } + + // set default handler, if none is set + if s.handler == nil { + if s.api == nil { + return errors.New("can't create the default handler, as no api is set") + } + + s.SetHandler(s.api.Serve(nil)) + } + + wg := new(sync.WaitGroup) + once := new(sync.Once) + signalNotify(s.interrupt) + go handleInterrupt(once, s) + + servers := []*http.Server{} + wg.Add(1) + go s.handleShutdown(wg, &servers) + + if s.hasScheme(schemeUnix) { + domainSocket := new(http.Server) + domainSocket.MaxHeaderBytes = int(s.MaxHeaderSize) + domainSocket.Handler = s.handler + if int64(s.CleanupTimeout) > 0 { + domainSocket.IdleTimeout = s.CleanupTimeout + } + + configureServer(domainSocket, "unix", string(s.SocketPath)) + + servers = append(servers, domainSocket) + wg.Add(1) + s.Logf("Serving di at unix://%s", s.SocketPath) + go func(l net.Listener) { + defer wg.Done() + if err := domainSocket.Serve(l); err != nil && err != http.ErrServerClosed { + s.Fatalf("%v", err) + } + s.Logf("Stopped serving di at unix://%s", s.SocketPath) + }(s.domainSocketL) + } + + if s.hasScheme(schemeHTTP) { + httpServer := new(http.Server) + httpServer.MaxHeaderBytes = int(s.MaxHeaderSize) + httpServer.ReadTimeout = s.ReadTimeout + httpServer.WriteTimeout = s.WriteTimeout + httpServer.SetKeepAlivesEnabled(int64(s.KeepAlive) > 0) + if s.ListenLimit > 0 { + s.httpServerL = netutil.LimitListener(s.httpServerL, s.ListenLimit) + } + + if int64(s.CleanupTimeout) > 0 { + httpServer.IdleTimeout = s.CleanupTimeout + } + + httpServer.Handler = s.handler + + configureServer(httpServer, "http", s.httpServerL.Addr().String()) + + servers = append(servers, httpServer) + wg.Add(1) + s.Logf("Serving di at http://%s", s.httpServerL.Addr()) + go func(l net.Listener) { + defer wg.Done() + if err := httpServer.Serve(l); err != nil && err != http.ErrServerClosed { + s.Fatalf("%v", err) + } + s.Logf("Stopped serving di at http://%s", l.Addr()) + }(s.httpServerL) + } + + if s.hasScheme(schemeHTTPS) { + httpsServer := new(http.Server) + httpsServer.MaxHeaderBytes = int(s.MaxHeaderSize) + httpsServer.ReadTimeout = s.TLSReadTimeout + httpsServer.WriteTimeout = s.TLSWriteTimeout + httpsServer.SetKeepAlivesEnabled(int64(s.TLSKeepAlive) > 0) + if s.TLSListenLimit > 0 { + s.httpsServerL = netutil.LimitListener(s.httpsServerL, s.TLSListenLimit) + } + if int64(s.CleanupTimeout) > 0 { + httpsServer.IdleTimeout = s.CleanupTimeout + } + httpsServer.Handler = s.handler + + // Inspired by https://blog.bracebin.com/achieving-perfect-ssl-labs-score-with-go + httpsServer.TLSConfig = &tls.Config{ + // Causes servers to use Go's default ciphersuite preferences, + // which are tuned to avoid attacks. Does nothing on clients. + PreferServerCipherSuites: true, + // Only use curves which have assembly implementations + // https://github.com/golang/go/tree/master/src/crypto/elliptic + CurvePreferences: []tls.CurveID{tls.CurveP256}, + // Use modern tls mode https://wiki.mozilla.org/Security/Server_Side_TLS#Modern_compatibility + NextProtos: []string{"h2", "http/1.1"}, + // https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet#Rule_-_Only_Support_Strong_Protocols + MinVersion: tls.VersionTLS12, + // These ciphersuites support Forward Secrecy: https://en.wikipedia.org/wiki/Forward_secrecy + CipherSuites: []uint16{ + tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, + tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, + tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, + tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, + }, + } + + // build standard config from server options + if s.TLSCertificate != "" && s.TLSCertificateKey != "" { + httpsServer.TLSConfig.Certificates = make([]tls.Certificate, 1) + httpsServer.TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(string(s.TLSCertificate), string(s.TLSCertificateKey)) + if err != nil { + return err + } + } + + if s.TLSCACertificate != "" { + // include specified CA certificate + caCert, caCertErr := ioutil.ReadFile(string(s.TLSCACertificate)) + if caCertErr != nil { + return caCertErr + } + caCertPool := x509.NewCertPool() + ok := caCertPool.AppendCertsFromPEM(caCert) + if !ok { + return fmt.Errorf("cannot parse CA certificate") + } + httpsServer.TLSConfig.ClientCAs = caCertPool + httpsServer.TLSConfig.ClientAuth = tls.RequireAndVerifyClientCert + } + + // call custom TLS configurator + configureTLS(httpsServer.TLSConfig) + + if len(httpsServer.TLSConfig.Certificates) == 0 && httpsServer.TLSConfig.GetCertificate == nil { + // after standard and custom config are passed, this ends up with no certificate + if s.TLSCertificate == "" { + if s.TLSCertificateKey == "" { + s.Fatalf("the required flags `--tls-certificate` and `--tls-key` were not specified") + } + s.Fatalf("the required flag `--tls-certificate` was not specified") + } + if s.TLSCertificateKey == "" { + s.Fatalf("the required flag `--tls-key` was not specified") + } + // this happens with a wrong custom TLS configurator + s.Fatalf("no certificate was configured for TLS") + } + + // must have at least one certificate or panics + httpsServer.TLSConfig.BuildNameToCertificate() + + configureServer(httpsServer, "https", s.httpsServerL.Addr().String()) + + servers = append(servers, httpsServer) + wg.Add(1) + s.Logf("Serving di at https://%s", s.httpsServerL.Addr()) + go func(l net.Listener) { + defer wg.Done() + if err := httpsServer.Serve(l); err != nil && err != http.ErrServerClosed { + s.Fatalf("%v", err) + } + s.Logf("Stopped serving di at https://%s", l.Addr()) + }(tls.NewListener(s.httpsServerL, httpsServer.TLSConfig)) + } + + wg.Wait() + return nil +} + +// Listen creates the listeners for the server +func (s *Server) Listen() error { + if s.hasListeners { // already done this + return nil + } + + if s.hasScheme(schemeHTTPS) { + // Use http host if https host wasn't defined + if s.TLSHost == "" { + s.TLSHost = s.Host + } + // Use http listen limit if https listen limit wasn't defined + if s.TLSListenLimit == 0 { + s.TLSListenLimit = s.ListenLimit + } + // Use http tcp keep alive if https tcp keep alive wasn't defined + if int64(s.TLSKeepAlive) == 0 { + s.TLSKeepAlive = s.KeepAlive + } + // Use http read timeout if https read timeout wasn't defined + if int64(s.TLSReadTimeout) == 0 { + s.TLSReadTimeout = s.ReadTimeout + } + // Use http write timeout if https write timeout wasn't defined + if int64(s.TLSWriteTimeout) == 0 { + s.TLSWriteTimeout = s.WriteTimeout + } + } + + if s.hasScheme(schemeUnix) { + domSockListener, err := net.Listen("unix", string(s.SocketPath)) + if err != nil { + return err + } + s.domainSocketL = domSockListener + } + + if s.hasScheme(schemeHTTP) { + listener, err := net.Listen("tcp", net.JoinHostPort(s.Host, strconv.Itoa(s.Port))) + if err != nil { + return err + } + + h, p, err := swag.SplitHostPort(listener.Addr().String()) + if err != nil { + return err + } + s.Host = h + s.Port = p + s.httpServerL = listener + } + + if s.hasScheme(schemeHTTPS) { + tlsListener, err := net.Listen("tcp", net.JoinHostPort(s.TLSHost, strconv.Itoa(s.TLSPort))) + if err != nil { + return err + } + + sh, sp, err := swag.SplitHostPort(tlsListener.Addr().String()) + if err != nil { + return err + } + s.TLSHost = sh + s.TLSPort = sp + s.httpsServerL = tlsListener + } + + s.hasListeners = true + return nil +} + +// Shutdown server and clean up resources +func (s *Server) Shutdown() error { + if atomic.CompareAndSwapInt32(&s.shuttingDown, 0, 1) { + close(s.shutdown) + } + return nil +} + +func (s *Server) handleShutdown(wg *sync.WaitGroup, serversPtr *[]*http.Server) { + // wg.Done must occur last, after s.api.ServerShutdown() + // (to preserve old behaviour) + defer wg.Done() + + <-s.shutdown + + servers := *serversPtr + + ctx, cancel := context.WithTimeout(context.TODO(), s.GracefulTimeout) + defer cancel() + + shutdownChan := make(chan bool) + for i := range servers { + server := servers[i] + go func() { + var success bool + defer func() { + shutdownChan <- success + }() + if err := server.Shutdown(ctx); err != nil { + // Error from closing listeners, or context timeout: + s.Logf("HTTP server Shutdown: %v", err) + } else { + success = true + } + }() + } + + // Wait until all listeners have successfully shut down before calling ServerShutdown + success := true + for range servers { + success = success && <-shutdownChan + } + if success { + s.api.ServerShutdown() + } +} + +// GetHandler returns a handler useful for testing +func (s *Server) GetHandler() http.Handler { + return s.handler +} + +// SetHandler allows for setting a http handler on this server +func (s *Server) SetHandler(handler http.Handler) { + s.handler = handler +} + +// UnixListener returns the domain socket listener +func (s *Server) UnixListener() (net.Listener, error) { + if !s.hasListeners { + if err := s.Listen(); err != nil { + return nil, err + } + } + return s.domainSocketL, nil +} + +// HTTPListener returns the http listener +func (s *Server) HTTPListener() (net.Listener, error) { + if !s.hasListeners { + if err := s.Listen(); err != nil { + return nil, err + } + } + return s.httpServerL, nil +} + +// TLSListener returns the https listener +func (s *Server) TLSListener() (net.Listener, error) { + if !s.hasListeners { + if err := s.Listen(); err != nil { + return nil, err + } + } + return s.httpsServerL, nil +} + +func handleInterrupt(once *sync.Once, s *Server) { + once.Do(func() { + for _ = range s.interrupt { + if s.interrupted { + s.Logf("Server already shutting down") + continue + } + s.interrupted = true + s.Logf("Shutting down... ") + if err := s.Shutdown(); err != nil { + s.Logf("HTTP server Shutdown: %v", err) + } + } + }) +} + +func signalNotify(interrupt chan<- os.Signal) { + signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) +} diff --git a/di/restapi/api_v1/swagger/swagger.yml b/di/restapi/api_v1/swagger/swagger.yml new file mode 100644 index 0000000..fbf4cbd --- /dev/null +++ b/di/restapi/api_v1/swagger/swagger.yml @@ -0,0 +1,863 @@ +# +# Copyright 2017-2018 IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +swagger: '2.0' +info: + title: Prophecis Rest Service + description: | + Prophecis Rest Service + version: "1.0.0" +host: di.prophecis.com +schemes: + - https +basePath: / +consumes: + - application/json +produces: + - application/json + +paths: + /di/v1/models: + post: + tags: + - Models + summary: Trains a new deep learning model. + description: | + Trains a deep neural network written in a DL framework supported by the DLaaS platform (such as Caffe, Tensorflow, etc.). The model code has to be uploaded and configuration parameters have to be provided. + operationId: postModel + consumes: + - multipart/form-data + produces: + - application/json + parameters: + - name: model_definition + in: formData + description: The deep learning model code as compressed archive (ZIP). + required: false + type: file + - name: manifest + in: formData + description: The manifest providing configuration for the deep learning model, the training data and the training execution. + required: true + type: file + - name: version + in: query + description: The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + required: true + type: string + default: "2017-02-13" + responses: + 201: + description: Deep learning model successfully accepted. + schema: + $ref: "#/definitions/BasicNewModel" + headers: + Location: + description: Location header containing the model id. + type: string + 400: + description: Error in the the model_definition or manifest. + schema: + $ref: '#/definitions/Error' + 401: + description: Unauthorized + schema: + $ref: '#/definitions/Error' + get: + tags: + - Models + summary: Get a list of available deep learning models. + description: | + Get a list of all available deep learning models and their configuration that a user can see. + operationId: listModels + parameters: + - name: version + in: query + description: The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + required: true + type: string + default: "2017-02-13" + - name: userid + in: query + description: owner's userid. + required: false + type: string + default: "" + - name: namespace + in: query + description: job's namespace. + required: false + type: string + default: "" + - name: page + in: query + description: page number. + required: false + type: string + default: "" + - name: size + in: query + description: entity number per page. + required: false + type: string + default: "" + - name: clusterName + in: query + description: entity clusterName + required: false + type: string + default: "" + - name: exp_id + in: query + description: experiment's id. + required: false + type: string + default: "" + - name: exp_run_id + in: query + description: experiment run's id. + required: false + type: string + default: "" + responses: + 200: + description: List of deep learning models. + schema: + $ref: '#/definitions/ModelList' + 401: + description: Unauthorized + schema: + $ref: '#/definitions/Error' + + /di/v1/models/{model_id}: + get: + tags: + - Models + summary: Get detailed information about a model. + description: | + Get detailed information about a model such as training status. + parameters: + - name: model_id + in: path + description: The id of the model. + required: true + type: string + - name: version + in: query + description: The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + required: true + type: string + default: "2017-02-13" + operationId: getModel + responses: + 200: + description: Detailed model and training information. + schema: + $ref: '#/definitions/Model' + 401: + description: Unauthorized + schema: + $ref: '#/definitions/Error' + 404: + description: Model with the given ID not found. + schema: + $ref: '#/definitions/Error' + patch: + tags: + - Models + summary: Changes the status of the training progress. + description: Changes the status of the training progress to the given `status` value (currently `halt` only). Halt means the training will be stopped and the last snapshot will be stored and can be retrieved. + operationId: patchModel + parameters: + - name: model_id + in: path + description: The id of the model. + required: true + type: string + - name: payload + in: body + description: Currently accepts "halt" as the only valid value. + required: true + schema: + $ref: '#/definitions/TrainingUpdate' + - name: version + in: query + description: The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + required: true + type: string + default: "2017-02-13" + responses: + 202: + description: Training successfully halted. + schema: + $ref: '#/definitions/BasicModel' + 400: + description: Incorrect status specified. + schema: + $ref: '#/definitions/Error' + 401: + description: Unauthorized + schema: + $ref: '#/definitions/Error' + 404: + description: Model with the given ID not found. + schema: + $ref: '#/definitions/Error' + delete: + tags: + - Models + summary: Deletes an existing model + description: | + Deletes an existing model. It does not delete any data in the user's data store. + parameters: + - name: model_id + description: The id of the model. + in: path + required: true + type: string + format: string + - name: version + in: query + description: The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + required: true + type: string + default: "2017-02-13" + operationId: deleteModel + responses: + 200: + description: Model deleted successfully. + schema: + $ref: '#/definitions/BasicModel' + 401: + description: Unauthorized + schema: + $ref: '#/definitions/Error' + 404: + description: The model cannot be found. + schema: + $ref: '#/definitions/Error' + /di/v1/models/{model_id}/export: + get: + tags: + - Models + summary: Export the model definition. + description: Export the model definition + operationId: exportModel + produces: + - application/octet-stream + parameters: + - name: model_id + description: The id of the model. + in: path + required: true + type: string + format: string + responses: + 200: + description: Model definition + schema: + type: string + format: binary + 401: + description: Unauthorized + schema: + $ref: '#/definitions/Error' + 404: + description: The model cannot be found. + schema: + $ref: '#/definitions/Error' + /di/v1/models/{model_id}/definition: + get: + tags: + - Models + summary: Downloads the model definition. + description: Downloads the model definition that was initial used for training as ZIP archive. + operationId: downloadModelDefinition + produces: + - application/octet-stream + parameters: + - name: model_id + description: The id of the model. + in: path + required: true + type: string + format: string + - name: version + in: query + description: The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + required: true + type: string + default: "2017-02-13" + responses: + 200: + description: Model definition + schema: + type: string + format: binary + 401: + description: Unauthorized + schema: + $ref: '#/definitions/Error' + 404: + description: The model cannot be found. + schema: + $ref: '#/definitions/Error' + /di/v1/models/{model_id}/trained_model: + get: + tags: + - Models + summary: Downloads the trained model. + description: Downloads the trained model as ZIP archive. + produces: + - application/octet-stream + operationId: downloadTrainedModel + parameters: + - name: model_id + description: The id of the model. + in: path + required: true + type: string + format: string + - name: version + in: query + description: The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + required: true + type: string + default: "2017-02-13" + responses: + 200: + description: Model definition + schema: + type: string + format: binary + 401: + description: Unauthorized + schema: + $ref: '#/definitions/Error' + 404: + description: The trained model cannot be found. + schema: + $ref: '#/definitions/Error' + 410: + description: If the trained model storage time has expired and it has been deleted. It only gets deleted if it not stored on an external data store. + schema: + $ref: '#/definitions/Error' + + /di/v1/models/{model_id}/logs: + get: + security: [] # disable basic auth b/c basic auth is not supported in the browser + tags: + - Models + summary: | + Get training logs as websocket stream. + description: | + Get training logs for the given model as websocket stream. Each message can contain one or more log lines. + produces: + - application/octet-stream + parameters: + - name: model_id + description: The id of the model. + in: path + required: true + type: string + format: string + - name: follow + description: Follow the log stream if true. Default false. + in: query + required: false + default: false + type: boolean + format: boolean + - name: since_time + description: An RFC3339 timestamp from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will be returned. + in: query + required: false + default: "" + type: string + format: string + - name: version + in: query + description: The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + required: true + type: string + default: "2017-02-13" + operationId: getLogs + responses: + 200: + description: Dump of the training log to-date + schema: + type: string + format: binary + 401: + description: Unauthorized + schema: + $ref: '#/definitions/Error' + 404: + description: The model cannot be found. + schema: + $ref: '#/definitions/Error' + /di/v1/logs/{model_id}/loglines: + get: + summary: Get loglines, based on query + responses: + 200: + description: "(streaming responses)" + schema: + "$ref": "#/definitions/v1LogLinesList" + 401: + description: Unauthorized + schema: + $ref: '#/definitions/Error' + operationId: getLoglines + parameters: + - name: model_id + description: The id of the model. + in: path + required: true + type: string + format: string + - name: searchType + in: query + required: false + type: string + enum: + - TERM + - NESTED + - MATCH + default: TERM + - name: since_time + description: 'Time from which to show logs. If this value precedes the time a pod was started, + only logs since the pod start will be returned. + If this value is in the future, no logs will be returned. If this value is a raw integer, it represents + the time that the metric occured: representing the number of milliseconds since midnight January 1, 1970. + If this value is a negative integer, it represents the number of lines to count backwards. + If this value is empty, the logs since the beginning of the job will be returned' + in: query + required: false + default: "" + type: string + format: string + - name: pagesize + description: 'Number of lines to output.' + in: query + required: false + type: integer + format: int32 + - name: pos + description: 'If positive, line number from start, if negative line counting from end' + in: query + required: false + type: integer + format: int64 + - name: version + in: query + description: The release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. + required: false + type: string + default: "2017-10-01" + tags: + - TrainingData + + + /di/v1/dashboards: + get: + summary: Get the dashboard belongs to a User + description: Get dashboard. + operationId: getDashboards + parameters: + - name: clusterName + in: query + description: entity clusterName + required: false + type: string + default: "" + responses: + 200: + description: OK + schema: + $ref: '#/definitions/GetDashboardsResponse' + 403: + description: Forbidden + schema: + $ref: '#/definitions/Error' + 404: + description: The dashboard cannot be found + schema: + $ref: '#/definitions/Error' + /di/v1/codeUpload: + post: + summary: upload code to s3 + description: upload code.zip to s3 + operationId: codeUpload + tags: + - Experiments + consumes: + - multipart/form-data + produces: + - application/json + parameters: + - name: file + in: formData + required: true + type: file + responses: + 200: + description: OK + schema: + $ref: '#/definitions/CodeUploadResponse' + 401: + description: Unauthorized + schema: + $ref: '#/definitions/Error' + 404: + description: Code ZIP upload failed + schema: + $ref: '#/definitions/Error' +definitions: + Endpoint: + type: object + properties: + id: + type: string + description: the id of the endpoint + url: + type: string + description: the url of the endpoint + + EndpointList: + type: object + properties: + endpoints: + type: array + items: + $ref: '#/definitions/Endpoint' + + + BasicModel: + type: object + properties: + model_id: + type: string + description: A unique id of the deep learning model. + BasicNewModel: + allOf: + - $ref: '#/definitions/BasicModel' + - properties: + location: + type: string + description: Location of the model to retrieve it. + Model: + allOf: + - $ref: '#/definitions/BasicNewModel' + - properties: + name: + type: string + description: The name of the deep learning model. + description: + type: string + description: Detailed description of deep learning model. + framework: + $ref: '#/definitions/Framework' + training: + $ref: '#/definitions/Training' + data_stores: + type: array + items: + $ref: '#/definitions/Datastore' + job_namespace: + type: string + description: job's namespace. + user_id: + type: string + description: user name. + pss: + type: string + description: Count of Param Server + ps_cpu: + type: string + description: Count of Param Server + ps_image: + type: string + description: Count of Param Server + ps_memory: + type: string + description: Count of Param Server + JobAlert: + type: string + description: Job Alert String. + JobType: + type: string + description: Job Type. + expRunId: + type: string + description: Experiment Run Id + expName: + type: string + description: Experiment Name + fileName: + type: string + description: Code File's Name + filePath: + type: string + description: Code File's Path + submission_timestamp: + type: string + description: submission timestamp of the job. + completed_timestamp: + type: string + description: completed timestamp of the job + TFosRequest: + $ref: '#/definitions/TFosRequest' + description: TFosRequest + + Framework: + type: object + properties: + name: + type: string + description: the name of the deep learning framework (e.g. caffe, torch, tensorflow) + version: + type: string + description: the version of the specific framework to use. + + Training: + type: object + properties: + command: + type: string + description: the command invoked for running the training. This is specific to the DL framework + size: + type: string + description: the pre-configured deployment size to used for training. The is used instead of directly specifying CPU, GPU, memory and learners. + cpus: + type: number + format: double + description: Number of CPUs required + gpus: + type: number + format: double + description: Number of CPUs required + memory: + type: number + format: double + description: Amount of memory required + memory_unit: + type: string + description: | + Memory unit (default: MiB) + enum: + - MiB + - MB + - GiB + - GB + default: MiB + learners: + type: integer + format: int32 + description: Number of learners required. + input_data: + type: array + description: Input data to the training, such as training data, pre-trained model. The input is specified as references to the data_store ids that contain the data. + items: + type: string + description: Reference to a data store id. + output_data: + type: array + description: Output data of the training, such as trained models. The output is specified as references to the data_store ids that contain the data. + items: + type: string + description: Reference to a data store id. + training_status: + $ref: '#/definitions/TrainingStatus' + Datastore: + type: object + properties: + data_store_id: + type: string + description: the id of the data store as defined in the manifest. + type: + type: string + description: the type of the data store as defined in the manifest. + connection: + type: object + additionalProperties: + type: string + ModelList: + type: object + properties: + models: + type: array + items: + $ref: '#/definitions/Model' + pages: + type: integer + total: + type: integer + TrainingStatus: + type: object + properties: + status: + description: Status of the training. + type: string + status_description: + description: Description of the training status. + type: string + submitted: + description: | + Training submission timestamp (Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z') + type: string + completed: + description: | + Training completion timestamp (Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z') + type: string + status_message: + description: A human readable message description of the training status. + type: string + error_code: + description: A code identifying the cause of a status message. + type: string + TrainingUpdate: + type: object + properties: + status: + description: The status action to be executed on the training job. (Currently only `halt` is supported.) + type: string + Error: + type: object + properties: + code: + type: integer + format: int32 + error: + type: string + msg: + type: string + v1LogLine: + type: object + properties: + meta: + "$ref": "#/definitions/v1MetaInfo" + line: + type: string + v1LogLinesList: + type: object + properties: + models: + type: array + items: + $ref: '#/definitions/v1LogLine' + v1MetaInfo: + type: object + properties: + training_id: + type: string + title: Unique id identifying the training job + user_id: + type: string + title: Unique id identifying the user + time: + type: number + format: int64 + description: 'Time that the metric occured: representing the number of millisecond + since midnight January 1, 1970.' + rindex: + type: number + format: int64 + title: sequential index + GetDashboardsResponse: + type: object + properties: + totalInstances: + type: string + description: total number of instances. + runningInstances: + type: string + description: number of running instances. + cpus: + type: string + description: number of cpu. + TFosRequest: + type: object + properties: + py_file: + type: array + description: PyFiles Fields. + items: + $ref: '#/definitions/Fields' + Archives: + type: array + description: Archives Fields. + items: + $ref: '#/definitions/Fields' + EntryPoint: + $ref: '#/definitions/Fields' + description: EntryPoint Fields. + TensorflowEnv: + $ref: '#/definitions/Fields' + description: Tensorflow Env Files. + Executors: + type: string + description: Queue Setting Executor Number. + ExecutorCores: + type: string + description: Queue Setting Executor Cores. + ExecutorMemory: + type: string + description: Queue Setting Executor Memory. + Queue: + type: string + description: Queue Setting. + DriverMemory: + type: string + description: Queue Setting Driver Memory. + Command: + type: string + description: Experiment Description. + Fields: + type: object + description: TFOS Archives & PyFile Fields + properties: + hdfs: + type: string + description: HDFS Path. + resource_id: + type: string + description: BML Resource ID. + version: + type: string + description: BML Resource Version. + User: + properties: + id: + type: number + format: int64 + description: Flag of Delete. + Name: + type: string + description: Flag of Delete. + Remarks: + type: string + description: Flag of Delete. + required: + - id + CodeUploadResponse: + type: object + properties: + s3Path: + type: string + format: int64 + description: S3 Path \ No newline at end of file diff --git a/di/restapi/certs/ca.crt b/di/restapi/certs/ca.crt new file mode 100644 index 0000000..f6b1e2b --- /dev/null +++ b/di/restapi/certs/ca.crt @@ -0,0 +1,32 @@ +-----BEGIN CERTIFICATE----- +MIIFdTCCA12gAwIBAgIJAMpWS0cTdN/xMA0GCSqGSIb3DQEBCwUAMFExCzAJBgNV +BAYTAlVTMQswCQYDVQQIDAJOWTEPMA0GA1UEBwwGQXJtb25rMQwwCgYDVQQKDANJ +Qk0xFjAUBgNVBAMMDWRsYWFzLmlibS5jb20wHhcNMTkwODAxMDk0MDE1WhcNMjkw +NzI5MDk0MDE1WjBRMQswCQYDVQQGEwJVUzELMAkGA1UECAwCTlkxDzANBgNVBAcM +BkFybW9uazEMMAoGA1UECgwDSUJNMRYwFAYDVQQDDA1kbGFhcy5pYm0uY29tMIIC +IjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA1qB+XOvdAPLBz7xIzsmK7wHv +S9TMFmg70yC7+cvPQlXstSn7dSPHLJ/IRBrWkVIY0qbFioHAUWaAG59AVBHt2gd9 +8FR8cMwaOAMr8mz20JHjyme01DvTuqri5UNXt1rIszI9h83lP/Ih+szrFcf2ZvsO +ROItQ2rcs/nY2/nt1A9SWO26x4Vy8UZKhml3OXFE1TzAc4cvjb8WrhwUUzNHEK0L +wq7KhQuMzSUALlBAwDzYKQPr8PXU8DKV4YO1Cs6hjYJirOCpCjq+jfRLnh3vcACb +CazUSWLUzVbpSNWa5yA3emGccetT4VZBGl/2B9dp/Gh8H75pmcyzy6ziJAFXHWeV +2lzdLDUDhuArHWIGskBUos/fW8QtkL5Suad0fMAsoRHE8sL0D+BiGF39i0Rjk6PK +cLCxcLcJyU1felQMevjMFsDShHtY82NM0rsyLFAvWfv0cH+0LVO/Mo3I3xzt6Yg1 +6UaQ9wU/qOjEw7mhqGw0fuB12HrLoBstof4Jyb3IMRkWM2TmlH918SKABuT69Dyr +c4xX90arGI5ZqafiwVSLnzam73AmKgqJSUa2AwVIL5ZMX1Au7O9wi3U9p8gjb5+M +OrjR4i2IPoz//9gwVj3pdu2tx2Ai9muH1Yi3tTh+IWMUB/LuOQSsdSd1kHt74mF5 +HzC8/3TJRyv4uNBfho0CAwEAAaNQME4wHQYDVR0OBBYEFHx/O0IFLMrFpYtbfUH6 +uojZHVNQMB8GA1UdIwQYMBaAFHx/O0IFLMrFpYtbfUH6uojZHVNQMAwGA1UdEwQF +MAMBAf8wDQYJKoZIhvcNAQELBQADggIBAKKYsj9Mjy819DOFKmE6eY+DIcBlkJGN +zknZr0qp1eieDa/ZRADowbcw18iQDiXi01BNAygMSLf6132RVMNY9p92U2s4KWom +1gfdBAykEnWuPB5uIXN7w5vV0X+Vp+kRI6op1UEhvf0fnpDKLjpfPx1wmUVZB2AR +uXq2z18b67K7PkF5fgm07ngE1O+ByIC05xEpNE9UBCSlgDLfjUFtFGPeCfhIMlYe +h2kgUY441U/ALneCv7WBR+09yUl51CEDENk4MCYq1qWqzYHuI9nlZzbU0G+JOVE0 +vPpgDkUOyZwbz244nI4jhI1cuFR00TMpXlQUe6rY3ndHImQD5NmS4kBr9xJm2e+H +5cwY+/0GjNXOxx5olXcMiLl4R9VA+KMPS9kYKl7E/J0M2WUeXjEGcGHqg12/QKiI +9fgIwd1WwkiJARDciUqYTw2GAOZrJ2lytH8WvV8lZIPUp8awUDnZzmg+iFIYlADC +jtOu4bdlnFVTGURCvPvrYA+8evtdFhXimWB/Chfof/EYv3r4qImL2/+N192jxilF +kb/OBMkmG9t97iLvJykjmTFKkzysRy53F4CVlgAAOst8MQsJ6tewmSvgHVWOT1Oh +i3eNzMCW/fTEjsf9hO/j23DHjwzZ3JIQxwNmNpdk8yIyhEQNnBQGjsZxB3MANqyO +iZcm1al/Tkxw +-----END CERTIFICATE----- diff --git a/di/restapi/certs/ca.key b/di/restapi/certs/ca.key new file mode 100644 index 0000000..d84b2a9 --- /dev/null +++ b/di/restapi/certs/ca.key @@ -0,0 +1,54 @@ +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,8541AA40D4A7C675 + +bvWKaSFRtD7S43Ya6unnQqDFbO3XwT5FiZpfDa+FJxdWMOfHKFK7p+mkOTgZ/MQu +/3CnfxVNWJvC/gKtdjAuVGCIRwg9mP0jj0to29Zee4Jmu1ymA+soPo0Ch3CCzB98 +rOMB07agJEixcTGfwqCe5zG4MO65TGg9OvisnZJcWgs47falbj4MprvkwL4m8cxj ++NAcezPRTlhFU+/09xDARvwnIwTraolz8mr49xk4g16NrDBFlOYjGwzoX4veB4QY +UNNTbDrjTeXD+kne38YEFcNNblXJ5m7ZQ0Uy+oQIHHiLRRH9DW8NmRx4p/3GybKI +XMYfMq/8Y25z7Bg/xtwof6W4RCjwQ26MDoDr2M27HrJdMbeDunl9dg6MkOZddv4E +a4V2ESwdYv/hLrP/ZXeFuG3b9qzRw7E5rLtvioIsv7pwC14rSplXJjAfnOgTp6V5 +bTjAuWBWBQBzpY1s4PoI2CCbE4zRa5hynlJBmMMn65h/3y2U1aN5P4KwmOYBiyf/ +bu7dyJwkm33FLYH0NnFNS5bamQWmD8VoSF6F7JoE/ApR8zKs+A5plwnbn8PJdWhN +gZhvwhGM0DqrZASgC+UPwkP12ICrgxm1Ci4uYou4jR/lNE5e5mNynql/etO3e0oU +CEeSpP3WZ/+e88OcT2sC1HTJbcgsBzkSXPz/0tSlq8aAr4lHKiNYqJ+TIWmoq5/x +WA6UObOBc798A5GR/Qd8taelRjDAnTlQWiyyGK5jCyZn+Nf1nKmq0t2Yk/SM/Aie +intre/nIj9IB9/+I1CfkYI06gXlWG1gWZqakTbDllVu6bvv7fzNbfcglePa21bPF +vsbtVgffN1zg4f6RbwYBebAVxcnU2KUJ11/4eEJrTvXx4ydZFTSBtiw8KFEfXb6G +6WfrOnlUcntsNdyO0LWMktR4wzaPMt/x1s/GQPUsRlMVbG1vi9RpQ2g4p7punwLU +9zjIZuZGiHMslate3EVaB1St3msJPRxEWYTrxoaowXd8MP7oqc5YXlYtvmBeIKdu +LthG/58mM/DLMZDCLw7QARoTCF6j8L6d0mr1pVFSZ2SyOM781015c5z8VewSSdN2 +gDhDTcHSloXOKJa1BtsUo+YBC85oapFEfIx7bZABauoaj3IPDSsbiQIlzqcwTu2j +7G+HFmIrjvFyKiJM1BmZCbRj3yt0mh92vBBZfCEyogPoXGZrmvbCDbsO4JMcgEfe +gELcdKAyAI53gkZHm/YaT6d/wMrH3NZOaQ87NYCdGiUXUNFmTnn1JfUCAOr6hhHd +sCiN4WvaQOL8zY2+vIvZH73AqiyKGMbHGU8/A2Xt14jDaTjWXoHwdQrlmQzV0x7z +0Gig8OI0xmcKsiLZq9Q1jOt6MdMQaeaCaUGrAer65nvl4QqEEKPVd7Wt2h8hi37U +i62wtxLrh9cTvW4LBWC0wqPkNDFZDA5cGChNKKfLzbLgeMTorZo/6TZiv0i0WBXY +WezxnrVpwtqdIsYQ3W4o2sEbJldm7sMIh/pl6s4xucLO9f4Q4WEWsbzobZ/i0m6t +GPtmrILGkLZ7VnX0XeZCG+0UzX+6Jq+dI7a8uP7NHmm0wUtInrYYUFo8reAkfzoQ +EV6SSJOJTSFC+4kZeFT40iLNri+xACKZCsebFhMqcsTMECv+pUWO6nMZQcxTi456 +CGIhh+8RmWE5DtSr0dboF7tHPViLzDy9SO47o9LApYXadoqipGdE7NHwh7JF7n18 +rsZMQmQCDV1LGxCyJrxY1c/LnJB13f3xE3/H9QqZShQjtVZ8w5kjGmHSQhnaMpaR +AmyMXfobof7l6ZpiYxYJ45xtjsdY9b4V8qH0U0WHgviJbaLxseo2SwnIJSZEzKts +JfEivN+4OETr0DcgF+ZmVLAadsngQa51b1UPF6yzGLVNDlmIBknucvY+wgnNdpiG +OOCPzNJbrymgCbFLsdDvhgNTKIph58zPEVwQx2ApLEQhhoS2kK1eBU8RDHHTnMP6 +t1M+DIQ8YbbzGQ5MBf/RhN0h2/Ur/TSsUxCujbHbmo11qkSWHLF3loZyCNR+y9Wv +JI/Hkm269QMqKjRPzwYoD8ylR8xCQcugr1US6eVcqwp6ptjkIQEq+9XtPAFpRrTs +fSZlewDxTmGb7GLdX7VEHl+/Myuq/JYIxwv12Zo0oIg8+aIo9rhir30XMthEgeuB +pcWHA59IPzQDQ19jWDuyf5ljbuXGigSZglisPY0Z1cRqgS0ErzU4Lyw0gtL7fIGn +1oe8Ae5kxzPJ3G/QLGpvQS3RwNAQ3l7qd1XHXz3jQjYLcd86pKXwedq6p6xyQMyP ++zA5bIlD2bO04XIFAZ/8JgxZcXhS3s9LFOEfXTyonyP7suIRBe1Ngt0zERzl8esQ +ckGabYyKDXRmjPGsA7pv2ZXOdSy7NmWDNSxqZkflcPRZGNJcboHDNHbYhb15LmZZ +cf583vx/6WkL/DWnU7f5Q6DGGkXAjovOlG0V2WhcE8uXUF+jALUCLhgb1GHZ/ovh +yQnrgizMmf2kkLM3uj281Y+yWn+gOHmRBvHJ/TL5uSlUA3xIeezpF79v1Ecjaw1W +sV4Uv844bchscCyy4aVoBCXGZ3yOcD18Bk9VDE0twHHaTVcdy5ADVzKcWViyH9aV +vGbxBPdnuO5P+qqMhJZvXv9zAMyESJhIImcrcqovJ9SI02+dXT4JOwLnv7g54MKe +m1ZjeVHvOBBwu+sukdfO3cjg1sbn1IAft1ki6A9DJexmzr0Cs6Z8srfYiLivmZOx +eDlMQniJ0FEvpPwXFrNqcFVQAGN821A8E1QCK/u/pmlrXnbrCMn1f3hXPYpPNvI8 +Wmd3ugzfuTB1cHeAHo/455tIZw+fpwsSP8Ok/5qYQpqlU2IWb194BgxKjK7emkH1 +fhflp4MWkia/gvIBz5bLLBC9fdI1AKh31Wq09dH/dYbCQ/pnvbObqPSn4GuxZuQJ +1XlSg0f9hRUnyEeLihDCQ6HFWRDjsvYvkt5Piz7bXqdgNuXHYoBI1omy4MVjBP4u +0NDmTO3Ihs2i2ZoLKpFxcmlWPo3ytlOVepogeF9nMncLHIYR+ka5n+i40vHLttwb +fl8RH3e7BiofxMMeMrd8gpZ/nHgXx94OUhabH/SP3bEqQZUVFiOEv78KHaoTWiTo +-----END RSA PRIVATE KEY----- diff --git a/di/restapi/certs/client.crt b/di/restapi/certs/client.crt new file mode 100644 index 0000000..cef8a83 --- /dev/null +++ b/di/restapi/certs/client.crt @@ -0,0 +1,30 @@ +-----BEGIN CERTIFICATE----- +MIIFFjCCAv4CAQEwDQYJKoZIhvcNAQELBQAwUTELMAkGA1UEBhMCVVMxCzAJBgNV +BAgMAk5ZMQ8wDQYDVQQHDAZBcm1vbmsxDDAKBgNVBAoMA0lCTTEWMBQGA1UEAwwN +ZGxhYXMuaWJtLmNvbTAeFw0xOTA4MDEwOTQwMTZaFw0yOTA3MjkwOTQwMTZaMFEx +CzAJBgNVBAYTAlVTMQswCQYDVQQIDAJOWTEPMA0GA1UEBwwGQXJtb25rMQwwCgYD +VQQKDANJQk0xFjAUBgNVBAMMDWRsYWFzLmlibS5jb20wggIiMA0GCSqGSIb3DQEB +AQUAA4ICDwAwggIKAoICAQDADXTy8edQwjrW7eof31SyaNh1l3BMlnTWPsWYtkhZ +ztKvH4sEPv4o7AJMuohBpzmSXbUe06XcNxwgd8G88LqsQZ/95PsIbZ5o/bIOEVcO +ZPFp2b0njR0V5/YhCnD6lcB0Tsm30MtvHAirCAPU1kvBmZ46e8rQaoFRzY1vav4M +7yAQHNKRuRtgDO9pXe+Npos61MgLMoJodtdGpgTt8IYRyY0sQ2JiOZEUroIFz9NI +iBFP1zicK9MMYAZpa6q2PMIQaWz+L4rZ0nELd4dGwEy7NOsN6/8qm/OyoxHTl5Uk +Ur5T/ZoOxm1msfx4oPrCPMYEoo8D2k1wLdaPJRJBipDAXYXUCQkhvVKtH8scbYU/ +xOD4kS0/Q/YdLLs7Ah/VtSPPX+NlCIBoqoULy3ocpU262+xfu54T8pIocufClmf9 +y+fF48M/3L/MkUXFihMfRkSepKvOZkEJXgT74X362Sr4W58ZKKl+mxZcPaQ89ks9 +HmNAIMQzRY9fHwyRcjqWRT7cN/D2ou/Xhun19xeJv/zwbzFsQZ0oVwVzG9+zGkeX +nNB/twccZKSOkx//oEAJXu84GEFxsDQ/p0AQl7vzVMya09NwzqKJYz5SXiGwNJWI +iOdoLsCq4Epjm8CkZqNP3gu35VlBg/93rWkhm1BcrIrmz5g4O1B7Pv3nll4+7Zfu +vwIDAQABMA0GCSqGSIb3DQEBCwUAA4ICAQB/sEJpnBTDYUy5PX4lADmPb/WNvgo1 +okfQsiedCA+9rcv+hGRkW2Mb08vwwT00TxeLnRNkcVxMWzBN7G61LAjwC5z1gVbh +NCrrZqBgwbDM9GMYri4XmeUi4mSrbHJj8HlmXmAwV/sApBcoR0Cts9ELIkn8tAU7 +Cz0k37XdcxwKNa/pstlAmkU6XitDp8WULC06IQzyiQ3gkHcWGS2zacCpA7spmSFH +s7/A6k076/mycRA+Ci09hWlkM+HKQukRvlAIBkfN8WDcdsLtOF3UJBPRLQPGUF/4 +7uy6uqbIi9RtWENYDFN2PI8ntaGCCNt4CTvxbRmu+cgIuZHHbTuhv4FeSRARA616 +ShXCDz+NhcudJOTibpQff/e4r53YQDSQLkc2oaYNQS41w/K7MGlYLQa9tceNHKUZ +lMtDV1mwfagYI2y1Yf6psLp+1wkmiaUGxJYGC097/RWJzYXTj7ljMBLVD2yb9LBB +HdplQtqXjJ6POEFXXFXrXxdHr2yZNbWGdKF0VWP+FF1iucB19r9QhJdLebV4Aytg +a4oCEZ27tmZs9fCiDWTfRalKJjbwwJhwTnLi+ZgCfJCljI/r3tcE0K0IVANF5VeT +obWJ6Pn4fwcz0cZoIeI4REqmVX6qrxGy9B/lLZtyrGj9WOcJOlpV1TBVSwuHbZA3 +xkI5km0uoIjoHw== +-----END CERTIFICATE----- diff --git a/di/restapi/certs/client.csr b/di/restapi/certs/client.csr new file mode 100644 index 0000000..5e9d1b0 --- /dev/null +++ b/di/restapi/certs/client.csr @@ -0,0 +1,27 @@ +-----BEGIN CERTIFICATE REQUEST----- +MIIEljCCAn4CAQAwUTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAk5ZMQ8wDQYDVQQH +DAZBcm1vbmsxDDAKBgNVBAoMA0lCTTEWMBQGA1UEAwwNZGxhYXMuaWJtLmNvbTCC +AiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAMANdPLx51DCOtbt6h/fVLJo +2HWXcEyWdNY+xZi2SFnO0q8fiwQ+/ijsAky6iEGnOZJdtR7Tpdw3HCB3wbzwuqxB +n/3k+whtnmj9sg4RVw5k8WnZvSeNHRXn9iEKcPqVwHROybfQy28cCKsIA9TWS8GZ +njp7ytBqgVHNjW9q/gzvIBAc0pG5G2AM72ld742mizrUyAsygmh210amBO3whhHJ +jSxDYmI5kRSuggXP00iIEU/XOJwr0wxgBmlrqrY8whBpbP4vitnScQt3h0bATLs0 +6w3r/yqb87KjEdOXlSRSvlP9mg7GbWax/Hig+sI8xgSijwPaTXAt1o8lEkGKkMBd +hdQJCSG9Uq0fyxxthT/E4PiRLT9D9h0suzsCH9W1I89f42UIgGiqhQvLehylTbrb +7F+7nhPykihy58KWZ/3L58Xjwz/cv8yRRcWKEx9GRJ6kq85mQQleBPvhffrZKvhb +nxkoqX6bFlw9pDz2Sz0eY0AgxDNFj18fDJFyOpZFPtw38Pai79eG6fX3F4m//PBv +MWxBnShXBXMb37MaR5ec0H+3BxxkpI6TH/+gQAle7zgYQXGwND+nQBCXu/NUzJrT +03DOooljPlJeIbA0lYiI52guwKrgSmObwKRmo0/eC7flWUGD/3etaSGbUFysiubP +mDg7UHs+/eeWXj7tl+6/AgMBAAGgADANBgkqhkiG9w0BAQsFAAOCAgEAJh9U+v5n +c+chhBXwDEh2ic1PiIcrypIzPol/I8GIxzOgxYrmdJt8Ux2biqFKx4PKrTlzPB7I +SUu3E/DwQg0eyGhJoHWUjG7iw7yYCAirNBNXf3qLASuFZTuSx9VAOUi/RaevmJCl +GibwciqpvC08OzYAo8qZ4+hk/dF+BBZFBZ8z8ATj8EO+K7c2Z34gbKpb5P8njN5C +Hq7U4AGPo0xzURTn2S6iP49jmOL/p7Txb9AEAVPZsuTBYUdi709jNDCVQ7XiTto1 +I0LH8YlXs4JBOIGL/9ppTi2Xb5xc+WGffiNARd9PUToXbWMjHnCEO2Aoy5Yw9ayd +h5G/GMujVmllt0bSJWfYQQymkuLxxeMe0XDZvPxQ9zKM0AtNiuyXTb/AhbsnPwda +6ep4fGT1TqYyl5qL9KEBP4EGH5WXvIUtNhuiBlwCRiZd+85KAfqllM7FLQ1YHpNQ +LZ5e9CGAadNTXuuPv3C23d3tu3jBsCNbtQyg19pEzhF7lzNYagEAOsWvv6bJyfSO +yAb4Jqxj8pi90nhodszk6l6MR1BiJwV2Arr2cR4kShbPm1K6kW+Ys5Y4E0HpEDWQ +394PPDYAx05j0eBeTaVdeAF52ykXKOCrlicPFjaqcj9YYpXAHObz/9SB36wp9Q/m +zU3S38YLQbKeRqyPTFHabAwyp8O08c+ZmGE= +-----END CERTIFICATE REQUEST----- diff --git a/di/restapi/certs/client.key b/di/restapi/certs/client.key new file mode 100644 index 0000000..a75b13c --- /dev/null +++ b/di/restapi/certs/client.key @@ -0,0 +1,51 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIJKgIBAAKCAgEAwA108vHnUMI61u3qH99UsmjYdZdwTJZ01j7FmLZIWc7Srx+L +BD7+KOwCTLqIQac5kl21HtOl3DccIHfBvPC6rEGf/eT7CG2eaP2yDhFXDmTxadm9 +J40dFef2IQpw+pXAdE7Jt9DLbxwIqwgD1NZLwZmeOnvK0GqBUc2Nb2r+DO8gEBzS +kbkbYAzvaV3vjaaLOtTICzKCaHbXRqYE7fCGEcmNLENiYjmRFK6CBc/TSIgRT9c4 +nCvTDGAGaWuqtjzCEGls/i+K2dJxC3eHRsBMuzTrDev/KpvzsqMR05eVJFK+U/2a +DsZtZrH8eKD6wjzGBKKPA9pNcC3WjyUSQYqQwF2F1AkJIb1SrR/LHG2FP8Tg+JEt +P0P2HSy7OwIf1bUjz1/jZQiAaKqFC8t6HKVNutvsX7ueE/KSKHLnwpZn/cvnxePD +P9y/zJFFxYoTH0ZEnqSrzmZBCV4E++F9+tkq+FufGSipfpsWXD2kPPZLPR5jQCDE +M0WPXx8MkXI6lkU+3Dfw9qLv14bp9fcXib/88G8xbEGdKFcFcxvfsxpHl5zQf7cH +HGSkjpMf/6BACV7vOBhBcbA0P6dAEJe781TMmtPTcM6iiWM+Ul4hsDSViIjnaC7A +quBKY5vApGajT94Lt+VZQYP/d61pIZtQXKyK5s+YODtQez7955ZePu2X7r8CAwEA +AQKCAgAfYdOLY1XuD174AfZw8NhxMsq0JGPYT/mVjLpTIu4dprssnJXlwrlbTH1v +tkdPmxjAPwm6mNEQc/znnUoOKrQGM88F+OXAUdFBzLrMq66zDnGYX1kWXmuzSa0h +ZwhhGhlRqBI0NC0Z4dXUxMGDhOTqJMUDP3k7pzusd082NqB+0pBFscACyeGcR2DT +seLUHbPAkEaD9ePzWAADblt92gC+ZVXpNrWb4VZAr+dVNcmLn5hcmImKk2qwKfzC +OzKxBqqbbe6+dlxVDZslSYnUWNXw/UuvgbG3b7ZZqWXfUnSvc8ngBZ+n7GqyDkF4 +IK35EV82IK4H7iMbQpI938vk49SVIfdn4qr6Oya2PfK1ww2/Z4jFJdW5p2Mc6RvW +tY/bnWf/LE4aM3VM/5RnADs3pFs/UQOo376MxLVG9xmDUvhwkE8gisluYO0ghICO +CGuziLC9+XAmWJ3LSAy8PtVWgj6K0Q3ZR0SgPBPMdkP0NUY5ZyrVqOxtRmhQJeMj +roKoSXdOKDgTkSf3QrnvRS3adM7CHSI78pgf1yOTDx1W5Muvs0sfStn8yo4YRs0i +itn5tVfwtxnh3EIk8A5kmG/fLEV4s+KX9aOBd3f25C2jtGr+XrnnW3RnO1MvP8Vh +cfW50pFtxh4zB/Wthpnq+N2NmZhIVe2XY/g7FvZQSUFUV7XAEQKCAQEA4r8nkyRU +B55oBoMDL8yuFgh0dS6xCWulQAbIM0VBqfNGKidvsZmYloBoFpDZuDlYQMN5LA9l +bTqftG4aoYDUPVa5Sw8i1edZcZy4LPyfsJRnEEpd/fab/o1sqRZtubpYqZSXnkNC +PP3ryGoPcmpw49XADwqejp/gl7n+xE4RcwsbiCCT0bvnLUlamj5Fz2vPGyBNR27m +KkjEs+4rtb/bI/+k3t0feyW7ASYxAM0DuFaLVpuNQGGSbmDxIyC4ZcsfHTp1XGGx +ElB8q/fWjJ106JpjEWw8qZ2uQcWgvFCVhaeItlWa2UoMklw3y0FmYoYKqoY9NtFh +Ml7+yyVJOEPWtwKCAQEA2NRyUk1kEehZi7d0otPVeJ/wsiU/DV2jpE1fuN8XllnC +KylcKnlRAFvIn/0ta/JgQdOueD1ePcTWEXBAUP29aoZqPCTAGVYDQaz1uNeUx3nj +hl6HH3LOMUINf11oRWZqNJhNo8n0uyIn4WNUwwyNRvQtSqQV4MFkUuRI9t/OX81N +592ur78zPndrHpKoimQqoUvIQOoL+bzLyvkPDRJHShwFwTVZ9jc18TpXvjPsTb/a +mwDH0aqhgPxFhDqprsHfUUG1U7cgAhqBPFioxM5Lqp8PdPjDCRPehGWmYR8fN8db +xw0vhRbFuSwYh012fSGGGu+rR9KHe3uq0XJv9UvgOQKCAQEAoP4gVzUABLjQG2+C +H7owEKzIIzuXr5yipCcsllqiGM0GEIAXqf3ofVOGlB8cttTgeHtR2ZrE5R0ur6lN +d0ZFa5fb0BNbJI0y0Jv5mNd1eqaj1sk2m08xyzcW46dtGOXade1vCYuvyCZx9sZ3 +WUGCDgKCbyuXEKUrjg8deLwFX62PSsP2sH+90EW48rMsVe2yCwyQUhvHiFZKc4az +ukQSkCi/Iw3VgFZ1xIcdW/g0n/myzTd8vy2IDp7+F3bv9jaWTOZo1cL3Oo2zN1at +GwHhNBYKKSC0oam3RDPRwGNnBpLBWtTFMWqGKpUXeFVjIKkTgaf2ZqmbXWxddFdw ++WYRWQKCAQEAkIhEUBIgQ0OS9OvrxmHX6NkME2N6fQlO/EVLKisjSOg54pVmRzWo +xclomSSlM1BT020r3iBiAmCDpQojBRmuOiSxCbghiIHqF8wX2wdwt+rKvBWkklTv +lqwF3UFBMQmMf9SJ5ETJajfhR37z0DQ8s/AthJSNtMyUeCCNdmpG4Vszs/vz5lhX +6yqk77Mov173f57JNGQOaYDsgzazTq5BcOfu+hP7DIFO5qZSOInZ2RWqvSmvCFZp +41XFbNfBpai7mClpmgz2PBC41qXukYlFrMzr+7eaIiHpcG1lk1WwdHjh93QVmexN +DhqTmxUKh2xiPPBHRs/R2YDco1JZyLO0GQKCAQEAxNxEsWIplwxraXyGoMXOPpO3 +fx1GSg0KSTqodax3UajPkx5Xl628zgJ8fzMdxQf8+2E/tW3moXVU9vPr6LH31LEV +6UbWywyo4zV2W4i2rNoDMmY1zJvbJuzXx+qePR2f0sLf+wheSz4uEkh3jRxH0WC4 +wWcRlRRkp75yrBhdh6c54Vbk1T0Acnu0y6ei9ogPkRKHujnF9E2GnnVNEQfsBrCI +SO9h3i1RFixzNPsUkghGqWphHfn53chN1cWJTsjlwzBKKZWfJoLqq5wUByWayPV+ +zBoW3Cav3/aWAVVw61NulCLoUcSrOKyW6Ks4aK/H7u+T9yVTQ5rZvDu1oTujpA== +-----END RSA PRIVATE KEY----- diff --git a/di/restapi/certs/server.crt b/di/restapi/certs/server.crt new file mode 100644 index 0000000..1535f82 --- /dev/null +++ b/di/restapi/certs/server.crt @@ -0,0 +1,30 @@ +-----BEGIN CERTIFICATE----- +MIIFFjCCAv4CAQEwDQYJKoZIhvcNAQELBQAwUTELMAkGA1UEBhMCVVMxCzAJBgNV +BAgMAk5ZMQ8wDQYDVQQHDAZBcm1vbmsxDDAKBgNVBAoMA0lCTTEWMBQGA1UEAwwN +ZGxhYXMuaWJtLmNvbTAeFw0xOTA4MDEwOTQwMTVaFw0yOTA3MjkwOTQwMTVaMFEx +CzAJBgNVBAYTAlVTMQswCQYDVQQIDAJOWTEPMA0GA1UEBwwGQXJtb25rMQwwCgYD +VQQKDANJQk0xFjAUBgNVBAMMDWRsYWFzLmlibS5jb20wggIiMA0GCSqGSIb3DQEB +AQUAA4ICDwAwggIKAoICAQD4QmjtNCzM0/jiGMB0c0ELwZ2/kZJNJVIEkXXvixb8 +5fDBKerm3+jKMCG/jxLpA5K5hrxyXbaIoBeSUlcvS1/QrUzHVWLDI4jj7wqvzT+O ++kdo/f1ehEna8LvgKaI+JUlkOMOhdEkpkitOJCpJI2k3ShL5rRHM4ecVL+gw6wyf +UhaBM7DP2Fq0FPYebxh2PzWDfop6E8NEftKMTBXcOqG5SpZE1qEVzplTZ/nlm9xU +82GcpwZCowHdgZMLgoMuoq9vHA0k8VEIup0bBj5xFjhiDx43Lq4fMy/hGKkgpWJ5 +ihwNa5oCaIz2hHNSe8uHz5I0EwW/GBBCeZnx7UlpjcxDUvTedHLFWC71iepk6csq +z8OXNJ/ENSF2njrgOeRYFnNyCLh2d81tsMPwuasXMqOW5B6LbWZAfwPOm9fxFcNq +fyVYmdZ5qveD5gSqDhC+a0Xz73injptYkAccQsnV20CH098a83IksmLFAV1a/5gN +lxUHDn/k4+b8VenBYw/A/o9B6fsoY4zjD3Tod9GVMSmVQfMJwN17TwmlzLquz+xr +sX99hUvl/1Q6wLID2NvFI0HhzOYNG9oK+QpxXemA9nDzvNb6yuQuQ6hLJxColnpJ +CStrit3RWQwNGEjyUjWRG1VH04UzD8pfBl0hMadwAJ1p/xWkA6XYg3AHCPuMthPe +twIDAQABMA0GCSqGSIb3DQEBCwUAA4ICAQA44mKffiMOXNG96C6U4LZgPgB/bbUt +qgjHHrhDv+fsMjC7jkWBc3UfkTkkNLb7MQmtpf+Y3TeEyEoakL753+5YPKGorsLv +x92N+pqm41VsbNHsGWUAVZg1CA9aA5uzVpKprPR3a9WinsrpY91wNHwMI61MJyXt +Jnz1d5dMboA93cZqHTkY4z8VQmXCZ0p9n6E5Nc2F2coI7h2v1RbhCXtVZExRLp2a +lQzsulEArtCBcsDkbunji/UJUPiCXg7zWRyj7ajpapdv0VKHcGEoLOLVuDBoS8hj +KTcowSQxYFr8d5Q5chlzfPR/GvGLWw6gEeAL3a/zssmvh0S+X+W6DvynFRqQ8aQr +UFXc36JBLssifocEawNdsrm+CWco/Z78lakyN5DVrsXhoYW1JC6EngoB9nL2RTig +3SoN8fy4T/zv/oUCfm4PAkKEyos+92TzpK4hJfk61AtmJREeMeW5IFTlaanGzv9j +JOaxCZ+b7BAHtMO75Kg3nwfBfetNu4lnkPCZ6Q7hsgDUyooO5hOMQdROTxXG0uS9 +owd7t8t3Bz7IcCVUF3jEi3p1Ff5UwqTiNo0OkHuuvfOzR6n8zH85E+k5yKQPOZ7R +66GvVKNqR8VSe4xewaFyufwl6R98ouX5c/dOWy2nW9i+IKu3ZvnqCsvhqU/sEm5r +uJaF587O3rApXQ== +-----END CERTIFICATE----- diff --git a/di/restapi/certs/server.csr b/di/restapi/certs/server.csr new file mode 100644 index 0000000..e427756 --- /dev/null +++ b/di/restapi/certs/server.csr @@ -0,0 +1,27 @@ +-----BEGIN CERTIFICATE REQUEST----- +MIIEljCCAn4CAQAwUTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAk5ZMQ8wDQYDVQQH +DAZBcm1vbmsxDDAKBgNVBAoMA0lCTTEWMBQGA1UEAwwNZGxhYXMuaWJtLmNvbTCC +AiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAPhCaO00LMzT+OIYwHRzQQvB +nb+Rkk0lUgSRde+LFvzl8MEp6ubf6MowIb+PEukDkrmGvHJdtoigF5JSVy9LX9Ct +TMdVYsMjiOPvCq/NP476R2j9/V6ESdrwu+Apoj4lSWQ4w6F0SSmSK04kKkkjaTdK +EvmtEczh5xUv6DDrDJ9SFoEzsM/YWrQU9h5vGHY/NYN+inoTw0R+0oxMFdw6oblK +lkTWoRXOmVNn+eWb3FTzYZynBkKjAd2BkwuCgy6ir28cDSTxUQi6nRsGPnEWOGIP +Hjcurh8zL+EYqSClYnmKHA1rmgJojPaEc1J7y4fPkjQTBb8YEEJ5mfHtSWmNzENS +9N50csVYLvWJ6mTpyyrPw5c0n8Q1IXaeOuA55FgWc3IIuHZ3zW2ww/C5qxcyo5bk +HottZkB/A86b1/EVw2p/JViZ1nmq94PmBKoOEL5rRfPveKeOm1iQBxxCydXbQIfT +3xrzciSyYsUBXVr/mA2XFQcOf+Tj5vxV6cFjD8D+j0Hp+yhjjOMPdOh30ZUxKZVB +8wnA3XtPCaXMuq7P7Guxf32FS+X/VDrAsgPY28UjQeHM5g0b2gr5CnFd6YD2cPO8 +1vrK5C5DqEsnEKiWekkJK2uK3dFZDA0YSPJSNZEbVUfThTMPyl8GXSExp3AAnWn/ +FaQDpdiDcAcI+4y2E963AgMBAAGgADANBgkqhkiG9w0BAQsFAAOCAgEA5SHqURAB +mgrYO0fIBJTv/oDauHVAQIibU2bD9ycJxGoQBaJDXUB2jeH8muW6JjIeggGxcpTb +t0OQCUFOvnIbq8D5/Zod1ZHOKySWK9chzXy2/PWZHNDBvnJWyuQQKbXK/hPmTPr9 +v7k/7FnTeN0CX9q94obSy665Xs4TaRKK6ypisVl3fSfAp8PeGRzssTP+rG+zC7UZ +3rsBv+ITLMkJt5crtTStKljU8dfVHz6JPabKnGpPf7M65BILhrfvFj7oa6Hy5eTp +Qb7P2ENc/uhGrwMuWzF+sdV1LZj26qX8chSJI/wromq/ZDOk4Dw6zWhhbOC3azXU +jTKztDuvbDtS4Vlcxw2Wp5iodJm1JR1W+JHSToptgKj4MTexfdM1q9rl/KxDSVh/ +vwBy9Mi8s9ljHBCNnMpT6eaWBpMUme1C51p8UlolkJG0v+SpuySmBH5+JTB0FeST +JBiMgCKZPTAHJCPbOoBHlLWqaNYsVVr/Yqi3tubZ+Ifr9KbWqK3ItuphaqmdG9V2 +l2hZwoyYGDhRkJWX5eTXEtjXiwDmMFl69CYyGNCYB+sqhhzeMd5dmGP5++tmxZXu +PcergtNs2rjsJU1nyU1MR67nBHewJd8mEKqcGQiKIyHrWk1rqazrMf80LzyHw9Oh +2gIA/zRS1ChxywzKrcjzA1OszZunZh4E/jE= +-----END CERTIFICATE REQUEST----- diff --git a/di/restapi/certs/server.key b/di/restapi/certs/server.key new file mode 100644 index 0000000..4de392c --- /dev/null +++ b/di/restapi/certs/server.key @@ -0,0 +1,51 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIJKQIBAAKCAgEA+EJo7TQszNP44hjAdHNBC8Gdv5GSTSVSBJF174sW/OXwwSnq +5t/oyjAhv48S6QOSuYa8cl22iKAXklJXL0tf0K1Mx1ViwyOI4+8Kr80/jvpHaP39 +XoRJ2vC74CmiPiVJZDjDoXRJKZIrTiQqSSNpN0oS+a0RzOHnFS/oMOsMn1IWgTOw +z9hatBT2Hm8Ydj81g36KehPDRH7SjEwV3DqhuUqWRNahFc6ZU2f55ZvcVPNhnKcG +QqMB3YGTC4KDLqKvbxwNJPFRCLqdGwY+cRY4Yg8eNy6uHzMv4RipIKVieYocDWua +AmiM9oRzUnvLh8+SNBMFvxgQQnmZ8e1JaY3MQ1L03nRyxVgu9YnqZOnLKs/DlzSf +xDUhdp464DnkWBZzcgi4dnfNbbDD8LmrFzKjluQei21mQH8DzpvX8RXDan8lWJnW +ear3g+YEqg4QvmtF8+94p46bWJAHHELJ1dtAh9PfGvNyJLJixQFdWv+YDZcVBw5/ +5OPm/FXpwWMPwP6PQen7KGOM4w906HfRlTEplUHzCcDde08Jpcy6rs/sa7F/fYVL +5f9UOsCyA9jbxSNB4czmDRvaCvkKcV3pgPZw87zW+srkLkOoSycQqJZ6SQkra4rd +0VkMDRhI8lI1kRtVR9OFMw/KXwZdITGncACdaf8VpAOl2INwBwj7jLYT3rcCAwEA +AQKCAgEAjYyX9P91t8f4tTl1qi/423Imto6Sw0fPLumdO9qrXcDhd9GlrMPoIDg3 +VdiG6LLv2rZ3BiJmrBnTtssaCM5KMFpPV6xYpnjBWWz3Q+ucHLKZOsTuzRBSZ/Iw +vQwgBJ0P7oPrD0iVWo2MAX7fWVpGaI7kqNVEO/Rl5I+vLQ0n4kNUr5BAdRGgDeOR +vSKM6Qb7RSFGZXqVMJ27AOF06V/IzDQ538Ackql8hLDZLFCk3Q70DfSxvhbhPmHd +7IcasuFxc8GjwPeSw45be4gg3CvWNBr4mHAWOZXe69I6xHFn53KWshQy+MKR9RDq +DBKnpqT0cJqUATQAOVbKLsWjwPpnhq/ukgD7wKrqK+AmhXQFsYrD/SGD4hchb7Zg +P5PHttTsOLiskpP8WbnAfHjx7mg6JLJ/znlBBI90+q/wR/vvvAo0aQHpiT1AYC5D +56+pm71JCtYdfZBL060JeIiDL1CJSjyPP+o1hcJueIHkWl2P0k90ESPivpu4S4V3 +J50/ntb2jKjuVFprdHmVVdoFXwvHkwqMjqA89fu8k4RY1+o3pttO3KfGfqppZKFu +W4VXbBnW0gNHbEG2/HcLy1B2j/nv0E2BCfjH+qJ+mI7LBomsnDphvhKnNq2yI1JJ +PhlKqooU6TAKye5mg8XrLlXzpv7Y+NQPWmBO811hUGDjsSLVvOkCggEBAP1riWBY +BRfhvLX2+/hUgqRKI/rf/p5A8w1lc/BlayMzZFcjRhdV9Ruk68INFgzL+nxHTIZe +iPE3IiQlqDDvFpT+ItTaLY62xf1pM10LWKOItpfmnDgVeQhG5m5x1JrkAu/wFXNF +98SvTs1E38aAHnpnoef+WZlS1ihwNVu6QaeqNvm7iQYsHrQMSFWdI7oQsfNTjS5q +UPYyO+/kHTm/fB2L3v9JXCE/ve9yF7PsyR31hB25HjpivXhf6xHKixtIxjdW48kr +QjFs6NwkS893pBNK091g12sMVktN3JvgPDhs5nHAPoerbzcBQzN5da1cL2qXCRg2 +HqKStytQtBwtfZMCggEBAPrJbG3/Z4GNJJaFuMtZv7MiMml5C5ClV91feGK9Vy1I +zDoBBz1j5lkT7tlxWrWbH9LCpuLQPToHcLbJhFMR+RI/r+R/CkKl+b9WI5lemeqz +gOl8qGQVziZ61V/2JZrDOTVzMaNncYOLMvOykIs2+ENVsR0+i44qBOk2yKZrKppK +tO9dZRXXbuzeoyOEyncPB9XrKUJGnnIQGL9sq+oaUj7tHi/UolG5Uk0vCP7pO8Ri +zcr0BLv/Fm8wAZ6rR2EPfDylFPIhQK1pXgWYKWryMGQvVZjwr9LLgnTYm63fvic1 +ce8lYfl+kXSePpHtdnDS47BltKy9svvqEDLPiGgycM0CggEAWwxZzQ2StuPZox7b +pHrofRJOHwJ/Pmhjarq6jvJBLeJ2+H+p3RR6/bWhJpUBCRP4KNKNAfHRDakbURVe +ekZMPLeZ2BOTLqUoOUWkuJcs/4RM5gJquhOs6nZer+uh0Qx+qan+au4GeNnrXACU +zYKWcK/vEaTmmBmU6+50nUIr+ItFOTBRqLANT+7hxjCw91asOJoaLUTxVaLyuduh +THAprYvlUJ8QxLlcCj1ZmsFF+MeO8gbif2OeYzNDB59XnzPkU1maeVpba9qPRxib +TCzV/EB0IiN7AfDqyB9vVWmY+UTW/qNtU90aFg8UD9hhmSl3t7oQAGzhUNOZj6xt +KXqGlQKCAQEA4dNbBjoEdI4qMji7zLFGhAH5LyzGkzuwQTFk8FTbGXYCIQEoCcnZ +dMEURU1jh0DmiRyqtncZixWEE7SmqT7378zVkIYtMRLQL9FbQRIEu2lkXdvYrjdM +aS4W0dCO0CuXamAOhLvzZaaE/RkAO7wGFmwljtXxSNThkze3utOpi0JWZ2zMR7y0 +sCtS7/r1bfxk6+ZUQs/ggYmpH0a2D5ogEXXnxt5MRBcC22nNSe2v2gm2kljlonvz +MbAi5UQKhIYzM1Db6aSz3vOQrKz2Ls1jcfOFurCRQtnq4Vjj5tAhJKFltRkOfmHQ +jRip8zHHg5UDXqZW6W3wrBN6/qYOiPVSyQKCAQAU9YO6g8Pug8Vk7k3OZ2OM6Egz +ipvaKAJw6XmKbhWQdauB/gx7n10j5A4bDo5OmA8V/oZunoNa5+1TXf4KxPvE4w1z +EhpaAjxLwmCq5OWb+kXJ2cv+568E9n7/xfZLKLHUEgNlwRgIj9+Zs1LD3qrlluN5 +cnHzddyiguTon3VwlwWyqbiMXs0X3t1CNfsToth7fkMQ6JsTdGRhBPkymEUEvuWy +FRu8f+eVV2zIQxOf516uwSo7PoLUUnFHVcynzy3KDTdgk7HdVWmzVsycgRrlngpS +ytYLjLaYt5obP2TbN/4tsdmiDUWOMZBYqt19yCCKdPQd/mfGdCOhwQxQiNoV +-----END RSA PRIVATE KEY----- diff --git a/di/restapi/main.go b/di/restapi/main.go new file mode 100644 index 0000000..8c21d3a --- /dev/null +++ b/di/restapi/main.go @@ -0,0 +1,73 @@ +/* + * Copyright 2017-2018 IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + "net/http" + "os" + "time" + datasource "webank/DI/commons/datasource/mysql" + "webank/DI/restapi/api_v1/server/rest_impl" + + log "github.com/sirupsen/logrus" + "github.com/spf13/viper" + "github.com/tylerb/graceful" + + "github.com/go-openapi/loads" + + "webank/DI/commons/config" + "webank/DI/commons/logger" + "webank/DI/restapi/api_v1/server" + "webank/DI/restapi/api_v1/server/operations" +) + +const ( + encodeFlag = "encodeFlag" +) + +func main() { + config.InitViper() + logger.Config() + datasource.InitDS(viper.GetBool(encodeFlag)) + + log.Printf("linkis executor image: %s, tag: %v, MEM: %v, MEM: %v", os.Getenv("LINKIS_EXECUTOR_IMAGE"), os.Getenv("LINKIS_EXECUTOR_TAG"), os.Getenv("LINKIS_EXECUTOR_CPU"), os.Getenv("LINKIS_EXECUTOR_MEM")) + + swaggerSpec, err := loads.Analyzed(server.SwaggerJSON, "") + if err != nil { + log.Fatalln(err) + } + + api := operations.NewDiAPI(swaggerSpec) + // api.Logger = log.Printf + + srv := server.NewServer(api) + defer srv.Shutdown() + srv.Port = viper.GetInt(config.PortKey) + srv.ConfigureAPI() + + mux := http.NewServeMux() + mux.Handle("/", srv.GetHandler()) + mux.HandleFunc("/health", rest_impl.GetHealth) + + address := fmt.Sprintf(":%d", srv.Port) + log.Printf("Prophecis REST API v1 serving on %s", address) + err = graceful.RunWithErr(address, 10*time.Second, mux) + if err != nil { + log.Fatalln(err) + } +} diff --git a/di/restapi/middleware/logging.go b/di/restapi/middleware/logging.go new file mode 100644 index 0000000..050201e --- /dev/null +++ b/di/restapi/middleware/logging.go @@ -0,0 +1,167 @@ +/* + * Copyright 2017-2018 IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package middleware + +import ( + "fmt" + "net/http" + "net/url" + "time" + + log "github.com/sirupsen/logrus" +) + +type timer interface { + Now() time.Time + Since(time.Time) time.Duration +} + +type realClock struct{} + +func (rc *realClock) Now() time.Time { + return time.Now() +} + +func (rc *realClock) Since(t time.Time) time.Duration { + return time.Since(t) +} + +// Middleware is a middleware handler that logs the request as it goes in and the response as it goes out. +type Middleware struct { + Name string + // Name is the name of the application as recorded in latency metrics + Before func(*log.Entry, *http.Request, string) *log.Entry + After func(*log.Entry, ResponseWriter, time.Duration, string) *log.Entry + + logStarting bool + + clock timer + + // Exclude URLs from logging + excludeURLs []string +} + +// NewLoggingMiddleware returns a new *Middleware. +func NewLoggingMiddleware(name string) *Middleware { + return &Middleware{ + Name: name, + Before: DefaultBefore, + After: DefaultAfter, + + logStarting: true, + clock: &realClock{}, + } +} + +// SetLogStarting accepts a bool to control the logging of "started handling +// request" prior to passing to the next middleware +func (m *Middleware) SetLogStarting(v bool) { + m.logStarting = v +} + +// ExcludeURL adds a new URL u to be ignored during logging. The URL u is parsed, hence the returned error +func (m *Middleware) ExcludeURL(u string) error { + if _, err := url.Parse(u); err != nil { + return err + } + m.excludeURLs = append(m.excludeURLs, u) + return nil +} + +// ExcludedURLs returns the list of excluded URLs for this middleware +func (m *Middleware) ExcludedURLs() []string { + return m.excludeURLs +} + +// Handle is the main entrypoint for the middleware to process the request +func (m *Middleware) Handle(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if m.Before == nil { + m.Before = DefaultBefore + } + + if m.After == nil { + m.After = DefaultAfter + } + + for _, u := range m.excludeURLs { + if r.URL.Path == u { + return + } + } + + start := m.clock.Now() + + // Try to get the real IP + remoteAddr := r.RemoteAddr + if realIP := r.Header.Get("X-Real-IP"); realIP != "" { + remoteAddr = realIP + } + + entry := log.NewEntry(log.StandardLogger()) + + if reqID := r.Header.Get("X-Request-Id"); reqID != "" { + entry = entry.WithField("request_id", reqID) + } + + if transID := r.Header.Get("X-Global-Transaction-ID "); transID != "" { + entry = entry.WithField("trans_id", transID) + } + + entry = m.Before(entry, r, remoteAddr) + + if m.logStarting { + entry.Info("Started handling request") + } + + rw := NewResponseWriter(w) + + next.ServeHTTP(rw, r) + + latency := m.clock.Since(start) + + m.After(entry, rw, latency, m.Name).Info("Completed handling request") + }) +} + +// BeforeFunc is the func type used to modify or replace the *logrus.Entry prior +// to calling the next func in the middleware chain +type BeforeFunc func(*log.Entry, *http.Request, string) *log.Entry + +// AfterFunc is the func type used to modify or replace the *logrus.Entry after +// calling the next func in the middleware chain +type AfterFunc func(*log.Entry, ResponseWriter, time.Duration, string) *log.Entry + +// DefaultBefore is the default func assigned to *Middleware.Before +func DefaultBefore(entry *log.Entry, req *http.Request, remoteAddr string) *log.Entry { + return entry.WithFields(log.Fields{ + "request": req.RequestURI, + "method": req.Method, + "remote": remoteAddr, + }) +} + +// DefaultAfter is the default func assigned to *Middleware.After +func DefaultAfter(entry *log.Entry, res ResponseWriter, latency time.Duration, name string) *log.Entry { + + return entry.WithFields(log.Fields{ + "status": res.Status(), + "text_status": http.StatusText(res.Status()), + "took": latency, + fmt.Sprintf("measure#%s.latency", name): latency.Nanoseconds(), + }) +} diff --git a/di/restapi/middleware/response_writer.go b/di/restapi/middleware/response_writer.go new file mode 100644 index 0000000..cbcf3f5 --- /dev/null +++ b/di/restapi/middleware/response_writer.go @@ -0,0 +1,110 @@ +package middleware + +// Copied from here https://github.com/urfave/negroni/blob/master/response_writer.go +// Did not want to import the whole package for tis simple wrapper. +// Note: MIT license + +import ( + "bufio" + "fmt" + "net" + "net/http" +) + +// ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about +// the response. It is recommended that middleware handlers use this construct to wrap a responsewriter +// if the functionality calls for it. +type ResponseWriter interface { + http.ResponseWriter + http.Flusher + // Status returns the status code of the response or 200 if the response has + // not been written (as this is the default response code in net/http) + Status() int + // Written returns whether or not the ResponseWriter has been written. + Written() bool + // Size returns the size of the response body. + Size() int + // Before allows for a function to be called before the ResponseWriter has been written to. This is + // useful for setting headers or any other operations that must happen before a response has been written. + Before(func(ResponseWriter)) +} + +type beforeFunc func(ResponseWriter) + +// NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter +func NewResponseWriter(rw http.ResponseWriter) ResponseWriter { + return &responseWriter{ + ResponseWriter: rw, + } +} + +type responseWriter struct { + http.ResponseWriter + status int + size int + beforeFuncs []beforeFunc + wroteHeader bool +} + +func (rw *responseWriter) WriteHeader(s int) { + rw.status = s + rw.callBefore() + rw.ResponseWriter.WriteHeader(s) + rw.wroteHeader = true +} + +func (rw *responseWriter) Write(b []byte) (int, error) { + if !rw.Written() { + // The status will be StatusOK if WriteHeader has not been called yet + rw.WriteHeader(http.StatusOK) + } + size, err := rw.ResponseWriter.Write(b) + rw.size += size + return size, err +} + +func (rw *responseWriter) Status() int { + // Default status code is 200 + if !rw.Written() { + return http.StatusOK + } + + return rw.status +} + +func (rw *responseWriter) Size() int { + return rw.size +} + +func (rw *responseWriter) Written() bool { + return rw.wroteHeader +} + +func (rw *responseWriter) Before(before func(ResponseWriter)) { + rw.beforeFuncs = append(rw.beforeFuncs, before) +} + +func (rw *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { + hijacker, ok := rw.ResponseWriter.(http.Hijacker) + if !ok { + return nil, nil, fmt.Errorf("the ResponseWriter doesn't support the Hijacker interface") + } + return hijacker.Hijack() +} + +func (rw *responseWriter) CloseNotify() <-chan bool { + return rw.ResponseWriter.(http.CloseNotifier).CloseNotify() +} + +func (rw *responseWriter) callBefore() { + for i := len(rw.beforeFuncs) - 1; i >= 0; i-- { + rw.beforeFuncs[i](rw) + } +} + +func (rw *responseWriter) Flush() { + flusher, ok := rw.ResponseWriter.(http.Flusher) + if ok { + flusher.Flush() + } +} diff --git a/di/restapi/service/experiment_service.go b/di/restapi/service/experiment_service.go new file mode 100644 index 0000000..2a8fc6f --- /dev/null +++ b/di/restapi/service/experiment_service.go @@ -0,0 +1,141 @@ +/* + * Copyright 2020 WeBank + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package service + +import ( + "context" + "errors" + "io" + "io/ioutil" + "os" + "webank/DI/commons/logger" + storageClient "webank/DI/storage/client" + "webank/DI/storage/storage/grpc_storage" + + "github.com/google/uuid" +) + +const ( + actualFlowFolderName = "flow" +) + +var ExperimentService ExperimentServiceIF = &ExperimentServiceImpl{} +var log = logger.GetLogger() + +type ExperimentServiceIF interface { + UploadCodeBucket(closer io.ReadCloser, bucket string) (string, error) + UploadCode(closer io.ReadCloser) (string, error) +} +type ExperimentServiceImpl struct { +} + +func (expService *ExperimentServiceImpl) UploadCode(closer io.ReadCloser) (string, error) { + hostpath := "/data/oss-storage/" + filename := uuid.New().String() + "file.zip" + filepath := hostpath + filename + //out, err := os.Create(filename) + //wt := bufio.NewWriter(out) + //_, err = io.Copy(wt, closer) + fileBytes, err := ioutil.ReadAll(closer) + if err != nil { + log.Error(err.Error()) + return "", err + } + + err = ioutil.WriteFile(filepath, fileBytes, os.ModePerm) + if err != nil { + log.Error(err.Error()) + return "", err + } + + //上传 code.zip 后, 更新flowJson 中每个 node 的 codePath + //创建 storage rpc client, 用于 上传code.zip + //ctx := context.TODO() + sClient, err := storageClient.NewStorage() + if err != nil { + log.Info("storageClient init Error " + err.Error()) + return "", err + } + + req := &grpc_storage.CodeUploadRequest{ + FileName: filename, + HostPath: hostpath, + } + ctx := context.TODO() + if sClient == nil { + log.Info("storageClient init Error,sclient is nil") + return "", errors.New("rpc upload code zip error, sclient is nil") + } + response, err := sClient.Client().UploadCode(ctx, req) + if err != nil { + log.Error("sclient upload code error: " + err.Error()) + return "", err + } + err = os.Remove(filepath) + if err != nil { + log.Error("" + err.Error()) + } + + return response.S3Path, err + +} + +func (expService *ExperimentServiceImpl) UploadCodeBucket(closer io.ReadCloser, bucket string) (string, error) { + hostpath := "/data/oss-storage/" + filename := uuid.New().String() + "file.zip" + filepath := hostpath + filename + fileBytes, err := ioutil.ReadAll(closer) + if err != nil { + log.Error(err.Error()) + return "", err + } + + err = ioutil.WriteFile(filepath, fileBytes, os.ModePerm) + if err != nil { + log.Error(err.Error()) + return "", err + } + + //上传 code.zip 后, 更新flowJson 中每个 node 的 codePath + //创建 storage rpc client, 用于 上传code.zip + //ctx := context.TODO() + sClient, err := storageClient.NewStorage() + if err != nil { + log.Info("storageClient init Error " + err.Error()) + return "", err + } + + req := &grpc_storage.CodeUploadRequest{ + FileName: filename, + HostPath: hostpath, + Bucket: bucket, + } + ctx := context.TODO() + if sClient == nil { + log.Info("storageClient init Error,sclient is nil") + return "", errors.New("rpc upload code zip error, sclient is nil") + } + response, err := sClient.Client().UploadCode(ctx, req) + if err != nil { + log.Error("sclient upload code error: " + err.Error()) + return "", err + } + err = os.Remove(filepath) + if err != nil { + log.Error("" + err.Error()) + } + return response.S3Path, err +}