Commit c3f29fd7 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added get attributes and get tosca credentials

parent 3890b724
...@@ -76,7 +76,6 @@ ...@@ -76,7 +76,6 @@
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.gsonfire</groupId> <groupId>io.gsonfire</groupId>
...@@ -132,7 +131,19 @@ ...@@ -132,7 +131,19 @@
<groupId>com.google.code.findbugs</groupId> <groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId> <artifactId>jsr305</artifactId>
<version>3.0.2</version> <version>3.0.2</version>
</dependency> </dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.25</version>
<type>jar</type>
</dependency>
</dependencies> </dependencies>
...@@ -151,7 +162,7 @@ ...@@ -151,7 +162,7 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!-- <plugin> <!-- <plugin>
<groupId>org.openapitools</groupId> <groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId> <artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.2</version> <version>4.2.2</version>
......
/*
* 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.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import org.yaml.snakeyaml.Yaml;
/**
*
* @author S. Koulouzis
*/
public class Converter {
public static String map2YmlString(Map<String, Object> map) throws JSONException {
JSONObject jsonObject = new JSONObject(map);
String yamlStr = json2Yml2(jsonObject.toString());
return yamlStr;
}
public static String json2Yml2(String jsonString) throws JSONException {
Yaml yaml = new Yaml();
String yamlStr = yaml.dump(ymlString2Map(jsonString));
return yamlStr;
}
public static Map<String, Object> ymlString2Map(String yamlString) {
Yaml yaml = new Yaml();
Object object = yaml.load(yamlString);
if (object instanceof List) {
Map<String, Object> map = new HashMap<>();
map.put("---", object);
return map;
}
return (Map<String, Object>) object;
}
}
...@@ -208,30 +208,18 @@ public class ToscaHelper { ...@@ -208,30 +208,18 @@ public class ToscaHelper {
NodeTemplate vmTopology = vmTopologyMap.getNodeTemplate(); NodeTemplate vmTopology = vmTopologyMap.getNodeTemplate();
if (vmTopology.getType().equals(VM_TOPOLOGY)) { if (vmTopology.getType().equals(VM_TOPOLOGY)) {
Map<String, Object> att = vmTopology.getAttributes(); Map<String, Object> att = vmTopology.getAttributes();
Object credentialMap = att.get("credential"); String ymlStr = Converter.map2YmlString((Map<String, Object>) att.get("credential"));
// Map<String, Object> toscaCredential = new HashMap<>(); Credential toscaCredential = objectMapper.readValue(ymlStr, Credential.class);
// toscaCredential.put("protocol", credential.getProtocol()); return toscaCredential;
// 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);
// return vmTopology;
} else { } else {
throw new Exception("NodeTemplate is not of type: " + VM_TOPOLOGY + " it is of type: " + vmTopology.getType()); throw new Exception("NodeTemplate is not of type: " + VM_TOPOLOGY + " it is of type: " + vmTopology.getType());
} }
return null;
} }
public ToscaTemplate setVMTopologyInToscaTemplate(ToscaTemplate toscaTemplate, NodeTemplateMap vmTopologyMap) { public ToscaTemplate setVMTopologyInToscaTemplate(ToscaTemplate toscaTemplate, NodeTemplateMap vmTopologyMap) {
Map<String, NodeTemplate> nodes = toscaTemplate.getTopologyTemplate().getNodeTemplates(); Map<String, NodeTemplate> nodes = toscaTemplate.getTopologyTemplate().getNodeTemplates();
nodes.put(vmTopologyMap.getName(), vmTopologyMap.getNodeTemplate()); nodes.put(vmTopologyMap.getName(), vmTopologyMap.getNodeTemplate());
// Set<String> keys = nodes.keySet();
// for (String key : keys) {
// NodeTemplate node = nodes.get(key);
// }
return toscaTemplate; return toscaTemplate;
} }
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
* 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.*;
...@@ -47,6 +49,8 @@ import nl.uva.sne.drip.sure.tosca.auth.Authentication; ...@@ -47,6 +49,8 @@ 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";
...@@ -76,6 +80,7 @@ public class ApiClient { ...@@ -76,6 +80,7 @@ public class ApiClient {
public ApiClient() { public ApiClient() {
httpClient = new OkHttpClient(); httpClient = new OkHttpClient();
verifyingSsl = true; verifyingSsl = true;
json = new JSON(); json = new JSON();
...@@ -101,8 +106,7 @@ public class ApiClient { ...@@ -101,8 +106,7 @@ public class ApiClient {
/** /**
* Set base path * Set base path
* *
* @param basePath Base path of the URL (e.g * @param basePath Base path of the URL (e.g https://localhost/tosca-sure/1.0.0
* 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) {
...@@ -160,9 +164,9 @@ public class ApiClient { ...@@ -160,9 +164,9 @@ public class ApiClient {
} }
/** /**
* Configure whether to verify certificate and hostname when making https * Configure whether to verify certificate and hostname when making https requests.
* requests. Default to true. NOTE: Do NOT set to false in production code, * Default to true.
* otherwise you would face multiple types of cryptographic attacks. * 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 * @param verifyingSsl True to verify TLS/SSL connection
* @return ApiClient * @return ApiClient
...@@ -200,8 +204,8 @@ public class ApiClient { ...@@ -200,8 +204,8 @@ public class ApiClient {
} }
/** /**
* Configure client keys to use for authorization in an SSL session. Use * Configure client keys to use for authorization in an SSL session.
* null to reset to default. * Use null to reset to default.
* *
* @param managers The KeyManagers to use * @param managers The KeyManagers to use
* @return ApiClient * @return ApiClient
...@@ -389,12 +393,11 @@ public class ApiClient { ...@@ -389,12 +393,11 @@ public class ApiClient {
} }
/** /**
* The path of temporary folder used to store downloaded files from * The path of temporary folder used to store downloaded files from endpoints
* endpoints with file response. The default value is <code>null</code>, * with file response. The default value is <code>null</code>, i.e. using
* i.e. using the system's default tempopary folder. * the system's default tempopary folder.
* *
* @see * @see <a href="https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile">createTempFile</a>
* <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() {
...@@ -422,8 +425,8 @@ public class ApiClient { ...@@ -422,8 +425,8 @@ public class ApiClient {
} }
/** /**
* Sets the connect timeout (in milliseconds). A value of 0 means no * Sets the connect timeout (in milliseconds).
* timeout, otherwise values must be between 1 and * A value of 0 means no 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
...@@ -444,8 +447,9 @@ public class ApiClient { ...@@ -444,8 +447,9 @@ public class ApiClient {
} }
/** /**
* Sets the read timeout (in milliseconds). A value of 0 means no timeout, * Sets the read timeout (in milliseconds).
* otherwise values must be between 1 and {@link Integer#MAX_VALUE}. * A value of 0 means no timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}.
* *
* @param readTimeout read timeout in milliseconds * @param readTimeout read timeout in milliseconds
* @return Api client * @return Api client
...@@ -465,8 +469,9 @@ public class ApiClient { ...@@ -465,8 +469,9 @@ public class ApiClient {
} }
/** /**
* Sets the write timeout (in milliseconds). A value of 0 means no timeout, * Sets the write timeout (in milliseconds).
* otherwise values must be between 1 and {@link Integer#MAX_VALUE}. * A value of 0 means no timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}.
* *
* @param writeTimeout connection timeout in milliseconds * @param writeTimeout connection timeout in milliseconds
* @return Api client * @return Api client
...@@ -491,7 +496,7 @@ public class ApiClient { ...@@ -491,7 +496,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(",");
} }
...@@ -504,8 +509,7 @@ public class ApiClient { ...@@ -504,8 +509,7 @@ public class ApiClient {
} }
/** /**
* Formats the specified query parameter to a list containing a single * Formats the specified query parameter to a list containing a single {@code Pair} object.
* {@code Pair} object.
* *
* Note that {@code value} must not be a collection. * Note that {@code value} must not be a collection.
* *
...@@ -517,20 +521,16 @@ public class ApiClient { ...@@ -517,20 +521,16 @@ 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) { if (name == null || name.isEmpty() || value == null || value instanceof Collection) return params;
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 * Formats the specified collection query parameters to a list of {@code Pair} objects.
* {@code Pair} objects.
* *
* Note that the values of each of the returned Pair objects are * Note that the values of each of the returned Pair objects are percent-encoded.
* 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 +566,7 @@ public class ApiClient { ...@@ -566,7 +566,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,7 +578,8 @@ public class ApiClient { ...@@ -578,7 +578,8 @@ public class ApiClient {
} }
/** /**
* Sanitize filename by removing path. e.g. ../../sun.gif becomes sun.gif * Sanitize filename by removing path.
* 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
...@@ -588,26 +589,29 @@ public class ApiClient { ...@@ -588,26 +589,29 @@ public class ApiClient {
} }
/** /**
* Check if the given MIME is a JSON MIME. JSON MIME examples: * Check if the given MIME is a JSON MIME.
* application/json application/json; charset=UTF8 APPLICATION/JSON * JSON MIME examples:
* application/vnd.company+json "* / *" is also default to JSON * application/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: if JSON * Select the Accept header's value from the given accepts array:
* exists in the given array, use it; otherwise use all of them (joining * if JSON exists in the given array, use it;
* into a string) * otherwise use all of them (joining 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, null will * @return The Accept header to use. If the given array is empty,
* be returned (not to set the Accept header explicitly). * null will 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) {
...@@ -622,17 +626,17 @@ public class ApiClient { ...@@ -622,17 +626,17 @@ public class ApiClient {
} }
/** /**
* Select the Content-Type header's value from the given array: if JSON * Select the Content-Type header's value from the given array:
* exists in the given array, use it; otherwise use the first one of the * if JSON exists in the given array, use it;
* array. * otherwise use the first one of the 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, or * @return The Content-Type header to use. If the given array is empty,
* matches "any", JSON will be used. * or 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)) {
...@@ -657,15 +661,15 @@ public class ApiClient { ...@@ -657,15 +661,15 @@ public class ApiClient {
} }
/** /**
* Deserialize response body to Java object, according to the return type * Deserialize response body to Java object, according to the return type and
* and the Content-Type response header. * 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 * @throws ApiException If fail to deserialize response body, i.e. cannot read response body
* read response body or the Content-Type of the response is not supported. * 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 {
...@@ -687,11 +691,10 @@ public class ApiClient { ...@@ -687,11 +691,10 @@ 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);
} }
...@@ -720,8 +723,8 @@ public class ApiClient { ...@@ -720,8 +723,8 @@ public class ApiClient {
} }
/** /**
* Serialize the given Java object into request body according to the * Serialize the given Java object into request body according to the object's
* object's class and the request Content-Type. * 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
...@@ -752,8 +755,7 @@ public class ApiClient { ...@@ -752,8 +755,7 @@ 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 * @throws ApiException If fail to read file content from response and write to disk
* to disk
* @return Downloaded file * @return Downloaded file
*/ */
public File downloadFileFromResponse(Response response) throws ApiException { public File downloadFileFromResponse(Response response) throws ApiException {
...@@ -801,16 +803,14 @@ public class ApiClient { ...@@ -801,16 +803,14 @@ 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,15 +826,14 @@ public class ApiClient { ...@@ -826,15 +826,14 @@ public class ApiClient {
} }
/** /**
* Execute HTTP call and deserialize the HTTP response body into the given * Execute HTTP call and deserialize the HTTP response body into the given return type.
* 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 data, * @return ApiResponse object containing response status, headers and
* which is a Java object deserialized from response body and would be null * data, 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 {
...@@ -890,14 +889,13 @@ public class ApiClient { ...@@ -890,14 +889,13 @@ public class ApiClient {
} }
/** /**
* Handle the given response, return the deserialized object when the * Handle the given response, return the deserialized object when the response is successful.
* 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 {
...@@ -933,8 +931,7 @@ public class ApiClient { ...@@ -933,8 +931,7 @@ 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", * @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
* "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
...@@ -955,8 +952,7 @@ public class ApiClient { ...@@ -955,8 +952,7 @@ 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", * @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
* "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
...@@ -964,7 +960,7 @@ public class ApiClient { ...@@ -964,7 +960,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 {
...@@ -1001,7 +997,7 @@ public class ApiClient { ...@@ -1001,7 +997,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 {
...@@ -1012,8 +1008,7 @@ public class ApiClient { ...@@ -1012,8 +1008,7 @@ public class ApiClient {
} }
/** /**
* Build full URL by concatenating base path, the given sub path and query * Build full URL by concatenating base path, the given sub path and query parameters.
* parameters.
* *
* @param path The sub path * @param path The sub path
* @param queryParams The query parameters * @param queryParams The query parameters
...@@ -1082,15 +1077,13 @@ public class ApiClient { ...@@ -1082,15 +1077,13 @@ 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) { if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
throw new RuntimeException("Authentication undefined: " + authName);
}
auth.applyToParams(queryParams, headerParams); auth.applyToParams(queryParams, headerParams);
} }
} }
...@@ -1102,7 +1095,7 @@ public class ApiClient { ...@@ -1102,7 +1095,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()));
} }
...@@ -1110,8 +1103,8 @@ public class ApiClient { ...@@ -1110,8 +1103,8 @@ public class ApiClient {
} }
/** /**
* Build a multipart (file uploading) request body with the given form * Build a multipart (file uploading) request body with the given form parameters,
* parameters, which could contain text fields and file fields. * 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
...@@ -1133,8 +1126,7 @@ public class ApiClient { ...@@ -1133,8 +1126,7 @@ public class ApiClient {
} }
/** /**
* Guess Content-Type header from the given file (defaults to * Guess Content-Type header from the given file (defaults to "application/octet-stream").
* "application/octet-stream").
* *
* @param file The given file * @param file The given file
* @return The guessed Content-Type * @return The guessed Content-Type
...@@ -1149,8 +1141,8 @@ public class ApiClient { ...@@ -1149,8 +1141,8 @@ public class ApiClient {
} }
/** /**
* Apply SSL related settings to httpClient according to the current values * Apply SSL related settings to httpClient according to the current values of
* of verifyingSsl and sslCaCert. * verifyingSsl and sslCaCert.
*/ */
private void applySslSettings() { private void applySslSettings() {
try { try {
...@@ -1159,25 +1151,17 @@ public class ApiClient { ...@@ -1159,25 +1151,17 @@ 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() { public X509Certificate[] getAcceptedIssuers() { return null; }
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) { public boolean verify(String hostname, SSLSession session) { return true; }
return true;
}
}; };
} else if (sslCaCert != null) { } else if (sslCaCert != null) {
char[] password = null; // Any password will work. char[] password = null; // Any password will work.
......
...@@ -16,7 +16,7 @@ package nl.uva.sne.drip.sure.tosca.client; ...@@ -16,7 +16,7 @@ package nl.uva.sne.drip.sure.tosca.client;
import java.util.Map; import java.util.Map;
import java.util.List; import java.util.List;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2019-12-20T15:53:11.510Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2019-12-25T13:58:54.535Z")
public class ApiException extends Exception { public class ApiException extends Exception {
private int code = 0; private int code = 0;
private Map<String, List<String>> responseHeaders = null; private Map<String, List<String>> responseHeaders = null;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
package nl.uva.sne.drip.sure.tosca.client; package nl.uva.sne.drip.sure.tosca.client;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2019-12-20T15:53:11.510Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2019-12-25T13:58:54.535Z")
public class Configuration { public class Configuration {
private static ApiClient defaultApiClient = new ApiClient(); private static ApiClient defaultApiClient = new ApiClient();
......
...@@ -754,6 +754,145 @@ public class DefaultApi { ...@@ -754,6 +754,145 @@ public class DefaultApi {
return call; return call;
} }
/**
* Build call for getNodeAttributes
*
* @param id ID of topolog template uplodaed (required)
* @param nodeName node_name (required)
* @param progressListener Progress listener
* @param progressRequestListener Progress request listener
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
public com.squareup.okhttp.Call getNodeAttributesCall(String id, String nodeName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
Object localVarPostBody = null;
// create path and map variables
String localVarPath = "/tosca_template/{id}/topology_template/node_templates/{node_name}/attributes"
.replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString()))
.replaceAll("\\{" + "node_name" + "\\}", apiClient.escapeString(nodeName.toString()));
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
final String[] localVarAccepts = {
"application/json"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}
final String[] localVarContentTypes = {};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);
if (progressListener != null) {
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
});
}
String[] localVarAuthNames = new String[]{};
return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}
@SuppressWarnings("rawtypes")
private com.squareup.okhttp.Call getNodeAttributesValidateBeforeCall(String id, String nodeName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
// verify the required parameter 'id' is set
if (id == null) {
throw new ApiException("Missing the required parameter 'id' when calling getNodeAttributes(Async)");
}
// verify the required parameter 'nodeName' is set
if (nodeName == null) {
throw new ApiException("Missing the required parameter 'nodeName' when calling getNodeAttributes(Async)");
}
com.squareup.okhttp.Call call = getNodeAttributesCall(id, nodeName, progressListener, progressRequestListener);
return call;
}
/**
*
*
* @param id ID of topolog template uplodaed (required)
* @param nodeName node_name (required)
* @return Map&lt;String, Object&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot
* deserialize the response body
*/
public Map<String, Object> getNodeAttributes(String id, String nodeName) throws ApiException {
ApiResponse<Map<String, Object>> resp = getNodeAttributesWithHttpInfo(id, nodeName);
return resp.getData();
}
/**
*
*
* @param id ID of topolog template uplodaed (required)
* @param nodeName node_name (required)
* @return ApiResponse&lt;Map&lt;String, Object&gt;&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot
* deserialize the response body
*/
public ApiResponse<Map<String, Object>> getNodeAttributesWithHttpInfo(String id, String nodeName) throws ApiException {
com.squareup.okhttp.Call call = getNodeAttributesValidateBeforeCall(id, nodeName, null, null);
Type localVarReturnType = new TypeToken<Map<String, Object>>() {
}.getType();
return apiClient.execute(call, localVarReturnType);
}
/**
* (asynchronously)
*
* @param id ID of topolog template uplodaed (required)
* @param nodeName node_name (required)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing
* the request body object
*/
public com.squareup.okhttp.Call getNodeAttributesAsync(String id, String nodeName, final ApiCallback<Map<String, Object>> callback) throws ApiException {
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
com.squareup.okhttp.Call call = getNodeAttributesValidateBeforeCall(id, nodeName, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken<Map<String, Object>>() {
}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
/** /**
* Build call for getNodeOutputs * Build call for getNodeOutputs
* *
...@@ -2389,6 +2528,154 @@ public class DefaultApi { ...@@ -2389,6 +2528,154 @@ public class DefaultApi {
return call; return call;
} }
/**
* Build call for setNodeAttributes
*
* @param id ID of topolog template uplodaed (required)
* @param properties (required)
* @param nodeName node_name (required)
* @param progressListener Progress listener
* @param progressRequestListener Progress request listener
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
public com.squareup.okhttp.Call setNodeAttributesCall(String id, Object properties, String nodeName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
Object localVarPostBody = properties;
// create path and map variables
String localVarPath = "/tosca_template/{id}/topology_template/node_templates/{node_name}/attributes"
.replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(id.toString()))
.replaceAll("\\{" + "node_name" + "\\}", apiClient.escapeString(nodeName.toString()));
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
final String[] localVarAccepts = {
"application/json"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}
final String[] localVarContentTypes = {};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);
if (progressListener != null) {
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
});
}
String[] localVarAuthNames = new String[]{};
return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}
@SuppressWarnings("rawtypes")
private com.squareup.okhttp.Call setNodeAttributesValidateBeforeCall(String id, Object properties, String nodeName, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
// verify the required parameter 'id' is set
if (id == null) {
throw new ApiException("Missing the required parameter 'id' when calling setNodeAttributes(Async)");
}
// verify the required parameter 'properties' is set
if (properties == null) {
throw new ApiException("Missing the required parameter 'properties' when calling setNodeAttributes(Async)");
}
// verify the required parameter 'nodeName' is set
if (nodeName == null) {
throw new ApiException("Missing the required parameter 'nodeName' when calling setNodeAttributes(Async)");
}
com.squareup.okhttp.Call call = setNodeAttributesCall(id, properties, nodeName, progressListener, progressRequestListener);
return call;
}
/**
*
*
* @param id ID of topolog template uplodaed (required)
* @param properties (required)
* @param nodeName node_name (required)
* @return String
* @throws ApiException If fail to call the API, e.g. server error or cannot
* deserialize the response body
*/
public String setNodeAttributes(String id, Object properties, String nodeName) throws ApiException {
ApiResponse<String> resp = setNodeAttributesWithHttpInfo(id, properties, nodeName);
return resp.getData();
}
/**
*
*
* @param id ID of topolog template uplodaed (required)
* @param properties (required)
* @param nodeName node_name (required)
* @return ApiResponse&lt;String&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot
* deserialize the response body
*/
public ApiResponse<String> setNodeAttributesWithHttpInfo(String id, Object properties, String nodeName) throws ApiException {
com.squareup.okhttp.Call call = setNodeAttributesValidateBeforeCall(id, properties, nodeName, null, null);
Type localVarReturnType = new TypeToken<String>() {
}.getType();
return apiClient.execute(call, localVarReturnType);
}
/**
* (asynchronously)
*
* @param id ID of topolog template uplodaed (required)
* @param properties (required)
* @param nodeName node_name (required)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing
* the request body object
*/
public com.squareup.okhttp.Call setNodeAttributesAsync(String id, Object properties, String nodeName, final ApiCallback<String> callback) throws ApiException {
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
com.squareup.okhttp.Call call = setNodeAttributesValidateBeforeCall(id, properties, nodeName, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken<String>() {
}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
/** /**
* Build call for setNodeProperties * Build call for setNodeProperties
* *
......
...@@ -23,7 +23,7 @@ import io.gsonfire.GsonFireBuilder; ...@@ -23,7 +23,7 @@ import io.gsonfire.GsonFireBuilder;
import org.threeten.bp.LocalDate; import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime; import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
;
import okio.ByteString; import okio.ByteString;
import java.io.IOException; import java.io.IOException;
...@@ -35,6 +35,8 @@ import java.text.ParsePosition; ...@@ -35,6 +35,8 @@ import java.text.ParsePosition;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
public class JSON { public class JSON {
private Gson gson; private Gson gson;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
package nl.uva.sne.drip.sure.tosca.client; package nl.uva.sne.drip.sure.tosca.client;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2019-12-20T15:53:11.510Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2019-12-25T13:58:54.535Z")
public class Pair { public class Pair {
private String name = ""; private String name = "";
private String value = ""; private String value = "";
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
package nl.uva.sne.drip.sure.tosca.client; package nl.uva.sne.drip.sure.tosca.client;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2019-12-20T15:53:11.510Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2019-12-25T13:58:54.535Z")
public class StringUtil { public class StringUtil {
/** /**
* Check if the given array contains the given value (with case-insensitive comparison). * Check if the given array contains the given value (with case-insensitive comparison).
......
...@@ -25,17 +25,12 @@ import java.nio.file.Files; ...@@ -25,17 +25,12 @@ import java.nio.file.Files;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.model.NodeTemplate;
import nl.uva.sne.drip.model.NodeTemplateMap; import nl.uva.sne.drip.model.NodeTemplateMap;
import nl.uva.sne.drip.model.tosca.ToscaTemplate; import nl.uva.sne.drip.model.tosca.ToscaTemplate;
import org.junit.After; import org.junit.After;
......
package nl.uva.sne.drip.api; package nl.uva.sne.drip.api;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -15,6 +16,7 @@ import javax.validation.Valid; ...@@ -15,6 +16,7 @@ import javax.validation.Valid;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.logging.Level;
import nl.uva.sne.drip.service.ToscaTemplateService; import nl.uva.sne.drip.service.ToscaTemplateService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -56,6 +58,8 @@ public class ToscaTemplateApiController implements ToscaTemplateApi { ...@@ -56,6 +58,8 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
} catch (IOException e) { } catch (IOException e) {
log.error("Couldn't serialize response for content type ", e); log.error("Couldn't serialize response for content type ", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (NotFoundException ex) {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
......
...@@ -202,10 +202,10 @@ class CloudStormService { ...@@ -202,10 +202,10 @@ class CloudStormService {
} }
private CredentialInfo getCloudStormCredentialInfo(Credential toscaCredentials) throws FileNotFoundException { private CredentialInfo getCloudStormCredentialInfo(Credential toscaCredentials) throws FileNotFoundException {
CredentialInfo cloudStormCredentialInfo = new CredentialInfo(); CredentialInfo cloudStormCredentialInfo = new CredentialInfo();
switch (toscaCredentials.getCloudProviderName().toLowerCase()) { switch (toscaCredentials.getCloudProviderName().toLowerCase()) {
case "exogeni": case "exogeni":
String base64Keystore = toscaCredentials.getKeys().get("keystore"); String base64Keystore = toscaCredentials.getKeys().get("keystore");
byte[] decoded = Base64.getDecoder().decode(base64Keystore); byte[] decoded = Base64.getDecoder().decode(base64Keystore);
try (PrintWriter out = new PrintWriter("user.jks")) { try (PrintWriter out = new PrintWriter("user.jks")) {
...@@ -217,7 +217,7 @@ CredentialInfo cloudStormCredentialInfo = new CredentialInfo(); ...@@ -217,7 +217,7 @@ CredentialInfo cloudStormCredentialInfo = new CredentialInfo();
return cloudStormCredentialInfo; return cloudStormCredentialInfo;
case "ec2": case "ec2":
// cloudStormCredentialInfo.setAccessKey(toscaCredentials.get); // cloudStormCredentialInfo.setAccessKey(toscaCredentials.get);
return cloudStormCredentialInfo; return cloudStormCredentialInfo;
} }
return null; return null;
......
...@@ -367,3 +367,39 @@ def upload_tosca_template(file): # noqa: E501 ...@@ -367,3 +367,39 @@ def upload_tosca_template(file): # noqa: E501
if res: if res:
return res return res
return 'Bad Request', 400 return 'Bad Request', 400
def set_node_attributes(id, properties, node_name): # noqa: E501
"""set_node_attributes
# noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param properties:
:type properties:
:param node_name: node_name
:type node_name: str
:rtype: str
"""
return 'do some magic!'
def get_node_attributes(id, node_name): # noqa: E501
"""get_node_attributes
# noqa: E501
:param id: ID of topolog template uplodaed
:type id: str
:param node_name: node_name
:type node_name: str
:rtype: Dict[str, object]
"""
res = tosca_template_service.get_node_attributes(id, node_name)
if res:
return res
return 'Not Found', 404
...@@ -118,7 +118,7 @@ def get_interface_types(id, interface_type=None): ...@@ -118,7 +118,7 @@ def get_interface_types(id, interface_type=None):
return query_db(queries, db=interface_types_db) return query_db(queries, db=interface_types_db)
def change_to_nodeTemplateModel(query_results): def change_to_node_template_model(query_results):
res = [] res = []
for node_template in query_results: for node_template in query_results:
# copy.deepcopy() # copy.deepcopy()
...@@ -189,7 +189,7 @@ def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None, ...@@ -189,7 +189,7 @@ def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None,
queries.append(query.artifacts != prop) queries.append(query.artifacts != prop)
query_results = query_db(queries, db=node_template_db) query_results = query_db(queries, db=node_template_db)
return change_to_nodeTemplateModel(query_results) return change_to_node_template_model(query_results)
def get_tosca_template_get_dsl_definitions(id, anchors, derived_from): def get_tosca_template_get_dsl_definitions(id, anchors, derived_from):
...@@ -325,6 +325,14 @@ def get_node_requirements(id, node_name): ...@@ -325,6 +325,14 @@ def get_node_requirements(id, node_name):
return None return None
def get_node_attributes(id, node_name):
node_template_map = get_node_templates(id, node_name=node_name)[0]
attributes = node_template_map.node_template.attributes
if attributes:
return attributes
return None
def get_related_nodes(id, node_name): def get_related_nodes(id, node_name):
tosca_template_dict = get_tosca_template_dict_by_id(id) tosca_template_dict = get_tosca_template_dict_by_id(id)
tosca_template = get_tosca_template(tosca_template_dict) tosca_template = get_tosca_template(tosca_template_dict)
......
...@@ -28,11 +28,11 @@ paths: ...@@ -28,11 +28,11 @@ paths:
required: true required: true
type: "file" type: "file"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "string" type: "string"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}: /tosca_template/{id}:
...@@ -48,13 +48,13 @@ paths: ...@@ -48,13 +48,13 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
$ref: "#/definitions/ToscaTemplate" $ref: "#/definitions/ToscaTemplate"
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/imports: /tosca_template/{id}/imports:
...@@ -71,7 +71,7 @@ paths: ...@@ -71,7 +71,7 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "array" type: "array"
...@@ -80,9 +80,9 @@ paths: ...@@ -80,9 +80,9 @@ paths:
additionalProperties: additionalProperties:
type: "object" type: "object"
properties: {} properties: {}
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/dsl_definitions: /tosca_template/{id}/dsl_definitions:
...@@ -112,7 +112,7 @@ paths: ...@@ -112,7 +112,7 @@ paths:
required: false required: false
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "array" type: "array"
...@@ -121,9 +121,9 @@ paths: ...@@ -121,9 +121,9 @@ paths:
additionalProperties: additionalProperties:
type: "object" type: "object"
properties: {} properties: {}
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/types: /tosca_template/{id}/types:
...@@ -195,7 +195,7 @@ paths: ...@@ -195,7 +195,7 @@ paths:
required: false required: false
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "array" type: "array"
...@@ -204,9 +204,9 @@ paths: ...@@ -204,9 +204,9 @@ paths:
additionalProperties: additionalProperties:
type: "object" type: "object"
properties: {} properties: {}
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/relationship_templates: /tosca_template/{id}/relationship_templates:
...@@ -233,7 +233,7 @@ paths: ...@@ -233,7 +233,7 @@ paths:
required: false required: false
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "array" type: "array"
...@@ -242,9 +242,9 @@ paths: ...@@ -242,9 +242,9 @@ paths:
additionalProperties: additionalProperties:
type: "object" type: "object"
properties: {} properties: {}
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template: /tosca_template/{id}/topology_template:
...@@ -260,13 +260,13 @@ paths: ...@@ -260,13 +260,13 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
$ref: "#/definitions/TopologyTemplate" $ref: "#/definitions/TopologyTemplate"
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates: /tosca_template/{id}/topology_template/node_templates:
...@@ -322,15 +322,15 @@ paths: ...@@ -322,15 +322,15 @@ paths:
required: false required: false
type: "boolean" type: "boolean"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "array" type: "array"
items: items:
$ref: "#/definitions/NodeTemplate" $ref: "#/definitions/NodeTemplateMap"
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_name}/type_name: /tosca_template/{id}/topology_template/node_templates/{node_name}/type_name:
...@@ -352,13 +352,13 @@ paths: ...@@ -352,13 +352,13 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "string" type: "string"
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_name}/requirements: /tosca_template/{id}/topology_template/node_templates/{node_name}/requirements:
...@@ -380,16 +380,16 @@ paths: ...@@ -380,16 +380,16 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "object" type: "object"
additionalProperties: additionalProperties:
type: "object" type: "object"
properties: {} properties: {}
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_name}/derived_from: /tosca_template/{id}/topology_template/node_templates/{node_name}/derived_from:
...@@ -411,13 +411,13 @@ paths: ...@@ -411,13 +411,13 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "string" type: "string"
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_requirements: /tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_requirements:
...@@ -440,16 +440,16 @@ paths: ...@@ -440,16 +440,16 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "object" type: "object"
additionalProperties: additionalProperties:
type: "object" type: "object"
properties: {} properties: {}
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_types: /tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_types:
...@@ -472,15 +472,15 @@ paths: ...@@ -472,15 +472,15 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "array" type: "array"
items: items:
type: "string" type: "string"
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_properties: /tosca_template/{id}/topology_template/node_templates/{node_name}/ancestors_properties:
...@@ -503,7 +503,7 @@ paths: ...@@ -503,7 +503,7 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "array" type: "array"
...@@ -512,9 +512,9 @@ paths: ...@@ -512,9 +512,9 @@ paths:
additionalProperties: additionalProperties:
type: "object" type: "object"
properties: {} properties: {}
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_name}/properties: /tosca_template/{id}/topology_template/node_templates/{node_name}/properties:
...@@ -536,16 +536,16 @@ paths: ...@@ -536,16 +536,16 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "object" type: "object"
additionalProperties: additionalProperties:
type: "object" type: "object"
properties: {} properties: {}
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
put: put:
...@@ -574,13 +574,13 @@ paths: ...@@ -574,13 +574,13 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "string" type: "string"
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_name}/outputs: /tosca_template/{id}/topology_template/node_templates/{node_name}/outputs:
...@@ -602,7 +602,7 @@ paths: ...@@ -602,7 +602,7 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "array" type: "array"
...@@ -611,9 +611,9 @@ paths: ...@@ -611,9 +611,9 @@ paths:
additionalProperties: additionalProperties:
type: "object" type: "object"
properties: {} properties: {}
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_name}/related: /tosca_template/{id}/topology_template/node_templates/{node_name}/related:
...@@ -635,15 +635,77 @@ paths: ...@@ -635,15 +635,77 @@ paths:
required: true required: true
type: "string" type: "string"
responses: responses:
200: "200":
description: "successful operation" description: "successful operation"
schema: schema:
type: "array" type: "array"
items: items:
$ref: "#/definitions/NodeTemplate" $ref: "#/definitions/NodeTemplateMap"
404: "404":
description: "Not found" description: "Not found"
405: "405":
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates/{node_name}/attributes:
get:
operationId: "get_node_attributes"
produces:
- "application/json"
parameters:
- name: "id"
in: "path"
description: "ID of topolog template uplodaed"
required: true
type: "string"
- name: "node_name"
in: "path"
description: "node_name"
required: true
type: "string"
responses:
"200":
description: "successful operation"
schema:
type: "object"
additionalProperties:
type: "object"
properties: {}
"404":
description: "Not found"
"405":
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
put:
operationId: "set_node_attributes"
produces:
- "application/json"
parameters:
- name: "id"
in: "path"
description: "ID of topolog template uplodaed"
required: true
type: "string"
- in: "body"
name: "properties"
required: true
schema:
type: "object"
additionalProperties:
type: "object"
properties: {}
- name: "node_name"
in: "path"
description: "node_name"
required: true
type: "string"
responses:
"200":
description: "successful operation"
schema:
type: "string"
"404":
description: "Not found"
"405":
description: "Invalid input" description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller" x-swagger-router-controller: "sure_tosca.controllers.default_controller"
definitions: definitions:
...@@ -935,3 +997,32 @@ definitions: ...@@ -935,3 +997,32 @@ definitions:
key: "{}" key: "{}"
artifacts: artifacts:
key: "{}" key: "{}"
NodeTemplateMap:
type: "object"
properties:
name:
type: "string"
nodeTemplate:
$ref: "#/definitions/NodeTemplate"
example:
name: "name"
nodeTemplate:
requirements:
- key: "{}"
- key: "{}"
interfaces:
key: "{}"
capabilities:
key: "{}"
directives:
- "directives"
- "directives"
derived_from: "derived_from"
description: "description"
attributes:
key: "{}"
type: "type"
properties:
key: "{}"
artifacts:
key: "{}"
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