Skip to content

Zero values in apps/groups doesnt work #75

New issue

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

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

Already on GitHub? Sign in to your account

Closed
Kaydannik opened this issue Jan 27, 2016 · 3 comments
Closed

Zero values in apps/groups doesnt work #75

Kaydannik opened this issue Jan 27, 2016 · 3 comments

Comments

@Kaydannik
Copy link

There is a json output broken.
You cannot use ports=[0], and port_index=0

Lets create simple app, put it in group, and see what we got.

from marathon.models import MarathonApp, MarathonHealthCheck,MarathonObject,MarathonGroup
import json

app = MarathonApp(
    id= '/somegroup/someapp',
    cmd='while true; do nc -l $PORT0;done ',
    cpus=1,
    mem=256,
    instances=1,
    ports=[ 0 ], # YOU ARE HERE!
    health_checks = [ MarathonHealthCheck(command=None,
                                          grace_period_seconds=300,
                                          interval_seconds=60,
                                          max_consecutive_failures=0,
                                          path=None,
                                          port_index=0, # ALSO AT PLACE
                                          protocol='TCP',
                                          timeout_seconds=20) ]
)

print json.dumps(
    json.loads(app.to_json()),
    sort_keys=True,
    indent=4, separators=(',', ': '))


group = MarathonGroup([app], dependencies=None, groups=None, id='/somegroup', version=None)


print json.dumps(
    json.loads(group.to_json()),
    sort_keys=True,
    indent=4, separators=(',', ': '))

Will output

{
    "cmd": "while true; do nc -l $PORT0;done ",
    "cpus": 1,
    "healthChecks": [
        {
            "gracePeriodSeconds": 300,
            "intervalSeconds": 60,
            "protocol": "TCP",
            "timeoutSeconds": 20 #WHERE IS MY PORTINDEX
        }
    ],
    "id": "/somegroup/someapp",
    "instances": 1,
    "mem": 256,
    "ports": [
        0
    ]
}
{
    "apps": [
        {
            "cmd": "while true; do nc -l $PORT0;done ",
            "cpus": 1,
            "healthChecks": [
                {
                    "gracePeriodSeconds": 300,
                    "intervalSeconds": 60,
                    "protocol": "TCP",
                    "timeoutSeconds": 20 #WHERE IS MY PortIndex
                }
            ],
            "id": "/somegroup/someapp",
            "instances": 1,
            "mem": 256,
            "ports": []  #WHERE IS MY PORTS! 
        }
    ],
    "id": "/somegroup"
}


@solarkennedy
Copy link
Contributor

Hmm. This seems kinda strange. My best guess is that this is being lost at the json encoding layer here?

return json.dumps(self.json_repr(minimal=True), cls=MarathonMinimalJsonEncoder, sort_keys=True)

with minimal=True?

@iksaif
Copy link
Contributor

iksaif commented Jan 29, 2016

I can confirm that I have the same issue. The bug is caused by MarathonMinimalJsonEncoder, changing it to this fixes the issue

        if isinstance(obj, collections.Iterable) and not is_stringy(obj):
            try:
                return {k: self.default(v) for k, v in obj.items() if (v or v is False or v is 0)}
            except AttributeError:
                return [self.default(e) for e in obj if (e or e is False or e is 0)]

(-> adding 'is 0')

iksaif pushed a commit to iksaif/marathon-python that referenced this issue Jan 29, 2016
iksaif pushed a commit to iksaif/marathon-python that referenced this issue Jan 29, 2016
@solarkennedy
Copy link
Contributor

Pretty sure this is solved in #79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants