util

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Copyright 2016 The Rook Authors. 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.

Copyright 2016 The Rook Authors. 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.

Copyright 2016 The Rook Authors. 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.

Copyright 2016 The Rook Authors. 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.

Copyright 2016 The Rook Authors. 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.

Copyright 2016 The Rook Authors. 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.

Index

Constants

View Source
const (
	InfiniteTimeout = -1
)

Variables

This section is empty.

Functions

func CreateEtcdDir

func CreateEtcdDir(etcdClient etcd.KeysAPI, key string) error

Create an etcd key. Ignores the error that it already exists.

func EtcdDirExists

func EtcdDirExists(etcdClient etcd.KeysAPI, key string) (bool, error)

func GetEtcdClient

func GetEtcdClient(peers []string) (etcd.KeysAPI, error)

func GetEtcdClientFromEnv

func GetEtcdClientFromEnv() (etcd.KeysAPI, error)

func GetEtcdCode

func GetEtcdCode(err error) (int, bool)

Converts the error to an etcd error code if possible. Returns the code and true if successfully parsed.

func GetEtcdPeers

func GetEtcdPeers() ([]string, error)

func GetEtcdValues

func GetEtcdValues(etcdClient etcd.KeysAPI, keys map[string]string) (values map[string]string, err error)

Get all the values for the specified etcd keys, returned as a map of key names to values.

func GetLeafKeyPath

func GetLeafKeyPath(key string) string

func GetParentKeyPath

func GetParentKeyPath(key string) string

func IsEtcdCompareFailed

func IsEtcdCompareFailed(err error) bool

func IsEtcdDirAlreadyExists

func IsEtcdDirAlreadyExists(err error) bool

func IsEtcdKeyNotFound

func IsEtcdKeyNotFound(err error) bool

Check the error to see if it indicates an etcd was not found. True if a match, false otherwise.

func IsEtcdKeyReset

func IsEtcdKeyReset(err error) bool

Check if the error indicates the etcd key was reset

func IsEtcdNodeExist

func IsEtcdNodeExist(err error) bool

Check the error to see if it indicates an etcd key already exists. True if so, false otherwise.

func LoadPersistedNodeID added in v0.1.1

func LoadPersistedNodeID(dataDir string) (string, error)

To ensure a constant node ID between runs, the id will be persisted in the data directory.

func MockEtcdValueResponse

func MockEtcdValueResponse(key string, value string, index uint64) *etcd.Response

func StoreEtcdProperties

func StoreEtcdProperties(etcdClient etcd.KeysAPI, baseKey string, properties map[string]string) error

Store each of the properties in etcd

func WatchEtcdKey

func WatchEtcdKey(etcdClient etcd.KeysAPI, key string, index *uint64, timeout int) (string, bool, error)

Watch an etcd key for changes since the provided index

func WriteFile

func WriteFile(filePath string, contentBuffer bytes.Buffer) error

func WriteFileToLog added in v0.3.0

func WriteFileToLog(logger *capnslog.PackageLogger, path string)

Types

type MockEtcdClient

type MockEtcdClient struct {
	MockSet          func(ctx context.Context, key, value string, opts *etcd.SetOptions) (*etcd.Response, error)
	MockGet          func(ctx context.Context, key string, opts *etcd.GetOptions) (*etcd.Response, error)
	MockDelete       func(ctx context.Context, key string, opts *etcd.DeleteOptions) (*etcd.Response, error)
	MockWatcher      func(key string, opts *etcd.WatcherOptions) etcd.Watcher
	WatcherResponses map[string]string
	// contains filtered or unexported fields
}

************************************************************************************************ KeysAPI interface mock implementation ************************************************************************************************

func NewMockEtcdClient

func NewMockEtcdClient() *MockEtcdClient

func (*MockEtcdClient) Create

func (r *MockEtcdClient) Create(ctx context.Context, key, value string) (*etcd.Response, error)

func (*MockEtcdClient) CreateDir

func (r *MockEtcdClient) CreateDir(key string)

Create a key and its parents as needed

func (*MockEtcdClient) CreateDirs

func (r *MockEtcdClient) CreateDirs(key string, children *Set)

func (*MockEtcdClient) CreateInOrder

