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
Expand all
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
This diff is collapsed.
Click to expand it.
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
This diff is collapsed.
Click to expand it.
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