Skip to content

Commit

Permalink
frontend: remove double call for getNodeInfo()
Browse files Browse the repository at this point in the history
This improves performance when rendering the main page of a service.

Also instances in a cluster are ordered by IP address.
  • Loading branch information
tcrivat committed Jul 16, 2016
1 parent b4419a2 commit 8c5348b
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 28 deletions.
8 changes: 4 additions & 4 deletions conpaas-frontend/www/lib/service/generic/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public function getInstanceRoles() {
return array('master', 'node');
}

public function createInstanceUI($node) {
$info = $this->getNodeInfo($node);
public function createInstanceUI($info) {
$nodeId = $info['id'];
if ($this->scriptStatus) {
$scriptStatus = $this->scriptStatus[$node];
$scriptStatus = $this->scriptStatus[$nodeId];
} else {
$scriptStatus = null;
}
if ($this->volumes) {
$volumes = $this->volumes[$node];
$volumes = $this->volumes[$nodeId];
} else {
$volumes = null;
}
Expand Down
3 changes: 1 addition & 2 deletions conpaas-frontend/www/lib/service/hadoop/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public function getAccessLocation() {
return 'http://'.$master_node['ip'];
}

public function createInstanceUI($node) {
$info = $this->getNodeInfo($node);
public function createInstanceUI($info) {
if ($this->nodesLists !== false) {
foreach ($this->nodesLists as $role => $nodesList) {
if (in_array($info['id'], $nodesList)) {
Expand Down
3 changes: 1 addition & 2 deletions conpaas-frontend/www/lib/service/htc/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public function fetchStateLog() {
return array();
}

public function createInstanceUI($node) {
$info = $this->getNodeInfo($node);
public function createInstanceUI($info) {
return new HTCInstance($info);
}

Expand Down
3 changes: 1 addition & 2 deletions conpaas-frontend/www/lib/service/htcondor/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public function fetchStateLog() {
return array();
}

public function createInstanceUI($node) {
$info = $this->getNodeInfo($node);
public function createInstanceUI($info) {
return new HTCondorInstance($info);
}

Expand Down
3 changes: 1 addition & 2 deletions conpaas-frontend/www/lib/service/java/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public function sendConfiguration($params) {
$params);
}

public function createInstanceUI($node) {
$info = $this->getNodeInfo($node);
public function createInstanceUI($info) {
return new JavaInstance($info);
}

Expand Down
3 changes: 1 addition & 2 deletions conpaas-frontend/www/lib/service/mysql/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public function getInstanceRoles() {
return array('mysql', 'glb');
}

public function createInstanceUI($node) {
$info = $this->getNodeInfo($node);
public function createInstanceUI($info) {
return new MySQLInstance($info);
}

Expand Down
3 changes: 1 addition & 2 deletions conpaas-frontend/www/lib/service/php/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public function sendConfiguration($params) {
$params);
}

public function createInstanceUI($node) {
$info = $this->getNodeInfo($node);
public function createInstanceUI($info) {
return new PHPInstance($info);
}

Expand Down
3 changes: 1 addition & 2 deletions conpaas-frontend/www/lib/service/scalaris/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function getInstanceRoles() {
return array('scalaris');
}

public function createInstanceUI($node) {
$info = $this->getNodeInfo($node);
public function createInstanceUI($info) {
return new ScalarisInstance($info);
}

Expand Down
3 changes: 1 addition & 2 deletions conpaas-frontend/www/lib/service/selenium/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public function getInstanceRoles() {
return array('hub', 'node');
}

public function createInstanceUI($node) {
$info = $this->getNodeInfo($node);
public function createInstanceUI($info) {
return new SeleniumInstance($info);
}

Expand Down
3 changes: 1 addition & 2 deletions conpaas-frontend/www/lib/service/xtreemfs/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public function needsPolling() {
return parent::needsPolling() || $this->state == self::STATE_INIT;
}

public function createInstanceUI($node) {
$info = $this->getNodeInfo($node);
public function createInstanceUI($info) {
return new XtreemFSInstance($info);
}

Expand Down
17 changes: 11 additions & 6 deletions conpaas-frontend/www/lib/ui/page/ServicePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function getNodes() {
$info = $this->service->getNodeInfo($node);
if ($info !== false) {
$cluster = new Cluster($nodeRoles);
$cluster->addNode($this->service->createInstanceUI($node));
$cluster->addNode($this->service->createInstanceUI($info));
$nodesInfo[] = $cluster;
}
$selected[$node] = true;
Expand All @@ -172,20 +172,25 @@ public function getNodes() {

// For each role, get the remaining nodes (that were not added already)
foreach ($roles as $role) {
$remainingNodes = array();
$remainingNodesInfo = array();
foreach ($nodesLists[$role] as $node) {
if (!array_key_exists($node, $selected)) {
$info = $this->service->getNodeInfo($node);
if ($info !== false) {
$remainingNodes[] = $node;
$remainingNodesInfo[] = $info;
}
}
}
if (count($remainingNodes) > 0) {
if (count($remainingNodesInfo) > 0) {
// Sort the nodes by the IP address
usort($remainingNodesInfo, function($i1, $i2) {
return strcmp($i1['ip'], $i2['ip']);
});

// We add all these nodes together in a cluster
$cluster = new Cluster(array($role));
foreach ($remainingNodes as $node) {
$cluster->addNode($this->service->createInstanceUI($node));
foreach ($remainingNodesInfo as $info) {
$cluster->addNode($this->service->createInstanceUI($info));
}
$nodesInfo[] = $cluster;
}
Expand Down

0 comments on commit 8c5348b

Please sign in to comment.