Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(494)

Side by Side Diff: state/state.go

Issue 92630043: cleanup code to remove pending Actions (Closed)
Patch Set: cleanup code to remove pending Actions Created 10 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « state/service.go ('k') | state/state_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 // Package state enables reading, observing, and changing 4 // Package state enables reading, observing, and changing
5 // the state stored in MongoDB of a whole environment 5 // the state stored in MongoDB of a whole environment
6 // managed by juju. 6 // managed by juju.
7 package state 7 package state
8 8
9 import ( 9 import (
10 "fmt" 10 "fmt"
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 err := st.actions.FindId(id).One(&doc) 1401 err := st.actions.FindId(id).One(&doc)
1402 if err == mgo.ErrNotFound { 1402 if err == mgo.ErrNotFound {
1403 return nil, errors.NotFoundf("action %q", id) 1403 return nil, errors.NotFoundf("action %q", id)
1404 } 1404 }
1405 if err != nil { 1405 if err != nil {
1406 return nil, fmt.Errorf("cannot get action %q: %v", id, err) 1406 return nil, fmt.Errorf("cannot get action %q: %v", id, err)
1407 } 1407 }
1408 return newAction(st, doc), nil 1408 return newAction(st, doc), nil
1409 } 1409 }
1410 1410
1411 // UnitActions returns a list of pending actions for a unit named name
1412 func (st *State) UnitActions(name string) ([]*Action, error) {
1413 actions := []*Action{}
1414 prefix := actionPrefix(unitGlobalKey(name))
1415 sel := bson.D{{"_id", bson.D{{"$regex", "^" + prefix}}}}
1416 iter := st.actions.Find(sel).Iter()
1417 doc := actionDoc{}
1418 for iter.Next(&doc) {
1419 actions = append(actions, newAction(st, doc))
1420 }
1421 if err := iter.Err(); err != nil {
1422 return actions, err
1423 }
1424 return actions, nil
1425 }
1426
1411 // Unit returns a unit by name. 1427 // Unit returns a unit by name.
1412 func (st *State) Unit(name string) (*Unit, error) { 1428 func (st *State) Unit(name string) (*Unit, error) {
1413 if !names.IsUnit(name) { 1429 if !names.IsUnit(name) {
1414 return nil, fmt.Errorf("%q is not a valid unit name", name) 1430 return nil, fmt.Errorf("%q is not a valid unit name", name)
1415 } 1431 }
1416 doc := unitDoc{} 1432 doc := unitDoc{}
1417 err := st.units.FindId(name).One(&doc) 1433 err := st.units.FindId(name).One(&doc)
1418 if err == mgo.ErrNotFound { 1434 if err == mgo.ErrNotFound {
1419 return nil, errors.NotFoundf("unit %q", name) 1435 return nil, errors.NotFoundf("unit %q", name)
1420 } 1436 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 func tagForGlobalKey(key string) (string, bool) { 1599 func tagForGlobalKey(key string) (string, bool) {
1584 if len(key) < 3 || key[1] != '#' { 1600 if len(key) < 3 || key[1] != '#' {
1585 return "", false 1601 return "", false
1586 } 1602 }
1587 p, ok := tagPrefix[key[0]] 1603 p, ok := tagPrefix[key[0]]
1588 if !ok { 1604 if !ok {
1589 return "", false 1605 return "", false
1590 } 1606 }
1591 return p + key[2:], true 1607 return p + key[2:], true
1592 } 1608 }
OLDNEW
« no previous file with comments | « state/service.go ('k') | state/state_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b