Skip to content
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

Creating Multiple Apps in Same Runtime / Community Proposal / Feedback Welcome #31

Open
j12y opened this issue Apr 6, 2018 · 0 comments

Comments

@j12y
Copy link
Member

j12y commented Apr 6, 2018

Context

It is not uncommon for somebody to want to work with more than one instance of a single type of service. For example, migrating data from one instance of Time Series to a second instance of Time Series.

app1 = predix.admin.app.Manifest('man1.yml')
app2 = predix.admin.app.Manifest('man2.yml')
ts1 = app1.get_timeseries()
ts2 = app2.get_timeseries()

Result

Both app1 and app2 will return the time series service instance as defined by app2.

What Happened?

To mimic behavior of Cloud Foundry VCAP services, the initialization of a Manifest app loads any environment variables into the runtime. The second app will overwrite those environment variables when the same type of service exists in both. For example, PREDIX_DATA_TIMESERIES_QUERY_URI from app2 will replace the value defined for app1.

When you call get_timeseries() the environment is inspected for VCAP or PREDIXPY environment variables to initialize the object.

Workaround

You can simply re-order operations to work around this.

app1 = predix.admin.app.Manifest('man1.yml')
ts1 = app1.get_timeseries()

app2 = predix.admin.app.Manifest('man2.yml')
ts2 = app2.get_timeseries()

How to fix it?

My proposal is that there really should only be one app per process. When trying to initialize app2 an exception would be raised after detecting app1. This will prevent overwriting any envrionment variables.

An expectation was that when you wanted to use more than one service, the predix.app.Manifest() may not be the best fit. You can just initialize the underlying objects directly and pull environment variables from wherever it makes sense to you -- different environment variables, configuration files, magic, etc.

import predix.data.timeseries
ts2 = predix.data.timeseries.TimeSeries(
        query_uri=uri_out, query_zone_id=zone_id_out,
        ingest_uri=uri_out, ingest_zone_id=zone_id_out,
        )

A second approach would be to create a new configuration system to be an alternative to the predix.app.Manifest(). Something like predix.app.CommonConfig() which would be a more complex configuration file but commonly shared by other language SDKs (java, javascript, etc.)

Community feedback is welcome.

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

No branches or pull requests

1 participant