#include <deque>
#include <ServerUtil.h>
+#include <Conf.h>
#include <JobAction.h>
#include "SchedTimer.h"
#include "JobRunner.h"
void JobManager::__verifyPeriodicJob(PeriodicJobInfo* jobInfo, IClient* owner)
{
- //TODO: parameter check
+ IF_FAIL_THROW_TAG(!(jobInfo->isOneTime() && jobInfo->isPersistent()), E_PARAM,
+ _W, "A one-time job cannot be persistent.");
+
+ IF_FAIL_THROW_TAG(jobInfo->getInterval() >= CTX_MIN_JOB_PERIOD, E_PARAM,
+ _W, "The interval is too short.");
+
+ IF_FAIL_THROW_TAG(jobInfo->getInterval() <= CTX_MAX_JOB_PERIOD, E_PARAM,
+ _W, "The interval is too long.");
+
+ IF_FAIL_THROW_TAG(jobInfo->getAnchor() >= 0, E_PARAM,
+ _W, "The anchor should be positive.");
+
__verifyRequirements(jobInfo, owner);
__verifyAction(jobInfo, owner);
}
void JobManager::__verifyOnDemandJob(OnDemandJobInfo* jobInfo, IClient* owner)
{
- //TODO: parameter check
+ IF_FAIL_THROW_TAG(!(jobInfo->isOneTime() && jobInfo->isPersistent()), E_PARAM,
+ _W, "A one-time job cannot be persistent.");
+
__verifyTriggers(jobInfo, owner);
__verifyRequirements(jobInfo, owner);
__verifyAction(jobInfo, owner);
void JobManager::__verifyTriggers(OnDemandJobInfo* jobInfo, IClient* owner)
{
+ IF_FAIL_THROW_TAG(!jobInfo->getTriggers().empty(), E_PARAM, _W, "No trigger");
+
for (auto& trig : jobInfo->getTriggers()) {
const std::string& uri = trig->getUri();
_D("Check %s", uri.c_str());
- if (!isSupported(JobContext::Type::TRIGGER, uri))
- throw static_cast<int>(E_SUPPORT);
+ IF_FAIL_THROW_TAG(isSupported(JobContext::Type::TRIGGER, uri), E_SUPPORT,
+ _W, "'%s' is not supported.", uri.c_str());
- if (!__isPermitted(owner, uri))
- throw static_cast<int>(E_ACCESS);
+ IF_FAIL_THROW_TAG(__isPermitted(owner, uri), E_ACCESS,
+ _W, "'%s' is not allowed to use '%s'.", owner->getName().c_str(), uri.c_str());
}
}
void JobManager::__verifyRequirements(JobInfo* jobInfo, IClient* owner)
{
+ IF_FAIL_THROW_TAG(jobInfo->getRequirementTimeout() <= CTX_MAX_REQ_TIMEOUT, E_PARAM,
+ _W, "The requirement timeout is too short.");
+
for (auto& req : jobInfo->getRequirements()) {
const std::string& uri = req->getUri();
_D("Check %s", uri.c_str());
- if (!isSupported(JobContext::Type::REQUIREMENT, uri))
- throw static_cast<int>(E_SUPPORT);
+ IF_FAIL_THROW_TAG(isSupported(JobContext::Type::REQUIREMENT, uri), E_SUPPORT,
+ _W, "'%s' is not supported.", uri.c_str());
- if (!__isPermitted(owner, uri))
- throw static_cast<int>(E_ACCESS);
+ IF_FAIL_THROW_TAG(__isPermitted(owner, uri), E_ACCESS,
+ _W, "'%s' is not allowed to use '%s'.", owner->getName().c_str(), uri.c_str());
}
}
}();
if (verified) return;
- throw static_cast<int>(E_PARAM);
+ _W("Invalid action");
+ throw E_PARAM;
}
unsigned int JobManager::__addRunner(JobRunner* runner)
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed 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.
+ */
+
+#ifndef __CONTEXT_JOB_SCHEDULER_CONF_H__
+#define __CONTEXT_JOB_SCHEDULER_CONF_H__
+
+#define CTX_MIN_JOB_PERIOD 1 // minutes
+#define CTX_MAX_JOB_PERIOD 1440 // minutes
+#define CTX_MAX_REQ_TIMEOUT 10000 // milli-seconds
+
+#endif /* __CONTEXT_JOB_SCHEDULER_CONF_H__ */