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>
...@@ -133,6 +132,18 @@ ...@@ -133,6 +132,18 @@
<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;
} }
......
...@@ -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();
......
...@@ -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,7 +202,7 @@ class CloudStormService { ...@@ -202,7 +202,7 @@ 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":
......
...@@ -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)
......
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