Commit ab5f29d0 authored by jackgr's avatar jackgr

Renames in manager/repository

parent 43a6876a
...@@ -44,7 +44,7 @@ type pManifest struct { ...@@ -44,7 +44,7 @@ type pManifest struct {
type pInstance struct { type pInstance struct {
ID string `bson:"_id"` ID string `bson:"_id"`
common.TypeInstance common.ChartInstance
} }
type pRepository struct { type pRepository struct {
...@@ -428,8 +428,8 @@ func (r *pRepository) removeManifestsForDeployment(d *common.Deployment) error { ...@@ -428,8 +428,8 @@ func (r *pRepository) removeManifestsForDeployment(d *common.Deployment) error {
return nil return nil
} }
// ListTypes returns all types known from existing instances. // ListCharts returns all types known from existing instances.
func (r *pRepository) ListTypes() ([]string, error) { func (r *pRepository) ListCharts() ([]string, error) {
var result []string var result []string
if err := r.Instances.Find(nil).Distinct("typeinstance.type", &result); err != nil { if err := r.Instances.Find(nil).Distinct("typeinstance.type", &result); err != nil {
return nil, fmt.Errorf("cannot list type instances: %s", err) return nil, fmt.Errorf("cannot list type instances: %s", err)
...@@ -438,9 +438,9 @@ func (r *pRepository) ListTypes() ([]string, error) { ...@@ -438,9 +438,9 @@ func (r *pRepository) ListTypes() ([]string, error) {
return result, nil return result, nil
} }
// GetTypeInstances returns all instances of a given type. If typeName is empty // GetChartInstances returns all instances of a given type. If typeName is empty
// or equal to "all", returns all instances of all types. // or equal to "all", returns all instances of all types.
func (r *pRepository) GetTypeInstances(typeName string) ([]*common.TypeInstance, error) { func (r *pRepository) GetChartInstances(typeName string) ([]*common.ChartInstance, error) {
query := bson.M{"typeinstance.type": typeName} query := bson.M{"typeinstance.type": typeName}
if typeName == "" || typeName == "all" { if typeName == "" || typeName == "all" {
query = nil query = nil
...@@ -451,17 +451,17 @@ func (r *pRepository) GetTypeInstances(typeName string) ([]*common.TypeInstance, ...@@ -451,17 +451,17 @@ func (r *pRepository) GetTypeInstances(typeName string) ([]*common.TypeInstance,
return nil, fmt.Errorf("cannot get instances of type %s: %s", typeName, err) return nil, fmt.Errorf("cannot get instances of type %s: %s", typeName, err)
} }
instances := []*common.TypeInstance{} instances := []*common.ChartInstance{}
for _, pi := range result { for _, pi := range result {
instances = append(instances, &pi.TypeInstance) instances = append(instances, &pi.ChartInstance)
} }
return instances, nil return instances, nil
} }
// ClearTypeInstancesForDeployment deletes all type instances associated with the given // ClearChartInstancesForDeployment deletes all type instances associated with the given
// deployment from the repository. // deployment from the repository.
func (r *pRepository) ClearTypeInstancesForDeployment(deploymentName string) error { func (r *pRepository) ClearChartInstancesForDeployment(deploymentName string) error {
if deploymentName != "" { if deploymentName != "" {
query := bson.M{"typeinstance.deployment": deploymentName} query := bson.M{"typeinstance.deployment": deploymentName}
if _, err := r.Instances.RemoveAll(query); err != nil { if _, err := r.Instances.RemoveAll(query); err != nil {
...@@ -472,12 +472,12 @@ func (r *pRepository) ClearTypeInstancesForDeployment(deploymentName string) err ...@@ -472,12 +472,12 @@ func (r *pRepository) ClearTypeInstancesForDeployment(deploymentName string) err
return nil return nil
} }
// AddTypeInstances adds the supplied type instances to the repository. // AddChartInstances adds the supplied type instances to the repository.
func (r *pRepository) AddTypeInstances(instances map[string][]*common.TypeInstance) error { func (r *pRepository) AddChartInstances(instances map[string][]*common.ChartInstance) error {
for _, is := range instances { for _, is := range instances {
for _, i := range is { for _, i := range is {
key := fmt.Sprintf("%s.%s.%s", i.Deployment, i.Type, i.Name) key := fmt.Sprintf("%s.%s.%s", i.Deployment, i.Type, i.Name)
wrapper := pInstance{ID: key, TypeInstance: *i} wrapper := pInstance{ID: key, ChartInstance: *i}
if err := r.Instances.Insert(&wrapper); err != nil { if err := r.Instances.Insert(&wrapper); err != nil {
return fmt.Errorf("cannot insert type instance %v: %s", wrapper, err) return fmt.Errorf("cannot insert type instance %v: %s", wrapper, err)
} }
......
...@@ -102,9 +102,9 @@ func TestRepositoryDeleteDeploymentWorksForget(t *testing.T) { ...@@ -102,9 +102,9 @@ func TestRepositoryDeleteDeploymentWorksForget(t *testing.T) {
} }
} }
func TestRepositoryTypeInstances(t *testing.T) { func TestRepositoryChartInstances(t *testing.T) {
if r := createRepository(); r != nil { if r := createRepository(); r != nil {
defer resetRepository(t, r) defer resetRepository(t, r)
repository.TestRepositoryTypeInstances(t, r) repository.TestRepositoryChartInstances(t, r)
} }
} }
...@@ -40,10 +40,10 @@ type Repository interface { ...@@ -40,10 +40,10 @@ type Repository interface {
GetLatestManifest(deploymentName string) (*common.Manifest, error) GetLatestManifest(deploymentName string) (*common.Manifest, error)
// Types. // Types.
ListTypes() ([]string, error) ListCharts() ([]string, error)
GetTypeInstances(typeName string) ([]*common.TypeInstance, error) GetChartInstances(chartName string) ([]*common.ChartInstance, error)
ClearTypeInstancesForDeployment(deploymentName string) error ClearChartInstancesForDeployment(deploymentName string) error
AddTypeInstances(instances map[string][]*common.TypeInstance) error AddChartInstances(instances map[string][]*common.ChartInstance) error
Close() Close()
} }
...@@ -210,9 +210,9 @@ func TestRepositoryDeleteDeploymentWorksForget(t *testing.T, r Repository) { ...@@ -210,9 +210,9 @@ func TestRepositoryDeleteDeploymentWorksForget(t *testing.T, r Repository) {
} }
} }
// TestRepositoryTypeInstances checks that type instances can be listed and retrieved successfully. // TestRepositoryChartInstances checks that type instances can be listed and retrieved successfully.
func TestRepositoryTypeInstances(t *testing.T, r Repository) { func TestRepositoryChartInstances(t *testing.T, r Repository) {
d1Map := map[string][]*common.TypeInstance{ d1Map := map[string][]*common.ChartInstance{
"t1": { "t1": {
{ {
Name: "i1", Name: "i1",
...@@ -224,7 +224,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) { ...@@ -224,7 +224,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
}, },
} }
d2Map := map[string][]*common.TypeInstance{ d2Map := map[string][]*common.ChartInstance{
"t2": { "t2": {
{ {
Name: "i2", Name: "i2",
...@@ -236,7 +236,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) { ...@@ -236,7 +236,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
}, },
} }
d3Map := map[string][]*common.TypeInstance{ d3Map := map[string][]*common.ChartInstance{
"t2": { "t2": {
{ {
Name: "i3", Name: "i3",
...@@ -248,7 +248,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) { ...@@ -248,7 +248,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
}, },
} }
instances, err := r.GetTypeInstances("noinstances") instances, err := r.GetChartInstances("noinstances")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -257,7 +257,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) { ...@@ -257,7 +257,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected no instances: %v", instances) t.Fatalf("expected no instances: %v", instances)
} }
types, err := r.ListTypes() types, err := r.ListCharts()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -266,11 +266,11 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) { ...@@ -266,11 +266,11 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected no types: %v", types) t.Fatalf("expected no types: %v", types)
} }
r.AddTypeInstances(d1Map) r.AddChartInstances(d1Map)
r.AddTypeInstances(d2Map) r.AddChartInstances(d2Map)
r.AddTypeInstances(d3Map) r.AddChartInstances(d3Map)
instances, err = r.GetTypeInstances("unknowntype") instances, err = r.GetChartInstances("unknowntype")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -279,7 +279,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) { ...@@ -279,7 +279,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected no instances: %v", instances) t.Fatalf("expected no instances: %v", instances)
} }
instances, err = r.GetTypeInstances("t1") instances, err = r.GetChartInstances("t1")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -288,7 +288,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) { ...@@ -288,7 +288,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected one instance: %v", instances) t.Fatalf("expected one instance: %v", instances)
} }
instances, err = r.GetTypeInstances("t2") instances, err = r.GetChartInstances("t2")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -297,7 +297,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) { ...@@ -297,7 +297,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected two instances: %v", instances) t.Fatalf("expected two instances: %v", instances)
} }
instances, err = r.GetTypeInstances("all") instances, err = r.GetChartInstances("all")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -306,7 +306,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) { ...@@ -306,7 +306,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected three total instances: %v", instances) t.Fatalf("expected three total instances: %v", instances)
} }
types, err = r.ListTypes() types, err = r.ListCharts()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -315,12 +315,12 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) { ...@@ -315,12 +315,12 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected two total types: %v", types) t.Fatalf("expected two total types: %v", types)
} }
err = r.ClearTypeInstancesForDeployment("d1") err = r.ClearChartInstancesForDeployment("d1")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
instances, err = r.GetTypeInstances("t1") instances, err = r.GetChartInstances("t1")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -329,7 +329,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) { ...@@ -329,7 +329,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected no instances after clear: %v", instances) t.Fatalf("expected no instances after clear: %v", instances)
} }
types, err = r.ListTypes() types, err = r.ListCharts()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
...@@ -27,16 +27,16 @@ import ( ...@@ -27,16 +27,16 @@ import (
"github.com/kubernetes/helm/pkg/common" "github.com/kubernetes/helm/pkg/common"
) )
// deploymentTypeInstanceMap stores type instances mapped by deployment name. // deploymentChartInstanceMap stores type instances mapped by deployment name.
// This allows for simple updating and deleting of per-deployment instances // This allows for simple updating and deleting of per-deployment instances
// when deployments are created/updated/deleted. // when deployments are created/updated/deleted.
type deploymentTypeInstanceMap map[string][]*common.TypeInstance type deploymentChartInstanceMap map[string][]*common.ChartInstance
type tRepository struct { type tRepository struct {
sync.RWMutex sync.RWMutex
deployments map[string]common.Deployment deployments map[string]common.Deployment
manifests map[string]map[string]*common.Manifest manifests map[string]map[string]*common.Manifest
instances map[string]deploymentTypeInstanceMap instances map[string]deploymentChartInstanceMap
} }
// NewRepository returns a new transient repository. Its lifetime is coupled // NewRepository returns a new transient repository. Its lifetime is coupled
...@@ -46,14 +46,14 @@ func NewRepository() repository.Repository { ...@@ -46,14 +46,14 @@ func NewRepository() repository.Repository {
return &tRepository{ return &tRepository{
deployments: make(map[string]common.Deployment, 0), deployments: make(map[string]common.Deployment, 0),
manifests: make(map[string]map[string]*common.Manifest, 0), manifests: make(map[string]map[string]*common.Manifest, 0),
instances: make(map[string]deploymentTypeInstanceMap, 0), instances: make(map[string]deploymentChartInstanceMap, 0),
} }
} }
func (r *tRepository) Close() { func (r *tRepository) Close() {
r.deployments = make(map[string]common.Deployment, 0) r.deployments = make(map[string]common.Deployment, 0)
r.manifests = make(map[string]map[string]*common.Manifest, 0) r.manifests = make(map[string]map[string]*common.Manifest, 0)
r.instances = make(map[string]deploymentTypeInstanceMap, 0) r.instances = make(map[string]deploymentChartInstanceMap, 0)
} }
// ListDeployments returns of all of the deployments in the repository. // ListDeployments returns of all of the deployments in the repository.
...@@ -258,8 +258,8 @@ func (r *tRepository) GetLatestManifest(deploymentName string) (*common.Manifest ...@@ -258,8 +258,8 @@ func (r *tRepository) GetLatestManifest(deploymentName string) (*common.Manifest
return r.getManifestForDeployment(deploymentName, d.LatestManifest) return r.getManifestForDeployment(deploymentName, d.LatestManifest)
} }
// ListTypes returns all types known from existing instances. // ListCharts returns all types known from existing instances.
func (r *tRepository) ListTypes() ([]string, error) { func (r *tRepository) ListCharts() ([]string, error) {
var keys []string var keys []string
for k := range r.instances { for k := range r.instances {
keys = append(keys, k) keys = append(keys, k)
...@@ -268,10 +268,10 @@ func (r *tRepository) ListTypes() ([]string, error) { ...@@ -268,10 +268,10 @@ func (r *tRepository) ListTypes() ([]string, error) {
return keys, nil return keys, nil
} }
// GetTypeInstances returns all instances of a given type. If type is empty, // GetChartInstances returns all instances of a given type. If type is empty,
// returns all instances for all types. // returns all instances for all types.
func (r *tRepository) GetTypeInstances(typeName string) ([]*common.TypeInstance, error) { func (r *tRepository) GetChartInstances(typeName string) ([]*common.ChartInstance, error) {
var instances []*common.TypeInstance var instances []*common.ChartInstance
for t, dInstMap := range r.instances { for t, dInstMap := range r.instances {
if t == typeName || typeName == "" || typeName == "all" { if t == typeName || typeName == "" || typeName == "all" {
for _, i := range dInstMap { for _, i := range dInstMap {
...@@ -283,9 +283,9 @@ func (r *tRepository) GetTypeInstances(typeName string) ([]*common.TypeInstance, ...@@ -283,9 +283,9 @@ func (r *tRepository) GetTypeInstances(typeName string) ([]*common.TypeInstance,
return instances, nil return instances, nil
} }
// ClearTypeInstancesForDeployment deletes all type instances associated with the given // ClearChartInstancesForDeployment deletes all type instances associated with the given
// deployment from the repository. // deployment from the repository.
func (r *tRepository) ClearTypeInstancesForDeployment(deploymentName string) error { func (r *tRepository) ClearChartInstancesForDeployment(deploymentName string) error {
r.Lock() r.Lock()
defer r.Unlock() defer r.Unlock()
...@@ -299,22 +299,22 @@ func (r *tRepository) ClearTypeInstancesForDeployment(deploymentName string) err ...@@ -299,22 +299,22 @@ func (r *tRepository) ClearTypeInstancesForDeployment(deploymentName string) err
return nil return nil
} }
// AddTypeInstances adds the supplied type instances to the repository. // AddChartInstances adds the supplied type instances to the repository.
func (r *tRepository) AddTypeInstances(instances map[string][]*common.TypeInstance) error { func (r *tRepository) AddChartInstances(instances map[string][]*common.ChartInstance) error {
r.Lock() r.Lock()
defer r.Unlock() defer r.Unlock()
// Add instances to the appropriate type and deployment maps. // Add instances to the appropriate type and deployment maps.
for t, is := range instances { for t, is := range instances {
if r.instances[t] == nil { if r.instances[t] == nil {
r.instances[t] = make(deploymentTypeInstanceMap) r.instances[t] = make(deploymentChartInstanceMap)
} }
tmap := r.instances[t] tmap := r.instances[t]
for _, instance := range is { for _, instance := range is {
deployment := instance.Deployment deployment := instance.Deployment
if tmap[deployment] == nil { if tmap[deployment] == nil {
tmap[deployment] = make([]*common.TypeInstance, 0) tmap[deployment] = make([]*common.ChartInstance, 0)
} }
tmap[deployment] = append(tmap[deployment], instance) tmap[deployment] = append(tmap[deployment], instance)
......
...@@ -50,6 +50,6 @@ func TestRepositoryDeleteDeploymentWorksForget(t *testing.T) { ...@@ -50,6 +50,6 @@ func TestRepositoryDeleteDeploymentWorksForget(t *testing.T) {
repository.TestRepositoryDeleteDeploymentWorksForget(t, NewRepository()) repository.TestRepositoryDeleteDeploymentWorksForget(t, NewRepository())
} }
func TestRepositoryTypeInstances(t *testing.T) { func TestRepositoryChartInstances(t *testing.T) {
repository.TestRepositoryTypeInstances(t, NewRepository()) repository.TestRepositoryChartInstances(t, NewRepository())
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment