Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kie-issues#1694: Apache KIE Extended Services extension issues #2802

Merged
merged 27 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cors-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.1",
"node-fetch": "^3.3.1"
"node-fetch": "^3.3.2"
},
"devDependencies": {
"@babel/core": "^7.16.0",
Expand Down
23 changes: 20 additions & 3 deletions packages/extended-services-vscode-extension/env/index.js
yesamer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,28 @@
* under the License.
*/

const { varsWithName, composeEnv } = require("@kie-tools-scripts/build-env");
const { getOrDefault, varsWithName, composeEnv } = require("@kie-tools-scripts/build-env");

module.exports = composeEnv([require("@kie-tools/root-env/env")], {
vars: varsWithName({}),
vars: varsWithName({
EXTENDED_SERVICES_JAVA__host: {
default: "0.0.0.0",
description:
"Quarkus HTTP Host. Configures the IP address or host to which a Quarkus application binds for incoming HTTP requests.",
},
EXTENDED_SERVICES_JAVA__port: {
default: "21345",
description:
"Quarkus HTTP Port. Configures the network port on which a Quarkus application accepts incoming HTTP requests.",
},
}),
get env() {
return {};
return {
extendedServicesJava: {
version: require("../package.json").version,
host: getOrDefault(this.vars.EXTENDED_SERVICES_JAVA__host),
port: getOrDefault(this.vars.EXTENDED_SERVICES_JAVA__port),
},
};
},
});
11 changes: 6 additions & 5 deletions packages/extended-services-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@vscode/test-web": "^0.0.30",
"@vscode/vsce": "^2.22.0",
"copy-webpack-plugin": "^11.0.0",
"node-fetch": "^3.3.1",
"node-fetch": "^3.3.2",
"rimraf": "^3.0.2",
"webpack": "^5.94.0",
"webpack-cli": "^4.10.0",
Expand Down Expand Up @@ -73,22 +73,23 @@
],
"configuration": {
"properties": {
"extendedServices.connectionHeartbeatIntervalinSecs": {
"default": 1,
"extendedServices.connectionHeartbeatIntervalInSecs": {
"default": 10,
"description": "Specifies the interval (in seconds) between each connection check.",
"format": "time",
"minimum": 10,
"order": 2,
"type": "integer"
},
"extendedServices.enableAutorun": {
"default": true,
"description": "Automatically run a local instance of the service.",
"description": "Automatically runs a local instance of the Extended Service.",
"order": 0,
"type": "boolean"
},
"extendedServices.extendedServicesURL": {
"default": "http://localhost:21345",
"description": "Specifies the Exnteded Services URL.",
"description": "Specifies the Extended Services URL.",
"format": "uri",
"order": 1,
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class Connection {
}

public stop(): void {
console.debug("[Extended Services Extension] Disconnecting from Extended Service");
if (this.timeout) {
this.fireDisconnectedEvent();
clearInterval(this.timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class LocalExtendedServices {
}

public stop(): void {
console.debug("[Extended Services Extension] Stopping local instance of Extended Service");
if (!this.serviceProcess) {
return;
}
Expand Down
14 changes: 8 additions & 6 deletions packages/extended-services-vscode-extension/src/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,28 @@ function createDMNDiagnostics(validationResponses: validationResponse.DMNValidat
});
}

export async function validateBPMN(serviceURL: URL, kieFile: kieFile.KieFile): Promise<vscode.Diagnostic[]> {
export async function validateBPMN(serviceURL: URL, bpmnFile: kieFile.KieFile): Promise<vscode.Diagnostic[]> {
try {
const validationResponses: validationResponse.BPMNValidationResponse[] = await validationRequests.validateBPMN(
serviceURL,
kieFile
bpmnFile
);
return createBPMNDiagnostics(validationResponses);
} catch (error) {
throw new Error("VALIDATE BPMN ERROR - " + error.message);
console.error(`An error occured while trying to validate DMN file: ${bpmnFile} with error: ${error.message}`);
throw new Error(`An error occured while trying to validate DMN file: ${bpmnFile} with error: ${error.message}`);
yesamer marked this conversation as resolved.
Show resolved Hide resolved
}
}

export async function validateDMN(serviceURL: URL, kieFile: kieFile.KieFile): Promise<vscode.Diagnostic[]> {
export async function validateDMN(serviceURL: URL, dmnFile: kieFile.KieFile): Promise<vscode.Diagnostic[]> {
try {
const validationResponses: validationResponse.DMNValidationResponse[] = await validationRequests.validateDMN(
serviceURL,
kieFile
dmnFile
);
return createDMNDiagnostics(validationResponses);
} catch (error) {
throw new Error("VALIDATE DMN ERROR - " + error.message);
console.error(`An error occured while trying to validate DMN file: ${dmnFile} with error: ${error.message}`);
throw new Error(`An error occured while trying to validate DMN file: ${dmnFile} with error: ${error.message}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

import * as vscode from "vscode";

export const enableAutoRunID: string = "extendedServices.enableAutorun";
export const connectionHeartbeatIntervalinSecsID: string = "extendedServices.connectionHeartbeatIntervalinSecs";
export const extendedServicesURLID: string = "extendedServices.extendedServicesURL";
export const enableAutoRunID = "extendedServices.enableAutorun";
export const connectionHeartbeatIntervalinSecsID = "extendedServices.connectionHeartbeatIntervalinSecs";
export const extendedServicesURLID = "extendedServices.extendedServicesURL";
const defaultExtendedServicesURL = "http://localhost:21345";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the env value instead of hardcoding. To do so, take a look into the build/defaultEnvJson.ts file in some packages (e.g. online-editor).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljmotta It's a good point. I would like to retrieve that default value directly from the configuration here https://github.com/apache/incubator-kie-tools/pull/2802/files#diff-153d43651b25ee3120020fae349c9e8ed99ccf90aa15995784702244decf9499R91 to avoid duplication and a single place for that property value, do you think is a valid alternative should I consider?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is important to have an option to configure the url of extended services, users report issues about it #2759

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljmotta In the examples I checked, the env variables are accessed using the useEnv() hook, but in this case, we are not managing a React app. How can I access to env variable from "plain" typescript?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yesamer That's true. the defaultEnvJson is used with the webpack transform + fetch, which isn't the case here. Now, you could use the webpack's EnvironmentPlugin to set env variables. The online-editor uses this approach to set some values inside the codebase. Take a look into the online-editor/webpack.config.ts, and search for EnvironmentPlugin. The WEBPACK_REPLACE__* values are the ones used in the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljmotta It should be done, there are two points to discuss:

  • I added EnvironmentPlugin in both extension-main and extension-browser. There's a way to define that once?
  • Currently, the host and the post are parametrized, In my opinion, it would be better to have the entire URL as a parameter. E.g. http protocol is hardcoded, what if the user provides its own instance using https?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yesamer

  • If you need to use in both, you can set the env variables in the commonConfig variable.
  • Good point. I'm not familiar on how the user set/use the Extended Services in the VS Code extension. Is it a embeded Extended Services or the user need to manually start the server? For the extended-services-java it will always use http. If the user wants to deploy it, the user will need to make the necessary adjustments to make it available through https.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljmotta


export class Configuration {
readonly enableAutoRun: boolean;
Expand All @@ -35,65 +36,31 @@ export class Configuration {
}
}

function fetchEnableAutoRun(): boolean {
const enableAutoRun = vscode.workspace.getConfiguration().get<boolean>(enableAutoRunID);
if (!enableAutoRun) {
throw new Error("Enable Auto Run configuration not found");
}
return enableAutoRun;
}

function fetchConnectionHeartbeatIntervalinSecs(): number {
const connectionHeartbeatIntervalinSecs = vscode.workspace
.getConfiguration()
.get<number>(connectionHeartbeatIntervalinSecsID);
if (!connectionHeartbeatIntervalinSecs) {
throw new Error("Connection Heartbeat Interval configuration not found");
}

return connectionHeartbeatIntervalinSecs;
}

function fetchExtendedServicesURL(): URL {
const extendedServicesURL = vscode.workspace.getConfiguration().get<string>(extendedServicesURLID);
if (!extendedServicesURL) {
throw new Error("URL configuration not found");
}

const extendedServicesURL = getConfigurationPropertyValue<string>(extendedServicesURLID, defaultExtendedServicesURL);
try {
return new URL(extendedServicesURL);
} catch (error) {
throw new Error("Invalid service URL:" + error.message);
throw new Error(`URL configuration ${extendedServicesURL} is invalid: ${error.message}`);
}
}

export function fetchConfiguration(): Configuration {
let errorMessages: string[] = [];
let enableAutoRun: any;
let connectionHeartbeatIntervalinSecs: any;
let extendedServicesURL: any;

try {
enableAutoRun = fetchEnableAutoRun();
} catch (error) {
errorMessages.push(error.message);
}

try {
connectionHeartbeatIntervalinSecs = fetchConnectionHeartbeatIntervalinSecs();
} catch (error) {
errorMessages.push(error.message);
const getConfigurationPropertyValue = <T>(property: string, defaultValue: T): T => {
const value = vscode.workspace.getConfiguration().get(property) as T;
if (value == null) {
console.warn(`Property: ${property} is missing, using the default: ${defaultValue}`);
value == defaultValue;
}
return value;
};

try {
extendedServicesURL = fetchExtendedServicesURL();
} catch (error) {
errorMessages.push(error.message);
}
export function fetchConfiguration(): Configuration {
const enableAutoRun = getConfigurationPropertyValue<boolean>(enableAutoRunID, true);
const connectionHeartbeatIntervalinSecs = getConfigurationPropertyValue<number>(
connectionHeartbeatIntervalinSecsID,
10
);
const extendedServicesURL = fetchExtendedServicesURL();

if (errorMessages.length < 0) {
throw new Error("CONFIGURATION ERROR - " + errorMessages.join(", "));
} else {
return new Configuration(enableAutoRun, connectionHeartbeatIntervalinSecs, extendedServicesURL);
}
return new Configuration(enableAutoRun, connectionHeartbeatIntervalinSecs, extendedServicesURL);
}
Loading
Loading