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
bbeff598
Commit
bbeff598
authored
Nov 02, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Experiment with queue logger
parent
f13a9bde
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
2 deletions
+96
-2
__init__.py
drip-api/src/main/java/nl/__init__.py
+0
-0
__init__.py
drip-api/src/main/java/nl/uva/__init__.py
+0
-0
__init__.py
drip-api/src/main/java/nl/uva/sne/__init__.py
+0
-0
__init__.py
drip-api/src/main/java/nl/uva/sne/drip/__init__.py
+0
-0
__init__.py
drip-api/src/main/java/nl/uva/sne/drip/api/__init__.py
+0
-0
DRIPLogger.java
...i/src/main/java/nl/uva/sne/drip/api/event/DRIPLogger.java
+83
-0
PlannerService.java
...main/java/nl/uva/sne/drip/api/service/PlannerService.java
+13
-2
No files found.
drip-api/src/main/java/nl/__init__.py
0 → 100644
View file @
bbeff598
drip-api/src/main/java/nl/uva/__init__.py
0 → 100644
View file @
bbeff598
drip-api/src/main/java/nl/uva/sne/__init__.py
0 → 100644
View file @
bbeff598
drip-api/src/main/java/nl/uva/sne/drip/__init__.py
0 → 100644
View file @
bbeff598
drip-api/src/main/java/nl/uva/sne/drip/api/__init__.py
0 → 100644
View file @
bbeff598
drip-api/src/main/java/nl/uva/sne/drip/api/event/DRIPLogger.java
0 → 100644
View file @
bbeff598
/*
* 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
.
api
.
event
;
import
com.rabbitmq.client.AMQP
;
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.LogRecord
;
import
java.util.logging.Logger
;
import
java.util.logging.StreamHandler
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Service
;
/**
*
* @author S. Koulouzis
*/
public
class
DRIPLogger
extends
StreamHandler
implements
AutoCloseable
{
private
final
Connection
connection
;
private
final
Channel
channel
;
private
static
final
String
EXCHANGE_NAME
=
"direct_logs"
;
public
DRIPLogger
(
String
messageBrokerHost
)
throws
IOException
,
TimeoutException
{
super
();
ConnectionFactory
factory
=
new
ConnectionFactory
();
factory
.
setHost
(
messageBrokerHost
);
factory
.
setPort
(
AMQP
.
PROTOCOL
.
PORT
);
connection
=
factory
.
newConnection
();
channel
=
connection
.
createChannel
();
channel
.
exchangeDeclare
(
EXCHANGE_NAME
,
"direct"
);
}
@Override
public
void
publish
(
LogRecord
record
)
{
try
{
String
level
=
record
.
getLevel
().
getName
();
String
message
=
record
.
getMessage
();
channel
.
basicPublish
(
EXCHANGE_NAME
,
level
,
null
,
message
.
getBytes
(
"UTF-8"
));
super
.
publish
(
record
);
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
DRIPLogger
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
@Override
public
void
close
()
{
if
(
channel
!=
null
&&
channel
.
isOpen
())
{
try
{
channel
.
close
();
}
catch
(
IOException
|
TimeoutException
ex
)
{
Logger
.
getLogger
(
DRIPLogger
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
if
(
connection
!=
null
&&
connection
.
isOpen
())
{
try
{
connection
.
close
();
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
DRIPLogger
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java
View file @
bbeff598
...
@@ -25,7 +25,10 @@ import java.util.List;
...
@@ -25,7 +25,10 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.TimeoutException
;
import
java.util.logging.LogManager
;
import
java.util.logging.Logger
;
import
nl.uva.sne.drip.api.dao.PlanDao
;
import
nl.uva.sne.drip.api.dao.PlanDao
;
import
nl.uva.sne.drip.api.event.DRIPLogger
;
import
nl.uva.sne.drip.api.exception.BadRequestException
;
import
nl.uva.sne.drip.api.exception.BadRequestException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.rpc.PlannerCaller
;
import
nl.uva.sne.drip.api.rpc.PlannerCaller
;
...
@@ -66,12 +69,20 @@ public class PlannerService {
...
@@ -66,12 +69,20 @@ public class PlannerService {
@Value
(
"${message.broker.host}"
)
@Value
(
"${message.broker.host}"
)
private
String
messageBrokerHost
;
private
String
messageBrokerHost
;
private
final
Logger
rootLogger
;
@Autowired
public
PlannerService
()
throws
IOException
,
TimeoutException
{
rootLogger
=
LogManager
.
getLogManager
().
getLogger
(
""
);
rootLogger
.
addHandler
(
new
DRIPLogger
(
messageBrokerHost
));
}
public
PlanResponse
getPlan
(
String
toscaId
)
throws
JSONException
,
UnsupportedEncodingException
,
IOException
,
TimeoutException
,
InterruptedException
{
public
PlanResponse
getPlan
(
String
toscaId
)
throws
JSONException
,
UnsupportedEncodingException
,
IOException
,
TimeoutException
,
InterruptedException
{
try
(
PlannerCaller
planner
=
new
PlannerCaller
(
messageBrokerHost
))
{
try
(
PlannerCaller
planner
=
new
PlannerCaller
(
messageBrokerHost
))
{
Message
plannerInvokationMessage
=
buildPlannerMessage
(
toscaId
);
Message
plannerInvokationMessage
=
buildPlannerMessage
(
toscaId
);
rootLogger
.
info
(
"some message"
);
Message
plannerReturnedMessage
=
(
planner
.
call
(
plannerInvokationMessage
));
Message
plannerReturnedMessage
=
(
planner
.
call
(
plannerInvokationMessage
));
// Message plannerReturnedMessage = (planner.generateFakeResponse(plannerInvokationMessage));
ObjectMapper
mapper
=
new
ObjectMapper
();
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
JsonParser
.
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
mapper
.
configure
(
JsonParser
.
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
List
<
MessageParameter
>
messageParams
=
plannerReturnedMessage
.
getParameters
();
List
<
MessageParameter
>
messageParams
=
plannerReturnedMessage
.
getParameters
();
...
...
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