---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
---
Test get all jobs and stats given no job exists:
- do:
    ml.get_jobs:
      job_id: "_all"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    count: 0
- match:
    jobs: []
- do:
    ml.get_job_stats:
      job_id: "_all"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    count: 0
- match:
    jobs: []
---
Test get jobs with expression that does not match and allow_no_match:
- skip:
    features:
    - "warnings"
- do:
    ml.get_jobs:
      job_id: "missing-*"
      allow_no_match: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    count: 0
- match:
    jobs: []
---
Test get jobs with expression that does not match and not allow_no_match:
- skip:
    features:
    - "warnings"
- do:
    catch: "missing"
    ml.get_jobs:
      job_id: "missing-*"
      allow_no_match: false
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test put job deprecated bucket span:
- skip:
    features:
    - "warnings"
- do:
    warnings:
    - "bucket_span 1.5d [129600s] is not an integral multiple of the number of seconds\
      \ in 1d [86400s]. This is now deprecated."
    ml.put_job:
      job_id: "job-deprecated-bucket-span-1.5d"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"bucket_span\": \"36h\",\n      \"detectors\"\
        \ :[{\"function\":\"metric\",\"field_name\":\"responsetime\",\"by_field_name\"\
        :\"airline\"}]\n  },\n  \"data_description\" : {\n      \"time_field\":\"\
        time\",\n      \"time_format\":\"yyyy-MM-dd HH:mm:ssX\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-deprecated-bucket-span-1.5d"
- match:
    analysis_config.bucket_span: "36h"
- match:
    analysis_limits.model_memory_limit: "1024mb"
- match:
    analysis_limits.categorization_examples_limit: 4
- do:
    warnings:
    - "bucket_span 19m [1140s] is not an integral divisor of the number of seconds\
      \ in 1d [86400s]. This is now deprecated."
    ml.put_job:
      job_id: "job-deprecated-bucket-span-19m"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"bucket_span\": \"19m\",\n      \"detectors\"\
        \ :[{\"function\":\"metric\",\"field_name\":\"responsetime\",\"by_field_name\"\
        :\"airline\"}]\n  },\n  \"data_description\" : {\n      \"time_field\":\"\
        time\",\n      \"time_format\":\"yyyy-MM-dd HH:mm:ssX\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-deprecated-bucket-span-19m"
- match:
    analysis_config.bucket_span: "19m"
- match:
    analysis_limits.model_memory_limit: "1024mb"
- match:
    analysis_limits.categorization_examples_limit: 4
---
Test job crud apis:
- do:
    ml.put_job:
      job_id: "job-crud-test-apis"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"bucket_span\": \"1h\",\n      \"detectors\"\
        \ :[{\"function\":\"metric\",\"field_name\":\"responsetime\",\"by_field_name\"\
        :\"airline\"}]\n  },\n  \"data_description\" : {\n      \"time_field\":\"\
        time\",\n      \"time_format\":\"yyyy-MM-dd HH:mm:ssX\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-crud-test-apis"
- match:
    analysis_limits.model_memory_limit: "1024mb"
- match:
    analysis_limits.categorization_examples_limit: 4
- is_true: "create_time"
- do:
    ml.get_jobs:
      job_id: "job-crud-test-apis"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    count: 1
- match:
    jobs.0.job_id: "job-crud-test-apis"
- match:
    jobs.0.analysis_limits.model_memory_limit: "1024mb"
- do:
    ml.delete_job:
      job_id: "job-crud-test-apis"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    acknowledged: true
---
Test put job with model_memory_limit as number:
- do:
    ml.put_job:
      job_id: "job-model-memory-limit-as-number"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\n  },\n  \"data_description\" : {\n  },\n  \"analysis_limits\":\
        \ {\n      \"model_memory_limit\": 2048\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-model-memory-limit-as-number"
- match:
    analysis_limits.model_memory_limit: "2048mb"
---
Test put job with model_prune_window:
- skip:
    features:
    - "warnings"
- do:
    ml.put_job:
      job_id: "job-model-prune-window"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"15m\",\n     \
        \ \"detectors\" :[{\"function\":\"count\"}],\n      \"model_prune_window\"\
        : \"14d\"\n  },\n  \"data_description\" : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-model-prune-window"
- match:
    analysis_config.bucket_span: "15m"
- match:
    analysis_config.model_prune_window: "14d"
- is_true: "create_time"
- do:
    ml.put_job:
      job_id: "job-default-model-prune-window"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"15m\",\n     \
        \ \"detectors\" :[{\"function\":\"count\"}]\n  },\n  \"data_description\"\
        \ : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-default-model-prune-window"
- match:
    analysis_config.bucket_span: "15m"
- match:
    analysis_config.model_prune_window: "30d"
- is_true: "create_time"
- do:
    warnings:
    - "bucket_span 1.6d [144000s] is not an integral multiple of the number of seconds\
      \ in 1d [86400s]. This is now deprecated."
    ml.put_job:
      job_id: "job-default-model-prune-window-40h"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"40h\",\n     \
        \ \"detectors\" :[{\"function\":\"count\"}]\n  },\n  \"data_description\"\
        \ : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-default-model-prune-window-40h"
- match:
    analysis_config.bucket_span: "40h"
- match:
    analysis_config.model_prune_window: "800h"
