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

How do you add Resource Options to a resource in JAVA CDK #774

Closed
ygoodmn opened this issue Sep 25, 2018 · 4 comments
Closed

How do you add Resource Options to a resource in JAVA CDK #774

ygoodmn opened this issue Sep 25, 2018 · 4 comments
Assignees
Labels
bug This issue is a bug. language/java Related to Java bindings

Comments

@ygoodmn
Copy link

ygoodmn commented Sep 25, 2018

JAVA CDK version 0.9.2

Unable to see CreationPolicy or UpdatePolicy when running 'cdk synth' on the following code attached to the autoscaling Resource:

How do you attach it, with dependsOn you have an addDependency, but on see a getOptions() then a setCreationPolicy, but do not see anything in the 'cdk sythn'

  1. Code

  2. Output from Synth

  3. Code:

        AutoScalingGroupResource autoScalingGroupResource = new AutoScalingGroupResource(this, "AutoScalingGroup",
                AutoScalingGroupResourceProps.builder()
                        .withAutoScalingGroupName(new FnSub("SMS-${ProjectID}-ServerGroup"))
                        .withLaunchConfigurationName(launchConfigurationResource.getLaunchConfigurationName())
                        .withMinSize(minSizeParam.getValue().toString()) //
                        .withMaxSize(maxSizeParam.getValue().toString()) //
                        .withDesiredCapacity(desiredCapacityParam.getValue().toString())
                        .withTargetGroupArns(Collections.singletonList(targetGroupResource.getTargetGroupArn()))
                        .withVpcZoneIdentifier(subnets)
                        .withHealthCheckType("ELB")
                        .withHealthCheckGracePeriod(120)
                        .build());

        //TODO  DOES not attach the Policies
        autoScalingGroupResource.getOptions().setCreationPolicy(CreationPolicy.builder().withResourceSignal(ResourceSignal.builder().withCount(0).build()).build());
        autoScalingGroupResource.getOptions().setUpdatePolicy(UpdatePolicy.builder().withAutoScalingRollingUpdate(AutoScalingRollingUpdate.builder()
                .withMinInstancesInService(1)
                .withMaxBatchSize(1)
                .withPauseTime("PT15M")
                .withWaitOnResourceSignals(true)
                .build()).build());

        ResourceOptions resourceOptions =  ResourceOptions.builder()
                .withCreationPolicy(CreationPolicy.builder().withResourceSignal(ResourceSignal.builder().withCount(0).build()).build())
                .withUpdatePolicy(UpdatePolicy.builder().withAutoScalingRollingUpdate(AutoScalingRollingUpdate.builder()
                        .withMinInstancesInService(1)
                        .withMaxBatchSize(1)
                        .withPauseTime("PT15M")
                        .withWaitOnResourceSignals(true)
                        .build()).build())
                .build();

Output:

AutoScalingGroup:
        Type: 'AWS::AutoScaling::AutoScalingGroup'
        Properties:
            MaxSize:
                Ref: MaxSize
            MinSize:
                Ref: MinSize
            AutoScalingGroupName:
                'Fn::Sub': 'SMS-${ProjectID}-ServerGroup'
            DesiredCapacity:
                Ref: DesirecCapacity
            HealthCheckGracePeriod: 120
            HealthCheckType: ELB
            LaunchConfigurationName:
                Ref: LaunchConfiguration
            TargetGroupARNs:
                -
                    Ref: TargetGroup
            VPCZoneIdentifier:
                -
                    'Fn::ImportValue':
                        'Fn::Sub': 'SMS-${ProjectID}-VPC-PrivateSubnetA'
                -
                    'Fn::ImportValue':
                        'Fn::Sub': 'SMS-${ProjectID}-VPC-PrivateSubnetC'
@rix0rrr rix0rrr added ❓ question bug This issue is a bug. language/java Related to Java bindings and removed ❓ question labels Sep 25, 2018
@rix0rrr
Copy link
Contributor

rix0rrr commented Sep 25, 2018

Yes, that seems like a bug. Thanks for reporting. We're going to have to investigate this.

@rix0rrr
Copy link
Contributor

rix0rrr commented Sep 26, 2018

In the mean time, have you considered using the AutoScalingGroup L2 resource (as opposed to AutoScalingGroupResource)?

@RomainMuller
Copy link
Contributor

