/** as {@link Machines#findUniqueMachineLocation(Iterable)} */ public static Maybe<MachineLocation> findUniqueMachineLocation(Iterable<? extends Location> locations) { return Machines.findUniqueMachineLocation(locations); }
/** as {@link Machines#findUniqueSshMachineLocation(Iterable)} */ public static Maybe<SshMachineLocation> findUniqueSshMachineLocation(Iterable<? extends Location> locations) { return Machines.findUniqueMachineLocation(locations, SshMachineLocation.class); }
/** * @deprecated since 0.9.0; see {@link #findUniqueMachineLocation(Iterable, Class)}, * e.g. {@code findUniqueMachineLocation(locations, SshMachineLocation.class)} */ @Deprecated public static Maybe<SshMachineLocation> findUniqueSshMachineLocation(Iterable<? extends Location> locations) { return findUniqueMachineLocation(locations, SshMachineLocation.class); }
@Override public SshMachineLocation get() { return Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).get(); } }
/** Finds a unique {@link MachineLocation} attached to the supplied entity * @throws IllegalStateException if there is not a unique such {@link SshMachineLocation} */ public static <T extends MachineLocation> T getMachine(Entity entity, Class<T> clazz) { try { return Machines.findUniqueMachineLocation(entity.getLocations(), clazz).get(); } catch (Exception e) { throw new IllegalStateException("Entity "+entity+" (in "+Tasks.current()+") requires a single " + clazz.getName() + ", but has "+entity.getLocations(), e); } }
@Test public void testFindUniqueMachineLocation() throws Exception { SshMachineLocation l1 = create(sshMachineSpec); LocalhostMachineProvisioningLocation l2 = create(otherLocSpec); assertEquals(Machines.findUniqueMachineLocation(ImmutableList.of(l1, l2)).get(), l1); assertFalse(Machines.findUniqueMachineLocation(ImmutableList.of(l2)).isPresent()); }
@Test public void testFindUniqueMachineLocationOfType() throws Exception { SshMachineLocation l1 = create(sshMachineSpec); LocalhostMachineProvisioningLocation l2 = create(otherLocSpec); assertEquals(Machines.findUniqueMachineLocation(ImmutableList.of(l1, l2), SshMachineLocation.class).get(), l1); assertFalse(Machines.findUniqueMachineLocation(ImmutableList.of(l2), LocalhostMachine.class).isPresent()); }
public void init(String marathonHostIp, MesosCluster cluster) { this.marathonHostname = marathonHostIp; this.cluster = cluster; this.portmap = MutableMap.of(); this.slave = cluster.getMesosSlave(marathonHostname); Maybe<SshMachineLocation> machine = Machines.findUniqueMachineLocation(slave.getLocations(), SshMachineLocation.class); this.host = machine.get(); }
public static Maybe<String> findSubnetHostname(Iterable<? extends Location> ll) { Maybe<MachineLocation> l = findUniqueMachineLocation(ll); if (!l.isPresent()) { return Maybe.absent(); // throw new IllegalStateException("Cannot find hostname for among "+ll); } return Machines.getSubnetHostname(l.get()); }
@Override protected void connectSensors() { super.connectSensors(); Maybe<SshMachineLocation> location = Machines.findUniqueMachineLocation(getLocations(), SshMachineLocation.class); if (location.isPresent() && location.get().getOsDetails().isLinux()) { LOG.info("Adding machine metrics feed"); machineMetrics = AddMachineMetrics.createMachineMetricsFeed(this); } else { LOG.warn("Not adding machine metrics feed as no suitable location available on entity"); } }
public static Maybe<String> findSubnetIp(Iterable<? extends Location> ll) { // TODO Or if can't find MachineLocation, should we throw new IllegalStateException("Cannot find hostname for among "+ll); Maybe<MachineLocation> l = findUniqueMachineLocation(ll); return (l.isPresent()) ? Machines.getSubnetIp(l.get()) : Maybe.<String>absent(); }
@Override @SuppressWarnings("unchecked") public T call() throws Exception { Maybe<WinRmMachineLocation> machineLocationMaybe = Machines.findUniqueMachineLocation(entity.getLocations(), WinRmMachineLocation.class); if (machineLocationMaybe.isAbsent()) { return null; } WinRmMachineLocation machine = EffectorTasks.getMachine(entity, WinRmMachineLocation.class); WinRmToolResponse response = machine.executePsScript(command); return (T)response; } }
private Collection<String> locationsToAddresses(int port, Collection<Entity> entities) { Set<String> result = MutableSet.of(); for (Entity e : entities) { SshMachineLocation machine = Machines.findUniqueMachineLocation(e.getLocations(), SshMachineLocation.class).get(); result.add(machine.getAddress().getHostName()+":"+port); } return result; }
@Override public void stop() { Maybe<MachineLocation> machine = Machines.findUniqueMachineLocation(getLocations(), MachineLocation.class); if (provisioner != null) { provisioner.release(machine.get()); } } }
@Override public MachineDetails call(ConfigBag parameters) { Maybe<MachineLocation> machine = Machines.findUniqueMachineLocation(entity().getLocations()); try { machine.get().getMachineDetails(); throw new IllegalStateException("Expected failure in ssh"); } catch (RuntimeException e) { return null; } }}) .build();
@Override protected JcloudsMachineLocation obtainMachine(JcloudsLocation jcloudsLoc, Map<?,?> props) throws Exception { final MachineEntity entity = (MachineEntity) Iterables.getOnlyElement(origApp.getChildren()); origApp.invoke(Startable.START, ImmutableMap.<String, Object>of()).get(); // Execute ssh (with RecordingSshTool), and confirm was given resolved password entity.execCommand("mycmd"); Map<?, ?> constructorProps = RecordingSshTool.getLastConstructorProps(); ExecCmd execCmd = RecordingSshTool.getLastExecCmd(); assertEquals(constructorProps.get("password"), "myYamlPassword", "constructorProps: "+constructorProps+"; execProps: "+execCmd.props); return Machines.findUniqueMachineLocation(entity.getLocations(), JcloudsMachineLocation.class).get(); } }
public static Maybe<String> findSubnetOrPrivateIp(Entity entity) { // see comments in findSubnetOrPrivateHostname String hn = entity.getAttribute(Attributes.ADDRESS); if (hn!=null) { Maybe<String> sn = findSubnetIp(entity); if (sn.isPresent()) return sn; return Maybe.of(hn); } Maybe<MachineLocation> l = findUniqueMachineLocation(entity.getLocations()); if (!l.isPresent()) return Maybe.absent(); InetAddress addr = l.get().getAddress(); if (addr==null) return Maybe.absent(); return Maybe.fromNullable(addr.getHostAddress()); }
public void run() { Entity entity = privatePort.getEntity(); Integer privatePortVal = privatePort.getValue(); MachineLocation machine = Machines.findUniqueMachineLocation(entity.getLocations()).get(); HostAndPort publicEndpoint = portForwarder.openPortForwarding(machine, privatePortVal, optionalPublicPort, protocol, accessingCidr); // TODO What publicIpId to use in portForwardManager.associate? Elsewhere, uses jcloudsMachine.getJcloudsId(). portForwarder.getPortForwardManager().associate(machine.getId(), publicEndpoint, machine, privatePortVal); whereToAdvertiseEndpoint.setValue(publicEndpoint.getHostText()+":"+publicEndpoint.getPort()); }}; }
@Override public void run() { // Nginx URL is available MachineLocation machine = Machines.findUniqueMachineLocation(nginx.getLocations()).get(); String url = "http://" + machine.getAddress().getHostName() + ":" + nginx.getAttribute(NginxController.PROXY_HTTP_PORT) + "/swf-booking-mvc"; HttpTestUtils.assertHttpStatusCodeEquals(url, 200); // Web-app URL is available for (Entity member : cluster.getMembers()) { HttpTestUtils.assertHttpStatusCodeEquals(member.getAttribute(JavaWebAppService.ROOT_URL) + "swf-booking-mvc", 200); } }});
@Test(groups = {"Live"}) public void testSetFixedHostname() throws Exception { SetHostnameCustomizer customizer = new SetHostnameCustomizer(ConfigBag.newInstance() .configure(SetHostnameCustomizer.FIXED_HOSTNAME, "myhostname")); MachineEntity entity = app.createAndManageChild(EntitySpec.create(MachineEntity.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true) .configure(MachineEntity.PROVISIONING_PROPERTIES.subKey(JcloudsLocation.MACHINE_LOCATION_CUSTOMIZERS.getName()), ImmutableSet.of(customizer)) .configure(MachineEntity.PROVISIONING_PROPERTIES.subKey(JcloudsLocation.IMAGE_ID.getName()), PROVIDER_IMAGE_ID)); app.start(ImmutableList.of(loc)); SshMachineLocation machine = Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).get(); assertEquals(getHostname(machine), "myhostname"); }