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

chore(rds): document DatabaseInstance.fromDatabaseInstanceAttributes() #11979

Merged
merged 5 commits into from
Dec 15, 2020

Conversation

ktheory
Copy link
Contributor

@ktheory ktheory commented Dec 10, 2020

Ensure DatabaseInstance.fromDatabaseInstanceAttributes is included in docs by moving it from the abstract DatabaseInstanceBase to the concrete DatabaseInstance class.

Thx @skinny85 for the suggestion in #11817.

Fixes #11817


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Dec 10, 2020

@github-actions github-actions bot added the @aws-cdk/aws-rds Related to Amazon Relational Database label Dec 10, 2020
…method

Ensure `DatabaseInstance.fromDatabaseInstanceAttributes` is included in docs by moving it from the abstract `DatabaseInstanceBase` to the concrete `DatabaseInstance` class.

Thx @skinny85 for the suggestion in aws#11817.

Fixes aws#11817
@ktheory ktheory changed the title fix(rds): document DatabaseInstance.fromDatabaseInstanceAttributes() chore(rds): document DatabaseInstance.fromDatabaseInstanceAttributes() Dec 10, 2020
ktheory and others added 2 commits December 10, 2020 03:30
fixes:

```
Member fromDatabaseInstanceAttributes should be declared before all field definitions  @typescript-eslint/member-ordering
```
@ktheory
Copy link
Contributor Author

ktheory commented Dec 10, 2020

From the build logs, looks like the error is about breaking backwards compatibility, which is strictly true. I'm curious if it matters in this case since DatabaseInstanceBase and intermediate classes are abstract.

Updated assembly:  @aws-cdk/[email protected]
API elements with incompatible changes:
err  - METHOD @aws-cdk/aws-rds.DatabaseInstanceBase.fromDatabaseInstanceAttributes: has been removed [removed:@aws-cdk/aws-rds.DatabaseInstanceBase.fromDatabaseInstanceAttributes]
err  - METHOD @aws-cdk/aws-rds.DatabaseInstanceFromSnapshot.fromDatabaseInstanceAttributes: has been removed [removed:@aws-cdk/aws-rds.DatabaseInstanceFromSnapshot.fromDatabaseInstanceAttributes]
err  - METHOD @aws-cdk/aws-rds.DatabaseInstanceReadReplica.fromDatabaseInstanceAttributes: has been removed [removed:@aws-cdk/aws-rds.DatabaseInstanceReadReplica.fromDatabaseInstanceAttributes]
...
Some packages seem to have undergone breaking API changes. Please avoid.

I could keep the method on DatabaseInstanceBase and mark it as deprecated to avoid breaking compatibility.
Curious for guidance, @skinny85.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Looks great @ktheory , thanks for the contribution!

Let's appease the backwards-compatibility checker by leaving the existing method 🙂.

packages/@aws-cdk/aws-rds/lib/instance.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-rds/lib/instance.ts Show resolved Hide resolved
@mergify mergify bot dismissed skinny85’s stale review December 11, 2020 02:01

Pull request has been modified.

Preserve backwards compatibility. Deprecate and delegate to new method.
@ktheory
Copy link
Contributor Author

ktheory commented Dec 11, 2020

@skinny85 just wanted to say kudos for making it easy and enjoyable to contribute to CDK.

In particular, I appreciate the effort y'all put in to the thorough Contributing guidelines, the helpful labels and comments on Issues, and robust CI+dev tooling.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @ktheory !

@skinny85 just wanted to say kudos for making it easy and enjoyable to contribute to CDK.

In particular, I appreciate the effort y'all put in to the thorough Contributing guidelines, the helpful labels and comments on Issues, and robust CI+dev tooling.

Thank you for the nice words, we're glad the contribution process is not too painful 😊.

@mergify
Copy link
Contributor

mergify bot commented Dec 15, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Dec 15, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit f2ecaf2 into aws:master Dec 15, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 1ade1b5
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

