Ejemplo n.º 1
0
// IsTableStatusWithConf will test the equality status of a table.
func IsTableStatusWithConf(tablename string, status string, c *conf.AWS_Conf) (bool, error) {
	if !conf.IsValid(c) {
		return false, errors.New("describe_table.IsTableStatusWithConf: c is not valid")
	}
	d := ep.Endpoint(&DescribeTable{TableName: tablename})
	s_resp, s_code, s_err := authreq.RetryReq_V4WithConf(d, DESCTABLE_ENDPOINT, c)
	if s_err != nil {
		e := fmt.Sprintf("describe_table.IsTableStatus: "+
			"check on %s err %s",
			tablename, s_err.Error())
		// if not a 500 problem, don't retry
		if !ep.ServerErr(s_code) {
			return false, errors.New(e)
		}
	}
	if s_resp != nil && s_code == http.StatusOK {
		var resp_json Response
		um_err := json.Unmarshal([]byte(s_resp), &resp_json)
		if um_err != nil {
			um_msg := fmt.Sprintf("describe_table.IsTableStatus:"+
				"cannot unmarshal %s, err: %s\ncheck "+
				"table creation of %s manually",
				s_resp, um_err.Error(), tablename)
			return false, errors.New(um_msg)
		}
		return (resp_json.Table.TableStatus == status), nil
	}
	e := fmt.Sprintf("describe_table.IsTableStatus:does %s exist?", tablename)
	return false, errors.New(e)
}
Ejemplo n.º 2
0
// IsTableStatus will test the equality status of a table.
func IsTableStatus(tablename string, status string) (bool, error) {
	d := ep.Endpoint(Describe{TableName: tablename})
	if authreq.AUTH_VERSION != authreq.AUTH_V4 {
		e := fmt.Sprintf("describe_table.IsTableStatus " +
			"auth must be v4")
		return false, errors.New(e)
	}
	s_resp, s_code, s_err := authreq.RetryReq_V4(d, DESCTABLE_ENDPOINT)
	if s_err != nil {
		e := fmt.Sprintf("describe_table.IsTableStatus: "+
			"check on %s err %s",
			tablename, s_err.Error())
		// if not a 500 problem, don't retry
		if !ep.ServerErr(s_code) {
			return false, errors.New(e)
		}
	}
	if s_resp != "" && s_code == http.StatusOK {
		var resp_json Response
		um_err := json.Unmarshal([]byte(s_resp), &resp_json)
		if um_err != nil {
			um_msg := fmt.Sprintf("describe_table.IsTableStatus:"+
				"cannot unmarshal %s, err: %s\ncheck "+
				"table creation of %s manually",
				s_resp, um_err.Error(), tablename)
			return false, errors.New(um_msg)
		}
		return (resp_json.Table.TableStatus == status), nil
	}
	e := fmt.Sprintf("describe_table.IsTableStatus:does %s exist?", tablename)
	return false, errors.New(e)
}