Commit 3945a56b authored by Stefan Dähling's avatar Stefan Dähling
Browse files

added files for handling of modules

parent 5a8f5e11
Pipeline #305961 passed with stages
in 1 minute and 18 seconds
......@@ -49,12 +49,58 @@ import (
"errors"
"io/ioutil"
"net/http"
"strconv"
amsclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/ams/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/common/httpreply"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
)
// handleAMS handles requests to /api/ams/...
func (fe *Frontend) handleAMS(w http.ResponseWriter, r *http.Request,
respath []string) (resvalid bool, cmapErr error, httpErr error) {
resvalid = false
switch len(respath) {
case 4:
if respath[3] == "mas" {
resvalid = true
cmapErr, httpErr = fe.handleMAS(w, r)
}
case 5:
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if respath[3] == "mas" && cmapErr == nil {
resvalid = true
cmapErr, httpErr = fe.handlemasID(masID, w, r)
}
case 6:
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if respath[2] == "clonemap" && respath[3] == "mas" && cmapErr == nil {
if respath[5] == "agents" {
cmapErr, httpErr = fe.handleAgent(masID, w, r)
resvalid = true
}
}
case 7:
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if respath[2] == "clonemap" && respath[3] == "mas" && cmapErr == nil {
if respath[5] == "agents" {
var agentID int
agentID, cmapErr = strconv.Atoi(respath[6])
if cmapErr == nil {
cmapErr, httpErr = fe.handleAgentID(masID, agentID, w, r)
resvalid = true
}
}
}
default:
cmapErr = errors.New("Resource not found")
}
return
}
// handleMAS is the handler for requests to path /api/ams/mas
func (fe *Frontend) handleMAS(w http.ResponseWriter, r *http.Request) (cmapErr, httpErr error) {
if r.Method == "GET" {
......
/*
Copyright 2020 Institute for Automation of Complex Power Systems,
E.ON Energy Research Center, RWTH Aachen University
This project is licensed under either of
- Apache License, Version 2.0
- MIT License
at your option.
Apache License, Version 2.0:
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.
MIT License:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package frontend
import (
"errors"
"net/http"
)
// handleDF handles requests to /api/df/...
func (fe *Frontend) handleDF(w http.ResponseWriter, r *http.Request,
respath []string) (resvalid bool, cmapErr error, httpErr error) {
resvalid = false
switch len(respath) {
case 4:
default:
cmapErr = errors.New("Resource not found")
}
return
}
......@@ -47,7 +47,6 @@ package frontend
import (
"errors"
"net/http"
"strconv"
"strings"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/common/httpreply"
......@@ -63,11 +62,14 @@ func (fe *Frontend) handleAPI(w http.ResponseWriter, r *http.Request) {
if len(respath) > 2 {
switch respath[2] {
case "pf":
resvalid, cmapErr, httpErr = fe.handlePlatform(w, r, respath)
case "ams":
resvalid, cmapErr, httpErr = fe.handleAMS(w, r, respath)
// resvalid = true
case "df":
resvalid, cmapErr, httpErr = fe.handleDF(w, r, respath)
case "logger":
resvalid, cmapErr, httpErr = fe.handleLogging(w, r, respath)
default:
cmapErr = errors.New("Resource not found")
}
......@@ -85,51 +87,6 @@ func (fe *Frontend) handleAPI(w http.ResponseWriter, r *http.Request) {
}
}
// handleAMS handles requests to /api/ams/...
func (fe *Frontend) handleAMS(w http.ResponseWriter, r *http.Request,
respath []string) (resvalid bool, cmapErr error, httpErr error) {
resvalid = false
switch len(respath) {
case 4:
if respath[3] == "mas" {
resvalid = true
cmapErr, httpErr = fe.handleMAS(w, r)
}
case 5:
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if respath[3] == "mas" && cmapErr == nil {
resvalid = true
cmapErr, httpErr = fe.handlemasID(masID, w, r)
}
case 6:
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if respath[2] == "clonemap" && respath[3] == "mas" && cmapErr == nil {
if respath[5] == "agents" {
cmapErr, httpErr = fe.handleAgent(masID, w, r)
resvalid = true
}
}
case 7:
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if respath[2] == "clonemap" && respath[3] == "mas" && cmapErr == nil {
if respath[5] == "agents" {
var agentID int
agentID, cmapErr = strconv.Atoi(respath[6])
if cmapErr == nil {
cmapErr, httpErr = fe.handleAgentID(masID, agentID, w, r)
resvalid = true
}
}
}
default:
cmapErr = errors.New("Resource not found")
}
return
}
// listen opens a http server listening and serving request
func (fe *Frontend) listen() (err error) {
mux := http.NewServeMux()
......
/*
Copyright 2020 Institute for Automation of Complex Power Systems,
E.ON Energy Research Center, RWTH Aachen University
This project is licensed under either of
- Apache License, Version 2.0
- MIT License
at your option.
Apache License, Version 2.0:
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.
MIT License:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package frontend
import (
"errors"
"net/http"
)
// handleLogging handles requests to /api/logger/...
func (fe *Frontend) handleLogging(w http.ResponseWriter, r *http.Request,
respath []string) (resvalid bool, cmapErr error, httpErr error) {
resvalid = false
switch len(respath) {
case 4:
default:
cmapErr = errors.New("Resource not found")
}
return
}
/*
Copyright 2020 Institute for Automation of Complex Power Systems,
E.ON Energy Research Center, RWTH Aachen University
This project is licensed under either of
- Apache License, Version 2.0
- MIT License
at your option.
Apache License, Version 2.0:
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.
MIT License:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package frontend
import (
"errors"
"net/http"
)
// handlePlatform handles requests to /api/pf/...
func (fe *Frontend) handlePlatform(w http.ResponseWriter, r *http.Request,
respath []string) (resvalid bool, cmapErr error, httpErr error) {
resvalid = false
switch len(respath) {
case 4:
if respath[3] == "modules" {
resvalid = true
}
default:
cmapErr = errors.New("Resource not found")
}
return
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment