Renames in manager/repository

pull/440/head
jackgr 9 years ago
parent 43a6876a4f
commit ab5f29d02d

@ -44,7 +44,7 @@ type pManifest struct {
type pInstance struct {
ID string `bson:"_id"`
common.TypeInstance
common.ChartInstance
}
type pRepository struct {
@ -428,8 +428,8 @@ func (r *pRepository) removeManifestsForDeployment(d *common.Deployment) error {
return nil
}
// ListTypes returns all types known from existing instances.
func (r *pRepository) ListTypes() ([]string, error) {
// ListCharts returns all types known from existing instances.
func (r *pRepository) ListCharts() ([]string, error) {
var result []string
if err := r.Instances.Find(nil).Distinct("typeinstance.type", &result); err != nil {
return nil, fmt.Errorf("cannot list type instances: %s", err)
@ -438,9 +438,9 @@ func (r *pRepository) ListTypes() ([]string, error) {
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.
func (r *pRepository) GetTypeInstances(typeName string) ([]*common.TypeInstance, error) {
func (r *pRepository) GetChartInstances(typeName string) ([]*common.ChartInstance, error) {
query := bson.M{"typeinstance.type": typeName}
if typeName == "" || typeName == "all" {
query = nil
@ -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)
}
instances := []*common.TypeInstance{}
instances := []*common.ChartInstance{}
for _, pi := range result {
instances = append(instances, &pi.TypeInstance)
instances = append(instances, &pi.ChartInstance)
}
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.
func (r *pRepository) ClearTypeInstancesForDeployment(deploymentName string) error {
func (r *pRepository) ClearChartInstancesForDeployment(deploymentName string) error {
if deploymentName != "" {
query := bson.M{"typeinstance.deployment": deploymentName}
if _, err := r.Instances.RemoveAll(query); err != nil {
@ -472,12 +472,12 @@ func (r *pRepository) ClearTypeInstancesForDeployment(deploymentName string) err
return nil
}
// AddTypeInstances adds the supplied type instances to the repository.
func (r *pRepository) AddTypeInstances(instances map[string][]*common.TypeInstance) error {
// AddChartInstances adds the supplied type instances to the repository.
func (r *pRepository) AddChartInstances(instances map[string][]*common.ChartInstance) error {
for _, is := range instances {
for _, i := range is {
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 {
return fmt.Errorf("cannot insert type instance %v: %s", wrapper, err)
}

@ -102,9 +102,9 @@ func TestRepositoryDeleteDeploymentWorksForget(t *testing.T) {
}
}
func TestRepositoryTypeInstances(t *testing.T) {
func TestRepositoryChartInstances(t *testing.T) {
if r := createRepository(); r != nil {
defer resetRepository(t, r)
repository.TestRepositoryTypeInstances(t, r)
repository.TestRepositoryChartInstances(t, r)
}
}

@ -40,10 +40,10 @@ type Repository interface {
GetLatestManifest(deploymentName string) (*common.Manifest, error)
// Types.
ListTypes() ([]string, error)
GetTypeInstances(typeName string) ([]*common.TypeInstance, error)
ClearTypeInstancesForDeployment(deploymentName string) error
AddTypeInstances(instances map[string][]*common.TypeInstance) error
ListCharts() ([]string, error)
GetChartInstances(chartName string) ([]*common.ChartInstance, error)
ClearChartInstancesForDeployment(deploymentName string) error
AddChartInstances(instances map[string][]*common.ChartInstance) error
Close()
}

@ -210,9 +210,9 @@ func TestRepositoryDeleteDeploymentWorksForget(t *testing.T, r Repository) {
}
}
// TestRepositoryTypeInstances checks that type instances can be listed and retrieved successfully.
func TestRepositoryTypeInstances(t *testing.T, r Repository) {
d1Map := map[string][]*common.TypeInstance{
// TestRepositoryChartInstances checks that type instances can be listed and retrieved successfully.
func TestRepositoryChartInstances(t *testing.T, r Repository) {
d1Map := map[string][]*common.ChartInstance{
"t1": {
{
Name: "i1",
@ -224,7 +224,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
},
}
d2Map := map[string][]*common.TypeInstance{
d2Map := map[string][]*common.ChartInstance{
"t2": {
{
Name: "i2",
@ -236,7 +236,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
},
}
d3Map := map[string][]*common.TypeInstance{
d3Map := map[string][]*common.ChartInstance{
"t2": {
{
Name: "i3",
@ -248,7 +248,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
},
}
instances, err := r.GetTypeInstances("noinstances")
instances, err := r.GetChartInstances("noinstances")
if err != nil {
t.Fatal(err)
}
@ -257,7 +257,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected no instances: %v", instances)
}
types, err := r.ListTypes()
types, err := r.ListCharts()
if err != nil {
t.Fatal(err)
}
@ -266,11 +266,11 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected no types: %v", types)
}
r.AddTypeInstances(d1Map)
r.AddTypeInstances(d2Map)
r.AddTypeInstances(d3Map)
r.AddChartInstances(d1Map)
r.AddChartInstances(d2Map)
r.AddChartInstances(d3Map)
instances, err = r.GetTypeInstances("unknowntype")
instances, err = r.GetChartInstances("unknowntype")
if err != nil {
t.Fatal(err)
}
@ -279,7 +279,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected no instances: %v", instances)
}
instances, err = r.GetTypeInstances("t1")
instances, err = r.GetChartInstances("t1")
if err != nil {
t.Fatal(err)
}
@ -288,7 +288,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected one instance: %v", instances)
}
instances, err = r.GetTypeInstances("t2")
instances, err = r.GetChartInstances("t2")
if err != nil {
t.Fatal(err)
}
@ -297,7 +297,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected two instances: %v", instances)
}
instances, err = r.GetTypeInstances("all")
instances, err = r.GetChartInstances("all")
if err != nil {
t.Fatal(err)
}
@ -306,7 +306,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected three total instances: %v", instances)
}
types, err = r.ListTypes()
types, err = r.ListCharts()
if err != nil {
t.Fatal(err)
}
@ -315,12 +315,12 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected two total types: %v", types)
}
err = r.ClearTypeInstancesForDeployment("d1")
err = r.ClearChartInstancesForDeployment("d1")
if err != nil {
t.Fatal(err)
}
instances, err = r.GetTypeInstances("t1")
instances, err = r.GetChartInstances("t1")
if err != nil {
t.Fatal(err)
}
@ -329,7 +329,7 @@ func TestRepositoryTypeInstances(t *testing.T, r Repository) {
t.Fatalf("expected no instances after clear: %v", instances)
}
types, err = r.ListTypes()
types, err = r.ListCharts()
if err != nil {
t.Fatal(err)
}

@ -27,16 +27,16 @@ import (
"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
// when deployments are created/updated/deleted.
type deploymentTypeInstanceMap map[string][]*common.TypeInstance
type deploymentChartInstanceMap map[string][]*common.ChartInstance
type tRepository struct {
sync.RWMutex
deployments map[string]common.Deployment
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
@ -46,14 +46,14 @@ func NewRepository() repository.Repository {
return &tRepository{
deployments: make(map[string]common.Deployment, 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() {
r.deployments = make(map[string]common.Deployment, 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.
@ -258,8 +258,8 @@ func (r *tRepository) GetLatestManifest(deploymentName string) (*common.Manifest
return r.getManifestForDeployment(deploymentName, d.LatestManifest)
}
// ListTypes returns all types known from existing instances.
func (r *tRepository) ListTypes() ([]string, error) {
// ListCharts returns all types known from existing instances.
func (r *tRepository) ListCharts() ([]string, error) {
var keys []string
for k := range r.instances {
keys = append(keys, k)
@ -268,10 +268,10 @@ func (r *tRepository) ListTypes() ([]string, error) {
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.
func (r *tRepository) GetTypeInstances(typeName string) ([]*common.TypeInstance, error) {
var instances []*common.TypeInstance
func (r *tRepository) GetChartInstances(typeName string) ([]*common.ChartInstance, error) {
var instances []*common.ChartInstance
for t, dInstMap := range r.instances {
if t == typeName || typeName == "" || typeName == "all" {
for _, i := range dInstMap {
@ -283,9 +283,9 @@ func (r *tRepository) GetTypeInstances(typeName string) ([]*common.TypeInstance,
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.
func (r *tRepository) ClearTypeInstancesForDeployment(deploymentName string) error {
func (r *tRepository) ClearChartInstancesForDeployment(deploymentName string) error {
r.Lock()
defer r.Unlock()
@ -299,22 +299,22 @@ func (r *tRepository) ClearTypeInstancesForDeployment(deploymentName string) err
return nil
}
// AddTypeInstances adds the supplied type instances to the repository.
func (r *tRepository) AddTypeInstances(instances map[string][]*common.TypeInstance) error {
// AddChartInstances adds the supplied type instances to the repository.
func (r *tRepository) AddChartInstances(instances map[string][]*common.ChartInstance) error {
r.Lock()
defer r.Unlock()
// Add instances to the appropriate type and deployment maps.
for t, is := range instances {
if r.instances[t] == nil {
r.instances[t] = make(deploymentTypeInstanceMap)
r.instances[t] = make(deploymentChartInstanceMap)
}
tmap := r.instances[t]
for _, instance := range is {
deployment := instance.Deployment
if tmap[deployment] == nil {
tmap[deployment] = make([]*common.TypeInstance, 0)
tmap[deployment] = make([]*common.ChartInstance, 0)
}
tmap[deployment] = append(tmap[deployment], instance)

@ -50,6 +50,6 @@ func TestRepositoryDeleteDeploymentWorksForget(t *testing.T) {
repository.TestRepositoryDeleteDeploymentWorksForget(t, NewRepository())
}
func TestRepositoryTypeInstances(t *testing.T) {
repository.TestRepositoryTypeInstances(t, NewRepository())
func TestRepositoryChartInstances(t *testing.T) {
repository.TestRepositoryChartInstances(t, NewRepository())
}

Loading…
Cancel
Save