Commit 9b8e422c authored by Spiros Koulouzis's avatar Spiros Koulouzis

use states to manipulate nodes

parent 9f91e794
...@@ -162,6 +162,26 @@ node_types: ...@@ -162,6 +162,26 @@ node_types:
interfaces: interfaces:
CloudsStorm: CloudsStorm:
type: tosca.interfaces.ARTICONF.CloudsStorm type: tosca.interfaces.ARTICONF.CloudsStorm
provision:
inputs:
code_type: SEQ
object_type: SubTopology
delete:
inputs:
code_type: SEQ
object_type: SubTopology
hscale:
inputs:
code_type: SEQ
object_type: SubTopology
stop:
inputs:
code_type: SEQ
object_type: SubTopology
start:
inputs:
code_type: SEQ
object_type: SubTopology
tosca.nodes.ARTICONF.VM.Compute: tosca.nodes.ARTICONF.VM.Compute:
derived_from: tosca.nodes.ARTICONF.Infrastructure derived_from: tosca.nodes.ARTICONF.Infrastructure
......
...@@ -61,6 +61,10 @@ public class ToscaHelper { ...@@ -61,6 +61,10 @@ public class ToscaHelper {
private static final String VM_TOPOLOGY = "tosca.nodes.ARTICONF.VM.topology"; private static final String VM_TOPOLOGY = "tosca.nodes.ARTICONF.VM.topology";
private Integer id; private Integer id;
public static enum NODE_STATES {
PROVISION, DELETE, START, STOP, H_SCALE, V_SCALE, CONFIGURE
}
@Autowired @Autowired
public ToscaHelper(String sureToscaBasePath) { public ToscaHelper(String sureToscaBasePath) {
init(sureToscaBasePath); init(sureToscaBasePath);
...@@ -295,4 +299,34 @@ public class ToscaHelper { ...@@ -295,4 +299,34 @@ public class ToscaHelper {
} }
} }
public NODE_STATES getNodeCurrentState(NodeTemplateMap node) {
return getNodeState(node, "current_state");
}
public NodeTemplateMap setNodeDesiredState(NodeTemplateMap node, NODE_STATES nodeState) {
return setNodeState(node, "desired_state", nodeState);
}
public NODE_STATES getNodeDesiredState(NodeTemplateMap node) {
return getNodeState(node, "desired_state");
}
private NODE_STATES getNodeState(NodeTemplateMap node, String stateName) {
if (node.getNodeTemplate().getArtifacts() != null) {
return NODE_STATES.valueOf((String) node.getNodeTemplate().getArtifacts().get(stateName));
}
return null;
}
private NodeTemplateMap setNodeState(NodeTemplateMap node, String stateName, NODE_STATES nodeState) {
Map<String, Object> artifacts = node.getNodeTemplate().getArtifacts();
if (artifacts == null) {
artifacts = new HashMap<>();
}
artifacts.put(stateName, nodeState.toString());
node.getNodeTemplate().setArtifacts(artifacts);
return node;
}
} }
...@@ -116,10 +116,10 @@ services: ...@@ -116,10 +116,10 @@ services:
ports: ports:
- "30000:8080" - "30000:8080"
#sure-tosca: sure-tosca:
#image: sure-tosca:3.0.0 image: sure-tosca:3.0.0
#ports: ports:
#- "8081:8081" - "8081:8081"
planner: planner:
depends_on: depends_on:
......
...@@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import nl.uva.sne.drip.service.DRIPService; import nl.uva.sne.drip.service.DRIPService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@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")
......
...@@ -15,7 +15,6 @@ import javax.servlet.http.HttpServletRequest; ...@@ -15,7 +15,6 @@ import javax.servlet.http.HttpServletRequest;
import nl.uva.sne.drip.service.DRIPService; import nl.uva.sne.drip.service.DRIPService;
import nl.uva.sne.drip.sure.tosca.client.ApiException; import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@Controller @Controller
public class PlannerApiController implements PlannerApi { public class PlannerApiController implements PlannerApi {
......
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 java.io.IOException; import java.io.IOException;
...@@ -19,7 +18,6 @@ import nl.uva.sne.drip.model.Exceptions.TypeExeption; ...@@ -19,7 +18,6 @@ import nl.uva.sne.drip.model.Exceptions.TypeExeption;
import nl.uva.sne.drip.service.DRIPService; import nl.uva.sne.drip.service.DRIPService;
import nl.uva.sne.drip.sure.tosca.client.ApiException; import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@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")
......
...@@ -7,20 +7,18 @@ package nl.uva.sne.drip.service; ...@@ -7,20 +7,18 @@ package nl.uva.sne.drip.service;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import nl.uva.sne.drip.api.NotFoundException; import nl.uva.sne.drip.api.NotFoundException;
import nl.uva.sne.drip.commons.utils.ToscaHelper; import nl.uva.sne.drip.commons.utils.ToscaHelper;
import nl.uva.sne.drip.commons.utils.ToscaHelper.NODE_STATES;
import nl.uva.sne.drip.model.Exceptions.MissingCredentialsException; import nl.uva.sne.drip.model.Exceptions.MissingCredentialsException;
import nl.uva.sne.drip.model.Exceptions.MissingVMTopologyException; import nl.uva.sne.drip.model.Exceptions.MissingVMTopologyException;
import nl.uva.sne.drip.model.Exceptions.TypeExeption; import nl.uva.sne.drip.model.Exceptions.TypeExeption;
import nl.uva.sne.drip.model.Message; import nl.uva.sne.drip.model.Message;
import nl.uva.sne.drip.model.NodeTemplateMap; import nl.uva.sne.drip.model.NodeTemplateMap;
import nl.uva.sne.drip.model.cloud.storm.CloudsStormSubTopology;
import nl.uva.sne.drip.model.tosca.Credential; import nl.uva.sne.drip.model.tosca.Credential;
import nl.uva.sne.drip.model.tosca.ToscaTemplate; import nl.uva.sne.drip.model.tosca.ToscaTemplate;
import nl.uva.sne.drip.rpc.DRIPCaller; import nl.uva.sne.drip.rpc.DRIPCaller;
...@@ -51,14 +49,6 @@ public class DRIPService { ...@@ -51,14 +49,6 @@ public class DRIPService {
@Autowired @Autowired
ProvisionerService provisionerService; ProvisionerService provisionerService;
enum PROVISIONER_OPERATION {
PROVISION, DELETE, START, STOP, H_SCALE, V_SCALE, CONFIGURE
}
enum DELETE_ACTIONS {
PROVISION, DEPLOYMENT
}
@Value("${message.broker.queue.provisioner}") @Value("${message.broker.queue.provisioner}")
private String provisionerQueueName; private String provisionerQueueName;
...@@ -93,7 +83,7 @@ public class DRIPService { ...@@ -93,7 +83,7 @@ public class DRIPService {
if (vmTopologies == null) { if (vmTopologies == null) {
throw new MissingVMTopologyException("ToscaTemplate: " + toscaTemplate + " has no VM topology"); throw new MissingVMTopologyException("ToscaTemplate: " + toscaTemplate + " has no VM topology");
} }
List<Credential> credentials = null; List<Credential> credentials;
for (NodeTemplateMap vmTopologyMap : vmTopologies) { for (NodeTemplateMap vmTopologyMap : vmTopologies) {
String provider = helper.getTopologyProvider(vmTopologyMap); String provider = helper.getTopologyProvider(vmTopologyMap);
if (needsCredentials(provider)) { if (needsCredentials(provider)) {
...@@ -114,31 +104,27 @@ public class DRIPService { ...@@ -114,31 +104,27 @@ public class DRIPService {
public String plan(String id) throws ApiException, NotFoundException, IOException, JsonProcessingException, TimeoutException, InterruptedException { public String plan(String id) throws ApiException, NotFoundException, IOException, JsonProcessingException, TimeoutException, InterruptedException {
ToscaTemplate toscaTemplate = initExecution(id); ToscaTemplate toscaTemplate = initExecution(id);
return execute(toscaTemplate,plannerQueueName); return execute(toscaTemplate, plannerQueueName);
} }
public String provision(String id) throws MissingCredentialsException, ApiException, TypeExeption, IOException, JsonProcessingException, TimeoutException, InterruptedException, NotFoundException, MissingVMTopologyException { public String provision(String id) throws MissingCredentialsException, ApiException, TypeExeption, IOException, JsonProcessingException, TimeoutException, InterruptedException, NotFoundException, MissingVMTopologyException {
ToscaTemplate toscaTemplate = initExecution(id); ToscaTemplate toscaTemplate = initExecution(id);
toscaTemplate = addCredentials(toscaTemplate); toscaTemplate = addCredentials(toscaTemplate);
toscaTemplate = setProvisionerOperation(toscaTemplate, PROVISIONER_OPERATION.PROVISION);
return execute(toscaTemplate,provisionerQueueName);
}
protected ToscaTemplate setProvisionerOperation(ToscaTemplate toscaTemplate, PROVISIONER_OPERATION operation) throws IOException, JsonProcessingException, ApiException {
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates(); List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
for (NodeTemplateMap vmTopologyMap : vmTopologies) { if (vmTopologies == null || vmTopologies.isEmpty()) {
Map<String, Object> provisionerInterface = helper.getProvisionerInterfaceFromVMTopology(vmTopologyMap); throw new MissingVMTopologyException("ToscaTemplate: " + toscaTemplate + " has no VM Topologies");
if (provisionerInterface == null || !provisionerInterface.containsKey(operation.toString().toLowerCase())) {
provisionerInterface = new HashMap<>();
Map<String, Object> inputsMap = new HashMap<>();
inputsMap.put("code_type", " SEQ");
inputsMap.put("object_type", " SubTopology");
Map<String, Object> provisionMap = new HashMap<>();
provisionMap.put("inputs", inputsMap);
provisionerInterface.put(operation.toString().toLowerCase(), provisionMap);
vmTopologyMap = helper.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisionerInterface);
toscaTemplate = helper.setNodeInToscaTemplate(toscaTemplate, vmTopologyMap);
} }
toscaTemplate = setDesieredSate(toscaTemplate, vmTopologies, NODE_STATES.PROVISION);
return execute(toscaTemplate, provisionerQueueName);
}
protected ToscaTemplate setDesieredSate(ToscaTemplate toscaTemplate,
List<NodeTemplateMap> nodes, NODE_STATES nodeState) throws IOException, JsonProcessingException, ApiException {
for (NodeTemplateMap node : nodes) {
NODE_STATES currentState = helper.getNodeCurrentState(node);
NODE_STATES desiredState = helper.getNodeDesiredState(node);
node = helper.setNodeDesiredState(node, nodeState);
toscaTemplate = helper.setNodeInToscaTemplate(toscaTemplate, node);
} }
return toscaTemplate; return toscaTemplate;
} }
...@@ -154,7 +140,7 @@ public class DRIPService { ...@@ -154,7 +140,7 @@ public class DRIPService {
public String deploy(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException, Exception { public String deploy(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException, Exception {
ToscaTemplate toscaTemplate = initExecution(id); ToscaTemplate toscaTemplate = initExecution(id);
return execute(toscaTemplate,deployerQueueName); return execute(toscaTemplate, deployerQueueName);
} }
protected ToscaTemplate initExecution(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException { protected ToscaTemplate initExecution(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException {
...@@ -166,19 +152,19 @@ public class DRIPService { ...@@ -166,19 +152,19 @@ public class DRIPService {
} }
public String delete(String id, List<String> nodeNames) throws NotFoundException, IOException, JsonProcessingException, ApiException, TypeExeption, TimeoutException, InterruptedException { public String delete(String id, List<String> nodeNames) throws NotFoundException, IOException, JsonProcessingException, ApiException, TypeExeption, TimeoutException, InterruptedException {
ToscaTemplate toscaTemplate = initExecution(id); // ToscaTemplate toscaTemplate = initExecution(id);
if (nodeNames == null || nodeNames.isEmpty()) { // if (nodeNames == null || nodeNames.isEmpty()) {
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates(); // List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
if (vmTopologies != null) { // if (vmTopologies != null) {
for (NodeTemplateMap vmTopology : vmTopologies) { // for (NodeTemplateMap vmTopology : vmTopologies) {
CloudsStormSubTopology.StatusEnum status = helper.getVMTopologyTemplateStatus(vmTopology); // CloudsStormSubTopology.StatusEnum status = helper.getVMTopologyTemplateStatus(vmTopology);
if (!status.equals(CloudsStormSubTopology.StatusEnum.DELETED)) { // if (!status.equals(CloudsStormSubTopology.StatusEnum.DELETED)) {
toscaTemplate = setProvisionerOperation(toscaTemplate, PROVISIONER_OPERATION.DELETE); // toscaTemplate = setDesieredSate(toscaTemplate, vmTopologies, NODE_STATES.DELETE);
} // }
} // }
return execute(toscaTemplate,provisionerQueueName); // return execute(toscaTemplate, provisionerQueueName);
} // }
} // }
return null; return null;
} }
......
...@@ -416,7 +416,6 @@ public class ServiceTests { ...@@ -416,7 +416,6 @@ public class ServiceTests {
ToscaTemplate toscaTemplate = dripService.initExecution(id); ToscaTemplate toscaTemplate = dripService.initExecution(id);
toscaTemplate = dripService.addCredentials(toscaTemplate); toscaTemplate = dripService.addCredentials(toscaTemplate);
toscaTemplate = dripService.setProvisionerOperation(toscaTemplate, DRIPService.PROVISIONER_OPERATION.PROVISION);
} }
} }
} }
...@@ -293,8 +293,14 @@ class CloudStormService { ...@@ -293,8 +293,14 @@ class CloudStormService {
int i = 0; int i = 0;
List<InfrasCode> infrasCodes = new ArrayList<>(); List<InfrasCode> infrasCodes = new ArrayList<>();
for (NodeTemplateMap vmTopologyMap : vmTopologiesMaps) { for (NodeTemplateMap vmTopologyMap : vmTopologiesMaps) {
ToscaHelper.NODE_STATES nodeCurrentState = helper.getNodeCurrentState(vmTopologyMap);
ToscaHelper.NODE_STATES nodeDesiredState = helper.getNodeDesiredState(vmTopologyMap);
if (nodeCurrentState != null && nodeCurrentState.equals(ToscaHelper.NODE_STATES.PROVISION)) {
//Already there
}
if (nodeCurrentState == null || nodeCurrentState.equals(ToscaHelper.NODE_STATES.DELETE)) {
Map<String, Object> provisionInterface = helper.getProvisionerInterfaceFromVMTopology(vmTopologyMap); Map<String, Object> provisionInterface = helper.getProvisionerInterfaceFromVMTopology(vmTopologyMap);
String operation = provisionInterface.keySet().iterator().next(); String operation = nodeDesiredState.toString().toLowerCase();
Map<String, Object> inputs = (Map<String, Object>) provisionInterface.get(operation); Map<String, Object> inputs = (Map<String, Object>) provisionInterface.get(operation);
inputs.put("object_type", cloudStormSubtopologies.get(i).getTopology()); inputs.put("object_type", cloudStormSubtopologies.get(i).getTopology());
OpCode opCode = new OpCode(); OpCode opCode = new OpCode();
...@@ -307,6 +313,7 @@ class CloudStormService { ...@@ -307,6 +313,7 @@ class CloudStormService {
infrasCode.setOpCode(opCode); infrasCode.setOpCode(opCode);
infrasCodes.add(infrasCode); infrasCodes.add(infrasCode);
} }
}
CloudsStormInfrasCode cloudsStormInfrasCode = new CloudsStormInfrasCode(); CloudsStormInfrasCode cloudsStormInfrasCode = new CloudsStormInfrasCode();
cloudsStormInfrasCode.setMode(CloudsStormInfrasCode.ModeEnum.LOCAL); cloudsStormInfrasCode.setMode(CloudsStormInfrasCode.ModeEnum.LOCAL);
cloudsStormInfrasCode.setInfrasCodes(infrasCodes); cloudsStormInfrasCode.setInfrasCodes(infrasCodes);
......
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