Commit 7dfd001e authored by Spiros Koulouzis's avatar Spiros Koulouzis

move state to constants

parent b2dad407
......@@ -30,5 +30,10 @@ public class Constatnts {
public static final String VM_TOPOLOGY = "tosca.nodes.ARTICONF.VM.topology";
public static final String CLOUD_STORM_INTERFACE = "tosca.interfaces.ARTICONF.CloudsStorm";
public static final String ENCODED_FILE_DATATYPE = "tosca.datatypes.ARTICONF.encodedFile";
public static final String CLOUD_STORM_FILES_ZIP_SUXIF = "-cloudStromFiles.zip";
public static enum NODE_STATES {
DELETED, STARTED, STOPPED, H_SCALED, V_SCALED, CONFIGURED, RUNNING, FAILED
}
}
......@@ -61,9 +61,7 @@ public class ToscaHelper {
private Integer id;
public static enum NODE_STATES {
DELETED, STARTED, STOPPED, H_SCALED, V_SCALED, CONFIGURED, RUNNING, FAILED
}
@Autowired
public ToscaHelper(String sureToscaBasePath) {
......@@ -105,11 +103,11 @@ public class ToscaHelper {
String ymlStr = objectMapper.writeValueAsString(toscaTemplate);
File toscaTemplateFile = File.createTempFile("temp-toscaTemplate", ".yml");
FileUtils.writeByteArrayToFile(toscaTemplateFile, ymlStr.getBytes());
Logger.getLogger(ToscaHelper.class.getName()).log(Level.INFO, "Uploading ToscaTemplate to sure-tosca service: {0}", api.getApiClient().getBasePath());
Logger.getLogger(ToscaHelper.class.getName()).log(Level.FINE, "Uploading ToscaTemplate to sure-tosca service: {0}", api.getApiClient().getBasePath());
String resp = api.uploadToscaTemplate(toscaTemplateFile);
id = Integer.valueOf(resp);
toscaTemplateFile.deleteOnExit();
Logger.getLogger(ToscaHelper.class.getName()).log(Level.INFO, "Uploaded ToscaTemplate to sure-tosca service got back id: {0}", id);
Logger.getLogger(ToscaHelper.class.getName()).log(Level.FINE, "Uploaded ToscaTemplate to sure-tosca service got back id: {0}", id);
}
public List<Map<String, Object>> getProvisionInterfaceDefinitions(List<String> toscaInterfaceTypes) throws ApiException {
......
......@@ -453,7 +453,7 @@ public class ToscaHelperTest {
public void testCloudStormStatus2NodeState() {
System.out.println("cloudStormStatus2NodeState");
for (CloudsStormSubTopology.StatusEnum value : CloudsStormSubTopology.StatusEnum.values()) {
ToscaHelper.NODE_STATES result = ToscaHelper.cloudStormStatus2NodeState(value);
Constatnts.NODE_STATES result = ToscaHelper.cloudStormStatus2NodeState(value);
if (value.equals(CloudsStormSubTopology.StatusEnum.FRESH)) {
assertNull(result);
} else {
......@@ -475,8 +475,8 @@ public class ToscaHelperTest {
System.out.println("getNodeCurrentState");
instance.uploadToscaTemplate(provisionedToscaTemplate);
NodeTemplateMap node = instance.getVMTopologyTemplates().get(0);
ToscaHelper.NODE_STATES expResult = ToscaHelper.NODE_STATES.RUNNING;
ToscaHelper.NODE_STATES result = instance.getNodeCurrentState(node);
Constatnts.NODE_STATES expResult = Constatnts.NODE_STATES.RUNNING;
Constatnts.NODE_STATES result = instance.getNodeCurrentState(node);
assertEquals(expResult, result);
}
......@@ -495,7 +495,7 @@ public class ToscaHelperTest {
System.out.println("setNodeCurrentState");
instance.uploadToscaTemplate(provisionedToscaTemplate);
NodeTemplateMap node = instance.getVMTopologyTemplates().get(0);
ToscaHelper.NODE_STATES nodeState = ToscaHelper.NODE_STATES.DELETED;
Constatnts.NODE_STATES nodeState = Constatnts.NODE_STATES.DELETED;
NodeTemplateMap result = instance.setNodeCurrentState(node, nodeState);
assertEquals(instance.getNodeCurrentState(node), nodeState);
......@@ -511,22 +511,22 @@ public class ToscaHelperTest {
@Test
public void testNodeDesiredState2CloudStormOperation() {
System.out.println("NodeDesiredState2CloudStormOperation");
ToscaHelper.NODE_STATES nodeDesiredState = ToscaHelper.NODE_STATES.RUNNING;
Constatnts.NODE_STATES nodeDesiredState = Constatnts.NODE_STATES.RUNNING;
OpCode.OperationEnum expResult = OpCode.OperationEnum.PROVISION;
OpCode.OperationEnum result = ToscaHelper.NodeDesiredState2CloudStormOperation(nodeDesiredState);
assertEquals(expResult, result);
nodeDesiredState = ToscaHelper.NODE_STATES.DELETED;
nodeDesiredState = Constatnts.NODE_STATES.DELETED;
expResult = OpCode.OperationEnum.DELETE;
result = ToscaHelper.NodeDesiredState2CloudStormOperation(nodeDesiredState);
assertEquals(expResult, result);
nodeDesiredState = ToscaHelper.NODE_STATES.STOPPED;
nodeDesiredState = Constatnts.NODE_STATES.STOPPED;
expResult = OpCode.OperationEnum.STOP;
result = ToscaHelper.NodeDesiredState2CloudStormOperation(nodeDesiredState);
assertEquals(expResult, result);
nodeDesiredState = ToscaHelper.NODE_STATES.STARTED;
nodeDesiredState = Constatnts.NODE_STATES.STARTED;
expResult = OpCode.OperationEnum.START;
result = ToscaHelper.NodeDesiredState2CloudStormOperation(nodeDesiredState);
assertEquals(expResult, result);
......@@ -539,7 +539,7 @@ public class ToscaHelperTest {
@Test
public void testNodeCurrentState2CloudStormStatus() {
System.out.println("nodeCurrentState2CloudStormStatus");
ToscaHelper.NODE_STATES currentState = ToscaHelper.NODE_STATES.CONFIGURED;
Constatnts.NODE_STATES currentState = Constatnts.NODE_STATES.CONFIGURED;
CloudsStormSubTopology.StatusEnum expResult = null;
CloudsStormSubTopology.StatusEnum result = ToscaHelper.nodeCurrentState2CloudStormStatus(currentState);
assertEquals(expResult, result);
......
......@@ -13,13 +13,12 @@ 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.commons.utils.Constatnts.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;
......
......@@ -39,6 +39,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.Swagger2SpringBoot;
import nl.uva.sne.drip.api.NotFoundException;
import nl.uva.sne.drip.commons.utils.Constatnts;
import static nl.uva.sne.drip.commons.utils.Constatnts.*;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.utils.ToscaHelper;
......@@ -434,7 +435,7 @@ public class ServiceTests {
Assert.assertTrue(attributes.containsKey("credential"));
assertNotNull(attributes.get("credential"));
}
toscaTemplate = dripService.setDesieredSate(toscaTemplate, vmTopologies, ToscaHelper.NODE_STATES.RUNNING);
toscaTemplate = dripService.setDesieredSate(toscaTemplate, vmTopologies, Constatnts.NODE_STATES.RUNNING);
Map<String, NodeTemplate> nodes = toscaTemplate.getTopologyTemplate().getNodeTemplates();
Set<String> names = nodes.keySet();
for (String name : names) {
......
......@@ -18,7 +18,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
......@@ -30,6 +29,8 @@ import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.commons.utils.Constatnts;
import static nl.uva.sne.drip.commons.utils.Constatnts.CLOUD_STORM_FILES_ZIP_SUXIF;
import static nl.uva.sne.drip.commons.utils.Constatnts.ENCODED_FILE_DATATYPE;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.utils.ToscaHelper;
......@@ -205,8 +206,8 @@ class CloudStormService {
cloudsStormSubTopology.setDomain(domain);
cloudsStormSubTopology.setCloudProvider(provider);
cloudsStormSubTopology.setTopology(SUB_TOPOLOGY_NAME + i);
ToscaHelper.NODE_STATES currentState = getHelper().getNodeCurrentState(nodeTemplateMap);
ToscaHelper.NODE_STATES desiredState = getHelper().getNodeDesiredState(nodeTemplateMap);
Constatnts.NODE_STATES currentState = getHelper().getNodeCurrentState(nodeTemplateMap);
Constatnts.NODE_STATES desiredState = getHelper().getNodeDesiredState(nodeTemplateMap);
cloudsStormSubTopology.setStatus(ToscaHelper.nodeCurrentState2CloudStormStatus(currentState));
CloudsStormVMs cloudsStormVMs = new CloudsStormVMs();
......@@ -269,7 +270,7 @@ class CloudStormService {
&& bestMatchingVM.getExtraInfo() == null && !bestMatchingVM.getExtraInfo().containsKey("DiskSize")) {
bestMatchingVM.setDiskSize(requestedDiskSize.intValue());
}
Logger.getLogger(CloudStormService.class.getName()).log(Level.INFO, "Found best matching VM: {0}", bestMatchingVM);
Logger.getLogger(CloudStormService.class.getName()).log(Level.FINE, "Found best matching VM: {0}", bestMatchingVM);
return bestMatchingVM;
}
......@@ -319,8 +320,8 @@ class CloudStormService {
int i = 0;
List<InfrasCode> infrasCodes = new ArrayList<>();
for (NodeTemplateMap vmTopologyMap : vmTopologiesMaps) {
ToscaHelper.NODE_STATES nodeCurrentState = getHelper().getNodeCurrentState(vmTopologyMap);
ToscaHelper.NODE_STATES nodeDesiredState = getHelper().getNodeDesiredState(vmTopologyMap);
Constatnts.NODE_STATES nodeCurrentState = getHelper().getNodeCurrentState(vmTopologyMap);
Constatnts.NODE_STATES nodeDesiredState = getHelper().getNodeDesiredState(vmTopologyMap);
//Can provision
Map<String, Object> provisionInterface = getHelper().getProvisionerInterfaceFromVMTopology(vmTopologyMap);
......@@ -406,9 +407,10 @@ class CloudStormService {
Map<String, String> provisionedFiles = new HashMap<>();
provisionedFiles.put("type", ENCODED_FILE_DATATYPE);
File tempInputDirFile = new File(tempInputDirPath);
String zipPath = (tempInputDirFile.getAbsolutePath() + "-cloudStromFiles.zip");
String zipPath = (tempInputDirFile.getAbsolutePath() + CLOUD_STORM_FILES_ZIP_SUXIF);
String sourceFolderPath = tempInputDirPath;
Converter.zipFolder(sourceFolderPath, zipPath);
Logger.getLogger(CloudStormService.class.getName()).log(Level.FINE, "Created zip at: {0}", zipPath);
String cloudStormZipFileContentsAsBase64 = Converter.encodeFileToBase64Binary(zipPath);
provisionedFiles.put("file_contents", cloudStormZipFileContentsAsBase64);
......@@ -416,6 +418,7 @@ class CloudStormService {
provisionedFiles.put("file_ext", "zip");
artifacts.put("provisioned_files", provisionedFiles);
vmTopologyMap.getNodeTemplate().setArtifacts(artifacts);
Logger.getLogger(CloudStormService.class.getName()).log(Level.FINE, "Added zip artifacts in node: {0}", vmTopologyMap.getName());
return vmTopologyMap;
}
......
......@@ -19,6 +19,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import static nl.uva.sne.drip.commons.utils.Constatnts.CLOUD_STORM_FILES_ZIP_SUXIF;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.utils.ToscaHelper;
import nl.uva.sne.drip.model.Message;
......@@ -259,7 +260,11 @@ public class CloudStormServiceTest {
List<NodeTemplateMap> vmTopologiesMaps = instance.getHelper().getVMTopologyTemplates();
for (NodeTemplateMap vmTopologyMap : vmTopologiesMaps) {
vmTopologyMap = instance.addCloudStromArtifacts(vmTopologyMap, tempInputDirPath);
File zipFile = new File(tempInputDirPath + File.separator + TOPOLOGY_FOLDER_NAME + ".zip");
File tempInputDirFile = new File(tempInputDirPath);
String zipPath = (tempInputDirFile.getAbsolutePath() + CLOUD_STORM_FILES_ZIP_SUXIF);
File zipFile = new File(zipPath);
assertTrue(zipFile.exists());
assertTrue(zipFile.length() > 1);
String contentType = Files.probeContentType(Paths.get(zipFile.getAbsolutePath()));
......
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