Skip to content

Commit

Permalink
PLAT-8047: fixes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
noam-arad committed Jan 14, 2018
1 parent 69059bc commit 97da8e8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
15 changes: 9 additions & 6 deletions api_v3/services/ServerNodeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ function reportStatusAction($hostName, KalturaServerNode $serverNode = null)
}

$dbServerNode->setHeartbeatTime(time());
if ($dbServerNode->getStatus() == ServerNodeStatus::NOT_REGISTERED)
$dbServerNode->setStatus(ServerNodeStatus::ACTIVE);
$dbServerNode->setStatus(ServerNodeStatus::ACTIVE);
$dbServerNode->save();

$serverNode = KalturaServerNode::getInstance($dbServerNode, $this->getResponseProfile());
Expand All @@ -192,17 +191,21 @@ private function addNewServerNode(KalturaServerNode $serverNode)
}

/**
* Unregister server node by id
* Mark server node offline
*
* @action unregister
* @action markOffline
* @param string $serverNodeId
* @throws KalturaErrors::INVALID_OBJECT_ID
* @return KalturaServerNode
* @throws KalturaAPIException
*/
function unregisterAction($serverNodeId)
function markOfflineAction($serverNodeId)
{
$dbServerNode = ServerNodePeer::retrieveByPK($serverNodeId);
$criteria = new Criteria(ServerNodePeer::DATABASE_NAME);
$criteria->add(ServerNodePeer::ID, $serverNodeId);
$criteria->add(ServerNodePeer::STATUS, ServerNodeStatus::ACTIVE);
$dbServerNode = ServerNodePeer::doSelectOne($criteria);

if(!$dbServerNode)
throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $serverNodeId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public static function getType()
public function run($jobs = null)
{
$filter = new KalturaServerNodeFilter();
$filter->statusEqual=KalturaServerNodeStatus::ACTIVE;
$filter->typeIn=self::$taskConfig->params->typesToMonitor;
$filter->heartbeatTimeLessThanOrEqual = (time() - self::$taskConfig->params->serverNodeTTL);
$pager = new KalturaFilterPager();
$pager->pageSize=1000;
$pager->pageSize=500;
$pager->pageIndex = 1;
$serverNodes = self::$kClient->serverNode->listAction($filter, $pager);
while (count($serverNodes->objects))
Expand All @@ -39,11 +39,8 @@ public function run($jobs = null)
/**
* @var KalturaEdgeServerNode $serverNode
*/
if ($serverNode->heartbeatTime < (time() - self::$taskConfig->params->serverNodeTTL))
{
KalturaLog::info("ServerNode [" . $serverNode->id . "] is offline");
self::$kClient->serverNode->unregister($serverNode->id);
}
KalturaLog::info("ServerNode [" . $serverNode->id . "] is offline, last heartbeat [" . $serverNode->heartbeatTime . "]");
self::$kClient->serverNode->markOffline($serverNode->id);
}

$pager->pageIndex++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,13 @@
<eventType>3</eventType> <!-- EventNotificationEventType::OBJECT_CHANGED -->
<eventObjectType>39</eventObjectType> <!-- EventNotificationEventObjectType::SERVER_NODE -->
<eventConditions objectType="array">
<item objectType="KalturaEventObjectChangedCondition">
<description>Server Node status changed </description>
<modifiedColumns>status</modifiedColumns>
<field objectType="KalturaEvalStringField">
<code>$scope->getObject()->getType()</code>
</field>
</item>
<item objectType="KalturaEventFieldCondition">
<field objectType="KalturaEvalBooleanField">
<code>$scope->getObject() instanceof EdgeServerNode &amp;&amp; $scope->getObject()->getStatus() == ServerNodeStatus::NOT_REGISTERED</code>
Expand Down
2 changes: 1 addition & 1 deletion deployment/permissions/service.servernode.ini
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ permissionItem8.tags =
permissionItem8.permissions = SERVER_NODE_UPDATE

permissionItem9.service = servernode
permissionItem9.action = unregister
permissionItem9.action = markoffline
permissionItem9.partnerId = 0
permissionItem9.param3 =
permissionItem9.param4 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
<eventType>3</eventType> <!-- EventNotificationEventType::OBJECT_CHANGED -->
<eventObjectType>39</eventObjectType> <!-- EventNotificationEventObjectType::SERVER_NODE -->
<eventConditions objectType="array">
<item objectType="KalturaEventObjectChangedCondition">
<description>Server Node status changed </description>
<modifiedColumns>status</modifiedColumns>
<field objectType="KalturaEvalStringField">
<code>$scope->getObject()->getType()</code>
</field>
</item>
<item objectType="KalturaEventFieldCondition">
<field objectType="KalturaEvalBooleanField">
<code>$scope->getObject() instanceof EdgeServerNode &amp;&amp; $scope->getObject()->getStatus() == ServerNodeStatus::NOT_REGISTERED</code>
Expand Down

0 comments on commit 97da8e8

Please sign in to comment.