- is_true: "create_time"
- do:
    catch: "/model_prune_window \\[29m\\] must be a multiple of bucket_span \\[15m\\\
      ]/"
    ml.put_job:
      job_id: "job-invalid-model-prune-window"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"15m\",\n     \
        \ \"detectors\" :[{\"function\":\"count\"}],\n      \"model_prune_window\"\
        : \"29m\"\n  },\n  \"data_description\" : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/model_prune_window \\[15m\\] must be at least 2 times greater than bucket_span\
      \ \\[15m\\]/"
    ml.put_job:
      job_id: "job-model-prune-window"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"15m\",\n     \
        \ \"detectors\" :[{\"function\":\"count\"}],\n      \"model_prune_window\"\
        : \"15m\"\n  },\n  \"data_description\" : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    warnings:
    - "bucket_span 17m [1020s] is not an integral divisor of the number of seconds\
      \ in 1d [86400s]. This is now deprecated."
    ml.put_job:
      job_id: "job-default-model-prune-window_with_odd_bucket_span"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"17m\",\n     \
        \ \"detectors\" :[{\"function\":\"count\"}]\n  },\n  \"data_description\"\
        \ : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-default-model-prune-window_with_odd_bucket_span"
- match:
    analysis_config.bucket_span: "17m"
- match:
    analysis_config.model_prune_window: "43214m"
- is_true: "create_time"
- do:
    ml.put_job:
      job_id: "job-default-model-prune-window_with_large_bucket_span"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"14d\",\n     \
        \ \"detectors\" :[{\"function\":\"count\"}]\n  },\n  \"data_description\"\
        \ : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-default-model-prune-window_with_large_bucket_span"
- match:
    analysis_config.bucket_span: "14d"
- match:
    analysis_config.model_prune_window: "280d"
- is_true: "create_time"
- do:
    ml.put_job:
      job_id: "job-default-model-prune-window_with_small_bucket_span"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"1s\",\n      \"\
        detectors\" :[{\"function\":\"count\"}]\n  },\n  \"data_description\" : {\n\
        \  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-default-model-prune-window_with_small_bucket_span"
- match:
    analysis_config.bucket_span: "1s"
- match:
    analysis_config.model_prune_window: "30d"
- is_true: "create_time"
---
Test put job with model_memory_limit as string and lazy open:
- skip:
    features: "headers"
- do:
    ml.put_job:
      job_id: "job-model-memory-limit-as-string"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\n  },\n  \"data_description\" : {\n  },\n  \"analysis_limits\":\
        \ {\n      \"model_memory_limit\": \"3000g\"\n  },\n  \"allow_lazy_open\"\
        : true\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-model-memory-limit-as-string"
- match:
    analysis_limits.model_memory_limit: "3072000mb"
- is_true: "create_time"
- do:
    ml.open_job:
      job_id: "job-model-memory-limit-as-string"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    opened: true
- match:
    node: ""
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.get_job_stats:
      job_id: "job-model-memory-limit-as-string"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.state: "opening"
- do:
    ml.close_job:
      job_id: "job-model-memory-limit-as-string"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    closed: true
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.get_job_stats:
      job_id: "job-model-memory-limit-as-string"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.state: "closed"
---
Test get job API with non existing job id:
- do:
    catch: "missing"
    ml.get_jobs:
      job_id: "non-existing"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test put job with inconsistent model snapshot settings:
- do:
    catch: "/The value of daily_model_snapshot_retention_after_days \\[4\\] cannot\
      \ be greater than model_snapshot_retention_days \\[3\\]/"
    ml.put_job:
      job_id: "inconsistent-snapshot-settings-1"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"bucket_span\": \"1h\",\n      \"detectors\"\
        \ :[{\"function\":\"metric\",\"field_name\":\"responsetime\",\"by_field_name\"\
        :\"airline\"}]\n  },\n  \"data_description\" : {\n      \"time_field\":\"\
        @timestamp\"\n  },\n  \"model_snapshot_retention_days\": 3,\n  \"daily_model_snapshot_retention_after_days\"\
        : 4\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/daily_model_snapshot_retention_after_days cannot be less than 0. Value\
      \ = -1/"
    ml.put_job:
      job_id: "inconsistent-snapshot-settings-2"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"bucket_span\": \"1h\",\n      \"detectors\"\
        \ :[{\"function\":\"metric\",\"field_name\":\"responsetime\",\"by_field_name\"\
        :\"airline\"}]\n  },\n  \"data_description\" : {\n      \"time_field\":\"\
        @timestamp\"\n  },\n  \"model_snapshot_retention_days\": 3,\n  \"daily_model_snapshot_retention_after_days\"\
        : -1\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test put job with inconsistent body/param ids:
- do:
    catch: "/illegal_argument_exception/"
    ml.put_job:
      job_id: "an_id"
      body: "{\n  \"job_id\":\"a_different_id\",\n  \"description\":\"Analysis of\
        \ response time by airline\",\n  \"analysis_config\" : {\n      \"bucket_span\"\
        : \"1h\",\n      \"detectors\" :[{\"function\":\"metric\",\"field_name\":\"\
        responsetime\",\"by_field_name\":\"airline\"}]\n  },\n  \"data_description\"\
        \ : {\n      \"time_field\":\"time\",\n      \"time_format\":\"yyyy-MM-dd\
        \ HH:mm:ssX\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/Inconsistent job_id; 'a_different_id' specified in the body differs from\
      \ 'an_id' specified as a URL argument/"
    ml.put_job:
      job_id: "an_id"
      body: "{\n  \"job_id\":\"a_different_id\",\n  \"description\":\"Analysis of\
        \ response time by airline\",\n  \"analysis_config\" : {\n      \"bucket_span\"\
        : \"3600s\",\n      \"detectors\" :[{\"function\":\"metric\",\"field_name\"\
        :\"responsetime\",\"by_field_name\":\"airline\"}]\n  },\n  \"data_description\"\
        \ : {\n      \"time_field\":\"time\",\n      \"time_format\":\"yyyy-MM-dd\
        \ HH:mm:ssX\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test put job with id that is already taken:
