Skip to content

Commit

Permalink
Fix plugin dependency (#117)
Browse files Browse the repository at this point in the history
* fix dependency handling

* add dependency

* fix lint

* Simplify plugin dependencies

* Improve test to ignore plugin order

* Add test case to detect more plugins than specified due to dependencies

* Use constants to handle plugin names

* Fix wrong comment

---------

Co-authored-by: Benjamin Weder <benjamin.weder@iaas.uni-stuttgart.de>
  • Loading branch information
LaviniaStiliadou and wederbn authored Nov 10, 2023
1 parent 863c85d commit d83bfbc
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 31 deletions.
10 changes: 10 additions & 0 deletions components/bpmn-q/modeler-component/editor/EditorConstants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// names of the supported plugins
export const pluginNames = {
QUANTME: "quantme",
OPENTOSCA: "opentosca",
PLANQK: "planqk",
QHANA: "qhana",
PATTERN: "pattern",
DATAFLOW: "dataflow",
};

// supported options to handle a transformed workflow
export const transformedWorkflowHandlers = {
NEW_TAB: "Open in new Tab",
Expand Down
20 changes: 10 additions & 10 deletions components/bpmn-q/modeler-component/editor/plugin/PluginHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import OpenTOSCAPlugin from "../../extensions/opentosca/OpenTOSCAPlugin";
import { getAllConfigs } from "./PluginConfigHandler";
import GeneralTab from "../config/GeneralTab";
import GitHubTab from "../../extensions/quantme/configTabs/GitHubTab";
import { pluginNames } from "../EditorConstants";

/**
* Handler for plugins of the modeler. Controls active plugins and the properties they define. Central access point to
Expand All @@ -18,7 +19,7 @@ import GitHubTab from "../../extensions/quantme/configTabs/GitHubTab";
const PLUGINS = [
{
plugin: QuantMEPlugin,
dependencies: ["DataFlowPlugin"],
dependencies: [pluginNames.OPENTOSCA],
},
{
plugin: DataFlowPlugin,
Expand All @@ -34,7 +35,7 @@ const PLUGINS = [
},
{
plugin: PatternPlugin,
dependencies: [],
dependencies: [pluginNames.QUANTME],
},
{
plugin: OpenTOSCAPlugin,
Expand All @@ -53,6 +54,7 @@ export function getActivePlugins() {

const loadPlugin = (plugin) => {
if (!activePlugins.includes(plugin.plugin)) {
activePlugins.push(plugin.plugin);
for (const dependency of plugin.dependencies) {
const dependencyPlugin = PLUGINS.find(
(p) => p.plugin.name === dependency
Expand All @@ -61,11 +63,9 @@ export function getActivePlugins() {
dependencyPlugin &&
!activePlugins.includes(dependencyPlugin.plugin)
) {
activePlugins.push(dependencyPlugin.plugin);
loadPlugin(dependencyPlugin);
}
}
activePlugins.push(plugin.plugin);
}
};

Expand All @@ -86,17 +86,17 @@ export function getActivePlugins() {

export function checkEnabledStatus(pluginName) {
switch (pluginName) {
case "dataflow":
case pluginNames.DATAFLOW:
return process.env.ENABLE_DATA_FLOW_PLUGIN !== "false";
case "planqk":
case pluginNames.PLANQK:
return process.env.ENABLE_PLANQK_PLUGIN !== "false";
case "qhana":
case pluginNames.QHANA:
return process.env.ENABLE_QHANA_PLUGIN !== "false";
case "quantme":
case pluginNames.QUANTME:
return process.env.ENABLE_QUANTME_PLUGIN !== "false";
case "pattern":
case pluginNames.PATTERN:
return process.env.ENABLE_PATTERN_PLUGIN !== "false";
case "opentosca":
case pluginNames.OPENTOSCA:
return process.env.ENABLE_OPENTOSCA_PLUGIN !== "false";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import defaultConfig from "./config";
import { getPluginConfig } from "../../../editor/plugin/PluginConfigHandler";
import { pluginNames } from "../../../editor/EditorConstants";

let config = {};

Expand All @@ -22,7 +23,7 @@ let config = {};
export function getOpenTOSCAEndpoint() {
if (config.opentoscaEndpoint === undefined) {
setOpenTOSCAEndpoint(
getPluginConfig("opentosca").opentoscaEndpoint ||
getPluginConfig(pluginNames.OPENTOSCA).opentoscaEndpoint ||
defaultConfig.opentoscaEndpoint
);
}
Expand All @@ -48,7 +49,7 @@ export function setOpenTOSCAEndpoint(opentoscaEndpoint) {
export function getWineryEndpoint() {
if (config.wineryEndpoint === undefined) {
setWineryEndpoint(
getPluginConfig("opentosca").wineryEndpoint ||
getPluginConfig(pluginNames.OPENTOSCA).wineryEndpoint ||
defaultConfig.wineryEndpoint
);
}
Expand Down
71 changes: 55 additions & 16 deletions components/bpmn-q/test/tests/editor/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getPluginConfig,
setPluginConfig,
} from "../../../modeler-component/editor/plugin/PluginConfigHandler";
import { pluginNames } from "../../../modeler-component/editor/EditorConstants";

describe("Test plugins", function () {
describe("Test PluginHandler", function () {
Expand All @@ -23,39 +24,77 @@ describe("Test plugins", function () {

it("Should find 4 active plugins", function () {
setPluginConfig([
{ name: "dataflow" },
{ name: "quantme" },
{ name: "opentosca" },
{ name: "planqk" },
{ name: pluginNames.DATAFLOW },
{ name: pluginNames.QUANTME },
{ name: pluginNames.OPENTOSCA },
{ name: pluginNames.PLANQK },
]);

const plugins = getActivePlugins();

expect(plugins.length).to.equal(4);
expect(plugins[0].name).to.equal("dataflow");
expect(plugins[1].name).to.equal("quantme");
expect(plugins[2].name).to.equal("opentosca");
expect(plugins[3].name).to.equal("planqk");
expect(
plugins.filter((plugin) => plugin.name === pluginNames.DATAFLOW)
.length
).to.equal(1);
expect(
plugins.filter((plugin) => plugin.name === pluginNames.OPENTOSCA)
.length
).to.equal(1);
expect(
plugins.filter((plugin) => plugin.name === pluginNames.QUANTME).length
).to.equal(1);
expect(
plugins.filter((plugin) => plugin.name === pluginNames.PLANQK).length
).to.equal(1);
});

it("Should find 4 active plugins due to dependencies", function () {
setPluginConfig([
{ name: pluginNames.DATAFLOW },
{ name: pluginNames.QUANTME },
{ name: pluginNames.PLANQK },
]);

const plugins = getActivePlugins();

expect(plugins.length).to.equal(4);
expect(
plugins.filter((plugin) => plugin.name === pluginNames.DATAFLOW)
.length
).to.equal(1);
expect(
plugins.filter((plugin) => plugin.name === pluginNames.QUANTME).length
).to.equal(1);
expect(
plugins.filter((plugin) => plugin.name === pluginNames.PLANQK).length
).to.equal(1);

// should be found due to dependency of quantme plugin
expect(
plugins.filter((plugin) => plugin.name === pluginNames.OPENTOSCA)
.length
).to.equal(1);
});
});

describe("Test getter for plugin attributes", function () {
it("Should get correct plugin entries for active plugins", function () {
setPluginConfig([
{ name: "dataflow" },
{ name: "quantme" },
{ name: "opentosca" },
{ name: "planqk" },
{ name: pluginNames.DATAFLOW },
{ name: pluginNames.QUANTME },
{ name: pluginNames.OPENTOSCA },
{ name: pluginNames.PLANQK },
]);

const modules = getAdditionalModules();
const extensions = getModdleExtension();

expect(modules.length).to.equal(4);
expect(extensions["dataflow"]).to.not.be.undefined;
expect(extensions["quantme"]).to.not.be.undefined;
expect(extensions["opentosca"]).to.not.be.undefined;
expect(extensions["planqk"]).to.not.be.undefined;
expect(extensions[pluginNames.DATAFLOW]).to.not.be.undefined;
expect(extensions[pluginNames.QUANTME]).to.not.be.undefined;
expect(extensions[pluginNames.OPENTOSCA]).to.not.be.undefined;
expect(extensions[pluginNames.PLANQK]).to.not.be.undefined;
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ const {
const config = require("../../../modeler-component/extensions/quantme/framework-config/config-manager");
const camundaConfig = require("../../../modeler-component/editor/config/EditorConfigManager");
const chai = require("chai");
const {
pluginNames,
} = require("../../../modeler-component/editor/EditorConstants");
describe("Test the QuantMETransformator of the QuantME extension.", function () {
describe("Transformation of QuantME extensions", function () {
it("should create a valid native workflow model after two transformations", async function () {
setPluginConfig([
{ name: "dataflow" },
{ name: pluginNames.DATAFLOW },
{
name: "quantme",
name: pluginNames.QUANTME,
config: {
githubRepositoryName: "QuantME-UseCases",
githubUsername: "UST-QuAntiL",
Expand Down Expand Up @@ -89,7 +92,10 @@ describe("Test the QuantMETransformator of the QuantME extension.", function ()
it("should fail due to missing QRMs", async function () {
resetQRMs();
// setConfig();
setPluginConfig([{ name: "dataflow" }, { name: "quantme" }]);
setPluginConfig([
{ name: pluginNames.DATAFLOW },
{ name: pluginNames.QUANTME },
]);
this.timeout(60000);

const result = await startQuantmeReplacementProcess(
Expand Down

0 comments on commit d83bfbc

Please sign in to comment.