mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-26 05:19:05 +01:00
Add check to ccms getSubCluster routine
- Fixes nil pointer panic if topology requested from undef'd subcluster - rest.go: vscode LINT
This commit is contained in:
parent
9aa12c6edc
commit
fc133f328a
@ -723,13 +723,13 @@ func (api *RestApi) updateUser(rw http.ResponseWriter, r *http.Request) {
|
|||||||
delrole := r.FormValue("remove-role")
|
delrole := r.FormValue("remove-role")
|
||||||
|
|
||||||
// TODO: Handle anything but roles...
|
// TODO: Handle anything but roles...
|
||||||
if (newrole != "") {
|
if newrole != "" {
|
||||||
if err := api.Authentication.AddRole(r.Context(), mux.Vars(r)["id"], newrole); err != nil {
|
if err := api.Authentication.AddRole(r.Context(), mux.Vars(r)["id"], newrole); err != nil {
|
||||||
http.Error(rw, err.Error(), http.StatusUnprocessableEntity)
|
http.Error(rw, err.Error(), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rw.Write([]byte("Add Role Success"))
|
rw.Write([]byte("Add Role Success"))
|
||||||
} else if (delrole != "") {
|
} else if delrole != "" {
|
||||||
if err := api.Authentication.RemoveRole(r.Context(), mux.Vars(r)["id"], delrole); err != nil {
|
if err := api.Authentication.RemoveRole(r.Context(), mux.Vars(r)["id"], delrole); err != nil {
|
||||||
http.Error(rw, err.Error(), http.StatusUnprocessableEntity)
|
http.Error(rw, err.Error(), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
|
@ -260,9 +260,14 @@ func (ccms *CCMetricStore) buildQueries(
|
|||||||
scopes []schema.MetricScope) ([]ApiQuery, []schema.MetricScope, error) {
|
scopes []schema.MetricScope) ([]ApiQuery, []schema.MetricScope, error) {
|
||||||
|
|
||||||
queries := make([]ApiQuery, 0, len(metrics)*len(scopes)*len(job.Resources))
|
queries := make([]ApiQuery, 0, len(metrics)*len(scopes)*len(job.Resources))
|
||||||
topology := archive.GetSubCluster(job.Cluster, job.SubCluster).Topology
|
|
||||||
assignedScope := []schema.MetricScope{}
|
assignedScope := []schema.MetricScope{}
|
||||||
|
|
||||||
|
subcluster, scerr := archive.GetSubCluster(job.Cluster, job.SubCluster)
|
||||||
|
if scerr != nil {
|
||||||
|
return nil, nil, scerr
|
||||||
|
}
|
||||||
|
topology := subcluster.Topology
|
||||||
|
|
||||||
for _, metric := range metrics {
|
for _, metric := range metrics {
|
||||||
remoteName := ccms.toRemoteName(metric)
|
remoteName := ccms.toRemoteName(metric)
|
||||||
mc := archive.GetMetricConfig(job.Cluster, metric)
|
mc := archive.GetMetricConfig(job.Cluster, metric)
|
||||||
|
@ -78,18 +78,17 @@ func GetCluster(cluster string) *schema.Cluster {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSubCluster(cluster, subcluster string) *schema.SubCluster {
|
func GetSubCluster(cluster, subcluster string) (*schema.SubCluster, error) {
|
||||||
|
|
||||||
for _, c := range Clusters {
|
for _, c := range Clusters {
|
||||||
if c.Name == cluster {
|
if c.Name == cluster {
|
||||||
for _, p := range c.SubClusters {
|
for _, p := range c.SubClusters {
|
||||||
if p.Name == subcluster {
|
if p.Name == subcluster {
|
||||||
return p
|
return p, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil, fmt.Errorf("Subcluster '%v' not found for cluster '%v', or cluster '%v' not configured!", subcluster, cluster, cluster)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMetricConfig(cluster, metric string) *schema.MetricConfig {
|
func GetMetricConfig(cluster, metric string) *schema.MetricConfig {
|
||||||
|
Loading…
Reference in New Issue
Block a user