public function _action($from, $to, $action)
{
switch ($action) {
case static::ACT_CONVERT_TO_OBJECT:
/* @var $from OrchestrationRule */
switch ($from->scriptType) {
case OrchestrationRule::ORCHESTRATION_RULE_TYPE_SCALR:
$to->action = ['actionType' => static::ACTION_SCRIPT, 'scriptVersion' => ['script' => ['id' => $from->scriptId]]];
if (!empty($from->version)) {
$to->action['scriptVersion']['version'] = $from->version;
}
break;
case OrchestrationRule::ORCHESTRATION_RULE_TYPE_LOCAL:
$to->action = ['actionType' => static::ACTION_URI, 'path' => $from->scriptPath];
break;
case OrchestrationRule::ORCHESTRATION_RULE_TYPE_CHEF:
$to->action = ['actionType' => static::ACTION_CHEF];
break;
}
break;
case static::ACT_CONVERT_TO_ENTITY:
/* @var $to OrchestrationRule */
$action = $from->action;
if (empty($action->actionType)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed action type");
}
switch ($action->actionType) {
case static::ACTION_SCRIPT:
$scriptId = ApiController::getBareId($from->action->scriptVersion, 'script');
if (empty($scriptId)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property script.id");
}
$to->scriptId = $scriptId;
$from->action->scriptVersion->version = $from->action->scriptVersion->version ?: ScriptVersion::LATEST_SCRIPT_VERSION;
$to->version = $from->action->scriptVersion->version;
$to->scriptType = OrchestrationRule::ORCHESTRATION_RULE_TYPE_SCALR;
break;
case static::ACTION_URI:
if (empty($action->path)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property path");
}
$this->validateString($action->path, 'Property path contains invalid characters');
$to->scriptPath = $action->path;
$to->scriptType = OrchestrationRule::ORCHESTRATION_RULE_TYPE_LOCAL;
break;
case static::ACTION_CHEF:
$to->scriptType = OrchestrationRule::ORCHESTRATION_RULE_TYPE_CHEF;
break;
default:
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Unexpected actionType");
}
break;
case static::ACT_GET_FILTER_CRITERIA:
break;
}
}