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
e3bfff6f
Commit
e3bfff6f
authored
Jun 15, 2018
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try to add streaming for logs
parent
49776fb6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
136 additions
and
17 deletions
+136
-17
pom.xml
drip-api/pom.xml
+2
-2
AsyncConfig.java
...i/src/main/java/nl/uva/sne/drip/api/conf/AsyncConfig.java
+43
-0
WebAppInitializer.java
...main/java/nl/uva/sne/drip/api/conf/WebAppInitializer.java
+6
-3
DRIPLogService.java
...main/java/nl/uva/sne/drip/api/service/DRIPLogService.java
+9
-4
DeployService.java
.../main/java/nl/uva/sne/drip/api/service/DeployService.java
+0
-2
CloudCredentialsController.java
.../uva/sne/drip/api/v1/rest/CloudCredentialsController.java
+13
-5
LogController.java
.../main/java/nl/uva/sne/drip/api/v1/rest/LogController.java
+63
-1
No files found.
drip-api/pom.xml
View file @
e3bfff6f
...
@@ -169,8 +169,8 @@
...
@@ -169,8 +169,8 @@
<artifactId>
maven-compiler-plugin
</artifactId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
2.3.2
</version>
<version>
2.3.2
</version>
<configuration>
<configuration>
<source>
1.
7
</source>
<source>
1.
8
</source>
<target>
1.
7
</target>
<target>
1.
8
</target>
<compilerArguments>
<compilerArguments>
<endorseddirs>
${endorsed.dir}
</endorseddirs>
<endorseddirs>
${endorsed.dir}
</endorseddirs>
</compilerArguments>
</compilerArguments>
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/conf/AsyncConfig.java
0 → 100644
View file @
e3bfff6f
/*
* 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
.
api
.
conf
;
import
java.util.concurrent.Executor
;
import
org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler
;
import
org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler
;
import
org.springframework.boot.context.embedded.ServletRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.AsyncConfigurer
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
;
/**
*
* @author S. Koulouzis
*/
@Configuration
@EnableScheduling
@EnableAsync
@ComponentScan
(
"nl.uva.sne.drip"
)
public
class
AsyncConfig
implements
AsyncConfigurer
{
@Override
public
Executor
getAsyncExecutor
()
{
ThreadPoolTaskScheduler
scheduler
=
new
ThreadPoolTaskScheduler
();
scheduler
.
setPoolSize
(
5
);
scheduler
.
initialize
();
return
scheduler
;
}
@Override
public
AsyncUncaughtExceptionHandler
getAsyncUncaughtExceptionHandler
()
{
return
new
SimpleAsyncUncaughtExceptionHandler
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/conf/WebAppInitializer.java
View file @
e3bfff6f
...
@@ -28,12 +28,15 @@ public class WebAppInitializer implements WebApplicationInitializer {
...
@@ -28,12 +28,15 @@ public class WebAppInitializer implements WebApplicationInitializer {
ctx
.
register
(
MultipartConfig
.
class
);
ctx
.
register
(
MultipartConfig
.
class
);
ctx
.
register
(
MongoConfig
.
class
);
ctx
.
register
(
MongoConfig
.
class
);
ctx
.
register
(
SecurityConfig
.
class
);
ctx
.
register
(
SecurityConfig
.
class
);
// ctx.register(MethodSecurity
Config.class);
ctx
.
register
(
Async
Config
.
class
);
// ctx.register(MethodSecurityConfig.class);
ctx
.
setServletContext
(
servletContext
);
ctx
.
setServletContext
(
servletContext
);
DispatcherServlet
dispatcher
=
new
DispatcherServlet
(
ctx
);
Dynamic
dynamic
=
servletContext
.
addServlet
(
"dispatcher"
,
new
DispatcherServlet
(
ctx
)
);
Dynamic
dynamic
=
servletContext
.
addServlet
(
"dispatcher"
,
dispatcher
);
dynamic
.
addMapping
(
"/"
);
dynamic
.
addMapping
(
"/"
);
dynamic
.
setLoadOnStartup
(
1
);
dynamic
.
setLoadOnStartup
(
1
);
dynamic
.
setAsyncSupported
(
true
);
}
}
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/DRIPLogService.java
View file @
e3bfff6f
...
@@ -23,6 +23,8 @@ import com.rabbitmq.client.Connection;
...
@@ -23,6 +23,8 @@ import com.rabbitmq.client.Connection;
import
com.rabbitmq.client.ConnectionFactory
;
import
com.rabbitmq.client.ConnectionFactory
;
import
com.rabbitmq.client.GetResponse
;
import
com.rabbitmq.client.GetResponse
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.TimeoutException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
...
@@ -47,8 +49,9 @@ public class DRIPLogService {
...
@@ -47,8 +49,9 @@ public class DRIPLogService {
private
ObjectMapper
mapper
;
private
ObjectMapper
mapper
;
private
ConnectionFactory
factory
;
private
ConnectionFactory
factory
;
public
DRIPLogRecord
get
()
throws
IOException
,
TimeoutException
{
public
List
<
DRIPLogRecord
>
get
()
throws
IOException
,
TimeoutException
{
Channel
channel
=
null
;
Channel
channel
=
null
;
if
(
factory
==
null
)
{
if
(
factory
==
null
)
{
this
.
factory
=
new
ConnectionFactory
();
this
.
factory
=
new
ConnectionFactory
();
factory
.
setHost
(
messageBrokerHost
);
factory
.
setHost
(
messageBrokerHost
);
...
@@ -68,13 +71,15 @@ public class DRIPLogService {
...
@@ -68,13 +71,15 @@ public class DRIPLogService {
channel
.
queueDeclare
(
qeueNameUser
,
true
,
false
,
false
,
null
);
channel
.
queueDeclare
(
qeueNameUser
,
true
,
false
,
false
,
null
);
GetResponse
response
=
channel
.
basicGet
(
qeueNameUser
,
true
);
GetResponse
response
=
channel
.
basicGet
(
qeueNameUser
,
true
);
if
(
response
!=
null
)
{
List
<
DRIPLogRecord
>
logs
=
new
ArrayList
<>();
while
(
response
!=
null
)
{
String
message
=
new
String
(
response
.
getBody
(),
"UTF-8"
);
String
message
=
new
String
(
response
.
getBody
(),
"UTF-8"
);
return
mapper
.
readValue
(
message
,
DRIPLogRecord
.
class
);
response
=
channel
.
basicGet
(
qeueNameUser
,
true
);
logs
.
add
(
mapper
.
readValue
(
message
,
DRIPLogRecord
.
class
));
}
}
return
logs
;
}
}
return
null
;
}
}
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/DeployService.java
View file @
e3bfff6f
...
@@ -54,13 +54,11 @@ import nl.uva.sne.drip.commons.utils.Converter;
...
@@ -54,13 +54,11 @@ import nl.uva.sne.drip.commons.utils.Converter;
import
nl.uva.sne.drip.commons.utils.DRIPLogHandler
;
import
nl.uva.sne.drip.commons.utils.DRIPLogHandler
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ConfigurationRepresentation
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ConfigurationRepresentation
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.KeyValueHolder
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.ansible.SysbenchCPUBenchmark
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/CloudCredentialsController.java
View file @
e3bfff6f
...
@@ -79,8 +79,10 @@ public class CloudCredentialsController {
...
@@ -79,8 +79,10 @@ public class CloudCredentialsController {
@RequestMapping
(
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
APPLICATION_JSON
)
@RequestMapping
(
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
APPLICATION_JSON
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@StatusCodes
({
@StatusCodes
({
@ResponseCode
(
code
=
404
,
condition
=
"Key can't be empty"
),
@ResponseCode
(
code
=
404
,
condition
=
"Key can't be empty"
)
@ResponseCode
(
code
=
404
,
condition
=
"Cloud provider's name can't be empty"
),
,
@ResponseCode
(
code
=
404
,
condition
=
"Cloud provider's name can't be empty"
)
,
@ResponseCode
(
code
=
200
,
condition
=
"At least one key ID is posted"
)
@ResponseCode
(
code
=
200
,
condition
=
"At least one key ID is posted"
)
})
})
public
@ResponseBody
public
@ResponseBody
...
@@ -107,8 +109,10 @@ public class CloudCredentialsController {
...
@@ -107,8 +109,10 @@ public class CloudCredentialsController {
@RequestMapping
(
value
=
"/upload/{id}"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/upload/{id}"
,
method
=
RequestMethod
.
POST
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@StatusCodes
({
@StatusCodes
({
@ResponseCode
(
code
=
404
,
condition
=
"Credential not found"
),
@ResponseCode
(
code
=
404
,
condition
=
"Credential not found"
)
@ResponseCode
(
code
=
400
,
condition
=
"Did not upload file"
),
,
@ResponseCode
(
code
=
400
,
condition
=
"Did not upload file"
)
,
@ResponseCode
(
code
=
200
,
condition
=
"Key added to credential"
)
@ResponseCode
(
code
=
200
,
condition
=
"Key added to credential"
)
})
})
public
@ResponseBody
public
@ResponseBody
...
@@ -139,6 +143,9 @@ public class CloudCredentialsController {
...
@@ -139,6 +143,9 @@ public class CloudCredentialsController {
pair
=
keyService
.
save
(
pair
);
pair
=
keyService
.
save
(
pair
);
// loginKeyIDs.add(pair.getId());
// loginKeyIDs.add(pair.getId());
}
}
if
(
cloudCredentials
.
getCloudProviderName
().
toLowerCase
().
equals
(
"egi"
))
{
cloudCredentials
.
setSecretKey
(
new
String
(
bytes
,
"UTF-8"
));
}
// cloudCredentials.setKeyIDs(loginKeyIDs);
// cloudCredentials.setKeyIDs(loginKeyIDs);
cloudCredentials
=
cloudCredentialsService
.
save
(
cloudCredentials
);
cloudCredentials
=
cloudCredentialsService
.
save
(
cloudCredentials
);
return
cloudCredentials
.
getId
();
return
cloudCredentials
.
getId
();
...
@@ -157,7 +164,8 @@ public class CloudCredentialsController {
...
@@ -157,7 +164,8 @@ public class CloudCredentialsController {
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@StatusCodes
({
@StatusCodes
({
@ResponseCode
(
code
=
404
,
condition
=
"Credential not found"
),
@ResponseCode
(
code
=
404
,
condition
=
"Credential not found"
)
,
@ResponseCode
(
code
=
200
,
condition
=
"Credential exists"
)
@ResponseCode
(
code
=
200
,
condition
=
"Credential exists"
)
})
})
public
@ResponseBody
public
@ResponseBody
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/LogController.java
View file @
e3bfff6f
...
@@ -15,9 +15,14 @@
...
@@ -15,9 +15,14 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
v1
.
rest
;
package
nl
.
uva
.
sne
.
drip
.
api
.
v1
.
rest
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.webcohesion.enunciate.metadata.rs.ResponseCode
;
import
com.webcohesion.enunciate.metadata.rs.ResponseCode
;
import
com.webcohesion.enunciate.metadata.rs.StatusCodes
;
import
com.webcohesion.enunciate.metadata.rs.StatusCodes
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.List
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.TimeoutException
;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
...
@@ -31,6 +36,9 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -31,6 +36,9 @@ import org.springframework.web.bind.annotation.RestController;
import
nl.uva.sne.drip.api.service.DRIPLogService
;
import
nl.uva.sne.drip.api.service.DRIPLogService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.DRIPLogRecord
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.DRIPLogRecord
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter
;
import
org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody
;
/**
/**
* This controller is responsible for storing TOSCA descriptions that can be
* This controller is responsible for storing TOSCA descriptions that can be
...
@@ -52,7 +60,7 @@ public class LogController {
...
@@ -52,7 +60,7 @@ public class LogController {
@RequestMapping
(
method
=
RequestMethod
.
GET
)
@RequestMapping
(
method
=
RequestMethod
.
GET
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
public
@ResponseBody
DRIPLogRecord
get
()
{
List
<
DRIPLogRecord
>
get
()
{
try
{
try
{
return
logService
.
get
();
return
logService
.
get
();
}
catch
(
IOException
|
TimeoutException
ex
)
{
}
catch
(
IOException
|
TimeoutException
ex
)
{
...
@@ -61,4 +69,58 @@ public class LogController {
...
@@ -61,4 +69,58 @@ public class LogController {
return
null
;
return
null
;
}
}
// @RequestMapping(method = RequestMethod.GET, value = "/ll")
// @RolesAllowed({UserService.USER, UserService.ADMIN})
// public @ResponseBody
// ResponseBodyEmitter streamLogs() {
//
// final ResponseBodyEmitter emitter = new ResponseBodyEmitter();
// ExecutorService service = Executors.newSingleThreadExecutor();
// service.execute(new Runnable() {
// @Override
// public void run() {
// int i = 0;
// while (true) {
// try {
// i++;
// emitter.send(i + " - ", MediaType.TEXT_PLAIN);
// Thread.sleep(10);
// } catch (InterruptedException | IOException ex) {
// Logger.getLogger(LogController.class.getName()).log(Level.SEVERE, null, ex);
// emitter.completeWithError(ex);
// }
//
// }
//// emitter.complete();
// }
// });
//
// return emitter;
// }
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/ll"
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
StreamingResponseBody
streamLogs
()
{
return
new
StreamingResponseBody
()
{
@Override
public
void
writeTo
(
OutputStream
out
)
throws
IOException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
while
(
true
)
{
try
{
List
<
DRIPLogRecord
>
logs
=
logService
.
get
();
for
(
DRIPLogRecord
log
:
logs
)
{
out
.
write
(
mapper
.
writeValueAsBytes
(
log
));
out
.
write
(
"\n"
.
getBytes
());
Thread
.
sleep
(
10
);
}
Thread
.
sleep
(
2000
);
}
catch
(
InterruptedException
|
TimeoutException
ex
)
{
Logger
.
getLogger
(
LogController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
finally
{
out
.
flush
();
}
}
}
};
}
}
}
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