-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement Media Proxy registry. * Implement Connection registry. * Implement Bridge registry. * Implement Multipoint Group registry. * Implement basic business logic to control the lifecycle of Multpoint Groups. * Implement gRPC API server to interface with Media Proxies. * Implement collection of metrics received from Media Proxies. Signed-off-by: Konstantin Ilichev <[email protected]>
- Loading branch information
Showing
50 changed files
with
6,490 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* SPDX-FileCopyrightText: Copyright (c) 2024 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
package controlplane | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
|
||
"control-plane-agent/internal/model" | ||
"control-plane-agent/internal/registry" | ||
) | ||
|
||
func (a *API) ListBridges(w http.ResponseWriter, r *http.Request) { | ||
query := r.URL.Query() | ||
addStatus := query.Has("status") | ||
addConfig := query.Has("config") | ||
|
||
items, err := registry.BridgeRegistry.List(r.Context(), nil, addStatus, addConfig) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
|
||
resp := struct { | ||
Bridge []model.Bridge `json:"bridge"` | ||
}{ | ||
Bridge: items, | ||
} | ||
applyContentTypeHeaderJSON(w) | ||
json.NewEncoder(w).Encode(resp) | ||
} | ||
|
||
func (a *API) GetBridge(w http.ResponseWriter, r *http.Request) { | ||
id := mux.Vars(r)["id"] | ||
addConfig := r.URL.Query().Has("config") | ||
|
||
item, err := registry.BridgeRegistry.Get(r.Context(), id, addConfig) | ||
if errors.Is(err, registry.ErrResourceNotFound) { | ||
http.Error(w, err.Error(), http.StatusNotFound) | ||
return | ||
} | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
|
||
item.Id = "" // hide the id in JSON (omitempty) | ||
|
||
applyContentTypeHeaderJSON(w) | ||
json.NewEncoder(w).Encode(item) | ||
} | ||
|
||
func (a *API) AddBridge(w http.ResponseWriter, r *http.Request) { | ||
// DEBUG | ||
proxyId := r.URL.Query().Get("proxy") | ||
groupId := r.URL.Query().Get("group") | ||
// DEBUG | ||
|
||
bridge := model.Bridge{ | ||
ProxyId: proxyId, | ||
GroupId: groupId, | ||
Config: &model.BridgeConfig{}, | ||
Status: &model.ConnectionStatus{}, | ||
} | ||
|
||
id, err := registry.BridgeRegistry.Add(r.Context(), bridge) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
|
||
bridge = model.Bridge{Id: id} | ||
|
||
applyContentTypeHeaderJSON(w) | ||
json.NewEncoder(w).Encode(bridge) | ||
} | ||
|
||
func (a *API) DeleteBridge(w http.ResponseWriter, r *http.Request) { | ||
id := mux.Vars(r)["id"] | ||
|
||
err := registry.BridgeRegistry.Delete(r.Context(), id) | ||
if errors.Is(err, registry.ErrResourceNotFound) { | ||
http.Error(w, err.Error(), http.StatusNotFound) | ||
return | ||
} | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* SPDX-FileCopyrightText: Copyright (c) 2024 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
package controlplane | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
|
||
"control-plane-agent/internal/model" | ||
"control-plane-agent/internal/registry" | ||
) | ||
|
||
func (a *API) ListConnections(w http.ResponseWriter, r *http.Request) { | ||
query := r.URL.Query() | ||
addStatus := query.Has("status") | ||
addConfig := query.Has("config") | ||
|
||
items, err := registry.ConnRegistry.List(r.Context(), nil, addStatus, addConfig) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
|
||
resp := struct { | ||
Conn []model.Connection `json:"connection"` | ||
}{ | ||
Conn: items, | ||
} | ||
applyContentTypeHeaderJSON(w) | ||
json.NewEncoder(w).Encode(resp) | ||
} | ||
|
||
func (a *API) GetConnection(w http.ResponseWriter, r *http.Request) { | ||
id := mux.Vars(r)["id"] | ||
addConfig := r.URL.Query().Has("config") | ||
|
||
item, err := registry.ConnRegistry.Get(r.Context(), id, addConfig) | ||
if errors.Is(err, registry.ErrResourceNotFound) { | ||
http.Error(w, err.Error(), http.StatusNotFound) | ||
return | ||
} | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
|
||
item.Id = "" // hide the id in JSON (omitempty) | ||
|
||
applyContentTypeHeaderJSON(w) | ||
json.NewEncoder(w).Encode(item) | ||
} | ||
|
||
func (a *API) AddConnection(w http.ResponseWriter, r *http.Request) { | ||
|
||
conn := model.Connection{ | ||
Status: &model.ConnectionStatus{}, | ||
Config: &model.ConnectionConfig{ | ||
Conn: model.ConnectionST2110{}, | ||
// Payload: model.PayloadVideo{}, | ||
}, | ||
} | ||
|
||
id, err := registry.ConnRegistry.Add(r.Context(), conn) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
|
||
conn = model.Connection{Id: id} | ||
|
||
applyContentTypeHeaderJSON(w) | ||
json.NewEncoder(w).Encode(conn) | ||
} | ||
|
||
func (a *API) DeleteConnection(w http.ResponseWriter, r *http.Request) { | ||
id := mux.Vars(r)["id"] | ||
|
||
err := registry.ConnRegistry.Delete(r.Context(), id) | ||
if errors.Is(err, registry.ErrResourceNotFound) { | ||
http.Error(w, err.Error(), http.StatusNotFound) | ||
return | ||
} | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
} |
Oops, something went wrong.