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
a9cb2403
Commit
a9cb2403
authored
Sep 11, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move plan creation to provisioner
parent
2bcce877
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
201 additions
and
1427 deletions
+201
-1427
nodes.yaml
TOSCA/types/nodes.yaml
+7
-1
PlannerService.java
...main/java/nl/uva/sne/drip/api/service/PlannerService.java
+10
-45
ProvisionService.java
...in/java/nl/uva/sne/drip/api/service/ProvisionService.java
+99
-123
SimplePlannerService.java
...ava/nl/uva/sne/drip/api/service/SimplePlannerService.java
+11
-11
CloudConfigurationController0.java
...a/sne/drip/api/v0/rest/CloudConfigurationController0.java
+0
-151
DeployController0.java
...n/java/nl/uva/sne/drip/api/v0/rest/DeployController0.java
+0
-101
PlannerController0.java
.../java/nl/uva/sne/drip/api/v0/rest/PlannerController0.java
+0
-91
ProvisionController0.java
...ava/nl/uva/sne/drip/api/v0/rest/ProvisionController0.java
+0
-155
UserController0.java
...ain/java/nl/uva/sne/drip/api/v0/rest/UserController0.java
+0
-79
UserPublicKeysController0.java
...l/uva/sne/drip/api/v0/rest/UserPublicKeysController0.java
+0
-85
UserScriptController0.java
...va/nl/uva/sne/drip/api/v0/rest/UserScriptController0.java
+0
-59
PlannerController.java
...n/java/nl/uva/sne/drip/api/v1/rest/PlannerController.java
+1
-3
Converter.java
...rc/main/java/nl/uva/sne/drip/commons/utils/Converter.java
+9
-9
PlanResponse.java
.../sne/drip/drip/commons/data/v1/external/PlanResponse.java
+1
-36
P2PConverter.java
...ain/java/nl/uva/sne/drip/drip/converter/P2PConverter.java
+20
-19
SimplePlanContainer.java
...a/nl/uva/sne/drip/drip/converter/SimplePlanContainer.java
+1
-1
pom.xml
drip-provisioner/pom.xml
+7
-1
RPCServer.java
...main/java/nl/uva/sne/drip/drip/provisioner/RPCServer.java
+5
-5
MessageParsing.java
...l/uva/sne/drip/drip/provisioner/utils/MessageParsing.java
+30
-12
Consumer.java
...in/java/nl/uva/sne/drip/drip/provisioner/v0/Consumer.java
+0
-440
No files found.
TOSCA/types/nodes.yaml
View file @
a9cb2403
...
...
@@ -106,6 +106,9 @@ node_types:
os
:
type
:
string
required
:
true
ssh_key
:
type
:
string
required
:
false
interfaces
:
Standard
:
create
:
dumy.yaml
...
...
@@ -135,6 +138,9 @@ node_types:
domain
:
type
:
string
required
:
true
credential
:
type
:
tosca.datatypes.Credential
required
:
false
interfaces
:
Standard
:
create
:
dumy.yaml
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java
View file @
a9cb2403
...
...
@@ -95,34 +95,19 @@ 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: "
+
toscaPlan
);
}
// String domainName = getBestDomain(cloudProvider);
Map
<
String
,
Object
>
toscaPlanMap
=
Converter
.
ymlString2Map
(
toscaPlan
);
// SimplePlanContainer simplePlan = P2PConverter.transfer(toscaPlanMap, null, null, null);
SimplePlanContainer
simplePlan
=
P2PConverter
.
transfer
(
toscaPlan
,
null
,
null
,
null
);
PlanResponse
planResponse
=
new
PlanResponse
();
planResponse
.
setToscaID
(
toscaId
);
planResponse
.
setKvMap
(
toscaPlanMap
);
PlanResponse
topLevel
=
new
PlanResponse
();
topLevel
.
setLevel
(
0
);
topLevel
.
setToscaID
(
toscaId
);
topLevel
.
setName
(
"planner_output_all.yml"
);
topLevel
.
setKvMap
(
Converter
.
ymlString2Map
(
simplePlan
.
topLevelContents
));
Map
<
String
,
String
>
map
=
simplePlan
.
lowerLevelContents
;
Set
<
String
>
loweLevelPlansIDs
=
new
HashSet
<>();
for
(
String
lowLevelNames
:
map
.
keySet
())
{
PlanResponse
lowLevelPlan
=
new
PlanResponse
();
lowLevelPlan
.
setLevel
(
1
);
lowLevelPlan
.
setToscaID
(
toscaId
);
lowLevelPlan
.
setName
(
lowLevelNames
);
lowLevelPlan
.
setKvMap
(
Converter
.
ymlString2Map
(
map
.
get
(
lowLevelNames
)));
save
(
lowLevelPlan
);
loweLevelPlansIDs
.
add
(
lowLevelPlan
.
getId
());
}
topLevel
.
setLoweLevelPlansIDs
(
loweLevelPlansIDs
);
save
(
topLevel
);
save
(
planResponse
);
logger
.
log
(
Level
.
INFO
,
"Plan saved"
);
return
topLevel
;
return
planResponse
;
}
}
...
...
@@ -167,16 +152,6 @@ public class PlannerService {
}
Map
<
String
,
Object
>
map
=
plan
.
getKeyValue
();
Set
<
String
>
ids
=
plan
.
getLoweLevelPlanIDs
();
if
(
ids
!=
null
)
{
for
(
String
lowID
:
ids
)
{
PlanResponse
ll
=
findOne
(
lowID
);
Map
<
String
,
Object
>
lowLevelMap
=
ll
.
getKeyValue
();
if
(
lowLevelMap
!=
null
)
{
map
.
put
(
ll
.
getName
(),
lowLevelMap
);
}
}
}
if
(
fromat
!=
null
&&
fromat
.
equals
(
"yml"
))
{
String
ymlStr
=
Converter
.
map2YmlString
(
map
);
...
...
@@ -200,13 +175,7 @@ public class PlannerService {
@PostFilter
(
"(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
public
List
<
PlanResponse
>
findAll
()
{
List
<
PlanResponse
>
all
=
planDao
.
findAll
();
List
<
PlanResponse
>
topLevel
=
new
ArrayList
<>();
for
(
PlanResponse
p
:
all
)
{
if
(
p
.
getLevel
()
==
0
)
{
topLevel
.
add
(
p
);
}
}
return
topLevel
;
return
all
;
}
public
PlanResponse
save
(
PlanResponse
ownedObject
)
{
...
...
@@ -251,8 +220,6 @@ public class PlannerService {
Map
<
String
,
Object
>
map
=
Converter
.
cleanStringContents
(
ymlContents
,
true
);
PlanResponse
pr
=
new
PlanResponse
();
pr
.
setKvMap
(
map
);
pr
.
setLevel
(
level
);
pr
.
setName
(
name
);
save
(
pr
);
return
pr
.
getId
();
}
...
...
@@ -283,7 +250,6 @@ public class PlannerService {
// List<CloudCredentials> creds = credentialService.findAll();
// return creds.get(0).getCloudProviderName().toUpperCase();
// }
// private String getBestDomain(String cloudProvider) {
// switch (cloudProvider.trim().toLowerCase()) {
// case "ec2":
...
...
@@ -295,5 +261,4 @@ public class PlannerService {
// }
// return null;
// }
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/ProvisionService.java
View file @
a9cb2403
...
...
@@ -63,6 +63,7 @@ import nl.uva.sne.drip.commons.utils.DRIPLogHandler;
import
nl.uva.sne.drip.drip.commons.data.v1.external.Key
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest
;
import
org.apache.commons.codec.binary.Base64
;
/**
*
...
...
@@ -133,61 +134,38 @@ public class ProvisionService {
}
public
ProvisionResponse
provisionResources
(
ProvisionRequest
provisionRequest
,
int
provisionerVersion
)
throws
IOException
,
TimeoutException
,
JSONException
,
InterruptedException
,
Exception
{
switch
(
provisionerVersion
)
{
case
0
:
return
callProvisioner0
(
provisionRequest
);
case
1
:
return
callProvisioner1
(
provisionRequest
);
}
return
null
;
}
private
Message
buildProvisioner0Message
(
ProvisionRequest
pReq
)
throws
JSONException
,
IOException
{
Message
invokationMessage
=
new
Message
();
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
CloudCredentials
cred
=
cloudCredentialsService
.
findOne
(
pReq
.
getCloudCredentialsIDs
().
get
(
0
));
if
(
cred
==
null
)
{
throw
new
CloudCredentialsNotFoundException
();
}
MessageParameter
conf
=
buildCloudCredentialParam
(
cred
,
0
).
get
(
0
);
parameters
.
add
(
conf
);
List
<
MessageParameter
>
certs
=
buildCertificatesParam
(
cred
);
parameters
.
addAll
(
certs
);
List
<
MessageParameter
>
topologies
=
buildTopologyParams
(
pReq
.
getPlanID
());
parameters
.
addAll
(
topologies
);
List
<
String
>
userKeyIDs
=
pReq
.
getUserKeyPairIDs
();
if
(
userKeyIDs
!=
null
)
{
List
<
MessageParameter
>
userKeys
=
buildUserKeysParams
(
userKeyIDs
.
get
(
0
),
0
);
parameters
.
addAll
(
userKeys
);
}
invokationMessage
.
setParameters
(
parameters
);
invokationMessage
.
setCreationDate
((
System
.
currentTimeMillis
()));
return
invokationMessage
;
}
// private Message buildProvisioner0Message(ProvisionRequest pReq) throws JSONException, IOException {
// Message invokationMessage = new Message();
// List<MessageParameter> parameters = new ArrayList();
// CloudCredentials cred = cloudCredentialsService.findOne(pReq.getCloudCredentialsIDs().get(0));
// if (cred == null) {
// throw new CloudCredentialsNotFoundException();
// }
// MessageParameter conf = buildCloudCredentialParam(cred, 0).get(0);
// parameters.add(conf);
//
// List<MessageParameter> certs = buildCertificatesParam(cred);
// parameters.addAll(certs);
//
// List<MessageParameter> topologies = buildTopologyParams(pReq.getPlanID());
// parameters.addAll(topologies);
//
// List<String> userKeyIDs = pReq.getUserKeyPairIDs();
// if (userKeyIDs != null) {
// List<MessageParameter> userKeys = buildUserKeysParams(userKeyIDs.get(0), 0);
// parameters.addAll(userKeys);
// }
//
// invokationMessage.setParameters(parameters);
// invokationMessage.setCreationDate((System.currentTimeMillis()));
// return invokationMessage;
// }
private
List
<
MessageParameter
>
buildCloudCredentialParam
(
CloudCredentials
cred
,
int
version
)
throws
JsonProcessingException
,
JSONException
,
IOException
{
List
<
MessageParameter
>
cloudCredentialParams
=
new
ArrayList
<>();
if
(
version
==
0
)
{
MessageParameter
cloudCredentialParam
=
new
MessageParameter
();
String
provider
=
cred
.
getCloudProviderName
();
if
(
provider
==
null
)
{
throw
new
BadRequestException
(
"Provider name can't be null. Check the cloud credentials: "
+
cred
.
getId
());
}
switch
(
cred
.
getCloudProviderName
().
toLowerCase
())
{
case
"ec2"
:
cloudCredentialParam
=
buildEC2Conf
(
cred
);
break
;
}
cloudCredentialParams
.
add
(
cloudCredentialParam
);
return
cloudCredentialParams
;
}
if
(
version
==
1
)
{
MessageParameter
cloudCred
=
new
MessageParameter
();
cloudCred
.
setName
(
"cloud_credential"
);
cloudCred
.
setEncoding
(
"UTF-8"
);
...
...
@@ -209,38 +187,37 @@ public class ProvisionService {
cloudCredentialParams
.
add
(
cloudCred
);
return
cloudCredentialParams
;
}
return
null
;
}
private
List
<
MessageParameter
>
buildCertificatesParam
(
CloudCredentials
cred
)
{
// List<String> loginKeysIDs = cred.getkeyPairIDs();
List
<
KeyPair
>
loginKeys
=
new
ArrayList
<>();
// for (String keyID : loginKeysIDs) {
// KeyPair key = keyDao.findOne(keyID);
// loginKeys.add(key);
// }
if
(
loginKeys
.
isEmpty
())
{
throw
new
BadRequestException
(
"Log in keys can't be empty"
);
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
<>();
for
(
KeyPair
lk
:
loginKeys
)
{
String
domainName
=
lk
.
getPrivateKey
().
getAttributes
().
get
(
"domain_name"
);
if
(
domainName
==
null
)
{
domainName
=
lk
.
getPrivateKey
().
getAttributes
().
get
(
"domain_name "
);
}
MessageParameter
cert
=
new
MessageParameter
();
cert
.
setName
(
"certificate"
);
cert
.
setValue
(
lk
.
getPrivateKey
().
getKey
());
Map
<
String
,
String
>
attributes
=
new
HashMap
<>();
attributes
.
put
(
"filename"
,
domainName
);
cert
.
setAttributes
(
attributes
);
parameters
.
add
(
cert
);
}
return
parameters
;
}
// private List<MessageParameter> buildCertificatesParam(CloudCredentials cred) {
//// List<String> loginKeysIDs = cred.getkeyPairIDs();
// List<KeyPair> loginKeys = new ArrayList<>();
//// for (String keyID : loginKeysIDs) {
//// KeyPair key = keyDao.findOne(keyID);
//// loginKeys.add(key);
//// }
// if (loginKeys.isEmpty()) {
// throw new BadRequestException("Log in keys can't be empty");
// }
// List<MessageParameter> parameters = new ArrayList<>();
// for (KeyPair lk : loginKeys) {
// String domainName = lk.getPrivateKey().getAttributes().get("domain_name");
// if (domainName == null) {
// domainName = lk.getPrivateKey().getAttributes().get("domain_name ");
// }
// MessageParameter cert = new MessageParameter();
// cert.setName("certificate");
// cert.setValue(lk.getPrivateKey().getKey());
// Map<String, String> attributes = new HashMap<>();
// attributes.put("filename", domainName);
// cert.setAttributes(attributes);
// parameters.add(cert);
// }
// return parameters;
// }
private
List
<
MessageParameter
>
buildTopologyParams
(
String
planID
)
throws
JSONException
,
FileNotFoundException
{
PlanResponse
plan
=
simplePlanService
.
getDao
().
findOne
(
planID
);
...
...
@@ -252,29 +229,30 @@ public class ProvisionService {
topology
.
setName
(
"topology"
);
String
val
=
Converter
.
map2YmlString
(
plan
.
getKeyValue
());
val
=
val
.
replaceAll
(
"\\uff0E"
,
"."
);
topology
.
setValue
(
val
);
String
encodedValue
=
new
String
(
Base64
.
encodeBase64
(
val
.
getBytes
()));
topology
.
setValue
(
encodedValue
);
Map
<
String
,
String
>
attributes
=
new
HashMap
<>();
attributes
.
put
(
"level"
,
String
.
valueOf
(
plan
.
getLevel
()));
attributes
.
put
(
"filename"
,
FilenameUtils
.
removeExtension
(
plan
.
getName
()));
//
attributes.put("level", String.valueOf(plan.getLevel()));
//
attributes.put("filename", FilenameUtils.removeExtension(plan.getName()));
topology
.
setAttributes
(
attributes
);
parameters
.
add
(
topology
);
Set
<
String
>
ids
=
plan
.
getLoweLevelPlanIDs
();
if
(
ids
!=
null
)
{
for
(
String
lowID
:
ids
)
{
PlanResponse
lowPlan
=
simplePlanService
.
getDao
().
findOne
(
lowID
);
topology
=
new
MessageParameter
();
topology
.
setName
(
"topology"
);
String
value
=
Converter
.
map2YmlString
(
lowPlan
.
getKeyValue
());
value
=
value
.
replaceAll
(
"\\uff0E"
,
"."
);
topology
.
setValue
(
value
);
attributes
=
new
HashMap
<>();
attributes
.
put
(
"level"
,
String
.
valueOf
(
lowPlan
.
getLevel
()));
attributes
.
put
(
"filename"
,
FilenameUtils
.
removeExtension
(
lowPlan
.
getName
()));
topology
.
setAttributes
(
attributes
);
parameters
.
add
(
topology
);
}
}
//
Set<String> ids = plan.getLoweLevelPlanIDs();
//
if (ids != null) {
//
for (String lowID : ids) {
//
PlanResponse lowPlan = simplePlanService.getDao().findOne(lowID);
//
topology = new MessageParameter();
//
topology.setName("topology");
//
String value = Converter.map2YmlString(lowPlan.getKeyValue());
//
value = value.replaceAll("\\uff0E", ".");
//
topology.setValue(value);
//
attributes = new HashMap<>();
////
attributes.put("level", String.valueOf(lowPlan.getLevel()));
////
attributes.put("filename", FilenameUtils.removeExtension(lowPlan.getName()));
//
topology.setAttributes(attributes);
//
parameters.add(topology);
//
}
//
}
return
parameters
;
}
...
...
@@ -408,20 +386,19 @@ public class ProvisionService {
}
private
List
<
MessageParameter
>
buildScriptParams
(
String
userScriptID
)
{
Script
script
=
userScriptService
.
findOne
(
userScriptID
);
if
(
script
==
null
)
{
throw
new
BadRequestException
(
"User script: "
+
userScriptID
+
" was not found"
);
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
MessageParameter
scriptParameter
=
new
MessageParameter
();
scriptParameter
.
setName
(
"guiscript"
);
scriptParameter
.
setValue
(
script
.
getContents
());
scriptParameter
.
setEncoding
(
"UTF-8"
);
parameters
.
add
(
scriptParameter
);
return
parameters
;
}
// private List<MessageParameter> buildScriptParams(String userScriptID) {
// Script script = userScriptService.findOne(userScriptID);
// if (script == null) {
// throw new BadRequestException("User script: " + userScriptID + " was not found");
// }
// List<MessageParameter> parameters = new ArrayList();
// MessageParameter scriptParameter = new MessageParameter();
// scriptParameter.setName("guiscript");
// scriptParameter.setValue(script.getContents());
// scriptParameter.setEncoding("UTF-8");
// parameters.add(scriptParameter);
// return parameters;
// }
private
List
<
MessageParameter
>
buildUserKeysParams
(
String
userKeyID
,
int
version
)
{
KeyPair
key
=
keyPairService
.
findOne
(
userKeyID
);
if
(
key
==
null
)
{
...
...
@@ -446,17 +423,16 @@ public class ProvisionService {
provisionDao
.
deleteAll
();
}
private
ProvisionResponse
callProvisioner0
(
ProvisionRequest
provisionRequest
)
throws
IOException
,
TimeoutException
,
JSONException
,
InterruptedException
,
Exception
{
try
(
DRIPCaller
provisioner
=
new
ProvisionerCaller0
(
messageBrokerHost
);)
{
Message
provisionerInvokationMessage
=
buildProvisioner0Message
(
provisionRequest
);
provisionerInvokationMessage
.
setOwner
(((
User
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
()).
getUsername
());
logger
.
info
(
"Calling provisioner"
);
Message
response
=
(
provisioner
.
call
(
provisionerInvokationMessage
));
logger
.
info
(
"Got provisioner response"
);
return
parseCreateResourcesResponse
(
response
.
getParameters
(),
provisionRequest
,
null
,
true
,
true
);
}
}
// private ProvisionResponse callProvisioner0(ProvisionRequest provisionRequest) throws IOException, TimeoutException, JSONException, InterruptedException, Exception {
// try (DRIPCaller provisioner = new ProvisionerCaller0(messageBrokerHost);) {
// Message provisionerInvokationMessage = buildProvisioner0Message(provisionRequest);
// provisionerInvokationMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
// logger.info("Calling provisioner");
// Message response = (provisioner.call(provisionerInvokationMessage));
// logger.info("Got provisioner response");
// return parseCreateResourcesResponse(response.getParameters(), provisionRequest, null, true, true);
// }
// }
private
ProvisionResponse
callProvisioner1
(
ProvisionRequest
provisionRequest
)
throws
IOException
,
TimeoutException
,
JSONException
,
InterruptedException
,
Exception
{
try
(
DRIPCaller
provisioner
=
new
ProvisionerCaller1
(
messageBrokerHost
);)
{
Message
provisionerInvokationMessage
=
buildProvisioner1Message
(
provisionRequest
);
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/service/SimplePlannerService.java
View file @
a9cb2403
...
...
@@ -78,14 +78,14 @@ public class SimplePlannerService {
String
originalFileName
=
p
.
getName
();
String
name
=
System
.
currentTimeMillis
()
+
"_"
+
originalFileName
;
if
(
originalFileName
.
equals
(
"planner_output_all.yml"
))
{
topLevel
.
setName
(
name
);
topLevel
.
setLevel
(
0
);
//
topLevel.setName(name);
//
topLevel.setLevel(0);
topLevel
.
setKvMap
(
Converter
.
ymlString2Map
(
p
.
getValue
()));
}
else
{
lowerLevelPlan
=
new
PlanResponse
();
lowerLevelPlan
.
setName
(
name
);
//
lowerLevelPlan.setName(name);
lowerLevelPlan
.
setKvMap
(
Converter
.
ymlString2Map
(
p
.
getValue
()));
lowerLevelPlan
.
setLevel
(
1
);
//
lowerLevelPlan.setLevel(1);
planDao
.
save
(
lowerLevelPlan
);
ids
.
add
(
lowerLevelPlan
.
getId
());
}
...
...
@@ -166,12 +166,12 @@ public class SimplePlannerService {
public
List
<
PlanResponse
>
findAll
()
{
List
<
PlanResponse
>
all
=
planDao
.
findAll
();
List
<
PlanResponse
>
topLevel
=
new
ArrayList
<>();
for
(
PlanResponse
p
:
all
)
{
if
(
p
.
getLevel
()
==
0
)
{
topLevel
.
add
(
p
);
}
}
return
topLeve
l
;
//
List<PlanResponse> topLevel = new ArrayList<>();
//
for (PlanResponse p : all) {
//
if (p.getLevel() == 0) {
//
topLevel.add(p);
//
}
//
}
return
al
l
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/CloudConfigurationController0.java
deleted
100644 → 0
View file @
2bcce877
/*
* 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
.
v0
.
rest
;
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
nl.uva.sne.drip.api.exception.KeyException
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.RequestMapping
;
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.NullKeyException
;
import
nl.uva.sne.drip.api.exception.NullKeyIDException
;
import
nl.uva.sne.drip.api.service.CloudCredentialsService
;
import
nl.uva.sne.drip.api.service.KeyPairService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Configure
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.Key
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
*
* This controller is responsible for handling cloud credentials used by the
* provisoner to request for resources (VMs).
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping
(
"/user/v0.0/switch/account/configure"
)
@Component
@Deprecated
public
class
CloudConfigurationController0
{
@Autowired
private
CloudCredentialsService
cloudCredentialsService
;
@Autowired
private
KeyPairService
keyService
;
@RequestMapping
(
value
=
"/ec2"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
String
postEC2Conf
(
@RequestBody
Configure
configure
)
throws
Exception
{
if
(
configure
.
key
==
null
)
{
throw
new
NullKeyException
();
}
if
(
configure
.
keyid
==
null
)
{
throw
new
NullKeyIDException
();
}
CloudCredentials
cloudCredentials
=
new
CloudCredentials
();
cloudCredentials
.
setAccessKeyId
(
configure
.
keyid
);
cloudCredentials
.
setSecretKey
(
configure
.
key
);
List
<
String
>
loginKeyIDs
=
new
ArrayList
<>();
for
(
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v0
.
external
.
LoginKey0
key0
:
configure
.
loginKey
)
{
try
{
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v1
.
external
.
Key
key1
=
new
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v1
.
external
.
Key
();
KeyPair
pair
=
new
KeyPair
();
key1
.
setKey
(
key0
.
content
);
Map
<
String
,
String
>
attributes
=
new
HashMap
<>();
attributes
.
put
(
"domain_name"
,
key0
.
domain_name
);
key1
.
setAttributes
(
attributes
);
pair
.
setPrivateKey
(
key1
);
pair
=
keyService
.
save
(
pair
);
loginKeyIDs
.
add
(
pair
.
getId
());
}
catch
(
KeyException
ex
)
{
Logger
.
getLogger
(
CloudConfigurationController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
// cloudCredentials.setKeyIDs(loginKeyIDs);
cloudCredentials
.
setCloudProviderName
(
"ec2"
);
cloudCredentials
=
cloudCredentialsService
.
save
(
cloudCredentials
);
return
"Success: "
+
cloudCredentials
.
getId
();
}
@RequestMapping
(
value
=
"/geni"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
String
postGeniConf
(
@RequestBody
Configure
configure
)
throws
Exception
{
if
(
configure
.
geniKey
==
null
)
{
throw
new
NullKeyException
();
}
if
(
configure
.
geniKeyAlias
==
null
)
{
throw
new
NullKeyIDException
();
}
CloudCredentials
cloudCredentials
=
new
CloudCredentials
();
// cloudCredentials.setKeyIdAlias(configure.geniKeyAlias);
cloudCredentials
.
setAccessKeyId
(
configure
.
geniKey
);
cloudCredentials
.
setSecretKey
(
configure
.
geniKeyPass
);
List
<
String
>
loginKeyIDs
=
new
ArrayList
<>();
for
(
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v0
.
external
.
LoginKey0
key0
:
configure
.
loginPubKey
)
{
try
{
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v1
.
external
.
Key
key1
=
new
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v1
.
external
.
Key
();
key1
.
setKey
(
key0
.
content
);
key1
.
setType
(
Key
.
KeyType
.
PUBLIC
);
KeyPair
pair
=
new
KeyPair
();
pair
.
setPublicKey
(
key1
);
pair
=
keyService
.
save
(
pair
);
loginKeyIDs
.
add
(
pair
.
getId
());
}
catch
(
KeyException
ex
)
{
Logger
.
getLogger
(
CloudConfigurationController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
for
(
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v0
.
external
.
LoginKey0
key0
:
configure
.
loginPriKey
)
{
try
{
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v1
.
external
.
Key
key1
=
new
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v1
.
external
.
Key
();
key1
.
setKey
(
key0
.
content
);
key1
.
setType
(
Key
.
KeyType
.
PRIVATE
);
KeyPair
pair
=
new
KeyPair
();
pair
.
setPrivateKey
(
key1
);
pair
=
keyService
.
save
(
pair
);
loginKeyIDs
.
add
(
pair
.
getId
());
}
catch
(
KeyException
ex
)
{
Logger
.
getLogger
(
CloudConfigurationController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
// cloudCredentials.setKeyIDs(loginKeyIDs);
cloudCredentials
.
setCloudProviderName
(
"geni"
);
cloudCredentialsService
.
save
(
cloudCredentials
);
return
"Success: "
+
cloudCredentials
.
getId
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/DeployController0.java
deleted
100644 → 0
View file @
2bcce877
/*
* 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
.
v0
.
rest
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javax.annotation.security.RolesAllowed
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
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.DeployService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Deploy
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Attribute
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Result
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.DeployRequest
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.Key
;
import
org.springframework.http.MediaType
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
* This controller is responsible for deploying a cluster on provisioned
* resources.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping
(
"/user/v0.0/switch/deploy"
)
@Component
@PreAuthorize
(
"isAuthenticated()"
)
@Deprecated
public
class
DeployController0
{
@Autowired
private
DeployService
deployService
;
@RequestMapping
(
value
=
"/kubernetes"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
,
produces
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
Result
deployKubernetes
(
@RequestBody
Deploy
deploy
)
{
try
{
DeployRequest
deployReq
=
new
DeployRequest
();
deployReq
.
setManagerType
(
"kubernetes"
);
deployReq
.
setProvisionID
(
deploy
.
action
);
return
deploy
(
deployReq
);
}
catch
(
Exception
ex
)
{
Logger
.
getLogger
(
DeployController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
return
null
;
}
@RequestMapping
(
value
=
"/swarm"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
,
produces
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
Result
deploySwarm
(
@RequestBody
Deploy
deploy
)
{
try
{
DeployRequest
deployReq
=
new
DeployRequest
();
deployReq
.
setManagerType
(
"swarm"
);
deployReq
.
setProvisionID
(
deploy
.
action
);
return
deploy
(
deployReq
);
}
catch
(
Exception
ex
)
{
Logger
.
getLogger
(
DeployController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
return
null
;
}
private
Result
deploy
(
DeployRequest
deployReq
)
throws
Exception
{
DeployResponse
key
=
deployService
.
deploySoftware
(
deployReq
);
Result
res
=
new
Result
();
res
.
info
=
"INFO"
;
res
.
status
=
"Success"
;
List
<
Attribute
>
files
=
new
ArrayList
<>();
Attribute
attribute
=
new
Attribute
();
attribute
.
content
=
key
.
getKeyPair
().
getPrivateKey
().
getKey
();
files
.
add
(
attribute
);
res
.
file
=
files
;
return
res
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/PlannerController0.java
deleted
100644 → 0
View file @
2bcce877
/*
* 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
.
v0
.
rest
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.TimeoutException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Result
;
import
javax.annotation.security.RolesAllowed
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
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.service.PlannerService
;
import
nl.uva.sne.drip.api.service.ToscaService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Attribute
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Plan
;
import
org.json.JSONException
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
* This controller is responsible for planning the type of resources to be
* provisioned based on a TOSCA description.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping
(
"/user/v0.0/switch/plan"
)
@Component
@Deprecated
public
class
PlannerController0
{
@Autowired
private
PlannerService
plannerService
;
@Autowired
private
ToscaService
toscaService
;
@RequestMapping
(
value
=
"/planning"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
,
produces
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
Result
plan
(
@RequestBody
Plan
plan0
)
{
try
{
String
yaml
=
plan0
.
file
;
yaml
=
yaml
.
replaceAll
(
"\\\\n"
,
"\n"
);
String
id
=
toscaService
.
saveYamlString
(
yaml
,
null
);
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v1
.
external
.
PlanResponse
plan1
=
plannerService
.
getPlan
(
id
,
null
,-
1
);
Result
r
=
new
Result
();
r
.
info
=
(
"INFO"
);
r
.
status
=
(
"Success"
);
List
<
Attribute
>
files
=
new
ArrayList
<>();
Attribute
e
=
Converter
.
plan1toFile
(
plan1
);
files
.
add
(
e
);
for
(
String
lowiID
:
plan1
.
getLoweLevelPlanIDs
())
{
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v1
.
external
.
PlanResponse
lowPlan1
=
plannerService
.
findOne
(
lowiID
);
e
=
Converter
.
plan1toFile
(
lowPlan1
);
files
.
add
(
e
);
//Don't save them cause they will be re-uploaded in the provision step
plannerService
.
delete
(
lowPlan1
.
getId
());
}
r
.
file
=
files
;
plannerService
.
delete
(
plan1
.
getId
());
return
r
;
}
catch
(
IOException
|
JSONException
|
TimeoutException
|
InterruptedException
ex
)
{
Logger
.
getLogger
(
PlannerController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
return
null
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/ProvisionController0.java
deleted
100644 → 0
View file @
2bcce877
/*
* 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
.
v0
.
rest
;
import
java.io.IOException
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionRequest
;
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
;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.commons.utils.Converter
;
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.service.CloudCredentialsService
;
import
nl.uva.sne.drip.api.service.PlannerService
;
import
nl.uva.sne.drip.api.service.ProvisionService
;
import
nl.uva.sne.drip.api.service.KeyPairService
;
import
nl.uva.sne.drip.api.service.ScriptService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Execute
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Attribute
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Result
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Upload
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse
;
import
org.json.JSONException
;
import
org.springframework.http.MediaType
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
* This controller is responsible for obtaining resources from cloud providers
* based the plan generated by the planner and uploaded by the user
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping
(
"/user/v0.0/switch/provision"
)
@Component
@PreAuthorize
(
"isAuthenticated()"
)
@Deprecated
public
class
ProvisionController0
{
@Autowired
private
ScriptService
userScriptService
;
@Autowired
private
KeyPairService
userKeysService
;
@Autowired
private
CloudCredentialsService
cloudCredentialsService
;
@Autowired
private
ProvisionService
provisionService
;
@Autowired
private
PlannerService
planService
;
@RequestMapping
(
value
=
"/upload"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
String
provision
(
@RequestBody
Upload
upload
)
{
ProvisionResponse
resp
=
new
ProvisionResponse
();
CloudCredentials
cloudCred
=
cloudCredentialsService
.
findAll
().
get
(
0
);
String
cloudCredID
=
cloudCred
.
getId
();
List
<
String
>
idList
=
new
ArrayList
<>();
idList
.
add
(
cloudCredID
);
resp
.
setCloudCredentialsIDs
(
idList
);
List
<
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v0
.
external
.
Attribute
>
plans
=
upload
.
file
;
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v1
.
external
.
PlanResponse
topLevelPlan
=
null
;
Set
<
String
>
loweLevelPlansIDs
=
new
HashSet
<>();
for
(
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v0
.
external
.
Attribute
p
:
plans
)
{
nl
.
uva
.
sne
.
drip
.
drip
.
commons
.
data
.
v1
.
external
.
PlanResponse
plan1
=
Converter
.
File2Plan1
(
p
);
if
(
plan1
.
getLevel
()
==
0
)
{
topLevelPlan
=
plan1
;
}
else
{
plan1
=
planService
.
save
(
plan1
);
loweLevelPlansIDs
.
add
(
plan1
.
getId
());
}
}
topLevelPlan
.
setLoweLevelPlansIDs
(
loweLevelPlansIDs
);
topLevelPlan
=
planService
.
save
(
topLevelPlan
);
String
planID
=
topLevelPlan
.
getId
();
resp
.
setPlanID
(
planID
);
List
<
KeyPair
>
allKeys
=
userKeysService
.
findAll
();
List
<
String
>
keyPairIDs
=
new
ArrayList
<>();
if
(
allKeys
!=
null
&&
!
allKeys
.
isEmpty
())
{
for
(
KeyPair
keyPair
:
allKeys
)
{
String
userKeyID
=
keyPair
.
getId
();
keyPairIDs
.
add
(
userKeyID
);
}
resp
.
setUserKeyPairIDs
(
keyPairIDs
);
}
resp
=
provisionService
.
save
(
resp
);
return
"Success: Infrastructure files are uploaded! Action number: "
+
resp
.
getId
();
}
@RequestMapping
(
value
=
"/execute"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
,
produces
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
Result
execute
(
@RequestBody
Execute
exc
)
{
try
{
ProvisionRequest
req
=
provisionService
.
findOne
(
exc
.
action
);
req
=
provisionService
.
provisionResources
(
req
,
0
);
Map
<
String
,
Object
>
map
=
req
.
getKeyValue
();
String
yaml
=
Converter
.
map2YmlString
(
map
);
yaml
=
yaml
.
replaceAll
(
"\n"
,
"\\\\n"
);
Result
res
=
new
Result
();
List
<
Attribute
>
files
=
new
ArrayList
<>();
Attribute
e
=
new
Attribute
();
e
.
content
=
yaml
;
e
.
level
=
"0"
;
e
.
name
=
"provisioned_"
+
exc
.
action
;
files
.
add
(
e
);
res
.
info
=
"INFO"
;
res
.
status
=
"Success"
;
res
.
file
=
files
;
return
res
;
}
catch
(
IOException
|
TimeoutException
|
JSONException
|
InterruptedException
ex
)
{
Logger
.
getLogger
(
ProvisionController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
Exception
ex
)
{
Logger
.
getLogger
(
ProvisionController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
return
null
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/UserController0.java
deleted
100644 → 0
View file @
2bcce877
/*
* 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
.
v0
.
rest
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.api.exception.PasswordNullException
;
import
nl.uva.sne.drip.api.exception.UserExistsException
;
import
nl.uva.sne.drip.api.exception.UserNullException
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.User
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.Register
;
import
org.springframework.http.MediaType
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
* This controller is responsible for handling user accounts
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping
(
"/manager/v0.0/switch/account"
)
@Component
@Deprecated
public
class
UserController0
{
@Autowired
private
UserService
service
;
@RequestMapping
(
value
=
"/register"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
ADMIN
})
public
@ResponseBody
String
register
(
@RequestBody
Register
register
)
{
if
(
register
.
user
==
null
)
{
throw
new
UserNullException
();
}
if
(
register
.
pwd
==
null
)
{
throw
new
PasswordNullException
();
}
UserDetails
registeredUser
=
service
.
loadUserByUsername
(
register
.
user
);
if
(
registeredUser
!=
null
)
{
throw
new
UserExistsException
(
"Username "
+
register
.
user
+
" is used"
);
}
User
user
=
new
User
();
user
.
setUsername
(
register
.
user
);
user
.
setAccountNonExpired
(
true
);
user
.
setAccountNonLocked
(
true
);
user
.
setEnabled
(
true
);
user
.
setCredentialsNonExpired
(
true
);
Collection
<
String
>
roles
=
new
ArrayList
<>();
roles
.
add
(
"USER"
);
user
.
setRoles
(
roles
);
user
.
setPassword
(
new
BCryptPasswordEncoder
().
encode
(
register
.
pwd
));
user
=
service
.
save
(
user
);
return
"Success: "
+
user
.
getId
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/UserPublicKeysController0.java
deleted
100644 → 0
View file @
2bcce877
/*
* 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
.
v0
.
rest
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.api.exception.KeyException
;
import
nl.uva.sne.drip.api.service.ProvisionService
;
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.service.KeyPairService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.ConfUserKey
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.Key
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionRequest
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
* 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/v0.0/switch/provision"
)
@Component
@Deprecated
public
class
UserPublicKeysController0
{
@Autowired
private
KeyPairService
service
;
@Autowired
private
ProvisionService
provisionService
;
@RequestMapping
(
value
=
"/confuserkey"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
String
uploadUserPublicKeys
(
@RequestBody
ConfUserKey
confUserKey
)
throws
Exception
{
try
{
KeyPair
pair
=
new
KeyPair
();
Key
upk
=
new
Key
();
upk
.
setKey
(
confUserKey
.
file
.
get
(
0
).
content
);
upk
.
setName
(
confUserKey
.
file
.
get
(
0
).
name
);
upk
.
setType
(
Key
.
KeyType
.
PUBLIC
);
pair
.
setPublicKey
(
upk
);
pair
=
service
.
save
(
pair
);
ProvisionResponse
provPlan
=
provisionService
.
findOne
(
confUserKey
.
action
);
List
<
String
>
keyPairIDs
=
new
ArrayList
<>();
keyPairIDs
.
add
(
pair
.
getId
());
provPlan
.
setUserKeyPairIDs
(
keyPairIDs
);
provisionService
.
save
(
provPlan
);
return
"Success: "
+
pair
.
getId
();
}
catch
(
KeyException
ex
)
{
Logger
.
getLogger
(
UserPublicKeysController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
return
null
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/UserScriptController0.java
deleted
100644 → 0
View file @
2bcce877
/*
* 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
.
v0
.
rest
;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.api.service.ProvisionService
;
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.RestController
;
import
nl.uva.sne.drip.api.service.ScriptService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.drip.commons.data.v0.external.ConfScript
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.Script
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
/**
* This controller is responsible for handling user scripts. These user can be
* used by the provisioner to run on the created VMs.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping
(
"/user/v0.0/switch/provision"
)
@Component
@Deprecated
public
class
UserScriptController0
{
@Autowired
private
ScriptService
scriptService
;
@RequestMapping
(
value
=
"/confscript"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
String
uploadUserScript
(
@RequestBody
ConfScript
confScript
)
{
Script
script
=
new
Script
();
script
.
setContents
(
confScript
.
script
);
script
=
scriptService
.
save
(
script
);
return
"Success: script for GUI is uploaded: "
+
script
.
getId
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/PlannerController.java
View file @
a9cb2403
...
...
@@ -185,10 +185,8 @@ public class PlannerController {
List
<
PlanResponse
>
all
=
plannerService
.
findAll
();
List
<
String
>
ids
=
new
ArrayList
<>();
for
(
PlanResponse
tr
:
all
)
{
if
(
tr
.
getLevel
()
==
0
)
{
ids
.
add
(
tr
.
getId
());
}
}
return
ids
;
}
...
...
drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java
View file @
a9cb2403
...
...
@@ -211,14 +211,14 @@ public class Converter {
public
static
Attribute
plan1toFile
(
PlanResponse
plan1
)
throws
JSONException
{
Attribute
e
=
new
Attribute
();
e
.
level
=
String
.
valueOf
(
plan1
.
getLevel
());
String
p1Name
=
FilenameUtils
.
getBaseName
(
plan1
.
getName
());
if
(
p1Name
==
null
)
{
p1Name
=
"Planned_tosca_file_"
+
plan1
.
getLevel
();
plan1
.
setName
(
p1Name
);
}
//
e.level = String.valueOf(plan1.getLevel());
//
String p1Name = FilenameUtils.getBaseName(plan1.getName());
//
if (p1Name == null) {
//
p1Name = "Planned_tosca_file_" + plan1.getLevel();
//
plan1.setName(p1Name);
//
}
e
.
name
=
p1Name
;
//
e.name = p1Name;
String
ymlString
=
Converter
.
map2YmlString
(
plan1
.
getKeyValue
());
e
.
content
=
ymlString
.
replaceAll
(
"\n"
,
"\\\\n"
);
return
e
;
...
...
@@ -226,8 +226,8 @@ public class Converter {
public
static
PlanResponse
File2Plan1
(
Attribute
p0
)
{
PlanResponse
p1
=
new
PlanResponse
();
p1
.
setLevel
(
Integer
.
valueOf
(
p0
.
level
));
p1
.
setName
(
p0
.
name
);
//
p1.setLevel(Integer.valueOf(p0.level));
//
p1.setName(p0.name);
String
yaml
=
p0
.
content
.
replaceAll
(
"\\\\n"
,
"\n"
);
p1
.
setKvMap
(
ymlString2Map
(
yaml
));
...
...
drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/data/v1/external/PlanResponse.java
View file @
a9cb2403
...
...
@@ -38,23 +38,6 @@ public class PlanResponse extends KeyValueHolder {
private
Set
<
String
>
loweLevelPlansIDs
;
/**
* The name of the generated plan
*
* @return the name
*/
@DocumentationExample
(
"planner_output_all.yml"
)
public
String
getName
()
{
return
name
;
}
/**
* @param name the name to set
*/
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
/**
* The id of the TOSCA <code>PlaybookRepresentation</code> description from
* which this plan was generated
...
...
@@ -73,24 +56,6 @@ public class PlanResponse extends KeyValueHolder {
this
.
toscaID
=
toscaID
;
}
/**
* The level of the plan. Some provisioners use levels to represent a plan.
* In these cases there are two levels of TOSCA descriptions.
*
* @return the level
*/
@DocumentationExample
(
"0"
)
public
Integer
getLevel
()
{
return
level
;
}
/**
* @param level the level to set
*/
public
void
setLevel
(
Integer
level
)
{
this
.
level
=
level
;
}
/**
* The list of the lower level plans attached to this plan. Some
* provisioners use levels to represent a plan. In these cases there are two
...
...
drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/P2PConverter.java
View file @
a9cb2403
...
...
@@ -56,6 +56,7 @@ public class P2PConverter {
List
<
Object
>
vmList
=
new
ArrayList
<>();
for
(
String
vmName
:
vmNames
)
{
Map
<
String
,
Object
>
vm
=
(
Map
<
String
,
Object
>)
topologyTemplate
.
get
(
vmName
);
userName
=
(
String
)
((
Map
<
String
,
Object
>)
vm
.
get
(
"properties"
)).
get
(
"user_name"
);
vm
.
put
(
"name"
,
vmName
);
vmList
.
add
(
vm
);
}
...
...
@@ -66,15 +67,15 @@ public class P2PConverter {
topTopology
.
topologies
=
new
ArrayList
<>();
boolean
firstVM
=
true
;
SubTopologyInfo
s
ti
=
new
SubTopologyInfo
();
SubTopologyInfo
s
ubTopologyInfo
=
new
SubTopologyInfo
();
String
provisionerScalingMode
=
"fixed"
;
SubTopology
subTopology
=
createSubTopology
(
cloudProvider
);
s
ti
.
cloudProvider
=
cloudProvider
;
s
ti
.
topology
=
UUID
.
randomUUID
().
toString
();
s
ti
.
domain
=
domainName
;
s
ti
.
status
=
"fresh"
;
s
ti
.
statusInfo
=
null
;
s
ti
.
tag
=
provisionerScalingMode
;
s
ubTopologyInfo
.
cloudProvider
=
cloudProvider
;
s
ubTopologyInfo
.
topology
=
UUID
.
randomUUID
().
toString
();
s
ubTopologyInfo
.
domain
=
domainName
;
s
ubTopologyInfo
.
status
=
"fresh"
;
s
ubTopologyInfo
.
statusInfo
=
null
;
s
ubTopologyInfo
.
tag
=
provisionerScalingMode
;
Map
<
String
,
SubTopologyInfo
>
subTopologyInfos
=
new
HashMap
<>();
for
(
Object
element
:
vmList
)
{
...
...
@@ -82,20 +83,20 @@ public class P2PConverter {
firstVM
=
false
;
if
(
isScalable
(
element
))
{
s
ti
=
new
SubTopologyInfo
();
s
ubTopologyInfo
=
new
SubTopologyInfo
();
subTopology
=
createSubTopology
(
cloudProvider
);
provisionerScalingMode
=
"scaling"
;
s
ti
.
cloudProvider
=
cloudProvider
;
s
ti
.
topology
=
UUID
.
randomUUID
().
toString
();
s
ti
.
domain
=
domainName
;
s
ti
.
status
=
"fresh"
;
s
ti
.
tag
=
provisionerScalingMode
;
s
ti
.
statusInfo
=
null
;
s
ubTopologyInfo
.
cloudProvider
=
cloudProvider
;
s
ubTopologyInfo
.
topology
=
UUID
.
randomUUID
().
toString
();
s
ubTopologyInfo
.
domain
=
domainName
;
s
ubTopologyInfo
.
status
=
"fresh"
;
s
ubTopologyInfo
.
tag
=
provisionerScalingMode
;
s
ubTopologyInfo
.
statusInfo
=
null
;
}
else
{
for
(
SubTopologyInfo
info
:
subTopologyInfos
.
values
())
{
if
(!
info
.
tag
.
equals
(
"scaling"
))
{
s
ti
=
info
;
subTopology
=
s
ti
.
subTopology
;
s
ubTopologyInfo
=
info
;
subTopology
=
s
ubTopologyInfo
.
subTopology
;
break
;
}
}
...
...
@@ -109,8 +110,8 @@ public class P2PConverter {
subTopology
.
subnets
=
new
ArrayList
<>();
subTopology
.
subnets
.
add
(
s
);
}
s
ti
.
subTopology
=
subTopology
;
subTopologyInfos
.
put
(
s
ti
.
topology
,
sti
);
s
ubTopologyInfo
.
subTopology
=
subTopology
;
subTopologyInfos
.
put
(
s
ubTopologyInfo
.
topology
,
subTopologyInfo
);
}
for
(
SubTopologyInfo
info
:
subTopologyInfos
.
values
())
{
topTopology
.
topologies
.
add
(
info
);
...
...
@@ -128,7 +129,7 @@ public class P2PConverter {
String
yamlString
=
mapper
.
writeValueAsString
(
topTopology
);
spc
.
topLevelContents
=
yamlString
.
substring
(
4
);
Map
<
String
,
String
>
output
=
new
HashMap
<>();
Map
<
String
,
Object
>
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
);
...
...
drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/SimplePlanContainer.java
View file @
a9cb2403
...
...
@@ -5,6 +5,6 @@ import java.util.Map;
public
class
SimplePlanContainer
{
public
String
topLevelContents
;
public
Map
<
String
,
String
>
lowerLevelContents
;
public
Map
<
String
,
Object
>
lowerLevelContents
;
}
drip-provisioner/pom.xml
View file @
a9cb2403
...
...
@@ -103,6 +103,12 @@
<artifactId>
logback-access
</artifactId>
<version>
${ch.qos.logback.version}
</version>
</dependency>
<dependency>
<groupId>
nl.uva.sne.drip
</groupId>
<artifactId>
drip-planner2provisioner
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<type>
jar
</type>
</dependency>
</dependencies>
...
...
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/RPCServer.java
View file @
a9cb2403
...
...
@@ -70,11 +70,11 @@ public class RPCServer {
//We define the queue name
channel
.
queueDeclare
(
PropertyValues
.
RPC_QUEUE_NAME
,
false
,
false
,
false
,
null
);
DefaultConsumer
c
;
if
(
PropertyValues
.
RPC_QUEUE_NAME
.
endsWith
(
"v0"
))
{
c
=
new
nl
.
uva
.
sne
.
drip
.
drip
.
provisioner
.
v0
.
Consumer
(
channel
);
}
else
{
//
if (PropertyValues.RPC_QUEUE_NAME.endsWith("v0")) {
//
c = new nl.uva.sne.drip.drip.provisioner.v0.Consumer(channel);
//
} else {
c
=
new
nl
.
uva
.
sne
.
drip
.
drip
.
provisioner
.
v1
.
Consumer
(
channel
,
PropertyValues
.
HOST
);
}
//
}
//Start listening for messages
channel
.
basicConsume
(
PropertyValues
.
RPC_QUEUE_NAME
,
false
,
c
);
...
...
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/utils/MessageParsing.java
View file @
a9cb2403
...
...
@@ -27,13 +27,18 @@ import java.security.cert.CertificateEncodingException;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Base64
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
nl.uva.sne.drip.commons.utils.AAUtils
;
import
nl.uva.sne.drip.commons.utils.AAUtils.SOURCE
;
import
static
nl
.
uva
.
sne
.
drip
.
commons
.
utils
.
AAUtils
.
downloadCACertificates
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.drip.commons.data.internal.MessageParameter
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials
;
import
nl.uva.sne.drip.drip.converter.P2PConverter
;
import
nl.uva.sne.drip.drip.converter.SimplePlanContainer
;
import
org.apache.commons.io.FileUtils
;
//import org.globus.myproxy.MyProxyException;
import
org.ietf.jgss.GSSException
;
...
...
@@ -51,6 +56,7 @@ import provisioning.credential.ExoGENICredential;
* @author S. Koulouzis
*/
public
class
MessageParsing
{
private
static
SimplePlanContainer
simplePlan
;
public
static
List
<
File
>
getTopologies
(
JSONArray
parameters
,
String
tempInputDirPath
,
int
level
)
throws
JSONException
,
IOException
{
List
<
File
>
topologyFiles
=
new
ArrayList
<>();
...
...
@@ -58,23 +64,35 @@ public class MessageParsing {
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"topology"
))
{
JSONObject
attributes
=
param
.
getJSONObject
(
"attributes"
);
int
fileLevel
=
Integer
.
valueOf
((
String
)
attributes
.
get
(
"level"
));
if
(
fileLevel
==
level
)
{
String
originalFilename
=
(
String
)
attributes
.
get
(
"filename"
);
String
fileName
=
originalFilename
;
String
toscaPlan
=
new
String
(
Base64
.
getDecoder
().
decode
((
String
)
param
.
get
(
"value"
)));
Map
<
String
,
Object
>
toscaPlanMap
=
Converter
.
ymlString2Map
(
toscaPlan
);
if
(
level
==
0
)
{
simplePlan
=
P2PConverter
.
transfer
(
toscaPlanMap
,
null
,
null
,
null
);
String
fileName
=
"planner_output_all.yml"
;
File
topologyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
fileName
);
topologyFile
.
createNewFile
();
writeValueToFile
(
simplePlan
.
topLevelContents
,
topologyFile
);
topologyFiles
.
add
(
topologyFile
);
//We should have only one top level topoloy
// if (level == 0) {
return
topologyFiles
;
// }
}
else
{
Set
<
String
>
keys
=
simplePlan
.
lowerLevelContents
.
keySet
();
for
(
String
key
:
keys
)
{
String
fileName
=
key
;
if
(!
fileName
.
endsWith
(
".yml"
))
{
fileName
+=
".yml"
;
}
File
topologyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
fileName
);
topologyFile
.
createNewFile
();
String
val
=
(
String
)
param
.
get
(
"value"
);
writeValueToFile
(
val
,
topologyFile
);
String
topologyContents
=
(
String
)
simplePlan
.
lowerLevelContents
.
get
(
key
);
writeValueToFile
(
topologyContents
,
topologyFile
);
topologyFiles
.
add
(
topologyFile
);
//We should have only one top level topoloy
if
(
level
==
0
)
{
return
topologyFiles
;
}
}
}
}
...
...
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/v0/Consumer.java
deleted
100644 → 0
View file @
2bcce877
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
drip
.
provisioner
.
v0
;
import
com.rabbitmq.client.AMQP
;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.DefaultConsumer
;
import
com.rabbitmq.client.Envelope
;
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
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.nio.file.attribute.PosixFilePermission
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.drip.provisioner.utils.MessageParsing
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/**
*
* This is an example of a Message consumer
*
*
* @author H. Zhou, S. Koulouzis
*/
@Deprecated
public
class
Consumer
extends
DefaultConsumer
{
private
final
Channel
channel
;
// private final String propertiesPath = "etc/consumer.properties";
Map
<
String
,
String
>
em
=
new
HashMap
<>();
// private String jarFilePath;
@Deprecated
public
class
TopologyElement
{
String
topologyName
=
""
;
String
outputFilePath
=
""
;
}
@Deprecated
public
Consumer
(
Channel
channel
)
throws
IOException
{
super
(
channel
);
this
.
channel
=
channel
;
// Properties prop = new Properties();
// try (InputStream in = new FileInputStream(propertiesPath)) {
// prop.load(in);
// }
// jarFilePath = prop.getProperty("jar.file.path", "/root/SWITCH/bin/ProvisioningCore.jar");
// File jarFile = new File(jarFilePath);
// if (!jarFile.exists()) {
// throw new IOException(jarFile.getAbsolutePath() + " not found!");
// } 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
public
void
handleDelivery
(
String
consumerTag
,
Envelope
envelope
,
AMQP
.
BasicProperties
properties
,
byte
[]
body
)
throws
IOException
{
//Create the reply properties which tells us where to reply, and which id to use.
//No need to change anything here
AMQP
.
BasicProperties
replyProps
=
new
AMQP
.
BasicProperties
.
Builder
()
.
correlationId
(
properties
.
getCorrelationId
())
.
build
();
String
response
=
""
;
try
{
//The queue only moves bytes so we need to convert them to stting
String
message
=
new
String
(
body
,
"UTF-8"
);
String
tempInputDirPath
=
System
.
getProperty
(
"java.io.tmpdir"
)
+
File
.
separator
+
"Input-"
+
Long
.
toString
(
System
.
nanoTime
())
+
File
.
separator
;
File
tempInputDir
=
new
File
(
tempInputDirPath
);
if
(!(
tempInputDir
.
mkdirs
()))
{
throw
new
FileNotFoundException
(
"Could not create input directory: "
+
tempInputDir
.
getAbsolutePath
());
}
ArrayList
topologyInfoArray
;
topologyInfoArray
=
invokeProvisioner
(
message
,
tempInputDirPath
);
response
=
generateResponse
(
topologyInfoArray
);
}
catch
(
Throwable
ex
)
{
try
{
response
=
generateExeptionResponse
(
ex
);
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
JSONException
ex1
)
{
response
=
"{\"creationDate\": "
+
System
.
currentTimeMillis
()
+
",\"parameters\": [{\"url\": null,\"encoding\": UTF-8,"
+
"\"value\": \""
+
ex
.
getMessage
()
+
"\",\"name\": \""
+
ex
.
getClass
().
getName
()
+
"\",\"attributes\": null}]}"
;
}
}
finally
{
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
INFO
,
"Sending Response: {0}"
,
response
);
//We send the response back. No need to change anything here
channel
.
basicPublish
(
""
,
properties
.
getReplyTo
(),
replyProps
,
response
.
getBytes
(
"UTF-8"
));
channel
.
basicAck
(
envelope
.
getDeliveryTag
(),
false
);
}
}
////If the provisioner jar file is successfully invoked, the returned value should be a set of output file paths which are expected.
////If there are some errors or some information missing with this message, the returned value will be null.
////The input dir path contains '/'
private
ArrayList
<
TopologyElement
>
invokeProvisioner
(
String
message
,
String
tempInputDirPath
)
throws
IOException
,
JSONException
{
//Use the Jackson API to convert json to Object
JSONObject
jo
=
new
JSONObject
(
message
);
JSONArray
parameters
=
jo
.
getJSONArray
(
"parameters"
);
//Create tmp input files
File
ec2ConfFile
=
null
;
File
geniConfFile
=
null
;
//loop through the parameters in a message to find the input files
String
logDir
,
mainTopologyPath
,
sshKeyFilePath
=
null
,
scriptPath
=
null
;
ArrayList
<
TopologyElement
>
topologyInfoArray
=
new
ArrayList
();
List
<
String
>
certificateNames
=
new
ArrayList
();
File
cloudConfFile
=
getCloudConfigurationFile
(
parameters
,
tempInputDirPath
);
if
(
cloudConfFile
.
getName
().
toLowerCase
().
contains
(
"ec2"
))
{
ec2ConfFile
=
cloudConfFile
;
}
else
if
(
cloudConfFile
.
getName
().
toLowerCase
().
contains
(
"geni"
))
{
geniConfFile
=
cloudConfFile
;
}
File
topologyFile
=
MessageParsing
.
getTopologies
(
parameters
,
tempInputDirPath
,
0
).
get
(
0
);
File
mainTopologyFile
=
new
File
(
tempInputDirPath
+
"topology_main"
);
FileUtils
.
moveFile
(
topologyFile
,
mainTopologyFile
);
mainTopologyPath
=
mainTopologyFile
.
getAbsolutePath
();
topologyFile
=
MessageParsing
.
getTopologies
(
parameters
,
tempInputDirPath
,
1
).
get
(
0
);
File
secondaryTopologyFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
topologyFile
.
getName
()
+
".yml"
);
String
outputFilePath
=
tempInputDirPath
+
File
.
separator
+
topologyFile
.
getName
()
+
"_provisioned.yml"
;
TopologyElement
x
=
new
TopologyElement
();
x
.
topologyName
=
topologyFile
.
getName
();
x
.
outputFilePath
=
outputFilePath
;
topologyInfoArray
.
add
(
x
);
FileUtils
.
moveFile
(
topologyFile
,
secondaryTopologyFile
);
Map
<
String
,
File
>
certificatesMap
=
getCertificates
(
parameters
,
tempInputDirPath
);
certificateNames
.
addAll
(
certificatesMap
.
keySet
());
logDir
=
getLogDirPath
(
parameters
,
tempInputDirPath
);
File
sshKey
=
MessageParsing
.
getSSHKeys
(
parameters
,
tempInputDirPath
,
"user.pem"
,
"sshkey"
).
get
(
0
);
if
(
sshKey
!=
null
)
{
sshKeyFilePath
=
sshKey
.
getAbsolutePath
();
}
File
scriptFile
=
getSciptFile
(
parameters
,
tempInputDirPath
);
if
(
scriptFile
!=
null
)
{
scriptPath
=
scriptFile
.
getAbsolutePath
();
}
File
curDir
=
new
File
(
tempInputDirPath
);
for
(
File
f
:
curDir
.
listFiles
())
{
String
fileType
=
FilenameUtils
.
getExtension
(
f
.
getName
());
if
(
fileType
!=
null
)
{
if
(
fileType
.
equals
(
"yml"
))
{
String
toscaFile
=
f
.
getAbsolutePath
();
if
(
sshKeyFilePath
!=
null
)
{
changeKeyFilePath
(
toscaFile
,
sshKeyFilePath
);
}
if
(
scriptPath
!=
null
)
{
changeGUIScriptFilePath
(
toscaFile
,
scriptPath
);
}
}
}
}
if
(
ec2ConfFile
==
null
&&
geniConfFile
==
null
)
{
return
null
;
}
if
(
mainTopologyPath
==
null
)
{
return
null
;
}
String
ec2ConfFilePath
=
null
;
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
);
}
String
cmd
=
"ec2="
+
ec2ConfFilePath
+
" exogeni="
+
geniConfFilePath
+
" logDir="
+
logDir
+
" topology="
+
mainTopologyPath
;
// Provisioning.ProvisioningCore.main(cmd.split(" "));
// String cmd = "java -jar " + jarFilePath + " ec2=" + ec2ConfFilePath + " exogeni=" + geniConfFilePath + " logDir=" + logDir + " topology=" + mainTopologyPath;
// try {
// Logger.getLogger(Consumer.class.getName()).log(Level.INFO, "Executing: " + cmd);
// Process p = Runtime.getRuntime().exec(cmd);
// p.waitFor();
// } catch (IOException | InterruptedException e) {
// // TODO Auto-generated catch block
// Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, e);
// }
x
=
new
TopologyElement
();
x
.
topologyName
=
"topology"
;
x
.
outputFilePath
=
tempInputDirPath
+
"file_topology"
;
topologyInfoArray
.
add
(
x
);
return
topologyInfoArray
;
}
////Change the key file path in the tosca file.
////Because the user needs to upload their public key file into the server file system.
private
void
changeKeyFilePath
(
String
toscaFilePath
,
String
newKeyFilePath
)
{
File
toscaFile
=
new
File
(
toscaFilePath
);
String
fileContent
=
""
;
try
(
BufferedReader
in
=
new
BufferedReader
(
new
FileReader
(
toscaFile
)))
{
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
if
(
line
.
contains
(
"publicKeyPath"
))
{
fileContent
+=
(
"publicKeyPath: "
+
newKeyFilePath
+
"\n"
);
}
else
{
fileContent
+=
(
line
+
"\n"
);
}
}
try
(
FileWriter
fw
=
new
FileWriter
(
toscaFilePath
,
false
))
{
fw
.
write
(
fileContent
);
}
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
}
}
private
void
changeGUIScriptFilePath
(
String
toscaFilePath
,
String
newScriptPath
)
{
File
toscaFile
=
new
File
(
toscaFilePath
);
String
fileContent
=
""
;
try
(
BufferedReader
in
=
new
BufferedReader
(
new
FileReader
(
toscaFile
)))
{
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
if
(
line
.
contains
(
"script"
))
{
int
index
=
line
.
indexOf
(
"script:"
);
String
prefix
=
line
.
substring
(
0
,
index
+
7
);
fileContent
+=
(
prefix
+
" "
+
newScriptPath
+
"\n"
);
}
else
{
fileContent
+=
(
line
+
"\n"
);
}
}
try
(
FileWriter
fw
=
new
FileWriter
(
toscaFilePath
,
false
))
{
fw
.
write
(
fileContent
);
}
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
}
}
private
String
generateResponse
(
ArrayList
<
TopologyElement
>
outputs
)
throws
JSONException
,
IOException
{
//Use the JSONObject API to convert Object (Message) to json
JSONObject
jo
=
new
JSONObject
();
jo
.
put
(
"creationDate"
,
(
System
.
currentTimeMillis
()));
List
parameters
=
new
ArrayList
();
String
charset
=
"UTF-8"
;
if
(
outputs
==
null
)
{
Map
<
String
,
String
>
fileArguments
=
new
HashMap
<>();
fileArguments
.
put
(
"encoding"
,
charset
);
fileArguments
.
put
(
"name"
,
"ERROR"
);
fileArguments
.
put
(
"value"
,
"Some error with input messages!"
);
parameters
.
add
(
fileArguments
);
}
else
{
for
(
int
i
=
0
;
i
<
outputs
.
size
();
i
++)
{
Map
<
String
,
String
>
fileArguments
=
new
HashMap
<>();
fileArguments
.
put
(
"encoding"
,
charset
);
File
f
=
new
File
(
outputs
.
get
(
i
).
outputFilePath
);
if
(
f
.
exists
())
{
fileArguments
.
put
(
"name"
,
outputs
.
get
(
i
).
topologyName
);
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
f
.
getAbsolutePath
()));
fileArguments
.
put
(
"value"
,
new
String
(
bytes
,
charset
));
parameters
.
add
(
fileArguments
);
}
else
{
fileArguments
.
put
(
"name"
,
outputs
.
get
(
i
).
topologyName
);
fileArguments
.
put
(
"value"
,
"ERROR::There is no output for topology "
+
outputs
.
get
(
i
).
topologyName
);
parameters
.
add
(
fileArguments
);
}
}
}
jo
.
put
(
"parameters"
,
parameters
);
return
jo
.
toString
();
}
private
String
generateExeptionResponse
(
Throwable
ex
)
throws
JSONException
{
JSONObject
jo
=
new
JSONObject
();
jo
.
put
(
"creationDate"
,
(
System
.
currentTimeMillis
()));
List
parameters
=
new
ArrayList
();
String
charset
=
"UTF-8"
;
Map
<
String
,
String
>
errorArgument
=
new
HashMap
<>();
errorArgument
.
put
(
"encoding"
,
charset
);
errorArgument
.
put
(
"name"
,
ex
.
getClass
().
getName
());
errorArgument
.
put
(
"value"
,
ex
.
getMessage
());
parameters
.
add
(
errorArgument
);
jo
.
put
(
"parameters"
,
parameters
);
return
jo
.
toString
();
}
private
File
getCloudConfigurationFile
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"ec2.conf"
)
||
name
.
equals
(
"geni.conf"
))
{
try
{
File
confFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
name
);
if
(
confFile
.
createNewFile
())
{
MessageParsing
.
writeValueToFile
((
String
)
param
.
get
(
"value"
),
confFile
);
return
confFile
;
}
else
{
return
null
;
}
}
catch
(
IOException
e
)
{
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
return
null
;
}
}
}
return
null
;
}
private
Map
<
String
,
File
>
getCertificates
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
,
IOException
{
Map
<
String
,
File
>
files
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"certificate"
))
{
JSONObject
attribute
=
param
.
getJSONObject
(
"attributes"
);
String
fileName
=
(
String
)
attribute
.
get
(
"filename"
);
File
certificate
=
new
File
(
tempInputDirPath
+
File
.
separator
+
fileName
+
".pem"
);
if
(
certificate
.
createNewFile
())
{
MessageParsing
.
writeValueToFile
((
String
)
param
.
get
(
"value"
),
certificate
);
Set
<
PosixFilePermission
>
perms
=
new
HashSet
<>();
perms
.
add
(
PosixFilePermission
.
OWNER_READ
);
Files
.
setPosixFilePermissions
(
Paths
.
get
(
certificate
.
getAbsolutePath
()),
perms
);
files
.
put
(
fileName
,
certificate
);
}
}
}
return
files
;
}
private
String
getLogDirPath
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"logdir"
))
{
return
(
String
)
param
.
get
(
"value"
);
}
}
return
System
.
getProperty
(
"java.io.tmpdir"
);
}
private
File
getSciptFile
(
JSONArray
parameters
,
String
tempInputDirPath
)
throws
JSONException
,
IOException
{
for
(
int
i
=
0
;
i
<
parameters
.
length
();
i
++)
{
JSONObject
param
=
(
JSONObject
)
parameters
.
get
(
i
);
String
name
=
(
String
)
param
.
get
(
"name"
);
if
(
name
.
equals
(
"guiscript"
))
{
String
scriptContent
=
(
String
)
param
.
get
(
"value"
);
File
scriptFile
=
new
File
(
tempInputDirPath
+
File
.
separator
+
"guiscipt.sh"
);
if
(
scriptFile
.
createNewFile
())
{
MessageParsing
.
writeValueToFile
(
scriptContent
,
scriptFile
);
return
scriptFile
;
}
}
}
return
null
;
}
}
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