Skip to content

Commit

Permalink
revert(rds): document DatabaseInstance.fromDatabaseInstanceAttributes…
Browse files Browse the repository at this point in the history
…() (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
  • Loading branch information
iliapolo authored Dec 15, 2020
1 parent bf05092 commit 054610f
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions packages/@aws-cdk/aws-rds/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,23 @@ export interface DatabaseInstanceAttributes {
export abstract class DatabaseInstanceBase extends Resource implements IDatabaseInstance {
/**
* Import an existing database instance.
*
* @deprecated use DatabaseInstance.fromDatabaseInstanceAttributes
*/
public static fromDatabaseInstanceAttributes(scope: Construct, id: string, attrs: DatabaseInstanceAttributes): IDatabaseInstance {
return DatabaseInstance.fromDatabaseInstanceAttributes(scope, id, attrs);
class Import extends DatabaseInstanceBase implements IDatabaseInstance {
public readonly defaultPort = ec2.Port.tcp(attrs.port);
public readonly connections = new ec2.Connections({
securityGroups: attrs.securityGroups,
defaultPort: this.defaultPort,
});
public readonly instanceIdentifier = attrs.instanceIdentifier;
public readonly dbInstanceEndpointAddress = attrs.instanceEndpointAddress;
public readonly dbInstanceEndpointPort = attrs.port.toString();
public readonly instanceEndpoint = new Endpoint(attrs.instanceEndpointAddress, attrs.port);
public readonly engine = attrs.engine;
protected enableIamAuthentication = true;
}

return new Import(scope, id);
}

public abstract readonly instanceIdentifier: string;
Expand Down Expand Up @@ -926,27 +938,6 @@ export interface DatabaseInstanceProps extends DatabaseInstanceSourceProps {
* @resource AWS::RDS::DBInstance
*/
export class DatabaseInstance extends DatabaseInstanceSource implements IDatabaseInstance {
/**
* Import an existing database instance.
*/
public static fromDatabaseInstanceAttributes(scope: Construct, id: string, attrs: DatabaseInstanceAttributes): IDatabaseInstance {
class Import extends DatabaseInstanceBase implements IDatabaseInstance {
public readonly defaultPort = ec2.Port.tcp(attrs.port);
public readonly connections = new ec2.Connections({
securityGroups: attrs.securityGroups,
defaultPort: this.defaultPort,
});
public readonly instanceIdentifier = attrs.instanceIdentifier;
public readonly dbInstanceEndpointAddress = attrs.instanceEndpointAddress;
public readonly dbInstanceEndpointPort = attrs.port.toString();
public readonly instanceEndpoint = new Endpoint(attrs.instanceEndpointAddress, attrs.port);
public readonly engine = attrs.engine;
protected enableIamAuthentication = true;
}

return new Import(scope, id);
}

public readonly instanceIdentifier: string;
public readonly dbInstanceEndpointAddress: string;
public readonly dbInstanceEndpointPort: string;
Expand Down

0 comments on commit 054610f

Please sign in to comment.