Skip to content
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

[FLINK-27279] Extract common status interfaces #176

Merged
merged 3 commits into from
Apr 24, 2022

Conversation

Aitozi
Copy link
Contributor

@Aitozi Aitozi commented Apr 20, 2022

This pr is meant to extract common status interfaces to simplify the ReconcileUtils

The brief change log

  1. Introduce the CommonView and SpecView to describe the common part between the FlinkDeployment and FlinkSessionJob
  2. Use the ReconciliationStatus for both FlinkDeployment and FlinkSessionJob

Verified by the current tests.

@Aitozi
Copy link
Contributor Author

Aitozi commented Apr 20, 2022

I also try to make the ReconcileUtils to a new Object to handle the reconciledSucceed, reconcileError and savepointSucceed. But I have to pass the object everywhere like controller and reconcilerFactory and reconciler. So I keep use the static way but unify the handle for FlinkDeployment and FlinkSessionJob

Please let me know if you have better suggestion cc @gyfora @wangyang0918 thanks

@gyfora
Copy link
Contributor

gyfora commented Apr 21, 2022

@Aitozi seems like the FlinkDeploymentStatus and FlinkSessionJobStatus also have a lot in common (the only diff is that FlinkDeploymentStatus has an extra JMDeploymentStatus field)

but jobStatus, error and reconciliationStatus could be completely shared

This could also simplify what you have tried to do with the CommonView logic which is a little confusing right now I think

@Aitozi
Copy link
Contributor Author

Aitozi commented Apr 21, 2022

@gyfora Thanks for your suggestion, I will try as you suggested

@Aitozi Aitozi marked this pull request as draft April 22, 2022 06:32
@Aitozi Aitozi force-pushed the FLINK-27279 branch 4 times, most recently from 1f106d6 to b8cedd1 Compare April 22, 2022 08:55
@Aitozi
Copy link
Contributor Author

Aitozi commented Apr 22, 2022

Due to the java type erasure, I can't not completly eliminate the FlinkDeploymentReconciliationStatus and FlinkSessionJobReconciliationStatus because I can't get the class at runtime 😔.
The new interface ReconcileTarget is responsible for get the common view of the custom resource. If we have special reconcile update logic for different custom resource, we can extend the interface to make it happen. What do you think about the current implementation @gyfora

@Aitozi Aitozi marked this pull request as ready for review April 22, 2022 10:09
@gyfora
Copy link
Contributor

gyfora commented Apr 22, 2022

Thank you, I will check this later today :)

Comment on lines 49 to 61
/**
* Get the current reconciliation status.
*
* @return the current reconciliation status.
*/
ReconciliationStatus<SPEC> getReconcileStatus();

/**
* Let the target custom resource handle the reconciliation error.
*
* @param error The error to be handled.
*/
void handleError(@Nullable String error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these methods should be part of the CommonStatus interface instead. Simply have the ReonciliationStatus and error fields there and use get/set

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way the ReconcileTerget interface could be also removed and use CustomResource<SPEC extends SpecView, STATUS extends CommonStatus>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, I have refactor based on your suggestion, please take a look again.

public FlinkDeploymentSpec deserializeLastReconciledSpec() {
return ReconciliationUtils.deserializedSpecWithVersion(
lastReconciledSpec, FlinkDeploymentSpec.class);
public abstract Class<SPEC> getSpecClass();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also simply add a constructor that takes the spec class (you have that when you call initStatus by calling getSpec().getClass()). Then you would not need 2 subclasses just to implement this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried this way, But if I add a field to record the spec class in ReconciliationStatus (making it @JsonIgnore ), It will cause the CRDGenerator stack overflow . So I kept it as it now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, I will take a look at this later :)

@Aitozi Aitozi force-pushed the FLINK-27279 branch 2 times, most recently from 5450276 to f62350d Compare April 23, 2022 15:11
Copy link
Contributor

@gyfora gyfora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some last minor comments. Thanks @Aitozi it looks really good now.

/** Error information about the FlinkDeployment/FlinkSessionJob. */
private String error;

public abstract ReconciliationStatus<SPEC> getReconciliationStatus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing javadoc comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

package org.apache.flink.kubernetes.operator.crd.spec;

/** The common view of the spec. */
public interface SpecView {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be an abstract class instead called FlinkSpecBase or AbstractFlinkSpec which could contain the job field (with the lombok annotation) that both deployment and sessionjobspec would extend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion, It looks more naturally now :).

public FlinkDeploymentSpec deserializeLastReconciledSpec() {
return ReconciliationUtils.deserializedSpecWithVersion(
lastReconciledSpec, FlinkDeploymentSpec.class);
public abstract Class<SPEC> getSpecClass();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, I will take a look at this later :)

Comment on lines +163 to +171
### CommonStatus
**Class**: org.apache.flink.kubernetes.operator.crd.status.CommonStatus

**Description**: Last observed common status of the Flink deployment/Flink SessionJob.

| Parameter | Type | Docs |
| ----------| ---- | ---- |
| jobStatus | org.apache.flink.kubernetes.operator.crd.status.JobStatus | Last observed status of the Flink job on Application/Session cluster. |
| error | java.lang.String | Error information about the FlinkDeployment/FlinkSessionJob. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inheritence structure breaks the (not very sophisticated) doc generation logic. We should either fix it here or open a blocker jira to track this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also confused here, what‘s the expect content here? Do we need to display the FlinkDeploymentReconciliationStatus fileds include (in the parent) directly and skip the abstract classes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would open another PR after this to fix this problem soon .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think from the users perspective it would be best to skip any abstract classes and only show the “child/leaf” classes in the hierarchy with all fields from the superclasses .

Copy link
Contributor Author

@Aitozi Aitozi Apr 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get it, I will try to make up the content in this way

@gyfora gyfora merged commit f520adf into apache:main Apr 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants