Commit 0662df0a authored by Spiros Koulouzis's avatar Spiros Koulouzis

test only set operation

parent 6b86c1a2
......@@ -267,8 +267,8 @@ public class ToscaHelper {
}
public NodeTemplateMap setProvisionerInterfaceInVMTopology(NodeTemplateMap vmTopologyMap, Map<String, Object> provisionerInterface) {
System.err.println(provisionerInterface);
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
vmTopologyMap.getNodeTemplate().setInterfaces(provisionerInterface);
return vmTopologyMap;
}
public String getVMTopologyUser() throws ApiException {
......
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;
......@@ -13,6 +14,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import javax.servlet.http.HttpServletRequest;
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.service.DRIPService;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
......@@ -52,9 +54,12 @@ public class ProvisionerApiController implements ProvisionerApi {
dripService.setRequestQeueName(queueName);
String planedYemplateId = dripService.provision(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException | MissingCredentialsException | TypeExeption | IOException | TimeoutException | InterruptedException | NotFoundException ex) {
} catch (ApiException | TypeExeption | IOException | TimeoutException | InterruptedException | NotFoundException ex) {
java.util.logging.Logger.getLogger(ProvisionerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (MissingCredentialsException | MissingVMTopologyException ex) {
java.util.logging.Logger.getLogger(ProvisionerApiController.class.getName()).log(Level.SEVERE, null, ex);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ex.getMessage());
}
} else {
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
......
......@@ -95,10 +95,10 @@ public class DRIPService {
return credentials.get(0);
}
private ToscaTemplate addCredentials(ToscaTemplate toscaTemplate) throws MissingCredentialsException, ApiException, TypeExeption, MissingVMTopologyException {
protected ToscaTemplate addCredentials(ToscaTemplate toscaTemplate) throws MissingCredentialsException, ApiException, TypeExeption, MissingVMTopologyException {
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
if(vmTopologies== null){
throw new MissingVMTopologyException("ToscaTemplate: "+toscaTemplate+" has no VM topology");
if (vmTopologies == null) {
throw new MissingVMTopologyException("ToscaTemplate: " + toscaTemplate + " has no VM topology");
}
List<Credential> credentials = null;
for (NodeTemplateMap vmTopologyMap : vmTopologies) {
......@@ -131,19 +131,21 @@ public class DRIPService {
return execute(toscaTemplate);
}
private ToscaTemplate setProvisionerOperation(ToscaTemplate toscaTemplate, PROVISIONER_OPERATION operation) throws IOException, JsonProcessingException, ApiException {
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.containsKey(operation.toString().toLowerCase())) {
// Map<String, Object> inputsMap = new HashMap<>();
// inputsMap.put(operation.toString().toLowerCase(), caller);
// Map<String, Object> provisionMap = new HashMap<>();
// provisionMap.put("inputs", inputsMap);
// provisionerInterface.put(operation.toString().toLowerCase(), caller);
// vmTopologyMap = helper.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisionerInterface);
// toscaTemplate = helper.setNodeInToscaTemplate(toscaTemplate, 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);
}
}
return toscaTemplate;
}
......@@ -162,7 +164,7 @@ public class DRIPService {
return execute(toscaTemplate);
}
private ToscaTemplate initExecution(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException {
protected ToscaTemplate initExecution(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException {
String ymlToscaTemplate = toscaTemplateService.findByID(id);
Logger.getLogger(DRIPService.class.getName()).log(Level.FINE, "Found ToscaTemplate with id: {0}", id);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate);
......
......@@ -45,6 +45,7 @@ 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.tosca.Credential;
import nl.uva.sne.drip.model.tosca.ToscaTemplate;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
......@@ -82,6 +83,7 @@ public class ServiceTests {
private String toscaTemplateID;
private String testApplicationExampleToscaContents;
private static final String testApplicationExampleToscaFilePath = ".." + File.separator + "TOSCA" + File.separator + "application_example_updated.yaml";
private static final String testApplicationExamplePlanedToscaFilePath = ".." + File.separator + "TOSCA" + File.separator + "application_example_planed.yaml";
private static final String testUpdatedApplicationExampleToscaFilePath = ".." + File.separator + "TOSCA" + File.separator + "application_example_updated.yaml";
private static final String testCredentialPath = ".." + File.separator + "fake_credentials" + File.separator + "test-geni.jks";
......@@ -388,10 +390,10 @@ public class ServiceTests {
}
@Test
public void testProvision() throws FileNotFoundException, IOException, MissingCredentialsException, ApiException, TypeExeption, JsonProcessingException, TimeoutException, InterruptedException, NotFoundException {
public void testSetProvisionerOperation() throws FileNotFoundException, IOException, MissingCredentialsException, ApiException, TypeExeption, JsonProcessingException, TimeoutException, InterruptedException, NotFoundException, MissingVMTopologyException {
if (ToscaHelper.isServiceUp(sureToscaBasePath) && ToscaHelper.isServiceUp("http://" + messageBrokerHost + ":15672")) {
Credential document = new Credential();
document.setCloudProviderName("exogeni");
document.setCloudProviderName("ExoGENI");
Map<String, String> keys = new HashMap<>();
keys.put("keystore", "/qTlqams0Ppq2rnaOgL5am7ExGO2nMsOZYM61kiAnsvkOixUuoPy9r4d4OfhwQXXg3lZmeRITjNz4ps+hIDKuxodIQXgBtfMy9Kx8Syb9bIl/MQQls5hWyp9yHAl6vAampoxYu0170lceT1sds4OCz3tM9eF7/UoBQwXBPo94QhO1/vSbtICyVsm3Z2HeGKcBWobT3opZV2w30GqX/7OBmNeIG7RBMPuxLsUxJ9Alahi1zXOUjLkd2bmmVFREngmeubgCzPFxxCQQrZK6WratTzJKc1sRVNK5GJzTwi9BlcZSQSgprum9yVHUgQc6Ylmvdrkhn2g9SlluY2JAZyCZvHYaRBKE4o5bXBDumTy1YAPMNPTfpeeLz+YmH0GMfVwKkxtIBpjb045QseoIWcqxke60WWfJguaTqymXknmcqcLNz+UzUdfVfyurOy9X8xmTGCW5V4N");
document.setKeys(keys);
......@@ -401,13 +403,15 @@ public class ServiceTests {
String credentialID = credentialService.save(document);
assertNotNull(credentialID);
FileInputStream in = new FileInputStream(testApplicationExampleToscaFilePath);
FileInputStream in = new FileInputStream(testApplicationExamplePlanedToscaFilePath);
MultipartFile file = new MockMultipartFile("file", in);
toscaTemplateID = toscaTemplateService.saveFile(file);
String id = toscaTemplateService.saveFile(file);
// dripService.setRequestQeueName(provisionerQueueName);
// String planedYemplateId = dripService.provision(toscaTemplateID);
dripService.setRequestQeueName(provisionerQueueName);
ToscaTemplate toscaTemplate = dripService.initExecution(id);
toscaTemplate = dripService.addCredentials(toscaTemplate);
toscaTemplate = dripService.setProvisionerOperation(toscaTemplate, DRIPService.PROVISIONER_OPERATION.PROVISION);
}
}
}
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