@Override protected void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes) { for (NodeMetadata deadNode : deadNodes) { cleanupResources.apply(deadNode); } }
@Override public void destroyNode(String id) { checkState(cleanupServer.apply(id), "server(%s) still there after deleting!?", id); }
private NovaSecurityGroupInRegionToSecurityGroup createGroupParser() { NovaSecurityGroupInRegionToSecurityGroup parser = new NovaSecurityGroupInRegionToSecurityGroup(locationIndex); return parser; } }
@Test public void testWhenComputeServiceSaysAllNodesAreDeadNoGroupsAreReturned() { ServerInZone withoutHost = new ServerInZone(new ServerInZoneToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1"); ServerInZone withHost = new ServerInZone(new ParseServerTest().expected(), "az-1.region-a.geo-1"); ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata( NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention); Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost)); assertEquals(new OrphanedGroupsByZoneId(Predicates.<ZoneAndName> alwaysFalse()).apply(set), ImmutableMultimap .<String, String> of()); } }
@Test public void testWhenComputeServiceSaysAllNodesAreDeadNoGroupsAreReturned() { ServerInRegion withoutHost = new ServerInRegion(new ServerInRegionToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1"); ServerInRegion withHost = new ServerInRegion(new ParseServerTest().expected(), "az-1.region-a.geo-1"); ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata( NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention); Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost)); assertEquals(new OrphanedGroupsByRegionId(Predicates.<RegionAndName> alwaysFalse()).apply(set), ImmutableMultimap .<String, String> of()); } }
private void removeFloatingIpFromNodeifAny(RegionAndId regionAndId) { try { removeFloatingIpFromNodeAndDeallocate.apply(regionAndId); } catch (RuntimeException e) { logger.warn(e, "<< error removing and deallocating ip from node(%s): %s", regionAndId, e.getMessage()); } }
@Test(expectedExceptions = IllegalStateException.class) public void testConversionWhereLocationNotFound() { UUID id = UUID.randomUUID(); Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).build(); OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86", "My Test OS", true); ImageInZoneToImage converter = new ImageInZoneToImage(NovaComputeServiceContextModule.toPortableImageStatus, constant(operatingSystem), locationIndex); ImageInZone novaImageInZoneToConvert = new ImageInZone(novaImageToConvert, "South"); converter.apply(novaImageInZoneToConvert); }
@Test(expectedExceptions = IllegalStateException.class) public void testConversionWhereLocationNotFound() { UUID id = UUID.randomUUID(); Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).build(); OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86", "My Test OS", true); ImageInRegionToImage converter = new ImageInRegionToImage(NovaComputeServiceContextModule.toPortableImageStatus, constant(operatingSystem), locationIndex); ImageInRegion novaImageInRegionToConvert = new ImageInRegion(novaImageToConvert, "South"); converter.apply(novaImageInRegionToConvert); }
@Override public Boolean apply(NodeMetadata node) { final RegionAndId regionAndId = RegionAndId.fromSlashEncoded(node.getId()); removeFloatingIpFromNodeifAny(regionAndId); return removeSecurityGroupCreatedByJcloudsAndInvalidateCache(node.getTags()); }
@Override public SecurityGroup getSecurityGroupById(String id) { RegionAndId regionAndId = RegionAndId.fromSlashEncoded(checkNotNull(id, "id")); String region = regionAndId.getRegion(); String groupId = regionAndId.getId(); SecurityGroupApi securityGroupApi = getSecurityGroupApi(region); Location location = locationIndex.get().get(region); return neutronSecurityGroupToSecurityGroup.create(location).apply(securityGroupApi.getSecurityGroup(groupId)); }
protected Hardware findHardwareForServerOrNull(ServerInZone serverInZone) { return findObjectOfTypeForServerOrNull(hardwares.get(), "hardware", serverInZone.getServer().getFlavor().getId(), serverInZone); }
public boolean removeSecurityGroupCreatedByJcloudsAndInvalidateCache(Set<String> tags) { String securityGroupIdCreatedByJclouds = getSecurityGroupIdCreatedByJclouds(tags); if (securityGroupIdCreatedByJclouds == null) return true; return securityGroupExtension.removeSecurityGroup(securityGroupIdCreatedByJclouds); }
@Test public void testWhenComputeServiceSaysAllNodesAreDeadBothGroupsAreReturned() { ServerInZone withoutHost = new ServerInZone(new ServerInZoneToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1"); ServerInZone withHost = new ServerInZone(new ParseServerTest().expected(), "az-1.region-a.geo-1"); ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata( NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention); Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost)); assertEquals(new OrphanedGroupsByZoneId(Predicates.<ZoneAndName> alwaysTrue()).apply(set), ImmutableMultimap .<String, String> builder().putAll("az-1.region-a.geo-1", "sample", "test").build()); }
@Test public void testWhenComputeServiceSaysAllNodesAreDeadBothGroupsAreReturned() { ServerInRegion withoutHost = new ServerInRegion(new ServerInRegionToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1"); ServerInRegion withHost = new ServerInRegion(new ParseServerTest().expected(), "az-1.region-a.geo-1"); ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata( NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention); Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost)); assertEquals(new OrphanedGroupsByRegionId(Predicates.<RegionAndName> alwaysTrue()).apply(set), ImmutableMultimap .<String, String> builder().putAll("az-1.region-a.geo-1", "sample", "test").build()); }
private void removeFloatingIpFromNodeifAny(RegionAndId regionAndId) { try { removeFloatingIpFromNodeAndDeallocate.apply(regionAndId); } catch (RuntimeException e) { logger.warn(e, "<< error removing and deallocating ip from node(%s): %s", regionAndId, e.getMessage()); } }
@Override public Boolean apply(NodeMetadata node) { final RegionAndId regionAndId = RegionAndId.fromSlashEncoded(node.getId()); removeFloatingIpFromNodeifAny(regionAndId); return removeSecurityGroupCreatedByJcloudsAndInvalidateCache(node.getTags()); }
@Override public SecurityGroup getSecurityGroupById(String id) { RegionAndId regionAndId = RegionAndId.fromSlashEncoded(checkNotNull(id, "id")); String region = regionAndId.getRegion(); String groupId = regionAndId.getId(); SecurityGroupApi securityGroupApi = getSecurityGroupApi(region); Location location = locationIndex.get().get(region); return neutronSecurityGroupToSecurityGroup.create(location).apply(securityGroupApi.getSecurityGroup(groupId)); }
@Override protected void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes) { for (NodeMetadata deadNode : deadNodes) { cleanupResources.apply(deadNode); } }
public boolean removeSecurityGroupCreatedByJcloudsAndInvalidateCache(Set<String> tags) { String securityGroupIdCreatedByJclouds = getSecurityGroupIdCreatedByJclouds(tags); if (securityGroupIdCreatedByJclouds == null) return true; return securityGroupExtension.removeSecurityGroup(securityGroupIdCreatedByJclouds); }
@Override protected void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes) { for (NodeMetadata deadNode : deadNodes) { cleanupServer.apply(deadNode.getId()); } }