-
Notifications
You must be signed in to change notification settings - Fork 3
/
serverman.py
240 lines (176 loc) · 7.78 KB
/
serverman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import requests
import json
CLOUDFACACE_URL = "https://vph.cyfronet.pl/cloudfacade"
class TavernaServerManager():
""" The TavernaServerManager allows the creation and destruction of a workflow with a Taverna Server AS running on it """
test = False
def __init__(self, atomicServiceId, workflowId = "", webendpoint="", atomicServiceConfigId="" ):
""" Initializes a new TS Manager
Arguments:
atomicServiceId (string): the cloudfacade id of the AS with the Taverna Server
workflowId (string): the workflow id of an already existing workflow with a Taverna Server, omit it if a new workflow will be created
webendpoint (string): the web endpoint of an already existing Taverna Server, omit it if a new Taverna Server will be created
atomicServiceConfigId (string): the configuration id of an already existing AS in a Taverna Server workflow, omit it if a new AS will be created
"""
self.workflowId = workflowId
self.atomicServiceConfigId = atomicServiceConfigId
self.atomicServiceId = atomicServiceId
self.webendpoint = webendpoint
def createTavernaServerWorkflow(self, ticket):
""" Creates a new workflow, which will contain a taverna server AS
Arguments:
ticket (string): a valid authentication ticket
Returns:
dictionary::
Success -- {'workflowId':'a string value'}
Failure -- {'workflowId':'', 'error.description':'', error.code:''}
"""
ret = {}
try:
body = json.dumps({'name': "tavernaserverworkflow", 'type': "workflow"})
con = requests.post(
"%s/workflows" % CLOUDFACACE_URL,
auth=("", ticket),
data = body,
verify = False
)
if con.status_code != 200:
ret["workflowId"] = ""
ret["error.description"] = "Error creating Taverna Server workflow"
ret["error.code"] = con.status_code
ret["workflowId"] = con.text
self.workflowId = con.text
except Exception as e:
ret["workflowId"] = ""
ret["error.description"] = "Error creating Taverna Server workflow"
ret["error.code"] = e
return ret
def deleteTavernaServerWorkflow(self, ticket):
""" Deletes the workflow containing the taverna server AS
Arguments:
ticket (string): a valid authentication ticket
Returns:
dictionary::
Success -- {'workflowId':'a string value'}
Failure -- {'workflowId':'', 'error.description':'', error.code:''}
"""
ret = {}
try:
ret["workflowId"] = self.workflowId
con = requests.delete(
"%s/workflows/%s" % (CLOUDFACACE_URL, self.workflowId),
auth=("", ticket),
verify = False
)
if con.status_code != 200 and con.status_code != 204:
ret["workflowId"] = ""
ret["error.description"] = "Error deleting workflow " + self.workflowId
ret["error.code"] = con.status_code
except Exception as e:
ret["workflowId"] = ""
ret["error.description"] = "Error deleting workflow " + self.workflowId
ret["error.code"] = e
return ret
def getTavernaServerAtomicServiceConfigId(self, ticket):
""" Retrieves the service configuration Id of the taverna server AS
Arguments:
ticket (string): a valid authentication ticket
Returns:
dictionary::
Success -- {'asConfigId':'a string value'}
Failure -- {'asConfigId':'', 'error.description':'', error.code:''}
"""
ret = {}
try:
con = requests.get(
"%s/atomic_services/%s/configurations" % (CLOUDFACACE_URL, self.atomicServiceId),
auth=("", ticket),
verify = False
)
if con.status_code != 200:
ret["asConfigId"] = ""
ret["error.description"] = "Error getting configuration Id for AS " + self.atomicServiceId
ret["error.code"] = con.status_code
json = con.json()
ret["asConfigId"] = json[0]["id"]
except Exception as e:
print e
ret["asConfigId"] = ""
ret["error.description"] = "Error getting configuration Id for AS " + self.atomicServiceId
ret["error.code"] = e
return ret
def startTavernaServer(self, ticket):
""" Adds the taverna server AS to the workflow
Arguments:
ticket (string): a valid authentication ticket
Returns:
dictionary::
Success -- {'workflowId':'a string value'}
Failure -- {'workflowId':'', 'error.description':'', error.code:''}
"""
ret = {}
try:
ret["workflowId"] = self.workflowId
ret_asi = self.getTavernaServerAtomicServiceConfigId(ticket)
self.atomicServiceConfigId = ret_asi["asConfigId"]
body = json.dumps( {'asConfigId': self.atomicServiceConfigId} )
con = requests.post(
"%s/workflows/%s/atomic_services" % (CLOUDFACACE_URL, self.workflowId),
auth=("", ticket),
data = body,
verify = False
)
if con.status_code != 200:
ret["workflowId"] = ""
ret["error.description"] = "Error starting Taverna Server in workflow " + self.workflowId
ret["error.code"] = con.status_code
except Exception as e:
ret["workflowId"] = ""
ret["error.description"] = "Error starting Taverna Server in workflow " + self.workflowId
ret["error.code"] = e
return ret
def getTavernaServerWebEndpoint(self, ticket):
""" Retrieves the web endpoint URL of the taverna server AS managed by this class
Arguments:
ticket (string): a valid authentication ticket
Returns:
dictionary::
Success -- {'endpoint':'a string value'}
Failure -- {'endpoint':'', 'error.description':'', error.code:''}
"""
ret = {}
try:
ret["workflowId"] = self.workflowId
url = "null"
while url.find("null")!=-1:
con = requests.get(
"%s/workflows/%s/atomic_services/%s/redirections" % (CLOUDFACACE_URL, self.workflowId, self.atomicServiceConfigId ),
auth=("", ticket),
verify = False
)
json = con.json()
if json["http"][0]["urls"][0].find("null")==-1:
url = json["http"][0]["urls"][0]
ret["endpoint"] = url
self.webendpoint = url
except Exception as e:
ret["endpoint"] = ""
ret["error.description"] = "Error getting Taverna Server endpoint in workflow " + self.workflowId
ret["error.code"] = e
return ret
def isWebEndpointReady(self, ticket):
""" Checks if the taverna server is running in the endpoint URL
Arguments:
ticket (string): a valid authentication ticket
Returns:
True is a successful connection was made to the endpoint. It returns False otherwise.
"""
if self.webendpoint:
con = requests.get(
self.webendpoint,
auth=("", ticket),
verify = False
)
if con.status_code == 200:
return True
return False;