/** * Placement strategy for Docker containers in host clusters. */ public interface DockerAwarePlacementStrategy extends HasShortName { @SetFromFlag("infrastructure") ConfigKey<DockerInfrastructure> DOCKER_INFRASTRUCTURE = DockerVirtualLocation.INFRASTRUCTURE; DockerInfrastructure getDockerInfrastructure(); /** * Filters a list of {@link DockerHostLocation locations} to determine if the given {@link Entity} can be * deployed into a new container there. */ List<DockerHostLocation> filterLocations(List<DockerHostLocation> locations, Entity context); }
if (optionalAnnotation!=null && optionalAnnotation.immutable()) { Object oldValue = f.get(objectOfField); if (!Objects.equal(oldValue, getDefaultValueForType(f.getType())) && oldValue != value) { if (optionalAnnotation!=null && !optionalAnnotation.nullable() && value==null) { throw new IllegalArgumentException("Forbidden null assignment to non-nullable field "+ f+" in "+objectOfField); log.warn("Setting static field "+f+" in "+objectOfField+" from flag "+optionalAnnotation.value()+": discouraged");
/** * @throws an IllegalStateException if there are fields required (nullable=false) which are unset * @throws wrapped IllegalAccessException */ public static void checkRequiredFields(Object o) { try { Set<String> unsetFields = Sets.newLinkedHashSet(); for (Map.Entry<Field, SetFromFlag> entry : getAnnotatedFields(o.getClass()).entrySet()) { Field f = entry.getKey(); SetFromFlag cf = entry.getValue(); if (!cf.nullable()) { String flagName = elvis(cf.value(), f.getName()); if (!f.isAccessible()) f.setAccessible(true); Object v = f.get(o); if (v==null) unsetFields.add(flagName); } } if (groovyTruth(unsetFields)) { throw new IllegalStateException("Missing required "+(unsetFields.size()>1 ? "fields" : "field")+": "+unsetFields); } } catch (IllegalAccessException e) { throw Throwables.propagate(e); } }
@Test public void testGetAnnotatedFields() throws Exception { Map<Field, SetFromFlag> fm = FlagUtils.getAnnotatedFields(WithImmutableNonNullableObject.class); assertEquals(fm.keySet().size(), 2); assertTrue(fm.get(WithImmutableNonNullableObject.class.getDeclaredField("b")).immutable()); }
private static void setFieldFromConfig(Object o, Field f, ConfigBag bag, SetFromFlag optionalAnnotation, boolean setDefaultVals) { String flagName = optionalAnnotation==null ? null : elvis(optionalAnnotation.value(), f.getName()); // prefer flag name, if present if (groovyTruth(flagName) && bag.containsKey(flagName)) { setField(o, f, bag.getStringKey(flagName), optionalAnnotation); return; } // first check whether it is a key ConfigKey<?> key = getFieldAsConfigKey(o, f); if (key!=null && bag.containsKey(key)) { Object uncoercedValue = bag.getObjKeyMaybe(key).get(); setField(o, f, uncoercedValue, optionalAnnotation); return; } if (setDefaultVals && optionalAnnotation!=null && groovyTruth(optionalAnnotation.defaultVal())) { Object oldValue; try { f.setAccessible(true); oldValue = f.get(o); if (oldValue==null || oldValue.equals(getDefaultValueForType(f.getType()))) { setField(o, f, optionalAnnotation.defaultVal(), optionalAnnotation); } } catch (Exception e) { Exceptions.propagate(e); } return; } }
/** * Represents an item that can be migrated between balanceable containers. */ public interface Movable extends Entity { @SetFromFlag("immovable") public static ConfigKey<Boolean> IMMOVABLE = new BasicConfigKey<Boolean>( Boolean.class, "movable.item.immovable", "Indicates whether this item instance is immovable, so cannot be moved by policies", false); public static BasicAttributeSensor<BalanceableContainer> CONTAINER = new BasicAttributeSensor<BalanceableContainer>( BalanceableContainer.class, "movable.item.container", "The container that this item is on"); public static final MethodEffector<Void> MOVE = new MethodEffector<Void>(Movable.class, "move"); public String getContainerId(); @Effector(description="Moves this entity to the given container") public void move(@EffectorParam(name="destination") Entity destination); }
public interface WebAppServiceConstants extends WebAppServiceMetrics { @SetFromFlag("httpPort") public static final PortAttributeSensorAndConfigKey HTTP_PORT = Attributes.HTTP_PORT; @SetFromFlag("httpsPort") public static final PortAttributeSensorAndConfigKey HTTPS_PORT = Attributes.HTTPS_PORT; @SuppressWarnings({ "unchecked", "rawtypes" }) @SetFromFlag("enabledProtocols") public static final BasicAttributeSensorAndConfigKey<Set<String>> ENABLED_PROTOCOLS = new BasicAttributeSensorAndConfigKey( Set.class, "webapp.enabledProtocols", "List of enabled protocols (e.g. http, https)", ImmutableSet.of("http")); @SetFromFlag("httpsSsl") public static final BasicAttributeSensorAndConfigKey<HttpsSslConfig> HTTPS_SSL_CONFIG = new BasicAttributeSensorAndConfigKey<HttpsSslConfig>( HttpsSslConfig.class, "webapp.https.ssl", "SSL Configuration for HTTPS", null); public static final AttributeSensor<String> ROOT_URL = RootUrl.ROOT_URL; }
/** * Shared Kafka broker and zookeeper properties. */ public interface Kafka { ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION, "2.9.2-0.8.2.1"); @SetFromFlag("downloadUrl") BasicAttributeSensorAndConfigKey<String> DOWNLOAD_URL = new BasicAttributeSensorAndConfigKey<String>( Attributes.DOWNLOAD_URL, "http://apache.cbox.biz/kafka/0.8.2.1/kafka_${version}.tgz"); // TODO: Upgrade to version 0.8.0, which will require refactoring of the sensors to reflect the changes to the JMX beans // @SetFromFlag("downloadUrl") // BasicAttributeSensorAndConfigKey<String> DOWNLOAD_URL = new BasicAttributeSensorAndConfigKey<String>( // Attributes.DOWNLOAD_URL, "http://mirror.catn.com/pub/apache/kafka/${version}/kafka-${version}-src.tgz"); @SetFromFlag("archiveNameFormat") ConfigKey<String> ARCHIVE_DIRECTORY_NAME_FORMAT = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.ARCHIVE_DIRECTORY_NAME_FORMAT, "kafka_%s"); }
/** * An interface that describes an AMQP exchange. */ public interface AmqpExchange { /* AMQP standard exchange names. */ String DIRECT = "amq.direct"; String TOPIC = "amq.topic"; /** The AMQP exchange name {@link Sensor}. */ @SetFromFlag("exchange") BasicAttributeSensorAndConfigKey<String> EXCHANGE_NAME = new BasicAttributeSensorAndConfigKey<String>( String.class, "amqp.exchange.name", "AMQP exchange name"); /** * Return the AMQP exchange name. */ public String getExchangeName(); }
public interface StartableApplication extends Application, Startable { ConfigKey<QuorumCheck> UP_QUORUM_CHECK = ConfigKeys.builder(QuorumCheck.class, "quorum.up") .description("Logic for checking whether this service is up, based on children and members, defaulting to all must be up") .defaultValue(QuorumCheck.QuorumChecks.all()) .runtimeInheritance(BasicConfigInheritance.NOT_REINHERITED) .build(); ConfigKey<QuorumCheck> RUNNING_QUORUM_CHECK = ConfigKeys.builder(QuorumCheck.class, "quorum.running") .description("Logic for checking whether this service is healthy, based on children and members running, defaulting to requiring none to be ON-FIRE") .defaultValue(QuorumCheck.QuorumChecks.all()) .runtimeInheritance(BasicConfigInheritance.NOT_REINHERITED) .build(); ConfigKey<Boolean> DESTROY_ON_STOP = ConfigKeys.newBooleanConfigKey("application.stop.shouldDestroy", "Whether the app should be removed from management after a successful stop (if it is a root); " + "true by default.", true); @SetFromFlag("startLatch") ConfigKey<Boolean> START_LATCH = BrooklynConfigKeys.START_LATCH; }
/** * Strategy that requires the hostname of the Docker location to match a particular regexp. */ public class HostnamePlacementStrategy extends BasicDockerPlacementStrategy { private static final Logger LOG = LoggerFactory.getLogger(HostnamePlacementStrategy.class); @SetFromFlag("hostname") public static final ConfigKey<String> HOSTNAME_PATTERN = ConfigKeys.newStringConfigKey( "docker.constraint.hostname", "The pattern the required hostname must match"); @Override public boolean apply(DockerHostLocation input) { String constraint = Preconditions.checkNotNull(config().get(HOSTNAME_PATTERN), "pattern"); String hostname = Strings.nullToEmpty(input.getMachine().getHostname()); boolean match = hostname.matches(constraint); LOG.debug("Hostname {} {} {}", new Object[] { hostname, match ? "matches" : "not", constraint }); return match; } }
/** * The Weave container. */ @ImplementedBy(WeaveRouterImpl.class) public interface WeaveRouter extends SdnAgent { @SetFromFlag("version") ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION, "1.1.2"); @SetFromFlag("weavePort") ConfigKey<Integer> WEAVE_PORT = ConfigKeys.newIntegerConfigKey("weave.port", "Weave port", 6783); @SetFromFlag("downloadUrl") BasicAttributeSensorAndConfigKey<String> DOWNLOAD_URL = new BasicAttributeSensorAndConfigKey<String>( SoftwareProcess.DOWNLOAD_URL, "https://raw.githubusercontent.com/weaveworks/weave/v${version}/weave"); }
public interface AbstractGeoDnsService extends Entity { @SetFromFlag("includeHomelessEntities") ConfigKey<Boolean> INCLUDE_HOMELESS_ENTITIES = ConfigKeys.newBooleanConfigKey( "geodns.includeHomeless", "Whether to include entities whose geo-coordinates cannot be inferred", false); @SetFromFlag("useHostnames") ConfigKey<Boolean> USE_HOSTNAMES = ConfigKeys.newBooleanConfigKey( "geodns.useHostnames", "Whether to use the hostname for the returned value for routing, rather than IP address (defaults to true)", true); @SetFromFlag("provider") ConfigKey<Group> ENTITY_PROVIDER = ConfigKeys.newConfigKey(Group.class, "geodns.entityProvider", "The group whose members should be tracked"); @SetFromFlag("filterForRunning") ConfigKey<Boolean> FILTER_FOR_RUNNING = ConfigKeys.newBooleanConfigKey( "geodns.filterForRunning", "Whether to only track targets whose status is \"RUNNING\"", true);
/** * The Calico plugin */ @ImplementedBy(CalicoNodeImpl.class) public interface CalicoNode extends SdnAgent { @SetFromFlag("version") ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION, "0.19.0"); @SetFromFlag("downloadUrl") AttributeSensorAndConfigKey<String, String> DOWNLOAD_URL = ConfigKeys.newSensorAndConfigKeyWithDefault(SoftwareProcess.DOWNLOAD_URL, "https://github.com/Metaswitch/calico-docker/releases/download/v${version}/calicoctl"); @SetFromFlag("etcdNode") AttributeSensorAndConfigKey<EtcdNode, EtcdNode> ETCD_NODE = ConfigKeys.newSensorAndConfigKey(EtcdNode.class, "calico.etcd.node", "The EtcdNode attached to the same DockerHost as the plugin"); }
@SetFromFlag("maxContainers") public static final ConfigKey<Integer> DOCKER_CONTAINER_CLUSTER_MAX_SIZE = ConfigKeys.newIntegerConfigKey( "docker.container.cluster.maxSize",
@SetFromFlag("owner") protected MesosFramework framework;
new TypeToken<Map<String, InetAddress>>() { }, "sdn.agent.addresses", "Allocated IP addresses for agents"); @SetFromFlag("agentSpec") AttributeSensorAndConfigKey<EntitySpec<?>,EntitySpec<?>> SDN_AGENT_SPEC = ConfigKeys.newSensorAndConfigKey( new TypeToken<EntitySpec<?>>() { }, "sdn.agent.spec", "SDN agent specification"); @SetFromFlag("dockerInfrastructure") AttributeSensorAndConfigKey<Entity, Entity> DOCKER_INFRASTRUCTURE = DockerAttributes.DOCKER_INFRASTRUCTURE;
@SetFromFlag("maxCpuUsage") public static final ConfigKey<Double> DOCKER_CONTAINER_CLUSTER_MAX_CPU = ConfigKeys.newDoubleConfigKey( "docker.container.cluster.maxCpu",
public interface UsesJava { @SetFromFlag("javaSysProps") public static final MapConfigKey<String> JAVA_SYSPROPS = new MapConfigKey<String>(String.class, "java.sysprops", @SetFromFlag("javaOpts") public static final SetConfigKey<String> JAVA_OPTS = new SetConfigKey<String>(String.class, "java.opts", "Java command line options", ImmutableSet.<String>of()); true); @SetFromFlag("javaVersionRequired") ConfigKey<String> JAVA_VERSION_REQUIRED = ConfigKeys.newStringConfigKey("java.version.required", "Java version required", "1.7");
@ImplementedBy(HAProxyControllerImpl.class) public interface HAProxyController extends AbstractController { @SetFromFlag("haProxyConfig") ConfigKey<String> HAPROXY_CONFIG_TEMPLATE_URL = ConfigKeys.newStringConfigKey( "haproxy.config.templateUrl", "Configuration template file (in freemarker format) for HAProxyController", "classpath://org/apache/brooklyn/entity/proxy/haproxy/haproxy.cfg"); @SetFromFlag("backendMode") ConfigKey<String> BACKEND_MODE = ConfigKeys.newStringConfigKey( "haproxy.backend.mode", "The mode of the backend", "http"); @SetFromFlag("frontendMode") ConfigKey<String> FRONTEND_MODE = ConfigKeys.newStringConfigKey( "haproxy.frontend.mode", "The mode of the frontend", "http"); @SetFromFlag("bindAddress") ConfigKey<String> BIND_ADDRESS = ConfigKeys.newStringConfigKey( "haproxy.frontend.bind.address", "The address frontend should bind to. If unset all" + "IPv4 addresses on the server will be listened on."); }