@Override public NodeMetadata apply(NodeMetadata arg0) { return credentialStore.containsKey("node#" + arg0.getId()) ? NodeMetadataBuilder.fromNodeMetadata(arg0) .credentials(LoginCredentials.fromCredentials(credentialStore.get("node#" + arg0.getId()))).build() : arg0; }
@Override public NodeMetadata apply(NodeMetadata arg0) { return credentialStore.containsKey("node#" + arg0.getId()) ? NodeMetadataBuilder.fromNodeMetadata(arg0) .credentials(LoginCredentials.fromCredentials(credentialStore.get("node#" + arg0.getId()))).build() : arg0; }
@Override public NodeMetadata apply(NodeMetadata input) { if (statement == null) return input; Credentials credentials = CredentialsFromAdminAccess.INSTANCE.apply(statement); if (credentials != null) { LoginCredentials creds = LoginCredentials.fromCredentials(credentials); input = NodeMetadataBuilder.fromNodeMetadata(input).credentials(creds).build(); credentialStore.put("node#" + input.getId(), input.getCredentials()); } return input; }
@Override public NodeMetadata apply(NodeMetadata input) { if (statement == null) return input; Credentials credentials = CredentialsFromAdminAccess.INSTANCE.apply(statement); if (credentials != null) { LoginCredentials creds = LoginCredentials.fromCredentials(credentials); input = NodeMetadataBuilder.fromNodeMetadata(input).credentials(creds).build(); credentialStore.put("node#" + input.getId(), input.getCredentials()); } return input; }
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 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); }
@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 testReturnsNodeWithIpWhenFoundInCacheAndNodeHadNoPublicIp() throws Exception { RegionAndName key = new RegionAndName("us-east-1", node.getProviderId()); String val = "1.1.1.1"; LoadingCache<RegionAndName, String> cache = cacheOf(key, val); AddElasticIpsToNodemetadata fn = new AddElasticIpsToNodemetadata(cache); assertEquals(fn.apply( NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.<String> of()).build()) .getPublicAddresses(), ImmutableSet.of("1.1.1.1")); }
protected void refreshSshIfNewAdminCredentialsConfigured(AdminAccess input) { if (input.getAdminCredentials() != null && input.shouldGrantSudoToAdminUser()) { ssh.disconnect(); logger.debug(">> reconnecting as %s@%s", input.getAdminCredentials().identity, ssh.getHostAddress()); ssh = sshFactory.apply(node = NodeMetadataBuilder.fromNodeMetadata(node) .credentials(LoginCredentials.fromCredentials(input.getAdminCredentials())).build()); ssh.connect(); setupLinkToInitFile(); } }
protected void refreshSshIfNewAdminCredentialsConfigured(AdminAccess input) { if (input.getAdminCredentials() != null && input.shouldGrantSudoToAdminUser()) { ssh.disconnect(); logger.debug(">> reconnecting as %s@%s", input.getAdminCredentials().identity, ssh.getHostAddress()); ssh = sshFactory.apply(node = NodeMetadataBuilder.fromNodeMetadata(node) .credentials(LoginCredentials.fromCredentials(input.getAdminCredentials())).build()); ssh.connect(); setupLinkToInitFile(); } }
protected void refreshSshIfNewAdminCredentialsConfigured(AdminAccess input) { if (input.getAdminCredentials() != null && input.shouldGrantSudoToAdminUser()) { ssh.disconnect(); logger.debug(">> reconnecting as %s@%s", input.getAdminCredentials().identity, ssh.getHostAddress()); ssh = sshFactory.apply(node = NodeMetadataBuilder.fromNodeMetadata(node) .credentials(LoginCredentials.fromCredentials(input.getAdminCredentials())).build()); ssh.connect(); setupLinkToInitFile(); } }
@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; } };
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); }