Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
Data Flow
Data Enrichment
wks
Commits
62d4df65
Commit
62d4df65
authored
Feb 16, 2021
by
SGupta79
Browse files
SLI logs implementation
parent
60ce9f1f
Pipeline
#26807
passed with stages
in 19 minutes and 31 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
provider/wks-azure/src/main/java/org/opengroup/osdu/wks/provider/azure/pubsub/ProcessWKSTransform.java
View file @
62d4df65
package
org.opengroup.osdu.wks.provider.azure.pubsub
;
package
org.opengroup.osdu.wks.provider.azure.pubsub
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonParser
;
import
com.google.gson.JsonSyntaxException
;
import
com.microsoft.azure.servicebus.IMessage
;
import
org.opengroup.osdu.core.common.model.http.DpsHeaders
;
import
org.opengroup.osdu.wks.config.ThreadScopeContextHolder
;
import
org.opengroup.osdu.wks.exceptions.ApplicationException
;
import
org.opengroup.osdu.wks.exceptions.BadRequestException
;
import
org.opengroup.osdu.wks.logging.SliLogger
;
import
org.opengroup.osdu.wks.logging.SliLoggerPayload
;
import
org.opengroup.osdu.wks.model.RawRecordDetails
;
import
org.opengroup.osdu.wks.provider.azure.config.ThreadDpsHeaders
;
import
org.opengroup.osdu.wks.provider.azure.utils.MDCContextMap
;
...
...
@@ -37,7 +40,14 @@ public class ProcessWKSTransform {
@Autowired
private
ThreadDpsHeaders
dpsHeaders
;
@Autowired
private
SliLogger
sliLogger
;
public
void
initiateWksTransformation
(
IMessage
message
)
{
String
dataPartitionId
=
null
;
String
correlationId
=
null
;
try
{
String
messageBody
=
new
String
(
message
.
getMessageBody
().
getBinaryData
().
get
(
0
),
UTF_8
);
...
...
@@ -47,8 +57,8 @@ public class ProcessWKSTransform {
String
messageId
=
jsonRoot
.
getAsJsonObject
().
get
(
ID
).
getAsString
();
message
.
setMessageId
(
messageId
);
String
dataPartitionId
=
messageData
.
getAsJsonObject
().
get
(
DpsHeaders
.
DATA_PARTITION_ID
).
getAsString
();
String
correlationId
=
messageData
.
getAsJsonObject
().
get
(
DpsHeaders
.
CORRELATION_ID
).
getAsString
();
dataPartitionId
=
messageData
.
getAsJsonObject
().
get
(
DpsHeaders
.
DATA_PARTITION_ID
).
getAsString
();
correlationId
=
messageData
.
getAsJsonObject
().
get
(
DpsHeaders
.
CORRELATION_ID
).
getAsString
();
MDC
.
setContextMap
(
mdcContextMap
.
getContextMap
(
correlationId
,
dataPartitionId
));
dpsHeaders
.
setThreadContext
(
dataPartitionId
,
correlationId
);
...
...
@@ -65,14 +75,36 @@ public class ProcessWKSTransform {
}
catch
(
BadRequestException
e
)
{
LOGGER
.
error
(
"Bad Request Reason: {}, pubsub message id: {}"
,
e
.
getErrorMsg
(),
message
.
getMessageId
(),
e
);
sliLogger
.
writeLog
(
SliLoggerPayload
.
builder
().
status
(
false
).
recordId
(
message
.
getMessageId
())
.
correlationId
(
correlationId
).
dataPartitionId
(
dataPartitionId
)
.
statusCode
(
HttpStatus
.
BAD_REQUEST
.
value
()).
build
());
}
catch
(
ApplicationException
e
)
{
LOGGER
.
error
(
"Application Error Reason: {}, pubsub message id: {}"
,
e
.
getErrorMsg
(),
message
.
getMessageId
(),
e
);
sliLogger
.
writeLog
(
SliLoggerPayload
.
builder
().
status
(
false
).
recordId
(
message
.
getMessageId
())
.
correlationId
(
correlationId
).
dataPartitionId
(
dataPartitionId
)
.
statusCode
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
()).
build
());
}
catch
(
NullPointerException
e
)
{
LOGGER
.
error
(
"Invalid format for message with id: {}"
,
message
.
getMessageId
(),
e
);
LOGGER
.
error
(
"Invalid format for message with id: {}"
,
message
.
getMessageId
(),
e
);
sliLogger
.
writeLog
(
SliLoggerPayload
.
builder
().
status
(
false
).
recordId
(
message
.
getMessageId
())
.
correlationId
(
correlationId
).
dataPartitionId
(
dataPartitionId
)
.
statusCode
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
()).
build
());
}
catch
(
JsonSyntaxException
e
)
{
LOGGER
.
error
(
"Error occurred in payload parsing with id: {}"
,
message
.
getMessageId
(),
e
);
sliLogger
.
writeLog
(
SliLoggerPayload
.
builder
().
status
(
false
).
recordId
(
message
.
getMessageId
())
.
correlationId
(
correlationId
).
dataPartitionId
(
dataPartitionId
)
.
statusCode
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
()).
build
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Exception encountered processing the message with id: {}"
,
message
.
getMessageId
(),
e
);
sliLogger
.
writeLog
(
SliLoggerPayload
.
builder
().
status
(
false
).
recordId
(
message
.
getMessageId
())
.
correlationId
(
correlationId
).
dataPartitionId
(
dataPartitionId
)
.
statusCode
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
()).
build
());
}
ThreadScopeContextHolder
.
getContext
().
clear
();
...
...
provider/wks-azure/src/test/java/org/opengroup/osdu/wks/provider/azure/pubsub/ProcessWKSTransformTest.java
View file @
62d4df65
...
...
@@ -25,6 +25,7 @@ import org.mockito.Spy;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.opengroup.osdu.wks.exceptions.ApplicationException
;
import
org.opengroup.osdu.wks.exceptions.BadRequestException
;
import
org.opengroup.osdu.wks.logging.SliLogger
;
import
org.opengroup.osdu.wks.model.RawRecordDetails
;
import
org.opengroup.osdu.wks.provider.azure.config.ThreadDpsHeaders
;
import
org.opengroup.osdu.wks.provider.azure.utils.MDCContextMap
;
...
...
@@ -66,6 +67,10 @@ public class ProcessWKSTransformTest {
@Spy
private
ThreadDpsHeaders
dpsHeaders
;
@Mock
private
SliLogger
sliLogger
;
@BeforeEach
public
void
init
()
{
lenient
().
when
(
message
.
getMessageId
()).
thenReturn
(
messageId
);
...
...
@@ -80,7 +85,7 @@ public class ProcessWKSTransformTest {
processWKSTransform
.
initiateWksTransformation
(
message
);
verify
(
message
,
times
(
1
)).
getMessageBody
();
verify
(
message
,
times
(
1
)).
getMessageId
();
verify
(
message
,
times
(
3
)).
getMessageId
();
}
@Test
...
...
@@ -92,7 +97,7 @@ public class ProcessWKSTransformTest {
verify
(
mdcContextMap
,
times
(
1
)).
getContextMap
(
correlationId
,
dataPartitionId
);
verify
(
message
,
times
(
1
)).
getMessageBody
();
verify
(
message
,
times
(
1
)).
getMessageId
();
verify
(
message
,
times
(
2
)).
getMessageId
();
verify
(
message
,
times
(
1
)).
setMessageId
(
messageId
);
}
...
...
@@ -107,7 +112,7 @@ public class ProcessWKSTransformTest {
verify
(
mdcContextMap
,
times
(
1
)).
getContextMap
(
correlationId
,
dataPartitionId
);
verify
(
message
,
times
(
1
)).
getMessageBody
();
verify
(
message
,
times
(
2
)).
getMessageId
();
verify
(
message
,
times
(
3
)).
getMessageId
();
verify
(
message
,
times
(
1
)).
setMessageId
(
messageId
);
}
...
...
wks-core/src/main/java/org/opengroup/osdu/wks/logging/SliLogger.java
0 → 100644
View file @
62d4df65
package
org.opengroup.osdu.wks.logging
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.opengroup.osdu.core.common.logging.DefaultLogger
;
import
org.opengroup.osdu.core.common.model.http.DpsHeaders
;
import
org.springframework.stereotype.Component
;
import
lombok.RequiredArgsConstructor
;
@Component
@RequiredArgsConstructor
public
class
SliLogger
{
private
final
DefaultLogger
logger
;
public
void
writeLog
(
SliLoggerPayload
payload
)
{
this
.
logger
.
info
(
"sli.log"
,
getSliLog
(
payload
),
getHeader
(
payload
));
}
private
String
getSliLog
(
SliLoggerPayload
payload
)
{
Map
<
String
,
Object
>
jsonPayload
=
createSliPayload
(
payload
);
return
String
.
format
(
"%s: "
,
jsonPayload
.
toString
());
}
private
Map
<
String
,
String
>
getHeader
(
SliLoggerPayload
payload
)
{
Map
<
String
,
String
>
jsonPayload
=
new
HashMap
<>();
jsonPayload
.
put
(
DpsHeaders
.
DATA_PARTITION_ID
,
payload
.
getDataPartitionId
());
jsonPayload
.
put
(
DpsHeaders
.
CORRELATION_ID
,
payload
.
getCorrelationId
());
return
jsonPayload
;
}
private
Map
<
String
,
Object
>
createSliPayload
(
SliLoggerPayload
payload
)
{
Map
<
String
,
Object
>
jsonPayload
=
new
HashMap
<>();
jsonPayload
.
put
(
"status"
,
payload
.
getStatus
());
jsonPayload
.
put
(
"statusCode"
,
payload
.
getStatusCode
());
jsonPayload
.
put
(
"id"
,
payload
.
getRecordId
());
jsonPayload
.
put
(
DpsHeaders
.
DATA_PARTITION_ID
,
payload
.
getDataPartitionId
());
jsonPayload
.
put
(
DpsHeaders
.
CORRELATION_ID
,
payload
.
getCorrelationId
());
return
jsonPayload
;
}
}
wks-core/src/main/java/org/opengroup/osdu/wks/logging/SliLoggerPayload.java
0 → 100644
View file @
62d4df65
package
org.opengroup.osdu.wks.logging
;
import
lombok.Builder
;
import
lombok.Data
;
@Data
@Builder
public
class
SliLoggerPayload
{
private
String
recordId
;
private
int
statusCode
;
private
Boolean
status
;
private
String
dataPartitionId
;
private
String
correlationId
;
}
wks-core/src/main/java/org/opengroup/osdu/wks/service/WKSServiceImpl.java
View file @
62d4df65
...
...
@@ -14,6 +14,8 @@ import org.opengroup.osdu.wks.config.ThreadScopeContextHolder;
import
org.opengroup.osdu.wks.constants.Constants
;
import
org.opengroup.osdu.wks.exceptions.ApplicationException
;
import
org.opengroup.osdu.wks.exceptions.BadRequestException
;
import
org.opengroup.osdu.wks.logging.SliLogger
;
import
org.opengroup.osdu.wks.logging.SliLoggerPayload
;
import
org.opengroup.osdu.wks.model.MappingsModel
;
import
org.opengroup.osdu.wks.model.RawRecordDetails
;
import
org.opengroup.osdu.wks.model.RelationshipStatus
;
...
...
@@ -25,6 +27,7 @@ import org.opengroup.osdu.wks.util.WksTransformator;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Service
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
...
...
@@ -62,6 +65,10 @@ public class WKSServiceImpl implements WKSService {
@Autowired
private
SchemaService
schemaService
;
@Autowired
private
SliLogger
sliLogger
;
/**
* This method applies the WKS transformation on the valid raw records
*
...
...
@@ -145,15 +152,27 @@ public class WKSServiceImpl implements WKSService {
LOGGER
.
info
(
Constants
.
TRANFORMATION_SUCCESSFUL
,
rawRecord
.
getId
(),
wksRecordTree
.
get
(
ID
).
asString
(),
wksRecordTree
.
get
(
KIND
));
sliLogger
.
writeLog
(
SliLoggerPayload
.
builder
().
status
(
true
).
recordId
(
rawRecord
.
getId
())
.
correlationId
(
correlationId
).
dataPartitionId
(
dataPartitionId
)
.
statusCode
(
HttpStatus
.
OK
.
value
()).
build
());
}
catch
(
ApplicationException
e
)
{
LOGGER
.
warn
(
Constants
.
TRANSFORMATION_FAILED_FOR_GIVEN_WKS_KIND
,
rawRecord
.
getId
(),
mappings
.
getTargetSchemaKind
(),
e
.
getErrorMsg
(),
e
);
sliLogger
.
writeLog
(
SliLoggerPayload
.
builder
().
status
(
false
).
recordId
(
rawRecord
.
getId
())
.
correlationId
(
correlationId
).
dataPartitionId
(
dataPartitionId
)
.
statusCode
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
()).
build
());
}
}
}
catch
(
ApplicationException
e
)
{
LOGGER
.
warn
(
Constants
.
TRANFORMATION_FAILED
,
rawRecord
.
getId
(),
e
.
getErrorMsg
(),
e
);
sliLogger
.
writeLog
(
SliLoggerPayload
.
builder
().
status
(
false
).
recordId
(
rawRecord
.
getId
())
.
correlationId
(
correlationId
).
dataPartitionId
(
dataPartitionId
)
.
statusCode
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
()).
build
());
}
}
...
...
wks-core/src/test/java/org/opengroup/osdu/wks/service/WKSServiceImplTest.java
View file @
62d4df65
...
...
@@ -23,6 +23,7 @@ import org.opengroup.osdu.wks.config.RequestIdentity;
import
org.opengroup.osdu.wks.constants.Constants
;
import
org.opengroup.osdu.wks.exceptions.ApplicationException
;
import
org.opengroup.osdu.wks.exceptions.BadRequestException
;
import
org.opengroup.osdu.wks.logging.SliLogger
;
import
org.opengroup.osdu.wks.model.AttributeMappingModel
;
import
org.opengroup.osdu.wks.model.MappingsModel
;
import
org.opengroup.osdu.wks.model.RawRecordDetails
;
...
...
@@ -79,6 +80,9 @@ public class WKSServiceImplTest {
@InjectMocks
private
WKSServiceImpl
wksService
;
@Mock
private
SliLogger
sliLogger
;
@Rule
public
ExpectedException
expectedException
=
ExpectedException
.
none
();
...
...
Write
Preview
Supports
Markdown
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