python3 ./testing/dummy_testing_data.py
# now we can run the main app with the right arguments
go build .
- ./songmanager -port 8000 -binb_location="" -songs_location="./testing/songs/" -redis_location="localhost:6379" -container_name=""
+ sudo ./songmanager -port 8000 -binb_location="" -songs_location="./testing/songs/" -redis_location="localhost:6379" -container_name="sis50binb:latest"
test:
sudo docker stop redis || true
mainLogger.Println("Given container_name:", *paramContainerName)
- DBwrapper := dbhandling.NewDbWrapper(*paramRedisLocation, *paramSongsLocation)
+ DBwrapper := dbhandling.NewDbWrapper(*paramRedisLocation, *paramSongsLocation, *paramContainerName, *paramBinbLocation)
// Setting up the routing
mux.HandleFunc("DELETE /api/files/delete/{name}", DBwrapper.FilesDeleteByName)
mux.HandleFunc("PUT /api/files/rename/{name}/{newname}", DBwrapper.FilesRenameByName)
+ mux.HandleFunc("GET /rebootapp", DBwrapper.SongsRestart)
+
listenPort := ":" + strconv.Itoa(*paramPort)
fmt.Println("Starting server...")
RedisDb *redis.Client
Ctx context.Context
PathToSongs string
+ ImageName string
+ BinbLocation string
}
-func NewDbWrapper(redisLocation string, songsLocation string) DBWrapper {
+func NewDbWrapper(redisLocation string, songsLocation string, imageName string, binbLocation string) DBWrapper {
return DBWrapper {
redis.NewClient(&redis.Options{
Addr: redisLocation,
}),
context.Background(),
songsLocation,
+ imageName,
+ binbLocation,
}
}
)
func TestFilesGet(t *testing.T) {
- wrapper := dbhandling.NewDbWrapper("localhost:6379", "../../testing/songs")
+ wrapper := dbhandling.NewDbWrapper("localhost:6379", "../../testing/songs", "", "")
t.Run("FilesGet1", func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/api/files/get", &EmptyReader{})
func TestRoomsGet(t *testing.T) {
r := httptest.NewRequest("GET", "/api/rooms/get/all", &EmptyReader{})
- wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+ wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
// subtests
t.Run("RoomsGet1", func(t *testing.T) {
}
func TestRoomsGetByName(t *testing.T) {
- wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+ wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
// subtests
t.Run("RoomsGet1", func(t *testing.T) {
}
func TestRoomsAddByNameAndId(t *testing.T) {
- wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+ wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
t.Run("RoomsAddByNameAndId1", func(t *testing.T) {
r := httptest.NewRequest(http.MethodPut, "/api/rooms/add/hits", &testAddReader{})
}
func TestRoomsRemoveByNameAndId(t *testing.T) {
- wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+ wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
t.Run("RoomsRemoveByNameAndId1", func(t *testing.T) {
r := httptest.NewRequest(http.MethodPut, "/api/rooms/remove/hits", &testRemoveReader{})
}
func TestRoomsDeleteByName(t *testing.T) {
- wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+ wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
t.Run("RoomsDeleteByName-1", func(t *testing.T) {
r := httptest.NewRequest(http.MethodDelete, "/api/rooms/delete/rock", &EmptyReader{})
import (
"encoding/json"
"net/http"
+ "os/exec"
"strconv"
)
w.WriteHeader(http.StatusOK)
}
+
+/**
+ * Function that will restart the main server that this song manager manges
+ * so that rooms etc. will all get updated
+ **/
+func (dbw *DBWrapper) SongsRestart(w http.ResponseWriter, r *http.Request) {
+ // ok to make this work, we have to do it as follows:
+ // we have to stop the container, and get rid of it
+ // then re-run the image.
+
+ // for that we have to know the name of the image (ik it says container name in the thing)
+
+ // sudo docker ps -aqf ancestor=sis50binb:latest // GET THE ID
+ // sudo docker stop $ID
+ // sudo docker rm $ID
+ // ./launch.sh // this might always be present
+ out, err := exec.Command("/bin/sh", "-c", "sudo docker ps -aqf ancestor=sis50binb:latest").Output()
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ id := string(out)
+ err = exec.Command("/bin/sh", "-c", "sudo docker stop", id).Run()
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ err = exec.Command("/bin/sh", "-c", "sudo docker rm", id).Run()
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ err = exec.Command("/bin/sh", "-c", "sudo", dbw.BinbLocation + "./launch.sh").Run()
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ w.WriteHeader(http.StatusOK)
+
+}
func TestGetSongs(t *testing.T) {
// setup some fake requests
r := httptest.NewRequest("GET", "/api/songs/get", &EmptyReader{})
- wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+ wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
// subtests
t.Run("SongsGet1", func(t *testing.T) {
func TestSongsCreate(t *testing.T) {
// setup fake requests and readers
r := httptest.NewRequest("POST", "/api/songs/create", &CreateReader{})
- wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs")
+ wrapper := dbhandling.NewDbWrapper("localhost:6379", "./testing/songs", "", "")
t.Run("SongsCreate1", func(t *testing.T) {
recorder := httptest.NewRecorder()