@Test public void testRefreshUpdatesAtomicReferenceOnRecheckPending() { NodeMetadata pending = new NodeMetadataBuilder().id("myid").status(Status.PENDING).build(); GetNodeMetadataStrategy computeService = createMock(GetNodeMetadataStrategy.class); expect(computeService.getNode("myid")).andReturn(pending); replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicReference<NodeMetadata> reference = Atomics.newReference(pending); Assert.assertFalse(nodeRunning.apply(reference)); Assert.assertEquals(reference.get(), pending); verify(computeService); }
public void testRefreshCredentialsForNodeWhenStatementIsNullSameCredentialsAndDoesCache() { @SuppressWarnings("unchecked") Map<String, Credentials> credstore = createMock(Map.class); LoginCredentials credentials = createMock(LoginCredentials.class); expect(credstore.put("node#id", credentials)).andReturn(null); replay(credstore); NodeMetadata node = new NodeMetadataBuilder().ids("id").status(Status.RUNNING).credentials(credentials).build(); RefreshCredentialsForNode fn = new PersistNodeCredentialsModule.RefreshCredentialsForNode(credstore, null); assertEquals(node, fn.apply(node)); verify(credstore); }
@Test public void testNoUpdatesAtomicReferenceOnPass() { NodeMetadata running = new NodeMetadataBuilder().id("myid").status(Status.RUNNING).build(); GetNodeMetadataStrategy computeService = createMock(GetNodeMetadataStrategy.class); replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicReference<NodeMetadata> reference = Atomics.newReference(running); Assert.assertTrue(nodeRunning.apply(reference)); Assert.assertEquals(reference.get(), running); verify(computeService); }
public void testRefreshCredentialsForNodeWhenStatementIsNullSameCredentialsAndDoesCache() { @SuppressWarnings("unchecked") Map<String, Credentials> credstore = createMock(Map.class); LoginCredentials credentials = createMock(LoginCredentials.class); expect(credstore.put("node#id", credentials)).andReturn(null); replay(credstore); NodeMetadata node = new NodeMetadataBuilder().ids("id").status(Status.RUNNING).credentials(credentials).build(); RefreshCredentialsForNode fn = new PersistNodeCredentialsModule.RefreshCredentialsForNode(credstore, null); assertEquals(node, fn.apply(node)); verify(credstore); }
@Test public void testNoUpdatesAtomicReferenceOnPass() { NodeMetadata running = new NodeMetadataBuilder().id("myid").status(Status.RUNNING).build(); GetNodeMetadataStrategy computeService = createMock(GetNodeMetadataStrategy.class); replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); AtomicReference<NodeMetadata> reference = Atomics.newReference(running); Assert.assertTrue(nodeRunning.apply(reference)); Assert.assertEquals(reference.get(), running); verify(computeService); }
public void testRefreshCredentialsForNodeIfRanAdminAccessWhenStatementIsNullSameCredentialsAndNoCaching() { @SuppressWarnings("unchecked") Map<String, Credentials> credstore = createMock(Map.class); replay(credstore); NodeMetadata node = new NodeMetadataBuilder().ids("id").status(Status.RUNNING).build(); RefreshCredentialsForNodeIfRanAdminAccess fn = new PersistNodeCredentialsModule.RefreshCredentialsForNodeIfRanAdminAccess( credstore, null); assertEquals(node, fn.apply(node)); verify(credstore); }
private void toStringAndEventBusExpectations(SudoAwareInitManager commandRunner, InitScript initScript) { toStringExpectations(commandRunner, initScript); expect(commandRunner.getStatement()).andReturn(initScript); expect(commandRunner.getNode()).andReturn( new NodeMetadataBuilder().ids("id").status(NodeMetadata.Status.RUNNING).build()); }
@Test public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationNotFound() throws UnknownHostException { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); assertEquals(parser.apply(server).toString(), new NodeMetadataBuilder().hostname("ip-10-243-42-70").status(Status.RUNNING).backendStatus("running") .publicAddresses(ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")) .publicAddresses(ImmutableSet.of("174.129.81.68")).imageId("us-east-1/ami-82e4b5c7") .id("us-east-1/i-0799056f").providerId("i-0799056f").build().toString()); }
@Test public void testApplyWhereTagDoesntMatchAndLocationFoundAndImageAndHardwareNotFound() throws UnknownHostException { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet.of(provider), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); NodeMetadata expected = new NodeMetadataBuilder().hostname("ip-10-243-42-70").status(Status.RUNNING).backendStatus("running") .privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")) .imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f") .location(provider).build(); assertEquals(parser.apply(server).toString(), expected.toString()); }
@Test public void testApplyWhereTagDoesntMatchAndLocationFoundAndImageAndHardwareNotFound() throws UnknownHostException { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet.of(provider), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()); RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); NodeMetadata expected = new NodeMetadataBuilder().hostname("ip-10-243-42-70").status(Status.RUNNING).backendStatus("running") .privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")) .imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f") .location(provider).build(); assertEquals(parser.apply(server).toString(), expected.toString()); }
@Test public void testPrivateIpAddressIncorrectlyInPublicAddressFieldGoesToPrivateAddressCollection() { RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").ipAddress("10.1.1.1").build(); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()); assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").publicAddresses( ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.1.1.1")).id("us-east-1/id").imageId( "us-east-1/image").providerId("id").build().toString()); }
@Test public void testPublicIpAddressIncorrectlyInPrivateAddressFieldGoesToPublicAddressCollection() { RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").privateIpAddress("1.1.1.1").build(); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet .<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of()); assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").privateAddresses( ImmutableSet.<String> of()).publicAddresses(ImmutableSet.of("1.1.1.1")).id("us-east-1/id").imageId( "us-east-1/image").providerId("id").build().toString()); }
@Test(expectedExceptions = IllegalStateException.class) public void testWithoutInitThrowsIllegalStateException() { Statement command = exec("doFoo"); NodeMetadata node = new NodeMetadataBuilder().ids("id").status(Status.RUNNING).credentials( LoginCredentials.builder().user("tester").password("notalot").build()).build(); SshClient sshClient = createMock(SshClient.class); replay(sshClient); RunScriptOnNodeAsInitScriptUsingSsh testMe = new RunScriptOnNodeAsInitScriptUsingSsh(Functions .forMap(ImmutableMap.of(node, sshClient)), eventBus, InitScriptConfigurationForTasks.create() .appendIncrementingNumberToAnonymousTaskNames(), node, command, new RunScriptOptions()); testMe.call(); }
@Override protected NodeMetadata newNode(String group, Template template) { NodeMetadata result = new NodeMetadataBuilder() .id("myid") .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build()) .loginPort(22) .status(Status.RUNNING) .publicAddresses(publicAddresses) .privateAddresses(privateAddresses) .build(); return result; } };
@Override protected NodeMetadata newNode(String group, Template template) { NodeMetadata result = new NodeMetadataBuilder() .id("myid") .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build()) .loginPort(22) .status(Status.RUNNING) .publicAddresses(publicAddresses) .privateAddresses(privateAddresses) .build(); return result; } };
protected AbstractNodeCreator newNodeCreator(final List<String> publicAddresses, final List<String> privateAddresses) { NodeMetadata node = new NodeMetadataBuilder() .id("myid-1") .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build()) .loginPort(22) .status(Status.RUNNING) .publicAddresses(publicAddresses) .privateAddresses(privateAddresses) .build(); return new SingleNodeCreator(node); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }