[ML] Only check licensing in the transport action of the open job and start datafeed apis.

Original commit: elastic/x-pack-elasticsearch@a59ef8884c
This commit is contained in:
Martijn van Groningen 2017-04-14 08:57:44 +02:00
parent 10390a5e50
commit e93b447b9c
3 changed files with 24 additions and 36 deletions

View File

@ -307,8 +307,8 @@ public class MachineLearning implements ActionPlugin {
new InvalidLicenseEnforcer(settings, licenseState, threadPool, datafeedManager, autodetectProcessManager);
PersistentTasksExecutorRegistry persistentTasksExecutorRegistry = new PersistentTasksExecutorRegistry(Settings.EMPTY, Arrays.asList(
new OpenJobAction.OpenJobPersistentTasksExecutor(settings, licenseState, clusterService, autodetectProcessManager),
new StartDatafeedAction.StartDatafeedPersistentTasksExecutor(settings, licenseState, datafeedManager)
new OpenJobAction.OpenJobPersistentTasksExecutor(settings, clusterService, autodetectProcessManager),
new StartDatafeedAction.StartDatafeedPersistentTasksExecutor(settings, datafeedManager)
));
return Arrays.asList(

View File

@ -447,15 +447,13 @@ public class OpenJobAction extends Action<OpenJobAction.Request, OpenJobAction.R
public static class OpenJobPersistentTasksExecutor extends PersistentTasksExecutor<JobParams> {
private final AutodetectProcessManager autodetectProcessManager;
private final XPackLicenseState licenseState;
private final int maxNumberOfOpenJobs;
private volatile int maxConcurrentJobAllocations;
public OpenJobPersistentTasksExecutor(Settings settings, XPackLicenseState licenseState,
ClusterService clusterService, AutodetectProcessManager autodetectProcessManager) {
public OpenJobPersistentTasksExecutor(Settings settings, ClusterService clusterService,
AutodetectProcessManager autodetectProcessManager) {
super(settings, TASK_NAME, ThreadPool.Names.MANAGEMENT);
this.licenseState = licenseState;
this.autodetectProcessManager = autodetectProcessManager;
this.maxNumberOfOpenJobs = AutodetectProcessManager.MAX_RUNNING_JOBS_PER_NODE.get(settings);
this.maxConcurrentJobAllocations = MachineLearning.CONCURRENT_JOB_ALLOCATIONS.get(settings);
@ -470,21 +468,17 @@ public class OpenJobAction extends Action<OpenJobAction.Request, OpenJobAction.R
@Override
public void validate(JobParams params, ClusterState clusterState) {
if (licenseState.isMachineLearningAllowed()) {
// If we already know that we can't find an ml node because all ml nodes are running at capacity or
// simply because there are no ml nodes in the cluster then we fail quickly here:
MlMetadata mlMetadata = clusterState.metaData().custom(MlMetadata.TYPE);
OpenJobAction.validate(params.getJobId(), mlMetadata);
Assignment assignment = selectLeastLoadedMlNode(params.getJobId(), clusterState, maxConcurrentJobAllocations,
maxNumberOfOpenJobs, logger);
if (assignment.getExecutorNode() == null) {
String msg = "Could not open job because no suitable nodes were found, allocation explanation ["
+ assignment.getExplanation() + "]";
logger.warn("[{}] {}", params.getJobId(), msg);
throw new ElasticsearchStatusException(msg, RestStatus.TOO_MANY_REQUESTS);
}
} else {
throw LicenseUtils.newComplianceException(XPackPlugin.MACHINE_LEARNING);
// If we already know that we can't find an ml node because all ml nodes are running at capacity or
// simply because there are no ml nodes in the cluster then we fail quickly here:
MlMetadata mlMetadata = clusterState.metaData().custom(MlMetadata.TYPE);
OpenJobAction.validate(params.getJobId(), mlMetadata);
Assignment assignment = selectLeastLoadedMlNode(params.getJobId(), clusterState, maxConcurrentJobAllocations,
maxNumberOfOpenJobs, logger);
if (assignment.getExecutorNode() == null) {
String msg = "Could not open job because no suitable nodes were found, allocation explanation ["
+ assignment.getExplanation() + "]";
logger.warn("[{}] {}", params.getJobId(), msg);
throw new ElasticsearchStatusException(msg, RestStatus.TOO_MANY_REQUESTS);
}
}

View File

@ -473,12 +473,10 @@ public class StartDatafeedAction
public static class StartDatafeedPersistentTasksExecutor extends PersistentTasksExecutor<DatafeedParams> {
private final DatafeedManager datafeedManager;
private final XPackLicenseState licenseState;
private final IndexNameExpressionResolver resolver;
public StartDatafeedPersistentTasksExecutor(Settings settings, XPackLicenseState licenseState, DatafeedManager datafeedManager) {
public StartDatafeedPersistentTasksExecutor(Settings settings, DatafeedManager datafeedManager) {
super(settings, TASK_NAME, ThreadPool.Names.MANAGEMENT);
this.licenseState = licenseState;
this.datafeedManager = datafeedManager;
this.resolver = new IndexNameExpressionResolver(settings);
}
@ -490,18 +488,14 @@ public class StartDatafeedAction
@Override
public void validate(DatafeedParams params, ClusterState clusterState) {
if (licenseState.isMachineLearningAllowed()) {
MlMetadata mlMetadata = clusterState.metaData().custom(MlMetadata.TYPE);
PersistentTasksCustomMetaData tasks = clusterState.getMetaData().custom(PersistentTasksCustomMetaData.TYPE);
StartDatafeedAction.validate(params.getDatafeedId(), mlMetadata, tasks);
Assignment assignment = selectNode(logger, params.getDatafeedId(), clusterState, resolver);
if (assignment.getExecutorNode() == null) {
String msg = "No node found to start datafeed [" + params.getDatafeedId()
+ "], allocation explanation [" + assignment.getExplanation() + "]";
throw new ElasticsearchException(msg);
}
} else {
throw LicenseUtils.newComplianceException(XPackPlugin.MACHINE_LEARNING);
MlMetadata mlMetadata = clusterState.metaData().custom(MlMetadata.TYPE);
PersistentTasksCustomMetaData tasks = clusterState.getMetaData().custom(PersistentTasksCustomMetaData.TYPE);
StartDatafeedAction.validate(params.getDatafeedId(), mlMetadata, tasks);
Assignment assignment = selectNode(logger, params.getDatafeedId(), clusterState, resolver);
if (assignment.getExecutorNode() == null) {
String msg = "No node found to start datafeed [" + params.getDatafeedId()
+ "], allocation explanation [" + assignment.getExplanation() + "]";
throw new ElasticsearchException(msg);
}
}