InboundPortsJcloudsLocationCustomizer
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/2e736083 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/2e736083 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/2e736083 Branch: refs/heads/master Commit: 2e736083e55a273c3485ab3f9cb2b033156e091d Parents: 6d7765b Author: Valentin Aitken <bos...@gmail.com> Authored: Tue Aug 23 15:24:59 2016 +0300 Committer: Valentin Aitken <bos...@gmail.com> Committed: Wed Aug 24 03:10:45 2016 +0300 ---------------------------------------------------------------------- .../InboundPortsJcloudsLocationCustomizer.java | 68 ++++++++++++++++++++ .../jclouds/networking/NetworkingEffectors.java | 2 + 2 files changed, 70 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2e736083/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/InboundPortsJcloudsLocationCustomizer.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/InboundPortsJcloudsLocationCustomizer.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/InboundPortsJcloudsLocationCustomizer.java new file mode 100644 index 0000000..11b01ee --- /dev/null +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/InboundPortsJcloudsLocationCustomizer.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.apache.brooklyn.location.jclouds.networking; + +import com.google.common.annotations.Beta; +import org.apache.brooklyn.api.entity.Entity; +import org.apache.brooklyn.api.mgmt.TaskAdaptable; +import org.apache.brooklyn.core.effector.Effectors; +import org.apache.brooklyn.core.location.cloud.CloudLocationConfig; +import org.apache.brooklyn.location.jclouds.BasicJcloudsLocationCustomizer; +import org.apache.brooklyn.location.jclouds.JcloudsLocation; +import org.apache.brooklyn.location.jclouds.JcloudsMachineLocation; +import org.apache.brooklyn.util.collections.MutableMap; +import org.apache.brooklyn.util.core.task.DynamicTasks; +import org.jclouds.compute.ComputeService; +import org.jclouds.net.domain.IpPermission; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.brooklyn.location.jclouds.networking.NetworkingEffectors.*; + +@Beta +public class InboundPortsJcloudsLocationCustomizer extends BasicJcloudsLocationCustomizer { + public static final Logger LOG = LoggerFactory.getLogger(InboundPortsJcloudsLocationCustomizer.class); + + private String inboundPortsList; + private String inboundPortsListProtocol; + + @Override + public void customize(JcloudsLocation location, ComputeService computeService, JcloudsMachineLocation machine) { + Object callerContext = machine.getConfig(CloudLocationConfig.CALLER_CONTEXT); + Entity entity; + if (callerContext instanceof Entity) { + entity = (Entity)callerContext; + } else { + throw new IllegalArgumentException("customizer should be called on against a jcloudsLocation which has callerContext of type Entity. Location " + location); + } + TaskAdaptable<Iterable<IpPermission>> taskAdaptable = Effectors.invocation(entity, + NetworkingEffectors.OPEN_INBOUND_PORTS_IN_SECURITY_GROUP_EFFECTOR, + MutableMap.<Object, Object>of(INBOUND_PORTS_LIST, inboundPortsList, INBOUND_PORTS_LIST_PROTOCOL, inboundPortsListProtocol, JCLOUDS_MACHINE_LOCATIN, machine)); + Iterable<IpPermission> result = DynamicTasks.submit(taskAdaptable.asTask(), entity).getUnchecked(); + LOG.info("Opened ports for " + entity + " " + result); + } + + public void setInboundPortsList(String inboundPortsList) { + this.inboundPortsList = inboundPortsList; + } + + public void setInboundPortsListProtocol(String inboundPortsListProtocol) { + this.inboundPortsListProtocol = inboundPortsListProtocol; + } +} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2e736083/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/NetworkingEffectors.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/NetworkingEffectors.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/NetworkingEffectors.java index 7244123..aba9753 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/NetworkingEffectors.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/NetworkingEffectors.java @@ -18,6 +18,7 @@ */ package org.apache.brooklyn.location.jclouds.networking; +import com.google.common.annotations.Beta; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -52,6 +53,7 @@ public class NetworkingEffectors { public static final ConfigKey<JcloudsMachineLocation> JCLOUDS_MACHINE_LOCATIN = ConfigKeys.newConfigKey(JcloudsMachineLocation.class, "jcloudsMachineLocation"); + @Beta @SuppressWarnings("unchecked") public static final Effector<Iterable<IpPermission>> OPEN_INBOUND_PORTS_IN_SECURITY_GROUP_EFFECTOR = (Effector<Iterable<IpPermission>>)(Effector<?>)Effectors.effector(Iterable.class, "openPortsInSecurityGroup") .parameter(INBOUND_PORTS_LIST)