public CreationResult<T,U> blockUntilComplete(Duration timeout) { if (task!=null) task.blockUntilEnded(timeout); return this; } public CreationResult<T,U> blockUntilComplete() { if (task!=null) task.blockUntilEnded(); return this; }
public CreationResult<T,U> blockUntilComplete() { if (task!=null) task.blockUntilEnded(); return this; } }
/** blocks until the task completes; does not throw */ public SshPutTaskWrapper block() { getTask().blockUntilEnded(); return this; }
/** blocks until the task completes; does not throw */ public ProcessTaskWrapper<RET> block() { getTask().blockUntilEnded(); return this; }
/** blocks until the task completes; does not throw */ public SshFetchTaskWrapper block() { getTask().blockUntilEnded(); return this; }
public static final void stop(Entity caller, Entity target, Duration timeout) { if (target != null && Entities.isManaged(target)) { boolean stopped = Entities.invokeEffector(caller, target, Startable.STOP) .blockUntilEnded(timeout); if (!stopped) { LOG.debug("{} may not have stopped. Proceeding to stop {} anyway", target, caller); } } }
@Override public void run() { if (latchTask != null) { latchTask.blockUntilEnded(); } else { log.debug("No latch task provided for UnmanageTask, falling back to fixed wait"); Time.sleep(Duration.FIVE_SECONDS); } synchronized (this) { Entities.unmanage(unmanageEntity); } } }
@Nullable @Override public Void apply(T node) { Task<Integer> task = sshTaskApply(node); Entities.submit(node, task); task.blockUntilEnded(); Integer result = task.getUnchecked(); if (result != 0) { BrooklynTaskTags.WrappedStream stream = BrooklynTaskTags.stream(task, "stderr"); final String errorMessage = String.format("%s: %s", errorDescription, stream != null ? stream.streamContents.get() : "Unexpected error"); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator((EntityLocal) node, errorKey, errorMessage); throw new RuntimeException(String.format("[Node %s] %s", node.getDisplayName(), errorMessage)); } return null; }
@Override public Boolean call() throws Exception { LOG.debug("Calling joinCluster effector on {} for {}", firstNode, member); if (member.hasJoinedCluster()) return true; String address = Preconditions.checkNotNull(getNodeAddress(member)); if (Entities.invokeEffectorWithArgs(EtcdClusterImpl.this, firstNode, EtcdNode.JOIN_ETCD_CLUSTER, name, address).blockUntilEnded(timeout)) { Duration.seconds(15).countdownTimer().waitForExpiryUnchecked(); addNode(member, name); return true; } else { return false; } } }
private Result runCommands(SshMachineLocation machine, List<String> commands, Map<String, String> env) { @SuppressWarnings({ "unchecked", "rawtypes" }) SshEffectorTasks.SshEffectorTaskFactory<Integer> etf = SshEffectorTasks.ssh(commands.toArray(new String[]{})) .environmentVariables(env) .machine(machine); ProcessTaskWrapper<Integer> job = DynamicTasks.queue(etf); job.asTask().blockUntilEnded(); return new Result(job); }
protected void waitForApplicationTasks(Entity app) { Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(brooklynMgmt.getExecutionManager(), app); getLogger().info("Waiting on " + tasks.size() + " task(s)"); for (Task<?> t : tasks) { t.blockUntilEnded(); } }
protected void waitForApplicationTasks(Entity app) { Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app); getLogger().info("Waiting on " + tasks.size() + " task(s)"); for (Task<?> t : tasks) { t.blockUntilEnded(); } }
@Test(groups="Integration") public void testBadExitCodeCaughtAndStdErrAvailable() { final ProcessTaskWrapper<?>[] sshTasks = new ProcessTaskWrapper[1]; Task<Void> call = Entities.invokeEffector(app, app, Effectors.effector(Void.class, "badExitCode") .impl(new SshEffectorBody<Void>() { @Override public Void call(ConfigBag parameters) { sshTasks[0] = queue( ssh(COMMAND_THAT_DOES_NOT_EXIST).requiringExitCodeZero() ); return null; } }).build() ); call.blockUntilEnded(); Assert.assertTrue(call.isError()); log.info("stderr gives: "+new String(sshTasks[0].getStderr())); Assert.assertTrue(new String(sshTasks[0].getStderr()).indexOf(COMMAND_THAT_DOES_NOT_EXIST) >= 0); }
public void doTestReleaseEvenIfErrorDuringStop(final Class<? extends SimulatedDriver> driver) throws Exception { MyService entity = app.addChild(EntitySpec.create(MyServiceWithCustomDriver.class) .configure(MyServiceWithCustomDriver.DRIVER_CLASS, driver)); entity.start(ImmutableList.of(loc)); Task<Void> t = entity.invoke(Startable.STOP, ImmutableMap.<String, Object>of()); t.blockUntilEnded(); assertFalse(t.isError(), "Expected parent to succeed, not fail with " + Tasks.getError(t)); Iterator<Task<?>> failures; failures = Tasks.failed(Tasks.descendants(t, true)).iterator(); Assert.assertTrue(failures.hasNext(), "Expected error in descendants"); Optional<Task<?>> stopping = Iterables.tryFind(Tasks.children(t), TaskPredicates.displayNameEqualTo("stopping")); Assert.assertTrue(stopping.isPresent(), "Could not find stopping task"); failures = Tasks.failed(Tasks.children(stopping.get())).iterator(); Assert.assertTrue(failures.hasNext(), "Expected error in child"); Throwable e = Tasks.getError(failures.next()); if (e == null || !e.toString().contains("Simulating stop error")) Assert.fail("Wrong error", e); Assert.assertEquals(loc.getAvailable(), ImmutableSet.of(machine), "Expected location to be available again"); Entities.unmanage(entity); }
public void apply(final Entity source, final Object valueIgnored) { T val = (T) attribute.getValue(); if (!readiness.apply(val)) { log.warn("Skipping {} for {} because attribute {} not ready", new Object[]{description, attribute.getEntity(), attribute.getAttribute()}); return; } final Task<Void> task = TaskBuilder.<Void>builder().displayName(description).body(runnable).build(); DynamicTasks.queueIfPossible(task).orSubmitAsync(source).asTask(); if (blockUntilEnded) { final String originalBlock = Tasks.setBlockingDetails(description); try { task.blockUntilEnded(); } finally { Tasks.setBlockingDetails(originalBlock); } } } }
@Test public void testWhenSwallowingChildrenFailureDoesNotAbortSecondaryOrFailPrimary() { Task<String> t1 = monitorableTask(null, "1", new FailCallable()); Task<String> t = Tasks.<String>builder().dynamic(true) .body(monitorableJob("main")) .add(t1).add(monitorableTask("2")).swallowChildrenFailures(true).build(); ec.submit(t); releaseAndWaitForMonitorableJob("1"); Assert.assertFalse(t.blockUntilEnded(TINY_TIME)); releaseAndWaitForMonitorableJob("2"); Assert.assertFalse(t.blockUntilEnded(TINY_TIME)); releaseMonitorableJob("main"); Assert.assertTrue(t.blockUntilEnded(TIMEOUT)); Assert.assertEquals(messages, MutableList.of("1", "2", "main")); Assert.assertTrue(stopwatch.elapsed(TimeUnit.MILLISECONDS) < TIMEOUT.toMilliseconds(), "took too long: "+stopwatch); Assert.assertFalse(t.isError()); Assert.assertTrue(t1.isError()); }
@Test public void testChildrenRunConcurrentlyWithPrimary() { Task<String> t = Tasks.<String>builder().dynamic(true) .body(monitorableJob("main")) .add(monitorableTask("1")).add(monitorableTask("2")).build(); ec.submit(t); releaseAndWaitForMonitorableJob("1"); releaseAndWaitForMonitorableJob("main"); Assert.assertFalse(t.blockUntilEnded(TINY_TIME)); releaseMonitorableJob("2"); Assert.assertTrue(t.blockUntilEnded(TIMEOUT)); Assert.assertEquals(messages, MutableList.of("1", "main", "2")); Assert.assertTrue(stopwatch.elapsed(TimeUnit.MILLISECONDS) < TIMEOUT.toMilliseconds(), "took too long: "+stopwatch); Assert.assertFalse(t.isError()); }
@Test public void testByDefaultChildrenFailureAbortsSecondaryFailsPrimaryButNotAbortsPrimary() { Task<String> t1 = monitorableTask(null, "1", new FailCallable()); Task<String> t = Tasks.<String>builder().dynamic(true) .body(monitorableJob("main")) .add(t1).add(monitorableTask("2")).build(); ec.submit(t); releaseAndWaitForMonitorableJob("1"); Assert.assertFalse(t.blockUntilEnded(TINY_TIME)); releaseMonitorableJob("main"); Assert.assertTrue(t.blockUntilEnded(TIMEOUT)); Assert.assertEquals(messages, MutableList.of("1", "main")); Assert.assertTrue(stopwatch.elapsed(TimeUnit.MILLISECONDS) < TIMEOUT.toMilliseconds(), "took too long: "+stopwatch); Assert.assertTrue(t.isError()); Assert.assertTrue(t1.isError()); }
@Test(groups={"Integration", "WIP", "Broken"}) public void testJavaWebWithMemberSpecRebind() throws Exception { Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("test-java-web-app-spec-and-db-with-function.yaml")); AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); final Application app = (Application) mgmt().getEntityManager().getEntity(assembly.getId()); Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app); for (Task<?> t: tasks) t.blockUntilEnded(); Entities.dumpInfo(app); Application app2 = rebind(app); Assert.assertEquals(app2.getChildren().size(), 2); }
/** as {@link JavaWebAppsIntegrationTest#testWithDbDeploy()} but with rebind */ @Test(groups={"Integration", "WIP", "Broken"}) public void testJavaWebAppDeployAndRebind() throws Exception { Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("java-web-app-and-db-with-function.yaml")); AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); final Application app = (Application) mgmt().getEntityManager().getEntity(assembly.getId()); Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app); for (Task<?> t: tasks) t.blockUntilEnded(); Entities.dumpInfo(app); Application app2 = rebind(app); Assert.assertEquals(app2.getChildren().size(), 2); }