Commit e760ce9d authored by Spiros Koulouzis's avatar Spiros Koulouzis

Merge branch 'DRIP_0.1'

# Conflicts:
#	docs/apidocs/data.html
#	docs/apidocs/downloads.html
#	docs/apidocs/drip-api-gwt-json-overlay.jar
#	docs/apidocs/drip-api-js.zip
#	docs/apidocs/drip-api-json-client-json-sources.jar
#	docs/apidocs/drip-api-json-client.jar
#	docs/apidocs/drip-api-php.zip
#	docs/apidocs/drip-api-xml-client-xml-sources.jar
#	docs/apidocs/drip-api-xml-client.jar
#	docs/apidocs/drip-api.rb
#	docs/apidocs/index.html
#	docs/apidocs/json_AnsibleOutput.html
#	docs/apidocs/json_AnsibleResult.html
#	docs/apidocs/json_BenchmarkResult.html
#	docs/apidocs/json_CloudCredentials.html
#	docs/apidocs/json_DeployParameter.html
#	docs/apidocs/json_DeployRequest.html
#	docs/apidocs/json_DeployResponse.html
#	docs/apidocs/json_Key.html
#	docs/apidocs/json_KeyPair.html
#	docs/apidocs/json_KeyType.html
#	docs/apidocs/json_KeyValueHolder.html
#	docs/apidocs/json_OwnedObject.html
#	docs/apidocs/json_PlanResponse.html
#	docs/apidocs/json_PlaybookRepresentation.html
#	docs/apidocs/json_ProvisionRequest.html
#	docs/apidocs/json_ProvisionResponse.html
#	docs/apidocs/json_Script.html
#	docs/apidocs/json_SysbenchCPUBenchmark.html
#	docs/apidocs/json_ToscaRepresentation.html
#	docs/apidocs/json_User.html
#	docs/apidocs/ns0.xsd
#	docs/apidocs/resource_AnsibleOutputController.html
#	docs/apidocs/resource_BenchmarkController.html
#	docs/apidocs/resource_CloudConfigurationController0.html
#	docs/apidocs/resource_CloudCredentialsController.html
#	docs/apidocs/resource_DeployController.html
#	docs/apidocs/resource_DeployController0.html
#	docs/apidocs/resource_KeyPairController.html
#	docs/apidocs/resource_PlannerController.html
#	docs/apidocs/resource_PlannerController0.html
#	docs/apidocs/resource_ProvisionController.html
#	docs/apidocs/resource_ProvisionController0.html
#	docs/apidocs/resource_ScriptController.html
#	docs/apidocs/resource_UserController.html
#	docs/apidocs/resource_UserPublicKeysController0.html
#	docs/apidocs/resource_UserScriptController0.html
#	docs/apidocs/resources.html
#	docs/apidocs/syntax_json.html
#	docs/apidocs/syntax_xml.html
#	docs/apidocs/xml_ns0_ansibleOutput.html
#	docs/apidocs/xml_ns0_attribute.html
#	docs/apidocs/xml_ns0_benchmarkResult.html
#	docs/apidocs/xml_ns0_cloudCredentials.html
#	docs/apidocs/xml_ns0_confScript.html
#	docs/apidocs/xml_ns0_confUserKey.html
#	docs/apidocs/xml_ns0_configure.html
#	docs/apidocs/xml_ns0_deploy.html
#	docs/apidocs/xml_ns0_deployParameter.html
#	docs/apidocs/xml_ns0_deployRequest.html
#	docs/apidocs/xml_ns0_deployResponse.html
#	docs/apidocs/xml_ns0_execute.html
#	docs/apidocs/xml_ns0_key.html
#	docs/apidocs/xml_ns0_keyPair.html
#	docs/apidocs/xml_ns0_keyType.html
#	docs/apidocs/xml_ns0_keyValueHolder.html
#	docs/apidocs/xml_ns0_ownedObject.html
#	docs/apidocs/xml_ns0_plan.html
#	docs/apidocs/xml_ns0_planResponse.html
#	docs/apidocs/xml_ns0_playbookRepresentation.html
#	docs/apidocs/xml_ns0_provisionRequest.html
#	docs/apidocs/xml_ns0_provisionResponse.html
#	docs/apidocs/xml_ns0_register.html
#	docs/apidocs/xml_ns0_result.html
#	docs/apidocs/xml_ns0_script.html
#	docs/apidocs/xml_ns0_sysbenchCPUBenchmark.html
#	docs/apidocs/xml_ns0_toscaRepresentation.html
#	docs/apidocs/xml_ns0_user.html
parents 96cac04a 81676ee0
......@@ -9,10 +9,10 @@
<api-classes>
<include pattern="nl.uva.sne.drip.api.v1.rest.*" />
<include pattern="nl.uva.sne.drip.api.v0.rest.*" />
<include pattern="nl.uva.sne.drip.data.v1.external.*" />
<include pattern="nl.uva.sne.drip.data.v1.external.ansible.*" />
<include pattern="nl.uva.sne.drip.data.v0.external.*" />
<exclude pattern="nl.uva.sne.drip.data.internal.*"/>
<include pattern="nl.uva.sne.drip.drip.commons.data.v1.external.*" />
<include pattern="nl.uva.sne.drip.drip.commons.data.v1.external.ansible.*" />
<include pattern="nl.uva.sne.drip.drip.commons.data.v0.external.*" />
<exclude pattern="nl.uva.sne.drip.drip.commons.data.internal.*"/>
</api-classes>
......
......@@ -21,7 +21,12 @@
</properties>
<dependencies>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
......
......@@ -16,7 +16,7 @@
package nl.uva.sne.drip.api.auth;
import java.io.Serializable;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
......
......@@ -15,7 +15,7 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.data.v1.external.ansible.AnsibleOutput;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
......
......@@ -15,7 +15,7 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.data.v1.external.ansible.BenchmarkResult;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
......
......@@ -15,7 +15,7 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
......
......@@ -15,9 +15,9 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.data.v1.external.DeployResponse;
import nl.uva.sne.drip.data.v1.external.Key;
import nl.uva.sne.drip.data.v1.external.ansible.AnsibleResult;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleResult;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
......
......@@ -15,7 +15,7 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
......
......@@ -15,7 +15,7 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.data.v1.external.PlanResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
......
......@@ -15,7 +15,7 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.data.v1.external.PlaybookRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlaybookRepresentation;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
......
......@@ -15,7 +15,7 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
......
......@@ -15,7 +15,7 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.data.v1.external.Script;
import nl.uva.sne.drip.drip.commons.data.v1.external.Script;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
......
......@@ -15,7 +15,7 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
......
......@@ -15,7 +15,7 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
......
......@@ -15,7 +15,7 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.data.internal.Message;
import nl.uva.sne.drip.drip.commons.data.internal.Message;
import nl.uva.sne.drip.commons.utils.Converter;
import org.json.JSONException;
......
......@@ -22,11 +22,11 @@ import java.util.concurrent.TimeoutException;
*
* @author S. Koulouzis
*/
public class ProvisionerCaller extends DRIPCaller {
public class ProvisionerCaller0 extends DRIPCaller {
private static final String REQUEST_QUEUE_NAME = "provisioner_queue";
private static final String REQUEST_QUEUE_NAME = "provisioner_queue_v0";
public ProvisionerCaller(String messageBrokerHost) throws IOException, TimeoutException {
public ProvisionerCaller0(String messageBrokerHost) throws IOException, TimeoutException {
super(messageBrokerHost, REQUEST_QUEUE_NAME);
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.api.rpc;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
/**
*
* @author S. Koulouzis
*/
public class ProvisionerCaller1 extends DRIPCaller {
private static final String REQUEST_QUEUE_NAME = "provisioner_queue_v1";
public ProvisionerCaller1(String messageBrokerHost) throws IOException, TimeoutException {
super(messageBrokerHost, REQUEST_QUEUE_NAME);
}
}
......@@ -21,9 +21,9 @@ import java.util.List;
import java.util.Set;
import nl.uva.sne.drip.api.dao.AnsibleOutputDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.data.v1.external.ansible.AnsibleOutput;
import nl.uva.sne.drip.data.v1.external.ansible.AnsibleResult;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
......
......@@ -18,8 +18,8 @@ package nl.uva.sne.drip.api.service;
import java.util.List;
import nl.uva.sne.drip.api.dao.BenchmarkResultDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.data.v1.external.ansible.BenchmarkResult;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
......
......@@ -18,8 +18,8 @@ package nl.uva.sne.drip.api.service;
import java.util.List;
import nl.uva.sne.drip.api.dao.CloudCredentialsDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
......@@ -42,6 +42,7 @@ public class CloudCredentialsService {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
cloudCredentials.setOwner(owner);
cloudCredentials.setTimestamp(System.currentTimeMillis());
return dao.save(cloudCredentials);
}
......
......@@ -18,7 +18,6 @@ package nl.uva.sne.drip.api.service;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -32,15 +31,15 @@ import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.DRIPCaller;
import nl.uva.sne.drip.api.rpc.DeployerCaller;
import nl.uva.sne.drip.api.v1.rest.DeployController;
import nl.uva.sne.drip.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.data.v1.external.DeployRequest;
import nl.uva.sne.drip.data.v1.external.DeployParameter;
import nl.uva.sne.drip.data.v1.external.DeployResponse;
import nl.uva.sne.drip.data.v1.external.Key;
import nl.uva.sne.drip.data.internal.Message;
import nl.uva.sne.drip.data.internal.MessageParameter;
import nl.uva.sne.drip.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployParameter;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.internal.Message;
import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -51,12 +50,11 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import nl.uva.sne.drip.api.dao.KeyPairDao;
import nl.uva.sne.drip.api.exception.KeyException;
import nl.uva.sne.drip.commons.utils.MessageGenerator;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.data.v1.external.ansible.AnsibleOutput;
import nl.uva.sne.drip.data.v1.external.ansible.AnsibleResult;
import nl.uva.sne.drip.data.v1.external.ansible.BenchmarkResult;
import nl.uva.sne.drip.data.v1.external.ansible.SysbenchCPUBenchmark;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleResult;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.SysbenchCPUBenchmark;
/**
*
......@@ -90,6 +88,9 @@ public class DeployService {
@Autowired
private BenchmarkResultService benchmarkResultService;
private static final String[] CLOUD_SITE_NAMES = new String[]{"nodeType", "VMResourceID"};
private static final String[] PUBLIC_ADRESS_NAMES = new String[]{"public_address", "publicAddress"};
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public DeployResponse findOne(String id) {
DeployResponse creds = deployDao.findOne(id);
......@@ -121,7 +122,7 @@ public class DeployService {
return deployDao.save(clusterCred);
}
public DeployResponse deploySoftware(DeployRequest deployInfo) {
public DeployResponse deploySoftware(DeployRequest deployInfo) throws Exception {
try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) {
Message deployerInvokationMessage = buildDeployerMessage(
deployInfo.getProvisionID(),
......@@ -154,9 +155,13 @@ public class DeployService {
if (pro == null) {
throw new NotFoundException();
}
List<String> cloudConfIDs = pro.getCloudCredentialsIDs();
CloudCredentials cCred = cloudCredentialsService.findOne(cloudConfIDs.get(0));
List<String> loginKeysIDs = cCred.getkeyPairIDs();
List<String> loginKeysIDs = pro.getDeployerKeyPairIDs();
if (loginKeysIDs == null || loginKeysIDs.isEmpty()) {
List<String> cloudConfIDs = pro.getCloudCredentialsIDs();
CloudCredentials cCred = cloudCredentialsService.findOne(cloudConfIDs.get(0));
loginKeysIDs = cCred.getkeyPairIDs();
}
List<KeyPair> loginKeys = new ArrayList<>();
for (String keyID : loginKeysIDs) {
KeyPair key = keyDao.findOne(keyID);
......@@ -191,17 +196,17 @@ public class DeployService {
}
private MessageParameter createCredentialPartameter(DeployParameter dp, List<KeyPair> loginKeys) {
String cName = dp.getCloudCertificateName();
// String cName = dp.getCloudCertificateName();
MessageParameter messageParameter = new MessageParameter();
messageParameter.setName("credential");
messageParameter.setEncoding("UTF-8");
String key = null;
for (KeyPair lk : loginKeys) {
String lkName = lk.getPrivateKey().getAttributes().get("domain_name");
if (lkName.equals(cName)) {
key = lk.getPrivateKey().getKey();
break;
}
// String lkName = lk.getPrivateKey().getAttributes().get("domain_name");
// if (lkName.equals(cName)) {
key = lk.getPrivateKey().getKey();
// break;
// }
}
messageParameter.setValue(key);
Map<String, String> attributes = new HashMap<>();
......@@ -229,7 +234,7 @@ public class DeployService {
return ansibleParameter;
}
private DeployResponse handleResponse(List<MessageParameter> params, DeployRequest deployInfo) throws KeyException, IOException {
private DeployResponse handleResponse(List<MessageParameter> params, DeployRequest deployInfo) throws KeyException, IOException, Exception {
DeployResponse deployResponse = new DeployResponse();
deployResponse.setTimestamp(System.currentTimeMillis());
......@@ -256,25 +261,57 @@ public class DeployService {
});
List<String> outputListIds = new ArrayList<>();
Map<String, String> nodeTypeCahche = new HashMap<>();
Map<String, String> domainCahche = new HashMap<>();
Map<String, String> nodeTypeCache = new HashMap<>();
Map<String, String> domainCache = new HashMap<>();
Map<String, String> osTypeCache = new HashMap<>();
// Map<String, String> cloudProviderCache = new HashMap<>();
for (AnsibleOutput ansOut : outputList) {
Map<String, Object> map = provisionService.findOne(deployInfo.getProvisionID()).getKeyValue();
String nodeType = nodeTypeCahche.get(ansOut.getHost());
String domain = domainCahche.get(ansOut.getHost());
String nodeType = nodeTypeCache.get(ansOut.getHost());
String domain = domainCache.get(ansOut.getHost());
String os = osTypeCache.get(ansOut.getHost());
if (nodeType == null) {
List<Map<String, Object>> components = (List<Map<String, Object>>) map.get("components");
List<Map<String, Object>> components = null;
List<Map<String, Object>> topologies = null;
if (map.containsKey("components")) {
components = (List<Map<String, Object>>) map.get("components");
// topologies = (List<Map<String, Object>>) map.get("topologies");
} else {
for (String key : map.keySet()) {
Map<String, Object> subMap = (Map<String, Object>) map.get(key);
if (subMap.containsKey("components") && components == null) {
components = (List<Map<String, Object>>) subMap.get("components");
}
if (subMap.containsKey("topologies") && topologies == null) {
topologies = (List<Map<String, Object>>) subMap.get("topologies");
}
if (components != null && topologies != null) {
break;
}
}
}
for (Map<String, Object> component : components) {
String publicAddress = (String) component.get("public_address");
if (publicAddress.equals(ansOut.getHost())) {
String publicAddress = null;
for (String addressName : PUBLIC_ADRESS_NAMES) {
if (component.containsKey(addressName)) {
publicAddress = (String) component.get(addressName);
break;
}
}
if (publicAddress != null && publicAddress.equals(ansOut.getHost())) {
nodeType = (String) component.get("nodeType");
domain = (String) component.get("domain");
nodeTypeCahche.put(ansOut.getHost(), nodeType);
domainCahche.put(ansOut.getHost(), domain);
// ansOut.setCloudProviderName("");
for (String siteName : CLOUD_SITE_NAMES) {
if (component.containsKey(siteName)) {
domain = (String) component.get(siteName);
break;
}
}
os = (String) component.get("OStype");
nodeTypeCache.put(ansOut.getHost(), nodeType);
domainCache.put(ansOut.getHost(), domain);
osTypeCache.put(ansOut.getHost(), os);
break;
}
}
......@@ -282,6 +319,7 @@ public class DeployService {
ansOut.setVmType(nodeType);
ansOut.setCloudDeploymentDomain(domain);
ansOut.setProvisionID(deployInfo.getProvisionID());
ansOut.setCloudProviderName(os);
ansOut = ansibleOutputService.save(ansOut);
BenchmarkResult benchmarkResult = parseSaveBenchmarkResult(ansOut);
......
......@@ -18,15 +18,15 @@ package nl.uva.sne.drip.api.service;
import java.util.ArrayList;
import java.util.List;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import nl.uva.sne.drip.api.dao.KeyPairDao;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
/**
*
......
......@@ -29,12 +29,13 @@ import nl.uva.sne.drip.api.dao.PlanDao;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import nl.uva.sne.drip.data.internal.Message;
import nl.uva.sne.drip.data.internal.MessageParameter;
import nl.uva.sne.drip.data.v1.external.PlanResponse;
import nl.uva.sne.drip.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Constants;
import nl.uva.sne.drip.drip.commons.data.internal.Message;
import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import nl.uva.sne.drip.drip.converter.P2PConverter;
import nl.uva.sne.drip.drip.converter.SimplePlanContainer;
import org.json.JSONException;
......@@ -63,7 +64,7 @@ public class PlannerService {
@Value("${message.broker.host}")
private String messageBrokerHost;
public PlanResponse getPlan(String toscaId) throws JSONException, UnsupportedEncodingException, IOException, TimeoutException, InterruptedException {
public PlanResponse getPlan(String toscaId, String clusterType) throws JSONException, UnsupportedEncodingException, IOException, TimeoutException, InterruptedException {
try (PlannerCaller planner = new PlannerCaller(messageBrokerHost)) {
Message plannerInvokationMessage = buildPlannerMessage(toscaId);
......@@ -84,7 +85,7 @@ public class PlannerService {
}
jsonArrayString.append("]");
SimplePlanContainer simplePlan = P2PConverter.convert(jsonArrayString.toString(), "vm_user", "Ubuntu 16.04", "swarm");
SimplePlanContainer simplePlan = P2PConverter.convert(jsonArrayString.toString(), "vm_user", "Ubuntu 16.04", clusterType);
PlanResponse topLevel = new PlanResponse();
topLevel.setTimestamp(System.currentTimeMillis());
topLevel.setLevel(0);
......@@ -117,7 +118,7 @@ public class PlannerService {
}
Map<String, Object> map = t2.getKeyValue();
String json = Converter.map2JsonString(map);
json = json.replaceAll("\\uff0E", "\\.");
json = json.replaceAll("\\uff0E", ".");
byte[] bytes = json.getBytes();
Message invokationMessage = new Message();
......@@ -143,24 +144,25 @@ public class PlannerService {
Map<String, Object> map = plan.getKeyValue();
Set<String> ids = plan.getLoweLevelPlanIDs();
for (String lowID : ids) {
Map<String, Object> lowLevelMap = findOne(lowID).getKeyValue();
PlanResponse ll = findOne(lowID);
Map<String, Object> lowLevelMap = ll.getKeyValue();
if (lowLevelMap != null) {
map.putAll(lowLevelMap);
map.put(ll.getName(), lowLevelMap);
}
}
if (fromat != null && fromat.equals("yml")) {
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
ymlStr = ymlStr.replaceAll("\\uff0E", ".");
return ymlStr;
}
if (fromat != null && fromat.equals("json")) {
String jsonStr = Converter.map2JsonString(map);
jsonStr = jsonStr.replaceAll("\\uff0E", "\\.");
jsonStr = jsonStr.replaceAll("\\uff0E", ".");
return jsonStr;
}
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
ymlStr = ymlStr.replaceAll("\\uff0E", ".");
return ymlStr;
}
......@@ -188,12 +190,11 @@ public class PlannerService {
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public PlanResponse findOne(String lowiID) {
PlanResponse plan = planDao.findOne(lowiID);
public PlanResponse findOne(String id) {
PlanResponse plan = planDao.findOne(id);
if (plan == null) {
throw new NotFoundException();
}
return plan;
}
......@@ -203,6 +204,12 @@ public class PlannerService {
if (plan == null) {
throw new NotFoundException();
}
Set<String> lowIds = plan.getLoweLevelPlanIDs();
if (lowIds != null) {
for (String lId : lowIds) {
planDao.delete(lId);
}
}
planDao.delete(plan);
return plan;
}
......@@ -212,4 +219,38 @@ public class PlannerService {
planDao.deleteAll();
}
public String saveStringContents(String ymlContents, Integer level, String name) {
//Remove '\' and 'n' if they are together and replace them with '\n'
char[] array = ymlContents.toCharArray();
StringBuilder sb = new StringBuilder();
int prevChar = -1;
for (int i = 0; i < array.length; i++) {
int currentChar = (int) array[i];
if (prevChar > 0 && prevChar == 92 && currentChar == 110) {
sb.delete(sb.length() - 1, sb.length());
sb.append('\n');
} else {
sb.append((char) currentChar);
}
prevChar = (int) array[i];
}
ymlContents = sb.toString();
ymlContents = ymlContents.replaceAll("(?m)^[ \t]*\r?\n", "");
for (int i = 0; i < Constants.BAD_CHARS.length; i++) {
int hex = Constants.BAD_CHARS[i];
ymlContents = ymlContents.replaceAll(String.valueOf((char) hex), "");
}
ymlContents = ymlContents.replaceAll("\\.", "\uff0E");
// ymlContents = ymlContents.replaceAll("\uff0E", ".");
Map<String, Object> map = Converter.ymlString2Map(ymlContents);
PlanResponse pr = new PlanResponse();
pr.setKvMap(map);
pr.setLevel(level);
pr.setName(name);
save(pr);
return pr.getId();
}
}
......@@ -20,9 +20,9 @@ import java.util.List;
import java.util.Map;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.commons.utils.Constants;
import nl.uva.sne.drip.data.v1.external.PlaybookRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlaybookRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
......@@ -54,17 +54,17 @@ public class PlaybookService {
if (fromat != null && fromat.toLowerCase().equals("yml")) {
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
ymlStr = ymlStr.replaceAll("\\uff0E", ".");
ymlStr = ymlStr.replaceAll("\'---':", "---");
return ymlStr;
}
if (fromat != null && fromat.toLowerCase().equals("json")) {
String jsonStr = Converter.map2JsonString(map);
jsonStr = jsonStr.replaceAll("\\uff0E", "\\.");
jsonStr = jsonStr.replaceAll("\\uff0E", ".");
return jsonStr;
}
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
ymlStr = ymlStr.replaceAll("\\uff0E", ".");
ymlStr = ymlStr.replaceAll("\'---':", "---");
return ymlStr;
......
......@@ -15,8 +15,11 @@
*/
package nl.uva.sne.drip.api.service;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -35,18 +38,18 @@ import nl.uva.sne.drip.api.exception.ExceptionHandler;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.exception.PlanNotFoundException;
import nl.uva.sne.drip.api.rpc.DRIPCaller;
import nl.uva.sne.drip.api.rpc.ProvisionerCaller;
import nl.uva.sne.drip.api.rpc.ProvisionerCaller0;
import nl.uva.sne.drip.api.v1.rest.ProvisionController;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.data.v1.external.DeployParameter;
import nl.uva.sne.drip.data.internal.Message;
import nl.uva.sne.drip.data.internal.MessageParameter;
import nl.uva.sne.drip.data.v1.external.PlanResponse;
import nl.uva.sne.drip.data.v1.external.ProvisionRequest;
import nl.uva.sne.drip.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.data.v1.external.Script;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployParameter;
import nl.uva.sne.drip.drip.commons.data.internal.Message;
import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.Script;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.apache.commons.io.FilenameUtils;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Value;
......@@ -56,7 +59,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import nl.uva.sne.drip.api.dao.ProvisionResponseDao;
import nl.uva.sne.drip.api.dao.KeyPairDao;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.api.rpc.ProvisionerCaller1;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
/**
*
......@@ -82,7 +87,7 @@ public class ProvisionService {
private ScriptService userScriptService;
@Autowired
private KeyPairService userKeysService;
private KeyPairService keyPairService;
@Value("${message.broker.host}")
private String messageBrokerHost;
......@@ -117,71 +122,26 @@ public class ProvisionService {
return provisionDao.findAll();
}
public ProvisionResponse provisionResources(ProvisionRequest provisionRequest) throws IOException, TimeoutException, JSONException, InterruptedException {
try (DRIPCaller provisioner = new ProvisionerCaller(messageBrokerHost);) {
Message provisionerInvokationMessage = buildProvisionerMessage(provisionRequest);
public ProvisionResponse provisionResources(ProvisionRequest provisionRequest, int provisionerVersion) throws IOException, TimeoutException, JSONException, InterruptedException, Exception {
Message response = (provisioner.call(provisionerInvokationMessage));
// Message response = MessageGenerator.generateArtificialMessage(System.getProperty("user.home")
// + File.separator + "workspace" + File.separator + "DRIP"
// + File.separator + "docs" + File.separator + "json_samples"
// + File.separator + "ec2_provisioner_provisoned3.json");
List<MessageParameter> params = response.getParameters();
ProvisionResponse provisionResponse = new ProvisionResponse();
provisionResponse.setTimestamp(System.currentTimeMillis());
for (MessageParameter p : params) {
String name = p.getName();
if (name.toLowerCase().contains("exception")) {
RuntimeException ex = ExceptionHandler.generateException(name, p.getValue());
Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex);
throw ex;
}
if (!name.equals("kubernetes")) {
String value = p.getValue();
Map<String, Object> kvMap = Converter.ymlString2Map(value);
provisionResponse.setKvMap(kvMap);
provisionResponse.setPlanID(provisionRequest.getPlanID());
} else {
String value = p.getValue();
String[] lines = value.split("\n");
List<DeployParameter> deployParameters = new ArrayList<>();
for (String line : lines) {
DeployParameter deployParam = new DeployParameter();
String[] parts = line.split(" ");
String deployIP = parts[0];
String deployUser = parts[1];
String deployCertPath = parts[2];
String cloudCertificateName = FilenameUtils.removeExtension(FilenameUtils.getBaseName(deployCertPath));
String deployRole = parts[3];
deployParam.setIP(deployIP);
deployParam.setRole(deployRole);
deployParam.setUser(deployUser);
deployParam.setCloudCertificateName(cloudCertificateName);
deployParameters.add(deployParam);
}
provisionResponse.setDeployParameters(deployParameters);
}
}
provisionResponse.setCloudCredentialsIDs(provisionRequest.getCloudCredentialsIDs());
provisionResponse.setKeyPairIDs(provisionRequest.getKeyPairIDs());
provisionResponse = save(provisionResponse);
return provisionResponse;
switch (provisionerVersion) {
case 0:
return callProvisioner0(provisionRequest);
case 1:
return callProvisioner1(provisionRequest);
}
return null;
}
private Message buildProvisionerMessage(ProvisionRequest pReq) throws JSONException, IOException {
private Message buildProvisioner0Message(ProvisionRequest pReq) throws JSONException, IOException {
Message invokationMessage = new Message();
List<MessageParameter> parameters = new ArrayList();
CloudCredentials cred = cloudCredentialsService.findOne(pReq.getCloudCredentialsIDs().get(0));
if (cred == null) {
throw new CloudCredentialsNotFoundException();
}
MessageParameter conf = buildCloudConfParam(cred);
MessageParameter conf = buildCloudCredentialParam(cred, 0).get(0);
parameters.add(conf);
List<MessageParameter> certs = buildCertificatesParam(cred);
......@@ -190,9 +150,9 @@ public class ProvisionService {
List<MessageParameter> topologies = buildTopologyParams(pReq.getPlanID());
parameters.addAll(topologies);
List<String> userKeyIDs = pReq.getKeyPairIDs();
List<String> userKeyIDs = pReq.getUserKeyPairIDs();
if (userKeyIDs != null) {
List<MessageParameter> userKeys = buildKeysParams(userKeyIDs.get(0));
List<MessageParameter> userKeys = buildUserKeysParams(userKeyIDs.get(0), 0);
parameters.addAll(userKeys);
}
......@@ -201,18 +161,47 @@ public class ProvisionService {
return invokationMessage;
}
private MessageParameter buildCloudConfParam(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
MessageParameter conf = null;
String provider = cred.getCloudProviderName();
if (provider == null) {
throw new BadRequestException("Provider name can't be null. Check the cloud credentials: " + cred.getId());
private List<MessageParameter> buildCloudCredentialParam(CloudCredentials cred, int version) throws JsonProcessingException, JSONException, IOException {
List<MessageParameter> cloudCredentialParams = new ArrayList<>();
if (version == 0) {
MessageParameter cloudCredentialParam = new MessageParameter();
String provider = cred.getCloudProviderName();
if (provider == null) {
throw new BadRequestException("Provider name can't be null. Check the cloud credentials: " + cred.getId());
}
switch (cred.getCloudProviderName().toLowerCase()) {
case "ec2":
cloudCredentialParam = buildEC2Conf(cred);
break;
}
cloudCredentialParams.add(cloudCredentialParam);
return cloudCredentialParams;
}
switch (cred.getCloudProviderName().toLowerCase()) {
case "ec2":
conf = buildEC2Conf(cred);
break;
if (version == 1) {
MessageParameter cloudCred = new MessageParameter();
cloudCred.setName("cloud_credential");
cloudCred.setEncoding("UTF-8");
List<KeyPair> keyPairs = new ArrayList<>();
List<String> keyPairIds = cred.getkeyPairIDs();
if (keyPairIds != null) {
for (String id : cred.getkeyPairIDs()) {
KeyPair pair = keyDao.findOne(id);
keyPairs.add(pair);
}
cred.setKeyPairs(keyPairs);
}
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
String jsonInString = mapper.writeValueAsString(cred);
cloudCred.setValue("\"" + jsonInString + "\"");
cloudCredentialParams.add(cloudCred);
return cloudCredentialParams;
}
return conf;
return null;
}
private List<MessageParameter> buildCertificatesParam(CloudCredentials cred) {
......@@ -222,7 +211,6 @@ public class ProvisionService {
KeyPair key = keyDao.findOne(keyID);
loginKeys.add(key);
}
if (loginKeys.isEmpty()) {
throw new BadRequestException("Log in keys can't be empty");
}
......@@ -243,15 +231,18 @@ public class ProvisionService {
return parameters;
}
private List<MessageParameter> buildTopologyParams(String planID) throws JSONException {
private List<MessageParameter> buildTopologyParams(String planID) throws JSONException, FileNotFoundException {
PlanResponse plan = planService.getDao().findOne(planID);
if (plan == null) {
throw new PlanNotFoundException();
}
List<MessageParameter> parameters = new ArrayList();
MessageParameter topology = new MessageParameter();
topology.setName("topology");
topology.setValue(Converter.map2YmlString(plan.getKeyValue()));
String val = Converter.map2YmlString(plan.getKeyValue());
val = val.replaceAll("\\uff0E", ".");
topology.setValue(val);
Map<String, String> attributes = new HashMap<>();
attributes.put("level", String.valueOf(plan.getLevel()));
attributes.put("filename", FilenameUtils.removeExtension(plan.getName()));
......@@ -263,7 +254,9 @@ public class ProvisionService {
PlanResponse lowPlan = planService.getDao().findOne(lowID);
topology = new MessageParameter();
topology.setName("topology");
topology.setValue(Converter.map2YmlString(lowPlan.getKeyValue()));
String value = Converter.map2YmlString(lowPlan.getKeyValue());
value = value.replaceAll("\\uff0E", ".");
topology.setValue(value);
attributes = new HashMap<>();
attributes.put("level", String.valueOf(lowPlan.getLevel()));
attributes.put("filename", FilenameUtils.removeExtension(lowPlan.getName()));
......@@ -273,8 +266,124 @@ public class ProvisionService {
return parameters;
}
private MessageParameter buildEC2Conf(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
private List<MessageParameter> buildProvisionedTopologyParams(ProvisionResponse provisionInfo) throws JSONException {
List<MessageParameter> parameters = new ArrayList();
Map<String, Object> map = provisionInfo.getKeyValue();
for (String topoName : map.keySet()) {
Map<String, Object> topo = (Map<String, Object>) map.get(topoName);
MessageParameter topology = new MessageParameter();
topology.setName("topology");
topology.setValue(Converter.map2YmlString(topo));
HashMap<String, String> attributes = new HashMap<>();
if (topoName.equals("topology_main")) {
attributes.put("level", String.valueOf(0));
} else {
attributes.put("level", String.valueOf(1));
}
attributes.put("filename", topoName);
topology.setAttributes(attributes);
parameters.add(topology);
}
return parameters;
}
private List<MessageParameter> buildClusterKeyParams(ProvisionResponse provisionInfo) {
List<MessageParameter> parameters = new ArrayList();
List<String> ids = provisionInfo.getDeployerKeyPairIDs();
for (String id : ids) {
KeyPair pair = keyPairService.findOne(id);
MessageParameter param = new MessageParameter();
param.setName("private_deployer_key");
param.setValue(pair.getPrivateKey().getKey());
HashMap<String, String> attributes = new HashMap<>();
if (pair.getPrivateKey() != null && pair.getPrivateKey().getAttributes() != null) {
attributes.putAll(pair.getPrivateKey().getAttributes());
}
attributes.put("name", pair.getPrivateKey().getName());
param.setAttributes(attributes);
parameters.add(param);
param = new MessageParameter();
param.setName("public_deployer_key");
param.setValue(pair.getPublicKey().getKey());
attributes = new HashMap<>();
if (pair.getPublicKey() != null && pair.getPublicKey().getAttributes() != null) {
attributes.putAll(pair.getPublicKey().getAttributes());
}
param.setAttributes(attributes);
attributes.put("name", pair.getPublicKey().getName());
parameters.add(param);
}
return parameters;
}
private List<MessageParameter> buildUserKeyParams(ProvisionResponse provisionInfo) {
List<MessageParameter> parameters = new ArrayList();
List<String> ids = provisionInfo.getUserKeyPairIDs();
for (String id : ids) {
KeyPair pair = keyPairService.findOne(id);
MessageParameter param = new MessageParameter();
param.setName("private_user_key");
param.setValue(pair.getPrivateKey().getKey());
HashMap<String, String> attributes = new HashMap<>();
if (pair.getPrivateKey().getAttributes() != null) {
attributes.putAll(pair.getPrivateKey().getAttributes());
}
attributes.put("name", pair.getPrivateKey().getName());
param.setAttributes(attributes);
parameters.add(param);
param = new MessageParameter();
param.setName("public_user_key");
param.setValue(pair.getPublicKey().getKey());
if (pair.getPublicKey().getAttributes() != null) {
attributes.putAll(pair.getPublicKey().getAttributes());
}
attributes.put("name", pair.getPublicKey().getName());
param.setAttributes(attributes);
parameters.add(param);
}
return parameters;
}
private List<MessageParameter> buildCloudKeyParams(ProvisionResponse provisionInfo) {
List<MessageParameter> parameters = new ArrayList();
List<String> ids = provisionInfo.getCloudKeyPairIDs();
if (ids != null) {
for (String id : ids) {
KeyPair pair = keyPairService.findOne(id);
MessageParameter param = new MessageParameter();
param.setName("private_cloud_key");
param.setValue(pair.getPrivateKey().getKey());
HashMap<String, String> attributes = new HashMap<>();
attributes.putAll(pair.getPrivateKey().getAttributes());
attributes.put("name", pair.getPrivateKey().getName());
attributes.put("key_pair_id", pair.getKeyPairId());
param.setAttributes(attributes);
parameters.add(param);
param = new MessageParameter();
param.setName("public_cloud_key");
param.setValue(pair.getPublicKey().getKey());
attributes = new HashMap<>();
attributes.putAll(pair.getPrivateKey().getAttributes());
attributes.put("name", pair.getPublicKey().getName());
attributes.put("key_pair_id", pair.getKeyPairId());
param.setAttributes(attributes);
parameters.add(param);
}
}
return parameters;
}
private MessageParameter buildEC2Conf(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
Properties prop = Converter.getEC2Properties(cred);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
prop.store(baos, null);
......@@ -301,23 +410,298 @@ public class ProvisionService {
return parameters;
}
private List<MessageParameter> buildKeysParams(String userKeyID) {
KeyPair key = userKeysService.findOne(userKeyID);
private List<MessageParameter> buildUserKeysParams(String userKeyID, int version) {
KeyPair key = keyPairService.findOne(userKeyID);
if (key == null) {
throw new BadRequestException("User key: " + userKeyID + " was not found");
}
List<MessageParameter> parameters = new ArrayList();
MessageParameter keyParameter = new MessageParameter();
keyParameter.setName("sshkey");
if (version == 0) {
keyParameter.setName("sshkey");
}
if (version == 1) {
keyParameter.setName("user_ssh_key");
}
keyParameter.setValue(key.getPublicKey().getKey());
keyParameter.setEncoding("UTF-8");
parameters.add(keyParameter);
return parameters;
}
@PostFilter("(hasRole('ROLE_ADMIN'))")
public void deleteAll() {
provisionDao.deleteAll();
}
private ProvisionResponse callProvisioner0(ProvisionRequest provisionRequest) throws IOException, TimeoutException, JSONException, InterruptedException, Exception {
try (DRIPCaller provisioner = new ProvisionerCaller0(messageBrokerHost);) {
Message provisionerInvokationMessage = buildProvisioner0Message(provisionRequest);
Message response = (provisioner.call(provisionerInvokationMessage));
// Message response = MessageGenerator.generateArtificialMessage(System.getProperty("user.home")
// + File.separator + "workspace" + File.separator + "DRIP"
// + File.separator + "docs" + File.separator + "json_samples"
// + File.separator + "ec2_provisioner_provisoned3.json");
return parseCreateResourcesResponse(response.getParameters(), provisionRequest);
}
}
private ProvisionResponse callProvisioner1(ProvisionRequest provisionRequest) throws IOException, TimeoutException, JSONException, InterruptedException, Exception {
try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) {
Message provisionerInvokationMessage = buildProvisione1Message(provisionRequest);
Message response = (provisioner.call(provisionerInvokationMessage));
return parseCreateResourcesResponse(response.getParameters(), provisionRequest);
}
}
public void deleteProvisionedResources(ProvisionResponse provisionInfo) throws IOException, TimeoutException, InterruptedException, JSONException {
try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) {
Message deleteInvokationMessage = buildDeleteMessage(provisionInfo);
Message response = (provisioner.call(deleteInvokationMessage));
parseDeleteResourcesResponse(response.getParameters(), provisionInfo);
}
}
private Message buildProvisione1Message(ProvisionRequest provisionRequest) throws JSONException, FileNotFoundException, IOException {
Message invokationMessage = new Message();
List<MessageParameter> parameters = new ArrayList();
MessageParameter action = new MessageParameter();
action.setName("action");
action.setValue("start_topology");
parameters.add(action);
List<MessageParameter> topologies = buildTopologyParams(provisionRequest.getPlanID());
parameters.addAll(topologies);
List<String> userKeyIDs = provisionRequest.getUserKeyPairIDs();
if (userKeyIDs != null) {
for (String keyID : userKeyIDs) {
List<MessageParameter> userKeys = buildUserKeysParams(keyID, 1);
parameters.addAll(userKeys);
}
}
List<String> deployerKeys = provisionRequest.getDeployerKeyPairIDs();
if (userKeyIDs != null) {
for (String keyID : deployerKeys) {
List<MessageParameter> deplyMessageKey = buildDeployKeysParams(keyID);
parameters.addAll(deplyMessageKey);
}
}
for (String id : provisionRequest.getCloudCredentialsIDs()) {
CloudCredentials cred = cloudCredentialsService.findOne(id);
if (cred == null) {
throw new CloudCredentialsNotFoundException();
}
List<MessageParameter> cloudCredentialParams = buildCloudCredentialParam(cred, 1);
parameters.addAll(cloudCredentialParams);
}
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate((System.currentTimeMillis()));
return invokationMessage;
}
private Message buildDeleteMessage(ProvisionResponse provisionInfo) throws JSONException, IOException {
Message invokationMessage = new Message();
List<MessageParameter> parameters = new ArrayList();
MessageParameter action = new MessageParameter();
action.setName("action");
action.setValue("kill_topology");
parameters.add(action);
List<MessageParameter> topologies = buildProvisionedTopologyParams(provisionInfo);
parameters.addAll(topologies);
List<MessageParameter> clusterKeys = buildClusterKeyParams(provisionInfo);
parameters.addAll(clusterKeys);
List<MessageParameter> userKeys = buildUserKeyParams(provisionInfo);
parameters.addAll(userKeys);
List<MessageParameter> cloudKeys = buildCloudKeyParams(provisionInfo);
parameters.addAll(cloudKeys);
for (String id : provisionInfo.getCloudCredentialsIDs()) {
CloudCredentials cred = cloudCredentialsService.findOne(id);
if (cred == null) {
throw new CloudCredentialsNotFoundException();
}
List<MessageParameter> cloudCredentialParams = buildCloudCredentialParam(cred, 1);
parameters.addAll(cloudCredentialParams);
}
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate(System.currentTimeMillis());
return invokationMessage;
}
private List<MessageParameter> buildDeployKeysParams(String keyID) {
KeyPair key = keyPairService.findOne(keyID);
if (key == null) {
throw new BadRequestException("User key: " + keyID + " was not found");
}
List<MessageParameter> parameters = new ArrayList();
MessageParameter keyParameter = new MessageParameter();
keyParameter.setName("deployer_ssh_key");
keyParameter.setValue(key.getPublicKey().getKey());
keyParameter.setEncoding("UTF-8");
parameters.add(keyParameter);
return parameters;
}
private ProvisionResponse parseCreateResourcesResponse(List<MessageParameter> parameters, ProvisionRequest provisionRequest) throws Exception {
ProvisionResponse provisionResponse = new ProvisionResponse();
provisionResponse.setTimestamp(System.currentTimeMillis());
List<DeployParameter> deployParameters = new ArrayList<>();
Map<String, Object> kvMap = null;
KeyPair userKey = new KeyPair();
KeyPair deployerKey = new KeyPair();
Map<String, Key> privateCloudKeys = new HashMap<>();
Map<String, Key> publicCloudKeys = new HashMap<>();
for (MessageParameter p : parameters) {
String name = p.getName();
if (name.toLowerCase().contains("exception")) {
RuntimeException ex = ExceptionHandler.generateException(name, p.getValue());
Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex);
throw ex;
}
switch (name) {
case "deploy_parameters":
String value = p.getValue();
String[] lines = value.split("\n");
for (String line : lines) {
DeployParameter deployParam = new DeployParameter();
String[] parts = line.split(" ");
String deployIP = parts[0];
String deployUser = parts[1];
// String deployCertPath = parts[2];
// String cloudCertificateName = FilenameUtils.removeExtension(FilenameUtils.getBaseName(deployCertPath));
String deployRole = parts[2];
deployParam.setIP(deployIP);
deployParam.setRole(deployRole);
deployParam.setUser(deployUser);
// deployParam.setCloudCertificateName(cloudCertificateName);
deployParameters.add(deployParam);
}
break;
case "public_user_key":
Key key = new Key();
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PUBLIC);
userKey.setPublicKey(key);
break;
case "private_user_key":
key = new Key();
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PRIVATE);
userKey.setPrivateKey(key);
break;
case "private_deployer_key":
key = new Key();
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PRIVATE);
deployerKey.setPrivateKey(key);
break;
case "public_deployer_key":
key = new Key();
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PUBLIC);
deployerKey.setPublicKey(key);
break;
case "public_cloud_key":
key = new Key();
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PUBLIC);
key.setAttributes(p.getAttributes());
publicCloudKeys.put(p.getAttributes().get("key_pair_id"), key);
break;
case "private_cloud_key":
key = new Key();
key.setKey(p.getValue());
key.setName(p.getAttributes().get("name"));
key.setType(Key.KeyType.PRIVATE);
key.setAttributes(p.getAttributes());
privateCloudKeys.put(p.getAttributes().get("key_pair_id"), key);
break;
default:
value = p.getValue();
if (kvMap == null) {
kvMap = new HashMap();
}
kvMap.put(name, Converter.ymlString2Map(value));
break;
}
}
List<String> userKeyIds = provisionRequest.getUserKeyPairIDs();
if (userKeyIds != null && !userKeyIds.isEmpty()) {
} else {
userKeyIds = new ArrayList<>();
if (userKey.getPublicKey() != null) {
userKey = keyPairService.save(userKey);
userKeyIds.add(userKey.getId());
}
}
ArrayList<String> deployerKeyIds = new ArrayList<>();
if (deployerKey.getPublicKey() != null) {
deployerKey = keyPairService.save(deployerKey);
deployerKeyIds.add(deployerKey.getId());
}
ArrayList<String> cloudKeyPairIDs = new ArrayList<>();
for (String id : publicCloudKeys.keySet()) {
KeyPair cloudPair = new KeyPair();
cloudPair.setPrivateKey(privateCloudKeys.get(id));
cloudPair.setPublicKey(publicCloudKeys.get(id));
cloudPair.setKeyPairId(id);
cloudPair = keyPairService.save(cloudPair);
cloudKeyPairIDs.add(cloudPair.getId());
}
provisionResponse.setCloudKeyPairIDs(cloudKeyPairIDs);
provisionResponse.setDeployParameters(deployParameters);
provisionResponse.setKvMap(kvMap);
provisionResponse.setCloudCredentialsIDs(provisionRequest.getCloudCredentialsIDs());
provisionResponse.setUserKeyPairIDs(userKeyIds);
provisionResponse.setDeployerKeyPairIDs(deployerKeyIds);
provisionResponse.setPlanID(provisionRequest.getPlanID());
provisionResponse = save(provisionResponse);
return provisionResponse;
}
private void parseDeleteResourcesResponse(List<MessageParameter> parameters, ProvisionResponse provisionInfo) {
// for (MessageParameter p : parameters) {
// System.err.println(p.getName() + " : " + p.getValue());
// }
}
}
......@@ -21,8 +21,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import nl.uva.sne.drip.api.dao.ScriptDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.data.v1.external.Script;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.Script;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.core.context.SecurityContextHolder;
......
......@@ -29,10 +29,10 @@ import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.api.dao.PlanDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import nl.uva.sne.drip.data.internal.Message;
import nl.uva.sne.drip.data.internal.MessageParameter;
import nl.uva.sne.drip.data.v1.external.PlanResponse;
import nl.uva.sne.drip.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.drip.commons.data.internal.Message;
import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -105,7 +105,7 @@ public class SimplePlannerService {
}
Map<String, Object> map = t2.getKeyValue();
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
ymlStr = ymlStr.replaceAll("\\uff0E", ".");
byte[] bytes = ymlStr.getBytes();
Message invokationMessage = new Message();
......@@ -145,16 +145,16 @@ public class SimplePlannerService {
if (fromat != null && fromat.equals("yml")) {
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
ymlStr = ymlStr.replaceAll("\\uff0E", ".");
return ymlStr;
}
if (fromat != null && fromat.equals("json")) {
String jsonStr = Converter.map2JsonString(map);
jsonStr = jsonStr.replaceAll("\\uff0E", "\\.");
jsonStr = jsonStr.replaceAll("\\uff0E", ".");
return jsonStr;
}
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
ymlStr = ymlStr.replaceAll("\\uff0E", ".");
return ymlStr;
}
......
......@@ -21,9 +21,9 @@ import java.util.Map;
import nl.uva.sne.drip.api.dao.ToscaDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.commons.utils.Constants;
import nl.uva.sne.drip.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
......@@ -54,16 +54,16 @@ public class ToscaService {
if (fromat != null && fromat.equals("yml")) {
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
ymlStr = ymlStr.replaceAll("\\uff0E", ".");
return ymlStr;
}
if (fromat != null && fromat.equals("json")) {
String jsonStr = Converter.map2JsonString(map);
jsonStr = jsonStr.replaceAll("\\uff0E", "\\.");
jsonStr = jsonStr.replaceAll("\\uff0E", ".");
return jsonStr;
}
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
ymlStr = ymlStr.replaceAll("\\uff0E", ".");
return ymlStr;
}
......
......@@ -19,7 +19,7 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.api.dao.UserDao;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
......
......@@ -23,7 +23,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.exception.KeyException;
import nl.uva.sne.drip.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -35,9 +35,9 @@ import nl.uva.sne.drip.api.exception.NullKeyIDException;
import nl.uva.sne.drip.api.service.CloudCredentialsService;
import nl.uva.sne.drip.api.service.KeyPairService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v0.external.Configure;
import nl.uva.sne.drip.data.v1.external.Key;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v0.external.Configure;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -62,7 +62,7 @@ public class CloudConfigurationController0 {
@RequestMapping(value = "/ec2", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String postEC2Conf(@RequestBody Configure configure) {
String postEC2Conf(@RequestBody Configure configure) throws Exception {
if (configure.key == null) {
throw new NullKeyException();
}
......@@ -76,9 +76,9 @@ public class CloudConfigurationController0 {
List<String> loginKeyIDs = new ArrayList<>();
for (nl.uva.sne.drip.data.v0.external.LoginKey0 key0 : configure.loginKey) {
for (nl.uva.sne.drip.drip.commons.data.v0.external.LoginKey0 key0 : configure.loginKey) {
try {
nl.uva.sne.drip.data.v1.external.Key key1 = new nl.uva.sne.drip.data.v1.external.Key();
nl.uva.sne.drip.drip.commons.data.v1.external.Key key1 = new nl.uva.sne.drip.drip.commons.data.v1.external.Key();
KeyPair pair = new KeyPair();
pair.setTimestamp(System.currentTimeMillis());
key1.setKey(key0.content);
......@@ -102,7 +102,7 @@ public class CloudConfigurationController0 {
@RequestMapping(value = "/geni", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String postGeniConf(@RequestBody Configure configure) {
String postGeniConf(@RequestBody Configure configure) throws Exception {
if (configure.geniKey == null) {
throw new NullKeyException();
}
......@@ -117,9 +117,9 @@ public class CloudConfigurationController0 {
List<String> loginKeyIDs = new ArrayList<>();
for (nl.uva.sne.drip.data.v0.external.LoginKey0 key0 : configure.loginPubKey) {
for (nl.uva.sne.drip.drip.commons.data.v0.external.LoginKey0 key0 : configure.loginPubKey) {
try {
nl.uva.sne.drip.data.v1.external.Key key1 = new nl.uva.sne.drip.data.v1.external.Key();
nl.uva.sne.drip.drip.commons.data.v1.external.Key key1 = new nl.uva.sne.drip.drip.commons.data.v1.external.Key();
key1.setKey(key0.content);
key1.setType(Key.KeyType.PUBLIC);
KeyPair pair = new KeyPair();
......@@ -132,9 +132,9 @@ public class CloudConfigurationController0 {
}
}
for (nl.uva.sne.drip.data.v0.external.LoginKey0 key0 : configure.loginPriKey) {
for (nl.uva.sne.drip.drip.commons.data.v0.external.LoginKey0 key0 : configure.loginPriKey) {
try {
nl.uva.sne.drip.data.v1.external.Key key1 = new nl.uva.sne.drip.data.v1.external.Key();
nl.uva.sne.drip.drip.commons.data.v1.external.Key key1 = new nl.uva.sne.drip.drip.commons.data.v1.external.Key();
key1.setKey(key0.content);
key1.setType(Key.KeyType.PRIVATE);
KeyPair pair = new KeyPair();
......
......@@ -17,6 +17,8 @@ package nl.uva.sne.drip.api.v0.rest;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -25,12 +27,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.DeployService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v0.external.Deploy;
import nl.uva.sne.drip.data.v0.external.Attribute;
import nl.uva.sne.drip.data.v0.external.Result;
import nl.uva.sne.drip.data.v1.external.DeployRequest;
import nl.uva.sne.drip.data.v1.external.DeployResponse;
import nl.uva.sne.drip.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v0.external.Deploy;
import nl.uva.sne.drip.drip.commons.data.v0.external.Attribute;
import nl.uva.sne.drip.drip.commons.data.v0.external.Result;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
......@@ -55,23 +57,33 @@ public class DeployController0 {
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result deployKubernetes(@RequestBody Deploy deploy) {
DeployRequest deployReq = new DeployRequest();
deployReq.setManagerType("kubernetes");
deployReq.setProvisionID(deploy.action);
return deploy(deployReq);
try {
DeployRequest deployReq = new DeployRequest();
deployReq.setManagerType("kubernetes");
deployReq.setProvisionID(deploy.action);
return deploy(deployReq);
} catch (Exception ex) {
Logger.getLogger(DeployController0.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
@RequestMapping(value = "/swarm", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result deploySwarm(@RequestBody Deploy deploy) {
DeployRequest deployReq = new DeployRequest();
deployReq.setManagerType("swarm");
deployReq.setProvisionID(deploy.action);
return deploy(deployReq);
try {
DeployRequest deployReq = new DeployRequest();
deployReq.setManagerType("swarm");
deployReq.setProvisionID(deploy.action);
return deploy(deployReq);
} catch (Exception ex) {
Logger.getLogger(DeployController0.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
private Result deploy(DeployRequest deployReq) {
private Result deploy(DeployRequest deployReq) throws Exception {
DeployResponse key = deployService.deploySoftware(deployReq);
......
......@@ -21,7 +21,7 @@ import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.data.v0.external.Result;
import nl.uva.sne.drip.drip.commons.data.v0.external.Result;
import javax.annotation.security.RolesAllowed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -33,8 +33,8 @@ import nl.uva.sne.drip.api.service.PlannerService;
import nl.uva.sne.drip.api.service.ToscaService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.data.v0.external.Attribute;
import nl.uva.sne.drip.data.v0.external.Plan;
import nl.uva.sne.drip.drip.commons.data.v0.external.Attribute;
import nl.uva.sne.drip.drip.commons.data.v0.external.Plan;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -65,7 +65,7 @@ public class PlannerController0 {
String yaml = plan0.file;
yaml = yaml.replaceAll("\\\\n", "\n");
String id = toscaService.saveYamlString(yaml, null);
nl.uva.sne.drip.data.v1.external.PlanResponse plan1 = plannerService.getPlan(id);
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse plan1 = plannerService.getPlan(id,"swarm");
Result r = new Result();
r.info = ("INFO");
......@@ -76,7 +76,7 @@ public class PlannerController0 {
files.add(e);
for (String lowiID : plan1.getLoweLevelPlanIDs()) {
nl.uva.sne.drip.data.v1.external.PlanResponse lowPlan1 = plannerService.findOne(lowiID);
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse lowPlan1 = plannerService.findOne(lowiID);
e = Converter.plan1toFile(lowPlan1);
files.add(e);
//Don't save them cause they will be re-uploaded in the provision step
......
......@@ -16,7 +16,7 @@
package nl.uva.sne.drip.api.v0.rest;
import java.io.IOException;
import nl.uva.sne.drip.data.v1.external.ProvisionRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionRequest;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
......@@ -39,13 +39,13 @@ import nl.uva.sne.drip.api.service.ProvisionService;
import nl.uva.sne.drip.api.service.KeyPairService;
import nl.uva.sne.drip.api.service.ScriptService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v0.external.Execute;
import nl.uva.sne.drip.data.v0.external.Attribute;
import nl.uva.sne.drip.data.v0.external.Result;
import nl.uva.sne.drip.data.v0.external.Upload;
import nl.uva.sne.drip.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.drip.commons.data.v0.external.Execute;
import nl.uva.sne.drip.drip.commons.data.v0.external.Attribute;
import nl.uva.sne.drip.drip.commons.data.v0.external.Result;
import nl.uva.sne.drip.drip.commons.data.v0.external.Upload;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -90,12 +90,12 @@ public class ProvisionController0 {
List<String> idList = new ArrayList<>();
idList.add(cloudCredID);
resp.setCloudCredentialsIDs(idList);
List<nl.uva.sne.drip.data.v0.external.Attribute> plans = upload.file;
nl.uva.sne.drip.data.v1.external.PlanResponse topLevelPlan = null;
List<nl.uva.sne.drip.drip.commons.data.v0.external.Attribute> plans = upload.file;
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse topLevelPlan = null;
Set<String> loweLevelPlansIDs = new HashSet<>();
for (nl.uva.sne.drip.data.v0.external.Attribute p : plans) {
nl.uva.sne.drip.data.v1.external.PlanResponse plan1 = Converter.File2Plan1(p);
for (nl.uva.sne.drip.drip.commons.data.v0.external.Attribute p : plans) {
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse plan1 = Converter.File2Plan1(p);
if (plan1.getLevel() == 0) {
topLevelPlan = plan1;
} else {
......@@ -114,7 +114,7 @@ public class ProvisionController0 {
String userKeyID = keyPair.getId();
keyPairIDs.add(userKeyID);
}
resp.setKeyPairIDs(keyPairIDs);
resp.setUserKeyPairIDs(keyPairIDs);
}
resp = provisionService.save(resp);
return "Success: Infrastructure files are uploaded! Action number: "
......@@ -128,7 +128,7 @@ public class ProvisionController0 {
try {
ProvisionRequest req = provisionService.findOne(exc.action);
req = provisionService.provisionResources(req);
req = provisionService.provisionResources(req,0);
Map<String, Object> map = req.getKeyValue();
String yaml = Converter.map2YmlString(map);
yaml = yaml.replaceAll("\n", "\\\\n");
......@@ -146,6 +146,8 @@ public class ProvisionController0 {
return res;
} catch (IOException | TimeoutException | JSONException | InterruptedException ex) {
Logger.getLogger(ProvisionController0.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(ProvisionController0.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
......
......@@ -21,7 +21,7 @@ import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.exception.PasswordNullException;
import nl.uva.sne.drip.api.exception.UserExistsException;
import nl.uva.sne.drip.api.exception.UserNullException;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -29,7 +29,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v0.external.Register;
import nl.uva.sne.drip.drip.commons.data.v0.external.Register;
import org.springframework.http.MediaType;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
......
......@@ -30,11 +30,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.KeyPairService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v0.external.ConfUserKey;
import nl.uva.sne.drip.data.v1.external.Key;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.data.v1.external.ProvisionRequest;
import nl.uva.sne.drip.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.drip.commons.data.v0.external.ConfUserKey;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -59,7 +59,7 @@ public class UserPublicKeysController0 {
@RequestMapping(value = "/confuserkey", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String uploadUserPublicKeys(@RequestBody ConfUserKey confUserKey) {
String uploadUserPublicKeys(@RequestBody ConfUserKey confUserKey) throws Exception {
try {
KeyPair pair = new KeyPair();
Key upk = new Key();
......@@ -72,7 +72,7 @@ public class UserPublicKeysController0 {
ProvisionResponse provPlan = provisionService.findOne(confUserKey.action);
List<String> keyPairIDs = new ArrayList<>();
keyPairIDs.add(pair.getId());
provPlan.setKeyPairIDs(keyPairIDs);
provPlan.setUserKeyPairIDs(keyPairIDs);
provisionService.save(provPlan);
return "Success: " + pair.getId();
......
......@@ -23,9 +23,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.ScriptService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v0.external.ConfScript;
import nl.uva.sne.drip.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.data.v1.external.Script;
import nl.uva.sne.drip.drip.commons.data.v0.external.ConfScript;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.Script;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
......
......@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v1.external.ansible.AnsibleOutput;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
......
......@@ -23,15 +23,13 @@ import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.service.BenchmarkResultService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v1.external.ansible.BenchmarkResult;
import nl.uva.sne.drip.data.v1.external.ansible.BenchmarkResult;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
......
......@@ -26,7 +26,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import javax.ws.rs.core.MediaType;
import nl.uva.sne.drip.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -40,8 +40,8 @@ import nl.uva.sne.drip.api.exception.NullKeyException;
import nl.uva.sne.drip.api.service.CloudCredentialsService;
import nl.uva.sne.drip.api.service.KeyPairService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v1.external.Key;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -105,11 +105,12 @@ public class CloudCredentialsController {
* @param file
* @param id
* @return the CloudCredentials id
* @throws java.lang.Exception
*/
@RequestMapping(value = "/upload/{id}", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String addLogineKey(@RequestParam("file") MultipartFile file, @PathVariable("id") String id) {
String addLogineKey(@RequestParam("file") MultipartFile file, @PathVariable("id") String id) throws Exception {
try {
CloudCredentials cloudCredentials = cloudCredentialsService.findOne(id);
......@@ -206,16 +207,19 @@ public class CloudCredentialsController {
@RequestMapping(value = "/sample", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
CloudCredentials geta() {
CloudCredentials getSample() {
CloudCredentials cloudCredentials = new CloudCredentials();
cloudCredentials.setTimestamp(System.currentTimeMillis());
cloudCredentials.setAccessKeyId("AKIAITY3KHZUQ6M7YBSQ");
cloudCredentials.setCloudProviderName("ec2");
cloudCredentials.setSecretKey("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");
cloudCredentials.setAccessKeyId("AKIAITWERHZUQ6M7YBSQ");
cloudCredentials.setCloudProviderName("egi");
cloudCredentials.setSecretKey("6J7uo99ifrff45sa6Gsy5vgb3b3ewdsdtwY6hBxtYt9y");
List<String> keyIDs = new ArrayList<>();
keyIDs.add("58da4c91f7b43a3282cacdbb");
keyIDs.add("58da4d2af7b43a3282cacdbd");
cloudCredentials.setKeyIDs(keyIDs);
Map<String, Object> attributes = new HashMap<>();
attributes.put("myProxyEndpoint", "myproxy.egee.host.com");
attributes.put("trustedCertificatesURL", "https://dist.eugridpma.info/distribution/igtf/current/accredited/igtf-preinstalled-bundle-classic.tar.gz");
cloudCredentials.setAttributes(attributes);
return cloudCredentials;
}
......
......@@ -17,7 +17,7 @@ package nl.uva.sne.drip.api.v1.rest;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import nl.uva.sne.drip.data.v1.external.PlaybookRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlaybookRepresentation;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
......
......@@ -19,6 +19,8 @@ import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.NotFoundException;
......@@ -29,8 +31,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.DeployService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v1.external.DeployRequest;
import nl.uva.sne.drip.data.v1.external.DeployResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -56,14 +58,19 @@ public class DeployController {
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String deploy(@RequestBody DeployRequest deployRequest) {
if (deployRequest.getManagerType() == null) {
throw new BadRequestException("Must provide manager type. Aveliable: ansible, swarm ,kubernetes");
try {
if (deployRequest.getManagerType() == null) {
throw new BadRequestException("Must provide manager type. Aveliable: ansible, swarm ,kubernetes");
}
if (deployRequest.getProvisionID() == null) {
throw new BadRequestException("Must provide provision ID");
}
DeployResponse deploy = deployService.deploySoftware(deployRequest);
return deploy.getId();
} catch (Exception ex) {
Logger.getLogger(DeployController.class.getName()).log(Level.SEVERE, null, ex);
}
if (deployRequest.getProvisionID() == null) {
throw new BadRequestException("Must provide provision ID");
}
DeployResponse deploy = deployService.deploySoftware(deployRequest);
return deploy.getId();
return null;
}
@RequestMapping(value = "/sample", method = RequestMethod.GET)
......
......@@ -17,7 +17,7 @@ package nl.uva.sne.drip.api.v1.rest;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import nl.uva.sne.drip.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -36,7 +36,7 @@ import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.exception.NullKeyException;
import nl.uva.sne.drip.api.service.KeyPairService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -136,7 +136,7 @@ public class KeyPairController {
@RequestMapping(value = "/sample", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
KeyPair geta() {
KeyPair geta() throws Exception {
try {
KeyPair pair = new KeyPair();
pair.setTimestamp(System.currentTimeMillis());
......
......@@ -19,7 +19,9 @@ import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -34,8 +36,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.PlannerService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v1.external.PlanResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
/**
......@@ -51,7 +54,7 @@ import org.springframework.web.bind.annotation.RequestParam;
@ResponseCode(code = 401, condition = "Bad credentials")
})
public class PlannerController {
@Autowired
private PlannerService plannerService;
......@@ -67,7 +70,7 @@ public class PlannerController {
String plan(@PathVariable("tosca_id") String toscaId) {
try {
PlanResponse plan = plannerService.getPlan(toscaId);
PlanResponse plan = plannerService.getPlan(toscaId, "swarm");
if (plan == null) {
throw new NotFoundException("Could not make plan");
}
......@@ -145,9 +148,39 @@ public class PlannerController {
List<PlanResponse> all = plannerService.findAll();
List<String> ids = new ArrayList<>();
for (PlanResponse tr : all) {
ids.add(tr.getId());
if (tr.getLevel() == 0) {
ids.add(tr.getId());
}
}
return ids;
}
@RequestMapping(value = "/post/{name}", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String postTop(@RequestBody String toscaContents, @PathVariable("name") String name) {
return plannerService.saveStringContents(toscaContents, 0, name);
}
@RequestMapping(value = "/post/{level}/{name}/{id}", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String postLow(@RequestBody String toscaContents, @PathVariable("level") String level, @PathVariable("name") String name, @PathVariable("id") String id) {
int intLevel = Integer.valueOf(level);
if (intLevel == 0) {
return plannerService.saveStringContents(toscaContents, 0, name);
}
PlanResponse topPlan = plannerService.findOne(id);
Set<String> lowIDs = topPlan.getLoweLevelPlanIDs();
if (lowIDs == null) {
lowIDs = new HashSet<>();
}
String lowPlanID = plannerService.saveStringContents(toscaContents, intLevel, name);
lowIDs.add(lowPlanID);
topPlan.setLoweLevelPlansIDs(lowIDs);
topPlan = plannerService.save(topPlan);
return topPlan.getId();
}
}
......@@ -17,7 +17,7 @@ package nl.uva.sne.drip.api.v1.rest;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import nl.uva.sne.drip.data.v1.external.ProvisionRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
......@@ -35,7 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.service.ProvisionService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse;
import org.json.JSONException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -72,6 +72,10 @@ public class ProvisionController {
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
ProvisionResponse get(@PathVariable("id") String id) {
ProvisionResponse pro = provisionService.findOne(id);
if (pro == null) {
throw new NotFoundException();
}
return provisionService.findOne(id);
}
......@@ -85,10 +89,15 @@ public class ProvisionController {
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String delete(@PathVariable("id") String id) {
ProvisionRequest provPlan = provisionService.findOne(id);
ProvisionResponse provPlan = provisionService.findOne(id);
if (provPlan != null) {
provisionService.delete(id);
return "Deleted : " + id;
try {
provisionService.deleteProvisionedResources(provPlan);
ProvisionResponse provisionInfo = provisionService.delete(id);
return "Deleted : " + id;
} catch (IOException | TimeoutException | InterruptedException | JSONException ex) {
Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex);
}
}
throw new NotFoundException();
}
......@@ -99,7 +108,6 @@ public class ProvisionController {
String deleteAll() {
provisionService.deleteAll();
return "Done";
}
/**
......@@ -137,12 +145,14 @@ public class ProvisionController {
throw new BadRequestException();
}
try {
req = provisionService.provisionResources(req);
req = provisionService.provisionResources(req, 1);
return req.getId();
} catch (IOException | TimeoutException | JSONException | InterruptedException ex) {
Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
......@@ -158,7 +168,7 @@ public class ProvisionController {
req.setCloudCredentialsIDs(cloudCredentialsIDs);
List<String> keyPairIDs = new ArrayList<>();
keyPairIDs.add("58f8da042af45d6621813c4e");
req.setKeyPairIDs(keyPairIDs);
req.setUserKeyPairIDs(keyPairIDs);
req.setPlanID("58da51f7f7b42e7d967752a1");
return req;
}
......
......@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.data.v1.external.Script;
import nl.uva.sne.drip.drip.commons.data.v1.external.Script;
import org.springframework.web.bind.annotation.PathVariable;
import nl.uva.sne.drip.api.service.ScriptService;
import nl.uva.sne.drip.api.service.UserService;
......
......@@ -17,7 +17,7 @@ package nl.uva.sne.drip.api.v1.rest;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import nl.uva.sne.drip.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
......
......@@ -26,7 +26,7 @@ import nl.uva.sne.drip.api.exception.PasswordNullException;
import nl.uva.sne.drip.api.exception.UserExistsException;
import nl.uva.sne.drip.api.exception.UserNotFoundException;
import nl.uva.sne.drip.api.exception.UserNullException;
import nl.uva.sne.drip.data.v1.external.User;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>drip-commons</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.0.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-core</artifactId>
<version>2.5.6.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-core-annotations</artifactId>
<version>2.8.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.17</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.2.1.RELEASE</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
......@@ -26,17 +26,18 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import nl.uva.sne.drip.data.v0.external.Attribute;
import nl.uva.sne.drip.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.data.internal.Message;
import nl.uva.sne.drip.data.internal.MessageParameter;
import nl.uva.sne.drip.data.v1.external.PlanResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import org.apache.commons.io.FilenameUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.yaml.snakeyaml.Yaml;
import nl.uva.sne.drip.drip.commons.data.internal.Message;
import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter;
import nl.uva.sne.drip.drip.commons.data.v0.external.Attribute;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse;
/**
*
* @author S. Koulouzis
......@@ -61,7 +62,7 @@ public class Converter {
return (Map<String, Object>) object;
}
public static Map<String, Object> ymlString2Map(InputStream in) {
public static Map<String, Object> ymlStream2Map(InputStream in) {
Yaml yaml = new Yaml();
Map<String, Object> map = (Map<String, Object>) yaml.load(in);
return map;
......
......@@ -20,9 +20,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.data.internal.Message;
import org.apache.commons.io.FileUtils;
import org.json.JSONException;
import nl.uva.sne.drip.drip.commons.data.internal.Message;
import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter;
/**
*
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.internal;
package nl.uva.sne.drip.drip.commons.data.internal;
import java.io.Serializable;
import java.util.List;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.internal;
package nl.uva.sne.drip.drip.commons.data.internal;
import java.io.Serializable;
import java.util.Map;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v0.external;
package nl.uva.sne.drip.drip.commons.data.v0.external;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import javax.xml.bind.annotation.XmlAttribute;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v0.external;
package nl.uva.sne.drip.drip.commons.data.v0.external;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import javax.xml.bind.annotation.XmlRootElement;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v0.external;
package nl.uva.sne.drip.drip.commons.data.v0.external;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v0.external;
package nl.uva.sne.drip.drip.commons.data.v0.external;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.util.List;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v0.external;
package nl.uva.sne.drip.drip.commons.data.v0.external;
import javax.xml.bind.annotation.XmlRootElement;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v0.external;
package nl.uva.sne.drip.drip.commons.data.v0.external;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import javax.xml.bind.annotation.XmlRootElement;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v0.external;
package nl.uva.sne.drip.drip.commons.data.v0.external;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v0.external;
package nl.uva.sne.drip.drip.commons.data.v0.external;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.io.Serializable;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v0.external;
package nl.uva.sne.drip.drip.commons.data.v0.external;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import javax.xml.bind.annotation.XmlRootElement;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v0.external;
package nl.uva.sne.drip.drip.commons.data.v0.external;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.util.List;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v0.external;
package nl.uva.sne.drip.drip.commons.data.v0.external;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
......
......@@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.util.List;
import java.util.Map;
import org.springframework.data.mongodb.core.mapping.Document;
/**
......@@ -26,19 +28,23 @@ import org.springframework.data.mongodb.core.mapping.Document;
* @author S. Koulouzis
*/
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CloudCredentials extends OwnedObject {
public static String ACCESS_KEY_NAME = "accessKeyId";
public static String SECRET_KEY_NAME = "secretKey";
private String secretKey;
private String accessKeyId;
private List<String> keyPairIDs;
private List<KeyPair> keyPairs;
private String cloudProviderName;
private Map<String, Object> attributes;
/**
* It is the secret key / password for accessing a cloud provider.
*
......@@ -71,7 +77,7 @@ public class CloudCredentials extends OwnedObject {
}
/**
* The access key ID for a cloud provider.
* The access key ID / user name for a cloud provider.
*
* @return the accessKeyId
*/
......@@ -103,4 +109,32 @@ public class CloudCredentials extends OwnedObject {
public void setKeyIDs(List<String> keyIDs) {
this.keyPairIDs = keyIDs;
}
/**
* @return the keyPairs
*/
public List<KeyPair> getKeyPairs() {
return keyPairs;
}
/**
* @param keyPairs the keyPairs to set
*/
public void setKeyPairs(List<KeyPair> keyPairs) {
this.keyPairs = keyPairs;
}
/**
* @return the attributes
*/
public Map<String, Object> getAttributes() {
return attributes;
}
/**
* @param attributes the attributes to set
*/
public void setAttributes(Map<String, Object> attributes) {
this.attributes = attributes;
}
}
......@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
/**
......@@ -25,31 +26,32 @@ import com.webcohesion.enunciate.metadata.DocumentationExample;
*
* @author S. Koulouzis
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DeployParameter {
private String cloudCertificateName;
// private String cloudCertificateName;
private String IP;
private String user;
private String role;
/**
* The file name of the certificate used to log in as root to the
* provisioned VM.
* @return the cloudCertificateName
*/
@DocumentationExample("Virginia")
public String getCloudCertificateName() {
return cloudCertificateName;
}
/**
* @param cloudCertificateName the cloudCertificateName to set
*/
public void setCloudCertificateName(String cloudCertificateName) {
this.cloudCertificateName = cloudCertificateName;
}
// /**
// * The file name of the certificate used to log in as root to the
// * provisioned VM.
// * @return the cloudCertificateName
// */
// @DocumentationExample("Virginia")
// public String getCloudCertificateName() {
// return cloudCertificateName;
// }
//
// /**
// * @param cloudCertificateName the cloudCertificateName to set
// */
// public void setCloudCertificateName(String cloudCertificateName) {
// this.cloudCertificateName = cloudCertificateName;
// }
/**
* The public IP of the provisioned VM
......
......@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
/**
......@@ -23,6 +24,7 @@ import com.webcohesion.enunciate.metadata.DocumentationExample;
*
* @author S. Koulouzis
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DeployRequest extends OwnedObject {
private String provisionID;
......
......@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;
import nl.uva.sne.drip.data.v1.external.ansible.AnsibleOutput;
import org.springframework.data.mongodb.core.mapping.Document;
......@@ -27,6 +28,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
* @author S. Koulouzis
*/
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DeployResponse extends DeployRequest {
private KeyPair key;
......
......@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.util.Map;
......@@ -25,6 +26,7 @@ import java.util.Map;
*
* @author S. Koulouzis
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Key{
private Map<String, String> attributes;
......
......@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import nl.uva.sne.drip.api.exception.KeyException;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
/**
......@@ -31,6 +31,8 @@ public class KeyPair extends OwnedObject {
private Key privateKey;
private Key publicKey;
@Indexed
private String keyPairId;
/**
* @return the privateKey
......@@ -41,11 +43,11 @@ public class KeyPair extends OwnedObject {
/**
* @param privateKey the privateKey to set
* @throws nl.uva.sne.drip.api.exception.KeyException
* @throws java.lang.Exception
*/
public void setPrivateKey(Key privateKey) throws KeyException {
public void setPrivateKey(Key privateKey) throws Exception {
if (privateKey != null && privateKey.getType() != Key.KeyType.PRIVATE) {
throw new KeyException("Trying to add public key to private");
throw new Exception("Trying to add public key to private");
}
this.privateKey = privateKey;
}
......@@ -59,13 +61,27 @@ public class KeyPair extends OwnedObject {
/**
* @param publicKey the publicKey to set
* @throws nl.uva.sne.drip.api.exception.KeyException
* @throws java.lang.Exception
*/
public void setPublicKey(Key publicKey) throws KeyException {
public void setPublicKey(Key publicKey) throws Exception {
if (publicKey != null && publicKey.getType() != Key.KeyType.PUBLIC) {
throw new KeyException("Trying to add private to public");
throw new Exception("Trying to add private to public");
}
this.publicKey = publicKey;
}
/**
* @return the keyPairId
*/
public String getKeyPairId() {
return keyPairId;
}
/**
* @param keyPairId the keyPairId to set
*/
public void setKeyPairId(String keyPairId) {
this.keyPairId = keyPairId;
}
}
......@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.util.Map;
import org.springframework.data.mongodb.core.mapping.Document;
......@@ -26,6 +27,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
* @author S. Koulouzis
*/
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class KeyValueHolder extends OwnedObject{
private Map<String, Object> keyValue;
......
......@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull;
......@@ -27,6 +28,7 @@ import org.springframework.data.annotation.Id;
* @author S. Koulouzis
*/
@MappedSuperclass
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OwnedObject {
@Id
......
......@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.util.Set;
import org.springframework.data.mongodb.core.mapping.Document;
......@@ -26,6 +27,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
* @author S. Koulouzis
*/
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PlanResponse extends KeyValueHolder {
private String toscaID;
......
......@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.data.mongodb.core.mapping.Document;
/**
......@@ -23,5 +24,6 @@ import org.springframework.data.mongodb.core.mapping.Document;
* @author S. Koulouzis
*/
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PlaybookRepresentation extends KeyValueHolder {
}
......@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import java.util.List;
import org.springframework.data.mongodb.core.mapping.Document;
......@@ -26,13 +27,16 @@ import org.springframework.data.mongodb.core.mapping.Document;
* @author S. Koulouzis
*/
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProvisionRequest extends KeyValueHolder {
private List<String> cloudCredentialsIDs;
private String planID;
private List<String> keyPairIDs;
private List<String> userKeyPairIDs;
private List<String> deployerKeyPairIDs;
/**
* The cloud credentials ids required to provision the cloud resources.
......@@ -70,18 +74,33 @@ public class ProvisionRequest extends KeyValueHolder {
/**
* The key pair id for the keys to use to log in the provisioned VMs.
* @return the keyPairIDs
*
* @return the userKeyPairIDs
*/
@DocumentationExample("ASedsfd46b4fFd344a1A")
public List<String> getUserKeyPairIDs() {
return userKeyPairIDs;
}
/**
* @param userKeyID the userKeyPairIDs to set
*/
@DocumentationExample("ASedsfd46b4fFd344a1A")
public List<String> getKeyPairIDs() {
return keyPairIDs;
public void setUserKeyPairIDs(List<String> userKeyID) {
this.userKeyPairIDs = userKeyID;
}
/**
* @param userKeyID the keyPairIDs to set
* @return the deployerKeyPairIDs
*/
public void setKeyPairIDs(List<String> userKeyID) {
this.keyPairIDs = userKeyID;
public List<String> getDeployerKeyPairIDs() {
return deployerKeyPairIDs;
}
/**
* @param deployerKeyPairIDs the deployerKeyPairIDs to set
*/
public void setDeployerKeyPairIDs(List<String> deployerKeyPairIDs) {
this.deployerKeyPairIDs = deployerKeyPairIDs;
}
}
......@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -22,9 +24,11 @@ import java.util.List;
*
* @author S. Koulouzis
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProvisionResponse extends ProvisionRequest {
private List<DeployParameter> deployParameters;
private ArrayList<String> cloudKeyPairIDs;
/**
* The deploy parameters.
......@@ -42,4 +46,15 @@ public class ProvisionResponse extends ProvisionRequest {
this.deployParameters = deployParameters;
}
public void setCloudKeyPairIDs(ArrayList<String> cloudKeyPairIDs) {
this.cloudKeyPairIDs = cloudKeyPairIDs;
}
/**
* @return the cloudKeyPairIDs
*/
public ArrayList<String> getCloudKeyPairIDs() {
return cloudKeyPairIDs;
}
}
......@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
......@@ -25,6 +25,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
* @author S. Koulouzis
*/
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Script extends OwnedObject {
private String contents;
......
......@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
......@@ -25,6 +25,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
* @author S. Koulouzis
*/
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ToscaRepresentation extends KeyValueHolder {
private String name;
......
......@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external;
package nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import com.webcohesion.enunciate.metadata.DocumentationExample;
......@@ -34,6 +35,7 @@ import org.springframework.security.core.userdetails.UserDetails;
* @author S. Koulouzis
*/
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class User implements UserDetails {
@Id
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external.ansible;
package nl.uva.sne.drip.drip.commons.data.v1.external.ansible;
/**
*
......@@ -22,7 +22,7 @@ package nl.uva.sne.drip.data.v1.external.ansible;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import nl.uva.sne.drip.data.v1.external.OwnedObject;
import nl.uva.sne.drip.drip.commons.data.v1.external.OwnedObject;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
......@@ -52,6 +52,10 @@ public class AnsibleOutput extends OwnedObject {
@JsonProperty("provisionID")
private String provisionID;
@Indexed
@JsonProperty("cloudProvider")
private String cloudProvider;
@JsonProperty("host")
public String getHost() {
return host;
......@@ -101,4 +105,22 @@ public class AnsibleOutput extends OwnedObject {
public String getProvisionID() {
return provisionID;
}
public void setCloudProviderName(String cloudProvider) {
this.setCloudProvider(cloudProvider);
}
/**
* @return the cloudProvider
*/
public String getCloudProvider() {
return cloudProvider;
}
/**
* @param cloudProvider the cloudProvider to set
*/
public void setCloudProvider(String cloudProvider) {
this.cloudProvider = cloudProvider;
}
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external.ansible;
package nl.uva.sne.drip.drip.commons.data.v1.external.ansible;
/**
*
......
/*
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
......@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external.ansible;
package nl.uva.sne.drip.drip.commons.data.v1.external.ansible;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Date;
import nl.uva.sne.drip.data.v1.external.OwnedObject;
import nl.uva.sne.drip.drip.commons.data.v1.external.OwnedObject;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
......@@ -33,8 +33,8 @@ public class BenchmarkResult extends OwnedObject {
private String host;
@Indexed
private String cloudDeploymentDomain;
@Indexed
@Indexed
@JsonProperty("vmType")
private String vmType;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external.ansible;
package nl.uva.sne.drip.drip.commons.data.v1.external.ansible;
/**
*
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external.ansible;
package nl.uva.sne.drip.drip.commons.data.v1.external.ansible;
/**
*
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.data.v1.external.ansible;
package nl.uva.sne.drip.drip.commons.data.v1.external.ansible;
import org.springframework.data.mongodb.core.mapping.Document;
......
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDAI5hMEdqCIf12SDh9N9hOTOX+yhTAxvF8YKwz9rD3N3F49e/e
aG6IzsixYPNrf8Aos0ANFnJDQK3wsC1PrfNLrEMz6/Kalj/D4GotCaVCFZBxvwjn
OotwYSyJF6bqnv5bun37xY9nrMcr1JmrxRtkhB4QDbW1vu0uzeezkbM1TQIDAQAB
AoGARlzCqRjgrEdGSsqn5TNOQ15l26ilcPNp++JrLZxpsh7brzBhZ1FXKUKQvGSE
wBlIhZ8fFavirD5DdKEP9t38+lZ0gE1Ky4Xz77J92RctIgSgReZ8niZGjDTiuS9o
QBEyfPcJXekVlEGDvyH4BkRocarGnaJfNBqu1+LSL+tDmQECQQDvK4py989ts1nt
O+fV2XH7sb1MeYVlWw8SgfUaHTQLCONpUSo+PIfdbCwYbxGTObWZmZs1Z/naVNU7
0FI8mronAkEAzajTx14yvr2tH8A8yTvXwyWXBU56uCAj6n8UI2kfGIoj5/oT5EzC
NX/bJsG5orS7roZqKvCmy6V2vKaKUdDBawJBAN5gJoeFABmoo9lfVMzSNBfpB/A+
IRi/VMFJkiJousXzyrZWoCdj0pO/CzTguH+iLcaWOuiqN3aYX/cQWBY/awsCQD8H
L6hZKSolzUn+y2JM0co/2fHJZHjLeNZkDdLwY5RMucZdcP01vQtSXOKa2n6P7zkE
fsMcL7IXyrT0QU3jsXMCQA5bQiZ7W4SlE5r1Odz8we+3r/6BbUeAT3WIY/bwAcWn
yEYfOy9GXmX97kTX92m1RjKylNv1B41RoEGGz3yuUtk=
-----END RSA PRIVATE KEY-----
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCrID6iv0ObjfT0EKTN/3YgWZUMGNo/IETu2nzRnKLU8W5YKp9N
9Zwl+rhHjyE+GOadx+brzThcGKawXkgNxu0KO7E+pKpnB3cuFdtfIqW9jFLrNopM
WuX7tquZPc8l49JPe+2Z5z6WitJ9XJWgpDqdE8Jba9B3o0GuwqYE36I0HwIDAQAB
AoGAFFE2vpHg0AYxsAyN1JthBgQ8yvvkZZxKMuWj7isfthKYHEWrNlFT4bp7yJs4
wiuordD/HL331A9lMwlumpwkpmEfpTJcN5ndw5wwt0XReXdp0Icu4/t7FufalcVb
eGEJQOMAPkfgGU6AciyHMKjzTa5ZWQhU4YpZ2JSlVmZNUUECQQDzHHrP3go77IRq
gSI8ytCOnm3tBL+Wo5yQfJv2PlQdD/v5TWIZTQoqgBsgpQZ70ylRiF/y9rAqebNx
8bTQGIf/AkEAtDLGufAPm36ja3LdgFUCvfeb0a8IOwc8ih6eAEuBpYqgwKwV+ota
WPXP3Cdw/patP2Ev9YwKBa6Vqz/oogVT4QJAU+2UFGkCPXfEqwQTrssRvvrA1l+a
SMYJCfSK3zLbVQEsqv9lC3kGNm/tbZKrL1pR3FzpSvaREMjdA0w/cMvXPwJBAIez
CTZy0r4NUvGSkb2XxzXZpmz0e6VAINX+kou0UNCiIcaWkQKZOJNvoXWv+gau346w
GJa4O7/lpm5M9Vo12uECQDJbvjums0EE0xPRe37uAqmYr9Aborex7RBO+kIs0eNE
RDbzuUMMs7pJbUeQ5bFaDMZKwoSIEJMWuJMSsZ1Jd1s=
-----END RSA PRIVATE KEY-----
......@@ -74,16 +74,17 @@ def execute_playbook(hosts, playbook_path,user,ssh_key_file,extra_vars,passwords
print '[ERROR] The playbook does not exist'
return '[ERROR] The playbook does not exist'
os.environ['ANSIBLE_HOST_KEY_CHECKING'] = 'False'
os.environ['ANSIBLE_HOST_KEY_CHECKING'] = 'false'
ansible.constants.HOST_KEY_CHECKING = False
variable_manager = VariableManager()
loader = DataLoader()
inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=hosts)
Options = namedtuple('Options', ['listtags', 'listtasks', 'listhosts', 'syntax', 'connection','module_path', 'forks', 'remote_user', 'private_key_file', 'ssh_common_args', 'ssh_extra_args', 'sftp_extra_args', 'scp_extra_args', 'become', 'become_method', 'become_user', 'verbosity', 'check'])
Options = namedtuple('Options', ['listtags', 'listtasks', 'listhosts', 'syntax', 'connection','module_path', 'forks', 'remote_user', 'private_key_file', 'ssh_common_args', 'ssh_extra_args', 'sftp_extra_args', 'scp_extra_args', 'become', 'become_method', 'become_user', 'verbosity', 'check','host_key_checking'])
options = Options(listtags=False, listtasks=False, listhosts=False, syntax=False, connection='smart', module_path=None, forks=None, remote_user=user, private_key_file=ssh_key_file, ssh_common_args=None, ssh_extra_args=None, sftp_extra_args=None, scp_extra_args=None, become=True, become_method='sudo', become_user='root', verbosity=None, check=False )
options = Options(listtags=False, listtasks=False, listhosts=False, syntax=False, connection='smart', module_path=None, forks=None, remote_user=user, private_key_file=ssh_key_file, ssh_common_args=None, ssh_extra_args=None, sftp_extra_args=None, scp_extra_args=None, become=True, become_method='sudo', become_user='root', verbosity=None, check=False , host_key_checking=False)
variable_manager.extra_vars = extra_vars
......
......@@ -105,11 +105,7 @@ def on_request(ch, method, props, body):
res_name = "ansible_output"
else:
res_name = "credential"
print manager_type
print res_name
response = {}
outcontent = {}
current_milli_time = lambda: int(round(time.time() * 1000))
......
CESNET&&https://carach5.ics.muni.cz:11443&&ubuntu 14.04&&medium&&http://fedcloud.egi.eu/occi/compute/flavour/1.0#medium&&http://occi.carach5.ics.muni.cz/occi/infrastructure/os_tpl#uuid_egi_ubuntu_server_14_04_lts_fedcloud_warg_131&&ubuntu
CESNET&&https://carach5.ics.muni.cz:11443&&ubuntu 14.04&&extra_large&&http://schemas.fedcloud.egi.eu/occi/infrastructure/resource_tpl#extra_large&& http://occi.carach5.ics.muni.cz/occi/infrastructure/os_tpl#uuid_egi_ubuntu_server_14_04_lts_fedcloud_warg_131&&ubuntu
\ No newline at end of file
Ubuntu 14.04&&Virginia&&ami-2d39803a
Ubuntu 14.04&&California&&ami-48db9d28
Ubuntu 16.04&&Virginia&&ami-40d28157
Ubuntu 16.04&&California&&ami-6e165d0e
Ubuntu 16.04&&Ohio&&ami-fcc19b99
Ubuntu 14.04&&Ohio&&ami-41d48e24
\ No newline at end of file
Virginia&&ec2.us-east-1.amazonaws.com
Ohio&&ec2.us-east-2.amazonaws.com
California&&ec2.us-west-1.amazonaws.com
Oregon&&ec2.us-west-2.amazonaws.com
Ireland&&ec2.eu-west-1.amazonaws.com
Frankfurt&&ec2.eu-central-1.amazonaws.com
Tokyo&&ec2.ap-northeast-1.amazonaws.com
Seoul&&ec2.ap-northeast-2.amazonaws.com
Singapore&&ec2.ap-southeast-1.amazonaws.com
Sydney&&ec2.ap-southeast-2.amazonaws.com
Mumbai&&ec2.ap-south-1.amazonaws.com
SanPaulo&&ec2.sa-east-1.amazonaws.com
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>nl.uva.sne.drip</groupId>
<version>1.0-SNAPSHOT</version>
......@@ -14,12 +18,24 @@
</properties>
<dependencies>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-provisioning-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-provisioning-agent</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
......@@ -45,6 +61,26 @@
<version>2.4</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jglobus</groupId>
<artifactId>myproxy</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.5</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.4.4</version>
<type>jar</type>
</dependency>
</dependencies>
......
......@@ -19,14 +19,17 @@ import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DefaultConsumer;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.text.MessageFormat;
import java.util.Properties;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.drip.provisioner.utils.PropertyValues;
/**
*
......@@ -34,10 +37,7 @@ import java.util.logging.Logger;
*/
public class RPCServer {
private static final String RPC_QUEUE_NAME = "provisioner_queue";
private static String HOST = "127.0.0.1";
public static void main(String[] argv) {
public static void main(String[] argv) throws MalformedURLException {
Properties prop = new Properties();
if (argv.length >= 1) {
try {
......@@ -54,26 +54,31 @@ public class RPCServer {
Logger.getLogger(RPCServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
HOST = prop.getProperty("rabbitmq.host", "127.0.0.1");
Logger.getLogger(RPCServer.class.getName()).log(Level.INFO, MessageFormat.format("rabbitmq.host: {0}", HOST));
PropertyValues.setPropertyValues(prop);
start();
}
private static void start() {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(HOST);
factory.setHost(PropertyValues.HOST);
factory.setPassword("guest");
factory.setUsername("guest");
factory.setPort(AMQP.PROTOCOL.PORT);
Logger.getLogger(RPCServer.class.getName()).log(Level.INFO, "Connected to: {0}", HOST);
Logger.getLogger(RPCServer.class.getName()).log(Level.INFO, "Connected to: {0}", PropertyValues.HOST);
try (Connection connection = factory.newConnection()) {
Channel channel = connection.createChannel();
//We define the queue name
channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null);
//Set our own customized consummer
Consumer c = new Consumer(channel);
channel.queueDeclare(PropertyValues.RPC_QUEUE_NAME, false, false, false, null);
DefaultConsumer c;
if (PropertyValues.RPC_QUEUE_NAME.endsWith("v0")) {
c = new nl.uva.sne.drip.drip.provisioner.v0.Consumer(channel);
} else {
c = new nl.uva.sne.drip.drip.provisioner.v1.Consumer(channel);
}
//Start listening for messages
channel.basicConsume(RPC_QUEUE_NAME, false, c);
channel.basicConsume(PropertyValues.RPC_QUEUE_NAME, false, c);
//Block so we don't close the channel
while (true) {
......
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.drip.provisioner.utils;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.security.cert.CertificateEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import org.globus.myproxy.MyProxyException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.yaml.snakeyaml.Yaml;
import provisioning.credential.Credential;
import provisioning.credential.EC2Credential;
import provisioning.credential.EGICredential;
/**
*
* @author S. Koulouzis
*/
public class MessageParsing {
enum SOURCE {
MY_PROXY,
CERTIFICATE
}
public static List<File> getTopologies(JSONArray parameters, String tempInputDirPath, int level) throws JSONException, IOException {
List<File> topologyFiles = new ArrayList<>();
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i);
String name = (String) param.get("name");
if (name.equals("topology")) {
JSONObject attributes = param.getJSONObject("attributes");
int fileLevel = Integer.valueOf((String) attributes.get("level"));
if (fileLevel == level) {
String originalFilename = (String) attributes.get("filename");
String fileName = originalFilename;
if (!fileName.endsWith(".yml")) {
fileName += ".yml";
}
File topologyFile = new File(tempInputDirPath + File.separator + fileName);
topologyFile.createNewFile();
String val = (String) param.get("value");
writeValueToFile(val, topologyFile);
topologyFiles.add(topologyFile);
//We should have only one top level topoloy
if (level == 0) {
return topologyFiles;
}
}
}
}
return topologyFiles;
}
public static void writeValueToFile(String value, File file) throws FileNotFoundException {
try (PrintWriter out = new PrintWriter(file)) {
out.print(value);
}
if (!file.exists() || file.length() < value.getBytes().length) {
throw new FileNotFoundException("File " + file.getAbsolutePath() + " doesn't exist or contents are missing ");
}
}
public static List<File> getSSHKeys(JSONArray parameters, String tempInputDirPath, String filename, String varName) throws JSONException, IOException {
List<File> sshKeys = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i);
MessageParameter messageParam = mapper.readValue(param.toString(), MessageParameter.class);
String name = messageParam.getName();
String value = messageParam.getValue();
if (name.equals(varName)) {
File sshKeyFile = null;
if (messageParam.getAttributes() != null) {
if (messageParam.getAttributes().get("name") != null) {
filename = messageParam.getAttributes().get("name");
}
if (messageParam.getAttributes().get("key_pair_id") != null) {
File tempInputDir = new File(tempInputDirPath + File.separator + messageParam.getAttributes().get("key_pair_id"));
tempInputDir.mkdir();
sshKeyFile = new File(tempInputDir.getAbsolutePath() + File.separator + filename);
}
}
if (sshKeyFile == null) {
sshKeyFile = new File(tempInputDirPath + File.separator + filename);
}
if (sshKeyFile.exists()) {
sshKeyFile = new File(tempInputDirPath + File.separator + i + "_" + filename);
}
if (sshKeyFile.createNewFile()) {
MessageParsing.writeValueToFile(value, sshKeyFile);
sshKeys.add(sshKeyFile);
}
}
}
return sshKeys;
}
public static Map<String, Object> ymlStream2Map(InputStream in) {
Yaml yaml = new Yaml();
Map<String, Object> map = (Map<String, Object>) yaml.load(in);
return map;
}
public static List<Credential> getCloudCredentials(JSONArray parameters, String tempInputDirPath) throws JSONException, FileNotFoundException, IOException, MyProxyException, CertificateEncodingException {
List<Credential> credentials = new ArrayList<>();
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
MessageParameter messageParam = mapper.readValue(param.toString(), MessageParameter.class);
String name = messageParam.getName();
String value = messageParam.getValue();
if (name.equals("cloud_credential")) {
Credential credential = null;
value = value.substring(1, value.length() - 1);
CloudCredentials cred = mapper.readValue(value, CloudCredentials.class);
if (cred.getCloudProviderName().toLowerCase().equals("ec2")) {
EC2Credential ec2 = new EC2Credential();
ec2.accessKey = cred.getAccessKeyId();
ec2.secretKey = cred.getSecretKey();
credential = ec2;
}
if (cred.getCloudProviderName().toLowerCase().equals("egi")) {
EGICredential egi = new EGICredential();
Map<String, Object> att = cred.getAttributes();
String trustedCertificatesURL = null;
if (att != null && att.containsKey("trustedCertificatesURL")) {
trustedCertificatesURL = (String) att.get("trustedCertificatesURL");
}
if (trustedCertificatesURL != null) {
downloadCACertificates(new URL(trustedCertificatesURL));
} else {
downloadCACertificates(PropertyValues.CA_BUNDLE_URL);
}
String myProxyEndpoint = null;
if (att != null && att.containsKey("myProxyEndpoint")) {
myProxyEndpoint = (String) att.get("myProxyEndpoint");
}
if (myProxyEndpoint == null && PropertyValues.MY_PROXY_ENDPOINT != null) {
myProxyEndpoint = PropertyValues.MY_PROXY_ENDPOINT;
}
if (myProxyEndpoint != null) {
egi.proxyFilePath = generateProxy(cred.getAccessKeyId(), cred.getSecretKey(), SOURCE.MY_PROXY);
} else {
egi.proxyFilePath = generateProxy(cred.getAccessKeyId(), cred.getSecretKey(), SOURCE.CERTIFICATE);
}
egi.trustedCertPath = PropertyValues.TRUSTED_CERTIFICATE_FOLDER;
credential = egi;
}
// for (KeyPair pair : cred.getKeyPairs()) {
// if (pair != null) {
// File dir = new File(tempInputDirPath + File.separator + pair.getId());
// dir.mkdir();
// Key privateKey = pair.getPrivateKey();
// if (privateKey != null) {
// writeValueToFile(privateKey.getKey(), new File(dir.getAbsolutePath() + File.separator + privateKey.getName()));
// }
// Key publicKey = pair.getPublicKey();
// if (publicKey != null) {
// writeValueToFile(publicKey.getKey(), new File(dir.getAbsolutePath() + File.separator + publicKey.getName()));
// }
// }
// }
credentials.add(credential);
}
}
return credentials;
}
private static String generateProxy(String accessKeyId, String secretKey, SOURCE source) throws MyProxyException, IOException, CertificateEncodingException {
if (source.equals(SOURCE.MY_PROXY)) {
//After 10 years of grid comuting and using certificates we still can't get it to work.
// MyProxy myProxy = new MyProxy(PropertyValues.MY_PROXY_ENDPOINT, 7512);
// myProxy.writeTrustRoots(PropertyValues.TRUSTED_CERTIFICATE_FOLDER);
//
// GSSCredential cert = myProxy.get(accessKeyId, secretKey, 2 * 3600);
// X509Credential gCred = ((GlobusGSSCredentialImpl) cert).getX509Credential();
// gCred.save(new FileOutputStream("/tmp/x509up_u0"));
String cmd = "myproxy-logon "
+ "--voms fedcloud.egi.eu "
+ "-s " + PropertyValues.MY_PROXY_ENDPOINT
+ " -l " + accessKeyId
+ " --stdin_pass"
+ " --out /tmp/x509up_u0";
//
InputStream fileIn = new ByteArrayInputStream(secretKey.getBytes());
Process process = Runtime.getRuntime().exec(cmd);
OutputStream stdin = process.getOutputStream();
InputStream stdout = process.getInputStream();
InputStream stderr = process.getErrorStream();
pipeStream(fileIn, stdin);
}
return "/tmp/x509up_u0";
}
public static void pipeStream(InputStream input, OutputStream output)
throws IOException {
byte buffer[] = new byte[1024];
int numRead = 0;
do {
numRead = input.read(buffer);
output.write(buffer, 0, numRead);
} while (input.available() > 0);
output.flush();
}
private static void downloadCACertificates(URL url) throws MalformedURLException, IOException {
String[] parts = url.getFile().split("/");
String fileName = parts[parts.length - 1];
File bundle = new File(PropertyValues.TRUSTED_CERTIFICATE_FOLDER + File.separator + fileName);
if (!bundle.getParentFile().exists()) {
if (!bundle.getParentFile().mkdirs()) {
throw new IOException(bundle + " could not be created");
}
}
if (!bundle.exists()) {
URL website = new URL(url.toString());
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(bundle);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
untar(new File(PropertyValues.TRUSTED_CERTIFICATE_FOLDER), bundle);
}
}
private static void untar(File dest, File tarFile) throws IOException {
Process p = Runtime.getRuntime().exec(" tar -xzvf " + tarFile.getAbsolutePath() + " -C " + dest.getAbsolutePath());
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String s = null;
StringBuilder error = new StringBuilder();
while ((s = stdError.readLine()) != null) {
error.append(s);
}
if (s != null) {
throw new IOException(error.toString());
}
// dest.mkdir();
// TarArchiveInputStream tarIn;
//
// tarIn = new TarArchiveInputStream(
// new GzipCompressorInputStream(
// new BufferedInputStream(
// new FileInputStream(
// tarFile
// )
// )
// )
// );
//
// org.apache.commons.compress.archivers.tar.TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
//
// while (tarEntry != null) {
// File destPath = new File(dest, tarEntry.getName());
// if (tarEntry.isDirectory()) {
// destPath.mkdirs();
// } else {
// destPath.createNewFile();
// byte[] btoRead = new byte[1024];
// try (BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath))) {
// int len;
//
// while ((len = tarIn.read(btoRead)) != -1) {
// bout.write(btoRead, 0, len);
// }
// }
//// Set<PosixFilePermission> perms = new HashSet<>();
//// perms.add(PosixFilePermission.OWNER_READ);
//// perms.add(PosixFilePermission.OWNER_WRITE);
//// perms.add(PosixFilePermission.OWNER_EXECUTE);
////
//// perms.add(PosixFilePermission.GROUP_READ);
//// perms.add(PosixFilePermission.GROUP_WRITE);
//// perms.add(PosixFilePermission.GROUP_EXECUTE);
////
//// perms.add(PosixFilePermission.OTHERS_READ);
//// perms.add(PosixFilePermission.OTHERS_EXECUTE);
//// perms.add(PosixFilePermission.OTHERS_EXECUTE);
//// Files.setPosixFilePermissions(Paths.get(destPath.getAbsolutePath()), perms);
// }
// tarEntry = tarIn.getNextTarEntry();
// }
// tarIn.close();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.drip.provisioner.utils;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.drip.provisioner.RPCServer;
/**
*
* @author S. Koulouzis
*/
public class PropertyValues {
public static String RPC_QUEUE_NAME = "provisioner_queue_v1";
public static String HOST = "127.0.0.1";
public static String TRUSTED_CERTIFICATE_FOLDER;
public static URL CA_BUNDLE_URL;
public static String MY_PROXY_ENDPOINT = "myproxy1.egee.cesnet.cz";
public static String DOMAIN_INFO_PATH = "etc";
public static void setPropertyValues(Properties prop) throws MalformedURLException {
PropertyValues.HOST = prop.getProperty("rabbitmq.host", "127.0.0.1");
PropertyValues.RPC_QUEUE_NAME = prop.getProperty("rpc.queue.name",
"provisioner_queue_v1");
PropertyValues.TRUSTED_CERTIFICATE_FOLDER = prop.getProperty("trusted.certificates.folder", "/etc/grid-security/certificates");
CA_BUNDLE_URL = new URL(prop.getProperty("ca.bundle.url",
"https://dist.eugridpma.info/distribution/igtf/current/accredited/igtf-preinstalled-bundle-classic.tar.gz"));
MY_PROXY_ENDPOINT = prop.getProperty("my.proxy.endpoint",
"myproxy1.egee.cesnet.cz");
DOMAIN_INFO_PATH = prop.getProperty("domain.info.path",
"etc");
Logger.getLogger(RPCServer.class.getName()).log(Level.INFO,
MessageFormat.format("rabbitmq.host: {0}", PropertyValues.HOST));
Logger.getLogger(RPCServer.class.getName()).log(Level.INFO,
MessageFormat.format("rpc.queue.name: {0}", PropertyValues.RPC_QUEUE_NAME));
}
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.drip.provisioner;
package nl.uva.sne.drip.drip.provisioner.v0;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
......@@ -27,7 +27,6 @@ import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
......@@ -40,6 +39,7 @@ import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.drip.provisioner.utils.MessageParsing;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.json.JSONArray;
......@@ -161,12 +161,12 @@ public class Consumer extends DefaultConsumer {
geniConfFile = cloudConfFile;
}
File topologyFile = getTopology(parameters, tempInputDirPath, 0);
File topologyFile = MessageParsing.getTopologies(parameters, tempInputDirPath, 0).get(0);
File mainTopologyFile = new File(tempInputDirPath + "topology_main");
FileUtils.moveFile(topologyFile, mainTopologyFile);
mainTopologyPath = mainTopologyFile.getAbsolutePath();
topologyFile = getTopology(parameters, tempInputDirPath, 1);
topologyFile = MessageParsing.getTopologies(parameters, tempInputDirPath, 1).get(0);
File secondaryTopologyFile = new File(tempInputDirPath + File.separator + topologyFile.getName() + ".yml");
String outputFilePath = tempInputDirPath + File.separator + topologyFile.getName() + "_provisioned.yml";
TopologyElement x = new TopologyElement();
......@@ -180,7 +180,7 @@ public class Consumer extends DefaultConsumer {
logDir = getLogDirPath(parameters, tempInputDirPath);
File sshKey = getSSHKey(parameters, tempInputDirPath);
File sshKey = MessageParsing.getSSHKeys(parameters, tempInputDirPath, "user.pem", "sshkey").get(0);
if (sshKey != null) {
sshKeyFilePath = sshKey.getAbsolutePath();
}
......@@ -255,8 +255,8 @@ public class Consumer extends DefaultConsumer {
// }
x = new TopologyElement();
x.topologyName = "kubernetes";
x.outputFilePath = tempInputDirPath + "file_kubernetes";
x.topologyName = "topology";
x.outputFilePath = tempInputDirPath + "file_topology";
topologyInfoArray.add(x);
return topologyInfoArray;
......@@ -342,7 +342,6 @@ public class Consumer extends DefaultConsumer {
fileArguments.put("value", "ERROR::There is no output for topology " + outputs.get(i).topologyName);
parameters.add(fileArguments);
}
}
}
jo.put("parameters", parameters);
......@@ -365,15 +364,6 @@ public class Consumer extends DefaultConsumer {
return jo.toString();
}
private void writeValueToFile(String value, File file) throws FileNotFoundException {
try (PrintWriter out = new PrintWriter(file)) {
out.print(value);
}
if (!file.exists() || file.length() < value.getBytes().length) {
throw new FileNotFoundException("File " + file.getAbsolutePath() + " doesn't exist or contents are missing ");
}
}
private File getCloudConfigurationFile(JSONArray parameters, String tempInputDirPath) throws JSONException {
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i);
......@@ -382,7 +372,7 @@ public class Consumer extends DefaultConsumer {
try {
File confFile = new File(tempInputDirPath + File.separator + name);
if (confFile.createNewFile()) {
writeValueToFile((String) param.get("value"), confFile);
MessageParsing.writeValueToFile((String) param.get("value"), confFile);
return confFile;
} else {
return null;
......@@ -396,39 +386,6 @@ public class Consumer extends DefaultConsumer {
return null;
}
private File getTopology(JSONArray parameters, String tempInputDirPath, int level) throws JSONException, IOException {
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i);
String name = (String) param.get("name");
if (name.equals("topology")) {
JSONObject attributes = param.getJSONObject("attributes");
int fileLevel = Integer.valueOf((String) attributes.get("level"));
if (fileLevel == level) {
String originalFilename = (String) attributes.get("filename");
String fileName = "";
// String[] parts = originalFilename.split("_");
// String prefix = "";
// //Clear date part form file name
// if (isNumeric(parts[0])) {
// for (int j = 1; j < parts.length; j++) {
// fileName += prefix + parts[j];
// prefix = "_";
// }
// } else {
fileName = originalFilename;
// }
File topologyFile = new File(tempInputDirPath + File.separator + fileName);
topologyFile.createNewFile();
String val = (String) param.get("value");
writeValueToFile(val, topologyFile);
return topologyFile;
}
}
}
return null;
}
private Map<String, File> getCertificates(JSONArray parameters, String tempInputDirPath) throws JSONException, IOException {
Map<String, File> files = new HashMap<>();
for (int i = 0; i < parameters.length(); i++) {
......@@ -439,7 +396,7 @@ public class Consumer extends DefaultConsumer {
String fileName = (String) attribute.get("filename");
File certificate = new File(tempInputDirPath + File.separator + fileName + ".pem");
if (certificate.createNewFile()) {
writeValueToFile((String) param.get("value"), certificate);
MessageParsing.writeValueToFile((String) param.get("value"), certificate);
Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_READ);
Files.setPosixFilePermissions(Paths.get(certificate.getAbsolutePath()), perms);
......@@ -461,22 +418,6 @@ public class Consumer extends DefaultConsumer {
return System.getProperty("java.io.tmpdir");
}
private File getSSHKey(JSONArray parameters, String tempInputDirPath) throws JSONException, IOException {
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i);
String name = (String) param.get("name");
if (name.equals("sshkey")) {
String sshKeyContent = (String) param.get("value");
File sshKeyFile = new File(tempInputDirPath + File.separator + "user.pem");
if (sshKeyFile.createNewFile()) {
writeValueToFile(sshKeyContent, sshKeyFile);
return sshKeyFile;
}
}
}
return null;
}
private File getSciptFile(JSONArray parameters, String tempInputDirPath) throws JSONException, IOException {
for (int i = 0; i < parameters.length(); i++) {
JSONObject param = (JSONObject) parameters.get(i);
......@@ -485,7 +426,7 @@ public class Consumer extends DefaultConsumer {
String scriptContent = (String) param.get("value");
File scriptFile = new File(tempInputDirPath + File.separator + "guiscipt.sh");
if (scriptFile.createNewFile()) {
writeValueToFile(scriptContent, scriptFile);
MessageParsing.writeValueToFile(scriptContent, scriptFile);
return scriptFile;
}
}
......@@ -493,8 +434,4 @@ public class Consumer extends DefaultConsumer {
return null;
}
private static boolean isNumeric(String str) {
return str.matches("-?\\d+(\\.\\d+)?");
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.drip.provisioner.v1;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.KeyPair;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.cert.CertificateEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.drip.commons.data.internal.Message;
import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter;
import nl.uva.sne.drip.drip.provisioner.utils.MessageParsing;
import nl.uva.sne.drip.drip.provisioner.utils.PropertyValues;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.globus.myproxy.MyProxyException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import provisioning.credential.Credential;
import provisioning.credential.EC2Credential;
import provisioning.credential.EGICredential;
import provisioning.credential.SSHKeyPair;
import provisioning.credential.UserCredential;
import provisioning.database.EC2.EC2Database;
import provisioning.database.EGI.EGIDatabase;
import provisioning.database.UserDatabase;
import provisioning.engine.TEngine.TEngine;
import topologyAnalysis.TopologyAnalysisMain;
import topologyAnalysis.dataStructure.SubTopologyInfo;
import topologyAnalysis.dataStructure.VM;
/**
*
* This is a provision Message consumer
*
*
* @author H. Zhou, S. Koulouzis
*/
public class Consumer extends DefaultConsumer {
private final Channel channel;
// Map<String, String> em = new HashMap<>();
public Consumer(Channel channel) throws IOException {
super(channel);
this.channel = channel;
// em.put("Virginia", "ec2.us-east-1.amazonaws.com");
// em.put("California", "ec2.us-west-1.amazonaws.com");
// em.put("Oregon", "ec2.us-west-2.amazonaws.com");
// em.put("Mumbai", "ec2.ap-south-1.amazonaws.com");
// em.put("Singapore", "ec2.ap-southeast-1.amazonaws.com");
// em.put("Seoul", "ec2.ap-northeast-2.amazonaws.com");
// em.put("Sydney", "ec2.ap-southeast-2.amazonaws.com");
// em.put("Tokyo", "ec2.ap-northeast-1.amazonaws.com");
// em.put("Frankfurt", "ec2.eu-central-1.amazonaws.com");
// em.put("Ireland", "ec2.eu-west-1.amazonaws.com");
// em.put("Paulo", "ec2.sa-east-1.amazonaws.com");
}
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
//Create the reply properties which tells us where to reply, and which id to use.
//No need to change anything here
AMQP.BasicProperties replyProps = new AMQP.BasicProperties.Builder()
.correlationId(properties.getCorrelationId())
.build();
String response = "";
try {
//The queue only moves bytes so we need to convert them to stting
String message = new String(body, "UTF-8");
String tempInputDirPath = System.getProperty("java.io.tmpdir") + File.separator + "Input-" + Long.toString(System.nanoTime()) + File.separator;
File tempInputDir = new File(tempInputDirPath);
if (!(tempInputDir.mkdirs())) {
throw new FileNotFoundException("Could not create input directory: " + tempInputDir.getAbsolutePath());
}
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
response = mapper.writeValueAsString(invokeProvisioner(message, tempInputDirPath));
} catch (Throwable ex) {
try {
response = generateExeptionResponse(ex);
Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
} catch (JSONException ex1) {
response = "{\"creationDate\": " + System.currentTimeMillis()
+ ",\"parameters\": [{\"url\": null,\"encoding\": UTF-8,"
+ "\"value\": \"" + ex.getMessage() + "\",\"name\": \""
+ ex.getClass().getName() + "\",\"attributes\": null}]}";
}
} finally {
Logger.getLogger(Consumer.class.getName()).log(Level.INFO, "Sending Response: {0}", response);
//We send the response back. No need to change anything here
channel.basicPublish("", properties.getReplyTo(), replyProps, response.getBytes("UTF-8"));
channel.basicAck(envelope.getDeliveryTag(), false);
}
}
private Message invokeProvisioner(String messageStr, String tempInputDirPath) throws IOException, JSONException, Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
Message massage = mapper.readValue(messageStr, Message.class);
List<MessageParameter> params = massage.getParameters();
for (MessageParameter mp : params) {
String name = mp.getName();
String value = mp.getValue();
if (name.equals("action")) {
switch (value) {
case "start_topology":
JSONObject jo = new JSONObject(messageStr);
return startTopology(jo.getJSONArray("parameters"), tempInputDirPath);
case "kill_topology":
jo = new JSONObject(messageStr);
return killTopology(jo.getJSONArray("parameters"), tempInputDirPath);
}
}
}
return null;
}
private Message startTopology(JSONArray parameters, String tempInputDirPath) throws Exception {
TEngine tEngine = new TEngine();
TopologyAnalysisMain tam = null;
UserCredential userCredential = new UserCredential();
UserDatabase userDatabase = new UserDatabase();
try {
File topologyFile = MessageParsing.getTopologies(parameters, tempInputDirPath, 0).get(0);
File mainTopologyFile = new File(tempInputDirPath + "topology_main.yml");
FileUtils.moveFile(topologyFile, mainTopologyFile);
String topTopologyLoadingPath = mainTopologyFile.getAbsolutePath();
List<File> topologyFiles = MessageParsing.getTopologies(parameters, tempInputDirPath, 1);
// for (File lowLevelTopologyFile : topologyFiles) {
// File secondaryTopologyFile = new File(tempInputDirPath + File.separator + lowLevelTopologyFile.getName() + ".yml");
// FileUtils.moveFile(lowLevelTopologyFile, secondaryTopologyFile);
// }
Map<String, Object> map = MessageParsing.ymlStream2Map(new FileInputStream(topTopologyLoadingPath));
String userPublicKeyName = ((String) map.get("publicKeyPath")).split("@")[1].replaceAll("\"", "");
String userPrivateName = FilenameUtils.removeExtension(userPublicKeyName);
List<File> sshKeys = MessageParsing.getSSHKeys(parameters, tempInputDirPath, userPublicKeyName, "user_ssh_key");
if (sshKeys == null || sshKeys.isEmpty()) {
JSch jsch = new JSch();
KeyPair kpair = KeyPair.genKeyPair(jsch, KeyPair.RSA);
kpair.writePrivateKey(tempInputDirPath + File.separator + userPrivateName);
kpair.writePublicKey(tempInputDirPath + File.separator + userPublicKeyName, "auto generated user accees keys");
kpair.dispose();
}
tam = new TopologyAnalysisMain(topTopologyLoadingPath);
if (!tam.fullLoadWholeTopology()) {
throw new Exception("sth wrong!");
}
userCredential = getUserCredential(parameters, tempInputDirPath);
ArrayList<SSHKeyPair> sshKeyPairs = userCredential.
loadSSHKeyPairFromFile(tempInputDirPath);
if (sshKeyPairs == null) {
throw new NullPointerException("ssh key pairs are null");
}
if (sshKeyPairs.isEmpty()) {
throw new IOException("No ssh key pair is loaded!");
} else if (!userCredential.initial(sshKeyPairs, tam.wholeTopology)) {
throw new IOException("ssh key pair initilaziation error");
}
userDatabase = getUserDB();
/*ProvisionRequest pq = new ProvisionRequest();
pq.topologyName = "ec2_zh_b";
ArrayList<ProvisionRequest> provisionReqs = new ArrayList<ProvisionRequest>();
provisionReqs.add(pq);*/
//tEngine.provision(tam.wholeTopology, userCredential, userDatabase, provisionReqs);
tEngine.provisionAll(tam.wholeTopology, userCredential, userDatabase);
String topologyUserName = tam.wholeTopology.userName;
String charset = "UTF-8";
List<MessageParameter> responseParameters = new ArrayList<>();
MessageParameter param = new MessageParameter();
param.setEncoding(charset);
String fileName = tam.wholeTopology.loadingPath;
if (!fileName.endsWith(".yml")) {
fileName += ".yml";
}
File f = new File(fileName);
if (f.exists()) {
param.setName(FilenameUtils.removeExtension(FilenameUtils.getBaseName(fileName)));
byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
param.setValue(new String(bytes, charset));
responseParameters.add(param);
} else {
param.setName(FilenameUtils.removeExtension(FilenameUtils.getBaseName(fileName)));
param.setValue("ERROR::There is no output for topology topology_main");
responseParameters.add(param);
}
for (SubTopologyInfo sub : tam.wholeTopology.topologies) {
param = new MessageParameter();
param.setEncoding(charset);
fileName = tempInputDirPath + File.separator + sub.topology;
if (!fileName.endsWith(".yml")) {
fileName += ".yml";
}
f = new File(fileName);
if (f.exists()) {
param.setName(sub.topology);
byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
param.setValue(new String(bytes, charset));
responseParameters.add(param);
} else {
param.setName(sub.topology);
param.setValue("ERROR::There is no output for topology " + sub.topology);
responseParameters.add(param);
}
}
param = new MessageParameter();
param.setEncoding(charset);
param.setName("public_user_key");
byte[] bytes = Files.readAllBytes(Paths.get(tempInputDirPath + File.separator + userPublicKeyName));
param.setValue(new String(bytes, charset));
Map<String, String> attributes = new HashMap<>();
attributes.put("name", userPublicKeyName);
param.setAttributes(attributes);
responseParameters.add(param);
param = new MessageParameter();
param.setEncoding(charset);
param.setName("private_user_key");
bytes = Files.readAllBytes(Paths.get(tempInputDirPath + File.separator + userPrivateName));
param.setValue(new String(bytes, charset));
attributes = new HashMap<>();
attributes.put("name", userPrivateName);
// attributes.put("username", sub.userName);
param.setAttributes(attributes);
responseParameters.add(param);
param = new MessageParameter();
param.setEncoding(charset);
param.setName("private_deployer_key");
bytes = Files.readAllBytes(Paths.get(tempInputDirPath + File.separator + "clusterKeyPair" + File.separator + "id_rsa"));
param.setValue(new String(bytes, charset));
attributes = new HashMap<>();
attributes.put("name", "id_rsa");
param.setAttributes(attributes);
responseParameters.add(param);
param = new MessageParameter();
param.setEncoding(charset);
param.setName("public_deployer_key");
bytes = Files.readAllBytes(Paths.get(tempInputDirPath + File.separator + "clusterKeyPair" + File.separator + "id_rsa.pub"));
param.setValue(new String(bytes, charset));
attributes = new HashMap<>();
attributes.put("name", "id_rsa.pub");
param.setAttributes(attributes);
responseParameters.add(param);
File dir = new File(tempInputDirPath);
for (File d : dir.listFiles()) {
if (d.isDirectory() && !d.getName().equals("clusterKeyPair")) {
param = new MessageParameter();
param.setEncoding(charset);
param.setName("public_cloud_key");
File publicKey = new File(d.getAbsolutePath() + File.separator + "name.pub");
if (!publicKey.exists()) {
publicKey = new File(d.getAbsolutePath() + File.separator + "id_rsa.pub");
}
bytes = Files.readAllBytes(Paths.get(publicKey.getAbsolutePath()));
param.setValue(new String(bytes, charset));
attributes = new HashMap<>();
attributes.put("name", publicKey.getName());
attributes.put("key_pair_id", d.getName());
param.setAttributes(attributes);
responseParameters.add(param);
param = new MessageParameter();
param.setEncoding(charset);
param.setName("private_cloud_key");
bytes = Files.readAllBytes(Paths.get(d.getAbsolutePath() + File.separator + "id_rsa"));
param.setValue(new String(bytes, charset));
attributes = new HashMap<>();
attributes.put("name", "id_rsa");
attributes.put("key_pair_id", d.getName());
param.setAttributes(attributes);
responseParameters.add(param);
}
}
param = new MessageParameter();
param.setEncoding(charset);
param.setName("deploy_parameters");
String paramValue = "";
for (SubTopologyInfo sub : tam.wholeTopology.topologies) {
ArrayList<VM> vms = sub.subTopology.getVMsinSubClass();
for (VM vm : vms) {
if (vm != null) {
paramValue += vm.publicAddress + " ";
paramValue += sub.userName + " ";
// paramValue += tempInputDirPath + File.separator + sub.subTopology.accessKeyPair.SSHKeyPairId + File.separator + "id_rsa";
paramValue += vm.role + "\n";
}
}
// String accessKeyPath = tempInputDirPath + File.separator + sub.subTopology.accessKeyPair.SSHKeyPairId + File.separator + "id_rsa";
// System.err.println("accessKeyPath: " + accessKeyPath);
}
param.setValue(paramValue);
responseParameters.add(param);
Message response = new Message();
response.setCreationDate(System.currentTimeMillis());
response.setParameters(responseParameters);
return response;
} catch (Throwable ex) {
if (tam != null) {
tEngine.deleteAll(tam.wholeTopology, userCredential, userDatabase);
}
throw ex;
} finally {
// if (tam != null) {
// tEngine.deleteAll(tam.wholeTopology, userCredential, userDatabase);
// }
}
}
private String generateExeptionResponse(Throwable ex) throws JSONException {
JSONObject jo = new JSONObject();
jo.put("creationDate", (System.currentTimeMillis()));
List parameters = new ArrayList();
String charset = "UTF-8";
Map<String, String> errorArgument = new HashMap<>();
errorArgument.put("encoding", charset);
errorArgument.put("name", ex.getClass().getName());
errorArgument.put("value", ex.getMessage());
parameters.add(errorArgument);
jo.put("parameters", parameters);
return jo.toString();
}
private Message killTopology(JSONArray parameters, String tempInputDirPath) throws Exception {
TEngine tEngine = new TEngine();
TopologyAnalysisMain tam;
File topologyFile = MessageParsing.getTopologies(parameters, tempInputDirPath, 0).get(0);
File mainTopologyFile = new File(tempInputDirPath + "topology_main.yml");
String topTopologyLoadingPath = mainTopologyFile.getAbsolutePath();
List<File> topologyFiles = MessageParsing.getTopologies(parameters, tempInputDirPath, 1);
// for (File lowLevelTopologyFile : topologyFiles) {
// File secondaryTopologyFile = new File(tempInputDirPath + File.separator + lowLevelTopologyFile.getName() + ".yml");
// FileUtils.moveFile(lowLevelTopologyFile, secondaryTopologyFile);
// }
File clusterDir = new File(tempInputDirPath + File.separator + "clusterKeyPair");
clusterDir.mkdir();
List<File> public_deployer_key = MessageParsing.getSSHKeys(parameters, clusterDir.getAbsolutePath(), "id_rsa.pub", "public_deployer_key");
List<File> private_deployer_key = MessageParsing.getSSHKeys(parameters, clusterDir.getAbsolutePath(), "id_rsa", "private_deployer_key");
Map<String, Object> map = MessageParsing.ymlStream2Map(new FileInputStream(topTopologyLoadingPath));
String userPublicKeyName = ((String) map.get("publicKeyPath")).split("@")[1].replaceAll("\"", "");
String userPrivateName = FilenameUtils.removeExtension(userPublicKeyName);
List<File> public_user_key = MessageParsing.getSSHKeys(parameters, tempInputDirPath + File.separator, userPublicKeyName, "public_user_key");
List<File> private_user_key = MessageParsing.getSSHKeys(parameters, tempInputDirPath + File.separator, "id_rsa", "private_user_key");
FileUtils.moveFile(private_user_key.get(0), new File(private_user_key.get(0).getParent() + File.separator + userPrivateName));
List<File> public_cloud_key = MessageParsing.getSSHKeys(parameters, tempInputDirPath + File.separator, "name.pub", "public_cloud_key");
List<File> private_cloud_key = MessageParsing.getSSHKeys(parameters, tempInputDirPath + File.separator, "id_rsa", "private_cloud_key");
UserCredential userCredential = getUserCredential(parameters, tempInputDirPath);
UserDatabase userDatabase = getUserDB();
tam = new TopologyAnalysisMain(topTopologyLoadingPath);
if (!tam.fullLoadWholeTopology()) {
throw new Exception("sth wrong!");
}
ArrayList<SSHKeyPair> sshKeyPairs = userCredential.
loadSSHKeyPairFromFile(tempInputDirPath);
if (sshKeyPairs == null) {
throw new NullPointerException("ssh key pairs are null");
}
if (sshKeyPairs.isEmpty()) {
throw new IOException("No ssh key pair is loaded!");
} else if (!userCredential.initial(sshKeyPairs, tam.wholeTopology)) {
throw new IOException("ssh key pair initilaziation error");
}
Message response = new Message();
try {
tEngine.deleteAll(tam.wholeTopology, userCredential, userDatabase);
} catch (Throwable ex) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
return mapper.readValue(generateExeptionResponse(ex), Message.class);
}
MessageParameter param = new MessageParameter();
param.setName("topology_killed");
param.setValue("true");
List<MessageParameter> messageParameters = new ArrayList<>();
messageParameters.add(param);
response.setParameters(messageParameters);
response.setCreationDate(System.currentTimeMillis());
return response;
}
private UserDatabase getUserDB() {
UserDatabase userDatabase = new UserDatabase();
EGIDatabase egiDatabase = new EGIDatabase();
egiDatabase.loadDomainInfoFromFile(PropertyValues.DOMAIN_INFO_PATH + File.separator + "EGI_Domain_Info");
EC2Database ec2Database = new EC2Database();
ec2Database.loadDomainFromFile(PropertyValues.DOMAIN_INFO_PATH + File.separator + "domains");
ec2Database.loadAmiFromFile(PropertyValues.DOMAIN_INFO_PATH + File.separator + "OS_Domain_AMI");
if (userDatabase.databases == null) {
userDatabase.databases = new HashMap<>();
}
userDatabase.databases.put("ec2", ec2Database);
userDatabase.databases.put("egi", egiDatabase);
return userDatabase;
}
private UserCredential getUserCredential(JSONArray parameters, String tempInputDirPath) throws JSONException, IOException, FileNotFoundException, MyProxyException, CertificateEncodingException {
UserCredential userCredential = new UserCredential();
List<Credential> credentials = MessageParsing.getCloudCredentials(parameters, tempInputDirPath);
for (Credential cred : credentials) {
////Initial credentials and ssh key pairs
if (userCredential.cloudAccess == null) {
userCredential.cloudAccess = new HashMap<>();
}
if (cred instanceof EC2Credential) {
userCredential.cloudAccess.put("ec2", cred);
}
if (cred instanceof EGICredential) {
userCredential.cloudAccess.put("egi", cred);
}
}
return userCredential;
}
}
rabbitmq.host=127.0.0.1
rpc.queue.name=provisioner_queue_v1
......@@ -13,5 +13,7 @@
<module>drip-api</module>
<module>drip-planner2provisioner</module>
<module>drip-tests</module>
<module>drip-commons</module>
<module>drip-provisioner</module>
</modules>
</project>
\ No newline at end of file
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