---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_job:
      job_id: "test-job-groups-foo-1"
      body: "{\n  \"groups\": [\"foo-group\", \"ones\"],\n  \"analysis_config\" :\
        \ {\n      \"detectors\" :[{\"function\":\"count\"}]\n  },\n  \"analysis_limits\"\
        \ : {\n      \"model_memory_limit\": \"10mb\"\n  },\n  \"data_description\"\
        \ : {}\n}\n"
    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.put_job:
      job_id: "test-job-groups-foo-2"
      body: "{\n  \"groups\": [\"foo-group\", \"twos\"],\n  \"analysis_config\" :\
        \ {\n      \"detectors\" :[{\"function\":\"count\"}]\n  },\n  \"analysis_limits\"\
        \ : {\n      \"model_memory_limit\": \"10mb\"\n  },\n  \"data_description\"\
        \ : {}\n}\n"
    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.put_job:
      job_id: "test-job-groups-bar-1"
      body: "{\n  \"groups\": [\"bar-group\", \"ones\"],\n  \"analysis_config\" :\
        \ {\n      \"detectors\" :[{\"function\":\"count\"}]\n  },\n  \"analysis_limits\"\
        \ : {\n      \"model_memory_limit\": \"10mb\"\n  },\n  \"data_description\"\
        \ : {}\n}\n"
    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.put_job:
      job_id: "test-job-groups-bar-2"
      body: "{\n  \"groups\": [\"bar-group\", \"twos\"],\n  \"analysis_config\" :\
        \ {\n      \"detectors\" :[{\"function\":\"count\"}]\n  },\n  \"analysis_limits\"\
        \ : {\n      \"model_memory_limit\": \"10mb\"\n  },\n  \"data_description\"\
        \ : {}\n}\n"
    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.put_job:
      job_id: "test-job-groups-nogroup"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\n  },\n  \"analysis_limits\" : {\n      \"model_memory_limit\":\
        \ \"10mb\"\n  },\n  \"data_description\" : {}\n}\n"
    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 matches an existing group:
- do:
    catch: "/resource_already_exists_exception/"
    ml.put_job:
      job_id: "foo-group"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        count\"}]\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 group that matches an job id:
- do:
    catch: "/resource_already_exists_exception/"
    ml.put_job:
      job_id: "test-job-groups-job-with-group-matching-existing-job-id"
      body: "{\n  \"groups\": [\"test-job-groups-nogroup\"],\n  \"analysis_config\"\
        \ : {\n      \"detectors\" :[{\"function\":\"count\"}]\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 group that matches its id:
- do:
    catch: "/resource_already_exists_exception/"
    ml.put_job:
      job_id: "test-job-groups-job-with-group-matching-its-id"
      body: "{\n  \"groups\": [\"test-job-groups-job-with-group-matching-its-id\"\
        ],\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"count\"\
        }]\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 empty group:
- do:
    catch: "/Invalid group id ''; must be non-empty string and may contain lowercase\
      \ alphanumeric \\(a-z and 0-9\\), hyphens or underscores; must start and end\
      \ with alphanumeric/"
    ml.put_job:
      job_id: "test-job-groups-job-with-empty-group"
      body: "{\n  \"groups\": [\"foo-group\", \"\"],\n  \"analysis_config\" : {\n\
        \      \"detectors\" :[{\"function\":\"count\"}]\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 invalid group:
- do:
    catch: "/Invalid group id '___'; must be non-empty string and may contain lowercase\
      \ alphanumeric \\(a-z and 0-9\\), hyphens or underscores; must start and end\
      \ with alphanumeric/"
    ml.put_job:
      job_id: "test-job-groups-job-with-invalid-group"
      body: "{\n  \"groups\": [\"foo\", \"___\"],\n  \"analysis_config\" : {\n   \
        \   \"detectors\" :[{\"function\":\"count\"}]\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 get job API:
- 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: 5
- match:
    jobs.0.job_id: "test-job-groups-bar-1"
- match:
    jobs.1.job_id: "test-job-groups-bar-2"
- match:
    jobs.2.job_id: "test-job-groups-foo-1"
- match:
    jobs.3.job_id: "test-job-groups-foo-2"
- match:
    jobs.4.job_id: "test-job-groups-nogroup"
- do:
    ml.get_jobs:
      job_id: "test-job-groups-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:
    count: 1
- match:
    jobs.0.job_id: "test-job-groups-bar-1"
- do:
    ml.get_jobs:
      job_id: "foo-group"
    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: 2
- match:
    jobs.0.job_id: "test-job-groups-foo-1"
- match:
    jobs.1.job_id: "test-job-groups-foo-2"
- do:
    ml.get_jobs:
      job_id: "bar-group"
    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: 2
- match:
    jobs.0.job_id: "test-job-groups-bar-1"
- match:
    jobs.1.job_id: "test-job-groups-bar-2"
- do:
    ml.get_jobs:
      job_id: "ones"
    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: 2
- match:
    jobs.0.job_id: "test-job-groups-bar-1"
- match:
    jobs.1.job_id: "test-job-groups-foo-1"
- do:
    ml.get_jobs:
      job_id: "twos"
    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: 2
- match:
    jobs.0.job_id: "test-job-groups-bar-2"
- match:
    jobs.1.job_id: "test-job-groups-foo-2"
- do:
    ml.get_jobs:
      job_id: "*-group"
    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: 4
- match:
    jobs.0.job_id: "test-job-groups-bar-1"
- match:
    jobs.1.job_id: "test-job-groups-bar-2"
- match:
    jobs.2.job_id: "test-job-groups-foo-1"
- match:
    jobs.3.job_id: "test-job-groups-foo-2"
- do:
    ml.get_jobs:
      job_id: "bar-group,test-job-groups-nogroup"
    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: 3
- match:
    jobs.0.job_id: "test-job-groups-bar-1"
- match:
    jobs.1.job_id: "test-job-groups-bar-2"
- match:
    jobs.2.job_id: "test-job-groups-nogroup"
---
Test get job stats API:
- do:
    ml.get_job_stats:
      job_id: "foo-group"
    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: 2
- match:
    jobs.0.job_id: "test-job-groups-foo-1"
- match:
    jobs.1.job_id: "test-job-groups-foo-2"
---
Test close job API:
- do:
    ml.open_job:
      job_id: "test-job-groups-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: "test-job-groups-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.get_job_stats:
      job_id: "ones"
    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: 2
- match:
    jobs.0.job_id: "test-job-groups-bar-1"
- match:
    jobs.0.state: "opened"
- match:
    jobs.1.job_id: "test-job-groups-foo-1"
- match:
    jobs.1.state: "opened"
- do:
    ml.close_job:
      job_id: "ones"
    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_job_stats:
      job_id: "ones"
    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: 2
- match:
    jobs.0.job_id: "test-job-groups-bar-1"
- match:
    jobs.0.state: "closed"
- match:
    jobs.1.job_id: "test-job-groups-foo-1"
- match:
    jobs.1.state: "closed"
