2014-10-18 02:41:22 +04:00
|
|
|
/*
|
|
|
|
Copyright 2014 CoreOS, Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2013-09-29 03:26:19 +04:00
|
|
|
package store
|
2013-09-03 22:30:42 +04:00
|
|
|
|
|
|
|
const (
|
2013-12-01 03:24:23 +04:00
|
|
|
Get = "get"
|
|
|
|
Create = "create"
|
|
|
|
Set = "set"
|
|
|
|
Update = "update"
|
|
|
|
Delete = "delete"
|
|
|
|
CompareAndSwap = "compareAndSwap"
|
2013-11-30 21:08:25 +04:00
|
|
|
CompareAndDelete = "compareAndDelete"
|
2013-12-01 03:24:23 +04:00
|
|
|
Expire = "expire"
|
2013-10-03 09:15:12 +04:00
|
|
|
)
|
|
|
|
|
2013-09-03 22:30:42 +04:00
|
|
|
type Event struct {
|
2014-09-18 03:20:34 +04:00
|
|
|
Action string `json:"action"`
|
|
|
|
Node *NodeExtern `json:"node,omitempty"`
|
|
|
|
PrevNode *NodeExtern `json:"prevNode,omitempty"`
|
|
|
|
EtcdIndex uint64 `json:"-"`
|
2013-09-03 22:30:42 +04:00
|
|
|
}
|
|
|
|
|
2013-11-28 08:04:52 +04:00
|
|
|
func newEvent(action string, key string, modifiedIndex, createdIndex uint64) *Event {
|
2013-11-29 06:34:38 +04:00
|
|
|
n := &NodeExtern{
|
2013-11-10 08:49:19 +04:00
|
|
|
Key: key,
|
2013-11-28 08:04:52 +04:00
|
|
|
ModifiedIndex: modifiedIndex,
|
|
|
|
CreatedIndex: createdIndex,
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Event{
|
|
|
|
Action: action,
|
|
|
|
Node: n,
|
2013-09-03 22:30:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-20 21:21:54 +04:00
|
|
|
func (e *Event) IsCreated() bool {
|
2013-10-20 06:57:36 +04:00
|
|
|
if e.Action == Create {
|
2013-10-20 21:21:54 +04:00
|
|
|
return true
|
2013-10-20 06:57:36 +04:00
|
|
|
}
|
|
|
|
|
2014-01-01 16:01:29 +04:00
|
|
|
if e.Action == Set && e.PrevNode == nil {
|
2013-10-20 21:21:54 +04:00
|
|
|
return true
|
2013-10-20 06:57:36 +04:00
|
|
|
}
|
|
|
|
|
2013-10-20 21:21:54 +04:00
|
|
|
return false
|
2013-10-20 06:57:36 +04:00
|
|
|
}
|
|
|
|
|
2013-11-10 08:49:19 +04:00
|
|
|
func (e *Event) Index() uint64 {
|
2013-11-28 08:04:52 +04:00
|
|
|
return e.Node.ModifiedIndex
|
2013-11-10 08:49:19 +04:00
|
|
|
}
|