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

Add support for storing subnet id in ec2instance and report vpc for stored subnet id in describeInstances #58

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

KraProgrammer
Copy link

Add support for persisting subnet id. The subnet id is also used to derive the vpc id.
Previously the default subnet id and vpc id were returned for all instances.

* @param subnetId The subnet id.
* @return The VPC id. Returns null, if no matching subnet is found.
*/
private String getVpcForSubnetId(final String subnetId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be more meaningful if we change the name to getVpcIdForSubnet

Copy link
Author

Choose a reason for hiding this comment

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

Agreed

return subnet.getVpcId();
}
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it's always expected that a VPC is tied to a subnet - it's better if we throw an Exception than returning null. It will also be difficult to catch if for some reason we do return null.

Copy link
Author

Choose a reason for hiding this comment

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

If we use a default value for not provided subnetIds, then we need here either a check for MOCK_SUBNET_ID where we return MOCK_VPC_ID. Or we just return MOCK_VPC_ID by default.

if (MOCK_SUBNET_ID.equals(subnetId)) { return MOCK_VPC_ID; }
Or
private String getVpcIdForSubnet(final String subnetId) { for (MockSubnet subnet : mockSubnetController.describeSubnets()) { if (subnet.getSubnetId().equals(subnetId)) { return subnet.getVpcId(); } } return MOCK_VPC_ID; }
What would be your prefered solution?

Copy link
Member

Choose a reason for hiding this comment

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

I feel we can return MOCK_VPC_ID if no matching vpcId found.

@@ -15,7 +15,7 @@
*
* @see Serializable
*/
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 2L;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain why the version is incremented for this class?

Copy link
Author

Choose a reason for hiding this comment

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

You are right, the base model would be a better place for the increment.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah not necessary a change here.

final String[] subnetIdArray = queryParams.get("SubnetId");
String subnetId = null;
if (subnetIdArray != null) {
subnetId = subnetIdArray[0];
Copy link
Member

Choose a reason for hiding this comment

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

What if SubnetId is not provided? Can we allocate a random uuid as the subnetId for an instance?

Copy link
Author

Choose a reason for hiding this comment

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

Another possibilty would be, that we use the MOCK_SUBNET_ID as default.
What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I agree that we use MOCK_SUBNET_ID as default.

@maxiaohao
Copy link
Member

Hi @KraProgrammer really sorry for the late response.
I note you've closed the PR but if you would reopen it I think we are not far away from merging this great feature! Thanks.

@nottoseethesun
Copy link
Member

I'm planning on having this work merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants