Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Register
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSDU
OSDU Data Platform
System
Register
Commits
8515852e
Commit
8515852e
authored
4 years ago
by
harshit aggarwal
Browse files
Options
Downloads
Patches
Plain Diff
Adding javaDoc
parent
636024a0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!16
Adding logic to handle failure scenario during Create Subscription
Pipeline
#6569
failed
4 years ago
Stage: review
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
provider/register-azure/pom.xml
+1
-1
1 addition, 1 deletion
provider/register-azure/pom.xml
provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/subscriber/SubscriptionRepository.java
+40
-11
40 additions, 11 deletions
...ter/provider/azure/subscriber/SubscriptionRepository.java
with
41 additions
and
12 deletions
provider/register-azure/pom.xml
+
1
−
1
View file @
8515852e
...
@@ -90,7 +90,7 @@
...
@@ -90,7 +90,7 @@
<dependency>
<dependency>
<groupId>
org.opengroup.osdu
</groupId>
<groupId>
org.opengroup.osdu
</groupId>
<artifactId>
core-lib-azure
</artifactId>
<artifactId>
core-lib-azure
</artifactId>
<version>
0.0.1
8
</version>
<version>
0.0.
2
1
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.opengroup.osdu
</groupId>
<groupId>
org.opengroup.osdu
</groupId>
...
...
This diff is collapsed.
Click to expand it.
provider/register-azure/src/main/java/org/opengroup/osdu/register/provider/azure/subscriber/SubscriptionRepository.java
+
40
−
11
View file @
8515852e
...
@@ -64,6 +64,32 @@ public class SubscriptionRepository implements ISubscriptionRepository {
...
@@ -64,6 +64,32 @@ public class SubscriptionRepository implements ISubscriptionRepository {
@Autowired
@Autowired
private
PushSubscription
pushSubscription
;
private
PushSubscription
pushSubscription
;
/**
* @param input Subscription Object
* @return Subscription Object
*
* This method creates a Record for the subscription in CosmosDb along
* with a Push Subscription in Event Grid.
*
* Expected Flow -> Create a record in Cosmos Db along with a Push Subscription in Event Grid
* Possible Failures ->
* 1) Creating PushSubscription in Event Grid
* How it is handled -> Delete the record in Cosmos Db as well
* Possible Issue -> What happens if this delete operation on Cosmos Db fails?
* Users won't be able to create a subscription again with same Topic and
* push endpoint combination since system will generate 409 on next retry
* because of presence of record with same Id in Cosmos Db
*
* How to resolve this?
* createPushSubscriptionIfDoesNotExist method takes care of that
* When Cosmos Db throws 409 while creating a new record we can check if a Push Subscription
* for that Record already exists in Event Grid or not.
* If present -> Return 409
* If not present -> We can try creating the Push Subscription again in Event Grid
* Also we will update the record in Cosmos Db in case other fields might
* be different like description etc.
*
*/
@Override
@Override
public
Subscription
create
(
Subscription
input
)
{
public
Subscription
create
(
Subscription
input
)
{
...
@@ -78,11 +104,11 @@ public class SubscriptionRepository implements ISubscriptionRepository {
...
@@ -78,11 +104,11 @@ public class SubscriptionRepository implements ISubscriptionRepository {
}
}
catch
(
AppException
e
)
{
catch
(
AppException
e
)
{
if
(
e
.
getError
().
getCode
()
==
409
)
{
if
(
e
.
getError
().
getCode
()
==
409
)
{
// This
case will
handle the scenario where creating PushSubscription in EventGrid failed
// This
flow is added to
handle the scenario where creating PushSubscription in EventGrid failed
//
but we failed to
delet
e
the corresponding record from Cosmos Db
. Since the operation
//
and
delet
ing
the corresponding record from Cosmos Db
was also unsuccessful.
//
failed last time throwing 500,
user should be able to create the subscription with
//
This will result in an 500 Exception so the
user should be able to create the subscription with
// the same topic and pushEndpoint combination
.
// the same topic and pushEndpoint combination
again
SubscriptionDoc
output
=
c
heckIf
PushSubscriptionExist
s
(
doc
);
SubscriptionDoc
output
=
c
reate
PushSubscription
IfDoesNot
Exist
(
doc
);
input
.
setNotificationId
(
output
.
getNotificationId
());
input
.
setNotificationId
(
output
.
getNotificationId
());
return
input
;
return
input
;
}
}
...
@@ -136,6 +162,12 @@ public class SubscriptionRepository implements ISubscriptionRepository {
...
@@ -136,6 +162,12 @@ public class SubscriptionRepository implements ISubscriptionRepository {
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
}
}
/**
* @param id Identifier for the subscription
* @return true if subscription successfully deleted
* false if subscription not found
* Exception thrown -> AppException with Status Codes 409 and 500
*/
@Override
@Override
public
boolean
delete
(
String
id
)
{
public
boolean
delete
(
String
id
)
{
...
@@ -195,17 +227,14 @@ public class SubscriptionRepository implements ISubscriptionRepository {
...
@@ -195,17 +227,14 @@ public class SubscriptionRepository implements ISubscriptionRepository {
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
}
}
private
SubscriptionDoc
c
heckIf
PushSubscriptionExist
s
(
SubscriptionDoc
input
)
{
private
SubscriptionDoc
c
reate
PushSubscription
IfDoesNot
Exist
(
SubscriptionDoc
input
)
{
try
{
try
{
// We are fetching the record from cosmos db again because we want to use the original
// We are fetching the record from cosmos db again because we want to use the original
// notification-id to create the Push Subscription
// notification-id to create the Push Subscription
Optional
<
SubscriptionDoc
>
originalDoc
=
cosmosStore
.
findItem
(
dpsHeaders
.
getPartitionId
(),
azureBootstrapConfig
.
getCosmosDBName
(),
cosmosContainerConfig
.
getSubscriptionContainerName
(),
input
.
getId
(),
dpsHeaders
.
getPartitionId
(),
SubscriptionDoc
.
class
);
Optional
<
SubscriptionDoc
>
originalDoc
=
cosmosStore
.
findItem
(
dpsHeaders
.
getPartitionId
(),
azureBootstrapConfig
.
getCosmosDBName
(),
cosmosContainerConfig
.
getSubscriptionContainerName
(),
input
.
getId
(),
dpsHeaders
.
getPartitionId
(),
SubscriptionDoc
.
class
);
if
(!
originalDoc
.
isPresent
())
{
originalDoc
.
ifPresent
(
subscriptionDoc
->
input
.
setNotificationId
(
subscriptionDoc
.
getNotificationId
()));
throw
new
AppException
(
500
,
"Server Error"
,
"Unexpected error creating subscription"
);
}
input
.
setNotificationId
(
originalDoc
.
get
().
getNotificationId
());
// We will check if Push Subscription does not exist we should try creating it again since
// We will check if Push Subscription does not exist
then
we should try creating it again since
// the corresponding record in the Cosmos Db is already present
// the corresponding record in the Cosmos Db is already present
pushSubscription
.
getPushSubscription
(
input
.
getNotificationId
(),
input
.
getTopic
());
pushSubscription
.
getPushSubscription
(
input
.
getNotificationId
(),
input
.
getTopic
());
logger
.
error
(
"A subscriber already exists with the same topic and endpoint combination"
);
logger
.
error
(
"A subscriber already exists with the same topic and endpoint combination"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment