public void execute(Iterable<? extends NodeMetadata> deadOnes) { for (NodeMetadata node : deadOnes){ credentialStore.remove("node#" + node.getId()); } Iterable<OrgAndName> orgGroups = filter(transform(deadOnes, nodeToOrgAndName), notNull()); for (OrgAndName orgGroup : orgGroups) { Iterable<? extends NodeMetadata> nodesInOrg = listNodes.listDetailsOnNodesMatching(parentLocationId(orgGroup .getOrg().toASCIIString())); Iterable<? extends NodeMetadata> nodesInGroup = filter(nodesInOrg, inGroup(orgGroup.getName())); if (size(nodesInGroup) == 0 || all(nodesInGroup, TERMINATED)){ deleteKeyPair.execute(orgGroup); } } }
@Override public boolean apply(ZoneAndName input) { // new nodes can have the zone as their location, existing nodes, the parent is the // location return all(computeService.listNodesDetailsMatching(Predicates.<ComputeMetadata> or(locationId(input.getZone()), parentLocationId(input.getZone()))), and(inGroup(input.getName()), TERMINATED)); } }
@Override public boolean apply(RegionAndName input) { // new nodes can have the region as their location, existing nodes, the parent is the // location return all(computeService.listNodesDetailsMatching(Predicates.<ComputeMetadata> or(locationId(input.getRegion()), parentLocationId(input.getRegion()))), Predicates.and(inGroup(input.getName()), TERMINATED)); } }
@Override public boolean apply(ZoneAndName input) { // new nodes can have the zone as their location, existing nodes, the parent is the // location return all(computeService.listNodesDetailsMatching(Predicates.<ComputeMetadata> or(locationId(input.getZone()), parentLocationId(input.getZone()))), and(inGroup(input.getName()), TERMINATED)); } }
@Override public boolean apply(RegionAndName input) { // new nodes can have the region as their location, existing nodes, the parent is the // location return all(computeService.listNodesDetailsMatching(Predicates.<ComputeMetadata> or(locationId(input.getRegion()), parentLocationId(input.getRegion()))), and(inGroup(input.getName()), TERMINATED)); } }
@Override public boolean apply(ZoneAndName input) { // new nodes can have the zone as their location, existing nodes, the parent is the // location return all(computeService.listNodesDetailsMatching(Predicates.<ComputeMetadata> or(locationId(input.getZone()), parentLocationId(input.getZone()))), Predicates.and(inGroup(input.getName()), TERMINATED)); } }
@Override public boolean apply(RegionAndName input) { // new nodes can have the region as their location, existing nodes, the parent is the // location return all(computeService.listNodesDetailsMatching(Predicates.<ComputeMetadata> or(locationId(input.getRegion()), parentLocationId(input.getRegion()))), and(inGroup(input.getName()), TERMINATED)); } }
@Override public boolean apply(ZoneAndName input) { // new nodes can have the zone as their location, existing nodes, the parent is the // location return all(computeService.listNodesDetailsMatching(Predicates.<ComputeMetadata> or(locationId(input.getZone()), parentLocationId(input.getZone()))), and(inGroup(input.getName()), TERMINATED)); } }
public void testWhenNoneLeftWithTag() { // create mocks CleanupOrphanKeys strategy = setupStrategy(); NodeMetadata nodeMetadata = createMock(NodeMetadata.class); Iterable<? extends NodeMetadata> deadOnes = ImmutableSet.<NodeMetadata> of(nodeMetadata); OrgAndName orgTag = new OrgAndName(URI.create("location"), "group"); // setup expectations expect(strategy.nodeToOrgAndName.apply(nodeMetadata)).andReturn(orgTag).atLeastOnce(); expect((Object) strategy.listNodes.listDetailsOnNodesMatching(parentLocationId(orgTag.getOrg().toASCIIString()))) .andReturn(ImmutableSet.of()); strategy.deleteKeyPair.execute(orgTag); expectCleanupCredentialStore(strategy, nodeMetadata); // replay mocks replay(nodeMetadata); replayStrategy(strategy); // run strategy.execute(deadOnes); // verify mocks verify(nodeMetadata); verifyStrategy(strategy); }
public void testWhenStillRunningWithTag() { // create mocks CleanupOrphanKeys strategy = setupStrategy(); NodeMetadata nodeMetadata = createMock(NodeMetadata.class); Iterable<? extends NodeMetadata> deadOnes = ImmutableSet.<NodeMetadata> of(nodeMetadata); OrgAndName orgTag = new OrgAndName(URI.create("location"), "group"); // setup expectations expect(strategy.nodeToOrgAndName.apply(nodeMetadata)).andReturn(orgTag).atLeastOnce(); expect((Object) strategy.listNodes.listDetailsOnNodesMatching(parentLocationId(orgTag.getOrg().toASCIIString()))) .andReturn(ImmutableSet.of(nodeMetadata)); expect(nodeMetadata.getGroup()).andReturn(orgTag.getName()).atLeastOnce(); expect(nodeMetadata.getStatus()).andReturn(Status.RUNNING).atLeastOnce(); expectCleanupCredentialStore(strategy, nodeMetadata); // replay mocks replay(nodeMetadata); replayStrategy(strategy); // run strategy.execute(deadOnes); // verify mocks verify(nodeMetadata); verifyStrategy(strategy); }
public void testWhenTerminatedWithTag() { // create mocks CleanupOrphanKeys strategy = setupStrategy(); NodeMetadata nodeMetadata = createMock(NodeMetadata.class); Iterable<? extends NodeMetadata> deadOnes = ImmutableSet.<NodeMetadata> of(nodeMetadata); OrgAndName orgTag = new OrgAndName(URI.create("location"), "group"); // setup expectations expect(strategy.nodeToOrgAndName.apply(nodeMetadata)).andReturn(orgTag).atLeastOnce(); expect((Object) strategy.listNodes.listDetailsOnNodesMatching(parentLocationId(orgTag.getOrg().toASCIIString()))) .andReturn(ImmutableSet.of(nodeMetadata)); expect(nodeMetadata.getGroup()).andReturn(orgTag.getName()).atLeastOnce(); expect(nodeMetadata.getStatus()).andReturn(Status.TERMINATED).atLeastOnce(); strategy.deleteKeyPair.execute(orgTag); expectCleanupCredentialStore(strategy, nodeMetadata); // replay mocks replay(nodeMetadata); replayStrategy(strategy); // run strategy.execute(deadOnes); // verify mocks verify(nodeMetadata); verifyStrategy(strategy); }