Skip to content

Commit 3402cba

Browse files
author
Benoit Moussaud
committed
implement snapshot
1 parent 958a081 commit 3402cba

File tree

11 files changed

+477
-109
lines changed

11 files changed

+477
-109
lines changed

build.gradle

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,65 @@
11
import org.apache.tools.ant.filters.ReplaceTokens
22

33
plugins {
4-
id "com.github.hierynomus.license" version "0.14.0"
5-
id "com.xebialabs.xldp" version "1.0.5"
6-
id 'nebula.release' version '6.0.0'
7-
id "com.xebialabs.xl.docker" version "1.1.0"
4+
id "com.github.hierynomus.license" version "0.13.0"
5+
id "com.github.hierynomus.jython" version "0.8.0"
6+
id "java"
87
}
98

9+
10+
sourceSets.main.resources.srcDirs += ["src/main/jython"]
11+
sourceSets.test.resources.srcDirs += ["src/test/jython"]
12+
1013
apply plugin: 'eclipse'
1114
apply plugin: 'idea'
1215
apply plugin: 'java'
1316
apply plugin: 'maven'
1417

1518
repositories {
16-
mavenLocal()
17-
mavenCentral()
18-
maven {
19-
url 'https://dist.xebialabs.com/public/maven2'
20-
}
19+
mavenLocal()
20+
mavenCentral()
21+
maven {
22+
url 'https://dist.xebialabs.com/public/maven2'
23+
}
2124
}
2225

2326

24-
version = "1.0.0"
27+
dependencies {
2528

26-
// sourceCompatibility = 1.7
27-
// targetCompatibility = 1.7
28-
29-
xlDocker {
30-
compileImage = 'xebialabs/xlr_dev_compile'
31-
compileVersion = 'v7.2.0.2'
32-
runImage = 'xebialabs/xlr_dev_run'
33-
runVersion = 'v7.2.0.1'
34-
runPortMapping = '15516:5516'
29+
jython ":requests:2.13.0"
30+
jython python(":six:1.11.0") {
31+
useModuleName = false
32+
copy {
33+
from "six.py"
34+
}
35+
}
3536
}
3637

38+
version = "1.0.0"
39+
40+
3741
if (!project.hasProperty('release.scope')) {
38-
project.ext['release.scope'] = 'patch'
42+
project.ext['release.scope'] = 'patch'
3943
}
4044

4145
if (!project.hasProperty('release.useLastTag')) {
42-
project.ext['release.useLastTag'] = true
46+
project.ext['release.useLastTag'] = true
4347
}
4448

4549
processResources.configure {
46-
filter ReplaceTokens, tokens: [
47-
'project.version': version.toString(),
48-
'project.name' : rootProject.name
49-
]
50+
filter ReplaceTokens, tokens: [
51+
'project.version': version.toString(),
52+
'project.name' : rootProject.name
53+
]
5054
}
5155

5256
license {
53-
header rootProject.file('License.md')
54-
strictCheck true
55-
ext.year = Calendar.getInstance().get(Calendar.YEAR)
56-
ext.name = 'XEBIALABS'
57+
header rootProject.file('License.md')
58+
strictCheck false
59+
ignoreFailures true
60+
excludes(["**/*.json", "**/requests/*", "**/responses/**", "**/logback-test.xml", "**/build/jython/**"])
61+
ext.year = Calendar.getInstance().get(Calendar.YEAR)
62+
ext.name = 'XEBIALABS'
5763
}
5864

5965

60-
61-
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
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+
166+
167+
client = DelphixClient(server)
168+
client.refresh(vdb)

0 commit comments

Comments
 (0)