Beispiel #1
0
func (ci *CpImage) Validate() (err error) {
	if err := ValidateSim(ci.Sim); err != nil {
		return err
	}
	if err := ValidateNetwork(ci.Network); err != nil {
		return err
	}

	dal, err := release.NewDal()
	if err != nil {
		return fmt.Errorf("Validate dtim error")
	}
	defer dal.Close()

	var image interface{}
	switch ci.Id {
	case ota_constant.ID_ARBI, ota_constant.ID_ARB2:
		image, _ = release.FindArbiByPath(dal, ci.Path)
	case ota_constant.ID_GRBI, ota_constant.ID_GRB2:
		image, _ = release.FindGrbiByPath(dal, ci.Path)
	case ota_constant.ID_RFIC, ota_constant.ID_RFI2:
		image, _ = release.FindRficByPath(dal, ci.Path)
	}

	v := reflect.ValueOf(image)
	if v.IsNil() {
		return fmt.Errorf("Illegal image path in dtim: %s", ci.Path)
	}

	return nil
}
Beispiel #2
0
func getArbiList(dal *release.Dal, cp *release.CpRelease, original_arbi string) ([]string, error) {
	arbi_list := make([]string, 0, 5)

	//0. replace version
	arbi_primary, err := ReplaceVersionInPath(original_arbi, cp.Version)
	if err == nil && arbi_primary != "" {
		rel_arbi, err := release.FindArbiByPath(dal, arbi_primary)
		if err == nil && rel_arbi != nil {
			//			fmt.Println("primary arbi ", arbi_primary, " exist")
			arbi_list = append(arbi_list, arbi_primary)
			return arbi_list, nil
		} else {
			//			fmt.Println("primary arbi ", arbi_primary, " not exist")
		}
	}

	//1. search in db
	if !ota_constant.QUERY_MODE_STRICT {
		query := fmt.Sprintf("SELECT * FROM %s where cp_id=%d AND flag=%d", cp_constant.TABLE_ARBI, cp.Id, cp_constant.AVAILABLE_FLAG)
		arbis, err := release.FindArbiList(dal, query)
		if err != nil {
			return nil, err
		}

		if len(arbis) == 0 {
			return nil, fmt.Errorf("Cannot find the right Image.")
		}

		for _, arbi := range arbis {
			arbi_list = append(arbi_list, arbi.RelPath)
		}
	}

	return arbi_list, nil
}
Beispiel #3
0
func ProcessArbi(cp *release.CpRelease, dal *release.Dal) error {
	arbi_list, err := policy.FindArbi(cp.RelPath, cp.Mode)
	if err != nil {
		return err
	} else {
		for _, arbi_path := range arbi_list {
			arbi_rel_path := arbi_path[constant.PATH_PREFIX_LEN:]
			arbi, err := release.FindArbiByPath(dal, arbi_rel_path)
			if err == nil && arbi != nil {
				log.Printf("Existed arbi : %s\n", arbi)
				//id unmatched, delete itself
				if arbi.CpId != cp.Id {
					log.Printf("Id unmatched cp[%d] <--> arbi[%d] : delete", cp.Id, arbi.CpId)
					arbi.Delete(dal)
				} else {
					continue
				}
			}
			arbi = &release.Arbi{}
			arbi.CpId = cp.Id
			arbi.Flag = constant.AVAILABLE_FLAG
			arbi.LastModifyTs = time.Now().Unix()
			arbi.RelPath = arbi_rel_path
			log.Printf("Found arbi in [%s] : %s\n", cp.RelPath, arbi)
			id, err := arbi.Save(dal)
			if err != nil {
				log.Printf("Save ARBI failed: %s\n", err)
			} else {
				log.Printf("Save ARBI success: %d | %s\n", id, arbi)
			}
		}
	}
	return nil
}