You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ne...@apache.org on 2022/09/26 16:33:46 UTC
[helix] branch master updated: Ensure request body is sent from helix-front to helix-rest
This is an automated email from the ASF dual-hosted git repository.
nealsun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/master by this push:
new 83e9bab30 Ensure request body is sent from helix-front to helix-rest
83e9bab30 is described below
commit 83e9bab30b36d9f0d67b0bbc62fd6f1536b04920
Author: Micah Stubbs <mi...@gmail.com>
AuthorDate: Mon Sep 26 09:33:41 2022 -0700
Ensure request body is sent from helix-front to helix-rest
Fix Angular http payload argument bug
Display helix-rest status codes in Helix UI
---
helix-front/server/controllers/helix.ts | 8 ++--
.../src/app/cluster/shared/cluster.service.ts | 9 ++--
.../configuration/shared/configuration.service.ts | 12 ++---
.../src/app/instance/shared/instance.service.ts | 2 +-
helix-front/src/app/shared/models/node.model.ts | 56 +++++++++++++++-------
5 files changed, 54 insertions(+), 33 deletions(-)
diff --git a/helix-front/server/controllers/helix.ts b/helix-front/server/controllers/helix.ts
index d5d9dbd44..4d70262af 100644
--- a/helix-front/server/controllers/helix.ts
+++ b/helix-front/server/controllers/helix.ts
@@ -41,6 +41,8 @@ export class HelixCtrl {
if (apiPrefix) {
const realUrl = apiPrefix + url.replace(`/${helixKey}`, '');
+ console.log(`helix-rest request url ${realUrl}`);
+
const options = {
url: realUrl,
json: req.body,
@@ -50,11 +52,11 @@ export class HelixCtrl {
};
request[method](options, (error, response, body) => {
if (error) {
- res.status(500).send(error);
+ res.status(response?.statusCode || 500).send(error);
} else if (body?.error) {
- res.status(500).send(body?.error);
+ res.status(response?.statusCode || 500).send(body?.error);
} else {
- res.status(response.statusCode).send(body);
+ res.status(response?.statusCode).send(body);
}
});
} else {
diff --git a/helix-front/src/app/cluster/shared/cluster.service.ts b/helix-front/src/app/cluster/shared/cluster.service.ts
index 547fde4ad..361c70095 100644
--- a/helix-front/src/app/cluster/shared/cluster.service.ts
+++ b/helix-front/src/app/cluster/shared/cluster.service.ts
@@ -42,12 +42,9 @@ export class ClusterService extends HelixService {
}
public enableMaintenanceMode(name: string, reason: string) {
- return this.post(
- `/clusters/${name}?command=enableMaintenanceMode`,
- JSON.stringify({
- reason,
- })
- );
+ return this.post(`/clusters/${name}?command=enableMaintenanceMode`, {
+ reason,
+ });
}
public disableMaintenanceMode(name: string) {
diff --git a/helix-front/src/app/configuration/shared/configuration.service.ts b/helix-front/src/app/configuration/shared/configuration.service.ts
index ea7bd8097..76395091e 100644
--- a/helix-front/src/app/configuration/shared/configuration.service.ts
+++ b/helix-front/src/app/configuration/shared/configuration.service.ts
@@ -12,14 +12,14 @@ export class ConfigurationService extends HelixService {
public setClusterConfig(name: string, config: Node) {
return this.post(
`/clusters/${name}/configs?command=update`,
- config.json(name)
+ JSON.parse(config.json(name))
);
}
public deleteClusterConfig(name: string, config: Node) {
return this.post(
`/clusters/${name}/configs?command=delete`,
- config.json(name)
+ JSON.parse(config.json(name))
);
}
@@ -36,7 +36,7 @@ export class ConfigurationService extends HelixService {
) {
return this.post(
`/clusters/${clusterName}/instances/${instanceName}/configs?command=update`,
- config.json(instanceName)
+ JSON.parse(config.json(instanceName))
);
}
@@ -47,7 +47,7 @@ export class ConfigurationService extends HelixService {
) {
return this.post(
`/clusters/${clusterName}/instances/${instanceName}/configs?command=delete`,
- config.json(instanceName)
+ JSON.parse(config.json(instanceName))
);
}
@@ -64,7 +64,7 @@ export class ConfigurationService extends HelixService {
) {
return this.post(
`/clusters/${clusterName}/resources/${resourceName}/configs?command=update`,
- config.json(resourceName)
+ JSON.parse(config.json(resourceName))
);
}
@@ -75,7 +75,7 @@ export class ConfigurationService extends HelixService {
) {
return this.post(
`/clusters/${clusterName}/resources/${resourceName}/configs?command=delete`,
- config.json(resourceName)
+ JSON.parse(config.json(resourceName))
);
}
}
diff --git a/helix-front/src/app/instance/shared/instance.service.ts b/helix-front/src/app/instance/shared/instance.service.ts
index 1d1668f40..187b4dea7 100644
--- a/helix-front/src/app/instance/shared/instance.service.ts
+++ b/helix-front/src/app/instance/shared/instance.service.ts
@@ -71,7 +71,7 @@ export class InstanceService extends HelixService {
return this.put(
`/clusters/${clusterName}/instances/${name}`,
- node.json(name)
+ JSON.parse(node.json(name))
);
}
diff --git a/helix-front/src/app/shared/models/node.model.ts b/helix-front/src/app/shared/models/node.model.ts
index d29460fd5..79e055f25 100644
--- a/helix-front/src/app/shared/models/node.model.ts
+++ b/helix-front/src/app/shared/models/node.model.ts
@@ -15,6 +15,13 @@ interface MapFieldObject {
value: SimpleFieldObject[];
}
+interface Payload {
+ id: string;
+ simpleFields?: any;
+ listFields?: any;
+ mapFields?: any;
+}
+
// This is a typical Helix Node definition
export class Node {
id: string;
@@ -77,30 +84,45 @@ export class Node {
}
public json(id: string): string {
- const obj = {
+ const obj: Payload = {
id,
- simpleFields: {},
- listFields: {},
- mapFields: {},
};
- _.forEach(this.simpleFields, (item: SimpleFieldObject) => {
- obj.simpleFields[item.name] = item.value;
- });
+ if (this?.simpleFields.length > 0) {
+ obj.simpleFields = {};
+ _.forEach(this.simpleFields, (item: SimpleFieldObject) => {
+ obj.simpleFields[item.name] = item.value;
+ });
+ }
- _.forEach(this.listFields, (item: ListFieldObject) => {
- obj.listFields[item.name] = [];
- _.forEach(item.value, (subItem: SimpleFieldObject) => {
- obj.listFields[item.name].push(subItem.value);
+ if (this?.listFields.length > 0) {
+ obj.listFields = {};
+ _.forEach(this.listFields, (item: ListFieldObject) => {
+ obj.listFields[item.name] = [];
+ _.forEach(item.value, (subItem: SimpleFieldObject) => {
+ obj.listFields[item.name].push(subItem.value);
+ });
});
- });
+ }
+
+ if (this?.mapFields.length > 0) {
+ obj.mapFields = {};
+ _.forEach(this.mapFields, (item: MapFieldObject) => {
+ obj.mapFields[item.name] = item.value ? {} : null;
+ _.forEach(item.value, (subItem: SimpleFieldObject) => {
+ // if the value is a string that contains all digits, parse it to a number
+ let parsedValue: string | number = subItem.value;
+ if (
+ typeof subItem.value === 'string' &&
+ /^\d+$/.test(subItem.value)
+ ) {
+ parsedValue = Number(subItem.value);
+ }
- _.forEach(this.mapFields, (item: MapFieldObject) => {
- obj.mapFields[item.name] = item.value ? {} : null;
- _.forEach(item.value, (subItem: SimpleFieldObject) => {
- obj.mapFields[item.name][subItem.name] = subItem.value;
+ obj.mapFields[item.name][subItem.name] = parsedValue;
+ });
});
- });
+ }
return JSON.stringify(obj);
}