@Test public void testCustomizerIgnoresNonMatchingMachine() throws Exception { SshMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocationThrowsException.class) .configure("address", "4.3.2.1")); customizer = new SetHostnameCustomizer(ConfigBag.newInstance() .configure(SetHostnameCustomizer.MACHINE_FILTER, Predicates.not(Predicates.<MachineLocation>equalTo(machine)))); customizer.customize(machine); }
@Override public void customize(MachineLocation machine) { if (config.get(MACHINE_FILTER).apply(machine)) { log.info("SetHostnameCustomizer setting hostname on "+machine); } else { log.info("SetHostnameCustomizer ignoring non-ssh machine "+machine); return; } try { String localHostname = setLocalHostname((SshMachineLocation) machine); machine.config().set(LOCAL_HOSTNAME, localHostname); String localIp = execHostnameMinusI((SshMachineLocation) machine); machine.config().set(LOCAL_IP, localIp); } catch (Exception e) { log.info("SetHostnameCustomizer failed to set hostname on "+machine+" (rethrowing)", e); throw e; } }
SetHostnameCustomizer extends BasicMachineLocationCustomizer { @Override public void customize(MachineLocation machine) { if (config.get(MACHINE_FILTER).apply(machine)) { log.info("SetHostnameCustomizer setting hostname on "+machine); } else { log.info("SetHostnameCustomizer ignoring non-ssh machine "+machine); return; } try { String localHostname = setLocalHostname((SshMachineLocation) machine); machine.config().set(LOCAL_HOSTNAME, localHostname); String localIp = execHostnameMinusI((SshMachineLocation) machine); machine.config().set(LOCAL_IP, localIp); } catch (Exception e) { log.info("SetHostnameCustomizer failed to set hostname on "+machine+" (rethrowing)", e); throw e; } } }
SetHostnameCustomizer extends BasicMachineLocationCustomizer { @Override public void customize(MachineLocation machine) { if (config.get(MACHINE_FILTER).apply(machine)) { log.info("SetHostnameCustomizer setting hostname on "+machine); } else { log.info("SetHostnameCustomizer ignoring non-ssh machine "+machine); return; } try { String localHostname = setLocalHostname((SshMachineLocation) machine); machine.config().set(LOCAL_HOSTNAME, localHostname); String localIp = execHostnameMinusI((SshMachineLocation) machine); machine.config().set(LOCAL_IP, localIp); } catch (Exception e) { log.info("SetHostnameCustomizer failed to set hostname on "+machine+" (rethrowing)", e); throw e; } } SetHostnameCustomizer(ConfigBag config); }
SetHostnameCustomizer extends BasicMachineLocationCustomizer { @Override public void customize(MachineLocation machine) { if (config.get(MACHINE_FILTER).apply(machine)) { log.info("SetHostnameCustomizer setting hostname on "+machine); } else { log.info("SetHostnameCustomizer ignoring non-ssh machine "+machine); return; } try { String localHostname = setLocalHostname((SshMachineLocation) machine); machine.config().set(LOCAL_HOSTNAME, localHostname); String localIp = execHostnameMinusI((SshMachineLocation) machine); machine.config().set(LOCAL_IP, localIp); } catch (Exception e) { log.info("SetHostnameCustomizer failed to set hostname on "+machine+" (rethrowing)", e); throw e; } } SetHostnameCustomizer(ConfigBag config); @Override void customize(MachineLocation machine); String setLocalHostname(SshMachineLocation machine); String setLocalHostname(SshMachineLocation machine, String hostName, String domainFixed); }
SetHostnameCustomizer extends BasicMachineLocationCustomizer { @Override public void customize(MachineLocation machine) { if (config.get(MACHINE_FILTER).apply(machine)) { log.info("SetHostnameCustomizer setting hostname on "+machine); } else { log.info("SetHostnameCustomizer ignoring non-ssh machine "+machine); return; } try { String localHostname = setLocalHostname((SshMachineLocation) machine); machine.config().set(LOCAL_HOSTNAME, localHostname); String localIp = execHostnameMinusI((SshMachineLocation) machine); machine.config().set(LOCAL_IP, localIp); } catch (Exception e) { log.info("SetHostnameCustomizer failed to set hostname on "+machine+" (rethrowing)", e); throw e; } } SetHostnameCustomizer(ConfigBag config); @Override void customize(MachineLocation machine); String setLocalHostname(SshMachineLocation machine); String setLocalHostname(SshMachineLocation machine, String hostName, String domainFixed); static final Logger log; static final ConfigKey<String> FIXED_HOSTNAME; static final ConfigKey<String> FIXED_DOMAIN; static final ConfigKey<String> HOSTNAME_TEMPLATE; static final ConfigKey<String> LOCAL_HOSTNAME; static final ConfigKey<String> LOCAL_IP; static final ConfigKey<Predicate<? super MachineLocation>> MACHINE_FILTER; }