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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions packages/extended-services-vscode-extension/env/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/

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

module.exports = composeEnv([require("@kie-tools/root-env/env")], {
module.exports = composeEnv([require("@kie-tools/root-env/env"), require("@kie-tools/extended-services-java/env")], {
vars: varsWithName({}),
get env() {
return {};
Expand Down
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 @@ -28,13 +28,14 @@ export class Connection {
private timeout: NodeJS.Timeout | null = null;
private connected: boolean = false;

public async start(extendedServicesURL: URL, connectionHeartbeatIntervalinSecs: number): Promise<void> {
public async start(extendedServicesURL: URL, connectionHeartbeatIntervalInSecs: number): Promise<void> {
this.timeout = setInterval(async () => {
this.performHeartbeatCheck(extendedServicesURL);
}, connectionHeartbeatIntervalinSecs * 1000);
}, connectionHeartbeatIntervalInSecs * 1000);
}

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}`);
}
}

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,81 +19,48 @@

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";

export class Configuration {
readonly enableAutoRun: boolean;
readonly connectionHeartbeatIntervalinSecs: number;
readonly connectionHeartbeatIntervalInSecs: number;
readonly extendedServicesURL: URL;

constructor(enableAutoRun: boolean, connectionHeartbeatIntervalinSecs: number, extendedServicesURL: URL) {
constructor(enableAutoRun: boolean, connectionHeartbeatIntervalInSecs: number, extendedServicesURL: URL) {
this.enableAutoRun = enableAutoRun;
this.connectionHeartbeatIntervalinSecs = connectionHeartbeatIntervalinSecs;
this.connectionHeartbeatIntervalInSecs = connectionHeartbeatIntervalInSecs;
this.extendedServicesURL = extendedServicesURL;
}
}

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 defaultExtendedServicesURL = `http://${process.env.WEBPACK_REPLACE__extendedServicesUrlHost}:${process.env.WEBPACK_REPLACE__extendedServicesUrlPort}`;
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: T | null = 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export class ConfigurationWatcher {

private handleConfigurationChange(configurationChange: vscode.ConfigurationChangeEvent) {
const enableAutoRunChanged = configurationChange.affectsConfiguration(configuration.enableAutoRunID);
const connectionHeartbeatIntervalinSecsChanged = configurationChange.affectsConfiguration(
configuration.connectionHeartbeatIntervalinSecsID
const connectionHeartbeatIntervalInSecsChanged = configurationChange.affectsConfiguration(
configuration.connectionHeartbeatIntervalInSecsID
);
const extendedServicesURLChanged = configurationChange.affectsConfiguration(configuration.extendedServicesURLID);

if (enableAutoRunChanged || connectionHeartbeatIntervalinSecsChanged || extendedServicesURLChanged) {
if (enableAutoRunChanged || connectionHeartbeatIntervalInSecsChanged || extendedServicesURLChanged) {
this.fireConfigurationChangedEvent();
}
}
Expand Down
Loading
Loading