- do:
    ml.put_job:
      job_id: "jobs-crud-id-already-taken"
      body: "{\n  \"job_id\":\"jobs-crud-id-already-taken\",\n  \"description\":\"\
        Analysis of response time by airline\",\n  \"analysis_config\" : {\n     \
        \ \"bucket_span\": \"3600000ms\",\n      \"detectors\" :[{\"function\":\"\
        metric\",\"field_name\":\"responsetime\",\"by_field_name\":\"airline\"}]\n\
        \  },\n  \"data_description\" : {\n      \"time_field\":\"time\",\n      \"\
        time_format\":\"yyyy-MM-dd HH:mm:ssX\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-id-already-taken"
- is_true: "create_time"
- do:
    catch: "/resource_already_exists_exception/"
    ml.put_job:
      job_id: "jobs-crud-id-already-taken"
      body: "{\n  \"job_id\":\"jobs-crud-id-already-taken\",\n  \"description\":\"\
        Analysis of response time by airline\",\n  \"analysis_config\" : {\n     \
        \ \"bucket_span\": \"1h\",\n      \"detectors\" :[{\"function\":\"metric\"\
        ,\"field_name\":\"responsetime\",\"by_field_name\":\"airline\"}]\n  },\n \
        \ \"data_description\" : {\n      \"time_field\":\"time\",\n      \"time_format\"\
        :\"yyyy-MM-dd HH:mm:ssX\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/The job cannot be created with the Id 'jobs-crud-id-already-taken'. The\
      \ Id is already used./"
    ml.put_job:
      job_id: "jobs-crud-id-already-taken"
      body: "{\n  \"job_id\":\"jobs-crud-id-already-taken\",\n  \"description\":\"\
        Analysis of response time by airline\",\n  \"analysis_config\" : {\n     \
        \ \"bucket_span\": \"1h\",\n      \"detectors\" :[{\"function\":\"metric\"\
        ,\"field_name\":\"responsetime\",\"by_field_name\":\"airline\"}]\n  },\n \
        \ \"data_description\" : {\n      \"time_field\":\"time\",\n      \"time_format\"\
        :\"yyyy-MM-dd HH:mm:ssX\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test update job:
- do:
    ml.put_job:
      job_id: "jobs-crud-update-job"
      body: "{\n  \"description\":\"Pre update description\",\n  \"analysis_config\"\
        \ : {\n      \"detectors\" :[{\"function\":\"mean\",\"field_name\":\"responsetime\"\
        ,\"by_field_name\":\"airline\"},\n          {\"function\":\"count\",\"by_field_name\"\
        :\"mlcategory\"}],\n      \"categorization_field_name\": \"some_category\"\
        ,\n      \"categorization_filters\" : [\"cat1.*\", \"cat2.*\"],\n      \"\
        model_prune_window\": \"30d\"\n  },\n  \"data_description\" : {\n  },\n  \"\
        model_plot_config\": {\n    \"enabled\": true,\n    \"terms\": \"foo,bar\"\
        \n  },\n  \"analysis_limits\": {\n    \"model_memory_limit\": \"10mb\"\n \
        \ },\n  \"renormalization_window_days\": 1,\n  \"background_persist_interval\"\
        : \"2h\",\n  \"model_snapshot_retention_days\": 3,\n  \"daily_model_snapshot_retention_after_days\"\
        : 2,\n  \"results_retention_days\": 4,\n  \"custom_settings\": {\n    \"setting1\"\
        : \"custom1\",\n    \"setting2\": \"custom2\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-update-job"
- length:
    analysis_config.categorization_analyzer.filter: 2
- match:
    analysis_config.categorization_analyzer.tokenizer: "ml_standard"
- length:
    analysis_config.categorization_analyzer.char_filter: 3
- match:
    analysis_config.categorization_analyzer.char_filter.0: "first_line_with_letters"
- match:
    analysis_config.categorization_analyzer.char_filter.1.pattern: "cat1.*"
- match:
    analysis_config.categorization_analyzer.char_filter.2.pattern: "cat2.*"
- match:
    analysis_config.bucket_span: "5m"
- match:
    analysis_config.model_prune_window: "30d"
- is_true: "create_time"
- do:
    ml.open_job:
      job_id: "jobs-crud-update-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.update_job:
      job_id: "jobs-crud-update-job"
      body: "{\n  \"groups\": [\"group-1\", \"group-2\"],\n  \"description\":\"Post\
        \ update description\",\n  \"detectors\": [\n    {\n      \"detector_index\"\
        : 0,\n      \"custom_rules\":[\n        {\n          \"conditions\": [\n \
        \           {\n              \"applies_to\": \"actual\",\n              \"\
        operator\": \"gt\",\n              \"value\": 10\n            }\n        \
        \  ]\n        }\n      ]\n    },\n    {\n      \"detector_index\": 1,\n  \
        \    \"description\": \"updated description\"\n    }\n  ],\n  \"model_prune_window\"\
        : \"60d\",\n  \"model_plot_config\": {\n    \"enabled\": false,\n    \"terms\"\
        : \"foobar\"\n  },\n  \"renormalization_window_days\": 10,\n  \"background_persist_interval\"\
        : \"3h\",\n  \"model_snapshot_retention_days\": 30,\n  \"results_retention_days\"\
        : 40,\n  \"custom_settings\": {\n    \"setting3\": \"custom3\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-update-job"
- match:
    groups:
    - "group-1"
    - "group-2"
