Skip to content

Commit 4752fb1

Browse files
author
Benoit Moussaud
committed
Refresh, Rewind and Snapshot
1 parent 3402cba commit 4752fb1

File tree

7 files changed

+248
-311
lines changed

7 files changed

+248
-311
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ supervisord.*
55
xl-release-7.6.1-server
66
*.iml
77
.idea
8+
*.pyc
89

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
#
2+
# Copyright 2018 XEBIALABS
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
#
6+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
#
10+
11+
import requests
12+
import json
13+
14+
15+
class DelphixClient:
16+
17+
def __init__(self, server):
18+
self.server = server
19+
self.cookies = self.get_session()
20+
21+
def get_session(self):
22+
print('- open session on {0}'.format(self.server['url']))
23+
headers = {'Content-type': 'application/json'}
24+
data = {
25+
"type": "APISession",
26+
"version": {
27+
"type": "APIVersion",
28+
"major": 1,
29+
"minor": 8,
30+
"micro": 2
31+
}
32+
}
33+
34+
r = requests.post('{0}/resources/json/delphix/session'.format(self.server['url']),
35+
headers=headers,
36+
data=json.dumps(data))
37+
return r.cookies
38+
39+
def _login(self):
40+
print('- login')
41+
headers = {'Content-type': 'application/json'}
42+
data = {
43+
"type": "LoginRequest",
44+
"username": self.server['username'],
45+
"password": self.server['password'],
46+
}
47+
r = requests.post('{0}/resources/json/delphix/login'.format(self.server['url']),
48+
headers=headers,
49+
cookies=self.cookies,
50+
data=json.dumps(data))
51+
52+
if self._response_ok(r):
53+
print("- Authenticated ! ")
54+
else:
55+
raise self._response_error(r)
56+
return r.text
57+
58+
def _logout(self):
59+
print('- logout')
60+
headers = {'Content-type': 'application/json'}
61+
r = requests.post('{0}/resources/json/delphix/logout'.format(self.server['url']),
62+
headers=headers,
63+
cookies=self.cookies)
64+
65+
return r.text
66+
67+
def _get_params(self, vdb):
68+
result = {'ref': 'XXXX', 'cont': 'YYYY', 'vsrc': 'ZZZZ'}
69+
print('- get params')
70+
headers = {'Content-type': 'application/json'}
71+
72+
r = requests.get('{0}/resources/json/delphix/database'.format(self.server['url']),
73+
headers=headers,
74+
cookies=self.cookies)
75+
76+
for db in r.json()['result']:
77+
if db['name'] == vdb:
78+
result['ref'] = db['reference']
79+
result['cont'] = db['provisionContainer']
80+
81+
r = requests.get('{0}/resources/json/delphix/source'.format(self.server['url']),
82+
headers=headers,
83+
cookies=self.cookies)
84+
85+
for db in r.json()['result']:
86+
if db['name'] == vdb:
87+
result['vsrc'] = db['reference']
88+
89+
print('- database reference {ref}'.format(**result))
90+
print('- database provisionContainer {cont}'.format(**result))
91+
print('- source reference {vsrc}'.format(**result))
92+
return result
93+
94+
def _refresh(self, vdb):
95+
parameters = self._get_params(vdb=vdb)
96+
print("- refresh ")
97+
headers = {'Content-type': 'application/json'}
98+
data = {
99+
"type": "OracleRefreshParameters",
100+
"timeflowPointParameters": {
101+
"type": "TimeflowPointSemantic",
102+
"container": parameters['cont'],
103+
"location": "LATEST_SNAPSHOT"
104+
}
105+
}
106+
107+
r = requests.post(
108+
'{0}/resources/json/delphix/database/{1}/refresh'.format(self.server['url'], parameters['ref']),
109+
headers=headers,
110+
cookies=self.cookies,
111+
data=json.dumps(data))
112+
if self._response_ok(r):
113+
print("- Job {0}".format(r.json()['job']))
114+
print("- Action {0}".format(r.json()['action']))
115+
return {'job': r.json()['job'], 'action': r.json()['action']}
116+
else:
117+
raise self._response_error(r)
118+
119+
def _rewind(self, vdb):
120+
parameters = self._get_params(vdb=vdb)
121+
print("- rewind ")
122+
headers = {'Content-type': 'application/json'}
123+
data = {
124+
"type": "OracleRollbackParameters",
125+
"timeflowPointParameters": {
126+
"type": "TimeflowPointSemantic",
127+
"container": parameters['cont'],
128+
129+
}
130+
}
131+
132+
r = requests.post(
133+
'{0}/resources/json/delphix/database/{1}/rollback'.format(self.server['url'], parameters['ref']),
134+
headers=headers,
135+
cookies=self.cookies,
136+
data=json.dumps(data))
137+
if self._response_ok(r):
138+
print("- Job {0}".format(r.json()['job']))
139+
print("- Action {0}".format(r.json()['action']))
140+
return {'job': r.json()['job'], 'action': r.json()['action']}
141+
else:
142+
raise self._response_error(r)
143+
144+
def _snapshot(self, vdb):
145+
parameters = self._get_params(vdb=vdb)
146+
print("- snapshot ")
147+
headers = {'Content-type': 'application/json'}
148+
data = {
149+
"type": "OracleSyncParameters"
150+
}
151+
152+
r = requests.post(
153+
'{0}/resources/json/delphix/database/{1}/sync'.format(self.server['url'], parameters['ref']),
154+
headers=headers,
155+
cookies=self.cookies,
156+
data=json.dumps(data))
157+
158+
if self._response_ok(r):
159+
print("- Job {0}".format(r.json()['job']))
160+
print("- Action {0}".format(r.json()['action']))
161+
return {'job': r.json()['job'], 'action': r.json()['action']}
162+
else:
163+
raise self._response_error(r)
164+
165+
def _response_ok(self, r):
166+
return r.status_code == 200 and r.json()['type'] == 'OKResult'
167+
168+
def _response_error(self, r):
169+
return Exception(r.text)
170+
171+
def refresh(self, vdb):
172+
self._login()
173+
print("- Refresh {0} with Delphix".format(vdb))
174+
self._refresh(vdb)
175+
self._logout()
176+
177+
def snapshot(self, vdb):
178+
self._login()
179+
print("- Snapshot {0} with Delphix".format(vdb))
180+
self._snapshot(vdb)
181+
self._logout()
182+
183+
def rewind(self, vdb):
184+
self._login()
185+
print("- Rewind {0} with Delphix".format(vdb))
186+
self._rewind(vdb)
187+
self._logout()