This is a bug in the jsii kernel: In the javascript world, the call to getOptions returns an object literal (as opposed to a class instance) that adheres to a particular interface, and this causes the kernel to return a copy of this (instead of a reference to it).

I've created aws/jsii#248 on jsii to track the fix there (will update this issue once resolved).

RomainMuller added a commit to aws/jsii that referenced this issue Sep 27, 2018
Use the javascript `Proxy` class to coalesce object literals to an
interface type, allowing them to be returned by reference instead of by
value.

Introduces a test in the `jsii-kernel` to demonstrate the feature works
as intended.

Fixes #248
Fixes aws/aws-cdk#774
@rix0rrr
Copy link
Contributor

rix0rrr commented Sep 27, 2018

Thanks for reporting. Closing this as it's being tracked elsewhere.

@rix0rrr rix0rrr closed this as completed Sep 27, 2018
RomainMuller added a commit to aws/jsii that referenced this issue Sep 28, 2018
Use the javascript `Proxy` class to coalesce object literals to an
interface type, allowing them to be returned by reference instead of by
value.

Introduces a test in the `jsii-kernel` to demonstrate the feature works
as intended.

Fixes #248
Fixes aws/aws-cdk#774
eladb pushed a commit to aws/jsii that referenced this issue Oct 9, 2018
### Bug Fixes

* **dotnet:** abstract classes should have proxy implementations ([#241](#241)) ([828a26f](828a26f)), closes [#223](#223)
* **jsii:** better usage reporting of private types ([#247](#247)) ([96ac5d6](96ac5d6))
* **jsii-runtime:** Use buffer factory methods instead of constructor. ([#246](#246)) ([6ad6b9d](6ad6b9d))
* **kernel:** Return object literals as references ([#249](#249)) ([61cb3a4](61cb3a4)), closes [#248](#248) [aws/aws-cdk#774](aws/aws-cdk#774)
@eladb eladb mentioned this issue Oct 9, 2018
eladb pushed a commit to aws/jsii that referenced this issue Oct 10, 2018
Bug Fixes
=========

* **dotnet:** abstract classes should have proxy implementations ([#241](#241)) ([828a26f](828a26f)), closes [#223](#223)
* **jsii:** better usage reporting of private types ([#247](#247)) ([96ac5d6](96ac5d6))
* **jsii:** support  public autoproperties in private constructor ([#256](#256)) ([181012e](181012e))
* **jsii:** use default jsx compiler options ([#260](#260)) ([660ae79](660ae79)), closes [aws/aws-cdk#830](aws/aws-cdk#830)
* **jsii-dotnet-generator:** Use FQ type returns in conflict. ([#258](#258)) ([a78784a](a78784a)), closes [#252](#252)
* **jsii-runtime:** Use buffer factory methods instead of constructor. ([#246](#246)) ([6ad6b9d](6ad6b9d))
* **kernel:** Return object literals as references ([#249](#249)) ([61cb3a4](61cb3a4)), closes [#248](#248) [aws/aws-cdk#774](aws/aws-cdk#774)

Misc
====

bump.sh was updated to let "lerna publish" automatically determine
the version number using conventional commits.
eladb pushed a commit to aws/jsii that referenced this issue Oct 10, 2018
Bug Fixes
=========

* **dotnet:** abstract classes should have proxy implementations ([#241](#241)) ([828a26f](828a26f)), closes [#223](#223)
* **jsii:** better usage reporting of private types ([#247](#247)) ([96ac5d6](96ac5d6))
* **jsii:** support  public autoproperties in private constructor ([#256](#256)) ([181012e](181012e))
* **jsii:** use default jsx compiler options ([#260](#260)) ([660ae79](660ae79)), closes [aws/aws-cdk#830](aws/aws-cdk#830)
* **jsii-dotnet-generator:** Use FQ type returns in conflict. ([#258](#258)) ([a78784a](a78784a)), closes [#252](#252)
* **jsii-runtime:** Use buffer factory methods instead of constructor. ([#246](#246)) ([6ad6b9d](6ad6b9d))
* **kernel:** Return object literals as references ([#249](#249)) ([61cb3a4](61cb3a4)), closes [#248](#248) [aws/aws-cdk#774](aws/aws-cdk#774)

Misc
====

bump.sh was updated to let "lerna publish" automatically determine
the version number using conventional commits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. language/java Related to Java bindings
Projects
None yet
Development

No branches or pull requests

3 participants