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
Mar 16, 2020
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added tests and get topology status
parent
41ce522b
Changes
5
Expand all
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;
import
nl.uva.sne.drip.model.Exceptions.TypeExeption
;
import
nl.uva.sne.drip.model.NodeTemplate
;
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.ToscaTemplate
;
import
nl.uva.sne.drip.sure.tosca.client.DefaultApi
;
...
...
@@ -261,4 +262,14 @@ public class ToscaHelper {
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
());
}
}
}
commons/src/test/java/nl/uva/sne/drip/commons/utils/ToscaHelperTest.java
View file @
1c0b0780
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;
import
java.io.IOException
;
import
java.util.List
;
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.sure.tosca.client.ApiException
;
import
org.springframework.beans.factory.annotation.Autowired
;
@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 {
public
ResponseEntity
<
String
>
deleteToscaTemplateByID
(
@ApiParam
(
value
=
"ID of topolog template to return"
,
required
=
true
)
@PathVariable
(
"id"
)
String
id
)
{
String
accept
=
request
.
getHeader
(
"Accept"
);
if
(
accept
!=
null
&&
accept
.
contains
(
"*/*"
))
{
toscaTemplateService
.
deleteByID
(
id
);
return
new
ResponseEntity
<>(
""
,
HttpStatus
.
OK
);
try
{
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
{
return
new
ResponseEntity
<>(
HttpStatus
.
NOT_ACCEPTABLE
);
}
...
...
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;
import
nl.uva.sne.drip.model.Exceptions.TypeExeption
;
import
nl.uva.sne.drip.model.Message
;
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.ToscaTemplate
;
import
nl.uva.sne.drip.rpc.DRIPCaller
;
...
...
@@ -49,7 +50,14 @@ public class DRIPService {
@Autowired
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
{
...
...
@@ -115,22 +123,23 @@ public class DRIPService {
public
String
provision
(
String
id
)
throws
MissingCredentialsException
,
ApiException
,
TypeExeption
,
IOException
,
JsonProcessingException
,
TimeoutException
,
InterruptedException
,
NotFoundException
{
ToscaTemplate
toscaTemplate
=
initExecution
(
id
);
toscaTemplate
=
addCredentials
(
toscaTemplate
);
toscaTemplate
=
setProvision
Operation
(
toscaTemplate
,
OPERATION_
PROVISION
);
toscaTemplate
=
setProvision
erOperation
(
toscaTemplate
,
PROVISIONER_OPERATION
.
PROVISION
);
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
();
for
(
NodeTemplateMap
vmTopologyMap
:
vmTopologies
)
{
Map
<
String
,
Object
>
provisionerInterface
=
helper
.
getProvisionerInterfaceFromVMTopology
(
vmTopologyMap
);
if
(!
provisionerInterface
.
containsKey
(
"provision"
))
{
Map
<
String
,
Object
>
inputsMap
=
new
HashMap
<>();
inputsMap
.
put
(
operation
,
caller
);
Map
<
String
,
Object
>
provisionMap
=
new
HashMap
<>();
provisionMap
.
put
(
"inputs"
,
inputsMap
);
provisionerInterface
.
put
(
operation
,
caller
);
vmTopologyMap
=
helper
.
setProvisionerInterfaceInVMTopology
(
vmTopologyMap
,
provisionerInterface
);
toscaTemplate
=
helper
.
setNodeInToscaTemplate
(
toscaTemplate
,
vmTopologyMap
);
if
(!
provisionerInterface
.
containsKey
(
operation
.
toString
().
toLowerCase
()))
{
throw
new
RuntimeException
(
"Fix this code. We are adding wrong interfaces"
);
// Map<String, Object> inputsMap = new HashMap<>();
// inputsMap.put(operation.toString().toLowerCase(), caller);
// Map<String, Object> provisionMap = new HashMap<>();
// provisionMap.put("inputs", inputsMap);
// provisionerInterface.put(operation.toString().toLowerCase(), caller);
// vmTopologyMap = helper.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisionerInterface);
// toscaTemplate = helper.setNodeInToscaTemplate(toscaTemplate, vmTopologyMap);
}
}
return
toscaTemplate
;
...
...
@@ -150,7 +159,7 @@ public class DRIPService {
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
);
Logger
.
getLogger
(
DRIPService
.
class
.
getName
()).
log
(
Level
.
FINE
,
"Found ToscaTemplate with id: {0}"
,
id
);
ToscaTemplate
toscaTemplate
=
toscaTemplateService
.
getYaml2ToscaTemplate
(
ymlToscaTemplate
);
...
...
@@ -158,4 +167,12 @@ public class DRIPService {
return
toscaTemplate
;
}
void
deleteActions
(
ToscaTemplate
toscaTemplate
)
throws
ApiException
,
TypeExeption
{
List
<
NodeTemplateMap
>
vmTopologies
=
helper
.
getVMTopologyTemplates
();
for
(
NodeTemplateMap
vmTopology
:
vmTopologies
){
CloudsStormSubTopology
.
StatusEnum
status
=
helper
.
getVMTopologyTemplateStatus
(
vmTopology
);
}
}
}
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;
import
java.io.IOException
;
import
java.util.ArrayList
;
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.dao.ToscaTemplateDAO
;
import
nl.uva.sne.drip.model.Exceptions.TypeExeption
;
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.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -39,6 +44,8 @@ public class ToscaTemplateService {
@Autowired
private
ToscaTemplateDAO
dao
;
@Autowired
private
DRIPService
dripService
;
public
String
save
(
ToscaTemplate
tt
)
{
dao
.
save
(
tt
);
...
...
@@ -69,14 +76,16 @@ public class ToscaTemplateService {
public
String
findByID
(
String
id
)
throws
JsonProcessingException
,
NotFoundException
{
ToscaTemplate
tt
=
dao
.
findById
(
id
).
get
();
if
(
tt
==
null
)
{
throw
new
NotFoundException
(
404
,
"ToscaTemplate with id: "
+
id
+
" not found"
);
if
(
tt
==
null
)
{
throw
new
NotFoundException
(
404
,
"ToscaTemplate with id: "
+
id
+
" not found"
);
}
String
ymlStr
=
objectMapper
.
writeValueAsString
(
tt
);
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
);
}
...
...
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