diff options
34 files changed, 1865 insertions, 334 deletions
diff --git a/artifact_alias.go b/artifact_alias.go new file mode 100644 index 0000000..d83e8fb --- /dev/null +++ b/artifact_alias.go @@ -0,0 +1,34 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// 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" +) + +// ArtifactAlias is an alternative name of an artifact. +// swagger:model ArtifactAlias +type ArtifactAlias string + +// Validate validates this artifact alias +func (m ArtifactAlias) Validate(formats strfmt.Registry) error { + return nil +} diff --git a/artifact_description.go b/artifact_description.go new file mode 100644 index 0000000..383c34c --- /dev/null +++ b/artifact_description.go @@ -0,0 +1,154 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// 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" +) + +// ArtifactDescription contains information needed to create new artifact in ArtifactDB. +// swagger:model ArtifactDescription +type ArtifactDescription struct { + + // alias + Alias ArtifactAlias `json:"Alias,omitempty"` + + // specifies Job for which artifact was created. + JobID JobID `json:"JobID,omitempty"` + + // type + Type ArtifactType `json:"Type,omitempty"` + + // URI + // Format: uri + URI ArtifactURI `json:"URI,omitempty"` +} + +// Validate validates this artifact description +func (m *ArtifactDescription) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateAlias(formats); err != nil { + res = append(res, err) + } + + if err := m.validateJobID(formats); err != nil { + res = append(res, err) + } + + if err := m.validateType(formats); err != nil { + res = append(res, err) + } + + if err := m.validateURI(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *ArtifactDescription) validateAlias(formats strfmt.Registry) error { + + if swag.IsZero(m.Alias) { // not required + return nil + } + + if err := m.Alias.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Alias") + } + return err + } + + return nil +} + +func (m *ArtifactDescription) validateJobID(formats strfmt.Registry) error { + + if swag.IsZero(m.JobID) { // not required + return nil + } + + if err := m.JobID.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("JobID") + } + return err + } + + return nil +} + +func (m *ArtifactDescription) validateType(formats strfmt.Registry) error { + + if swag.IsZero(m.Type) { // not required + return nil + } + + if err := m.Type.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Type") + } + return err + } + + return nil +} + +func (m *ArtifactDescription) validateURI(formats strfmt.Registry) error { + + if swag.IsZero(m.URI) { // not required + return nil + } + + if err := m.URI.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("URI") + } + return err + } + + return nil +} + +// MarshalBinary interface implementation +func (m *ArtifactDescription) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *ArtifactDescription) UnmarshalBinary(b []byte) error { + var res ArtifactDescription + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/artifact_filter.go b/artifact_filter.go new file mode 100644 index 0000000..f110f38 --- /dev/null +++ b/artifact_filter.go @@ -0,0 +1,171 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// 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" +) + +// ArtifactFilter is used to filter results from ArtifactDB. +// swagger:model ArtifactFilter +type ArtifactFilter struct { + + // alias + Alias []ArtifactAlias `json:"Alias"` + + // job ID + JobID []JobID `json:"JobID"` + + // status + Status []ArtifactStatus `json:"Status"` + + // type + Type []ArtifactType `json:"Type"` +} + +// Validate validates this artifact filter +func (m *ArtifactFilter) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateAlias(formats); err != nil { + res = append(res, err) + } + + if err := m.validateJobID(formats); err != nil { + res = append(res, err) + } + + if err := m.validateStatus(formats); err != nil { + res = append(res, err) + } + + if err := m.validateType(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *ArtifactFilter) validateAlias(formats strfmt.Registry) error { + + if swag.IsZero(m.Alias) { // not required + return nil + } + + for i := 0; i < len(m.Alias); i++ { + + if err := m.Alias[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Alias" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *ArtifactFilter) validateJobID(formats strfmt.Registry) error { + + if swag.IsZero(m.JobID) { // not required + return nil + } + + for i := 0; i < len(m.JobID); i++ { + + if err := m.JobID[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("JobID" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *ArtifactFilter) validateStatus(formats strfmt.Registry) error { + + if swag.IsZero(m.Status) { // not required + return nil + } + + for i := 0; i < len(m.Status); i++ { + + if err := m.Status[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Status" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *ArtifactFilter) validateType(formats strfmt.Registry) error { + + if swag.IsZero(m.Type) { // not required + return nil + } + + for i := 0; i < len(m.Type); i++ { + + if err := m.Type[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Type" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *ArtifactFilter) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *ArtifactFilter) UnmarshalBinary(b []byte) error { + var res ArtifactFilter + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/artifact_info.go b/artifact_info.go new file mode 100644 index 0000000..d376776 --- /dev/null +++ b/artifact_info.go @@ -0,0 +1,168 @@ +// Code generated by go-swagger; DO NOT EDIT. +// NOTE: above is not entirely true. see TODO: below. + +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// 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" +) + +// ArtifactInfo describes single artifact stored in ArtifactDB. +// swagger:model ArtifactInfo +type ArtifactInfo struct { + ArtifactDescription + + // path + Path ArtifactPath `json:"Path,omitempty"` + + // status + Status ArtifactStatus `json:"Status,omitempty"` + + // is date of creating the artifact. + // Format: date-time + Timestamp strfmt.DateTime `json:"Timestamp,omitempty"` +} + +// TODO +// current go-swagger generates broken marshalling and unmarshalling: +// https://github.com/go-swagger/go-swagger/issues/1617 +// it is commented out as implicit marshalling works fine. + +/* +// UnmarshalJSON unmarshals this object from a JSON structure +func (m *ArtifactInfo) UnmarshalJSON(raw []byte) error { + // AO0 + var aO0 ArtifactDescription + if err := swag.ReadJSON(raw, &aO0); err != nil { + return err + } + m.ArtifactDescription = aO0 + + return nil +} + +// MarshalJSON marshals this object to a JSON structure +func (m ArtifactInfo) MarshalJSON() ([]byte, error) { + _parts := make([][]byte, 0, 1) + + aO0, err := swag.WriteJSON(m.ArtifactDescription) + if err != nil { + return nil, err + } + _parts = append(_parts, aO0) + + return swag.ConcatJSON(_parts...), nil +} +*/ + +// Validate validates this artifact info +func (m *ArtifactInfo) Validate(formats strfmt.Registry) error { + var res []error + + // validation for a type composition with ArtifactDescription + if err := m.ArtifactDescription.Validate(formats); err != nil { + res = append(res, err) + } + + if err := m.validatePath(formats); err != nil { + res = append(res, err) + } + + if err := m.validateStatus(formats); err != nil { + res = append(res, err) + } + + if err := m.validateTimestamp(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *ArtifactInfo) validatePath(formats strfmt.Registry) error { + + if swag.IsZero(m.Path) { // not required + return nil + } + + if err := m.Path.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Path") + } + return err + } + + return nil +} + +func (m *ArtifactInfo) validateStatus(formats strfmt.Registry) error { + + if swag.IsZero(m.Status) { // not required + return nil + } + + if err := m.Status.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Status") + } + return err + } + + return nil +} + +func (m *ArtifactInfo) validateTimestamp(formats strfmt.Registry) error { + + if swag.IsZero(m.Timestamp) { // not required + return nil + } + + if err := validate.FormatOf("Timestamp", "body", "date-time", m.Timestamp.String(), formats); err != nil { + return err + } + + return nil +} + +// MarshalBinary interface implementation +func (m *ArtifactInfo) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *ArtifactInfo) UnmarshalBinary(b []byte) error { + var res ArtifactInfo + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/artifact_path.go b/artifact_path.go new file mode 100644 index 0000000..5677d16 --- /dev/null +++ b/artifact_path.go @@ -0,0 +1,34 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// 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" +) + +// ArtifactPath describes path to artifact in ArtifactDB filesystem. +// swagger:model ArtifactPath +type ArtifactPath string + +// Validate validates this artifact path +func (m ArtifactPath) Validate(formats strfmt.Registry) error { + return nil +} diff --git a/artifact_status.go b/artifact_status.go new file mode 100644 index 0000000..2c30dab --- /dev/null +++ b/artifact_status.go @@ -0,0 +1,93 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// 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" +) + +// ArtifactStatus describes artifact status and availability. +// +// * DOWNLOADING - artifact is currently being downloaded. +// +// * READY - artifact has been downloaded and is ready to use. +// +// * FAILED - file is not available for use (e.g. download failed). +// +// * PENDING - artifact download has not started yet. +// +// swagger:model ArtifactStatus +type ArtifactStatus string + +const ( + + // ArtifactStatusDOWNLOADING captures enum value "DOWNLOADING" + ArtifactStatusDOWNLOADING ArtifactStatus = "DOWNLOADING" + + // ArtifactStatusREADY captures enum value "READY" + ArtifactStatusREADY ArtifactStatus = "READY" + + // ArtifactStatusFAILED captures enum value "FAILED" + ArtifactStatusFAILED ArtifactStatus = "FAILED" + + // ArtifactStatusPENDING captures enum value "PENDING" + ArtifactStatusPENDING ArtifactStatus = "PENDING" +) + +// for schema +var artifactStatusEnum []interface{} + +func init() { + var res []ArtifactStatus + if err := json.Unmarshal([]byte(`["DOWNLOADING","READY","FAILED","PENDING"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + artifactStatusEnum = append(artifactStatusEnum, v) + } +} + +func (m ArtifactStatus) validateArtifactStatusEnum(path, location string, value ArtifactStatus) error { + if err := validate.Enum(path, location, value, artifactStatusEnum); err != nil { + return err + } + return nil +} + +// Validate validates this artifact status +func (m ArtifactStatus) Validate(formats strfmt.Registry) error { + var res []error + + // value enum + if err := m.validateArtifactStatusEnum("", "body", m); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/artifact_status_change.go b/artifact_status_change.go new file mode 100644 index 0000000..525f34c --- /dev/null +++ b/artifact_status_change.go @@ -0,0 +1,22 @@ +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// ArtifactStatusChange contains information about new status of an artifact. +// It is used to monitor status changes. +type ArtifactStatusChange struct { + Path ArtifactPath + NewStatus ArtifactStatus +} diff --git a/artifact_type.go b/artifact_type.go new file mode 100644 index 0000000..eada618 --- /dev/null +++ b/artifact_type.go @@ -0,0 +1,93 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// 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" +) + +// ArtifactType denotes type and function of an artifact. +// +// * IMAGE - image file. +// +// * RESULT - all outputs, files built during tests, etc. +// +// * TEST - additional files uploaded by user for conducting test. +// +// * YAML - yaml file describing Weles Job. +// +// swagger:model ArtifactType +type ArtifactType string + +const ( + + // ArtifactTypeIMAGE captures enum value "IMAGE" + ArtifactTypeIMAGE ArtifactType = "IMAGE" + + // ArtifactTypeRESULT captures enum value "RESULT" + ArtifactTypeRESULT ArtifactType = "RESULT" + + // ArtifactTypeTEST captures enum value "TEST" + ArtifactTypeTEST ArtifactType = "TEST" + + // ArtifactTypeYAML captures enum value "YAML" + ArtifactTypeYAML ArtifactType = "YAML" +) + +// for schema +var artifactTypeEnum []interface{} + +func init() { + var res []ArtifactType + if err := json.Unmarshal([]byte(`["IMAGE","RESULT","TEST","YAML"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + artifactTypeEnum = append(artifactTypeEnum, v) + } +} + +func (m ArtifactType) validateArtifactTypeEnum(path, location string, value ArtifactType) error { + if err := validate.Enum(path, location, value, artifactTypeEnum); err != nil { + return err + } + return nil +} + +// Validate validates this artifact type +func (m ArtifactType) Validate(formats strfmt.Registry) error { + var res []error + + // value enum + if err := m.validateArtifactTypeEnum("", "body", m); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/artifact_uri.go b/artifact_uri.go new file mode 100644 index 0000000..3e42aa8 --- /dev/null +++ b/artifact_uri.go @@ -0,0 +1,46 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// 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/validate" +) + +// ArtifactURI is used to identify artifact's source. +// swagger:model ArtifactURI +type ArtifactURI strfmt.URI + +// Validate validates this artifact URI +func (m ArtifactURI) Validate(formats strfmt.Registry) error { + var res []error + + if err := validate.FormatOf("", "body", "uri", strfmt.URI(m).String(), formats); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/artifactmanager.go b/artifactmanager.go index cc9058c..76877bf 100644 --- a/artifactmanager.go +++ b/artifactmanager.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,80 +14,10 @@ * limitations under the License */ -// File artifactmanager.go defines ArtifactManager interface and structures related to it. +// File artifactmanager.go defines ArtifactManager interface. package weles -import "time" - -// ArtifactType denotes type and function of an artifact. -type ArtifactType string - -const ( - // AM_IMAGEFILE - image file. - AM_IMAGEFILE ArtifactType = "IMAGE" - // AM_RESULTFILE - all outputs, files built during tests, etc. - AM_RESULTFILE ArtifactType = "RESULT" - // AM_TESTFILE - additional files uploaded by user for conducting test. - AM_TESTFILE ArtifactType = "TESTFILE" - // AM_YAMLFILE - yaml file describing Weles Job. - AM_YAMLFILE ArtifactType = "YAMLFILE" -) - -// ArtifactPath describes path to artifact in ArtifactDB filesystem. -type ArtifactPath string - -// ArtifactStatus describes artifact status and availability. -type ArtifactStatus string - -const ( - // AM_DOWNLOADING - artifact is currently being downloaded. - AM_DOWNLOADING ArtifactStatus = "DOWNLOADING" - // AM_READY - artifact has been downloaded and is ready to use. - AM_READY ArtifactStatus = "READY" - // AM_FAILED - file is not available for use (e.g. download failed). - AM_FAILED ArtifactStatus = "FAILED" - // AM_PENDING - artifact download has not started yet. - AM_PENDING ArtifactStatus = "PENDING" -) - -// ArtifactURI is used to identify artifact's source. -type ArtifactURI string - -// ArtifactAlias is used to identify artifact's alias. -type ArtifactAlias string - -// ArtifactDescription contains information needed to create new artifact in ArtifactDB. -type ArtifactDescription struct { - JobID JobID - Type ArtifactType - Alias ArtifactAlias - URI ArtifactURI -} - -// ArtifactInfo describes single artifact stored in ArtifactDB. -type ArtifactInfo struct { - ArtifactDescription - Path ArtifactPath - Status ArtifactStatus - Timestamp time.Time -} - -// ArtifactFilter is used to filter results from ArtifactDB. -type ArtifactFilter struct { - JobID []JobID - Type []ArtifactType - Status []ArtifactStatus - Alias []ArtifactAlias -} - -// ArtifactStatusChange contains information about new status of an artifact. -// It is used to monitor status changes. -type ArtifactStatusChange struct { - Path ArtifactPath - NewStatus ArtifactStatus -} - // ArtifactManager provides access to content in ArtifactDB required for Job execution. // It provides data from ArtifactDB for lookup and retrieval. // It is responsible for downloading job artifacts to ArtifactDB. diff --git a/artifacts/artifacts.go b/artifacts/artifacts.go index 4e61c64..eda1a18 100644 --- a/artifacts/artifacts.go +++ b/artifacts/artifacts.go @@ -24,6 +24,8 @@ import ( "strconv" "time" + "github.com/go-openapi/strfmt" + "git.tizen.org/tools/weles" "git.tizen.org/tools/weles/artifacts/database" "git.tizen.org/tools/weles/artifacts/downloader" @@ -111,7 +113,7 @@ func (s *Storage) PushArtifact(artifact weles.ArtifactDescription, ch chan weles err = s.downloader.Download(artifact.URI, path, ch) if err != nil { - s.db.SetStatus(weles.ArtifactStatusChange{path, weles.AM_FAILED}) + s.db.SetStatus(weles.ArtifactStatusChange{path, weles.ArtifactStatusFAILED}) return "", err } return path, nil @@ -124,7 +126,7 @@ func (s *Storage) CreateArtifact(artifact weles.ArtifactDescription) (weles.Arti return "", err } - err = s.db.InsertArtifactInfo(&weles.ArtifactInfo{artifact, path, "", time.Now().UTC()}) + err = s.db.InsertArtifactInfo(&weles.ArtifactInfo{artifact, path, "", strfmt.DateTime(time.Now().UTC())}) if err != nil { return "", err } diff --git a/artifacts/artifacts_test.go b/artifacts/artifacts_test.go index 0336835..1086f18 100644 --- a/artifacts/artifacts_test.go +++ b/artifacts/artifacts_test.go @@ -64,23 +64,23 @@ With gently smiling jaws! var ( description = weles.ArtifactDescription{ - job, - weles.AM_IMAGEFILE, "alias", + job, + weles.ArtifactTypeIMAGE, "uri", } dSameJobNType = weles.ArtifactDescription{ - job, - weles.AM_IMAGEFILE, "other alias", + job, + weles.ArtifactTypeIMAGE, "other uri", } dSameJobOtherType = weles.ArtifactDescription{ - job, - weles.AM_YAMLFILE, "another alias", + job, + weles.ArtifactTypeYAML, "another uri", } ) @@ -226,16 +226,16 @@ With gently smiling jaws! ch chan weles.ArtifactStatusChange ad weles.ArtifactDescription = weles.ArtifactDescription{ - job, - weles.AM_IMAGEFILE, "somealias", + job, + weles.ArtifactTypeIMAGE, validURL, } adInvalid weles.ArtifactDescription = weles.ArtifactDescription{ - job, - weles.AM_IMAGEFILE, "somealias", + job, + weles.ArtifactTypeIMAGE, invalidURL, } ) @@ -255,11 +255,11 @@ With gently smiling jaws! Expect(err).ToNot(HaveOccurred()) - Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.AM_PENDING}))) - Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.AM_DOWNLOADING}))) + Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.ArtifactStatusPENDING}))) + Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.ArtifactStatusDOWNLOADING}))) Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, finalStatus}))) - if finalStatus != weles.AM_FAILED { + if finalStatus != weles.ArtifactStatusFAILED { By("Check if file exists and has proper content") content, err := ioutil.ReadFile(string(path)) @@ -278,8 +278,8 @@ With gently smiling jaws! By("Check if artifact is in ArtifactDB") Expect(checkPathInDb(path)).To(BeTrue()) }, - Entry("push artifact to db and download file", ad, weles.AM_READY), - Entry("do not push an invalid artifact", adInvalid, weles.AM_FAILED), + Entry("push artifact to db and download file", ad, weles.ArtifactStatusREADY), + Entry("do not push an invalid artifact", adInvalid, weles.ArtifactStatusFAILED), ) }) }) diff --git a/artifacts/database/database_test.go b/artifacts/database/database_test.go index 5f4dff7..6eaea32 100644 --- a/artifacts/database/database_test.go +++ b/artifacts/database/database_test.go @@ -24,6 +24,8 @@ import ( "path/filepath" "time" + "github.com/go-openapi/strfmt" + "git.tizen.org/tools/weles" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" @@ -43,73 +45,137 @@ var _ = Describe("ArtifactDB", func() { artifact = weles.ArtifactInfo{ weles.ArtifactDescription{ - job, - weles.AM_IMAGEFILE, "some alias", + job, + weles.ArtifactTypeIMAGE, "http://example.com", }, "path1", - weles.AM_PENDING, - time.Now().UTC(), + weles.ArtifactStatusPENDING, + strfmt.DateTime(time.Now().Round(time.Millisecond).UTC()), } aImageReady = weles.ArtifactInfo{ weles.ArtifactDescription{ - job + 1, - weles.AM_IMAGEFILE, "other alias", + job + 1, + weles.ArtifactTypeIMAGE, "http://example.com/1", }, "path2", - weles.AM_READY, - time.Now().UTC(), + weles.ArtifactStatusREADY, + strfmt.DateTime(time.Now().Round(time.Millisecond).UTC()), } aYamlFailed = weles.ArtifactInfo{ weles.ArtifactDescription{ - job + 1, - weles.AM_YAMLFILE, "other alias", + job + 1, + weles.ArtifactTypeYAML, "http://example.com/2", }, "path3", - weles.AM_FAILED, - time.Now().UTC(), + weles.ArtifactStatusFAILED, + strfmt.DateTime(time.Now().Round(time.Millisecond).UTC()), } aTestFailed = weles.ArtifactInfo{ weles.ArtifactDescription{ - job + 2, - weles.AM_TESTFILE, "alias", + job + 2, + weles.ArtifactTypeTEST, "http://example.com/2", }, "path4", - weles.AM_FAILED, - time.Unix(3000, 60).UTC(), + weles.ArtifactStatusFAILED, + strfmt.DateTime(time.Unix(3000, 60).Round(time.Millisecond).UTC()), } testArtifacts = []weles.ArtifactInfo{artifact, aImageReady, aYamlFailed, aTestFailed} - oneJobFilter = weles.ArtifactFilter{[]weles.JobID{artifact.JobID}, nil, nil, nil} - twoJobsFilter = weles.ArtifactFilter{[]weles.JobID{artifact.JobID, aImageReady.JobID}, nil, nil, nil} - noJobFilter = weles.ArtifactFilter{[]weles.JobID{invalidJob}, nil, nil, nil} - - oneTypeFilter = weles.ArtifactFilter{nil, []weles.ArtifactType{aYamlFailed.Type}, nil, nil} - twoTypesFilter = weles.ArtifactFilter{nil, []weles.ArtifactType{aYamlFailed.Type, aTestFailed.Type}, nil, nil} - noTypeFilter = weles.ArtifactFilter{nil, []weles.ArtifactType{invalidType}, nil, nil} - - oneStatusFilter = weles.ArtifactFilter{nil, nil, []weles.ArtifactStatus{artifact.Status}, nil} - twoStatusFilter = weles.ArtifactFilter{nil, nil, []weles.ArtifactStatus{artifact.Status, aYamlFailed.Status}, nil} - noStatusFilter = weles.ArtifactFilter{nil, nil, []weles.ArtifactStatus{invalidStatus}, nil} - - oneAliasFilter = weles.ArtifactFilter{nil, nil, nil, []weles.ArtifactAlias{artifact.Alias}} - twoAliasFilter = weles.ArtifactFilter{nil, nil, nil, []weles.ArtifactAlias{artifact.Alias, aImageReady.Alias}} - noAliasFilter = weles.ArtifactFilter{nil, nil, nil, []weles.ArtifactAlias{invalidAlias}} - - fullFilter = weles.ArtifactFilter{twoJobsFilter.JobID, twoTypesFilter.Type, twoStatusFilter.Status, twoAliasFilter.Alias} - noMatchFilter = weles.ArtifactFilter{oneJobFilter.JobID, oneTypeFilter.Type, nil, nil} - emptyFilter = weles.ArtifactFilter{} + oneJobFilter = weles.ArtifactFilter{ + JobID: []weles.JobID{artifact.JobID}, + Alias: nil, + Status: nil, + Type: nil} + twoJobsFilter = weles.ArtifactFilter{ + JobID: []weles.JobID{artifact.JobID, aImageReady.JobID}, + Alias: nil, + Status: nil, + Type: nil} + noJobFilter = weles.ArtifactFilter{ + JobID: []weles.JobID{invalidJob}, + Alias: nil, + Status: nil, + Type: nil} + + oneTypeFilter = weles.ArtifactFilter{ + JobID: nil, + Type: []weles.ArtifactType{aYamlFailed.Type}, + Status: nil, + Alias: nil} + + twoTypesFilter = weles.ArtifactFilter{ + JobID: nil, + Type: []weles.ArtifactType{aYamlFailed.Type, aTestFailed.Type}, + Status: nil, + Alias: nil} + + noTypeFilter = weles.ArtifactFilter{ + JobID: nil, + Type: []weles.ArtifactType{invalidType}, + Status: nil, + Alias: nil} + + oneStatusFilter = weles.ArtifactFilter{ + JobID: nil, + Type: nil, + Status: []weles.ArtifactStatus{artifact.Status}, + Alias: nil} + + twoStatusFilter = weles.ArtifactFilter{ + JobID: nil, + Type: nil, + Status: []weles.ArtifactStatus{artifact.Status, aYamlFailed.Status}, + Alias: nil} + + noStatusFilter = weles.ArtifactFilter{ + JobID: nil, + Type: nil, + Status: []weles.ArtifactStatus{invalidStatus}, + Alias: nil} + + oneAliasFilter = weles.ArtifactFilter{ + JobID: nil, + Type: nil, + Status: nil, + Alias: []weles.ArtifactAlias{artifact.Alias}} + + twoAliasFilter = weles.ArtifactFilter{ + JobID: nil, + Type: nil, + Status: nil, + Alias: []weles.ArtifactAlias{artifact.Alias, aImageReady.Alias}} + + noAliasFilter = weles.ArtifactFilter{ + JobID: nil, + Type: nil, + Status: nil, + Alias: []weles.ArtifactAlias{invalidAlias}} + + fullFilter = weles.ArtifactFilter{ + JobID: twoJobsFilter.JobID, + Type: twoTypesFilter.Type, + Status: twoStatusFilter.Status, + Alias: twoAliasFilter.Alias} + + noMatchFilter = weles.ArtifactFilter{ + JobID: oneJobFilter.JobID, + Type: oneTypeFilter.Type, + Status: nil, + Alias: nil} + + emptyFilter = weles.ArtifactFilter{} ) jobsInDB := func(job weles.JobID) int64 { @@ -210,17 +276,17 @@ var _ = Describe("ArtifactDB", func() { }, // types supported by select. Entry("select JobID", artifact.JobID, nil, artifact), - Entry("select Type", weles.AM_YAMLFILE, nil, aYamlFailed), - Entry("select Status", weles.AM_READY, nil, aImageReady), + Entry("select Type", weles.ArtifactTypeYAML, nil, aYamlFailed), + Entry("select Status", weles.ArtifactStatusREADY, nil, aImageReady), Entry("select Alias", artifact.Alias, nil, artifact), // type bool is not supported by select. Entry("select unsupported value", true, ErrUnsupportedQueryType), // test query itsef. Entry("select multiple entries for JobID", aImageReady.JobID, nil, aImageReady, aYamlFailed), Entry("select no entries for invalid JobID", invalidJob, nil), - Entry("select multiple entries for Type", weles.AM_IMAGEFILE, nil, artifact, aImageReady), + Entry("select multiple entries for Type", weles.ArtifactTypeIMAGE, nil, artifact, aImageReady), Entry("select multiple entries for Alias", aImageReady.Alias, nil, aImageReady, aYamlFailed), - Entry("select multiple entries for Status", weles.AM_FAILED, nil, aYamlFailed, aTestFailed), + Entry("select multiple entries for Status", weles.ArtifactStatusFAILED, nil, aYamlFailed, aTestFailed), ) }) @@ -278,8 +344,8 @@ var _ = Describe("ArtifactDB", func() { Expect(a).To(Equal(weles.ArtifactInfo{})) } }, - Entry("change status of artifact not present in ArtifactDB", weles.ArtifactStatusChange{invalidPath, weles.AM_DOWNLOADING}, sql.ErrNoRows), - Entry("change status of artifact present in ArtifactDB", weles.ArtifactStatusChange{artifact.Path, weles.AM_DOWNLOADING}, nil), + Entry("change status of artifact not present in ArtifactDB", weles.ArtifactStatusChange{invalidPath, weles.ArtifactStatusDOWNLOADING}, sql.ErrNoRows), + Entry("change status of artifact present in ArtifactDB", weles.ArtifactStatusChange{artifact.Path, weles.ArtifactStatusDOWNLOADING}, nil), ) }) }) diff --git a/artifacts/downloader/downloader.go b/artifacts/downloader/downloader.go index 3074d61..d5a278d 100644 --- a/artifacts/downloader/downloader.go +++ b/artifacts/downloader/downloader.go @@ -104,7 +104,7 @@ func (d *Downloader) download(URI weles.ArtifactURI, path weles.ArtifactPath, ch change := weles.ArtifactStatusChange{ Path: path, - NewStatus: weles.AM_DOWNLOADING, + NewStatus: weles.ArtifactStatusDOWNLOADING, } channels := []chan weles.ArtifactStatusChange{ch, d.notification} notify(change, channels) @@ -112,9 +112,9 @@ func (d *Downloader) download(URI weles.ArtifactURI, path weles.ArtifactPath, ch err := d.getData(URI, path) if err != nil { os.Remove(string(path)) - change.NewStatus = weles.AM_FAILED + change.NewStatus = weles.ArtifactStatusFAILED } else { - change.NewStatus = weles.AM_READY + change.NewStatus = weles.ArtifactStatusREADY } notify(change, channels) } @@ -123,7 +123,7 @@ func (d *Downloader) download(URI weles.ArtifactURI, path weles.ArtifactPath, ch // It puts new downloadJob on the queue. func (d *Downloader) Download(URI weles.ArtifactURI, path weles.ArtifactPath, ch chan weles.ArtifactStatusChange) error { channels := []chan weles.ArtifactStatusChange{ch, d.notification} - notify(weles.ArtifactStatusChange{path, weles.AM_PENDING}, channels) + notify(weles.ArtifactStatusChange{path, weles.ArtifactStatusPENDING}, channels) job := downloadJob{ path: path, diff --git a/artifacts/downloader/downloader_test.go b/artifacts/downloader/downloader_test.go index c6537b3..ac5d21d 100644 --- a/artifacts/downloader/downloader_test.go +++ b/artifacts/downloader/downloader_test.go @@ -125,10 +125,10 @@ I call it stupid of the pig. } }, - Entry("download valid file to valid path", validURL, true, weles.AM_READY), - Entry("fail when url is invalid", invalidURL, true, weles.AM_FAILED), - Entry("fail when path is invalid", validURL, false, weles.AM_FAILED), - Entry("fail when url and path are invalid", invalidURL, false, weles.AM_FAILED), + Entry("download valid file to valid path", validURL, true, weles.ArtifactStatusREADY), + Entry("fail when url is invalid", invalidURL, true, weles.ArtifactStatusFAILED), + Entry("fail when path is invalid", validURL, false, weles.ArtifactStatusFAILED), + Entry("fail when url and path are invalid", invalidURL, false, weles.ArtifactStatusFAILED), ) DescribeTable("download(): Notify channels and save data to file", @@ -142,11 +142,11 @@ I call it stupid of the pig. } filename := weles.ArtifactPath(filepath.Join(dir, "test")) - status := weles.ArtifactStatusChange{filename, weles.AM_DOWNLOADING} + status := weles.ArtifactStatusChange{filename, weles.ArtifactStatusDOWNLOADING} platinumKoala.download(weles.ArtifactURI(ts.URL), weles.ArtifactPath(filename), ch) - status.NewStatus = weles.AM_DOWNLOADING + status.NewStatus = weles.ArtifactStatusDOWNLOADING checkChannels(ch, platinumKoala.notification, status) status.NewStatus = finalResult @@ -161,10 +161,10 @@ I call it stupid of the pig. } }, - Entry("download valid file to valid path", validURL, true, weles.AM_READY), - Entry("fail when url is invalid", invalidURL, true, weles.AM_FAILED), - Entry("fail when path is invalid", validURL, false, weles.AM_FAILED), - Entry("fail when url and path are invalid", invalidURL, false, weles.AM_FAILED), + Entry("download valid file to valid path", validURL, true, weles.ArtifactStatusREADY), + Entry("fail when url is invalid", invalidURL, true, weles.ArtifactStatusFAILED), + Entry("fail when path is invalid", validURL, false, weles.ArtifactStatusFAILED), + Entry("fail when url and path are invalid", invalidURL, false, weles.ArtifactStatusFAILED), ) DescribeTable("Download(): Notify ch channel about any changes", @@ -181,19 +181,19 @@ I call it stupid of the pig. err := platinumKoala.Download(weles.ArtifactURI(ts.URL), path, ch) Expect(err).ToNot(HaveOccurred()) - status := weles.ArtifactStatusChange{path, weles.AM_PENDING} + status := weles.ArtifactStatusChange{path, weles.ArtifactStatusPENDING} Eventually(ch).Should(Receive(Equal(status))) - status.NewStatus = weles.AM_DOWNLOADING + status.NewStatus = weles.ArtifactStatusDOWNLOADING Eventually(ch).Should(Receive(Equal(status))) status.NewStatus = finalResult Eventually(ch).Should(Receive(Equal(status))) }, - Entry("download valid file to valid path", validURL, true, weles.AM_READY), - Entry("fail when url is invalid", invalidURL, true, weles.AM_FAILED), - Entry("fail when path is invalid", validURL, false, weles.AM_FAILED), - Entry("fail when url and path are invalid", invalidURL, false, weles.AM_FAILED), + Entry("download valid file to valid path", validURL, true, weles.ArtifactStatusREADY), + Entry("fail when url is invalid", invalidURL, true, weles.ArtifactStatusFAILED), + Entry("fail when path is invalid", validURL, false, weles.ArtifactStatusFAILED), + Entry("fail when url and path are invalid", invalidURL, false, weles.ArtifactStatusFAILED), ) DescribeTable("Download(): Download files to specified path.", @@ -206,16 +206,16 @@ I call it stupid of the pig. err := platinumKoala.Download(weles.ArtifactURI(ts.URL), path, ch) Expect(err).ToNot(HaveOccurred()) - Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.AM_PENDING}))) - Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.AM_DOWNLOADING}))) + Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.ArtifactStatusPENDING}))) + Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.ArtifactStatusDOWNLOADING}))) if poem != "" { - Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.AM_READY}))) + Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.ArtifactStatusREADY}))) content, err := ioutil.ReadFile(string(path)) Expect(err).ToNot(HaveOccurred()) Expect(string(content)).To(BeIdenticalTo(poem)) } else { - Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.AM_FAILED}))) + Eventually(ch).Should(Receive(Equal(weles.ArtifactStatusChange{path, weles.ArtifactStatusFAILED}))) content, err := ioutil.ReadFile(string(path)) Expect(err).To(HaveOccurred()) Expect(content).To(BeNil()) diff --git a/controller/boruterimpl.go b/controller/boruterimpl.go index 25c2866..b45b871 100644 --- a/controller/boruterimpl.go +++ b/controller/boruterimpl.go @@ -265,7 +265,7 @@ func (h *BoruterImpl) getDeadline(config weles.Config) time.Time { // Request registers new request in Boruta and adds it to monitored requests. func (h *BoruterImpl) Request(j weles.JobID) { - err := h.jobs.SetStatusAndInfo(j, weles.JOB_WAITING, "") + err := h.jobs.SetStatusAndInfo(j, weles.JobStatusWAITING, "") if err != nil { h.SendFail(j, fmt.Sprintf("Internal Weles error while changing Job status : %s", err.Error())) return diff --git a/controller/boruterimpl_test.go b/controller/boruterimpl_test.go index 6512505..0c646e6 100644 --- a/controller/boruterimpl_test.go +++ b/controller/boruterimpl_test.go @@ -120,7 +120,7 @@ var _ = Describe("BoruterImpl", func() { It("should ignore ListRequests errors", func() { counter := 5 mutex := &sync.Mutex{} - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, priority, owner, gomock.Any(), gomock.Any()).Return(rid, nil) req.EXPECT().ListRequests(nil).AnyTimes().Return([]boruta.ReqInfo{}, err).Do(func(boruta.ListFilter) { @@ -142,7 +142,7 @@ var _ = Describe("BoruterImpl", func() { Describe("Request", func() { It("should register job successfully", func() { var va, dl time.Time - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, priority, owner, gomock.Any(), gomock.Any()).Return(rid, nil).Do( func(c boruta.Capabilities, p boruta.Priority, ui boruta.UserInfo, validAfter time.Time, deadline time.Time) { @@ -167,7 +167,7 @@ var _ = Describe("BoruterImpl", func() { config.Timeouts.JobTimeout = weles.ValidPeriod(0) defaultDelay := 24 * time.Hour - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, priority, owner, gomock.Any(), gomock.Any()).Return(rid, nil).Do( func(c boruta.Capabilities, p boruta.Priority, ui boruta.UserInfo, validAfter time.Time, deadline time.Time) { @@ -188,7 +188,7 @@ var _ = Describe("BoruterImpl", func() { expectRegistered(1) }) It("should fail if NewRequest fails", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, priority, owner, gomock.Any(), gomock.Any()).Return(boruta.ReqID(0), err) req.EXPECT().ListRequests(nil).AnyTimes() @@ -199,7 +199,7 @@ var _ = Describe("BoruterImpl", func() { eventuallyEmpty(1) }) It("should fail if GetConfig fails", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(weles.Config{}, err) req.EXPECT().ListRequests(nil).AnyTimes() @@ -209,7 +209,7 @@ var _ = Describe("BoruterImpl", func() { eventuallyEmpty(1) }) It("should fail if SetStatusAndInfo fails", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "").Return(err) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "").Return(err) req.EXPECT().ListRequests(nil).AnyTimes() h.Request(j) @@ -219,7 +219,7 @@ var _ = Describe("BoruterImpl", func() { }) It("should call NewRequest with empty caps if no device type provided", func() { config.DeviceType = "" - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(boruta.Capabilities{}, priority, owner, gomock.Any(), gomock.Any()).Return(boruta.ReqID(0), err) req.EXPECT().ListRequests(nil).AnyTimes() @@ -238,7 +238,7 @@ var _ = Describe("BoruterImpl", func() { } for k, v := range m { config.Priority = k - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, v, owner, gomock.Any(), gomock.Any()).Return(boruta.ReqID(0), err) req.EXPECT().ListRequests(nil).AnyTimes() @@ -264,7 +264,7 @@ var _ = Describe("BoruterImpl", func() { ai := boruta.AccessInfo{Addr: &net.IPNet{IP: net.IPv4(1, 2, 3, 4), Mask: net.IPv4Mask(5, 6, 7, 8)}} BeforeEach(func() { var va, dl time.Time - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_WAITING, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusWAITING, "") jc.EXPECT().GetConfig(j).Return(config, nil) req.EXPECT().NewRequest(caps, priority, owner, gomock.Any(), gomock.Any()).Return(rid, nil).Do( func(c boruta.Capabilities, p boruta.Priority, ui boruta.UserInfo, validAfter time.Time, deadline time.Time) { diff --git a/controller/controller.go b/controller/controller.go index 59d39ba..55b5f0c 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -109,7 +109,7 @@ func (c *Controller) CreateJob(yaml []byte) (weles.JobID, error) { // CancelJob cancels Job identified by argument. Job execution is stopped. // It is a part of JobManager implementation. func (c *Controller) CancelJob(j weles.JobID) error { - err := c.jobs.SetStatusAndInfo(j, weles.JOB_CANCELED, "") + err := c.jobs.SetStatusAndInfo(j, weles.JobStatusCANCELED, "") if err != nil { return err } @@ -165,13 +165,13 @@ func (c *Controller) loop() { // fail sets Job in FAILED state and if needed stops Job's execution on Dryad // and releases Dryad to Boruta. func (c *Controller) fail(j weles.JobID, msg string) { - c.jobs.SetStatusAndInfo(j, weles.JOB_FAILED, msg) + c.jobs.SetStatusAndInfo(j, weles.JobStatusFAILED, msg) c.dryader.CancelJob(j) c.boruter.Release(j) } // succeed sets Job in COMPLETED state. func (c *Controller) succeed(j weles.JobID) { - c.jobs.SetStatusAndInfo(j, weles.JOB_COMPLETED, "") + c.jobs.SetStatusAndInfo(j, weles.JobStatusCOMPLETED, "") c.boruter.Release(j) } diff --git a/controller/controller_test.go b/controller/controller_test.go index b792a95..1d5a9fc 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -149,7 +149,7 @@ var _ = Describe("Controller", func() { Describe("CancelJob", func() { It("should cancel Job, stop execution on Dryad and release Dryad to Boruta", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_CANCELED, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusCANCELED, "") dry.EXPECT().CancelJob(j) bor.EXPECT().Release(j) @@ -158,7 +158,7 @@ var _ = Describe("Controller", func() { Expect(retErr).To(BeNil()) }) It("should return error if Job fails to be cancelled", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_CANCELED, "").Return(testErr) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusCANCELED, "").Return(testErr) retErr := h.CancelJob(j) @@ -203,13 +203,13 @@ var _ = Describe("Controller", func() { }, &borChan), Entry("should complete Job after Dryad Job is done", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_COMPLETED, "") + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusCOMPLETED, "") bor.EXPECT().Release(j).Do(setDone) }, &dryChan), ) DescribeTable("Action fail", func(cnn *chan notifier.Notification) { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_FAILED, testMsg) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusFAILED, testMsg) dry.EXPECT().CancelJob(j) bor.EXPECT().Release(j) *cnn <- notiFail diff --git a/controller/downloaderimpl.go b/controller/downloaderimpl.go index 6f3a14f..c5e2a8d 100644 --- a/controller/downloaderimpl.go +++ b/controller/downloaderimpl.go @@ -99,10 +99,10 @@ func (h *DownloaderImpl) pathStatusChange(path string, status weles.ArtifactStat return } switch status { - case weles.AM_READY: + case weles.ArtifactStatusREADY: i.ready++ info = fmt.Sprintf(formatReady, i.ready, i.paths) - case weles.AM_FAILED: + case weles.ArtifactStatusFAILED: i.failed++ info = "Failed to download artifact" default: @@ -136,7 +136,7 @@ func (h *DownloaderImpl) loop() { continue } - err := h.jobs.SetStatusAndInfo(j, weles.JOB_DOWNLOADING, info) + err := h.jobs.SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, info) if err != nil { h.removePath(string(change.Path)) h.fail(j, fmt.Sprintf(formatJobStatus, err.Error())) @@ -211,7 +211,7 @@ func (h *DownloaderImpl) push(j weles.JobID, t weles.ArtifactType, alias string, func (h *DownloaderImpl) pullCreate(j weles.JobID, alias string) (string, error) { p, err := h.artifacts.CreateArtifact(weles.ArtifactDescription{ JobID: j, - Type: weles.AM_TESTFILE, + Type: weles.ArtifactTypeTEST, Alias: weles.ArtifactAlias(alias), }) return string(p), err @@ -272,7 +272,7 @@ func (h *DownloaderImpl) sendIfReady(j weles.JobID) { func (h *DownloaderImpl) DispatchDownloads(j weles.JobID) { h.initializeJobInfo(j) - err := h.jobs.SetStatusAndInfo(j, weles.JOB_DOWNLOADING, "") + err := h.jobs.SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, "") if err != nil { h.fail(j, fmt.Sprintf(formatJobStatus, err.Error())) return @@ -286,7 +286,7 @@ func (h *DownloaderImpl) DispatchDownloads(j weles.JobID) { for i, image := range config.Action.Deploy.Images { if image.URI != "" { - path, err := h.push(j, weles.AM_IMAGEFILE, fmt.Sprintf("Image_%d", i), image.URI) + path, err := h.push(j, weles.ArtifactTypeIMAGE, fmt.Sprintf("Image_%d", i), image.URI) if err != nil { h.fail(j, fmt.Sprintf(formatURI, image.URI, err.Error())) return @@ -294,7 +294,7 @@ func (h *DownloaderImpl) DispatchDownloads(j weles.JobID) { config.Action.Deploy.Images[i].Path = path } if image.ChecksumURI != "" { - path, err := h.push(j, weles.AM_IMAGEFILE, fmt.Sprintf("ImageMD5_%d", i), image.ChecksumURI) + path, err := h.push(j, weles.ArtifactTypeIMAGE, fmt.Sprintf("ImageMD5_%d", i), image.ChecksumURI) if err != nil { h.fail(j, fmt.Sprintf(formatURI, image.ChecksumURI, err.Error())) return @@ -307,7 +307,7 @@ func (h *DownloaderImpl) DispatchDownloads(j weles.JobID) { switch ta.(type) { case weles.Push: action := ta.(weles.Push) - path, err := h.push(j, weles.AM_TESTFILE, action.Alias, action.URI) + path, err := h.push(j, weles.ArtifactTypeTEST, action.Alias, action.URI) if err != nil { h.fail(j, fmt.Sprintf(formatURI, action.URI, err.Error())) return diff --git a/controller/downloaderimpl_test.go b/controller/downloaderimpl_test.go index 28e9098..1d401bf 100644 --- a/controller/downloaderimpl_test.go +++ b/controller/downloaderimpl_test.go @@ -172,7 +172,7 @@ var _ = Describe("DownloaderImpl", func() { eventuallyNoti(offset+1, false, msg) expectPath(offset+1, 0, pathsNo) eventuallyInfoEmpty(offset + 1) - sendChange(0, pathsNo, weles.AM_READY) + sendChange(0, pathsNo, weles.ArtifactStatusREADY) eventuallyPathEmpty(offset + 1) } defaultSetStatusAndInfo := func(successfulEntries int, fail bool) *gomock.Call { @@ -180,14 +180,14 @@ var _ = Describe("DownloaderImpl", func() { var prev, call *gomock.Call for i = 0; i < successfulEntries; i++ { - call = jc.EXPECT().SetStatusAndInfo(j, weles.JOB_DOWNLOADING, infos[i]) + call = jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, infos[i]) if prev != nil { call.After(prev) } prev = call } if fail { - call = jc.EXPECT().SetStatusAndInfo(j, weles.JOB_DOWNLOADING, infos[i]).Return(err) + call = jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, infos[i]).Return(err) if prev != nil { call.After(prev) } @@ -198,7 +198,7 @@ var _ = Describe("DownloaderImpl", func() { jc.EXPECT().GetConfig(j).Return(config, nil) } defaultPush := func(successfulEntries int, fail bool) *gomock.Call { - types := []weles.ArtifactType{weles.AM_IMAGEFILE, weles.AM_IMAGEFILE, weles.AM_IMAGEFILE, weles.AM_IMAGEFILE, weles.AM_TESTFILE, weles.AM_TESTFILE, weles.AM_TESTFILE} + types := []weles.ArtifactType{weles.ArtifactTypeIMAGE, weles.ArtifactTypeIMAGE, weles.ArtifactTypeIMAGE, weles.ArtifactTypeIMAGE, weles.ArtifactTypeTEST, weles.ArtifactTypeTEST, weles.ArtifactTypeTEST} aliases := []weles.ArtifactAlias{"Image_0", "ImageMD5_0", "Image_1", "ImageMD5_2", "alias_0", "alias_1", "alias_3"} uris := []weles.ArtifactURI{"image_0", "md5_0", "image_1", "md5_2", "uri_0", "uri_1", "uri_3"} var i int @@ -222,7 +222,7 @@ var _ = Describe("DownloaderImpl", func() { return call } defaultCreate := func(successfulEntries int, fail bool) *gomock.Call { - types := []weles.ArtifactType{weles.AM_TESTFILE, weles.AM_TESTFILE} + types := []weles.ArtifactType{weles.ArtifactTypeTEST, weles.ArtifactTypeTEST} aliases := []weles.ArtifactAlias{"alias_2", "alias_4"} returnPaths := []weles.ArtifactPath{weles.ArtifactPath(paths[7]), weles.ArtifactPath(paths[8])} var i int @@ -260,7 +260,7 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, true, 7) - sendChange(0, 7, weles.AM_READY) + sendChange(0, 7, weles.ArtifactStatusREADY) eventuallyNoti(1, true, "") eventuallyEmpty(1) @@ -365,7 +365,7 @@ var _ = Describe("DownloaderImpl", func() { }) It("should handle downloading failure", func() { c := defaultSetStatusAndInfo(4, false) - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_DOWNLOADING, "Failed to download artifact").After(c) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, "Failed to download artifact").After(c) defaultGetConfig() defaultPush(7, false) defaultCreate(2, false) @@ -376,14 +376,14 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, true, 7) - sendChange(0, 3, weles.AM_READY) - sendChange(3, 4, weles.AM_FAILED) + sendChange(0, 3, weles.ArtifactStatusREADY) + sendChange(3, 4, weles.ArtifactStatusFAILED) eventuallyNoti(1, false, formatDownload) expectPath(1, 4, 7) eventuallyInfoEmpty(1) - sendChange(4, 7, weles.AM_DOWNLOADING) + sendChange(4, 7, weles.ArtifactStatusDOWNLOADING) eventuallyPathEmpty(1) }) It("should block reply until configuration is saved and all artifacts are downloaded", func() { @@ -409,7 +409,7 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, false, 7) - sendChange(0, 7, weles.AM_READY) + sendChange(0, 7, weles.ArtifactStatusREADY) holdDownload.Done() eventuallyNoti(1, true, "") @@ -427,7 +427,7 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, true, 7) - sendChange(0, 7, weles.AM_READY) + sendChange(0, 7, weles.ArtifactStatusREADY) eventuallyNoti(1, false, "Internal Weles error while changing Job status : test error") eventuallyEmpty(1) @@ -454,7 +454,7 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, false, 7) - sendChange(0, 7, weles.AM_READY) + sendChange(0, 7, weles.ArtifactStatusREADY) eventuallyNoti(1, false, "Internal Weles error while changing Job status : test error") @@ -464,7 +464,7 @@ var _ = Describe("DownloaderImpl", func() { }) It("should leave no data left if failure response is sent while pushing", func() { c := defaultSetStatusAndInfo(1, false) - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_DOWNLOADING, "1 / 1 artifacts ready").Return(err).After(c) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusDOWNLOADING, "1 / 1 artifacts ready").Return(err).After(c) defaultGetConfig() holdDownload := sync.WaitGroup{} holdDownload.Add(1) @@ -482,12 +482,12 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 1) expectInfo(1, false, 1) - sendChange(0, 1, weles.AM_READY) + sendChange(0, 1, weles.ArtifactStatusREADY) eventuallyNoti(1, false, "Internal Weles error while changing Job status : test error") holdDownload.Done() - sendChange(1, 2, weles.AM_READY) + sendChange(1, 2, weles.ArtifactStatusREADY) eventuallyEmpty(1) }) @@ -503,13 +503,13 @@ var _ = Describe("DownloaderImpl", func() { expectPath(1, 0, 7) expectInfo(1, true, 7) - sendChange(0, 7, weles.AM_DOWNLOADING) - sendChange(0, 7, weles.AM_PENDING) + sendChange(0, 7, weles.ArtifactStatusDOWNLOADING) + sendChange(0, 7, weles.ArtifactStatusPENDING) expectPath(1, 0, 7) expectInfo(1, true, 7) - sendChange(0, 7, weles.AM_READY) + sendChange(0, 7, weles.ArtifactStatusREADY) eventuallyNoti(1, true, "") eventuallyEmpty(1) diff --git a/controller/dryaderimpl.go b/controller/dryaderimpl.go index ac5b1d3..b4e4eae 100644 --- a/controller/dryaderimpl.go +++ b/controller/dryaderimpl.go @@ -90,7 +90,7 @@ func (h *DryaderImpl) remove(j weles.JobID) { // setStatus sets Jobs status to RUNNING and updates info. func (h *DryaderImpl) setStatus(j weles.JobID, msg string) { - err := h.jobs.SetStatusAndInfo(j, weles.JOB_RUNNING, msg) + err := h.jobs.SetStatusAndInfo(j, weles.JobStatusRUNNING, msg) if err != nil { h.remove(j) h.SendFail(j, fmt.Sprintf("Internal Weles error while changing Job status : %s", err.Error())) diff --git a/controller/dryaderimpl_test.go b/controller/dryaderimpl_test.go index 4e11997..deac3cf 100644 --- a/controller/dryaderimpl_test.go +++ b/controller/dryaderimpl_test.go @@ -162,7 +162,7 @@ var _ = Describe("DryaderImpl", func() { It("should update status of the Job", func() { for i, s := range updateStates { change := weles.DryadJobInfo{Job: j, Status: s} - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_RUNNING, updateMsgs[i]) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusRUNNING, updateMsgs[i]) h.(*DryaderImpl).listener <- weles.DryadJobStatusChange(change) @@ -179,7 +179,7 @@ var _ = Describe("DryaderImpl", func() { DescribeTable("should fail if updating status of the Job fails", func(s weles.DryadJobStatus, msg string) { change := weles.DryadJobInfo{Job: j, Status: s} - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_RUNNING, msg).Return(err) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusRUNNING, msg).Return(err) h.(*DryaderImpl).listener <- weles.DryadJobStatusChange(change) diff --git a/controller/jobscontrollerimpl.go b/controller/jobscontrollerimpl.go index b7cd51c..49fbd5e 100644 --- a/controller/jobscontrollerimpl.go +++ b/controller/jobscontrollerimpl.go @@ -23,6 +23,8 @@ import ( "sync" "time" + "github.com/go-openapi/strfmt" + "git.tizen.org/tools/weles" ) @@ -80,13 +82,13 @@ func (js *JobsControllerImpl) NewJob(yaml []byte) (weles.JobID, error) { j := js.nextID() - now := time.Now() + now := strfmt.DateTime(time.Now()) js.jobs[j] = &Job{ JobInfo: weles.JobInfo{ JobID: j, Created: now, Updated: now, - Status: weles.JOB_NEW, + Status: weles.JobStatusNEW, }, yaml: yaml, } @@ -120,7 +122,7 @@ func (js *JobsControllerImpl) SetConfig(j weles.JobID, conf weles.Config) error } job.config = conf - job.Updated = time.Now() + job.Updated = strfmt.DateTime(time.Now()) return nil } @@ -131,29 +133,29 @@ func isStatusChangeValid(oldStatus, newStatus weles.JobStatus) bool { return true } switch oldStatus { - case weles.JOB_NEW: + case weles.JobStatusNEW: switch newStatus { - case weles.JOB_PARSING, weles.JOB_CANCELED, weles.JOB_FAILED: + case weles.JobStatusPARSING, weles.JobStatusCANCELED, weles.JobStatusFAILED: return true } - case weles.JOB_PARSING: + case weles.JobStatusPARSING: switch newStatus { - case weles.JOB_DOWNLOADING, weles.JOB_CANCELED, weles.JOB_FAILED: + case weles.JobStatusDOWNLOADING, weles.JobStatusCANCELED, weles.JobStatusFAILED: return true } - case weles.JOB_DOWNLOADING: + case weles.JobStatusDOWNLOADING: switch newStatus { - case weles.JOB_WAITING, weles.JOB_CANCELED, weles.JOB_FAILED: + case weles.JobStatusWAITING, weles.JobStatusCANCELED, weles.JobStatusFAILED: return true } - case weles.JOB_WAITING: + case weles.JobStatusWAITING: switch newStatus { - case weles.JOB_RUNNING, weles.JOB_CANCELED, weles.JOB_FAILED: + case weles.JobStatusRUNNING, weles.JobStatusCANCELED, weles.JobStatusFAILED: return true } - case weles.JOB_RUNNING: + case weles.JobStatusRUNNING: switch newStatus { - case weles.JOB_COMPLETED, weles.JOB_CANCELED, weles.JOB_FAILED: + case weles.JobStatusCOMPLETED, weles.JobStatusCANCELED, weles.JobStatusFAILED: return true } } @@ -162,15 +164,15 @@ func isStatusChangeValid(oldStatus, newStatus weles.JobStatus) bool { // SetStatusAndInfo changes status of the Job and updates info. Only valid // changes are allowed. -// There are 3 terminal statuses: JOB_FAILED, JOB_CANCELED, JOB_COMPLETED; -// and 5 non-terminal statuses: JOB_NEW, JOB_PARSING, JOB_DOWNLOADING, -// JOB_WAITING, JOB_RUNNING. +// There are 3 terminal statuses: JobStatusFAILED, JobStatusCANCELED, JobStatusCOMPLETED; +// and 5 non-terminal statuses: JobStatusNEW, JobStatusPARSING, JobStatusDOWNLOADING, +// JobStatusWAITING, JobStatusRUNNING. // Only below changes of statuses are allowed: -// * JOB_NEW --> {JOB_PARSING, JOB_CANCELED, JOB_FAILED} -// * JOB_PARSING --> {JOB_DOWNLOADING, JOB_CANCELED, JOB_FAILED} -// * JOB_DOWNLOADING --> {JOB_WAITING, JOB_CANCELED, JOB_FAILED} -// * JOB_WAITING --> {JOB_RUNNING, JOB_CANCELED, JOB_FAILED} -// * JOB_RUNNING --> {JOB_COMPLETED, JOB_CANCELED, JOB_FAILED} +// * JobStatusNEW --> {JobStatusPARSING, JobStatusCANCELED, JobStatusFAILED} +// * JobStatusPARSING --> {JobStatusDOWNLOADING, JobStatusCANCELED, JobStatusFAILED} +// * JobStatusDOWNLOADING --> {JobStatusWAITING, JobStatusCANCELED, JobStatusFAILED} +// * JobStatusWAITING --> {JobStatusRUNNING, JobStatusCANCELED, JobStatusFAILED} +// * JobStatusRUNNING --> {JobStatusCOMPLETED, JobStatusCANCELED, JobStatusFAILED} func (js *JobsControllerImpl) SetStatusAndInfo(j weles.JobID, newStatus weles.JobStatus, msg string) error { js.mutex.Lock() defer js.mutex.Unlock() @@ -186,7 +188,7 @@ func (js *JobsControllerImpl) SetStatusAndInfo(j weles.JobID, newStatus weles.Jo job.Status = newStatus job.Info = msg - job.Updated = time.Now() + job.Updated = strfmt.DateTime(time.Now()) return nil } diff --git a/controller/jobscontrollerimpl_test.go b/controller/jobscontrollerimpl_test.go index 8598f4a..bead78b 100644 --- a/controller/jobscontrollerimpl_test.go +++ b/controller/jobscontrollerimpl_test.go @@ -21,9 +21,10 @@ import ( "net" "time" - "git.tizen.org/tools/weles" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + + "git.tizen.org/tools/weles" ) var _ = Describe("JobsControllerImpl", func() { @@ -75,9 +76,9 @@ var _ = Describe("JobsControllerImpl", func() { Expect(ok).To(BeTrue()) Expect(job.JobID).To(Equal(j)) Expect(job.Created).To(Equal(job.Updated)) - Expect(job.Created).To(BeTemporally(">=", before)) - Expect(job.Created).To(BeTemporally("<=", after)) - Expect(job.Status).To(Equal(weles.JOB_NEW)) + Expect(time.Time(job.Created)).To(BeTemporally(">=", before)) + Expect(time.Time(job.Created)).To(BeTemporally("<=", after)) + Expect(job.Status).To(Equal(weles.JobStatusNEW)) Expect(job.yaml).To(Equal(yaml)) }) }) @@ -95,54 +96,54 @@ var _ = Describe("JobsControllerImpl", func() { }) Describe("SetStatus", func() { allStatus := []weles.JobStatus{ - weles.JOB_NEW, - weles.JOB_PARSING, - weles.JOB_DOWNLOADING, - weles.JOB_WAITING, - weles.JOB_RUNNING, - weles.JOB_FAILED, - weles.JOB_CANCELED, - weles.JOB_COMPLETED, + weles.JobStatusNEW, + weles.JobStatusPARSING, + weles.JobStatusDOWNLOADING, + weles.JobStatusWAITING, + weles.JobStatusRUNNING, + weles.JobStatusFAILED, + weles.JobStatusCANCELED, + weles.JobStatusCOMPLETED, } validChanges := map[weles.JobStatus](map[weles.JobStatus]bool){ - weles.JOB_NEW: map[weles.JobStatus]bool{ - weles.JOB_NEW: true, - weles.JOB_PARSING: true, - weles.JOB_FAILED: true, - weles.JOB_CANCELED: true, + weles.JobStatusNEW: map[weles.JobStatus]bool{ + weles.JobStatusNEW: true, + weles.JobStatusPARSING: true, + weles.JobStatusFAILED: true, + weles.JobStatusCANCELED: true, }, - weles.JOB_PARSING: map[weles.JobStatus]bool{ - weles.JOB_PARSING: true, - weles.JOB_DOWNLOADING: true, - weles.JOB_FAILED: true, - weles.JOB_CANCELED: true, + weles.JobStatusPARSING: map[weles.JobStatus]bool{ + weles.JobStatusPARSING: true, + weles.JobStatusDOWNLOADING: true, + weles.JobStatusFAILED: true, + weles.JobStatusCANCELED: true, }, - weles.JOB_DOWNLOADING: map[weles.JobStatus]bool{ - weles.JOB_DOWNLOADING: true, - weles.JOB_WAITING: true, - weles.JOB_FAILED: true, - weles.JOB_CANCELED: true, + weles.JobStatusDOWNLOADING: map[weles.JobStatus]bool{ + weles.JobStatusDOWNLOADING: true, + weles.JobStatusWAITING: true, + weles.JobStatusFAILED: true, + weles.JobStatusCANCELED: true, }, - weles.JOB_WAITING: map[weles.JobStatus]bool{ - weles.JOB_WAITING: true, - weles.JOB_RUNNING: true, - weles.JOB_FAILED: true, - weles.JOB_CANCELED: true, + weles.JobStatusWAITING: map[weles.JobStatus]bool{ + weles.JobStatusWAITING: true, + weles.JobStatusRUNNING: true, + weles.JobStatusFAILED: true, + weles.JobStatusCANCELED: true, }, - weles.JOB_RUNNING: map[weles.JobStatus]bool{ - weles.JOB_RUNNING: true, - weles.JOB_FAILED: true, - weles.JOB_CANCELED: true, - weles.JOB_COMPLETED: true, + weles.JobStatusRUNNING: map[weles.JobStatus]bool{ + weles.JobStatusRUNNING: true, + weles.JobStatusFAILED: true, + weles.JobStatusCANCELED: true, + weles.JobStatusCOMPLETED: true, }, - weles.JOB_FAILED: map[weles.JobStatus]bool{ - weles.JOB_FAILED: true, + weles.JobStatusFAILED: map[weles.JobStatus]bool{ + weles.JobStatusFAILED: true, }, - weles.JOB_CANCELED: map[weles.JobStatus]bool{ - weles.JOB_CANCELED: true, + weles.JobStatusCANCELED: map[weles.JobStatus]bool{ + weles.JobStatusCANCELED: true, }, - weles.JOB_COMPLETED: map[weles.JobStatus]bool{ - weles.JOB_COMPLETED: true, + weles.JobStatusCOMPLETED: map[weles.JobStatus]bool{ + weles.JobStatusCOMPLETED: true, }, } It("should return error for not existing job", func() { @@ -172,7 +173,7 @@ var _ = Describe("JobsControllerImpl", func() { Expect(err).NotTo(HaveOccurred()) Expect(job.Status).To(Equal(newStatus)) Expect(job.Info).To(Equal(info)) - Expect(job.Updated).To(BeTemporally(">=", oldUpdated)) + Expect(time.Time(job.Updated)).To(BeTemporally(">=", time.Time(oldUpdated))) }) } } @@ -188,8 +189,8 @@ var _ = Describe("JobsControllerImpl", func() { Expect(err).NotTo(HaveOccurred()) Expect(jc.(*JobsControllerImpl).jobs[j].config).To(Equal(config)) - Expect(jc.(*JobsControllerImpl).jobs[j].Updated).To(BeTemporally(">=", before)) - Expect(jc.(*JobsControllerImpl).jobs[j].Updated).To(BeTemporally("<=", after)) + Expect(time.Time(jc.(*JobsControllerImpl).jobs[j].Updated)).To(BeTemporally(">=", before)) + Expect(time.Time(jc.(*JobsControllerImpl).jobs[j].Updated)).To(BeTemporally("<=", after)) }) It("should return error for not existing job", func() { config := weles.Config{JobName: "Test Job"} diff --git a/controller/parserimpl.go b/controller/parserimpl.go index 613623a..17f0643 100644 --- a/controller/parserimpl.go +++ b/controller/parserimpl.go @@ -52,7 +52,7 @@ func NewParser(j JobsController, a weles.ArtifactManager, p weles.Parser) Parser // Parse prepares new Job to be processed by saving yaml file in ArtifactDB, // parsing yaml and preparing Job's configuration. func (h *ParserImpl) Parse(j weles.JobID) { - err := h.jobs.SetStatusAndInfo(j, weles.JOB_PARSING, "") + err := h.jobs.SetStatusAndInfo(j, weles.JobStatusPARSING, "") if err != nil { h.SendFail(j, fmt.Sprintf("Internal Weles error while changing Job status : %s", err.Error())) return @@ -66,7 +66,7 @@ func (h *ParserImpl) Parse(j weles.JobID) { path, err := h.artifacts.CreateArtifact(weles.ArtifactDescription{ JobID: j, - Type: weles.AM_YAMLFILE, + Type: weles.ArtifactTypeYAML, }) if err != nil { h.SendFail(j, fmt.Sprintf("Internal Weles error while creating file path in ArtifactDB : %s", err.Error())) diff --git a/controller/parserimpl_test.go b/controller/parserimpl_test.go index 0f48ff3..9ff7556 100644 --- a/controller/parserimpl_test.go +++ b/controller/parserimpl_test.go @@ -66,9 +66,9 @@ var _ = Describe("ParserImpl", func() { Describe("Parse", func() { It("should handle job successfully", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return(yaml, nil), - am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.AM_YAMLFILE}).Return(goodpath, nil), + am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.ArtifactTypeYAML}).Return(goodpath, nil), yp.EXPECT().ParseYaml(yaml).Return(&config, nil), jc.EXPECT().SetConfig(j, config), ) @@ -82,9 +82,9 @@ var _ = Describe("ParserImpl", func() { }) It("should fail when unable to set config", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return(yaml, nil), - am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.AM_YAMLFILE}).Return(goodpath, nil), + am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.ArtifactTypeYAML}).Return(goodpath, nil), yp.EXPECT().ParseYaml(yaml).Return(&config, nil), jc.EXPECT().SetConfig(j, config).Return(err), ) @@ -100,9 +100,9 @@ var _ = Describe("ParserImpl", func() { }) It("should fail when unable to parse yaml", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return(yaml, nil), - am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.AM_YAMLFILE}).Return(goodpath, nil), + am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.ArtifactTypeYAML}).Return(goodpath, nil), yp.EXPECT().ParseYaml(yaml).Return(&weles.Config{}, err), ) @@ -117,9 +117,9 @@ var _ = Describe("ParserImpl", func() { }) It("should fail when unable to write yaml file", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return(yaml, nil), - am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.AM_YAMLFILE}).Return(badpath, nil), + am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.ArtifactTypeYAML}).Return(badpath, nil), ) h.Parse(j) @@ -133,9 +133,9 @@ var _ = Describe("ParserImpl", func() { }) It("should fail when unable to create path in ArtifactDB", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return(yaml, nil), - am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.AM_YAMLFILE}).Return(weles.ArtifactPath(""), err), + am.EXPECT().CreateArtifact(weles.ArtifactDescription{JobID: j, Type: weles.ArtifactTypeYAML}).Return(weles.ArtifactPath(""), err), ) h.Parse(j) @@ -149,7 +149,7 @@ var _ = Describe("ParserImpl", func() { }) It("should fail when unable to get yaml", func() { gomock.InOrder( - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, ""), + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, ""), jc.EXPECT().GetYaml(j).Return([]byte{}, err), ) @@ -163,7 +163,7 @@ var _ = Describe("ParserImpl", func() { Eventually(r).Should(Receive(Equal(expectedNotification))) }) It("should fail when unable to change job status", func() { - jc.EXPECT().SetStatusAndInfo(j, weles.JOB_PARSING, "").Return(err) + jc.EXPECT().SetStatusAndInfo(j, weles.JobStatusPARSING, "").Return(err) h.Parse(j) diff --git a/job_id.go b/job_id.go new file mode 100644 index 0000000..2338cf4 --- /dev/null +++ b/job_id.go @@ -0,0 +1,34 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// 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" +) + +// JobID is a unique identifier for Weles Job. +// swagger:model JobID +type JobID uint64 + +// Validate validates this job ID +func (m JobID) Validate(formats strfmt.Registry) error { + return nil +} diff --git a/job_info.go b/job_info.go new file mode 100644 index 0000000..86f3d93 --- /dev/null +++ b/job_info.go @@ -0,0 +1,156 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// 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" +) + +// JobInfo contains information about a Job available for public API. +// swagger:model JobInfo +type JobInfo struct { + + // is the Job creation time in UTC. + // Format: date-time + Created strfmt.DateTime `json:"created,omitempty"` + + // provides additional information about current state, e.g. cause of failure + Info string `json:"info,omitempty"` + + // is a unique Job identifier + JobID JobID `json:"jobID,omitempty"` + + // is the Job name acquired from yaml file during Job creation. + Name string `json:"name,omitempty"` + + // specifies current state of the Job. + Status JobStatus `json:"status,omitempty"` + + // is the time of latest Jobs' status modification. + // Format: date-time + Updated strfmt.DateTime `json:"updated,omitempty"` +} + +// Validate validates this job info +func (m *JobInfo) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateCreated(formats); err != nil { + res = append(res, err) + } + + if err := m.validateJobID(formats); err != nil { + res = append(res, err) + } + + if err := m.validateStatus(formats); err != nil { + res = append(res, err) + } + + if err := m.validateUpdated(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *JobInfo) validateCreated(formats strfmt.Registry) error { + + if swag.IsZero(m.Created) { // not required + return nil + } + + if err := validate.FormatOf("created", "body", "date-time", m.Created.String(), formats); err != nil { + return err + } + + return nil +} + +func (m *JobInfo) validateJobID(formats strfmt.Registry) error { + + if swag.IsZero(m.JobID) { // not required + return nil + } + + if err := m.JobID.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("jobID") + } + return err + } + + return nil +} + +func (m *JobInfo) validateStatus(formats strfmt.Registry) error { + + if swag.IsZero(m.Status) { // not required + return nil + } + + if err := m.Status.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("status") + } + return err + } + + return nil +} + +func (m *JobInfo) validateUpdated(formats strfmt.Registry) error { + + if swag.IsZero(m.Updated) { // not required + return nil + } + + if err := validate.FormatOf("updated", "body", "date-time", m.Updated.String(), formats); err != nil { + return err + } + + return nil +} + +// MarshalBinary interface implementation +func (m *JobInfo) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *JobInfo) UnmarshalBinary(b []byte) error { + var res JobInfo + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/job_status.go b/job_status.go new file mode 100644 index 0000000..45e0888 --- /dev/null +++ b/job_status.go @@ -0,0 +1,113 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved +// +// 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 weles + +// 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" +) + +// JobStatus specifies state of the Job. +// +// * NEW - The new Job has been created. +// +// * PARSING - Provided yaml file is being parsed and interpreted. +// +// * DOWNLOADING - Images and/or files required for the test are being downloaded. +// +// * WAITING - Job is waiting for Boruta worker. +// +// * RUNNING - Job is being executed. +// +// * COMPLETED - Job is completed. This is terminal state. +// +// * FAILED - Job execution has failed. This is terminal state. +// +// * CANCELED -Job has been canceled with API call. This is terminal state. +// +// swagger:model JobStatus +type JobStatus string + +const ( + + // JobStatusNEW captures enum value "NEW" + JobStatusNEW JobStatus = "NEW" + + // JobStatusPARSING captures enum value "PARSING" + JobStatusPARSING JobStatus = "PARSING" + + // JobStatusDOWNLOADING captures enum value "DOWNLOADING" + JobStatusDOWNLOADING JobStatus = "DOWNLOADING" + + // JobStatusWAITING captures enum value "WAITING" + JobStatusWAITING JobStatus = "WAITING" + + // JobStatusRUNNING captures enum value "RUNNING" + JobStatusRUNNING JobStatus = "RUNNING" + + // JobStatusCOMPLETED captures enum value "COMPLETED" + JobStatusCOMPLETED JobStatus = "COMPLETED" + + // JobStatusFAILED captures enum value "FAILED" + JobStatusFAILED JobStatus = "FAILED" + + // JobStatusCANCELED captures enum value "CANCELED" + JobStatusCANCELED JobStatus = "CANCELED" +) + +// for schema +var jobStatusEnum []interface{} + +func init() { + var res []JobStatus + if err := json.Unmarshal([]byte(`["NEW","PARSING","DOWNLOADING","WAITING","RUNNING","COMPLETED","FAILED","CANCELED"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + jobStatusEnum = append(jobStatusEnum, v) + } +} + +func (m JobStatus) validateJobStatusEnum(path, location string, value JobStatus) error { + if err := validate.Enum(path, location, value, jobStatusEnum); err != nil { + return err + } + return nil +} + +// Validate validates this job status +func (m JobStatus) Validate(formats strfmt.Registry) error { + var res []error + + // value enum + if err := m.validateJobStatusEnum("", "body", m); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/jobmanager.go b/jobmanager.go index c5ce847..2b9cf38 100644 --- a/jobmanager.go +++ b/jobmanager.go @@ -14,56 +14,10 @@ * limitations under the License */ -// File jobmanager.go provides JobManager interface with Job related -// structures. +// File jobmanager.go provides JobManager interface. package weles -import "time" - -// JobStatus specifies state of the Job. -type JobStatus string - -const ( - // JOB_NEW - The new Job has been created. - JOB_NEW JobStatus = "NEW" - // JOB_PARSING - Provided yaml file is being parsed and interpreted. - JOB_PARSING JobStatus = "PARSING" - // JOB_DOWNLOADING - Images and/or files required for the test are being - // downloaded. - JOB_DOWNLOADING JobStatus = "DOWNLOADING" - // JOB_WAITING - Job is waiting for Boruta worker. - JOB_WAITING JobStatus = "WAITING" - // JOB_RUNNING - Job is being executed. - JOB_RUNNING JobStatus = "RUNNING" - // JOB_COMPLETED - Job is completed. - // This is a terminal state. - JOB_COMPLETED JobStatus = "COMPLETED" - // JOB_FAILED - Job execution has failed. - // This is a terminal state. - JOB_FAILED JobStatus = "FAILED" - // JOB_CANCELED - Job has been canceled with API call. - // This is a terminal state. - JOB_CANCELED JobStatus = "CANCELED" -) - -// JobInfo contains Job information available for public API. -type JobInfo struct { - // JobID is a unique Job identifier. - JobID JobID - // Name is the Job name acquired from yaml file during Job creation. - Name string - // Created is the Job creation time in UTC. - Created time.Time - // Updated is the time of latest Jobs' status modification. - Updated time.Time - // Status specifies current state of the Job. - Status JobStatus - // Info provides additional information about current state, - // e.g. cause of failure. - Info string -} - // JobManager interface defines API for actions that can be called on Weles' Jobs // by external modules. These methods are intended to be used by HTTP server. type JobManager interface { diff --git a/server/embedded_spec.go b/server/embedded_spec.go index edbdf59..d5db164 100644 --- a/server/embedded_spec.go +++ b/server/embedded_spec.go @@ -70,6 +70,110 @@ func init() { } }, "definitions": { + "ArtifactAlias": { + "description": "is an alternative name of an artifact.", + "type": "string" + }, + "ArtifactDescription": { + "description": "contains information needed to create new artifact in ArtifactDB.", + "type": "object", + "properties": { + "Alias": { + "$ref": "#/definitions/ArtifactAlias" + }, + "JobID": { + "description": "specifies Job for which artifact was created.", + "$ref": "#/definitions/JobID" + }, + "Type": { + "$ref": "#/definitions/ArtifactType" + }, + "URI": { + "$ref": "#/definitions/ArtifactURI" + } + } + }, + "ArtifactFilter": { + "description": "is used to filter results from ArtifactDB.", + "type": "object", + "properties": { + "Alias": { + "type": "array", + "items": { + "$ref": "#/definitions/ArtifactAlias" + } + }, + "JobID": { + "type": "array", + "items": { + "$ref": "#/definitions/JobID" + } + }, + "Status": { + "type": "array", + "items": { + "$ref": "#/definitions/ArtifactStatus" + } + }, + "Type": { + "type": "array", + "items": { + "$ref": "#/definitions/ArtifactType" + } + } + } + }, + "ArtifactInfo": { + "description": "describes single artifact stored in ArtifactDB.", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ArtifactDescription" + } + ], + "properties": { + "Path": { + "$ref": "#/definitions/ArtifactPath" + }, + "Status": { + "$ref": "#/definitions/ArtifactStatus" + }, + "Timestamp": { + "description": "is date of creating the artifact.", + "type": "string", + "format": "date-time" + } + } + }, + "ArtifactPath": { + "description": "describes path to artifact in ArtifactDB filesystem.", + "type": "string" + }, + "ArtifactStatus": { + "description": "describes artifact status and availability.\n\n* DOWNLOADING - artifact is currently being downloaded.\n\n* READY - artifact has been downloaded and is ready to use.\n\n* FAILED - file is not available for use (e.g. download failed).\n\n* PENDING - artifact download has not started yet.\n", + "type": "string", + "enum": [ + "DOWNLOADING", + "READY", + "FAILED", + "PENDING" + ] + }, + "ArtifactType": { + "description": "denotes type and function of an artifact.\n\n* IMAGE - image file.\n\n* RESULT - all outputs, files built during tests, etc.\n\n* TEST - additional files uploaded by user for conducting test.\n\n* YAML - yaml file describing Weles Job.\n", + "type": "string", + "enum": [ + "IMAGE", + "RESULT", + "TEST", + "YAML" + ] + }, + "ArtifactURI": { + "description": "is used to identify artifact's source.", + "type": "string", + "format": "uri" + }, "ErrResponse": { "description": "is a standard error response containing information about the error. It consists of error type and message.", "type": "object", @@ -81,6 +185,57 @@ func init() { "type": "string" } } + }, + "JobID": { + "description": "is a unique identifier for Weles Job.", + "type": "integer", + "format": "uint64" + }, + "JobInfo": { + "description": "contains information about a Job available for public API.", + "type": "object", + "properties": { + "created": { + "description": "is the Job creation time in UTC.", + "type": "string", + "format": "date-time" + }, + "info": { + "description": "provides additional information about current state, e.g. cause of failure", + "type": "string" + }, + "jobID": { + "description": "is a unique Job identifier", + "$ref": "#/definitions/JobID" + }, + "name": { + "description": "is the Job name acquired from yaml file during Job creation.", + "type": "string" + }, + "status": { + "description": "specifies current state of the Job.", + "$ref": "#/definitions/JobStatus" + }, + "updated": { + "description": "is the time of latest Jobs' status modification.", + "type": "string", + "format": "date-time" + } + } + }, + "JobStatus": { + "description": "specifies state of the Job.\n\n* NEW - The new Job has been created.\n\n* PARSING - Provided yaml file is being parsed and interpreted.\n\n* DOWNLOADING - Images and/or files required for the test are being downloaded.\n\n* WAITING - Job is waiting for Boruta worker.\n\n* RUNNING - Job is being executed.\n\n* COMPLETED - Job is completed. This is terminal state.\n\n* FAILED - Job execution has failed. This is terminal state.\n\n* CANCELED -Job has been canceled with API call. This is terminal state.\n", + "type": "string", + "enum": [ + "NEW", + "PARSING", + "DOWNLOADING", + "WAITING", + "RUNNING", + "COMPLETED", + "FAILED", + "CANCELED" + ] } }, "responses": { @@ -137,6 +292,110 @@ func init() { } }, "definitions": { + "ArtifactAlias": { + "description": "is an alternative name of an artifact.", + "type": "string" + }, + "ArtifactDescription": { + "description": "contains information needed to create new artifact in ArtifactDB.", + "type": "object", + "properties": { + "Alias": { + "$ref": "#/definitions/ArtifactAlias" + }, + "JobID": { + "description": "specifies Job for which artifact was created.", + "$ref": "#/definitions/JobID" + }, + "Type": { + "$ref": "#/definitions/ArtifactType" + }, + "URI": { + "$ref": "#/definitions/ArtifactURI" + } + } + }, + "ArtifactFilter": { + "description": "is used to filter results from ArtifactDB.", + "type": "object", + "properties": { + "Alias": { + "type": "array", + "items": { + "$ref": "#/definitions/ArtifactAlias" + } + }, + "JobID": { + "type": "array", + "items": { + "$ref": "#/definitions/JobID" + } + }, + "Status": { + "type": "array", + "items": { + "$ref": "#/definitions/ArtifactStatus" + } + }, + "Type": { + "type": "array", + "items": { + "$ref": "#/definitions/ArtifactType" + } + } + } + }, + "ArtifactInfo": { + "description": "describes single artifact stored in ArtifactDB.", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/ArtifactDescription" + } + ], + "properties": { + "Path": { + "$ref": "#/definitions/ArtifactPath" + }, + "Status": { + "$ref": "#/definitions/ArtifactStatus" + }, + "Timestamp": { + "description": "is date of creating the artifact.", + "type": "string", + "format": "date-time" + } + } + }, + "ArtifactPath": { + "description": "describes path to artifact in ArtifactDB filesystem.", + "type": "string" + }, + "ArtifactStatus": { + "description": "describes artifact status and availability.\n\n* DOWNLOADING - artifact is currently being downloaded.\n\n* READY - artifact has been downloaded and is ready to use.\n\n* FAILED - file is not available for use (e.g. download failed).\n\n* PENDING - artifact download has not started yet.\n", + "type": "string", + "enum": [ + "DOWNLOADING", + "READY", + "FAILED", + "PENDING" + ] + }, + "ArtifactType": { + "description": "denotes type and function of an artifact.\n\n* IMAGE - image file.\n\n* RESULT - all outputs, files built during tests, etc.\n\n* TEST - additional files uploaded by user for conducting test.\n\n* YAML - yaml file describing Weles Job.\n", + "type": "string", + "enum": [ + "IMAGE", + "RESULT", + "TEST", + "YAML" + ] + }, + "ArtifactURI": { + "description": "is used to identify artifact's source.", + "type": "string", + "format": "uri" + }, "ErrResponse": { "description": "is a standard error response containing information about the error. It consists of error type and message.", "type": "object", @@ -148,6 +407,57 @@ func init() { "type": "string" } } + }, + "JobID": { + "description": "is a unique identifier for Weles Job.", + "type": "integer", + "format": "uint64" + }, + "JobInfo": { + "description": "contains information about a Job available for public API.", + "type": "object", + "properties": { + "created": { + "description": "is the Job creation time in UTC.", + "type": "string", + "format": "date-time" + }, + "info": { + "description": "provides additional information about current state, e.g. cause of failure", + "type": "string" + }, + "jobID": { + "description": "is a unique Job identifier", + "$ref": "#/definitions/JobID" + }, + "name": { + "description": "is the Job name acquired from yaml file during Job creation.", + "type": "string" + }, + "status": { + "description": "specifies current state of the Job.", + "$ref": "#/definitions/JobStatus" + }, + "updated": { + "description": "is the time of latest Jobs' status modification.", + "type": "string", + "format": "date-time" + } + } + }, + "JobStatus": { + "description": "specifies state of the Job.\n\n* NEW - The new Job has been created.\n\n* PARSING - Provided yaml file is being parsed and interpreted.\n\n* DOWNLOADING - Images and/or files required for the test are being downloaded.\n\n* WAITING - Job is waiting for Boruta worker.\n\n* RUNNING - Job is being executed.\n\n* COMPLETED - Job is completed. This is terminal state.\n\n* FAILED - Job execution has failed. This is terminal state.\n\n* CANCELED -Job has been canceled with API call. This is terminal state.\n", + "type": "string", + "enum": [ + "NEW", + "PARSING", + "DOWNLOADING", + "WAITING", + "RUNNING", + "COMPLETED", + "FAILED", + "CANCELED" + ] } }, "responses": { diff --git a/swagger.yml b/swagger.yml index 690f3fa..951d5bf 100644 --- a/swagger.yml +++ b/swagger.yml @@ -32,6 +32,157 @@ responses: schema: $ref: '#/definitions/ErrResponse' definitions: + JobID: + description: is a unique identifier for Weles Job. + type: integer + format: uint64 + JobStatus: + description: | + specifies state of the Job. + + * NEW - The new Job has been created. + + * PARSING - Provided yaml file is being parsed and interpreted. + + * DOWNLOADING - Images and/or files required for the test are being downloaded. + + * WAITING - Job is waiting for Boruta worker. + + * RUNNING - Job is being executed. + + * COMPLETED - Job is completed. This is terminal state. + + * FAILED - Job execution has failed. This is terminal state. + + * CANCELED -Job has been canceled with API call. This is terminal state. + + type: string + enum: + - NEW + - PARSING + - DOWNLOADING + - WAITING + - RUNNING + - COMPLETED + - FAILED + - CANCELED + JobInfo: + description: contains information about a Job available for public API. + type: object + properties: + jobID: + $ref: '#/definitions/JobID' + description: is a unique Job identifier + name: + type: string + description: is the Job name acquired from yaml file during Job creation. + created: + type: string + format: date-time + description: is the Job creation time in UTC. + updated: + type: string + format: date-time + description: is the time of latest Jobs' status modification. + status: + $ref: '#/definitions/JobStatus' + description: specifies current state of the Job. + info: + type: string + description: provides additional information about current state, e.g. cause of failure + ArtifactType: + description: | + denotes type and function of an artifact. + + * IMAGE - image file. + + * RESULT - all outputs, files built during tests, etc. + + * TEST - additional files uploaded by user for conducting test. + + * YAML - yaml file describing Weles Job. + + type: string + enum: + - IMAGE + - RESULT + - TEST + - YAML + ArtifactPath: + description: describes path to artifact in ArtifactDB filesystem. + type: string + ArtifactStatus: + description: | + describes artifact status and availability. + + * DOWNLOADING - artifact is currently being downloaded. + + * READY - artifact has been downloaded and is ready to use. + + * FAILED - file is not available for use (e.g. download failed). + + * PENDING - artifact download has not started yet. + + type: string + enum: + - DOWNLOADING + - READY + - FAILED + - PENDING + ArtifactURI: + description: is used to identify artifact's source. + type: string + format: uri + ArtifactAlias: + description: is an alternative name of an artifact. + type: string + ArtifactDescription: + description: contains information needed to create new artifact in ArtifactDB. + type: object + properties: + JobID: + $ref: '#/definitions/JobID' + description: specifies Job for which artifact was created. + Type: + $ref: '#/definitions/ArtifactType' + Alias: + $ref: '#/definitions/ArtifactAlias' + URI: + $ref: '#/definitions/ArtifactURI' + ArtifactInfo: + description: describes single artifact stored in ArtifactDB. + type: object + allOf: + - $ref: '#/definitions/ArtifactDescription' + properties: + Path: + $ref: '#/definitions/ArtifactPath' + Status: + $ref: '#/definitions/ArtifactStatus' + Timestamp: + description: is date of creating the artifact. + type: string + format: date-time + ArtifactFilter: + description: is used to filter results from ArtifactDB. + type: object + properties: + JobID: + type: array + items: + $ref: '#/definitions/JobID' + Type: + type: array + items: + $ref: '#/definitions/ArtifactType' + Status: + type: array + items: + $ref: '#/definitions/ArtifactStatus' + Alias: + type: array + items: + $ref: '#/definitions/ArtifactAlias' ErrResponse: description: >- is a standard error response containing information about the @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,3 @@ // Package weles represents the base of the Weles system. package weles - -// JobID is a unique identifier for Weles Job. -type JobID uint64 |