Documentation ¶
Overview ¶
Copyright 2019 Northern.tech AS
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.
Copyright 2019 Northern.tech AS
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.
Copyright 2019 Northern.tech AS
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.
Copyright 2019 Northern.tech AS
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.
Index ¶
- Constants
- Variables
- func Migrate(ctx context.Context, version string, session *mgo.Session, automigrate bool) error
- func MigrateSingle(ctx context.Context, db string, version string, session *mgo.Session, ...) error
- func NewMongoSession(c config.Reader) (*mgo.Session, error)
- type DataStoreMongo
- func (db *DataStoreMongo) AbortDeviceDeployments(ctx context.Context, deploymentId string) error
- func (db *DataStoreMongo) AggregateDeviceDeploymentByStatus(ctx context.Context, id string) (model.Stats, error)
- func (db *DataStoreMongo) AssignArtifact(ctx context.Context, deviceID string, deploymentID string, ...) error
- func (db *DataStoreMongo) DecommissionDeviceDeployments(ctx context.Context, deviceId string) error
- func (db *DataStoreMongo) DeleteDeployment(ctx context.Context, id string) error
- func (db *DataStoreMongo) DeleteImage(ctx context.Context, id string) error
- func (db *DataStoreMongo) DeviceCountByDeployment(ctx context.Context, id string) (int, error)
- func (db *DataStoreMongo) DoEnsureAdditionalIndexing(dataBase string, session *mgo.Session) error
- func (db *DataStoreMongo) DoEnsureIndexing(dataBase string, session *mgo.Session) error
- func (db *DataStoreMongo) EnsureIndexing(ctx context.Context, session *mgo.Session) error
- func (db *DataStoreMongo) ExistAssignedImageWithIDAndStatuses(ctx context.Context, imageID string, statuses ...string) (bool, error)
- func (db *DataStoreMongo) ExistByArtifactId(ctx context.Context, id string) (bool, error)
- func (db *DataStoreMongo) ExistUnfinishedByArtifactId(ctx context.Context, id string) (bool, error)
- func (db *DataStoreMongo) Exists(ctx context.Context, id string) (bool, error)
- func (db *DataStoreMongo) Find(ctx context.Context, match model.Query) ([]*model.Deployment, error)
- func (db *DataStoreMongo) FindAll(ctx context.Context) ([]*model.SoftwareImage, error)
- func (db *DataStoreMongo) FindAllDeploymentsForDeviceIDWithStatuses(ctx context.Context, deviceID string, statuses ...string) ([]model.DeviceDeployment, error)
- func (db *DataStoreMongo) FindDeploymentByID(ctx context.Context, id string) (*model.Deployment, error)
- func (db *DataStoreMongo) FindImageByID(ctx context.Context, id string) (*model.SoftwareImage, error)
- func (db *DataStoreMongo) FindOldestDeploymentForDeviceIDWithStatuses(ctx context.Context, deviceID string, statuses ...string) (*model.DeviceDeployment, error)
- func (db *DataStoreMongo) FindUnfinishedByID(ctx context.Context, id string) (*model.Deployment, error)
- func (db *DataStoreMongo) Finish(ctx context.Context, id string, when time.Time) error
- func (db *DataStoreMongo) GetDeviceDeploymentLog(ctx context.Context, deviceID, deploymentID string) (*model.DeploymentLog, error)
- func (db *DataStoreMongo) GetDeviceDeploymentStatus(ctx context.Context, deploymentID string, deviceID string) (string, error)
- func (db *DataStoreMongo) GetDeviceStatusesForDeployment(ctx context.Context, deploymentID string) ([]model.DeviceDeployment, error)
- func (db *DataStoreMongo) GetLimit(ctx context.Context, name string) (*model.Limit, error)
- func (db *DataStoreMongo) GetReleases(ctx context.Context, filt *model.ReleaseFilter) ([]model.Release, error)
- func (db *DataStoreMongo) HasDeploymentForDevice(ctx context.Context, deploymentID string, deviceID string) (bool, error)
- func (db *DataStoreMongo) ImageByIdsAndDeviceType(ctx context.Context, ids []string, deviceType string) (*model.SoftwareImage, error)
- func (db *DataStoreMongo) ImageByNameAndDeviceType(ctx context.Context, name, deviceType string) (*model.SoftwareImage, error)
- func (db *DataStoreMongo) ImagesByName(ctx context.Context, name string) ([]*model.SoftwareImage, error)
- func (db *DataStoreMongo) InsertDeployment(ctx context.Context, deployment *model.Deployment) error
- func (db *DataStoreMongo) InsertImage(ctx context.Context, image *model.SoftwareImage) error
- func (db *DataStoreMongo) InsertMany(ctx context.Context, deployments ...*model.DeviceDeployment) error
- func (db *DataStoreMongo) IsArtifactUnique(ctx context.Context, artifactName string, deviceTypesCompatible []string) (bool, error)
- func (db *DataStoreMongo) ProvisionTenant(ctx context.Context, tenantId string) error
- func (db *DataStoreMongo) SaveDeviceDeploymentLog(ctx context.Context, log model.DeploymentLog) error
- func (db *DataStoreMongo) Update(ctx context.Context, image *model.SoftwareImage) (bool, error)
- func (db *DataStoreMongo) UpdateDeviceDeploymentLogAvailability(ctx context.Context, deviceID string, deploymentID string, log bool) error
- func (db *DataStoreMongo) UpdateDeviceDeploymentStatus(ctx context.Context, deviceID string, deploymentID string, ...) (string, error)
- func (db *DataStoreMongo) UpdateStats(ctx context.Context, id string, state_from, state_to string) error
- func (db *DataStoreMongo) UpdateStatsAndFinishDeployment(ctx context.Context, id string, stats model.Stats) error
Constants ¶
const ( DatabaseName = "deployment_service" CollectionLimits = "limits" CollectionImages = "images" CollectionDeployments = "deployments" CollectionDeviceDeploymentLogs = "devices.logs" CollectionDevices = "devices" )
const ( IndexUniqeNameAndDeviceTypeStr = "uniqueNameAndDeviceTypeIndex" IndexDeploymentArtifactNameStr = "deploymentArtifactNameIndex" IndexDeploymentDeviceStatusesStr = "deviceIdWithStatusByCreated" IndexDeploymentDeviceIdStatusStr = "devicesIdWithStatus" IndexDeploymentDeviceDeploymentIdStr = "devicesDeploymentId" IndexDeploymentStatusFinishedStr = "deploymentStatusFinished" IndexDeploymentStatusPendingStr = "deploymentStatusPending" IndexDeploymentCreatedStr = "deploymentCreated" IndexDeploymentDeviceStatusRebootingStr = "deploymentsDeviceStatusRebooting" IndexDeploymentDeviceStatusPendingStr = "deploymentsDeviceStatusPending" IndexDeploymentDeviceStatusInstallingStr = "deploymentsDeviceStatusInstalling" IndexDeploymentDeviceStatusFinishedStr = "deploymentsFinished" )
Indexes
const ( // Need to be kept in sync with structure filed names StorageKeySoftwareImageDeviceTypes = "meta_artifact.device_types_compatible" StorageKeySoftwareImageName = "meta_artifact.name" StorageKeySoftwareImageId = "_id" StorageKeyDeviceDeploymentLogMessages = "messages" StorageKeyDeviceDeploymentAssignedImage = "image" StorageKeyDeviceDeploymentAssignedImageId = StorageKeyDeviceDeploymentAssignedImage + "." + StorageKeySoftwareImageId StorageKeyDeviceDeploymentDeviceId = "deviceid" StorageKeyDeviceDeploymentStatus = "status" StorageKeyDeviceDeploymentSubState = "substate" StorageKeyDeviceDeploymentDeploymentID = "deploymentid" StorageKeyDeviceDeploymentFinished = "finished" StorageKeyDeviceDeploymentIsLogAvailable = "log" StorageKeyDeviceDeploymentArtifact = "image" StorageKeyDeploymentName = "deploymentconstructor.name" StorageKeyDeploymentArtifactName = "deploymentconstructor.artifactname" StorageKeyDeploymentStats = "stats" StorageKeyDeploymentStatsCreated = "created" StorageKeyDeploymentFinished = "finished" StorageKeyDeploymentArtifacts = "artifacts" )
Database keys
const ( DbVersion = "1.2.2" DbName = "deployment_service" )
Variables ¶
var ( StorageIndexes = []string{ "$text:" + StorageKeyDeploymentName, "$text:" + StorageKeyDeploymentArtifactName, } StatusIndexes = []string{ StorageKeyDeviceDeploymentDeviceId, StorageKeyDeviceDeploymentStatus, StorageKeyDeploymentStatsCreated, } DeviceIDStatusIndexes = []string{"deviceID", "status"} //IndexDeploymentDeviceIdStatusStr DeploymentIdIndexes = []string{"deploymentid"} //IndexDeploymentDeviceDeploymentIdStr DeploymentStatusFinishedIndex = []string{ "stats.downloading", "stats.installing", "stats.pending", "stats.rebooting", "-created", } //IndexDeploymentStatusFinishedStr DeploymentStatusPendingIndex = []string{ "stats.aborted", "stats.already-installed", "stats.decommissioned", "stats.downloading", "stats.failure", "stats.installing", "stats.noartifact", "stats.rebooting", "stats.success", "-created", } //IndexDeploymentStatusPendingStr DeploymentCreatedIndex = []string{"-created"} //IndexDeploymentCreatedStr DeploymentDeviceStatusRebootingIndex = []string{"stats.rebooting"} //IndexDeploymentDeviceStatusRebootingStr DeploymentDeviceStatusPendingIndex = []string{"stats.pending"} //IndexDeploymentDeviceStatusPendingStr DeploymentDeviceStatusInstallingIndex = []string{"stats.installing"} //IndexDeploymentDeviceStatusInstallingStr DeploymentDeviceStatusFinishedIndex = []string{"finished"} //IndexDeploymentDeviceStatusFinishedStr )
var ( ErrSoftwareImagesStorageInvalidID = errors.New("Invalid id") ErrSoftwareImagesStorageInvalidArtifactName = errors.New("Invalid artifact name") ErrSoftwareImagesStorageInvalidName = errors.New("Invalid name") ErrSoftwareImagesStorageInvalidDeviceType = errors.New("Invalid device type") ErrSoftwareImagesStorageInvalidImage = errors.New("Invalid image") ErrStorageInvalidDeviceDeployment = errors.New("Invalid device deployment") ErrDeploymentStorageInvalidDeployment = errors.New("Invalid deployment") ErrStorageInvalidID = errors.New("Invalid id") ErrStorageNotFound = errors.New("Not found") ErrDeploymentStorageInvalidQuery = errors.New("Invalid query") ErrDeploymentStorageCannotExecQuery = errors.New("Cannot execute query") ErrStorageInvalidInput = errors.New("invalid input") ErrLimitNotFound = errors.New("limit not found") )
Errors
Functions ¶
func MigrateSingle ¶
Types ¶
type DataStoreMongo ¶
type DataStoreMongo struct {
// contains filtered or unexported fields
}
func NewDataStoreMongoWithSession ¶
func NewDataStoreMongoWithSession(session *mgo.Session) *DataStoreMongo
func (*DataStoreMongo) AbortDeviceDeployments ¶
func (db *DataStoreMongo) AbortDeviceDeployments(ctx context.Context, deploymentId string) error
func (*DataStoreMongo) AggregateDeviceDeploymentByStatus ¶
func (*DataStoreMongo) AssignArtifact ¶
func (db *DataStoreMongo) AssignArtifact(ctx context.Context, deviceID string, deploymentID string, artifact *model.SoftwareImage) error
AssignArtifact assignes artifact to the device deployment
func (*DataStoreMongo) DecommissionDeviceDeployments ¶
func (db *DataStoreMongo) DecommissionDeviceDeployments(ctx context.Context, deviceId string) error
func (*DataStoreMongo) DeleteDeployment ¶
func (db *DataStoreMongo) DeleteDeployment(ctx context.Context, id string) error
Delete removed entry by ID Noop on ID not found
func (*DataStoreMongo) DeleteImage ¶
func (db *DataStoreMongo) DeleteImage(ctx context.Context, id string) error
Delete image specified by ID Noop on if not found.
func (*DataStoreMongo) DeviceCountByDeployment ¶
func (*DataStoreMongo) DoEnsureAdditionalIndexing ¶
func (db *DataStoreMongo) DoEnsureAdditionalIndexing(dataBase string, session *mgo.Session) error
func (*DataStoreMongo) DoEnsureIndexing ¶
func (db *DataStoreMongo) DoEnsureIndexing(dataBase string, session *mgo.Session) error
func (*DataStoreMongo) EnsureIndexing ¶
func (*DataStoreMongo) ExistAssignedImageWithIDAndStatuses ¶
func (db *DataStoreMongo) ExistAssignedImageWithIDAndStatuses(ctx context.Context, imageID string, statuses ...string) (bool, error)
ExistAssignedImageWithIDAndStatuses checks if image is used by deplyment with specified status.
func (*DataStoreMongo) ExistByArtifactId ¶
ExistByArtifactId check if there is any deployment that uses give artifact
func (*DataStoreMongo) ExistUnfinishedByArtifactId ¶
ExistUnfinishedByArtifactId checks if there is an active deployment that uses given artifact
func (*DataStoreMongo) Find ¶
func (db *DataStoreMongo) Find(ctx context.Context, match model.Query) ([]*model.Deployment, error)
func (*DataStoreMongo) FindAll ¶
func (db *DataStoreMongo) FindAll(ctx context.Context) ([]*model.SoftwareImage, error)
FindAll lists all images
func (*DataStoreMongo) FindAllDeploymentsForDeviceIDWithStatuses ¶
func (db *DataStoreMongo) FindAllDeploymentsForDeviceIDWithStatuses(ctx context.Context, deviceID string, statuses ...string) ([]model.DeviceDeployment, error)
FindAllDeploymentsForDeviceIDWithStatuses finds all deployments matching device id and one of specified statuses.
func (*DataStoreMongo) FindDeploymentByID ¶
func (db *DataStoreMongo) FindDeploymentByID(ctx context.Context, id string) (*model.Deployment, error)
func (*DataStoreMongo) FindImageByID ¶
func (db *DataStoreMongo) FindImageByID(ctx context.Context, id string) (*model.SoftwareImage, error)
FindImageByID search storage for image with ID, returns nil if not found
func (*DataStoreMongo) FindOldestDeploymentForDeviceIDWithStatuses ¶
func (db *DataStoreMongo) FindOldestDeploymentForDeviceIDWithStatuses(ctx context.Context, deviceID string, statuses ...string) (*model.DeviceDeployment, error)
FindOldestDeploymentForDeviceIDWithStatuses find oldest deployment matching device id and one of specified statuses.
func (*DataStoreMongo) FindUnfinishedByID ¶
func (db *DataStoreMongo) FindUnfinishedByID(ctx context.Context, id string) (*model.Deployment, error)
func (*DataStoreMongo) GetDeviceDeploymentLog ¶
func (db *DataStoreMongo) GetDeviceDeploymentLog(ctx context.Context, deviceID, deploymentID string) (*model.DeploymentLog, error)
func (*DataStoreMongo) GetDeviceDeploymentStatus ¶
func (*DataStoreMongo) GetDeviceStatusesForDeployment ¶
func (db *DataStoreMongo) GetDeviceStatusesForDeployment(ctx context.Context, deploymentID string) ([]model.DeviceDeployment, error)
GetDeviceStatusesForDeployment retrieve device deployment statuses for a given deployment.
func (*DataStoreMongo) GetReleases ¶
func (db *DataStoreMongo) GetReleases(ctx context.Context, filt *model.ReleaseFilter) ([]model.Release, error)
func (*DataStoreMongo) HasDeploymentForDevice ¶
func (db *DataStoreMongo) HasDeploymentForDevice(ctx context.Context, deploymentID string, deviceID string) (bool, error)
Returns true if deployment of ID `deploymentID` is assigned to device with ID `deviceID`, false otherwise. In case of errors returns false and an error that occurred
func (*DataStoreMongo) ImageByIdsAndDeviceType ¶
func (db *DataStoreMongo) ImageByIdsAndDeviceType(ctx context.Context, ids []string, deviceType string) (*model.SoftwareImage, error)
ImageByIdsAndDeviceType finds image with id from ids and targed device type
func (*DataStoreMongo) ImageByNameAndDeviceType ¶
func (db *DataStoreMongo) ImageByNameAndDeviceType(ctx context.Context, name, deviceType string) (*model.SoftwareImage, error)
ImageByNameAndDeviceType finds image with speficied application name and targed device type
func (*DataStoreMongo) ImagesByName ¶
func (db *DataStoreMongo) ImagesByName( ctx context.Context, name string) ([]*model.SoftwareImage, error)
ImagesByName finds images with speficied artifact name
func (*DataStoreMongo) InsertDeployment ¶
func (db *DataStoreMongo) InsertDeployment(ctx context.Context, deployment *model.Deployment) error
Insert persists object
func (*DataStoreMongo) InsertImage ¶
func (db *DataStoreMongo) InsertImage(ctx context.Context, image *model.SoftwareImage) error
Insert persists object
func (*DataStoreMongo) InsertMany ¶
func (db *DataStoreMongo) InsertMany(ctx context.Context, deployments ...*model.DeviceDeployment) error
InsertMany stores multiple device deployment objects. TODO: Handle error cleanup, multi insert is not atomic, loop into two-phase commits
func (*DataStoreMongo) IsArtifactUnique ¶
func (db *DataStoreMongo) IsArtifactUnique(ctx context.Context, artifactName string, deviceTypesCompatible []string) (bool, error)
IsArtifactUnique checks if there is no artifact with the same artifactName supporting one of the device types from deviceTypesCompatible list. Returns true, nil if artifact is unique; false, nil if artifact is not unique; false, error in case of error.
func (*DataStoreMongo) ProvisionTenant ¶
func (db *DataStoreMongo) ProvisionTenant(ctx context.Context, tenantId string) error
func (*DataStoreMongo) SaveDeviceDeploymentLog ¶
func (db *DataStoreMongo) SaveDeviceDeploymentLog(ctx context.Context, log model.DeploymentLog) error
func (*DataStoreMongo) Update ¶
func (db *DataStoreMongo) Update(ctx context.Context, image *model.SoftwareImage) (bool, error)
Update proviced SoftwareImage Return false if not found
func (*DataStoreMongo) UpdateDeviceDeploymentLogAvailability ¶
func (*DataStoreMongo) UpdateDeviceDeploymentStatus ¶
func (db *DataStoreMongo) UpdateDeviceDeploymentStatus(ctx context.Context, deviceID string, deploymentID string, ddStatus model.DeviceDeploymentStatus) (string, error)