Updated Branches:
  refs/heads/jclouds-101 [created] 917bd29c9

JCLOUDS-101 - first chunk of work on generalized domain classes


Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/commit/1ceccd5b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/tree/1ceccd5b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/diff/1ceccd5b

Branch: refs/heads/jclouds-101
Commit: 1ceccd5b1b2451b2f8242fbb68aa07a9f75b762a
Parents: a3488dc
Author: Andrew Bayer <[email protected]>
Authored: Fri Jun 7 11:03:25 2013 -0700
Committer: Andrew Bayer <[email protected]>
Committed: Fri Jun 7 11:03:25 2013 -0700

----------------------------------------------------------------------
 .../org/jclouds/compute/domain/ComputeType.java |   2 +-
 .../org/jclouds/compute/domain/IpProtocol.java  |  39 ++++++
 .../jclouds/compute/domain/SecurityGroup.java   |  40 ++++++
 .../compute/domain/SecurityGroupRule.java       |  71 ++++++++++
 .../domain/internal/SecurityGroupImpl.java      |  68 ++++++++++
 .../domain/internal/SecurityGroupRuleImpl.java  | 130 +++++++++++++++++++
 6 files changed, 349 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1ceccd5b/compute/src/main/java/org/jclouds/compute/domain/ComputeType.java
