Commit e2ec6617 authored by Spiros Koulouzis's avatar Spiros Koulouzis

set timeout

parent 6e2537d0
...@@ -15,11 +15,21 @@ ...@@ -15,11 +15,21 @@
*/ */
package nl.uva.sne.drip.commons.utils; package nl.uva.sne.drip.commons.utils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.web.multipart.MultipartFile;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
/** /**
...@@ -51,4 +61,37 @@ public class Converter { ...@@ -51,4 +61,37 @@ public class Converter {
return (Map<String, Object>) object; return (Map<String, Object>) object;
} }
public static String encodeFileToBase64Binary(String fileName) throws IOException {
return encode2Bas64(Files.readAllBytes(Paths.get(fileName)));
}
public static void decodeBase64BToFile(String base64, String fileName) throws IOException {
byte[] decodedBytrs = Base64.getDecoder().decode(base64);
Files.write(Paths.get(fileName), decodedBytrs);
}
public static String getFileMD5(String filePath) throws NoSuchAlgorithmException, IOException {
MessageDigest md = MessageDigest.getInstance("MD5");
String keyStoreContents = new String(Files.readAllBytes(Paths.get(filePath)));
md.update(keyStoreContents.getBytes());
byte[] digest = md.digest();
return new String(digest, StandardCharsets.UTF_8);
}
public static String encodeFileToBase64Binary(MultipartFile file) throws IOException {
String originalFileName = file.getOriginalFilename();
String name = System.currentTimeMillis() + "_" + originalFileName;
byte[] bytes = file.getBytes();
return encode2Bas64(bytes);
}
private static String encode2Bas64(byte[] bytes) {
byte[] encodedBytes = Base64.getEncoder().encode(bytes);
return new String(encodedBytes, StandardCharsets.UTF_8);
}
} }
...@@ -68,7 +68,10 @@ public class ToscaHelper { ...@@ -68,7 +68,10 @@ public class ToscaHelper {
private void init(String sureToscaBasePath) { private void init(String sureToscaBasePath) {
Configuration.getDefaultApiClient().setBasePath(sureToscaBasePath); Configuration.getDefaultApiClient().setBasePath(sureToscaBasePath);
Configuration.getDefaultApiClient().setConnectTimeout(1200000);
api = new DefaultApi(Configuration.getDefaultApiClient()); api = new DefaultApi(Configuration.getDefaultApiClient());
System.err.println("ConnectTimeout: " + api.getApiClient().getConnectTimeout());
this.objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)); this.objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
...@@ -186,14 +189,7 @@ public class ToscaHelper { ...@@ -186,14 +189,7 @@ public class ToscaHelper {
if (att == null) { if (att == null) {
att = new HashMap<>(); att = new HashMap<>();
} }
Map<String, Object> toscaCredential = new HashMap<>(); att.put("credential", credential);
toscaCredential.put("protocol", credential.getProtocol());
toscaCredential.put("token_type", credential.getTokenType());
toscaCredential.put("token", credential.getToken());
toscaCredential.put("keys", credential.getKeys());
toscaCredential.put("user", credential.getUser());
toscaCredential.put("cloud_provider_name", credential.getCloudProviderName());
att.put("credential", toscaCredential);
vmTopology.setAttributes(att); vmTopology.setAttributes(att);
vmTopologyMap.setNodeTemplate(vmTopology); vmTopologyMap.setNodeTemplate(vmTopology);
return vmTopologyMap; return vmTopologyMap;
......
...@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
import nl.uva.sne.drip.model.tosca.Credential; import nl.uva.sne.drip.model.tosca.Credential;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z")
......
...@@ -3,6 +3,7 @@ package nl.uva.sne.drip.api; ...@@ -3,6 +3,7 @@ package nl.uva.sne.drip.api;
import nl.uva.sne.drip.model.tosca.Credential; import nl.uva.sne.drip.model.tosca.Credential;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import java.io.IOException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -12,8 +13,11 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -12,8 +13,11 @@ import org.springframework.web.bind.annotation.RequestBody;
import javax.validation.Valid; import javax.validation.Valid;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.service.CredentialService; import nl.uva.sne.drip.service.CredentialService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-10T17:15:46.465Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-10T17:15:46.465Z")
...@@ -56,5 +60,4 @@ public class CredentialApiController implements CredentialApi { ...@@ -56,5 +60,4 @@ public class CredentialApiController implements CredentialApi {
} }
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
} }
} }
...@@ -7,19 +7,10 @@ package nl.uva.sne.drip.api; ...@@ -7,19 +7,10 @@ package nl.uva.sne.drip.api;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-12-06T13:31:49.386Z")
@Api(value = "deployer", description = "the deployer API") @Api(value = "deployer", description = "the deployer API")
...@@ -27,18 +18,22 @@ public interface DeployerApi { ...@@ -27,18 +18,22 @@ public interface DeployerApi {
@ApiOperation(value = "deploy the software tosca template", nickname = "deployProvisionToscaTemplateByID", notes = "Returns the deployment ID", response = String.class, authorizations = { @ApiOperation(value = "deploy the software tosca template", nickname = "deployProvisionToscaTemplateByID", notes = "Returns the deployment ID", response = String.class, authorizations = {
@Authorization(value = "auth", scopes = { @Authorization(value = "auth", scopes = {
@AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template"), @AuthorizationScope(scope = "read:ToscaTemplate", description = "read your topolog template")
,
@AuthorizationScope(scope = "write:ToscaTemplate", description = "modify topolog template in your account") @AuthorizationScope(scope = "write:ToscaTemplate", description = "modify topolog template in your account")
}) })
}, tags={ }) }, tags = {})
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class), @ApiResponse(code = 200, message = "successful operation", response = String.class)
@ApiResponse(code = 400, message = "Invalid ID supplied"), ,
@ApiResponse(code = 404, message = "ToscaTemplate not found"), @ApiResponse(code = 400, message = "Invalid ID supplied")
@ApiResponse(code = 405, message = "Invalid input") }) ,
@ApiResponse(code = 404, message = "ToscaTemplate not found")
,
@ApiResponse(code = 405, message = "Invalid input")})
@RequestMapping(value = "/deployer/deploy/{id}", @RequestMapping(value = "/deployer/deploy/{id}",
produces = { "text/plain" }, produces = {"text/plain"},
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<String> deployProvisionToscaTemplateByID(@ApiParam(value = "ID of topolog template to deploy",required=true) @PathVariable("id") String id); ResponseEntity<String> deployProvisionToscaTemplateByID(@ApiParam(value = "ID of topolog template to deploy", required = true) @PathVariable("id") String id);
} }
...@@ -28,20 +28,17 @@ import java.io.File; ...@@ -28,20 +28,17 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.xml.bind.DatatypeConverter;
import nl.uva.sne.drip.Swagger2SpringBoot; import nl.uva.sne.drip.Swagger2SpringBoot;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.configuration.MongoConfig; import nl.uva.sne.drip.configuration.MongoConfig;
import nl.uva.sne.drip.model.cloud.storm.CloudDB;
import nl.uva.sne.drip.model.tosca.Credential; import nl.uva.sne.drip.model.tosca.Credential;
import org.junit.Assert; import org.junit.Assert;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
...@@ -274,19 +271,10 @@ public class ServiceTests { ...@@ -274,19 +271,10 @@ public class ServiceTests {
@Test @Test
public void testCredentialService() throws IOException, NoSuchAlgorithmException { public void testCredentialService() throws IOException, NoSuchAlgorithmException {
Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "testCredentialService"); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "testCredentialService");
MessageDigest md = MessageDigest.getInstance("MD5"); String keyStoreEncoded = Converter.encodeFileToBase64Binary(testCredentialPath);
md.update(Files.readAllBytes(Paths.get(testCredentialPath)));
byte[] digest = md.digest();
String fileChecksum = DatatypeConverter
.printHexBinary(digest).toUpperCase();
String keyStore = new String(Files.readAllBytes(Paths.get(testCredentialPath)));
byte[] encodedBytes = Base64.getEncoder().encode(keyStore.getBytes());
String keyStoreEncoded = new String(encodedBytes, "UTF-8");
Credential credential = new Credential(); Credential credential = new Credential();
credential.setCloudProviderName("exogeni"); credential.setCloudProviderName("ExoGENI");
Map<String, String> keys = new HashMap<>(); Map<String, String> keys = new HashMap<>();
keys.put("keystore", keyStoreEncoded); keys.put("keystore", keyStoreEncoded);
credential.setKeys(keys); credential.setKeys(keys);
...@@ -294,28 +282,16 @@ public class ServiceTests { ...@@ -294,28 +282,16 @@ public class ServiceTests {
credential.setTokenType("password"); credential.setTokenType("password");
credential.setUser("user"); credential.setUser("user");
byte[] decodedBytes = Base64.getDecoder().decode(keys.get("keystore")); String keyStoreEncodedFromCredential = credential.getKeys().get("keystore");
md = MessageDigest.getInstance("MD5"); assertEquals(keyStoreEncoded, keyStoreEncodedFromCredential);
md.update(decodedBytes);
digest = md.digest();
String credentialChecksum = DatatypeConverter
.printHexBinary(digest).toUpperCase();
assertEquals(fileChecksum, credentialChecksum);
HashMap<Object, Object> att = new HashMap<>();
Map<String, Object> toscaCredential = new HashMap<>();
toscaCredential.put("protocol", credential.getProtocol());
toscaCredential.put("token_type", credential.getTokenType());
toscaCredential.put("token", credential.getToken());
toscaCredential.put("keys", credential.getKeys());
toscaCredential.put("user", credential.getUser());
toscaCredential.put("cloud_provider_name", credential.getCloudProviderName());
att.put("credential", toscaCredential);
String copyTestCredentialPath = ".." + File.separator + "fake_credentials" + File.separator + "copy_of_test-geni.jks";
Converter.decodeBase64BToFile(keyStoreEncodedFromCredential, copyTestCredentialPath);
String keystorFileChecksum = Converter.getFileMD5(testCredentialPath);
String keystorFileCopyChecksum = Converter.getFileMD5(copyTestCredentialPath);
assertEquals(keystorFileChecksum, keystorFileCopyChecksum);
} }
public String saveCredential() { public String saveCredential() {
...@@ -354,6 +330,7 @@ public class ServiceTests { ...@@ -354,6 +330,7 @@ public class ServiceTests {
credentialService.deleteByID(id); credentialService.deleteByID(id);
try { try {
Credential res = credentialService.findByID(id); Credential res = credentialService.findByID(id);
assertNotNull(res);
} catch (Exception ex) { } catch (Exception ex) {
if (!(ex instanceof NoSuchElementException)) { if (!(ex instanceof NoSuchElementException)) {
fail(ex.getMessage()); fail(ex.getMessage());
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e478ccae-5352-4e8e-9efb-3f5cda44e877" name="Default Changelist" comment="" /> <list default="true" id="e478ccae-5352-4e8e-9efb-3f5cda44e877" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/CredentialApi.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/CredentialApi.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/CredentialApiController.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/CredentialApiController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/DeployerApi.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/DeployerApi.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/test/java/nl/uva/sne/drip/service/ServiceTests.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/test/java/nl/uva/sne/drip/service/ServiceTests.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../openAPI/API/CONF-3.0.0-swagger.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../openAPI/API/CONF-3.0.0-swagger.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/service/tosca_template_service.py" beforeDir="false" afterPath="$PROJECT_DIR$/../sure_tosca-flask-server/sure_tosca/service/tosca_template_service.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
......
...@@ -234,6 +234,29 @@ paths: ...@@ -234,6 +234,29 @@ paths:
- read:ToscaTemplate - read:ToscaTemplate
/credential: /credential:
post: post:
summary: get credential key file as base64
description: get credential key file as base64
operationId: getFileasBase64
consumes:
- multipart/form-data
parameters:
- name: file
in: formData
description: credential key file
required: true
type: file
responses:
"200":
description: successful operation
schema:
type: string
"405":
description: Invalid input
security:
- auth:
- write:ToscaTemplate
- read:ToscaTemplate
put:
summary: Create credentials summary: Create credentials
description: Creates credentials description: Creates credentials
operationId: createCredentials operationId: createCredentials
...@@ -247,7 +270,7 @@ paths: ...@@ -247,7 +270,7 @@ paths:
description: Created user object description: Created user object
required: true required: true
schema: schema:
$ref: '#/definitions/Credentials' $ref: '#/definitions/Credential'
responses: responses:
"200": "200":
description: successful operation description: successful operation
...@@ -458,23 +481,29 @@ definitions: ...@@ -458,23 +481,29 @@ definitions:
type: integer type: integer
format: int32 format: int32
description: User Status description: User Status
Credentials: Credential:
type: object type: object
properties: properties:
protocol: protocol:
type: string type: string
description: The optional protocol name. e.g. http,xauth,oauth2,ssh
token_type: token_type:
type: string type: string
description: 'The required token type. default: password. e.g. basic_auth,X-Auth-Token, bearer, identifier'
token: token:
type: string type: string
description: The required token used as a credential for authorization or access to a networked resource. e.g. mypassword, myusername:mypassword, 604bbe45ac7143a79e14f3158df67091, keypair_id
keys: keys:
type: object type: object
description: The optional list of protocol-specific keys or assertions.
additionalProperties: additionalProperties:
type: string type: string
user: user:
type: string type: string
description: The optional user (name or ID) used for non-token based credentials.
cloud_provider_name: cloud_provider_name:
type: string type: string
description: The cloud provider name e.g. ec2.
NodeTemplate: NodeTemplate:
type: object type: object
properties: properties:
...@@ -661,19 +690,14 @@ definitions: ...@@ -661,19 +690,14 @@ definitions:
type: array type: array
items: items:
$ref: '#/definitions/CloudDB' $ref: '#/definitions/CloudDB'
CloudDB:
type: object
properties:
cloudProvider:
type: string
dbInfoFile:
type: string
DBInfo: DBInfo:
type: object type: object
properties: properties:
GlobalEntry: GlobalEntry:
type: string type: string
DCMetaInfo: DCMetaInfo:
type: array
items:
$ref: '#/definitions/DCMetaInfo' $ref: '#/definitions/DCMetaInfo'
DCMetaInfo: DCMetaInfo:
type: object type: object
...@@ -691,6 +715,8 @@ definitions: ...@@ -691,6 +715,8 @@ definitions:
availability: availability:
type: string type: string
VMMetaInfo: VMMetaInfo:
type: array
items:
$ref: '#/definitions/VMMetaInfo' $ref: '#/definitions/VMMetaInfo'
extraInfo: extraInfo:
type: object type: object
...@@ -706,6 +732,8 @@ definitions: ...@@ -706,6 +732,8 @@ definitions:
type: string type: string
MEM: MEM:
type: string type: string
VMType:
type: string
Price: Price:
type: string type: string
DefaultSSHAccount: DefaultSSHAccount:
...@@ -717,6 +745,67 @@ definitions: ...@@ -717,6 +745,67 @@ definitions:
additionalProperties: additionalProperties:
type: object type: object
properties: {} properties: {}
CloudsStormVMs:
type: object
properties:
VMs:
type: array
items:
$ref: '#/definitions/CloudsStormVM'
CloudCredentialDB:
type: object
properties:
cloudCreds:
type: array
items:
$ref: '#/definitions/CloudCred'
CredentialInfo:
type: object
properties:
userKeyName:
type: string
keyAlias:
type: string
keyPassword:
type: string
proxyFileName:
type: string
trustedCertDirName:
type: string
accessKey:
type: string
secretKey:
type: string
NodeTemplateMap:
type: object
properties:
name:
type: string
nodeTemplate:
$ref: '#/definitions/NodeTemplate'
Provisioner:
type: object
properties:
name:
type: string
version:
type: string
description:
type: string
tosca_interface_type:
type: string
CloudsStormInfrasCode:
type: object
properties:
Mode:
type: string
enum:
- LOCAL
- CTRL
InfrasCodes:
type: array
items:
$ref: '#/definitions/InfrasCode'
CloudsStormSubTopology: CloudsStormSubTopology:
type: object type: object
properties: properties:
...@@ -728,6 +817,12 @@ definitions: ...@@ -728,6 +817,12 @@ definitions:
type: string type: string
status: status:
type: string type: string
enum:
- fresh
- running
- deleted
- failed
- stopped
CloudsStormSubnets: CloudsStormSubnets:
type: object type: object
properties: properties:
...@@ -748,3 +843,82 @@ definitions: ...@@ -748,3 +843,82 @@ definitions:
type: string type: string
address: address:
type: string type: string
CloudDB:
type: object
properties:
cloudProvider:
type: string
enum:
- EC2
- ExoGENI
- EGI
dbInfoFile:
type: string
CloudsStormVM:
type: object
properties:
name:
type: string
nodeType:
type: string
OStype:
type: string
script:
type: string
publicAddress:
type: string
CloudCred:
type: object
properties:
cloudProvider:
type: string
credInfoFile:
type: string
InfrasCode:
type: object
properties:
CodeType:
type: string
enum:
- SEQ
- LOOP
OpCode:
$ref: '#/definitions/OpCode'
Count:
type: integer
OpCode:
type: object
properties:
Operation:
type: string
enum:
- provision
- delete
- execute
- put
- get
- vscale
- hscale
- recover
- start
ObjectType:
type: string
enum:
- SubTopology
- VM
- REQ
Objects:
type: string
Command:
type: string
Log:
type: boolean
Options:
$ref: '#/definitions/Options'
Options:
type: object
properties:
Src:
type: string
Dst:
type: string
...@@ -2,6 +2,7 @@ import json ...@@ -2,6 +2,7 @@ import json
import logging import logging
import os import os
import tempfile import tempfile
import time
import uuid import uuid
from builtins import print from builtins import print
from functools import reduce from functools import reduce
...@@ -31,6 +32,15 @@ node_template_db = TinyDB(storage=CachingMiddleware(MemoryStorage)) ...@@ -31,6 +32,15 @@ node_template_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
dsl_definitions_db = TinyDB(storage=CachingMiddleware(MemoryStorage)) dsl_definitions_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
relationship_template_db = TinyDB(storage=CachingMiddleware(MemoryStorage)) relationship_template_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
interface_types_db = TinyDB(storage=CachingMiddleware(MemoryStorage)) interface_types_db = TinyDB(storage=CachingMiddleware(MemoryStorage))
logger = logging.getLogger(__name__)
if not getattr(logger, 'handler_set', None):
logger.setLevel(logging.INFO)
h = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
h.setFormatter(formatter)
logger.addHandler(h)
logger.handler_set = True
root_key = 'root_key' root_key = 'root_key'
...@@ -50,7 +60,7 @@ def query_db(queries, db=None): ...@@ -50,7 +60,7 @@ def query_db(queries, db=None):
res_copy.pop(root_key) res_copy.pop(root_key)
node = {key: res_copy} node = {key: res_copy}
else: else:
logging.error(str(res) + ' has no ' + root_key) logger.error(str(res) + ' has no ' + root_key)
updated_results.append(node) updated_results.append(node)
return updated_results return updated_results
return None return None
...@@ -90,17 +100,27 @@ def purge_all_tables(): ...@@ -90,17 +100,27 @@ def purge_all_tables():
def save(file): def save(file):
# try: # try:
# tosca_template_file_path = os.path.join(db_dir_path, file.filename) # tosca_template_file_path = os.path.join(db_dir_path, file.filename)
start = time.time()
logger.info("Got request for tosca template")
purge_all_tables() purge_all_tables()
dictionary = yaml.safe_load(file.stream) dictionary = yaml.safe_load(file.stream)
print(yaml.dump(dictionary)) logger.info("tosca template: \n" + str(yaml.dump(dictionary)))
# print(yaml.dump(dictionary))
tosca_template = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(dictionary)) tosca_template = ToscaTemplate(yaml_dict_tpl=copy.deepcopy(dictionary))
# all_custom_def = tosca_template.nodetemplates[0].custom_def # all_custom_def = tosca_template.nodetemplates[0].custom_def
tosca_template_model = ToscaTemplateModel.from_dict(dictionary) tosca_template_model = ToscaTemplateModel.from_dict(dictionary)
doc_id = tosca_templates_db.insert(dictionary) doc_id = tosca_templates_db.insert(dictionary)
# tosca_templates_db.close() # tosca_templates_db.close()
logger.info("Returning doc_id: " + str(doc_id))
end = time.time()
elapsed = end - start
logger.info("Time elapsed: " + str(elapsed))
return doc_id return doc_id
# except Exception as e: # except Exception as e:
# logging.error(str(e)) # logger.error(str(e))
# return str(e), 400 # return str(e), 400
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment