Commit a7d5e9ad authored by Spiros Koulouzis's avatar Spiros Koulouzis

implemented configure id for deploy to map to ansible playbook

parent a4b4b101
...@@ -48,6 +48,8 @@ import org.springframework.security.core.context.SecurityContextHolder; ...@@ -48,6 +48,8 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import nl.uva.sne.drip.api.dao.DeployDao; import nl.uva.sne.drip.api.dao.DeployDao;
import nl.uva.sne.drip.api.dao.KeyDao; import nl.uva.sne.drip.api.dao.KeyDao;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.v1.types.PlaybookRepresentation;
/** /**
* *
...@@ -72,6 +74,9 @@ public class DeployClusterService { ...@@ -72,6 +74,9 @@ public class DeployClusterService {
@Autowired @Autowired
private ProvisionService provisionService; private ProvisionService provisionService;
@Autowired
private PlaybookService playbookService;
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public DeployResponse findOne(String id) { public DeployResponse findOne(String id) {
DeployResponse creds = deployDao.findOne(id); DeployResponse creds = deployDao.findOne(id);
...@@ -105,7 +110,10 @@ public class DeployClusterService { ...@@ -105,7 +110,10 @@ public class DeployClusterService {
public DeployResponse deployCluster(DeployRequest deployInfo) { public DeployResponse deployCluster(DeployRequest deployInfo) {
try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) { try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) {
Message deployerInvokationMessage = buildDeployerMessage(deployInfo.getProvisionID(), deployInfo.getClusterType().toLowerCase(), deployInfo.getConfigurationID()); Message deployerInvokationMessage = buildDeployerMessage(
deployInfo.getProvisionID(),
deployInfo.getClusterType().toLowerCase(),
deployInfo.getConfigurationID());
// Message deployerInvokationMessage = MessageGenerator.generateArtificialMessage(System.getProperty("user.home") // Message deployerInvokationMessage = MessageGenerator.generateArtificialMessage(System.getProperty("user.home")
// + File.separator + "workspace" + File.separator + "DRIP" // + File.separator + "workspace" + File.separator + "DRIP"
...@@ -133,7 +141,7 @@ public class DeployClusterService { ...@@ -133,7 +141,7 @@ public class DeployClusterService {
return null; return null;
} }
private Message buildDeployerMessage(String provisionID, String managerType, String configurationID) { private Message buildDeployerMessage(String provisionID, String managerType, String configurationID) throws JSONException {
ProvisionResponse pro = provisionService.findOne(provisionID); ProvisionResponse pro = provisionService.findOne(provisionID);
if (pro == null) { if (pro == null) {
throw new NotFoundException(); throw new NotFoundException();
...@@ -148,39 +156,22 @@ public class DeployClusterService { ...@@ -148,39 +156,22 @@ public class DeployClusterService {
} }
List<DeployParameter> deployParams = pro.getDeployParameters(); List<DeployParameter> deployParams = pro.getDeployParameters();
List<MessageParameter> parameters = new ArrayList<>(); List<MessageParameter> parameters = new ArrayList<>();
for (DeployParameter dp : deployParams) { for (DeployParameter dp : deployParams) {
String cName = dp.getCloudCertificateName(); MessageParameter messageParameter = createCredentialPartameter(dp, loginKeys);
MessageParameter messageParameter = new MessageParameter();
messageParameter.setName("credential");
messageParameter.setEncoding("UTF-8");
String key = null;
for (Key lk : loginKeys) {
String lkName = lk.getName();
if (lkName == null) {
lkName = lk.getAttributes().get("domain_name");
}
if (lkName.equals(cName)) {
key = lk.getKey();
break;
}
}
messageParameter.setValue(key);
Map<String, String> attributes = new HashMap<>();
attributes.put("IP", dp.getIP());
attributes.put("role", dp.getRole());
attributes.put("user", dp.getUser());
messageParameter.setAttributes(attributes);
parameters.add(messageParameter); parameters.add(messageParameter);
} }
MessageParameter clusterTypeParameter = new MessageParameter();
clusterTypeParameter.setName("cluster");
clusterTypeParameter.setEncoding("UTF-8");
clusterTypeParameter.setValue(managerType);
parameters.add(clusterTypeParameter);
Message deployInvokationMessage = new Message();
MessageParameter managerTypeParameter = createManagerTypeParameter(managerType);
parameters.add(managerTypeParameter);
if (managerType.toLowerCase().equals("ansible") && configurationID != null) {
MessageParameter ansibleParameter = createAnsibleParameter(configurationID);
parameters.add(ansibleParameter);
}
Message deployInvokationMessage = new Message();
deployInvokationMessage.setParameters(parameters); deployInvokationMessage.setParameters(parameters);
deployInvokationMessage.setCreationDate(System.currentTimeMillis()); deployInvokationMessage.setCreationDate(System.currentTimeMillis());
return deployInvokationMessage; return deployInvokationMessage;
...@@ -225,4 +216,46 @@ public class DeployClusterService { ...@@ -225,4 +216,46 @@ public class DeployClusterService {
public void deleteAll() { public void deleteAll() {
deployDao.deleteAll(); deployDao.deleteAll();
} }
private MessageParameter createCredentialPartameter(DeployParameter dp, List<Key> loginKeys) {
String cName = dp.getCloudCertificateName();
MessageParameter messageParameter = new MessageParameter();
messageParameter.setName("credential");
messageParameter.setEncoding("UTF-8");
String key = null;
for (Key lk : loginKeys) {
String lkName = lk.getName();
if (lkName == null) {
lkName = lk.getAttributes().get("domain_name");
}
if (lkName.equals(cName)) {
key = lk.getKey();
break;
}
}
messageParameter.setValue(key);
Map<String, String> attributes = new HashMap<>();
attributes.put("IP", dp.getIP());
attributes.put("role", dp.getRole());
attributes.put("user", dp.getUser());
messageParameter.setAttributes(attributes);
return messageParameter;
}
private MessageParameter createManagerTypeParameter(String managerType) {
MessageParameter managerTypeParameter = new MessageParameter();
managerTypeParameter.setName("cluster");
managerTypeParameter.setEncoding("UTF-8");
managerTypeParameter.setValue(managerType);
return managerTypeParameter;
}
private MessageParameter createAnsibleParameter(String configurationID) throws JSONException {
PlaybookRepresentation playbook = playbookService.findOne(configurationID);
MessageParameter ansibleParameter = new MessageParameter();
ansibleParameter.setName("playbook");
ansibleParameter.setEncoding("UTF-8");
ansibleParameter.setValue(Converter.map2YmlString(playbook.getKeyValue()));
return ansibleParameter;
}
} }
...@@ -35,8 +35,6 @@ import nl.uva.sne.drip.api.service.CloudCredentialsService; ...@@ -35,8 +35,6 @@ import nl.uva.sne.drip.api.service.CloudCredentialsService;
import nl.uva.sne.drip.api.service.PlannerService; import nl.uva.sne.drip.api.service.PlannerService;
import nl.uva.sne.drip.api.service.ProvisionService; import nl.uva.sne.drip.api.service.ProvisionService;
import nl.uva.sne.drip.api.service.UserService; import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.v1.types.CloudCredentials;
import nl.uva.sne.drip.commons.v1.types.PlanResponse;
import nl.uva.sne.drip.commons.v1.types.ProvisionResponse; import nl.uva.sne.drip.commons.v1.types.ProvisionResponse;
import org.json.JSONException; import org.json.JSONException;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
......
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