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
a5bb42ce
Commit
a5bb42ce
authored
Feb 08, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented message for drip componets
implmented example planner
parent
92988cd0
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
446 additions
and
138 deletions
+446
-138
.gitignore
.gitignore
+2
-1
UploadToscaController.java
.../java/nl/uva/sne/drip/api/rest/UploadToscaController.java
+37
-36
DRIPComponentCaller.java
...ain/java/nl/uva/sne/drip/api/rpc/DRIPComponentCaller.java
+2
-2
PlannerCaller.java
.../src/main/java/nl/uva/sne/drip/api/rpc/PlannerCaller.java
+4
-8
FileParameter.java
...ain/java/nl/uva/sne/drip/commons/types/FileParameter.java
+23
-23
IFileParameter.java
...in/java/nl/uva/sne/drip/commons/types/IFileParameter.java
+4
-8
IMessage.java
...src/main/java/nl/uva/sne/drip/commons/types/IMessage.java
+5
-18
IParameter.java
...c/main/java/nl/uva/sne/drip/commons/types/IParameter.java
+32
-0
Message.java
.../src/main/java/nl/uva/sne/drip/commons/types/Message.java
+7
-34
pom.xml
drip-planner/pom.xml
+18
-0
Consumer.java
.../src/main/java/nl/uva/sne/drip/drip/planner/Consumer.java
+126
-8
Planner.java
...r/src/main/java/nl/uva/sne/drip/drip/planner/Planner.java
+124
-0
RPCServer.java
...src/main/java/nl/uva/sne/drip/drip/planner/RPCServer.java
+62
-0
No files found.
.gitignore
View file @
a5bb42ce
/drip-commons/target/
/drip-api/target/
/drip-planner/target/
\ No newline at end of file
drip-api/src/main/java/nl/uva/sne/drip/api/rest/UploadToscaController.java
View file @
a5bb42ce
...
...
@@ -15,11 +15,11 @@
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
rest
;
import
nl.uva.sne.drip.commons.types.FileParameter
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
nl.uva.sne.drip.api.rpc.Planner
;
import
nl.uva.sne.drip.api.rpc.Planner
Caller
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
...
...
@@ -28,25 +28,16 @@ import java.util.List;
import
java.util.concurrent.TimeoutException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javax.annotation.security.RolesAllowed
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.PUT
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.Response
;
import
nl.uva.sne.drip.commons.types.IRequest
;
import
nl.uva.sne.drip.commons.types.Request
;
import
nl.uva.sne.drip.commons.types.Message
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
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.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.multipart.MultipartFile
;
import
nl.uva.sne.drip.commons.types.IMessage
;
/**
*
...
...
@@ -71,22 +62,33 @@ public class UploadToscaController {
try
{
String
originalFileName
=
file
.
getOriginalFilename
();
String
name
=
originalFileName
+
System
.
currentTimeMillis
()
;
File
targetToscaFile
=
new
File
(
inputToscaFolderPath
+
File
.
separator
+
name
);
file
.
transferTo
(
targetToscaFile
);
String
name
=
System
.
currentTimeMillis
()
+
"_"
+
originalFileName
;
//
File targetToscaFile = new File(inputToscaFolderPath + File.separator + name);
//
file.transferTo(targetToscaFile);
Planner
planner
=
new
Planner
(
messageBrokerHost
);
Message
invokationMessage
=
new
Message
(
);
Request
r
=
new
Reque
st
();
List
args
=
new
ArrayList
();
FileArgument
fileArg
=
new
FileArgument
(
);
fileArg
.
setURL
(
targetToscaFile
.
toURI
().
toString
())
;
args
.
add
(
targetToscaFile
);
r
.
setArguments
(
args
);
r
.
setCreationDate
(
new
Date
(
System
.
currentTimeMillis
())
);
r
.
setStatus
(
IRequest
.
Status
.
SUCCESS
);
List
parameters
=
new
ArrayLi
st
();
FileParameter
fileArgument
=
new
FileParameter
();
byte
[]
bytes
=
file
.
getBytes
();
//Files.readAllBytes(Paths.get(targetToscaFile.getAbsolutePath())
);
String
charset
=
"UTF-8"
;
fileArgument
.
setValue
(
new
String
(
bytes
,
charset
)
);
fileArgument
.
setEncoding
(
charset
);
fileArgument
.
setName
(
name
);
parameters
.
add
(
fileArgument
);
String
returned
=
planner
.
plan
(
r
);
fileArgument
=
new
FileParameter
();
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
"/home/alogo/Downloads/DRIP/example_a.yml"
));
fileArgument
.
setValue
(
new
String
(
bytes
,
charset
));
fileArgument
.
setEncoding
(
charset
);
fileArgument
.
setName
(
"example_a.yml"
);
parameters
.
add
(
fileArgument
);
invokationMessage
.
setParameters
(
parameters
);
invokationMessage
.
setCreationDate
(
new
Date
(
System
.
currentTimeMillis
()));
PlannerCaller
planner
=
new
PlannerCaller
(
messageBrokerHost
);
String
returned
=
planner
.
plan
(
invokationMessage
);
planner
.
close
();
return
"You successfully uploaded "
+
name
+
" into "
+
name
+
"-uploaded !"
;
...
...
@@ -98,26 +100,25 @@ public class UploadToscaController {
}
@RequestMapping
(
value
=
"/args"
,
method
=
RequestMethod
.
GET
)
public
Request
args
()
{
public
Message
args
()
{
try
{
Request
r
=
new
Request
();
Message
r
=
new
Message
();
List
args
=
new
ArrayList
();
args
.
add
(
1
);
args
.
add
(
"str"
);
File
Argument
targetToscaFile
=
new
FileArgument
();
File
Parameter
targetToscaFile
=
new
FileParameter
();
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
"/home/alogo/Downloads/planner_output_all.yml"
));
targetToscaFile
.
setContents
(
new
String
(
bytes
,
"UTF-8"
));
targetToscaFile
.
setValue
(
new
String
(
bytes
,
"UTF-8"
));
targetToscaFile
.
setName
(
"planner_output_all.yml"
);
targetToscaFile
.
setEncoding
(
"UTF-8"
);
args
.
add
(
targetToscaFile
);
r
.
set
Argument
s
(
args
);
r
.
set
Parameter
s
(
args
);
r
.
setCreationDate
(
new
Date
(
System
.
currentTimeMillis
()));
r
.
setStatus
(
IRequest
.
Status
.
SUCCESS
);
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonInString
=
mapper
.
writeValueAsString
(
r
);
System
.
err
.
println
(
jsonInString
);
// ObjectMapper mapper = new ObjectMapper();
// String jsonInString = mapper.writeValueAsString(r);
// System.err.println(jsonInString);
return
r
;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
UploadToscaController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPComponent.java
→
drip-api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPComponent
Caller
.java
View file @
a5bb42ce
...
...
@@ -19,9 +19,9 @@ package nl.uva.sne.drip.api.rpc;
*
* @author S. Koulouzis.
*/
class
DRIPComponent
{
class
DRIPComponent
Caller
{
public
DRIPComponent
(){
public
DRIPComponent
Caller
(){
}
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/rpc/Planner.java
→
drip-api/src/main/java/nl/uva/sne/drip/api/rpc/Planner
Caller
.java
View file @
a5bb42ce
...
...
@@ -16,7 +16,6 @@
package
nl
.
uva
.
sne
.
drip
.
api
.
rpc
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.io.File
;
import
java.io.IOException
;
import
com.rabbitmq.client.AMQP
;
...
...
@@ -25,27 +24,24 @@ import com.rabbitmq.client.Connection;
import
com.rabbitmq.client.ConnectionFactory
;
import
com.rabbitmq.client.DefaultConsumer
;
import
com.rabbitmq.client.Envelope
;
import
com.rabbitmq.client.RpcClient
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.UUID
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.TimeoutException
;
import
nl.uva.sne.drip.commons.types.
Request
;
import
nl.uva.sne.drip.commons.types.
Message
;
/**
*
* @author S. Koulouzis.
*/
public
class
Planner
{
public
class
Planner
Caller
{
private
static
final
String
REQUEST_QUEUE_NAME
=
"planner_queue"
;
private
final
Connection
connection
;
private
final
Channel
channel
;
private
final
String
replyQueueName
;
public
Planner
(
String
messageBrokerHost
)
throws
IOException
,
TimeoutException
{
public
Planner
Caller
(
String
messageBrokerHost
)
throws
IOException
,
TimeoutException
{
ConnectionFactory
factory
=
new
ConnectionFactory
();
factory
.
setHost
(
messageBrokerHost
);
...
...
@@ -59,7 +55,7 @@ public class Planner {
replyQueueName
=
channel
.
queueDeclare
().
getQueue
();
}
public
String
plan
(
Request
r
)
throws
IOException
,
TimeoutException
,
InterruptedException
{
public
String
plan
(
Message
r
)
throws
IOException
,
TimeoutException
,
InterruptedException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonInString
=
mapper
.
writeValueAsString
(
r
);
...
...
drip-
api/src/main/java/nl/uva/sne/drip/api/rest/FileArgument
.java
→
drip-
commons/src/main/java/nl/uva/sne/drip/commons/types/FileParameter
.java
View file @
a5bb42ce
...
...
@@ -13,35 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
rest
;
package
nl
.
uva
.
sne
.
drip
.
commons
.
types
;
import
java.io.Serializable
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
/**
*
* @author S. Koulouzis.
*/
class
FileArgument
implements
IFileArgument
,
Serializable
{
public
class
FileParameter
implements
IFileParameter
,
IParameter
,
Serializable
{
public
static
final
String
NAME
=
"name"
;
public
static
final
String
URL
=
"url"
;
public
static
final
String
VALUE
=
"value"
;
public
static
final
String
ENCODING
=
"encoding"
;
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
String
id
;
private
String
url
;
private
String
encoding
;
private
String
contents
;
@Override
public
void
setID
(
String
id
)
{
this
.
id
=
id
;
}
@Override
public
String
getID
()
{
return
this
.
id
;
}
private
String
value
;
private
String
name
;
@Override
public
String
getURL
()
{
...
...
@@ -64,13 +54,23 @@ class FileArgument implements IFileArgument, Serializable {
}
@Override
public
String
getContents
()
{
return
this
.
contents
;
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
@Override
public
String
getName
()
{
return
this
.
name
;
}
@Override
public
String
getValue
()
{
return
this
.
value
;
}
@Override
public
void
set
Contents
(
String
contents
)
{
this
.
contents
=
contents
;
public
void
set
Value
(
String
value
)
{
this
.
value
=
value
;
}
}
drip-
api/src/main/java/nl/uva/sne/drip/api/rest/IFileArgument
.java
→
drip-
commons/src/main/java/nl/uva/sne/drip/commons/types/IFileParameter
.java
View file @
a5bb42ce
...
...
@@ -13,17 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
rest
;
package
nl
.
uva
.
sne
.
drip
.
commons
.
types
;
/**
*
* @author S. Koulouzis.
*/
interface
IFileArgument
{
public
void
setID
(
String
id
);
public
String
getID
();
public
interface
IFileParameter
{
public
String
getURL
();
...
...
@@ -33,8 +29,8 @@ interface IFileArgument {
public
void
setEncoding
(
String
encoding
);
public
String
getContents
(
);
public
void
setName
(
String
name
);
public
void
setContents
(
String
contents
);
public
String
getName
(
);
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/types/I
Request
.java
→
drip-commons/src/main/java/nl/uva/sne/drip/commons/types/I
Message
.java
View file @
a5bb42ce
...
...
@@ -22,27 +22,14 @@ import java.util.List;
*
* @author S. Koulouzis
*/
public
interface
IRequest
{
public
enum
Status
{
FAILED
,
SUCCESS
;
}
public
void
setID
(
String
id
);
public
String
getID
();
public
interface
IMessage
{
public
Date
getCreationDate
();
public
void
setCreationDate
(
Date
creationDate
);
public
Status
getStatus
();
public
void
setStatus
(
Status
status
);
public
void
setArguments
(
List
args
);
public
void
setParameters
(
List
args
);
public
List
get
Argument
s
();
public
List
get
Parameter
s
();
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/types/IParameter.java
0 → 100644
View file @
a5bb42ce
/*
* 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
.
commons
.
types
;
/**
*
* @author S. Koulouzis
*/
public
interface
IParameter
{
public
void
setName
(
String
name
);
public
String
getName
();
public
String
getValue
();
public
void
setValue
(
String
value
);
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/types/
Request
.java
→
drip-commons/src/main/java/nl/uva/sne/drip/commons/types/
Message
.java
View file @
a5bb42ce
...
...
@@ -34,31 +34,14 @@ import java.util.List;
* @author S. Koulouzis.
*/
//@Entity
public
class
Request
implements
IRequest
,
Serializable
{
// @Id
// @GeneratedValue(strategy = GenerationType.AUTO)
private
String
id
;
public
class
Message
implements
IMessage
,
Serializable
{
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss.S"
)
// @Temporal(TemporalType.DATE)
private
Date
creationDate
;
// @Column
private
Status
status
;
// @Column
private
List
arguments
;
@Override
public
void
setID
(
String
id
)
{
this
.
id
=
id
;
}
@Override
public
String
getID
()
{
return
this
.
id
;
}
private
List
<
IParameter
>
parameters
;
@Override
public
Date
getCreationDate
()
{
...
...
@@ -66,23 +49,13 @@ public class Request implements IRequest, Serializable {
}
@Override
public
Status
getStatus
()
{
return
this
.
status
;
}
@Override
public
void
setStatus
(
Status
status
)
{
status
=
this
.
status
;
}
@Override
public
void
setArguments
(
List
args
)
{
this
.
arguments
=
args
;
public
void
setParameters
(
List
args
)
{
this
.
parameters
=
args
;
}
@Override
public
List
get
Argument
s
()
{
return
this
.
argument
s
;
public
List
get
Parameter
s
()
{
return
this
.
parameter
s
;
}
@Override
...
...
drip-planner/pom.xml
View file @
a5bb42ce
...
...
@@ -14,10 +14,28 @@
</properties>
<dependencies>
<dependency>
<groupId>
nl.uva.sne.drip
</groupId>
<artifactId>
drip-commons
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
com.rabbitmq
</groupId>
<artifactId>
amqp-client
</artifactId>
<version>
4.0.2
</version>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
<version>
2.8.6
</version>
</dependency>
<dependency>
<groupId>
org.json
</groupId>
<artifactId>
json
</artifactId>
<version>
20090211
</version>
<type>
jar
</type>
</dependency>
</dependencies>
</project>
\ No newline at end of file
drip-planner/src/main/java/nl/uva/sne/drip/drip/planner/Consumer.java
View file @
a5bb42ce
...
...
@@ -15,11 +15,32 @@
*/
package
nl
.
uva
.
sne
.
drip
.
drip
.
planner
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.rabbitmq.client.AMQP
;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.DefaultConsumer
;
import
com.rabbitmq.client.Envelope
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.commons.types.FileParameter
;
import
nl.uva.sne.drip.commons.types.Message
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
nl.uva.sne.drip.commons.types.IFileParameter
;
/**
*
...
...
@@ -27,13 +48,13 @@ import java.io.IOException;
*/
public
class
Consumer
extends
DefaultConsumer
{
private
static
final
String
RPC_QUEUE_NAME
=
"planner_queue"
;
private
static
final
String
HOST
=
"172.17.0.2"
;
private
final
Channel
channel
;
private
final
Planner
panner
;
public
Consumer
(
Channel
channel
)
{
super
(
channel
);
this
.
channel
=
channel
;
this
.
panner
=
new
Planner
();
}
@Override
...
...
@@ -41,22 +62,119 @@ public class Consumer extends DefaultConsumer {
AMQP
.
BasicProperties
replyProps
=
new
AMQP
.
BasicProperties
.
Builder
()
.
correlationId
(
properties
.
getCorrelationId
())
.
build
();
String
response
=
""
;
try
{
String
message
=
new
String
(
body
,
"UTF-8"
);
System
.
out
.
println
(
" [.] fib("
+
message
+
")"
);
File
[]
inputFiles
;
inputFiles
=
jacksonUnmarshalExample
(
message
);
panner
.
plan
(
inputFiles
[
0
].
getAbsolutePath
(),
inputFiles
[
1
].
getAbsolutePath
(),
"/tmp/out"
);
inputFiles
=
simpleJsonUnmarshalExample
(
message
);
List
<
File
>
files
=
panner
.
plan
(
inputFiles
[
0
].
getAbsolutePath
(),
inputFiles
[
1
].
getAbsolutePath
(),
"/tmp/out"
);
response
=
jacksonMarshalExample
(
files
);
System
.
err
.
println
(
response
);
response
+=
message
;
}
catch
(
RuntimeException
e
)
{
System
.
out
.
println
(
" [.] "
+
e
.
toString
());
response
=
simpleJsonMarshalExample
(
files
);
System
.
err
.
println
(
response
);
}
catch
(
RuntimeException
|
JSONException
ex
)
{
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
finally
{
channel
.
basicPublish
(
""
,
properties
.
getReplyTo
(),
replyProps
,
response
.
getBytes
(
"UTF-8"
));
channel
.
basicAck
(
envelope
.
getDeliveryTag
(),
false
);
}
}
private
File
[]
jacksonUnmarshalExample
(
String
message
)
throws
IOException
{
File
[]
files
=
new
File
[
2
];
ObjectMapper
mapper
=
new
ObjectMapper
();
Message
request
=
mapper
.
readValue
(
message
,
Message
.
class
);
//We know that in parameters 0-1 we should have files
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
Map
<
String
,
String
>
fileArg
=
(
java
.
util
.
LinkedHashMap
)
request
.
getParameters
().
get
(
i
);
String
fileName
=
fileArg
.
get
(
FileParameter
.
NAME
);
//If not null should be able to use it to download file
String
url
=
fileArg
.
get
(
FileParameter
.
URL
);
if
(
url
!=
null
)
{
//download
}
String
encoding
=
fileArg
.
get
(
FileParameter
.
ENCODING
);
String
value
=
fileArg
.
get
(
FileParameter
.
VALUE
);
try
(
PrintWriter
out
=
new
PrintWriter
(
fileName
))
{
out
.
print
(
value
);
}
files
[
i
]
=
new
File
(
fileName
);
}
return
files
;
}
private
File
[]
simpleJsonUnmarshalExample
(
String
message
)
throws
JSONException
,
FileNotFoundException
{
File
[]
files
=
new
File
[
2
];
JSONObject
jo
=
new
JSONObject
(
message
);
JSONArray
args
=
jo
.
getJSONArray
(
"parameters"
);
//We know that in parameters 0-2 we should have files
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
JSONObject
arg
=
(
JSONObject
)
args
.
get
(
i
);
String
fileName
=
(
String
)
arg
.
get
(
FileParameter
.
NAME
);
//If not null should be able to use it to download file
if
(!
arg
.
isNull
(
"url"
))
{
String
url
=
(
String
)
arg
.
get
(
"url"
);
//download
}
//Otherwise get contents as string
String
value
=
(
String
)
arg
.
get
(
FileParameter
.
VALUE
);
String
encoding
=
(
String
)
arg
.
get
(
FileParameter
.
ENCODING
);
try
(
PrintWriter
out
=
new
PrintWriter
(
fileName
))
{
out
.
print
(
value
);
}
files
[
i
]
=
new
File
(
fileName
);
}
return
files
;
}
private
String
jacksonMarshalExample
(
List
<
File
>
files
)
throws
UnsupportedEncodingException
,
IOException
{
Message
responseMessage
=
new
Message
();
List
parameters
=
new
ArrayList
();
String
charset
=
"UTF-8"
;
for
(
File
f
:
files
)
{
FileParameter
fileParam
=
new
FileParameter
();
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
f
.
getAbsolutePath
()));
fileParam
.
setValue
(
new
String
(
bytes
,
charset
));
fileParam
.
setEncoding
(
charset
);
fileParam
.
setName
(
f
.
getName
());
parameters
.
add
(
fileParam
);
}
responseMessage
.
setParameters
(
parameters
);
responseMessage
.
setCreationDate
(
new
Date
(
System
.
currentTimeMillis
()));
ObjectMapper
mapper
=
new
ObjectMapper
();
return
mapper
.
writeValueAsString
(
responseMessage
);
}
private
String
simpleJsonMarshalExample
(
List
<
File
>
files
)
throws
JSONException
,
IOException
{
JSONObject
jo
=
new
JSONObject
();
jo
.
put
(
"creationDate"
,
new
Date
(
System
.
currentTimeMillis
()));
List
parameters
=
new
ArrayList
();
String
charset
=
"UTF-8"
;
for
(
File
f
:
files
)
{
Map
<
String
,
String
>
fileArguments
=
new
HashMap
<>();
fileArguments
.
put
(
"encoding"
,
charset
);
fileArguments
.
put
(
"name"
,
f
.
getName
());
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
f
.
getAbsolutePath
()));
fileArguments
.
put
(
"value"
,
new
String
(
bytes
,
charset
));
parameters
.
add
(
fileArguments
);
}
jo
.
put
(
"parameters"
,
parameters
);
return
jo
.
toString
();
}
}
drip-planner/src/main/java/nl/uva/sne/drip/drip/planner/Panner.java
→
drip-planner/src/main/java/nl/uva/sne/drip/drip/planner/P
l
anner.java
View file @
a5bb42ce
...
...
@@ -16,24 +16,27 @@
package
nl
.
uva
.
sne
.
drip
.
drip
.
planner
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
/**
*
* @author S. Koulouzis
*/
public
class
Panner
{
public
class
P
l
anner
{
public
void
plan
(
String
input
,
String
example
,
String
outputDirPath
)
{
public
List
<
File
>
plan
(
String
input
,
String
example
,
String
outputDirPath
)
throws
FileNotFoundException
,
IOException
{
// TODO Auto-generated method stub
BufferedReader
in
;
try
{
in
=
new
BufferedReader
(
new
FileReader
(
input
));
String
line
=
null
;
String
line
;
boolean
check
=
false
;
ArrayList
<
String
>
dockerNames
=
new
ArrayList
<>();
while
((
line
=
in
.
readLine
())
!=
null
)
{
...
...
@@ -103,10 +106,11 @@ public class Panner {
outputf
.
write
(
" - topology: "
+
file_guid
+
"\n"
);
outputf
.
write
(
" cloudProvider: EC2\n"
);
outputf
.
close
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
List
<
File
>
outputFiles
=
new
ArrayList
<>();
outputFiles
.
add
(
new
File
(
outfPath
));
outputFiles
.
add
(
new
File
(
allFilePath
));
return
outputFiles
;
}
private
String
generateVM
(
String
block
,
String
nodeName
,
String
dockerName
,
String
privateAddress
,
String
role
)
{
...
...
drip-planner/src/main/java/nl/uva/sne/drip/drip/planner/RPCServer.java
0 → 100644
View file @
a5bb42ce
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
drip
.
planner
;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.Connection
;
import
com.rabbitmq.client.ConnectionFactory
;
import
java.io.IOException
;
import
java.util.concurrent.TimeoutException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
/**
*
* @author S. Koulouzis
*/
public
class
RPCServer
{
private
static
final
String
RPC_QUEUE_NAME
=
"planner_queue"
;
private
static
final
String
HOST
=
"172.17.0.2"
;
public
static
void
main
(
String
[]
argv
)
{
start
();
}
private
static
void
start
()
{
ConnectionFactory
factory
=
new
ConnectionFactory
();
factory
.
setHost
(
HOST
);
try
(
Connection
connection
=
factory
.
newConnection
())
{
Channel
channel
=
connection
.
createChannel
();
channel
.
queueDeclare
(
RPC_QUEUE_NAME
,
false
,
false
,
false
,
null
);
Consumer
c
=
new
Consumer
(
channel
);
channel
.
basicConsume
(
RPC_QUEUE_NAME
,
false
,
c
);
//Block so we don't close the channel
while
(
true
)
{
try
{
Thread
.
sleep
(
100
);
}
catch
(
InterruptedException
_ignore
)
{
}
}
}
catch
(
IOException
|
TimeoutException
ex
)
{
Logger
.
getLogger
(
RPCServer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
}
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