You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2022/10/21 13:58:31 UTC

[brooklyn-ui] 22/24: support running a workflow from ui

This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git

commit 961e2ad96710f261c0eb9b59840a4a70da48e39d
Author: Alex Heneveld <al...@cloudsoft.io>
AuthorDate: Thu Oct 20 10:13:26 2022 +0100

    support running a workflow from ui
---
 .../inspect/activities/activities.controller.js    |  1 -
 .../app/views/main/inspect/inspect.controller.js   | 46 ++++++++++++++++++++++
 .../app/views/main/inspect/inspect.template.html   |  3 ++
 .../main/inspect/run-workflow-modal.template.html  | 33 ++++++++++++++++
 4 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/ui-modules/app-inspector/app/views/main/inspect/activities/activities.controller.js b/ui-modules/app-inspector/app/views/main/inspect/activities/activities.controller.js
index dbb487e3..b005142f 100644
--- a/ui-modules/app-inspector/app/views/main/inspect/activities/activities.controller.js
+++ b/ui-modules/app-inspector/app/views/main/inspect/activities/activities.controller.js
@@ -176,7 +176,6 @@ function ActivitiesController($scope, $state, $stateParams, $log, $timeout, enti
 }
 
 export function makeTaskStubFromWorkflowRecord(wf, wft) {
-    console.log("WFT", wft.status, wft);
     const result = {
         id: wft.taskId,
         displayName: wf.name + (wft.reasonForReplay ? " ("+wft.reasonForReplay+")" : ""),
diff --git a/ui-modules/app-inspector/app/views/main/inspect/inspect.controller.js b/ui-modules/app-inspector/app/views/main/inspect/inspect.controller.js
index 0248fb0e..04808be3 100644
--- a/ui-modules/app-inspector/app/views/main/inspect/inspect.controller.js
+++ b/ui-modules/app-inspector/app/views/main/inspect/inspect.controller.js
@@ -18,6 +18,7 @@
  */
 import template from "./inspect.template.html";
 import addChildModalTemplate from "./add-child-modal.template.html";
+import runWorkflowModalTemplate from "./run-workflow-modal.template.html";
 import confirmModalTemplate from "./confirm.modal.template.html";
 
 export const inspectState = {
@@ -75,6 +76,25 @@ export function inspectController($scope, $stateParams, $uibModal, brSnackbar, e
         })
     };
 
+    this.runWorkflow = function() {
+        $uibModal.open({
+            animation: true,
+            template: runWorkflowModalTemplate,
+            controller: ['$scope', '$http', '$uibModalInstance', 'applicationId', 'entityId', runWorkflowController],
+            size: 'lg',
+            resolve: {
+                applicationId: ()=>(applicationId),
+                entityId: ()=>(entityId),
+            }
+        }).result.then((closeData)=> {
+            $state.go('main.inspect.activites', {
+                applicationId: applicationId,
+                entityId: closeData.entityId,
+                activityId: closeData.id
+            });
+        })
+    };
+
     this.resetEntityProblems = function() {
         entityApi.resetEntityProblems(applicationId, entityId).catch((error)=> {
             brSnackbar.create('Cannot reset entity problems: the entity [' + entityId + '] or sensor [service.notUp.indicators] is undefined');
@@ -113,6 +133,7 @@ export function addChildController($scope, $http, $uibModalInstance, application
                 $scope.deploying = false;
                 $uibModalInstance.close(response.data);
             }, (error)=> {
+                console.log("Error adding child", error);
                 $scope.deploying = false;
                 if (error.data.hasOwnProperty('message')) {
                     $scope.errorMessage = error.data.message;
@@ -122,3 +143,28 @@ export function addChildController($scope, $http, $uibModalInstance, application
             });
     }
 }
+
+export function runWorkflowController($scope, $http, $uibModalInstance, applicationId, entityId) {
+    $scope.workflowYaml = 'steps:\n  - ';
+    $scope.errorMessage = null;
+    $scope.running = false;
+    $scope.runWorkflow = runWorkflow;
+
+    function runWorkflow() {
+        $scope.running = true;
+        $scope.errorMessage = null;
+        $http.post('/v1/applications/' + applicationId + '/entities/' + entityId + '/workflow?start=true&timeout=20ms', $scope.workflowYaml)
+            .then((response)=> {
+                $scope.running = false;
+                $uibModalInstance.close(response.data);
+            }, (error)=> {
+                console.log("Error running workflow", error);
+                $scope.running = false;
+                if (error.data.hasOwnProperty('message')) {
+                    $scope.errorMessage = error.data.message;
+                } else {
+                    $scope.errorMessage = 'Could not run workflow ... unknown error';
+                }
+            });
+    }
+}
diff --git a/ui-modules/app-inspector/app/views/main/inspect/inspect.template.html b/ui-modules/app-inspector/app/views/main/inspect/inspect.template.html
index 58126b41..aa348ffd 100644
--- a/ui-modules/app-inspector/app/views/main/inspect/inspect.template.html
+++ b/ui-modules/app-inspector/app/views/main/inspect/inspect.template.html
@@ -37,6 +37,9 @@
             <i class="fa fa-ellipsis-v" aria-hidden="true" ></i>
         </a>
         <ul uib-dropdown-menu class="entity-advanced-dropdown dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="single-button">
+            <li role="menuitem">
+                <a ng-click="vm.runWorkflow()">Run Workflow</a>
+            </li>
             <li role="menuitem">
                 <a ng-click="vm.addChildToEntity()">Add Child</a>
             </li>
diff --git a/ui-modules/app-inspector/app/views/main/inspect/run-workflow-modal.template.html b/ui-modules/app-inspector/app/views/main/inspect/run-workflow-modal.template.html
new file mode 100644
index 00000000..9bb3e654
--- /dev/null
+++ b/ui-modules/app-inspector/app/views/main/inspect/run-workflow-modal.template.html
@@ -0,0 +1,33 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<div class="modal-header">
+    <br-svg type="close" class="pull-right" ng-click="$dismiss('Close modal')"></br-svg>
+    <h3 class="modal-title">Run Workflow</h3>
+</div>
+
+<div>
+    <div ng-if="errorMessage" class="alert alert-danger" role="alert">
+        <strong>Error</strong> {{errorMessage}}
+    </div>
+    <br-yaml-editor value="workflowYaml" enable-auto-complete></br-yaml-editor>
+</div>
+
+<div class="modal-footer">
+    <button class="btn btn-success" ng-disabled="running" ng-click="runWorkflow()" type="button">Run</button>
+</div>