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
1c0b0780
Commit
1c0b0780
authored
5 years ago
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added tests and get topology status
parent
41ce522b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
266 additions
and
25 deletions
+266
-25
ToscaHelper.java
.../main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java
+11
-0
ToscaHelperTest.java
...t/java/nl/uva/sne/drip/commons/utils/ToscaHelperTest.java
+205
-8
ToscaTemplateApiController.java
.../java/nl/uva/sne/drip/api/ToscaTemplateApiController.java
+9
-2
DRIPService.java
...er/src/main/java/nl/uva/sne/drip/service/DRIPService.java
+29
-12
ToscaTemplateService.java
...in/java/nl/uva/sne/drip/service/ToscaTemplateService.java
+12
-3
No files found.
commons/src/main/java/nl/uva/sne/drip/commons/utils/ToscaHelper.java
View file @
1c0b0780
...
@@ -32,6 +32,7 @@ import java.util.logging.Logger;
...
@@ -32,6 +32,7 @@ import java.util.logging.Logger;
import
nl.uva.sne.drip.model.Exceptions.TypeExeption
;
import
nl.uva.sne.drip.model.Exceptions.TypeExeption
;
import
nl.uva.sne.drip.model.NodeTemplate
;
import
nl.uva.sne.drip.model.NodeTemplate
;
import
nl.uva.sne.drip.model.NodeTemplateMap
;
import
nl.uva.sne.drip.model.NodeTemplateMap
;
import
nl.uva.sne.drip.model.cloud.storm.CloudsStormSubTopology
;
import
nl.uva.sne.drip.model.tosca.Credential
;
import
nl.uva.sne.drip.model.tosca.Credential
;
import
nl.uva.sne.drip.model.tosca.ToscaTemplate
;
import
nl.uva.sne.drip.model.tosca.ToscaTemplate
;
import
nl.uva.sne.drip.sure.tosca.client.DefaultApi
;
import
nl.uva.sne.drip.sure.tosca.client.DefaultApi
;
...
@@ -261,4 +262,14 @@ public class ToscaHelper {
...
@@ -261,4 +262,14 @@ public class ToscaHelper {
return
"vm_user"
;
return
"vm_user"
;
}
}
public
CloudsStormSubTopology
.
StatusEnum
getVMTopologyTemplateStatus
(
NodeTemplateMap
nodeTemplateMap
)
throws
TypeExeption
{
NodeTemplate
nodeTemplate
=
nodeTemplateMap
.
getNodeTemplate
();
if
(
nodeTemplate
.
getType
().
equals
(
VM_TOPOLOGY
))
{
String
status
=
(
String
)
nodeTemplate
.
getAttributes
().
get
(
"status"
);
return
CloudsStormSubTopology
.
StatusEnum
.
fromValue
(
status
);
}
else
{
throw
new
TypeExeption
(
"NodeTemplateMap is not of type: "
+
VM_TOPOLOGY
+
" it is of type: "
+
nodeTemplate
.
getType
());
}
}
}
}
This diff is collapsed.
Click to expand it.
commons/src/test/java/nl/uva/sne/drip/commons/utils/ToscaHelperTest.java
View file @
1c0b0780
...
@@ -36,6 +36,7 @@ import java.util.Properties;
...
@@ -36,6 +36,7 @@ import java.util.Properties;
import
nl.uva.sne.drip.model.NodeTemplate
;
import
nl.uva.sne.drip.model.NodeTemplate
;
import
nl.uva.sne.drip.model.NodeTemplateMap
;
import
nl.uva.sne.drip.model.NodeTemplateMap
;
import
nl.uva.sne.drip.model.Provisioner
;
import
nl.uva.sne.drip.model.Provisioner
;
import
nl.uva.sne.drip.model.cloud.storm.CloudsStormSubTopology
;
import
nl.uva.sne.drip.model.tosca.Credential
;
import
nl.uva.sne.drip.model.tosca.Credential
;
import
nl.uva.sne.drip.model.tosca.ToscaTemplate
;
import
nl.uva.sne.drip.model.tosca.ToscaTemplate
;
import
org.junit.After
;
import
org.junit.After
;
...
@@ -53,12 +54,15 @@ import nl.uva.sne.drip.sure.tosca.client.ApiException;
...
@@ -53,12 +54,15 @@ import nl.uva.sne.drip.sure.tosca.client.ApiException;
public
class
ToscaHelperTest
{
public
class
ToscaHelperTest
{
private
static
ObjectMapper
objectMapper
;
private
static
ObjectMapper
objectMapper
;
private
static
final
String
testUpdatedA
pplicationExampleToscaFilePath
=
".."
+
File
.
separator
+
"TOSCA"
+
File
.
separator
+
"application_example_2_topologies.yaml"
;
private
static
final
String
a
pplicationExampleToscaFilePath
=
".."
+
File
.
separator
+
"TOSCA"
+
File
.
separator
+
"application_example_2_topologies.yaml"
;
private
static
ToscaHelper
instance
;
private
static
ToscaHelper
instance
;
private
static
ToscaTemplate
toscaTemplate
;
private
static
ToscaTemplate
toscaTemplate
a2TVMopologies
;
private
static
Boolean
serviceUp
;
private
static
Boolean
serviceUp
;
private
static
ToscaTemplate
provisionedToscaTemplate
;
private
ToscaTemplate
toscaTemplateWithCredentials
;
private
ToscaTemplate
toscaTemplateWithCredentials
;
private
static
final
String
provisionedToscaFilePath
=
".."
+
File
.
separator
+
"TOSCA"
+
File
.
separator
+
"application_example_provisioned.yaml"
;
public
ToscaHelperTest
()
{
public
ToscaHelperTest
()
{
}
}
...
@@ -68,17 +72,23 @@ public class ToscaHelperTest {
...
@@ -68,17 +72,23 @@ public class ToscaHelperTest {
Properties
prop
=
new
Properties
();
Properties
prop
=
new
Properties
();
String
resourceName
=
"src/test/resources/application.properties"
;
String
resourceName
=
"src/test/resources/application.properties"
;
prop
.
load
(
new
FileInputStream
(
resourceName
));
prop
.
load
(
new
FileInputStream
(
resourceName
));
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
testUpdatedA
pplicationExampleToscaFilePath
));
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
a
pplicationExampleToscaFilePath
));
String
ymlStr
=
new
String
(
bytes
,
"UTF-8"
);
String
ymlStr
=
new
String
(
bytes
,
"UTF-8"
);
objectMapper
=
new
ObjectMapper
(
new
YAMLFactory
().
disable
(
YAMLGenerator
.
Feature
.
WRITE_DOC_START_MARKER
));
objectMapper
=
new
ObjectMapper
(
new
YAMLFactory
().
disable
(
YAMLGenerator
.
Feature
.
WRITE_DOC_START_MARKER
));
objectMapper
.
setSerializationInclusion
(
JsonInclude
.
Include
.
NON_NULL
);
objectMapper
.
setSerializationInclusion
(
JsonInclude
.
Include
.
NON_NULL
);
toscaTemplatea2TVMopologies
=
objectMapper
.
readValue
(
ymlStr
,
ToscaTemplate
.
class
);
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
provisionedToscaFilePath
));
ymlStr
=
new
String
(
bytes
,
"UTF-8"
);
objectMapper
=
new
ObjectMapper
(
new
YAMLFactory
().
disable
(
YAMLGenerator
.
Feature
.
WRITE_DOC_START_MARKER
));
objectMapper
.
setSerializationInclusion
(
JsonInclude
.
Include
.
NON_NULL
);
provisionedToscaTemplate
=
objectMapper
.
readValue
(
ymlStr
,
ToscaTemplate
.
class
);
toscaTemplate
=
objectMapper
.
readValue
(
ymlStr
,
ToscaTemplate
.
class
);
String
serviceBasePath
=
prop
.
getProperty
(
"sure-tosca.base.path"
);
String
serviceBasePath
=
prop
.
getProperty
(
"sure-tosca.base.path"
);
serviceUp
=
isServiceUp
(
serviceBasePath
);
serviceUp
=
isServiceUp
(
serviceBasePath
);
if
(
serviceUp
)
{
if
(
serviceUp
)
{
instance
=
new
ToscaHelper
(
serviceBasePath
);
instance
=
new
ToscaHelper
(
serviceBasePath
);
instance
.
uploadToscaTemplate
(
toscaTemplate
);
instance
.
uploadToscaTemplate
(
toscaTemplate
a2TVMopologies
);
}
}
}
}
...
@@ -159,6 +169,7 @@ public class ToscaHelperTest {
...
@@ -159,6 +169,7 @@ public class ToscaHelperTest {
/**
/**
* Test of getTemplateVMsForVMTopology method, of class ToscaHelper.
* Test of getTemplateVMsForVMTopology method, of class ToscaHelper.
*
* @throws java.lang.Exception
* @throws java.lang.Exception
*/
*/
@Test
@Test
...
@@ -188,6 +199,7 @@ public class ToscaHelperTest {
...
@@ -188,6 +199,7 @@ public class ToscaHelperTest {
toscaTemplateWithCredentials
=
null
;
toscaTemplateWithCredentials
=
null
;
System
.
out
.
println
(
"setCredentialsInVMTopology"
);
System
.
out
.
println
(
"setCredentialsInVMTopology"
);
instance
.
uploadToscaTemplate
(
toscaTemplatea2TVMopologies
);
List
<
NodeTemplateMap
>
vmTopologies
=
instance
.
getVMTopologyTemplates
();
List
<
NodeTemplateMap
>
vmTopologies
=
instance
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
vmTopologyMap
:
vmTopologies
)
{
for
(
NodeTemplateMap
vmTopologyMap
:
vmTopologies
)
{
...
@@ -203,7 +215,7 @@ public class ToscaHelperTest {
...
@@ -203,7 +215,7 @@ public class ToscaHelperTest {
credential
.
setTokenType
(
"passwrd"
);
credential
.
setTokenType
(
"passwrd"
);
credential
.
setUser
(
"user"
);
credential
.
setUser
(
"user"
);
vmTopologyMap
=
instance
.
setCredentialsInVMTopology
(
vmTopologyMap
,
credential
);
vmTopologyMap
=
instance
.
setCredentialsInVMTopology
(
vmTopologyMap
,
credential
);
toscaTemplateWithCredentials
=
instance
.
setNodeInToscaTemplate
(
toscaTemplate
,
vmTopologyMap
);
toscaTemplateWithCredentials
=
instance
.
setNodeInToscaTemplate
(
toscaTemplate
a2TVMopologies
,
vmTopologyMap
);
}
}
instance
.
uploadToscaTemplate
(
toscaTemplateWithCredentials
);
instance
.
uploadToscaTemplate
(
toscaTemplateWithCredentials
);
...
@@ -246,14 +258,199 @@ public class ToscaHelperTest {
...
@@ -246,14 +258,199 @@ public class ToscaHelperTest {
// }
// }
// }
// }
// vmTopologyMap = instance.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisionInterface);
// vmTopologyMap = instance.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisionInterface);
// toscaTemplateWithInterface = instance.setNodeInToscaTemplate(toscaTemplate, vmTopologyMap);
// toscaTemplateWithInterface = instance.setNodeInToscaTemplate(toscaTemplate
a2TVMopologies
, vmTopologyMap);
//// }
//// }
// instance.uploadToscaTemplate(toscaTemplateWithInterface);
// instance.uploadToscaTemplate(toscaTemplateWithInterface);
// topology_1 = toscaTemplateWithCredentials.getTopologyTemplate().getNodeTemplates().get("topology_1");
// topology_1 = toscaTemplateWithCredentials.getTopologyTemplate().getNodeTemplates().get("topology_1");
//
//
// topology = toscaTemplateWithCredentials.getTopologyTemplate().getNodeTemplates().get("topology");
// topology = toscaTemplateWithCredentials.getTopologyTemplate().getNodeTemplates().get("topology");
instance
.
uploadToscaTemplate
(
toscaTemplate
);
instance
.
uploadToscaTemplate
(
toscaTemplatea2TVMopologies
);
}
}
/**
* Test of uploadToscaTemplate method, of class ToscaHelper.
*
* @throws java.lang.Exception
*/
@Test
public
void
testUploadToscaTemplate
()
throws
Exception
{
if
(
serviceUp
)
{
System
.
out
.
println
(
"uploadToscaTemplate"
);
instance
.
uploadToscaTemplate
(
toscaTemplatea2TVMopologies
);
assertTrue
(
true
);
}
}
/**
* Test of getVMNumOfCores method, of class ToscaHelper.
*/
@Test
public
void
testGetVMNumOfCores
()
throws
Exception
{
if
(
serviceUp
)
{
System
.
out
.
println
(
"getVMNumOfCores"
);
instance
.
uploadToscaTemplate
(
provisionedToscaTemplate
);
List
<
NodeTemplateMap
>
vmTopologyTemplatesMap
=
instance
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
nodeTemplateMap
:
vmTopologyTemplatesMap
)
{
List
<
NodeTemplateMap
>
vmTemplatesMap
=
instance
.
getTemplateVMsForVMTopology
(
nodeTemplateMap
);
for
(
NodeTemplateMap
vmMap
:
vmTemplatesMap
)
{
Double
result
=
instance
.
getVMNumOfCores
(
vmMap
);
assertNotNull
(
result
);
}
}
}
}
/**
* Test of getVMNMemSize method, of class ToscaHelper.
*/
@Test
public
void
testGetVMNMemSize
()
throws
Exception
{
if
(
serviceUp
)
{
System
.
out
.
println
(
"getVMNMemSize"
);
instance
.
uploadToscaTemplate
(
provisionedToscaTemplate
);
List
<
NodeTemplateMap
>
vmTopologyTemplatesMap
=
instance
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
nodeTemplateMap
:
vmTopologyTemplatesMap
)
{
List
<
NodeTemplateMap
>
vmTemplatesMap
=
instance
.
getTemplateVMsForVMTopology
(
nodeTemplateMap
);
for
(
NodeTemplateMap
vmMap
:
vmTemplatesMap
)
{
Double
result
=
instance
.
getVMNMemSize
(
vmMap
);
assertNotNull
(
result
);
}
}
}
}
/**
* Test of getVMNDiskSize method, of class ToscaHelper.
*/
@Test
public
void
testGetVMNDiskSize
()
throws
Exception
{
if
(
serviceUp
)
{
System
.
out
.
println
(
"getVMNDiskSize"
);
instance
.
uploadToscaTemplate
(
provisionedToscaTemplate
);
List
<
NodeTemplateMap
>
vmTopologyTemplatesMap
=
instance
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
nodeTemplateMap
:
vmTopologyTemplatesMap
)
{
List
<
NodeTemplateMap
>
vmTemplatesMap
=
instance
.
getTemplateVMsForVMTopology
(
nodeTemplateMap
);
for
(
NodeTemplateMap
vmMap
:
vmTemplatesMap
)
{
Double
result
=
instance
.
getVMNDiskSize
(
vmMap
);
assertNotNull
(
result
);
}
}
}
}
/**
* Test of getVMNOS method, of class ToscaHelper.
*/
@Test
public
void
testGetVMNOS
()
throws
Exception
{
if
(
serviceUp
)
{
System
.
out
.
println
(
"getVMNOS"
);
instance
.
uploadToscaTemplate
(
provisionedToscaTemplate
);
List
<
NodeTemplateMap
>
vmTopologyTemplatesMap
=
instance
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
nodeTemplateMap
:
vmTopologyTemplatesMap
)
{
List
<
NodeTemplateMap
>
vmTemplatesMap
=
instance
.
getTemplateVMsForVMTopology
(
nodeTemplateMap
);
for
(
NodeTemplateMap
vmMap
:
vmTemplatesMap
)
{
String
result
=
instance
.
getVMNOS
(
vmMap
);
assertNotNull
(
result
);
}
}
}
}
/**
* Test of getTopologyDomain method, of class ToscaHelper.
*/
@Test
public
void
testGetTopologyDomain
()
throws
Exception
{
if
(
serviceUp
)
{
System
.
out
.
println
(
"getTopologyDomain"
);
instance
.
uploadToscaTemplate
(
provisionedToscaTemplate
);
for
(
NodeTemplateMap
nodeTemplateMap
:
instance
.
getVMTopologyTemplates
())
{
String
result
=
instance
.
getTopologyDomain
(
nodeTemplateMap
);
assertNotNull
(
result
);
}
}
}
/**
* Test of getTopologyProvider method, of class ToscaHelper.
*/
@Test
public
void
testGetTopologyProvider
()
throws
Exception
{
if
(
serviceUp
)
{
System
.
out
.
println
(
"getTopologyProvider"
);
instance
.
uploadToscaTemplate
(
provisionedToscaTemplate
);
for
(
NodeTemplateMap
nodeTemplateMap
:
instance
.
getVMTopologyTemplates
())
{
String
result
=
instance
.
getTopologyProvider
(
nodeTemplateMap
);
assertNotNull
(
result
);
}
}
}
/**
* Test of setCredentialsInVMTopology method, of class ToscaHelper.
*/
@Test
public
void
testSetCredentialsInVMTopology
()
throws
Exception
{
if
(
serviceUp
)
{
toscaTemplateWithCredentials
=
null
;
instance
.
uploadToscaTemplate
(
provisionedToscaTemplate
);
System
.
out
.
println
(
"setCredentialsInVMTopology"
);
List
<
NodeTemplateMap
>
vmTopologies
=
instance
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
vmTopologyMap
:
vmTopologies
)
{
String
provider
=
instance
.
getTopologyProvider
(
vmTopologyMap
);
Credential
credential
=
new
Credential
();
credential
.
setCloudProviderName
(
provider
);
credential
.
setProtocol
(
"protocol"
);
Map
<
String
,
String
>
keys
=
new
HashMap
<>();
keys
.
put
(
"key1"
,
"eeeeeeavovfouirveiuvbepuyb8rwqovd8boacbdbvwy8oqry7f08r3euadinanzxcjc078yn0183xoqedw"
);
credential
.
setKeys
(
keys
);
credential
.
setToken
(
"ijwbfciweubfriw"
);
credential
.
setTokenType
(
"passwrd"
);
credential
.
setUser
(
"user"
);
vmTopologyMap
=
instance
.
setCredentialsInVMTopology
(
vmTopologyMap
,
credential
);
}
}
}
}
}
/**
* Test of getVMTopologyUser method, of class ToscaHelper.
*/
@Test
public
void
testGetVMTopologyUser
()
throws
Exception
{
if
(
serviceUp
)
{
System
.
out
.
println
(
"getVMTopologyUser"
);
instance
.
uploadToscaTemplate
(
provisionedToscaTemplate
);
String
result
=
instance
.
getVMTopologyUser
();
assertEquals
(
"vm_user"
,
result
);
}
}
/**
* Test of getVMTopologyTemplateStatus method, of class ToscaHelper.
*/
@Test
public
void
testGetVMTopologyTemplateStatus
()
throws
Exception
{
if
(
serviceUp
)
{
System
.
out
.
println
(
"getVMTopologyTemplateStatus"
);
toscaTemplateWithCredentials
=
null
;
instance
.
uploadToscaTemplate
(
provisionedToscaTemplate
);
List
<
NodeTemplateMap
>
vmTopologies
=
instance
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
vmTopology
:
vmTopologies
)
{
CloudsStormSubTopology
.
StatusEnum
status
=
instance
.
getVMTopologyTemplateStatus
(
vmTopology
);
assertEquals
(
CloudsStormSubTopology
.
StatusEnum
.
RUNNING
,
status
);
}
}
}
}
}
This diff is collapsed.
Click to expand it.
manager/src/main/java/nl/uva/sne/drip/api/ToscaTemplateApiController.java
View file @
1c0b0780
...
@@ -17,7 +17,9 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -17,7 +17,9 @@ import javax.servlet.http.HttpServletRequest;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
import
nl.uva.sne.drip.model.Exceptions.TypeExeption
;
import
nl.uva.sne.drip.service.ToscaTemplateService
;
import
nl.uva.sne.drip.service.ToscaTemplateService
;
import
nl.uva.sne.drip.sure.tosca.client.ApiException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.SpringCodegen"
,
date
=
"2019-10-10T17:15:46.465Z"
)
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.SpringCodegen"
,
date
=
"2019-10-10T17:15:46.465Z"
)
...
@@ -41,8 +43,13 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
...
@@ -41,8 +43,13 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
public
ResponseEntity
<
String
>
deleteToscaTemplateByID
(
@ApiParam
(
value
=
"ID of topolog template to return"
,
required
=
true
)
@PathVariable
(
"id"
)
String
id
)
{
public
ResponseEntity
<
String
>
deleteToscaTemplateByID
(
@ApiParam
(
value
=
"ID of topolog template to return"
,
required
=
true
)
@PathVariable
(
"id"
)
String
id
)
{
String
accept
=
request
.
getHeader
(
"Accept"
);
String
accept
=
request
.
getHeader
(
"Accept"
);
if
(
accept
!=
null
&&
accept
.
contains
(
"*/*"
))
{
if
(
accept
!=
null
&&
accept
.
contains
(
"*/*"
))
{
toscaTemplateService
.
deleteByID
(
id
);
try
{
return
new
ResponseEntity
<>(
""
,
HttpStatus
.
OK
);
toscaTemplateService
.
deleteByID
(
id
);
return
new
ResponseEntity
<>(
""
,
HttpStatus
.
OK
);
}
catch
(
NotFoundException
|
IOException
|
ApiException
|
TypeExeption
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
ToscaTemplateApiController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
return
new
ResponseEntity
<>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
else
{
}
else
{
return
new
ResponseEntity
<>(
HttpStatus
.
NOT_ACCEPTABLE
);
return
new
ResponseEntity
<>(
HttpStatus
.
NOT_ACCEPTABLE
);
}
}
...
...
This diff is collapsed.
Click to expand it.
manager/src/main/java/nl/uva/sne/drip/service/DRIPService.java
View file @
1c0b0780
...
@@ -19,6 +19,7 @@ import nl.uva.sne.drip.model.Exceptions.MissingCredentialsException;
...
@@ -19,6 +19,7 @@ import nl.uva.sne.drip.model.Exceptions.MissingCredentialsException;
import
nl.uva.sne.drip.model.Exceptions.TypeExeption
;
import
nl.uva.sne.drip.model.Exceptions.TypeExeption
;
import
nl.uva.sne.drip.model.Message
;
import
nl.uva.sne.drip.model.Message
;
import
nl.uva.sne.drip.model.NodeTemplateMap
;
import
nl.uva.sne.drip.model.NodeTemplateMap
;
import
nl.uva.sne.drip.model.cloud.storm.CloudsStormSubTopology
;
import
nl.uva.sne.drip.model.tosca.Credential
;
import
nl.uva.sne.drip.model.tosca.Credential
;
import
nl.uva.sne.drip.model.tosca.ToscaTemplate
;
import
nl.uva.sne.drip.model.tosca.ToscaTemplate
;
import
nl.uva.sne.drip.rpc.DRIPCaller
;
import
nl.uva.sne.drip.rpc.DRIPCaller
;
...
@@ -49,7 +50,14 @@ public class DRIPService {
...
@@ -49,7 +50,14 @@ public class DRIPService {
@Autowired
@Autowired
ProvisionerService
provisionerService
;
ProvisionerService
provisionerService
;
private
static
final
String
OPERATION_PROVISION
=
"provision"
;
enum
PROVISIONER_OPERATION
{
PROVISION
,
DELETE
,
START
,
STOP
,
H_SCALE
,
V_SCALE
,
CONFIGURE
}
enum
DELETE_ACTIONS
{
PROVISION
,
DEPLOYMENT
}
private
String
execute
(
ToscaTemplate
toscaTemplate
)
throws
JsonProcessingException
,
ApiException
,
IOException
,
TimeoutException
,
InterruptedException
{
private
String
execute
(
ToscaTemplate
toscaTemplate
)
throws
JsonProcessingException
,
ApiException
,
IOException
,
TimeoutException
,
InterruptedException
{
...
@@ -115,22 +123,23 @@ public class DRIPService {
...
@@ -115,22 +123,23 @@ public class DRIPService {
public
String
provision
(
String
id
)
throws
MissingCredentialsException
,
ApiException
,
TypeExeption
,
IOException
,
JsonProcessingException
,
TimeoutException
,
InterruptedException
,
NotFoundException
{
public
String
provision
(
String
id
)
throws
MissingCredentialsException
,
ApiException
,
TypeExeption
,
IOException
,
JsonProcessingException
,
TimeoutException
,
InterruptedException
,
NotFoundException
{
ToscaTemplate
toscaTemplate
=
initExecution
(
id
);
ToscaTemplate
toscaTemplate
=
initExecution
(
id
);
toscaTemplate
=
addCredentials
(
toscaTemplate
);
toscaTemplate
=
addCredentials
(
toscaTemplate
);
toscaTemplate
=
setProvision
Operation
(
toscaTemplate
,
OPERATION_
PROVISION
);
toscaTemplate
=
setProvision
erOperation
(
toscaTemplate
,
PROVISIONER_OPERATION
.
PROVISION
);
return
execute
(
toscaTemplate
);
return
execute
(
toscaTemplate
);
}
}
private
ToscaTemplate
setProvision
Operation
(
ToscaTemplate
toscaTemplate
,
String
operation
)
throws
IOException
,
JsonProcessingException
,
ApiException
{
private
ToscaTemplate
setProvision
erOperation
(
ToscaTemplate
toscaTemplate
,
PROVISIONER_OPERATION
operation
)
throws
IOException
,
JsonProcessingException
,
ApiException
{
List
<
NodeTemplateMap
>
vmTopologies
=
helper
.
getVMTopologyTemplates
();
List
<
NodeTemplateMap
>
vmTopologies
=
helper
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
vmTopologyMap
:
vmTopologies
)
{
for
(
NodeTemplateMap
vmTopologyMap
:
vmTopologies
)
{
Map
<
String
,
Object
>
provisionerInterface
=
helper
.
getProvisionerInterfaceFromVMTopology
(
vmTopologyMap
);
Map
<
String
,
Object
>
provisionerInterface
=
helper
.
getProvisionerInterfaceFromVMTopology
(
vmTopologyMap
);
if
(!
provisionerInterface
.
containsKey
(
"provision"
))
{
if
(!
provisionerInterface
.
containsKey
(
operation
.
toString
().
toLowerCase
()))
{
Map
<
String
,
Object
>
inputsMap
=
new
HashMap
<>();
throw
new
RuntimeException
(
"Fix this code. We are adding wrong interfaces"
);
inputsMap
.
put
(
operation
,
caller
);
// Map<String, Object> inputsMap = new HashMap<>();
Map
<
String
,
Object
>
provisionMap
=
new
HashMap
<>();
// inputsMap.put(operation.toString().toLowerCase(), caller);
provisionMap
.
put
(
"inputs"
,
inputsMap
);
// Map<String, Object> provisionMap = new HashMap<>();
provisionerInterface
.
put
(
operation
,
caller
);
// provisionMap.put("inputs", inputsMap);
vmTopologyMap
=
helper
.
setProvisionerInterfaceInVMTopology
(
vmTopologyMap
,
provisionerInterface
);
// provisionerInterface.put(operation.toString().toLowerCase(), caller);
toscaTemplate
=
helper
.
setNodeInToscaTemplate
(
toscaTemplate
,
vmTopologyMap
);
// vmTopologyMap = helper.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisionerInterface);
// toscaTemplate = helper.setNodeInToscaTemplate(toscaTemplate, vmTopologyMap);
}
}
}
}
return
toscaTemplate
;
return
toscaTemplate
;
...
@@ -150,7 +159,7 @@ public class DRIPService {
...
@@ -150,7 +159,7 @@ public class DRIPService {
return
execute
(
toscaTemplate
);
return
execute
(
toscaTemplate
);
}
}
private
ToscaTemplate
initExecution
(
String
id
)
throws
JsonProcessingException
,
NotFoundException
,
IOException
,
ApiException
{
private
ToscaTemplate
initExecution
(
String
id
)
throws
JsonProcessingException
,
NotFoundException
,
IOException
,
ApiException
{
String
ymlToscaTemplate
=
toscaTemplateService
.
findByID
(
id
);
String
ymlToscaTemplate
=
toscaTemplateService
.
findByID
(
id
);
Logger
.
getLogger
(
DRIPService
.
class
.
getName
()).
log
(
Level
.
FINE
,
"Found ToscaTemplate with id: {0}"
,
id
);
Logger
.
getLogger
(
DRIPService
.
class
.
getName
()).
log
(
Level
.
FINE
,
"Found ToscaTemplate with id: {0}"
,
id
);
ToscaTemplate
toscaTemplate
=
toscaTemplateService
.
getYaml2ToscaTemplate
(
ymlToscaTemplate
);
ToscaTemplate
toscaTemplate
=
toscaTemplateService
.
getYaml2ToscaTemplate
(
ymlToscaTemplate
);
...
@@ -158,4 +167,12 @@ public class DRIPService {
...
@@ -158,4 +167,12 @@ public class DRIPService {
return
toscaTemplate
;
return
toscaTemplate
;
}
}
void
deleteActions
(
ToscaTemplate
toscaTemplate
)
throws
ApiException
,
TypeExeption
{
List
<
NodeTemplateMap
>
vmTopologies
=
helper
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
vmTopology
:
vmTopologies
){
CloudsStormSubTopology
.
StatusEnum
status
=
helper
.
getVMTopologyTemplateStatus
(
vmTopology
);
}
}
}
}
This diff is collapsed.
Click to expand it.
manager/src/main/java/nl/uva/sne/drip/service/ToscaTemplateService.java
View file @
1c0b0780
...
@@ -14,9 +14,14 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
...
@@ -14,9 +14,14 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.api.NotFoundException
;
import
nl.uva.sne.drip.api.NotFoundException
;
import
nl.uva.sne.drip.dao.ToscaTemplateDAO
;
import
nl.uva.sne.drip.dao.ToscaTemplateDAO
;
import
nl.uva.sne.drip.model.Exceptions.TypeExeption
;
import
nl.uva.sne.drip.model.tosca.ToscaTemplate
;
import
nl.uva.sne.drip.model.tosca.ToscaTemplate
;
import
nl.uva.sne.drip.sure.tosca.client.ApiException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
...
@@ -39,6 +44,8 @@ public class ToscaTemplateService {
...
@@ -39,6 +44,8 @@ public class ToscaTemplateService {
@Autowired
@Autowired
private
ToscaTemplateDAO
dao
;
private
ToscaTemplateDAO
dao
;
@Autowired
private
DRIPService
dripService
;
public
String
save
(
ToscaTemplate
tt
)
{
public
String
save
(
ToscaTemplate
tt
)
{
dao
.
save
(
tt
);
dao
.
save
(
tt
);
...
@@ -69,14 +76,16 @@ public class ToscaTemplateService {
...
@@ -69,14 +76,16 @@ public class ToscaTemplateService {
public
String
findByID
(
String
id
)
throws
JsonProcessingException
,
NotFoundException
{
public
String
findByID
(
String
id
)
throws
JsonProcessingException
,
NotFoundException
{
ToscaTemplate
tt
=
dao
.
findById
(
id
).
get
();
ToscaTemplate
tt
=
dao
.
findById
(
id
).
get
();
if
(
tt
==
null
)
{
if
(
tt
==
null
)
{
throw
new
NotFoundException
(
404
,
"ToscaTemplate with id: "
+
id
+
" not found"
);
throw
new
NotFoundException
(
404
,
"ToscaTemplate with id: "
+
id
+
" not found"
);
}
}
String
ymlStr
=
objectMapper
.
writeValueAsString
(
tt
);
String
ymlStr
=
objectMapper
.
writeValueAsString
(
tt
);
return
ymlStr
;
return
ymlStr
;
}
}
public
void
deleteByID
(
String
id
)
{
public
void
deleteByID
(
String
id
)
throws
JsonProcessingException
,
NotFoundException
,
IOException
,
ApiException
,
TypeExeption
{
ToscaTemplate
toscaTemplate
=
getYaml2ToscaTemplate
(
findByID
(
id
));
dripService
.
deleteActions
(
toscaTemplate
);
dao
.
deleteById
(
id
);
dao
.
deleteById
(
id
);
}
}
...
...
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