func (r *MockEtcdClient) CreateInOrder(ctx context.Context, dir, value string, opts *etcd.CreateInOrderOptions) (*etcd.Response, error)

func (*MockEtcdClient) Delete

func (r *MockEtcdClient) Delete(ctx context.Context, key string, opts *etcd.DeleteOptions) (*etcd.Response, error)

func (*MockEtcdClient) DeleteDir

func (r *MockEtcdClient) DeleteDir(key string)

Delete a key and its children

func (*MockEtcdClient) DeleteValue

func (r *MockEtcdClient) DeleteValue(key string)

Delete a value

func (*MockEtcdClient) Dump

func (r *MockEtcdClient) Dump()

func (*MockEtcdClient) Get

func (r *MockEtcdClient) Get(ctx context.Context, key string, opts *etcd.GetOptions) (*etcd.Response, error)

Get an etcd value. Defaults to an in-memory response to values that have been set for this client.

func (*MockEtcdClient) GetChildDirs

func (r *MockEtcdClient) GetChildDirs(key string) *Set

Get the child directories of the key

func (*MockEtcdClient) GetValue

func (r *MockEtcdClient) GetValue(key string) string

Get a value. If the key was not found, returns the empty string. To distinguish between an empty value and a key not found, call Get()

func (*MockEtcdClient) MockEtcdDirResponse

func (r *MockEtcdClient) MockEtcdDirResponse(key string, dir *MockEtcdDir, recursive bool, index uint64) *etcd.Response

************************************************************************************************ Helpers to create etcd mocked responses ************************************************************************************************

func (*MockEtcdClient) ResetStore

func (r *MockEtcdClient) ResetStore()

Reset the test value and directory store

func (*MockEtcdClient) Set

func (r *MockEtcdClient) Set(ctx context.Context, key, value string, opts *etcd.SetOptions) (*etcd.Response, error)

Set an etcd value. Defaults to an in-memory store.

func (*MockEtcdClient) SetValue

func (r *MockEtcdClient) SetValue(key, value string)

Set a value

func (*MockEtcdClient) Update

func (r *MockEtcdClient) Update(ctx context.Context, key, value string) (*etcd.Response, error)

func (*MockEtcdClient) Watcher

func (r *MockEtcdClient) Watcher(key string, opts *etcd.WatcherOptions) etcd.Watcher

type MockEtcdDir

type MockEtcdDir struct {
	Path   string
	Dirs   map[string]*MockEtcdDir
	Values map[string]string
}

type MockWatcher

type MockWatcher struct {
	MockNext func(context.Context) (*etcd.Response, error)
}

************************************************************************************************ Watcher interface Mock implementation ************************************************************************************************

func (*MockWatcher) Next

func (r *MockWatcher) Next(ctx context.Context) (*etcd.Response, error)

type Set

type Set struct {
	// contains filtered or unexported fields
}

func CreateSet

func CreateSet(values []string) *Set

Create a new set from the array

func GetDirChildKeys

func GetDirChildKeys(etcdClient etcd.KeysAPI, key string) (*Set, error)

func NewSet

func NewSet() *Set

Create a new empty set

func SetDifference

func SetDifference(left, right []string) *Set

find items in the left slice that are not in the right slice

func (*Set) Add

func (s *Set) Add(newValue string) bool

Add a value to the set. Returns true if the value was added, false if it already exists.

func (*Set) AddMultiple

func (s *Set) AddMultiple(values []string)

Add multiple items more efficiently

func (*Set) AddSet

func (s *Set) AddSet(other *Set)

Add other set items

func (*Set) Contains

func (s *Set) Contains(value string) bool

Check whether a value is already contained in the set

func (*Set) Copy

func (s *Set) Copy() *Set

Create a copy of the set

func (*Set) Count

func (s *Set) Count() int

Get the count of items in the set

func (*Set) Equals

func (s *Set) Equals(other *Set) bool

Check if two sets contain the same elements

func (*Set) Iter

func (s *Set) Iter() <-chan string

Iterate over the items in the set

func (*Set) Remove

func (s *Set) Remove(oldValue string) bool

Add a value to the set. Returns true if the value was added, false if it already exists.

func (*Set) Subtract

func (s *Set) Subtract(subset *Set)

Subtract the subset from the set

func (*Set) ToSlice

func (s *Set) ToSlice() []string

Convert the set to an array

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL