Exemplo n.º 1
0
// Executes ListTables assuming it were requested with the POST method.
func listTables_POST_Handler(w http.ResponseWriter, req *http.Request) {
	start := time.Now()
	pathElts := strings.Split(req.URL.Path, "/")
	if len(pathElts) != 2 {
		e := "list_tables_route.listTables_POST_Handler:cannot parse path. try /batch-get-item"
		log.Printf(e)
		http.Error(w, e, http.StatusBadRequest)
		return
	}

	bodybytes, read_err := ioutil.ReadAll(req.Body)
	req.Body.Close()
	if read_err != nil && read_err != io.EOF {
		e := fmt.Sprintf("list_tables_route.listTables_POST_Handler err reading req body: %s", read_err.Error())
		log.Printf(e)
		http.Error(w, e, http.StatusInternalServerError)
		return
	}

	var l list.List

	um_err := json.Unmarshal(bodybytes, &l)
	if um_err != nil {
		e := fmt.Sprintf("list_tables_route.listTables_POST_Handler unmarshal err on %s to Get %s", string(bodybytes), um_err.Error())
		log.Printf(e)
		http.Error(w, e, http.StatusInternalServerError)
		return
	}

	resp_body, code, resp_err := l.EndpointReq()

	if resp_err != nil {
		e := fmt.Sprintf("list_table_route.ListTable_POST_Handler:err %s",
			resp_err.Error())
		log.Printf(e)
		http.Error(w, e, http.StatusInternalServerError)
		return
	}

	if ep.HttpErr(code) {
		route_response.WriteError(w, code, "list_table_route.ListTable_POST_Handler", resp_body)
		return
	}

	mr_err := route_response.MakeRouteResponse(
		w,
		req,
		resp_body,
		code,
		start,
		list.ENDPOINT_NAME)
	if mr_err != nil {
		e := fmt.Sprintf("list_tables_route.listTables_POST_Handler %s",
			mr_err.Error())
		log.Printf(e)
		http.Error(w, e, http.StatusInternalServerError)
		return
	}
}
Exemplo n.º 2
0
func main() {
	// conf file must be read in before anything else, to initialize permissions etc
	conf_file.Read()
	if conf.Vals.Initialized == false {
		panic("the conf.Vals global conf struct has not been initialized")
	}

	// deal with iam, or not
	iam_ready_chan := make(chan bool)
	go conf_iam.GoIAM(iam_ready_chan)
	iam_ready := <-iam_ready_chan
	if iam_ready {
		fmt.Printf("using iam\n")
	} else {
		fmt.Printf("not using iam\n")
	}

	tn := "test-godynamo-livetest"
	tablename1 := tn
	fmt.Printf("tablename1: %s\n", tablename1)

	var code int
	var err error
	var body string

	// DELETE THE TABLE
	var del_table1 delete_table.Request
	del_table1.TableName = tablename1
	_, code, err = del_table1.EndpointReq()
	if err != nil || code != http.StatusOK {
		fmt.Printf("fail delete %d %v %s\n", code, err, body)
		os.Exit(1)
	}

	// List TABLES
	var l list.List
	l.ExclusiveStartTableName = ""
	l.Limit = 100
	lbody, lcode, lerr := l.EndpointReq()
	fmt.Printf("%v\n%v\n,%v\n", lbody, lcode, lerr)
}
Exemplo n.º 3
0
func main() {
	conf_file.Read()
	if conf.Vals.Initialized == false {
		panic("the conf.Vals global conf struct has not been initialized")
	}

	iam_ready_chan := make(chan bool)
	go conf_iam.GoIAM(iam_ready_chan)
	iam_ready := <-iam_ready_chan
	if iam_ready {
		fmt.Printf("using iam\n")
	} else {
		fmt.Printf("not using iam\n")
	}

	tablename1 := "test-godynamo-livetest"
	fmt.Printf("tablename: %s\n", tablename1)

	var code int
	var err error
	var body string

	// CREATE TABLE
	var create1 create.Create
	create1.TableName = tablename1
	create1.ProvisionedThroughput.ReadCapacityUnits = 100
	create1.ProvisionedThroughput.WriteCapacityUnits = 100
	create1.AttributeDefinitions = append(create1.AttributeDefinitions,
		ep.AttributeDefinition{AttributeName: "TheHashKey", AttributeType: ep.S})
	create1.AttributeDefinitions = append(create1.AttributeDefinitions,
		ep.AttributeDefinition{AttributeName: "TheRangeKey", AttributeType: ep.N})
	create1.AttributeDefinitions = append(create1.AttributeDefinitions,
		ep.AttributeDefinition{AttributeName: "AnAttrName", AttributeType: ep.S})
	create1.KeySchema = append(create1.KeySchema,
		ep.KeyDefinition{AttributeName: "TheHashKey", KeyType: ep.HASH})
	create1.KeySchema = append(create1.KeySchema,
		ep.KeyDefinition{AttributeName: "TheRangeKey", KeyType: ep.RANGE})
	lsi := ep.NewLocalSecondaryIndex()
	lsi.IndexName = "AnAttrIndex"
	lsi.Projection.ProjectionType = ep.KEYS_ONLY
	lsi.KeySchema = append(lsi.KeySchema,
		ep.KeyDefinition{AttributeName: "TheHashKey", KeyType: ep.HASH})
	lsi.KeySchema = append(lsi.KeySchema,
		ep.KeyDefinition{AttributeName: "AnAttrName", KeyType: ep.RANGE})
	create1.LocalSecondaryIndexes = append(create1.LocalSecondaryIndexes, *lsi)

	create_json, create_json_err := json.Marshal(create1)
	if create_json_err != nil {
		fmt.Printf("%v\n", create_json_err)
		os.Exit(1)
	}
	fmt.Printf("%s\n", string(create_json))
	fmt.Printf("%v\n", create1)

	cbody, ccode, cerr := create1.EndpointReq()
	fmt.Printf("%v\n%v\n,%v\n", cbody, ccode, cerr)

	var desc1 desc.Describe
	desc1.TableName = tablename1
	body, code, err = desc1.EndpointReq()
	fmt.Printf("desc:%v\n%v\n,%v\n", body, code, err)

	// WAIT FOR IT TO BE ACTIVE
	fmt.Printf("checking for ACTIVE status for table....\n")
	active, poll_err := desc.PollTableStatus(tablename1, desc.ACTIVE, 100)
	if poll_err != nil {
		fmt.Printf("poll1:%v\n", poll_err)
		os.Exit(1)
	}
	fmt.Printf("ACTIVE:%v\n", active)

	// List TABLES
	var l list.List
	l.ExclusiveStartTableName = ""
	l.Limit = 100
	lbody, lcode, lerr := l.EndpointReq()
	fmt.Printf("%v\n%v\n,%v\n", lbody, lcode, lerr)

}
Exemplo n.º 4
0
// Executes ListTables assuming it were requested with the GET method.
func listTables_GET_Handler(w http.ResponseWriter, req *http.Request) {
	start := time.Now()
	pathElts := strings.Split(req.URL.Path, "/")
	if len(pathElts) != 2 {
		e := "list_table_route.ListTablesHandler:cannot parse path." +
			"try /list?ExclusiveStartTableName=$T&Limit=$L"
		log.Printf(e)
		http.Error(w, e, http.StatusBadRequest)
		return
	}
	queryMap := make(map[string]string)
	for k, v := range req.URL.Query() {
		queryMap[strings.ToLower(k)] = v[0]
	}

	q_estn, estn_exists := queryMap[strings.ToLower(list.EXCLUSIVE_START_TABLE_NAME)]
	estn := ""
	if estn_exists {
		estn = q_estn
	}
	q_limit, limit_exists := queryMap[strings.ToLower(list.LIMIT)]
	limit := uint64(0)
	if limit_exists {
		limit_conv, conv_err := strconv.ParseUint(q_limit, 10, 64)
		if conv_err != nil {
			e := fmt.Sprintf("list_table_route.listTables_GET_Handler bad limit %s", q_limit)
			log.Printf(e)
		} else {
			limit = limit_conv
			if limit > DEFAULT_LIMIT {
				e := fmt.Sprintf("list_table_route.listTables_GET_Handler: high limit %d", limit_conv)
				log.Printf(e)
				limit = DEFAULT_LIMIT
			}
		}
	}

	l := list.List{
		Limit: limit,
		ExclusiveStartTableName: estn}

	resp_body, code, resp_err := l.EndpointReq()

	if resp_err != nil {
		e := fmt.Sprintf("list_table_route.ListTable_GET_Handler:err %s",
			resp_err.Error())
		log.Printf(e)
		http.Error(w, e, http.StatusInternalServerError)
		return
	}

	if ep.HttpErr(code) {
		route_response.WriteError(w, code, "list_table_route.ListTable_GET_Handler", resp_body)
		return
	}

	mr_err := route_response.MakeRouteResponse(
		w,
		req,
		resp_body,
		code,
		start,
		list.ENDPOINT_NAME)
	if mr_err != nil {
		e := fmt.Sprintf("list_table_route.listTable_GET_Handler %s", mr_err.Error())
		log.Printf(e)
	}
}
Exemplo n.º 5
0
func main() {
	// conf file must be read in before anything else, to initialize permissions etc
	conf_file.Read()
	if conf.Vals.Initialized == false {
		panic("the conf.Vals global conf struct has not been initialized")
	}

	// deal with iam, or not
	iam_ready_chan := make(chan bool)
	go conf_iam.GoIAM(iam_ready_chan)
	iam_ready := <-iam_ready_chan
	if iam_ready {
		fmt.Printf("using iam\n")
	} else {
		fmt.Printf("not using iam\n")
	}

	tn := "test-godynamo-livetest"
	tablename1 := tn
	fmt.Printf("tablename1: %s\n", tablename1)

	var code int
	var err error
	var body string

	var update_table1 update_table.Request
	update_table1.TableName = tablename1
	update_table1.ProvisionedThroughput.ReadCapacityUnits = 200
	update_table1.ProvisionedThroughput.WriteCapacityUnits = 200
	body, code, err = update_table1.EndpointReq()
	if err != nil || code != http.StatusOK {
		fmt.Printf("update table failed %d %v %s\n", code, err, body)
		os.Exit(1)
	}

	// WAIT FOR THE PROVISIONING TO FINISH
	fmt.Printf("checking for ACTIVE status for update....\n")
	active, poll_err := desc.PollTableStatus(tablename1,
		desc.ACTIVE, 100)
	if poll_err != nil {
		fmt.Printf("poll1:%v\n", poll_err)
		os.Exit(1)
	}
	fmt.Printf("ACTIVE:%v\n", active)

	var desc1 desc.Describe
	desc1.TableName = tablename1
	body, code, err = desc1.EndpointReq()
	fmt.Printf("desc:%v\n%v\n,%v\n", body, code, err)

	// WAIT FOR IT TO BE ACTIVE
	fmt.Printf("checking for ACTIVE status for table....\n")
	active, poll_err = desc.PollTableStatus(tablename1, desc.ACTIVE, 100)
	if poll_err != nil {
		fmt.Printf("poll1:%v\n", poll_err)
		os.Exit(1)
	}
	fmt.Printf("ACTIVE:%v\n", active)

	// List TABLES
	var l list.List
	l.ExclusiveStartTableName = ""
	l.Limit = 100
	lbody, lcode, lerr := l.EndpointReq()
	fmt.Printf("%v\n%v\n,%v\n", lbody, lcode, lerr)

}
Exemplo n.º 6
0
func main() {
	conf_file.Read()
	conf.Vals.ConfLock.RLock()
	if conf.Vals.Initialized == false {
		panic("the conf.Vals global conf struct has not been initialized")
	}

	// launch a background poller to keep conns to aws alive
	if conf.Vals.Network.DynamoDB.KeepAlive {
		log.Printf("launching background keepalive")
		go keepalive.KeepAlive([]string{})
	}

	// deal with iam, or not
	if conf.Vals.UseIAM {
		iam_ready_chan := make(chan bool)
		go conf_iam.GoIAM(iam_ready_chan)
		_ = <-iam_ready_chan
	}
	conf.Vals.ConfLock.RUnlock()

	tn := "test-godynamo-livetest"
	tablename1 := tn
	fmt.Printf("tablename1: %s\n", tablename1)

	var code int
	var err error
	var body []byte

	update_table1 := update_table.NewUpdateTable()
	update_table1.TableName = tablename1
	update_table1.ProvisionedThroughput.ReadCapacityUnits = 200
	update_table1.ProvisionedThroughput.WriteCapacityUnits = 200
	body, code, err = update_table1.EndpointReq()
	if err != nil || code != http.StatusOK {
		fmt.Printf("update table failed %d %v %s\n", code, err, string(body))
		os.Exit(1)
	}

	// WAIT FOR THE PROVISIONING TO FINISH
	fmt.Printf("checking for ACTIVE status for update....\n")
	active, poll_err := desc.PollTableStatus(tablename1,
		desc.ACTIVE, 100)
	if poll_err != nil {
		fmt.Printf("poll1:%v\n", poll_err)
		os.Exit(1)
	}
	fmt.Printf("ACTIVE:%v\n", active)

	var desc1 desc.DescribeTable
	desc1.TableName = tablename1
	body, code, err = desc1.EndpointReq()
	if err != nil || code != http.StatusOK {
		fmt.Printf("desc failed %d %v %s\n", code, err, string(body))
		os.Exit(1)
	}
	fmt.Printf("desc:%v\n%v\n,%v\n", string(body), code, err)

	// WAIT FOR IT TO BE ACTIVE
	fmt.Printf("checking for ACTIVE status for table....\n")
	active, poll_err = desc.PollTableStatus(tablename1, desc.ACTIVE, 100)
	if poll_err != nil {
		fmt.Printf("poll1:%v\n", poll_err)
		os.Exit(1)
	}
	fmt.Printf("ACTIVE:%v\n", active)

	// List TABLES
	var l list.List
	l.ExclusiveStartTableName = ""
	l.Limit = 100
	body, code, err = l.EndpointReq()
	if err != nil || code != http.StatusOK {
		fmt.Printf("list failed %d %v %s\n", code, err, string(body))
		os.Exit(1)
	}
	fmt.Printf("%v\n%v\n,%v\n", string(body), code, err)

}
Exemplo n.º 7
0
func main() {
	conf_file.Read()
	conf.Vals.ConfLock.RLock()
	if conf.Vals.Initialized == false {
		panic("the conf.Vals global conf struct has not been initialized")
	}

	// launch a background poller to keep conns to aws alive
	if conf.Vals.Network.DynamoDB.KeepAlive {
		log.Printf("launching background keepalive")
		go keepalive.KeepAlive([]string{})
	}

	// deal with iam, or not
	if conf.Vals.UseIAM {
		iam_ready_chan := make(chan bool)
		go conf_iam.GoIAM(iam_ready_chan)
		_ = <-iam_ready_chan
	}
	conf.Vals.ConfLock.RUnlock()

	tablename1 := "test-godynamo-livetest"
	fmt.Printf("tablename: %s\n", tablename1)

	var code int
	var err error
	var body []byte

	// CREATE TABLE
	create1 := create.NewCreateTable()
	create1.TableName = tablename1
	create1.ProvisionedThroughput.ReadCapacityUnits = 100
	create1.ProvisionedThroughput.WriteCapacityUnits = 100

	create1.AttributeDefinitions = append(create1.AttributeDefinitions,
		attributedefinition.AttributeDefinition{AttributeName: "TheHashKey", AttributeType: ep.S})
	create1.AttributeDefinitions = append(create1.AttributeDefinitions,
		attributedefinition.AttributeDefinition{AttributeName: "TheRangeKey", AttributeType: ep.N})
	create1.AttributeDefinitions = append(create1.AttributeDefinitions,
		attributedefinition.AttributeDefinition{AttributeName: "AnAttrName", AttributeType: ep.S})
	create1.KeySchema = append(create1.KeySchema,
		keydefinition.KeyDefinition{AttributeName: "TheHashKey", KeyType: ep.HASH})
	create1.KeySchema = append(create1.KeySchema,
		keydefinition.KeyDefinition{AttributeName: "TheRangeKey", KeyType: ep.RANGE})

	lsi := localsecondaryindex.NewLocalSecondaryIndex()
	lsi.IndexName = "AnAttrIndex"
	lsi.Projection.ProjectionType = aws_strings.KEYS_ONLY
	lsi.KeySchema = append(lsi.KeySchema,
		keydefinition.KeyDefinition{AttributeName: "TheHashKey", KeyType: ep.HASH})
	lsi.KeySchema = append(lsi.KeySchema,
		keydefinition.KeyDefinition{AttributeName: "AnAttrName", KeyType: ep.RANGE})
	create1.LocalSecondaryIndexes = append(create1.LocalSecondaryIndexes, *lsi)

	create_json, create_json_err := json.Marshal(create1)
	if create_json_err != nil {
		fmt.Printf("%v\n", create_json_err)
		os.Exit(1)
	}
	fmt.Printf("%s\n", string(create_json))
	fmt.Printf("%v\n", create1)

	body, code, err = create1.EndpointReq()
	fmt.Printf("%v\n%v\n,%v\n", string(body), code, err)
	if err != nil || code != http.StatusOK {
		fmt.Printf("create failed %d %v %s\n", code, err, string(body))
		os.Exit(1)
	}

	var desc1 desc.Describe
	desc1.TableName = tablename1
	body, code, err = desc1.EndpointReq()
	fmt.Printf("desc:%v\n%v\n,%v\n", string(body), code, err)
	if err != nil || code != http.StatusOK {
		fmt.Printf("desc failed %d %v %s\n", code, err, string(body))
		os.Exit(1)
	}

	// WAIT FOR IT TO BE ACTIVE
	fmt.Printf("checking for ACTIVE status for table....\n")
	active, poll_err := desc.PollTableStatus(tablename1, desc.ACTIVE, 100)
	if poll_err != nil {
		fmt.Printf("poll1:%v\n", poll_err)
		os.Exit(1)
	}
	fmt.Printf("ACTIVE:%v\n", active)

	// List TABLES
	var l list.List
	l.ExclusiveStartTableName = ""
	l.Limit = 100
	body, code, err = l.EndpointReq()
	if err != nil || code != http.StatusOK {
		fmt.Printf("list failed %d %v %s\n", code, err, string(body))
		os.Exit(1)
	}
	fmt.Printf("%v\n%v\n,%v\n", string(body), code, err)
}