Skip to content

Commit 104f92c

Browse files
committedMay 6, 2020
Rebrand to Astra
1 parent 1ec3db5 commit 104f92c

7 files changed

+47
-45
lines changed
 

‎README.md

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
# Getting Started with Apollo - Python backend
1+
# Getting Started with Astra - Python backend
22

3-
This sample Python backend provides a REST API service that is used with the [Getting Started with Apollo UI](https://github.com/DataStax-Examples/getting-started-with-apollo-ui) to show a
4-
simple example of how to connect to and query DataStax Apollo databases.
3+
This sample Python backend provides a REST API service that is used with the [Getting Started with Astra UI](https://github.com/DataStax-Examples/getting-started-with-astra-ui) to show a
4+
simple example of how to connect to and query DataStax Astra databases.
55

6-
Contributor(s): [Chris Splinter](https://github.com/csplinter)
6+
Contributor(s):
7+
* [Chris Splinter](https://github.com/csplinter)
8+
* [Madhavan Sridharan](https://github.com/msmygit)
79

810
## Objectives
9-
- How to connect to DataStax Apollo using the secure connect bundle
11+
- How to connect to DataStax Astra using the secure connect bundle
1012
- How to share a DataStax Driver Session throughout a Python application
1113
- How to expose a basic REST API using the DataStax Driver
1214

1315
## Project Layout
14-
- [getting_started_with_apollo.py](getting_started_with_apollo.py) - entrypoint for the backend, registers controller blueprints with Flask app
16+
- [getting_started_with_astra.py](getting_started_with_astra.py) - entrypoint for the backend, registers controller blueprints with Flask app
1517
- [schema.cql](schema.cql) - database schema used by the application
1618
- [service](service/) - acts as the middle-man to take requests from the controllers and calls the corresponding dao methods.
1719
Note how this and [session_manager.py](dao/session_manager.py) are used to share a single DataStax Driver Session across API requests, this is a best practice.
@@ -20,9 +22,9 @@ Note how this and [session_manager.py](dao/session_manager.py) are used to share
2022
- [controller](controller/) - defines the API endpoints using Flask decorators
2123

2224
## How this works
23-
This project is built in Python and uses Flask to expose a REST API backend for use with the [Getting Started with Apollo UI](https://github.com/DataStax-Examples/getting-started-with-apollo-ui).
25+
This project is built in Python and uses Flask to expose a REST API backend for use with the [Getting Started with Astra UI](https://github.com/DataStax-Examples/getting-started-with-astra-ui).
2426

25-
This application is the middle man that receives requests from the UI web page and serves data from the underlying DataStax Apollo database.
27+
This application is the middle man that receives requests from the UI web page and serves data from the underlying DataStax Astra database.
2628

2729
## Setup & Running
2830

@@ -31,7 +33,7 @@ If you are familiar with Python, then you've likely gotten your hands on Python
3133
We'll be leveraging pyenv while setting up this backend, which will serve our
3234
Spacecraft frontend that will have you flying through the stars.
3335

34-
If you aren't familiar with Python, hop over to our [official documentation](https://helpdocs.datastax.com/aws/dscloud/apollo/dscloudPythonDriver.html#Installingpyenv,Python,andvirtualenv)
36+
If you aren't familiar with Python, hop over to our [official documentation](https://helpdocs.datastax.com/aws/dscloud/astra/dscloudPythonDriver.html#Installingpyenv,Python,andvirtualenv)
3537
for setting that up on your machine, and come back here after you have it installed ( specifically after Step 5 of the Procedure ).
3638

3739
Now that we have that out of the way, we'll use pyenv to install Python 3.6.9
@@ -42,13 +44,13 @@ pyenv install 3.6.9
4244
Next create a new virtualenv using that Python version we just installed.
4345

4446
```
45-
pyenv virtualenv 3.6.9 apollo-venv
47+
pyenv virtualenv 3.6.9 astra-venv
4648
```
4749

4850
Almost off to the races, go ahead and activate that virtualenv
4951

5052
```
51-
pyenv activate apollo-venv
53+
pyenv activate astra-venv
5254
```
5355

5456
Woot, now 3 quick dependencies ( Flask, Flask CORS, and the DataStax Cassandra Driver )
@@ -60,25 +62,25 @@ pip install Flask flask-cors cassandra-driver
6062
Last one, clone this repo
6163
```
6264
git clone https://github.com/DataStax-Examples
63-
/getting-started-with-apollo-python.git
65+
/getting-started-with-astra-python.git
6466
```
6567

6668
### Running
6769

6870
If everything above went smoothly, fingers crossed, then we are ready to rock.
6971
Go to the directory that you just cloned this repo into
7072
```
71-
cd getting-started-with-apollo-python
73+
cd getting-started-with-astra-python
7274
```
7375

7476
Fire up the engines
7577
```
76-
FLASK_ENV=development FLASK_APP=getting_started_with_apollo.py flask run
78+
FLASK_ENV=development FLASK_APP=getting_started_with_astra.py flask run
7779
```
7880

7981
You should be met with the following output, note that it's running on `localhost` and port `5000`
8082
```
81-
* Serving Flask app "getting_started_with_apollo.py" (lazy loading)
83+
* Serving Flask app "getting_started_with_astra.py" (lazy loading)
8284
* Environment: development
8385
* Debug mode: on
8486
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
@@ -87,4 +89,4 @@ You should be met with the following output, note that it's running on `localhos
8789
* Debugger PIN: 204-527-831
8890
```
8991

90-
Once the backend is running, you can start the [Getting Started with Apollo UI](https://github.com/DataStax-Examples/getting-started-with-apollo-ui) in order to use a web page that leverages this backend.
92+
Once the backend is running, you can start the [Getting Started with Astra UI](https://github.com/DataStax-Examples/getting-started-with-astra-ui) in order to use a web page that leverages this backend.

‎controller/credentials_controller.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from flask import Blueprint, request
33
from flask_cors import CORS
44

5-
from service.apollo_service import apollo_service
5+
from service.astra_service import astra_service
66

77
credentials_controller = Blueprint('credentials_controller', __name__)
88

@@ -11,7 +11,7 @@
1111

1212
# This controller handles the functionality for connecting to the database
1313
#
14-
# Here we define the REST API endpoints and call our Apollo Service
14+
# Here we define the REST API endpoints and call our Astra Service
1515
# to send the request to the underlying Data Access Objects
1616
@credentials_controller.route("/api/credentials", methods=['GET', 'POST'])
1717
def connect():
@@ -22,17 +22,17 @@ def connect():
2222
f.write(request.get_data())
2323

2424
try:
25-
apollo_service.save_credentials(request.args['username'], request.args['password'],
25+
astra_service.save_credentials(request.args['username'], request.args['password'],
2626
request.args['keyspace'], temp_zip_path)
27-
apollo_service.connect()
27+
astra_service.connect()
2828
finally:
2929
os.remove(temp_zip_path)
3030

3131
return {'connected': True}, 200
3232

3333
if request.method == 'GET':
3434

35-
resp = apollo_service.check_connection()
35+
resp = astra_service.check_connection()
3636

3737
if resp is True:
3838
status_code = 200
@@ -54,7 +54,7 @@ def test_credentials():
5454
status_code = 400
5555

5656
try:
57-
test_connection = apollo_service.test_credentials(request.args['username'], request.args['password'],
57+
test_connection = astra_service.test_credentials(request.args['username'], request.args['password'],
5858
request.args['keyspace'], temp_zip_path)
5959
resp = {'success': test_connection}
6060
if resp['success'] is True:

‎controller/spacecraft_instruments_controller.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from flask import Blueprint, request
33
from flask_cors import CORS
44

5-
from service.apollo_service import apollo_service
5+
from service.astra_service import astra_service
66

77
spacecraft_instruments_controller = Blueprint('spacecraft_instruments_controller', __name__)
88

@@ -15,17 +15,17 @@
1515
# spacecraft_speed_over_time
1616
# spacecraft_temperature_over_time
1717
#
18-
# Here we define the REST API endpoints and call our Apollo Service
18+
# Here we define the REST API endpoints and call our Astra Service
1919
# to send the request to the underlying Data Access Objects
2020
@spacecraft_instruments_controller.route('/api/spacecraft/<spacecraft_name>/<journey_id>/instruments/location',
2121
methods=['GET', 'POST'])
2222
def location_reading_for_spacecraft_journey(spacecraft_name, journey_id):
2323
if request.method == 'POST':
24-
apollo_service.save_location_reading_for_spacecraft_journey(spacecraft_name, journey_id, request.get_json())
24+
astra_service.save_location_reading_for_spacecraft_journey(spacecraft_name, journey_id, request.get_json())
2525
return {'success': True}, 200
2626

2727
if request.method == 'GET':
28-
result = apollo_service.get_location_readings_for_spacecraft_journey(spacecraft_name, journey_id,
28+
result = astra_service.get_location_readings_for_spacecraft_journey(spacecraft_name, journey_id,
2929
request.args.get('pagesize', 25),
3030
request.args.get('pagestate', None))
3131

@@ -40,11 +40,11 @@ def location_reading_for_spacecraft_journey(spacecraft_name, journey_id):
4040
methods=['GET', 'POST'])
4141
def pressure_reading_for_spacecraft_journey(spacecraft_name, journey_id):
4242
if request.method == 'POST':
43-
apollo_service.save_pressure_reading_for_spacecraft_journey(spacecraft_name, journey_id, request.get_json())
43+
astra_service.save_pressure_reading_for_spacecraft_journey(spacecraft_name, journey_id, request.get_json())
4444
return {'success': True}, 200
4545

4646
if request.method == 'GET':
47-
result = apollo_service.get_pressure_readings_for_spacecraft_journey(spacecraft_name, journey_id,
47+
result = astra_service.get_pressure_readings_for_spacecraft_journey(spacecraft_name, journey_id,
4848
request.args.get('pagesize', 25),
4949
request.args.get('pagestate', None))
5050

@@ -59,11 +59,11 @@ def pressure_reading_for_spacecraft_journey(spacecraft_name, journey_id):
5959
methods=['GET', 'POST'])
6060
def speed_reading_for_spacecraft_journey(spacecraft_name, journey_id):
6161
if request.method == 'POST':
62-
apollo_service.save_speed_reading_for_spacecraft_journey(spacecraft_name, journey_id, request.get_json())
62+
astra_service.save_speed_reading_for_spacecraft_journey(spacecraft_name, journey_id, request.get_json())
6363
return {'success': True}, 200
6464

6565
if request.method == 'GET':
66-
result = apollo_service.get_speed_readings_for_spacecraft_journey(spacecraft_name, journey_id,
66+
result = astra_service.get_speed_readings_for_spacecraft_journey(spacecraft_name, journey_id,
6767
request.args.get('pagesize', 25),
6868
request.args.get('pagestate', None))
6969

@@ -78,11 +78,11 @@ def speed_reading_for_spacecraft_journey(spacecraft_name, journey_id):
7878
methods=['GET', 'POST'])
7979
def temperature_reading_for_spacecraft_journey(spacecraft_name, journey_id):
8080
if request.method == 'POST':
81-
apollo_service.save_temperature_reading_for_spacecraft_journey(spacecraft_name, journey_id, request.get_json())
81+
astra_service.save_temperature_reading_for_spacecraft_journey(spacecraft_name, journey_id, request.get_json())
8282
return {'success': True}, 200
8383

8484
if request.method == 'GET':
85-
result = apollo_service.get_temperature_readings_for_spacecraft_journey(spacecraft_name, journey_id,
85+
result = astra_service.get_temperature_readings_for_spacecraft_journey(spacecraft_name, journey_id,
8686
request.args.get('pagesize', 25),
8787
request.args.get('pagestate', None))
8888

‎controller/spacecraft_journey_controller.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from flask_cors import CORS
33
from cassandra.util import min_uuid_from_time
44
from datetime import datetime, timedelta
5-
from service.apollo_service import apollo_service
5+
from service.astra_service import astra_service
66

77
spacecraft_journey_controller = Blueprint('spacecraft_journey_controller', __name__)
88

@@ -11,11 +11,11 @@
1111

1212
# This controller handles the all of the GET and POST REST API calls for the spacecraft_journey_catalog table
1313
#
14-
# Here we define the REST API endpoints and call our Apollo Service
14+
# Here we define the REST API endpoints and call our Astra Service
1515
# to send the request to the underlying Data Access Objects
1616
@spacecraft_journey_controller.route('/api/spacecraft')
1717
def get_all_journeys():
18-
result = apollo_service.get_all_spacecraft_journeys()
18+
result = astra_service.get_all_spacecraft_journeys()
1919
return jsonify(result.current_rows), 200
2020

2121

@@ -29,12 +29,12 @@ def journeys_for_spacecraft(spacecraft_name):
2929
active = True
3030
summary = request.get_data(as_text=True)
3131

32-
apollo_service.create_new_journey_for_spacecraft(spacecraft_name, journey_id, start, end, active, summary)
32+
astra_service.create_new_journey_for_spacecraft(spacecraft_name, journey_id, start, end, active, summary)
3333

3434
return str(journey_id), 200
3535

3636
if request.method == 'GET':
37-
result = apollo_service.get_all_journeys_for_spacecraft(spacecraft_name)
37+
result = astra_service.get_all_journeys_for_spacecraft(spacecraft_name)
3838

3939
return jsonify(result.current_rows), 200
4040

‎dao/session_manager.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ def test_credentials(self, username, password, keyspace, secure_connection_bundl
3939
temp_session = None
4040
success = False
4141
try:
42-
# This is how you use the Apollo secure connect bundle to connect to an Apollo database
42+
# This is how you use the Astra secure connect bundle to connect to an Astra database
4343
# note that the database username and password required.
4444
# note that no contact points or any other driver customization is required.
45-
apollo_config = {
45+
astra_config = {
4646
'secure_connect_bundle': secure_connection_bundle_path
4747
}
4848

49-
cluster = Cluster(cloud=apollo_config, auth_provider=PlainTextAuthProvider(username, password))
49+
cluster = Cluster(cloud=astra_config, auth_provider=PlainTextAuthProvider(username, password))
5050

5151
temp_session = cluster.connect(keyspace=keyspace)
5252
result = temp_session.execute(self.ping_query)
@@ -63,14 +63,14 @@ def connect(self):
6363
raise Exception('Please initialize the connection parameters first with SessionManager.save_credentials')
6464

6565
if self._session is None:
66-
# This is how you use the Apollo secure connect bundle to connect to an Apollo database
66+
# This is how you use the Astra secure connect bundle to connect to an Astra database
6767
# note that the database username and password required.
6868
# note that no contact points or any other driver customization is required.
69-
apollo_config = {
69+
astra_config = {
7070
'secure_connect_bundle': self.secure_connect_bundle_path
7171
}
7272

73-
cluster = Cluster(cloud=apollo_config, auth_provider=PlainTextAuthProvider(self.username, self.password))
73+
cluster = Cluster(cloud=astra_config, auth_provider=PlainTextAuthProvider(self.username, self.password))
7474
self._session = cluster.connect(keyspace=self.keyspace)
7575

7676
# have the driver return results as dict
File renamed without changes.

‎service/apollo_service.py ‎service/astra_service.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dao.spacecraft_temperature_dao import SpacecraftTemperatureDAO
77

88

9-
class ApolloService(object):
9+
class AstraService(object):
1010

1111
spacecraft_journey_catalog_dao = None
1212
spacecraft_location_dao = None
@@ -106,4 +106,4 @@ def save_temperature_reading_for_spacecraft_journey(self, spacecraft_name, journ
106106
self.get_spacecraft_temperature_dao().write_readings(spacecraft_name, journey_id, data)
107107

108108

109-
apollo_service = ApolloService()
109+
astra_service = AstraService()

0 commit comments

Comments
 (0)
Failed to load comments.