Commit e2ec6617 authored by Spiros Koulouzis's avatar Spiros Koulouzis

set timeout

parent 6e2537d0
...@@ -15,11 +15,21 @@ ...@@ -15,11 +15,21 @@
*/ */
package nl.uva.sne.drip.commons.utils; package nl.uva.sne.drip.commons.utils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.web.multipart.MultipartFile;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
/** /**
...@@ -51,4 +61,37 @@ public class Converter { ...@@ -51,4 +61,37 @@ public class Converter {
return (Map<String, Object>) object; return (Map<String, Object>) object;
} }
public static String encodeFileToBase64Binary(String fileName) throws IOException {
return encode2Bas64(Files.readAllBytes(Paths.get(fileName)));
}
public static void decodeBase64BToFile(String base64, String fileName) throws IOException {
byte[] decodedBytrs = Base64.getDecoder().decode(base64);
Files.write(Paths.get(fileName), decodedBytrs);
}
public static String getFileMD5(String filePath) throws NoSuchAlgorithmException, IOException {
MessageDigest md = MessageDigest.getInstance("MD5");
String keyStoreContents = new String(Files.readAllBytes(Paths.get(filePath)));
md.update(keyStoreContents.getBytes());
byte[] digest = md.digest();
return new String(digest, StandardCharsets.UTF_8);
}
public static String encodeFileToBase64Binary(MultipartFile file) throws IOException {
String originalFileName = file.getOriginalFilename();
String name = System.currentTimeMillis() + "_" + originalFileName;
byte[] bytes = file.getBytes();
return encode2Bas64(bytes);
}
private static String encode2Bas64(byte[] bytes) {
byte[] encodedBytes = Base64.getEncoder().encode(bytes);
return new String(encodedBytes, StandardCharsets.UTF_8);
}
} }
...@@ -68,7 +68,10 @@ public class ToscaHelper { ...@@ -68,7 +68,10 @@ public class ToscaHelper {
private void init(String sureToscaBasePath) { private void init(String sureToscaBasePath) {
Configuration.getDefaultApiClient().setBasePath(sureToscaBasePath); Configuration.getDefaultApiClient().setBasePath(sureToscaBasePath);
Configuration.getDefaultApiClient().setConnectTimeout(1200000);
api = new DefaultApi(Configuration.getDefaultApiClient()); api = new DefaultApi(Configuration.getDefaultApiClient());
System.err.println("ConnectTimeout: " + api.getApiClient().getConnectTimeout());
this.objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)); this.objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
...@@ -186,14 +189,7 @@ public class ToscaHelper { ...@@ -186,14 +189,7 @@ public class ToscaHelper {
if (att == null) { if (att == null) {
att = new HashMap<>(); att = new HashMap<>();
} }
Map<String, Object> toscaCredential = new HashMap<>(); att.put("credential", credential);
toscaCredential.put("protocol", credential.getProtocol());
toscaCredential.put("token_type", credential.getTokenType());
toscaCredential.put("token", credential.getToken());
toscaCredential.put("keys", credential.getKeys());
toscaCredential.put("user", credential.getUser());
toscaCredential.put("cloud_provider_name", credential.getCloudProviderName());
att.put("credential", toscaCredential);
vmTopology.setAttributes(att); vmTopology.setAttributes(att);
vmTopologyMap.setNodeTemplate(vmTopology); vmTopologyMap.setNodeTemplate(vmTopology);
return vmTopologyMap; return vmTopologyMap;
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
* https://github.com/swagger-api/swagger-codegen.git * https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually. * Do not edit the class manually.
*/ */
package nl.uva.sne.drip.sure.tosca.client; package nl.uva.sne.drip.sure.tosca.client;
import com.squareup.okhttp.*; import com.squareup.okhttp.*;
...@@ -49,8 +47,6 @@ import nl.uva.sne.drip.sure.tosca.auth.Authentication; ...@@ -49,8 +47,6 @@ import nl.uva.sne.drip.sure.tosca.auth.Authentication;
import nl.uva.sne.drip.sure.tosca.auth.HttpBasicAuth; import nl.uva.sne.drip.sure.tosca.auth.HttpBasicAuth;
import nl.uva.sne.drip.sure.tosca.auth.OAuth; import nl.uva.sne.drip.sure.tosca.auth.OAuth;
public class ApiClient { public class ApiClient {
private String basePath = "https://localhost/tosca-sure/1.0.0"; private String basePath = "https://localhost/tosca-sure/1.0.0";
...@@ -79,7 +75,8 @@ public class ApiClient { ...@@ -79,7 +75,8 @@ public class ApiClient {
*/ */
public ApiClient() { public ApiClient() {
httpClient = new OkHttpClient(); httpClient = new OkHttpClient();
httpClient.setConnectTimeout(3, TimeUnit.MINUTES); // connect timeout
httpClient.setReadTimeout(3, TimeUnit.MINUTES);
verifyingSsl = true; verifyingSsl = true;
...@@ -106,7 +103,8 @@ public class ApiClient { ...@@ -106,7 +103,8 @@ public class ApiClient {
/** /**
* Set base path * Set base path
* *
* @param basePath Base path of the URL (e.g https://localhost/tosca-sure/1.0.0 * @param basePath Base path of the URL (e.g
* https://localhost/tosca-sure/1.0.0
* @return An instance of OkHttpClient * @return An instance of OkHttpClient
*/ */
public ApiClient setBasePath(String basePath) { public ApiClient setBasePath(String basePath) {
...@@ -164,9 +162,9 @@ public class ApiClient { ...@@ -164,9 +162,9 @@ public class ApiClient {
} }
/** /**
* Configure whether to verify certificate and hostname when making https requests. * Configure whether to verify certificate and hostname when making https
* Default to true. * requests. Default to true. NOTE: Do NOT set to false in production code,
* NOTE: Do NOT set to false in production code, otherwise you would face multiple types of cryptographic attacks. * otherwise you would face multiple types of cryptographic attacks.
* *
* @param verifyingSsl True to verify TLS/SSL connection * @param verifyingSsl True to verify TLS/SSL connection
* @return ApiClient * @return ApiClient
...@@ -204,8 +202,8 @@ public class ApiClient { ...@@ -204,8 +202,8 @@ public class ApiClient {
} }
/** /**
* Configure client keys to use for authorization in an SSL session. * Configure client keys to use for authorization in an SSL session. Use
* Use null to reset to default. * null to reset to default.
* *
* @param managers The KeyManagers to use * @param managers The KeyManagers to use
* @return ApiClient * @return ApiClient
...@@ -393,11 +391,12 @@ public class ApiClient { ...@@ -393,11 +391,12 @@ public class ApiClient {
} }
/** /**
* The path of temporary folder used to store downloaded files from endpoints * The path of temporary folder used to store downloaded files from
* with file response. The default value is <code>null</code>, i.e. using * endpoints with file response. The default value is <code>null</code>,
* the system's default tempopary folder. * 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> * @see
* <a href="https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile">createTempFile</a>
* @return Temporary folder path * @return Temporary folder path
*/ */
public String getTempFolderPath() { public String getTempFolderPath() {
...@@ -425,8 +424,8 @@ public class ApiClient { ...@@ -425,8 +424,8 @@ public class ApiClient {
} }
/** /**
* Sets the connect timeout (in milliseconds). * Sets the connect timeout (in milliseconds). A value of 0 means no
* A value of 0 means no timeout, otherwise values must be between 1 and * timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}. * {@link Integer#MAX_VALUE}.
* *
* @param connectionTimeout connection timeout in milliseconds * @param connectionTimeout connection timeout in milliseconds
...@@ -447,9 +446,8 @@ public class ApiClient { ...@@ -447,9 +446,8 @@ public class ApiClient {
} }
/** /**
* Sets the read timeout (in milliseconds). * Sets the read timeout (in milliseconds). A value of 0 means no timeout,
* A value of 0 means no timeout, otherwise values must be between 1 and * otherwise values must be between 1 and {@link Integer#MAX_VALUE}.
* {@link Integer#MAX_VALUE}.
* *
* @param readTimeout read timeout in milliseconds * @param readTimeout read timeout in milliseconds
* @return Api client * @return Api client
...@@ -469,9 +467,8 @@ public class ApiClient { ...@@ -469,9 +467,8 @@ public class ApiClient {
} }
/** /**
* Sets the write timeout (in milliseconds). * Sets the write timeout (in milliseconds). A value of 0 means no timeout,
* A value of 0 means no timeout, otherwise values must be between 1 and * otherwise values must be between 1 and {@link Integer#MAX_VALUE}.
* {@link Integer#MAX_VALUE}.
* *
* @param writeTimeout connection timeout in milliseconds * @param writeTimeout connection timeout in milliseconds
* @return Api client * @return Api client
...@@ -496,7 +493,7 @@ public class ApiClient { ...@@ -496,7 +493,7 @@ public class ApiClient {
return jsonStr.substring(1, jsonStr.length() - 1); return jsonStr.substring(1, jsonStr.length() - 1);
} else if (param instanceof Collection) { } else if (param instanceof Collection) {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
for (Object o : (Collection)param) { for (Object o : (Collection) param) {
if (b.length() > 0) { if (b.length() > 0) {
b.append(","); b.append(",");
} }
...@@ -509,7 +506,8 @@ public class ApiClient { ...@@ -509,7 +506,8 @@ public class ApiClient {
} }
/** /**
* Formats the specified query parameter to a list containing a single {@code Pair} object. * Formats the specified query parameter to a list containing a single
* {@code Pair} object.
* *
* Note that {@code value} must not be a collection. * Note that {@code value} must not be a collection.
* *
...@@ -521,16 +519,20 @@ public class ApiClient { ...@@ -521,16 +519,20 @@ public class ApiClient {
List<Pair> params = new ArrayList<Pair>(); List<Pair> params = new ArrayList<Pair>();
// preconditions // preconditions
if (name == null || name.isEmpty() || value == null || value instanceof Collection) return params; if (name == null || name.isEmpty() || value == null || value instanceof Collection) {
return params;
}
params.add(new Pair(name, parameterToString(value))); params.add(new Pair(name, parameterToString(value)));
return params; return params;
} }
/** /**
* Formats the specified collection query parameters to a list of {@code Pair} objects. * 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. * Note that the values of each of the returned Pair objects are
* percent-encoded.
* *
* @param collectionFormat The collection format of the parameter. * @param collectionFormat The collection format of the parameter.
* @param name The name of the parameter. * @param name The name of the parameter.
...@@ -566,7 +568,7 @@ public class ApiClient { ...@@ -566,7 +568,7 @@ public class ApiClient {
delimiter = escapeString("|"); delimiter = escapeString("|");
} }
StringBuilder sb = new StringBuilder() ; StringBuilder sb = new StringBuilder();
for (Object item : value) { for (Object item : value) {
sb.append(delimiter); sb.append(delimiter);
sb.append(escapeString(parameterToString(item))); sb.append(escapeString(parameterToString(item)));
...@@ -578,8 +580,7 @@ public class ApiClient { ...@@ -578,8 +580,7 @@ public class ApiClient {
} }
/** /**
* Sanitize filename by removing path. * Sanitize filename by removing path. e.g. ../../sun.gif becomes sun.gif
* e.g. ../../sun.gif becomes sun.gif
* *
* @param filename The filename to be sanitized * @param filename The filename to be sanitized
* @return The sanitized filename * @return The sanitized filename
...@@ -589,29 +590,26 @@ public class ApiClient { ...@@ -589,29 +590,26 @@ public class ApiClient {
} }
/** /**
* Check if the given MIME is a JSON MIME. * Check if the given MIME is a JSON MIME. JSON MIME examples:
* JSON MIME examples: * application/json application/json; charset=UTF8 APPLICATION/JSON
* application/json * application/vnd.company+json "* / *" is also default to JSON
* application/json; charset=UTF8 *
* APPLICATION/JSON
* application/vnd.company+json
* "* / *" is also default to JSON
* @param mime MIME (Multipurpose Internet Mail Extensions) * @param mime MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise. * @return True if the given MIME is JSON, false otherwise.
*/ */
public boolean isJsonMime(String mime) { public boolean isJsonMime(String mime) {
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*")); return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
} }
/** /**
* Select the Accept header's value from the given accepts array: * Select the Accept header's value from the given accepts array: if JSON
* if JSON exists in the given array, use it; * exists in the given array, use it; otherwise use all of them (joining
* otherwise use all of them (joining into a string) * into a string)
* *
* @param accepts The accepts array to select from * @param accepts The accepts array to select from
* @return The Accept header to use. If the given array is empty, * @return The Accept header to use. If the given array is empty, null will
* null will be returned (not to set the Accept header explicitly). * be returned (not to set the Accept header explicitly).
*/ */
public String selectHeaderAccept(String[] accepts) { public String selectHeaderAccept(String[] accepts) {
if (accepts.length == 0) { if (accepts.length == 0) {
...@@ -626,17 +624,17 @@ public class ApiClient { ...@@ -626,17 +624,17 @@ public class ApiClient {
} }
/** /**
* Select the Content-Type header's value from the given array: * Select the Content-Type header's value from the given array: if JSON
* if JSON exists in the given array, use it; * exists in the given array, use it; otherwise use the first one of the
* otherwise use the first one of the array. * array.
* *
* @param contentTypes The Content-Type array to select from * @param contentTypes The Content-Type array to select from
* @return The Content-Type header to use. If the given array is empty, * @return The Content-Type header to use. If the given array is empty, or
* or matches "any", JSON will be used. * matches "any", JSON will be used.
*/ */
public String selectHeaderContentType(String[] contentTypes) { public String selectHeaderContentType(String[] contentTypes) {
if (contentTypes.length == 0 || contentTypes[0].equals("*/*")) { if (contentTypes.length == 0 || contentTypes[0].equals("*/*")) {
return "application/json"; return "application/json";
} }
for (String contentType : contentTypes) { for (String contentType : contentTypes) {
if (isJsonMime(contentType)) { if (isJsonMime(contentType)) {
...@@ -661,15 +659,15 @@ public class ApiClient { ...@@ -661,15 +659,15 @@ public class ApiClient {
} }
/** /**
* Deserialize response body to Java object, according to the return type and * Deserialize response body to Java object, according to the return type
* the Content-Type response header. * and the Content-Type response header.
* *
* @param <T> Type * @param <T> Type
* @param response HTTP response * @param response HTTP response
* @param returnType The type of the Java object * @param returnType The type of the Java object
* @return The deserialized Java object * @return The deserialized Java object
* @throws ApiException If fail to deserialize response body, i.e. cannot read response body * @throws ApiException If fail to deserialize response body, i.e. cannot
* or the Content-Type of the response is not supported. * read response body or the Content-Type of the response is not supported.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T deserialize(Response response, Type returnType) throws ApiException { public <T> T deserialize(Response response, Type returnType) throws ApiException {
...@@ -691,10 +689,11 @@ public class ApiClient { ...@@ -691,10 +689,11 @@ public class ApiClient {
String respBody; String respBody;
try { try {
if (response.body() != null) if (response.body() != null) {
respBody = response.body().string(); respBody = response.body().string();
else } else {
respBody = null; respBody = null;
}
} catch (IOException e) { } catch (IOException e) {
throw new ApiException(e); throw new ApiException(e);
} }
...@@ -723,8 +722,8 @@ public class ApiClient { ...@@ -723,8 +722,8 @@ public class ApiClient {
} }
/** /**
* Serialize the given Java object into request body according to the object's * Serialize the given Java object into request body according to the
* class and the request Content-Type. * object's class and the request Content-Type.
* *
* @param obj The Java object * @param obj The Java object
* @param contentType The request Content-Type * @param contentType The request Content-Type
...@@ -755,7 +754,8 @@ public class ApiClient { ...@@ -755,7 +754,8 @@ public class ApiClient {
* Download file from the given response. * Download file from the given response.
* *
* @param response An instance of the Response object * @param response An instance of the Response object
* @throws ApiException If fail to read file content from response and write to disk * @throws ApiException If fail to read file content from response and write
* to disk
* @return Downloaded file * @return Downloaded file
*/ */
public File downloadFileFromResponse(Response response) throws ApiException { public File downloadFileFromResponse(Response response) throws ApiException {
...@@ -803,14 +803,16 @@ public class ApiClient { ...@@ -803,14 +803,16 @@ public class ApiClient {
suffix = filename.substring(pos); suffix = filename.substring(pos);
} }
// File.createTempFile requires the prefix to be at least three characters long // File.createTempFile requires the prefix to be at least three characters long
if (prefix.length() < 3) if (prefix.length() < 3) {
prefix = "download-"; prefix = "download-";
}
} }
if (tempFolderPath == null) if (tempFolderPath == null) {
return File.createTempFile(prefix, suffix); return File.createTempFile(prefix, suffix);
else } else {
return File.createTempFile(prefix, suffix, new File(tempFolderPath)); return File.createTempFile(prefix, suffix, new File(tempFolderPath));
}
} }
/** /**
...@@ -826,14 +828,15 @@ public class ApiClient { ...@@ -826,14 +828,15 @@ public class ApiClient {
} }
/** /**
* Execute HTTP call and deserialize the HTTP response body into the given return type. * 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 returnType The return type used to deserialize HTTP response body
* @param <T> The return type corresponding to (same with) returnType * @param <T> The return type corresponding to (same with) returnType
* @param call Call * @param call Call
* @return ApiResponse object containing response status, headers and * @return ApiResponse object containing response status, headers and data,
* data, which is a Java object deserialized from response body and would be null * which is a Java object deserialized from response body and would be null
* when returnType is null. * when returnType is null.
* @throws ApiException If fail to execute the call * @throws ApiException If fail to execute the call
*/ */
public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException { public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException {
...@@ -889,13 +892,14 @@ public class ApiClient { ...@@ -889,13 +892,14 @@ public class ApiClient {
} }
/** /**
* Handle the given response, return the deserialized object when the response is successful. * Handle the given response, return the deserialized object when the
* response is successful.
* *
* @param <T> Type * @param <T> Type
* @param response Response * @param response Response
* @param returnType Return type * @param returnType Return type
* @throws ApiException If the response has a unsuccessful status code or * @throws ApiException If the response has a unsuccessful status code or
* fail to deserialize the response body * fail to deserialize the response body
* @return Type * @return Type
*/ */
public <T> T handleResponse(Response response, Type returnType) throws ApiException { public <T> T handleResponse(Response response, Type returnType) throws ApiException {
...@@ -931,7 +935,8 @@ public class ApiClient { ...@@ -931,7 +935,8 @@ public class ApiClient {
* Build HTTP call with the given options. * Build HTTP call with the given options.
* *
* @param path The sub-path of the HTTP URL * @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 method The request method, one of "GET", "HEAD", "OPTIONS",
* "POST", "PUT", "PATCH" and "DELETE"
* @param queryParams The query parameters * @param queryParams The query parameters
* @param collectionQueryParams The collection query parameters * @param collectionQueryParams The collection query parameters
* @param body The request body object * @param body The request body object
...@@ -952,7 +957,8 @@ public class ApiClient { ...@@ -952,7 +957,8 @@ public class ApiClient {
* Build an HTTP request with the given options. * Build an HTTP request with the given options.
* *
* @param path The sub-path of the HTTP URL * @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 method The request method, one of "GET", "HEAD", "OPTIONS",
* "POST", "PUT", "PATCH" and "DELETE"
* @param queryParams The query parameters * @param queryParams The query parameters
* @param collectionQueryParams The collection query parameters * @param collectionQueryParams The collection query parameters
* @param body The request body object * @param body The request body object
...@@ -960,7 +966,7 @@ public class ApiClient { ...@@ -960,7 +966,7 @@ public class ApiClient {
* @param formParams The form parameters * @param formParams The form parameters
* @param authNames The authentications to apply * @param authNames The authentications to apply
* @param progressRequestListener Progress request listener * @param progressRequestListener Progress request listener
* @return The HTTP request * @return The HTTP request
* @throws ApiException If fail to serialize the request body object * @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 { 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 {
...@@ -997,7 +1003,7 @@ public class ApiClient { ...@@ -997,7 +1003,7 @@ public class ApiClient {
Request request = null; Request request = null;
if(progressRequestListener != null && reqBody != null) { if (progressRequestListener != null && reqBody != null) {
ProgressRequestBody progressRequestBody = new ProgressRequestBody(reqBody, progressRequestListener); ProgressRequestBody progressRequestBody = new ProgressRequestBody(reqBody, progressRequestListener);
request = reqBuilder.method(method, progressRequestBody).build(); request = reqBuilder.method(method, progressRequestBody).build();
} else { } else {
...@@ -1008,7 +1014,8 @@ public class ApiClient { ...@@ -1008,7 +1014,8 @@ public class ApiClient {
} }
/** /**
* Build full URL by concatenating base path, the given sub path and query parameters. * Build full URL by concatenating base path, the given sub path and query
* parameters.
* *
* @param path The sub path * @param path The sub path
* @param queryParams The query parameters * @param queryParams The query parameters
...@@ -1077,13 +1084,15 @@ public class ApiClient { ...@@ -1077,13 +1084,15 @@ public class ApiClient {
* Update query and header parameters based on authentication settings. * Update query and header parameters based on authentication settings.
* *
* @param authNames The authentications to apply * @param authNames The authentications to apply
* @param queryParams List of query parameters * @param queryParams List of query parameters
* @param headerParams Map of header parameters * @param headerParams Map of header parameters
*/ */
public void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) { public void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
for (String authName : authNames) { for (String authName : authNames) {
Authentication auth = authentications.get(authName); Authentication auth = authentications.get(authName);
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName); if (auth == null) {
throw new RuntimeException("Authentication undefined: " + authName);
}
auth.applyToParams(queryParams, headerParams); auth.applyToParams(queryParams, headerParams);
} }
} }
...@@ -1095,7 +1104,7 @@ public class ApiClient { ...@@ -1095,7 +1104,7 @@ public class ApiClient {
* @return RequestBody * @return RequestBody
*/ */
public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams) { public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams) {
FormEncodingBuilder formBuilder = new FormEncodingBuilder(); FormEncodingBuilder formBuilder = new FormEncodingBuilder();
for (Entry<String, Object> param : formParams.entrySet()) { for (Entry<String, Object> param : formParams.entrySet()) {
formBuilder.add(param.getKey(), parameterToString(param.getValue())); formBuilder.add(param.getKey(), parameterToString(param.getValue()));
} }
...@@ -1103,8 +1112,8 @@ public class ApiClient { ...@@ -1103,8 +1112,8 @@ public class ApiClient {
} }
/** /**
* Build a multipart (file uploading) request body with the given form parameters, * Build a multipart (file uploading) request body with the given form
* which could contain text fields and file fields. * parameters, which could contain text fields and file fields.
* *
* @param formParams Form parameters in the form of Map * @param formParams Form parameters in the form of Map
* @return RequestBody * @return RequestBody
...@@ -1126,7 +1135,8 @@ public class ApiClient { ...@@ -1126,7 +1135,8 @@ public class ApiClient {
} }
/** /**
* Guess Content-Type header from the given file (defaults to "application/octet-stream"). * Guess Content-Type header from the given file (defaults to
* "application/octet-stream").
* *
* @param file The given file * @param file The given file
* @return The guessed Content-Type * @return The guessed Content-Type
...@@ -1141,8 +1151,8 @@ public class ApiClient { ...@@ -1141,8 +1151,8 @@ public class ApiClient {
} }
/** /**
* Apply SSL related settings to httpClient according to the current values of * Apply SSL related settings to httpClient according to the current values
* verifyingSsl and sslCaCert. * of verifyingSsl and sslCaCert.
*/ */
private void applySslSettings() { private void applySslSettings() {
try { try {
...@@ -1151,17 +1161,25 @@ public class ApiClient { ...@@ -1151,17 +1161,25 @@ public class ApiClient {
if (!verifyingSsl) { if (!verifyingSsl) {
TrustManager trustAll = new X509TrustManager() { TrustManager trustAll = new X509TrustManager() {
@Override @Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {} public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override @Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {} public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override @Override
public X509Certificate[] getAcceptedIssuers() { return null; } public X509Certificate[] getAcceptedIssuers() {
return null;
}
}; };
SSLContext sslContext = SSLContext.getInstance("TLS"); SSLContext sslContext = SSLContext.getInstance("TLS");
trustManagers = new TrustManager[]{ trustAll }; trustManagers = new TrustManager[]{trustAll};
hostnameVerifier = new HostnameVerifier() { hostnameVerifier = new HostnameVerifier() {
@Override @Override
public boolean verify(String hostname, SSLSession session) { return true; } public boolean verify(String hostname, SSLSession session) {
return true;
}
}; };
} else if (sslCaCert != null) { } else if (sslCaCert != null) {
char[] password = null; // Any password will work. char[] password = null; // Any password will work.
......
...@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
import nl.uva.sne.drip.model.tosca.Credential; import nl.uva.sne.drip.model.tosca.Credential;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z")
......
...@@ -3,6 +3,7 @@ package nl.uva.sne.drip.api; ...@@ -3,6 +3,7 @@ package nl.uva.sne.drip.api;
import nl.uva.sne.drip.model.tosca.Credential; import nl.uva.sne.drip.model.tosca.Credential;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import java.io.IOException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -12,8 +13,11 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -12,8 +13,11 @@ import org.springframework.web.bind.annotation.RequestBody;
import javax.validation.Valid; import javax.validation.Valid;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.service.CredentialService; import nl.uva.sne.drip.service.CredentialService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-10T17:15:46.465Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-10T17:15:46.465Z")
...@@ -56,5 +60,4 @@ public class CredentialApiController implements CredentialApi { ...@@ -56,5 +60,4 @@ public class CredentialApiController implements CredentialApi {
} }
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
} }
} }
...@@ -7,19 +7,10 @@ package nl.uva.sne.drip.api; ...@@ -7,19 +7,10 @@ package nl.uva.sne.drip.api;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z")
@Api(value = "deployer", description = "the deployer API") @Api(value = "deployer", description = "the deployer API")
...@@ -27,18 +18,22 @@ public interface DeployerApi { ...@@ -27,18 +18,22 @@ public interface DeployerApi {
@ApiOperation(value = "deploy the software tosca template", nickname = "deployProvisionToscaTemplateByID", notes = "Returns the deployment ID", response = String.class, authorizations = { @ApiOperation(value = "deploy the software tosca template", nickname = "deployProvisionToscaTemplateByID", notes = "Returns the deployment ID", response = String.class, authorizations = {
@Authorization(value = "auth", scopes = { @Authorization(value = "auth", scopes = {
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template"), @AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template")
,
@AuthorizationScope(scope = "write:ToscaTemplate", description = "modify topolog template in your account") @AuthorizationScope(scope = "write:ToscaTemplate", description = "modify topolog template in your account")
}) })
}, tags={ }) }, tags = {})
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class), @ApiResponse(code = 200, message = "successful operation", response = String.class)
@ApiResponse(code = 400, message = "Invalid ID supplied"), ,
@ApiResponse(code = 404, message = "ToscaTemplate not found"), @ApiResponse(code = 400, message = "Invalid ID supplied")
@ApiResponse(code = 405, message = "Invalid input") }) ,
@ApiResponse(code = 404, message = "ToscaTemplate not found")
,
@ApiResponse(code = 405, message = "Invalid input")})
@RequestMapping(value = "/deployer/deploy/{id}", @RequestMapping(value = "/deployer/deploy/{id}",
produces = { "text/plain" }, produces = {"text/plain"},
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<String> deployProvisionToscaTemplateByID(@ApiParam(value = "ID of topolog template to deploy",required=true) @PathVariable("id") String id); ResponseEntity<String> deployProvisionToscaTemplateByID(@ApiParam(value = "ID of topolog template to deploy", required = true) @PathVariable("id") String id);
} }
...@@ -28,20 +28,17 @@ import java.io.File; ...@@ -28,20 +28,17 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.xml.bind.DatatypeConverter;
import nl.uva.sne.drip.Swagger2SpringBoot; import nl.uva.sne.drip.Swagger2SpringBoot;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.configuration.MongoConfig; import nl.uva.sne.drip.configuration.MongoConfig;
import nl.uva.sne.drip.model.cloud.storm.CloudDB;
import nl.uva.sne.drip.model.tosca.Credential; import nl.uva.sne.drip.model.tosca.Credential;
import org.junit.Assert; import org.junit.Assert;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
...@@ -274,19 +271,10 @@ public class ServiceTests { ...@@ -274,19 +271,10 @@ public class ServiceTests {
@Test @Test
public void testCredentialService() throws IOException, NoSuchAlgorithmException { public void testCredentialService() throws IOException, NoSuchAlgorithmException {
Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "testCredentialService"); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "testCredentialService");
MessageDigest md = MessageDigest.getInstance("MD5"); String keyStoreEncoded = Converter.encodeFileToBase64Binary(testCredentialPath);
md.update(Files.readAllBytes(Paths.get(testCredentialPath)));
byte[] digest = md.digest();
String fileChecksum = DatatypeConverter
.printHexBinary(digest).toUpperCase();
String keyStore = new String(Files.readAllBytes(Paths.get(testCredentialPath)));
byte[] encodedBytes = Base64.getEncoder().encode(keyStore.getBytes());
String keyStoreEncoded = new String(encodedBytes, "UTF-8");
Credential credential = new Credential(); Credential credential = new Credential();
credential.setCloudProviderName("exogeni"); credential.setCloudProviderName("ExoGENI");
Map<String, String> keys = new HashMap<>(); Map<String, String> keys = new HashMap<>();
keys.put("keystore", keyStoreEncoded); keys.put("keystore", keyStoreEncoded);
credential.setKeys(keys); credential.setKeys(keys);
...@@ -294,28 +282,16 @@ public class ServiceTests { ...@@ -294,28 +282,16 @@ public class ServiceTests {
credential.setTokenType("password"); credential.setTokenType("password");
credential.setUser("user"); credential.setUser("user");
byte[] decodedBytes = Base64.getDecoder().decode(keys.get("keystore")); String keyStoreEncodedFromCredential = credential.getKeys().get("keystore");
md = MessageDigest.getInstance("MD5"); assertEquals(keyStoreEncoded, keyStoreEncodedFromCredential);
md.update(decodedBytes);
digest = md.digest(); String copyTestCredentialPath = ".." + File.separator + "fake_credentials" + File.separator + "copy_of_test-geni.jks";
String credentialChecksum = DatatypeConverter Converter.decodeBase64BToFile(keyStoreEncodedFromCredential, copyTestCredentialPath);
.printHexBinary(digest).toUpperCase();
String keystorFileChecksum = Converter.getFileMD5(testCredentialPath);
assertEquals(fileChecksum, credentialChecksum); String keystorFileCopyChecksum = Converter.getFileMD5(copyTestCredentialPath);
HashMap<Object, Object> att = new HashMap<>();
Map<String, Object> toscaCredential = new HashMap<>();
toscaCredential.put("protocol", credential.getProtocol());
toscaCredential.put("token_type", credential.getTokenType());
toscaCredential.put("token", credential.getToken());
toscaCredential.put("keys", credential.getKeys());
toscaCredential.put("user", credential.getUser());
toscaCredential.put("cloud_provider_name", credential.getCloudProviderName());
att.put("credential", toscaCredential);
assertEquals(keystorFileChecksum, keystorFileCopyChecksum);
} }
public String saveCredential() { public String saveCredential() {
...@@ -354,6 +330,7 @@ public class ServiceTests { ...@@ -354,6 +330,7 @@ public class ServiceTests {
credentialService.deleteByID(id); credentialService.deleteByID(id);
try { try {
Credential res = credentialService.findByID(id); Credential res = credentialService.findByID(id);
assertNotNull(res);
} catch (Exception ex) { } catch (Exception ex) {
if (!(ex instanceof NoSuchElementException)) { if (!(ex instanceof NoSuchElementException)) {
fail(ex.getMessage()); fail(ex.getMessage());
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e478ccae-5352-4e8e-9efb-3f5cda44e877" name="Default Changelist" comment="" /> <list default="true" id="e478ccae-5352-4e8e-9efb-3f5cda44e877" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/CredentialApi.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/CredentialApi.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/CredentialApiController.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/CredentialApiController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/DeployerApi.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/DeployerApi.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/test/java/nl/uva/sne/drip/service/ServiceTests.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/test/java/nl/uva/sne/drip/service/ServiceTests.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../openAPI/API/CONF-3.0.0-swagger.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../openAPI/API/CONF-3.0.0-swagger.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/service/tosca_template_service.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/service/tosca_template_service.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
......
...@@ -234,6 +234,29 @@ paths: ...@@ -234,6 +234,29 @@ paths:
- read:ToscaTemplate - read:ToscaTemplate
/credential: /credential:
post: post:
summary: get credential key file as base64
description: get credential key file as base64
operationId: getFileasBase64
consumes:
- multipart/form-data
parameters:
- name: file
in: formData
description: credential key file
required: true
type: file
responses:
"200":
description: successful operation
schema:
type: string
"405":
description: Invalid input
security:
- auth:
- write:ToscaTemplate
- read:ToscaTemplate
put:
summary: Create credentials summary: Create credentials
description: Creates credentials description: Creates credentials
operationId: createCredentials operationId: createCredentials
...@@ -247,7 +270,7 @@ paths: ...@@ -247,7 +270,7 @@ paths:
description: Created user object description: Created user object
required: true required: true
schema: schema:
$ref: '#/definitions/Credentials' $ref: '#/definitions/Credential'
responses: responses:
"200": "200":
description: successful operation description: successful operation
...@@ -458,23 +481,29 @@ definitions: ...@@ -458,23 +481,29 @@ definitions:
type: integer type: integer
format: int32 format: int32
description: User Status description: User Status
Credentials: Credential:
type: object type: object
properties: properties:
protocol: protocol:
type: string type: string
description: The optional protocol name. e.g. http,xauth,oauth2,ssh
token_type: token_type:
type: string type: string
description: 'The required token type. default: password. e.g. basic_auth,X-Auth-Token, bearer, identifier'
token: token:
type: string type: string
description: The required token used as a credential for authorization or access to a networked resource. e.g. mypassword, myusername:mypassword, 604bbe45ac7143a79e14f3158df67091, keypair_id
keys: keys:
type: object type: object
description: The optional list of protocol-specific keys or assertions.
additionalProperties: additionalProperties:
type: string type: string
user: user:
type: string type: string
description: The optional user (name or ID) used for non-token based credentials.
cloud_provider_name: cloud_provider_name:
type: string type: string
description: The cloud provider name e.g. ec2.
NodeTemplate: NodeTemplate:
type: object type: object
properties: properties:
...@@ -661,20 +690,15 @@ definitions: ...@@ -661,20 +690,15 @@ definitions:
type: array type: array
items: items:
$ref: '#/definitions/CloudDB' $ref: '#/definitions/CloudDB'
CloudDB:
type: object
properties:
cloudProvider:
type: string
dbInfoFile:
type: string
DBInfo: DBInfo:
type: object type: object
properties: properties:
GlobalEntry: GlobalEntry:
type: string type: string
DCMetaInfo: DCMetaInfo:
$ref: '#/definitions/DCMetaInfo' type: array
items:
$ref: '#/definitions/DCMetaInfo'
DCMetaInfo: DCMetaInfo:
type: object type: object
properties: properties:
...@@ -691,7 +715,9 @@ definitions: ...@@ -691,7 +715,9 @@ definitions:
availability: availability:
type: string type: string
VMMetaInfo: VMMetaInfo:
$ref: '#/definitions/VMMetaInfo' type: array
items:
$ref: '#/definitions/VMMetaInfo'
extraInfo: extraInfo:
type: object type: object
additionalProperties: additionalProperties:
...@@ -706,6 +732,8 @@ definitions: ...@@ -706,6 +732,8 @@ definitions:
type: string type: string
MEM: MEM:
type: string type: string
VMType:
type: string
Price: Price:
type: string type: string
DefaultSSHAccount: DefaultSSHAccount:
...@@ -717,6 +745,67 @@ definitions: ...@@ -717,6 +745,67 @@ definitions:
additionalProperties: additionalProperties:
type: object type: object
properties: {} properties: {}
CloudsStormVMs:
type: object
properties:
VMs:
type: array
items:
$ref: '#/definitions/CloudsStormVM'
CloudCredentialDB:
type: object
properties:
cloudCreds:
type: array
items:
$ref: '#/definitions/CloudCred'
CredentialInfo:
type: object
properties:
userKeyName:
type: string
keyAlias:
type: string
keyPassword:
type: string
proxyFileName:
type: string
trustedCertDirName:
type: string
accessKey:
type: string
secretKey:
type: string
NodeTemplateMap:
type: object
properties:
name:
type: string
nodeTemplate:
$ref: '#/definitions/NodeTemplate'
Provisioner:
type: object
properties:
name:
type: string
version:
type: string
description:
type: string
tosca_interface_type:
type: string
CloudsStormInfrasCode:
type: object
properties:
Mode:
type: string
enum:
- LOCAL
- CTRL
InfrasCodes:
type: array
items:
$ref: '#/definitions/InfrasCode'
CloudsStormSubTopology: CloudsStormSubTopology:
type: object type: object
properties: properties:
...@@ -728,6 +817,12 @@ definitions: ...@@ -728,6 +817,12 @@ definitions:
type: string type: string
status: status:
type: string type: string
enum:
- fresh
- running
- deleted
- failed
- stopped
CloudsStormSubnets: CloudsStormSubnets:
type: object type: object
properties: properties:
...@@ -748,3 +843,82 @@ definitions: ...@@ -748,3 +843,82 @@ definitions:
type: string type: string
address: address:
type: string type: string
CloudDB:
type: object
properties:
cloudProvider:
type: string
enum:
- EC2
- ExoGENI
- EGI
dbInfoFile:
type: string
CloudsStormVM:
type: object
properties:
name:
type: string
nodeType:
type: string
OStype:
type: string
script:
type: string
publicAddress:
type: string
CloudCred:
type: object
properties:
cloudProvider:
type: string
credInfoFile:
type: string
InfrasCode:
type: object
properties:
CodeType:
type: string
enum:
- SEQ
- LOOP
OpCode:
$ref: '#/definitions/OpCode'
Count:
type: integer
OpCode:
type: object
properties:
Operation:
type: string
enum:
- provision
- delete
- execute
- put
- get
- vscale
- hscale
- recover
- start
ObjectType:
type: string
enum:
- SubTopology
- VM
- REQ
Objects:
type: string
Command:
type: string
Log:
type: boolean
Options:
$ref: '#/definitions/Options'
Options:
type: object
properties:
Src:
type: string
Dst:
type: string
...@@ -2,6 +2,7 @@ import json ...@@ -2,6 +2,7 @@ import json
import logging import logging
import os import os
import tempfile import tempfile
import time
import uuid import uuid
from builtins import print from builtins import print
from functools import reduce from functools import reduce
...@@ -31,6 +32,15 @@ node_template_db = TinyDB(storage=CachingMiddleware(MemoryStorage)) ...@@ -31,6 +32,15 @@ node_template_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
dsl_definitions_db = TinyDB(storage=CachingMiddleware(MemoryStorage)) dsl_definitions_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
relationship_template_db = TinyDB(storage=CachingMiddleware(MemoryStorage)) relationship_template_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
interface_types_db = TinyDB(storage=CachingMiddleware(MemoryStorage)) interface_types_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
logger = logging.getLogger(__name__)
if not getattr(logger, 'handler_set', None):
logger.setLevel(logging.INFO)
h = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
h.setFormatter(formatter)
logger.addHandler(h)
logger.handler_set = True
root_key = 'root_key' root_key = 'root_key'
...@@ -50,7 +60,7 @@ def query_db(queries, db=None): ...@@ -50,7 +60,7 @@ def query_db(queries, db=None):
res_copy.pop(root_key) res_copy.pop(root_key)
node = {key: res_copy} node = {key: res_copy}
else: else:
logging.error(str(res) + ' has no ' + root_key) logger.error(str(res) + ' has no ' + root_key)
updated_results.append(node) updated_results.append(node)
return updated_results return updated_results
return None return None
...@@ -90,17 +100,27 @@ def purge_all_tables(): ...@@ -90,17 +100,27 @@ def purge_all_tables():
def save(file): def save(file):
# try: # try:
# tosca_template_file_path = os.path.join(db_dir_path, file.filename) # tosca_template_file_path = os.path.join(db_dir_path, file.filename)
start = time.time()
logger.info("Got request for tosca template")
purge_all_tables() purge_all_tables()
dictionary = yaml.safe_load(file.stream) dictionary = yaml.safe_load(file.stream)
print(yaml.dump(dictionary)) logger.info("tosca template: \n" + str(yaml.dump(dictionary)))
# print(yaml.dump(dictionary))
tosca_template = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(dictionary)) tosca_template = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(dictionary))
# all_custom_def = tosca_template.nodetemplates[0].custom_def # all_custom_def = tosca_template.nodetemplates[0].custom_def
tosca_template_model = ToscaTemplateModel.from_dict(dictionary) tosca_template_model = ToscaTemplateModel.from_dict(dictionary)
doc_id = tosca_templates_db.insert(dictionary) doc_id = tosca_templates_db.insert(dictionary)
# tosca_templates_db.close() # tosca_templates_db.close()
logger.info("Returning doc_id: " + str(doc_id))
end = time.time()
elapsed = end - start
logger.info("Time elapsed: " + str(elapsed))
return doc_id return doc_id
# except Exception as e: # except Exception as e:
# logging.error(str(e)) # logger.error(str(e))
# return str(e), 400 # return str(e), 400
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment