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

use states to manipulate nodes

parent 9f91e794
......@@ -162,6 +162,26 @@ node_types:
interfaces:
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:
derived_from: tosca.nodes.ARTICONF.Infrastructure
......
......@@ -61,6 +61,10 @@ public class ToscaHelper {
private static final String VM_TOPOLOGY = "tosca.nodes.ARTICONF.VM.topology";
private Integer id;
public static enum NODE_STATES {
PROVISION, DELETE, START, STOP, H_SCALE, V_SCALE, CONFIGURE
}
@Autowired
public ToscaHelper(String sureToscaBasePath) {
init(sureToscaBasePath);
......@@ -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:
ports:
- "30000:8080"
#sure-tosca:
#image: sure-tosca:3.0.0
#ports:
#- "8081:8081"
sure-tosca:
image: sure-tosca:3.0.0
ports:
- "8081:8081"
planner:
depends_on:
......
......@@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import javax.servlet.http.HttpServletRequest;
import nl.uva.sne.drip.service.DRIPService;
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")
......
......@@ -15,7 +15,6 @@ import javax.servlet.http.HttpServletRequest;
import nl.uva.sne.drip.service.DRIPService;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@Controller
public class PlannerApiController implements PlannerApi {
......
package nl.uva.sne.drip.api;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*;
import java.io.IOException;
......@@ -19,7 +18,6 @@ import nl.uva.sne.drip.model.Exceptions.TypeExeption;
import nl.uva.sne.drip.service.DRIPService;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
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")
......
......@@ -7,20 +7,18 @@ package nl.uva.sne.drip.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.api.NotFoundException;
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.MissingVMTopologyException;
import nl.uva.sne.drip.model.Exceptions.TypeExeption;
import nl.uva.sne.drip.model.Message;
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.ToscaTemplate;
import nl.uva.sne.drip.rpc.DRIPCaller;
......@@ -51,14 +49,6 @@ public class DRIPService {
@Autowired
ProvisionerService provisionerService;
enum PROVISIONER_OPERATION {
PROVISION, DELETE, START, STOP, H_SCALE, V_SCALE, CONFIGURE
}
enum DELETE_ACTIONS {
PROVISION, DEPLOYMENT
}
@Value("${message.broker.queue.provisioner}")
private String provisionerQueueName;
......@@ -93,7 +83,7 @@ public class DRIPService {
if (vmTopologies == null) {
throw new MissingVMTopologyException("ToscaTemplate: " + toscaTemplate + " has no VM topology");
}
List<Credential> credentials = null;
List<Credential> credentials;
for (NodeTemplateMap vmTopologyMap : vmTopologies) {
String provider = helper.getTopologyProvider(vmTopologyMap);
if (needsCredentials(provider)) {
......@@ -114,31 +104,27 @@ public class DRIPService {
public String plan(String id) throws ApiException, NotFoundException, IOException, JsonProcessingException, TimeoutException, InterruptedException {
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 {
ToscaTemplate toscaTemplate = initExecution(id);
toscaTemplate = addCredentials(toscaTemplate);
toscaTemplate = setProvisionerOperation(toscaTemplate, PROVISIONER_OPERATION.PROVISION);
return execute(toscaTemplate,provisionerQueueName);
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
if (vmTopologies == null || vmTopologies.isEmpty()) {
throw new MissingVMTopologyException("ToscaTemplate: " + toscaTemplate + " has no VM Topologies");
}
toscaTemplate = setDesieredSate(toscaTemplate, vmTopologies, NODE_STATES.PROVISION);
return execute(toscaTemplate, provisionerQueueName);
}
protected ToscaTemplate setProvisionerOperation(ToscaTemplate toscaTemplate, PROVISIONER_OPERATION operation) throws IOException, JsonProcessingException, ApiException {
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
for (NodeTemplateMap vmTopologyMap : vmTopologies) {
Map<String, Object> provisionerInterface = helper.getProvisionerInterfaceFromVMTopology(vmTopologyMap);
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);
}
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;
}
......@@ -154,7 +140,7 @@ public class DRIPService {
public String deploy(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException, Exception {
ToscaTemplate toscaTemplate = initExecution(id);
return execute(toscaTemplate,deployerQueueName);
return execute(toscaTemplate, deployerQueueName);
}
protected ToscaTemplate initExecution(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException {
......@@ -166,19 +152,19 @@ public class DRIPService {
}
public String delete(String id, List<String> nodeNames) throws NotFoundException, IOException, JsonProcessingException, ApiException, TypeExeption, TimeoutException, InterruptedException {
ToscaTemplate toscaTemplate = initExecution(id);
if (nodeNames == null || nodeNames.isEmpty()) {
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
if (vmTopologies != null) {
for (NodeTemplateMap vmTopology : vmTopologies) {
CloudsStormSubTopology.StatusEnum status = helper.getVMTopologyTemplateStatus(vmTopology);
if (!status.equals(CloudsStormSubTopology.StatusEnum.DELETED)) {
toscaTemplate = setProvisionerOperation(toscaTemplate, PROVISIONER_OPERATION.DELETE);
}
}
return execute(toscaTemplate,provisionerQueueName);
}
}
// ToscaTemplate toscaTemplate = initExecution(id);
// if (nodeNames == null || nodeNames.isEmpty()) {
// List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
// if (vmTopologies != null) {
// for (NodeTemplateMap vmTopology : vmTopologies) {
// CloudsStormSubTopology.StatusEnum status = helper.getVMTopologyTemplateStatus(vmTopology);
// if (!status.equals(CloudsStormSubTopology.StatusEnum.DELETED)) {
// toscaTemplate = setDesieredSate(toscaTemplate, vmTopologies, NODE_STATES.DELETE);
// }
// }
// return execute(toscaTemplate, provisionerQueueName);
// }
// }
return null;
}
......
......@@ -416,7 +416,6 @@ public class ServiceTests {
ToscaTemplate toscaTemplate = dripService.initExecution(id);
toscaTemplate = dripService.addCredentials(toscaTemplate);
toscaTemplate = dripService.setProvisionerOperation(toscaTemplate, DRIPService.PROVISIONER_OPERATION.PROVISION);
}
}
}
......@@ -293,19 +293,26 @@ class CloudStormService {
int i = 0;
List<InfrasCode> infrasCodes = new ArrayList<>();
for (NodeTemplateMap vmTopologyMap : vmTopologiesMaps) {
Map<String, Object> provisionInterface = helper.getProvisionerInterfaceFromVMTopology(vmTopologyMap);
String operation = provisionInterface.keySet().iterator().next();
Map<String, Object> inputs = (Map<String, Object>) provisionInterface.get(operation);
inputs.put("object_type", cloudStormSubtopologies.get(i).getTopology());
OpCode opCode = new OpCode();
opCode.setLog(Boolean.FALSE);
opCode.setObjectType(OpCode.ObjectTypeEnum.SUBTOPOLOGY);
opCode.setObjects(cloudStormSubtopologies.get(i).getTopology());
opCode.setOperation(OpCode.OperationEnum.fromValue(operation));
InfrasCode infrasCode = new InfrasCode();
infrasCode.setCodeType(InfrasCode.CodeTypeEnum.SEQ);
infrasCode.setOpCode(opCode);
infrasCodes.add(infrasCode);
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);
String operation = nodeDesiredState.toString().toLowerCase();
Map<String, Object> inputs = (Map<String, Object>) provisionInterface.get(operation);
inputs.put("object_type", cloudStormSubtopologies.get(i).getTopology());
OpCode opCode = new OpCode();
opCode.setLog(Boolean.FALSE);
opCode.setObjectType(OpCode.ObjectTypeEnum.SUBTOPOLOGY);
opCode.setObjects(cloudStormSubtopologies.get(i).getTopology());
opCode.setOperation(OpCode.OperationEnum.fromValue(operation));
InfrasCode infrasCode = new InfrasCode();
infrasCode.setCodeType(InfrasCode.CodeTypeEnum.SEQ);
infrasCode.setOpCode(opCode);
infrasCodes.add(infrasCode);
}
}
CloudsStormInfrasCode cloudsStormInfrasCode = new CloudsStormInfrasCode();
cloudsStormInfrasCode.setMode(CloudsStormInfrasCode.ModeEnum.LOCAL);
......
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