Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Adds $applyAsync calls to angular based new jobs pages #28325

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { checkFindFileStructurePrivilege } from 'plugins/ml/privilege/check_priv
import { getMlNodeCount } from 'plugins/ml/ml_nodes_check/check_ml_nodes';
import { loadNewJobDefaults } from 'plugins/ml/jobs/new_job/utils/new_job_defaults';
import { loadIndexPatterns } from '../util/index_utils';
import { initPromise } from 'plugins/ml/util/promise';
import { FileDataVisualizerPage } from './file_datavisualizer';

import uiRoutes from 'ui/routes';
Expand All @@ -35,7 +34,6 @@ uiRoutes
indexPatterns: loadIndexPatterns,
mlNodeCount: getMlNodeCount,
loadNewJobDefaults,
initPromise: initPromise(true)
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
import { mlJobService } from 'plugins/ml/services/job_service';
import { mlMessageBarService } from 'plugins/ml/components/messagebar/messagebar_service';
import { ml } from 'plugins/ml/services/ml_api_service';
import { initPromise } from 'plugins/ml/util/promise';

uiRoutes
.when('/jobs/new_job/advanced', {
Expand All @@ -52,7 +51,6 @@ uiRoutes
savedSearch: loadCurrentSavedSearch,
checkMlNodesAvailable,
loadNewJobDefaults,
initPromise: initPromise(true)
}
})
.when('/jobs/new_job/advanced/:jobId', {
Expand All @@ -66,7 +64,6 @@ uiRoutes
savedSearch: loadCurrentSavedSearch,
checkMlNodesAvailable,
loadNewJobDefaults,
initPromise: initPromise(true)
}
});

Expand Down Expand Up @@ -389,6 +386,9 @@ module.controller('MlNewJob',
loadFields()
.catch(() => {
// No need to do anything here as loadFields handles the displaying of any errors.
})
.then(() => {
$scope.$applyAsync();
});
};

Expand Down Expand Up @@ -826,6 +826,9 @@ module.controller('MlNewJob',
}
);
$scope.ui.cardinalityValidator.status = STATUS.FAILED;
})
.then(() => {
$scope.$applyAsync();
});
}

Expand Down Expand Up @@ -1122,6 +1125,9 @@ module.controller('MlNewJob',
getCustomUrlSelection();
getCategorizationFilterSelection();
$scope.ui.jsonText = angular.toJson($scope.job, true);
setTimeout(() => {
$scope.$applyAsync();
}, 0);
}

// add new custom URL
Expand Down Expand Up @@ -1389,11 +1395,15 @@ module.controller('MlNewJob',
})
.catch(function (resp) {
$scope.ui.dataPreview = angular.toJson(resp, true);
})
.then(() => {
$scope.$applyAsync();
});
} else {
$scope.ui.dataPreview = i18n('xpack.ml.newJob.advanced.dataPreview.datafeedDoesNotExistLabel', {
defaultMessage: 'Datafeed does not exist'
});
$scope.$applyAsync();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ module.directive('mlBucketSpanEstimator', function (i18n) {
console.log('Bucket span could not be estimated', error);
$scope.ui.bucketSpanEstimator.status = STATUS.FAILED;
$scope.ui.bucketSpanEstimator.message = 'Bucket span could not be estimated';
$scope.$applyAsync();
};

$scope.guessBucketSpan = function () {
$scope.ui.bucketSpanEstimator.status = STATUS.RUNNING;
$scope.ui.bucketSpanEstimator.message = '';
$scope.$applyAsync();

// we need to create a request object here because $scope.formConfig
// includes objects with methods which might break the required
Expand Down Expand Up @@ -91,6 +93,7 @@ module.directive('mlBucketSpanEstimator', function (i18n) {
if (notify && typeof $scope.bucketSpanFieldChange === 'function') {
$scope.bucketSpanFieldChange();
}
$scope.$applyAsync();
})
.catch(errorHandler);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ module.directive('mlEnableModelPlotCheckbox', function (i18n) {
$scope.ui.showAdvanced = true;
}
})
.catch(errorHandler);
.catch(errorHandler)
.then(() => {
$scope.$applyAsync();
});
}

// Re-validate cardinality for updated fields/splitField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ module.directive('mlPostSaveOptions', function (Private, i18n) {
};

