blob: 47409cd4d02e238d1d182571d92019114662cd41 [file] [log] [blame]
/**
* 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.
*/
#include <mesos/hook.hpp>
#include <mesos/mesos.hpp>
#include <mesos/module.hpp>
#include <mesos/module/hook.hpp>
#include <stout/foreach.hpp>
#include <stout/os.hpp>
#include <stout/try.hpp>
using namespace mesos;
// Must be kept in sync with variables of the same name in
// tests/hook_tests.cpp.
const char* testLabelKey = "MESOS_Test_Label";
const char* testLabelValue = "ApacheMesos";
class TestHook : public Hook
{
public:
virtual Result<Labels> masterLaunchTaskLabelDecorator(
const TaskInfo& taskInfo,
const FrameworkInfo& frameworkInfo,
const SlaveInfo& slaveInfo)
{
LOG(INFO) << "Executing 'masterLaunchTaskLabelDecorator' hook";
Labels labels;
Label *label = labels.add_labels();
label->set_key(testLabelKey);
label->set_value(testLabelValue);
return labels;
}
// In this hook, we create a new environment variable "FOO" and set
// it's value to "bar".
virtual Result<Environment> slaveExecutorEnvironmentDecorator(
const ExecutorInfo& executorInfo)
{
LOG(INFO) << "Executing 'slaveExecutorEnvironmentDecorator' hook";
Environment environment;
Environment::Variable* variable = environment.add_variables();
variable->set_name("FOO");
variable->set_value("bar");
return environment;
}
// This hook locates the file created by environment decorator hook
// and deletes it.
virtual Try<Nothing> slaveRemoveExecutorHook(
const FrameworkInfo& frameworkInfo,
const ExecutorInfo& executorInfo)
{
LOG(INFO) << "Executing 'slaveRemoveExecutorHook'";
// TODO(karya): Need to synchronize VerifySlaveLaunchExecutorHook
// test with this hook for validation. The issue is tracked by
// MESOS-2226.
return Nothing();
}
};
static Hook* createHook(const Parameters& parameters)
{
return new TestHook();
}
// Declares a Hook module named 'TestHook'.
mesos::modules::Module<Hook> org_apache_mesos_TestHook(
MESOS_MODULE_API_VERSION,
MESOS_VERSION,
"Apache Mesos",
"modules@mesos.apache.org",
"Test Hook module.",
NULL,
createHook);