Esempio n. 1
0
func NewApi(ng *graph.NodeGraph) OlympusApi {
	r := mux.NewRouter()
	v1Router := r.PathPrefix("/v1").Subrouter()

	restApi := OlympusApi{r, ng}

	v1Router.HandleFunc(ListNodes.Template(), restApi.ListNodes).Methods(ListNodes.Verb)
	v1Router.HandleFunc(ListBlocks.Template(), restApi.Blocks).Methods(ListBlocks.Verb)
	v1Router.HandleFunc(WriteBlock.Template(), restApi.WriteBlock).Methods(WriteBlock.Verb)
	v1Router.HandleFunc(RemoveNode.Template(), restApi.RemoveNode).Methods(RemoveNode.Verb)
	v1Router.HandleFunc(CreateNode.Template(), restApi.CreateNode).Methods(CreateNode.Verb)
	v1Router.HandleFunc(UpdateNode.Template(), restApi.UpdateNode).Methods(UpdateNode.Verb)
	v1Router.HandleFunc(ReadBlock.Template(), restApi.ReadBlock).Methods(ReadBlock.Verb)
	v1Router.HandleFunc(DownloadNode.Template(), restApi.DownloadFile).Methods(ReadBlock.Verb)

	blockServer := http.FileServer(http.Dir(env.EnvPath(env.DataPath)))
	r.Handle("/block/{blockId}", http.StripPrefix("/block/", blockServer))

	return restApi
}
Esempio n. 2
0
func initDb() (*graph.NodeGraph, error) {
	var handle *cayley.Handle
	var err error
	if !debug {
		dbPath := filepath.Join(env.EnvPath(env.DbPath), "db.dat")
		if !env.Exists(dbPath) {
			if err = cgraph.InitQuadStore("bolt", dbPath, nil); err != nil {
				return nil, err
			}
		}
		if handle, err = cayley.NewGraph("bolt", dbPath, nil); err != nil {
			return nil, err
		}
	} else {
		if handle, err = cayley.NewMemoryGraph(); err != nil {
			return nil, err
		}
	}

	return graph.NewGraph(handle)
}
Esempio n. 3
0
func TestInit() (*graph.NodeGraph, string) {
	if dir, err := ioutil.TempDir(os.TempDir(), ".olympus"); err != nil {
		panic(err)
	} else {
		os.Setenv("OLYMPUS_HOME", dir)
		if err = env.InitializeEnvironment(); err != nil {
			panic(err)
		}

		dbPath := filepath.Join(env.EnvPath(env.DbPath), "db.dat")
		if !env.Exists(dbPath) {
			cgraph.InitQuadStore("bolt", dbPath, nil)
			if handle, err := cayley.NewGraph("bolt", dbPath, nil); err != nil {
				panic(err)
			} else if ng, err := graph.NewGraph(handle); err != nil {
				panic(err)
			} else {
				return ng, dir
			}
		} else {
			return nil, ""
		}
	}
}
Esempio n. 4
0
func LocationOnDisk(hash string) string {
	return filepath.Join(env.EnvPath(env.DataPath), hash)
}