/** * @param Orchestration $entity * @param \Keboola\StorageApi\Client $storageApi * @return Orchestration */ public function fillOrchestrationEntity(Orchestration $entity, Client $storageApi) { $oldTokenId = $entity->getTokenId(); $oldName = $entity->getName(); /** @var $entity Orchestration */ $entity = parent::fillEntity($entity); $name = $entity->getName(); if (empty($name)) { $entity->setName($oldName); } // token change if ($oldTokenId !== $entity->getTokenId()) { $token = $storageApi->getToken($entity->getTokenId()); $token = new Token(new Client(array('token' => $token['token'], 'url' => $storageApi->getApiUrl()))); $entity->setToken($token)->setTokenId($token->getId())->setTokenDesc($token->getDescription())->setTokenOwnerName($token->getOwnerName())->setProjectId($token->getProjectId()); } // notifications $data = $this->getPostJsonData(); if (!empty($data['notifications'])) { $data['notifications'] = array_map(function ($row) { $notification = new Notification(); $notification->fromArray($row); return $notification; }, $data['notifications']); $entity->setNotifications($data['notifications']); } // tasks $data = $this->getPostJsonData(); if (array_key_exists('tasks', $data)) { $entity->removeTasks(); $data['tasks'] = array_map(function ($row) { $notification = new OrchestrationTask(); $notification->fromArray($row); return $notification; }, $data['tasks']); foreach ($data['tasks'] as $task) { $entity->addTask($task); } } //@FIXME catch and throw exception return $entity; }
/** * @param Orchestration $orchestration * @param Client $storageApi * @return bool * @throws StorageApi\InvalidStateException */ private function validateConfiguration(Orchestration $orchestration, Client $storageApi) { $components = new Components($storageApi); $configuration = $components->getConfiguration(KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME, $orchestration->getId()); // same name if ($configuration['name'] !== $orchestration->getName()) { throw new StorageApi\InvalidStateException('Orchestration names are different'); } if (count($configuration['configuration']['tasks']) !== count($orchestration->getTasks())) { throw new StorageApi\InvalidStateException('Orchestration has same tasks count'); } $configurationTasks = $configuration['configuration']['tasks']; foreach ($orchestration->getTasks() as $i => $task) { $task = $task->toApiArray(); foreach ($task as $key => $value) { if ($configurationTasks[$i][$key] != $value) { throw new StorageApi\InvalidStateException(sprintf('Task %s is different: %s||%s', $task['id'], json_encode($task), $configurationTasks[$i])); } } } return true; }