func (self *EndpointBundle) HttpGet(huddle *core.Huddle) ([]*model.Instance, error) { tenant := self.Parent.Parent.Tenant bundleType := self.BundleType instances, err := huddle.ListInstances(tenant, bundleType) if err != nil { return nil, err } if instances == nil { return nil, nil } models := []*model.Instance{} for _, instance := range instances { model, err := instance.GetState() if err != nil { return nil, err } if model == nil { log.Debug("Ignoring concurrently deleted (?) instance: %v", instance) continue } models = append(models, model) } return models, nil }
// update_relation_properties RPC handler func (self *EndpointRpcUpdateRelationProperties) HttpPost(huddle *core.Huddle, request *RpcUpdateRelationPropertiesRequest) (*RpcUpdateRelationPropertiesResponse, error) { // TODO: Validate that this is coming from one of our machines? log.Info("Got RPC request: UpdateRelationProperties: %v", request) response := &RpcUpdateRelationPropertiesResponse{} // Sanitize if request.Properties == nil { request.Properties = make(map[string]string) } localUnit := request.ServiceName if localUnit == "" { return nil, fmt.Errorf("ServiceName is required") } tenant, bundleTypeName, instanceId, _, _, err := core.ParseUnit(localUnit) if err != nil { return nil, err } bundleType := huddle.System.GetBundleType(bundleTypeName) if bundleType == nil { return nil, fmt.Errorf("Unknown bundle type: %v", bundleTypeName) } primaryService := bundleType.PrimaryJujuService() // remoteUnit := request.RemoteName // if remoteUnit == "" { // // We're a bit stuck here. We do have the relationId and other info, // // we just don't have the remote relation, and we're storing the attributes on the remote relation // // TODO: Infer the remote relation? (-stubclient to -primary)? // log.Warn("No remote unit; can't remove relations") // return response, nil // } // // _, _, remoteInstanceId, _, remoteUnitId, err := core.ParseUnit(remoteUnit) // if err != nil { // return nil, err // } instance := huddle.NewInstance(tenant, bundleType, instanceId) relationId := request.RelationId if request.Action == "broken" { err = instance.DeleteRelationInfo(primaryService, relationId) } else { err = instance.SetRelationInfo(primaryService, relationId, request.Properties) } if err != nil { return nil, err } return response, nil }