Commit c3f29fd7 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added get attributes and get tosca credentials

parent 3890b724
......@@ -76,7 +76,6 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
<dependency>
<groupId>io.gsonfire</groupId>
......@@ -133,6 +132,18 @@
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</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>
......@@ -151,7 +162,7 @@
</execution>
</executions>
</plugin>
<!-- <plugin>
<!-- <plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<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 {
NodeTemplate vmTopology = vmTopologyMap.getNodeTemplate();
if (vmTopology.getType().equals(VM_TOPOLOGY)) {
Map<String, Object> att = vmTopology.getAttributes();
Object credentialMap = att.get("credential");
// 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);
// vmTopology.setAttributes(att);
// return vmTopology;
String ymlStr = Converter.map2YmlString((Map<String, Object>) att.get("credential"));
Credential toscaCredential = objectMapper.readValue(ymlStr, Credential.class);
return toscaCredential;
} else {
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) {
Map<String, NodeTemplate> nodes = toscaTemplate.getTopologyTemplate().getNodeTemplates();
nodes.put(vmTopologyMap.getName(), vmTopologyMap.getNodeTemplate());
// Set<String> keys = nodes.keySet();
// for (String key : keys) {
// NodeTemplate node = nodes.get(key);
// }
return toscaTemplate;
}
......
......@@ -9,6 +9,8 @@
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package nl.uva.sne.drip.sure.tosca.client;
import com.squareup.okhttp.*;
......@@ -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.OAuth;
public class ApiClient {
private String basePath = "https://localhost/tosca-sure/1.0.0";
......@@ -76,6 +80,7 @@ public class ApiClient {
public ApiClient() {
httpClient = new OkHttpClient();
verifyingSsl = true;
json = new JSON();
......@@ -101,8 +106,7 @@ public class ApiClient {
/**
* 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
*/
public ApiClient setBasePath(String basePath) {
......@@ -160,9 +164,9 @@ public class ApiClient {
}
/**
* Configure whether to verify certificate and hostname when making https
* requests. Default to true. NOTE: Do NOT set to false in production code,
* otherwise you would face multiple types of cryptographic attacks.
* Configure whether to verify certificate and hostname when making https requests.
* Default to true.
* NOTE: Do NOT set to false in production code, otherwise you would face multiple types of cryptographic attacks.
*
* @param verifyingSsl True to verify TLS/SSL connection
* @return ApiClient
......@@ -200,8 +204,8 @@ public class ApiClient {
}
/**
* Configure client keys to use for authorization in an SSL session. Use
* null to reset to default.
* Configure client keys to use for authorization in an SSL session.
* Use null to reset to default.
*
* @param managers The KeyManagers to use
* @return ApiClient
......@@ -389,12 +393,11 @@ public class ApiClient {
}
/**
* The path of temporary folder used to store downloaded files from
* endpoints with file response. The default value is <code>null</code>,
* i.e. using the system's default tempopary folder.
* The path of temporary folder used to store downloaded files from endpoints
* with file response. The default value is <code>null</code>, i.e. using
* the system's default tempopary folder.
*
* @see
* <a href="https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile">createTempFile</a>
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile">createTempFile</a>
* @return Temporary folder path
*/
public String getTempFolderPath() {
......@@ -422,8 +425,8 @@ public class ApiClient {
}
/**
* Sets the connect timeout (in milliseconds). A value of 0 means no
* timeout, otherwise values must be between 1 and
* Sets the connect timeout (in milliseconds).
* A value of 0 means no timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}.
*
* @param connectionTimeout connection timeout in milliseconds
......@@ -444,8 +447,9 @@ public class ApiClient {
}
/**
* Sets the read timeout (in milliseconds). A value of 0 means no timeout,
* otherwise values must be between 1 and {@link Integer#MAX_VALUE}.
* Sets the read timeout (in milliseconds).
* A value of 0 means no timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}.
*
* @param readTimeout read timeout in milliseconds
* @return Api client
......@@ -465,8 +469,9 @@ public class ApiClient {
}
/**
* Sets the write timeout (in milliseconds). A value of 0 means no timeout,
* otherwise values must be between 1 and {@link Integer#MAX_VALUE}.
* Sets the write timeout (in milliseconds).
* A value of 0 means no timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}.
*
* @param writeTimeout connection timeout in milliseconds
* @return Api client
......@@ -491,7 +496,7 @@ public class ApiClient {
return jsonStr.substring(1, jsonStr.length() - 1);
} else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for (Object o : (Collection) param) {
for (Object o : (Collection)param) {
if (b.length() > 0) {
b.append(",");
}
......@@ -504,8 +509,7 @@ 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.
*
......@@ -517,20 +521,16 @@ public class ApiClient {
List<Pair> params = new ArrayList<Pair>();
// 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)));
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 name The name of the parameter.
......@@ -566,7 +566,7 @@ public class ApiClient {
delimiter = escapeString("|");
}
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder() ;
for (Object item : value) {
sb.append(delimiter);
sb.append(escapeString(parameterToString(item)));
......@@ -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
* @return The sanitized filename
......@@ -588,10 +589,13 @@ public class ApiClient {
}
/**
* Check if the given MIME is a JSON MIME. JSON MIME examples:
* application/json application/json; charset=UTF8 APPLICATION/JSON
* application/vnd.company+json "* / *" is also default to JSON
*
* Check if the given MIME is a JSON MIME.
* JSON MIME examples:
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* "* / *" is also default to JSON
* @param mime MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
......@@ -601,13 +605,13 @@ public class ApiClient {
}
/**
* Select the Accept header's value from the given accepts array: if JSON
* exists in the given array, use it; otherwise use all of them (joining
* into a string)
* Select the Accept header's value from the given accepts array:
* if JSON exists in the given array, use it;
* otherwise use all of them (joining into a string)
*
* @param accepts The accepts array to select from
* @return The Accept header to use. If the given array is empty, null will
* be returned (not to set the Accept header explicitly).
* @return The Accept header to use. If the given array is empty,
* null will be returned (not to set the Accept header explicitly).
*/
public String selectHeaderAccept(String[] accepts) {
if (accepts.length == 0) {
......@@ -622,13 +626,13 @@ public class ApiClient {
}
/**
* Select the Content-Type header's value from the given array: if JSON
* exists in the given array, use it; otherwise use the first one of the
* array.
* Select the Content-Type header's value from the given array:
* if JSON exists in the given array, use it;
* otherwise use the first one of the array.
*
* @param contentTypes The Content-Type array to select from
* @return The Content-Type header to use. If the given array is empty, or
* matches "any", JSON will be used.
* @return The Content-Type header to use. If the given array is empty,
* or matches "any", JSON will be used.
*/
public String selectHeaderContentType(String[] contentTypes) {
if (contentTypes.length == 0 || contentTypes[0].equals("*/*")) {
......@@ -657,15 +661,15 @@ public class ApiClient {
}
/**
* Deserialize response body to Java object, according to the return type
* and the Content-Type response header.
* Deserialize response body to Java object, according to the return type and
* the Content-Type response header.
*
* @param <T> Type
* @param response HTTP response
* @param returnType The type of the Java object
* @return The deserialized Java object
* @throws ApiException If fail to deserialize response body, i.e. cannot
* read response body or the Content-Type of the response is not supported.
* @throws ApiException If fail to deserialize response body, i.e. cannot read response body
* or the Content-Type of the response is not supported.
*/
@SuppressWarnings("unchecked")
public <T> T deserialize(Response response, Type returnType) throws ApiException {
......@@ -687,11 +691,10 @@ public class ApiClient {
String respBody;
try {
if (response.body() != null) {
if (response.body() != null)
respBody = response.body().string();
} else {
else
respBody = null;
}
} catch (IOException e) {
throw new ApiException(e);
}
......@@ -720,8 +723,8 @@ public class ApiClient {
}
/**
* Serialize the given Java object into request body according to the
* object's class and the request Content-Type.
* Serialize the given Java object into request body according to the object's
* class and the request Content-Type.
*
* @param obj The Java object
* @param contentType The request Content-Type
......@@ -752,8 +755,7 @@ public class ApiClient {
* Download file from the given response.
*
* @param response An instance of the Response object
* @throws ApiException If fail to read file content from response and write
* to disk
* @throws ApiException If fail to read file content from response and write to disk
* @return Downloaded file
*/
public File downloadFileFromResponse(Response response) throws ApiException {
......@@ -801,17 +803,15 @@ public class ApiClient {
suffix = filename.substring(pos);
}
// File.createTempFile requires the prefix to be at least three characters long
if (prefix.length() < 3) {
if (prefix.length() < 3)
prefix = "download-";
}
}
if (tempFolderPath == null) {
if (tempFolderPath == null)
return File.createTempFile(prefix, suffix);
} else {
else
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
}
}
/**
* {@link #execute(Call, Type)}
......@@ -826,14 +826,13 @@ 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 <T> The return type corresponding to (same with) returnType
* @param call Call
* @return ApiResponse object containing response status, headers and data,
* which is a Java object deserialized from response body and would be null
* @return ApiResponse object containing response status, headers and
* data, which is a Java object deserialized from response body and would be null
* when returnType is null.
* @throws ApiException If fail to execute the call
*/
......@@ -890,8 +889,7 @@ 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 response Response
......@@ -933,8 +931,7 @@ public class ApiClient {
* Build HTTP call with the given options.
*
* @param path The sub-path of the HTTP URL
* @param method The request method, one of "GET", "HEAD", "OPTIONS",
* "POST", "PUT", "PATCH" and "DELETE"
* @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
* @param queryParams The query parameters
* @param collectionQueryParams The collection query parameters
* @param body The request body object
......@@ -955,8 +952,7 @@ public class ApiClient {
* Build an HTTP request with the given options.
*
* @param path The sub-path of the HTTP URL
* @param method The request method, one of "GET", "HEAD", "OPTIONS",
* "POST", "PUT", "PATCH" and "DELETE"
* @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"
* @param queryParams The query parameters
* @param collectionQueryParams The collection query parameters
* @param body The request body object
......@@ -1001,7 +997,7 @@ public class ApiClient {
Request request = null;
if (progressRequestListener != null && reqBody != null) {
if(progressRequestListener != null && reqBody != null) {
ProgressRequestBody progressRequestBody = new ProgressRequestBody(reqBody, progressRequestListener);
request = reqBuilder.method(method, progressRequestBody).build();
} else {
......@@ -1012,8 +1008,7 @@ 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 queryParams The query parameters
......@@ -1088,9 +1083,7 @@ public class ApiClient {
public void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
for (String authName : authNames) {
Authentication auth = authentications.get(authName);
if (auth == null) {
throw new RuntimeException("Authentication undefined: " + authName);
}
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
auth.applyToParams(queryParams, headerParams);
}
}
......@@ -1110,8 +1103,8 @@ public class ApiClient {
}
/**
* Build a multipart (file uploading) request body with the given form
* parameters, which could contain text fields and file fields.
* Build a multipart (file uploading) request body with the given form parameters,
* which could contain text fields and file fields.
*
* @param formParams Form parameters in the form of Map
* @return RequestBody
......@@ -1133,8 +1126,7 @@ 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
* @return The guessed Content-Type
......@@ -1149,8 +1141,8 @@ public class ApiClient {
}
/**
* Apply SSL related settings to httpClient according to the current values
* of verifyingSsl and sslCaCert.
* Apply SSL related settings to httpClient according to the current values of
* verifyingSsl and sslCaCert.
*/
private void applySslSettings() {
try {
......@@ -1159,25 +1151,17 @@ public class ApiClient {
if (!verifyingSsl) {
TrustManager trustAll = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public X509Certificate[] getAcceptedIssuers() { return null; }
};
SSLContext sslContext = SSLContext.getInstance("TLS");
trustManagers = new TrustManager[]{trustAll};
trustManagers = new TrustManager[]{ trustAll };
hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
public boolean verify(String hostname, SSLSession session) { return true; }
};
} else if (sslCaCert != null) {
char[] password = null; // Any password will work.
......
......@@ -16,7 +16,7 @@ package nl.uva.sne.drip.sure.tosca.client;
import java.util.Map;
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 {
private int code = 0;
private Map<String, List<String>> responseHeaders = null;
......
......@@ -13,7 +13,7 @@
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 {
private static ApiClient defaultApiClient = new ApiClient();
......
......@@ -754,6 +754,145 @@ public class DefaultApi {
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
*
......@@ -2389,6 +2528,154 @@ public class DefaultApi {
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
*
......
......@@ -23,7 +23,7 @@ import io.gsonfire.GsonFireBuilder;
import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.format.DateTimeFormatter;
;
import okio.ByteString;
import java.io.IOException;
......@@ -35,6 +35,8 @@ import java.text.ParsePosition;
import java.util.Date;
import java.util.Map;
public class JSON {
private Gson gson;
......
......@@ -13,7 +13,7 @@
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 {
private String name = "";
private String value = "";
......
......@@ -13,7 +13,7 @@
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 {
/**
* Check if the given array contains the given value (with case-insensitive comparison).
......
......@@ -25,17 +25,12 @@ import java.nio.file.Files;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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.tosca.ToscaTemplate;
import org.junit.After;
......
package nl.uva.sne.drip.api;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*;
import org.slf4j.Logger;
......@@ -15,6 +16,7 @@ import javax.validation.Valid;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import nl.uva.sne.drip.service.ToscaTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -56,6 +58,8 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
} catch (IOException e) {
log.error("Couldn't serialize response for content type ", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (NotFoundException ex) {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, ex);
}
}
......
......@@ -202,7 +202,7 @@ class CloudStormService {
}
private CredentialInfo getCloudStormCredentialInfo(Credential toscaCredentials) throws FileNotFoundException {
CredentialInfo cloudStormCredentialInfo = new CredentialInfo();
CredentialInfo cloudStormCredentialInfo = new CredentialInfo();
switch (toscaCredentials.getCloudProviderName().toLowerCase()) {
case "exogeni":
......
......@@ -367,3 +367,39 @@ def upload_tosca_template(file): # noqa: E501
if res:
return res
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):
return query_db(queries, db=interface_types_db)
def change_to_nodeTemplateModel(query_results):
def change_to_node_template_model(query_results):
res = []
for node_template in query_results:
# copy.deepcopy()
......@@ -189,7 +189,7 @@ def get_node_templates(id, type_name=None, node_name=None, has_interfaces=None,
queries.append(query.artifacts != prop)
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):
......@@ -325,6 +325,14 @@ def get_node_requirements(id, node_name):
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):
tosca_template_dict = get_tosca_template_dict_by_id(id)
tosca_template = get_tosca_template(tosca_template_dict)
......
......@@ -28,11 +28,11 @@ paths:
required: true
type: "file"
responses:
200:
"200":
description: "successful operation"
schema:
type: "string"
405:
"405":
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}:
......@@ -48,13 +48,13 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
$ref: "#/definitions/ToscaTemplate"
404:
"404":
description: "Not found"
405:
"405":
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/imports:
......@@ -71,7 +71,7 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "array"
......@@ -80,9 +80,9 @@ paths:
additionalProperties:
type: "object"
properties: {}
404:
"404":
description: "Not found"
405:
"405":
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/dsl_definitions:
......@@ -112,7 +112,7 @@ paths:
required: false
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "array"
......@@ -121,9 +121,9 @@ paths:
additionalProperties:
type: "object"
properties: {}
404:
"404":
description: "Not found"
405:
"405":
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/types:
......@@ -195,7 +195,7 @@ paths:
required: false
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "array"
......@@ -204,9 +204,9 @@ paths:
additionalProperties:
type: "object"
properties: {}
404:
"404":
description: "Not found"
405:
"405":
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/relationship_templates:
......@@ -233,7 +233,7 @@ paths:
required: false
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "array"
......@@ -242,9 +242,9 @@ paths:
additionalProperties:
type: "object"
properties: {}
404:
"404":
description: "Not found"
405:
"405":
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template:
......@@ -260,13 +260,13 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
$ref: "#/definitions/TopologyTemplate"
404:
"404":
description: "Not found"
405:
"405":
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
/tosca_template/{id}/topology_template/node_templates:
......@@ -322,15 +322,15 @@ paths:
required: false
type: "boolean"
responses:
200:
"200":
description: "successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/NodeTemplate"
404:
$ref: "#/definitions/NodeTemplateMap"
"404":
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}/type_name:
......@@ -352,13 +352,13 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "string"
404:
"404":
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}/requirements:
......@@ -380,16 +380,16 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "object"
additionalProperties:
type: "object"
properties: {}
404:
"404":
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}/derived_from:
......@@ -411,13 +411,13 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "string"
404:
"404":
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}/ancestors_requirements:
......@@ -440,16 +440,16 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "object"
additionalProperties:
type: "object"
properties: {}
404:
"404":
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}/ancestors_types:
......@@ -472,15 +472,15 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "array"
items:
type: "string"
404:
"404":
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}/ancestors_properties:
......@@ -503,7 +503,7 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "array"
......@@ -512,9 +512,9 @@ paths:
additionalProperties:
type: "object"
properties: {}
404:
"404":
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}/properties:
......@@ -536,16 +536,16 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "object"
additionalProperties:
type: "object"
properties: {}
404:
"404":
description: "Not found"
405:
"405":
description: "Invalid input"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
put:
......@@ -574,13 +574,13 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "string"
404:
"404":
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}/outputs:
......@@ -602,7 +602,7 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "array"
......@@ -611,9 +611,9 @@ paths:
additionalProperties:
type: "object"
properties: {}
404:
"404":
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}/related:
......@@ -635,15 +635,77 @@ paths:
required: true
type: "string"
responses:
200:
"200":
description: "successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/NodeTemplate"
404:
$ref: "#/definitions/NodeTemplateMap"
"404":
description: "Not found"
"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:
"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"
x-swagger-router-controller: "sure_tosca.controllers.default_controller"
definitions:
......@@ -935,3 +997,32 @@ definitions:
key: "{}"
artifacts:
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