Commit d047cdfa authored by Spiros Koulouzis's avatar Spiros Koulouzis

clean unused code

parent 81931542
/*
* 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.dao;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface BenchmarkResultDao extends MongoRepository<BenchmarkResult, String> {
}
/*
* 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.dao;
import nl.uva.sne.drip.drip.commons.data.v1.external.Script;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface ScriptDao extends MongoRepository<Script, String> {
}
/*
* 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.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.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;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
@PreAuthorize("isAuthenticated()")
public class BenchmarkResultService {
@Autowired
private BenchmarkResultDao benchmarkResultDao;
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public BenchmarkResult findOne(String id) {
BenchmarkResult benchmarkResult = benchmarkResultDao.findOne(id);
if (benchmarkResult == null) {
throw new NotFoundException();
}
return benchmarkResult;
}
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public List<BenchmarkResult> findAll() {
return benchmarkResultDao.findAll();
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public BenchmarkResult delete(String id) {
BenchmarkResult benchmarkResult = benchmarkResultDao.findOne(id);
if (benchmarkResult == null) {
throw new NotFoundException();
}
benchmarkResultDao.delete(benchmarkResult);
return benchmarkResult;
}
public BenchmarkResult save(BenchmarkResult ownedObject) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
ownedObject.setOwner(owner);
return benchmarkResultDao.save(ownedObject);
}
@PostAuthorize("(hasRole('ROLE_ADMIN'))")
public void deleteAll() {
benchmarkResultDao.deleteAll();
}
public List<BenchmarkResult> findBySysbench() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.s
}
}
......@@ -34,7 +34,6 @@ 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.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;
......@@ -50,16 +49,12 @@ import org.springframework.security.access.prepost.PreAuthorize;
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.BadRequestException;
import nl.uva.sne.drip.api.exception.KeyException;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.utils.DRIPLogHandler;
import nl.uva.sne.drip.commons.utils.TOSCAUtils;
import nl.uva.sne.drip.drip.commons.data.v1.external.ConfigurationRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult;
import org.json.JSONArray;
......@@ -85,23 +80,9 @@ public class DeployService {
@Value("${message.broker.host}")
private String messageBrokerHost;
// @Autowired
// private CloudCredentialsService cloudCredentialsService;
@Autowired
private ProvisionService provisionService;
@Autowired
private ConfigurationService configurationService;
@Autowired
private BenchmarkResultService benchmarkResultService;
@Autowired
private ToscaService toscaService;
@Autowired
private PlannerService plannerService;
private static final String[] CLOUD_SITE_NAMES = new String[]{"domain", "VMResourceID"};
private static final String[] PUBLIC_ADRESS_NAMES = new String[]{"public_address", "publicAddress"};
private final Logger logger;
......
/*
* 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.service;
import java.util.List;
import nl.uva.sne.drip.api.exception.NotFoundException;
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.drip.commons.data.v1.external.KeyPair;
/**
*
* @author S. Koulouzis
*/
@Service
public class KeyPairService {
@Autowired
KeyPairDao dao;
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public List<KeyPair> findAll() {
return dao.findAll();
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public KeyPair findOne(String id) {
KeyPair key = dao.findOne(id);
if (key == null) {
throw new NotFoundException();
}
return key;
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public KeyPair delete(KeyPair k) {
k = dao.findOne(k.getId());
dao.delete(k);
return k;
}
public KeyPair save(KeyPair ownedObject) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
ownedObject.setOwner(owner);
return dao.save(ownedObject);
}
@PostAuthorize("(hasRole('ROLE_ADMIN'))")
public void deleteAll() {
dao.deleteAll();
}
}
......@@ -21,10 +21,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -38,10 +36,7 @@ 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.drip.commons.data.v1.external.CloudCredentials;
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -63,9 +58,6 @@ public class PlannerService {
@Autowired
private ToscaService toscaService;
@Autowired
private CloudCredentialsService credentialService;
@Autowired
private PlanDao planDao;
......@@ -95,7 +87,7 @@ public class PlannerService {
for (MessageParameter mp : messageParams) {
String value = mp.getValue();
toscaPlan = new String(Base64.getDecoder().decode(value));
logger.log(Level.INFO, "TOSCA Plann: " + toscaPlan);
logger.log(Level.INFO, "TOSCA Plann: {0}", toscaPlan);
}
Map<String, Object> toscaPlanMap = Converter.ymlString2Map(toscaPlan);
......
......@@ -74,12 +74,6 @@ public class ProvisionService {
@Autowired
private SimplePlannerService simplePlanService;
@Autowired
private ScriptService userScriptService;
@Autowired
private KeyPairService keyPairService;
@Value("${message.broker.host}")
private String messageBrokerHost;
private final Logger logger;
......
/*
* 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.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
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.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;
/**
*
* @author S. Koulouzis
*/
@Service
@PreAuthorize("isAuthenticated()")
public class ScriptService {
@Autowired
ScriptDao dao;
public Script save(Script ownedObject) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
ownedObject.setOwner(owner);
return dao.save(ownedObject);
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public Script findOne(String id) {
Script script = dao.findOne(id);
if (script == null) {
throw new NotFoundException();
}
return script;
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public Script delete(String id) {
Script script = dao.findOne(id);
if (script == null) {
throw new NotFoundException();
}
dao.delete(script);
return script;
}
// @PreAuthorize(" (hasRole('ROLE_ADMIN')) or (hasRole('ROLE_USER'))")
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
// @PostFilter("hasPermission(filterObject, 'read') or hasPermission(filterObject, 'admin')")
public List<Script> findAll() {
return dao.findAll();
}
@PostFilter("(hasRole('ROLE_ADMIN'))")
public void deleteAll() {
dao.deleteAll();
}
}
......@@ -21,10 +21,8 @@ import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.api.dao.PlanDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
......
/*
* 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.v1.rest;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import java.util.ArrayList;
import java.util.List;
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.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.ResponseBody;
/**
* This controller is responsible for handling cloud benchmark tests like
* sysbench
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v1.0/benchmark")
@Controller
@StatusCodes({
@ResponseCode(code = 401, condition = "Bad credentials")
})
public class BenchmarkController {
@Autowired
private BenchmarkResultService benchmarkResultService;
/**
* Returns a BenchmarkResult
*
* @param id
* @return
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 404, condition = "BenchmarkResult not found"),
@ResponseCode(code = 200, condition = "BenchmarkResult exists")
})
public @ResponseBody
BenchmarkResult get(@PathVariable("id") String id) {
BenchmarkResult resp = benchmarkResultService.findOne(id);
if (resp == null) {
throw new NotFoundException();
}
return resp;
}
/**
* Returns sysbench results only. Not supported yet
*
* @return
*/
@RequestMapping(method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 200, condition = "Successful query")
})
public @ResponseBody
List<BenchmarkResult> getBySysbench() {
return benchmarkResultService.findBySysbench();
}
/**
* Returns the ids of stored objects. Empty list if non stored
*
* @return
*/
@RequestMapping(value = "/ids", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 200, condition = "Successful query")
})
public @ResponseBody
List<String> getIds() {
List<BenchmarkResult> all = benchmarkResultService.findAll();
List<String> ids = new ArrayList<>(all.size());
for (BenchmarkResult pi : all) {
ids.add(pi.getId());
}
return ids;
}
/**
* Deletes object
*
* @param id
* @return
*/
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 200, condition = "Successful delete"),
@ResponseCode(code = 404, condition = "Non existing id")
})
public @ResponseBody
String delete(@PathVariable("id") String id) {
BenchmarkResult Key = benchmarkResultService.findOne(id);
if (Key != null) {
benchmarkResultService.delete(id);
return "Deleted : " + id;
}
throw new NotFoundException();
}
/**
* Deletes all entries. Use with caution !
*
* @return
*/
@RequestMapping(value = "/all", method = RequestMethod.DELETE)
@RolesAllowed({UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 200, condition = "Successful delete")
})
public @ResponseBody
String deleteAll() {
benchmarkResultService.deleteAll();
return "Done";
}
}
......@@ -39,7 +39,6 @@ import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.exception.NullCloudProviderException;
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.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
......@@ -67,8 +66,6 @@ public class CloudCredentialsController {
@Autowired
private CloudCredentialsService cloudCredentialsService;
@Autowired
private KeyPairService keyService;
/**
* Post the cloud credentials.
......@@ -140,13 +137,10 @@ public class CloudCredentialsController {
key.setAttributes(attributes);
KeyPair pair = new KeyPair();
pair.setPrivateKey(key);
pair = keyService.save(pair);
// loginKeyIDs.add(pair.getId());
}
if (cloudCredentials.getCloudProviderName().toLowerCase().equals("egi")) {
cloudCredentials.setSecretKey(new String(bytes, "UTF-8"));
}
// cloudCredentials.setKeyIDs(loginKeyIDs);
cloudCredentials = cloudCredentialsService.save(cloudCredentials);
return cloudCredentials.getId();
} catch (IOException | KeyException ex) {
......
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.v1.rest;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
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 javax.annotation.security.RolesAllowed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
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.exception.KeyException;
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.drip.commons.data.v1.external.KeyPair;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for handling user public keys. These keys can
* be used by the provisoner to allow the user to login to the VMs from the
* machine the keys correspond to.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v1.0/keys")
@Component
@StatusCodes({
@ResponseCode(code = 401, condition = "Bad credentials")
})
public class KeyPairController {
@Autowired
private KeyPairService service;
// curl -v -X POST -F "file=@.ssh/id_dsa.pub" localhost:8080/drip-api/user_key/upload
// /**
// * Uploads a public key (id_dsa.pub,id_rsa.pub)
// *
// * @param file the public key file
// * @return the ID of the stored public key
// */
// @RequestMapping(value = "/upload/private", method = RequestMethod.POST)
// @RolesAllowed({UserService.USER, UserService.ADMIN})
// public @ResponseBody
// String upload(@RequestParam("file") MultipartFile file) {
// if (!file.isEmpty()) {
// try {
// String originalFileName = file.getOriginalFilename();
// String name = System.currentTimeMillis() + "_" + originalFileName;
// byte[] bytes = file.getBytes();
// String key = new String(bytes, "UTF-8");
//
// Key upk = new Key();
// upk.setKey(key);
// upk.setName(name);
// KeyPair pair = new KeyPair();
// pair.setPrivateKey(upk);
// service.save(pair);
//
// return pair.getId();
// } catch (IOException | IllegalStateException ex) {
// Logger.getLogger(KeyPairController.class.getName()).log(Level.SEVERE, null, ex);
// } catch (KeyException ex) {
// Logger.getLogger(KeyPairController.class.getName()).log(Level.SEVERE, null, ex);
// }
// }
// return null;
// }
// curl -H "Content-KeyType: application/json" -X POST -d '{"key":"ssh-rsa AAAAB3NzaDWBqs75i849MytgwgQcRYMcsXIki0yeYTKABH6JqoiyFBHtYlyh/EV1t6cujb9LyNP4J5EN4fPbtwKYvxecd0LojSPxl4wjQlfrHyg6iKUYB7hVzGqACMvgYZHrtHPfrdEmOGPplPVPpoaX2j+u0BZ0yYhrWMKjzyYZKa68yy5N18+Gq+1p83HfUDwIU9wWaUYdgEvDujqF6b8p3z6LDx9Ob+RanSMZSt+b8eZRcd+F2Oy/gieJEJ8kc152VIOv8UY1xB3hVEwVnSRGgrAsa+9PChfF6efXUGWiKf8KBlWgBOYsSTsOY4ks9zkXMnbcTdC+o7xspOkyIcWjv us@u\n","name":"id_rsa.pub"}' localhost:8080/drip-api/user_key/
/**
* Posts the Key and stores it. The Key is a container for public pair
* contents. The public pair contents are represented in the 'pair' field.
* All new lines in the 'pair' field have to be replaced with the '\n'
* character.
*
* @param pair. The Key
* @return the ID of the Key
*/
@RequestMapping(method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 400, condition = "Key can't be empty")
})
public @ResponseBody
String postKeyPair(@RequestBody KeyPair pair) {
if (pair.getPrivateKey() == null && pair.getPublicKey() == null) {
throw new NullKeyException();
}
service.save(pair);
return pair.getId();
}
/**
* Gets the Key.
*
* @param id . The ID of the Key to return
* @return The Key
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
KeyPair get(@PathVariable("id") String id) {
KeyPair key = service.findOne(id);
if (key == null) {
throw new NotFoundException();
}
return key;
}
@RequestMapping(value = "/sample", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
KeyPair geta() throws Exception {
try {
KeyPair pair = new KeyPair();
Key pk = new Key();
Map<String, String> attributes = new HashMap<>();
attributes.put("domain_name", "Virginia");
pk.setAttributes(attributes);
pk.setKey("-----BEGIN RSA PRIVATE KEY-----\\nMIIEogIBAAm6AALYxkJFNzD3bfVJ4+hMY5j0/kqM9CURLKXMlYuAysnvoG8wZKx9Bedefm\\neNSse4zTg798ZA2kDMZFIrwp1Asetj8DDu5fhG5DjyI3g6iJltS5zFQdMXneDlHXBX8cncSzNY\\nRx0NdjEMAe7YttvI8FNlxL0VnMFli/HB/ftzYMe5+AmkSROncVGHiwoiUpj+vtobCFOYtXsCf6ri\\nd4lgWA5wv6DZT/JKCYymiBqgSXu3ueFcEzw5SAukARWVjn1xccjZkokFfBbO/FpYY00TrUTBw9S6\\nD3iM+gj8RT6EKILOmhrt71D21S95WAWIT7h2YBsy1KAvMixhNf9VaQIDAQABAoIBAHhVYK3Xl3tr\\nN1Xm0ctJTQg3ijxhR2qsUBgGUokqezpdOoD2zbbX1GLr967U9pwxzUpELexexwiTvk\\nnLv8D7ui6qbRsmc4DSsWBRSophVIVFKQmftO8Xow6x+fuYJAYmsicM1KIYHBILtL+PSzV8anenWq\\nKQ3r0tfCiQhEzKEk4b1uT3SJWQyHE++JAhVkO7lIeb6S9Dg1jAaAeMnJ/NiMxTarpPRnxe6hsTsH\\ngG1iKWo+Skcl4SknOc+CMEfyDjG4FL7MGhKduahsO8vMUrgGsDD7EH3NiX/FweB8La6qpDYAwFpC\\nycrooyhiyzw8Wb5gGaYnmvr9l70CgYEAx74O8JleXaHpxEAmh4h7VbLmJ3mOylfBmOdzcHeedJQw\\nack2SAv65WBI9S9MEQ7J/vFuyw5HNk3C/mcWgzDQXSNIhHLvl/Z9sux/Qpm3SQWLz0RBxKV3dJ4r\\nwcAxzVA93+/L1Nee+VOKnlyRumvVa6+XLsLagpap2AVcTqlerMcCgYEAx3T2pXtqkCE9eU/ov22r\\npdaKjgHoGOUg1CMEfWi/Ch6sYIIRyrHz6dhy+yR1pXNgPbLWdrn8l88F3+IsmbaMupMgRmqwEC3G\\n9Y2FglGIVvRdZaagvRxLzRCcvcN4v6OYs9ST4o1xlv7Qxphld+0XDKv7VSCv/rASuK8BqlFL3E8C\\ngYArMXJRnRjG7qh6g9TRIjZphdI3XxX9s5Rt2D8iZvuhAhqmBZjzY4PR7kxYmO2+EpCjzNnEl0XW\\n/GHaWbiIjhnAykx4N9KP7gGom3O5lzwHUme1XnFKcO2wDjQwJbufRmba8iQF1srN577mF+Z7ha4V\\nJ1duCTzvWF1KFX6sk/uhKQKBgAcDFai7rgNjJ8YcCRKxyFcMM9LKPl6hr4XFtWKzTAQPEABUkkuN\\n9gVClsg9f+VRKRECOIf0Ae1UWeCFEwxUXp4wjfHrzkTDVztKvmbWdvSXorDwKrZ7SC7tZpVFSfly\\nxuuLjadpUZT9YFmbAfY1X5oSccOMYqORjRbxEB3svb4BAoGAGTgFuq9Zojh/KIqY8b4HpEfmh6CQ\\nhLVfD98Nqd6GDbxgvIM0v4mFXE92x2jn35Ia0JdFyh3B8Vkl7sqQZfxDFXI9O9pte2mPJxY9ICaY\\n55+X/SN1pd53BH+gaPZJy/R+Vpvs5MN48ho=\\n-----END RSA PRIVATE KEY-----\\n");
pk.setType(Key.KeyType.PRIVATE);
pair.setPrivateKey(pk);
return pair;
} catch (KeyException ex) {
Logger.getLogger(KeyPairController.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* Gets the IDs of all the stored Key
*
* @return a list of all the IDs
*/
@RequestMapping(value = "/ids", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
List<String> getIds() {
List<KeyPair> all = service.findAll();
List<String> ids = new ArrayList<>();
for (KeyPair tr : all) {
ids.add(tr.getId());
}
return ids;
}
/**
* Deletes a Key
*
* @param id. The ID of the Key to deleted.
* @return The ID of the deleted Key
*/
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String delete(@PathVariable("id") String id) {
service.delete(service.findOne(id));
return "Deleted: " + id;
}
@RequestMapping(value = "/all", method = RequestMethod.DELETE)
@RolesAllowed({UserService.ADMIN})
public @ResponseBody
String deleteAll() {
service.deleteAll();
return "Done";
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.v1.rest;
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.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.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
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.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;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for handling user scripts. These user can be
* used by the provisoner to run on the created VMs.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v1.0/script")
@Component
@StatusCodes({
@ResponseCode(code = 401, condition = "Bad credentials")
})
public class ScriptController {
@Autowired
private ScriptService scriptService;
// curl -v -X POST -F "file=@script.sh" localhost:8080/drip-api/rest/user_script/upload
/**
* Uploads a script
*
* @param file. The file of the script
* @return the ID of the stopred script
*/
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String uploadUserScript(@RequestParam("file") MultipartFile file) {
if (!file.isEmpty()) {
try {
String originalFileName = file.getOriginalFilename();
String name = System.currentTimeMillis() + "_" + originalFileName;
byte[] bytes = file.getBytes();
String conents = new String(bytes, "UTF-8");
Script us = new Script();
us.setContents(conents);
us.setName(name);
scriptService.save(us);
return us.getId();
} catch (IOException | IllegalStateException ex) {
Logger.getLogger(ScriptController.class.getName()).log(Level.SEVERE, null, ex);
}
}
return null;
}
@RequestMapping(method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String uploadUserScript(@RequestBody Script script) {
return null;
}
/**
* Gets a script
*
* @param id. The ID of the script to return
* @return the script
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Script get(@PathVariable("id") String id) {
return scriptService.findOne(id);
}
@RequestMapping(value = "/sample", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Script get() {
Script script = new Script();
script.setContents("#! /bin/bash\n"
+ " apt-get update\n"
+ " apt-get -y install linux-image-extra-$(uname -r) linux-image-extra-virtual\n"
+ " apt-get -y install apt-transport-https ca-certificates curl software-properties-common\n"
+ " curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -\n"
+ " apt-key fingerprint 0EBFCD88\n"
+ " add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"\n"
+ " apt-get update\n"
+ " apt-get -y install docker-ce\n"
+ " service docker restart");
script.setName("setupDocker.sh");
return script;
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String delete(@PathVariable("id") String id) {
Script script = scriptService.findOne(id);
if (script == null) {
throw new NotFoundException();
}
scriptService.delete(id);
return "Deleted: " + id;
}
@RequestMapping(value = "/all", method = RequestMethod.DELETE)
@RolesAllowed({UserService.ADMIN})
public @ResponseBody
String deleteAll() {
scriptService.deleteAll();
return "Done";
}
/**
* Gets the IDs of all the stored scripts
*
* @return a list of all the IDs
*/
@RequestMapping(value = "/ids", method = RequestMethod.GET)
public @ResponseBody
List<String> getIds() {
List<Script> all = scriptService.findAll();
List<String> ids = new ArrayList<>();
for (Script us : all) {
ids.add(us.getId());
}
return ids;
}
}
......@@ -2,17 +2,8 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="slolved cap error">
<change afterPath="$PROJECT_DIR$/src/planner/planner.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/planner/spec_service.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/planner/basic_planner.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/basic_planner.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/rpc_server.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/rpc_server.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/easy-install.pth" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/prettytable.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/pyparsing.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/setuptools-40.8.0-py3.6.egg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/setuptools.pth" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/six.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/setuptools-40.8.0-py3.6.egg" beforeDir="false" afterPath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/setuptools-40.8.0-py3.6.egg" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
......@@ -159,7 +150,28 @@
<option name="project" value="LOCAL" />
<updated>1569889346968</updated>
</task>
<option name="localTasksCounter" value="6" />
<task id="LOCAL-00006" summary="refactor planner: separate functions">
<created>1570101378502</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1570101378502</updated>
</task>
<task id="LOCAL-00007" summary="split methods to util and set node properties to default">
<created>1570204408643</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1570204408643</updated>
</task>
<task id="LOCAL-00008" summary="slolved cap error">
<created>1570268541450</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1570268541450</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
......@@ -176,13 +188,15 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="slolved cap error" />
<MESSAGE value="produces valid TOSCA" />
<MESSAGE value="format TOSCA output" />
<MESSAGE value="changed to ubunut 17.10" />
<MESSAGE value="debug" />
<MESSAGE value="check if message is byte" />
<option name="LAST_COMMIT_MESSAGE" value="check if message is byte" />
<MESSAGE value="refactor planner: separate functions" />
<MESSAGE value="split methods to util and set node properties to default" />
<MESSAGE value="slolved cap error" />
<option name="LAST_COMMIT_MESSAGE" value="slolved cap error" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
......@@ -192,11 +206,6 @@
<line>64</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/planner/planner.py</url>
<line>44</line>
<option name="timeStamp" value="5" />
</line-breakpoint>
</breakpoints>
<default-breakpoints>
<breakpoint type="python-exception">
......
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