Commit a059b890 authored by Spiros Koulouzis's avatar Spiros Koulouzis

fixed outputs to add values for all nodes

parent e34bbc8d
......@@ -30,3 +30,4 @@
/winery_service/src/winery/__pycache__/
/tosca_service/nbproject/private/
/tosca_service/src/winery/__pycache__/
/drip-deployer/venv/
\ No newline at end of file
......@@ -20,7 +20,7 @@ RUN pip install tosca-parser
RUN pip install pika
RUN export LC_ALL="en_US.UTF-8"
RUN pip install paramiko
RUN pip install ansible
RUN pip install ansible==2.7.0
......
This diff is collapsed.
......@@ -14,7 +14,7 @@ That way multiple projects can share the same settings (useful for formatting ru
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.6-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<netbeans.hint.licensePath>${project.basedir}/../licenseheader.txt</netbeans.hint.licensePath>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
</properties>
</project-shared-configuration>
......@@ -399,32 +399,12 @@ public class ProvisionService {
return null;
}
// private List<MessageParameter> buildDeployKeysParams(String keyID) {
// KeyPair key = keyPairService.findOne(keyID);
// if (key == null) {
// throw new BadRequestException("User key: " + keyID + " was not found");
// }
// List<MessageParameter> parameters = new ArrayList();
// MessageParameter keyParameter = new MessageParameter();
//
// keyParameter.setName("deployer_ssh_key");
//
// keyParameter.setValue(key.getPublicKey().getKey());
// keyParameter.setEncoding("UTF-8");
// parameters.add(keyParameter);
// return parameters;
// }
private ProvisionResponse parseCreateResourcesResponse(List<MessageParameter> parameters,
ProvisionRequest provisionRequest, ProvisionResponse provisionResponse, boolean saveUserKeys, boolean saveDeployerKeyI) throws Exception {
if (provisionResponse == null) {
provisionResponse = new ProvisionResponse();
}
// Map<String, Object> kvMap = null;
// KeyPair userKey = new KeyPair();
// KeyPair deployerKey = new KeyPair();
// Map<String, Key> privateCloudKeys = new HashMap<>();
// Map<String, Key> publicCloudKeys = new HashMap<>();
PlanResponse plan = addCloudCredentialsOnTOSCAPlan(provisionRequest);
Map<String, Object> toscaPlan = plan.getKeyValue();
Map<String, Object> topologyTemplate = (Map<String, Object>) ((Map<String, Object>) toscaPlan.get("topology_template"));
......@@ -456,19 +436,17 @@ public class ProvisionService {
String nodeName = nodeNames.get(i);
Map<String, Object> ipOutput = TOSCAUtils.buildTOSCAOutput(nodeName, deployIP);
Map<String, Object> roleOutput = TOSCAUtils.buildTOSCAOutput(nodeName, deployRole);
outputs.put("ip", ipOutput);
outputs.put("role", roleOutput);
Map<String, Object> properties = (Map<String, Object>) vmList.get(i).get("properties");
properties.put("user_name", deployUser);
outputs = TOSCAUtils.buildTOSCAOutput(outputs, nodeName, deployIP, "ip", false);
outputs = TOSCAUtils.buildTOSCAOutput(outputs, nodeName, deployUser, "user_name", false);
outputs = TOSCAUtils.buildTOSCAOutput(outputs, nodeName, deployRole, "role", false);
}
}
if (name.contains("_key")) {
for (String nodeName : nodeNames) {
Map<String, Object> keyOutput = TOSCAUtils.buildTOSCAOutput(nodeName, p.getValue());
outputs.put(name, keyOutput);
outputs = TOSCAUtils.buildTOSCAOutput(outputs, nodeName, p.getValue(), name, true);
}
}
}
......
......@@ -70,7 +70,6 @@ public class DeployController {
@RequestMapping(value = "/deploy", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 400, condition = "Empty manager type. Aveliable: ansible, swarm ,kubernetes"),
@ResponseCode(code = 400, condition = "Empty provision ID"),
@ResponseCode(code = 500, condition = "Deploymet failed"),
@ResponseCode(code = 200, condition = "Successful deploymet")
......@@ -78,9 +77,6 @@ public class DeployController {
public @ResponseBody
String deploy(@RequestBody DeployRequest deployRequest) {
try {
if (deployRequest.getManagerType() == null) {
throw new BadRequestException("Must provide manager type. Aveliable: ansible, swarm ,kubernetes");
}
if (deployRequest.getProvisionID() == null) {
throw new BadRequestException("Must provide provision ID");
}
......@@ -115,16 +111,6 @@ public class DeployController {
return null;
}
@RequestMapping(value = "/sample", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
DeployRequest sample() {
DeployRequest req = new DeployRequest();
req.setManagerType("ansible");
req.setConfigurationID("58e2681ba9961baa096c8541");
req.setProvisionID("58f8dd3a2af41387c32ff602");
return req;
}
/**
* Returns a deployment description
......@@ -144,10 +130,10 @@ public class DeployController {
try {
resp = deployService.findOne(id);
if (resp.getManagerType().equals("swarm")) {
Map<String, Object> swarmInfo = deployService.getSwarmInfo(resp);
resp.setManagerInfo(swarmInfo);
}
// if (resp.getManagerType().equals("swarm")) {
// Map<String, Object> swarmInfo = deployService.getSwarmInfo(resp);
// resp.setManagerInfo(swarmInfo);
// }
} catch (JSONException | IOException | TimeoutException | InterruptedException ex) {
Logger.getLogger(DeployController.class.getName()).log(Level.SEVERE, null, ex);
......
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.api.v1.rest;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.xml.namespace.QName;
import org.jvnet.ws.wadl.Application;
import org.jvnet.ws.wadl.Doc;
import org.jvnet.ws.wadl.Param;
import org.jvnet.ws.wadl.ParamStyle;
import org.jvnet.ws.wadl.Representation;
import org.jvnet.ws.wadl.Request;
import org.jvnet.ws.wadl.Resource;
import org.jvnet.ws.wadl.Resources;
import org.jvnet.ws.wadl.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
/**
*
* @author S. Koulouzis
*/
@Controller
@RequestMapping("/")
public class RootController {
String xs_namespace = "http://www.w3.org/2001/XMLSchema";
@Autowired
private RequestMappingHandlerMapping handlerMapping;
@Autowired
private WebApplicationContext webApplicationContext;
@RequestMapping(method = RequestMethod.GET,
// consumes = MediaType.APPLICATION_XML_VALUE,
produces = MediaType.APPLICATION_XML_VALUE)
public @ResponseBody
Application generateWadl(HttpServletRequest request, @RequestParam("wadl") String wadl) {
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = (String) headerNames.nextElement();
String value = request.getHeader(key);
}
Application result = new Application();
Doc doc = new Doc();
doc.setTitle("Spring REST Service WADL");
result.getDoc().add(doc);
Resources wadResources = new Resources();
wadResources.setBase(getBaseUrl(request));
Map<RequestMappingInfo, HandlerMethod> handletMethods = handlerMapping.getHandlerMethods();
for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : handletMethods.entrySet()) {
HandlerMethod handlerMethod = entry.getValue();
Object object = handlerMethod.getBean();
Object bean = webApplicationContext.getBean(object.toString());
boolean isRestContoller = bean.getClass().isAnnotationPresent(RestController.class);
if (bean.getClass().getName().contains("nl.uva.sne.drip.api.v1.rest")) {
isRestContoller = true;
}
if (!isRestContoller) {
continue;
}
RequestMappingInfo mappingInfo = entry.getKey();
Set<String> pattern = mappingInfo.getPatternsCondition().getPatterns();
Set<RequestMethod> httpMethods = mappingInfo.getMethodsCondition().getMethods();
ProducesRequestCondition producesRequestCondition = mappingInfo.getProducesCondition();
Set<MediaType> mediaTypes = producesRequestCondition.getProducibleMediaTypes();
Resource wadlResource = null;
for (RequestMethod httpMethod : httpMethods) {
org.jvnet.ws.wadl.Method wadlMethod = new org.jvnet.ws.wadl.Method();
for (String uri : pattern) {
wadlResource = createOrFind(uri, wadResources);
wadlResource.setPath(uri);
}
wadlMethod.setName(httpMethod.name());
Method javaMethod = handlerMethod.getMethod();
wadlMethod.setId(javaMethod.getName());
Doc wadlDocMethod = new Doc();
wadlDocMethod.setTitle(javaMethod.getDeclaringClass().getSimpleName() + "." + javaMethod.getName());
wadlMethod.getDoc().add(wadlDocMethod);
// Request
Request wadlRequest = new Request();
Annotation[][] annotations = javaMethod.getParameterAnnotations();
Class<?>[] paramTypes = javaMethod.getParameterTypes();
int i = 0;
for (Annotation[] annotation : annotations) {
Class<?> paramType = paramTypes[i];
i++;
for (Annotation annotation2 : annotation) {
if (annotation2 instanceof RequestParam) {
RequestParam param2 = (RequestParam) annotation2;
Param waldParam = new Param();
QName nm = convertJavaToXMLType(paramType);
waldParam.setName(param2.value());
waldParam.setStyle(ParamStyle.QUERY);
waldParam.setRequired(param2.required());
String defaultValue = cleanDefault(param2.defaultValue());
if (!defaultValue.equals("")) {
waldParam.setDefault(defaultValue);
}
waldParam.setType(nm);
wadlRequest.getParam().add(waldParam);
} else if (annotation2 instanceof PathVariable) {
PathVariable param2 = (PathVariable) annotation2;
QName nm = convertJavaToXMLType(paramType);
Param waldParam = new Param();
waldParam.setName(param2.value());
waldParam.setStyle(ParamStyle.TEMPLATE);
waldParam.setRequired(true);
wadlRequest.getParam().add(waldParam);
waldParam.setType(nm);
}
}
}
if (!wadlRequest.getParam().isEmpty()) {
wadlMethod.setRequest(wadlRequest);
}
// Response
if (!mediaTypes.isEmpty()) {
Response wadlResponse = new Response();
Class methodReturn = handlerMethod.getReturnType().getClass();
ResponseStatus status = handlerMethod.getMethodAnnotation(ResponseStatus.class);
if (status == null) {
wadlResponse.getStatus().add((long) (HttpStatus.OK.value()));
} else {
HttpStatus httpcode = status.value();
wadlResponse.getStatus().add((long) httpcode.value());
}
for (MediaType mediaType : mediaTypes) {
Representation wadlRepresentation = new Representation();
wadlRepresentation.setMediaType(mediaType.toString());
wadlResponse.getRepresentation().add(wadlRepresentation);
}
wadlMethod.getResponse().add(wadlResponse);
}
wadlResource.getMethodOrResource().add(wadlMethod);
}
}
result.getResources().add(wadResources);
return result;
}
private QName convertJavaToXMLType(Class<?> type) {
QName nm = new QName("");
String classname = type.toString();
if (classname.indexOf("String") >= 0) {
nm = new QName(xs_namespace, "string", "xs");
} else if (classname.indexOf("Integer") >= 0) {
nm = new QName(xs_namespace, "int", "xs");
}
return nm;
}
private Resource createOrFind(String uri, Resources wadResources) {
List<Resource> current = wadResources.getResource();
for (Resource resource : current) {
if (resource.getPath().equalsIgnoreCase(uri)) {
return resource;
}
}
Resource wadlResource = new Resource();
current.add(wadlResource);
return wadlResource;
}
//
private String getBaseUrl(HttpServletRequest request) {
String requestUri = request.getRequestURI();
return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + requestUri;
}
private String cleanDefault(String value) {
value = value.replaceAll("\t", "");
value = value.replaceAll("\n", "");
return value;
}
}
......@@ -16,6 +16,7 @@
package nl.uva.sne.drip.commons.utils;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
......@@ -60,14 +61,42 @@ public class TOSCAUtils {
return vmNames;
}
public static Map<String, Object> buildTOSCAOutput(String nodeName, String value) {
Map<String, Object> output = new HashMap();
Map<String, Object> outputValue = new HashMap();
List<String> att = new ArrayList<>();
att.add(nodeName);
att.add(value);
outputValue.put("get_attribute", att);
output.put("value", outputValue);
return output;
public static Map<String, Object> buildTOSCAOutput(Map<String, Object> outputs, String nodeName, String value, String key, boolean encodeValueToBas64) {
List<Map<String, String>> values;
if (outputs.containsKey(key)) {
values = (List<Map<String, String>>) outputs.get(key);
} else {
values = new ArrayList<>();
}
if (encodeValueToBas64) {
value = Base64.getEncoder().encodeToString(value.getBytes());
}
Map<String, String> map = new HashMap<>();
map.put(nodeName, value);
values.add(map);
outputs.put(key, values);
return outputs;
}
public static Map<String, Object> getOutputsForNode(Map<String, Object> toscaProvisonMap, String nodeName) {
Map<String, Object> topologyTemplate = (Map<String, Object>) ((Map<String, Object>) toscaProvisonMap.get("topology_template"));
Map<String, Object> outputs = (Map<String, Object>) topologyTemplate.get("outputs");
Map<String, Object> matchedOutputs = new HashMap<>();
Iterator it = outputs.entrySet().iterator();
while (it.hasNext()) {
Map.Entry output = (Map.Entry) it.next();
Map<String, Object> outputValue = (Map<String, Object>) output.getValue();
Map<String, Object> val = (Map<String, Object>) outputValue.get("value");
List<String> attribute = (List<String>) val.get("get_attribute");
if (attribute.get(0).equals(nodeName)) {
matchedOutputs.put((String) output.getKey(), outputValue);
}
}
return matchedOutputs;
}
public static List<String> getOutputPair(Map<String, Object> outputs, String key) {
List<String> outputPair = (List<String>) ((Map<String, Object>) ((Map<String, Object>) outputs.get(key)).get("value")).get("get_attribute");
return outputPair;
}
}
......@@ -36,23 +36,6 @@ public class DeployParameter {
private String user;
private String role;
// /**
// * The file name of the certificate used to log in as root to the
// * provisioned VM.
// * @return the cloudCertificateName
// */
// @DocumentationExample("Virginia")
// public String getCloudCertificateName() {
// return cloudCertificateName;
// }
//
// /**
// * @param cloudCertificateName the cloudCertificateName to set
// */
// public void setCloudCertificateName(String cloudCertificateName) {
// this.cloudCertificateName = cloudCertificateName;
// }
/**
* The public IP of the provisioned VM
* @return the IP
......
......@@ -28,8 +28,8 @@ import com.webcohesion.enunciate.metadata.DocumentationExample;
public class DeployRequest extends OwnedObject {
private String provisionID;
private String managerType;
private String configurationID;
// private String managerType;
// private String configurationID;
/**
* The ID of the provision resources description <code>ProvisionResponse</code>
......@@ -46,39 +46,4 @@ public class DeployRequest extends OwnedObject {
public void setProvisionID(String provisionID) {
this.provisionID = provisionID;
}
/**
* The type of deployment manager to be used (swarm, ansile, kubernetes)
* @return the managerType
*/
@DocumentationExample("ansible")
public String getManagerType() {
return managerType;
}
/**
* @param managerType the managerType to set
*/
public void setManagerType(String managerType) {
this.managerType = managerType;
}
/**
* The ID of the configuration POJO that contains information used the
* chosen deployment manager (for now only ansible)
* <code>PlaybookRepresentation</code>
* @return the configurationID
*/
@DocumentationExample("58e3946e0fb4f562d84ba1ad")
public String getConfigurationID() {
return configurationID;
}
/**
* @param configurationID the configurationID to set
*/
public void setConfigurationID(String configurationID) {
this.configurationID = configurationID;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 2.7 (drip-deployer)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7 (drip-deployer)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
......@@ -19,7 +19,7 @@ __author__ = 'Yang Hu'
import paramiko, os
import logging
from drip_logging.drip_logging_handler import *
# from drip_logging.drip_logging_handler import *
logger = logging.getLogger(__name__)
......
......@@ -25,7 +25,7 @@ import linecache
import sys
import ast
import re
from drip_logging.drip_logging_handler import *
# from drip_logging.drip_logging_handler import *
logger = logging.getLogger(__name__)
if not getattr(logger, 'handler_set', None):
......
......@@ -20,7 +20,7 @@ __author__ = 'Yang Hu'
import paramiko, os
from vm_info import VmInfo
import logging
from drip_logging.drip_logging_handler import *
# from drip_logging.drip_logging_handler import *
logger = logging.getLogger(__name__)
......
......@@ -20,7 +20,7 @@ __author__ = 'Yang Hu'
import paramiko, os
import threading
import logging
from drip_logging.drip_logging_handler import *
# from drip_logging.drip_logging_handler import *
import multiprocessing
logger = logging.getLogger(__name__)
......
......@@ -21,7 +21,7 @@ from vm_info import VmInfo
import linecache
import sys
import logging
from drip_logging.drip_logging_handler import *
# from drip_logging.drip_logging_handler import *
logger = logging.getLogger(__name__)
......@@ -123,8 +123,8 @@ def install_worker(join_cmd, vm):
return "SUCCESS"
def run(vm_list,rabbitmq_host,owner):
rabbit = DRIPLoggingHandler(host=rabbitmq_host, port=5672,user=owner)
logger.addHandler(rabbit)
# rabbit = DRIPLoggingHandler(host=rabbitmq_host, port=5672,user=owner)
# logger.addHandler(rabbit)
for i in vm_list:
if i.role == "master":
join_cmd = install_manager(i)
......
......@@ -20,7 +20,7 @@ __author__ = 'Yang Hu'
import paramiko, os
from vm_info import VmInfo
import logging
from drip_logging.drip_logging_handler import *
# from drip_logging.drip_logging_handler import *
import multiprocessing
logger = logging.getLogger(__name__)
......
......@@ -20,7 +20,7 @@ __author__ = 'Yang Hu'
import paramiko, os
from vm_info import VmInfo
import logging
from drip_logging.drip_logging_handler import *
# from drip_logging.drip_logging_handler import *
import multiprocessing
......
......@@ -11,7 +11,7 @@ import docker_compose
import docker_service
import docker_check
import control_agent
import ansible_playbook
# import ansible_playbook
import sys, argparse
from threading import Thread
from time import sleep
......
......@@ -269,19 +269,19 @@ public class Consumer extends DefaultConsumer {
File clusterDir = new File(tempInputDirPath + File.separator + "clusterKeyPair");
clusterDir.mkdir();
List<File> public_deployer_key = MessageParsing.getSSHKeys(parameters, clusterDir.getAbsolutePath(), "id_rsa.pub", "public_deployer_key");
List<File> private_deployer_key = MessageParsing.getSSHKeys(parameters, clusterDir.getAbsolutePath(), "id_rsa", "private_deployer_key");
// List<File> public_deployer_key = MessageParsing.getSSHKeys(parameters, clusterDir.getAbsolutePath(), "id_rsa.pub", "public_deployer_key");
// List<File> private_deployer_key = MessageParsing.getSSHKeys(parameters, clusterDir.getAbsolutePath(), "id_rsa", "private_deployer_key");
Map<String, Object> map = MessageParsing.ymlStream2Map(new FileInputStream(topTopologyLoadingPath));
String userPublicKeyName = ((String) map.get("publicKeyPath")).split("@")[1].replaceAll("\"", "");
String userPrivateName = FilenameUtils.removeExtension(userPublicKeyName);
List<File> public_user_key = MessageParsing.getSSHKeys(parameters, tempInputDirPath + File.separator, userPublicKeyName, "public_user_key");
// List<File> public_user_key = MessageParsing.getSSHKeys(parameters, tempInputDirPath + File.separator, userPublicKeyName, "public_user_key");
List<File> private_user_key = MessageParsing.getSSHKeys(parameters, tempInputDirPath + File.separator, "id_rsa", "private_user_key");
FileUtils.moveFile(private_user_key.get(0), new File(private_user_key.get(0).getParent() + File.separator + userPrivateName));
List<File> public_cloud_key = MessageParsing.getSSHKeys(parameters, tempInputDirPath + File.separator, "name.pub", "public_cloud_key");
List<File> private_cloud_key = MessageParsing.getSSHKeys(parameters, tempInputDirPath + File.separator, "id_rsa", "private_cloud_key");
// List<File> public_cloud_key = MessageParsing.getSSHKeys(parameters, tempInputDirPath + File.separator, "name.pub", "public_cloud_key");
// List<File> private_cloud_key = MessageParsing.getSSHKeys(parameters, tempInputDirPath + File.separator, "id_rsa", "private_cloud_key");
UserCredential userCredential = getUserCredential(parameters, tempInputDirPath);
UserDatabase userDatabase = getUserDB();
......
......@@ -2,8 +2,28 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="slolved cap error">
<change beforePath="$PROJECT_DIR$/../Dockerfiles/deployer/Dockerfile" beforeDir="false" afterPath="$PROJECT_DIR$/../Dockerfiles/deployer/Dockerfile" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/nb-configuration.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-api/nb-configuration.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/DeployService.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/DeployService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/ProvisionService.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/service/ProvisionService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/DeployController.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/DeployController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/RootController.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/TOSCAUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/TOSCAUtils.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/data/v1/external/DeployParameter.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/data/v1/external/DeployParameter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/data/v1/external/DeployRequest.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/data/v1/external/DeployRequest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-deployer/.idea/drip-deployer.iml" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/.idea/drip-deployer.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-deployer/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-deployer/control_agent.py" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/control_agent.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-deployer/docker_check.py" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/docker_check.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-deployer/docker_compose.py" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/docker_compose.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-deployer/docker_engine.py" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/docker_engine.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-deployer/docker_kubernetes.py" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/docker_kubernetes.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-deployer/docker_service.py" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/docker_service.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-deployer/docker_swarm.py" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/docker_swarm.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-deployer/rpc_server.py" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-deployer/rpc_server.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/v1/Consumer.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/v1/Consumer.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/planner/basic_planner.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/basic_planner.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/easy-install.pth" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/prettytable.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/pyparsing.py" beforeDir="false" />
......@@ -153,11 +173,6 @@
<line>64</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/planner/basic_planner.py</url>
<line>103</line>
<option name="timeStamp" value="2" />
</line-breakpoint>
</breakpoints>
<default-breakpoints>
<breakpoint type="python-exception">
......
......@@ -74,6 +74,13 @@ def fill_in_properties(nodetemplate_dict):
nodetemplate_dict = set_VM_properties(nodetemplate_dict)
return nodetemplate_dict
def fix_occurrences(node_templates):
# Replace 'occurrences': [1, 'UNBOUNDED'] with 'occurrences': 1
for node in node_templates:
for req in node.requirements:
if 'occurrences' in req[next(iter(req))]:
req[next(iter(req))].pop('occurrences')
return node_templates
def node_type_2_node_template(node_type):
nodetemplate_dict = {}
......@@ -97,6 +104,40 @@ def node_type_2_node_template(node_type):
return NodeTemplate(name, nodetemplate_dict, node_type)
def contains_node_type(capable_node_types_list, node_type):
if capable_node_types_list == None:
return False
for capable_node_type in capable_node_types_list:
if isinstance(capable_node_type, NodeTemplate):
type_name = capable_node_type.type
elif isinstance(capable_node_type, dict):
type_name = next(iter(capable_node_type))
if type_name == node_type:
return True
return False
def get_requirement_occurrences(req):
if 'occurrences' in req:
return req['occurrences']
return None
def fix_duplicate_vm_names(yaml_str):
topology_dict = yaml.load(yaml_str)
node_templates = topology_dict['tosca_template']['node_templates']
vm_names = []
for node_name in node_templates:
if node_templates[node_name]['type'] == 'tosca.nodes.ARTICONF.VM.Compute':
vm_names.append(node_name)
for node_name in node_templates:
if node_templates[node_name]['type'] == 'tosca.nodes.ARTICONF.VM.topology':
i=0
for req in node_templates[node_name]['requirements']:
req['vm']['node'] = vm_names[i]
i+=1
return yaml.dump(topology_dict)
class BasicPlanner:
def __init__(self, path):
......@@ -112,17 +153,13 @@ class BasicPlanner:
node_templates = self.add_reqired_nods(node, None)
if node_templates:
# Replace 'occurrences': [1, 'UNBOUNDED'] with 'occurrences': 1
for node in node_templates:
for req in node.requirements:
if 'occurrences' in req[next(iter(req))]:
req[next(iter(req))].pop('occurrences')
node_templates = fix_occurrences(node_templates)
self.template.nodetemplates = node_templates
else:
logging.info('The TOSCA template in: ' + path + ' has no requirements')
tp = TOSCAParser()
yaml_str = tp.tosca_template2_yaml(self.template)
yaml_str = fix_duplicate_vm_names(yaml_str)
yaml_str = yaml_str.replace('tosca_definitions_version: tosca_simple_yaml_1_0', '')
yaml_str = yaml_str.replace('description: TOSCA example', '')
yaml_str = yaml_str.replace('tosca_template', 'topology_template')
......@@ -187,8 +224,7 @@ class BasicPlanner:
# Only return the nodes that have interfaces. This means that they are not "abstract"
for candidate_node_name in candidate_nodes:
if 'interfaces' in candidate_nodes[
candidate_node_name].keys() and 'tosca.nodes.Root' != candidate_node_name:
if 'interfaces' in candidate_nodes[candidate_node_name].keys() and 'tosca.nodes.Root' != candidate_node_name:
capable_nodes[candidate_node_name] = candidate_nodes[candidate_node_name]
return capable_nodes
......@@ -211,23 +247,6 @@ class BasicPlanner:
else:
return False
def contains_node_type(self, capable_node_types_list, node_type):
if capable_node_types_list == None:
return False
for capable_node_type in capable_node_types_list:
if isinstance(capable_node_type, NodeTemplate):
type_name = capable_node_type.type
elif isinstance(capable_node_type, dict):
type_name = next(iter(capable_node_type))
if type_name == node_type:
return True
return False
def get_requirement_occurrences(self, req):
if 'occurrences' in req:
return req['occurrences']
return None
def get_optimal_num_of_occurrences(self, node_type, min_max_occurrences):
max_occurrences = -1
min_occurrences = -1
......@@ -255,7 +274,7 @@ class BasicPlanner:
min_max_occurrences = []
for req in missing_requirements:
for key in req:
min_max_occurrences = self.get_requirement_occurrences(req[key])
min_max_occurrences = get_requirement_occurrences(req[key])
logging.info('Looking for capability: ' + req[key]['capability'] + ' for node: ' + node.name)
capable_node = self.get_node_types_by_capability(req[key]['capability'])
if capable_node:
......@@ -265,7 +284,7 @@ class BasicPlanner:
logging.error('Did not find node with reuired capability: ' + str(req[key]['capability']))
occurrences = self.get_optimal_num_of_occurrences(capable_node_type, min_max_occurrences)
if not self.contains_node_type(node_templates, capable_node_type) and occurrences == 1:
if not contains_node_type(node_templates, capable_node_type) and occurrences == 1:
capable_node_template = node_type_2_node_template(capable_node)
capable_node_name = capable_node_template.name
node_templates.append(capable_node_template)
......@@ -285,7 +304,7 @@ class BasicPlanner:
req[next(iter(req))]['node'] = capable_node_name
node.requirements.append(req)
if not self.contains_node_type(node_templates, node):
if not contains_node_type(node_templates, node):
node_templates.append(node)
return node_templates
......
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