Hi Scott,
How best to model this in Brooklyn depends very much on your use-case.
There's lots that could be said on this topic, but I don't want to flood
you with too much info! Can you share more on your use-case please?
e.g. do you want to create the VPC so that your Brooklyn app gets
deployed into that new VPC? Or is creation of the VPC part of some other
workflow, going beyond the use-case of deploying an app into a VPC with
Brooklyn?
---
For advanced-networking, some of that code is supporting the common
patterns of either:
* creating an app (or part of app) in a pre-existing private
networking (creating NAT rules etc); or
* creating a new private network, and then deploying the app inside it.
In each of those cases, it just has a "SubnetTier" entity as a parent of
the rest of the app. This entity can then create the private network and
ensure the location used by the app will provision its VMs in the
private network.
It does not create an entity to explicitly represent the private network
/ VPC.
---
It would certainly be possible to create an entity to represent the VPC
you want to create. If that is the thing you want to "manage" then that
makes sense.
Another alternative would be to have an entity for the AWS account /
region. That could have an effector for createVpc (returning the id),
and another effector for deleteVpc. It really depends how it's going to
be used, and thus what feels most natural.
We have entities that just bind to a pre-existing service, to use it
(e.g. GeoscalingDnsService), rather than it having to provision VMs etc.
---
You could extend AbstractEntity for this (the BasicEntity really just
does that - it provides a concrete class that is the simplest possible
entity).
You could have your entity implement Startable. Then in
start(Collection<Location>) you could create the VPC. The location
passed in would presumably be of type JcloudsLocation for an aws-ec2
location; you could extract the cloud credentials from that - or even
call into jclouds code using it.
The Startable interface also gives you a stop(), where you could delete
the VPC.
The connectSensors in your code won't get called. That is wired in by
the SoftwareProcess entity, rather than being part of all entities.
You'd really only need to do that if you want to poll for values for the
sensors (or subscribe to some event stream for those values).
Aled
p.s. Java convention is to capitalise the class; I'd personally go for
AwsVpc instead of awsVPC.
On 22/07/2015 06:48, Kellish, Scott (CT US) wrote:
Hi Richard,
Thanks for the reply. I looked at the advanced networking project and as you
mentioned, found it pretty daunting but will look again. My initial takeaway
about Brooklyn is that all of the entities seem to involve running instances. I
don't see any docs/examples showing more static infrastructure like an AWS VPC
or subnet or security group etc. Am I correct? I started creating some code
inheriting from BasicEntity (as opposed to SoftwareProcess since there's
nothing to SSH into for a VPC), but I don't quite understand the lifecycle of
how a BasicEntity derived object gets initialized.
Where would I put my code to create the VPC and later destroy it?
Would I still use "sensors" for example to return the VPC id provided by AWS?
My code thus far is attached.
awsVPC.java
==========
/**
* An {@link brooklyn.entity.Entity} that represents an ElasticSearch node
*/
@Catalog(name="AWS VPC", description="AWS VPC")
@ImplementedBy(awsVPCImpl.class)
public interface awsVPC extends BasicEntity {
@SetFromFlag("version")
ConfigKey<String> SUGGESTED_VERSION =
ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION, "4.0.1");
@SetFromFlag("CidrBlock")
ConfigKey<String> CIDR_BLOCK = ConfigKeys.newStringConfigKey("CIDR_BLOCK", "The CIDR
block you want the VPC to cover. For example: '10.0.0.0/16'", "10.0.0.0/16");
@SetFromFlag("EnableDnsSupport")
ConfigKey<Boolean> ENABLE_DNS_SUPPORT =
ConfigKeys.newBooleanConfigKey("ENABLE_DNS_SUPPORT", "Specifies whether DNS resolution is
supported for the VPC", true);
@SetFromFlag("EnableDnsHostnames")
ConfigKey<Boolean> ENABLE_DNS_HOSTNAMES =
ConfigKeys.newBooleanConfigKey("ENABLE_DNS_HOSTNAMES", "Specifies whether the instances
launched in the VPC get DNS hostnames.", false);
@SetFromFlag("InstanceTenancy")
ConfigKey<String> INSTANCE_TENANCY = ConfigKeys.newStringConfigKey("INSTANCE_TENANCY",
"The allowed tenancy of instances launched into the VPC, default or dedicated", "default");
}
awsVPCImpl.java
=============
package com.siemens.cip.services.awsVPC;
import static com.google.common.base.Preconditions.checkNotNull;
import brooklyn.entity.basic.BasicEntityImpl;
import brooklyn.entity.basic.SoftwareProcessImpl;
import brooklyn.event.feed.http.HttpFeed;
import brooklyn.event.feed.http.HttpPollConfig;
import brooklyn.event.feed.http.HttpValueFunctions;
import brooklyn.location.access.BrooklynAccessUtils;
import com.google.common.base.Functions;
import com.google.common.net.HostAndPort;
public class awsVPCImpl extends BasicEntityImpl implements awsVPC {
private HttpFeed httpFeed;
public awsVPCImpl() {
super();
}
@SuppressWarnings("rawtypes")
@Override
public void init() {
super.init();
}
@Override
protected void connectSensors() {
// Integer rawPort = getAttribute(HTTP_PORT);
// checkNotNull(rawPort, "HTTP_PORT sensors not set for %s; is an acceptable
port available?", this);
// HostAndPort hp =
BrooklynAccessUtils.getBrooklynAccessibleAddress(this, rawPort);
//
// super.connectSensors();
// httpFeed = HttpFeed.builder()
// .entity(this)
// .period(200)
// .baseUri(String.format("http://%s:%s",
hp.getHostText(), hp.getPort()))
// .poll(new HttpPollConfig<Boolean>(SERVICE_UP)
//
.onSuccess(HttpValueFunctions.responseCodeEquals(200))
//
.onFailureOrException(Functions.constant(false)))
// .build();
//super.connectSensors();
//connectServiceUpIsRunning();
}
@Override
protected void disconnectSensors() {
// super.disconnectSensors();
// if (httpFeed != null) httpFeed.stop();
//super.disconnectSensors();
//disconnectServiceUpIsRunning();
}
}
Thanks
Scott
-----Original Message-----
From: Richard Downer [mailto:[email protected]]
Sent: Wednesday, July 22, 2015 9:20 AM
To: [email protected]
Subject: Re: Help getting started with AWS VPC
Hi Scott,
Welcome to Brooklyn :-)
I suggest you take a look at the "advanced networking" project:
https://github.com/brooklyncentral/advanced-networking
It's a set of entities that support network concepts for a few clouds. It's not
strictly part of Brooklyn, instead it's part of the wider community.
AWS is not yet supported by advanced-networking, so your contribution could be
very useful! You could start by looking at how advanced-networking has done
this for CloudStack, and use similar techniques for your AWS VPC implementation.
Be warned that the networking is pretty complex code. If you are new to
Brooklyn and to Java I'd suggest starting with simpler entities first?
Richard.
On Tue, 21 Jul 2015 at 17:35 Kellish, Scott (CT US) <[email protected]>
wrote:
Hi,
New to Brooklyn (and java for that matter). Have Brooklyn installed
and built one of the example entities.
I would like to create a java entity to model an AWS VPC but not
really sure how to start. Which class should I inherit from etc. Can
someone point me in the right direction.
Scott
This message and any attachments are solely for the use of intended
recipients. The information contained herein may include trade
secrets, protected health or personal information, privileged or
otherwise confidential information. Unauthorized review, forwarding,
printing, copying, distributing, or using such information is strictly
prohibited and may be unlawful. If you are not an intended recipient,
you are hereby notified that you received this email in error, and
that any review, dissemination, distribution or copying of this email
and any attachment is strictly prohibited. If you have received this
email in error, please contact the sender and delete the message and
any attachment from your system. Thank you for your cooperation
This message and any attachments are solely for the use of intended recipients.
The information contained herein may include trade secrets, protected health or
personal information, privileged or otherwise confidential information.
Unauthorized review, forwarding, printing, copying, distributing, or using such
information is strictly prohibited and may be unlawful. If you are not an
intended recipient, you are hereby notified that you received this email in
error, and that any review, dissemination, distribution or copying of this
email and any attachment is strictly prohibited. If you have received this
email in error, please contact the sender and delete the message and any
attachment from your system. Thank you for your cooperation