-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OBSOLETE] Added API handler functions (scan and get) for LRO #15408
Conversation
adrikagupta
commented
Nov 7, 2023
- Added scanOperations and getOperationRun API handler functions in OperationHttpHandler.java
- Added getOperationRun() in OperationLifecycleManager.java
- Added unit tests in the OperationLifecycleManagerTest.java
- Manual testing for OperationHttpHandler is in progress
.vscode/launch.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add .vscode to local gitignore so that this files are not committed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Done
responder, | ||
OPERATIONS_LIST_PAGINATED_KEY, | ||
jsonListResponder -> { | ||
AtomicReference<OperationRun> lastRun = new AtomicReference<>(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to pass null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if (filter != null && !filter.isEmpty()) { | ||
OperationType operationType = null; | ||
OperationRunStatus operationStatus = null; | ||
Pattern typePattern = Pattern.compile("type=(\\w+)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please convert this to a function which parses pattern of key=val(ANDkey=val)* then returns the key,val pairs. Then we can match the key to type/status using switch case. if there is a unknown key we throw exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Done
operationType = OperationType.valueOf(typeStr.toUpperCase()); | ||
} | ||
while (statusMatcher.find()) { | ||
String statusStr = statusMatcher.group(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw error if not valid OperationStatus/OperationType
return builder.build(); | ||
} | ||
|
||
private void validateNamespace(@Nullable String namespaceId) throws BadRequestException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move after public methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/** | ||
* Service that manages lifecycle of Operation. | ||
*/ | ||
/** Service that manages lifecycle of Operation. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove all formatting changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
public class OperationLifecycleManager { | ||
|
||
private final TransactionRunner transactionRunner; | ||
private static final AtomicInteger sourceId = new AtomicInteger(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this are added ? this are not being used anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad. That time I was trying to do manual testing but forgot to remove it later. I'll double check before pushing the changes
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runs)); | ||
@QueryParam("filter") String filter) | ||
throws BadRequestException, IOException { | ||
validateNamespace(namespaceId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a todo for rbac check with a corresponding jira
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think these handlers should have a feature flag check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I have added the check for this feature flag: SOURCE_CONTROL_MANAGEMENT_MULTI_APP
|
||
// if (latestOnly != null) { | ||
// uri += ("&latestOnly=" + latestOnly); | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. done
return detail; | ||
} | ||
|
||
private static List<OperationRunDetail> insertTestRuns() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is same in store also. we can separate this into a OperationTestBase class which in turn extends AppFabricTestBase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thank you for the suggestion :)
…entity token exchanges, and do not retry on status code zero for ApiExceptions
[CDAP-20879] Use default k8s namespace in hybrid mode for workload identity token exchanges
[CDAP-20785] do not set WI env vars when NSA is enabled
CDAP-20809: Operation Runner
Multi push operation
[CDAP-20785] Use GCP remote authenticator to fetch token
.vscode/launch.json
Outdated
@@ -0,0 +1,364 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the .vscode folder from the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes done
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runs)); | ||
@QueryParam("filter") String filter) | ||
throws BadRequestException, IOException { | ||
validateNamespace(namespaceId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think these handlers should have a feature flag check.
private void validateNamespace(@Nullable String namespaceId) throws BadRequestException { | ||
if (namespaceId == null) { | ||
throw new BadRequestException("Path parameter namespaceId cannot be empty"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more cases that need to be validated here, like in this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I have added more cases
|
||
@ClassRule public static final TemporaryFolder TEMP_FOLDER = new TemporaryFolder(); | ||
|
||
private static EmbeddedPostgres pg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename this variable for better readability. Possibly postgres
or psql
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Thank you for the correction
Operation state publisher
Fix the null pointer exception caused by unsafe unboxing of Boolean
return new OperationRunFilter(operationType, operationStatus); | ||
} | ||
|
||
private static Map<String, String> parseFilter(String filter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: change the name to parseFilterStr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes done. I have edited this function and made it more generic
OperationRunStatus operationStatus = null; | ||
|
||
for (Map.Entry<String, String> entry : filterKeyValMap.entrySet()) { | ||
String key = entry.getKey(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filterKey
|
||
for (Map.Entry<String, String> entry : filterKeyValMap.entrySet()) { | ||
String key = entry.getKey(); | ||
String value = entry.getValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filterValue
String value = entry.getValue(); | ||
|
||
switch (key) { | ||
case "type": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a enum for this
OpreationFilterKey{
TYPE
STATUS
}
We convert the key
string to the enum. After that we can use switch case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes right. Thank you for the correction
return new OperationRunFilter(operationType, operationStatus); | ||
} | ||
|
||
private static Map<String, String> parseFilter(String filter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a javadoc explaining the parsing logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sure
Map<String, String> filterKeyValMap = new HashMap<>(); | ||
String[] filterKeyValPairs = filter.split("AND"); | ||
|
||
for (String keyValPair : filterKeyValPairs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use regex to parse this easily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Done
* | ||
* @param runId run id of the operation to be fetched | ||
* @return operation run detail of the operation to be fetched. If not found, | ||
* OperationRunNotFoundException is thrown.S |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove S
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also use @throws for documenting exception
@@ -338,4 +338,4 @@ void clearData() throws IOException { | |||
SMALLEST_POSSIBLE_STRING)), | |||
Range.Bound.INCLUSIVE)); | |||
} | |||
} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this change
@@ -69,7 +69,10 @@ protected void configure() { | |||
} | |||
|
|||
@AfterClass | |||
public static void afterClass() throws IOException { | |||
public static void afterClass(){ | |||
try{ | |||
pg.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use Colsables.closequitely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Fix the operation runner test
Add scan operation runs by status method
cdap-app-fabric/.gitignore
Outdated
@@ -1,3 +1,4 @@ | |||
.vscode/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add in a seperate section similar to intellij files
@@ -98,4 +176,115 @@ public void failOperation(FullHttpRequest request, HttpResponder responder, | |||
String.format("Updated status for operation run %s in namespace '%s'.", runId, | |||
namespaceId)); | |||
} | |||
|
|||
private ScanOperationRunsRequest getScanRequest( | |||
String namespaceId, String pageToken, Integer pageSize, String filter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filterStr
return builder.build(); | ||
} | ||
|
||
private OperationRunFilter getFilter(String filter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a TODO for adding unit test for this
return builder.build(); | ||
} | ||
|
||
private OperationRunFilter getFilter(String filter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this throes IllegalArgumentException
case TYPE: | ||
try { | ||
operationType = OperationType.valueOf(filterValue.toUpperCase()); | ||
} catch (IllegalArgumentException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to catch and rethrow it
return keyValMap; | ||
} | ||
|
||
private void validateNamespace(@Nullable String namespace) throws BadRequestException, NamespaceNotFoundException, AccessException{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think this can be shorthened to
private NamespaceId validateNamespaceId(String namespaceId) throws BadRequestException {
try {
return new NamespaceId(namespaceId);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e.getMessage(), e);
}
}
see SourceControlManagementHttpHandler
for reference
Resolved conflicts for rebasing
Resolved conflicts for rebasing
Resolved conflicts for rebasing
resolved conflicts while rebasing