- match:
    description: "Post update description"
- match:
    model_plot_config.enabled: false
- match:
    model_plot_config.terms: "foobar"
- match:
    model_plot_config.annotations_enabled: false
- match:
    analysis_config.detectors.0.custom_rules.0.actions:
    - "skip_result"
- length:
    analysis_config.detectors.0.custom_rules.0.conditions: 1
- match:
    analysis_config.detectors.0.detector_index: 0
- match:
    analysis_config.detectors.1.detector_description: "updated description"
- match:
    analysis_config.detectors.1.detector_index: 1
- match:
    renormalization_window_days: 10
- match:
    background_persist_interval: "3h"
- match:
    model_snapshot_retention_days: 30
- match:
    daily_model_snapshot_retention_after_days: 2
- match:
    results_retention_days: 40
- match:
    analysis_config.bucket_span: "5m"
- match:
    analysis_config.model_prune_window: "60d"
- do:
    catch: "/Cannot update analysis_limits while the job is open/"
    ml.update_job:
      job_id: "jobs-crud-update-job"
      body: "{\n  \"analysis_limits\": {\n    \"model_memory_limit\": \"20mb\"\n \
        \ }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.close_job:
      job_id: "jobs-crud-update-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    closed: true
- do:
    ml.update_job:
      job_id: "jobs-crud-update-job"
      body: "{\n  \"analysis_limits\": {\n    \"model_memory_limit\": \"20mb\"\n \
        \ }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    analysis_limits.model_memory_limit: "20mb"
- do:
    ml.update_job:
      job_id: "jobs-crud-update-job"
      body: "{\n    \"model_prune_window\": \"12h\"\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    analysis_config.model_prune_window: "12h"
- do:
    catch: "/model_prune_window \\[5m\\] must be at least 2 times greater than bucket_span\
      \ \\[5m\\]/"
    ml.update_job:
      job_id: "jobs-crud-update-job"
      body: "{\n    \"model_prune_window\": \"5m\"\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/model_prune_window \\[2m\\] must be a multiple of bucket_span \\[5m\\\
      ]/"
    ml.update_job:
      job_id: "jobs-crud-update-job"
      body: "{\n    \"model_prune_window\": \"2m\"\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/\\[job_update\\] failed to parse field \\[model_prune_window\\]/"
    ml.update_job:
      job_id: "jobs-crud-update-job"
      body: "{\n    \"model_prune_window\": \"8w\"\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    analysis_config.model_prune_window: null
- do:
    ml.update_job:
      job_id: "jobs-crud-update-job"
      body: "{\n  \"analysis_limits\": {\n    \"model_memory_limit\": \"15mb\"\n \
        \ }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    analysis_limits.model_memory_limit: "15mb"
- do:
    catch: "/The value of daily_model_snapshot_retention_after_days \\[31\\] cannot\
      \ be greater than model_snapshot_retention_days \\[30\\]/"
    ml.update_job:
      job_id: "jobs-crud-update-job"
      body: "{\n  \"daily_model_snapshot_retention_after_days\": 31\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/The value of daily_model_snapshot_retention_after_days \\[2\\] cannot\
      \ be greater than model_snapshot_retention_days \\[1\\]/"
    ml.update_job:
      job_id: "jobs-crud-update-job"
      body: "{\n  \"model_snapshot_retention_days\": 1\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "bad_request"
    ml.update_job:
      job_id: "_all"
      body: "{\n  \"description\":\"Can't update all description\"\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.put_job:
      job_id: "job-crud-update-group-name-clash"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"1h\",\n      \"\
        detectors\" :[{\"function\":\"metric\",\"field_name\":\"responsetime\",\"\
        by_field_name\":\"airline\"}]\n  },\n  \"data_description\" : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/job and group names must be unique/"
    ml.update_job:
      job_id: "jobs-crud-update-job"
      body: "{\n  \"groups\": [\"job-crud-update-group-name-clash\"]\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test delete job that does not exist:
- do:
    catch: "missing"
    ml.delete_job:
      job_id: "not-a-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test delete job that is referred by a datafeed:
- do:
    ml.put_job:
      job_id: "jobs-crud-datafeed-job"
      body: "{\n  \"job_id\":\"jobs-crud-datafeed-job\",\n  \"description\":\"Analysis\
        \ of response time by airline\",\n  \"analysis_config\" : {\n      \"bucket_span\"\
        : \"1h\",\n      \"detectors\" :[{\"function\":\"metric\",\"field_name\":\"\
        responsetime\",\"by_field_name\":\"airline\"}]\n  },\n  \"data_description\"\
        \ : {\n      \"format\":\"xcontent\",\n      \"time_field\":\"time\",\n  \
        \    \"time_format\":\"yyyy-MM-dd HH:mm:ssX\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-datafeed-job"
- is_true: "create_time"
- do:
    ml.put_datafeed:
      datafeed_id: "jobs-crud-test-datafeed-1"
      body: "{\n  \"job_id\":\"jobs-crud-datafeed-job\",\n  \"indexes\":[\"index-foo\"\
        ]\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    datafeed_id: "jobs-crud-test-datafeed-1"
- do:
    ml.delete_job:
      job_id: "jobs-crud-datafeed-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    acknowledged: true
---
Test delete job that is opened:
- do:
    ml.put_job:
      job_id: "delete-opened-job"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"1h\",\n      \"\
        detectors\" :[{\"function\":\"count\"}]\n  },\n  \"analysis_limits\" : {\n\
        \      \"model_memory_limit\": \"20mb\"\n  },\n  \"data_description\" : {\n\
        \      \"time_field\":\"time\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "delete-opened-job"
