OLD | NEW |
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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 // The charm may already exist in state as a placeholder, so we | 516 // The charm may already exist in state as a placeholder, so we |
517 // check for that situation and update the existing charm record | 517 // check for that situation and update the existing charm record |
518 // if necessary, otherwise add a new record. | 518 // if necessary, otherwise add a new record. |
519 var existing charmDoc | 519 var existing charmDoc |
520 err = st.charms.Find(bson.D{{"_id", curl.String()}, {"placeholder", true
}}).One(&existing) | 520 err = st.charms.Find(bson.D{{"_id", curl.String()}, {"placeholder", true
}}).One(&existing) |
521 if err == mgo.ErrNotFound { | 521 if err == mgo.ErrNotFound { |
522 cdoc := &charmDoc{ | 522 cdoc := &charmDoc{ |
523 URL: curl, | 523 URL: curl, |
524 Meta: ch.Meta(), | 524 Meta: ch.Meta(), |
525 Config: ch.Config(), | 525 Config: ch.Config(), |
| 526 Actions: ch.Actions(), |
526 BundleURL: bundleURL, | 527 BundleURL: bundleURL, |
527 BundleSha256: bundleSha256, | 528 BundleSha256: bundleSha256, |
528 } | 529 } |
529 err = st.charms.Insert(cdoc) | 530 err = st.charms.Insert(cdoc) |
530 if err != nil { | 531 if err != nil { |
531 return nil, fmt.Errorf("cannot add charm %q: %v", curl,
err) | 532 return nil, fmt.Errorf("cannot add charm %q: %v", curl,
err) |
532 } | 533 } |
533 return newCharm(st, cdoc) | 534 return newCharm(st, cdoc) |
534 } else if err != nil { | 535 } else if err != nil { |
535 return nil, err | 536 return nil, err |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 // updateCharmDoc updates the charm with specified URL with the given | 867 // updateCharmDoc updates the charm with specified URL with the given |
867 // data, and resets the placeholder and pendingupdate flags. If the | 868 // data, and resets the placeholder and pendingupdate flags. If the |
868 // charm is no longer a placeholder or pending (depending on preReq), | 869 // charm is no longer a placeholder or pending (depending on preReq), |
869 // it returns ErrCharmRevisionAlreadyModified. | 870 // it returns ErrCharmRevisionAlreadyModified. |
870 func (st *State) updateCharmDoc( | 871 func (st *State) updateCharmDoc( |
871 ch charm.Charm, curl *charm.URL, bundleURL *url.URL, bundleSha256 string
, preReq interface{}) (*Charm, error) { | 872 ch charm.Charm, curl *charm.URL, bundleURL *url.URL, bundleSha256 string
, preReq interface{}) (*Charm, error) { |
872 | 873 |
873 updateFields := bson.D{{"$set", bson.D{ | 874 updateFields := bson.D{{"$set", bson.D{ |
874 {"meta", ch.Meta()}, | 875 {"meta", ch.Meta()}, |
875 {"config", ch.Config()}, | 876 {"config", ch.Config()}, |
| 877 {"actions", ch.Actions()}, |
876 {"bundleurl", bundleURL}, | 878 {"bundleurl", bundleURL}, |
877 {"bundlesha256", bundleSha256}, | 879 {"bundlesha256", bundleSha256}, |
878 {"pendingupload", false}, | 880 {"pendingupload", false}, |
879 {"placeholder", false}, | 881 {"placeholder", false}, |
880 }}} | 882 }}} |
881 ops := []txn.Op{{ | 883 ops := []txn.Op{{ |
882 C: st.charms.Name, | 884 C: st.charms.Name, |
883 Id: curl, | 885 Id: curl, |
884 Assert: preReq, | 886 Assert: preReq, |
885 Update: updateFields, | 887 Update: updateFields, |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 func tagForGlobalKey(key string) (string, bool) { | 1601 func tagForGlobalKey(key string) (string, bool) { |
1600 if len(key) < 3 || key[1] != '#' { | 1602 if len(key) < 3 || key[1] != '#' { |
1601 return "", false | 1603 return "", false |
1602 } | 1604 } |
1603 p, ok := tagPrefix[key[0]] | 1605 p, ok := tagPrefix[key[0]] |
1604 if !ok { | 1606 if !ok { |
1605 return "", false | 1607 return "", false |
1606 } | 1608 } |
1607 return p + key[2:], true | 1609 return p + key[2:], true |
1608 } | 1610 } |
OLD | NEW |