Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
8e781faa
Commit
8e781faa
authored
Nov 01, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added client
parent
9e9ab47b
Changes
29
Show whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
5914 additions
and
1048 deletions
+5914
-1048
pom.xml
drip-commons/pom.xml
+45
-0
ApiKeyAuth.java
...a/sne/drip/commons/sure-tosca/client/auth/ApiKeyAuth.java
+75
-0
Authentication.java
...e/drip/commons/sure-tosca/client/auth/Authentication.java
+29
-0
HttpBasicAuth.java
...ne/drip/commons/sure-tosca/client/auth/HttpBasicAuth.java
+54
-0
OAuth.java
...nl/uva/sne/drip/commons/sure-tosca/client/auth/OAuth.java
+39
-0
OAuthFlow.java
...va/sne/drip/commons/sure-tosca/client/auth/OAuthFlow.java
+18
-0
ApiCallback.java
...l/uva/sne/drip/commons/sure_tosca/client/ApiCallback.java
+61
-0
ApiClient.java
.../nl/uva/sne/drip/commons/sure_tosca/client/ApiClient.java
+1205
-0
ApiException.java
.../uva/sne/drip/commons/sure_tosca/client/ApiException.java
+91
-0
ApiResponse.java
...l/uva/sne/drip/commons/sure_tosca/client/ApiResponse.java
+59
-0
Configuration.java
...uva/sne/drip/commons/sure_tosca/client/Configuration.java
+39
-0
DefaultApi.java
...nl/uva/sne/drip/commons/sure_tosca/client/DefaultApi.java
+2683
-0
GzipRequestInterceptor.java
...rip/commons/sure_tosca/client/GzipRequestInterceptor.java
+81
-0
JSON.java
.../java/nl/uva/sne/drip/commons/sure_tosca/client/JSON.java
+391
-0
Pair.java
.../java/nl/uva/sne/drip/commons/sure_tosca/client/Pair.java
+52
-0
ProgressRequestBody.java
...e/drip/commons/sure_tosca/client/ProgressRequestBody.java
+77
-0
ProgressResponseBody.java
.../drip/commons/sure_tosca/client/ProgressResponseBody.java
+76
-0
StringUtil.java
...nl/uva/sne/drip/commons/sure_tosca/client/StringUtil.java
+55
-0
TOSCAUtils.java
...c/main/java/nl/uva/sne/drip/commons/utils/TOSCAUtils.java
+0
-169
ToscaHelper.java
.../main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java
+64
-0
Credentials.java
...mons/src/main/java/nl/uva/sne/drip/model/Credentials.java
+201
-187
NodeTemplate.java
...ons/src/main/java/nl/uva/sne/drip/model/NodeTemplate.java
+199
-89
TopologyTemplate.java
...src/main/java/nl/uva/sne/drip/model/TopologyTemplate.java
+96
-74
ToscaTemplate.java
...ns/src/main/java/nl/uva/sne/drip/model/ToscaTemplate.java
+145
-112
User.java
drip-commons/src/main/java/nl/uva/sne/drip/model/User.java
+53
-209
TOSCAUtilsTest.java
...st/java/nl/uva/sne/drip/commons/utils/TOSCAUtilsTest.java
+0
-169
ProvisionerService.java
...main/java/nl/uva/sne/drip/service/ProvisionerService.java
+16
-25
ToscaTemplateService.java
...in/java/nl/uva/sne/drip/service/ToscaTemplateService.java
+1
-1
TopologyTemplate.yml
openAPI/TOSCA/TopologyTemplate.yml
+9
-13
No files found.
drip-commons/pom.xml
View file @
8e781faa
...
@@ -12,6 +12,12 @@
...
@@ -12,6 +12,12 @@
<maven.compiler.source>
${java.version}
</maven.compiler.source>
<maven.compiler.source>
${java.version}
</maven.compiler.source>
<maven.compiler.target>
${java.version}
</maven.compiler.target>
<maven.compiler.target>
${java.version}
</maven.compiler.target>
<springfox-version>
2.9.2
</springfox-version>
<springfox-version>
2.9.2
</springfox-version>
<gson-fire-version>
1.8.3
</gson-fire-version>
<swagger-core-version>
1.5.24
</swagger-core-version>
<okhttp-version>
2.7.5
</okhttp-version>
<gson-version>
2.8.6
</gson-version>
<threetenbp-version>
1.4.0
</threetenbp-version>
</properties>
</properties>
<parent>
<parent>
<groupId>
nl.uva.sne.drip
</groupId>
<groupId>
nl.uva.sne.drip
</groupId>
...
@@ -52,6 +58,39 @@
...
@@ -52,6 +58,39 @@
<artifactId>
jackson-datatype-jsr310
</artifactId>
<artifactId>
jackson-datatype-jsr310
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
io.swagger
</groupId>
<artifactId>
swagger-annotations
</artifactId>
<version>
${swagger-core-version}
</version>
</dependency>
<dependency>
<groupId>
com.squareup.okhttp
</groupId>
<artifactId>
okhttp
</artifactId>
<version>
${okhttp-version}
</version>
</dependency>
<dependency>
<groupId>
com.squareup.okhttp
</groupId>
<artifactId>
logging-interceptor
</artifactId>
<version>
${okhttp-version}
</version>
</dependency>
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<version>
${gson-version}
</version>
</dependency>
<dependency>
<groupId>
io.gsonfire
</groupId>
<artifactId>
gson-fire
</artifactId>
<version>
${gson-fire-version}
</version>
</dependency>
<dependency>
<groupId>
org.threeten
</groupId>
<artifactId>
threetenbp
</artifactId>
<version>
1.3.2
</version>
<type>
jar
</type>
</dependency>
<!-- Bean Validation API support -->
<!-- Bean Validation API support -->
<dependency>
<dependency>
<groupId>
javax.validation
</groupId>
<groupId>
javax.validation
</groupId>
...
@@ -84,6 +123,12 @@
...
@@ -84,6 +123,12 @@
<version>
2.1.10.RELEASE
</version>
<version>
2.1.10.RELEASE
</version>
<type>
jar
</type>
<type>
jar
</type>
</dependency>
</dependency>
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<version>
2.6
</version>
<type>
jar
</type>
</dependency>
</dependencies>
</dependencies>
...
...
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure-tosca/client/auth/ApiKeyAuth.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
auth
;
import
nl.uva.sne.drip.commons.sure_tosca.client.Pair
;
import
java.util.Map
;
import
java.util.List
;
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.JavaClientCodegen"
,
date
=
"2019-11-01T13:11:24.211Z"
)
public
class
ApiKeyAuth
implements
Authentication
{
private
final
String
location
;
private
final
String
paramName
;
private
String
apiKey
;
private
String
apiKeyPrefix
;
public
ApiKeyAuth
(
String
location
,
String
paramName
)
{
this
.
location
=
location
;
this
.
paramName
=
paramName
;
}
public
String
getLocation
()
{
return
location
;
}
public
String
getParamName
()
{
return
paramName
;
}
public
String
getApiKey
()
{
return
apiKey
;
}
public
void
setApiKey
(
String
apiKey
)
{
this
.
apiKey
=
apiKey
;
}
public
String
getApiKeyPrefix
()
{
return
apiKeyPrefix
;
}
public
void
setApiKeyPrefix
(
String
apiKeyPrefix
)
{
this
.
apiKeyPrefix
=
apiKeyPrefix
;
}
@Override
public
void
applyToParams
(
List
<
Pair
>
queryParams
,
Map
<
String
,
String
>
headerParams
)
{
if
(
apiKey
==
null
)
{
return
;
}
String
value
;
if
(
apiKeyPrefix
!=
null
)
{
value
=
apiKeyPrefix
+
" "
+
apiKey
;
}
else
{
value
=
apiKey
;
}
if
(
"query"
.
equals
(
location
))
{
queryParams
.
add
(
new
Pair
(
paramName
,
value
));
}
else
if
(
"header"
.
equals
(
location
))
{
headerParams
.
put
(
paramName
,
value
);
}
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure-tosca/client/auth/Authentication.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
auth
;
import
nl.uva.sne.drip.commons.sure_tosca.client.Pair
;
import
java.util.Map
;
import
java.util.List
;
public
interface
Authentication
{
/**
* Apply authentication settings to header and query params.
*
* @param queryParams List of query parameters
* @param headerParams Map of header parameters
*/
void
applyToParams
(
List
<
Pair
>
queryParams
,
Map
<
String
,
String
>
headerParams
);
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure-tosca/client/auth/HttpBasicAuth.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
auth
;
import
nl.uva.sne.drip.commons.sure_tosca.client.Pair
;
import
com.squareup.okhttp.Credentials
;
import
java.util.Map
;
import
java.util.List
;
import
java.io.UnsupportedEncodingException
;
public
class
HttpBasicAuth
implements
Authentication
{
private
String
username
;
private
String
password
;
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
@Override
public
void
applyToParams
(
List
<
Pair
>
queryParams
,
Map
<
String
,
String
>
headerParams
)
{
if
(
username
==
null
&&
password
==
null
)
{
return
;
}
headerParams
.
put
(
"Authorization"
,
Credentials
.
basic
(
username
==
null
?
""
:
username
,
password
==
null
?
""
:
password
));
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure-tosca/client/auth/OAuth.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
auth
;
import
nl.uva.sne.drip.commons.sure_tosca.client.Pair
;
import
java.util.Map
;
import
java.util.List
;
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.JavaClientCodegen"
,
date
=
"2019-11-01T13:11:24.211Z"
)
public
class
OAuth
implements
Authentication
{
private
String
accessToken
;
public
String
getAccessToken
()
{
return
accessToken
;
}
public
void
setAccessToken
(
String
accessToken
)
{
this
.
accessToken
=
accessToken
;
}
@Override
public
void
applyToParams
(
List
<
Pair
>
queryParams
,
Map
<
String
,
String
>
headerParams
)
{
if
(
accessToken
!=
null
)
{
headerParams
.
put
(
"Authorization"
,
"Bearer "
+
accessToken
);
}
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure-tosca/client/auth/OAuthFlow.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
auth
;
public
enum
OAuthFlow
{
accessCode
,
implicit
,
password
,
application
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/ApiCallback.java
0 → 100644
View file @
8e781faa
package
nl
.
uva
.
sne
.
drip
.
commons
.
sure_tosca
.
client
;
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
import
java.io.IOException
;
import
java.util.Map
;
import
java.util.List
;
/**
* Callback for asynchronous API call.
*
* @param <T> The return type
*/
public
interface
ApiCallback
<
T
>
{
/**
* This is called when the API call fails.
*
* @param e The exception causing the failure
* @param statusCode Status code of the response if available, otherwise it would be 0
* @param responseHeaders Headers of the response if available, otherwise it would be null
*/
void
onFailure
(
ApiException
e
,
int
statusCode
,
Map
<
String
,
List
<
String
>>
responseHeaders
);
/**
* This is called when the API call succeeded.
*
* @param result The result deserialized from response
* @param statusCode Status code of the response
* @param responseHeaders Headers of the response
*/
void
onSuccess
(
T
result
,
int
statusCode
,
Map
<
String
,
List
<
String
>>
responseHeaders
);
/**
* This is called when the API upload processing.
*
* @param bytesWritten bytes Written
* @param contentLength content length of request body
* @param done write end
*/
void
onUploadProgress
(
long
bytesWritten
,
long
contentLength
,
boolean
done
);
/**
* This is called when the API downlond processing.
*
* @param bytesRead bytes Read
* @param contentLength content lenngth of the response
* @param done Read end
*/
void
onDownloadProgress
(
long
bytesRead
,
long
contentLength
,
boolean
done
);
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/ApiClient.java
0 → 100644
View file @
8e781faa
package
nl
.
uva
.
sne
.
drip
.
commons
.
sure_tosca
.
client
;
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
import
com.squareup.okhttp.*
;
import
com.squareup.okhttp.internal.http.HttpMethod
;
import
com.squareup.okhttp.logging.HttpLoggingInterceptor
;
import
com.squareup.okhttp.logging.HttpLoggingInterceptor.Level
;
import
okio.BufferedSink
;
import
okio.Okio
;
import
org.threeten.bp.LocalDate
;
import
org.threeten.bp.OffsetDateTime
;
import
org.threeten.bp.format.DateTimeFormatter
;
import
javax.net.ssl.*
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.lang.reflect.Type
;
import
java.net.URLConnection
;
import
java.net.URLEncoder
;
import
java.security.GeneralSecurityException
;
import
java.security.KeyStore
;
import
java.security.SecureRandom
;
import
java.security.cert.Certificate
;
import
java.security.cert.CertificateException
;
import
java.security.cert.CertificateFactory
;
import
java.security.cert.X509Certificate
;
import
java.text.DateFormat
;
import
java.util.*
;
import
java.util.Map.Entry
;
import
java.util.concurrent.TimeUnit
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
nl.uva.sne.drip.auth.Authentication
;
import
nl.uva.sne.drip.auth.HttpBasicAuth
;
import
nl.uva.sne.drip.auth.ApiKeyAuth
;
import
nl.uva.sne.drip.auth.OAuth
;
public
class
ApiClient
{
private
String
basePath
=
"https://localhost/tosca-sure/1.0.0"
;
private
boolean
debugging
=
false
;
private
Map
<
String
,
String
>
defaultHeaderMap
=
new
HashMap
<
String
,
String
>();
private
String
tempFolderPath
=
null
;
private
Map
<
String
,
Authentication
>
authentications
;
private
DateFormat
dateFormat
;
private
DateFormat
datetimeFormat
;
private
boolean
lenientDatetimeFormat
;
private
int
dateLength
;
private
InputStream
sslCaCert
;
private
boolean
verifyingSsl
;
private
KeyManager
[]
keyManagers
;
private
OkHttpClient
httpClient
;
private
JSON
json
;
private
HttpLoggingInterceptor
loggingInterceptor
;
/*
* Constructor for ApiClient
*/
public
ApiClient
()
{
httpClient
=
new
OkHttpClient
();
verifyingSsl
=
true
;
json
=
new
JSON
();
// Set default User-Agent.
setUserAgent
(
"Swagger-Codegen/1.0.0/java"
);
// Setup authentications (key: authentication name, value: authentication).
authentications
=
new
HashMap
<
String
,
Authentication
>();
// Prevent the authentications from being modified.
authentications
=
Collections
.
unmodifiableMap
(
authentications
);
}
/**
* Get base path
*
* @return Baes path
*/
public
String
getBasePath
()
{
return
basePath
;
}
/**
* Set base path
*
* @param basePath Base path of the URL (e.g https://localhost/tosca-sure/1.0.0
* @return An instance of OkHttpClient
*/
public
ApiClient
setBasePath
(
String
basePath
)
{
this
.
basePath
=
basePath
;
return
this
;
}
/**
* Get HTTP client
*
* @return An instance of OkHttpClient
*/
public
OkHttpClient
getHttpClient
()
{
return
httpClient
;
}
/**
* Set HTTP client
*
* @param httpClient An instance of OkHttpClient
* @return Api Client
*/
public
ApiClient
setHttpClient
(
OkHttpClient
httpClient
)
{
this
.
httpClient
=
httpClient
;
return
this
;
}
/**
* Get JSON
*
* @return JSON object
*/
public
JSON
getJSON
()
{
return
json
;
}
/**
* Set JSON
*
* @param json JSON object
* @return Api client
*/
public
ApiClient
setJSON
(
JSON
json
)
{
this
.
json
=
json
;
return
this
;
}
/**
* True if isVerifyingSsl flag is on
*
* @return True if isVerifySsl flag is on
*/
public
boolean
isVerifyingSsl
()
{
return
verifyingSsl
;
}
/**
* Configure whether to verify certificate and hostname when making https requests.
* Default to true.
* NOTE: Do NOT set to false in production code, otherwise you would face multiple types of cryptographic attacks.
*
* @param verifyingSsl True to verify TLS/SSL connection
* @return ApiClient
*/
public
ApiClient
setVerifyingSsl
(
boolean
verifyingSsl
)
{
this
.
verifyingSsl
=
verifyingSsl
;
applySslSettings
();
return
this
;
}
/**
* Get SSL CA cert.
*
* @return Input stream to the SSL CA cert
*/
public
InputStream
getSslCaCert
()
{
return
sslCaCert
;
}
/**
* Configure the CA certificate to be trusted when making https requests.
* Use null to reset to default.
*
* @param sslCaCert input stream for SSL CA cert
* @return ApiClient
*/
public
ApiClient
setSslCaCert
(
InputStream
sslCaCert
)
{
this
.
sslCaCert
=
sslCaCert
;
applySslSettings
();
return
this
;
}
public
KeyManager
[]
getKeyManagers
()
{
return
keyManagers
;
}
/**
* Configure client keys to use for authorization in an SSL session.
* Use null to reset to default.
*
* @param managers The KeyManagers to use
* @return ApiClient
*/
public
ApiClient
setKeyManagers
(
KeyManager
[]
managers
)
{
this
.
keyManagers
=
managers
;
applySslSettings
();
return
this
;
}
public
DateFormat
getDateFormat
()
{
return
dateFormat
;
}
public
ApiClient
setDateFormat
(
DateFormat
dateFormat
)
{
this
.
json
.
setDateFormat
(
dateFormat
);
return
this
;
}
public
ApiClient
setSqlDateFormat
(
DateFormat
dateFormat
)
{
this
.
json
.
setSqlDateFormat
(
dateFormat
);
return
this
;
}
public
ApiClient
setOffsetDateTimeFormat
(
DateTimeFormatter
dateFormat
)
{
this
.
json
.
setOffsetDateTimeFormat
(
dateFormat
);
return
this
;
}
public
ApiClient
setLocalDateFormat
(
DateTimeFormatter
dateFormat
)
{
this
.
json
.
setLocalDateFormat
(
dateFormat
);
return
this
;
}
public
ApiClient
setLenientOnJson
(
boolean
lenientOnJson
)
{
this
.
json
.
setLenientOnJson
(
lenientOnJson
);
return
this
;
}
/**
* Get authentications (key: authentication name, value: authentication).
*
* @return Map of authentication objects
*/
public
Map
<
String
,
Authentication
>
getAuthentications
()
{
return
authentications
;
}
/**
* Get authentication for the given name.
*
* @param authName The authentication name
* @return The authentication, null if not found
*/
public
Authentication
getAuthentication
(
String
authName
)
{
return
authentications
.
get
(
authName
);
}
/**
* Helper method to set username for the first HTTP basic authentication.
*
* @param username Username
*/
public
void
setUsername
(
String
username
)
{
for
(
Authentication
auth
:
authentications
.
values
())
{
if
(
auth
instanceof
HttpBasicAuth
)
{
((
HttpBasicAuth
)
auth
).
setUsername
(
username
);
return
;
}
}
throw
new
RuntimeException
(
"No HTTP basic authentication configured!"
);
}
/**
* Helper method to set password for the first HTTP basic authentication.
*
* @param password Password
*/
public
void
setPassword
(
String
password
)
{
for
(
Authentication
auth
:
authentications
.
values
())
{
if
(
auth
instanceof
HttpBasicAuth
)
{
((
HttpBasicAuth
)
auth
).
setPassword
(
password
);
return
;
}
}
throw
new
RuntimeException
(
"No HTTP basic authentication configured!"
);
}
/**
* Helper method to set API key value for the first API key authentication.
*
* @param apiKey API key
*/
public
void
setApiKey
(
String
apiKey
)
{
for
(
Authentication
auth
:
authentications
.
values
())
{
if
(
auth
instanceof
ApiKeyAuth
)
{
((
ApiKeyAuth
)
auth
).
setApiKey
(
apiKey
);
return
;
}
}
throw
new
RuntimeException
(
"No API key authentication configured!"
);
}
/**
* Helper method to set API key prefix for the first API key authentication.
*
* @param apiKeyPrefix API key prefix
*/
public
void
setApiKeyPrefix
(
String
apiKeyPrefix
)
{
for
(
Authentication
auth
:
authentications
.
values
())
{
if
(
auth
instanceof
ApiKeyAuth
)
{
((
ApiKeyAuth
)
auth
).
setApiKeyPrefix
(
apiKeyPrefix
);
return
;
}
}
throw
new
RuntimeException
(
"No API key authentication configured!"
);
}
/**
* Helper method to set access token for the first OAuth2 authentication.
*
* @param accessToken Access token
*/
public
void
setAccessToken
(
String
accessToken
)
{
for
(
Authentication
auth
:
authentications
.
values
())
{
if
(
auth
instanceof
OAuth
)
{
((
OAuth
)
auth
).
setAccessToken
(
accessToken
);
return
;
}
}
throw
new
RuntimeException
(
"No OAuth2 authentication configured!"
);
}
/**
* Set the User-Agent header's value (by adding to the default header map).
*
* @param userAgent HTTP request's user agent
* @return ApiClient
*/
public
ApiClient
setUserAgent
(
String
userAgent
)
{
addDefaultHeader
(
"User-Agent"
,
userAgent
);
return
this
;
}
/**
* Add a default header.
*
* @param key The header's key
* @param value The header's value
* @return ApiClient
*/
public
ApiClient
addDefaultHeader
(
String
key
,
String
value
)
{
defaultHeaderMap
.
put
(
key
,
value
);
return
this
;
}
/**
* Check that whether debugging is enabled for this API client.
*
* @return True if debugging is enabled, false otherwise.
*/
public
boolean
isDebugging
()
{
return
debugging
;
}
/**
* Enable/disable debugging for this API client.
*
* @param debugging To enable (true) or disable (false) debugging
* @return ApiClient
*/
public
ApiClient
setDebugging
(
boolean
debugging
)
{
if
(
debugging
!=
this
.
debugging
)
{
if
(
debugging
)
{
loggingInterceptor
=
new
HttpLoggingInterceptor
();
loggingInterceptor
.
setLevel
(
Level
.
BODY
);
httpClient
.
interceptors
().
add
(
loggingInterceptor
);
}
else
{
httpClient
.
interceptors
().
remove
(
loggingInterceptor
);
loggingInterceptor
=
null
;
}
}
this
.
debugging
=
debugging
;
return
this
;
}
/**
* The path of temporary folder used to store downloaded files from endpoints
* with file response. The default value is <code>null</code>, i.e. using
* the system's default tempopary folder.
*
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile">createTempFile</a>
* @return Temporary folder path
*/
public
String
getTempFolderPath
()
{
return
tempFolderPath
;
}
/**
* Set the temporary folder path (for downloading files)
*
* @param tempFolderPath Temporary folder path
* @return ApiClient
*/
public
ApiClient
setTempFolderPath
(
String
tempFolderPath
)
{
this
.
tempFolderPath
=
tempFolderPath
;
return
this
;
}
/**
* Get connection timeout (in milliseconds).
*
* @return Timeout in milliseconds
*/
public
int
getConnectTimeout
()
{
return
httpClient
.
getConnectTimeout
();
}
/**
* Sets the connect timeout (in milliseconds).
* A value of 0 means no timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}.
*
* @param connectionTimeout connection timeout in milliseconds
* @return Api client
*/
public
ApiClient
setConnectTimeout
(
int
connectionTimeout
)
{
httpClient
.
setConnectTimeout
(
connectionTimeout
,
TimeUnit
.
MILLISECONDS
);
return
this
;
}
/**
* Get read timeout (in milliseconds).
*
* @return Timeout in milliseconds
*/
public
int
getReadTimeout
()
{
return
httpClient
.
getReadTimeout
();
}
/**
* Sets the read timeout (in milliseconds).
* A value of 0 means no timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}.
*
* @param readTimeout read timeout in milliseconds
* @return Api client
*/
public
ApiClient
setReadTimeout
(
int
readTimeout
)
{
httpClient
.
setReadTimeout
(
readTimeout
,
TimeUnit
.
MILLISECONDS
);
return
this
;
}
/**
* Get write timeout (in milliseconds).
*
* @return Timeout in milliseconds
*/
public
int
getWriteTimeout
()
{
return
httpClient
.
getWriteTimeout
();
}
/**
* Sets the write timeout (in milliseconds).
* A value of 0 means no timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}.
*
* @param writeTimeout connection timeout in milliseconds
* @return Api client
*/
public
ApiClient
setWriteTimeout
(
int
writeTimeout
)
{
httpClient
.
setWriteTimeout
(
writeTimeout
,
TimeUnit
.
MILLISECONDS
);
return
this
;
}
/**
* Format the given parameter object into string.
*
* @param param Parameter
* @return String representation of the parameter
*/
public
String
parameterToString
(
Object
param
)
{
if
(
param
==
null
)
{
return
""
;
}
else
if
(
param
instanceof
Date
||
param
instanceof
OffsetDateTime
||
param
instanceof
LocalDate
)
{
//Serialize to json string and remove the " enclosing characters
String
jsonStr
=
json
.
serialize
(
param
);
return
jsonStr
.
substring
(
1
,
jsonStr
.
length
()
-
1
);
}
else
if
(
param
instanceof
Collection
)
{
StringBuilder
b
=
new
StringBuilder
();
for
(
Object
o
:
(
Collection
)
param
)
{
if
(
b
.
length
()
>
0
)
{
b
.
append
(
","
);
}
b
.
append
(
String
.
valueOf
(
o
));
}
return
b
.
toString
();
}
else
{
return
String
.
valueOf
(
param
);
}
}
/**
* Formats the specified query parameter to a list containing a single {@code Pair} object.
*
* Note that {@code value} must not be a collection.
*
* @param name The name of the parameter.
* @param value The value of the parameter.
* @return A list containing a single {@code Pair} object.
*/
public
List
<
Pair
>
parameterToPair
(
String
name
,
Object
value
)
{
List
<
Pair
>
params
=
new
ArrayList
<
Pair
>();
// preconditions
if
(
name
==
null
||
name
.
isEmpty
()
||
value
==
null
||
value
instanceof
Collection
)
return
params
;
params
.
add
(
new
Pair
(
name
,
parameterToString
(
value
)));
return
params
;
}
/**
* Formats the specified collection query parameters to a list of {@code Pair} objects.
*
* Note that the values of each of the returned Pair objects are percent-encoded.
*
* @param collectionFormat The collection format of the parameter.
* @param name The name of the parameter.
* @param value The value of the parameter.
* @return A list of {@code Pair} objects.
*/
public
List
<
Pair
>
parameterToPairs
(
String
collectionFormat
,
String
name
,
Collection
value
)
{
List
<
Pair
>
params
=
new
ArrayList
<
Pair
>();
// preconditions
if
(
name
==
null
||
name
.
isEmpty
()
||
value
==
null
||
value
.
isEmpty
())
{
return
params
;
}
// create the params based on the collection format
if
(
"multi"
.
equals
(
collectionFormat
))
{
for
(
Object
item
:
value
)
{
params
.
add
(
new
Pair
(
name
,
escapeString
(
parameterToString
(
item
))));
}
return
params
;
}
// collectionFormat is assumed to be "csv" by default
String
delimiter
=
","
;
// escape all delimiters except commas, which are URI reserved
// characters
if
(
"ssv"
.
equals
(
collectionFormat
))
{
delimiter
=
escapeString
(
" "
);
}
else
if
(
"tsv"
.
equals
(
collectionFormat
))
{
delimiter
=
escapeString
(
"\t"
);
}
else
if
(
"pipes"
.
equals
(
collectionFormat
))
{
delimiter
=
escapeString
(
"|"
);
}
StringBuilder
sb
=
new
StringBuilder
()
;
for
(
Object
item
:
value
)
{
sb
.
append
(
delimiter
);
sb
.
append
(
escapeString
(
parameterToString
(
item
)));
}
params
.
add
(
new
Pair
(
name
,
sb
.
substring
(
delimiter
.
length
())));
return
params
;
}
/**
* Sanitize filename by removing path.
* e.g. ../../sun.gif becomes sun.gif
*
* @param filename The filename to be sanitized
* @return The sanitized filename
*/
public
String
sanitizeFilename
(
String
filename
)
{
return
filename
.
replaceAll
(
".*[/\\\\]"
,
""
);
}
/**
* Check if the given MIME is a JSON MIME.
* JSON MIME examples:
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* "* / *" is also default to JSON
* @param mime MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public
boolean
isJsonMime
(
String
mime
)
{
String
jsonMime
=
"(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"
;
return
mime
!=
null
&&
(
mime
.
matches
(
jsonMime
)
||
mime
.
equals
(
"*/*"
));
}
/**
* Select the Accept header's value from the given accepts array:
* if JSON exists in the given array, use it;
* otherwise use all of them (joining into a string)
*
* @param accepts The accepts array to select from
* @return The Accept header to use. If the given array is empty,
* null will be returned (not to set the Accept header explicitly).
*/
public
String
selectHeaderAccept
(
String
[]
accepts
)
{
if
(
accepts
.
length
==
0
)
{
return
null
;
}
for
(
String
accept
:
accepts
)
{
if
(
isJsonMime
(
accept
))
{
return
accept
;
}
}
return
StringUtil
.
join
(
accepts
,
","
);
}
/**
* Select the Content-Type header's value from the given array:
* if JSON exists in the given array, use it;
* otherwise use the first one of the array.
*
* @param contentTypes The Content-Type array to select from
* @return The Content-Type header to use. If the given array is empty,
* or matches "any", JSON will be used.
*/
public
String
selectHeaderContentType
(
String
[]
contentTypes
)
{
if
(
contentTypes
.
length
==
0
||
contentTypes
[
0
].
equals
(
"*/*"
))
{
return
"application/json"
;
}
for
(
String
contentType
:
contentTypes
)
{
if
(
isJsonMime
(
contentType
))
{
return
contentType
;
}
}
return
contentTypes
[
0
];
}
/**
* Escape the given string to be used as URL query value.
*
* @param str String to be escaped
* @return Escaped string
*/
public
String
escapeString
(
String
str
)
{
try
{
return
URLEncoder
.
encode
(
str
,
"utf8"
).
replaceAll
(
"\\+"
,
"%20"
);
}
catch
(
UnsupportedEncodingException
e
)
{
return
str
;
}
}
/**
* Deserialize response body to Java object, according to the return type and
* the Content-Type response header.
*
* @param <T> Type
* @param response HTTP response
* @param returnType The type of the Java object
* @return The deserialized Java object
* @throws ApiException If fail to deserialize response body, i.e. cannot read response body
* or the Content-Type of the response is not supported.
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
deserialize
(
Response
response
,
Type
returnType
)
throws
ApiException
{
if
(
response
==
null
||
returnType
==
null
)
{
return
null
;
}
if
(
"byte[]"
.
equals
(
returnType
.
toString
()))
{
// Handle binary response (byte array).
try
{
return
(
T
)
response
.
body
().
bytes
();
}
catch
(
IOException
e
)
{
throw
new
ApiException
(
e
);
}
}
else
if
(
returnType
.
equals
(
File
.
class
))
{
// Handle file downloading.
return
(
T
)
downloadFileFromResponse
(
response
);
}
String
respBody
;
try
{
if
(
response
.
body
()
!=
null
)
respBody
=
response
.
body
().
string
();
else
respBody
=
null
;
}
catch
(
IOException
e
)
{
throw
new
ApiException
(
e
);
}
if
(
respBody
==
null
||
""
.
equals
(
respBody
))
{
return
null
;
}
String
contentType
=
response
.
headers
().
get
(
"Content-Type"
);
if
(
contentType
==
null
)
{
// ensuring a default content type
contentType
=
"application/json"
;
}
if
(
isJsonMime
(
contentType
))
{
return
json
.
deserialize
(
respBody
,
returnType
);
}
else
if
(
returnType
.
equals
(
String
.
class
))
{
// Expecting string, return the raw response body.
return
(
T
)
respBody
;
}
else
{
throw
new
ApiException
(
"Content type \""
+
contentType
+
"\" is not supported for type: "
+
returnType
,
response
.
code
(),
response
.
headers
().
toMultimap
(),
respBody
);
}
}
/**
* Serialize the given Java object into request body according to the object's
* class and the request Content-Type.
*
* @param obj The Java object
* @param contentType The request Content-Type
* @return The serialized request body
* @throws ApiException If fail to serialize the given object
*/
public
RequestBody
serialize
(
Object
obj
,
String
contentType
)
throws
ApiException
{
if
(
obj
instanceof
byte
[])
{
// Binary (byte array) body parameter support.
return
RequestBody
.
create
(
MediaType
.
parse
(
contentType
),
(
byte
[])
obj
);
}
else
if
(
obj
instanceof
File
)
{
// File body parameter support.
return
RequestBody
.
create
(
MediaType
.
parse
(
contentType
),
(
File
)
obj
);
}
else
if
(
isJsonMime
(
contentType
))
{
String
content
;
if
(
obj
!=
null
)
{
content
=
json
.
serialize
(
obj
);
}
else
{
content
=
null
;
}
return
RequestBody
.
create
(
MediaType
.
parse
(
contentType
),
content
);
}
else
{
throw
new
ApiException
(
"Content type \""
+
contentType
+
"\" is not supported"
);
}
}
/**
* Download file from the given response.
*
* @param response An instance of the Response object
* @throws ApiException If fail to read file content from response and write to disk
* @return Downloaded file
*/
public
File
downloadFileFromResponse
(
Response
response
)
throws
ApiException
{
try
{
File
file
=
prepareDownloadFile
(
response
);
BufferedSink
sink
=
Okio
.
buffer
(
Okio
.
sink
(
file
));
sink
.
writeAll
(
response
.
body
().
source
());
sink
.
close
();
return
file
;
}
catch
(
IOException
e
)
{
throw
new
ApiException
(
e
);
}
}
/**
* Prepare file for download
*
* @param response An instance of the Response object
* @throws IOException If fail to prepare file for download
* @return Prepared file for the download
*/
public
File
prepareDownloadFile
(
Response
response
)
throws
IOException
{
String
filename
=
null
;
String
contentDisposition
=
response
.
header
(
"Content-Disposition"
);
if
(
contentDisposition
!=
null
&&
!
""
.
equals
(
contentDisposition
))
{
// Get filename from the Content-Disposition header.
Pattern
pattern
=
Pattern
.
compile
(
"filename=['\"]?([^'\"\\s]+)['\"]?"
);
Matcher
matcher
=
pattern
.
matcher
(
contentDisposition
);
if
(
matcher
.
find
())
{
filename
=
sanitizeFilename
(
matcher
.
group
(
1
));
}
}
String
prefix
=
null
;
String
suffix
=
null
;
if
(
filename
==
null
)
{
prefix
=
"download-"
;
suffix
=
""
;
}
else
{
int
pos
=
filename
.
lastIndexOf
(
"."
);
if
(
pos
==
-
1
)
{
prefix
=
filename
+
"-"
;
}
else
{
prefix
=
filename
.
substring
(
0
,
pos
)
+
"-"
;
suffix
=
filename
.
substring
(
pos
);
}
// File.createTempFile requires the prefix to be at least three characters long
if
(
prefix
.
length
()
<
3
)
prefix
=
"download-"
;
}
if
(
tempFolderPath
==
null
)
return
File
.
createTempFile
(
prefix
,
suffix
);
else
return
File
.
createTempFile
(
prefix
,
suffix
,
new
File
(
tempFolderPath
));
}
/**
* {@link #execute(Call, Type)}
*
* @param <T> Type
* @param call An instance of the Call object
* @throws ApiException If fail to execute the call
* @return ApiResponse<T>
*/
public
<
T
>
ApiResponse
<
T
>
execute
(
Call
call
)
throws
ApiException
{
return
execute
(
call
,
null
);
}
/**
* Execute HTTP call and deserialize the HTTP response body into the given return type.
*
* @param returnType The return type used to deserialize HTTP response body
* @param <T> The return type corresponding to (same with) returnType
* @param call Call
* @return ApiResponse object containing response status, headers and
* data, which is a Java object deserialized from response body and would be null
* when returnType is null.
* @throws ApiException If fail to execute the call
*/
public
<
T
>
ApiResponse
<
T
>
execute
(
Call
call
,
Type
returnType
)
throws
ApiException
{
try
{
Response
response
=
call
.
execute
();
T
data
=
handleResponse
(
response
,
returnType
);
return
new
ApiResponse
<
T
>(
response
.
code
(),
response
.
headers
().
toMultimap
(),
data
);
}
catch
(
IOException
e
)
{
throw
new
ApiException
(
e
);
}
}
/**
* {@link #executeAsync(Call, Type, ApiCallback)}
*
* @param <T> Type
* @param call An instance of the Call object
* @param callback ApiCallback<T>
*/
public
<
T
>
void
executeAsync
(
Call
call
,
ApiCallback
<
T
>
callback
)
{
executeAsync
(
call
,
null
,
callback
);
}
/**
* Execute HTTP call asynchronously.
*
* @see #execute(Call, Type)
* @param <T> Type
* @param call The callback to be executed when the API call finishes
* @param returnType Return type
* @param callback ApiCallback
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
void
executeAsync
(
Call
call
,
final
Type
returnType
,
final
ApiCallback
<
T
>
callback
)
{
call
.
enqueue
(
new
Callback
()
{
@Override
public
void
onFailure
(
Request
request
,
IOException
e
)
{
callback
.
onFailure
(
new
ApiException
(
e
),
0
,
null
);
}
@Override
public
void
onResponse
(
Response
response
)
throws
IOException
{
T
result
;
try
{
result
=
(
T
)
handleResponse
(
response
,
returnType
);
}
catch
(
ApiException
e
)
{
callback
.
onFailure
(
e
,
response
.
code
(),
response
.
headers
().
toMultimap
());
return
;
}
callback
.
onSuccess
(
result
,
response
.
code
(),
response
.
headers
().
toMultimap
());
}
});
}
/**
* Handle the given response, return the deserialized object when the response is successful.
*
* @param <T> Type
* @param response Response
* @param returnType Return type
* @throws ApiException If the response has a unsuccessful status code or
* fail to deserialize the response body
* @return Type
*/
public
<
T
>
T
handleResponse
(
Response
response
,
Type
returnType
)
throws
ApiException
{
if
(
response
.
isSuccessful
())
{
if
(
returnType
==
null
||
response
.
code
()
==
204
)
{
// returning null if the returnType is not defined,
// or the status code is 204 (No Content)
if
(
response
.
body
()
!=
null
)
{
try
{
response
.
body
().
close
();
}
catch
(
IOException
e
)
{
throw
new
ApiException
(
response
.
message
(),
e
,
response
.
code
(),
response
.
headers
().
toMultimap
());
}
}
return
null
;
}
else
{
return
deserialize
(
response
,
returnType
);
}
}
else
{
String
respBody
=
null
;
if
(
response
.
body
()
!=
null
)
{
try
{
respBody
=
response
.
body
().
string
();
}
catch
(
IOException
e
)
{
throw
new
ApiException
(
response
.
message
(),
e
,
response
.
code
(),
response
.
headers
().
toMultimap
());
}
}
throw
new
ApiException
(
response
.
message
(),
response
.
code
(),
response
.
headers
().
toMultimap
(),
respBody
);
}
}
/**
* Build HTTP call with the given options.
*
* @param path The sub-path of the HTTP URL
* @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
* @param queryParams The query parameters
* @param collectionQueryParams The collection query parameters
* @param body The request body object
* @param headerParams The header parameters
* @param formParams The form parameters
* @param authNames The authentications to apply
* @param progressRequestListener Progress request listener
* @return The HTTP call
* @throws ApiException If fail to serialize the request body object
*/
public
Call
buildCall
(
String
path
,
String
method
,
List
<
Pair
>
queryParams
,
List
<
Pair
>
collectionQueryParams
,
Object
body
,
Map
<
String
,
String
>
headerParams
,
Map
<
String
,
Object
>
formParams
,
String
[]
authNames
,
ProgressRequestBody
.
ProgressRequestListener
progressRequestListener
)
throws
ApiException
{
Request
request
=
buildRequest
(
path
,
method
,
queryParams
,
collectionQueryParams
,
body
,
headerParams
,
formParams
,
authNames
,
progressRequestListener
);
return
httpClient
.
newCall
(
request
);
}
/**
* Build an HTTP request with the given options.
*
* @param path The sub-path of the HTTP URL
* @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
* @param queryParams The query parameters
* @param collectionQueryParams The collection query parameters
* @param body The request body object
* @param headerParams The header parameters
* @param formParams The form parameters
* @param authNames The authentications to apply
* @param progressRequestListener Progress request listener
* @return The HTTP request
* @throws ApiException If fail to serialize the request body object
*/
public
Request
buildRequest
(
String
path
,
String
method
,
List
<
Pair
>
queryParams
,
List
<
Pair
>
collectionQueryParams
,
Object
body
,
Map
<
String
,
String
>
headerParams
,
Map
<
String
,
Object
>
formParams
,
String
[]
authNames
,
ProgressRequestBody
.
ProgressRequestListener
progressRequestListener
)
throws
ApiException
{
updateParamsForAuth
(
authNames
,
queryParams
,
headerParams
);
final
String
url
=
buildUrl
(
path
,
queryParams
,
collectionQueryParams
);
final
Request
.
Builder
reqBuilder
=
new
Request
.
Builder
().
url
(
url
);
processHeaderParams
(
headerParams
,
reqBuilder
);
String
contentType
=
(
String
)
headerParams
.
get
(
"Content-Type"
);
// ensuring a default content type
if
(
contentType
==
null
)
{
contentType
=
"application/json"
;
}
RequestBody
reqBody
;
if
(!
HttpMethod
.
permitsRequestBody
(
method
))
{
reqBody
=
null
;
}
else
if
(
"application/x-www-form-urlencoded"
.
equals
(
contentType
))
{
reqBody
=
buildRequestBodyFormEncoding
(
formParams
);
}
else
if
(
"multipart/form-data"
.
equals
(
contentType
))
{
reqBody
=
buildRequestBodyMultipart
(
formParams
);
}
else
if
(
body
==
null
)
{
if
(
"DELETE"
.
equals
(
method
))
{
// allow calling DELETE without sending a request body
reqBody
=
null
;
}
else
{
// use an empty request body (for POST, PUT and PATCH)
reqBody
=
RequestBody
.
create
(
MediaType
.
parse
(
contentType
),
""
);
}
}
else
{
reqBody
=
serialize
(
body
,
contentType
);
}
Request
request
=
null
;
if
(
progressRequestListener
!=
null
&&
reqBody
!=
null
)
{
ProgressRequestBody
progressRequestBody
=
new
ProgressRequestBody
(
reqBody
,
progressRequestListener
);
request
=
reqBuilder
.
method
(
method
,
progressRequestBody
).
build
();
}
else
{
request
=
reqBuilder
.
method
(
method
,
reqBody
).
build
();
}
return
request
;
}
/**
* Build full URL by concatenating base path, the given sub path and query parameters.
*
* @param path The sub path
* @param queryParams The query parameters
* @param collectionQueryParams The collection query parameters
* @return The full URL
*/
public
String
buildUrl
(
String
path
,
List
<
Pair
>
queryParams
,
List
<
Pair
>
collectionQueryParams
)
{
final
StringBuilder
url
=
new
StringBuilder
();
url
.
append
(
basePath
).
append
(
path
);
if
(
queryParams
!=
null
&&
!
queryParams
.
isEmpty
())
{
// support (constant) query string in `path`, e.g. "/posts?draft=1"
String
prefix
=
path
.
contains
(
"?"
)
?
"&"
:
"?"
;
for
(
Pair
param
:
queryParams
)
{
if
(
param
.
getValue
()
!=
null
)
{
if
(
prefix
!=
null
)
{
url
.
append
(
prefix
);
prefix
=
null
;
}
else
{
url
.
append
(
"&"
);
}
String
value
=
parameterToString
(
param
.
getValue
());
url
.
append
(
escapeString
(
param
.
getName
())).
append
(
"="
).
append
(
escapeString
(
value
));
}
}
}
if
(
collectionQueryParams
!=
null
&&
!
collectionQueryParams
.
isEmpty
())
{
String
prefix
=
url
.
toString
().
contains
(
"?"
)
?
"&"
:
"?"
;
for
(
Pair
param
:
collectionQueryParams
)
{
if
(
param
.
getValue
()
!=
null
)
{
if
(
prefix
!=
null
)
{
url
.
append
(
prefix
);
prefix
=
null
;
}
else
{
url
.
append
(
"&"
);
}
String
value
=
parameterToString
(
param
.
getValue
());
// collection query parameter value already escaped as part of parameterToPairs
url
.
append
(
escapeString
(
param
.
getName
())).
append
(
"="
).
append
(
value
);
}
}
}
return
url
.
toString
();
}
/**
* Set header parameters to the request builder, including default headers.
*
* @param headerParams Header parameters in the ofrm of Map
* @param reqBuilder Reqeust.Builder
*/
public
void
processHeaderParams
(
Map
<
String
,
String
>
headerParams
,
Request
.
Builder
reqBuilder
)
{
for
(
Entry
<
String
,
String
>
param
:
headerParams
.
entrySet
())
{
reqBuilder
.
header
(
param
.
getKey
(),
parameterToString
(
param
.
getValue
()));
}
for
(
Entry
<
String
,
String
>
header
:
defaultHeaderMap
.
entrySet
())
{
if
(!
headerParams
.
containsKey
(
header
.
getKey
()))
{
reqBuilder
.
header
(
header
.
getKey
(),
parameterToString
(
header
.
getValue
()));
}
}
}
/**
* Update query and header parameters based on authentication settings.
*
* @param authNames The authentications to apply
* @param queryParams List of query parameters
* @param headerParams Map of header parameters
*/
public
void
updateParamsForAuth
(
String
[]
authNames
,
List
<
Pair
>
queryParams
,
Map
<
String
,
String
>
headerParams
)
{
for
(
String
authName
:
authNames
)
{
Authentication
auth
=
authentications
.
get
(
authName
);
if
(
auth
==
null
)
throw
new
RuntimeException
(
"Authentication undefined: "
+
authName
);
auth
.
applyToParams
(
queryParams
,
headerParams
);
}
}
/**
* Build a form-encoding request body with the given form parameters.
*
* @param formParams Form parameters in the form of Map
* @return RequestBody
*/
public
RequestBody
buildRequestBodyFormEncoding
(
Map
<
String
,
Object
>
formParams
)
{
FormEncodingBuilder
formBuilder
=
new
FormEncodingBuilder
();
for
(
Entry
<
String
,
Object
>
param
:
formParams
.
entrySet
())
{
formBuilder
.
add
(
param
.
getKey
(),
parameterToString
(
param
.
getValue
()));
}
return
formBuilder
.
build
();
}
/**
* Build a multipart (file uploading) request body with the given form parameters,
* which could contain text fields and file fields.
*
* @param formParams Form parameters in the form of Map
* @return RequestBody
*/
public
RequestBody
buildRequestBodyMultipart
(
Map
<
String
,
Object
>
formParams
)
{
MultipartBuilder
mpBuilder
=
new
MultipartBuilder
().
type
(
MultipartBuilder
.
FORM
);
for
(
Entry
<
String
,
Object
>
param
:
formParams
.
entrySet
())
{
if
(
param
.
getValue
()
instanceof
File
)
{
File
file
=
(
File
)
param
.
getValue
();
Headers
partHeaders
=
Headers
.
of
(
"Content-Disposition"
,
"form-data; name=\""
+
param
.
getKey
()
+
"\"; filename=\""
+
file
.
getName
()
+
"\""
);
MediaType
mediaType
=
MediaType
.
parse
(
guessContentTypeFromFile
(
file
));
mpBuilder
.
addPart
(
partHeaders
,
RequestBody
.
create
(
mediaType
,
file
));
}
else
{
Headers
partHeaders
=
Headers
.
of
(
"Content-Disposition"
,
"form-data; name=\""
+
param
.
getKey
()
+
"\""
);
mpBuilder
.
addPart
(
partHeaders
,
RequestBody
.
create
(
null
,
parameterToString
(
param
.
getValue
())));
}
}
return
mpBuilder
.
build
();
}
/**
* Guess Content-Type header from the given file (defaults to "application/octet-stream").
*
* @param file The given file
* @return The guessed Content-Type
*/
public
String
guessContentTypeFromFile
(
File
file
)
{
String
contentType
=
URLConnection
.
guessContentTypeFromName
(
file
.
getName
());
if
(
contentType
==
null
)
{
return
"application/octet-stream"
;
}
else
{
return
contentType
;
}
}
/**
* Apply SSL related settings to httpClient according to the current values of
* verifyingSsl and sslCaCert.
*/
private
void
applySslSettings
()
{
try
{
TrustManager
[]
trustManagers
=
null
;
HostnameVerifier
hostnameVerifier
=
null
;
if
(!
verifyingSsl
)
{
TrustManager
trustAll
=
new
X509TrustManager
()
{
@Override
public
void
checkClientTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{}
@Override
public
void
checkServerTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{}
@Override
public
X509Certificate
[]
getAcceptedIssuers
()
{
return
null
;
}
};
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"TLS"
);
trustManagers
=
new
TrustManager
[]{
trustAll
};
hostnameVerifier
=
new
HostnameVerifier
()
{
@Override
public
boolean
verify
(
String
hostname
,
SSLSession
session
)
{
return
true
;
}
};
}
else
if
(
sslCaCert
!=
null
)
{
char
[]
password
=
null
;
// Any password will work.
CertificateFactory
certificateFactory
=
CertificateFactory
.
getInstance
(
"X.509"
);
Collection
<?
extends
Certificate
>
certificates
=
certificateFactory
.
generateCertificates
(
sslCaCert
);
if
(
certificates
.
isEmpty
())
{
throw
new
IllegalArgumentException
(
"expected non-empty set of trusted certificates"
);
}
KeyStore
caKeyStore
=
newEmptyKeyStore
(
password
);
int
index
=
0
;
for
(
Certificate
certificate
:
certificates
)
{
String
certificateAlias
=
"ca"
+
Integer
.
toString
(
index
++);
caKeyStore
.
setCertificateEntry
(
certificateAlias
,
certificate
);
}
TrustManagerFactory
trustManagerFactory
=
TrustManagerFactory
.
getInstance
(
TrustManagerFactory
.
getDefaultAlgorithm
());
trustManagerFactory
.
init
(
caKeyStore
);
trustManagers
=
trustManagerFactory
.
getTrustManagers
();
}
if
(
keyManagers
!=
null
||
trustManagers
!=
null
)
{
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"TLS"
);
sslContext
.
init
(
keyManagers
,
trustManagers
,
new
SecureRandom
());
httpClient
.
setSslSocketFactory
(
sslContext
.
getSocketFactory
());
}
else
{
httpClient
.
setSslSocketFactory
(
null
);
}
httpClient
.
setHostnameVerifier
(
hostnameVerifier
);
}
catch
(
GeneralSecurityException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
private
KeyStore
newEmptyKeyStore
(
char
[]
password
)
throws
GeneralSecurityException
{
try
{
KeyStore
keyStore
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
keyStore
.
load
(
null
,
password
);
return
keyStore
;
}
catch
(
IOException
e
)
{
throw
new
AssertionError
(
e
);
}
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/ApiException.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
sure_tosca
.
client
;
import
java.util.Map
;
import
java.util.List
;
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.JavaClientCodegen"
,
date
=
"2019-11-01T13:11:24.211Z"
)
public
class
ApiException
extends
Exception
{
private
int
code
=
0
;
private
Map
<
String
,
List
<
String
>>
responseHeaders
=
null
;
private
String
responseBody
=
null
;
public
ApiException
()
{}
public
ApiException
(
Throwable
throwable
)
{
super
(
throwable
);
}
public
ApiException
(
String
message
)
{
super
(
message
);
}
public
ApiException
(
String
message
,
Throwable
throwable
,
int
code
,
Map
<
String
,
List
<
String
>>
responseHeaders
,
String
responseBody
)
{
super
(
message
,
throwable
);
this
.
code
=
code
;
this
.
responseHeaders
=
responseHeaders
;
this
.
responseBody
=
responseBody
;
}
public
ApiException
(
String
message
,
int
code
,
Map
<
String
,
List
<
String
>>
responseHeaders
,
String
responseBody
)
{
this
(
message
,
(
Throwable
)
null
,
code
,
responseHeaders
,
responseBody
);
}
public
ApiException
(
String
message
,
Throwable
throwable
,
int
code
,
Map
<
String
,
List
<
String
>>
responseHeaders
)
{
this
(
message
,
throwable
,
code
,
responseHeaders
,
null
);
}
public
ApiException
(
int
code
,
Map
<
String
,
List
<
String
>>
responseHeaders
,
String
responseBody
)
{
this
((
String
)
null
,
(
Throwable
)
null
,
code
,
responseHeaders
,
responseBody
);
}
public
ApiException
(
int
code
,
String
message
)
{
super
(
message
);
this
.
code
=
code
;
}
public
ApiException
(
int
code
,
String
message
,
Map
<
String
,
List
<
String
>>
responseHeaders
,
String
responseBody
)
{
this
(
code
,
message
);
this
.
responseHeaders
=
responseHeaders
;
this
.
responseBody
=
responseBody
;
}
/**
* Get the HTTP status code.
*
* @return HTTP status code
*/
public
int
getCode
()
{
return
code
;
}
/**
* Get the HTTP response headers.
*
* @return A map of list of string
*/
public
Map
<
String
,
List
<
String
>>
getResponseHeaders
()
{
return
responseHeaders
;
}
/**
* Get the HTTP response body.
*
* @return Response body in the form of string
*/
public
String
getResponseBody
()
{
return
responseBody
;
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/ApiResponse.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
sure_tosca
.
client
;
import
java.util.List
;
import
java.util.Map
;
/**
* API response returned by API call.
*
* @param <T> The type of data that is deserialized from response body
*/
public
class
ApiResponse
<
T
>
{
final
private
int
statusCode
;
final
private
Map
<
String
,
List
<
String
>>
headers
;
final
private
T
data
;
/**
* @param statusCode The status code of HTTP response
* @param headers The headers of HTTP response
*/
public
ApiResponse
(
int
statusCode
,
Map
<
String
,
List
<
String
>>
headers
)
{
this
(
statusCode
,
headers
,
null
);
}
/**
* @param statusCode The status code of HTTP response
* @param headers The headers of HTTP response
* @param data The object deserialized from response bod
*/
public
ApiResponse
(
int
statusCode
,
Map
<
String
,
List
<
String
>>
headers
,
T
data
)
{
this
.
statusCode
=
statusCode
;
this
.
headers
=
headers
;
this
.
data
=
data
;
}
public
int
getStatusCode
()
{
return
statusCode
;
}
public
Map
<
String
,
List
<
String
>>
getHeaders
()
{
return
headers
;
}
public
T
getData
()
{
return
data
;
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/Configuration.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
sure_tosca
.
client
;
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.JavaClientCodegen"
,
date
=
"2019-11-01T13:11:24.211Z"
)
public
class
Configuration
{
private
static
ApiClient
defaultApiClient
=
new
ApiClient
();
/**
* Get the default API client, which would be used when creating API
* instances without providing an API client.
*
* @return Default API client
*/
public
static
ApiClient
getDefaultApiClient
()
{
return
defaultApiClient
;
}
/**
* Set the default API client, which would be used when creating API
* instances without providing an API client.
*
* @param apiClient API client
*/
public
static
void
setDefaultApiClient
(
ApiClient
apiClient
)
{
defaultApiClient
=
apiClient
;
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/DefaultApi.java
0 → 100644
View file @
8e781faa
This source diff could not be displayed because it is too large. You can
view the blob
instead.
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/GzipRequestInterceptor.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
sure_tosca
.
client
;
import
com.squareup.okhttp.*
;
import
okio.Buffer
;
import
okio.BufferedSink
;
import
okio.GzipSink
;
import
okio.Okio
;
import
java.io.IOException
;
/**
* Encodes request bodies using gzip.
*
* Taken from https://github.com/square/okhttp/issues/350
*/
class
GzipRequestInterceptor
implements
Interceptor
{
@Override
public
Response
intercept
(
Chain
chain
)
throws
IOException
{
Request
originalRequest
=
chain
.
request
();
if
(
originalRequest
.
body
()
==
null
||
originalRequest
.
header
(
"Content-Encoding"
)
!=
null
)
{
return
chain
.
proceed
(
originalRequest
);
}
Request
compressedRequest
=
originalRequest
.
newBuilder
()
.
header
(
"Content-Encoding"
,
"gzip"
)
.
method
(
originalRequest
.
method
(),
forceContentLength
(
gzip
(
originalRequest
.
body
())))
.
build
();
return
chain
.
proceed
(
compressedRequest
);
}
private
RequestBody
forceContentLength
(
final
RequestBody
requestBody
)
throws
IOException
{
final
Buffer
buffer
=
new
Buffer
();
requestBody
.
writeTo
(
buffer
);
return
new
RequestBody
()
{
@Override
public
MediaType
contentType
()
{
return
requestBody
.
contentType
();
}
@Override
public
long
contentLength
()
{
return
buffer
.
size
();
}
@Override
public
void
writeTo
(
BufferedSink
sink
)
throws
IOException
{
sink
.
write
(
buffer
.
snapshot
());
}
};
}
private
RequestBody
gzip
(
final
RequestBody
body
)
{
return
new
RequestBody
()
{
@Override
public
MediaType
contentType
()
{
return
body
.
contentType
();
}
@Override
public
long
contentLength
()
{
return
-
1
;
// We don't know the compressed length in advance!
}
@Override
public
void
writeTo
(
BufferedSink
sink
)
throws
IOException
{
BufferedSink
gzipSink
=
Okio
.
buffer
(
new
GzipSink
(
sink
));
body
.
writeTo
(
gzipSink
);
gzipSink
.
close
();
}
};
}
}
\ No newline at end of file
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/JSON.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
sure_tosca
.
client
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.JsonParseException
;
import
com.google.gson.TypeAdapter
;
import
com.google.gson.internal.bind.util.ISO8601Utils
;
import
com.google.gson.stream.JsonReader
;
import
com.google.gson.stream.JsonWriter
;
import
com.google.gson.JsonElement
;
import
io.gsonfire.GsonFireBuilder
;
import
org.threeten.bp.LocalDate
;
import
org.threeten.bp.OffsetDateTime
;
import
org.threeten.bp.format.DateTimeFormatter
;
import
okio.ByteString
;
import
java.io.IOException
;
import
java.io.StringReader
;
import
java.lang.reflect.Type
;
import
java.text.DateFormat
;
import
java.text.ParseException
;
import
java.text.ParsePosition
;
import
java.util.Date
;
import
java.util.Map
;
public
class
JSON
{
private
Gson
gson
;
private
boolean
isLenientOnJson
=
false
;
private
DateTypeAdapter
dateTypeAdapter
=
new
DateTypeAdapter
();
private
SqlDateTypeAdapter
sqlDateTypeAdapter
=
new
SqlDateTypeAdapter
();
private
OffsetDateTimeTypeAdapter
offsetDateTimeTypeAdapter
=
new
OffsetDateTimeTypeAdapter
();
private
LocalDateTypeAdapter
localDateTypeAdapter
=
new
LocalDateTypeAdapter
();
private
ByteArrayAdapter
byteArrayAdapter
=
new
ByteArrayAdapter
();
public
static
GsonBuilder
createGson
()
{
GsonFireBuilder
fireBuilder
=
new
GsonFireBuilder
()
;
GsonBuilder
builder
=
fireBuilder
.
createGsonBuilder
();
return
builder
;
}
private
static
String
getDiscriminatorValue
(
JsonElement
readElement
,
String
discriminatorField
)
{
JsonElement
element
=
readElement
.
getAsJsonObject
().
get
(
discriminatorField
);
if
(
null
==
element
)
{
throw
new
IllegalArgumentException
(
"missing discriminator field: <"
+
discriminatorField
+
">"
);
}
return
element
.
getAsString
();
}
private
static
Class
getClassByDiscriminator
(
Map
classByDiscriminatorValue
,
String
discriminatorValue
)
{
Class
clazz
=
(
Class
)
classByDiscriminatorValue
.
get
(
discriminatorValue
.
toUpperCase
());
if
(
null
==
clazz
)
{
throw
new
IllegalArgumentException
(
"cannot determine model class of name: <"
+
discriminatorValue
+
">"
);
}
return
clazz
;
}
public
JSON
()
{
gson
=
createGson
()
.
registerTypeAdapter
(
Date
.
class
,
dateTypeAdapter
)
.
registerTypeAdapter
(
java
.
sql
.
Date
.
class
,
sqlDateTypeAdapter
)
.
registerTypeAdapter
(
OffsetDateTime
.
class
,
offsetDateTimeTypeAdapter
)
.
registerTypeAdapter
(
LocalDate
.
class
,
localDateTypeAdapter
)
.
registerTypeAdapter
(
byte
[].
class
,
byteArrayAdapter
)
.
create
();
}
/**
* Get Gson.
*
* @return Gson
*/
public
Gson
getGson
()
{
return
gson
;
}
/**
* Set Gson.
*
* @param gson Gson
* @return JSON
*/
public
JSON
setGson
(
Gson
gson
)
{
this
.
gson
=
gson
;
return
this
;
}
public
JSON
setLenientOnJson
(
boolean
lenientOnJson
)
{
isLenientOnJson
=
lenientOnJson
;
return
this
;
}
/**
* Serialize the given Java object into JSON string.
*
* @param obj Object
* @return String representation of the JSON
*/
public
String
serialize
(
Object
obj
)
{
return
gson
.
toJson
(
obj
);
}
/**
* Deserialize the given JSON string to Java object.
*
* @param <T> Type
* @param body The JSON string
* @param returnType The type to deserialize into
* @return The deserialized Java object
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
deserialize
(
String
body
,
Type
returnType
)
{
try
{
if
(
isLenientOnJson
)
{
JsonReader
jsonReader
=
new
JsonReader
(
new
StringReader
(
body
));
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
jsonReader
.
setLenient
(
true
);
return
gson
.
fromJson
(
jsonReader
,
returnType
);
}
else
{
return
gson
.
fromJson
(
body
,
returnType
);
}
}
catch
(
JsonParseException
e
)
{
// Fallback processing when failed to parse JSON form response body:
// return the response body string directly for the String return type;
if
(
returnType
.
equals
(
String
.
class
))
return
(
T
)
body
;
else
throw
(
e
);
}
}
/**
* Gson TypeAdapter for Byte Array type
*/
public
class
ByteArrayAdapter
extends
TypeAdapter
<
byte
[]>
{
@Override
public
void
write
(
JsonWriter
out
,
byte
[]
value
)
throws
IOException
{
if
(
value
==
null
)
{
out
.
nullValue
();
}
else
{
out
.
value
(
ByteString
.
of
(
value
).
base64
());
}
}
@Override
public
byte
[]
read
(
JsonReader
in
)
throws
IOException
{
switch
(
in
.
peek
())
{
case
NULL:
in
.
nextNull
();
return
null
;
default
:
String
bytesAsBase64
=
in
.
nextString
();
ByteString
byteString
=
ByteString
.
decodeBase64
(
bytesAsBase64
);
return
byteString
.
toByteArray
();
}
}
}
/**
* Gson TypeAdapter for JSR310 OffsetDateTime type
*/
public
static
class
OffsetDateTimeTypeAdapter
extends
TypeAdapter
<
OffsetDateTime
>
{
private
DateTimeFormatter
formatter
;
public
OffsetDateTimeTypeAdapter
()
{
this
(
DateTimeFormatter
.
ISO_OFFSET_DATE_TIME
);
}
public
OffsetDateTimeTypeAdapter
(
DateTimeFormatter
formatter
)
{
this
.
formatter
=
formatter
;
}
public
void
setFormat
(
DateTimeFormatter
dateFormat
)
{
this
.
formatter
=
dateFormat
;
}
@Override
public
void
write
(
JsonWriter
out
,
OffsetDateTime
date
)
throws
IOException
{
if
(
date
==
null
)
{
out
.
nullValue
();
}
else
{
out
.
value
(
formatter
.
format
(
date
));
}
}
@Override
public
OffsetDateTime
read
(
JsonReader
in
)
throws
IOException
{
switch
(
in
.
peek
())
{
case
NULL:
in
.
nextNull
();
return
null
;
default
:
String
date
=
in
.
nextString
();
if
(
date
.
endsWith
(
"+0000"
))
{
date
=
date
.
substring
(
0
,
date
.
length
()-
5
)
+
"Z"
;
}
return
OffsetDateTime
.
parse
(
date
,
formatter
);
}
}
}
/**
* Gson TypeAdapter for JSR310 LocalDate type
*/
public
class
LocalDateTypeAdapter
extends
TypeAdapter
<
LocalDate
>
{
private
DateTimeFormatter
formatter
;
public
LocalDateTypeAdapter
()
{
this
(
DateTimeFormatter
.
ISO_LOCAL_DATE
);
}
public
LocalDateTypeAdapter
(
DateTimeFormatter
formatter
)
{
this
.
formatter
=
formatter
;
}
public
void
setFormat
(
DateTimeFormatter
dateFormat
)
{
this
.
formatter
=
dateFormat
;
}
@Override
public
void
write
(
JsonWriter
out
,
LocalDate
date
)
throws
IOException
{
if
(
date
==
null
)
{
out
.
nullValue
();
}
else
{
out
.
value
(
formatter
.
format
(
date
));
}
}
@Override
public
LocalDate
read
(
JsonReader
in
)
throws
IOException
{
switch
(
in
.
peek
())
{
case
NULL:
in
.
nextNull
();
return
null
;
default
:
String
date
=
in
.
nextString
();
return
LocalDate
.
parse
(
date
,
formatter
);
}
}
}
public
JSON
setOffsetDateTimeFormat
(
DateTimeFormatter
dateFormat
)
{
offsetDateTimeTypeAdapter
.
setFormat
(
dateFormat
);
return
this
;
}
public
JSON
setLocalDateFormat
(
DateTimeFormatter
dateFormat
)
{
localDateTypeAdapter
.
setFormat
(
dateFormat
);
return
this
;
}
/**
* Gson TypeAdapter for java.sql.Date type
* If the dateFormat is null, a simple "yyyy-MM-dd" format will be used
* (more efficient than SimpleDateFormat).
*/
public
static
class
SqlDateTypeAdapter
extends
TypeAdapter
<
java
.
sql
.
Date
>
{
private
DateFormat
dateFormat
;
public
SqlDateTypeAdapter
()
{
}
public
SqlDateTypeAdapter
(
DateFormat
dateFormat
)
{
this
.
dateFormat
=
dateFormat
;
}
public
void
setFormat
(
DateFormat
dateFormat
)
{
this
.
dateFormat
=
dateFormat
;
}
@Override
public
void
write
(
JsonWriter
out
,
java
.
sql
.
Date
date
)
throws
IOException
{
if
(
date
==
null
)
{
out
.
nullValue
();
}
else
{
String
value
;
if
(
dateFormat
!=
null
)
{
value
=
dateFormat
.
format
(
date
);
}
else
{
value
=
date
.
toString
();
}
out
.
value
(
value
);
}
}
@Override
public
java
.
sql
.
Date
read
(
JsonReader
in
)
throws
IOException
{
switch
(
in
.
peek
())
{
case
NULL:
in
.
nextNull
();
return
null
;
default
:
String
date
=
in
.
nextString
();
try
{
if
(
dateFormat
!=
null
)
{
return
new
java
.
sql
.
Date
(
dateFormat
.
parse
(
date
).
getTime
());
}
return
new
java
.
sql
.
Date
(
ISO8601Utils
.
parse
(
date
,
new
ParsePosition
(
0
)).
getTime
());
}
catch
(
ParseException
e
)
{
throw
new
JsonParseException
(
e
);
}
}
}
}
/**
* Gson TypeAdapter for java.util.Date type
* If the dateFormat is null, ISO8601Utils will be used.
*/
public
static
class
DateTypeAdapter
extends
TypeAdapter
<
Date
>
{
private
DateFormat
dateFormat
;
public
DateTypeAdapter
()
{
}
public
DateTypeAdapter
(
DateFormat
dateFormat
)
{
this
.
dateFormat
=
dateFormat
;
}
public
void
setFormat
(
DateFormat
dateFormat
)
{
this
.
dateFormat
=
dateFormat
;
}
@Override
public
void
write
(
JsonWriter
out
,
Date
date
)
throws
IOException
{
if
(
date
==
null
)
{
out
.
nullValue
();
}
else
{
String
value
;
if
(
dateFormat
!=
null
)
{
value
=
dateFormat
.
format
(
date
);
}
else
{
value
=
ISO8601Utils
.
format
(
date
,
true
);
}
out
.
value
(
value
);
}
}
@Override
public
Date
read
(
JsonReader
in
)
throws
IOException
{
try
{
switch
(
in
.
peek
())
{
case
NULL:
in
.
nextNull
();
return
null
;
default
:
String
date
=
in
.
nextString
();
try
{
if
(
dateFormat
!=
null
)
{
return
dateFormat
.
parse
(
date
);
}
return
ISO8601Utils
.
parse
(
date
,
new
ParsePosition
(
0
));
}
catch
(
ParseException
e
)
{
throw
new
JsonParseException
(
e
);
}
}
}
catch
(
IllegalArgumentException
e
)
{
throw
new
JsonParseException
(
e
);
}
}
}
public
JSON
setDateFormat
(
DateFormat
dateFormat
)
{
dateTypeAdapter
.
setFormat
(
dateFormat
);
return
this
;
}
public
JSON
setSqlDateFormat
(
DateFormat
dateFormat
)
{
sqlDateTypeAdapter
.
setFormat
(
dateFormat
);
return
this
;
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/Pair.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
sure_tosca
.
client
;
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.JavaClientCodegen"
,
date
=
"2019-11-01T13:11:24.211Z"
)
public
class
Pair
{
private
String
name
=
""
;
private
String
value
=
""
;
public
Pair
(
String
name
,
String
value
)
{
setName
(
name
);
setValue
(
value
);
}
private
void
setName
(
String
name
)
{
if
(!
isValidString
(
name
))
return
;
this
.
name
=
name
;
}
private
void
setValue
(
String
value
)
{
if
(!
isValidString
(
value
))
return
;
this
.
value
=
value
;
}
public
String
getName
()
{
return
this
.
name
;
}
public
String
getValue
()
{
return
this
.
value
;
}
private
boolean
isValidString
(
String
arg
)
{
if
(
arg
==
null
)
return
false
;
if
(
arg
.
trim
().
isEmpty
())
return
false
;
return
true
;
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/ProgressRequestBody.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
sure_tosca
.
client
;
import
com.squareup.okhttp.MediaType
;
import
com.squareup.okhttp.RequestBody
;
import
java.io.IOException
;
import
okio.Buffer
;
import
okio.BufferedSink
;
import
okio.ForwardingSink
;
import
okio.Okio
;
import
okio.Sink
;
public
class
ProgressRequestBody
extends
RequestBody
{
public
interface
ProgressRequestListener
{
void
onRequestProgress
(
long
bytesWritten
,
long
contentLength
,
boolean
done
);
}
private
final
RequestBody
requestBody
;
private
final
ProgressRequestListener
progressListener
;
public
ProgressRequestBody
(
RequestBody
requestBody
,
ProgressRequestListener
progressListener
)
{
this
.
requestBody
=
requestBody
;
this
.
progressListener
=
progressListener
;
}
@Override
public
MediaType
contentType
()
{
return
requestBody
.
contentType
();
}
@Override
public
long
contentLength
()
throws
IOException
{
return
requestBody
.
contentLength
();
}
@Override
public
void
writeTo
(
BufferedSink
sink
)
throws
IOException
{
BufferedSink
bufferedSink
=
Okio
.
buffer
(
sink
(
sink
));
requestBody
.
writeTo
(
bufferedSink
);
bufferedSink
.
flush
();
}
private
Sink
sink
(
Sink
sink
)
{
return
new
ForwardingSink
(
sink
)
{
long
bytesWritten
=
0L
;
long
contentLength
=
0L
;
@Override
public
void
write
(
Buffer
source
,
long
byteCount
)
throws
IOException
{
super
.
write
(
source
,
byteCount
);
if
(
contentLength
==
0
)
{
contentLength
=
contentLength
();
}
bytesWritten
+=
byteCount
;
progressListener
.
onRequestProgress
(
bytesWritten
,
contentLength
,
bytesWritten
==
contentLength
);
}
};
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/ProgressResponseBody.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
sure_tosca
.
client
;
import
com.squareup.okhttp.MediaType
;
import
com.squareup.okhttp.ResponseBody
;
import
java.io.IOException
;
import
okio.Buffer
;
import
okio.BufferedSource
;
import
okio.ForwardingSource
;
import
okio.Okio
;
import
okio.Source
;
public
class
ProgressResponseBody
extends
ResponseBody
{
public
interface
ProgressListener
{
void
update
(
long
bytesRead
,
long
contentLength
,
boolean
done
);
}
private
final
ResponseBody
responseBody
;
private
final
ProgressListener
progressListener
;
private
BufferedSource
bufferedSource
;
public
ProgressResponseBody
(
ResponseBody
responseBody
,
ProgressListener
progressListener
)
{
this
.
responseBody
=
responseBody
;
this
.
progressListener
=
progressListener
;
}
@Override
public
MediaType
contentType
()
{
return
responseBody
.
contentType
();
}
@Override
public
long
contentLength
()
throws
IOException
{
return
responseBody
.
contentLength
();
}
@Override
public
BufferedSource
source
()
throws
IOException
{
if
(
bufferedSource
==
null
)
{
bufferedSource
=
Okio
.
buffer
(
source
(
responseBody
.
source
()));
}
return
bufferedSource
;
}
private
Source
source
(
Source
source
)
{
return
new
ForwardingSource
(
source
)
{
long
totalBytesRead
=
0L
;
@Override
public
long
read
(
Buffer
sink
,
long
byteCount
)
throws
IOException
{
long
bytesRead
=
super
.
read
(
sink
,
byteCount
);
// read() returns the number of bytes read, or -1 if this source is exhausted.
totalBytesRead
+=
bytesRead
!=
-
1
?
bytesRead
:
0
;
progressListener
.
update
(
totalBytesRead
,
responseBody
.
contentLength
(),
bytesRead
==
-
1
);
return
bytesRead
;
}
};
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/sure_tosca/client/StringUtil.java
0 → 100644
View file @
8e781faa
/*
* tosca-sure
* TOSCA Simple qUeRy sErvice (SURE).
*
* OpenAPI spec version: 1.0.0
* Contact: S.Koulouzis@uva.nl
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
sure_tosca
.
client
;
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.JavaClientCodegen"
,
date
=
"2019-11-01T13:11:24.211Z"
)
public
class
StringUtil
{
/**
* Check if the given array contains the given value (with case-insensitive comparison).
*
* @param array The array
* @param value The value to search
* @return true if the array contains the value
*/
public
static
boolean
containsIgnoreCase
(
String
[]
array
,
String
value
)
{
for
(
String
str
:
array
)
{
if
(
value
==
null
&&
str
==
null
)
return
true
;
if
(
value
!=
null
&&
value
.
equalsIgnoreCase
(
str
))
return
true
;
}
return
false
;
}
/**
* Join an array of strings with the given separator.
* <p>
* Note: This might be replaced by utility method from commons-lang or guava someday
* if one of those libraries is added as dependency.
* </p>
*
* @param array The array of strings
* @param separator The separator
* @return the resulting string
*/
public
static
String
join
(
String
[]
array
,
String
separator
)
{
int
len
=
array
.
length
;
if
(
len
==
0
)
return
""
;
StringBuilder
out
=
new
StringBuilder
();
out
.
append
(
array
[
0
]);
for
(
int
i
=
1
;
i
<
len
;
i
++)
{
out
.
append
(
separator
).
append
(
array
[
i
]);
}
return
out
.
toString
();
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/TOSCAUtils.java
deleted
100644 → 0
View file @
9e9ab47b
/*
* Copyright 2019 S. Koulouzis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
utils
;
import
java.util.ArrayList
;
import
java.util.Base64
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
nl.uva.sne.drip.model.NodeTemplate
;
import
nl.uva.sne.drip.model.TopologyTemplate
;
import
nl.uva.sne.drip.model.ToscaTemplate
;
/**
*
* @author S. Koulouzis
*/
public
class
TOSCAUtils
{
private
static
List
<
Map
<
String
,
NodeTemplate
>>
getNodes
(
ToscaTemplate
toscaTemplate
,
String
filterType
,
String
filterValue
)
{
boolean
byType
=
false
;
boolean
byName
=
false
;
switch
(
filterType
)
{
case
"type"
:
byType
=
true
;
break
;
case
"name"
:
byName
=
true
;
break
;
}
TopologyTemplate
topologyTemplate
=
toscaTemplate
.
getTopologyTemplate
();
Map
<
String
,
NodeTemplate
>
nodeTemplates
=
topologyTemplate
.
getNodeTemplates
();
List
<
Map
<
String
,
NodeTemplate
>>
nodeList
=
new
ArrayList
<>();
Set
<
String
>
keys
=
nodeTemplates
.
keySet
();
for
(
String
key
:
keys
)
{
NodeTemplate
node
=
nodeTemplates
.
get
(
key
);
if
(
byName
&&
key
.
equals
(
filterValue
))
{
Map
<
String
,
NodeTemplate
>
ntMap
=
new
HashMap
<>();
ntMap
.
put
(
key
,
node
);
nodeList
.
add
(
ntMap
);
}
if
(
byType
)
{
if
(
node
.
getType
().
equals
(
filterValue
))
{
Map
<
String
,
NodeTemplate
>
ntMap
=
new
HashMap
<>();
ntMap
.
put
(
key
,
node
);
nodeList
.
add
(
ntMap
);
}
}
}
return
nodeList
;
}
public
static
List
<
Map
<
String
,
NodeTemplate
>>
getNodesByType
(
ToscaTemplate
toscaTemplate
,
String
nodeTypeName
)
{
return
getNodes
(
toscaTemplate
,
"type"
,
nodeTypeName
);
}
public
static
Map
<
String
,
Object
>
buildTOSCAOutput
(
Map
<
String
,
Object
>
outputs
,
String
nodeName
,
String
value
,
String
key
,
boolean
encodeValueToBas64
)
{
List
<
Map
<
String
,
String
>>
values
;
if
(
outputs
.
containsKey
(
key
))
{
values
=
(
List
<
Map
<
String
,
String
>>)
outputs
.
get
(
key
);
}
else
{
values
=
new
ArrayList
<>();
}
if
(
encodeValueToBas64
)
{
value
=
Base64
.
getEncoder
().
encodeToString
(
value
.
getBytes
());
}
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
nodeName
,
value
);
values
.
add
(
map
);
outputs
.
put
(
key
,
values
);
return
outputs
;
}
public
static
Map
<
String
,
String
>
getOutputsForNode
(
ToscaTemplate
toscaTemplate
,
String
nodeName
)
{
TopologyTemplate
topologyTemplate
=
toscaTemplate
.
getTopologyTemplate
();
List
<
Map
<
String
,
Object
>>
outputs
=
topologyTemplate
.
getOutputs
();
List
<
Map
<
String
,
Object
>>
matchedOutputs
=
new
ArrayList
<>();
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
//To change body of generated methods, choose Tools | Templates.
}
public
static
List
<
String
>
getOutputPair
(
Map
<
String
,
Object
>
outputs
,
String
key
)
{
List
<
String
>
outputPair
=
(
List
<
String
>)
((
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
outputs
.
get
(
key
)).
get
(
"value"
)).
get
(
"get_attribute"
);
return
outputPair
;
}
private
static
List
<
Map
<
String
,
Object
>>
getImageEnvirmoent
(
Map
<
String
,
Object
>
properties
)
{
Map
<
String
,
Object
>
envMap
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"environment"
);
List
<
Map
<
String
,
Object
>>
imageEnv
=
new
ArrayList
<>();
Set
<
String
>
keys
=
envMap
.
keySet
();
for
(
String
key
:
keys
)
{
Map
<
String
,
Object
>
kubernetesEnvMap
=
new
HashMap
();
kubernetesEnvMap
.
put
(
"name"
,
key
);
kubernetesEnvMap
.
put
(
"value"
,
envMap
.
get
(
key
));
imageEnv
.
add
(
kubernetesEnvMap
);
}
return
imageEnv
;
}
private
static
String
getImageFile
(
Map
<
String
,
Object
>
dockerValues
)
{
Map
<
String
,
Object
>
image
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
dockerValues
.
get
(
"artifacts"
)).
get
(
"image"
);
if
(
image
==
null
)
{
image
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
dockerValues
.
get
(
"artifacts"
)).
get
(
"my_image"
);
}
String
imageFile
=
(
String
)
image
.
get
(
"file"
);
return
imageFile
;
}
public
static
List
<
Map
<
String
,
NodeTemplate
>>
getRelatedNodes
(
NodeTemplate
node
,
ToscaTemplate
toscaTemplate
)
{
if
(
node
.
getRequirements
()
!=
null
)
{
List
<
String
>
nodeNames
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
requirements
=
node
.
getRequirements
();
for
(
Map
<
String
,
Object
>
requirement
:
requirements
)
{
String
reqName
=
requirement
.
keySet
().
iterator
().
next
();
Map
<
String
,
Object
>
requirementMap
=
(
Map
<
String
,
Object
>)
requirement
.
get
(
reqName
);
String
relatedNode
=
(
String
)
requirementMap
.
get
(
"node"
);
nodeNames
.
add
(
relatedNode
);
}
List
<
Map
<
String
,
NodeTemplate
>>
retaltedNodes
=
new
ArrayList
<>();
for
(
String
name
:
nodeNames
)
{
List
<
Map
<
String
,
NodeTemplate
>>
relatedNode
=
getNodesByName
(
toscaTemplate
,
name
);
for
(
Map
<
String
,
NodeTemplate
>
rNode
:
relatedNode
)
{
retaltedNodes
.
add
(
rNode
);
}
}
return
retaltedNodes
;
}
return
null
;
}
private
static
List
<
Map
<
String
,
NodeTemplate
>>
getNodesByName
(
ToscaTemplate
toscaTemplate
,
String
name
)
{
return
getNodes
(
toscaTemplate
,
"name"
,
name
);
}
public
static
boolean
nodeIsOfType
(
NodeTemplate
node
,
String
type
)
{
if
(
node
.
getType
().
equals
(
type
))
{
return
true
;
}
return
false
;
}
public
static
Object
getNodeProperty
(
NodeTemplate
node
,
String
propertyName
)
{
if
(
node
.
getProperties
()
!=
null
)
{
return
node
.
getProperties
().
get
(
propertyName
);
}
return
null
;
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java
0 → 100644
View file @
8e781faa
/*
* Copyright 2019 S. Koulouzis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
utils
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.dataformat.yaml.YAMLFactory
;
import
com.fasterxml.jackson.dataformat.yaml.YAMLGenerator
;
import
java.io.File
;
import
java.io.IOException
;
import
nl.uva.sne.drip.commons.sure_tosca.client.ApiException
;
import
nl.uva.sne.drip.commons.sure_tosca.client.DefaultApi
;
import
nl.uva.sne.drip.model.ToscaTemplate
;
import
org.apache.commons.io.FileUtils
;
/**
*
* @author S. Koulouzis
*/
public
class
ToscaHelper
{
private
final
DefaultApi
api
;
private
final
ObjectMapper
objectMapper
;
/**
* @return the id
*/
public
Integer
getId
()
{
return
id
;
}
private
final
Integer
id
;
public
ToscaHelper
(
ToscaTemplate
toscaTemplate
)
throws
JsonProcessingException
,
IOException
,
ApiException
{
api
=
new
DefaultApi
();
id
=
uploadToscaTemplate
(
toscaTemplate
);
this
.
objectMapper
=
new
ObjectMapper
(
new
YAMLFactory
().
disable
(
YAMLGenerator
.
Feature
.
WRITE_DOC_START_MARKER
));
objectMapper
.
disable
(
SerializationFeature
.
WRITE_DATES_AS_TIMESTAMPS
);
}
private
Integer
uploadToscaTemplate
(
ToscaTemplate
toscaTemplate
)
throws
JsonProcessingException
,
IOException
,
ApiException
{
String
ymlStr
=
objectMapper
.
writeValueAsString
(
toscaTemplate
);
File
toscaTemplateFile
=
File
.
createTempFile
(
"temp-toscaTemplate"
,
".yml"
);
FileUtils
.
writeByteArrayToFile
(
toscaTemplateFile
,
ymlStr
.
getBytes
());
String
resp
=
api
.
uploadToscaTemplate
(
toscaTemplateFile
);
return
null
;
}
}
drip-commons/src/main/java/nl/uva/sne/drip/model/Credentials.java
View file @
8e781faa
package
nl
.
uva
.
sne
.
drip
.
model
;
package
nl
.
uva
.
sne
.
drip
.
model
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
java.util.Objects
;
import
java.util.Objects
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
javax.validation.constraints.*
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
/**
/**
...
@@ -18,10 +22,23 @@ import org.springframework.data.annotation.Id;
...
@@ -18,10 +22,23 @@ import org.springframework.data.annotation.Id;
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
Credentials
{
public
class
Credentials
{
/**
* @return the id
*/
public
String
getId
()
{
return
id
;
}
/**
* @param id the id to set
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
@Id
@Id
@JsonIgnore
@JsonIgnore
private
String
id
;
private
String
id
;
@JsonProperty
(
"protocol"
)
@JsonProperty
(
"protocol"
)
private
String
protocol
=
null
;
private
String
protocol
=
null
;
...
@@ -45,21 +62,15 @@ public class Credentials {
...
@@ -45,21 +62,15 @@ public class Credentials {
this
.
protocol
=
protocol
;
this
.
protocol
=
protocol
;
return
this
;
return
this
;
}
}
@JsonIgnore
public
String
getId
()
{
return
id
;
}
public
void
setID
(
String
id
)
{
this
.
id
=
id
;
}
/**
/**
* Get protocol
* Get protocol
*
* @return protocol
* @return protocol
**/
*
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
String
getProtocol
()
{
public
String
getProtocol
()
{
return
protocol
;
return
protocol
;
}
}
...
@@ -75,11 +86,12 @@ public class Credentials {
...
@@ -75,11 +86,12 @@ public class Credentials {
/**
/**
* Get tokenType
* Get tokenType
*
* @return tokenType
* @return tokenType
**/
*
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
String
getTokenType
()
{
public
String
getTokenType
()
{
return
tokenType
;
return
tokenType
;
}
}
...
@@ -95,11 +107,12 @@ public class Credentials {
...
@@ -95,11 +107,12 @@ public class Credentials {
/**
/**
* Get token
* Get token
*
* @return token
* @return token
**/
*
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
String
getToken
()
{
public
String
getToken
()
{
return
token
;
return
token
;
}
}
...
@@ -123,11 +136,12 @@ public class Credentials {
...
@@ -123,11 +136,12 @@ public class Credentials {
/**
/**
* Get keys
* Get keys
*
* @return keys
* @return keys
**/
*
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
Map
<
String
,
String
>
getKeys
()
{
public
Map
<
String
,
String
>
getKeys
()
{
return
keys
;
return
keys
;
}
}
...
@@ -143,11 +157,12 @@ public class Credentials {
...
@@ -143,11 +157,12 @@ public class Credentials {
/**
/**
* Get user
* Get user
*
* @return user
* @return user
**/
*
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
String
getUser
()
{
public
String
getUser
()
{
return
user
;
return
user
;
}
}
...
@@ -163,11 +178,12 @@ public class Credentials {
...
@@ -163,11 +178,12 @@ public class Credentials {
/**
/**
* Get cloudProviderName
* Get cloudProviderName
*
* @return cloudProviderName
* @return cloudProviderName
**/
*
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
String
getCloudProviderName
()
{
public
String
getCloudProviderName
()
{
return
cloudProviderName
;
return
cloudProviderName
;
}
}
...
@@ -176,7 +192,6 @@ public class Credentials {
...
@@ -176,7 +192,6 @@ public class Credentials {
this
.
cloudProviderName
=
cloudProviderName
;
this
.
cloudProviderName
=
cloudProviderName
;
}
}
@Override
@Override
public
boolean
equals
(
java
.
lang
.
Object
o
)
{
public
boolean
equals
(
java
.
lang
.
Object
o
)
{
if
(
this
==
o
)
{
if
(
this
==
o
)
{
...
@@ -186,12 +201,12 @@ public class Credentials {
...
@@ -186,12 +201,12 @@ public class Credentials {
return
false
;
return
false
;
}
}
Credentials
credentials
=
(
Credentials
)
o
;
Credentials
credentials
=
(
Credentials
)
o
;
return
Objects
.
equals
(
this
.
protocol
,
credentials
.
protocol
)
&&
return
Objects
.
equals
(
this
.
protocol
,
credentials
.
protocol
)
Objects
.
equals
(
this
.
tokenType
,
credentials
.
tokenType
)
&&
&&
Objects
.
equals
(
this
.
tokenType
,
credentials
.
tokenType
)
Objects
.
equals
(
this
.
token
,
credentials
.
token
)
&&
&&
Objects
.
equals
(
this
.
token
,
credentials
.
token
)
Objects
.
equals
(
this
.
keys
,
credentials
.
keys
)
&&
&&
Objects
.
equals
(
this
.
keys
,
credentials
.
keys
)
Objects
.
equals
(
this
.
user
,
credentials
.
user
)
&&
&&
Objects
.
equals
(
this
.
user
,
credentials
.
user
)
Objects
.
equals
(
this
.
cloudProviderName
,
credentials
.
cloudProviderName
);
&&
Objects
.
equals
(
this
.
cloudProviderName
,
credentials
.
cloudProviderName
);
}
}
@Override
@Override
...
@@ -225,4 +240,3 @@ public class Credentials {
...
@@ -225,4 +240,3 @@ public class Credentials {
return
o
.
toString
().
replace
(
"\n"
,
"\n "
);
return
o
.
toString
().
replace
(
"\n"
,
"\n "
);
}
}
}
}
drip-commons/src/main/java/nl/uva/sne/drip/model/NodeTemplate.java
View file @
8e781faa
...
@@ -2,6 +2,10 @@ package nl.uva.sne.drip.model;
...
@@ -2,6 +2,10 @@ package nl.uva.sne.drip.model;
import
java.util.Objects
;
import
java.util.Objects
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -9,30 +13,44 @@ import java.util.List;
...
@@ -9,30 +13,44 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
javax.validation.constraints.*
;
import
org.springframework.data.annotation.Id
;
/**
/**
* NodeTemplate
* NodeTemplate
*/
*/
@Validated
@Validated
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.SpringCodegen"
,
date
=
"2019-10-25T14:09:25.182Z"
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
NodeTemplate
{
public
class
NodeTemplate
{
@JsonProperty
(
"type"
)
/**
private
String
type
=
null
;
* @return the id
*/
public
String
getId
()
{
return
id
;
}
@JsonProperty
(
"requirements"
)
/**
@Valid
* @param id the id to set
private
List
<
Map
<
String
,
Object
>>
requirements
=
null
;
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
@JsonProperty
(
"artifacts"
)
@Id
@Valid
@JsonIgnore
private
Map
<
String
,
Object
>
artifacts
=
null
;
private
String
id
;
@JsonProperty
(
"derived_from"
)
private
String
derivedFrom
=
null
;
@JsonProperty
(
"properties"
)
@JsonProperty
(
"properties"
)
@Valid
@Valid
private
Map
<
String
,
Object
>
properties
=
null
;
private
Map
<
String
,
Object
>
properties
=
null
;
@JsonProperty
(
"requirements"
)
@Valid
private
List
<
Map
<
String
,
Object
>>
requirements
=
null
;
@JsonProperty
(
"interfaces"
)
@JsonProperty
(
"interfaces"
)
@Valid
@Valid
private
Map
<
String
,
Object
>
interfaces
=
null
;
private
Map
<
String
,
Object
>
interfaces
=
null
;
...
@@ -41,29 +59,72 @@ public class NodeTemplate {
...
@@ -41,29 +59,72 @@ public class NodeTemplate {
@Valid
@Valid
private
Map
<
String
,
Object
>
capabilities
=
null
;
private
Map
<
String
,
Object
>
capabilities
=
null
;
@JsonProperty
(
"workflows"
)
@JsonProperty
(
"type"
)
private
String
type
=
null
;
@JsonProperty
(
"description"
)
private
String
description
=
null
;
@JsonProperty
(
"directives"
)
@Valid
@Valid
private
Map
<
String
,
Object
>
workflow
s
=
null
;
private
List
<
String
>
directive
s
=
null
;
public
NodeTemplate
type
(
String
type
)
{
@JsonProperty
(
"attributes"
)
this
.
type
=
type
;
@Valid
private
Map
<
String
,
Object
>
attributes
=
null
;
@JsonProperty
(
"artifacts"
)
@Valid
private
Map
<
String
,
Object
>
artifacts
=
null
;
public
NodeTemplate
derivedFrom
(
String
derivedFrom
)
{
this
.
derivedFrom
=
derivedFrom
;
return
this
;
return
this
;
}
}
/**
/**
* Get
type
* Get
derivedFrom
*
*
* @return
type
* @return
derivedFrom
*
*
*/
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
String
get
Type
()
{
public
String
get
DerivedFrom
()
{
return
type
;
return
derivedFrom
;
}
}
public
void
setType
(
String
type
)
{
public
void
setDerivedFrom
(
String
derivedFrom
)
{
this
.
type
=
type
;
this
.
derivedFrom
=
derivedFrom
;
}
public
NodeTemplate
properties
(
Map
<
String
,
Object
>
properties
)
{
this
.
properties
=
properties
;
return
this
;
}
public
NodeTemplate
putPropertiesItem
(
String
key
,
Object
propertiesItem
)
{
if
(
this
.
properties
==
null
)
{
this
.
properties
=
new
HashMap
<
String
,
Object
>();
}
this
.
properties
.
put
(
key
,
propertiesItem
);
return
this
;
}
/**
* Get properties
*
* @return properties
*
*/
@ApiModelProperty
(
value
=
""
)
public
Map
<
String
,
Object
>
getProperties
()
{
return
properties
;
}
public
void
setProperties
(
Map
<
String
,
Object
>
properties
)
{
this
.
properties
=
properties
;
}
}
public
NodeTemplate
requirements
(
List
<
Map
<
String
,
Object
>>
requirements
)
{
public
NodeTemplate
requirements
(
List
<
Map
<
String
,
Object
>>
requirements
)
{
...
@@ -97,149 +158,191 @@ public class NodeTemplate {
...
@@ -97,149 +158,191 @@ public class NodeTemplate {
this
.
requirements
=
requirements
;
this
.
requirements
=
requirements
;
}
}
public
NodeTemplate
artifacts
(
Map
<
String
,
Object
>
artifact
s
)
{
public
NodeTemplate
interfaces
(
Map
<
String
,
Object
>
interface
s
)
{
this
.
artifacts
=
artifact
s
;
this
.
interfaces
=
interface
s
;
return
this
;
return
this
;
}
}
public
NodeTemplate
put
ArtifactsItem
(
String
key
,
Object
artifact
sItem
)
{
public
NodeTemplate
put
InterfacesItem
(
String
key
,
Object
interface
sItem
)
{
if
(
this
.
artifact
s
==
null
)
{
if
(
this
.
interface
s
==
null
)
{
this
.
artifact
s
=
new
HashMap
<
String
,
Object
>();
this
.
interface
s
=
new
HashMap
<
String
,
Object
>();
}
}
this
.
artifacts
.
put
(
key
,
artifact
sItem
);
this
.
interfaces
.
put
(
key
,
interface
sItem
);
return
this
;
return
this
;
}
}
/**
/**
* Get
artifact
s
* Get
interface
s
*
*
* @return
artifact
s
* @return
interface
s
*
*
*/
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
Map
<
String
,
Object
>
get
Artifact
s
()
{
public
Map
<
String
,
Object
>
get
Interface
s
()
{
return
artifact
s
;
return
interface
s
;
}
}
public
void
set
Artifacts
(
Map
<
String
,
Object
>
artifact
s
)
{
public
void
set
Interfaces
(
Map
<
String
,
Object
>
interface
s
)
{
this
.
artifacts
=
artifact
s
;
this
.
interfaces
=
interface
s
;
}
}
public
NodeTemplate
properties
(
Map
<
String
,
Object
>
proper
ties
)
{
public
NodeTemplate
capabilities
(
Map
<
String
,
Object
>
capabili
ties
)
{
this
.
properties
=
proper
ties
;
this
.
capabilities
=
capabili
ties
;
return
this
;
return
this
;
}
}
public
NodeTemplate
put
PropertiesItem
(
String
key
,
Object
proper
tiesItem
)
{
public
NodeTemplate
put
CapabilitiesItem
(
String
key
,
Object
capabili
tiesItem
)
{
if
(
this
.
proper
ties
==
null
)
{
if
(
this
.
capabili
ties
==
null
)
{
this
.
proper
ties
=
new
HashMap
<
String
,
Object
>();
this
.
capabili
ties
=
new
HashMap
<
String
,
Object
>();
}
}
this
.
properties
.
put
(
key
,
proper
tiesItem
);
this
.
capabilities
.
put
(
key
,
capabili
tiesItem
);
return
this
;
return
this
;
}
}
/**
/**
* Get
proper
ties
* Get
capabili
ties
*
*
* @return
proper
ties
* @return
capabili
ties
*
*
*/
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
Map
<
String
,
Object
>
get
Proper
ties
()
{
public
Map
<
String
,
Object
>
get
Capabili
ties
()
{
return
proper
ties
;
return
capabili
ties
;
}
}
public
void
set
Properties
(
Map
<
String
,
Object
>
proper
ties
)
{
public
void
set
Capabilities
(
Map
<
String
,
Object
>
capabili
ties
)
{
this
.
properties
=
proper
ties
;
this
.
capabilities
=
capabili
ties
;
}
}
public
NodeTemplate
interfaces
(
Map
<
String
,
Object
>
interfaces
)
{
public
NodeTemplate
type
(
String
type
)
{
this
.
interfaces
=
interfaces
;
this
.
type
=
type
;
return
this
;
return
this
;
}
}
public
NodeTemplate
putInterfacesItem
(
String
key
,
Object
interfacesItem
)
{
/**
if
(
this
.
interfaces
==
null
)
{
* Get type
this
.
interfaces
=
new
HashMap
<>();
*
* @return type
*
*/
@ApiModelProperty
(
value
=
""
)
public
String
getType
()
{
return
type
;
}
}
this
.
interfaces
.
put
(
key
,
interfacesItem
);
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
public
NodeTemplate
description
(
String
description
)
{
this
.
description
=
description
;
return
this
;
return
this
;
}
}
/**
/**
* Get
interfaces
* Get
description
*
*
* @return
interfaces
* @return
description
*
*
*/
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
Map
<
String
,
Object
>
getInterfaces
()
{
public
String
getDescription
()
{
return
interfaces
;
return
description
;
}
}
public
void
set
Interfaces
(
Map
<
String
,
Object
>
interfaces
)
{
public
void
set
Description
(
String
description
)
{
this
.
interfaces
=
interfaces
;
this
.
description
=
description
;
}
}
public
NodeTemplate
capabilities
(
Map
<
String
,
Object
>
capabiliti
es
)
{
public
NodeTemplate
directives
(
List
<
String
>
directiv
es
)
{
this
.
capabilities
=
capabiliti
es
;
this
.
directives
=
directiv
es
;
return
this
;
return
this
;
}
}
public
NodeTemplate
putCapabilitiesItem
(
String
key
,
Object
capabiliti
esItem
)
{
public
NodeTemplate
addDirectivesItem
(
String
directiv
esItem
)
{
if
(
this
.
capabiliti
es
==
null
)
{
if
(
this
.
directiv
es
==
null
)
{
this
.
capabilities
=
new
HashMap
<
String
,
Object
>();
this
.
directives
=
new
ArrayList
<
String
>();
}
}
this
.
capabilities
.
put
(
key
,
capabiliti
esItem
);
this
.
directives
.
add
(
directiv
esItem
);
return
this
;
return
this
;
}
}
/**
/**
* Get
capabiliti
es
* Get
directiv
es
*
*
* @return
capabiliti
es
* @return
directiv
es
*
*
*/
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
Map
<
String
,
Object
>
getCapabiliti
es
()
{
public
List
<
String
>
getDirectiv
es
()
{
return
capabiliti
es
;
return
directiv
es
;
}
}
public
void
set
Capabilities
(
Map
<
String
,
Object
>
capabiliti
es
)
{
public
void
set
Directives
(
List
<
String
>
directiv
es
)
{
this
.
capabilities
=
capabiliti
es
;
this
.
directives
=
directiv
es
;
}
}
public
NodeTemplate
workflows
(
Map
<
String
,
Object
>
workflow
s
)
{
public
NodeTemplate
attributes
(
Map
<
String
,
Object
>
attribute
s
)
{
this
.
workflows
=
workflow
s
;
this
.
attributes
=
attribute
s
;
return
this
;
return
this
;
}
}
public
NodeTemplate
put
WorkflowsItem
(
String
key
,
Object
workflow
sItem
)
{
public
NodeTemplate
put
AttributesItem
(
String
key
,
Object
attribute
sItem
)
{
if
(
this
.
workflow
s
==
null
)
{
if
(
this
.
attribute
s
==
null
)
{
this
.
workflow
s
=
new
HashMap
<
String
,
Object
>();
this
.
attribute
s
=
new
HashMap
<
String
,
Object
>();
}
}
this
.
workflows
.
put
(
key
,
workflow
sItem
);
this
.
attributes
.
put
(
key
,
attribute
sItem
);
return
this
;
return
this
;
}
}
/**
/**
* Get
workflow
s
* Get
attribute
s
*
*
* @return
workflow
s
* @return
attribute
s
*
*
*/
*/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
Map
<
String
,
Object
>
getWorkflows
()
{
public
Map
<
String
,
Object
>
getAttributes
()
{
return
workflows
;
return
attributes
;
}
public
void
setAttributes
(
Map
<
String
,
Object
>
attributes
)
{
this
.
attributes
=
attributes
;
}
public
NodeTemplate
artifacts
(
Map
<
String
,
Object
>
artifacts
)
{
this
.
artifacts
=
artifacts
;
return
this
;
}
}
public
void
setWorkflows
(
Map
<
String
,
Object
>
workflows
)
{
public
NodeTemplate
putArtifactsItem
(
String
key
,
Object
artifactsItem
)
{
this
.
workflows
=
workflows
;
if
(
this
.
artifacts
==
null
)
{
this
.
artifacts
=
new
HashMap
<
String
,
Object
>();
}
this
.
artifacts
.
put
(
key
,
artifactsItem
);
return
this
;
}
/**
* Get artifacts
*
* @return artifacts
*
*/
@ApiModelProperty
(
value
=
""
)
public
Map
<
String
,
Object
>
getArtifacts
()
{
return
artifacts
;
}
public
void
setArtifacts
(
Map
<
String
,
Object
>
artifacts
)
{
this
.
artifacts
=
artifacts
;
}
}
@Override
@Override
...
@@ -251,31 +354,38 @@ public class NodeTemplate {
...
@@ -251,31 +354,38 @@ public class NodeTemplate {
return
false
;
return
false
;
}
}
NodeTemplate
nodeTemplate
=
(
NodeTemplate
)
o
;
NodeTemplate
nodeTemplate
=
(
NodeTemplate
)
o
;
return
Objects
.
equals
(
this
.
type
,
nodeTemplate
.
type
)
return
Objects
.
equals
(
this
.
derivedFrom
,
nodeTemplate
.
derivedFrom
)
&&
Objects
.
equals
(
this
.
requirements
,
nodeTemplate
.
requirements
)
&&
Objects
.
equals
(
this
.
artifacts
,
nodeTemplate
.
artifacts
)
&&
Objects
.
equals
(
this
.
properties
,
nodeTemplate
.
properties
)
&&
Objects
.
equals
(
this
.
properties
,
nodeTemplate
.
properties
)
&&
Objects
.
equals
(
this
.
requirements
,
nodeTemplate
.
requirements
)
&&
Objects
.
equals
(
this
.
interfaces
,
nodeTemplate
.
interfaces
)
&&
Objects
.
equals
(
this
.
interfaces
,
nodeTemplate
.
interfaces
)
&&
Objects
.
equals
(
this
.
capabilities
,
nodeTemplate
.
capabilities
)
&&
Objects
.
equals
(
this
.
capabilities
,
nodeTemplate
.
capabilities
)
&&
Objects
.
equals
(
this
.
workflows
,
nodeTemplate
.
workflows
);
&&
Objects
.
equals
(
this
.
type
,
nodeTemplate
.
type
)
&&
Objects
.
equals
(
this
.
description
,
nodeTemplate
.
description
)
&&
Objects
.
equals
(
this
.
directives
,
nodeTemplate
.
directives
)
&&
Objects
.
equals
(
this
.
attributes
,
nodeTemplate
.
attributes
)
&&
Objects
.
equals
(
this
.
artifacts
,
nodeTemplate
.
artifacts
);
}
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Objects
.
hash
(
type
,
requirements
,
artifacts
,
properties
,
interfaces
,
capabilities
,
workflow
s
);
return
Objects
.
hash
(
derivedFrom
,
properties
,
requirements
,
interfaces
,
capabilities
,
type
,
description
,
directives
,
attributes
,
artifact
s
);
}
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"class NodeTemplate {\n"
);
sb
.
append
(
"class NodeTemplate {\n"
);
sb
.
append
(
" type: "
).
append
(
toIndentedString
(
type
)).
append
(
"\n"
);
sb
.
append
(
" requirements: "
).
append
(
toIndentedString
(
requirements
)).
append
(
"\n"
);
sb
.
append
(
" derivedFrom: "
).
append
(
toIndentedString
(
derivedFrom
)).
append
(
"\n"
);
sb
.
append
(
" artifacts: "
).
append
(
toIndentedString
(
artifacts
)).
append
(
"\n"
);
sb
.
append
(
" properties: "
).
append
(
toIndentedString
(
properties
)).
append
(
"\n"
);
sb
.
append
(
" properties: "
).
append
(
toIndentedString
(
properties
)).
append
(
"\n"
);
sb
.
append
(
" requirements: "
).
append
(
toIndentedString
(
requirements
)).
append
(
"\n"
);
sb
.
append
(
" interfaces: "
).
append
(
toIndentedString
(
interfaces
)).
append
(
"\n"
);
sb
.
append
(
" interfaces: "
).
append
(
toIndentedString
(
interfaces
)).
append
(
"\n"
);
sb
.
append
(
" capabilities: "
).
append
(
toIndentedString
(
capabilities
)).
append
(
"\n"
);
sb
.
append
(
" capabilities: "
).
append
(
toIndentedString
(
capabilities
)).
append
(
"\n"
);
sb
.
append
(
" workflows: "
).
append
(
toIndentedString
(
workflows
)).
append
(
"\n"
);
sb
.
append
(
" type: "
).
append
(
toIndentedString
(
type
)).
append
(
"\n"
);
sb
.
append
(
" description: "
).
append
(
toIndentedString
(
description
)).
append
(
"\n"
);
sb
.
append
(
" directives: "
).
append
(
toIndentedString
(
directives
)).
append
(
"\n"
);
sb
.
append
(
" attributes: "
).
append
(
toIndentedString
(
attributes
)).
append
(
"\n"
);
sb
.
append
(
" artifacts: "
).
append
(
toIndentedString
(
artifacts
)).
append
(
"\n"
);
sb
.
append
(
"}"
);
sb
.
append
(
"}"
);
return
sb
.
toString
();
return
sb
.
toString
();
}
}
...
...
drip-commons/src/main/java/nl/uva/sne/drip/model/TopologyTemplate.java
View file @
8e781faa
...
@@ -2,6 +2,10 @@ package nl.uva.sne.drip.model;
...
@@ -2,6 +2,10 @@ package nl.uva.sne.drip.model;
import
java.util.Objects
;
import
java.util.Objects
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -9,14 +13,32 @@ import java.util.List;
...
@@ -9,14 +13,32 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
javax.validation.constraints.*
;
import
org.springframework.data.annotation.Id
;
/**
/**
* TopologyTemplate
* TopologyTemplate
*/
*/
@Validated
@Validated
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.SpringCodegen"
,
date
=
"2019-10-25T14:47:27.096Z"
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
TopologyTemplate
{
public
class
TopologyTemplate
{
/**
* @return the id
*/
public
String
getId
()
{
return
id
;
}
/**
* @param id the id to set
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
@Id
@JsonIgnore
private
String
id
;
@JsonProperty
(
"description"
)
@JsonProperty
(
"description"
)
private
String
description
=
null
;
private
String
description
=
null
;
...
@@ -24,14 +46,6 @@ public class TopologyTemplate {
...
@@ -24,14 +46,6 @@ public class TopologyTemplate {
@Valid
@Valid
private
List
<
Map
<
String
,
Object
>>
inputs
=
null
;
private
List
<
Map
<
String
,
Object
>>
inputs
=
null
;
@JsonProperty
(
"policies"
)
@Valid
private
List
<
Map
<
String
,
Object
>>
policies
=
null
;
@JsonProperty
(
"outputs"
)
@Valid
private
List
<
Map
<
String
,
Object
>>
outputs
=
null
;
@JsonProperty
(
"node_templates"
)
@JsonProperty
(
"node_templates"
)
@Valid
@Valid
private
Map
<
String
,
NodeTemplate
>
nodeTemplates
=
null
;
private
Map
<
String
,
NodeTemplate
>
nodeTemplates
=
null
;
...
@@ -40,6 +54,10 @@ public class TopologyTemplate {
...
@@ -40,6 +54,10 @@ public class TopologyTemplate {
@Valid
@Valid
private
Map
<
String
,
Object
>
relationshipTemplates
=
null
;
private
Map
<
String
,
Object
>
relationshipTemplates
=
null
;
@JsonProperty
(
"outputs"
)
@Valid
private
List
<
Map
<
String
,
Object
>>
outputs
=
null
;
@JsonProperty
(
"groups"
)
@JsonProperty
(
"groups"
)
@Valid
@Valid
private
Map
<
String
,
Object
>
groups
=
null
;
private
Map
<
String
,
Object
>
groups
=
null
;
...
@@ -48,6 +66,10 @@ public class TopologyTemplate {
...
@@ -48,6 +66,10 @@ public class TopologyTemplate {
@Valid
@Valid
private
Map
<
String
,
Object
>
substitutionMappings
=
null
;
private
Map
<
String
,
Object
>
substitutionMappings
=
null
;
@JsonProperty
(
"policies"
)
@Valid
private
List
<
Map
<
String
,
Object
>>
policies
=
null
;
public
TopologyTemplate
description
(
String
description
)
{
public
TopologyTemplate
description
(
String
description
)
{
this
.
description
=
description
;
this
.
description
=
description
;
return
this
;
return
this
;
...
@@ -97,64 +119,6 @@ public class TopologyTemplate {
...
@@ -97,64 +119,6 @@ public class TopologyTemplate {
this
.
inputs
=
inputs
;
this
.
inputs
=
inputs
;
}
}
public
TopologyTemplate
policies
(
List
<
Map
<
String
,
Object
>>
policies
)
{
this
.
policies
=
policies
;
return
this
;
}
public
TopologyTemplate
addPoliciesItem
(
Map
<
String
,
Object
>
policiesItem
)
{
if
(
this
.
policies
==
null
)
{
this
.
policies
=
new
ArrayList
<
Map
<
String
,
Object
>>();
}
this
.
policies
.
add
(
policiesItem
);
return
this
;
}
/**
* Get policies
* @return policies
**/
@ApiModelProperty
(
value
=
""
)
@Valid
public
List
<
Map
<
String
,
Object
>>
getPolicies
()
{
return
policies
;
}
public
void
setPolicies
(
List
<
Map
<
String
,
Object
>>
policies
)
{
this
.
policies
=
policies
;
}
public
TopologyTemplate
outputs
(
List
<
Map
<
String
,
Object
>>
outputs
)
{
this
.
outputs
=
outputs
;
return
this
;
}
public
TopologyTemplate
addOutputsItem
(
Map
<
String
,
Object
>
outputsItem
)
{
if
(
this
.
outputs
==
null
)
{
this
.
outputs
=
new
ArrayList
<
Map
<
String
,
Object
>>();
}
this
.
outputs
.
add
(
outputsItem
);
return
this
;
}
/**
* Get outputs
* @return outputs
**/
@ApiModelProperty
(
value
=
""
)
@Valid
public
List
<
Map
<
String
,
Object
>>
getOutputs
()
{
return
outputs
;
}
public
void
setOutputs
(
List
<
Map
<
String
,
Object
>>
outputs
)
{
this
.
outputs
=
outputs
;
}
public
TopologyTemplate
nodeTemplates
(
Map
<
String
,
NodeTemplate
>
nodeTemplates
)
{
public
TopologyTemplate
nodeTemplates
(
Map
<
String
,
NodeTemplate
>
nodeTemplates
)
{
this
.
nodeTemplates
=
nodeTemplates
;
this
.
nodeTemplates
=
nodeTemplates
;
return
this
;
return
this
;
...
@@ -212,6 +176,35 @@ public class TopologyTemplate {
...
@@ -212,6 +176,35 @@ public class TopologyTemplate {
this
.
relationshipTemplates
=
relationshipTemplates
;
this
.
relationshipTemplates
=
relationshipTemplates
;
}
}
public
TopologyTemplate
outputs
(
List
<
Map
<
String
,
Object
>>
outputs
)
{
this
.
outputs
=
outputs
;
return
this
;
}
public
TopologyTemplate
addOutputsItem
(
Map
<
String
,
Object
>
outputsItem
)
{
if
(
this
.
outputs
==
null
)
{
this
.
outputs
=
new
ArrayList
<
Map
<
String
,
Object
>>();
}
this
.
outputs
.
add
(
outputsItem
);
return
this
;
}
/**
* Get outputs
* @return outputs
**/
@ApiModelProperty
(
value
=
""
)
@Valid
public
List
<
Map
<
String
,
Object
>>
getOutputs
()
{
return
outputs
;
}
public
void
setOutputs
(
List
<
Map
<
String
,
Object
>>
outputs
)
{
this
.
outputs
=
outputs
;
}
public
TopologyTemplate
groups
(
Map
<
String
,
Object
>
groups
)
{
public
TopologyTemplate
groups
(
Map
<
String
,
Object
>
groups
)
{
this
.
groups
=
groups
;
this
.
groups
=
groups
;
return
this
;
return
this
;
...
@@ -268,6 +261,35 @@ public class TopologyTemplate {
...
@@ -268,6 +261,35 @@ public class TopologyTemplate {
this
.
substitutionMappings
=
substitutionMappings
;
this
.
substitutionMappings
=
substitutionMappings
;
}
}
public
TopologyTemplate
policies
(
List
<
Map
<
String
,
Object
>>
policies
)
{
this
.
policies
=
policies
;
return
this
;
}
public
TopologyTemplate
addPoliciesItem
(
Map
<
String
,
Object
>
policiesItem
)
{
if
(
this
.
policies
==
null
)
{
this
.
policies
=
new
ArrayList
<
Map
<
String
,
Object
>>();
}
this
.
policies
.
add
(
policiesItem
);
return
this
;
}
/**
* Get policies
* @return policies
**/
@ApiModelProperty
(
value
=
""
)
@Valid
public
List
<
Map
<
String
,
Object
>>
getPolicies
()
{
return
policies
;
}
public
void
setPolicies
(
List
<
Map
<
String
,
Object
>>
policies
)
{
this
.
policies
=
policies
;
}
@Override
@Override
public
boolean
equals
(
java
.
lang
.
Object
o
)
{
public
boolean
equals
(
java
.
lang
.
Object
o
)
{
...
@@ -280,17 +302,17 @@ public class TopologyTemplate {
...
@@ -280,17 +302,17 @@ public class TopologyTemplate {
TopologyTemplate
topologyTemplate
=
(
TopologyTemplate
)
o
;
TopologyTemplate
topologyTemplate
=
(
TopologyTemplate
)
o
;
return
Objects
.
equals
(
this
.
description
,
topologyTemplate
.
description
)
&&
return
Objects
.
equals
(
this
.
description
,
topologyTemplate
.
description
)
&&
Objects
.
equals
(
this
.
inputs
,
topologyTemplate
.
inputs
)
&&
Objects
.
equals
(
this
.
inputs
,
topologyTemplate
.
inputs
)
&&
Objects
.
equals
(
this
.
policies
,
topologyTemplate
.
policies
)
&&
Objects
.
equals
(
this
.
outputs
,
topologyTemplate
.
outputs
)
&&
Objects
.
equals
(
this
.
nodeTemplates
,
topologyTemplate
.
nodeTemplates
)
&&
Objects
.
equals
(
this
.
nodeTemplates
,
topologyTemplate
.
nodeTemplates
)
&&
Objects
.
equals
(
this
.
relationshipTemplates
,
topologyTemplate
.
relationshipTemplates
)
&&
Objects
.
equals
(
this
.
relationshipTemplates
,
topologyTemplate
.
relationshipTemplates
)
&&
Objects
.
equals
(
this
.
outputs
,
topologyTemplate
.
outputs
)
&&
Objects
.
equals
(
this
.
groups
,
topologyTemplate
.
groups
)
&&
Objects
.
equals
(
this
.
groups
,
topologyTemplate
.
groups
)
&&
Objects
.
equals
(
this
.
substitutionMappings
,
topologyTemplate
.
substitutionMappings
);
Objects
.
equals
(
this
.
substitutionMappings
,
topologyTemplate
.
substitutionMappings
)
&&
Objects
.
equals
(
this
.
policies
,
topologyTemplate
.
policies
);
}
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Objects
.
hash
(
description
,
inputs
,
policies
,
outputs
,
nodeTemplates
,
relationshipTemplates
,
groups
,
substitutionMapping
s
);
return
Objects
.
hash
(
description
,
inputs
,
nodeTemplates
,
relationshipTemplates
,
outputs
,
groups
,
substitutionMappings
,
policie
s
);
}
}
@Override
@Override
...
@@ -300,12 +322,12 @@ public class TopologyTemplate {
...
@@ -300,12 +322,12 @@ public class TopologyTemplate {
sb
.
append
(
" description: "
).
append
(
toIndentedString
(
description
)).
append
(
"\n"
);
sb
.
append
(
" description: "
).
append
(
toIndentedString
(
description
)).
append
(
"\n"
);
sb
.
append
(
" inputs: "
).
append
(
toIndentedString
(
inputs
)).
append
(
"\n"
);
sb
.
append
(
" inputs: "
).
append
(
toIndentedString
(
inputs
)).
append
(
"\n"
);
sb
.
append
(
" policies: "
).
append
(
toIndentedString
(
policies
)).
append
(
"\n"
);
sb
.
append
(
" outputs: "
).
append
(
toIndentedString
(
outputs
)).
append
(
"\n"
);
sb
.
append
(
" nodeTemplates: "
).
append
(
toIndentedString
(
nodeTemplates
)).
append
(
"\n"
);
sb
.
append
(
" nodeTemplates: "
).
append
(
toIndentedString
(
nodeTemplates
)).
append
(
"\n"
);
sb
.
append
(
" relationshipTemplates: "
).
append
(
toIndentedString
(
relationshipTemplates
)).
append
(
"\n"
);
sb
.
append
(
" relationshipTemplates: "
).
append
(
toIndentedString
(
relationshipTemplates
)).
append
(
"\n"
);
sb
.
append
(
" outputs: "
).
append
(
toIndentedString
(
outputs
)).
append
(
"\n"
);
sb
.
append
(
" groups: "
).
append
(
toIndentedString
(
groups
)).
append
(
"\n"
);
sb
.
append
(
" groups: "
).
append
(
toIndentedString
(
groups
)).
append
(
"\n"
);
sb
.
append
(
" substitutionMappings: "
).
append
(
toIndentedString
(
substitutionMappings
)).
append
(
"\n"
);
sb
.
append
(
" substitutionMappings: "
).
append
(
toIndentedString
(
substitutionMappings
)).
append
(
"\n"
);
sb
.
append
(
" policies: "
).
append
(
toIndentedString
(
policies
)).
append
(
"\n"
);
sb
.
append
(
"}"
);
sb
.
append
(
"}"
);
return
sb
.
toString
();
return
sb
.
toString
();
}
}
...
...
drip-commons/src/main/java/nl/uva/sne/drip/model/ToscaTemplate.java
View file @
8e781faa
package
nl
.
uva
.
sne
.
drip
.
model
;
package
nl
.
uva
.
sne
.
drip
.
model
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
java.util.Objects
;
import
java.util.Objects
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -11,6 +13,7 @@ import java.util.List;
...
@@ -11,6 +13,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
javax.validation.constraints.*
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
/**
/**
...
@@ -18,12 +21,24 @@ import org.springframework.data.annotation.Id;
...
@@ -18,12 +21,24 @@ import org.springframework.data.annotation.Id;
*/
*/
@Validated
@Validated
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
ToscaTemplate
{
public
class
ToscaTemplate
{
/**
* @return the id
*/
public
String
getId
()
{
return
id
;
}
/**
* @param id the id to set
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
@Id
@Id
@JsonIgnore
@JsonIgnore
private
String
id
;
private
String
id
;
@JsonProperty
(
"tosca_definitions_version"
)
@JsonProperty
(
"tosca_definitions_version"
)
private
String
toscaDefinitionsVersion
=
null
;
private
String
toscaDefinitionsVersion
=
null
;
...
@@ -33,25 +48,30 @@ public class ToscaTemplate {
...
@@ -33,25 +48,30 @@ public class ToscaTemplate {
@JsonProperty
(
"template_name"
)
@JsonProperty
(
"template_name"
)
private
String
templateName
=
null
;
private
String
templateName
=
null
;
@JsonProperty
(
"imports"
)
@JsonProperty
(
"topology_template"
)
@Valid
private
TopologyTemplate
topologyTemplate
=
null
;
private
List
<
Map
<
String
,
String
>>
imports
=
null
;
@JsonProperty
(
"repositories"
)
@JsonProperty
(
"template_author"
)
private
String
templateAuthor
=
null
;
@JsonProperty
(
"template_version"
)
private
String
templateVersion
=
null
;
@JsonProperty
(
"description"
)
private
String
description
=
null
;
@JsonProperty
(
"imports"
)
@Valid
@Valid
private
Map
<
String
,
String
>
repositorie
s
=
null
;
private
List
<
Map
<
String
,
Object
>>
import
s
=
null
;
@JsonProperty
(
"dsl_definitions"
)
@JsonProperty
(
"dsl_definitions"
)
@Valid
@Valid
private
Map
<
String
,
String
>
dslDefinitions
=
null
;
private
Map
<
String
,
Object
>
dslDefinitions
=
null
;
@JsonProperty
(
"node_types"
)
@JsonProperty
(
"node_types"
)
@Valid
@Valid
private
Map
<
String
,
Object
>
nodeTypes
=
null
;
private
Map
<
String
,
Object
>
nodeTypes
=
null
;
@JsonProperty
(
"topology_template"
)
private
TopologyTemplate
topologyTemplate
=
null
;
@JsonProperty
(
"relationship_types"
)
@JsonProperty
(
"relationship_types"
)
@Valid
@Valid
private
Map
<
String
,
Object
>
relationshipTypes
=
null
;
private
Map
<
String
,
Object
>
relationshipTypes
=
null
;
...
@@ -84,24 +104,15 @@ public class ToscaTemplate {
...
@@ -84,24 +104,15 @@ public class ToscaTemplate {
@Valid
@Valid
private
Map
<
String
,
Object
>
groupTypes
=
null
;
private
Map
<
String
,
Object
>
groupTypes
=
null
;
@JsonProperty
(
"description"
)
@JsonProperty
(
"repositories"
)
private
String
description
=
null
;
@Valid
private
Map
<
String
,
Object
>
repositories
=
null
;
@JsonProperty
(
"template_author"
)
private
String
templateAuthor
=
null
;
public
ToscaTemplate
toscaDefinitionsVersion
(
String
toscaDefinitionsVersion
)
{
public
ToscaTemplate
toscaDefinitionsVersion
(
String
toscaDefinitionsVersion
)
{
this
.
toscaDefinitionsVersion
=
toscaDefinitionsVersion
;
this
.
toscaDefinitionsVersion
=
toscaDefinitionsVersion
;
return
this
;
return
this
;
}
}
@JsonIgnore
public
String
getId
()
{
return
id
;
}
public
void
setID
(
String
id
)
{
this
.
id
=
id
;
}
/**
/**
* Get toscaDefinitionsVersion
* Get toscaDefinitionsVersion
* @return toscaDefinitionsVersion
* @return toscaDefinitionsVersion
...
@@ -157,71 +168,124 @@ public class ToscaTemplate {
...
@@ -157,71 +168,124 @@ public class ToscaTemplate {
this
.
templateName
=
templateName
;
this
.
templateName
=
templateName
;
}
}
public
ToscaTemplate
imports
(
List
<
Map
<
String
,
String
>>
imports
)
{
public
ToscaTemplate
topologyTemplate
(
TopologyTemplate
topologyTemplate
)
{
this
.
imports
=
imports
;
this
.
topologyTemplate
=
topologyTemplate
;
return
this
;
return
this
;
}
}
public
ToscaTemplate
addImportsItem
(
Map
<
String
,
String
>
importsItem
)
{
/**
if
(
this
.
imports
==
null
)
{
* Get topologyTemplate
this
.
imports
=
new
ArrayList
<
Map
<
String
,
String
>>();
* @return topologyTemplate
**/
@ApiModelProperty
(
value
=
""
)
@Valid
public
TopologyTemplate
getTopologyTemplate
()
{
return
topologyTemplate
;
}
}
this
.
imports
.
add
(
importsItem
);
public
void
setTopologyTemplate
(
TopologyTemplate
topologyTemplate
)
{
this
.
topologyTemplate
=
topologyTemplate
;
}
public
ToscaTemplate
templateAuthor
(
String
templateAuthor
)
{
this
.
templateAuthor
=
templateAuthor
;
return
this
;
return
this
;
}
}
/**
/**
* Get
imports
* Get
templateAuthor
* @return
imports
* @return
templateAuthor
**/
**/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
@Valid
public
List
<
Map
<
String
,
String
>>
getImports
()
{
public
String
getTemplateAuthor
()
{
return
imports
;
return
templateAuthor
;
}
}
public
void
set
Imports
(
List
<
Map
<
String
,
String
>>
imports
)
{
public
void
set
TemplateAuthor
(
String
templateAuthor
)
{
this
.
imports
=
imports
;
this
.
templateAuthor
=
templateAuthor
;
}
}
public
ToscaTemplate
repositories
(
Map
<
String
,
String
>
repositories
)
{
public
ToscaTemplate
templateVersion
(
String
templateVersion
)
{
this
.
repositories
=
repositories
;
this
.
templateVersion
=
templateVersion
;
return
this
;
return
this
;
}
}
public
ToscaTemplate
putRepositoriesItem
(
String
key
,
String
repositoriesItem
)
{
/**
if
(
this
.
repositories
==
null
)
{
* Get templateVersion
this
.
repositories
=
new
HashMap
<>();
* @return templateVersion
**/
@ApiModelProperty
(
value
=
""
)
public
String
getTemplateVersion
()
{
return
templateVersion
;
}
}
this
.
repositories
.
put
(
key
,
repositoriesItem
);
public
void
setTemplateVersion
(
String
templateVersion
)
{
this
.
templateVersion
=
templateVersion
;
}
public
ToscaTemplate
description
(
String
description
)
{
this
.
description
=
description
;
return
this
;
return
this
;
}
}
/**
/**
* Get
repositories
* Get
description
* @return
repositories
* @return
description
**/
**/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
Map
<
String
,
String
>
getRepositories
()
{
public
String
getDescription
()
{
return
repositories
;
return
description
;
}
}
public
void
setRepositories
(
Map
<
String
,
String
>
repositories
)
{
public
void
setDescription
(
String
description
)
{
this
.
repositories
=
repositories
;
this
.
description
=
description
;
}
public
ToscaTemplate
imports
(
List
<
Map
<
String
,
Object
>>
imports
)
{
this
.
imports
=
imports
;
return
this
;
}
public
ToscaTemplate
addImportsItem
(
Map
<
String
,
Object
>
importsItem
)
{
if
(
this
.
imports
==
null
)
{
this
.
imports
=
new
ArrayList
<
Map
<
String
,
Object
>>();
}
this
.
imports
.
add
(
importsItem
);
return
this
;
}
/**
* Get imports
* @return imports
**/
@ApiModelProperty
(
value
=
""
)
@Valid
public
List
<
Map
<
String
,
Object
>>
getImports
()
{
return
imports
;
}
public
void
setImports
(
List
<
Map
<
String
,
Object
>>
imports
)
{
this
.
imports
=
imports
;
}
}
public
ToscaTemplate
dslDefinitions
(
Map
<
String
,
String
>
dslDefinitions
)
{
public
ToscaTemplate
dslDefinitions
(
Map
<
String
,
Object
>
dslDefinitions
)
{
this
.
dslDefinitions
=
dslDefinitions
;
this
.
dslDefinitions
=
dslDefinitions
;
return
this
;
return
this
;
}
}
public
ToscaTemplate
putDslDefinitionsItem
(
String
key
,
String
dslDefinitionsItem
)
{
public
ToscaTemplate
putDslDefinitionsItem
(
String
key
,
Object
dslDefinitionsItem
)
{
if
(
this
.
dslDefinitions
==
null
)
{
if
(
this
.
dslDefinitions
==
null
)
{
this
.
dslDefinitions
=
new
HashMap
<
String
,
String
>();
this
.
dslDefinitions
=
new
HashMap
<
String
,
Object
>();
}
}
this
.
dslDefinitions
.
put
(
key
,
dslDefinitionsItem
);
this
.
dslDefinitions
.
put
(
key
,
dslDefinitionsItem
);
return
this
;
return
this
;
...
@@ -234,11 +298,11 @@ public class ToscaTemplate {
...
@@ -234,11 +298,11 @@ public class ToscaTemplate {
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
Map
<
String
,
String
>
getDslDefinitions
()
{
public
Map
<
String
,
Object
>
getDslDefinitions
()
{
return
dslDefinitions
;
return
dslDefinitions
;
}
}
public
void
setDslDefinitions
(
Map
<
String
,
String
>
dslDefinitions
)
{
public
void
setDslDefinitions
(
Map
<
String
,
Object
>
dslDefinitions
)
{
this
.
dslDefinitions
=
dslDefinitions
;
this
.
dslDefinitions
=
dslDefinitions
;
}
}
...
@@ -270,27 +334,6 @@ public class ToscaTemplate {
...
@@ -270,27 +334,6 @@ public class ToscaTemplate {
this
.
nodeTypes
=
nodeTypes
;
this
.
nodeTypes
=
nodeTypes
;
}
}
public
ToscaTemplate
topologyTemplate
(
TopologyTemplate
topologyTemplate
)
{
this
.
topologyTemplate
=
topologyTemplate
;
return
this
;
}
/**
* Get topologyTemplate
* @return topologyTemplate
**/
@ApiModelProperty
(
value
=
""
)
@Valid
public
TopologyTemplate
getTopologyTemplate
()
{
return
topologyTemplate
;
}
public
void
setTopologyTemplate
(
TopologyTemplate
topologyTemplate
)
{
this
.
topologyTemplate
=
topologyTemplate
;
}
public
ToscaTemplate
relationshipTypes
(
Map
<
String
,
Object
>
relationshipTypes
)
{
public
ToscaTemplate
relationshipTypes
(
Map
<
String
,
Object
>
relationshipTypes
)
{
this
.
relationshipTypes
=
relationshipTypes
;
this
.
relationshipTypes
=
relationshipTypes
;
return
this
;
return
this
;
...
@@ -515,44 +558,32 @@ public class ToscaTemplate {
...
@@ -515,44 +558,32 @@ public class ToscaTemplate {
this
.
groupTypes
=
groupTypes
;
this
.
groupTypes
=
groupTypes
;
}
}
public
ToscaTemplate
description
(
String
description
)
{
public
ToscaTemplate
repositories
(
Map
<
String
,
Object
>
repositories
)
{
this
.
description
=
description
;
this
.
repositories
=
repositories
;
return
this
;
return
this
;
}
}
/**
public
ToscaTemplate
putRepositoriesItem
(
String
key
,
Object
repositoriesItem
)
{
* Get description
if
(
this
.
repositories
==
null
)
{
* @return description
this
.
repositories
=
new
HashMap
<
String
,
Object
>();
**/
@ApiModelProperty
(
value
=
""
)
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
}
this
.
repositories
.
put
(
key
,
repositoriesItem
);
public
ToscaTemplate
templateAuthor
(
String
templateAuthor
)
{
this
.
templateAuthor
=
templateAuthor
;
return
this
;
return
this
;
}
}
/**
/**
* Get
templateAuthor
* Get
repositories
* @return
templateAuthor
* @return
repositories
**/
**/
@ApiModelProperty
(
value
=
""
)
@ApiModelProperty
(
value
=
""
)
public
String
getTemplateAuthor
()
{
public
Map
<
String
,
Object
>
getRepositories
()
{
return
templateAuthor
;
return
repositories
;
}
}
public
void
set
TemplateAuthor
(
String
templateAuthor
)
{
public
void
set
Repositories
(
Map
<
String
,
Object
>
repositories
)
{
this
.
templateAuthor
=
templateAuthor
;
this
.
repositories
=
repositories
;
}
}
...
@@ -568,11 +599,13 @@ public class ToscaTemplate {
...
@@ -568,11 +599,13 @@ public class ToscaTemplate {
return
Objects
.
equals
(
this
.
toscaDefinitionsVersion
,
toscaTemplate
.
toscaDefinitionsVersion
)
&&
return
Objects
.
equals
(
this
.
toscaDefinitionsVersion
,
toscaTemplate
.
toscaDefinitionsVersion
)
&&
Objects
.
equals
(
this
.
toscaDefaultNamespace
,
toscaTemplate
.
toscaDefaultNamespace
)
&&
Objects
.
equals
(
this
.
toscaDefaultNamespace
,
toscaTemplate
.
toscaDefaultNamespace
)
&&
Objects
.
equals
(
this
.
templateName
,
toscaTemplate
.
templateName
)
&&
Objects
.
equals
(
this
.
templateName
,
toscaTemplate
.
templateName
)
&&
Objects
.
equals
(
this
.
topologyTemplate
,
toscaTemplate
.
topologyTemplate
)
&&
Objects
.
equals
(
this
.
templateAuthor
,
toscaTemplate
.
templateAuthor
)
&&
Objects
.
equals
(
this
.
templateVersion
,
toscaTemplate
.
templateVersion
)
&&
Objects
.
equals
(
this
.
description
,
toscaTemplate
.
description
)
&&
Objects
.
equals
(
this
.
imports
,
toscaTemplate
.
imports
)
&&
Objects
.
equals
(
this
.
imports
,
toscaTemplate
.
imports
)
&&
Objects
.
equals
(
this
.
repositories
,
toscaTemplate
.
repositories
)
&&
Objects
.
equals
(
this
.
dslDefinitions
,
toscaTemplate
.
dslDefinitions
)
&&
Objects
.
equals
(
this
.
dslDefinitions
,
toscaTemplate
.
dslDefinitions
)
&&
Objects
.
equals
(
this
.
nodeTypes
,
toscaTemplate
.
nodeTypes
)
&&
Objects
.
equals
(
this
.
nodeTypes
,
toscaTemplate
.
nodeTypes
)
&&
Objects
.
equals
(
this
.
topologyTemplate
,
toscaTemplate
.
topologyTemplate
)
&&
Objects
.
equals
(
this
.
relationshipTypes
,
toscaTemplate
.
relationshipTypes
)
&&
Objects
.
equals
(
this
.
relationshipTypes
,
toscaTemplate
.
relationshipTypes
)
&&
Objects
.
equals
(
this
.
relationshipTemplates
,
toscaTemplate
.
relationshipTemplates
)
&&
Objects
.
equals
(
this
.
relationshipTemplates
,
toscaTemplate
.
relationshipTemplates
)
&&
Objects
.
equals
(
this
.
capabilityTypes
,
toscaTemplate
.
capabilityTypes
)
&&
Objects
.
equals
(
this
.
capabilityTypes
,
toscaTemplate
.
capabilityTypes
)
&&
...
@@ -581,13 +614,12 @@ public class ToscaTemplate {
...
@@ -581,13 +614,12 @@ public class ToscaTemplate {
Objects
.
equals
(
this
.
interfaceTypes
,
toscaTemplate
.
interfaceTypes
)
&&
Objects
.
equals
(
this
.
interfaceTypes
,
toscaTemplate
.
interfaceTypes
)
&&
Objects
.
equals
(
this
.
policyTypes
,
toscaTemplate
.
policyTypes
)
&&
Objects
.
equals
(
this
.
policyTypes
,
toscaTemplate
.
policyTypes
)
&&
Objects
.
equals
(
this
.
groupTypes
,
toscaTemplate
.
groupTypes
)
&&
Objects
.
equals
(
this
.
groupTypes
,
toscaTemplate
.
groupTypes
)
&&
Objects
.
equals
(
this
.
description
,
toscaTemplate
.
description
)
&&
Objects
.
equals
(
this
.
repositories
,
toscaTemplate
.
repositories
);
Objects
.
equals
(
this
.
templateAuthor
,
toscaTemplate
.
templateAuthor
);
}
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Objects
.
hash
(
toscaDefinitionsVersion
,
toscaDefaultNamespace
,
templateName
,
imports
,
repositories
,
dslDefinitions
,
nodeTypes
,
topologyTemplate
,
relationshipTypes
,
relationshipTemplates
,
capabilityTypes
,
artifactTypes
,
dataTypes
,
interfaceTypes
,
policyTypes
,
groupTypes
,
description
,
templateAuthor
);
return
Objects
.
hash
(
toscaDefinitionsVersion
,
toscaDefaultNamespace
,
templateName
,
topologyTemplate
,
templateAuthor
,
templateVersion
,
description
,
imports
,
dslDefinitions
,
nodeTypes
,
relationshipTypes
,
relationshipTemplates
,
capabilityTypes
,
artifactTypes
,
dataTypes
,
interfaceTypes
,
policyTypes
,
groupTypes
,
repositories
);
}
}
@Override
@Override
...
@@ -598,11 +630,13 @@ public class ToscaTemplate {
...
@@ -598,11 +630,13 @@ public class ToscaTemplate {
sb
.
append
(
" toscaDefinitionsVersion: "
).
append
(
toIndentedString
(
toscaDefinitionsVersion
)).
append
(
"\n"
);
sb
.
append
(
" toscaDefinitionsVersion: "
).
append
(
toIndentedString
(
toscaDefinitionsVersion
)).
append
(
"\n"
);
sb
.
append
(
" toscaDefaultNamespace: "
).
append
(
toIndentedString
(
toscaDefaultNamespace
)).
append
(
"\n"
);
sb
.
append
(
" toscaDefaultNamespace: "
).
append
(
toIndentedString
(
toscaDefaultNamespace
)).
append
(
"\n"
);
sb
.
append
(
" templateName: "
).
append
(
toIndentedString
(
templateName
)).
append
(
"\n"
);
sb
.
append
(
" templateName: "
).
append
(
toIndentedString
(
templateName
)).
append
(
"\n"
);
sb
.
append
(
" topologyTemplate: "
).
append
(
toIndentedString
(
topologyTemplate
)).
append
(
"\n"
);
sb
.
append
(
" templateAuthor: "
).
append
(
toIndentedString
(
templateAuthor
)).
append
(
"\n"
);
sb
.
append
(
" templateVersion: "
).
append
(
toIndentedString
(
templateVersion
)).
append
(
"\n"
);
sb
.
append
(
" description: "
).
append
(
toIndentedString
(
description
)).
append
(
"\n"
);
sb
.
append
(
" imports: "
).
append
(
toIndentedString
(
imports
)).
append
(
"\n"
);
sb
.
append
(
" imports: "
).
append
(
toIndentedString
(
imports
)).
append
(
"\n"
);
sb
.
append
(
" repositories: "
).
append
(
toIndentedString
(
repositories
)).
append
(
"\n"
);
sb
.
append
(
" dslDefinitions: "
).
append
(
toIndentedString
(
dslDefinitions
)).
append
(
"\n"
);
sb
.
append
(
" dslDefinitions: "
).
append
(
toIndentedString
(
dslDefinitions
)).
append
(
"\n"
);
sb
.
append
(
" nodeTypes: "
).
append
(
toIndentedString
(
nodeTypes
)).
append
(
"\n"
);
sb
.
append
(
" nodeTypes: "
).
append
(
toIndentedString
(
nodeTypes
)).
append
(
"\n"
);
sb
.
append
(
" topologyTemplate: "
).
append
(
toIndentedString
(
topologyTemplate
)).
append
(
"\n"
);
sb
.
append
(
" relationshipTypes: "
).
append
(
toIndentedString
(
relationshipTypes
)).
append
(
"\n"
);
sb
.
append
(
" relationshipTypes: "
).
append
(
toIndentedString
(
relationshipTypes
)).
append
(
"\n"
);
sb
.
append
(
" relationshipTemplates: "
).
append
(
toIndentedString
(
relationshipTemplates
)).
append
(
"\n"
);
sb
.
append
(
" relationshipTemplates: "
).
append
(
toIndentedString
(
relationshipTemplates
)).
append
(
"\n"
);
sb
.
append
(
" capabilityTypes: "
).
append
(
toIndentedString
(
capabilityTypes
)).
append
(
"\n"
);
sb
.
append
(
" capabilityTypes: "
).
append
(
toIndentedString
(
capabilityTypes
)).
append
(
"\n"
);
...
@@ -611,8 +645,7 @@ public class ToscaTemplate {
...
@@ -611,8 +645,7 @@ public class ToscaTemplate {
sb
.
append
(
" interfaceTypes: "
).
append
(
toIndentedString
(
interfaceTypes
)).
append
(
"\n"
);
sb
.
append
(
" interfaceTypes: "
).
append
(
toIndentedString
(
interfaceTypes
)).
append
(
"\n"
);
sb
.
append
(
" policyTypes: "
).
append
(
toIndentedString
(
policyTypes
)).
append
(
"\n"
);
sb
.
append
(
" policyTypes: "
).
append
(
toIndentedString
(
policyTypes
)).
append
(
"\n"
);
sb
.
append
(
" groupTypes: "
).
append
(
toIndentedString
(
groupTypes
)).
append
(
"\n"
);
sb
.
append
(
" groupTypes: "
).
append
(
toIndentedString
(
groupTypes
)).
append
(
"\n"
);
sb
.
append
(
" description: "
).
append
(
toIndentedString
(
description
)).
append
(
"\n"
);
sb
.
append
(
" repositories: "
).
append
(
toIndentedString
(
repositories
)).
append
(
"\n"
);
sb
.
append
(
" templateAuthor: "
).
append
(
toIndentedString
(
templateAuthor
)).
append
(
"\n"
);
sb
.
append
(
"}"
);
sb
.
append
(
"}"
);
return
sb
.
toString
();
return
sb
.
toString
();
}
}
...
...
drip-commons/src/main/java/nl/uva/sne/drip/model/User.java
View file @
8e781faa
package
nl
.
uva
.
sne
.
drip
.
model
;
package
nl
.
uva
.
sne
.
drip
.
model
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
java.util.Objects
;
import
java.util.Objects
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
javax.validation.Valid
;
import
javax.validation.constraints.*
;
import
org.springframework.data.annotation.Id
;
/**
/**
* User
* User
*/
*/
@Validated
@Validated
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.SpringCodegen"
,
date
=
"2019-10-25T14:09:25.182Z"
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
User
{
public
class
User
{
@JsonProperty
(
"id"
)
private
Long
id
=
null
;
@JsonProperty
(
"username"
)
private
String
username
=
null
;
@JsonProperty
(
"firstName"
)
private
String
firstName
=
null
;
@JsonProperty
(
"lastName"
)
private
String
lastName
=
null
;
@JsonProperty
(
"email"
)
private
String
email
=
null
;
@JsonProperty
(
"password"
)
private
String
password
=
null
;
@JsonProperty
(
"userStatus"
)
private
Integer
userStatus
=
null
;
public
User
id
(
Long
id
)
{
this
.
id
=
id
;
return
this
;
}
/**
/**
* Get id
* @return the id
* @return id
*/
**/
public
String
getId
()
{
@ApiModelProperty
(
value
=
""
)
public
Long
getId
()
{
return
id
;
return
id
;
}
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
User
username
(
String
username
)
{
this
.
username
=
username
;
return
this
;
}
/**
* Get username
* @return username
**/
@ApiModelProperty
(
value
=
""
)
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
User
firstName
(
String
firstName
)
{
this
.
firstName
=
firstName
;
return
this
;
}
/**
* Get firstName
* @return firstName
**/
@ApiModelProperty
(
value
=
""
)
public
String
getFirstName
()
{
return
firstName
;
}
public
void
setFirstName
(
String
firstName
)
{
this
.
firstName
=
firstName
;
}
public
User
lastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
return
this
;
}
/**
/**
* Get lastName
* @param id the id to set
* @return lastName
*/
**/
public
void
setId
(
String
id
)
{
@ApiModelProperty
(
value
=
""
)
this
.
id
=
id
;
public
String
getLastName
()
{
return
lastName
;
}
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
public
User
email
(
String
email
)
{
this
.
email
=
email
;
return
this
;
}
/**
* Get email
* @return email
**/
@ApiModelProperty
(
value
=
""
)
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
User
password
(
String
password
)
{
this
.
password
=
password
;
return
this
;
}
/**
* Get password
* @return password
**/
@ApiModelProperty
(
value
=
""
)
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
User
userStatus
(
Integer
userStatus
)
{
this
.
userStatus
=
userStatus
;
return
this
;
}
/**
* User Status
* @return userStatus
**/
@ApiModelProperty
(
value
=
"User Status"
)
public
Integer
getUserStatus
()
{
return
userStatus
;
}
public
void
setUserStatus
(
Integer
userStatus
)
{
this
.
userStatus
=
userStatus
;
}
}
@Id
@JsonIgnore
private
String
id
;
@Override
@Override
public
boolean
equals
(
java
.
lang
.
Object
o
)
{
public
boolean
equals
(
java
.
lang
.
Object
o
)
{
...
@@ -182,19 +41,12 @@ public class User {
...
@@ -182,19 +41,12 @@ public class User {
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
return
false
;
}
}
User
user
=
(
User
)
o
;
return
true
;
return
Objects
.
equals
(
this
.
id
,
user
.
id
)
&&
Objects
.
equals
(
this
.
username
,
user
.
username
)
&&
Objects
.
equals
(
this
.
firstName
,
user
.
firstName
)
&&
Objects
.
equals
(
this
.
lastName
,
user
.
lastName
)
&&
Objects
.
equals
(
this
.
email
,
user
.
email
)
&&
Objects
.
equals
(
this
.
password
,
user
.
password
)
&&
Objects
.
equals
(
this
.
userStatus
,
user
.
userStatus
);
}
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Objects
.
hash
(
id
,
username
,
firstName
,
lastName
,
email
,
password
,
userStatus
);
return
Objects
.
hash
(
);
}
}
@Override
@Override
...
@@ -202,13 +54,6 @@ public class User {
...
@@ -202,13 +54,6 @@ public class User {
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"class User {\n"
);
sb
.
append
(
"class User {\n"
);
sb
.
append
(
" id: "
).
append
(
toIndentedString
(
id
)).
append
(
"\n"
);
sb
.
append
(
" username: "
).
append
(
toIndentedString
(
username
)).
append
(
"\n"
);
sb
.
append
(
" firstName: "
).
append
(
toIndentedString
(
firstName
)).
append
(
"\n"
);
sb
.
append
(
" lastName: "
).
append
(
toIndentedString
(
lastName
)).
append
(
"\n"
);
sb
.
append
(
" email: "
).
append
(
toIndentedString
(
email
)).
append
(
"\n"
);
sb
.
append
(
" password: "
).
append
(
toIndentedString
(
password
)).
append
(
"\n"
);
sb
.
append
(
" userStatus: "
).
append
(
toIndentedString
(
userStatus
)).
append
(
"\n"
);
sb
.
append
(
"}"
);
sb
.
append
(
"}"
);
return
sb
.
toString
();
return
sb
.
toString
();
}
}
...
@@ -224,4 +69,3 @@ public class User {
...
@@ -224,4 +69,3 @@ public class User {
return
o
.
toString
().
replace
(
"\n"
,
"\n "
);
return
o
.
toString
().
replace
(
"\n"
,
"\n "
);
}
}
}
}
drip-commons/src/test/java/nl/uva/sne/drip/commons/utils/TOSCAUtilsTest.java
deleted
100644 → 0
View file @
9e9ab47b
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
utils
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.dataformat.yaml.YAMLFactory
;
import
com.fasterxml.jackson.dataformat.yaml.YAMLGenerator
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
nl.uva.sne.drip.model.NodeTemplate
;
import
nl.uva.sne.drip.model.ToscaTemplate
;
import
org.junit.After
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
/**
*
* @author alogo
*/
public
class
TOSCAUtilsTest
{
private
static
ToscaTemplate
toscaTemplate
;
public
TOSCAUtilsTest
()
{
}
@BeforeClass
public
static
void
setUpClass
()
throws
IOException
{
String
toscaFilePath
=
"../TOSCA/application_example_output.yaml"
;
String
ymlStr
=
new
String
(
Files
.
readAllBytes
(
Paths
.
get
(
toscaFilePath
)));
ObjectMapper
objectMapper
=
new
ObjectMapper
(
new
YAMLFactory
().
disable
(
YAMLGenerator
.
Feature
.
WRITE_DOC_START_MARKER
));
objectMapper
.
disable
(
SerializationFeature
.
WRITE_DATES_AS_TIMESTAMPS
);
toscaTemplate
=
objectMapper
.
readValue
(
ymlStr
,
ToscaTemplate
.
class
);
}
@AfterClass
public
static
void
tearDownClass
()
{
}
@Before
public
void
setUp
()
{
}
@After
public
void
tearDown
()
{
}
/**
* Test of getNodesByType method, of class TOSCAUtils.
*/
@Test
public
void
testGetNodesByType
()
{
System
.
out
.
println
(
"getNodesByType"
);
String
nodeTypeName
=
"tosca.nodes.ARTICONF.VM.topology"
;
List
<
Map
<
String
,
NodeTemplate
>>
result
=
testGetNodesByType
(
nodeTypeName
);
assertEquals
(
1
,
result
.
size
());
nodeTypeName
=
"tosca.nodes.ARTICONF.VM.Compute"
;
result
=
testGetNodesByType
(
nodeTypeName
);
assertEquals
(
2
,
result
.
size
());
}
/**
* Test of getRelatedNodes method, of class TOSCAUtils.
*/
@Test
public
void
testGetRelatedNodes
()
{
System
.
out
.
println
(
"getRelatedNodes"
);
String
nodeTypeName
=
"tosca.nodes.ARTICONF.VM.topology"
;
List
<
Map
<
String
,
NodeTemplate
>>
vmTopologies
=
TOSCAUtils
.
getNodesByType
(
toscaTemplate
,
nodeTypeName
);
NodeTemplate
vmTopology
=
vmTopologies
.
get
(
0
).
get
(
vmTopologies
.
get
(
0
).
keySet
().
iterator
().
next
());
nodeTypeName
=
"tosca.nodes.ARTICONF.VM.Compute"
;
List
<
Map
<
String
,
NodeTemplate
>>
result
=
TOSCAUtils
.
getRelatedNodes
(
vmTopology
,
toscaTemplate
);
assertEquals
(
2
,
result
.
size
());
for
(
Map
<
String
,
NodeTemplate
>
node
:
result
)
{
String
name
=
node
.
keySet
().
iterator
().
next
();
assertEquals
(
nodeTypeName
,
node
.
get
(
name
).
getType
());
}
}
/**
* Test of nodeIsOfType method, of class TOSCAUtils.
*/
@Test
public
void
testNodeIsOfType
()
{
System
.
out
.
println
(
"nodeIsOfType"
);
String
nodeTypeName
=
"tosca.nodes.ARTICONF.VM.topology"
;
List
<
Map
<
String
,
NodeTemplate
>>
vmTopologies
=
TOSCAUtils
.
getNodesByType
(
toscaTemplate
,
nodeTypeName
);
NodeTemplate
vmTopology
=
vmTopologies
.
get
(
0
).
get
(
vmTopologies
.
get
(
0
).
keySet
().
iterator
().
next
());
boolean
expResult
=
true
;
boolean
result
=
TOSCAUtils
.
nodeIsOfType
(
vmTopology
,
nodeTypeName
);
assertEquals
(
expResult
,
result
);
expResult
=
false
;
nodeTypeName
=
"tosca.nodes.ARTICONF"
;
result
=
TOSCAUtils
.
nodeIsOfType
(
vmTopology
,
nodeTypeName
);
assertEquals
(
expResult
,
result
);
}
/**
* Test of getNodeProperty method, of class TOSCAUtils.
*/
@Test
public
void
testGetNodeProperty
()
{
System
.
out
.
println
(
"getNodeProperty"
);
testGetVMProperties
();
}
private
void
testGetVMProperties
()
{
String
nodeTypeName
=
"tosca.nodes.ARTICONF.VM.Compute"
;
List
<
Map
<
String
,
NodeTemplate
>>
vms
=
TOSCAUtils
.
getNodesByType
(
toscaTemplate
,
nodeTypeName
);
assertEquals
(
2
,
vms
.
size
());
Map
<
String
,
Object
>
vmProertyMap
=
new
HashMap
<>();
vmProertyMap
.
put
(
"disk_size"
,
"50000 MB"
);
vmProertyMap
.
put
(
"host_name"
,
"vm"
);
vmProertyMap
.
put
(
"mem_size"
,
"6000 MB"
);
vmProertyMap
.
put
(
"num_cores"
,
2
);
vmProertyMap
.
put
(
"os"
,
"ubuntu 16"
);
vmProertyMap
.
put
(
"user_name"
,
"vm_user"
);
for
(
Map
<
String
,
NodeTemplate
>
vmMap
:
vms
)
{
Set
<
String
>
keys
=
vmProertyMap
.
keySet
();
NodeTemplate
vm
=
vmMap
.
get
(
vmMap
.
keySet
().
iterator
().
next
());
for
(
String
propName
:
keys
)
{
Object
result
=
TOSCAUtils
.
getNodeProperty
(
vm
,
propName
);
assertEquals
(
vmProertyMap
.
get
(
propName
),
result
);
}
}
}
private
List
<
Map
<
String
,
NodeTemplate
>>
testGetNodesByType
(
String
nodeTypeName
)
{
List
<
Map
<
String
,
NodeTemplate
>>
result
=
TOSCAUtils
.
getNodesByType
(
toscaTemplate
,
nodeTypeName
);
for
(
Map
<
String
,
NodeTemplate
>
node
:
result
)
{
String
name
=
node
.
keySet
().
iterator
().
next
();
assertEquals
(
nodeTypeName
,
node
.
get
(
name
).
getType
());
}
return
result
;
}
}
drip-manager/src/main/java/nl/uva/sne/drip/service/ProvisionerService.java
View file @
8e781faa
...
@@ -12,7 +12,7 @@ import java.util.Map;
...
@@ -12,7 +12,7 @@ import java.util.Map;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.TimeoutException
;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.commons.utils.T
OSCAUtils
;
import
nl.uva.sne.drip.commons.utils.T
oscaHelper
;
import
nl.uva.sne.drip.model.Message
;
import
nl.uva.sne.drip.model.Message
;
import
nl.uva.sne.drip.model.NodeTemplate
;
import
nl.uva.sne.drip.model.NodeTemplate
;
import
nl.uva.sne.drip.model.ToscaTemplate
;
import
nl.uva.sne.drip.model.ToscaTemplate
;
...
@@ -37,45 +37,36 @@ public class ProvisionerService {
...
@@ -37,45 +37,36 @@ public class ProvisionerService {
@Autowired
@Autowired
private
ToscaTemplateService
toscaTemplateService
;
private
ToscaTemplateService
toscaTemplateService
;
ToscaHelper
toscaHelper
;
private
Integer
toscaHelperID
;
public
String
provision
(
String
id
)
throws
IOException
{
public
String
provision
(
String
id
)
throws
IOException
{
String
ymlToscaTemplate
=
toscaTemplateService
.
findByID
(
id
);
String
ymlToscaTemplate
=
toscaTemplateService
.
findByID
(
id
);
ToscaTemplate
toscaTemplate
=
toscaTemplateService
.
getYaml2ToscaTemplate
(
ymlToscaTemplate
);
ToscaTemplate
toscaTemplate
=
toscaTemplateService
.
getYaml2ToscaTemplate
(
ymlToscaTemplate
);
toscaHelper
=
new
ToscaHelper
(
toscaTemplate
);
toscaTemplate
=
addProvisionInterface
(
toscaTemplate
);
toscaTemplate
=
addProvisionInterface
(
toscaTemplate
);
return
null
;
return
null
;
}
}
private
List
<
Map
<
String
,
NodeTemplate
>>
getVmTopologies
(
ToscaTemplate
toscaTemplate
)
{
//
private List<Map<String, NodeTemplate>> getVmTopologies(ToscaTemplate toscaTemplate) {
return
TOSCAUtils
.
getNodesByType
(
toscaTemplate
,
"tosca.nodes.ARTICONF.VM.topology"
);
// return ToscaHelper
.getNodesByType(toscaTemplate, "tosca.nodes.ARTICONF.VM.topology");
}
//
}
protected
ToscaTemplate
addProvisionInterface
(
ToscaTemplate
toscaTemplate
)
{
protected
ToscaTemplate
addProvisionInterface
(
ToscaTemplate
toscaTemplate
)
{
List
<
Map
<
String
,
NodeTemplate
>>
vmTopologies
=
getVmTopologies
(
toscaTemplate
);
// List<Map<String, NodeTemplate>> vmTopologies = getVmTopologies(toscaTemplate);
for
(
Map
<
String
,
NodeTemplate
>
vmTopologyMap
:
vmTopologies
)
{
// for (Map<String, NodeTemplate> vmTopologyMap : vmTopologies) {
String
topologyName
=
vmTopologyMap
.
keySet
().
iterator
().
next
();
// String topologyName = vmTopologyMap.keySet().iterator().next();
NodeTemplate
vmTopology
=
vmTopologyMap
.
get
(
topologyName
);
// NodeTemplate vmTopology = vmTopologyMap.get(topologyName);
Map
<
String
,
Object
>
interfaces
=
vmTopology
.
getInterfaces
();
// Map<String, Object> interfaces = vmTopology.getInterfaces();
Map
<
String
,
Object
>
cloudStormInterface
=
getCloudStormProvisionInterface
(
topologyName
);
// Map<String, Object> cloudStormInterface = getCloudStormProvisionInterface(topologyName);
interfaces
.
put
(
"cloudStorm"
,
cloudStormInterface
);
// interfaces.put("cloudStorm", cloudStormInterface);
// }
}
return
toscaTemplate
;
return
toscaTemplate
;
}
}
private
Map
<
String
,
Object
>
getCloudStormProvisionInterface
(
String
topologyName
)
{
Map
<
String
,
Object
>
csMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
provisionMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
inputs
=
new
HashMap
<>();
inputs
.
put
(
"code_type"
,
"SEQ"
);
inputs
.
put
(
"object_type"
,
"SubTopology"
);
inputs
.
put
(
"objects"
,
topologyName
);
provisionMap
.
put
(
"inputs"
,
inputs
);
csMap
.
put
(
"provision"
,
provisionMap
);
return
null
;
}
}
}
drip-manager/src/main/java/nl/uva/sne/drip/service/ToscaTemplateService.java
View file @
8e781faa
...
@@ -61,7 +61,7 @@ public class ToscaTemplateService {
...
@@ -61,7 +61,7 @@ public class ToscaTemplateService {
byte
[]
bytes
=
file
.
getBytes
();
byte
[]
bytes
=
file
.
getBytes
();
String
ymlStr
=
new
String
(
bytes
,
"UTF-8"
);
String
ymlStr
=
new
String
(
bytes
,
"UTF-8"
);
tt
=
objectMapper
.
readValue
(
ymlStr
,
ToscaTemplate
.
class
);
tt
=
objectMapper
.
readValue
(
ymlStr
,
ToscaTemplate
.
class
);
tt
.
setI
D
(
id
);
tt
.
setI
d
(
id
);
return
save
(
tt
);
return
save
(
tt
);
}
}
...
...
openAPI/TOSCA/TopologyTemplate.yml
View file @
8e781faa
...
@@ -4,9 +4,7 @@
...
@@ -4,9 +4,7 @@
description
:
description
:
type
:
"
string"
type
:
"
string"
inputs
:
inputs
:
type
:
"
array"
type
:
string
items
:
type
:
object
additionalProperties
:
additionalProperties
:
type
:
object
type
:
object
node_templates
:
node_templates
:
...
@@ -18,22 +16,20 @@
...
@@ -18,22 +16,20 @@
additionalProperties
:
additionalProperties
:
type
:
object
type
:
object
outputs
:
outputs
:
type
:
"
array"
type
:
string
items
:
type
:
object
additionalProperties
:
additionalProperties
:
type
:
object
type
:
object
groups
:
groups
:
type
:
object
type
:
string
additionalProperties
:
additionalProperties
:
type
:
object
type
:
object
substitution_mappings
:
substitution_mappings
:
type
:
object
type
:
string
additionalProperties
:
additionalProperties
:
type
:
object
type
:
object
policies
:
policies
:
type
:
"
array"
type
:
"
array"
items
:
items
:
type
:
object
type
:
string
additionalProperties
:
additionalProperties
:
type
:
object
type
:
object
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment