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>
......@@ -132,7 +131,19 @@
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<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>
......@@ -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;
}
......
......@@ -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();
......
......@@ -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,10 +202,10 @@ class CloudStormService {
}
private CredentialInfo getCloudStormCredentialInfo(Credential toscaCredentials) throws FileNotFoundException {
CredentialInfo cloudStormCredentialInfo = new CredentialInfo();
CredentialInfo cloudStormCredentialInfo = new CredentialInfo();
switch (toscaCredentials.getCloudProviderName().toLowerCase()) {
case "exogeni":
String base64Keystore = toscaCredentials.getKeys().get("keystore");
byte[] decoded = Base64.getDecoder().decode(base64Keystore);
try (PrintWriter out = new PrintWriter("user.jks")) {
......@@ -217,7 +217,7 @@ CredentialInfo cloudStormCredentialInfo = new CredentialInfo();
return cloudStormCredentialInfo;
case "ec2":
// cloudStormCredentialInfo.setAccessKey(toscaCredentials.get);
return cloudStormCredentialInfo;
return cloudStormCredentialInfo;
}
return null;
......
......@@ -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)
......
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