public static <T> Task<List<T>> invokeEffectorListWithMap(Entity callingEntity, Iterable<? extends Entity> entitiesToCall, final Effector<T> effector, final Map<String,?> parameters) { return invokeEffectorList(callingEntity, entitiesToCall, effector, parameters); }
public static <T> Task<List<T>> invokeEffectorList(Entity callingEntity, Iterable<? extends Entity> entitiesToCall, final Effector<T> effector) { return invokeEffectorList(callingEntity, entitiesToCall, effector, Collections.<String,Object>emptyMap()); }
/** Invokes in parallel if multiple, but otherwise invokes the item directly. */ public static Task<?> invokeEffector(Entity callingEntity, Iterable<? extends Entity> entitiesToCall, final Effector<?> effector, final Map<String,?> parameters) { if (Iterables.size(entitiesToCall)==1) return invokeEffector(callingEntity, entitiesToCall.iterator().next(), effector, parameters); else return invokeEffectorList(callingEntity, entitiesToCall, effector, parameters); }
@Test public void testInvokeEffectorListWithEmpty() throws Exception{ Entities.invokeEffectorList(app, ImmutableList.<StartableApplication>of(), Startable.STOP).get(Duration.THIRTY_SECONDS); }
@Test public void testInvokeEffectorList() throws Exception{ List<TestEntity> entities = Lists.newArrayList(); for (int i = 0; i < 10; i++) { entities.add(app.addChild(EntitySpec.create(TestEntity.class))); } Entities.invokeEffectorList(app, entities, Startable.STOP).get(Duration.THIRTY_SECONDS); for (TestEntity entity : entities) { assertEquals(entity.getCallHistory(), ImmutableList.of("stop")); } }
})); LOG.debug("Stopping applications: {}", Iterables.toString(applications)); Entities.invokeEffectorList(this, applications, Startable.STOP).get(timeout); } catch (Exception e) { LOG.warn("Error stopping applications", e); Group frameworks = sensors().get(MESOS_FRAMEWORKS); LOG.debug("Stopping framework tasks in: {}", Iterables.toString(frameworks.getMembers())); Entities.invokeEffectorList(this, frameworks.getMembers(), Startable.STOP).get(timeout); } catch (Exception e) { LOG.warn("Error stopping frameworks", e);
Entities.invokeEffectorList(this, applications, Startable.STOP).get(timeout); } catch (Exception e) { LOG.warn("Error stopping applications", e); DynamicCluster hosts = getDockerHostCluster(); LOG.debug("Stopping hosts: {}", Iterables.toString(hosts.getMembers())); Entities.invokeEffectorList(this, hosts.getMembers(), Startable.STOP).get(timeout); } catch (Exception e) { LOG.warn("Error stopping hosts", e);
@Override public void preStop() { if (scan != null && scan.isActivated()) scan.stop(); super.preStop(); deleteLocation(); // Stop all Docker containers in parallel try { Group containers = getDockerContainerCluster(); // TODO filter out SDN containers LOG.debug("Stopping containers: {}", Iterables.toString(containers.getMembers())); Entities.invokeEffectorList(this, containers.getMembers(), Startable.STOP).get(Duration.ONE_MINUTE); } catch (Exception e) { LOG.warn("Error stopping containers", e); } EtcdNode etcd = sensors().get(ETCD_NODE); DockerUtils.stop(getInfrastructure(), etcd, Duration.THIRTY_SECONDS); }
@Override public void doStart(Collection<? extends Location> locs) { List<Location> locations = MutableList.of(); sensors().set(SERVICE_UP, Boolean.FALSE); ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); LOG.info("Creating new MesosLocation"); createLocation(MutableMap.<String, Object>of()); // Start frameworks try { Group frameworks = sensors().get(MESOS_FRAMEWORKS); Entities.invokeEffectorList(this, frameworks.getMembers(), Startable.START, ImmutableMap.of("locations", locations)).getUnchecked(); } catch (Exception e) { LOG.warn("Error starting frameworks", e); ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); Exceptions.propagate(e); } super.doStart(locations); connectSensors(); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); sensors().set(SERVICE_UP, Boolean.TRUE); }
@Test public void testInvokeEffectorListWithEmptyUsingUnmanagedContext() throws Exception { // Previously this threw the IllegalStateException directly, because DynamicTasks called // ((EntityInternal)entity).getManagementSupport().getExecutionContext(); // (so it successfully called getManagementSupport, and then hit the exception. // Now it calls ((EntityInternal)entity).getExecutionContext(), so the exception happens in // the entity-proxy and is thus wrapped. TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class)); Entities.unmanage(entity); try { Entities.invokeEffectorList(entity, ImmutableList.<StartableApplication>of(), Startable.STOP).get(Duration.THIRTY_SECONDS); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { IllegalStateException e2 = Exceptions.getFirstThrowableOfType(e, IllegalStateException.class); if (e2 == null) throw e; Asserts.expectedFailureContains(e2, "no longer managed"); } }
Entities.invokeEffectorList(this, applications, Startable.STOP).get(Duration.THIRTY_SECONDS); } catch (Exception e) { LOG.warn("Error stopping applications", e); DynamicCluster hosts = sensors().get(DOCKER_HOST_CLUSTER); LOG.debug("Stopping hosts: {}", Iterables.toString(hosts.getMembers())); Entities.invokeEffectorList(this, hosts.getMembers(), Startable.STOP).get(Duration.THIRTY_SECONDS); } catch (Exception e) { LOG.warn("Error stopping hosts", e);
childrenToStart.add(getController()); } else { startControllerTask = Entities.invokeEffectorList(this, MutableList.<Entity>of(getController()), Startable.START, ImmutableMap.of("locations", getController().getLocations())); Entities.invokeEffectorList(this, childrenToStart, Startable.START, ImmutableMap.of("locations", MutableList.of())).get(); if (startControllerTask != null) { startControllerTask.get();