Commit 98461ebf authored by Spiros Koulouzis's avatar Spiros Koulouzis

added static vars for tosca names

parent dec39138
/*
* Copyright 2019 S. Koulouzis
*
* 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.commons.utils;
/**
*
* @author S. Koulouzis
*/
public class Constatnts {
public static final String VM_CAPABILITY = "tosca.capabilities.ARTICONF.VM";
public static final String VM_TYPE = "tosca.nodes.ARTICONF.VM.Compute";
public static final String VM_NUM_OF_CORES = "num_cores";
public static final String MEM_SIZE = "mem_size";
public static final String DISK_SIZE = "disk_size";
public static final String VM_OS = "os";
public static final String VM_TOPOLOGY = "tosca.nodes.ARTICONF.VM.topology";
public static final String CLOUD_STORM_INTERFACE = "tosca.interfaces.ARTICONF.CloudsStorm";
}
......@@ -42,6 +42,7 @@ import org.apache.commons.io.FileUtils;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
import nl.uva.sne.drip.sure.tosca.client.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import static nl.uva.sne.drip.commons.utils.Constatnts.*;
/**
*
......@@ -52,13 +53,7 @@ public class ToscaHelper {
private DefaultApi api;
private ObjectMapper objectMapper;
public static final String VM_CAPABILITY = "tosca.capabilities.ARTICONF.VM";
private static final String VM_TYPE = "tosca.nodes.ARTICONF.VM.Compute";
private static final String VM_NUM_OF_CORES = "num_cores";
private static final String MEM_SIZE = "mem_size";
private static final String DISK_SIZE = "disk_size";
private static final String VM_OS = "os";
private static final String VM_TOPOLOGY = "tosca.nodes.ARTICONF.VM.topology";
private Integer id;
public static enum NODE_STATES {
......@@ -125,7 +120,7 @@ public class ToscaHelper {
public List<NodeTemplateMap> getVMTopologyTemplates() throws ApiException {
try {
List<NodeTemplateMap> vmTopologyTemplates = api.getNodeTemplates(String.valueOf(id), "tosca.nodes.ARTICONF.VM.topology", null, null, null, null, null, null, null);
List<NodeTemplateMap> vmTopologyTemplates = api.getNodeTemplates(String.valueOf(id), VM_TOPOLOGY, null, null, null, null, null, null, null);
return vmTopologyTemplates;
} catch (ApiException ex) {
if (ex.getCode() == 404) {
......@@ -313,8 +308,9 @@ public class ToscaHelper {
}
private NODE_STATES getNodeState(NodeTemplateMap node, String stateName) {
if (node.getNodeTemplate().getAttributes() != null) {
return NODE_STATES.valueOf((String) node.getNodeTemplate().getAttributes().get(stateName));
Map<String, Object> attributes = node.getNodeTemplate().getAttributes();
if (attributes != null && attributes.containsKey(stateName)) {
return NODE_STATES.valueOf((String) attributes.get(stateName));
}
return null;
}
......
......@@ -25,14 +25,13 @@ import java.io.FileInputStream;
import java.nio.file.Files;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import static nl.uva.sne.drip.commons.utils.Constatnts.*;
import nl.uva.sne.drip.model.NodeTemplate;
import nl.uva.sne.drip.model.NodeTemplateMap;
import nl.uva.sne.drip.model.Provisioner;
......@@ -127,7 +126,7 @@ public class ToscaHelperTest {
public void testGetProvisionInterfaceDefinitions() throws ApiException {
if (serviceUp) {
System.out.println("getProvisionInterfaceDefinitions");
String expected = "tosca.interfaces.ARTICONF.CloudsStorm";
String expected = CLOUD_STORM_INTERFACE;
List<String> toscaInterfaceTypes = new ArrayList<>();
toscaInterfaceTypes.add(expected);
List<Map<String, Object>> result = instance.getProvisionInterfaceDefinitions(toscaInterfaceTypes);
......@@ -149,13 +148,11 @@ public class ToscaHelperTest {
List<NodeTemplateMap> result = instance.getVMTopologyTemplates();
assertNotNull(result);
for (NodeTemplateMap nodeTemplateMap : result) {
assertEquals(nodeTemplateMap.getNodeTemplate().getType(), "tosca.nodes.ARTICONF.VM.topology");
assertEquals(nodeTemplateMap.getNodeTemplate().getType(), VM_TOPOLOGY);
}
}
}
/**
* Test of getTemplateVMsForVMTopology method, of class ToscaHelper.
*
......@@ -169,7 +166,7 @@ public class ToscaHelperTest {
for (NodeTemplateMap nodeTemplateMap : vmTopologyTemplatesMap) {
List<NodeTemplateMap> result = instance.getTemplateVMsForVMTopology(nodeTemplateMap);
for (NodeTemplateMap mvmTopology : result) {
assertEquals("tosca.nodes.ARTICONF.VM.Compute", mvmTopology.getNodeTemplate().getType());
assertEquals(VM_TYPE, mvmTopology.getNodeTemplate().getType());
}
}
......@@ -229,7 +226,7 @@ public class ToscaHelperTest {
Provisioner provisioner = new Provisioner();
provisioner.setName("CloudsStorm");
provisioner.setDescription("Interface for VM topology management with CloudsStorm. More at https://cloudsstorm.github.io/");
provisioner.setToscaInterfaceType("tosca.interfaces.ARTICONF.CloudsStorm");
provisioner.setToscaInterfaceType(CLOUD_STORM_INTERFACE);
String operation = "provision";
// for (NodeTemplateMap vmTopologyMap : vmTopologies) {
......
......@@ -7,6 +7,7 @@ package nl.uva.sne.drip.service;
import java.util.ArrayList;
import java.util.List;
import static nl.uva.sne.drip.commons.utils.Constatnts.CLOUD_STORM_INTERFACE;
import org.springframework.stereotype.Service;
import nl.uva.sne.drip.model.Provisioner;
......@@ -22,7 +23,7 @@ public class ProvisionerService {
Provisioner provisioner = new Provisioner();
provisioner.setName("CloudsStorm");
provisioner.setDescription("Interface for VM topology management with CloudsStorm. More at https://cloudsstorm.github.io/");
provisioner.setToscaInterfaceType("tosca.interfaces.ARTICONF.CloudsStorm");
provisioner.setToscaInterfaceType(CLOUD_STORM_INTERFACE);
all.add(provisioner);
return all;
}
......
......@@ -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 static nl.uva.sne.drip.commons.utils.Constatnts.*;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.utils.ToscaHelper;
import nl.uva.sne.drip.configuration.MongoConfig;
......@@ -259,7 +260,7 @@ public class ServiceTests {
Assert.assertNotNull(id);
toscaTemplateService.deleteByID(id);
id = toscaTemplateService.findByID(id);
toscaTemplateService.findByID(id);
} catch (Exception ex) {
if (!(ex instanceof NoSuchElementException)) {
fail(ex.getMessage());
......@@ -422,7 +423,7 @@ public class ServiceTests {
ToscaTemplate toscaTemplate = dripService.initExecution(id);
toscaTemplate = dripService.addCredentials(toscaTemplate);
helper.uploadToscaTemplate(toscaTemplate);
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
if (vmTopologies == null || vmTopologies.isEmpty()) {
throw new MissingVMTopologyException("ToscaTemplate: " + toscaTemplate + " has no VM Topologies");
......@@ -438,7 +439,7 @@ public class ServiceTests {
Set<String> names = nodes.keySet();
for (String name : names) {
NodeTemplate node = nodes.get(name);
if (node.getType().equals("tosca.nodes.ARTICONF.VM.topology")) {
if (node.getType().equals(VM_TOPOLOGY)) {
Map<String, Object> attributes = node.getAttributes();
assertNotNull(attributes);
Assert.assertTrue(attributes.containsKey("credential"));
......
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