123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724 |
- /* Declarations of global data. */
- var fetchClusterServicesPoller;
- var clusterServices;
- // Storing globally for the sake of multiple screens in reconfigure
- var reconfigureServicesData = {};
- var confirmationDataPanelBodyContent = '';
- var confirmationDataPanel;
- var panelNoButton = {
- value: 'Cancel',
- action: function (e) {
- e.preventDefault();
- hideAndDestroyPanel();
- },
- section: 'footer'
- };
- var panelYesButton;
- // Only one service can be reconfigured at a time.
- var reconfigLevelOneYesButton;
- var reconfigLevelTwoNoButton;
- function showPanel() {
- showPanel(function() {});
- }
- function showPanel(postShowFn) {
- confirmationDataPanel.set('y', -400);
- confirmationDataPanel.set('x', (globalYui.one('body').get('region').width - confirmationDataPanel.get('width'))/2);
- confirmationDataPanel.show();
- var bb = confirmationDataPanel.get('boundingBox');
- bb.transition({
- duration: 0.5,
- top : '0px'
- }, postShowFn);
- }
- function hidePanel(postHideFn) {
- var bb = confirmationDataPanel.get('boundingBox');
- bb.transition({
- duration: 0.8,
- top : '-' + confirmationDataPanel.get('height') + 'px'
- }, postHideFn);
- }
- function hideAndDestroyPanel() {
- hidePanel(function() {
- confirmationDataPanel.hide();
- destroyInformationalPanel(confirmationDataPanel);
- });
- }
- function getTitleForReconfiguration(serviceName) {
- return 'Make configuration changes for ' + serviceName ;
- }
- function setupReconfigureFirstScreen(serviceName) {
- var panelTitle = getTitleForReconfiguration(serviceName);
- confirmationDataPanel.set( 'headerContent', panelTitle);
- confirmationDataPanel.set( 'bodyContent', confirmationDataPanelBodyContent);
- // Remove buttons from previous stage
- confirmationDataPanel.removeButton(0);
- confirmationDataPanel.removeButton(0);
- confirmationDataPanel.addButton( panelNoButton );
- confirmationDataPanel.addButton( reconfigLevelOneYesButton );
- }
- function setupReconfigureSecondScreen(serviceName) {
- var affectedServices = clusterServices[serviceName].dependencies;
- var dependents = clusterServices[serviceName].dependents;
- for (dep in dependents) {
- affectedServices.push(dependents[dep]);
- }
- var panelContent = 'Affected services:' + getAffectedDependenciesMarkup(affectedServices, serviceName, 'reconfigure');
- var panelTitle = 'Review changes to ' + serviceName + '\'s configuration';
- confirmationDataPanel.set( 'headerContent', panelTitle);
- confirmationDataPanel.set( 'bodyContent', panelContent);
- // Remove buttons from previous stage
- confirmationDataPanel.removeButton(0);
- confirmationDataPanel.removeButton(0);
- confirmationDataPanel.addButton( reconfigLevelTwoNoButton );
- confirmationDataPanel.addButton( panelYesButton );
- }
- // Clean up the affected-services list to only include appropriate installed long-running services
- function getAffectedDependenciesMarkup(affectedServices, serviceName, action) {
- var affectedDependenciesMarkup = '';
- var serviceDisplayName = clusterServices[serviceName].displayName;
- var deps = affectedServices;
- affectedServices = [];
- for (dep in deps) {
- var svc = deps[dep];
- if (clusterServices.hasOwnProperty(svc) && (clusterServices[svc].isEnabled == 1) && clusterServices[svc].attributes.runnable ) {
- affectedServices.push(svc);
- }
- }
- var dependencyMarkup = "";
- for (affectedSrvc in affectedServices) {
- if (clusterServices[affectedServices[affectedSrvc]].attributes.runnable) {
- dependencyMarkup += '<tr><td>' + clusterServices[affectedServices[affectedSrvc]].displayName + '</td><td>' + titleCase(clusterServices[affectedServices[affectedSrvc]].state) + '</td></tr>';
- }
- }
- if (dependencyMarkup != '') {
- // Add this service at the top of the list
- dependencyMarkup = '<table><thead><th>Service name</th><th>Current state</th></thead><tr><td>' + serviceDisplayName + '</td><td>' + titleCase(clusterServices[serviceName].state) + '</td></tr>' + dependencyMarkup + '</table>';
- affectedDependenciesMarkup += 'Including this service and all its recursive dependencies, the following is the list of services that will be affected by ' + action + ' of ' + serviceName + ' :' +
- '<br/>' +
- '<div id="manageServicesDisplayDepsOnAction">' +
- dependencyMarkup +
- '</div>';
- }
- return affectedDependenciesMarkup;
- }
- function setupStartServiceScreen(serviceName) {
- setupStartStopServiceScreen('start', serviceName);
- }
- function setupStopServiceScreen(serviceName) {
- setupStartStopServiceScreen('stop', serviceName);
- }
- function setupStartStopServiceScreen(action, serviceName) {
- var serviceDisplayName = clusterServices[serviceName].displayName;
- var affectedServices;
- var confirmationDataPanelTitle;
- if ( action == 'start') {
- confirmationDataPanelTitle = 'Starting ' + serviceDisplayName;
- confirmationDataPanelBodyContent = "We are now going to start " + serviceDisplayName + "..<br/><br/>";
- affectedServices = clusterServices[serviceName].dependencies;
- } else if (action == 'stop') {
- confirmationDataPanelTitle = 'Stopping ' + serviceDisplayName;
- confirmationDataPanelBodyContent = "We are now going to stop " + serviceDisplayName + "..<br/><br/>";
- affectedServices = clusterServices[serviceName].dependents;
- }
- confirmationDataPanelBodyContent += getAffectedDependenciesMarkup(affectedServices, serviceName, action);
- confirmationDataPanelBodyContent = '<div id="confirmationDataPanelBodyContent">' + confirmationDataPanelBodyContent + '</div>';
- var confirmationDataPanelWidth = 800;
- var confirmationDataPanelHeight = 400;
- confirmationDataPanel.set( 'headerContent', confirmationDataPanelTitle);
- confirmationDataPanel.set( 'bodyContent', confirmationDataPanelBodyContent);
- confirmationDataPanel.set( 'height', confirmationDataPanelHeight );
- confirmationDataPanel.set( 'width', confirmationDataPanelWidth );
- confirmationDataPanel.addButton( panelNoButton);
- confirmationDataPanel.addButton( panelYesButton );
- showPanel();
- }
- function setupStartAllServicesScreen() {
- setupStartStopAllServicesScreen('startAll');
- }
- function setupStopAllServicesScreen() {
- setupStartStopAllServicesScreen('stopAll');
- }
- function setupStartStopAllServicesScreen(action) {
- var confirmationDataPanelTitle;
- var confirmationDataPanelBodyContent;
- if ( action == 'startAll' ) {
- confirmationDataPanelTitle = 'Start All Services';
- confirmationDataPanelBodyContent = "We are now going to start all services in the cluster";
- } else if ( action == 'stopAll' ) {
- confirmationDataPanelTitle = 'Stop All Services';
- confirmationDataPanelBodyContent = "We are now going to stop all the services in the cluster";
- }
- var confirmationDataPanelWidth = 800;
- var confirmationDataPanelHeight = 400;
- confirmationDataPanel.set( 'headerContent', confirmationDataPanelTitle);
- confirmationDataPanel.set( 'bodyContent', confirmationDataPanelBodyContent);
- confirmationDataPanel.set( 'height', confirmationDataPanelHeight );
- confirmationDataPanel.set( 'width', confirmationDataPanelWidth );
- confirmationDataPanel.addButton( panelNoButton);
- confirmationDataPanel.addButton( panelYesButton );
- showPanel();
- }
- function setupReconfigureScreens(serviceName) {
- // TODO: Needed for others too?
- /* First, (temporarily) stop any further fetches. */
- fetchClusterServicesPoller.stop();
- reconfigLevelOneYesButton = {
- value: 'Submit',
- action: function (e) {
- e.preventDefault();
- hidePanel(function() {
- // Store the requestData and the html
- confirmationDataPanelBodyContent = confirmationDataPanel.get( 'bodyContent' );
- reconfigureServicesData = generateUserOpts();
- setupReconfigureSecondScreen(serviceName);
- showPanel();
- });
- },
- classNames: 'yo',
- section: 'footer'
- };
- reconfigLevelTwoNoButton = {
- value: 'Go back and re-edit',
- action: function (e) {
- e.preventDefault();
- hidePanel(function() {
- setupReconfigureFirstScreen(serviceName);
- showPanel();
- });
- },
- section: 'footer'
- };
- // Render first with a loading image and then get config items
- confirmationDataPanelBodyContent =
- "<img id=errorInfoPanelLoadingImgId class=loadingImg src=../images/loading.gif />";
- var confirmationDataPanelWidth = 1000;
- var confirmationDataPanelHeight = 500;
- var confirmationDataPanelTitle = getTitleForReconfiguration(serviceName);
- confirmationDataPanel.set( 'height', confirmationDataPanelHeight );
- confirmationDataPanel.set( 'width', confirmationDataPanelWidth );
- confirmationDataPanel.set( 'headerContent', confirmationDataPanelTitle);
- confirmationDataPanel.set( 'bodyContent', confirmationDataPanelBodyContent );
- showPanel();
- executeStage( '../php/frontend/fetchClusterServices.php?clusterName=' + clusterName +
- '&getConfigs=true&serviceName=' + serviceName, function (serviceConfigurationData) {
- var serviceConfigurationMarkup = constructDOM( serviceConfigurationData );
- if( globalYui.Lang.trim( serviceConfigurationMarkup).length == 0 ) {
- serviceConfigurationMarkup = '<p>Move along folks, nothing to see here...</p>';
- }
- else {
- /* Augment confirmationDataPanel with the relevant buttons only if there
- * is something of value to show.
- */
- confirmationDataPanel.addButton( panelNoButton );
- confirmationDataPanel.addButton( reconfigLevelOneYesButton );
- }
- /* XXX Note that this must be kept in-sync with the corresponding markup
- * on the InstallationWizard page.
- */
- confirmationDataPanelBodyContent =
- '<div id=formStatusDivId class=formStatusBar style="visibility:hidden">'+
- 'Placeholder' +
- '</div>' +
- '<br/>' +
- '<div id=configureClusterAdvancedCoreDivId>' +
- '<form id=configureClusterAdvancedFormId>' +
- '<fieldset id=configureClusterAdvancedFieldSetId>' +
- '<div id=configureClusterAdvancedDynamicRenderDivId>' +
- serviceConfigurationMarkup +
- '</div>' +
- '</fieldset>' +
- '</form>' +
- '</div>';
- confirmationDataPanelBodyContent = '<div id="confirmationDataPanelBodyContent">' + confirmationDataPanelBodyContent + '</div>';
- confirmationDataPanel.set( 'bodyContent', confirmationDataPanelBodyContent );
- });
- }
- function performServiceManagement( action, serviceName, confirmationDataPanel ) {
- /* First, (temporarily) stop any further fetches. */
- fetchClusterServicesPoller.stop();
- var manageServicesRequestData = {
- action: action,
- services: {}
- };
- if( action == "reconfigure" ) {
- manageServicesRequestData.services = reconfigureServicesData;
- }
- else {
- /* Need to explicitly set a key named for serviceName this way because it's
- * a variable - in the future, the value will be a filled-out array (for
- * now, we only support managing a single service at a time).
- */
- manageServicesRequestData.services[serviceName] = {};
- }
- globalYui.io( "../php/frontend/manageServices.php?clusterName=" + clusterName, {
- method: 'POST',
- data: globalYui.JSON.stringify(manageServicesRequestData),
- timeout: 10000,
- on: {
- success: function(x, o) {
- globalYui.log("RAW JSON DATA: " + o.responseText);
- var manageServicesResponseJson;
- try {
- manageServicesResponseJson = globalYui.JSON.parse(o.responseText);
- }
- catch (e) {
- alert("JSON Parse failed!");
- return;
- }
- globalYui.log(globalYui.Lang.dump(manageServicesResponseJson));
- /* Check that manageServicesResponseJson actually indicates success. */
- if( manageServicesResponseJson.result == 0 ) {
- /* Only on success should we destroy confirmationDataPanel - on
- * failure, we depend on the fact that there'll be errors shown
- * inside the panel that the user will want/need to interact with.
- */
- hideAndDestroyPanel();
- var manageServicesProgressStatusMessage = {
- success:
- '<p>' +
- 'Yabba Dabba Doo! Manage services ' +
- '<a href="javascript:void(null)" id=closeManageServicesProgressWidgetLinkId>' +
- 'even harder' +
- '</a>' +
- '?' +
- '</p>',
- failure:
- '<p>' +
- 'Scooby Doo, where are you? Perhaps in the ' +
- '<a href="javascript:void(null)" id=showManageServicesTxnLogsLinkId>Operation Logs</a>' +
- '?' +
- '</p>'
- };
- var manageServicesProgressPostCompletionFixup = {
- success: function( txnProgressWidget ) {
- /* Register a click-handler for the just-rendered
- * #closeManageServicesProgressWidgetLinkId.
- *
- * Don't worry about this being a double-registration - although
- * it looks that way, it's not, because (an identical, but that's
- * irrelevant, really) manageServicesProgressStatusMessage.success
- * is re-rendered afresh each time through, and thus this
- * click-handler must also be re-registered each time 'round.
- */
- globalYui.one("#closeManageServicesProgressWidgetLinkId").on( "click", function(e) {
- txnProgressWidget.hide();
- });
- /* Resume polling for information about the cluster's services. */
- fetchClusterServicesPoller.start();
- },
- failure: function( txnProgressWidget ) {
- /* <-------------------- REZXXX BEGIN -----------------------> */
- /* Create the panel that'll display our error info. */
- var errorInfoPanel =
- createInformationalPanel( '#informationalPanelContainerDivId', 'Operation Logs' );
- /* Prime the panel to start off showing our stock loading image. */
- var errorInfoPanelBodyContent =
- '<img id=errorInfoPanelLoadingImgId class=loadingImg src=../images/loading.gif />';
- /* Make the call to our backend to fetch the report for this txnId. */
- globalYui.io('../php/frontend/fetchTxnLogs.php?clusterName=' +
- txnProgressWidget.txnProgressContext.clusterName + '&txnId=' + txnProgressWidget.txnProgressContext.txnId, {
-
- timeout: 10000,
- on: {
- success: function (x,o) {
- globalYui.log("RAW JSON DATA: " + o.responseText);
- var errorInfoJson = null;
- // Process the JSON data returned from the server
- try {
- errorInfoJson = globalYui.JSON.parse(o.responseText);
- }
- catch (e) {
- alert("JSON Parse failed!");
- return;
- }
- /* TODO XXX Remove some of the noise from this to allow
- * for better corelation - for now, just dump a
- * pretty-printed version of the returned JSON.
- */
- errorInfoPanelBodyContent =
- '<pre>' +
- globalYui.JSON.stringify( errorInfoJson.logs, null, 4 ) +
- '</pre>';
- /* Update the contents of errorInfoPanel (which was, till
- * now, showing the loading image).
- */
- errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
- },
- failure: function (x,o) {
- alert("Async call failed!");
- }
- }
- });
- var firstTimeShowingErrorInfoPanel = true;
- /* Register a click-handler for #showManageServicesTxnLogsLinkId
- * to render the contents inside errorInfoPanel (and make it visible).
- */
- globalYui.one("#showManageServicesTxnLogsLinkId").on( "click", function(e) {
- errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
- errorInfoPanel.show();
- if( firstTimeShowingErrorInfoPanel ) {
- globalYui.one('#txnProgressStatusActionsDivId').setContent(
- '<a href="javascript:void(null)" id=closeManageServicesProgressWidgetLinkId>' +
- 'Close' +
- '</a>' );
- globalYui.one("#closeManageServicesProgressWidgetLinkId").on( "click", function(e) {
- txnProgressWidget.hide();
- });
- firstTimeShowingErrorInfoPanel = false;
- }
- });
- /* <--------------------- REZXXX END ------------------------> */
- /* Resume polling for information about the cluster's services. */
- /* TODO XXX Move this into the click handler for closing the widget after the first show of the panel... */
- fetchClusterServicesPoller.start();
- }
- };
- var manageServicesProgressWidget = new TxnProgressWidget
- ( manageServicesResponseJson, manageServicesProgressStatusMessage, manageServicesProgressPostCompletionFixup );
- /* And now that confirmationDataPanel is hidden, show manageServicesProgressWidget. */
- manageServicesProgressWidget.show();
- }
- else {
- /* No need to hide confirmationDataPanel here - there are errors
- * that need to be handled.
- */
- if (action == 'reconfigure') {
- hidePanel(function() {
- setupReconfigureFirstScreen(serviceName);
- showPanel( function() {
- handleConfigureServiceErrors( manageServicesResponseJson );
- });
- });
- } else {
- // Can't do anything for others
- alert('Got error during ' + action + ' : ' + globalYui.Lang.dump(manageServicesResponseJson));
- }
- }
- },
- failure: function(x, o) {
- alert("Async call failed!");
- }
- }
- });
- }
- function getServiceConfigurationMarkup( serviceConfigurationData ) {
- return serviceConfigurationMarkup;
- }
- function serviceManagementActionClickHandler( action, serviceName ) {
- // Reinit the global content
- confirmationDataPanelBodyContent = '';
- var confirmationDataPanelTitle = ''; // Set title later
- /* Create the panel that'll display our confirmation/data dialog. */
- confirmationDataPanel =
- createInformationalPanel( '#informationalPanelContainerDivId', confirmationDataPanelTitle );
- panelYesButton = {
- value: 'OK',
- action: function (e) {
- e.preventDefault();
- performServiceManagement( action, serviceName, confirmationDataPanel );
- },
- classNames: 'yo',
- section: 'footer'
- };
- if ( action == 'start') {
- setupStartServiceScreen(serviceName);
- } else if ( action == 'stop') {
- setupStopServiceScreen(serviceName);
- } else if( action == 'startAll' ) {
- setupStartAllServicesScreen();
- } else if( action == 'stopAll' ) {
- setupStopAllServicesScreen();
- } else if( action == 'reconfigure' ) {
- setupReconfigureScreens(serviceName);
- }
- }
- function deduceServiceManagementEntryCssClass( serviceInfo ) {
- var serviceManagementEntryCssClass = '';
- var serviceState = serviceInfo.state;
- if( serviceState.match(/^stop/i) || serviceState.match(/^fail/i) ) {
- serviceManagementEntryCssClass = "serviceManagementEntryStopped";
- }
- else if( serviceState.match(/^start/i) ) {
- serviceManagementEntryCssClass = "serviceManagementEntryStarted";
- }
- else if( serviceState.match(/^install/i) ) {
- serviceManagementEntryCssClass = "serviceManagementEntryInstalled";
- }
- else if( serviceState.match(/^uninstall/i) ) {
- serviceManagementEntryCssClass = "serviceManagementEntryUninstalled";
- }
- // globalYui.log( "Picking CSS class for" + serviceInfo.serviceName + ": " + serviceManagementEntryCssClass );
- return serviceManagementEntryCssClass;
- }
- function generateServiceManagementEntryMarkup( serviceName, serviceInfo ) {
-
- var generatedServiceManagementEntryMarkup = '';
- var serviceAttributes = serviceInfo.attributes;
- /* Only generate a Service Management entry for services that are:
- *
- * a) enabled
- * b) runnable
- * c) meant to be displayed
- */
- if( (serviceInfo.isEnabled == true) && !serviceAttributes.noDisplay ) {
- var serviceManagementEntryCssClass = deduceServiceManagementEntryCssClass( serviceInfo );
- generatedServiceManagementEntryMarkup +=
- '<li class="serviceManagementEntry '+ serviceManagementEntryCssClass + '">' +
- '<div>' +
- '<span class="serviceManagementEntryNameContainer">' +
- '<a href="javascript:void(null)" name="' + serviceName + '" class="serviceManagementEntryName">' +
- serviceInfo.displayName +
- '</a>' +
- '</span>' +
- '<div class="serviceManagementEntryStateContainer">' +
- titleCase(serviceInfo.state) +
- '</div>' +
- '<div class="serviceManagementEntryActionsContainer">';
- if( serviceAttributes.runnable ) {
- var serviceManagementEntryAnchorName = '';
- var serviceManagementEntryAnchorTitle = '';
- var serviceManagementEntryAnchorCssClasses = 'serviceManagementEntryAction btn ';
- var serviceManagementEntryIconCssClass = '';
- /* Already-started/stopped services shouldn't allow a start/stop operation on them. */
- if( serviceInfo.state == 'STOPPED' ) {
- serviceManagementEntryAnchorName = 'start';
- serviceManagementEntryAnchorTitle = 'Start';
- serviceManagementEntryAnchorCssClasses += 'serviceManagementEntryActionStart';
- serviceManagementEntryIconCssClass = 'iconic-play';
- }
- else if ( serviceInfo.state == 'STARTED' ) {
- serviceManagementEntryAnchorName = 'stop';
- serviceManagementEntryAnchorTitle = 'Stop';
- serviceManagementEntryAnchorCssClasses += 'serviceManagementEntryActionStop';
- serviceManagementEntryIconCssClass = 'iconic-stop';
- }
- generatedServiceManagementEntryMarkup +=
- '<a href="javascript:void(null)" name="' + serviceManagementEntryAnchorName + '" ' +
- 'title="' + serviceManagementEntryAnchorTitle + '" ' +
- 'class="' + serviceManagementEntryAnchorCssClasses + '"><i class="' + serviceManagementEntryIconCssClass + '"></i></a> ';
- }
- generatedServiceManagementEntryMarkup +=
- '<a href="javascript:void(null)" name="reconfigure" title="Reconfigure" ' +
- 'class="btn serviceManagementEntryAction serviceManagementEntryActionReconfigure"><i class="iconic-cog"></i></a>' +
- '</div>' +
- '</div>' +
- '</li>';
- }
- return generatedServiceManagementEntryMarkup;
- }
- // Do Not Remove --> We'll uncomment this section when the Service names link to something meaningful.
- //
- // /* Register click handlers for the service links themselves. */
- // globalYui.one('#serviceManagementListId').delegate('click', function (e) {
- // alert(this.getAttribute('name'));
- // }, 'li.serviceManagementEntry span.serviceManagementEntryNameContainer a.serviceManagementEntryName' );
- /* Register click handlers for the global-action buttons. */
- globalYui.one('#serviceManagementGlobalActionsDivId').delegate('click', function (e) {
- var action = this.getAttribute('name');
- serviceManagementActionClickHandler( action );
- }, 'button' );
- /* Register click handlers for the action links for each service. */
- globalYui.one('#serviceManagementListId').delegate('click', function (e) {
- var action = this.getAttribute('name');
- var serviceName = this.ancestor('li.serviceManagementEntry').
- one('span.serviceManagementEntryNameContainer a.serviceManagementEntryName').getAttribute('name');
- serviceManagementActionClickHandler( action, serviceName );
- }, 'li.serviceManagementEntry div.serviceManagementEntryActionsContainer a.serviceManagementEntryAction' );
- /* Main() */
- /* The clusterName variable is set in the Javascript scaffolding spit out by manageServices.php */
- var fetchClusterServicesPollerContext = {
- source: '../php/frontend/fetchClusterServices.php',
- schema: {
- metaFields: {
- services: 'response.services'
- }
- },
- request: '?clusterName=' + clusterName,
- /* TODO XXX Change this from 5 seconds to 1 minute. */
- pollInterval: 5000,
- maxFailedAttempts: 5
- };
- var fetchClusterServicesPollerResponseHandler = {
- success: function (e, pdp) {
- /* Clear the screen of the loading image (in case it's currently showing). */
- hideLoadingImg();
- /* The data from our backend. */
- clusterServices = e.response.meta.services;
- /* What we're here to render. */
- var serviceManagementMarkup = '';
- // Separate block for client-only software
- var clientOnlySoftwareMarkup = '';
- for (var serviceName in clusterServices) {
- var serviceInfo = clusterServices[serviceName];
- if (clusterServices.hasOwnProperty(serviceName) && !serviceInfo.attributes.runnable) {
- clientOnlySoftwareMarkup += generateServiceManagementEntryMarkup( serviceName, serviceInfo );
- }
- }
- if (clientOnlySoftwareMarkup != '') {
- serviceManagementMarkup += '<div class="serviceManagementGroup"> Client-only software: <br/>';
- serviceManagementMarkup += clientOnlySoftwareMarkup;
- serviceManagementMarkup += '</div>';
- }
- // Real services with server side components
- serviceManagementMarkup += '<div class="serviceManagementGroup"> Long running services: <br/><ul>';
- for (var serviceName in clusterServices) {
- var serviceInfo = clusterServices[serviceName];
- if (clusterServices.hasOwnProperty(serviceName) && serviceInfo.attributes.runnable) {
- serviceManagementMarkup += generateServiceManagementEntryMarkup( serviceName, serviceInfo );
- }
- }
- serviceManagementMarkup += '</ul></div>';
- /* Link the newly-generated serviceManagementMarkup into the DOM. */
- globalYui.one("#serviceManagementDynamicRenderDivId").setContent( serviceManagementMarkup );
- /* If serviceManagementMarkup is non-empty, unveil the contents of
- * #serviceManagementGlobalActionsDivId (which contains the StartAll
- * and StopAll buttons) as well.
- */
- if( globalYui.Lang.trim( serviceManagementMarkup ).length > 0 ) {
- globalYui.one("#serviceManagementGlobalActionsDivId").setStyle( 'display', 'block' );
- }
- },
- failure: function (e, pdp) {
- /* Clear the screen of the loading image (in case it's currently showing). */
- hideLoadingImg();
- alert('Failed to fetch cluster services!');
- }
- };
- fetchClusterServicesPoller = new PeriodicDataPoller
- ( fetchClusterServicesPollerContext, fetchClusterServicesPollerResponseHandler );
- /* Kick the polling loop off. */
- fetchClusterServicesPoller.start();
|