src/main/resources/delphix/Refresh.py

Lines changed: 9 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -7,162 +7,16 @@
77
#
88
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
99
#
10+
if __name__ == '__main__':
11+
import sys
1012

13+
sys.path.append('/Users/bmoussaud/Workspace/xebialabs-community/xlr-delphix-plugin/src/main/resources')
14+
server = {'url': 'http://ba5b5824.ngrok.io', 'username': 'delphix_admin', 'password': 'landshark'}
15+
vdb = 'ITIM'
1116

12-
import requests
13-
import json
14-
15-
16-
class DelphixClient:
17-
18-
def __init__(self, server):
19-
self.server = server
20-
self.cookies = self.get_session()
21-
22-
def get_session(self):
23-
print('- open session on {0}'.format(self.server['url']))
24-
headers = {'Content-type': 'application/json'}
25-
data = {
26-
"type": "APISession",
27-
"version": {
28-
"type": "APIVersion",
29-
"major": 1,
30-
"minor": 8,
31-
"micro": 2
32-
}
33-
}
34-
35-
print("-- post")
36-
37-
r = requests.post('{0}/resources/json/delphix/session'.format(self.server['url']),
38-
headers=headers,
39-
data=json.dumps(data))
40-
print(r.status_code)
41-
print("-- response")
42-
print(r.text)
43-
return r.cookies
44-
45-
def _login(self):
46-
print('- login -')
47-
headers = {'Content-type': 'application/json'}
48-
data = {
49-
"type": "LoginRequest",
50-
"username": self.server['username'],
51-
"password": self.server['password'],
52-
}
53-
54-
print("-- post")
55-
r = requests.post('{0}/resources/json/delphix/login'.format(self.server['url']),
56-
headers=headers,
57-
cookies=self.cookies,
58-
data=json.dumps(data))
59-
print(r.status_code)
60-
print("-- response")
61-
return r.text
62-
63-
def _logout(self):
64-
print('- logout -')
65-
headers = {'Content-type': 'application/json'}
66-
print("-- post")
67-
r = requests.post('{0}/resources/json/delphix/logout'.format(self.server['url']),
68-
headers=headers,
69-
cookies=self.cookies)
70-
print(r.status_code)
71-
print("-- response")
72-
print(r.text)
73-
return r.text
74-
75-
def _get_params(self, vdb):
76-
result = {'ref': 'XXXX', 'cont': 'YYYY', 'vsrc': 'ZZZZ'}
77-
print('- get params')
78-
headers = {'Content-type': 'application/json'}
79-
80-
r = requests.get('{0}/resources/json/delphix/database'.format(self.server['url']),
81-
headers=headers,
82-
cookies=self.cookies)
83-
84-
for db in r.json()['result']:
85-
if db['name'] == vdb:
86-
result['ref'] = db['reference']
87-
result['cont'] = db['provisionContainer']
88-
89-
r = requests.get('{0}/resources/json/delphix/source'.format(self.server['url']),
90-
headers=headers,
91-
cookies=self.cookies)
92-
93-
for db in r.json()['result']:
94-
if db['name'] == vdb:
95-
result['vsrc'] = db['reference']
96-
97-
return result
98-
99-
def _refresh(self, vdb):
100-
parameters = self._get_params(vdb=vdb)
101-
print("- refresh ")
102-
headers = {'Content-type': 'application/json'}
103-
data = {
104-
"type": "OracleRefreshParameters",
105-
"timeflowPointParameters": {
106-
"type": "TimeflowPointSemantic",
107-
"container": parameters['cont'],
108-
"location": "LATEST_SNAPSHOT"
109-
}
110-
}
111-
112-
r = requests.post(
113-
'{0}/resources/json/delphix/database/{1}/refresh'.format(self.server['url'], parameters['ref']),
114-
headers=headers,
115-
cookies=self.cookies,
116-
data=json.dumps(data))
117-
print(r.status_code)
118-
print("- response {0}".format(r.json()))
119-
120-
if self._response_ok(r):
121-
print("- Job {0}".format(r.json()['job']))
122-
print("- Action {0}".format(r.json()['action']))
123-
else:
124-
raise RuntimeException(self._response_error(r))
125-
126-
def _snapshot(self, vdb):
127-
parameters = self._get_params(vdb=vdb)
128-
print("- refresh ")
129-
headers = {'Content-type': 'application/json'}
130-
data = {
131-
"type": "OracleSyncParameters"
132-
}
133-
134-
r = requests.post(
135-
'{0}/resources/json/delphix/database/{1}/sync'.format(self.server['url'], parameters['ref']),
136-
headers=headers,
137-
cookies=self.cookies,
138-
data=json.dumps(data))
139-
print(r.status_code)
140-
print("- response {0}".format(r.json()))
141-
142-
if self._response_ok(r):
143-
print("- Job {0}".format(r.json()['job']))
144-
print("- Action {0}".format(r.json()['action']))
145-
else:
146-
raise RuntimeException(self._response_error(r))
147-
148-
def _response_ok(self, r):
149-
return r.status_code == 200 and r.json()['type'] == 'OKResult'
150-
151-
def _response_error(self, r):
152-
return r.text
153-
154-
def refresh(self, vdb):
155-
self._login()
156-
print("Refresh {0} with Delphix".format(vdb))
157-
self._refresh(vdb)
158-
self._logout()
159-
160-
def snapshot(self, vdb):
161-
self._login()
162-
print("Snapshot {0} with Delphix".format(vdb))
163-
self._snapshot(vdb)
164-
self._logout()
165-
17+
from delphix.DelphixClient import DelphixClient
16618

16719
client = DelphixClient(server)
168-
client.refresh(vdb)
20+
output = client.refresh(vdb)
21+
job = output['job']
22+
action = output['action']
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Copyright 2018 XEBIALABS
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
#
6+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
#
10+
if __name__ == '__main__':
11+
import sys
12+
13+
sys.path.append('/Users/bmoussaud/Workspace/xebialabs-community/xlr-delphix-plugin/src/main/resources')
14+
server = {'url': 'http://ba5b5824.ngrok.io', 'username': 'delphix_admin', 'password': 'landshark'}
15+
vdb = 'ITIM'
16+
17+
from delphix.DelphixClient import DelphixClient
18+
19+
client = DelphixClient(server)
20+
client.rewind(vdb)
21+
job = output['job']
22+
action = output['action']

0 commit comments

Comments
 (0)