Skip to content

Commit

Permalink
Merge pull request #1793 from senthuran16/siddhi-extensions-installer…
Browse files Browse the repository at this point in the history
…-front-end-connection

Connect Siddhi Extensions Installer front end and back end
  • Loading branch information
sajithshn authored Feb 24, 2020
2 parents 3225bd9 + b288dbb commit e8cfb3d
Show file tree
Hide file tree
Showing 15 changed files with 739 additions and 344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,7 @@ div.consoleIcon {
}

.partial-extension-install-btn,
.extension-un-install-btn,
.extension-install-btn {
color: whitesmoke;
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
*/
define(['require', 'jquery', 'constants'],
function (require, $, Constants) {
define(['require', 'jquery', 'constants', 'alerts'],
function (require, $, Constants, alerts) {
var self = this;
var Utils = function () {
this.extensionData = getExtensionDetails();
};

var rest_client_constants = {
Expand All @@ -18,109 +17,23 @@ define(['require', 'jquery', 'constants'],
};

/**
* getting extension data from back end.
* @returns {Map|Map}
* Installs or un-installs an extension.
*
* @param extension Extension object.
* @param app Reference of the app.
* @param handleLoading Function which handles the 'loading' state of the installation.
* @param handleCallback Callback function after a successful installation.
* @param callerObject The object which calls this method.
* @param requestedActionText The requested action, i.e: either install or un-install
* @param callerScope Scope of the caller.
*/
function getExtensionDetails() {
return new Map(Object.entries({
"kafka": {
"extensionStatus": "NOT_INSTALLED",
"extensionInfo": {
"name": "kafka",
"version": "5.0.8-SNAPSHOT"
}
},
"redis": {
"extensionStatus": "NOT_INSTALLED",
"extensionInfo": {
"name": "redis",
"version": "3.1.2-SNAPSHOT"
},
"manuallyInstall": [
{
"name": "redis-clients",
"version": "2.3.0",
"download": {
"info": {
"description": "redis clients is like a one extension",
"install": "by using this way we can install redis-clients"
},
"autoDownloadable": false,
"url": "https://repo1.maven.org/maven2/org/apache/redis/redis_2.11/2.1.1/redis_2.11-2.1.1.jar"
},
"type": "BUNDLE",
"lookupRegex": "kafka-clients-(.+).jar"
},
{
"name": "redis-server",
"version": "2.3.0",
"download": {
"info": {
"description": "redis clients is like a one extension",
"install": "by using this way we can install redis-clients"
},
"autoDownloadable": false,
"url": "https://repo1.maven.org/maven2/org/apache/redis/redis_2.11/2.1.1/kafka_2.11-2.1.1.jar"
},
"type": "BUNDLE",
"lookupRegex": "kafka-server-(.+).jar"
}
]
},
"grpc": {
"extensionStatus": "NOT_INSTALLED",
"extensionInfo": {
"name": "grpc",
"version": "3.1.2-SNAPSHOT"
},
"manuallyInstall": [
{
"name": "grpc-clients",
"version": "2.3.0",
"download": {
"info": {
"description": "grpc clients is like a one extension",
"install": "by using this way we can install grpc-clients"
},
"autoDownloadable": false,
"url": "https://repo1.maven.org/maven2/org/apache/grpc/grpc_2.11/2.1.1/grpc_2.11-2.1.1.jar"
},
"type": "BUNDLE",
"lookupRegex": "grpc-clients-(.+).jar"
},
{
"name": "grpc-server",
"version": "2.3.0",
"download": {
"info": {
"description": "grpc server is like a one extension",
"install": "by using this way we can install grpc-server"
},
"autoDownloadable": false,
"url": "https://repo1.maven.org/maven2/org/apache/grpc/grpc_2.11/2.1.1/grpc_2.11-2.1.1.jar"
},
"type": "BUNDLE",
"lookupRegex": "grpc-server-(.+).jar"
}
]
},
"nats": {
"extensionStatus": "NOT_INSTALLED",
"extensionInfo": {
"name": "nats",
"version": "3.1.2-SNAPSHOT"
},
}
}));
}
/**
* provide the update details about the extension
* @param extension
* @param callbackUpdater
* @param key
* @param callback
*/
Utils.prototype.extensionUpdateThroughFile = function (extension,callbackUpdater) {
Utils.prototype.installOrUnInstallExtension = function (extension,
app,
handleLoading,
handleCallback,
callerObject,
requestedActionText,
callerScope) {
self.extensionInstallUninstallAlertModal = $(
"<div class='modal fade' id='extensionAlertModal' tabindex='-1' role='dialog'" +
" aria-tydden='true'>" +
Expand All @@ -138,14 +51,14 @@ define(['require', 'jquery', 'constants'],
"<div class='container-fluid'>" +
"<form class='form-horizontal' onsubmit='return false'>" +
"<div class='form-group'>" +
"<label for='configName' class='col-sm-9 file-dialog-label'>" +
"Are you sure to " + ((extension.extensionStatus.trim().toUpperCase() === Constants.EXTENSION_NOT_INSTALLED) ? 'install' : 'unInstall') + " " + extension.extensionInfo.name + " ?" +
"<label for='configName' class='col-sm-9 file-dialog-label'>" + "Are you sure you want to " +
requestedActionText.toLowerCase() + " <b>" + extension.extensionInfo.name + "</b>?" +
"</label>" +
"</div>" +
"<div class='form-group'>" +
"<div class='file-dialog-form-btn'>" +
"<button id='installUninstallId' type='button' class='btn btn-primary'>" + ((extension.extensionStatus.trim().toUpperCase() === Constants.EXTENSION_NOT_INSTALLED) ? 'install' : 'unInstall') +
"</button>" +
"<button id='installUninstallId' type='button' class='btn btn-primary'>" +
requestedActionText + "</button>" +
"<div class='divider'/>" +
"<button type='cancelButton' class='btn btn-default' data-dismiss='modal'>cancel</button>" +
"</div>" +
Expand All @@ -159,23 +72,35 @@ define(['require', 'jquery', 'constants'],

self.extensionInstallUninstallAlertModal.find("button").filter("#installUninstallId").click(function () {
self.extensionInstallUninstallAlertModal.modal('hide');
var updateData = {
"name": extension.extensionInfo.name,
"action": (extension.extensionStatus.trim().toUpperCase() === Constants.EXTENSION_NOT_INSTALLED)
? Constants.INSTALL : Constants.UNINSTALL
};
//this updateData goes to back end.
console.log(updateData.name + " " + updateData.action);
//this updatedExtension data should come from backend.
var updatedExtension = {
"extensionStatus": "INSTALLED",
"extensionInfo": {
"name": "kafka",
"version": "5.0.8-SNAPSHOT"
var action = requestedActionText;

// Wait until installation completes.
if (handleLoading) {
var actionStatus = action + 'ing';
actionStatus = actionStatus.charAt(0).toUpperCase() + actionStatus.substr(1).toLowerCase();
handleLoading(callerObject, extension, actionStatus, callerScope);
}

var serviceUrl = app.config.services.extensionsInstallation.endpoint;
var installUninstallUrl = serviceUrl + "/" + extension.extensionInfo.name + "/" + action.toLowerCase();
$.ajax({
type: "POST",
contentType: "json",
url: installUninstallUrl,
async: true,
success: function (response) {
handleCallback(extension, response.status, callerObject, response, callerScope);
app.utils.extensionStatusListener.reArrangeExtensions(extension, response.status);
alerts.info(`Extension was successfully ${action.toLowerCase()}ed. ` +
`Please restart the editor.`);
},
error: function (e) {
var message = `Unable to ${action.toLowerCase()} the extension. ` +
`Please check editor console for further information.`;
alerts.error(message);
throw message;
}
};
//call back function changes the front design based on the updated json data from back end
callbackUpdater(updatedExtension, true);
});
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ define(['app/main', 'jquery'],
},
deploymentConfigs: {
endpoint: window.location.protocol + "//" + window.location.host + '/editor/deploymentConfigs'
},
extensionsInstallation: {
endpoint: window.location.protocol + "//" + window.location.host + '/siddhi-extensions'
}
},
alerts: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ define(function () {
EXTENSION_INSTALLED: "INSTALLED",
EXTENSION_NOT_INSTALLED: "NOT_INSTALLED",
EXTENSION_PARTIALLY_INSTALLED: "PARTIALLY_INSTALLED",
EXTENSION_UNINSTALLED: "UNINSTALLED",
EXTENSION_NOT_UNINSTALLED: "NOT_UNINSTALLED",
EXTENSION_PARTIALLY_UNINSTALLED: "PARTIALLY_UNINSTALLED",
EXTENSION_INSTALLED_TEXT: "Installed",
EXTENSION_NOT_INSTALLED_TEXT: "Not-Installed",
EXTENSION_PARTIALLY_INSTALLED_TEXT: "Partially-Installed",
INSTALL: "Install",
UNINSTALL: "UnInstall"
};
Expand Down
Loading

0 comments on commit e8cfb3d

Please sign in to comment.