Beispiel #1
0
func buildRoute(name string, kvs kvstore.KVStore) (*route, error) {
	var r route

	r.Name = name

	routeConfig, err := config.ReadRouteConfig(name, kvs)
	if err != nil {
		return nil, err
	}

	if routeConfig == nil {
		return nil, makeRouteNotFoundError(name)
	}

	backends, err := buildBackends(kvs, routeConfig.Backends)
	if err != nil {
		return nil, err
	}

	r.URIRoot = routeConfig.URIRoot
	r.Backends = backends
	r.MultiBackendPluginName = routeConfig.MultiBackendAdapter

	if len(r.Backends) == 0 {
		return nil, errors.New("No backends configured for route")
	}

	if len(r.Backends) > 1 && r.MultiBackendPluginName == "" {
		return nil, errors.New("MultiRoute plugin name must be provided when multiple backends are configured")
	}

	for _, pluginName := range routeConfig.Plugins {
		factory, err := plugin.LookupWrapperFactoryCtx(pluginName)
		if err != nil {
			return nil, fmt.Errorf("No wrapper factory with name %s in registry", pluginName)
		}

		log.Debug("adding wrapper factory to factories")
		r.WrapperFactories = append(r.WrapperFactories, factory)

	}

	r.MsgProps = routeConfig.MsgProps

	return &r, nil
}
Beispiel #2
0
//GetDefinition retrieves a specific route definition
func (RouteDef) GetDefinition(kvs kvstore.KVStore, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
	routeName := resourceIDFromURI(req.RequestURI)

	routeConfig, err := config.ReadRouteConfig(routeName, kvs)
	if err != nil {
		resp.WriteHeader(http.StatusInternalServerError)
		return nil, err
	}

	if routeConfig == nil {
		resp.WriteHeader(http.StatusNotFound)
		return nil, errRouteNotFound
	}

	return routeConfig, err

}