public Task<?> destroy(final Application application) { return mgmt.getExecutionManager().submit(new Runnable() { @Override public void run() { ((EntityInternal)application).destroy(); mgmt.getEntityManager().unmanage(application); } }); }
public static Set<Task<?>> getTasksInEntityContext(ExecutionManager em, Entity e) { return em.getTasksWithTag(tagForContextEntity(e)); }
/** returns tasks started by this context (or tasks which have all the tags on this object) */ public Set<Task<?>> getTasks() { return executionManager.getTasksWithAllTags((Set<?>)tags); }
@Override public Iterable<TaskSummary> children(String taskId) { Task<?> t = mgmt().getExecutionManager().getTask(taskId); if (t==null) throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); if (!(t instanceof HasTaskChildren)) return Collections.emptyList(); return Collections2.transform(Lists.newArrayList(((HasTaskChildren)t).getChildren()), TaskTransformer.FROM_TASK); }
private boolean isActive() { return running && persister != null && !executionManager.isShutdown(); }
@Override public TaskSummary get(String taskId) { Task<?> t = mgmt().getExecutionManager().getTask(taskId); if (t==null) throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); return TaskTransformer.FROM_TASK.apply(t); }
@Override public void onItemRemoved(final Item item) { executor.submit(MutableMap.of("tag", delegate), new Runnable() { public void run() { try { delegate.onItemRemoved(item); } catch (Throwable t) { LOG.warn("Error notifying listener of itemAdded("+item+")", t); Exceptions.propagate(t); } } }); }
@Override public TaskSummary getTask(final String application, final String entityToken, String taskId) { // TODO deprecate in favour of ActivityApi.get ? Task<?> t = mgmt().getExecutionManager().getTask(taskId); if (t==null) throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); return TaskTransformer.FROM_TASK.apply(t); }
@GET @ApiOperation( value = "Fetch list of activities for this application" ) public Iterable<TaskSummary> list(@PathParam("application") String applicationId, @PathParam("entity") String entityId) { Entity entity = brooklyn().getEntity(applicationId, entityId); Set<Task<?>> tasks = mgmt().getExecutionManager().getTasksWithTag(entity); return Collections2.transform(tasks, TaskSummary.FROM_TASK); }
@Override public void onItemAdded(final Item item) { executor.submit(MutableMap.of("tag", delegate), new Runnable() { public void run() { try { delegate.onItemAdded(item); } catch (Throwable t) { LOG.warn("Error notifying listener of itemAdded("+item+")", t); Exceptions.propagate(t); } } }); }
public String stream(String taskId, String streamId) { Task<?> t = mgmt().getExecutionManager().getTask(taskId); if (t==null) throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); WrappedStream stream = BrooklynTasks.stream(t, streamId); if (stream==null) throw WebResourceUtils.notFound("Cannot find stream '%s' in task '%s'", streamId, taskId); return stream.streamContents.get(); }
public BasicBrooklynCatalog(final ManagementContext mgmt, final CatalogDto dto) { this.mgmt = Preconditions.checkNotNull(mgmt, "managementContext"); this.catalog = new CatalogDo(dto); mgmt.getExecutionManager().submit(MutableMap.of("name", "loading catalog"), new Runnable() { public void run() { log.debug("Loading catalog for "+mgmt); catalog.load(mgmt, null); if (log.isDebugEnabled()) log.debug("Loaded catalog for "+mgmt+": "+catalog+"; search classpath is "+catalog.getRootClassLoader()); } }); }
@GET @Path("/{task}") @ApiOperation(value = "Fetch task details", responseClass = "brooklyn.rest.domain.TaskSummary") @ApiErrors(value = { @ApiError(code = 404, reason = "Could not find application, entity or task") }) @Produces("text/json") public TaskSummary get( @ApiParam(value = "Application ID or name", required = true) @PathParam("application") final String application, @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") final String entityToken, @ApiParam(value = "Task ID", required = true) @PathParam("task") String taskId ) { // final EntityLocal entity = brooklyn().getEntity(application, entityToken); // no entity checking done/needed // (should API be refactored to be a top-level?) Task<?> t = mgmt().getExecutionManager().getTask(taskId); if (t==null) throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); return TaskSummary.FROM_TASK.apply(t); }
public Task<?> destroy(final Application application) { return mgmt.getExecutionManager().submit( MutableMap.of("displayName", "destroying "+application, "description", "REST call to destroy application "+application.getDisplayName()+" ("+application+")"), new Runnable() { @Override public void run() { ((EntityInternal)application).destroy(); mgmt.getEntityManager().unmanage(application); } }); }
public PeriodicDeltaChangeListener(ExecutionManager executionManager, BrooklynMementoPersister persister, long periodMillis) { this.executionManager = executionManager; this.persister = persister; Callable<Task<?>> taskFactory = new Callable<Task<?>>() { @Override public Task<Void> call() { return new BasicTask<Void>(new Callable<Void>() { public Void call() { try { persistNow(); return null; } catch (Exception e) { // Don't rethrow: the behaviour of executionManager is different from a scheduledExecutorService, // if we throw an exception, then our task will never get executed again LOG.warn("Problem persisting change-delta", e); return null; } catch (Throwable t) { LOG.warn("Problem persisting change-delta (rethrowing)", t); throw Throwables.propagate(t); } }}); } }; ScheduledTask scheduledTask = new ScheduledTask(taskFactory).period(periodMillis); executionManager.submit(scheduledTask); }
@SuppressWarnings("deprecation") protected void submitIfNecessary(TaskAdaptable<?> task) { if (!task.asTask().isSubmitted()) { if (BasicExecutionContext.getCurrentExecutionContext() == null) { if (em!=null) { log.warn("Discouraged submission of compound task ({}) from {} without execution context; using execution manager", task, this); em.submit(task); } else { throw new IllegalStateException("Compound task ("+task+") launched from "+this+" missing required execution context"); } } else { BasicExecutionContext.getCurrentExecutionContext().submit(task); } } }
continue; final Subscription sAtClosureCreation = s; em.submit(mapOf("tag", s.subscriberExecutionManagerTag), new Runnable() { public void run() { sAtClosureCreation.listener.onEvent(event);
}}); return executionManager.submit(properties, task);