- is_true: "create_time"
- do:
    ml.open_job:
      job_id: "delete-opened-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    opened: true
- match:
    node: "/\\S+/"
- do:
    catch: "/Cannot delete job \\[delete-opened-job\\] because the job is opened/"
    ml.delete_job:
      job_id: "delete-opened-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test close job:
- skip:
    features:
    - "headers"
- do:
    ml.put_job:
      job_id: "jobs-crud-close-job"
      body: "{\n  \"job_id\":\"jobs-crud-close-job\",\n  \"description\":\"Analysis\
        \ of response time by airline\",\n  \"analysis_config\" : {\n      \"bucket_span\"\
        :\"1h\",\n      \"detectors\" :[{\"function\":\"metric\",\"field_name\":\"\
        responsetime\",\"by_field_name\":\"airline\"}]\n  },\n  \"data_description\"\
        \ : {\n      \"format\":\"xcontent\",\n      \"time_field\":\"time\",\n  \
        \    \"time_format\":\"epoch\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-close-job"
- is_true: "create_time"
- do:
    ml.open_job:
      job_id: "jobs-crud-close-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.get_job_stats:
      job_id: "jobs-crud-close-job"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.state: "opened"
- do:
    ml.close_job:
      job_id: "jobs-crud-close-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    closed: true
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.get_job_stats:
      job_id: "jobs-crud-close-job"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.state: "closed"
---
Test closing a closed job isn't an error:
- do:
    ml.put_job:
      job_id: "jobs-crud-close-a-closed-job"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"detectors\" :[{\"function\":\"count\"}]\n \
        \ },\n  \"analysis_limits\" : {\n      \"model_memory_limit\": \"20mb\"\n\
        \  },\n  \"data_description\" : {\n      \"format\":\"xcontent\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-close-a-closed-job"
- is_true: "create_time"
- do:
    ml.open_job:
      job_id: "jobs-crud-close-a-closed-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.close_job:
      job_id: "jobs-crud-close-a-closed-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    closed: true
- do:
    ml.close_job:
      job_id: "jobs-crud-close-a-closed-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    closed: true
---
Test close all jobs:
- do:
    ml.put_job:
      job_id: "jobs-crud-close-all-1"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"detectors\" :[{\"function\":\"count\"}]\n \
        \ },\n  \"analysis_limits\" : {\n      \"model_memory_limit\": \"20mb\"\n\
        \  },\n  \"data_description\" : {\n      \"format\":\"xcontent\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-close-all-1"
- is_true: "create_time"
- do:
    ml.put_job:
      job_id: "jobs-crud-close-all-2"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"detectors\" :[{\"function\":\"count\"}]\n \
        \ },\n  \"analysis_limits\" : {\n      \"model_memory_limit\": \"20mb\"\n\
        \  },\n  \"data_description\" : {\n      \"format\":\"xcontent\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-close-all-2"
- is_true: "create_time"
- do:
    ml.open_job:
      job_id: "jobs-crud-close-all-2"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.close_job:
      job_id: "_all"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    closed: true
- do:
    ml.get_job_stats:
      job_id: "_all"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.state: "closed"
- match:
    jobs.1.state: "closed"
---
Test close jobs with expression that matches:
- do:
    ml.put_job:
      job_id: "jobs-crud-with-expression-that-matches-foo-1"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\n  },\n  \"analysis_limits\" : {\n      \"model_memory_limit\":\
        \ \"20mb\"\n  },\n  \"data_description\" : {}\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.put_job:
      job_id: "jobs-crud-with-expression-that-matches-foo-2"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\n  },\n  \"analysis_limits\" : {\n      \"model_memory_limit\":\
        \ \"20mb\"\n  },\n  \"data_description\" : {}\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.put_job:
      job_id: "jobs-crud-with-expression-that-matches-bar-1"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\n  },\n  \"analysis_limits\" : {\n      \"model_memory_limit\":\
        \ \"20mb\"\n  },\n  \"data_description\" : {}\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.open_job:
      job_id: "jobs-crud-with-expression-that-matches-foo-1"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.open_job:
      job_id: "jobs-crud-with-expression-that-matches-foo-2"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.open_job:
      job_id: "jobs-crud-with-expression-that-matches-bar-1"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.close_job:
      job_id: "*foo-*"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    closed: true
- do:
    ml.get_job_stats:
      job_id: "*foo-*"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.state: "closed"
- match:
    jobs.1.state: "closed"
- do:
    ml.get_job_stats:
      job_id: "*bar-1"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.state: "opened"
---
Test close jobs with expression that does not match and allow_no_match:
- skip:
    features:
    - "warnings"
- do:
    ml.close_job:
      job_id: "missing-*"
      allow_no_match: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    closed: true
---
Test close jobs with expression that does not match and not allow_no_match:
- skip:
    features:
    - "warnings"
- do:
    catch: "missing"
    ml.close_job:
      job_id: "missing-*"
      allow_no_match: false
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test force close job:
- skip:
    features:
    - "headers"
- do:
    ml.put_job:
      job_id: "jobs-crud-force-close-job"
      body: "{\n  \"job_id\":\"jobs-crud-force-close-job\",\n  \"description\":\"\
        Analysis of response time by airline\",\n  \"analysis_config\" : {\n     \
        \ \"bucket_span\":\"1h\",\n      \"detectors\" :[{\"function\":\"metric\"\
        ,\"field_name\":\"responsetime\",\"by_field_name\":\"airline\"}]\n  },\n \
        \ \"analysis_limits\" : {\n      \"model_memory_limit\": \"20mb\"\n  },\n\
        \  \"data_description\" : {\n      \"format\":\"xcontent\",\n      \"time_field\"\
        :\"time\",\n      \"time_format\":\"epoch\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-force-close-job"
