func UpdateAssociatedObjectList(nsId string, resourceType string, resourceId string, cmd string, objectKey string) ([]string, error) {

	err := common.CheckString(nsId)
	if err != nil {
		common.CBLog.Error(err)
		return nil, err
	}

	err = common.CheckString(resourceId)
	if err != nil {
		common.CBLog.Error(err)
		return nil, err
	}
	/*
		check, err := CheckResource(nsId, resourceType, resourceId)

		if !check {
			errString := "The " + resourceType + " " + resourceId + " does not exist."
			//mapA := map[string]string{"message": errString}
			//mapB, _ := json.Marshal(mapA)
			err := fmt.Errorf(errString)
			return -1, err
		}

		if err != nil {
			common.CBLog.Error(err)
			return -1, err
		}
	*/
	fmt.Println("[Set count] " + resourceType + ", " + resourceId)

	key := common.GenResourceKey(nsId, resourceType, resourceId)
	//fmt.Println(key)

	keyValue, err := common.CBStore.Get(key)
	if err != nil {
		common.CBLog.Error(err)
		return nil, err
	}

	if keyValue != nil {
		objList, _ := GetAssociatedObjectList(nsId, resourceType, resourceId)
		switch cmd {
		case common.StrAdd:
			for _, v := range objList {
				if v == objectKey {
					errString := objectKey + " is already associated with " + resourceType + " " + resourceId + "."
					err = fmt.Errorf(errString)
					return nil, err
				}
			}
			// fmt.Println("len(objList): " + strconv.Itoa(len(objList))) // for debug
			// fmt.Print("objList: ")                                     // for debug
			// fmt.Println(objList)                                       // for debug

			var anyJson map[string]interface{}
			json.Unmarshal([]byte(keyValue.Value), &anyJson)
			if anyJson["associatedObjectList"] == nil {
				arrayToBe := []string{objectKey}
				// fmt.Println("array_to_be: ", array_to_be) // for debug

				anyJson["associatedObjectList"] = arrayToBe
			} else { // anyJson["associatedObjectList"] != nil
				arrayAsIs := anyJson["associatedObjectList"].([]interface{})
				// fmt.Println("array_as_is: ", array_as_is) // for debug

				arrayToBe := append(arrayAsIs, objectKey)
				// fmt.Println("array_to_be: ", array_to_be) // for debug

				anyJson["associatedObjectList"] = arrayToBe
			}
			updatedJson, _ := json.Marshal(anyJson)
			// fmt.Println(string(updatedJson)) // for debug

			keyValue.Value = string(updatedJson)
		case common.StrDelete:
			var foundKey int
			var foundVal string
			for k, v := range objList {
				if v == objectKey {
					foundKey = k
					foundVal = v
					break
				}
			}
			if foundVal == "" {
				errString := "Cannot find the associated object " + objectKey + "."
				err = fmt.Errorf(errString)
				return nil, err
			} else {
				keyValue.Value, err = sjson.Delete(keyValue.Value, "associatedObjectList."+strconv.Itoa(foundKey))
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
			}
		}

		if err != nil {
			common.CBLog.Error(err)
			return nil, err
		}
		err = common.CBStore.Put(key, keyValue.Value)
		if err != nil {
			common.CBLog.Error(err)
			return nil, err
		}
		/*
			keyValue, _ := common.CBStore.Get(key)
			//fmt.Println("<" + keyValue.Key + "> \n" + keyValue.Value)
			fmt.Println("===========================")
			to_be = int8(gjson.Get(keyValue.Value, "inUseCount").Uint())
			return to_be, nil
		*/

		result, _ := GetAssociatedObjectList(nsId, resourceType, resourceId)
		return result, nil
	}
	errString := "Cannot get " + resourceType + " " + resourceId + "."
	err = fmt.Errorf(errString)
	return nil, err
}
// UpdateAssociatedObjectList adds or deletes the objectKey (currently, vmKey) to/from TB object's associatedObjectList
UpdateAssociatedObjectList adds or deletes the objectKey (currently, vmKey) to/from TB object's associatedObjectList
// UpdateAssociatedObjectList adds or deletes the objectKey ( currently vmKey ) to / from TB object ' s associatedObjectList
func UpdateAssociatedObjectList(nsId string, resourceType string, resourceId string, cmd string, objectKey string) ([]string, error) {
	err := common.CheckString(nsId)
	if err != nil {
		common.CBLog.Error(err)
		return nil, err
	}
	err = common.CheckString(resourceId)
	if err != nil {
		common.CBLog.Error(err)
		return nil, err
	}
	fmt.Println("[Set count] " + resourceType + ", " + resourceId)
	key := common.GenResourceKey(nsId, resourceType, resourceId)
	keyValue, err := common.CBStore.Get(key)
	if err != nil {
		common.CBLog.Error(err)
		return nil, err
	}
	if keyValue != nil {
		objList, _ := GetAssociatedObjectList(nsId, resourceType, resourceId)
		switch cmd {
		case common.StrAdd:
			for _, v := range objList {
				if v == objectKey {
					errString := objectKey + " is already associated with " + resourceType + " " + resourceId + "."
					err = fmt.Errorf(errString)
					return nil, err
				}
			}
			var anyJson map[string]interface{}
			json.Unmarshal([]byte(keyValue.Value), &anyJson)
			if anyJson["associatedObjectList"] == nil {
				arrayToBe := []string{objectKey}
				anyJson["associatedObjectList"] = arrayToBe
			} else { 
				arrayAsIs := anyJson["associatedObjectList"].([]interface{})
				arrayToBe := append(arrayAsIs, objectKey)
				anyJson["associatedObjectList"] = arrayToBe
			}
			updatedJson, _ := json.Marshal(anyJson)
			keyValue.Value = string(updatedJson)
		case common.StrDelete:
			var foundKey int
			var foundVal string
			for k, v := range objList {
				if v == objectKey {
					foundKey = k
					foundVal = v
					break
				}
			}
			if foundVal == "" {
				errString := "Cannot find the associated object " + objectKey + "."
				err = fmt.Errorf(errString)
				return nil, err
			} else {
				keyValue.Value, err = sjson.Delete(keyValue.Value, "associatedObjectList."+strconv.Itoa(foundKey))
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
			}
		}
		if err != nil {
			common.CBLog.Error(err)
			return nil, err
		}
		err = common.CBStore.Put(key, keyValue.Value)
		if err != nil {
			common.CBLog.Error(err)
			return nil, err
		}
		result, _ := GetAssociatedObjectList(nsId, resourceType, resourceId)
		return result, nil
	}
	errString := "Cannot get " + resourceType + " " + resourceId + "."
	err = fmt.Errorf(errString)
	return nil, err
}
func UpdateAssociatedObjectList ( nsId string , resourceType string , resourceId string , cmd string , objectKey string ) ( [ ] string , error ) { err := common . CheckString ( nsId ) if err != nil { common . CBLog . Error ( err ) return nil , err } err = common . CheckString ( resourceId ) if err != nil { common . CBLog . Error ( err ) return nil , err } fmt . Println ( " " + resourceType + " " + resourceId ) key := common . GenResourceKey ( nsId , resourceType , resourceId ) keyValue , err := common . CBStore . Get ( key ) if err != nil { common . CBLog . Error ( err ) return nil , err } if keyValue != nil { objList , _ := GetAssociatedObjectList ( nsId , resourceType , resourceId ) switch cmd { case common . StrAdd : for _ , v := range objList { if v == objectKey { errString := objectKey + " " + resourceType + " " + resourceId + " " err = fmt . Errorf ( errString ) return nil , err } } var anyJson map [ string ] interface { } json . Unmarshal ( [ ] byte ( keyValue . Value ) , & anyJson ) if anyJson [ " " ] == nil { arrayToBe := [ ] string { objectKey } anyJson [ " " ] = arrayToBe } else { arrayAsIs := anyJson [ " " ] . ( [ ] interface { } ) arrayToBe := append ( arrayAsIs , objectKey ) anyJson [ " " ] = arrayToBe } updatedJson , _ := json . Marshal ( anyJson ) keyValue . Value = string ( updatedJson ) case common . StrDelete : var foundKey int var foundVal string for k , v := range objList { if v == objectKey { foundKey = k foundVal = v break } } if foundVal == " " { errString := " " + objectKey + " " err = fmt . Errorf ( errString ) return nil , err } else { keyValue . Value , err = sjson . Delete ( keyValue . Value , " " + strconv . Itoa ( foundKey ) ) if err != nil { common . CBLog . Error ( err ) return nil , err } } } if err != nil { common . CBLog . Error ( err ) return nil , err } err = common . CBStore . Put ( key , keyValue . Value ) if err != nil { common . CBLog . Error ( err ) return nil , err } result , _ := GetAssociatedObjectList ( nsId , resourceType , resourceId ) return result , nil } errString := " " + resourceType + " " + resourceId + " " err = fmt . Errorf ( errString ) return nil , err }
UpdateAssociatedObjectList adds or deletes the objectKey (currently, vmKey) to/from TB object's associatedObjectList
UpdateAssociatedObjectList adds or deletes the objectKey ( currently vmKey ) to / from TB object ' s associatedObjectList
/*
		check, err := CheckResource(nsId, resourceType, resourceId)

		if !check {
			errString := "The " + resourceType + " " + resourceId + " does not exist."
			//mapA := map[string]string{"message": errString}
			//mapB, _ := json.Marshal(mapA)
			err := fmt.Errorf(errString)
			return -1, err
		}

		if err != nil {
			common.CBLog.Error(err)
			return -1, err
		}
	*/ //fmt.Println(key) // fmt.Println("len(objList): " + strconv.Itoa(len(objList))) // for debug // fmt.Print("objList: ")                                     // for debug // fmt.Println(objList)                                       // for debug // fmt.Println("array_to_be: ", array_to_be) // for debug // anyJson["associatedObjectList"] != nil // fmt.Println("array_as_is: ", array_as_is) // for debug // fmt.Println("array_to_be: ", array_to_be) // for debug // fmt.Println(string(updatedJson)) // for debug /*
			keyValue, _ := common.CBStore.Get(key)
			//fmt.Println("<" + keyValue.Key + "> \n" + keyValue.Value)
			fmt.Println("===========================")
			to_be = int8(gjson.Get(keyValue.Value, "inUseCount").Uint())
			return to_be, nil
		*/