public Maybe<SshMachineLocation> getMachine() { return Locations.findUniqueSshMachineLocation(entity.getLocations()); }
private boolean isMachineStopped() { // Don't rely on effector parameters, check if there is still a machine running. // If the entity was previously stopped with STOP_MACHINE_MODE=StopMode.NEVER // and a second time with STOP_MACHINE_MODE=StopMode.IF_NOT_STOPPED, then the // machine is still running, but there is no deterministic way to infer this from // the parameters alone. return Locations.findUniqueSshMachineLocation(this.getLocations()).isAbsent(); }
@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { app = TestApplication.Factory.newManagedInstanceForTests(); entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).location(TestApplication.LOCALHOST_MACHINE_SPEC)); machine = Locations.findUniqueSshMachineLocation(entity.getLocations()).get(); app.start(ImmutableList.<Location>of()); tempFile = File.createTempFile("testSshCommand", ".txt"); }
@Override protected void doTest(Location loc) throws Exception { Entity testEntity = app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class)); app.start(ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually(MutableMap.of("timeout", TIMEOUT_MS), testEntity, Startable.SERVICE_UP, true); SshMachineLocation sshLoc = Locations.findUniqueSshMachineLocation(testEntity.getLocations()).get(); MachineDetails machine = app.getExecutionContext() .submit(BasicMachineDetails.taskForSshMachineLocation(sshLoc)) .getUnchecked(); LOG.info("Found the following at {}: {}", loc, machine); assertNotNull(machine); OsDetails details = machine.getOsDetails(); assertNotNull(details); assertNotNull(details.getArch()); assertNotNull(details.getName()); assertNotNull(details.getVersion()); assertFalse(details.getArch().startsWith("architecture:")); assertFalse(details.getName().startsWith("name:")); assertFalse(details.getVersion().startsWith("version:")); } }
@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { app = TestApplication.Factory.newManagedInstanceForTests(); entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).location(TestApplication.LOCALHOST_MACHINE_SPEC)); machine = Locations.findUniqueSshMachineLocation(entity.getLocations()).get(); app.start(ImmutableList.<Location>of()); }
@Override protected void doTest(Location loc) throws Exception { Entity testEntity = app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class)); app.start(ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually(testEntity, Startable.SERVICE_UP, true); SshMachineLocation sshLoc = Locations.findUniqueSshMachineLocation(testEntity.getLocations()).get(); MachineDetails machine = app.getExecutionContext() .submit(BasicMachineDetails.taskForSshMachineLocation(sshLoc)) .getUnchecked(); LOG.info("Found the following at {}: {}", loc, machine); assertNotNull(machine); OsDetails details = machine.getOsDetails(); assertNotNull(details); assertNotNull(details.getArch()); assertNotNull(details.getName()); assertNotNull(details.getVersion()); assertFalse(details.getArch().startsWith("architecture:")); assertFalse(details.getName().startsWith("name:")); assertFalse(details.getVersion().startsWith("version:")); } }
protected void connectSensors() { sensors().set(DATASTORE_URL, String.format("postgresql://%s:%s/", getAttribute(HOSTNAME), getAttribute(POSTGRESQL_PORT))); Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(getLocations()); if (machine.isPresent()) { feed = SshFeed.builder() .entity(this) .machine(machine.get()) .poll(new SshPollConfig<Boolean>(SERVICE_UP) .command("ps -ef | grep [p]ostgres") .setOnSuccess(true) .setOnFailureOrException(false)) .build(); } else { LOG.warn("Location(s) {} not an ssh-machine location, so not polling for status; setting serviceUp immediately", getLocations()); } }
loc.removeMachine(Locations.findUniqueSshMachineLocation(entity.getLocations()).get());
public String callMany(Collection<Entity> targets, ConfigBag params) { TaskBuilder<Object> ptb = Tasks.builder().parallel(true).displayName("effector "+effector.getName()+" ssh to targets"); for (Entity target: targets) { if (Entities.isNoLongerManaged(target)) continue; Lifecycle state = target.getAttribute(Attributes.SERVICE_STATE_ACTUAL); if (state==Lifecycle.STOPPING || state==Lifecycle.STOPPED) continue; Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(target.getLocations()); if (machine.isAbsent()) continue; SshEffectorTaskFactory<String> t = makePartialTaskFactory(params, target); t.summary("effector "+effector.getName()+" at "+target); t.machine( machine.get() ); ptb.add(t.newTask()); } queue(ptb.build()).getUnchecked(); return null; }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { // Don't let any defaults from brooklyn.properties (except credentials) interfere with test brooklynProperties = BrooklynProperties.Factory.newDefault(); brooklynProperties.remove("brooklyn.jclouds."+PROVIDER+".image-description-regex"); brooklynProperties.remove("brooklyn.jclouds."+PROVIDER+".image-name-regex"); brooklynProperties.remove("brooklyn.jclouds."+PROVIDER+".image-id"); brooklynProperties.remove("brooklyn.jclouds."+PROVIDER+".inboundPorts"); brooklynProperties.remove("brooklyn.jclouds."+PROVIDER+".hardware-id"); // Also removes scriptHeader (e.g. if doing `. ~/.bashrc` and `. ~/.profile`, then that can cause "stdin: is not a tty") brooklynProperties.remove("brooklyn.ssh.config.scriptHeader"); mgmt = new LocalManagementContextForTests(brooklynProperties); super.setUp(); Map<String,?> allFlags = MutableMap.<String,Object>builder() .put("tags", ImmutableList.of(getClass().getName())) .putAll(ImmutableMap.of("imageId", UBUNTU_12, "loginUser", "ubuntu", "hardwareId", "m1.small")) .build(); loc = mgmt.getLocationRegistry().getLocationManaged(LOCATION_SPEC, allFlags); testEntity = app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class)); app.start(ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually(MutableMap.of("timeout", TIMEOUT_MS), testEntity, Startable.SERVICE_UP, true); SshMachineLocation sshLoc = Locations.findUniqueSshMachineLocation(testEntity.getLocations()).get(); jcloudsMachineLocation = (JcloudsMachineLocation)sshLoc; computeService = jcloudsMachineLocation.getParent().getComputeService(); }
Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(getLocations());
Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(getLocations()); boolean retrieveUsageMetrics = getConfig(RETRIEVE_USAGE_METRICS);