| Index: appengine/cmd/dm/distributor/task_description.go
|
| diff --git a/appengine/cmd/dm/distributor/task_description.go b/appengine/cmd/dm/distributor/task_description.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..baef72399e3a367a55b35f92caf44fefcfcefde3
|
| --- /dev/null
|
| +++ b/appengine/cmd/dm/distributor/task_description.go
|
| @@ -0,0 +1,73 @@
|
| +// Copyright 2016 The LUCI Authors. All rights reserved.
|
| +// Use of this source code is governed under the Apache License, Version 2.0
|
| +// that can be found in the LICENSE file.
|
| +
|
| +package distributor
|
| +
|
| +import (
|
| + "fmt"
|
| +
|
| + "github.com/golang/protobuf/proto"
|
| + "github.com/luci/gae/service/info"
|
| + dm "github.com/luci/luci-go/common/api/dm/service/v1"
|
| + "github.com/luci/luci-go/common/gcloud/pubsub"
|
| + "golang.org/x/net/context"
|
| +)
|
| +
|
| +// NewTaskDescription builds a new *TaskDescription.
|
| +//
|
| +// It's intended for use by the DM core logic, and not for use by distributor
|
| +// implementations.
|
| +func NewTaskDescription(c context.Context, payload *dm.Quest_Desc, exAuth *dm.Execution_Auth,
|
| + state PersistentState) *TaskDescription {
|
| + return &TaskDescription{
|
| + c: c,
|
| + payload: payload,
|
| + executionAuth: exAuth,
|
| + previousState: state,
|
| + }
|
| +}
|
| +
|
| +// TaskDescription is the parameters for PrepareTask.
|
| +type TaskDescription struct {
|
| + c context.Context
|
| + payload *dm.Quest_Desc
|
| + executionAuth *dm.Execution_Auth
|
| + previousState PersistentState
|
| +}
|
| +
|
| +// PrepareTopic returns the pubsub topic that notifications should be sent to.
|
| +//
|
| +// It returns the full name of the topic and a token that will be used to route
|
| +// PubSub messages back to the Distributor. The publisher to the topic must be
|
| +// instructed to put the token into the 'auth_token' attribute of PubSub
|
| +// messages. DM will know how to route such messages to D.HandleNotification.
|
| +func (t *TaskDescription) PrepareTopic() (topic pubsub.Topic, token string, err error) {
|
| + topic = pubsub.NewTopic(info.Get(t.c).TrimmedAppID(), notifyTopicSuffix)
|
| + if err := topic.Validate(); err != nil {
|
| + panic(fmt.Errorf("failed to validate Topic %q: %s", topic, err))
|
| + }
|
| + token, err = encodeAuthToken(t.c, t.executionAuth.Id,
|
| + t.payload.DistributorConfigName)
|
| + return
|
| +}
|
| +
|
| +// PreviousState is the current PersistentState of the Attempt (e.g. the
|
| +// PersistentState returned by the previous Execution). This will be empty
|
| +// for the first Execution.
|
| +func (t *TaskDescription) PreviousState() PersistentState {
|
| + return t.previousState
|
| +}
|
| +
|
| +// Payload is description of the job to run.
|
| +func (t *TaskDescription) Payload() *dm.Quest_Desc {
|
| + return proto.Clone(t.payload).(*dm.Quest_Desc)
|
| +}
|
| +
|
| +// ExecutionAuth is the combined execution_id+activation token that the
|
| +// execution must use to call ActivateExecution before making further API calls
|
| +// into DM.
|
| +func (t *TaskDescription) ExecutionAuth() *dm.Execution_Auth {
|
| + ret := *t.executionAuth
|
| + return &ret
|
| +}
|
|
|