- is_true: "create_time"
- do:
    ml.open_job:
      job_id: "jobs-crud-force-close-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.get_job_stats:
      job_id: "jobs-crud-force-close-job"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.state: "opened"
- do:
    ml.close_job:
      job_id: "jobs-crud-force-close-job"
      force: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    closed: true
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.get_job_stats:
      job_id: "jobs-crud-force-close-job"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    jobs.0.state: "closed"
---
Test force closing a closed job isn't an error:
- do:
    ml.put_job:
      job_id: "jobs-crud-close-a-closed-job"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"detectors\" :[{\"function\":\"count\"}]\n \
        \ },\n  \"analysis_limits\" : {\n      \"model_memory_limit\": \"20mb\"\n\
        \  },\n  \"data_description\" : {\n      \"format\":\"xcontent\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-close-a-closed-job"
- is_true: "create_time"
- do:
    ml.open_job:
      job_id: "jobs-crud-close-a-closed-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.close_job:
      job_id: "jobs-crud-close-a-closed-job"
      force: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    closed: true
- do:
    ml.close_job:
      job_id: "jobs-crud-close-a-closed-job"
      force: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    closed: true
---
Test open and close an unknown job is resource not found:
- do:
    catch: "missing"
    ml.open_job:
      job_id: "jobs-crud-some-missing-job-i-made-up"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "missing"
    ml.close_job:
      job_id: "jobs-crud-some-missing-job-i-made-up"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test cannot create job with model snapshot id set:
- do:
    catch: "/x_content_parse_exception/"
    ml.put_job:
      job_id: "has-model-snapshot-id"
      body: "{\n  \"model_snapshot_id\": \"wont-create-with-this-setting\",\n  \"\
        analysis_config\" : {\n      \"bucket_span\": \"1h\",\n      \"detectors\"\
        \ :[{\"function\":\"metric\",\"field_name\":\"responsetime\",\"by_field_name\"\
        :\"airline\"}]\n  },\n  \"data_description\" : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test put job with time field in analysis_config:
- do:
    catch: "/illegal_argument_exception/"
    ml.put_job:
      job_id: "jobs-crud-time-field-in-analysis_config"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"1h\",\n      \"\
        detectors\" :[{\"function\":\"rare\",\"by_field_name\":\"@timestamp\"}]\n\
        \  },\n  \"data_description\" : {\n      \"time_field\":\"@timestamp\"\n \
        \ }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/data_description.time_field may not be used in the analysis_config/"
    ml.put_job:
      job_id: "jobs-crud-time-field-in-analysis_config"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"1h\",\n      \"\
        detectors\" :[{\"function\":\"mean\",\"field_name\":\"time\"}]\n  },\n  \"\
        data_description\" : {}\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test put job with duplicate detector configurations:
- do:
    catch: "/illegal_argument_exception.*Duplicate detectors are not allowed/"
    ml.put_job:
      job_id: "jobs-crud-duplicate-detectors"
      body: "{\n  \"analysis_config\": {\n      \"bucket_span\": \"1h\",\n      \"\
        detectors\": [\n          {\"function\":\"max\", \"field_name\":\"responsetime\"\
        },\n          {\"function\":\"max\", \"field_name\":\"responsetime\"}\n  \
        \    ]\n  },\n  \"data_description\": {\n      \"time_field\": \"@timestamp\"\
        \n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/illegal_argument_exception.*Duplicate detectors are not allowed/"
    ml.put_job:
      job_id: "jobs-crud-duplicate-detectors-with-explicit-indices"
      body: "{\n  \"analysis_config\": {\n      \"bucket_span\": \"1h\",\n      \"\
        detectors\": [\n          {\"function\":\"max\", \"field_name\":\"responsetime\"\
        , \"detector_index\": 0},\n          {\"function\":\"max\", \"field_name\"\
        :\"responsetime\", \"detector_index\": 1}\n      ]\n  },\n  \"data_description\"\
        : {\n      \"time_field\": \"@timestamp\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test put job with datafeed:
- do:
    ml.put_job:
      job_id: "jobs-crud-put-with-datafeed"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"detectors\" :[{\"function\":\"count\"}]\n \
        \ },\n  \"analysis_limits\" : {\n      \"model_memory_limit\": \"20mb\"\n\
        \  },\n  \"data_description\" : {\n      \"format\":\"xcontent\"\n  },\n \
        \ \"datafeed_config\": {\n    \"indexes\":[\"index-foo\"]\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-put-with-datafeed"
- is_true: "datafeed_config"
- match:
    datafeed_config.job_id: "jobs-crud-put-with-datafeed"
- match:
    datafeed_config.datafeed_id: "jobs-crud-put-with-datafeed"
- is_true: "datafeed_config.authorization.roles"
- is_true: "create_time"
- do:
    ml.get_datafeeds:
      datafeed_id: "jobs-crud-put-with-datafeed"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    count: 1
- match:
    datafeeds.0.job_id: "jobs-crud-put-with-datafeed"
- match:
    datafeeds.0.datafeed_id: "jobs-crud-put-with-datafeed"
---
Test get job with datafeed:
- do:
    ml.put_job:
      job_id: "jobs-crud-get-with-datafeed"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"detectors\" :[{\"function\":\"count\"}]\n \
        \ },\n  \"analysis_limits\" : {\n      \"model_memory_limit\": \"20mb\"\n\
        \  },\n  \"data_description\" : {\n      \"format\":\"xcontent\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-get-with-datafeed"
