@Override protected Map<String, Object> obtainProvisioningFlags(MachineProvisioningLocation location) { Map<String, Object> flags = MutableMap.copyOf(super.obtainProvisioningFlags(location)); flags.putAll(config().get(PROVISIONING_FLAGS)); String securityGroup = config().get(DockerInfrastructure.SECURITY_GROUP); if (Strings.isNonBlank(securityGroup)) { if (DockerUtils.isJcloudsLocation(location, "google-compute-engine")) { config().set(DockerInfrastructure.USE_JCLOUDS_HOSTNAME_CUSTOMIZER, true); if (config().get(DockerInfrastructure.USE_JCLOUDS_HOSTNAME_CUSTOMIZER)) { customizers.add(JcloudsHostnameCustomizer.instanceOf());
Map<String, Object> raw1 = PROVISIONING_PROPERTIES.rawValue(config().getBag().getAllConfigRaw()); Maybe<Object> raw2 = config().getRaw(PROVISIONING_PROPERTIES); if (raw2.isPresentAndNonNull()) { Object pp = raw2.get(); if (!(pp instanceof Map)) { LOG.debug("When obtaining provisioning properties for "+this+" to deploy to "+location+", detected that coercion was needed, so coercing sooner than we would otherwise"); pp = config().get(PROVISIONING_PROPERTIES);
return; config().set(BaseTest.TARGET_ENTITY, target);
String password = config().get(DOCKER_LOGIN_PASSWORD); if (Strings.isBlank(password)) { password = Identifiers.makeRandomId(12); config().set(DOCKER_LOGIN_PASSWORD, password); EntitySpec<DockerContainer> dockerContainerSpec = EntitySpec.create(config().get(DOCKER_CONTAINER_SPEC)); dockerContainerSpec.configure(DockerContainer.DOCKER_HOST, this) .configure(DockerContainer.DOCKER_INFRASTRUCTURE, getInfrastructure()); if (config().get(DockerInfrastructure.HA_POLICY_ENABLE)) { dockerContainerSpec.policy(PolicySpec.create(ServiceRestarter.class) .configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, ServiceFailureDetector.ENTITY_FAILED)); .configure(BrooklynCampConstants.PLAN_ID, "docker-host-containers") .displayName("Docker Containers")); if (config().get(DockerInfrastructure.HA_POLICY_ENABLE)) { containers.policies().add(PolicySpec.create(ServiceReplacer.class) .configure(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR, ServiceRestarter.ENTITY_RESTART_FAILED));
@Override public void init() { super.init(); String imageName = config().get(DockerContainer.IMAGE_NAME); if (!Strings.isNullOrEmpty(imageName)) { config().set(PROVISIONING_PROPERTIES.subKey("imageId"), imageName); } if (Boolean.TRUE.equals(config().get(DockerContainer.DISABLE_SSH))) { config().set(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true); config().set(PROVISIONING_PROPERTIES.subKey("useJcloudsSshInit"), false); config().set(PROVISIONING_PROPERTIES.subKey("waitForSshable"), false); config().set(PROVISIONING_PROPERTIES.subKey("pollForFirstReachableAddress"), false); config().set(EmptySoftwareProcessImpl.USE_SSH_MONITORING, false); } ImmutableSet.Builder<AttributeSensor<Integer>> builder = ImmutableSet.builder(); List<String> portRanges = MutableList.copyOf(config().get(DockerContainer.INBOUND_TCP_PORTS)); for (String portRange : portRanges) { Iterator<Integer> iterator = PortRanges.fromString(portRange).iterator(); while (iterator.hasNext()) { Integer port = iterator.next(); AttributeSensor<Integer> element = Sensors.newIntegerSensor("docker.port." + port); sensors().set(element, port); builder.add(element); } } enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class).configure(OnPublicNetworkEnricher.SENSORS, builder.build())); }
String sshMachineInstallDir = getSSHMachineInstallDir(); config().set(DockerAttributes.DOCKER_PORT_BINDINGS, MutableMap.of(sensors().get(DOCKER_REGISTRY_PORT), 5000)); config().set(DockerAttributes.DOCKER_HOST_VOLUME_MAPPING, MutableMap.of(Os.mergePaths(installDir, "certs"), "/certs")); sshMachine.installTo(config().get(DockerInfrastructure.DOCKER_CA_CERTIFICATE_PATH), Os.mergePaths(sshMachineInstallDir, "ca-cert.pem")); sshMachine.installTo(config().get(DockerInfrastructure.DOCKER_CA_KEY_PATH), Os.mergePaths(sshMachineInstallDir, "ca-key.pem"));
@Override public void start(Collection<? extends Location> locs) { // TODO Auto-generated method stub super.start(locs); sensors().set(Attributes.HOSTNAME, "localhost"); sensors().set(UsesJmx.JMX_PORT, LocalhostMachineProvisioningLocation.obtainPort(PortRanges.fromString("40123+"))); // only supports no-agent, at the moment config().set(UsesJmx.JMX_AGENT_MODE, JmxAgentModes.NONE); sensors().set(UsesJmx.RMI_REGISTRY_PORT, -1); // -1 means to use the JMX_PORT only ConfigToAttributes.apply(this, UsesJmx.JMX_CONTEXT); JmxFeed.Builder feedBuilder = JmxFeed.builder() .entity(this) .pollAttribute(new JmxAttributePollConfig<String>(SENSOR_STRING) .objectName(OBJECT_NAME) .period(50) .attributeName(JMX_ATTRIBUTE_NAME)); if (getConfig(PRE_CREATE_JMX_HELPER)) { JmxHelper jmxHelper = new JmxHelper(this); feedBuilder.helper(jmxHelper); } addFeed(feedBuilder.build()); } }
@Override public Entity resolveTarget() { Entity anchor = config().get(ANCHOR); if (anchor == null) { Maybe<Entity> resolvedTarget = tryResolveTarget(); if (resolvedTarget.isPresent()) { anchor = resolvedTarget.get(); } else { throw new IllegalArgumentException("No anchor entity found for " + this); } } sensors().set(ANCHOR, anchor); Maybe<Object> component = config().getRaw(COMPONENT); if (component.isAbsentOrNull()) { throw new IllegalArgumentException("No component found for " + this); } else if (!(component.get() instanceof DslComponent)) { throw new IllegalArgumentException("Expected DslComponent value for component, found " + component.get()); } DslComponent finder = DslComponent.class.cast(component.get()); Task<Entity> task = Entities.submit(anchor, finder); return task.getUnchecked(); }
private EntitySpec<? extends AmbariServer> createServerSpec(Object securityGroup) { Iterable<Map.Entry<ConfigKey<?>, Object>> ambariConfigFromPropertiesIterator = Iterables.filter(getManagementContext().getConfig().getAllConfig().entrySet(), new Predicate<Object>() { @Override public boolean apply(@Nullable Object input) { return ((ConfigKey<?>) ((Map.Entry) input).getKey()).getName().contains(AMBARI_ALERTS_CONFIG_PREFIX); } }); Map<String, Object> ambariConfigFromProperties = MutableMap.of(); for (Map.Entry entry: ambariConfigFromPropertiesIterator) { ambariConfigFromProperties.put(((ConfigKey<?>) entry.getKey()).getName(), entry.getValue()); } EntitySpec<? extends AmbariServer> serverSpec = EntitySpec.create(getConfig(SERVER_SPEC)) .configure(SoftwareProcess.SUGGESTED_VERSION, getConfig(AmbariCluster.SUGGESTED_VERSION)) .configure(ambariConfigFromProperties) .configure(config().getBag().getAllConfig()) .displayName("Ambari Server"); if (securityGroup != null) { serverSpec.configure(SoftwareProcess.PROVISIONING_PROPERTIES.subKey("securityGroups"), securityGroup); } return serverSpec; }
@Override protected void connectSensors() { // Override management username and password from brooklyn.properties // TODO Why use BrooklynProperties, rather than StringConfigMap returned by mgmt.getConfig()? BrooklynProperties properties = ((ManagementContextInternal)getManagementContext()).getBrooklynProperties(); String user = (String) properties.getConfig(String.format(LOCAL_BROOKLYN_NODE_KEY, "user")); String password = (String) properties.getConfig(String.format(LOCAL_BROOKLYN_NODE_KEY, "password")); if (Strings.isBlank(password)) { if (Strings.isBlank(user)) user = "admin"; password = (String) properties.getConfig(String.format(BROOKLYN_WEBCONSOLE_PASSWORD_KEY, user)); } if (Strings.isNonBlank(user) && Strings.isNonBlank(password)) { config().set(MANAGEMENT_USER, user); config().set(MANAGEMENT_PASSWORD, password); } super.connectSensors(); }
protected void computePortsAndUrls() { AttributeSensor<String> hostAndPortSensor = getConfig(HOST_AND_PORT_SENSOR); Maybe<Object> hostnameSensor = config().getRaw(HOSTNAME_SENSOR); Maybe<Object> portSensor = config().getRaw(PORT_NUMBER_SENSOR); if (hostAndPortSensor != null) { checkState(!hostnameSensor.isPresent() && !portSensor.isPresent(), "Must not set %s and either of %s or %s", HOST_AND_PORT_SENSOR, HOSTNAME_SENSOR, PORT_NUMBER_SENSOR); } ConfigToAttributes.apply(this); sensors().set(PROTOCOL, inferProtocol()); sensors().set(MAIN_URI, createUriOrNull(inferUrl())); sensors().set(MAIN_URI_MAPPED_SUBNET, createUriOrNull(inferUrlForSubnet())); sensors().set(MAIN_URI_MAPPED_PUBLIC, createUriOrNull(inferUrlForPublic())); sensors().set(ROOT_URL, inferUrl()); checkNotNull(getPortNumberSensor(), "no sensor configured to infer port number"); }
@Override public void init() { super.init(); String password = "p4ssw0rd"; config().set(CHEF_COOKBOOK_PRIMARY_NAME, "mysql"); config().set(CHEF_COOKBOOK_URLS, ImmutableMap.of( "mysql", GithubUrls.tgz("opscode-cookbooks", "mysql", "v4.0.12"), "openssl", GithubUrls.tgz("opscode-cookbooks", "openssl", "v1.1.0"), "mysql", GithubUrls.tgz("opscode-cookbooks", "build-essential", "v1.4.4"))); config().set(CHEF_LAUNCH_RUN_LIST, ImmutableSet.of("mysql::server")); config().set(CHEF_LAUNCH_ATTRIBUTES, ImmutableMap.<String,Object>of( "mysql", ImmutableMap.of( "server_root_password", password, "server_repl_password", password, "server_debian_password", password))); config().set(ChefConfig.PID_FILE, "/var/run/mysqld/mysqld.pid"); config().set(CHEF_MODE, ChefModes.SOLO); }
@Override public void init() { sensors().set(Attributes.HOSTNAME, JmxHelperTest.LOCALHOST_NAME); sensors().set(UsesJmx.JMX_PORT, LocalhostMachineProvisioningLocation.obtainPort(PortRanges.fromString( // just doing "40123+" was not enough to avoid collisions (on 40125), // observed on jenkins, not sure why but // maybe something else had a UDP connection we weren't detected, // or the static lock our localhost uses was being bypassed; // this should improve things (2016-01) NetworkingTestUtils.randomPortAround(40000)+"+"))); // only supports no-agent, at the moment config().set(UsesJmx.JMX_AGENT_MODE, JmxAgentModes.NONE); sensors().set(UsesJmx.RMI_REGISTRY_PORT, -1); // -1 means to use the JMX_PORT only ConfigToAttributes.apply(this, UsesJmx.JMX_CONTEXT); } }
@Override public void init() { super.init(); String password = "p4ssw0rd"; config().set(CHEF_COOKBOOK_PRIMARY_NAME, "mysql"); config().set(CHEF_COOKBOOK_URLS, ImmutableMap.of( "mysql", GithubUrls.tgz("opscode-cookbooks", "mysql", "v4.0.12"), "openssl", GithubUrls.tgz("opscode-cookbooks", "openssl", "v1.1.0"), "mysql", GithubUrls.tgz("opscode-cookbooks", "build-essential", "v1.4.4"))); config().set(CHEF_LAUNCH_RUN_LIST, ImmutableSet.of("mysql::server")); config().set(CHEF_LAUNCH_ATTRIBUTES, ImmutableMap.<String,Object>of( "mysql", ImmutableMap.of( "server_root_password", password, "server_repl_password", password, "server_debian_password", password))); config().set(ChefConfig.PID_FILE, "/var/run/mysqld/mysqld.pid"); config().set(CHEF_MODE, ChefModes.SOLO); }
/** * Returns the ports that this entity wants to be opened. * @see InboundPortsUtils#getRequiredOpenPorts(Entity, Set, Boolean, String) * @see #REQUIRED_OPEN_LOGIN_PORTS * @see #INBOUND_PORTS_AUTO_INFER * @see #INBOUND_PORTS_CONFIG_REGEX */ protected Collection<Integer> getRequiredOpenPorts() { Set<Integer> ports = MutableSet.copyOf(getConfig(REQUIRED_OPEN_LOGIN_PORTS)); Boolean portsAutoInfer = getConfig(INBOUND_PORTS_AUTO_INFER); String portsRegex = getConfig(INBOUND_PORTS_CONFIG_REGEX); ports.addAll(InboundPortsUtils.getRequiredOpenPorts(this, config().getBag().getAllConfigAsConfigKeyMap().keySet(), portsAutoInfer, portsRegex)); return ports; }
@Override public void init() { LOG.info("Starting Weave network id {}", getId()); super.init(); EntitySpec<?> agentSpec = EntitySpec.create(config().get(WEAVE_ROUTER_SPEC)) .configure(WeaveRouter.WEAVE_PORT, config().get(WeaveNetwork.WEAVE_PORT)); String weaveVersion = config().get(WEAVE_VERSION); if (Strings.isNonBlank(weaveVersion)) { agentSpec.configure(SoftwareProcess.SUGGESTED_VERSION, weaveVersion); } sensors().set(SDN_AGENT_SPEC, agentSpec); Cidr weaveCidr = getNextSubnetCidr(); config().set(AGENT_CIDR, weaveCidr); }
private Integer sequence(Entity entity) { String format = config().get(SEQUENCE_FORMAT); Integer increment = config().get(SEQUENCE_INCREMENT); AtomicInteger state = sensors().get(SEQUENCE_STATE); Integer current = state.getAndAdd(increment); String string = String.format(format, current); AttributeSensor<Integer> valueSensor = config().get(SEQUENCE_VALUE_SENSOR); AttributeSensor<String> stringSensor = config().get(SEQUENCE_STRING_SENSOR); entity.sensors().set(valueSensor, current); entity.sensors().set(stringSensor, string); LOG.debug("Sequence on {} set to to {}", entity, current); sensors().set(SEQUENCE_CURRENT, entity); LOG.debug("Sequence for {} incremented to {}", this, state.get()); return current; }
protected <T> T getRequiredConfig(ConfigKey<T> key) { return checkNotNull(config().get(key), "config %s must not be null", key); }
public String getMajorVersion() { return getEntity().config().get(MySqlNode.SUGGESTED_VERSION).replaceAll("(\\d+\\.\\d+)\\.\\d+", "$1"); }