Commit b05c8605 authored by Oceans's avatar Oceans

Merge branch 'package' of https://github.com/skoulouzis/DRIP into package

parents 6b4ca7a3 cb72571b
......@@ -3,4 +3,6 @@
/drip-planner/target/
/drip-commons/nbproject/
/drip-simple_planner/target/
/drip-provisioner/target/
\ No newline at end of file
/drip-provisioner/target/
/target/
/drip-planner2provisioner/target/
\ No newline at end of file
{"creationDate":1488794695660,"parameters":[{"name":"com.amazonaws.AmazonServiceException","encoding":"UTF-8","value":"The maximum number of VPCs has been reached. (Service: AmazonEC2; Status Code: 400; Error Code: VpcLimitExceeded; Request ID: e854939e-5386-46f3-baa8-4e3c425b98ee)"}]}
\ No newline at end of file
{"creationDate":1488801250836,"parameters":[{"name":"2e5dafb6-5a1c-4a66-9dca-5841f99ea735","encoding":"UTF-8","value":"publicKeyPath: /tmp/Input-7642741842514/user.pem\nuserName: zh9314\nsubnets:\n- {name: s1, subnet: 192.168.10.0, netmask: 255.255.255.0}\ncomponents:\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\n type: Switch.nodes.Compute\n nodeType: t2.medium\n OStype: Ubuntu 16.04\n script: /tmp/Input-7642741842514/guiscipt.sh\n domain: ec2.us-east-1.amazonaws.com\n installation: null\n clusterType: swarm\n role: master\n dockers: mogswitch/ProxyTranscoder:1.0\n public_address: 54.236.125.129\n instanceId: i-01067856cdd3be521\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.10}\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\n type: Switch.nodes.Compute\n nodeType: t2.medium\n OStype: Ubuntu 16.04\n script: /tmp/Input-7642741842514/guiscipt.sh\n domain: ec2.us-east-1.amazonaws.com\n installation: null\n clusterType: swarm\n role: slave\n dockers: mogswitch/ProxyTranscoder:1.0\n public_address: 54.236.125.129\n instanceId: i-01067856cdd3be521\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\n"},{"name":"kubernetes","encoding":"UTF-8","value":"54.236.125.129 ubuntu /tmp/Input-7642741842514/Virginia.pem master\n54.236.125.129 ubuntu /tmp/Input-7642741842514/Virginia.pem slave\n"}]}
\ No newline at end of file
{"creationDate":1488805337447,"parameters":[{"name":"2e5dafb6-5a1c-4a66-9dca-5841f99ea735","encoding":"UTF-8","value":"publicKeyPath: /tmp/Input-11594765342486/user.pem\nuserName: zh9314\nsubnets:\n\n- {name: s1, subnet: 192.168.10.0, netmask: 255.255.255.0}\ncomponents:\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\n type: Switch.nodes.Compute\n nodeType: t2.medium\n OStype: Ubuntu 16.04\n script: /tmp/Input-11594765342486/guiscipt.sh\n domain: ec2.us-east-1.amazonaws.com\n installation: null\n clusterType: swarm\n role: master\n dockers: mogswitch/ProxyTranscoder:1.0\n public_address: 34.207.73.18\n instanceId: i-0e82b5624a0df99b1\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.10}\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\n type: Switch.nodes.Compute\n nodeType: t2.medium\n OStype: Ubuntu 16.04\n script: /tmp/Input-11594765342486/guiscipt.sh\n domain: ec2.us-east-1.amazonaws.com\n installation: null\n clusterType: swarm\n role: slave\n dockers: mogswitch/ProxyTranscoder:1.0\n public_address: 34.207.73.18\n instanceId: i-0e82b5624a0df99b1\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\n"},{"name":"kubernetes","encoding":"UTF-8","value":"34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem master\n34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem slave\n"}]}
\ No newline at end of file
{"creationDate":1488808559406,"parameters":[{"name":"2e5dafb6-5a1c-4a66-9dca-5841f99ea735","encoding":"UTF-8","value":"publicKeyPath:/tmp/Input-14773430542445/user.pem\nuserName:zh9314\nsubnets:\n-{name:s1,subnet:192.168.10.0,netmask:255.255.255.0}\ncomponents:\n-name:8fcc1788d9ee462c826572c79fdb2a6a\ntype:Switch.nodes.Compute\nnodeType:t2.medium\nOStype:Ubuntu16.04\nscript:/tmp/Input-14773430542445/guiscipt.sh\ndomain:ec2.us-east-1.amazonaws.com\ninstallation:null\nclusterType:swarm\nrole:master\ndockers:mogswitch/ProxyTranscoder:1.0\npublic_address:52.73.245.157\ninstanceId:i-0aea14557986d25d0\nethernet_port:\n-{name:p1,subnet_name:s1,address:192.168.10.10}\n-name:8fcc1788d9ee462c826572c79fdb2a6a\ntype:Switch.nodes.Compute\nnodeType:t2.medium\nOStype:Ubuntu16.04\nscript:/tmp/Input-14773430542445/guiscipt.sh\ndomain:ec2.us-east-1.amazonaws.com\ninstallation:null\nclusterType:swarm\nrole:slave\ndockers:mogswitch/ProxyTranscoder:1.0\npublic_address:52.73.245.157\ninstanceId:i-0aea14557986d25d0\nethernet_port:\n-{name:p1,subnet_name:s1,address:192.168.10.11}\n"},{"name":"kubernetes","encoding":"UTF-8","value":"52.73.245.157ubuntu/tmp/Input-14773430542445/Virginia.pemmaster\n52.73.245.157ubuntu/tmp/Input-14773430542445/Virginia.pemslave\n"}]}
\ No newline at end of file
{"creationDate":1488368936945,"parameters":[{"name":"f293ff03-4b82-49e2-871a-899aadf821ce","encoding":"UTF-8","value":"publicKeyPath: /tmp/Input-4007028381500/user.pem\nuserName: zh9314\nsubnets:\n- {name: s1, subnet: 192.168.10.0, netmask: 255.255.255.0}\ncomponents:\n- name: faab6756-61b6-4800-bffa-ae9d859a9d6c\n type: Switch.nodes.Compute\n nodetype: t2.medium\n OStype: Ubuntu 16.04\n domain: ec2.us-east-1.amazonaws.com\n script: /tmp/Input-4007028381500/guiscipt.sh\n installation: null\n role: master\n dockers: mogswitch/InputDistributor\n public_address: 54.144.0.91\n instanceId: i-0e78cbf853328b820\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.10}\n- name: 1c75eedf-8497-46fe-aeb8-dab6a62154cb\n type: Switch.nodes.Compute\n nodetype: t2.medium\n OStype: Ubuntu 16.04\n domain: ec2.us-east-1.amazonaws.com\n script: /tmp/Input-4007028381500/guiscipt.sh\n installation: null\n role: slave\n dockers: mogswitch/ProxyTranscoder\n public_address: 34.207.254.160\n instanceId: i-0a99ea18fcc77ed7a\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\n"},{"name":"kubernetes","encoding":"UTF-8","value":"54.144.0.91 ubuntu /tmp/Input-4007028381500/Virginia.pem master\n34.207.254.160 ubuntu /tmp/Input-4007028381500/Virginia.pem slave\n"}]}
\ No newline at end of file
......@@ -119,6 +119,13 @@
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-planner2provisioner</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
......
......@@ -29,4 +29,8 @@ public class BadRequestException extends RuntimeException {
super(massage);
}
public BadRequestException() {
super();
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Cloud credentials not found")
public class CloudCredentialsNotFoundException extends RuntimeException {
public CloudCredentialsNotFoundException(String string) {
super(string);
}
public CloudCredentialsNotFoundException() {
super();
}
}
/*
* 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.exception;
/**
*
* @author S. Koulouzis
*/
public class ExceptionHandler {
public static RuntimeException generateException(String name, String value) {
if (value == null) {
return new InternalServerErrorExeption();
}
if (value.contains("The maximum number of VPCs has been reached")) {
return new VMLimitException(name + "." + value);
} else {
return new InternalServerErrorExeption();
}
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public class InternalServerErrorException extends RuntimeException {
public InternalServerErrorException(String massage) {
super(massage);
}
public InternalServerErrorException() {
super();
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public class InternalServerErrorExeption extends RuntimeException {
public InternalServerErrorExeption(String massage) {
super(massage);
}
public InternalServerErrorExeption() {
super();
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Key can't be null")
public class NullKeyException extends RuntimeException {
public NullKeyException(String string) {
super(string);
}
public NullKeyException() {
super();
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "KeyId can't be null")
public class NullKeyIDException extends RuntimeException {
public NullKeyIDException(String string) {
super(string);
}
public NullKeyIDException() {
super();
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "User already exists")
public class PasswordNullException extends RuntimeException {
public PasswordNullException() {
super();
}
public PasswordNullException(String string) {
super(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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Plan not found")
public class PlanNotFoundException extends RuntimeException {
public PlanNotFoundException(String string) {
super(string);
}
public PlanNotFoundException() {
super();
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "User already exists")
public class UserExistsException extends RuntimeException {
public UserExistsException() {
super();
}
public UserExistsException(String string) {
super(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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "User not found")
public class UserNotFoundException extends RuntimeException {
public UserNotFoundException(String string) {
super(string);
}
public UserNotFoundException() {
super();
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "User name can't be null")
public class UserNullException extends RuntimeException {
public UserNullException(String massage) {
super(massage);
}
public UserNullException() {
super();
}
}
/*
* 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.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR, reason = "The maximum number of VMs has been reached")
public class VMLimitException extends RuntimeException {
public VMLimitException(String string) {
super(string);
}
public VMLimitException() {
super();
}
}
......@@ -33,6 +33,8 @@ import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.dao.CloudCredentialsDao;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.exception.NullKeyException;
import nl.uva.sne.drip.api.exception.NullKeyIDException;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.types.LoginKey;
import org.apache.commons.io.FilenameUtils;
......@@ -60,10 +62,10 @@ public class CloudConfigurationController {
public @ResponseBody
String postConf(@RequestBody CloudCredentials cc) {
if (cc.getKey() == null) {
throw new BadRequestException("key can't be null");
throw new NullKeyException();
}
if (cc.getKeyIdAlias() == null) {
throw new BadRequestException("keyIdAlias can't be null");
throw new NullKeyIDException();
}
cloudCredentialsDao.save(cc);
return cc.getId();
......
......@@ -28,6 +28,7 @@ import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.dao.CloudCredentialsDao;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.MessageParameter;
import org.json.JSONException;
......@@ -80,8 +81,8 @@ public class DeployController {
try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) {
Message deployerInvokationMessage = buildDeployerMessage(provisionID, clusterType.toLowerCase());
// Message response = deployer.call(deployerInvokationMessage);
Message response = generateFakeResponse();
Message response = (deployer.call(deployerInvokationMessage));
// Message response = generateFakeResponse();
List<MessageParameter> params = response.getParameters();
ClusterCredentials clusterCred = new ClusterCredentials();
for (MessageParameter p : params) {
......@@ -104,11 +105,42 @@ public class DeployController {
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
ClusterCredentials get(@PathVariable("id") String id) {
return clusterCredentialService.getDao().findOne(id);
ClusterCredentials clusterC = clusterCredentialService.getDao().findOne(id);
if (clusterC == null) {
throw new NotFoundException();
}
return clusterC;
}
@RequestMapping(value = "/ids", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
List<String> getIds() {
List<ClusterCredentials> all = clusterCredentialService.getDao().findAll();
List<String> ids = new ArrayList<>(all.size());
for (ClusterCredentials pi : all) {
ids.add(pi.getId());
}
return ids;
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String delete(@PathVariable("id") String id) {
ClusterCredentials cred = clusterCredentialService.getDao().findOne(id);
if (cred != null) {
provisionService.getDao().delete(id);
return "Deleted : " + id;
}
throw new NotFoundException();
}
private Message buildDeployerMessage(String provisionID, String clusterType) {
ProvisionInfo pro = provisionService.getDao().findOne(provisionID);
if (pro == null) {
throw new NotFoundException();
}
String cloudConfID = pro.getCloudConfID();
CloudCredentials cCred = cloudCredentialsDao.findOne(cloudConfID);
List<LoginKey> loginKeys = cCred.getLoginKeys();
......
......@@ -15,7 +15,6 @@
*/
package nl.uva.sne.drip.api.rest;
import nl.uva.sne.drip.api.service.SimplePlannerService;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
......@@ -33,7 +32,6 @@ 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.PlannerService;
import nl.uva.sne.drip.api.service.ToscaService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.types.Plan;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -47,9 +45,8 @@ import org.springframework.web.bind.annotation.RequestParam;
@Component
public class PlannerController {
@Autowired
private SimplePlannerService simplePlannerService;
// @Autowired
// private SimplePlannerService simplePlannerService;
@Autowired
private PlannerService plannerService;
......@@ -76,7 +73,7 @@ public class PlannerController {
public @ResponseBody
String get(@PathVariable("id") String id, @RequestParam(value = "format") String format) {
try {
return simplePlannerService.get(id, format);
return plannerService.get(id, format);
} catch (JSONException ex) {
Logger.getLogger(ToscaController.class.getName()).log(Level.SEVERE, null, ex);
}
......@@ -87,22 +84,22 @@ public class PlannerController {
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String getToscaID(@PathVariable("id") String id) {
return simplePlannerService.getToscaID(id);
return plannerService.getToscaID(id);
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String delete(@PathVariable("id") String id) {
simplePlannerService.getDao().delete(id);
return "Deleted tosca :" + id;
plannerService.getDao().delete(id);
return "Deleted : " + id;
}
@RequestMapping(value = "/ids")
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
List<String> getIds() {
List<Plan> all = simplePlannerService.findAll();
List<Plan> all = plannerService.findAll();
List<String> ids = new ArrayList<>();
for (Plan tr : all) {
ids.add(tr.getId());
......
......@@ -82,7 +82,7 @@ public class ToscaController {
public @ResponseBody
String delete(@PathVariable("id") String id) {
toscaService.delete(id);
return "Deleted tosca :" + id;
return "Deleted : " + id;
}
// http://localhost:8080/drip-api/tosca/ids
......
......@@ -22,6 +22,10 @@ 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;
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.commons.types.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -62,14 +66,14 @@ public class UserController {
public @ResponseBody
String register(@RequestBody User user) {
if (user.getUsername() == null) {
throw new BadRequestException("Username can't be null");
throw new UserNullException();
}
if (user.getPassword() == null) {
throw new BadRequestException("Password can't be null");
throw new PasswordNullException();
}
UserDetails registeredUser = service.loadUserByUsername(user.getUsername());
if (registeredUser != null) {
throw new BadRequestException("Username " + user.getUsername() + " is used");
throw new UserExistsException("Username " + user.getUsername() + " is used");
}
user.setPassword(new BCryptPasswordEncoder().encode(user.getPassword()));
service.getDao().save(user);
......@@ -82,7 +86,7 @@ public class UserController {
String modify(@RequestBody User user) {
UserDetails registeredUser = service.loadUserByUsername(user.getUsername());
if (registeredUser == null) {
throw new NotFoundException("User " + user.getUsername() + " not found");
throw new UserNotFoundException("User " + user.getUsername() + " not found");
}
return this.register(user);
}
......@@ -94,7 +98,7 @@ public class UserController {
try {
User user = service.getDao().findOne(id);
if (user == null) {
throw new NotFoundException();
throw new UserNotFoundException("User " + id + " not found");
}
return user;
} catch (Exception ex) {
......@@ -110,10 +114,10 @@ public class UserController {
try {
User user = service.getDao().findOne(id);
if (user == null) {
throw new NotFoundException();
throw new UserNotFoundException("User " + id + " not found");
}
service.getDao().delete(user);
return "Deleted used :" + id;
return "Deleted : " + id;
} catch (Exception ex) {
Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
}
......
......@@ -15,8 +15,11 @@ import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
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.commons.types.Message;
import nl.uva.sne.drip.commons.types.MessageParameter;
import nl.uva.sne.drip.commons.utils.Converter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -46,6 +49,7 @@ public abstract class DRIPCaller implements AutoCloseable {
private final Channel channel;
private final String replyQueueName;
private final String requestQeueName;
private final ObjectMapper mapper;
public DRIPCaller(String messageBrokerHost, String requestQeueName) throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
......@@ -59,6 +63,8 @@ public abstract class DRIPCaller implements AutoCloseable {
// create a single callback queue per client not per requests.
replyQueueName = channel.queueDeclare().getQueue();
this.requestQeueName = requestQeueName;
this.mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
}
/**
......@@ -94,8 +100,6 @@ public abstract class DRIPCaller implements AutoCloseable {
public Message call(Message r) throws IOException, TimeoutException, InterruptedException, JSONException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
String jsonInString = mapper.writeValueAsString(r);
//Build a correlation ID to distinguish responds
......@@ -117,11 +121,16 @@ public abstract class DRIPCaller implements AutoCloseable {
}
}
});
String strResponse = response.take();
strResponse = strResponse.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
System.err.println(strResponse);
// return unMarshallWithSimpleJson(strResponse);
return mapper.readValue(strResponse, Message.class);
String resp = response.take();
String clean = resp;
if (resp.contains("'null'")) {
clean = resp.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
}
if (clean.contains("\"value\":{\"")) {
return Converter.string2Message(clean);
}
Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Got: {0}", clean);
return mapper.readValue(clean, Message.class);
}
private Message unMarshallWithSimpleJson(String strResponse) throws JSONException {
......@@ -147,4 +156,11 @@ public abstract class DRIPCaller implements AutoCloseable {
}
// public Message unmarshall(String strResponse) throws IOException {
//
// mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
// strResponse = strResponse.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
//// return unMarshallWithSimpleJson(strResponse);
// return mapper.readValue(strResponse, Message.class);
// }
}
......@@ -15,15 +15,18 @@
*/
package nl.uva.sne.drip.api.rpc;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.commons.types.Message;
/**
*
* @author S. Koulouzis.
*/
public class PlannerCaller extends DRIPCaller {
public class PlannerCaller extends DRIPCaller {
private static final String REQUEST_QUEUE_NAME = "planner_queue";
......@@ -31,4 +34,33 @@ public class PlannerCaller extends DRIPCaller {
super(messageBrokerHost, REQUEST_QUEUE_NAME);
}
public String generateFakeResponse(Message plannerInvokationMessage) throws IOException {
return "{\n"
+ " \"creationDate\": 1487002029722,\n"
+ " \"parameters\": [\n"
+ " {\n"
+ " \"url\": null,\n"
+ " \"encoding\": \"UTF-8\",\n"
+ " \"value\": \"{\\\"name\\\":\\\"2d13d708e3a9441ab8336ce874e08dd1\\\",\\\"size\\\":\\\"Small\\\",\\\"docker\\\":\\\"mogswitch/InputDistributor\\\"}\",\n"
+ " \"name\": \"component\",\n"
+ " \"attributes\": null\n"
+ " },\n"
+ " {\n"
+ " \"url\": null,\n"
+ " \"encoding\": \"UTF-8\",\n"
+ " \"value\": \"{\\\"name\\\":\\\"8fcc1788d9ee462c826572c79fdb2a6a\\\",\\\"size\\\":\\\"Small\\\",\\\"docker\\\":\\\"mogswitch/InputDistributor\\\"}\",\n"
+ " \"name\": \"component\",\n"
+ " \"attributes\": null\n"
+ " },\n"
+ " {\n"
+ " \"url\": null,\n"
+ " \"encoding\": \"UTF-8\",\n"
+ " \"value\": \"{\\\"name\\\":\\\"5e0add703c8a43938a39301f572e46c0\\\",\\\"size\\\":\\\"Small\\\",\\\"docker\\\":\\\"mogswitch/InputDistributor\\\"}\",\n"
+ " \"name\": \"component\",\n"
+ " \"attributes\": null\n"
+ " }\n"
+ " ]\n"
+ "}";
}
}
......@@ -27,13 +27,15 @@ import java.util.Set;
import java.util.concurrent.TimeoutException;
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.commons.types.Message;
import nl.uva.sne.drip.commons.types.MessageParameter;
import nl.uva.sne.drip.commons.types.Plan;
import nl.uva.sne.drip.commons.types.SimplePlanContainer;
import nl.uva.sne.drip.commons.types.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
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;
......@@ -59,18 +61,30 @@ public class PlannerService {
try (PlannerCaller planner = new PlannerCaller(messageBrokerHost)) {
Message plannerInvokationMessage = buildPlannerMessage(toscaId);
Message plannerReturnedMessage = planner.call(plannerInvokationMessage);
Message plannerReturnedMessage = (planner.call(plannerInvokationMessage));
// Message plannerReturnedMessage = (planner.generateFakeResponse(plannerInvokationMessage));
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
String jsonString = mapper.writeValueAsString(plannerReturnedMessage);
SimplePlanContainer simplePlan = Converter.plannerOutput2SimplePlanContainer(jsonString);
List<MessageParameter> messageParams = plannerReturnedMessage.getParameters();
StringBuilder jsonArrayString = new StringBuilder();
jsonArrayString.append("[");
String prefix = "";
for (MessageParameter mp : messageParams) {
String value = mp.getValue();
jsonArrayString.append(prefix);
prefix = ",";
String jsonValue = value.replaceAll("\\\"", "\"");
jsonArrayString.append(jsonValue);
}
jsonArrayString.append("]");
SimplePlanContainer simplePlan = P2PConverter.convert(jsonArrayString.toString(), "vm_user", "Ubuntu 16.04", "swarm");
Plan topLevel = new Plan();
topLevel.setLevel(0);
topLevel.setToscaID(toscaId);
topLevel.setName("planner_output_all.yml");
topLevel.setKvMap(Converter.ymlString2Map(simplePlan.getTopLevel()));
Map<String, String> map = simplePlan.getLowerLevels();
topLevel.setKvMap(Converter.ymlString2Map(simplePlan.topLevelContents));
Map<String, String> map = simplePlan.lowerLevelContents;
Set<String> loweLevelPlansIDs = new HashSet<>();
for (String lowLevelNames : map.keySet()) {
Plan lowLevelPlan = new Plan();
......@@ -91,7 +105,7 @@ public class PlannerService {
private Message buildPlannerMessage(String toscaId) throws JSONException, UnsupportedEncodingException {
ToscaRepresentation t2 = toscaService.getDao().findOne(toscaId);
if (t2 == null) {
throw new BadRequestException("The description: " + toscaId + " is a plan. Cannot be used as planner input");
throw new BadRequestException();
}
Map<String, Object> map = t2.getKvMap();
String json = Converter.map2JsonString(map);
......@@ -112,4 +126,51 @@ public class PlannerService {
return invokationMessage;
}
public String get(String id, String fromat) throws JSONException {
Plan plan = planDao.findOne(id);
if (plan == null) {
throw new NotFoundException();
}
Map<String, Object> map = plan.getKvMap();
Set<String> ids = plan.getLoweLevelPlanIDs();
for (String lowID : ids) {
Map<String, Object> lowLevelMap = planDao.findOne(lowID).getKvMap();
map.putAll(lowLevelMap);
}
if (fromat != null && fromat.equals("yml")) {
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
}
if (fromat != null && fromat.equals("json")) {
String jsonStr = Converter.map2JsonString(map);
jsonStr = jsonStr.replaceAll("\\uff0E", "\\.");
return jsonStr;
}
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
}
public String getToscaID(String id) {
return planDao.findOne(id).getToscaID();
}
public PlanDao getDao() {
return this.planDao;
}
public List<Plan> findAll() {
List<Plan> all = planDao.findAll();
List<Plan> topLevel = new ArrayList<>();
for (Plan p : all) {
if (p.getLevel() == 0) {
topLevel.add(p);
}
}
return topLevel;
}
}
......@@ -61,7 +61,7 @@ public class SimplePlannerService {
Plan topLevel;
try (PlannerCaller planner = new PlannerCaller(messageBrokerHost)) {
Message plannerReturnedMessage = planner.call(plannerInvokationMessage);
Message plannerReturnedMessage = (planner.call(plannerInvokationMessage));
List<MessageParameter> planFiles = plannerReturnedMessage.getParameters();
topLevel = new Plan();
Set<String> ids = topLevel.getLoweLevelPlanIDs();
......
# Internal log4j configuration. This is not packaged and distributed. The using
# party is in control of its own log4j.properties.
# LOG4J Configuration
# ===================
# Root logger option
log4j.rootLogger=INFO, stdout
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=FINE, A1
log4j.appender.authorizationLog=org.apache.log4j.RollingFileAppender
log4j.appender.authorizationLog.File=logs/authorization.log
log4j.appender.authorizationLog.MaxFileSize=20MB
log4j.appender.authorizationLog.MaxBackupIndex=10
log4j.appender.authorizationLog.layout=org.apache.log4j.PatternLayout
log4j.appender.authorizationLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n
log4j.appender.authenticationLog=org.apache.log4j.RollingFileAppender
log4j.appender.authenticationLog.File=logs/authentication.log
log4j.appender.authenticationLog.MaxFileSize=20MB
log4j.appender.authenticationLog.MaxBackupIndex=10
log4j.appender.authenticationLog.layout=org.apache.log4j.PatternLayout
log4j.appender.authenticationLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n
log4j.category.org.apache.http=OFF
log4j.category.io.milton=OFF
log4j.category.org.apache.commons=OFF
log4j.category.org.globus=OFF
log4j.org.apache.axis=OFF
log4j.org.apache.http=OFF
log4j.org.apache.jackrabbit=OFF
log4j.logger.org.apache.jackrabbit=OFF
log4j.logger.httpclient.wire.header=OFF
log4j.logger.httpclient.wire.content=OFF
log4j.logger.org.globus=OFF
log4j.logger.io.milton=SEVERE
log4j.io.milton=SEVERE
log4j.category.authorizationLogger=TRACE, authorizationLog
#log4j.additivity.authorizationLogger=false
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.category.authenticationLogger=DEBUG, authenticationLog
#log4j.additivity.authenticationLogger=false
\ No newline at end of file
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n
\ No newline at end of file
handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
nl.uva.cs.level = FINE
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
org.apache.juli.FileHandler.level = FINE
org.apache.juli.FileHandler.directory = ${catalina.base}/logs
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
\ No newline at end of file
......@@ -58,12 +58,21 @@
<version>1.10.0.RELEASE</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>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-planner2provisioner</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
......
......@@ -30,7 +30,6 @@ public class CloudCredentials {
private String id;
private String key;
private String keyIdAlias;
......
......@@ -17,6 +17,7 @@ package nl.uva.sne.drip.commons.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
......@@ -26,6 +27,8 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import nl.uva.sne.drip.commons.types.CloudCredentials;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.MessageParameter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -37,7 +40,7 @@ import org.yaml.snakeyaml.Yaml;
*/
public class Converter {
private static Map<String, String> EC2_NAME_MAP = new HashMap();
private static final Map<String, String> EC2_NAME_MAP = new HashMap();
public static String ymlString2Json(String yamlString) {
JSONObject jsonObject = new JSONObject(ymlString2Map(yamlString));
......@@ -71,11 +74,6 @@ public class Converter {
return jsonObject2Map(jsonObject);
}
public static SimplePlanContainer plannerOutput2SimplePlanContainer(String jsonString) throws JSONException {
return null;
}
public static Map<String, Object> jsonObject2Map(JSONObject object) throws JSONException {
Map<String, Object> map = new HashMap();
......@@ -144,4 +142,36 @@ public class Converter {
EC2_NAME_MAP.put("key", "AWSSecretKey");
}
public static Message string2Message(String clean) throws JSONException, IOException {
Message mess = new Message();
JSONObject jsonObj = new JSONObject(clean);
long creationDate = jsonObj.getLong("creationDate");
mess.setCreationDate(creationDate);
JSONArray jsonParams = (JSONArray) jsonObj.get("parameters");
List<MessageParameter> params = new ArrayList<>();
for (int i = 0; i < jsonParams.length(); i++) {
MessageParameter p = new MessageParameter();
JSONObject jsonParam = (JSONObject) jsonParams.get(i);
String url;
if (!jsonObj.isNull("url")) {
p.setURL((String) jsonObj.get("url"));
}
if (!jsonObj.isNull("encoding")) {
p.setEncoding(jsonObj.getString("encoding"));
}
if (!jsonObj.isNull("attributes")) {
Map<String, String> attributes = new ObjectMapper().readValue("", Map.class);
p.setAttributes(attributes);
}
String val = jsonParam.getString("value");
val = val.replaceAll("\"", "\\\"");
p.setValue(val);
params.add(p);
}
mess.setParameters(params);
return mess;
}
}
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAm6AALYxkJFNzD3bfVJ4+hMY5j0/kqM9CURLKXMlYuAysnvoG8wZKx9Bedefm
eNSse4zTg798Z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j in json1:
if not json1[j]['type'] == "Switch.nodes.Application.Connection":
print j, json1[j]
nodeDic[j] = i
nodeDic1[i] = j
i = i + 1
#print j, json1[j]
nodeDic[j] = i
nodeDic1[i] = j
i = i + 1
#get the links from the json
links = []
for j in json1:
if json1[j]['type'] == "Switch.nodes.Application.Connection":
print json1[j]['properties']['source']['component_name']
print json1[j]['properties']['target']['component_name']
#print json1[j]['properties']['source']['component_name']
#print json1[j]['properties']['target']['component_name']
link= {}
link['source'] = nodeDic[json1[j]['properties']['source']['component_name']]
link['target'] = nodeDic[json1[j]['properties']['target']['component_name']]
......@@ -88,7 +88,7 @@ def handleDelivery(message):
performance[str(value)] = "1,2,3"
wfJson['performance'] = performance
print wfJson
#print wfJson
#send request to the server
start = time.time()
......@@ -100,32 +100,34 @@ def handleDelivery(message):
res = wf.generateJSON()
end = time.time()
print (end - start)
#print (end - start)
# convert the json to the file required
res1 = {}
for key, value in sorted_nodeDic:
print value, res[str(value)]
res1[nodeDic1[value]] = res[str(value)]
print res1
# generate the json files in the corresponding format as the
outcontent = {}
current_milli_time = lambda: int(round(time.time() * 1000))
outcontent["creationDate"] = current_milli_time()
outcontent["parameters"] = []
par1 = {}
par1["url"] = "null"
par1["encoding"] = "UTF-8"
par1["value"] = res1
par1["attributes"] = "null"
outcontent["parameters"].append(par1)
for key, value in sorted_nodeDic:
par = {}
par["url"] = "null"
par["encoding"] = "UTF-8"
docker = json1[nodeDic1[value]].get('artifacts').get('docker_image').get('file')
res1["name"] = str(nodeDic1[value])
res1["size"] = res[str(value)]
res1["docker"] = str(docker)
#v = str("{\\'name\\':\\'"+str(nodeDic1[value])+"\\',\\'size\\':\\'"+res[str(value)]+"\\',\\'docker\\':\\'"+docker+"\\'}")
par["value"] = res1
par["attributes"] = "null"
outcontent["parameters"].append(par)
return outcontent
def on_request(ch, method, props, body):
response = handleDelivery(body)
ch.basic_publish(exchange='',
routing_key=props.reply_to,
properties=pika.BasicProperties(correlation_id = \
......
......@@ -33,7 +33,7 @@ def main(argv):
SDI_file = arg
data = {}
print workflow_file
#print workflow_file
with open(workflow_file) as data_file:
data = json.load(data_file)
#print data
......@@ -58,13 +58,14 @@ def main(argv):
#get the nodes from the json
nodeDic = {}
nodeDic1 = {}
i = 1
for j in json1:
if not json1[j]['type'] == "Switch.nodes.Application.Connection":
print j, json1[j]
nodeDic[j] = i
nodeDic1[i] = j
i = i + 1
nodeDic[j] = i
nodeDic1[i] = j
i = i + 1
#get the links from the json
links = []
......@@ -118,7 +119,11 @@ def main(argv):
res1 = {}
for key, value in sorted_nodeDic:
print value, res[str(value)]
res1[nodeDic1[value]] = res[str(value)]
res1_value = {}
res1_value["size"] = res[str(value)]
res1_value["docker"] = json1[nodeDic1[value]].get('artifacts').get('docker_image').get('file')
res1[str(nodeDic1[value])] = res1_value
print res1
# generate the json files in the corresponding format as the
outcontent = {}
......@@ -130,6 +135,7 @@ def main(argv):
par1["value"] = res1
par1["attributes"] = "null"
outcontent["parameters"].append(par1)
#print outcontent
return outcontent
......
{
"creationDate": 1488459287833,
"parameters": [
{
"url": null,
"attributes": null,
"value": [
{
"name": "2d13d708e3a9441ab8336ce874e08dd1",
"size": "Small",
"docker": "mogswitch/InputDistributor"
},
{
"name": "8fcc1788d9ee462c826572c79fdb2a6a",
"size": "Small",
"docker": "mogswitch/InputDistributor"
},
{
"name": "5e0add703c8a43938a39301f572e46c0",
"size": "Small",
"docker": "mogswitch/InputDistributor"
}
],
"encoding": "UTF-8"
}
]
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.licensePath>${project.basedir}/../licenseheader.txt</netbeans.hint.licensePath>
</properties>
</project-shared-configuration>
<?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>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-planner2provisioner</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<!--mvn clean compile assembly:single-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass></mainClass>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package nl.uva.sne.drip.drip.converter;
import nl.uva.sne.drip.drip.converter.planner.out.Component;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import java.util.List;
import nl.uva.sne.drip.drip.converter.provisioner.in.Eth;
import nl.uva.sne.drip.drip.converter.provisioner.in.SubTopology;
import nl.uva.sne.drip.drip.converter.provisioner.in.SubTopologyInfo;
import nl.uva.sne.drip.drip.converter.provisioner.in.Subnet;
import nl.uva.sne.drip.drip.converter.provisioner.in.TopTopology;
import nl.uva.sne.drip.drip.converter.provisioner.in.VM;
public class P2PConverter {
public static SimplePlanContainer convert(String plannerOutputJson, String userName, String OStype, String clusterType) throws JsonParseException, JsonMappingException, IOException {
List<Component> components = getInfoFromPlanner(plannerOutputJson);
TopTopology topTopology = new TopTopology();
SubTopology subTopology = new SubTopology();
SubTopologyInfo sti = new SubTopologyInfo();
sti.cloudProvider = "EC2";
sti.topology = UUID.randomUUID().toString();
subTopology.publicKeyPath = "~/.ssh/id_dsa.pub";
subTopology.userName = userName;
Subnet s = new Subnet();
s.name = "s1";
s.subnet = "192.168.10.0";
s.netmask = "255.255.255.0";
subTopology.subnets = new ArrayList<>();
subTopology.subnets.add(s);
subTopology.components = new ArrayList<>();
boolean firstVM = true;
int count = 0;
for (Component cmp : components) {
VM curVM = new VM();
curVM.name = cmp.getName();
curVM.type = "Switch.nodes.Compute";
curVM.OStype = OStype;
curVM.domain = "ec2.us-east-1.amazonaws.com";
curVM.clusterType = clusterType;
curVM.dockers = cmp.getDocker();
curVM.public_address = cmp.getName();
curVM.nodeType = "t2." + cmp.getSize().toLowerCase();
Eth eth = new Eth();
eth.name = "p1";
eth.subnet_name = "s1";
int hostNum = 10 + count++;
String priAddress = "192.168.10." + hostNum;
eth.address = priAddress;
curVM.ethernet_port = new ArrayList<>();
curVM.ethernet_port.add(eth);
if (firstVM) {
curVM.role = "master";
firstVM = false;
} else {
curVM.role = "slave";
}
subTopology.components.add(curVM);
}
sti.subTopology = subTopology;
topTopology.topologies = new ArrayList<>();
topTopology.topologies.add(sti);
SimplePlanContainer spc = generateInfo(topTopology);
return spc;
}
private static List<Component> getInfoFromPlanner(String json) throws IOException {
ObjectMapper mapper = new ObjectMapper();
TypeReference<List<Component>> mapType = new TypeReference<List<Component>>() {
};
List<Component> components = mapper.readValue(json, mapType);
return components;
}
private static SimplePlanContainer generateInfo(TopTopology topTopology) throws JsonProcessingException {
SimplePlanContainer spc = new SimplePlanContainer();
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
String yamlString = mapper.writeValueAsString(topTopology);
spc.topLevelContents = yamlString.substring(4);
Map<String, String> output = new HashMap<>();
for (int i = 0; i < topTopology.topologies.size(); i++) {
String key = topTopology.topologies.get(i).topology;
String value = mapper.writeValueAsString(topTopology.topologies.get(i).subTopology);
output.put(key, value.substring(4));
}
spc.lowerLevelContents = output;
return spc;
}
}
package nl.uva.sne.drip.drip.converter;
import java.util.Map;
public class SimplePlanContainer {
public String topLevelContents;
public Map<String, String> lowerLevelContents;
}
/*
* 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.converter.planner.out;
/**
*
* @author S. Koulouzis
*/
public class Component {
private String name;
private String size;
private String docker;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the size
*/
public String getSize() {
return size;
}
/**
* @param size the size to set
*/
public void setSize(String size) {
this.size = size;
}
/**
* @return the docker
*/
public String getDocker() {
return docker;
}
/**
* @param docker the docker to set
*/
public void setDocker(String docker) {
this.docker = docker;
}
}
package nl.uva.sne.drip.drip.converter.provisioner.in;
public class Eth {
public String name;
public String subnet_name;
public String address;
}
package nl.uva.sne.drip.drip.converter.provisioner.in;
import java.util.ArrayList;
public class SubTopology {
public String publicKeyPath;
public String userName;
//Indicate a subnet that several can be put in.
public ArrayList<Subnet> subnets;
public ArrayList<VM> components;
}
package nl.uva.sne.drip.drip.converter.provisioner.in;
import com.fasterxml.jackson.annotation.JsonIgnore;
public class SubTopologyInfo {
//The name of the topology. It is also the file name of the low level description.
public String topology;
//Currently, only support "EC2" and "ExoGENI"/"GENI". This is not case sensitive.
public String cloudProvider;
//Point to the detailed description of the sub-topology.
@JsonIgnore
public SubTopology subTopology;
}
package nl.uva.sne.drip.drip.converter.provisioner.in;
public class Subnet {
//The name of the subnet. Two subnets cannot have same name in one subnet.
public String name;
public String subnet;
public String netmask;
}
package nl.uva.sne.drip.drip.converter.provisioner.in;
import java.util.ArrayList;
public class TopTopology {
public ArrayList<SubTopologyInfo> topologies;
}
package nl.uva.sne.drip.drip.converter.provisioner.in;
import java.util.ArrayList;
public class VM {
public String name;
public String type;
public String nodeType;
public String OStype;
//Currently, the SIDE subsystem uses this field for GUI.
public String script;
public String domain;
public String installation;
public String clusterType;
//The role of this node in docker cluster.
//The possible value can only be "null", "slave" and "master".
//This is not case sensitive.
public String role;
//The name of the docker in repository, which can be "null".
public String dockers;
//Do not need to be the same with the node name any more.
//The initial value should be "null", which means the public is not determined.
//When the status of the sub-topology is stopped, deleted or failed, this field should also be "null".
public String public_address;
public ArrayList<Eth> ethernet_port;
}
import nl.uva.sne.drip.drip.converter.P2PConverter;
import nl.uva.sne.drip.drip.converter.SimplePlanContainer;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.io.FileUtils;
public class testConverter {
public static void main(String[] args) {
File jsonFile = new File("input.json");
String json = "";
try {
json = FileUtils.readFileToString(jsonFile, "UTF-8");
} catch (IOException e1) {
e1.printStackTrace();
}
try {
SimplePlanContainer spc = P2PConverter.convert(json, "vm_user", "Ubuntu 16.04", "kubernetes");
System.out.println("--topLevel:\n"+spc.topLevelContents);
System.out.println("--lowLevel:");
for (Map.Entry<String, String> entry : spc.lowerLevelContents.entrySet()){
System.out.println(entry.getKey()+":\n"+entry.getValue());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
......@@ -50,6 +50,6 @@
<artifactId>commons-io</artifactId>
<version>2.4</version>
<type>jar</type>
</dependency>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -129,6 +129,7 @@ public class Consumer extends DefaultConsumer {
+ 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);
......@@ -397,26 +398,26 @@ public class Consumer extends DefaultConsumer {
if (name.equals("topology")) {
JSONObject attributes = param.getJSONObject("attributes");
int fileLevel = Integer.valueOf((String) attributes.get("level"));
String[] parts = ((String) attributes.get("filename")).split("_");
String fileName = "";
String prefix = "";
//Clear date part form file name
for (int j = 1; j < parts.length; j++) {
fileName += prefix + parts[j];
prefix = "_";
}
if (fileLevel == level) {
File topologyFile = new File(tempInputDirPath + File.separator + fileName);
if (topologyFile.createNewFile()) {
String val = (String) param.get(MessageParameter.VALUE);
//Replace '{' with indentation otherwise we get 'End of document execption'
// val = val.replaceAll("- \\{", " - ").replaceAll(", ", "\n ").replaceAll("}", "");
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;
// }
writeValueToFile(val, topologyFile);
return topologyFile;
} else {
return null;
}
File topologyFile = new File(tempInputDirPath + File.separator + fileName);
topologyFile.createNewFile();
String val = (String) param.get(MessageParameter.VALUE);
writeValueToFile(val, topologyFile);
return topologyFile;
}
}
}
......@@ -484,4 +485,8 @@ public class Consumer extends DefaultConsumer {
return null;
}
private static boolean isNumeric(String str) {
return str.matches("-?\\d+(\\.\\d+)?");
}
}
<?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>
......@@ -13,5 +14,6 @@
<module>drip-commons</module>
<module>drip-simple_planner</module>
<module>drip-provisioner</module>
<module>drip-planner2provisioner</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