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
111c45c0
Commit
111c45c0
authored
Oct 14, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added planner service
parent
cf85aed9
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
553 additions
and
123 deletions
+553
-123
DRIPCaller.java
...api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPCaller.java
+1
-1
Message.java
...a/nl/uva/sne/drip/drip/commons/data/internal/Message.java
+0
-7
pom.xml
drip-manager/pom.xml
+2
-4
Swagger2SpringBoot.java
...ger/src/main/java/nl/uva/sne/drip/Swagger2SpringBoot.java
+17
-1
PlannerApiController.java
...c/main/java/nl/uva/sne/drip/api/PlannerApiController.java
+9
-17
MongoConfig.java
.../main/java/nl/uva/sne/drip/configuration/MongoConfig.java
+0
-2
RPCCallersConfig.java
.../java/nl/uva/sne/drip/configuration/RPCCallersConfig.java
+27
-0
RabbitMQConfig.java
...in/java/nl/uva/sne/drip/configuration/RabbitMQConfig.java
+36
-0
Message.java
...-manager/src/main/java/nl/uva/sne/drip/model/Message.java
+81
-0
MessageParameter.java
...src/main/java/nl/uva/sne/drip/model/MessageParameter.java
+88
-0
ToscaTemplate.java
...er/src/main/java/nl/uva/sne/drip/model/ToscaTemplate.java
+1
-0
DRIPCaller.java
...manager/src/main/java/nl/uva/sne/drip/rpc/DRIPCaller.java
+123
-0
PlannerCaller.java
...ager/src/main/java/nl/uva/sne/drip/rpc/PlannerCaller.java
+42
-0
CredentialService.java
.../main/java/nl/uva/sne/drip/service/CredentialService.java
+0
-4
PlannerService.java
...src/main/java/nl/uva/sne/drip/service/PlannerService.java
+49
-1
ToscaTemplateService.java
...in/java/nl/uva/sne/drip/service/ToscaTemplateService.java
+5
-3
application.properties
drip-manager/src/main/resources/application.properties
+3
-0
workspace.xml
drip_planner2/.idea/workspace.xml
+18
-21
rpc_server.py
drip_planner2/src/rpc_server.py
+51
-62
tosca.cpython-36.pyc
drip_planner2/src/utils/__pycache__/tosca.cpython-36.pyc
+0
-0
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPCaller.java
View file @
111c45c0
...
...
@@ -103,7 +103,7 @@ public abstract class DRIPCaller implements AutoCloseable {
.
correlationId
(
corrId
)
.
replyTo
(
getReplyQueueName
())
.
build
();
Logger
.
getLogger
(
DRIPCaller
.
class
.
getName
()).
log
(
Level
.
INFO
,
"Sending:
"
+
jsonInString
+
" to queue: "
+
requestQeueName
);
Logger
.
getLogger
(
DRIPCaller
.
class
.
getName
()).
log
(
Level
.
INFO
,
"Sending:
{0} to queue: {1}"
,
new
Object
[]{
jsonInString
,
requestQeueName
}
);
getChannel
().
basicPublish
(
""
,
requestQeueName
,
props
,
jsonInString
.
getBytes
(
"UTF-8"
));
final
BlockingQueue
<
String
>
response
=
new
ArrayBlockingQueue
(
1
);
...
...
drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/data/internal/Message.java
View file @
111c45c0
...
...
@@ -17,13 +17,6 @@ package nl.uva.sne.drip.drip.commons.data.internal;
import
java.io.Serializable
;
import
java.util.List
;
//import javax.persistence.Column;
//import javax.persistence.Entity;
//import javax.persistence.GeneratedValue;
//import javax.persistence.GenerationType;
//import javax.persistence.Id;
//import javax.persistence.Temporal;
//import javax.persistence.TemporalType;
/**
*
...
...
drip-manager/pom.xml
View file @
111c45c0
...
...
@@ -86,10 +86,8 @@
<type>
jar
</type>
</dependency>
<dependency>
<groupId>
nl.uva.sne.drip
</groupId>
<artifactId>
drip-commons
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<type>
jar
</type>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
</dependency>
<dependency>
...
...
drip-manager/src/main/java/nl/uva/sne/drip/Swagger2SpringBoot.java
View file @
111c45c0
package
nl
.
uva
.
sne
.
drip
;
import
nl.uva.sne.drip.dao.ToscaTemplateDAO
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.ExitCodeGenerator
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.context.annotation.PropertySources
;
import
org.springframework.data.mongodb.repository.config.EnableMongoRepositories
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@SpringBootApplication
@EnableSwagger2
@PropertySources
({
@PropertySource
(
value
=
"classpath:application.properties"
,
ignoreResourceNotFound
=
true
)
})
@EnableMongoRepositories
(
basePackageClasses
=
{
ToscaTemplateDAO
.
class
})
@ComponentScan
(
basePackages
=
{
"nl.uva.sne.drip"
,
"nl.uva.sne.drip.api"
,
"nl.uva.sne.drip.configuration"
,
"nl.uva.sne.drip.dao"
,
"nl.uva.sne.drip.model"
,
"nl.uva.sne.drip.service"
})
@ComponentScan
(
basePackages
=
{
"nl.uva.sne.drip"
,
"nl.uva.sne.drip.api"
,
"nl.uva.sne.drip.configuration"
,
"nl.uva.sne.drip.dao"
,
"nl.uva.sne.drip.model"
,
"nl.uva.sne.drip.service"
})
public
class
Swagger2SpringBoot
implements
CommandLineRunner
{
@Value
(
"${message.broker.host}"
)
private
String
messageBrokerHost
;
@Value
(
"${message.broker.username}"
)
private
String
messageBrokerUsername
;
@Value
(
"${message.broker.password}"
)
private
String
messageBrokerPassword
;
@Override
public
void
run
(
String
...
arg0
)
throws
Exception
{
if
(
arg0
.
length
>
0
&&
arg0
[
0
].
equals
(
"exitcode"
))
{
...
...
@@ -28,6 +43,7 @@ public class Swagger2SpringBoot implements CommandLineRunner {
}
class
ExitException
extends
RuntimeException
implements
ExitCodeGenerator
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
...
...
drip-manager/src/main/java/nl/uva/sne/drip/api/PlannerApiController.java
View file @
111c45c0
...
...
@@ -9,12 +9,9 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
java.util.List
;
import
nl.uva.sne.drip.service.PlannerService
;
import
nl.uva.sne.drip.service.ToscaTemplateService
;
import
org.springframework.beans.factory.annotation.Autowired
;
@javax
.
annotation
.
Generated
(
value
=
"io.swagger.codegen.languages.SpringCodegen"
,
date
=
"2019-10-10T17:15:46.465Z"
)
@Controller
public
class
PlannerApiController
implements
PlannerApi
{
...
...
@@ -30,9 +27,6 @@ public class PlannerApiController implements PlannerApi {
private
PlannerService
plannerService
;
@Autowired
private
ToscaTemplateService
toscaTemplateService
;
@org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
public
PlannerApiController
(
ObjectMapper
objectMapper
,
HttpServletRequest
request
)
{
this
.
objectMapper
=
objectMapper
;
...
...
@@ -41,18 +35,16 @@ public class PlannerApiController implements PlannerApi {
public
ResponseEntity
<
String
>
planToscaTemplateByID
(
@ApiParam
(
value
=
"ID of topolog template to plan"
,
required
=
true
)
@PathVariable
(
"id"
)
String
id
)
{
@Override
public
ResponseEntity
<
String
>
planToscaTemplateByID
(
@ApiParam
(
value
=
"ID of topolog template to plan"
,
required
=
true
)
@PathVariable
(
"id"
)
String
id
)
{
String
accept
=
request
.
getHeader
(
"Accept"
);
if
(
accept
!=
null
&&
accept
.
contains
(
""
))
{
try
{
return
new
ResponseEntity
<
String
>(
objectMapper
.
readValue
(
""
,
String
.
class
),
HttpStatus
.
NOT_IMPLEMENTED
);
}
catch
(
IOException
e
)
{
log
.
error
(
"Couldn't serialize response for content type "
,
e
);
return
new
ResponseEntity
<
String
>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
if
(
accept
!=
null
&&
accept
.
contains
(
"text/plain"
))
{
String
planedYemplateId
=
plannerService
.
plan
(
id
);
return
new
ResponseEntity
<>(
planedYemplateId
,
HttpStatus
.
OK
);
}
}
return
new
ResponseEntity
<>(
HttpStatus
.
NOT_IMPLEMENTED
);
return
new
ResponseEntity
<>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
drip-manager/src/main/java/nl/uva/sne/drip/configuration/MongoConfig.java
View file @
111c45c0
...
...
@@ -32,8 +32,6 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie
@EnableMongoRepositories
(
basePackages
=
"nl.uva.sne.drip.api"
)
@PropertySources
({
@PropertySource
(
value
=
"classpath:application.properties"
,
ignoreResourceNotFound
=
true
)
,
@PropertySource
(
value
=
"file:etc/application.properties"
,
ignoreResourceNotFound
=
true
)
})
@ComponentScan
(
basePackages
=
{
"nl.uva.sne.drip"
,
"nl.uva.sne.drip.api"
,
"nl.uva.sne.drip.configuration"
,
"nl.uva.sne.drip.dao"
,
"nl.uva.sne.drip.model"
,
"nl.uva.sne.drip.service"
})
public
class
MongoConfig
extends
AbstractMongoConfiguration
{
...
...
drip-manager/src/main/java/nl/uva/sne/drip/configuration/RPCCallersConfig.java
0 → 100644
View file @
111c45c0
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
nl
.
uva
.
sne
.
drip
.
configuration
;
import
com.rabbitmq.client.ConnectionFactory
;
import
java.io.IOException
;
import
java.util.concurrent.TimeoutException
;
import
nl.uva.sne.drip.rpc.PlannerCaller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
*
* @author S. Koulouzis
*/
@Configuration
public
class
RPCCallersConfig
{
@Autowired
ConnectionFactory
factory
;
}
drip-manager/src/main/java/nl/uva/sne/drip/configuration/RabbitMQConfig.java
0 → 100644
View file @
111c45c0
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
nl
.
uva
.
sne
.
drip
.
configuration
;
import
com.rabbitmq.client.ConnectionFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
*
* @author S. Koulouzis
*/
@Configuration
public
class
RabbitMQConfig
{
@Value
(
"${message.broker.host}"
)
private
String
messageBrokerHost
;
@Value
(
"${message.broker.username}"
)
private
String
messageBrokerUsername
;
@Value
(
"${message.broker.password}"
)
private
String
messageBrokerPassword
;
@Bean
public
ConnectionFactory
connectionFactory
()
{
ConnectionFactory
connectionFactory
=
new
ConnectionFactory
();
connectionFactory
.
setHost
(
messageBrokerHost
);
connectionFactory
.
setUsername
(
messageBrokerUsername
);
connectionFactory
.
setPassword
(
messageBrokerPassword
);
return
connectionFactory
;
}
}
drip-manager/src/main/java/nl/uva/sne/drip/model/Message.java
0 → 100644
View file @
111c45c0
/*
* 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
.
model
;
import
java.io.Serializable
;
import
java.util.List
;
/**
*
*
*
* @author S. Koulouzis.
*/
public
class
Message
implements
Serializable
{
private
String
owner
;
private
Long
creationDate
;
private
List
<
MessageParameter
>
parameters
;
private
ToscaTemplate
toscaTemplate
;
public
Long
getCreationDate
()
{
return
this
.
creationDate
;
}
public
void
setParameters
(
List
<
MessageParameter
>
parameters
)
{
this
.
parameters
=
parameters
;
}
public
List
<
MessageParameter
>
getParameters
()
{
return
this
.
parameters
;
}
public
void
setCreationDate
(
Long
creationDate
)
{
this
.
creationDate
=
creationDate
;
}
/**
* @return the owner
*/
public
String
getOwner
()
{
return
owner
;
}
/**
* @param owner the owner to set
*/
public
void
setOwner
(
String
owner
)
{
this
.
owner
=
owner
;
}
/**
* @return the toscaTemplate
*/
public
ToscaTemplate
getToscaTemplate
()
{
return
toscaTemplate
;
}
/**
* @param toscaTemplate the toscaTemplate to set
*/
public
void
setToscaTemplate
(
ToscaTemplate
toscaTemplate
)
{
this
.
toscaTemplate
=
toscaTemplate
;
}
}
drip-manager/src/main/java/nl/uva/sne/drip/model/MessageParameter.java
0 → 100644
View file @
111c45c0
/*
* 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
.
model
;
import
java.io.Serializable
;
import
java.util.Map
;
/**
*
* @author S. Koulouzis.
*/
public
class
MessageParameter
implements
Serializable
{
private
String
url
;
private
String
encoding
;
private
String
value
;
private
String
name
;
private
Map
<
String
,
String
>
attributes
;
public
static
final
String
NAME
=
"name"
;
public
static
final
String
URL
=
"url"
;
public
static
final
String
VALUE
=
"value"
;
public
static
final
String
ENCODING
=
"encoding"
;
public
static
final
String
TOSCA_TEMPLATE
=
"tosca_template"
;
public
String
getURL
()
{
return
this
.
url
;
}
public
void
setURL
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getEncoding
()
{
return
this
.
encoding
;
}
public
void
setEncoding
(
String
encoding
)
{
this
.
encoding
=
encoding
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getName
()
{
return
this
.
name
;
}
public
String
getValue
()
{
return
this
.
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
/**
* @return the attributes
*/
public
Map
<
String
,
String
>
getAttributes
()
{
return
attributes
;
}
/**
* @param attributes the attributes to set
*/
public
void
setAttributes
(
Map
<
String
,
String
>
attributes
)
{
this
.
attributes
=
attributes
;
}
}
drip-manager/src/main/java/nl/uva/sne/drip/model/ToscaTemplate.java
View file @
111c45c0
...
...
@@ -19,6 +19,7 @@ import org.springframework.data.annotation.Id;
*/
@Validated
@JsonInclude
(
Include
.
NON_NULL
)
public
class
ToscaTemplate
{
@Id
...
...
drip-manager/src/main/java/nl/uva/sne/drip/rpc/DRIPCaller.java
0 → 100644
View file @
111c45c0
package
nl
.
uva
.
sne
.
drip
.
rpc
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.rabbitmq.client.AMQP
;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.Connection
;
import
com.rabbitmq.client.ConnectionFactory
;
import
com.rabbitmq.client.DefaultConsumer
;
import
com.rabbitmq.client.Envelope
;
import
java.io.IOException
;
import
java.util.UUID
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.TimeoutException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.model.Message
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/*
* 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.
*/
/**
*
* @author S. Koulouzis
*/
public
abstract
class
DRIPCaller
implements
AutoCloseable
{
private
final
Connection
connection
;
private
final
Channel
channel
;
private
final
String
replyQueueName
;
private
final
String
requestQeueName
;
private
final
ObjectMapper
mapper
;
public
DRIPCaller
(
String
requestQeueName
,
ConnectionFactory
factory
)
throws
IOException
,
TimeoutException
{
// factory.setHost(messageBrokerHost);
// factory.setPort(AMQP.PROTOCOL.PORT);
// factory.setUsername(username);
// factory.setPassword(password);
connection
=
factory
.
newConnection
();
channel
=
connection
.
createChannel
();
// create a single callback queue per client not per requests.
replyQueueName
=
channel
.
queueDeclare
().
getQueue
();
this
.
requestQeueName
=
requestQeueName
;
this
.
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
JsonParser
.
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
}
/**
* @return the connection
*/
public
Connection
getConnection
()
{
return
connection
;
}
/**
* @return the channel
*/
public
Channel
getChannel
()
{
return
channel
;
}
/**
* @return the replyQueueName
*/
public
String
getReplyQueueName
()
{
return
replyQueueName
;
}
@Override
public
void
close
()
throws
IOException
,
TimeoutException
{
if
(
channel
!=
null
&&
channel
.
isOpen
())
{
channel
.
close
();
}
if
(
connection
!=
null
&&
connection
.
isOpen
())
{
connection
.
close
();
}
}
public
Message
call
(
Message
r
)
throws
IOException
,
TimeoutException
,
InterruptedException
{
String
jsonInString
=
mapper
.
writeValueAsString
(
r
);
//Build a correlation ID to distinguish responds
final
String
corrId
=
UUID
.
randomUUID
().
toString
();
AMQP
.
BasicProperties
props
=
new
AMQP
.
BasicProperties
.
Builder
()
.
correlationId
(
corrId
)
.
replyTo
(
getReplyQueueName
())
.
build
();
Logger
.
getLogger
(
DRIPCaller
.
class
.
getName
()).
log
(
Level
.
INFO
,
"Sending: {0} to queue: {1}"
,
new
Object
[]{
jsonInString
,
requestQeueName
});
getChannel
().
basicPublish
(
""
,
requestQeueName
,
props
,
jsonInString
.
getBytes
(
"UTF-8"
));
final
BlockingQueue
<
String
>
response
=
new
ArrayBlockingQueue
(
1
);
getChannel
().
basicConsume
(
getReplyQueueName
(),
true
,
new
DefaultConsumer
(
getChannel
())
{
@Override
public
void
handleDelivery
(
String
consumerTag
,
Envelope
envelope
,
AMQP
.
BasicProperties
properties
,
byte
[]
body
)
throws
IOException
{
if
(
properties
.
getCorrelationId
().
equals
(
corrId
))
{
response
.
offer
(
new
String
(
body
,
"UTF-8"
));
}
}
});
String
resp
=
response
.
take
();
Logger
.
getLogger
(
DRIPCaller
.
class
.
getName
()).
log
(
Level
.
INFO
,
"Got: {0}"
,
resp
);
return
mapper
.
readValue
(
resp
,
Message
.
class
);
}
}
drip-manager/src/main/java/nl/uva/sne/drip/rpc/PlannerCaller.java
0 → 100644
View file @
111c45c0
/*
* 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
.
rpc
;
import
com.rabbitmq.client.ConnectionFactory
;
import
java.io.IOException
;
import
java.util.concurrent.TimeoutException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
*
* @author S. Koulouzis.
*/
@Component
public
class
PlannerCaller
extends
DRIPCaller
{
private
static
final
String
REQUEST_QUEUE_NAME
=
"planner_queue"
;
@Autowired
ConnectionFactory
factory
;
@Autowired
public
PlannerCaller
(
ConnectionFactory
factory
)
throws
IOException
,
TimeoutException
{
super
(
REQUEST_QUEUE_NAME
,
factory
);
}
}
drip-manager/src/main/java/nl/uva/sne/drip/service/CredentialService.java
View file @
111c45c0
...
...
@@ -6,10 +6,6 @@
package
nl
.
uva
.
sne
.
drip
.
service
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.dataformat.yaml.YAMLFactory
;
import
com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
drip-manager/src/main/java/nl/uva/sne/drip/service/PlannerService.java
View file @
111c45c0
...
...
@@ -5,10 +5,58 @@
*/
package
nl
.
uva
.
sne
.
drip
.
service
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
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.model.Message
;
import
nl.uva.sne.drip.model.MessageParameter
;
import
nl.uva.sne.drip.model.ToscaTemplate
;
import
nl.uva.sne.drip.rpc.DRIPCaller
;
import
nl.uva.sne.drip.rpc.PlannerCaller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
/**
*
* @author S. Koulouzis
*/
@Service
public
class
PlannerService
{
@Autowired
private
ToscaTemplateService
toscaTemplateService
;
@Autowired
PlannerCaller
plannerCaller
;
public
String
plan
(
String
id
)
{
try
{
String
ymlToscaTemplate
=
toscaTemplateService
.
findByID
(
id
);
ToscaTemplate
toscaTemplate
=
toscaTemplateService
.
getYaml2ToscaTemplate
(
ymlToscaTemplate
);
Message
message
=
new
Message
();
message
.
setCreationDate
(
System
.
currentTimeMillis
());
message
.
setToscaTemplate
(
toscaTemplate
);
Message
plannerResponse
=
plannerCaller
.
call
(
message
);
ToscaTemplate
plannedToscaTemplate
=
plannerResponse
.
getToscaTemplate
();
return
toscaTemplateService
.
save
(
plannedToscaTemplate
);
}
catch
(
IOException
|
TimeoutException
|
InterruptedException
ex
)
{
Logger
.
getLogger
(
PlannerService
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
finally
{
try
{
plannerCaller
.
close
();
}
catch
(
IOException
|
TimeoutException
ex
)
{
Logger
.
getLogger
(
PlannerService
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
return
null
;
}
}
drip-manager/src/main/java/nl/uva/sne/drip/service/ToscaTemplateService.java
View file @
111c45c0
...
...
@@ -44,7 +44,6 @@ public class ToscaTemplateService {
}
public
String
saveFile
(
MultipartFile
file
)
throws
IOException
,
ApiException
{
String
originalFileName
=
file
.
getOriginalFilename
();
String
name
=
System
.
currentTimeMillis
()
+
"_"
+
originalFileName
;
byte
[]
bytes
=
file
.
getBytes
();
...
...
@@ -89,5 +88,8 @@ public class ToscaTemplateService {
dao
.
deleteAll
();
}
public
ToscaTemplate
getYaml2ToscaTemplate
(
String
ymlStr
)
throws
IOException
{
return
objectMapper
.
readValue
(
ymlStr
,
ToscaTemplate
.
class
);
}
}
drip-manager/src/main/resources/application.properties
View file @
111c45c0
...
...
@@ -5,6 +5,9 @@ spring.jackson.date-format=nl.uva.sne.drip.RFC3339DateFormat
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS
=
false
message.broker.host
=
127.0.0.1
message.broker.username
=
guest
message.broker.password
=
guest
db.host
=
127.0.0.1
db.name
=
drip
db.username
=
drip-user
...
...
drip_planner2/.idea/workspace.xml
View file @
111c45c0
...
...
@@ -2,30 +2,22 @@
<project
version=
"4"
>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"462ede19-adfe-472b-975e-fefefa973fe0"
name=
"Default Changelist"
comment=
"slolved cap error"
>
<change
beforePath=
"$PROJECT_DIR$/../docs/NOTES"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../docs/NOTES"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/nb-configuration.xml"
beforeDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/Message.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/MessageParameter.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/rpc/DRIPCaller.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/rpc/PlannerCaller.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPCaller.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPCaller.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/data/internal/Message.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/data/internal/Message.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/pom.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/pom.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/Swagger2SpringBoot.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/Swagger2SpringBoot.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiException.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiException.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiOriginFilter.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiOriginFilter.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiResponseMessage.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiResponseMessage.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/NotFoundException.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/NotFoundException.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/TopologTemplateApi.java"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/TopologTemplateApiController.java"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/UserApi.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/UserApi.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/UserApiController.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/UserApiController.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/CustomInstantDeserializer.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/CustomInstantDeserializer.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/PlannerApiController.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/PlannerApiController.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/MongoConfig.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/MongoConfig.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/SwaggerDocumentationConfig.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/SwaggerDocumentationConfig.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/dao/TopologTemplateDAO.java"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/NodeTemplate.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/NodeTemplate.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/TopologyTemplate.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/TopologyTemplate.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/ToscaTemplate.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/ToscaTemplate.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/User.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/User.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/TopologTemplateService.java"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/swagger.yaml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/swagger.yaml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/CredentialService.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/CredentialService.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/PlannerService.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/PlannerService.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/ToscaTemplateService.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/ToscaTemplateService.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-manager/src/main/resources/application.properties"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-manager/src/main/resources/application.properties"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/
venv/lib/python3.6/site-packages/setuptools-40.8.0-py3.6.egg"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/venv/lib/python3.6/site-packages/setuptools-40.8.0-py3.6.egg
"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/
src/rpc_server.py"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/src/rpc_server.py
"
afterDir=
"false"
/>
</list>
<option
name=
"EXCLUDED_CONVERTED_TO_IGNORED"
value=
"true"
/>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
...
...
@@ -111,7 +103,7 @@
<option
name=
"ADD_CONTENT_ROOTS"
value=
"true"
/>
<option
name=
"ADD_SOURCE_ROOTS"
value=
"true"
/>
<option
name=
"SCRIPT_NAME"
value=
"$PROJECT_DIR$/src/rpc_server.py"
/>
<option
name=
"PARAMETERS"
value=
"
test_local
"
/>
<option
name=
"PARAMETERS"
value=
"
localhost planner_queue
"
/>
<option
name=
"SHOW_COMMAND_LINE"
value=
"false"
/>
<option
name=
"EMULATE_TERMINAL"
value=
"false"
/>
<option
name=
"MODULE_MODE"
value=
"false"
/>
...
...
@@ -228,6 +220,11 @@
<line>
64
</line>
<option
name=
"timeStamp"
value=
"1"
/>
</line-breakpoint>
<line-breakpoint
enabled=
"true"
suspend=
"THREAD"
type=
"python-line"
>
<url>
file://$PROJECT_DIR$/src/rpc_server.py
</url>
<line>
95
</line>
<option
name=
"timeStamp"
value=
"11"
/>
</line-breakpoint>
</breakpoints>
<default-breakpoints>
<breakpoint
type=
"python-exception"
>
...
...
drip_planner2/src/rpc_server.py
View file @
111c45c0
...
...
@@ -7,6 +7,8 @@ import logging
import
os
import
os.path
from
builtins
import
print
import
yaml
from
planner.basic_planner
import
*
from
planner.planner
import
*
import
pika
...
...
@@ -18,13 +20,15 @@ import base64
from
utils
import
tosca
as
tosca_util
logger
=
logging
.
getLogger
(
__name__
)
# if not getattr(logger, 'handler_set', None):
# logger.setLevel(logging.INFO)
# h = logging.StreamHandler()
# formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# h.setFormatter(formatter)
# logger.addHandler(h)
# logger.handler_set = True
# logger.setLevel(logging.INFO)
# h = logging.StreamHandler()
# formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# h.setFormatter(formatter)
# logger.addHandler(h)
# logger.handler_set = True
def
init_chanel
(
args
):
...
...
@@ -41,12 +45,11 @@ def init_chanel(args):
return
channel
def
start
(
channel
):
channel
.
basic_qos
(
prefetch_count
=
1
)
channel
.
basic_consume
(
on_request
,
queue
=
queue_name
)
def
start
(
this_channel
):
this_channel
.
basic_qos
(
prefetch_count
=
1
)
this_channel
.
basic_consume
(
queue
=
queue_name
,
on_message_callback
=
on_request
)
logger
.
info
(
" [x] Awaiting RPC requests"
)
channel
.
start_consuming
()
this_
channel
.
start_consuming
()
def
on_request
(
ch
,
method
,
props
,
body
):
...
...
@@ -61,57 +64,48 @@ def on_request(ch, method, props, body):
def
handle_delivery
(
message
):
logger
.
info
(
"Got: "
+
str
(
message
))
logger
.
info
(
"Got: "
+
str
(
message
))
try
:
message
=
message
.
decode
()
except
(
UnicodeDecodeError
,
AttributeError
):
pass
parsed_json_message
=
json
.
loads
(
message
)
params
=
parsed_json_message
[
"parameters"
]
owner
=
parsed_json_message
[
'owner'
]
tosca_value
=
{}
tosca_file_name
=
''
max_vms
=
-
1
for
param
in
params
:
value
=
param
[
'value'
]
name
=
param
[
"name"
]
if
name
==
'tosca_input'
:
tosca_value
=
json
.
loads
(
value
)
tosca_file_name
=
name
if
name
==
'max_vm'
:
max_vms
=
int
(
value
)
current_milli_time
=
lambda
:
int
(
round
(
time
.
time
()
*
1000
))
#rabbit = DRIPLoggingHandler(host=rabbitmq_host, port=5672, user=owner)
#logger.addHandler(rabbit)
tosca_file_name
=
'tosca_template'
tosca_template_json
=
parsed_json_message
[
'toscaTemplate'
]
input_current_milli_time
=
lambda
:
int
(
round
(
time
.
time
()
*
1000
))
# rabbit = DRIPLoggingHandler(host=rabbitmq_host, port=5672, user=owner)
# logger.addHandler(rabbit)
try
:
tosca_f
ile_path
=
tempfile
.
gettempdir
()
+
"/planner_files/"
+
str
(
current_milli_time
())
+
"/"
tosca_f
older_path
=
os
.
path
.
join
(
tempfile
.
gettempdir
(),
"planner_files"
,
str
(
input_current_milli_time
()))
except
NameError
:
import
sys
tosca_file_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
sys
.
argv
[
0
]))
+
"/planner_files/"
+
str
(
current_milli_time
())
+
"/"
tosca_folder_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
sys
.
argv
[
0
]))
+
os
.
path
.
join
(
tempfile
.
gettempdir
(),
"planner_files"
,
str
(
current_milli_time
()))
if
not
os
.
path
.
exists
(
tosca_file_path
):
os
.
makedirs
(
tosca_file_path
)
with
open
(
tosca_file_path
+
"/"
+
tosca_file_name
+
".yml"
,
'w'
)
as
outfile
:
outfile
.
write
(
json
.
dumps
(
tosca_value
))
if
not
os
.
path
.
exists
(
tosca_folder_path
):
os
.
makedirs
(
tosca_folder_path
)
input_tosca_file_path
=
os
.
path
.
join
(
tosca_folder_path
,
tosca_file_name
+
".yml"
)
with
open
(
input_tosca_file_path
,
'w'
)
as
outfile
:
outfile
.
write
(
yaml
.
dump
(
tosca_template_json
))
response
=
{}
current_milli_time
=
lambda
:
int
(
round
(
time
.
time
()
*
1000
))
response
[
"creationDate"
]
=
current_milli_time
()
planner
=
Planner
(
input_tosca_file_path
)
required_nodes
=
planner
.
resolve_requirements
()
required_nodes
=
planner
.
set_infrastructure_specifications
(
required_nodes
)
planner
.
add_required_nodes_to_template
(
required_nodes
)
planned_template
=
tosca_util
.
get_tosca_template_as_yml
(
planner
.
template
)
logger
.
info
(
"template ----:
\n
"
+
planned_template
)
template_dict
=
yaml
.
load
(
planned_template
)
response
=
{
'toscaTemplate'
:
template_dict
}
output_current_milli_time
=
lambda
:
int
(
round
(
time
.
time
()
*
1000
))
response
[
"creationDate"
]
=
output_current_milli_time
response
[
"parameters"
]
=
[]
if
queue_name
==
"planner_queue"
:
planner
=
BasicPlanner
(
tosca_file_path
+
"/"
+
tosca_file_name
+
".yml"
)
plan
=
planner
.
get_plan
()
parameter
=
{}
encodedBytes
=
base64
.
b64encode
(
plan
.
encode
(
"utf-8"
))
encodedStr
=
str
(
encodedBytes
,
"utf-8"
)
parameter
[
'value'
]
=
encodedStr
parameter
[
'name'
]
=
'tosca_plan'
parameter
[
'encoding'
]
=
'UTF-8'
response
[
"parameters"
]
.
append
(
parameter
)
logger
.
info
(
"Planning"
)
logger
.
info
(
"Returning plan"
)
logger
.
info
(
"Output message:"
+
json
.
dumps
(
response
))
return
json
.
dumps
(
response
)
...
...
@@ -119,19 +113,14 @@ def handle_delivery(message):
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
if
(
sys
.
argv
[
1
]
==
"test_local"
):
# home = expanduser("~")
# tosca_reposetory_api_base_url = "http://localhost:8080/winery"
# namespace = "http%253A%252F%252Fsne.uva.nl%252Fservicetemplates"
# servicetemplate_id = "wordpress_w1-wip1"
# planner = WineryPlanner(tosca_reposetory_api_base_url,namespace,servicetemplate_id)
if
sys
.
argv
[
1
]
==
"test_local"
:
tosca_file_path
=
"../../TOSCA/application_example.yaml"
# planner = BasicPlanner(tosca_file_path)
planner
=
Planner
(
tosca_file_path
)
required_nodes
=
planner
.
resolve_requirements
()
required_nodes
=
planner
.
set_infrastructure_specifications
(
required_nodes
)
planner
.
add_required_nodes_to_template
(
required_nodes
)
template
=
tosca_util
.
get_tosca_template_as_yml
(
planner
.
template
)
test_
planner
=
Planner
(
tosca_file_path
)
test_planner_required_nodes
=
test_
planner
.
resolve_requirements
()
test_planner_required_nodes
=
test_planner
.
set_infrastructure_specifications
(
test_planner_
required_nodes
)
test_planner
.
add_required_nodes_to_template
(
test_planner_
required_nodes
)
template
=
tosca_util
.
get_tosca_template_as_yml
(
test_
planner
.
template
)
logger
.
info
(
"template ----:
\n
"
+
template
)
else
:
logger
.
info
(
"Input args: "
+
sys
.
argv
[
0
]
+
' '
+
sys
.
argv
[
1
]
+
' '
+
sys
.
argv
[
2
])
...
...
drip_planner2/src/utils/__pycache__/tosca.cpython-36.pyc
View file @
111c45c0
No preview for this file type
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