Skip to content

Commit 3bbc4fd

Browse files
author
Adam Cox
committed
Adds support for Stocator driver (swift2d).
1 parent 64f3f3f commit 3bbc4fd

File tree

4 files changed

+119
-2
lines changed

4 files changed

+119
-2
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.0.1b0 (2016-03-17)
2+
====================
3+
4+
- [NEW] Added support for Stocator driver to connect to Swift Object Stores
5+
16
0.0.1a1 (2016-03-02)
27
====================
38

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Use this when trying to access data on either a Softlayer or Bluemix ObjectStore
44

55

66
### Bluemix
7+
8+
#### Using Swift Driver
79
```python
810
import ibmos2spark as os2s
911

@@ -26,8 +28,35 @@ bmos = os2s.bluemix(sc, credentials) #sc is the SparkContext instance
2628
data = sc.textFile(bmos.url(container_name, file_name))
2729
```
2830

31+
#### Using Stocator (Swift2d) Driver
32+
33+
```python
34+
import ibmos2spark as os2s
35+
36+
#To obtain these credentials in IBM Spark, click the "insert to code"
37+
#button below your data source found on the panel to the right of your notebook.
38+
39+
credentials = {
40+
'auth_url': 'https://identity.open.softlayer.com', #your URL might be different
41+
'project_id': 'sssssssss',
42+
'region': 'dallas',
43+
'user_id': 'uuuuuuuuuuu',
44+
'username': 'uuuuuuuuuuu',
45+
'password': 'ppppppppppp',
46+
}
47+
48+
credentials['name'] = 'my_bluemix_os' #you can give any name you like
49+
50+
bmos = os2s.bluemix2d(sc, credentials) #sc is the SparkContext instance
51+
52+
data = sc.textFile(bmos.url(container_name, file_name))
53+
```
54+
2955

3056
### Softlayer
57+
58+
#### Using Swift Driver
59+
3160
```python
3261
import ibmos2spark as os2s
3362

@@ -41,3 +70,17 @@ slos = os2s.softlayer(sc, "my_softlayer_os", auth_url, username, password)
4170
data = sc.textFile(slos.url(container_name, file_name))
4271
```
4372

73+
#### Using Stocator (Swift2d) Driver
74+
75+
```python
76+
import ibmos2spark as os2s
77+
78+
#you need to know the credentials to your Softlayer ObjectStore.
79+
80+
#sc is the SparkContext instance
81+
#you can give any name you like
82+
83+
slos = os2s.softlayer2d(sc, "my_softlayer_os", auth_url, tenant, username, password)
84+
85+
data = sc.textFile(slos.url(container_name, file_name))
86+
```

ibmOS2Spark/osconfig.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
def swifturl(name, container_name, object_name):
2121
return 'swift://{}.{}/{}'.format(container_name, name, object_name)
2222

23+
def swifturl2d(name, container_name, object_name):
24+
return 'swift2d://{}.{}/{}'.format(container_name, name, object_name)
25+
2326
class softlayer(object):
2427

2528
def __init__(self, sparkcontext, name, auth_url, username, password):
@@ -47,7 +50,36 @@ def __init__(self, sparkcontext, name, auth_url, username, password):
4750

4851
def url(self, container_name, object_name):
4952
return swifturl(self.name, container_name, object_name)
50-
53+
54+
class softlayer2d(object):
55+
56+
def __init__(self, sparkcontext, name, auth_url, tenant, username, password):
57+
'''
58+
sparkcontext is a SparkContext object.
59+
name is a string that can be anything other than an empty string.
60+
auth_url, username and password are string credentials for your
61+
Softlayer Objectstore
62+
63+
'''
64+
self.name = name
65+
66+
prefix = "fs.swift2d.service." + name
67+
hconf = sparkcontext._jsc.hadoopConfiguration()
68+
hconf.set(prefix + ".auth.url", auth_url)
69+
hconf.set(prefix + ".username", username)
70+
hconf.set(prefix + ".tenant", tenant)
71+
hconf.set(prefix + ".auth.endpoint.prefix", "endpoints")
72+
hconf.set(prefix + ".auth.method", "swiftauth")
73+
hconf.setInt(prefix + ".http.port", 8080)
74+
hconf.set(prefix + ".apikey", password)
75+
hconf.setBoolean(prefix + ".public", True)
76+
hconf.set(prefix + ".use.get.auth", "true")
77+
hconf.setBoolean(prefix + ".location-aware", False)
78+
hconf.set(prefix + ".password", password)
79+
80+
def url(self, container_name, object_name):
81+
return swifturl2d(self.name, container_name, object_name)
82+
5183
class bluemix(object):
5284

5385
def __init__(self, sparkcontext, credentials):
@@ -84,3 +116,40 @@ def __init__(self, sparkcontext, credentials):
84116
def url(self, container_name, object_name):
85117
return swifturl(self.name, container_name, object_name)
86118

119+
class bluemix2d(object):
120+
121+
def __init__(self, sparkcontext, credentials):
122+
'''
123+
sparkcontext is a SparkContext object.
124+
125+
credentials is a dictionary with the following required keys:
126+
name
127+
auth_url
128+
project_id
129+
user_id
130+
password
131+
region
132+
133+
When using this from a IBM Spark service instance that
134+
is configured to connect to particular Bluemix object store
135+
instances, the values for these credentials can be obtained
136+
by clicking on the 'insert to code' link just below a data
137+
source.
138+
'''
139+
self.name = credentials['name']
140+
141+
142+
prefix = "fs.swift2d.service." + credentials['name']
143+
hconf = sparkcontext._jsc.hadoopConfiguration()
144+
hconf.set(prefix + ".auth.url", credentials['auth_url']+'/v3/auth/tokens')
145+
hconf.set(prefix + ".auth.endpoint.prefix", "endpoints")
146+
hconf.set(prefix + ".auth.method","keystoneV3 ")
147+
hconf.set(prefix + ".tenant", credentials['project_id'])
148+
hconf.set(prefix + ".username", credentials['user_id'])
149+
hconf.set(prefix + ".password", credentials['password'])
150+
hconf.setInt(prefix + ".http.port", 8080)
151+
hconf.set(prefix + ".region", credentials['region'])
152+
hconf.setBoolean(prefix + ".public", True)
153+
154+
def url(self, container_name, object_name):
155+
return swifturl2d(self.name, container_name, object_name)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
'include_package_data': True,
2828
'install_requires': [],
2929
'name': 'ibmos2spark',
30-
'version': '0.0.1a1',
30+
'version': '0.0.1b0',
3131
'author': 'gadamc',
3232
'author_email': '[email protected]',
3333
'url': 'https://github.com/gadamc/ibmos2spark',

0 commit comments

Comments
 (0)