コード例 #1
0
ファイル: handler.go プロジェクト: vrosnet/kubernetes
// The user can set any or none of the following arguments in any order
// with any twice defined arguments being assigned the first value.
// If the value type for the argument is wrong the field will be assumed to be
// unassigned
// bools: historical, subcontainers, oom_events, creation_events, deletion_events
// ints: max_events, start_time (unix timestamp), end_time (unix timestamp)
// example r.URL: http://localhost:8080/api/v1.3/events?oom_events=true&historical=true&max_events=10
func getEventRequest(r *http.Request) (*events.Request, bool, error) {
	query := events.NewRequest()
	getHistoricalEvents := false

	urlMap := r.URL.Query()

	if val, ok := urlMap["historical"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			getHistoricalEvents = newBool
		}
	}
	if val, ok := urlMap["subcontainers"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			query.IncludeSubcontainers = newBool
		}
	}
	if val, ok := urlMap["oom_events"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			query.EventType[events.TypeOom] = newBool
		}
	}
	if val, ok := urlMap["creation_events"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			query.EventType[events.TypeContainerCreation] = newBool
		}
	}
	if val, ok := urlMap["deletion_events"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			query.EventType[events.TypeContainerDeletion] = newBool
		}
	}
	if val, ok := urlMap["max_events"]; ok {
		newInt, err := strconv.Atoi(val[0])
		if err == nil {
			query.MaxEventsReturned = int(newInt)
		}
	}
	if val, ok := urlMap["start_time"]; ok {
		newTime, err := time.Parse(time.RFC3339, val[0])
		if err == nil {
			query.StartTime = newTime
		}
	}
	if val, ok := urlMap["end_time"]; ok {
		newTime, err := time.Parse(time.RFC3339, val[0])
		if err == nil {
			query.EndTime = newTime
		}
	}

	glog.V(2).Infof(
		"%v was returned in api/handler.go:getEventRequest from the url rawQuery %v",
		query, r.URL.RawQuery)
	return query, getHistoricalEvents, nil
}
コード例 #2
0
func TestGetEventEmptyRequest(t *testing.T) {
	r := makeHTTPRequest("", t)
	expectedQuery := events.NewRequest()

	receivedQuery, stream, err := getEventRequest(r)

	if !reflect.DeepEqual(expectedQuery, receivedQuery) {
		t.Errorf("expected %#v but received %#v", expectedQuery, receivedQuery)
	}
	assert.False(t, stream)
	assert.Nil(t, err)
}
コード例 #3
0
func TestGetEventRequestDoubleArgument(t *testing.T) {
	r := makeHTTPRequest("http://localhost:8080/api/v1.3/events?stream=true&oom_events=true&oom_events=false", t)
	expectedQuery := events.NewRequest()
	expectedQuery.EventType = map[info.EventType]bool{
		info.EventOom: true,
	}

	receivedQuery, stream, err := getEventRequest(r)

	if !reflect.DeepEqual(expectedQuery, receivedQuery) {
		t.Errorf("expected %#v but received %#v", expectedQuery, receivedQuery)
	}
	assert.True(t, stream)
	assert.Nil(t, err)
}
コード例 #4
0
func TestGetEventRequestBasicRequest(t *testing.T) {
	r := makeHTTPRequest("http://localhost:8080/api/v1.3/events?oom_events=true&stream=false&max_events=20", t)
	expectedQuery := events.NewRequest()
	expectedQuery.EventType = map[info.EventType]bool{
		info.EventOom: true,
	}
	expectedQuery.MaxEventsReturned = 20

	receivedQuery, stream, err := getEventRequest(r)

	if !reflect.DeepEqual(expectedQuery, receivedQuery) {
		t.Errorf("expected %#v but received %#v", expectedQuery, receivedQuery)
	}
	assert.False(t, stream)
	assert.Nil(t, err)
}
コード例 #5
0
// The user can set any or none of the following arguments in any order
// with any twice defined arguments being assigned the first value.
// If the value type for the argument is wrong the field will be assumed to be
// unassigned
// bools: stream, subcontainers, oom_events, creation_events, deletion_events
// ints: max_events, start_time (unix timestamp), end_time (unix timestamp)
// example r.URL: http://localhost:8080/api/v1.3/events?oom_events=true&stream=true
func getEventRequest(r *http.Request) (*events.Request, bool, error) {
	query := events.NewRequest()
	stream := false

	urlMap := r.URL.Query()

	if val, ok := urlMap["stream"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			stream = newBool
		}
	}
	if val, ok := urlMap["subcontainers"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			query.IncludeSubcontainers = newBool
		}
	}
	if val, ok := urlMap["oom_events"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			query.EventType[info.EventOom] = newBool
		}
	}
	if val, ok := urlMap["oom_kill_events"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			query.EventType[info.EventOomKill] = newBool
		}
	}
	if val, ok := urlMap["creation_events"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			query.EventType[info.EventContainerCreation] = newBool
		}
	}
	if val, ok := urlMap["deletion_events"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			query.EventType[info.EventContainerDeletion] = newBool
		}
	}
	if val, ok := urlMap["max_events"]; ok {
		newInt, err := strconv.Atoi(val[0])
		if err == nil {
			query.MaxEventsReturned = int(newInt)
		}
	}
	if val, ok := urlMap["start_time"]; ok {
		newTime, err := time.Parse(time.RFC3339, val[0])
		if err == nil {
			query.StartTime = newTime
		}
	}
	if val, ok := urlMap["end_time"]; ok {
		newTime, err := time.Parse(time.RFC3339, val[0])
		if err == nil {
			query.EndTime = newTime
		}
	}

	return query, stream, nil
}
コード例 #6
0
ファイル: handler.go プロジェクト: kaushikanurag/cadvisor
// The user can set any or none of the following arguments in any order
// with any twice defined arguments being assigned the first value.
// If the value type for the argument is wrong the field will be assumed to be
// unassigned
// bools: stream, subcontainers, oom_events, creation_events, deletion_events
// ints: max_events, start_time (unix timestamp), end_time (unix timestamp)
// example r.URL: http://localhost:8080/api/v1.3/events?oom_events=true&stream=true
func getEventRequest(r *http.Request) (*events.Request, bool, error) {
	query := events.NewRequest()
	stream := false

	urlMap := r.URL.Query()

	if val, ok := urlMap["stream"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			stream = newBool
		}
	}
	if val, ok := urlMap["subcontainers"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			query.IncludeSubcontainers = newBool
		}
	}
	eventTypes := map[string]info.EventType{
		"oom_events":      info.EventOom,
		"oom_kill_events": info.EventOomKill,
		"creation_events": info.EventContainerCreation,
		"deletion_events": info.EventContainerDeletion,
	}
	allEventTypes := false
	if val, ok := urlMap["all_events"]; ok {
		newBool, err := strconv.ParseBool(val[0])
		if err == nil {
			allEventTypes = newBool
		}
	}
	for opt, eventType := range eventTypes {
		if allEventTypes {
			query.EventType[eventType] = true
		} else if val, ok := urlMap[opt]; ok {
			newBool, err := strconv.ParseBool(val[0])
			if err == nil {
				query.EventType[eventType] = newBool
			}
		}
	}
	if val, ok := urlMap["max_events"]; ok {
		newInt, err := strconv.Atoi(val[0])
		if err == nil {
			query.MaxEventsReturned = int(newInt)
		}
	}
	if val, ok := urlMap["start_time"]; ok {
		newTime, err := time.Parse(time.RFC3339, val[0])
		if err == nil {
			query.StartTime = newTime
		}
	}
	if val, ok := urlMap["end_time"]; ok {
		newTime, err := time.Parse(time.RFC3339, val[0])
		if err == nil {
			query.EndTime = newTime
		}
	}

	return query, stream, nil
}