- is_true: "create_time"
- do:
    ml.put_datafeed:
      datafeed_id: "jobs-crud-get-with-datafeed"
      body: "{\n  \"job_id\":\"jobs-crud-get-with-datafeed\",\n  \"indexes\":[\"index-foo\"\
        ]\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    datafeed_id: "jobs-crud-get-with-datafeed"
- do:
    ml.get_jobs:
      job_id: "jobs-crud-get-with-datafeed"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    count: 1
- match:
    jobs.0.job_id: "jobs-crud-get-with-datafeed"
- match:
    jobs.0.datafeed_config.datafeed_id: "jobs-crud-get-with-datafeed"
- do:
    ml.get_jobs:
      job_id: "jobs-crud-get-with-datafeed"
      exclude_generated: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    count: 1
- match:
    jobs.0.job_id: "jobs-crud-get-with-datafeed"
- is_false: "jobs.0.datafeed_config"
---
Test put job with datafeed with indices options in params:
- skip:
    features: "warnings"
- do:
    warnings:
    - "[ignore_throttled] parameter is deprecated because frozen indices have been\
      \ deprecated. Consider cold or frozen tiers in place of frozen indices."
    ml.put_job:
      job_id: "jobs-crud-put-with-datafeed-with-indices-options"
      ignore_throttled: false
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"detectors\" :[{\"function\":\"count\"}]\n \
        \ },\n  \"analysis_limits\" : {\n      \"model_memory_limit\": \"20mb\"\n\
        \  },\n  \"data_description\" : {\n      \"format\":\"xcontent\"\n  },\n \
        \ \"datafeed_config\": {\n    \"indexes\":[\"index-foo\"]\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-put-with-datafeed-with-indices-options"
- match:
    datafeed_config.datafeed_id: "jobs-crud-put-with-datafeed-with-indices-options"
- match:
    datafeed_config.indices_options.ignore_throttled: false
- is_true: "create_time"
- do:
    ml.get_datafeeds:
      datafeed_id: "jobs-crud-put-with-datafeed-with-indices-options"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    datafeeds.0.indices_options.ignore_throttled: false
---
Test max model memory limit:
- skip:
    features: "headers"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    cluster.put_settings:
      body:
        persistent:
          xpack.ml.max_model_memory_limit: "9g"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    persistent.xpack.ml.max_model_memory_limit: "9g"
- do:
    ml.put_job:
      job_id: "job-model-memory-limit-below-global-max"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\n  },\n  \"data_description\" : {\n  },\n  \"analysis_limits\":\
        \ {\n      \"model_memory_limit\": \"8g\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-model-memory-limit-below-global-max"
- match:
    analysis_limits.model_memory_limit: "8192mb"
- is_true: "create_time"
- do:
    catch: "/model_memory_limit \\[10gb\\] must be less than the value of the xpack.ml.max_model_memory_limit\
      \ setting \\[9gb\\]/"
    ml.put_job:
      job_id: "job-model-memory-limit-above-global-max"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\n  },\n  \"data_description\" : {\n  },\n  \"analysis_limits\":\
        \ {\n      \"model_memory_limit\": \"10g\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    cluster.put_settings:
      body:
        persistent:
          xpack.ml.max_model_memory_limit: null
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    persistent: {}
- do:
    ml.put_job:
      job_id: "job-model-memory-limit-above-removed-global-max"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\n  },\n  \"data_description\" : {\n  },\n  \"analysis_limits\":\
        \ {\n      \"model_memory_limit\": \"10g\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "job-model-memory-limit-above-removed-global-max"
- match:
    analysis_limits.model_memory_limit: "10240mb"
- is_true: "create_time"
---
Test jobs with named and custom categorization_analyzer:
- do:
    ml.put_job:
      job_id: "jobs-crud-named-categorization-analyzer-job"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        mean\",\"field_name\":\"responsetime\",\"by_field_name\":\"airline\"},\n \
        \         {\"function\":\"count\",\"by_field_name\":\"mlcategory\"}],\n  \
        \    \"categorization_field_name\": \"some_category\",\n      \"categorization_analyzer\"\
        \ : \"standard\"\n  },\n  \"data_description\" : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-named-categorization-analyzer-job"
- match:
    analysis_config.categorization_analyzer: "standard"
- is_true: "create_time"
- do:
    ml.put_job:
      job_id: "jobs-crud-custom-categorization-analyzer-job"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        mean\",\"field_name\":\"responsetime\",\"by_field_name\":\"airline\"},\n \
        \         {\"function\":\"count\",\"by_field_name\":\"mlcategory\"}],\n  \
        \    \"categorization_field_name\": \"some_category\",\n      \"categorization_analyzer\"\
        \ : {\n          \"char_filter\" : [\"html_strip\"],\n          \"tokenizer\"\
        \ : \"classic\",\n          \"filter\" : [\"stop\"]\n      }\n  },\n  \"data_description\"\
        \ : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-custom-categorization-analyzer-job"
- match:
    analysis_config.categorization_analyzer.char_filter.0: "html_strip"
- match:
    analysis_config.categorization_analyzer.tokenizer: "classic"
- match:
    analysis_config.categorization_analyzer.filter.0: "stop"
