http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptHelper.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptHelper.java b/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptHelper.java deleted file mode 100644 index b722b1f..0000000 --- a/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptHelper.java +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package brooklyn.entity.basic.lifecycle; - -import static java.lang.String.format; -import groovy.lang.Closure; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; - -import javax.annotation.Nullable; - -import org.apache.brooklyn.api.mgmt.ExecutionContext; -import org.apache.brooklyn.api.mgmt.Task; -import org.apache.brooklyn.api.mgmt.TaskQueueingContext; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.brooklyn.location.basic.SshMachineLocation; -import org.apache.brooklyn.util.GroovyJavaMethods; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.core.internal.ssh.ShellTool; -import org.apache.brooklyn.util.core.mutex.WithMutexes; -import org.apache.brooklyn.util.core.task.DynamicTasks; -import org.apache.brooklyn.util.core.task.TaskBuilder; -import org.apache.brooklyn.util.core.task.Tasks; -import org.apache.brooklyn.util.exceptions.RuntimeInterruptedException; -import org.apache.brooklyn.util.stream.Streams; -import org.apache.brooklyn.util.text.Identifiers; -import org.apache.brooklyn.util.text.Strings; - -import com.google.common.annotations.Beta; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; - -public class ScriptHelper { - - public static final Logger log = LoggerFactory.getLogger(ScriptHelper.class); - - protected final NaiveScriptRunner runner; - public final String summary; - - public final ScriptPart header = new ScriptPart(this); - public final ScriptPart body = new ScriptPart(this); - public final ScriptPart footer = new ScriptPart(this); - - @SuppressWarnings("rawtypes") - protected final Map flags = new LinkedHashMap(); - protected Predicate<? super Integer> resultCodeCheck = Predicates.alwaysTrue(); - protected Predicate<? super ScriptHelper> executionCheck = Predicates.alwaysTrue(); - - protected boolean isTransient = false; - protected boolean isInessential = false; - protected boolean closeSshConnection = false; - protected boolean gatherOutput = false; - protected boolean noExtraOutput = false; - protected ByteArrayOutputStream stdout, stderr; - protected Task<Integer> task; - - public ScriptHelper(NaiveScriptRunner runner, String summary) { - this.runner = runner; - this.summary = summary; - } - - /** - * Takes a closure which accepts this ScriptHelper and returns true or false - * as to whether the script needs to run (or can throw error if desired) - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - public ScriptHelper executeIf(Closure c) { - Predicate<ScriptHelper> predicate = GroovyJavaMethods.predicateFromClosure(c); - return executeIf(predicate); - } - - public ScriptHelper executeIf(Predicate<? super ScriptHelper> c) { - executionCheck = c; - return this; - } - - public ScriptHelper skipIfBodyEmpty() { - Predicate<ScriptHelper> p = new Predicate<ScriptHelper>() { - @Override - public boolean apply(ScriptHelper input) { - return !input.body.isEmpty(); - } - }; - - return executeIf(p); - } - - public ScriptHelper failIfBodyEmpty() { - Predicate<ScriptHelper> p = new Predicate<ScriptHelper>() { - @Override - public boolean apply(ScriptHelper input) { - if (input.body.isEmpty()) { - throw new IllegalStateException("body empty for " + summary); - } - return true; - } - }; - - return executeIf(p); - } - - public ScriptHelper failOnNonZeroResultCode(boolean val) { - if (val) { - failOnNonZeroResultCode(); - } else { - requireResultCode(Predicates.alwaysTrue()); - } - return this; - } - - public ScriptHelper failOnNonZeroResultCode() { - return updateTaskAndFailOnNonZeroResultCode(); - } - - public ScriptHelper failOnNonZeroResultCodeWithoutUpdatingTask() { - requireResultCode(Predicates.equalTo(0)); - return this; - } - - public ScriptHelper updateTaskAndFailOnNonZeroResultCode() { - gatherOutput(); - // a failure listener would be a cleaner way - - resultCodeCheck = new Predicate<Integer>() { - @Override - public boolean apply(@Nullable Integer input) { - if (input==0) return true; - - try { - String notes = ""; - if (!getResultStderr().isEmpty()) - notes += "STDERR\n" + getResultStderr()+"\n"; - if (!getResultStdout().isEmpty()) - notes += "\n" + "STDOUT\n" + getResultStdout()+"\n"; - Tasks.setExtraStatusDetails(notes.trim()); - } catch (Exception e) { - log.warn("Unable to collect additional metadata on failure of "+summary+": "+e); - } - - return false; - } - }; - - return this; - } - - /** - * Convenience for error-checking the result. - * <p/> - * Takes closure which accepts bash exit code (integer), - * and returns false if it is invalid. Default is that this resultCodeCheck - * closure always returns true (and the exit code is made available to the - * caller if they care) - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - public ScriptHelper requireResultCode(Closure integerFilter) { - Predicate<Integer> objectPredicate = GroovyJavaMethods.predicateFromClosure(integerFilter); - return requireResultCode(objectPredicate); - } - - public ScriptHelper requireResultCode(Predicate<? super Integer> integerFilter) { - resultCodeCheck = integerFilter; - return this; - } - - protected Runnable mutexAcquire = new Runnable() { - public void run() { - } - }; - - protected Runnable mutexRelease = new Runnable() { - public void run() { - } - }; - - /** - * indicates that the script should acquire the given mutexId on the given mutexSupport - * and maintain it for the duration of script execution; - * typically used to prevent parallel scripts from conflicting in access to a resource - * (e.g. a folder, or a config file used by a process) - */ - public ScriptHelper useMutex(final WithMutexes mutexSupport, final String mutexId, final String description) { - mutexAcquire = new Runnable() { - public void run() { - try { - mutexSupport.acquireMutex(mutexId, description); - } catch (InterruptedException e) { - throw new RuntimeInterruptedException(e); - } - } - }; - - mutexRelease = new Runnable() { - public void run() { - mutexSupport.releaseMutex(mutexId); - } - }; - - return this; - } - - public ScriptHelper gatherOutput() { - return gatherOutput(true); - } - public ScriptHelper gatherOutput(boolean gather) { - gatherOutput = gather; - return this; - } - - /** - * Indicate that no extra output should be appended to stdout. - * <p> - * By default Brooklyn appends a message like - * "<tt>Executed /tmp/brooklyn-20141010-164855950...sh, result 0</tt>" - * to script output. - */ - public ScriptHelper noExtraOutput() { - return noExtraOutput(true); - } - - /** - * @see #noExtraOutput() - */ - private ScriptHelper noExtraOutput(boolean output) { - this.noExtraOutput = output; - return this; - } - - /** The connection should be closed and disconnected once the commands have executed. */ - public ScriptHelper closeSshConnection() { - closeSshConnection = true; - return this; - } - - /** Unique ID for the command execution; ensures new SSH connection from the pool. */ - public ScriptHelper uniqueSshConnection() { - setFlag(SshMachineLocation.UNIQUE_ID, Identifiers.makeRandomBase64Id(32)); - return this; - } - - /** indicates explicitly that the task can be safely forgotten about after it runs; useful for things like - * check_running which run repeatedly */ - public void setTransient() { - isTransient = true; - } - - public void setInessential() { - isInessential = true; - } - - public ScriptHelper inessential() { - isInessential = true; - return this; - } - - /** creates a task which will execute this script; note this can only be run once per instance of this class */ - public synchronized Task<Integer> newTask() { - if (task!=null) throw new IllegalStateException("task can only be generated once"); - TaskBuilder<Integer> tb = Tasks.<Integer>builder().name("ssh: "+summary).body( - new Callable<Integer>() { - public Integer call() throws Exception { - return executeInternal(); - } - }); - - try { - ByteArrayOutputStream stdin = new ByteArrayOutputStream(); - for (String line: getLines()) { - stdin.write(line.getBytes()); - stdin.write("\n".getBytes()); - } - tb.tag(BrooklynTaskTags.tagForStreamSoft(BrooklynTaskTags.STREAM_STDIN, stdin)); - } catch (IOException e) { - log.warn("Error registering stream "+BrooklynTaskTags.STREAM_STDIN+" on "+tb+": "+e, e); - } - - Map<?,?> env = (Map<?,?>) flags.get("env"); - if (env!=null) { - // if not explicitly set, env will come from getShellEnv in AbstractSoftwareProcessSshDriver.execute, - // which will also update this tag appropriately - tb.tag(BrooklynTaskTags.tagForEnvStream(BrooklynTaskTags.STREAM_ENV, env)); - } - - if (gatherOutput) { - stdout = new ByteArrayOutputStream(); - tb.tag(BrooklynTaskTags.tagForStreamSoft(BrooklynTaskTags.STREAM_STDOUT, stdout)); - stderr = new ByteArrayOutputStream(); - tb.tag(BrooklynTaskTags.tagForStreamSoft(BrooklynTaskTags.STREAM_STDERR, stderr)); - } - task = tb.build(); - if (isTransient) BrooklynTaskTags.setTransient(task); - if (isInessential) BrooklynTaskTags.setInessential(task); - return task; - } - - /** returns the task, if it has been constructed, or null; use {@link #newTask()} to build - * (if it is null and you need a task) */ - public Task<Integer> peekTask() { - return task; - } - - /** queues the task for execution if we are in a {@link TaskQueueingContext} (e.g. EffectorTaskFactory); - * or if we aren't in a queueing context, it will submit the task (assuming there is an {@link ExecutionContext} - * _and_ block until completion, throwing on error */ - @Beta - public Task<Integer> queue() { - return DynamicTasks.queueIfPossible(newTask()).orSubmitAndBlock().getTask(); - } - - public int execute() { - if (DynamicTasks.getTaskQueuingContext()!=null) { - return queue().getUnchecked(); - } else { - return executeInternal(); - } - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public int executeInternal() { - if (!executionCheck.apply(this)) { - return 0; - } - - List<String> lines = getLines(); - if (log.isTraceEnabled()) log.trace("executing: {} - {}", summary, lines); - - int result; - try { - mutexAcquire.run(); - Map flags = getFlags(); - if (closeSshConnection) { - flags.put("close", true); - } - if (gatherOutput) { - if (stdout==null) stdout = new ByteArrayOutputStream(); - if (stderr==null) stderr = new ByteArrayOutputStream(); - flags.put("out", stdout); - flags.put("err", stderr); - } - flags.put(ShellTool.PROP_NO_EXTRA_OUTPUT.getName(), noExtraOutput); - result = runner.execute(flags, lines, summary); - } catch (RuntimeInterruptedException e) { - throw logWithDetailsAndThrow(format("Execution failed, invocation error for %s: %s", summary, e.getMessage()), e); - } catch (Exception e) { - throw logWithDetailsAndThrow(format("Execution failed, invocation error for %s: %s", summary, e.getMessage()), e); - } finally { - mutexRelease.run(); - } - if (log.isTraceEnabled()) log.trace("finished executing: {} - result code {}", summary, result); - - if (!resultCodeCheck.apply(result)) { - throw logWithDetailsAndThrow(format("Execution failed, invalid result %s for %s", result, summary), null); - } - return result; - } - - protected RuntimeException logWithDetailsAndThrow(String message, Throwable optionalCause) { - log.warn(message+" (throwing)"); - Streams.logStreamTail(log, "STDERR of problem in "+Tasks.current(), stderr, 1024); - Streams.logStreamTail(log, "STDOUT of problem in "+Tasks.current(), stdout, 1024); - Streams.logStreamTail(log, "STDIN of problem in "+Tasks.current(), Streams.byteArrayOfString(Strings.join(getLines(),"\n")), 4096); - if (optionalCause!=null) throw new IllegalStateException(message, optionalCause); - throw new IllegalStateException(message); - } - - @SuppressWarnings("rawtypes") - public Map getFlags() { - return flags; - } - - @SuppressWarnings("unchecked") - public ScriptHelper setFlag(String flag, Object value) { - flags.put(flag, value); - return this; - } - - public <T> ScriptHelper setFlag(ConfigKey<T> flag, T value) { - return setFlag(flag.getName(), value); - } - - /** ensures the script runs with no environment variables; by default they will be inherited */ - public ScriptHelper environmentVariablesReset() { - return environmentVariablesReset(MutableMap.of()); - } - - /** overrides the default environment variables to use the given set; by default they will be inherited. - * TODO would be nice to have a way to add just a few, but there is no way currently to access the - * getShellEnvironment() from the driver which is what gets inherited (at execution time) */ - public ScriptHelper environmentVariablesReset(Map<?,?> envVarsToSet) { - setFlag("env", envVarsToSet); - return this; - } - - public List<String> getLines() { - List<String> result = new LinkedList<String>(); - result.addAll(header.lines); - result.addAll(body.lines); - result.addAll(footer.lines); - return result; - } - - public String getResultStdout() { - if (stdout==null) throw new IllegalStateException("output not available on "+this+"; ensure gatherOutput(true) is set"); - return stdout.toString(); - } - public String getResultStderr() { - if (stderr==null) throw new IllegalStateException("output not available on "+this+"; ensure gatherOutput(true) is set"); - return stderr.toString(); - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptPart.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptPart.java b/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptPart.java deleted file mode 100644 index e14c526..0000000 --- a/software/base/src/main/java/brooklyn/entity/basic/lifecycle/ScriptPart.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package brooklyn.entity.basic.lifecycle; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -public class ScriptPart { - protected ScriptHelper helper; - protected List<String> lines = new LinkedList<String>(); - - public ScriptPart(ScriptHelper helper) { - this.helper = helper; - } - - public ScriptHelper append(CharSequence line) { - lines.add(line.toString()); - return helper; - } - - public ScriptHelper append(Collection<? extends CharSequence> lines) { - for (CharSequence line : lines) { - append(line); - } - return helper; - } - - public ScriptHelper append(CharSequence... lines) { - return append(Arrays.asList(lines)); - } - - public ScriptHelper prepend(CharSequence line) { - lines.add(0, line.toString()); - return helper; - } - - public ScriptHelper prepend(Collection<? extends CharSequence> lines) { - List<CharSequence> reversedLines = new ArrayList<CharSequence>(lines); - Collections.reverse(reversedLines); - for (CharSequence line : reversedLines) { - prepend(line); - } - return helper; - } - - public ScriptHelper prepend(CharSequence... lines) { - return prepend(Arrays.asList(lines)); - } - - public ScriptHelper reset(CharSequence line) { - return reset(Arrays.asList(line)); - } - - public ScriptHelper reset(List<? extends CharSequence> ll) { - lines.clear(); - return append(ll); - } - - public boolean isEmpty() { - return lines.isEmpty(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynCluster.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynCluster.java b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynCluster.java deleted file mode 100644 index 0123231..0000000 --- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynCluster.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package brooklyn.entity.brooklynnode; - -import java.util.Map; - -import org.apache.brooklyn.api.effector.Effector; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.entity.ImplementedBy; -import org.apache.brooklyn.api.sensor.AttributeSensor; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.effector.core.Effectors; -import org.apache.brooklyn.entity.group.DynamicCluster; -import org.apache.brooklyn.sensor.core.Sensors; - -import brooklyn.entity.brooklynnode.effector.BrooklynNodeUpgradeEffectorBody; - -@ImplementedBy(BrooklynClusterImpl.class) -public interface BrooklynCluster extends DynamicCluster { - - ConfigKey<EntitySpec<?>> MEMBER_SPEC = ConfigKeys.newConfigKeyWithDefault(DynamicCluster.MEMBER_SPEC, - EntitySpec.create(BrooklynNode.class)); - - AttributeSensor<BrooklynNode> MASTER_NODE = Sensors.newSensor( - BrooklynNode.class, "brooklyncluster.master", "Pointer to the child node with MASTER state in the cluster"); - - interface SelectMasterEffector { - ConfigKey<String> NEW_MASTER_ID = ConfigKeys.newStringConfigKey( - "brooklyncluster.new_master_id", "The ID of the node to become master", null); - Effector<Void> SELECT_MASTER = Effectors.effector(Void.class, "selectMaster") - .description("Select a new master in the cluster") - .parameter(NEW_MASTER_ID) - .buildAbstract(); - } - - Effector<Void> SELECT_MASTER = SelectMasterEffector.SELECT_MASTER; - - interface UpgradeClusterEffector { - ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey(); - ConfigKey<Map<String,Object>> EXTRA_CONFIG = BrooklynNodeUpgradeEffectorBody.EXTRA_CONFIG; - - Effector<Void> UPGRADE_CLUSTER = Effectors.effector(Void.class, "upgradeCluster") - .description("Upgrade the cluster with new distribution version, " - + "by provisioning new nodes with the new version, failing over, " - + "and then deprovisioning the original nodes") - .parameter(BrooklynNode.SUGGESTED_VERSION) - .parameter(DOWNLOAD_URL) - .parameter(EXTRA_CONFIG) - .buildAbstract(); - } - - Effector<Void> UPGRADE_CLUSTER = UpgradeClusterEffector.UPGRADE_CLUSTER; - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynClusterImpl.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynClusterImpl.java b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynClusterImpl.java deleted file mode 100644 index 5209192..0000000 --- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynClusterImpl.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package brooklyn.entity.brooklynnode; - -import java.util.Collection; -import java.util.concurrent.Callable; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.mgmt.ha.ManagementNodeState; -import org.apache.brooklyn.entity.core.EntityFunctions; -import org.apache.brooklyn.entity.core.EntityPredicates; -import org.apache.brooklyn.entity.group.DynamicClusterImpl; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic.ServiceProblemsLogic; -import org.apache.brooklyn.sensor.enricher.Enrichers; -import org.apache.brooklyn.sensor.feed.function.FunctionFeed; -import org.apache.brooklyn.sensor.feed.function.FunctionPollConfig; -import org.apache.brooklyn.util.time.Duration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.entity.brooklynnode.effector.BrooklynClusterUpgradeEffectorBody; -import brooklyn.entity.brooklynnode.effector.SelectMasterEffectorBody; - -import com.google.common.collect.FluentIterable; -import com.google.common.collect.Iterables; - -public class BrooklynClusterImpl extends DynamicClusterImpl implements BrooklynCluster { - - private static final String MSG_NO_MASTER = "No master node in cluster"; - private static final String MSG_TOO_MANY_MASTERS = "Too many master nodes in cluster"; - - private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class); - - // TODO should we set a default MEMBER_SPEC ? difficult though because we'd need to set a password - - @Override - public void init() { - super.init(); - getMutableEntityType().addEffector(SelectMasterEffectorBody.SELECT_MASTER); - getMutableEntityType().addEffector(BrooklynClusterUpgradeEffectorBody.UPGRADE_CLUSTER); - - ServiceProblemsLogic.updateProblemsIndicator(this, MASTER_NODE, MSG_NO_MASTER); - addFeed(FunctionFeed.builder() - .entity(this) - .poll(new FunctionPollConfig<Object, BrooklynNode>(MASTER_NODE) - .period(Duration.ONE_SECOND) - .callable(new MasterChildFinder())) - .build()); - - addEnricher( Enrichers.builder().transforming(MASTER_NODE) - .uniqueTag("master-node-web-uri") - .publishing(BrooklynNode.WEB_CONSOLE_URI) - .computing(EntityFunctions.attribute(BrooklynNode.WEB_CONSOLE_URI)) - .build() ); - } - - private final class MasterChildFinder implements Callable<BrooklynNode> { - @Override - public BrooklynNode call() throws Exception { - return findMasterChild(); - } - } - - BrooklynNode findMasterChild() { - Collection<Entity> masters = FluentIterable.from(getMembers()) - .filter(EntityPredicates.attributeEqualTo(BrooklynNode.MANAGEMENT_NODE_STATE, ManagementNodeState.MASTER)) - .toList(); - - if (masters.size() == 0) { - ServiceProblemsLogic.updateProblemsIndicator(this, MASTER_NODE, MSG_NO_MASTER); - return null; - - } else if (masters.size() == 1) { - ServiceStateLogic.ServiceProblemsLogic.clearProblemsIndicator(this, MASTER_NODE); - return (BrooklynNode)Iterables.getOnlyElement(masters); - - } else if (masters.size() == 2) { - LOG.warn("Two masters detected, probably a handover just occured: " + masters); - - //Don't clearProblemsIndicator - if there were no masters previously why have two now. - //But also don't set it. Probably hit a window where we have a new master - //its BrooklynNode picked it up, but the BrooklynNode - //for the old master hasn't refreshed its state yet. - //Just pick one of them, should sort itself out in next update. - - //TODO Do set such indicator if this continues for an extended period of time - - return (BrooklynNode)masters.iterator().next(); - - } else { - ServiceProblemsLogic.updateProblemsIndicator(this, MASTER_NODE, MSG_TOO_MANY_MASTERS); - String msg = "Multiple (>=3) master nodes in cluster: " + masters; - LOG.error(msg); - throw new IllegalStateException(msg); - - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirror.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirror.java b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirror.java deleted file mode 100644 index c8b665f..0000000 --- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirror.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package brooklyn.entity.brooklynnode; - -import java.util.Map; - -import org.apache.brooklyn.api.catalog.Catalog; -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.ImplementedBy; -import org.apache.brooklyn.api.sensor.AttributeSensor; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.sensor.core.Sensors; -import org.apache.brooklyn.util.time.Duration; - -import brooklyn.entity.brooklynnode.BrooklynNode; - -/** Provides an entity which can sit in one brooklyn domain and reflect the status of an entity - * via the REST API of another domain. - * <p> - * Note tests for this depend on a REST server so are in other projects; search for *Mirror*Test, - * as well as *BrooklynNode*Test. */ -@Catalog(name="Brooklyn Entity Mirror", description="Provides an entity which can sit in one brooklyn " - + "domain and reflect the status of an entity via the REST API of another domain.") -@ImplementedBy(BrooklynEntityMirrorImpl.class) -public interface BrooklynEntityMirror extends Entity { - - // caller must specify this: - public static final ConfigKey<String> MIRRORED_ENTITY_URL = ConfigKeys.newStringConfigKey("brooklyn.mirror.entity_url", - "URL for the entity in the remote Brooklyn mgmt endpoint"); - - // caller may specify this for reference: - public static final ConfigKey<String> MIRRORED_ENTITY_ID = ConfigKeys.newStringConfigKey("brooklyn.mirror.entity_id", - "Brooklyn ID of the entity being mirrored"); - - // must be specified if required (could be inherited if parent/config is available at init time, but it's not currently) - public static final ConfigKey<String> MANAGEMENT_USER = BrooklynNode.MANAGEMENT_USER; - public static final ConfigKey<String> MANAGEMENT_PASSWORD = BrooklynNode.MANAGEMENT_PASSWORD; - - public static final ConfigKey<Duration> POLL_PERIOD = ConfigKeys.newConfigKey(Duration.class, "brooklyn.mirror.poll_period", - "Frequency to poll for client sensors", Duration.FIVE_SECONDS); - - public static final AttributeSensor<String> MIRROR_STATUS = Sensors.newStringSensor("brooklyn.mirror.monitoring_status"); - @SuppressWarnings("rawtypes") - public static final AttributeSensor<Map> MIRROR_SUMMARY = Sensors.newSensor(Map.class, "brooklyn.mirror.summary", - "The json map returned by the entity rest endpoint (ie the EntitySummary model)"); - public static final AttributeSensor<String> MIRROR_CATALOG_ITEM_ID = Sensors.newStringSensor("brooklyn.mirror.catalog_item_id", - "The catalog item id of the mirrored entity in the remote brooklyn"); - - public EntityHttpClient http(); - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorImpl.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorImpl.java b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorImpl.java deleted file mode 100644 index 72b9d01..0000000 --- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorImpl.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package brooklyn.entity.brooklynnode; - -import java.util.Collection; -import java.util.Map; -import java.util.concurrent.Callable; - -import javax.annotation.Nullable; - -import org.apache.brooklyn.api.effector.Effector; -import org.apache.brooklyn.effector.core.EffectorBody; -import org.apache.brooklyn.entity.core.AbstractEntity; -import org.apache.brooklyn.entity.core.Attributes; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.core.EntityDynamicType; -import org.apache.brooklyn.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic; -import org.apache.brooklyn.sensor.core.Sensors; -import org.apache.brooklyn.sensor.feed.http.HttpFeed; -import org.apache.brooklyn.sensor.feed.http.HttpPollConfig; -import org.apache.brooklyn.util.collections.Jsonya; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.core.config.ConfigBag; -import org.apache.brooklyn.util.core.http.HttpToolResponse; -import org.apache.brooklyn.util.core.task.DynamicTasks; -import org.apache.brooklyn.util.core.task.Tasks; -import org.apache.brooklyn.util.net.Urls; -import org.apache.http.HttpStatus; - -import com.google.common.base.Function; -import com.google.common.base.Preconditions; -import com.google.common.net.MediaType; -import com.google.gson.Gson; - -public class BrooklynEntityMirrorImpl extends AbstractEntity implements BrooklynEntityMirror { - @SuppressWarnings("rawtypes") - private class MirrorSummary implements Function<HttpToolResponse, Map> { - @Override - public Map apply(HttpToolResponse input) { - Map<?, ?> entitySummary = new Gson().fromJson(input.getContentAsString(), Map.class); - String catalogItemId = (String)entitySummary.get("catalogItemId"); - setAttribute(MIRROR_CATALOG_ITEM_ID, catalogItemId); - return entitySummary; - } - } - - private HttpFeed mirror; - - - //Passively mirror entity's state - @Override - protected void initEnrichers() {} - - @Override - public void init() { - super.init(); - connectSensorsAsync(); - - //start spinning, could take some time before MIRRORED_ENTITY_URL is available for first time mirroring - setAttribute(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING); - } - - @Override - public void rebind() { - super.rebind(); - connectSensorsAsync(); - } - - protected void connectSensorsAsync() { - Callable<Void> asyncTask = new Callable<Void>() { - @Override - public Void call() throws Exception { - //blocks until available (could be a task) - String mirroredEntityUrl = getConfig(MIRRORED_ENTITY_URL); - Preconditions.checkNotNull(mirroredEntityUrl, "Required config: "+MIRRORED_ENTITY_URL); - - connectSensors(mirroredEntityUrl); - return null; - } - }; - - DynamicTasks.queueIfPossible( - Tasks.<Void>builder() - .name("Start entity mirror feed") - .body(asyncTask) - .build()) - .orSubmitAsync(this); - } - - protected void connectSensors(String mirroredEntityUrl) { - Function<HttpToolResponse, Void> mirrorSensors = new Function<HttpToolResponse,Void>() { - @SuppressWarnings("rawtypes") - @Override - public Void apply(HttpToolResponse input) { - Map sensors = new Gson().fromJson(input.getContentAsString(), Map.class); - for (Object kv: sensors.entrySet()) - setAttribute(Sensors.newSensor(Object.class, ""+((Map.Entry)kv).getKey()), ((Map.Entry)kv).getValue()); - setAttribute(MIRROR_STATUS, "normal"); - return null; - } - }; - - final BrooklynEntityMirrorImpl self = this; - mirror = HttpFeed.builder().entity(this) - .baseUri(mirroredEntityUrl) - .credentialsIfNotNull(getConfig(BrooklynNode.MANAGEMENT_USER), getConfig(BrooklynNode.MANAGEMENT_PASSWORD)) - .period(getConfig(POLL_PERIOD)) - .poll(HttpPollConfig.forMultiple() - .suburl("/sensors/current-state") - .onSuccess(mirrorSensors) - .onFailureOrException(new Function<Object, Void>() { - @Override - public Void apply(Object input) { - ServiceStateLogic.updateMapSensorEntry(self, Attributes.SERVICE_PROBLEMS, "mirror-feed", "error contacting service"); - if (input instanceof HttpToolResponse) { - int responseCode = ((HttpToolResponse)input).getResponseCode(); - if (responseCode == HttpStatus.SC_NOT_FOUND) { - //the remote entity no longer exists - Entities.unmanage(self); - } - } - return null; - } - })) - .poll(HttpPollConfig.forSensor(MIRROR_SUMMARY).onSuccess(new MirrorSummary())).build(); - - populateEffectors(); - } - - private void populateEffectors() { - HttpToolResponse result = http().get("/effectors"); - Collection<?> cfgEffectors = new Gson().fromJson(result.getContentAsString(), Collection.class); - Collection<Effector<String>> remoteEntityEffectors = RemoteEffectorBuilder.of(cfgEffectors); - EntityDynamicType mutableEntityType = getMutableEntityType(); - for (Effector<String> eff : remoteEntityEffectors) { - //remote already started - if ("start".equals(eff.getName())) continue; - mutableEntityType.addEffector(eff); - } - } - - protected void disconnectSensors() { - if (mirror != null) mirror.stop(); - } - - @Override - public void destroy() { - disconnectSensors(); - } - - @Override - public EntityHttpClient http() { - return new EntityHttpClientImpl(this, MIRRORED_ENTITY_URL); - } - - public static class RemoteEffector<T> extends EffectorBody<T> { - public final String remoteEffectorName; - public final Function<HttpToolResponse, T> resultParser; - - /** creates an effector implementation which POSTs to a remote effector endpoint, optionally converting - * the byte[] response (if resultParser is null then null is returned) */ - public RemoteEffector(String remoteEffectorName, @Nullable Function<HttpToolResponse,T> resultParser) { - this.remoteEffectorName = remoteEffectorName; - this.resultParser = resultParser; - } - - @Override - public T call(ConfigBag parameters) { - MutableMap<String, String> headers = MutableMap.of(com.google.common.net.HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()); - byte[] httpBody = Jsonya.of(parameters.getAllConfig()).toString().getBytes(); - String effectorUrl = Urls.mergePaths("effectors", Urls.encode(remoteEffectorName)); - HttpToolResponse result = ((BrooklynEntityMirror)entity()).http().post(effectorUrl, headers, httpBody); - if (resultParser!=null) return resultParser.apply(result); - else return null; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java deleted file mode 100644 index e232d4e..0000000 --- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package brooklyn.entity.brooklynnode; - -import java.net.InetAddress; -import java.net.URI; -import java.util.List; -import java.util.Map; - -import org.apache.brooklyn.api.catalog.Catalog; -import org.apache.brooklyn.api.effector.Effector; -import org.apache.brooklyn.api.entity.ImplementedBy; -import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode; -import org.apache.brooklyn.api.mgmt.ha.ManagementNodeState; -import org.apache.brooklyn.api.sensor.AttributeSensor; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.BrooklynVersion; -import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.core.config.MapConfigKey; -import org.apache.brooklyn.effector.core.Effectors; -import org.apache.brooklyn.entity.core.BrooklynConfigKeys; -import org.apache.brooklyn.sensor.core.BasicAttributeSensor; -import org.apache.brooklyn.sensor.core.BasicAttributeSensorAndConfigKey; -import org.apache.brooklyn.sensor.core.PortAttributeSensorAndConfigKey; -import org.apache.brooklyn.sensor.core.Sensors; -import org.apache.brooklyn.sensor.core.BasicAttributeSensorAndConfigKey.StringAttributeSensorAndConfigKey; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.core.flags.SetFromFlag; -import org.apache.brooklyn.util.net.Networking; -import org.apache.brooklyn.util.ssh.BashCommands; -import org.apache.brooklyn.util.time.Duration; - -import brooklyn.entity.basic.SoftwareProcess; -import brooklyn.entity.java.UsesJava; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; -import com.google.common.base.Functions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.google.common.reflect.TypeToken; - -@Catalog(name="Brooklyn Node", description="Deploys a Brooklyn management server") -@ImplementedBy(BrooklynNodeImpl.class) -public interface BrooklynNode extends SoftwareProcess, UsesJava { - - @SuppressWarnings("serial") - @SetFromFlag("copyToRundir") - public static final BasicAttributeSensorAndConfigKey<Map<String,String>> COPY_TO_RUNDIR = new BasicAttributeSensorAndConfigKey<Map<String,String>>( - new TypeToken<Map<String,String>>() {}, "brooklynnode.copytorundir", "URLs of resources to be copied across to the server, giving the path they are to be copied to", MutableMap.<String,String>of()); - - @SetFromFlag("version") - public static final ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(BrooklynConfigKeys.SUGGESTED_VERSION, "0.8.0-SNAPSHOT"); // BROOKLYN_VERSION - - @SetFromFlag("distroUploadUrl") - public static final ConfigKey<String> DISTRO_UPLOAD_URL = ConfigKeys.newStringConfigKey( - "brooklynnode.distro.uploadurl", "URL for uploading the brooklyn distro (retrieved locally and pushed to remote install location. Takes precedence over downloadUrl, if non-null)", null); - - // Note that download URL only supports versions in org.apache.brooklyn, so not 0.6.0 and earlier - // (which used maven group io.brooklyn). Aled thinks we can live with that. - @SetFromFlag("downloadUrl") - BasicAttributeSensorAndConfigKey<String> DOWNLOAD_URL = new StringAttributeSensorAndConfigKey( - SoftwareProcess.DOWNLOAD_URL, - "<#if version?contains(\"SNAPSHOT\")>"+ - "https://repository.apache.org/service/local/artifact/maven/redirect?r=snapshots&g=org.apache.brooklyn&v=${version}&a=brooklyn-dist&c=dist&e=tar.gz" + - "<#else>"+ - "http://search.maven.org/remotecontent?filepath=org/apache/brooklyn/brooklyn-dist/${version}/brooklyn-dist-${version}-dist.tar.gz"+ - "</#if>"); - - @SetFromFlag("subpathInArchive") - ConfigKey<String> SUBPATH_IN_ARCHIVE = ConfigKeys.newStringConfigKey("brooklynnode.download.archive.subpath", - "Path to the main directory in the archive being supplied for installation; " - + "to use the root of an archive, specify '.'; " - + "default value taken based on download URL (e.g. 'name' for 'http://path/name.tgz' or 'http://path/name-dist.tgz') " - + "falling back to an appropriate value for brooklyn, " - + "e.g. 'brooklyn-"+BrooklynVersion.INSTANCE.getVersion()+"'", null); - - @SetFromFlag("managementUser") - ConfigKey<String> MANAGEMENT_USER = ConfigKeys.newConfigKey("brooklynnode.managementUser", - "The user for logging into the brooklyn web-console (also used for health-checks)", - "admin"); - - @SetFromFlag("managementPassword") - ConfigKey<String> MANAGEMENT_PASSWORD = - ConfigKeys.newStringConfigKey("brooklynnode.managementPassword", "Password for MANAGEMENT_USER", null); - - /** useful e.g. with {@link BashCommands#generateKeyInDotSshIdRsaIfNotThere() } */ - @SetFromFlag("extraCustomizationScript") - ConfigKey<String> EXTRA_CUSTOMIZATION_SCRIPT = ConfigKeys.newStringConfigKey("brooklynnode.customization.extraScript", - "Optional additional script commands to run as part of customization; this might e.g. ensure id_rsa is set up", - null); - - static enum ExistingFileBehaviour { - DO_NOT_USE, USE_EXISTING, OVERWRITE, FAIL - } - - @SetFromFlag("onExistingProperties") - ConfigKey<ExistingFileBehaviour> ON_EXISTING_PROPERTIES_FILE = ConfigKeys.newConfigKey(ExistingFileBehaviour.class, - "brooklynnode.properties.file.ifExists", - "What to do in the case where a global brooklyn.properties already exists", - ExistingFileBehaviour.FAIL); - - @SetFromFlag("launchCommand") - ConfigKey<String> LAUNCH_COMMAND = ConfigKeys.newStringConfigKey("brooklynnode.launch.command", - "Path to the script to launch Brooklyn / the app relative to the subpath in the archive, defaulting to 'bin/brooklyn'", - "bin/brooklyn"); - - @SetFromFlag("launchParameters") - ConfigKey<String> EXTRA_LAUNCH_PARAMETERS = ConfigKeys.newStringConfigKey("brooklynnode.launch.parameters.extra", - "Launch parameters passed on the CLI, in addition to 'launch' and parameters implied by other config keys (and placed afterwards on the command line)"); - - @SetFromFlag("launchCommandCreatesPidFile") - ConfigKey<Boolean> LAUNCH_COMMAND_CREATES_PID_FILE = ConfigKeys.newBooleanConfigKey("brooklynnode.launch.command.pid.updated", - "Whether the launch script creates/updates the PID file, if not the entity will do so, " - + "but note it will not necessarily kill sub-processes", - true); - - @SetFromFlag("app") - public static final BasicAttributeSensorAndConfigKey<String> APP = new BasicAttributeSensorAndConfigKey<String>( - String.class, "brooklynnode.app", "Application (fully qualified class name) to launch using the brooklyn CLI", null); - - @SetFromFlag("locations") - public static final BasicAttributeSensorAndConfigKey<String> LOCATIONS = new BasicAttributeSensorAndConfigKey<String>( - String.class, "brooklynnode.locations", "Locations to use when launching the app", null); - - /** - * Exposed just for testing; remote path is not passed into the launched brooklyn so this won't be used! - * This will likely change in a future version. - */ - @VisibleForTesting - @SetFromFlag("brooklynGlobalPropertiesRemotePath") - public static final ConfigKey<String> BROOKLYN_GLOBAL_PROPERTIES_REMOTE_PATH = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklynproperties.global.remotepath", - "Remote path for the global brooklyn.properties file to be uploaded", "${HOME}/.brooklyn/brooklyn.properties; "+ - "only useful for testing as this path will not be used on the remote system"); - - @SetFromFlag("brooklynGlobalPropertiesUri") - public static final ConfigKey<String> BROOKLYN_GLOBAL_PROPERTIES_URI = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklynproperties.global.uri", "URI for the global brooklyn properties file (uploaded to ~/.brooklyn/brooklyn.properties)", null); - - @SetFromFlag("brooklynGlobalPropertiesContents") - public static final ConfigKey<String> BROOKLYN_GLOBAL_PROPERTIES_CONTENTS = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklynproperties.global.contents", "Contents for the global brooklyn properties file (uploaded to ~/.brooklyn/brooklyn.properties)", null); - - @SetFromFlag("brooklynLocalPropertiesRemotePath") - public static final ConfigKey<String> BROOKLYN_LOCAL_PROPERTIES_REMOTE_PATH = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklynproperties.local.remotepath", "Remote path for the launch-specific brooklyn.properties file to be uploaded", "${driver.runDir}/brooklyn-local.properties"); - - @SetFromFlag("brooklynLocalPropertiesUri") - public static final ConfigKey<String> BROOKLYN_LOCAL_PROPERTIES_URI = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklynproperties.local.uri", "URI for the launch-specific brooklyn properties file", null); - - @SetFromFlag("brooklynLocalPropertiesContents") - public static final ConfigKey<String> BROOKLYN_LOCAL_PROPERTIES_CONTENTS = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklynproperties.local.contents", "Contents for the launch-specific brooklyn properties file", null); - - // For use in testing primarily - /** @deprecated since 0.7.0; TODO this should support BOM files */ - @Deprecated - @SetFromFlag("brooklynCatalogRemotePath") - public static final ConfigKey<String> BROOKLYN_CATALOG_REMOTE_PATH = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklyncatalog.remotepath", "Remote path for the brooklyn catalog.xml file to be uploaded", "${HOME}/.brooklyn/catalog.xml"); - - /** @deprecated since 0.7.0; TODO this should support BOM files */ - @Deprecated - @SetFromFlag("brooklynCatalogUri") - public static final ConfigKey<String> BROOKLYN_CATALOG_URI = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklyncatalog.uri", "URI for the brooklyn catalog.xml file (uploaded to ~/.brooklyn/catalog.xml)", null); - - /** @deprecated since 0.7.0; TODO this should support BOM files */ - @Deprecated - @SetFromFlag("brooklynCatalogContents") - public static final ConfigKey<String> BROOKLYN_CATALOG_CONTENTS = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklyncatalog.contents", "Contents for the brooklyn catalog.xml file (uploaded to ~/.brooklyn/catalog.xml)", null); - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @SetFromFlag("enabledHttpProtocols") - public static final BasicAttributeSensorAndConfigKey<List<String>> ENABLED_HTTP_PROTOCOLS = new BasicAttributeSensorAndConfigKey( - List.class, "brooklynnode.webconsole.enabledHttpProtocols", "List of enabled protocols (e.g. http, https)", ImmutableList.of("http")); - - @SetFromFlag("httpPort") - public static final PortAttributeSensorAndConfigKey HTTP_PORT = new PortAttributeSensorAndConfigKey( - "brooklynnode.webconsole.httpPort", "HTTP Port for the brooklyn web-console", "8081+"); - - @SetFromFlag("httpsPort") - public static final PortAttributeSensorAndConfigKey HTTPS_PORT = new PortAttributeSensorAndConfigKey( - "brooklynnode.webconsole.httpsPort", "HTTPS Port for the brooklyn web-console", "8443+"); - - @SetFromFlag("noWebConsoleSecurity") - public static final BasicAttributeSensorAndConfigKey<Boolean> NO_WEB_CONSOLE_AUTHENTICATION = new BasicAttributeSensorAndConfigKey<Boolean>( - Boolean.class, "brooklynnode.webconsole.nosecurity", "Whether to start the web console with no security", false); - - @SetFromFlag("bindAddress") - public static final BasicAttributeSensorAndConfigKey<InetAddress> WEB_CONSOLE_BIND_ADDRESS = new BasicAttributeSensorAndConfigKey<InetAddress>( - InetAddress.class, "brooklynnode.webconsole.address.bind", "Specifies the IP address of the NIC to bind the Brooklyn Management Console to (default 0.0.0.0)", Networking.ANY_NIC); - - @SetFromFlag("publicAddress") - public static final BasicAttributeSensorAndConfigKey<InetAddress> WEB_CONSOLE_PUBLIC_ADDRESS = new BasicAttributeSensorAndConfigKey<InetAddress>( - InetAddress.class, "brooklynnode.webconsole.address.public", "Specifies the public IP address or hostname for the Brooklyn Management Console"); - - public static final AttributeSensor<Boolean> WEB_CONSOLE_ACCESSIBLE = Sensors.newBooleanSensor( - "brooklynnode.webconsole.up", "Whether the web console is responding normally"); - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @SetFromFlag("classpath") - public static final BasicAttributeSensorAndConfigKey<List<String>> CLASSPATH = new BasicAttributeSensorAndConfigKey( - List.class, "brooklynnode.classpath", "classpath to use, as list of URL entries", Lists.newArrayList()); - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @SetFromFlag("portMapper") - public static final ConfigKey<Function<? super Integer, ? extends Integer>> PORT_MAPPER = (ConfigKey) ConfigKeys.newConfigKey(Function.class, - "brooklynnode.webconsole.portMapper", "Function for mapping private to public ports, for use in inferring the brooklyn URI", Functions.<Integer>identity()); - - public static final AttributeSensor<URI> WEB_CONSOLE_URI = new BasicAttributeSensor<URI>( - URI.class, "brooklynnode.webconsole.url", "URL of the brooklyn web-console"); - - public static final AttributeSensor<ManagementNodeState> MANAGEMENT_NODE_STATE = new BasicAttributeSensor<ManagementNodeState>( - ManagementNodeState.class, "brooklynnode.ha.state", "High-availability state of the management node (MASTER, HOT_STANDBY, etc)"); - - public static final ConfigKey<Duration> POLL_PERIOD = ConfigKeys.newConfigKey(Duration.class, "brooklynnode.poll_period", - "Frequency to poll for client sensors", Duration.seconds(2)); - - public interface DeployBlueprintEffector { - ConfigKey<Map<String,Object>> BLUEPRINT_CAMP_PLAN = new MapConfigKey<Object>(Object.class, "blueprintPlan", - "CAMP plan for the blueprint to be deployed; currently only supports Java map or JSON string (not yet YAML)"); - ConfigKey<String> BLUEPRINT_TYPE = ConfigKeys.newStringConfigKey("blueprintType"); - ConfigKey<Map<String,Object>> BLUEPRINT_CONFIG = new MapConfigKey<Object>(Object.class, "blueprintConfig"); - Effector<String> DEPLOY_BLUEPRINT = Effectors.effector(String.class, "deployBlueprint") - .description("Deploy a blueprint, either given a plan (as Java map or JSON string for a map), or given URL and optional config") - .parameter(BLUEPRINT_TYPE) - .parameter(BLUEPRINT_CONFIG) - .parameter(BLUEPRINT_CAMP_PLAN) - .buildAbstract(); - } - - public static final Effector<String> DEPLOY_BLUEPRINT = DeployBlueprintEffector.DEPLOY_BLUEPRINT; - - public interface ShutdownEffector { - ConfigKey<Boolean> STOP_APPS_FIRST = ConfigKeys.newBooleanConfigKey("stopAppsFirst", "Whether to stop apps before shutting down"); - ConfigKey<Boolean> FORCE_SHUTDOWN_ON_ERROR = ConfigKeys.newBooleanConfigKey("forceShutdownOnError", "Force shutdown if apps fail to stop or timeout"); - ConfigKey<Duration> SHUTDOWN_TIMEOUT = ConfigKeys.newConfigKey(Duration.class, "shutdownTimeout", "A maximum delay to wait for apps to gracefully stop before giving up or forcibly exiting"); - ConfigKey<Duration> REQUEST_TIMEOUT = ConfigKeys.newConfigKey(Duration.class, "requestTimeout", "Maximum time to block the request for the shutdown to finish, 0 to wait infinitely"); - ConfigKey<Duration> DELAY_FOR_HTTP_RETURN = ConfigKeys.newConfigKey(Duration.class, "delayForHttpReturn", "The delay before exiting the process, to permit the REST response to be returned"); - Effector<Void> SHUTDOWN = Effectors.effector(Void.class, "shutdown") - .description("Shutdown the remote brooklyn instance (stops via the REST API only; leaves any VM)") - .parameter(STOP_APPS_FIRST) - .parameter(FORCE_SHUTDOWN_ON_ERROR) - .parameter(SHUTDOWN_TIMEOUT) - .parameter(REQUEST_TIMEOUT) - .parameter(DELAY_FOR_HTTP_RETURN) - .buildAbstract(); - } - - public static final Effector<Void> SHUTDOWN = ShutdownEffector.SHUTDOWN; - - public interface StopNodeButLeaveAppsEffector { - ConfigKey<Duration> TIMEOUT = ConfigKeys.newConfigKey(Duration.class, "timeout", "How long to wait before giving up on stopping the node", Duration.ONE_HOUR); - Effector<Void> STOP_NODE_BUT_LEAVE_APPS = Effectors.effector(Void.class, "stopNodeButLeaveApps") - .description("Stop the Brooklyn process, and any VM created, and unmanage this entity; but if it was managing other applications, leave them running") - .parameter(TIMEOUT) - .buildAbstract(); - } - - public static final Effector<Void> STOP_NODE_BUT_LEAVE_APPS = StopNodeButLeaveAppsEffector.STOP_NODE_BUT_LEAVE_APPS; - - public interface StopNodeAndKillAppsEffector { - ConfigKey<Duration> TIMEOUT = ConfigKeys.newConfigKey(Duration.class, "timeout", "How long to wait before giving up on stopping the node", Duration.ONE_HOUR); - Effector<Void> STOP_NODE_AND_KILL_APPS = Effectors.effector(Void.class, "stopNodeAndKillApps") - .description("Stop all apps managed by the Brooklyn process, stop the process, and any VM created, and unmanage this entity") - .parameter(TIMEOUT) - .buildAbstract(); - } - - public static final Effector<Void> STOP_NODE_AND_KILL_APPS = StopNodeAndKillAppsEffector.STOP_NODE_AND_KILL_APPS; - - public interface SetHighAvailabilityPriorityEffector { - ConfigKey<Integer> PRIORITY = ConfigKeys.newIntegerConfigKey("priority", "HA priority"); - Effector<Integer> SET_HIGH_AVAILABILITY_PRIORITY = Effectors.effector(Integer.class, "setHighAvailabilityPriority") - .description("Set the HA priority on the node, returning the old priority") - .parameter(PRIORITY) - .buildAbstract(); - } - - public static final Effector<Integer> SET_HIGH_AVAILABILITY_PRIORITY = SetHighAvailabilityPriorityEffector.SET_HIGH_AVAILABILITY_PRIORITY; - - public interface SetHighAvailabilityModeEffector { - ConfigKey<HighAvailabilityMode> MODE = ConfigKeys.newConfigKey(HighAvailabilityMode.class, "mode", "HA mode"); - Effector<ManagementNodeState> SET_HIGH_AVAILABILITY_MODE = Effectors.effector(ManagementNodeState.class, "setHighAvailabilityMode") - .description("Set the HA mode on the node, returning the existing state") - .parameter(MODE) - .buildAbstract(); - } - - public static final Effector<ManagementNodeState> SET_HIGH_AVAILABILITY_MODE = SetHighAvailabilityModeEffector.SET_HIGH_AVAILABILITY_MODE; - - public EntityHttpClient http(); -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeDriver.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeDriver.java b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeDriver.java deleted file mode 100644 index df27e1f..0000000 --- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeDriver.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package brooklyn.entity.brooklynnode; - -import brooklyn.entity.java.JavaSoftwareProcessDriver; - -public interface BrooklynNodeDriver extends JavaSoftwareProcessDriver { - - void clearInstallDir(); - -}