----------------------------------------------------------------------
diff --git a/compute/src/main/java/org/jclouds/compute/domain/ComputeType.java 
b/compute/src/main/java/org/jclouds/compute/domain/ComputeType.java
index 26df759..8e2c75c 100644
--- a/compute/src/main/java/org/jclouds/compute/domain/ComputeType.java
+++ b/compute/src/main/java/org/jclouds/compute/domain/ComputeType.java
@@ -22,6 +22,6 @@ package org.jclouds.compute.domain;
  */
 public enum ComputeType {
 
-   NODE, IMAGE, HARDWARE;
+   NODE, IMAGE, HARDWARE, SECURITYGROUP;
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1ceccd5b/compute/src/main/java/org/jclouds/compute/domain/IpProtocol.java
----------------------------------------------------------------------
diff --git a/compute/src/main/java/org/jclouds/compute/domain/IpProtocol.java 
b/compute/src/main/java/org/jclouds/compute/domain/IpProtocol.java
new file mode 100644
index 0000000..2ec6993
--- /dev/null
+++ b/compute/src/main/java/org/jclouds/compute/domain/IpProtocol.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.compute.domain;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public enum IpProtocol {
+   TCP, UDP, ICMP, UNRECOGNIZED;
+   public String value() {
+      return name().toLowerCase();
+   }
+
+   @Override
+   public String toString() {
+      return value();
+   }
+
+   public static IpProtocol fromValue(String protocol) {
+      try {
+         return valueOf(checkNotNull(protocol, "protocol").toUpperCase());
+      } catch (IllegalArgumentException e) {
+         return UNRECOGNIZED;
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1ceccd5b/compute/src/main/java/org/jclouds/compute/domain/SecurityGroup.java
----------------------------------------------------------------------
diff --git 
a/compute/src/main/java/org/jclouds/compute/domain/SecurityGroup.java 
b/compute/src/main/java/org/jclouds/compute/domain/SecurityGroup.java
new file mode 100644
index 0000000..b5434af
--- /dev/null
+++ b/compute/src/main/java/org/jclouds/compute/domain/SecurityGroup.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.compute.domain;
+
+import java.util.Set;
+
+import org.jclouds.compute.domain.internal.SecurityGroupImpl;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.inject.ImplementedBy;
+
+/**
+ * Describes a security group containing a set of @{link SecurityGroupRule}s
+ * 
+ * @author Andrew Bayer
+ */
+@ImplementedBy(SecurityGroupImpl.class)
+public interface SecurityGroup extends ComputeMetadata {
+
+   /**
+    * 
+    * @return The set of @{link SecurityGroupRule}s for this security group
+    */
+   Set<SecurityGroupRule> getRules();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1ceccd5b/compute/src/main/java/org/jclouds/compute/domain/SecurityGroupRule.java
----------------------------------------------------------------------
diff --git 
a/compute/src/main/java/org/jclouds/compute/domain/SecurityGroupRule.java 
b/compute/src/main/java/org/jclouds/compute/domain/SecurityGroupRule.java
new file mode 100644
index 0000000..af6f5d3
--- /dev/null
+++ b/compute/src/main/java/org/jclouds/compute/domain/SecurityGroupRule.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.compute.domain;
+
+import java.util.Set;
+
+import org.jclouds.compute.domain.internal.SecurityGroupRuleImpl;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.inject.ImplementedBy;
+
+/**
+ * The port range, IP ranges, protocol and instance groups for a rule in a 
@{link SecurityGroup}.
+ * 
+ * @author Andrew Bayer
+ */
+@ImplementedBy(SecurityGroupRuleImpl.class)
+public interface SecurityGroupRule {
+
+   /**
+    * @return Unique identifier.
+    *
+    */
+   @Nullable
+   String getId();
+
+   /**
+    * @return The IP protocol for the rule.
+    */
+   IpProtocol getProtocol();
+
+   /**
+    *
+    * @return the start port.
+    */
+   int getStartPort();
+
+   /**
+    *
+    * @return the end port.
+    */
+   int getEndPort();
+
+   /**
+    * 
+    * @return The set of IP ranges for this rule.
+    */
+   Set<String> getIpRanges();
+
+   /**
+    * 
+    * @return The set of instance group IDs for this rule.
+    */
+   Set<String> getGroupIds();
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1ceccd5b/compute/src/main/java/org/jclouds/compute/domain/internal/SecurityGroupImpl.java
----------------------------------------------------------------------
diff --git 
a/compute/src/main/java/org/jclouds/compute/domain/internal/SecurityGroupImpl.java
 
b/compute/src/main/java/org/jclouds/compute/domain/internal/SecurityGroupImpl.java
new file mode 100644
index 0000000..108c14b
--- /dev/null
+++ 
b/compute/src/main/java/org/jclouds/compute/domain/internal/SecurityGroupImpl.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.compute.domain.internal;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.Set;
+
+import org.jclouds.compute.domain.ComputeType;
+import org.jclouds.compute.domain.SecurityGroup;
+import org.jclouds.compute.domain.SecurityGroupRule;
+import org.jclouds.domain.Location;
+import org.jclouds.domain.ResourceMetadata;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.base.Predicate;
+import com.google.common.collect.ComparisonChain;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * @author Andrew Bayer
+ */
+public class SecurityGroupImpl extends ComputeMetadataImpl implements 
SecurityGroup {
+
+   private final Set<SecurityGroupRule> rules;
+
+   public SecurityGroupImpl(String providerId, String name, String id, 
@Nullable Location location, URI uri,
+                            Map<String, String> userMetadata, Set<String> tags,
+                            Iterable<SecurityGroupRule> rules) { 
+      super(ComputeType.SECURITYGROUP, providerId, name, id, location, uri, 
userMetadata, tags);
+      this.rules = ImmutableSet.copyOf(checkNotNull(rules, "rules"));
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<SecurityGroupRule> getRules() {
+      return rules;
+   }
+
+
+   @Override
+   protected ToStringHelper string() {
+      ToStringHelper helper = computeToStringPrefix();
+      if (rules.size() > 0)
+         helper.add("rules", rules);
+      return addComputeToStringSuffix(helper);
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/1ceccd5b/compute/src/main/java/org/jclouds/compute/domain/internal/SecurityGroupRuleImpl.java
----------------------------------------------------------------------
diff --git 
a/compute/src/main/java/org/jclouds/compute/domain/internal/SecurityGroupRuleImpl.java
 
b/compute/src/main/java/org/jclouds/compute/domain/internal/SecurityGroupRuleImpl.java
new file mode 100644
index 0000000..0448318
--- /dev/null
+++ 
b/compute/src/main/java/org/jclouds/compute/domain/internal/SecurityGroupRuleImpl.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.compute.domain.internal;
+
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Set;
+
+import org.jclouds.compute.domain.IpProtocol;
+import org.jclouds.compute.domain.SecurityGroupRule;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * @author Adrian Cole
+ */
+public class SecurityGroupRuleImpl implements SecurityGroupRule {
+
+   @Nullable
+   private final String id;
+   private final IpProtocol protocol;
+   private final int startPort;
+   private final int endPort;
+   private final Set<String> ipRanges;
+   private final Set<String> groupIds;
+
+   @Override
+   public boolean equals(Object o) {
+      if (this == o)
+         return true;
+      if (o == null || getClass() != o.getClass())
+         return false;
+      SecurityGroupRuleImpl that = SecurityGroupRuleImpl.class.cast(o);
+      return equal(this.id, that.id) && equal(this.getProtocol(), 
that.getProtocol()) && equal(this.startPort, that.startPort)
+         && equal(this.endPort, that.endPort) && equal(this.getIpRanges(), 
that.getIpRanges())
+         && equal(this.getGroupIds(), that.getGroupIds());
+   }
+
+   @Override
+   public int hashCode() {
+      return Objects.hashCode(id, protocol, startPort, endPort, ipRanges, 
groupIds);
+   }
+
+   @Override
+   public String toString() {
+      return string().toString();
+   }
+
+   protected ToStringHelper string() {
+      return Objects.toStringHelper("").omitNullValues().add("id", 
id).add("protocol", getProtocol()).add("startPort", startPort)
+         .add("endPort", endPort).add("ipRanges", 
getIpRanges()).add("groupIds", getGroupIds());
+   }
+
+   public SecurityGroupRuleImpl(@Nullable String id, IpProtocol protocol, int 
startPort, int endPort,
+                                Iterable<String> ipRanges, Iterable<String> 
groupIds) {
+      this.id = id;
+      this.protocol = checkNotNull(protocol, "protocol");
+      this.startPort = startPort;
+      this.endPort = endPort;
+      this.ipRanges = ImmutableSet.copyOf(checkNotNull(ipRanges, "ipRanges"));
+      this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds"));
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public String getId() {
+      return id;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public IpProtocol getProtocol() {
+      return protocol;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public int getStartPort() {
+      return startPort;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public int getEndPort() {
+      return endPort;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<String> getIpRanges() {
+      return ipRanges;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<String> getGroupIds() {
+      return groupIds;
+   }
+
+}

Reply via email to