- is_true: "create_time"
---
Test job with categorization_analyzer and categorization_filters:
- do:
    catch: "/categorization_filters cannot be used with categorization_analyzer -\
      \ instead specify them as pattern_replace char_filters in the analyzer/"
    ml.put_job:
      job_id: "jobs-crud-categorization-analyzer-job"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        mean\",\"field_name\":\"responsetime\",\"by_field_name\":\"airline\"},\n \
        \         {\"function\":\"count\",\"by_field_name\":\"mlcategory\"}],\n  \
        \    \"categorization_field_name\": \"some_category\",\n      \"categorization_analyzer\"\
        \ : {\n          \"char_filter\" : [\"html_strip\"],\n          \"tokenizer\"\
        \ : \"classic\",\n          \"filter\" : [\"stop\"]\n      },\n      \"categorization_filters\"\
        \ : [\"cat1.*\", \"cat2.*\"]\n  },\n  \"data_description\" : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test job with rules:
- do:
    ml.put_job:
      job_id: "jobs-crud-rules"
      body: "{\n  \"analysis_config\": {\n    \"detectors\": [\n      {\n        \"\
        function\": \"count\",\n        \"by_field_name\": \"country\",\n        \"\
        custom_rules\": [\n          {\n            \"actions\": [\"skip_result\"\
        , \"skip_model_update\"],\n            \"scope\": {\n              \"country\"\
        : {\"filter_id\": \"safe_countries\"}\n            },\n            \"conditions\"\
        : [\n              {\n                \"applies_to\":\"actual\",\n       \
        \         \"operator\":\"lt\",\n                \"value\": 33.3\n        \
        \      },\n              {\n                \"applies_to\":\"typical\",\n\
        \                \"operator\":\"lte\",\n                \"value\": 42.0\n\
        \              }\n            ]\n          }\n        ]\n      }\n    ]\n\
        \  },\n  \"data_description\" : {}\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.get_jobs:
      job_id: "jobs-crud-rules"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    count: 1
- match:
    jobs.0.analysis_config.detectors.0.custom_rules:
    - actions:
      - "skip_result"
      - "skip_model_update"
      scope:
        country:
          filter_id: "safe_countries"
          filter_type: "include"
      conditions:
      - applies_to: "actual"
        operator: "lt"
        value: 33.3
      - applies_to: "typical"
        operator: "lte"
        value: 42.0
---
Test function shortcut expansion:
- do:
    ml.put_job:
      job_id: "jobs-function-shortcut-expansion"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"1h\",\n      \"\
        detectors\" :[{\"function\":\"nzc\",\"by_field_name\":\"airline\"}]\n  },\n\
        \  \"data_description\" : {}\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-function-shortcut-expansion"
- match:
    analysis_config.detectors.0.function: "non_zero_count"
- is_true: "create_time"
---
Test open job when persistent task allocation disabled:
- skip:
    features: "headers"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    cluster.put_settings:
      body:
        persistent:
          cluster.persistent_tasks.allocation.enable: "none"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    persistent.cluster.persistent_tasks.allocation.enable: "none"
- do:
    ml.put_job:
      job_id: "persistent-task-allocation-allowed-test"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\n  },\n  \"data_description\" : {\n  },\n  \"analysis_limits\":\
        \ {\n      \"model_memory_limit\": \"10m\"\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "persistent-task-allocation-allowed-test"
- is_true: "create_time"
- do:
    catch: "/Cannot open jobs because persistent task assignment is disabled by the\
      \ \\[cluster.persistent_tasks.allocation.enable\\] setting/"
    ml.open_job:
      job_id: "persistent-task-allocation-allowed-test"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    cluster.put_settings:
      body:
        persistent:
          cluster.persistent_tasks.allocation.enable: "all"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    persistent.cluster.persistent_tasks.allocation.enable: "all"
- do:
    ml.open_job:
      job_id: "persistent-task-allocation-allowed-test"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    opened: true
- match:
    node: "/\\S+/"
---
Test reopen job resets the finished time:
- do:
    ml.put_job:
      job_id: "jobs-crud-reset-finished-time"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\n  },\n  \"data_description\" : {\n  }\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    job_id: "jobs-crud-reset-finished-time"
- is_true: "create_time"
- do:
    ml.open_job:
      job_id: "jobs-crud-reset-finished-time"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.get_jobs:
      job_id: "jobs-crud-reset-finished-time"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- is_false: "jobs.0.finished_time"
- do:
    ml.close_job:
      job_id: "jobs-crud-reset-finished-time"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.get_jobs:
      job_id: "jobs-crud-reset-finished-time"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- is_true: "jobs.0.finished_time"
- do:
    ml.open_job:
      job_id: "jobs-crud-reset-finished-time"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.get_jobs:
      job_id: "jobs-crud-reset-finished-time"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- is_false: "jobs.0.finished_time"
---
Test close job with body params:
- skip:
    features:
    - "warnings"
- do:
    catch: "missing"
    ml.close_job:
      job_id: "job-that-doesnot-exist*"
      body: "{\n  \"allow_no_match\" : false\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    ml.close_job:
      job_id: "job-that-doesnot-exist*"
      body: "{\n  \"allow_no_match\" : true\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test job with rule referencing missing filter:
- do:
    ml.put_job:
      job_id: "jobs-crud-rule-missing-filter"
      body: "{\n  \"analysis_config\": {\n    \"detectors\": [\n      {\n        \"\
        function\": \"count\",\n        \"by_field_name\": \"country\",\n        \"\
        custom_rules\": [\n          {\n            \"actions\": [\"skip_result\"\
        ],\n            \"scope\": {\n              \"country\": {\"filter_id\": \"\
        safe_countries\"}\n            }\n          }\n        ]\n      }\n    ]\n\
        \  },\n  \"data_description\" : {}\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/Unable to find filter \\[safe_countries\\]/"
    ml.open_job:
      job_id: "jobs-crud-rule-missing-filter"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