iliapolo added a commit that referenced this pull request Dec 15, 2020
mergify bot pushed a commit that referenced this pull request Dec 15, 2020
…() (#12091)

Reverts #11979

This commit broke java compilation of the module:

```console
#STDOUT> [ERROR] COMPILATION ERROR : 
#STDOUT> [INFO] -------------------------------------------------------------
#STDOUT> [ERROR] /tmp/npm-packP61iji/monocdk/src/main/java/software/amazon/awscdk/services/rds/DatabaseInstance.java:[38,5] method does not override or implement a method from a supertype
```

Basically the `fromDatabaseInstanceAttributes` function now exists both in `DatabaseInstanceBase` and `DatabaseInstance`, and for some reason the one in the child is annotated with an `@Override`, despite being a static function. (see more details below).

Since this module is stable, I don't want to simply move the function, but I do want to bring our pipeline back to life quickly, so this seems like an ok compromise for now.

-----------------

What happens is that the generated java code for some reason adds an `@Override` annotation to the function signature of the concrete class, as if its overriding the function in the base class, even though these are static methods.

```java
@javax.annotation.Generated(value = "jsii-pacmak/1.15.0 (build 585166b)", date = "2020-12-15T17:40:10.678Z")
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable)
@software.amazon.jsii.Jsii(module = software.amazon.awscdk.services.rds.$Module.class, fqn = "@aws-cdk/aws-rds.DatabaseInstance")
public class DatabaseInstance extends software.amazon.awscdk.services.rds.DatabaseInstanceBase implements software.amazon.awscdk.services.rds.IDatabaseInstance {

    protected DatabaseInstance(final software.amazon.jsii.JsiiObjectRef objRef) {
        super(objRef);
    }

    protected DatabaseInstance(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) {
        super(initializationMode);
    }

    /**
     * @param scope This parameter is required.
     * @param id This parameter is required.
     * @param props This parameter is required.
     */
    @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable)
    public DatabaseInstance(final @org.jetbrains.annotations.NotNull software.constructs.Construct scope, final @org.jetbrains.annotations.NotNull java.lang.String id, final @org.jetbrains.annotations.NotNull software.amazon.awscdk.services.rds.DatabaseInstanceProps props) {
        super(software.amazon.jsii.JsiiObject.InitializationMode.JSII);
        software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this, new Object[] { java.util.Objects.requireNonNull(scope, "scope is required"), java.util.Objects.requireNonNull(id, "id is required"), java.util.Objects.requireNonNull(props, "props is required") });
    }

    /**
     * Import an existing database instance.
     * <p>
     * @param scope This parameter is required.
     * @param id This parameter is required.
     * @param attrs This parameter is required.
     */
    @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable)
    @OverRide
    public static @org.jetbrains.annotations.NotNull software.amazon.awscdk.services.rds.IDatabaseInstance fromDatabaseInstanceAttributes(final @org.jetbrains.annotations.NotNull software.constructs.Construct scope, final @org.jetbrains.annotations.NotNull java.lang.String id, final @org.jetbrains.annotations.NotNull software.amazon.awscdk.services.rds.DatabaseInstanceAttributes attrs) {
        return software.amazon.jsii.JsiiObject.jsiiStaticCall(software.amazon.awscdk.services.rds.DatabaseInstance.class, "fromDatabaseInstanceAttributes", software.amazon.jsii.NativeType.forClass(software.amazon.awscdk.services.rds.IDatabaseInstance.class), new Object[] { java.util.Objects.requireNonNull(scope, "scope is required"), java.util.Objects.requireNonNull(id, "id is required"), java.util.Objects.requireNonNull(attrs, "attrs is required") });
    }
```

JSII assembly also shows:

```json
"name": "fromDatabaseInstanceAttributes",
"overrides": "@aws-cdk/aws-rds.DatabaseInstanceBase",
"parameters": [
  {
    "name": "scope",
    "type": {
      "fqn": "constructs.Construct"
    }
  },
  {
    "name": "id",
    "type": {
      "primitive": "string"
    }
  },
  {
    "name": "attrs",
    "type": {
      "fqn": "@aws-cdk/aws-rds.DatabaseInstanceAttributes"
    }
  }
],
"returns": {
  "type": {
    "fqn": "@aws-cdk/aws-rds.IDatabaseInstance"
  }
},
"static": true
```

This feels like a JSII bug, it shouldn't be marking this method as an override in the assembly, and regardless, it should not generate java code that has an `@Override` annotation on a static function, better to validate and throw beforehand.

I guess this is related to Typescript quirks with inheritance of static members?

cc @RomainMuller @skinny85
flochaz pushed a commit to flochaz/aws-cdk that referenced this pull request Jan 5, 2021
aws#11979)

Ensure `DatabaseInstance.fromDatabaseInstanceAttributes` is included in docs by moving it from the abstract `DatabaseInstanceBase` to the concrete `DatabaseInstance` class.

Thx @skinny85 for the suggestion in aws#11817.

Fixes aws#11817


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
flochaz pushed a commit to flochaz/aws-cdk that referenced this pull request Jan 5, 2021
…() (aws#12091)

Reverts aws#11979

This commit broke java compilation of the module:

```console
#STDOUT> [ERROR] COMPILATION ERROR : 
#STDOUT> [INFO] -------------------------------------------------------------
#STDOUT> [ERROR] /tmp/npm-packP61iji/monocdk/src/main/java/software/amazon/awscdk/services/rds/DatabaseInstance.java:[38,5] method does not override or implement a method from a supertype
```

Basically the `fromDatabaseInstanceAttributes` function now exists both in `DatabaseInstanceBase` and `DatabaseInstance`, and for some reason the one in the child is annotated with an `@Override`, despite being a static function. (see more details below).

Since this module is stable, I don't want to simply move the function, but I do want to bring our pipeline back to life quickly, so this seems like an ok compromise for now.

-----------------

What happens is that the generated java code for some reason adds an `@Override` annotation to the function signature of the concrete class, as if its overriding the function in the base class, even though these are static methods.

```java
@javax.annotation.Generated(value = "jsii-pacmak/1.15.0 (build 585166b)", date = "2020-12-15T17:40:10.678Z")
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable)
@software.amazon.jsii.Jsii(module = software.amazon.awscdk.services.rds.$Module.class, fqn = "@aws-cdk/aws-rds.DatabaseInstance")
public class DatabaseInstance extends software.amazon.awscdk.services.rds.DatabaseInstanceBase implements software.amazon.awscdk.services.rds.IDatabaseInstance {

    protected DatabaseInstance(final software.amazon.jsii.JsiiObjectRef objRef) {
        super(objRef);
    }

    protected DatabaseInstance(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) {
        super(initializationMode);
    }

    /**
     * @param scope This parameter is required.
     * @param id This parameter is required.
     * @param props This parameter is required.
     */
    @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable)
    public DatabaseInstance(final @org.jetbrains.annotations.NotNull software.constructs.Construct scope, final @org.jetbrains.annotations.NotNull java.lang.String id, final @org.jetbrains.annotations.NotNull software.amazon.awscdk.services.rds.DatabaseInstanceProps props) {
        super(software.amazon.jsii.JsiiObject.InitializationMode.JSII);
        software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this, new Object[] { java.util.Objects.requireNonNull(scope, "scope is required"), java.util.Objects.requireNonNull(id, "id is required"), java.util.Objects.requireNonNull(props, "props is required") });
    }

    /**
     * Import an existing database instance.
     * <p>
     * @param scope This parameter is required.
     * @param id This parameter is required.
     * @param attrs This parameter is required.
     */
    @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable)
    @OverRide
    public static @org.jetbrains.annotations.NotNull software.amazon.awscdk.services.rds.IDatabaseInstance fromDatabaseInstanceAttributes(final @org.jetbrains.annotations.NotNull software.constructs.Construct scope, final @org.jetbrains.annotations.NotNull java.lang.String id, final @org.jetbrains.annotations.NotNull software.amazon.awscdk.services.rds.DatabaseInstanceAttributes attrs) {
        return software.amazon.jsii.JsiiObject.jsiiStaticCall(software.amazon.awscdk.services.rds.DatabaseInstance.class, "fromDatabaseInstanceAttributes", software.amazon.jsii.NativeType.forClass(software.amazon.awscdk.services.rds.IDatabaseInstance.class), new Object[] { java.util.Objects.requireNonNull(scope, "scope is required"), java.util.Objects.requireNonNull(id, "id is required"), java.util.Objects.requireNonNull(attrs, "attrs is required") });
    }
```

JSII assembly also shows:

```json
"name": "fromDatabaseInstanceAttributes",
"overrides": "@aws-cdk/aws-rds.DatabaseInstanceBase",
"parameters": [
  {
    "name": "scope",
    "type": {
      "fqn": "constructs.Construct"
    }
  },
  {
    "name": "id",
    "type": {
      "primitive": "string"
    }
  },
  {
    "name": "attrs",
    "type": {
      "fqn": "@aws-cdk/aws-rds.DatabaseInstanceAttributes"
    }
  }
],
"returns": {
  "type": {
    "fqn": "@aws-cdk/aws-rds.IDatabaseInstance"
  }
},
"static": true
```

This feels like a JSII bug, it shouldn't be marking this method as an override in the assembly, and regardless, it should not generate java code that has an `@Override` annotation on a static function, better to validate and throw beforehand.

I guess this is related to Typescript quirks with inheritance of static members?

cc @RomainMuller @skinny85
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-rds: fromDatabaseInstanceAttributes static method missing
3 participants