Exemple #1
0
func (self *Huddle) ListInstances(tenant string, bundleType bundletype.BundleType) ([]*Instance, error) {
	prefix := self.jujuPrefix(tenant, bundleType)

	statuses, err := self.JujuClient.GetServiceStatusList(prefix)
	if err != nil {
		return nil, err
	}
	if statuses == nil {
		return nil, rs.HttpError(http.StatusNotFound)
	}

	instances := []*Instance{}
	for key, state := range statuses {
		_, bundleTypeId, instanceId, module, _, err := ParseUnit(key)
		if err != nil {
			log.Debug("Ignoring unparseable service: %v", key)
			continue
		}

		assert.That(bundleTypeId == bundleType.Key())

		if module != bundleType.PrimaryJujuService() {
			continue
		}

		i := self.NewInstance(tenant, bundleType, instanceId)
		i.cacheState(&state)

		instances = append(instances, i)
	}

	return instances, nil
}
Exemple #2
0
func (self *Huddle) jujuPrefix(tenant string, bundleType bundletype.BundleType) string {
	tenant = strings.Replace(tenant, "-", "", -1)

	// The u prefix is for user.
	// This is both a way to separate out user services from our services,
	// and a way to make sure the service name is valid (is not purely numeric / does not start with a number)
	prefix := "u" + tenant + "-" + bundleType.Key() + "-"

	return prefix
}
Exemple #3
0
// Builds an Instance object representing a particular JXaaS Instance.
// This just builds the object, it does not e.g. check that the instance already exists.
func (self *Huddle) NewInstance(tenant string, bundleType bundletype.BundleType, instanceId string) *Instance {
	s := &Instance{}
	s.huddle = self
	s.tenant = tenant
	s.bundleType = bundleType
	s.instanceId = instanceId

	// The u prefix is for user.
	// This is both a way to separate out user services from our services,
	// and a way to make sure the service name is valid (is not purely numeric / does not start with a number)
	prefix := "u" + tenant + "-" + bundleType.Key() + "-"

	prefix = prefix + instanceId + "-"

	s.jujuPrefix = prefix

	prefix = prefix + bundleType.PrimaryJujuService()
	s.primaryServiceId = prefix

	return s
}
Exemple #4
0
// Adds a bundletype to the system
func (self *System) AddBundleType(bundleType bundletype.BundleType) {
	self.BundleTypes[bundleType.Key()] = bundleType
}