aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/app/instance.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-05-23 13:50:50 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-05-23 19:28:22 -0700
commit5207bd099a84832a5d7c3333bf540fa8481ce78a (patch)
treeb6f3aaea641ceb3406dc1c14c7d642098558129f /src/k8splugin/internal/app/instance.go
parent525023e1d288bbf9cf59584c5b5dd37d83be7a4b (diff)
Update broker responses to match spec and SO
The broker responses need to match the spec and what SO expects as responses. CREATE_COMPLETE instead of CREATED in both POST and GET DELETE now returns a response body GET by name is now supported Name is an alias for vf_module_id which is expected to be provided as an attribute in sdnc_directives in the original POST request Issue-ID: MULTICLOUD-645 Change-Id: Ifeca755a07298d0a858cbe9e80f9ce654d6d21b8 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/app/instance.go')
-rw-r--r--src/k8splugin/internal/app/instance.go66
1 files changed, 45 insertions, 21 deletions
diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go
index fe9f3857..19841c01 100644
--- a/src/k8splugin/internal/app/instance.go
+++ b/src/k8splugin/internal/app/instance.go
@@ -50,7 +50,7 @@ type InstanceResponse struct {
type InstanceManager interface {
Create(i InstanceRequest) (InstanceResponse, error)
Get(id string) (InstanceResponse, error)
- Find(rbName string, ver string, profile string) ([]InstanceResponse, error)
+ Find(rbName string, ver string, profile string, labelKeys map[string]string) ([]InstanceResponse, error)
Delete(id string) error
}
@@ -131,13 +131,8 @@ func (v *InstanceClient) Create(i InstanceRequest) (InstanceResponse, error) {
//Compose the return response
resp := InstanceResponse{
- ID: id,
- Request: InstanceRequest{
- RBName: i.RBName,
- RBVersion: i.RBVersion,
- ProfileName: i.ProfileName,
- CloudRegion: i.CloudRegion,
- },
+ ID: id,
+ Request: i,
Namespace: profile.Namespace,
Resources: createdResources,
}
@@ -179,9 +174,11 @@ func (v *InstanceClient) Get(id string) (InstanceResponse, error) {
// Find returns the instances that match the given criteria
// If version is empty, it will return all instances for a given rbName
// If profile is empty, it will return all instances for a given rbName+version
-func (v *InstanceClient) Find(rbName string, version string, profile string) ([]InstanceResponse, error) {
- if rbName == "" {
- return []InstanceResponse{}, pkgerrors.New("rbName is required and cannot be empty")
+// If labelKeys are provided, the results are filtered based on that.
+// It is an AND operation for labelkeys.
+func (v *InstanceClient) Find(rbName string, version string, profile string, labelKeys map[string]string) ([]InstanceResponse, error) {
+ if rbName == "" && len(labelKeys) == 0 {
+ return []InstanceResponse{}, pkgerrors.New("rbName or labelkeys is required and cannot be empty")
}
values, err := db.DBconn.ReadAll(v.storeName, v.tagInst)
@@ -191,6 +188,7 @@ func (v *InstanceClient) Find(rbName string, version string, profile string) ([]
response := []InstanceResponse{}
//values is a map[string][]byte
+InstanceResponseLoop:
for _, value := range values {
resp := InstanceResponse{}
db.DBconn.Unmarshal(value, &resp)
@@ -198,19 +196,45 @@ func (v *InstanceClient) Find(rbName string, version string, profile string) ([]
return []InstanceResponse{}, pkgerrors.Wrap(err, "Unmarshaling Instance Value")
}
- if resp.Request.RBName == rbName {
+ // Filter by labels provided
+ if len(labelKeys) != 0 {
+ for lkey, lvalue := range labelKeys {
+ //Check if label key exists and get its value
+ if val, ok := resp.Request.Labels[lkey]; ok {
+ if lvalue != val {
+ continue InstanceResponseLoop
+ }
+ } else {
+ continue InstanceResponseLoop
+ }
+ }
+ }
+
+ if rbName != "" {
+ if resp.Request.RBName == rbName {
- //Check if a version is provided and if it matches
- if version != "" {
- if resp.Request.RBVersion == version {
- //Check if a profilename matches or if it is not provided
- if profile == "" || resp.Request.ProfileName == profile {
- response = append(response, resp)
+ //Check if a version is provided and if it matches
+ if version != "" {
+ if resp.Request.RBVersion == version {
+ //Check if a profilename matches or if it is not provided
+ if profile == "" || resp.Request.ProfileName == profile {
+ response = append(response, resp)
+ }
}
+ } else {
+ //Append all versions as version is not provided
+ response = append(response, resp)
}
- } else {
- //Append all versions as version is not provided
- response = append(response, resp)
+ }
+ } else {
+ response = append(response, resp)
+ }
+ }
+
+ //filter the list by labelKeys now
+ for _, value := range response {
+ for _, label := range labelKeys {
+ if _, ok := value.Request.Labels[label]; ok {
}
}
}