Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
7e2c4eef
Commit
7e2c4eef
authored
Feb 17, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fxed conf and certificate bugs
parent
8e2940de
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
121 additions
and
11 deletions
+121
-11
PlannerController.java
...main/java/nl/uva/sne/drip/api/rest/PlannerController.java
+24
-8
PlannerService.java
...main/java/nl/uva/sne/drip/api/service/PlannerService.java
+27
-0
Converter.java
...rc/main/java/nl/uva/sne/drip/commons/utils/Converter.java
+27
-0
pom.xml
drip-provisioner/pom.xml
+1
-0
Consumer.java
.../main/java/nl/uva/sne/drip/drip/provisioner/Consumer.java
+42
-3
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/rest/PlannerController.java
View file @
7e2c4eef
...
...
@@ -49,6 +49,7 @@ import org.springframework.web.bind.annotation.RestController;
import
nl.uva.sne.drip.api.dao.ToscaDao
;
import
nl.uva.sne.drip.api.rpc.DRIPCaller
;
import
nl.uva.sne.drip.api.rpc.ProvisionerCaller
;
import
nl.uva.sne.drip.api.service.PlannerService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.types.LoginKey
;
...
...
@@ -70,6 +71,8 @@ public class PlannerController {
@Autowired
private
CloudCredentialsDao
cloudCredentialsDao
;
// @Autowired
// PlannerService plannerService;
@RequestMapping
(
value
=
"/plan/{tosca_id}"
,
method
=
RequestMethod
.
POST
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
...
...
@@ -157,14 +160,13 @@ public class PlannerController {
}
private
Parameter
buildCloudConfParam
(
CloudCredentials
cred
)
throws
JsonProcessingException
,
JSONException
,
IOException
{
Parameter
conf
=
new
Parameter
();
String
charset
=
"UTF-8"
;
Properties
prop
=
Converter
.
Object2Properties
(
cred
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
prop
.
store
(
baos
,
null
);
byte
[]
bytes
=
baos
.
toByteArray
();
conf
.
setName
(
"ec2.conf"
);
conf
.
setValue
(
new
String
(
bytes
,
charset
));
Parameter
conf
=
null
;
switch
(
cred
.
getCloudProviderName
().
toLowerCase
())
{
case
"ec2"
:
conf
=
buildEC2Conf
(
cred
);
break
;
}
return
conf
;
}
...
...
@@ -212,4 +214,18 @@ public class PlannerController {
}
return
parameters
;
}
private
Parameter
buildEC2Conf
(
CloudCredentials
cred
)
throws
JsonProcessingException
,
JSONException
,
IOException
{
Properties
prop
=
Converter
.
getEC2Properties
(
cred
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
prop
.
store
(
baos
,
null
);
byte
[]
bytes
=
baos
.
toByteArray
();
Parameter
conf
=
new
Parameter
();
conf
.
setName
(
"ec2.conf"
);
String
charset
=
"UTF-8"
;
conf
.
setValue
(
new
String
(
bytes
,
charset
));
return
conf
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java
0 → 100644
View file @
7e2c4eef
/*
* 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
org.springframework.stereotype.Service
;
/**
*
* @author S. Koulouzis
*/
@Service
public
class
PlannerService
{
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java
View file @
7e2c4eef
...
...
@@ -19,11 +19,13 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
nl.uva.sne.drip.commons.types.CloudCredentials
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -35,6 +37,8 @@ import org.yaml.snakeyaml.Yaml;
*/
public
class
Converter
{
private
static
Map
<
String
,
String
>
EC2_NAME_MAP
=
new
HashMap
();
public
static
String
ymlString2Json
(
String
yamlString
)
{
JSONObject
jsonObject
=
new
JSONObject
(
ymlString2Map
(
yamlString
));
return
jsonObject
.
toString
();
...
...
@@ -110,4 +114,27 @@ public class Converter {
return
Property
.
toProperties
(
new
JSONObject
(
jsonInString
));
}
public
static
Properties
getEC2Properties
(
CloudCredentials
cred
)
throws
JsonProcessingException
,
JSONException
{
Properties
prop
=
Object2Properties
(
cred
);
Enumeration
<
String
>
names
=
(
Enumeration
<
String
>)
prop
.
propertyNames
();
Properties
ec2Props
=
new
Properties
();
if
(
EC2_NAME_MAP
.
isEmpty
())
{
initEC2_NAME_MAP
();
}
while
(
names
.
hasMoreElements
())
{
String
name
=
names
.
nextElement
();
String
ec2Name
=
EC2_NAME_MAP
.
get
(
name
);
if
(
ec2Name
!=
null
)
{
ec2Props
.
setProperty
(
ec2Name
,
prop
.
getProperty
(
name
));
}
}
return
ec2Props
;
}
private
static
void
initEC2_NAME_MAP
()
{
EC2_NAME_MAP
.
put
(
"keyIdAlias"
,
"AWSAccessKeyId"
);
EC2_NAME_MAP
.
put
(
"key"
,
"AWSSecretKey"
);
}
}
drip-provisioner/pom.xml
View file @
7e2c4eef
...
...
@@ -6,6 +6,7 @@
<artifactId>
drip
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<artifactId>
drip-provisioner
</artifactId>
<packaging>
jar
</packaging>
<properties>
...
...
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/Consumer.java
View file @
7e2c4eef
...
...
@@ -23,6 +23,7 @@ import java.io.BufferedReader;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.IOException
;
...
...
@@ -32,6 +33,7 @@ import java.nio.file.Files;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -55,8 +57,10 @@ public class Consumer extends DefaultConsumer {
private
final
Channel
channel
;
private
final
String
propertiesPath
=
"etc/consumer.properties"
;
// private String jarFilePath;
Map
<
String
,
String
>
em
=
new
HashMap
<
String
,
String
>();
// private String jarFilePath;
public
class
topologyElement
{
String
topologyName
=
""
;
...
...
@@ -77,6 +81,18 @@ public class Consumer extends DefaultConsumer {
// } else {
// jarFilePath = jarFile.getAbsolutePath();
// }
em
.
put
(
"Virginia"
,
"ec2.us-east-1.amazonaws.com"
);
em
.
put
(
"California"
,
"ec2.us-west-1.amazonaws.com"
);
em
.
put
(
"Oregon"
,
"ec2.us-west-2.amazonaws.com"
);
em
.
put
(
"Mumbai"
,
"ec2.ap-south-1.amazonaws.com"
);
em
.
put
(
"Singapore"
,
"ec2.ap-southeast-1.amazonaws.com"
);
em
.
put
(
"Seoul"
,
"ec2.ap-northeast-2.amazonaws.com"
);
em
.
put
(
"Sydney"
,
"ec2.ap-southeast-2.amazonaws.com"
);
em
.
put
(
"Tokyo"
,
"ec2.ap-northeast-1.amazonaws.com"
);
em
.
put
(
"Frankfurt"
,
"ec2.eu-central-1.amazonaws.com"
);
em
.
put
(
"Ireland"
,
"ec2.eu-west-1.amazonaws.com"
);
em
.
put
(
"Paulo"
,
"ec2.sa-east-1.amazonaws.com"
);
}
@Override
...
...
@@ -128,6 +144,7 @@ public class Consumer extends DefaultConsumer {
//loop through the parameters in a message to find the input files
String
logDir
=
"null"
,
mainTopologyPath
=
"null"
,
sshKeyFilePath
=
"null"
,
scriptPath
=
"null"
;
ArrayList
<
topologyElement
>
topologyInfoArray
=
new
ArrayList
();
List
<
String
>
certificateNames
=
new
ArrayList
();
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
Parameter
.
NAME
);
...
...
@@ -187,8 +204,9 @@ public class Consumer extends DefaultConsumer {
}
}
else
if
(
name
.
equals
(
"certificate"
))
{
JSONObject
attribute
=
param
.
getJSONObject
(
"attributes"
);
String
fileName
=
(
String
)
attribute
.
get
(
"filename"
);
////This file name does not contain suffix of '.yml' for example
File
certificate
=
new
File
(
tempInputDirPath
+
fileName
+
".pem"
);
String
fileName
=
(
String
)
attribute
.
get
(
"filename"
);
certificateNames
.
add
(
fileName
);
File
certificate
=
new
File
(
tempInputDirPath
+
File
.
separator
+
fileName
+
".pem"
);
if
(
certificate
.
createNewFile
())
{
writeValueToFile
((
String
)
param
.
get
(
Parameter
.
VALUE
),
certificate
);
}
...
...
@@ -235,9 +253,30 @@ public class Consumer extends DefaultConsumer {
String
geniConfFilePath
=
"null"
;
if
(
ec2ConfFile
!=
null
)
{
ec2ConfFilePath
=
ec2ConfFile
.
getAbsolutePath
();
Properties
prop
=
new
Properties
();
prop
.
load
(
new
FileInputStream
(
ec2ConfFile
));
StringBuilder
supportDomains
=
new
StringBuilder
();
String
prefix
=
""
;
for
(
String
certName
:
certificateNames
)
{
String
supported
=
this
.
em
.
get
(
certName
);
if
(
supported
!=
null
)
{
supportDomains
.
append
(
prefix
);
prefix
=
", "
;
supportDomains
.
append
(
supported
);
}
}
prop
.
setProperty
(
"KeyDir"
,
tempInputDirPath
);
prop
.
setProperty
(
"SupportDomains"
,
supportDomains
.
toString
());
prop
.
store
(
new
FileOutputStream
(
ec2ConfFile
),
null
);
}
if
(
geniConfFile
!=
null
)
{
geniConfFilePath
=
geniConfFile
.
getAbsolutePath
();
Properties
prop
=
new
Properties
();
prop
.
load
(
new
FileInputStream
(
geniConfFile
));
prop
.
propertyNames
();
prop
.
setProperty
(
"KeyDir"
,
tempInputDirPath
);
prop
.
store
(
new
FileOutputStream
(
geniConfFile
),
null
);
}
if
(
logDir
.
equals
(
"null"
))
{
logDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment