Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #41 from lpabon/restapp
Browse files Browse the repository at this point in the history
Start of GlusterFS Application
  • Loading branch information
Luis Pabón committed Jul 2, 2015
2 parents 479c448 + 47611fe commit cb7eaf8
Show file tree
Hide file tree
Showing 29 changed files with 382 additions and 176 deletions.
2 changes: 1 addition & 1 deletion .travis-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# the tool requires that it be used only on one package when
# capturing the coverage
# This is why we need this little script here.
packages="./handlers ./plugins"
packages="./rest"
COVERFILE=packagecover.out

coverage()
Expand Down
5 changes: 5 additions & 0 deletions GLOCKFILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
github.com/codegangsta/negroni c7477ad8e330bef55bf1ebe300cf8aa67c492d1b
github.com/gorilla/context 215affda49addc4c8ef7e2534915df2c8c35c6cd
github.com/gorilla/mux 47e8f450ef38c857cdd922ec08862ca9d65a1c6d
github.com/lpabon/godbc 9577782540c1398b710ddae1b86268ba03a19b0c
golang.org/x/crypto 1e856cbfdf9bc25eefca75f83f25d55e35ae72e0
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions apps/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Location for applications for Heketi
package apps
78 changes: 78 additions & 0 deletions apps/glusterfs/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// Copyright (c) 2015 The heketi Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package glusterfs

import (
"fmt"
"github.com/heketi/heketi/rest"
"net/http"
)

type App struct {
hello string
}

func NewApp() *App {
return &App{}
}

// Interface rest.App
func (a *App) GetRoutes() rest.Routes {

return rest.Routes{

// HelloWorld
rest.Route{"Hello", "GET", "/hello", a.Hello},

// Cluster
rest.Route{"ClusterCreate", "POST", "/clusters", a.NotImplemented},
rest.Route{"ClusterInfo", "GET", "/clusters/{id:[A-Fa-f0-9]+}", a.NotImplemented},
rest.Route{"ClusterList", "GET", "/clusters", a.NotImplemented},
rest.Route{"ClusterDelete", "DELETE", "/clusters/{id:[A-Fa-f0-9]+}", a.NotImplemented},

// Node
rest.Route{"NodeAdd", "POST", "/nodes", a.NotImplemented},
rest.Route{"NodeInfo", "GET", "/nodes/{id:[A-Fa-f0-9]+}", a.NotImplemented},
rest.Route{"NodeDelete", "DELETE", "/nodes/{id:[A-Fa-f0-9]+}", a.NotImplemented},

// Devices
rest.Route{"DeviceAdd", "POST", "/devices", a.NotImplemented},
rest.Route{"DeviceInfo", "GET", "/devices/{id:[A-Fa-f0-9]+}", a.NotImplemented},
rest.Route{"DeviceDelete", "DELETE", "/devices/{id:[A-Fa-f0-9]+}", a.NotImplemented},

// Volume
rest.Route{"VolumeCreate", "POST", "/volumes", a.NotImplemented},
rest.Route{"VolumeInfo", "GET", "/volumes/{id:[A-Fa-f0-9]+}", a.NotImplemented},
rest.Route{"VolumeExpand", "POST", "/volumes/{id:[A-Fa-f0-9]+}/expand", a.NotImplemented},
rest.Route{"VolumeDelete", "DELETE", "/volumes/{id:[A-Fa-f0-9]+}", a.NotImplemented},
rest.Route{"VolumeList", "GET", "/volumes", a.NotImplemented},
}
}

func (a *App) Close() {

}

func (a *App) Hello(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=UTF-8")
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, "HelloWorld from GlusterFS Application")
}

func (a *App) NotImplemented(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Function not yet supported", http.StatusNotImplemented)
}
158 changes: 0 additions & 158 deletions handlers/asynchttp.go

This file was deleted.

23 changes: 10 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2014 The heketi Authors
// Copyright (c) 2015 The heketi Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -20,8 +20,8 @@ import (
"fmt"
"github.com/codegangsta/negroni"
"github.com/gorilla/mux"
"github.com/heketi/heketi/handlers"
"github.com/heketi/heketi/plugins"
"github.com/heketi/heketi/apps/glusterfs"
"github.com/heketi/heketi/rest"
"log"
"net/http"
"os"
Expand All @@ -30,20 +30,17 @@ import (

func main() {

// Get a mock node server
plugin := plugins.NewPlugin("glusterfs")
var app rest.Application

//
nodeserver := handlers.NewNodeServer(plugin)
volumeserver := handlers.NewVolumeServer(plugin)

r := volumeserver.VolumeRoutes()
r = append(r, nodeserver.NodeRoutes()...)
// Setup a new GlusterFS application
app = glusterfs.NewApp()

// Create a router and do not allow any routes
// unless defined.
router := mux.NewRouter().StrictSlash(true)
for _, route := range r {

// Register all routes from the App
for _, route := range app.GetRoutes() {

// Add routes from the table
router.
Expand All @@ -68,7 +65,7 @@ func main() {
select {
case <-signalch:
fmt.Printf("Shutting down...")
plugin.Close()
app.Close()
os.Exit(0)
}
}()
Expand Down
22 changes: 22 additions & 0 deletions rest/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Copyright (c) 2015 The heketi Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package rest

type Application interface {
GetRoutes() Routes
Close()
}

0 comments on commit cb7eaf8

Please sign in to comment.