$scope.apply = function () {
postSaveService.apply($scope.jobId, $scope.runInRealtime, $scope.createWatch, i18n);
postSaveService.apply($scope.jobId, $scope.runInRealtime, $scope.createWatch, i18n)
.catch()
.then(() => {
$scope.$applyAsync();
});
};
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class PostSaveService {
const datafeedId = mlJobService.getDatafeedId(jobId);

mlJobService.openJob(jobId)
.finally(() => {
.catch()
.then(() => {
mlJobService.startDatafeed(datafeedId, jobId, 0, undefined)
.then(() => {
this.status.realtimeJob = this.STATUS.SAVED;
Expand All @@ -56,14 +57,24 @@ class PostSaveService {
}

apply(jobId, runInRealtime, createWatch, i18n) {
if (runInRealtime) {
this.startRealtimeJob(jobId, i18n)
.then(() => {
if (createWatch) {
mlCreateWatchService.createNewWatch(jobId);
}
});
}
return new Promise((resolve) => {
if (runInRealtime) {
this.startRealtimeJob(jobId, i18n)
.then(() => {
if (createWatch) {
mlCreateWatchService.createNewWatch(jobId)
.catch()
.then(() => {
resolve();
});
} else {
resolve();
}
});
} else {
resolve();
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ module.directive('mlCreateWatch', function () {
}

// load elasticsearch settings to see if email has been configured
ml.getNotificationSettings().then((resp) => {
if (_.has(resp, 'defaults.xpack.notification.email')) {
$scope.ui.emailEnabled = true;
}
});
ml.getNotificationSettings()
.then((resp) => {
if (_.has(resp, 'defaults.xpack.notification.email')) {
$scope.ui.emailEnabled = true;
$scope.$applyAsync();
}
});

// check to see whether a watch for this job has already been created.
// display a warning if it has.
Expand All @@ -62,6 +64,9 @@ module.directive('mlCreateWatch', function () {
})
.catch(() => {
$scope.ui.watchAlreadyExists = false;
})
.then(() => {
$scope.$applyAsync();
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { preLoadJob } from 'plugins/ml/jobs/new_job/simple/components/utils/prep
import { MultiMetricJobServiceProvider } from './create_job_service';
import { FullTimeRangeSelectorServiceProvider } from 'plugins/ml/components/full_time_range_selector/full_time_range_selector_service';
import { mlMessageBarService } from 'plugins/ml/components/messagebar/messagebar_service';
import { initPromise } from 'plugins/ml/util/promise';
import { ml } from 'plugins/ml/services/ml_api_service';
import template from './create_job.html';
import { timefilter } from 'ui/timefilter';
Expand All @@ -56,7 +55,6 @@ uiRoutes
savedSearch: loadCurrentSavedSearch,
checkMlNodesAvailable,
loadNewJobDefaults,
initPromise: initPromise(true)
}
});

Expand Down Expand Up @@ -351,20 +349,21 @@ module

mlMultiMetricJobService.clearChartData();

// $scope.chartStates.eventRate = CHART_STATE.LOADING;
setFieldsChartStates(CHART_STATE.LOADING);

if (Object.keys($scope.formConfig.fields).length) {
$scope.ui.showFieldCharts = true;
mlMultiMetricJobService.getLineChartResults($scope.formConfig, thisLoadTimestamp)
.then((resp) => {
$scope.$applyAsync();
loadDocCountData(resp.detectors);
})
.catch((resp) => {
msgs.error(resp.message);
_.each($scope.formConfig.fields, (field, id) => {
$scope.chartStates.fields[id] = CHART_STATE.NO_RESULTS;
});
$scope.$applyAsync();
});
} else {
$scope.ui.showFieldCharts = false;
Expand All @@ -382,13 +381,16 @@ module

$scope.chartData.lastLoadTimestamp = null;
chartDataUtils.updateChartMargin($scope.chartData);
$scope.$broadcast('render');
$scope.chartStates.eventRate = (resp.totalResults) ? CHART_STATE.LOADED : CHART_STATE.NO_RESULTS;
$scope.$broadcast('render');
}
})
.catch((resp) => {
$scope.chartStates.eventRate = CHART_STATE.NO_RESULTS;
msgs.error(resp.message);
})
.then(() => {
$scope.$applyAsync();
});
}
};
Expand All @@ -397,6 +399,7 @@ module
_.each($scope.chartStates.fields, (chart, key) => {
$scope.chartStates.fields[key] = state;
});
$scope.$applyAsync();
}

function showSparseDataCheckbox() {
Expand Down Expand Up @@ -508,7 +511,6 @@ module
// as it may have failed because we've hit the limit of open jobs
saveNewDatafeed(job, false);
});

})
.catch((resp) => {
// save failed
Expand All @@ -518,6 +520,7 @@ module
}),
resp.resp
);
$scope.$applyAsync();
});
} else {
// show the advanced section as the model memory limit is invalid
Expand All @@ -532,7 +535,6 @@ module
function saveNewDatafeed(job, startDatafeedAfterSave) {
mlJobService.saveNewDatafeed(job.datafeed_config, job.job_id)
.then(() => {

if (startDatafeedAfterSave) {
mlMultiMetricJobService.startDatafeed($scope.formConfig)
.then(() => {
Expand Down Expand Up @@ -566,7 +568,12 @@ module
}),
resp
);
})
.then(() => {
$scope.$applyAsync();
});
} else {
$scope.$applyAsync();
}
})
.catch((resp) => {
Expand All @@ -576,6 +583,7 @@ module
}),
resp
);
$scope.$applyAsync();
});
}
};
Expand All @@ -596,6 +604,7 @@ module
.then((state) => {
if (state === 'stopped') {
console.log('Stopping poll because datafeed state is: ' + state);
$scope.$applyAsync();
$scope.$broadcast('render-results');
forceStop = true;
}
Expand Down Expand Up @@ -642,6 +651,7 @@ module
// fade the bar chart once we have results
toggleSwimlaneVisibility();
}
$scope.$applyAsync();
$scope.$broadcast('render-results');
}

Expand Down Expand Up @@ -693,7 +703,11 @@ module
$scope.stopJob = function () {
// setting the status to STOPPING disables the stop button
$scope.jobState = JOB_STATE.STOPPING;
mlMultiMetricJobService.stopDatafeed($scope.formConfig);
mlMultiMetricJobService.stopDatafeed($scope.formConfig)
.catch()
.then(() => {
$scope.$applyAsync();
});
};

$scope.moveToAdvancedJobCreation = function () {
Expand Down
Loading