Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Add IS constraint operator #5587

Closed
wants to merge 10 commits into from
Closed
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 79 additions & 1 deletion docs/docs/constraints.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ Constraints control where apps run to allow optimizing for either fault toleranc

Entering `hostname` as the field name matches the agent node hostnames. See `UNIQUE operator`, below, for a usage example.

All Marathon operators are supported when the field name is `hostname`.
All Marathon operators are supported when the field name is `hostname`.

### Attribute as field name

@@ -168,3 +168,81 @@ $ curl -X POST -H "Content-type: application/json" localhost:8080/v2/apps -d '{
"constraints": [["rack_id", "GROUP_BY", "3"]]
}'
```

### IN operator

**Value** (required): A Mesos Set, as specified by the [Mesos Attributes and Resources Type Specification](http://mesos.apache.org/documentation/latest/attributes-resources/#types):

```
set : "{" text ( "," text )* "}"

text : [a-zA-Z0-9_/.-]
```

#### Comparing text values

The following example tells Marathon to launch an application on nodes with a rack_id attribute value of `rack-1`, `rack-2`, or `rack-3`.

``` bash
$ curl -X POST -H "Content-type: application/json" localhost:8080/v2/apps -d '{
"id": "sleep-cluster",
"cmd": "sleep 60",
"instances": 3,
"constraints": [["rack_id", "IN", "{rack-1,rack-2,rack-3}"]]
}'
```

#### Comparing scalar values

Scalar values are compared to the nearest thousandth (using half-even rounding strategy).

Given a node with attribute "level:0.8", the following constraints would match:

``` json
[["level", "IN", "{0.8,...}"]]

[["level", "IN", "{0.80,...}"]]

[["level", "IN", "{0.8001,...}"]]
```

### IS operator

**Value** (required): A Mesos Scalar or Text value, as specified by the [Mesos Attributes and Resources Type Specification](http://mesos.apache.org/documentation/latest/attributes-resources/#types):

```
scalar : floatValue

floatValue : ( intValue ( "." intValue )? ) | ...

intValue : [0-9]+

text : [a-zA-Z0-9_/.-]
```

#### Comparing text values

When an `IS` constraint is specified, a task is only launched on nodes that have the specified attribute value. Note that `IS` behaves similar to `CLUSTER` with a value, and has been added mostly for semantic value (except its behavior differs when comparing scalars).

``` bash
$ curl -X POST -H "Content-type: application/json" localhost:8080/v2/apps -d '{
"id": "sleep-cluster",
"cmd": "sleep 60",
"instances": 3,
"constraints": [["", "IS", "rack-1"]]
}'
```

#### Comparing scalar values

When comparing scalars, the value is compared to the nearest thousandth (using half-even rounding strategy)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^Period at the end of the sentence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Given a node with attribute "level:0.8", the following constraints would match:

``` json
[["level", "IS", "0.8"]]

[["level", "IS", "0.80"]]

[["level", "IS", "0.8001"]]
```
2 changes: 1 addition & 1 deletion docs/docs/rest-api/public/api/v2/types/constraint.raml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ uses:
types:
ConstraintOperator:
type: string
enum: [UNIQUE, CLUSTER, GROUP_BY, LIKE, UNLIKE, MAX_PER]
enum: [UNIQUE, CLUSTER, GROUP_BY, LIKE, UNLIKE, MAX_PER, IN, IS]
Constraint:
type: object
properties:
Loading