private Location getLocation(boolean required) { Collection<? extends Location> ll = Locations.getLocationsCheckingAncestors(getLocations(), this); if (ll.isEmpty()) { if (!required) return null; throw new IllegalStateException("No location available for "+this); } if (ll.size()>1) { throw new IllegalStateException("Ambiguous location for "+this+"; expected one but had "+ll); } return Iterables.getOnlyElement(ll); }
protected Location getLocation(@Nullable Collection<? extends Location> locations) { if (locations==null || locations.isEmpty()) locations = entity().getLocations(); if (locations.isEmpty()) { MachineProvisioningLocation<?> provisioner = entity().getAttribute(SoftwareProcess.PROVISIONING_LOCATION); if (provisioner!=null) locations = Arrays.<Location>asList(provisioner); } locations = Locations.getLocationsCheckingAncestors(locations, entity()); Maybe<MachineLocation> ml = Locations.findUniqueMachineLocation(locations); if (ml.isPresent()) return ml.get(); if (locations.isEmpty()) throw new IllegalArgumentException("No locations specified when starting "+entity()); if (locations.size() != 1 || Iterables.getOnlyElement(locations)==null) throw new IllegalArgumentException("Ambiguous locations detected when starting "+entity()+": "+locations); return Iterables.getOnlyElement(locations); }
@Override public void start(Collection<? extends Location> locs) { addLocations(locs); List<Location> locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locs, this)); connectSensors(); super.start(locations); }
locations = Locations.getLocationsCheckingAncestors(locations, this); log.info("Starting entity "+this+" at "+locations);
Collection<? extends Location> allLocations = Locations.getLocationsCheckingAncestors(locsO, this);
@Override public void start(Collection<? extends Location> locs) { addLocations(locs); List<Location> locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locs, this)); sensors().set(SERVICE_UP, Boolean.FALSE); super.start(locations); connectSensors(); }
@Override public void start(Collection<? extends Location> locations) { if (isLegacyConstruction()) { // TODO should no longer be needed? init(); } locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locations, this)); Iterables.getOnlyElement(locations); // Assert just one // set it; here we don't allow changing locations addLocations(locations); List<Entity> childrenToStart = MutableList.<Entity>of(getCluster()); // Set the KafkaZookeeper entity as child of cluster, if it does not already have a parent if (getZooKeeper().getParent() == null) { addChild(getZooKeeper()); } // And only start zookeeper if we are parent if (Objects.equal(this, getZooKeeper().getParent())) childrenToStart.add(getZooKeeper()); Entities.invokeEffector(this, childrenToStart, Startable.START, ImmutableMap.of("locations", locations)).getUnchecked(); }
/** * Starts the entity and its children in the given locations. * <p/> * Subclasses should override {@link #doStart} to customise behaviour. */ @Override public final void start(Collection<? extends Location> locsO) { addLocations(locsO); final Collection<? extends Location> locations = Locations.getLocationsCheckingAncestors(locsO, this); checkNotNull(locations, "locations"); if (DynamicTasks.getTaskQueuingContext() != null) { doStart(locations); } else { Task<?> task = Tasks.builder().displayName("start").body(new Runnable() { @Override public void run() { doStart(locations); } }).build(); Entities.submit(this, task).getUnchecked(); } }
} else { HttpExecutorFactory httpExecutorFactory = null; Collection<? extends Location> locations = Locations.getLocationsCheckingAncestors(builder.entity.getLocations(), builder.entity); Maybe<MachineLocation> location = Machines.findUniqueElement(locations, MachineLocation.class); if (location.isPresent() && location.get().hasExtension(HttpExecutorFactory.class)) {
if (state==Lifecycle.STOPPING || state==Lifecycle.STOPPED) return; Collection<? extends Location> locations = Locations.getLocationsCheckingAncestors(target.getLocations(), target); Maybe<SshMachineLocation> machine = Machines.findUniqueMachineLocation(locations, SshMachineLocation.class); if (machine.isAbsentOrNull()) {
@Override public void start(Collection<? extends Location> locs) { addLocations(locs); List<Location> locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locs, this)); sensors().set(SERVICE_UP, Boolean.FALSE); // Add ouserlves as an extension to the Docker location DockerInfrastructure infrastructure = (DockerInfrastructure) config().get(DOCKER_INFRASTRUCTURE); infrastructure.getDynamicLocation().addExtension(NetworkProvisioningExtension.class, this); super.start(locations); addHostTrackerPolicy(); sensors().set(SERVICE_UP, Boolean.TRUE); }
@Override public void start(Collection<? extends Location> locs) { addLocations(locs); List<Location> locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locs, this)); sensors().set(SERVICE_UP, Boolean.FALSE); // Add ouserlves as an extension to the Docker location MesosCluster cluster = (MesosCluster) config().get(MESOS_CLUSTER); cluster.getDynamicLocation().addExtension(NetworkProvisioningExtension.class, this); super.start(locations); sensors().set(SERVICE_UP, Boolean.TRUE); }
@Override public void start(Collection<? extends Location> locs) { addLocations(locs); List<Location> locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locs, this));
@Override public void doStart(Collection<? extends Location> locs) { addLocations(locs); List<Location> locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locs, this)); sensors().set(SERVICE_UP, Boolean.FALSE); ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); // TODO support multiple provisioners Location provisioner = Iterables.getOnlyElement(locations); LOG.info("Creating new DockerLocation wrapping {}", provisioner); Map<String, ?> flags = MutableMap.<String, Object>builder() .putAll(config().get(LOCATION_FLAGS)) .put("provisioner", provisioner) .putIfNotNull("strategies", config().get(PLACEMENT_STRATEGIES)) .build(); createLocation(flags); super.doStart(locations); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); sensors().set(SERVICE_UP, Boolean.TRUE); }
locations = Locations.getLocationsCheckingAncestors(locations, this); LOG.info("Starting entity {}: {}", this, locations);
locations = Locations.getLocationsCheckingAncestors(locations, this); LOG.info("Starting entity {}: {}", this, locations);
@Override public void start(Collection<? extends Location> locs) { addLocations(locs); List<Location> locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locs, this)); sensors().set(SERVICE_UP, Boolean.FALSE); super.start(locations); try { NetworkProvisioningExtension provisioner = null; Entity sdn = sensors().get(SDN_PROVIDER); if (sdn instanceof NetworkProvisioningExtension) { provisioner = (NetworkProvisioningExtension) sdn; } else { provisioner = findNetworkProvisioner(locations); } sensors().set(NETWORK_PROVISIONER, provisioner); provisioner.provisionNetwork(this); } catch (Exception e) { ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); throw Exceptions.propagate(e); } sensors().set(SERVICE_UP, Boolean.TRUE); }
locations = Locations.getLocationsCheckingAncestors(locations, this);
@Override public void start(Collection<? extends Location> locs) { addLocations(locs); List<Location> locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locs, this)); ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); try { Boolean started = config().get(SoftwareProcess.ENTITY_STARTED); Boolean managed = config().get(DockerContainer.MANAGED); if (Boolean.TRUE.equals(started) || !managed) { DockerHost dockerHost = getDockerHost(); DockerHostLocation host = dockerHost.getDynamicLocation(); sensors().set(DOCKER_IMAGE_ID, config().get(DOCKER_IMAGE_ID)); sensors().set(DOCKER_IMAGE_NAME, config().get(DOCKER_IMAGE_NAME)); sensors().set(SSH_MACHINE_LOCATION, host.getMachine()); } else { Map<String, ?> flags = MutableMap.copyOf(config().get(LOCATION_FLAGS)); DockerContainerLocation location = createLocation(flags); sensors().set(SSH_MACHINE_LOCATION, location.getMachine()); } connectSensors(); super.start(locations); } catch (Exception e) { ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); throw Exceptions.propagate(e); } ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); }
connectServiceUpIsRunning(); Collection<? extends Location> locations = Locations.getLocationsCheckingAncestors(getLocations(), this); Maybe<MachineLocation> location = Machines.findUniqueElement(locations, MachineLocation.class); if (location.isPresent() && location.get().hasExtension(HttpExecutorFactory.class)) {