/* * * 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. * */ InstallationWizard.AddNodes = { renderData: {}, render: function (addNodesRenderData) { /* Always update the object's renderData first. */ InstallationWizard.AddNodes.renderData = addNodesRenderData; /* Since this screen is completely statically rendered, nothing else * needs to be done here. */ if (globalYui.one("#yumMirrorSupportFormButtonId")) { if (globalYui.one("#yumMirrorSupportFormButtonId").get('checked')) { globalYui.one('#yumMirrorSupportFormFieldsId').setStyle('display', 'block'); } else { globalYui.one('#yumMirrorSupportFormFieldsId').setStyle('display', 'none'); globalYui.one("#yumRepoFilePathId").set('value', ''); } } globalYui.one("#addNodesCoreDivId").setStyle('display', 'block'); hideLoadingImg(); } }; if (globalYui.one("#yumMirrorSupportFormButtonId")) { globalYui.one("#yumMirrorSupportFormButtonId").on('click', function(e) { if (globalYui.one("#yumMirrorSupportFormButtonId").get('checked')) { globalYui.one('#yumMirrorSupportFormFieldsId').setStyle('display', 'block'); } else { globalYui.one('#yumMirrorSupportFormFieldsId').setStyle('display', 'none'); } }); } globalYui.one('#addNodesSubmitButtonId').on('click',function (e) { var focusId = ''; var message = ''; var errCount = 0; var userId = globalYui.Lang.trim(globalYui.one("#clusterDeployUserId").get('value')); if (userId == '') { errCount++; focusId = '#clusterDeployUserId'; message += 'SSH Username cannot be empty'; globalYui.one("#clusterDeployUserId").addClass('formInputError'); } else { globalYui.one("#clusterDeployUserId").removeClass('formInputError'); } var fileName = globalYui.one("#clusterDeployUserIdentityFileId").get('value'); if (fileName == '') { errCount++; if (focusId == '') { focusId = '#clusterDeployUserIdentityFileId'; } if (message != '') { message += '. '; } message += 'SSH Private Key File not specified'; globalYui.one("#clusterDeployUserIdentityFileId").addClass('formInputError'); } else { globalYui.one("#clusterDeployUserIdentityFileId").removeClass('formInputError'); } fileName = globalYui.one("#clusterHostsFileId").get('value'); if (fileName == '') { errCount++; if (focusId == '') { focusId = '#clusterHostsFileId'; } if (message != '') { message += '. '; } message += 'Hosts File not specified'; globalYui.one("#clusterHostsFileId").addClass('formInputError'); } else { globalYui.one("#clusterHostsFileId").removeClass('formInputError'); } if (globalYui.one("#yumMirrorSupportFormButtonId")) { if (globalYui.one("#yumMirrorSupportFormButtonId").get('checked')) { // local yum mirror support var repoFile = globalYui.Lang.trim(globalYui.one("#yumRepoFilePathId").get('value')); if (repoFile == '') { errCount++; if (focusId == '') { focusId = '#yumRepoFilePathId'; } if (message != '') { message += '. '; } message += 'Yum Repo file not specified'; globalYui.one("#yumRepoFilePathId").addClass('formInputError'); } } } if (errCount != 0) { globalYui.one(focusId).focus(); setFormStatus(message, true); return; } clearFormStatus(); showLoadingImg(); globalYui.log("About to upload files."); e.target.set('disabled', true); var addNodesFilesForm = globalYui.one("#addNodesFilesFormId"); addNodesFilesForm.set('action', '../php/frontend/addNodes.php?clusterName=' + InstallationWizard.AddNodes.renderData.clusterName); /* Set the target of the first form's upload to be a hidden iframe * on the page so as not to redirect to the PHP page we're POSTing * to. * * See http://www.openjs.com/articles/ajax/ajax_file_upload/ for * more on this. */ addNodesFilesForm.set('target', 'fileUploadTarget'); /* And then programmatically submit the first of the 2 forms. */ doPostUpload = true; addNodesFilesForm.submit(); globalYui.log("Files submitted to server."); e.target.set('disabled', false); }); var setupNodesJson = ""; var doPostUpload = false; // this flag is to prevent the #fileUploadTargetId iframe onload event from being invoked on browser back action globalYui.one("#fileUploadTargetId").on('load', function (e) { if (!doPostUpload) { return; } globalYui.log("File upload finished"); if (freshInstall == false) { // Do checks only in case of addNodesWizard var myIFrame = globalYui.one("#fileUploadTargetId"); var myIFrameContent = myIFrame.get('contentWindow.document.body'); var content = myIFrameContent.one('pre:first-child'); var responseText = content.get('text'); var responseJson = globalYui.JSON.parse(responseText); if (responseJson.result != 0) { // This means we hit an error if (responseJson.result == 3) { info = '
' + responseJson.error + '. ' + '' + 'Show me the duplicates' + '
'; setFormStatus(info, true); var infoPanel = createInformationalPanel("#informationalPanelContainerDivId", "Duplicate nodes"); infoPanel.set('centered', true); var infoPanelContent = ''; for (cluster in responseJson.hosts) { infoPanelContent += 'Cluster: ' + cluster + '