http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskConstraints.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskConstraints.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskConstraints.java new file mode 100644 index 0000000..ace9928 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskConstraints.java @@ -0,0 +1,35 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler; + +/** + * Generic interface to represent some constraints that task can impose + * while figuring out whether to accept or reject the offer + * We may start small and then eventually add more constraints + */ +public interface TaskConstraints { + + /** + * Required number of ports + * + * @return portsNumber + */ + public int portsCount(); + +}
http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskConstraintsManager.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskConstraintsManager.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskConstraintsManager.java new file mode 100644 index 0000000..0665190 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskConstraintsManager.java @@ -0,0 +1,48 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler; + +import java.util.HashMap; +import java.util.Map; + +/** + * Factory class to keep map of the constraints + */ +public class TaskConstraintsManager { + + /** + * Since all the additions will happen during init time, there is no need to make this map Concurrent + * if/when later on it will change we may need to change HashMap to Concurrent one + */ + private Map<String, TaskConstraints> taskConstraintsMap = new HashMap<>(); + + public TaskConstraints getConstraints(String taskPrefix) { + return taskConstraintsMap.get(taskPrefix); + } + + public void addTaskConstraints(final String taskPrefix, final TaskConstraints taskConstraints) { + if (taskConstraints != null) { + taskConstraintsMap.put(taskPrefix, taskConstraints); + } + } + + public boolean exists(String taskPrefix) { + return taskConstraintsMap.containsKey(taskPrefix); + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskFactory.java new file mode 100644 index 0000000..33bc832 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskFactory.java @@ -0,0 +1,200 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Objects; + +import javax.inject.Inject; + +import org.apache.myriad.configuration.MyriadConfiguration; +import org.apache.myriad.configuration.MyriadExecutorConfiguration; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; + +import org.apache.mesos.Protos.CommandInfo; +import org.apache.mesos.Protos.CommandInfo.URI; +import org.apache.mesos.Protos.ExecutorID; +import org.apache.mesos.Protos.ExecutorInfo; +import org.apache.mesos.Protos.FrameworkID; +import org.apache.mesos.Protos.Offer; +import org.apache.mesos.Protos.Resource; +import org.apache.mesos.Protos.TaskInfo; +import org.apache.mesos.Protos.TaskID; +import org.apache.mesos.Protos.Value; +import org.apache.mesos.Protos.Value.Scalar; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Creates Tasks based on mesos offers + */ +public interface TaskFactory { + static final String YARN_RESOURCEMANAGER_HOSTNAME = "yarn.resourcemanager.hostname"; + static final String YARN_RESOURCEMANAGER_WEBAPP_ADDRESS = "yarn.resourcemanager.webapp.address"; + static final String YARN_RESOURCEMANAGER_WEBAPP_HTTPS_ADDRESS = "yarn.resourcemanager.webapp.https.address"; + static final String YARN_HTTP_POLICY = "yarn.http.policy"; + static final String YARN_HTTP_POLICY_HTTPS_ONLY = "HTTPS_ONLY"; + + TaskInfo createTask(Offer offer, FrameworkID frameworkId, TaskID taskId, org.apache.myriad.state.NodeTask nodeTask); + + // TODO(Santosh): This is needed because the ExecutorInfo constructed + // to launch NM needs to be specified to launch placeholder tasks for + // yarn containers (for fine grained scaling). + // If mesos supports just specifying the 'ExecutorId' without the full + // ExecutorInfo, we wouldn't need this interface method. + ExecutorInfo getExecutorInfoForSlave(FrameworkID frameworkId, Offer offer, CommandInfo commandInfo); + + /** + * Creates TaskInfo objects to launch NMs as mesos tasks. + */ + class NMTaskFactoryImpl implements TaskFactory { + public static final String EXECUTOR_NAME = "myriad_task"; + public static final String EXECUTOR_PREFIX = "myriad_executor"; + public static final String YARN_NODEMANAGER_OPTS_KEY = "YARN_NODEMANAGER_OPTS"; + + private static final Logger LOGGER = LoggerFactory.getLogger(NMTaskFactoryImpl.class); + private MyriadConfiguration cfg; + private TaskUtils taskUtils; + private ExecutorCommandLineGenerator clGenerator; + private TaskConstraints constraints; + + @Inject + public NMTaskFactoryImpl(MyriadConfiguration cfg, TaskUtils taskUtils, ExecutorCommandLineGenerator clGenerator) { + this.cfg = cfg; + this.taskUtils = taskUtils; + this.clGenerator = clGenerator; + this.constraints = new NMTaskConstraints(); + } + + //Utility function to get the first NMPorts.expectedNumPorts number of ports of an offer + private static NMPorts getPorts(Offer offer) { + HashSet<Long> ports = new HashSet<>(); + for (Resource resource : offer.getResourcesList()) { + if (resource.getName().equals("ports")) { + /* + ranges.getRangeList() returns a list of ranges, each range specifies a begin and end only. + so must loop though each range until we get all ports needed. We exit each loop as soon as all + ports are found so bounded by NMPorts.expectedNumPorts. + */ + Iterator<Value.Range> itr = resource.getRanges().getRangeList().iterator(); + while (itr.hasNext() && ports.size() < NMPorts.expectedNumPorts()) { + Value.Range range = itr.next(); + if (range.getBegin() <= range.getEnd()) { + long i = range.getBegin(); + while (i <= range.getEnd() && ports.size() < NMPorts.expectedNumPorts()) { + ports.add(i); + i++; + } + } + } + } + } + + Preconditions.checkState(ports.size() == NMPorts.expectedNumPorts(), "Not enough ports in offer"); + Long[] portArray = ports.toArray(new Long[ports.size()]); + return new NMPorts(portArray); + } + + @VisibleForTesting + CommandInfo getCommandInfo(ServiceResourceProfile profile, NMPorts ports) { + MyriadExecutorConfiguration myriadExecutorConfiguration = cfg.getMyriadExecutorConfiguration(); + CommandInfo.Builder commandInfo = CommandInfo.newBuilder(); + String cmd; + + if (myriadExecutorConfiguration.getNodeManagerUri().isPresent()) { + //Both FrameworkUser and FrameworkSuperuser to get all of the directory permissions correct. + if (!(cfg.getFrameworkUser().isPresent() && cfg.getFrameworkSuperUser().isPresent())) { + throw new RuntimeException("Trying to use remote distribution, but frameworkUser" + "and/or frameworkSuperUser not set!"); + } + String nodeManagerUri = myriadExecutorConfiguration.getNodeManagerUri().get(); + cmd = clGenerator.generateCommandLine(profile, ports); + + //get the nodemanagerURI + //We're going to extract ourselves, so setExtract is false + LOGGER.info("Getting Hadoop distribution from:" + nodeManagerUri); + URI nmUri = URI.newBuilder().setValue(nodeManagerUri).setExtract(false).build(); + + //get configs directly from resource manager + String configUrlString = clGenerator.getConfigurationUrl(); + LOGGER.info("Getting config from:" + configUrlString); + URI configUri = URI.newBuilder().setValue(configUrlString).build(); + LOGGER.info("Slave will execute command:" + cmd); + commandInfo.addUris(nmUri).addUris(configUri).setValue("echo \"" + cmd + "\";" + cmd); + commandInfo.setUser(cfg.getFrameworkSuperUser().get()); + + } else { + cmd = clGenerator.generateCommandLine(profile, ports); + commandInfo.setValue("echo \"" + cmd + "\";" + cmd); + + if (cfg.getFrameworkUser().isPresent()) { + commandInfo.setUser(cfg.getFrameworkUser().get()); + } + } + return commandInfo.build(); + } + + @Override + public TaskInfo createTask(Offer offer, FrameworkID frameworkId, TaskID taskId, org.apache.myriad.state.NodeTask nodeTask) { + Objects.requireNonNull(offer, "Offer should be non-null"); + Objects.requireNonNull(nodeTask, "NodeTask should be non-null"); + + NMPorts ports = getPorts(offer); + LOGGER.debug(ports.toString()); + + ServiceResourceProfile serviceProfile = nodeTask.getProfile(); + Scalar taskMemory = Scalar.newBuilder().setValue(serviceProfile.getAggregateMemory()).build(); + Scalar taskCpus = Scalar.newBuilder().setValue(serviceProfile.getAggregateCpu()).build(); + + CommandInfo commandInfo = getCommandInfo(serviceProfile, ports); + ExecutorInfo executorInfo = getExecutorInfoForSlave(frameworkId, offer, commandInfo); + + TaskInfo.Builder taskBuilder = TaskInfo.newBuilder().setName("task-" + taskId.getValue()).setTaskId(taskId).setSlaveId(offer.getSlaveId()); + + return taskBuilder.addResources(Resource.newBuilder().setName("cpus").setType(Value.Type.SCALAR).setScalar(taskCpus).build()).addResources(Resource.newBuilder().setName("mem").setType(Value.Type.SCALAR).setScalar(taskMemory).build()) + .addResources(Resource.newBuilder().setName("ports").setType(Value.Type.RANGES).setRanges(Value.Ranges.newBuilder().addRange(Value.Range.newBuilder().setBegin(ports.getRpcPort()).setEnd(ports.getRpcPort()).build()).addRange(Value.Range + .newBuilder().setBegin(ports.getLocalizerPort()).setEnd(ports.getLocalizerPort()).build()).addRange(Value.Range.newBuilder().setBegin(ports.getWebAppHttpPort()).setEnd(ports.getWebAppHttpPort()).build()).addRange(Value.Range + .newBuilder().setBegin(ports.getShufflePort()).setEnd(ports.getShufflePort()).build()))).setExecutor(executorInfo).build(); + } + + @Override + public ExecutorInfo getExecutorInfoForSlave(FrameworkID frameworkId, Offer offer, CommandInfo commandInfo) { + Scalar executorMemory = Scalar.newBuilder().setValue(taskUtils.getExecutorMemory()).build(); + Scalar executorCpus = Scalar.newBuilder().setValue(taskUtils.getExecutorCpus()).build(); + + ExecutorID executorId = ExecutorID.newBuilder().setValue(EXECUTOR_PREFIX + frameworkId.getValue() + + offer.getId().getValue() + offer.getSlaveId().getValue()).build(); + return ExecutorInfo.newBuilder().setCommand(commandInfo).setName(EXECUTOR_NAME).addResources(Resource.newBuilder().setName("cpus").setType(Value.Type.SCALAR).setScalar(executorCpus).build()).addResources(Resource.newBuilder().setName("mem") + .setType(Value.Type.SCALAR).setScalar(executorMemory).build()).setExecutorId(executorId).build(); + } + } + + /** + * Implement NM Task Constraints + */ + public static class NMTaskConstraints implements TaskConstraints { + + @Override + public int portsCount() { + return NMPorts.expectedNumPorts(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskTerminator.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskTerminator.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskTerminator.java new file mode 100644 index 0000000..f0b3fa6 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskTerminator.java @@ -0,0 +1,86 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler; + +import org.apache.myriad.scheduler.fgs.OfferLifecycleManager; +import org.apache.myriad.state.NodeTask; +import org.apache.myriad.state.SchedulerState; +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; + +import java.util.Set; + +import javax.inject.Inject; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.mesos.Protos.Status; +import org.apache.mesos.Protos.TaskID; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * {@link TaskTerminator} is responsible for killing tasks. + */ +public class TaskTerminator implements Runnable { + private static final Logger LOGGER = LoggerFactory.getLogger(TaskTerminator.class); + + private final SchedulerState schedulerState; + private final MyriadDriverManager driverManager; + private final OfferLifecycleManager offerLifeCycleManager; + + @Inject + public TaskTerminator(SchedulerState schedulerState, MyriadDriverManager driverManager, OfferLifecycleManager offerLifecycleManager) { + this.schedulerState = schedulerState; + this.driverManager = driverManager; + this.offerLifeCycleManager = offerLifecycleManager; + } + + @Override + public void run() { + // clone a copy of the killable tasks + Set<TaskID> killableTasks = Sets.newHashSet(schedulerState.getKillableTasks()); + + if (CollectionUtils.isEmpty(killableTasks)) { + return; + } + + Status driverStatus = driverManager.getDriverStatus(); + if (Status.DRIVER_RUNNING != driverStatus) { + LOGGER.warn("Cannot kill tasks, as driver is not running. Status: {}", driverStatus); + return; + } + + for (TaskID taskIdToKill : killableTasks) { + if (this.schedulerState.getPendingTaskIds().contains(taskIdToKill)) { + this.schedulerState.removeTask(taskIdToKill); + } else { + Status status = this.driverManager.kill(taskIdToKill); + NodeTask task = schedulerState.getTask(taskIdToKill); + if (task != null) { + offerLifeCycleManager.declineOutstandingOffers(task.getHostname()); + this.schedulerState.removeTask(taskIdToKill); + } else { + schedulerState.removeTask(taskIdToKill); + LOGGER.warn("NodeTask with taskId: {} does not exist", taskIdToKill); + } + Preconditions.checkState(status == Status.DRIVER_RUNNING); + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskUtils.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskUtils.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskUtils.java new file mode 100644 index 0000000..375ff3c --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/TaskUtils.java @@ -0,0 +1,208 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler; + +import org.apache.myriad.configuration.ServiceConfiguration; +import org.apache.myriad.configuration.MyriadBadConfigurationException; +import org.apache.myriad.configuration.MyriadConfiguration; +import org.apache.myriad.configuration.MyriadExecutorConfiguration; +import org.apache.myriad.configuration.NodeManagerConfiguration; +import com.google.common.base.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import javax.inject.Inject; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; + +/** + * utility class for working with tasks and node manager profiles + */ +public class TaskUtils { + private static final Logger LOGGER = LoggerFactory.getLogger(TaskUtils.class); + + private static final String YARN_NODEMANAGER_RESOURCE_CPU_VCORES = "yarn.nodemanager.resource.cpu-vcores"; + private static final String YARN_NODEMANAGER_RESOURCE_MEMORY_MB = "yarn.nodemanager.resource.memory-mb"; + + private MyriadConfiguration cfg; + + @Inject + public TaskUtils(MyriadConfiguration cfg) { + this.cfg = cfg; + } + + public static String getRevisedConfig(Double cpu, Double memory) { + String revisedConfig = ""; + try { + + // todo:(kgs) replace with more abstract xml parser + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + DocumentBuilder builder; + Document doc; + + builder = factory.newDocumentBuilder(); + InputStream resourceAsStream = TaskUtils.class.getClassLoader().getResourceAsStream("yarn-site.xml"); + + doc = builder.parse(new InputSource(resourceAsStream)); + resourceAsStream.close(); + + XPathFactory xFactory = XPathFactory.newInstance(); + + XPath xpath = xFactory.newXPath(); + XPathExpression cpuXpath = xpath.compile("//property/name"); + Object cpuNodeObj = cpuXpath.evaluate(doc, XPathConstants.NODESET); + + NodeList cpuNode = (NodeList) cpuNodeObj; + + for (int i = 0; i < cpuNode.getLength(); i++) { + Node item = cpuNode.item(i); + if (YARN_NODEMANAGER_RESOURCE_CPU_VCORES.equals(item.getTextContent())) { + Node propertyNode = item.getParentNode(); + NodeList childNodes = propertyNode.getChildNodes(); + for (int j = 0; j < childNodes.getLength(); j++) { + Node item2 = childNodes.item(j); + if ("value".equals(item2.getNodeName())) { + item2.setTextContent(cpu.intValue() + ""); + } + } + } else if (YARN_NODEMANAGER_RESOURCE_MEMORY_MB.equals(item.getTextContent())) { + Node propertyNode = item.getParentNode(); + NodeList childNodes = propertyNode.getChildNodes(); + for (int j = 0; j < childNodes.getLength(); j++) { + Node item2 = childNodes.item(j); + if ("value".equals(item2.getNodeName())) { + item2.setTextContent(memory.intValue() + ""); + } + } + } + } + + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer transformer = tf.newTransformer(); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + StringWriter writer = new StringWriter(); + transformer.transform(new DOMSource(doc), new StreamResult(writer)); + + revisedConfig = writer.getBuffer().toString().replaceAll("\n|\r", ""); + } catch (TransformerConfigurationException e) { + e.printStackTrace(); + } catch (TransformerException | SAXException | XPathExpressionException | ParserConfigurationException e) { + LOGGER.error("Error with xml operation", e); + } catch (IOException e) { + LOGGER.error("Error with xml operation", e); + } + return revisedConfig; + } + + public double getAggregateMemory(NMProfile profile) { + double totalTaskMemory; + double executorMemory = getExecutorMemory(); + double nmJvmMaxMemoryMB = getNodeManagerMemory(); + double advertisableMemory = profile.getMemory(); + totalTaskMemory = executorMemory + nmJvmMaxMemoryMB + advertisableMemory; + return totalTaskMemory; + } + + public double getAggregateCpus(NMProfile profile) { + return getNodeManagerCpus() + org.apache.myriad.executor.MyriadExecutorDefaults.DEFAULT_CPUS + profile.getCpus(); + } + + public double getNodeManagerMemory() { + NodeManagerConfiguration nmCfg = this.cfg.getNodeManagerConfiguration(); + return (nmCfg.getJvmMaxMemoryMB().isPresent() ? nmCfg.getJvmMaxMemoryMB().get() : NodeManagerConfiguration.DEFAULT_JVM_MAX_MEMORY_MB) * (1 + NodeManagerConfiguration.JVM_OVERHEAD); + } + + public double getNodeManagerCpus() { + Optional<Double> cpus = this.cfg.getNodeManagerConfiguration().getCpus(); + return cpus.isPresent() ? cpus.get() : NodeManagerConfiguration.DEFAULT_NM_CPUS; + } + + public double getExecutorCpus() { + + return org.apache.myriad.executor.MyriadExecutorDefaults.DEFAULT_CPUS; + } + + public double getExecutorMemory() { + MyriadExecutorConfiguration executorCfg = this.cfg.getMyriadExecutorConfiguration(); + return (executorCfg.getJvmMaxMemoryMB().isPresent() ? executorCfg.getJvmMaxMemoryMB().get() : org.apache.myriad.executor.MyriadExecutorDefaults.DEFAULT_JVM_MAX_MEMORY_MB) * (1 + org.apache.myriad.executor.MyriadExecutorDefaults.JVM_OVERHEAD); + } + + public double getTaskCpus(NMProfile profile) { + + return getAggregateCpus(profile) - getExecutorCpus(); + } + + public double getTaskMemory(NMProfile profile) { + + return getAggregateMemory(profile) - getExecutorMemory(); + } + + public double getAuxTaskCpus(NMProfile profile, String taskName) throws MyriadBadConfigurationException { + if (taskName.startsWith(NodeManagerConfiguration.NM_TASK_PREFIX)) { + return getAggregateCpus(profile); + } + ServiceConfiguration auxConf = cfg.getServiceConfiguration(taskName); + if (auxConf == null) { + throw new MyriadBadConfigurationException("Can not find profile for task name: " + taskName); + } + if (!auxConf.getCpus().isPresent()) { + throw new MyriadBadConfigurationException("cpu is not defined for task with name: " + taskName); + } + return auxConf.getCpus().get(); + } + + public double getAuxTaskMemory(NMProfile profile, String taskName) throws MyriadBadConfigurationException { + if (taskName.startsWith(NodeManagerConfiguration.NM_TASK_PREFIX)) { + return getAggregateMemory(profile); + } + ServiceConfiguration auxConf = cfg.getServiceConfiguration(taskName); + if (auxConf == null) { + throw new MyriadBadConfigurationException("Can not find profile for task name: " + taskName); + } + if (!auxConf.getJvmMaxMemoryMB().isPresent()) { + throw new MyriadBadConfigurationException("memory is not defined for task with name: " + taskName); + } + return auxConf.getJvmMaxMemoryMB().get(); + + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/Constraint.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/Constraint.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/Constraint.java new file mode 100644 index 0000000..6d66e5a --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/Constraint.java @@ -0,0 +1,35 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.constraints; + +/** + * Interface for Constraint. + */ +public interface Constraint { + /** + * Type of Constraint + */ + enum Type { + NULL, // to help with serialization + LIKE + } + + public Type getType(); + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/ConstraintFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/ConstraintFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/ConstraintFactory.java new file mode 100644 index 0000000..2929cb3 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/ConstraintFactory.java @@ -0,0 +1,36 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.constraints; + +/** + * Factory to create constraints. + */ +public class ConstraintFactory { + + public static Constraint createConstraint(String constraintStr) { + if (constraintStr != null) { + String[] splits = constraintStr.split(" LIKE "); + if (splits.length == 2) { + return new LikeConstraint(splits[0], splits[1]); + } + } + return null; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/LikeConstraint.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/LikeConstraint.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/LikeConstraint.java new file mode 100644 index 0000000..6ccda7b --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/constraints/LikeConstraint.java @@ -0,0 +1,113 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.constraints; + +import com.google.gson.Gson; +import java.util.Collection; +import java.util.regex.Pattern; +import org.apache.mesos.Protos.Attribute; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Constraint for LIKE operator. + * Format: <mesos_slave_attribute|hostname> LIKE <regex_value> + */ +public class LikeConstraint implements Constraint { + private static final Logger LOGGER = LoggerFactory.getLogger(LikeConstraint.class); + + private static final String HOSTNAME = "hostname"; + + private final String lhs; + private final Pattern pattern; + + public LikeConstraint(String lhs, String rhsRegex) { + this.lhs = lhs; + this.pattern = Pattern.compile(rhsRegex); + } + + public boolean isConstraintOnHostName() { + return lhs.equalsIgnoreCase(HOSTNAME); + } + + public boolean matchesHostName(String hostname) { + return lhs.equalsIgnoreCase(HOSTNAME) && hostname != null && pattern.matcher(hostname).matches(); + } + + public boolean matchesSlaveAttributes(Collection<Attribute> attributes) { + if (!lhs.equalsIgnoreCase(HOSTNAME) && attributes != null) { + for (Attribute attr : attributes) { + if (attr.getName().equalsIgnoreCase(lhs)) { + switch (attr.getType()) { + case TEXT: + return this.pattern.matcher(attr.getText().getValue()).matches(); + + case SCALAR: + return this.pattern.matcher(String.valueOf(attr.getScalar().getValue())).matches(); + + default: + LOGGER.warn("LIKE constraint currently doesn't support Mesos slave attributes " + "of type {}. Attribute Name: {}", attr.getType(), attr.getName()); + return false; + + } + } + } + } + return false; + } + + @Override + public Type getType() { + return Type.LIKE; + } + + @Override + public String toString() { + Gson gson = new Gson(); + return gson.toJson(this); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof LikeConstraint)) { + return false; + } + + LikeConstraint that = (LikeConstraint) o; + + if (lhs != null ? !lhs.equals(that.lhs) : that.lhs != null) { + return false; + } + if (pattern != null ? !pattern.pattern().equals(that.pattern.pattern()) : that.pattern != null) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + int result = lhs != null ? lhs.hashCode() : 0; + result = 31 * result + (pattern != null ? pattern.pattern().hashCode() : 0); + return result; + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/DisconnectedEvent.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/DisconnectedEvent.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/DisconnectedEvent.java new file mode 100644 index 0000000..f35045b --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/DisconnectedEvent.java @@ -0,0 +1,37 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import org.apache.mesos.SchedulerDriver; + +/** + * Event to disconnect from mesos + */ +public class DisconnectedEvent { + private SchedulerDriver driver; + + public SchedulerDriver getDriver() { + return driver; + } + + public void setDriver(SchedulerDriver driver) { + this.driver = driver; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/DisconnectedEventFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/DisconnectedEventFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/DisconnectedEventFactory.java new file mode 100644 index 0000000..481ec28 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/DisconnectedEventFactory.java @@ -0,0 +1,33 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import com.lmax.disruptor.EventFactory; + +/** + * Factory for creating the disconnect event + */ +public class DisconnectedEventFactory implements EventFactory<DisconnectedEvent> { + + @Override + public DisconnectedEvent newInstance() { + return new DisconnectedEvent(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ErrorEvent.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ErrorEvent.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ErrorEvent.java new file mode 100644 index 0000000..f870f1d --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ErrorEvent.java @@ -0,0 +1,46 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import org.apache.mesos.SchedulerDriver; + +/** + * Error event in the system + */ +public class ErrorEvent { + private SchedulerDriver driver; + private String message; + + public SchedulerDriver getDriver() { + return driver; + } + + public void setDriver(SchedulerDriver driver) { + this.driver = driver; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ErrorEventFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ErrorEventFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ErrorEventFactory.java new file mode 100644 index 0000000..9dde796 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ErrorEventFactory.java @@ -0,0 +1,33 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import com.lmax.disruptor.EventFactory; + +/** + * Factory for error events + */ +public class ErrorEventFactory implements EventFactory<ErrorEvent> { + + @Override + public ErrorEvent newInstance() { + return new ErrorEvent(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ExecutorLostEvent.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ExecutorLostEvent.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ExecutorLostEvent.java new file mode 100644 index 0000000..11cf892 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ExecutorLostEvent.java @@ -0,0 +1,65 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import org.apache.mesos.Protos; +import org.apache.mesos.SchedulerDriver; + +/** + * executor lost event + */ +public class ExecutorLostEvent { + private SchedulerDriver driver; + private Protos.ExecutorID executorId; + private Protos.SlaveID slaveId; + private int exitStatus; + + public SchedulerDriver getDriver() { + return driver; + } + + public void setDriver(SchedulerDriver driver) { + this.driver = driver; + } + + public Protos.ExecutorID getExecutorId() { + return executorId; + } + + public void setExecutorId(Protos.ExecutorID executorId) { + this.executorId = executorId; + } + + public Protos.SlaveID getSlaveId() { + return slaveId; + } + + public void setSlaveId(Protos.SlaveID slaveId) { + this.slaveId = slaveId; + } + + public int getExitStatus() { + return exitStatus; + } + + public void setExitStatus(int exitStatus) { + this.exitStatus = exitStatus; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ExecutorLostEventFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ExecutorLostEventFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ExecutorLostEventFactory.java new file mode 100644 index 0000000..5f79101 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ExecutorLostEventFactory.java @@ -0,0 +1,33 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import com.lmax.disruptor.EventFactory; + +/** + * executor lost event factory + */ +public class ExecutorLostEventFactory implements EventFactory<ExecutorLostEvent> { + + @Override + public ExecutorLostEvent newInstance() { + return new ExecutorLostEvent(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/FrameworkMessageEvent.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/FrameworkMessageEvent.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/FrameworkMessageEvent.java new file mode 100644 index 0000000..c0c2442 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/FrameworkMessageEvent.java @@ -0,0 +1,65 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import org.apache.mesos.Protos; +import org.apache.mesos.SchedulerDriver; + +/** + * framework message event + */ +public class FrameworkMessageEvent { + private SchedulerDriver driver; + private Protos.ExecutorID executorId; + private Protos.SlaveID slaveId; + private byte[] bytes; + + public SchedulerDriver getDriver() { + return driver; + } + + public void setDriver(SchedulerDriver driver) { + this.driver = driver; + } + + public Protos.ExecutorID getExecutorId() { + return executorId; + } + + public void setExecutorId(Protos.ExecutorID executorId) { + this.executorId = executorId; + } + + public Protos.SlaveID getSlaveId() { + return slaveId; + } + + public void setSlaveId(Protos.SlaveID slaveId) { + this.slaveId = slaveId; + } + + public byte[] getBytes() { + return bytes; + } + + public void setBytes(byte[] bytes) { + this.bytes = bytes; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/FrameworkMessageEventFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/FrameworkMessageEventFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/FrameworkMessageEventFactory.java new file mode 100644 index 0000000..31d1ff1 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/FrameworkMessageEventFactory.java @@ -0,0 +1,33 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import com.lmax.disruptor.EventFactory; + +/** + * framework message event factory + */ +public class FrameworkMessageEventFactory implements EventFactory<FrameworkMessageEvent> { + + @Override + public FrameworkMessageEvent newInstance() { + return new FrameworkMessageEvent(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/OfferRescindedEvent.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/OfferRescindedEvent.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/OfferRescindedEvent.java new file mode 100644 index 0000000..180655c --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/OfferRescindedEvent.java @@ -0,0 +1,47 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import org.apache.mesos.Protos; +import org.apache.mesos.SchedulerDriver; + +/** + * offer rescinded event + */ +public class OfferRescindedEvent { + private SchedulerDriver driver; + private Protos.OfferID offerId; + + public SchedulerDriver getDriver() { + return driver; + } + + public void setDriver(SchedulerDriver driver) { + this.driver = driver; + } + + public Protos.OfferID getOfferId() { + return offerId; + } + + public void setOfferId(Protos.OfferID offerId) { + this.offerId = offerId; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/OfferRescindedEventFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/OfferRescindedEventFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/OfferRescindedEventFactory.java new file mode 100644 index 0000000..9bea202 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/OfferRescindedEventFactory.java @@ -0,0 +1,32 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import com.lmax.disruptor.EventFactory; + +/** + * offer rescinded event factory + */ +public class OfferRescindedEventFactory implements EventFactory<OfferRescindedEvent> { + + @Override + public OfferRescindedEvent newInstance() { + return new OfferRescindedEvent(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ReRegisteredEvent.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ReRegisteredEvent.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ReRegisteredEvent.java new file mode 100644 index 0000000..d739a54 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ReRegisteredEvent.java @@ -0,0 +1,46 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import org.apache.mesos.Protos; +import org.apache.mesos.SchedulerDriver; + +/** + * Mesos re-register event + */ +public class ReRegisteredEvent { + private SchedulerDriver driver; + private Protos.MasterInfo masterInfo; + + public SchedulerDriver getDriver() { + return driver; + } + + public void setDriver(SchedulerDriver driver) { + this.driver = driver; + } + + public Protos.MasterInfo getMasterInfo() { + return masterInfo; + } + + public void setMasterInfo(Protos.MasterInfo masterInfo) { + this.masterInfo = masterInfo; + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ReRegisteredEventFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ReRegisteredEventFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ReRegisteredEventFactory.java new file mode 100644 index 0000000..92a9d0c --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ReRegisteredEventFactory.java @@ -0,0 +1,32 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import com.lmax.disruptor.EventFactory; + +/** + * Mesos re-register event factory + */ +public class ReRegisteredEventFactory implements EventFactory<ReRegisteredEvent> { + + @Override + public ReRegisteredEvent newInstance() { + return new ReRegisteredEvent(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/RegisteredEvent.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/RegisteredEvent.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/RegisteredEvent.java new file mode 100644 index 0000000..17a2c76 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/RegisteredEvent.java @@ -0,0 +1,56 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import org.apache.mesos.Protos; +import org.apache.mesos.SchedulerDriver; + +/** + * mesos register event + */ +public class RegisteredEvent { + private SchedulerDriver driver; + private Protos.FrameworkID frameworkId; + private Protos.MasterInfo masterInfo; + + public SchedulerDriver getDriver() { + return driver; + } + + public void setDriver(SchedulerDriver driver) { + this.driver = driver; + } + + public Protos.FrameworkID getFrameworkId() { + return frameworkId; + } + + public void setFrameworkId(Protos.FrameworkID frameworkId) { + this.frameworkId = frameworkId; + } + + public Protos.MasterInfo getMasterInfo() { + return masterInfo; + } + + public void setMasterInfo(Protos.MasterInfo masterInfo) { + this.masterInfo = masterInfo; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/RegisteredEventFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/RegisteredEventFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/RegisteredEventFactory.java new file mode 100644 index 0000000..8d39dc7 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/RegisteredEventFactory.java @@ -0,0 +1,33 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import com.lmax.disruptor.EventFactory; + +/** + * mesos register event factory + */ +public class RegisteredEventFactory implements EventFactory<RegisteredEvent> { + + @Override + public RegisteredEvent newInstance() { + return new RegisteredEvent(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ResourceOffersEvent.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ResourceOffersEvent.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ResourceOffersEvent.java new file mode 100644 index 0000000..1f52faa --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ResourceOffersEvent.java @@ -0,0 +1,48 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import org.apache.mesos.Protos; +import org.apache.mesos.SchedulerDriver; + +import java.util.List; + +/** + * resource offer event + */ +public class ResourceOffersEvent { + private SchedulerDriver driver; + private List<Protos.Offer> offers; + + public SchedulerDriver getDriver() { + return driver; + } + + public void setDriver(SchedulerDriver driver) { + this.driver = driver; + } + + public List<Protos.Offer> getOffers() { + return offers; + } + + public void setOffers(List<Protos.Offer> offers) { + this.offers = offers; + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ResourceOffersEventFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ResourceOffersEventFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ResourceOffersEventFactory.java new file mode 100644 index 0000000..99fbb00 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/ResourceOffersEventFactory.java @@ -0,0 +1,32 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import com.lmax.disruptor.EventFactory; + +/** + * resource offer event factory + */ +public class ResourceOffersEventFactory implements EventFactory<ResourceOffersEvent> { + + @Override + public ResourceOffersEvent newInstance() { + return new ResourceOffersEvent(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/SlaveLostEvent.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/SlaveLostEvent.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/SlaveLostEvent.java new file mode 100644 index 0000000..9342604 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/SlaveLostEvent.java @@ -0,0 +1,46 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import org.apache.mesos.Protos; +import org.apache.mesos.SchedulerDriver; + +/** + * mesos slave lost event + */ +public class SlaveLostEvent { + private SchedulerDriver driver; + private Protos.SlaveID slaveId; + + public SchedulerDriver getDriver() { + return driver; + } + + public void setDriver(SchedulerDriver driver) { + this.driver = driver; + } + + public Protos.SlaveID getSlaveId() { + return slaveId; + } + + public void setSlaveId(Protos.SlaveID slaveId) { + this.slaveId = slaveId; + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/SlaveLostEventFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/SlaveLostEventFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/SlaveLostEventFactory.java new file mode 100644 index 0000000..f79b50c --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/SlaveLostEventFactory.java @@ -0,0 +1,33 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import com.lmax.disruptor.EventFactory; + +/** + * mesos slave lost event factory + */ +public class SlaveLostEventFactory implements EventFactory<SlaveLostEvent> { + + @Override + public SlaveLostEvent newInstance() { + return new SlaveLostEvent(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/StatusUpdateEvent.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/StatusUpdateEvent.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/StatusUpdateEvent.java new file mode 100644 index 0000000..b55bb17 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/StatusUpdateEvent.java @@ -0,0 +1,47 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import org.apache.mesos.Protos; +import org.apache.mesos.SchedulerDriver; + +/** + * mesos status update event + */ +public class StatusUpdateEvent { + private SchedulerDriver driver; + private Protos.TaskStatus status; + + public SchedulerDriver getDriver() { + return driver; + } + + public void setDriver(SchedulerDriver driver) { + this.driver = driver; + } + + public Protos.TaskStatus getStatus() { + return status; + } + + public void setStatus(Protos.TaskStatus status) { + this.status = status; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/StatusUpdateEventFactory.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/StatusUpdateEventFactory.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/StatusUpdateEventFactory.java new file mode 100644 index 0000000..c797133 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/StatusUpdateEventFactory.java @@ -0,0 +1,33 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event; + +import com.lmax.disruptor.EventFactory; + +/** + * mesos status update event + */ +public class StatusUpdateEventFactory implements EventFactory<StatusUpdateEvent> { + + @Override + public StatusUpdateEvent newInstance() { + return new StatusUpdateEvent(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/DisconnectedEventHandler.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/DisconnectedEventHandler.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/DisconnectedEventHandler.java new file mode 100644 index 0000000..293676e --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/DisconnectedEventHandler.java @@ -0,0 +1,36 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event.handlers; + +import com.lmax.disruptor.EventHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * handles and logs disconnected events + */ +public class DisconnectedEventHandler implements EventHandler<org.apache.myriad.scheduler.event.DisconnectedEvent> { + private static final Logger LOGGER = LoggerFactory.getLogger(DisconnectedEventHandler.class); + + @Override + public void onEvent(org.apache.myriad.scheduler.event.DisconnectedEvent event, long sequence, boolean endOfBatch) throws Exception { + LOGGER.info("Framework disconnected!"); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ErrorEventHandler.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ErrorEventHandler.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ErrorEventHandler.java new file mode 100644 index 0000000..5c58c20 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ErrorEventHandler.java @@ -0,0 +1,37 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event.handlers; + +import com.lmax.disruptor.EventHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * handles and logs error events + */ +public class ErrorEventHandler implements EventHandler<org.apache.myriad.scheduler.event.ErrorEvent> { + private static final Logger LOGGER = LoggerFactory.getLogger(ErrorEventHandler.class); + + @Override + public void onEvent(org.apache.myriad.scheduler.event.ErrorEvent event, long sequence, boolean endOfBatch) throws Exception { + String message = event.getMessage(); + LOGGER.error(message); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ExecutorLostEventHandler.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ExecutorLostEventHandler.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ExecutorLostEventHandler.java new file mode 100644 index 0000000..053baaa --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ExecutorLostEventHandler.java @@ -0,0 +1,41 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event.handlers; + +import com.lmax.disruptor.EventHandler; +import org.apache.mesos.Protos.ExecutorID; +import org.apache.mesos.Protos.SlaveID; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * handles and logs executor lost events + */ +public class ExecutorLostEventHandler implements EventHandler<org.apache.myriad.scheduler.event.ExecutorLostEvent> { + private static final Logger LOGGER = LoggerFactory.getLogger(ExecutorLostEventHandler.class); + + @Override + public void onEvent(org.apache.myriad.scheduler.event.ExecutorLostEvent event, long sequence, boolean endOfBatch) throws Exception { + ExecutorID executorId = event.getExecutorId(); + SlaveID slaveId = event.getSlaveId(); + int exitStatus = event.getExitStatus(); + LOGGER.info("Executor {} of slave {} lost with exit status: {}", executorId, slaveId, exitStatus); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/FrameworkMessageEventHandler.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/FrameworkMessageEventHandler.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/FrameworkMessageEventHandler.java new file mode 100644 index 0000000..0140f93 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/FrameworkMessageEventHandler.java @@ -0,0 +1,40 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event.handlers; + +import com.lmax.disruptor.EventHandler; +import org.apache.mesos.Protos.ExecutorID; +import org.apache.mesos.Protos.SlaveID; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * handles and logs mesos framework messages + */ +public class FrameworkMessageEventHandler implements EventHandler<org.apache.myriad.scheduler.event.FrameworkMessageEvent> { + private static final Logger LOGGER = LoggerFactory.getLogger(FrameworkMessageEventHandler.class); + + @Override + public void onEvent(org.apache.myriad.scheduler.event.FrameworkMessageEvent event, long sequence, boolean endOfBatch) throws Exception { + ExecutorID executorId = event.getExecutorId(); + SlaveID slaveId = event.getSlaveId(); + LOGGER.info("Received framework message from executor {} of slave {}", executorId, slaveId); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/OfferRescindedEventHandler.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/OfferRescindedEventHandler.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/OfferRescindedEventHandler.java new file mode 100644 index 0000000..9d37ff1 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/OfferRescindedEventHandler.java @@ -0,0 +1,36 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event.handlers; + +import com.lmax.disruptor.EventHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * handles and logs offer rescinded events + */ +public class OfferRescindedEventHandler implements EventHandler<org.apache.myriad.scheduler.event.OfferRescindedEvent> { + private static final Logger LOGGER = LoggerFactory.getLogger(OfferRescindedEventHandler.class); + + @Override + public void onEvent(org.apache.myriad.scheduler.event.OfferRescindedEvent event, long sequence, boolean endOfBatch) throws Exception { + LOGGER.info("OfferRescinded event: {}", event); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ReRegisteredEventHandler.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ReRegisteredEventHandler.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ReRegisteredEventHandler.java new file mode 100644 index 0000000..57f9630 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/ReRegisteredEventHandler.java @@ -0,0 +1,46 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event.handlers; + +import org.apache.myriad.scheduler.ReconcileService; +import org.apache.myriad.scheduler.event.ReRegisteredEvent; +import org.apache.myriad.state.SchedulerState; +import com.google.inject.Inject; +import com.lmax.disruptor.EventHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * handles and logs mesos re-register events + */ +public class ReRegisteredEventHandler implements EventHandler<ReRegisteredEvent> { + private static final Logger LOGGER = LoggerFactory.getLogger(ReRegisteredEventHandler.class); + + @Inject + private SchedulerState state; + + @Inject + private ReconcileService reconcileService; + + @Override + public void onEvent(ReRegisteredEvent event, long sequence, boolean endOfBatch) throws Exception { + LOGGER.info("Framework re-registered: {}", event); + reconcileService.reconcile(event.getDriver()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-myriad/blob/101bcad3/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/RegisteredEventHandler.java ---------------------------------------------------------------------- diff --git a/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/RegisteredEventHandler.java b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/RegisteredEventHandler.java new file mode 100644 index 0000000..0678bf0 --- /dev/null +++ b/myriad-scheduler/src/main/java/org/apache/myriad/scheduler/event/handlers/RegisteredEventHandler.java @@ -0,0 +1,46 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 org.apache.myriad.scheduler.event.handlers; + +import com.lmax.disruptor.EventHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; + +/** + * handles and logs mesos registered events + */ +public class RegisteredEventHandler implements EventHandler<org.apache.myriad.scheduler.event.RegisteredEvent> { + private static final Logger LOGGER = LoggerFactory.getLogger(RegisteredEventHandler.class); + + @Inject + private org.apache.myriad.state.SchedulerState schedulerState; + + @Inject + private org.apache.myriad.scheduler.ReconcileService reconcileService; + + @Override + public void onEvent(org.apache.myriad.scheduler.event.RegisteredEvent event, long sequence, boolean endOfBatch) throws Exception { + LOGGER.info("Received event: {} with frameworkId: {}", event, event.getFrameworkId()); + schedulerState.setFrameworkId(event.getFrameworkId()); + reconcileService.reconcile(event.getDriver()); + } + +}