@Override public boolean isJmxEnabled() { return (entity instanceof UsesJmx) && (entity.getConfig(UsesJmx.USE_JMX)); }
@Override public Map<String, String> getShellEnvironment() { ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String> builder() .putAll(super.getShellEnvironment()) .put("CHECKPOINT_DISABLE", "1") .put("WEAVE_VERSION", entity.config().get(WeaveRouter.SUGGESTED_VERSION)) .put("VERSION", entity.config().get(WeaveRouter.SUGGESTED_VERSION)); return builder.build(); }
@Override public String getRunDir() { // TODO: This needs to be tidied, and read from the appropriate flags (if set) return "$HOME\\brooklyn-managed-processes\\apps\\" + entity.getApplicationId() + "\\entities\\" + getEntityVersionLabel()+"_"+entity.getId(); }
private boolean isEntityUp() { if (entity == null) { return false; } else if (entity.getEntityType().getSensors().contains(Startable.SERVICE_UP)) { return Boolean.TRUE.equals(entity.getAttribute(Startable.SERVICE_UP)); } else { return true; } }
private String getConfigOrDefault(BasicAttributeSensorAndConfigKey<String> key, String def) { String val = entity.getConfig(key); if (Strings.isEmpty(val)) { val = entity.sensors().get(key); if (Strings.isEmpty(val)) { val = def; log.debug(entity + " has no config specified for " + key + "; using default `" + def + "`"); entity.sensors().set(key, val); } } return val; }
@Override public void onEvent(@Nullable SensorEvent<Object> event) { Preconditions.checkNotNull(entity, "Cannot handle subscriptions or compute state until associated with an entity"); Map<String, Object> serviceProblems = entity.getAttribute(SERVICE_PROBLEMS); Boolean serviceUp = entity.getAttribute(SERVICE_UP); Lifecycle.Transition serviceExpected = entity.getAttribute(SERVICE_STATE_EXPECTED); if (serviceExpected!=null && serviceExpected.getState()==Lifecycle.RUNNING) { setActualState( computeActualStateWhenExpectedRunning(serviceProblems, serviceUp) ); } else { setActualState( computeActualStateWhenNotExpectedRunning(serviceProblems, serviceUp, serviceExpected) ); } }
public void setExpandedInstallDir(String val) { String oldVal = getEntity().getAttribute(SoftwareProcess.EXPANDED_INSTALL_DIR); if (Strings.isNonBlank(oldVal) && !oldVal.equals(val)) { log.info("Resetting expandedInstallDir (to "+val+" from "+oldVal+") for "+getEntity()); } expandedInstallDir = val; getEntity().sensors().set(SoftwareProcess.EXPANDED_INSTALL_DIR, val); }
@Override public void install() { String parentFQDN = entity.getParent() instanceof AmbariServer ? ((AmbariServer) entity.getParent()).getFqdn() : ""; Entity parentHostGroup = Iterables.getFirst( Iterables.filter(Entities.ancestors(entity), AmbariHostGroup.class), entity); String fqdn = parentFQDN.isEmpty() ? String.format("%s-%s.%s", parentHostGroup.getDisplayName().toLowerCase(), entity.getId().toLowerCase(), entity.getConfig(AmbariCluster.DOMAIN_NAME)) : parentFQDN; getEntity().setFqdn(fqdn); ImmutableList<String> commands = ImmutableList.<String>builder() .add(defaultAmbariInstallHelper.installAmbariRequirements(getMachine())) .addAll(BashCommands.setHostname(fqdn)) .add(installPackage("ambari-agent")) .add(BashCommands.appendToEtcHosts( getParentAmbariCluster().getMasterAmbariServer().sensors().get(Attributes.SUBNET_ADDRESS), getEntity().getAmbariServerFQDN())) .build(); newScript(INSTALLING).body .append(commands) .failOnNonZeroResultCode() .execute(); }
@Override public void apply(final EntityLocal entity) { super.apply(entity); epochSensor = Sensors.newLongSensor(sensor.getName() + ".epoch"); if (entity.sensors().get(epochSensor) == null) { Long epoch = epochSupplier.get(); if (epoch == null) { epoch = CURRENT_TIME_SUPPLIER.get(); } entity.sensors().set(epochSensor, epoch); } FunctionFeed feed = FunctionFeed.builder() .entity(entity) .poll(new FunctionPollConfig<>(sensor).callable(new UpdateTimeSince(entity))) .period(period) .build(); entity.addFeed(feed); }
@Override public void install() { String fqdn = String.format("%s-%s.%s", entity.getConfig(AmbariCluster.SERVER_HOST_GROUP).toLowerCase(), entity.getId().toLowerCase(), entity.getConfig(AmbariCluster.DOMAIN_NAME)); getEntity().setFqdn(fqdn); ImmutableList<String> commands = ImmutableList.<String>builder() .add(ambariInstallHelper.installAmbariRequirements(getMachine())) .addAll(BashCommands.setHostname(fqdn)) .add(installPackage("ambari-server")) .build(); newScript(INSTALLING).body .append(commands) .failOnNonZeroResultCode() .execute(); }
@Override public void onAddEnricherFailed(EntityLocal entity, Enricher enricher, Exception e) { Exceptions.propagateIfFatal(e); String errmsg = "problem adding enricher "+enricher.getId()+" ("+enricher+") to entity "+entity.getId()+" ("+entity+")"; switch (addPolicyFailureMode) { case FAIL_FAST: throw new IllegalStateException("Rebind: aborting due to "+errmsg, e); case FAIL_AT_END: addPolicyFailures.add(new IllegalStateException(errmsg, e)); break; case CONTINUE: warn(errmsg+"; continuing", e); break; default: throw new IllegalStateException("Unexpected state '"+addPolicyFailureMode+"' for addPolicyFailureMode"); } }
private void executeSuccessfully(ConfigKey<String> configKey, String label) { if(Strings.isNonBlank(getEntity().getConfig(configKey))) { log.debug("Executing {} on entity {}", label, entity.getDisplayName()); int result = execute(ImmutableList.of(getEntity().getConfig(configKey)), label); if (0 != result) { log.debug("Executing {} failed with return code {}", label, result); throw new IllegalStateException("commands for " + configKey.getName() + " failed with return code " + result); } } }
protected void setInstallLabel() { if (((EntityInternal)getEntity()).config().getLocalRaw(SoftwareProcess.INSTALL_UNIQUE_LABEL).isPresentAndNonNull()) return; getEntity().config().set(SoftwareProcess.INSTALL_UNIQUE_LABEL, getEntity().getEntityType().getSimpleName()+ (Strings.isNonBlank(getVersion()) ? "_"+getVersion() : "")+ (Strings.isNonBlank(getInstallLabelExtraSalt()) ? "_"+getInstallLabelExtraSalt() : "") ); }
protected Maybe<MachineLocation> getMachine() { return Machines.findUniqueMachineLocation(entity.getLocations()); }
protected <T> void subscribe(Entity entity, Sensor<T> attribute, SensorEventListener<? super T> listener) { adjunctEntity.subscriptions().subscribe(entity, attribute, listener); }
@Override public void start() { WinRmMachineLocation machine = (WinRmMachineLocation) location; Integer port = entity.getConfig(WinRmTool.PROP_PORT); UserAndHostAndPort winrmAddress = UserAndHostAndPort.fromParts(machine.getUser(), machine.getAddress().getHostName(), Optional.fromNullable(port)); getEntity().sensors().set(Attributes.WINRM_ADDRESS, winrmAddress); super.start(); }
private String getDockerRegistryOpts() { String registryUrl = entity.config().get(DockerInfrastructure.DOCKER_IMAGE_REGISTRY_URL); if (Strings.isNonBlank(registryUrl)) { return format("--insecure-registry %s", registryUrl); } if (entity.config().get(DockerInfrastructure.DOCKER_SHOULD_START_REGISTRY)) { String firstHostname = entity.sensors().get(DynamicGroup.FIRST).sensors().get(Attributes.HOSTNAME); Integer registryPort = entity.config().get(DockerInfrastructure.DOCKER_REGISTRY_PORT); return format("--insecure-registry %s:%d", firstHostname, registryPort); } return null; }