private String getMarathonApplicationId() { String id = "/brooklyn/" + config().get(TASK_NAME).toLowerCase(Locale.ENGLISH); return TASK_CHARACTERS_INVALID.trimAndCollapseFrom(id, '_'); }
private void initialiseTaskPermitSemaphore() { synchronized (mutex) { if (getChildTaskSemaphore() == null) { Integer maxChildTasks = config().get(MAX_CONCURRENT_CHILD_COMMANDS); if (maxChildTasks != null && maxChildTasks > 0) { childTaskSemaphore = new Semaphore(maxChildTasks); } } } }
@Override public Void reset() { synchronized (memberChangeMutex) { sensors().set(SEQUENCE_CACHE, Maps.<String, Integer>newConcurrentMap()); sensors().set(SEQUENCE_CURRENT, null); Integer initial = config().get(SEQUENCE_START); AtomicInteger state = new AtomicInteger(initial); sensors().set(SEQUENCE_STATE, state); return null; } }
@Override public void init() { super.init(); Group initialProvider = config().get(ENTITY_PROVIDER); if (initialProvider != null) { setTargetEntityProvider(initialProvider); } }
@Override public void preStart() { super.preStart(); ConfigToAttributes.apply(this); createLocation(config().get(LOCATION_FLAGS)); sensors().get(DOCKER_CONTAINER_CLUSTER).sensors().set(SERVICE_UP, Boolean.TRUE); }
@Override public <T> T getConfig(HasConfigKey<T> key) { return config().get(key); }
@Override public Cidr getNextSubnetCidr() { synchronized (networkMutex) { Cidr networkCidr = config().get(CONTAINER_NETWORK_CIDR); Integer networkSize = config().get(CONTAINER_NETWORK_SIZE); Integer allocated = sensors().get(ALLOCATED_NETWORKS); InetAddress baseAddress = networkCidr.addressAtOffset(allocated * (1 << (32 - networkSize))); Cidr subnetCidr = new Cidr(baseAddress.getHostAddress() + "/" + networkSize); LOG.debug("Allocated {} from {} for subnet #{}", new Object[] { subnetCidr, networkCidr, allocated }); sensors().set(ALLOCATED_NETWORKS, allocated + 1); return subnetCidr; } }
@Override public Class<?> getDriverInterface() { return config().get(DRIVER_CLASS); } }
@Override public <T> T getConfig(ConfigKey<T> key) { return config().get(key); }
@Override public void init() { super.init(); poller = config().get(POLLER); FunctionFeed.builder() .entity(this) .period(1L) .poll(new FunctionPollConfig<Boolean, Boolean>(FLAG) .callable(poller) .onException(Functions.constant(false))) .build(); }
@Override public void init() { LOG.info("Starting virtual network segment id {}", getId()); super.init(); String networkId = config().get(NETWORK_ID); if (Strings.isEmpty(networkId)) networkId = getId(); sensors().set(NETWORK_ID, networkId); setDisplayName(String.format("Virtual Network (%s)", networkId)); ConfigToAttributes.apply(this, SDN_PROVIDER); }
/** * Sets the default {@link #MEMBER_SPEC} to describe the ZooKeeper nodes. * Overwrites any value configured for {@link ZooKeeperNode#MY_ID} to use * the value given by {@link ZooKeeperEnsemble#NODE_ID_SUPPLIER}. */ @Override protected EntitySpec<?> getMemberSpec() { EntitySpec<?> spec = getConfig(MEMBER_SPEC, EntitySpec.create(ZooKeeperNode.class)); spec.configure(ZooKeeperNode.MY_ID, config().get(ZooKeeperEnsemble.NODE_ID_SUPPLIER).get()); return spec; }
@Override protected void initEnrichers() { // Deliberately not calling `super.initEnrichers()`. For our state (i.e. "service.state" // and "service.isUp"), we rely on the `serviceStateComputer`. This keeps things a lot // simpler. However, it means that if someone manually sets a "service.notUp.indicators" // or "service.problems" then that won't cause the entity to transition to false or ON_FIRE. enrichers().add(EnricherSpec.create(ServiceStateComputer.class) .configure(ServiceStateComputer.FROM_CHILDREN, true) .configure(ServiceStateComputer.UP_QUORUM_CHECK, config().get(UP_QUORUM_CHECK)) .configure(ServiceStateComputer.RUNNING_QUORUM_CHECK, config().get(RUNNING_QUORUM_CHECK))); }
@Override public void init() { LOG.info("Connecting to framework id: {}", getId()); super.init(); ConfigToAttributes.apply(this); Group tasks = addChild(EntitySpec.create(BasicGroup.class) .configure(BasicGroup.RUNNING_QUORUM_CHECK, QuorumChecks.atLeastOneUnlessEmpty()) .configure(BasicGroup.UP_QUORUM_CHECK, QuorumChecks.atLeastOneUnlessEmpty()) .displayName("Framework Tasks")); sensors().set(FRAMEWORK_TASKS, tasks); sensors().set(Attributes.MAIN_URI, URI.create(config().get(FRAMEWORK_URL))); }
@Override public void start(Collection<? extends Location> locations) { super.start(locations); subscribe(getMasterAmbariServer(), AmbariServer.REGISTERED_HOSTS, new RegisteredHostEventListener(this, config().get(AmbariCluster.PAUSE_FOR_DEPLOYMENT))); subscribe(getMasterAmbariServer(), AmbariServer.CLUSTER_STATE, new ClusterStateEventListener(this)); EtcHostsManager.setHostsOnMachines(getAmbariNodes(), getConfig(ETC_HOST_ADDRESS)); }
@Override public void provisionNetwork(VirtualNetwork network) { Cidr subnetCidr = SdnUtils.provisionNetwork(this, network); boolean ipip = config().get(CalicoModule.USE_IPIP); boolean nat = config().get(CalicoModule.USE_NAT); String addPool = String.format("calicoctl pool add %s %s %s", subnetCidr, ipip ? "--ipip" : "", nat ? "--nat-outgoing" : ""); MesosSlave slave = (MesosSlave) getMesosCluster().sensors().get(MesosCluster.MESOS_SLAVES).getMembers().iterator().next(); execCalicoCommand(slave, addPool); sensors().get(SDN_NETWORKS).addMember(network); }
@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 @SuppressWarnings("unchecked") public Class<EntityDriver> getDriverInterface() { return (Class<EntityDriver>) config().get(DRIVER_CLASS); }
/** as {@link AbstractEntity#initEnrichers()} but also adding default service not-up and problem indicators from children */ @Override protected void initEnrichers() { super.initEnrichers(); // default app logic; easily overridable by adding a different enricher with the same tag ServiceStateLogic.newEnricherFromChildren().checkChildrenAndMembers() .configure(ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers.UP_QUORUM_CHECK, config().get(UP_QUORUM_CHECK)) .configure(ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers.RUNNING_QUORUM_CHECK, config().get(RUNNING_QUORUM_CHECK)) .addTo(this); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application created but not yet started, at "+Time.makeDateString()); }