Skip to content

Commit

Permalink
Merge branch 'dev' into fix/event-use-instance-hash
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert authored Jun 26, 2019
2 parents 5e72f28 + 40a1278 commit 12a57af
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 204 deletions.
18 changes: 0 additions & 18 deletions database/instance_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ type InstanceDB interface {
// GetAll retrieves all instances.
GetAll() ([]*instance.Instance, error)

// GetAllByService retrieves all instances of service by service's hash.
GetAllByService(serviceHash hash.Hash) ([]*instance.Instance, error)

// Save saves instance to database.
Save(i *instance.Instance) error

Expand Down Expand Up @@ -85,21 +82,6 @@ func (d *LevelDBInstanceDB) GetAll() ([]*instance.Instance, error) {
return instances, iter.Error()
}

// GetAllByService retrieves all instances of service by service's hash.
func (d *LevelDBInstanceDB) GetAllByService(serviceHash hash.Hash) ([]*instance.Instance, error) {
instances, err := d.GetAll()
if err != nil {
return nil, err
}
someInstances := []*instance.Instance{}
for _, instance := range instances {
if instance.ServiceHash.Equal(serviceHash) {
someInstances = append(someInstances, instance)
}
}
return someInstances, nil
}

// Save saves instance to database.
func (d *LevelDBInstanceDB) Save(i *instance.Instance) error {
if i.Hash.IsZero() {
Expand Down
36 changes: 18 additions & 18 deletions execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,28 @@ func (s Status) String() (r string) {

// Execution stores all information about executions.
type Execution struct {
Hash hash.Hash `hash:"-"`
ParentHash hash.Hash `hash:"name:parentHash"`
EventID string `hash:"name:eventID"`
Status Status `hash:"-"`
ServiceHash hash.Hash `hash:"name:serviceHash"`
TaskKey string `hash:"name:taskKey"`
Tags []string `hash:"name:tags"`
Inputs map[string]interface{} `hash:"name:inputs"`
Outputs map[string]interface{} `hash:"-"`
Error string `hash:"-"`
Hash hash.Hash `hash:"-"`
ParentHash hash.Hash `hash:"name:parentHash"`
EventID string `hash:"name:eventID"`
Status Status `hash:"-"`
InstanceHash hash.Hash `hash:"name:instanceHash"`
TaskKey string `hash:"name:taskKey"`
Tags []string `hash:"name:tags"`
Inputs map[string]interface{} `hash:"name:inputs"`
Outputs map[string]interface{} `hash:"-"`
Error string `hash:"-"`
}

// New returns a new execution. It returns an error if inputs are invalid.
func New(serviceHash, parentHash hash.Hash, eventID, taskKey string, inputs map[string]interface{}, tags []string) *Execution {
func New(instanceHash, parentHash hash.Hash, eventID, taskKey string, inputs map[string]interface{}, tags []string) *Execution {
exec := &Execution{
EventID: eventID,
ServiceHash: serviceHash,
ParentHash: parentHash,
Inputs: inputs,
TaskKey: taskKey,
Tags: tags,
Status: Created,
EventID: eventID,
InstanceHash: instanceHash,
ParentHash: parentHash,
Inputs: inputs,
TaskKey: taskKey,
Tags: tags,
Status: Created,
}
exec.Hash = hash.Dump(exec)
return exec
Expand Down
6 changes: 3 additions & 3 deletions execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestNewFromService(t *testing.T) {

execution := New(hash, parentHash, eventID, taskKey, nil, tags)
require.NotNil(t, execution)
require.Equal(t, hash, execution.ServiceHash)
require.Equal(t, hash, execution.InstanceHash)
require.Equal(t, parentHash, execution.ParentHash)
require.Equal(t, eventID, execution.EventID)
require.Equal(t, taskKey, execution.TaskKey)
Expand Down Expand Up @@ -67,8 +67,8 @@ func TestStatus(t *testing.T) {
func TestExecutionHash(t *testing.T) {
ids := make(map[string]bool)

f := func(serviceHash, parentHash []byte, eventID, taskKey, input string, tags []string) bool {
e := New(serviceHash, parentHash, eventID, taskKey, map[string]interface{}{"input": input}, tags)
f := func(instanceHash, parentHash []byte, eventID, taskKey, input string, tags []string) bool {
e := New(instanceHash, parentHash, eventID, taskKey, map[string]interface{}{"input": input}, tags)
if ids[string(e.Hash)] {
return false
}
Expand Down
50 changes: 25 additions & 25 deletions protobuf/api/execution.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions protobuf/api/execution.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ message StreamExecutionRequest{
// Status to filter executions.
definition.Status status = 1;

// Service's hash to filter executions.
string serviceHash = 2;
// Instance's hash to filter executions.
string instanceHash = 2;
}

// Filter used to filter a stream of executions.
Expand Down
59 changes: 29 additions & 30 deletions protobuf/api/instance.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions protobuf/api/instance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ message CreateInstanceRequest {

// The response's data for the `Create` API.
message CreateInstanceResponse {
// The instance created.
definition.Instance instance = 1;
// The instance's hash created.
string hash = 1;
}

// The request's data for the `Delete` API.
Expand Down
Loading

0 comments on commit 12a57af

Please sign in to comment.