mirror of https://github.com/apache/jclouds.git
Remove firewall-tag filtering
This commit is contained in:
parent
5adfce8d48
commit
465a62aa27
|
@ -22,8 +22,6 @@ import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.compute.functions.GroupNamingConvention;
|
import org.jclouds.compute.functions.GroupNamingConvention;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The convention for naming instance tags that firewall rules recognise.
|
* The convention for naming instance tags that firewall rules recognise.
|
||||||
*/
|
*/
|
||||||
|
@ -58,14 +56,4 @@ public final class FirewallTagNamingConvention {
|
||||||
|
|
||||||
return String.format("%s-%s", sharedResourceName, Integer.toHexString(result));
|
return String.format("%s-%s", sharedResourceName, Integer.toHexString(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Predicate<String> isFirewallTag() {
|
|
||||||
return new Predicate<String>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(String input) {
|
|
||||||
return input != null && input.startsWith(sharedResourceName + "-port-");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.googlecomputeengine.compute.functions;
|
package org.jclouds.googlecomputeengine.compute.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static org.jclouds.compute.util.ComputeServiceUtils.groupFromMapOrName;
|
import static org.jclouds.compute.util.ComputeServiceUtils.groupFromMapOrName;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -36,7 +34,6 @@ import org.jclouds.domain.Location;
|
||||||
import org.jclouds.googlecomputeengine.domain.Instance;
|
import org.jclouds.googlecomputeengine.domain.Instance;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
@ -47,33 +44,21 @@ public final class InstanceToNodeMetadata implements Function<Instance, NodeMeta
|
||||||
private final Map<URI, URI> diskToSourceImage;
|
private final Map<URI, URI> diskToSourceImage;
|
||||||
private final Supplier<Map<URI, Hardware>> hardwares;
|
private final Supplier<Map<URI, Hardware>> hardwares;
|
||||||
private final Supplier<Map<URI, Location>> locationsByUri;
|
private final Supplier<Map<URI, Location>> locationsByUri;
|
||||||
private final FirewallTagNamingConvention.Factory firewallTagNamingConvention;
|
|
||||||
|
|
||||||
@Inject InstanceToNodeMetadata(Map<Instance.Status, NodeMetadata.Status> toPortableNodeStatus,
|
@Inject InstanceToNodeMetadata(Map<Instance.Status, NodeMetadata.Status> toPortableNodeStatus,
|
||||||
GroupNamingConvention.Factory namingConvention,
|
GroupNamingConvention.Factory namingConvention,
|
||||||
Map<URI, URI> diskToSourceImage,
|
Map<URI, URI> diskToSourceImage,
|
||||||
@Memoized Supplier<Map<URI, Hardware>> hardwares,
|
@Memoized Supplier<Map<URI, Hardware>> hardwares,
|
||||||
@Memoized Supplier<Map<URI, Location>> locationsByUri,
|
@Memoized Supplier<Map<URI, Location>> locationsByUri) {
|
||||||
FirewallTagNamingConvention.Factory firewallTagNamingConvention) {
|
|
||||||
this.toPortableNodeStatus = toPortableNodeStatus;
|
this.toPortableNodeStatus = toPortableNodeStatus;
|
||||||
this.nodeNamingConvention = namingConvention.createWithoutPrefix();
|
this.nodeNamingConvention = namingConvention.createWithoutPrefix();
|
||||||
this.diskToSourceImage = diskToSourceImage;
|
this.diskToSourceImage = diskToSourceImage;
|
||||||
this.hardwares = hardwares;
|
this.hardwares = hardwares;
|
||||||
this.locationsByUri = locationsByUri;
|
this.locationsByUri = locationsByUri;
|
||||||
this.firewallTagNamingConvention = checkNotNull(firewallTagNamingConvention, "firewallTagNamingConvention");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public NodeMetadata apply(Instance input) {
|
@Override public NodeMetadata apply(Instance input) {
|
||||||
String group = groupFromMapOrName(input.metadata().asMap(), input.name(), nodeNamingConvention);
|
String group = groupFromMapOrName(input.metadata().asMap(), input.name(), nodeNamingConvention);
|
||||||
Predicate<String> isFirewallTag = firewallTagNamingConvention.get(group).isFirewallTag();
|
|
||||||
if (group != null) {
|
|
||||||
for (Iterator<String> tag = input.tags().items().iterator(); tag.hasNext(); ) {
|
|
||||||
if (isFirewallTag.apply(tag.next())) {
|
|
||||||
tag.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||||
|
|
||||||
Location zone = locationsByUri.get().get(input.zone());
|
Location zone = locationsByUri.get().get(input.zone());
|
||||||
|
|
|
@ -178,18 +178,7 @@ public class InstanceToNodeMetadataTest {
|
||||||
namingConventionFactory,
|
namingConventionFactory,
|
||||||
ImmutableMap.of(instance.disks().get(0).source(), imageUrl),
|
ImmutableMap.of(instance.disks().get(0).source(), imageUrl),
|
||||||
hardwareSupplier,
|
hardwareSupplier,
|
||||||
locationSupplier,
|
locationSupplier);
|
||||||
new FirewallTagNamingConvention.Factory(namingConventionFactory));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public final void testTagFilteringWorks() {
|
|
||||||
NodeMetadata nodeMetadata = groupGroupNodeParser.apply(instance);
|
|
||||||
assertEquals(nodeMetadata.getId(), instance.selfLink().toString());
|
|
||||||
assertEquals(nodeMetadata.getTags(), ImmutableSet.of(
|
|
||||||
"aTag" // "aTag" kept as a non firewall tag.
|
|
||||||
// "Group-port-42" filtered out as a firewall tag.
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue