Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Adding mode of operations - either single-instance or clus… #29492

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,15 @@
*/
'config_is_read_only' => false,

/**
* This defines the mode of operations. The default value is 'single-instance'
* which means that ownCloud is running on a single node, which might be the
* most common operations mode. The only other possible value for now is
* 'clustered-instance' which means that ownCloud is running on at least 2
* nodes. The mode of operations has various impact on the behavior of ownCloud.
*/
'operation.mode' => 'single-instance',

/**
* Logging
*/
Expand Down
12 changes: 11 additions & 1 deletion lib/private/App/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\Files;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserSession;
Expand Down Expand Up @@ -72,24 +73,29 @@ class AppManager implements IAppManager {
private $alwaysEnabled;
/** @var EventDispatcherInterface */
private $dispatcher;
/** @var IConfig */
private $config;

/**
* @param IUserSession $userSession
* @param IAppConfig $appConfig
* @param IGroupManager $groupManager
* @param ICacheFactory $memCacheFactory
* @param EventDispatcherInterface $dispatcher
* @param IConfig $config
*/
public function __construct(IUserSession $userSession = null,
IAppConfig $appConfig,
IGroupManager $groupManager,
ICacheFactory $memCacheFactory,
EventDispatcherInterface $dispatcher) {
EventDispatcherInterface $dispatcher,
IConfig $config) {
$this->userSession = $userSession;
$this->appConfig = $appConfig;
$this->groupManager = $groupManager;
$this->memCacheFactory = $memCacheFactory;
$this->dispatcher = $dispatcher;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -435,6 +441,10 @@ public function readAppPackage($path) {
* @since 10.0.3
*/
public function canInstall() {
if ($this->config->getSystemValue('operation.mode', 'single-instance') !== 'single-instance') {
return false;
}

$appsFolder = OC_App::getInstallPath();
return $appsFolder !== null && is_writable($appsFolder) && is_readable($appsFolder);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ public function isReadOnly() {
if (!$this->getValue('installed', false)) {
return false;
}
if ($this->getValue('operation.mode', 'single-instance') !== 'single-instance') {
return false;
}

return $this->getValue('config_is_read_only', false);
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ public function __construct($webRoot, \OC\Config $config) {
$c->getAppConfig(),
$c->getGroupManager(),
$c->getMemCacheFactory(),
$c->getEventDispatcher()
$c->getEventDispatcher(),
$c->getConfig()
);
});
$this->registerService('DateTimeZone', function (Server $c) {
Expand Down
99 changes: 64 additions & 35 deletions tests/lib/App/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@

namespace Test\App;

use OC\App\AppManager;
use OC\Group\Group;
use OCP\App\IAppManager;
use OCP\IAppConfig;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;

Expand All @@ -21,12 +29,30 @@
* @group DB
*/
class ManagerTest extends TestCase {

/** @var IUserSession | \PHPUnit_Framework_MockObject_MockObject */
protected $userSession;
/** @var IGroupManager | \PHPUnit_Framework_MockObject_MockObject */
protected $groupManager;
/** @var IAppConfig */
protected $appConfig;
/** @var ICache | \PHPUnit_Framework_MockObject_MockObject */
protected $cache;
/** @var ICacheFactory | \PHPUnit_Framework_MockObject_MockObject */
protected $cacheFactory;
/** @var IAppManager */
protected $manager;
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
protected $eventDispatcher;
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
private $config;

/**
* @return \OCP\IAppConfig | \PHPUnit_Framework_MockObject_MockObject
* @return IAppConfig | \PHPUnit_Framework_MockObject_MockObject
*/
protected function getAppConfig() {
$appConfig = [];
$config = $this->getMockBuilder('\OCP\IAppConfig')
$config = $this->getMockBuilder(IAppConfig::class)
->disableOriginalConstructor()
->getMock();

Expand Down Expand Up @@ -62,41 +88,23 @@ protected function getAppConfig() {
return $config;
}

/** @var \OCP\IUserSession | \PHPUnit_Framework_MockObject_MockObject */
protected $userSession;

/** @var \OCP\IGroupManager | \PHPUnit_Framework_MockObject_MockObject */
protected $groupManager;

/** @var \OCP\IAppConfig */
protected $appConfig;

/** @var \OCP\ICache | \PHPUnit_Framework_MockObject_MockObject */
protected $cache;

/** @var \OCP\ICacheFactory | \PHPUnit_Framework_MockObject_MockObject */
protected $cacheFactory;

/** @var \OCP\App\IAppManager */
protected $manager;

/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
protected $eventDispatcher;

protected function setUp() {
parent::setUp();

$this->userSession = $this->createMock('\OCP\IUserSession');
$this->groupManager = $this->createMock('\OCP\IGroupManager');
$this->userSession = $this->createMock(IUserSession::class);
$this->config = $this->createMock(IConfig::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->appConfig = $this->getAppConfig();
$this->cacheFactory = $this->createMock('\OCP\ICacheFactory');
$this->cache = $this->createMock('\OCP\ICache');
$this->eventDispatcher = $this->createMock('\Symfony\Component\EventDispatcher\EventDispatcherInterface');
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->cache = $this->createMock(ICache::class);
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->cacheFactory->expects($this->any())
->method('create')
->with('settings')
->willReturn($this->cache);
$this->manager = new \OC\App\AppManager($this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher);
$this->manager = new AppManager($this->userSession, $this->appConfig,
$this->groupManager, $this->cacheFactory, $this->eventDispatcher,
$this->config);
}

protected function expectClearCache() {
Expand Down Expand Up @@ -164,10 +172,11 @@ public function testEnableAppForGroupsAllowedTypes(array $appInfo) {
];
$this->expectClearCache();

/** @var \OC\App\AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder('OC\App\AppManager')
->setConstructorArgs([
$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher
$this->userSession, $this->appConfig, $this->groupManager,
$this->cacheFactory, $this->eventDispatcher, $this->config
])
->setMethods([
'getAppInfo'
Expand Down Expand Up @@ -207,10 +216,11 @@ public function testEnableAppForGroupsForbiddenTypes($type) {
new Group('group2', [], null)
];

/** @var \OC\App\AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder('OC\App\AppManager')
->setConstructorArgs([
$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher
$this->userSession, $this->appConfig, $this->groupManager,
$this->cacheFactory, $this->eventDispatcher, $this->config
])
->setMethods([
'getAppInfo'
Expand Down Expand Up @@ -333,7 +343,8 @@ public function testGetAppsForUser() {

public function testGetAppsNeedingUpgrade() {
$this->manager = $this->getMockBuilder('\OC\App\AppManager')
->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher])
->setConstructorArgs([$this->userSession, $this->appConfig,
$this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->config])
->setMethods(['getAppInfo'])
->getMock();

Expand Down Expand Up @@ -375,7 +386,8 @@ function($appId) use ($appInfos) {

public function testGetIncompatibleApps() {
$this->manager = $this->getMockBuilder('\OC\App\AppManager')
->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher])
->setConstructorArgs([$this->userSession, $this->appConfig,
$this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->config])
->setMethods(['getAppInfo'])
->getMock();

Expand Down Expand Up @@ -408,4 +420,21 @@ function($appId) use ($appInfos) {
$this->assertEquals('test1', $apps[0]['id']);
$this->assertEquals('test3', $apps[1]['id']);
}

/**
* @dataProvider providesDataForCanInstall
* @param bool $canInstall
* @param string $opsMode
*/
public function testCanInstall($canInstall, $opsMode) {
$this->config->expects($this->once())->method('getSystemValue')->willReturn($opsMode);
$this->assertEquals($canInstall, $this->manager->canInstall());
}

public function providesDataForCanInstall() {
return [
[true, 'single-instance'],
[false, 'clustered-instance'],
];
}
}
8 changes: 6 additions & 2 deletions tests/lib/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ private function registerAppConfig(IAppConfig $appConfig) {
return $appConfig;
});
\OC::$server->registerService('AppManager', function (\OC\Server $c) use ($appConfig) {
return new \OC\App\AppManager($c->getUserSession(), $appConfig, $c->getGroupManager(), $c->getMemCacheFactory(), $c->getEventDispatcher());
return new \OC\App\AppManager($c->getUserSession(), $appConfig,
$c->getGroupManager(), $c->getMemCacheFactory(),
$c->getEventDispatcher(), $c->getConfig());
});
}

Expand All @@ -518,7 +520,9 @@ private function restoreAppConfig() {
return new \OC\AppConfig($c->getDatabaseConnection());
});
\OC::$server->registerService('AppManager', function (\OC\Server $c) {
return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory(), $c->getEventDispatcher());
return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(),
$c->getGroupManager(), $c->getMemCacheFactory(),
$c->getEventDispatcher(), $c->getConfig());
});

// Remove the cache of the mocked apps list with a forceRefresh
Expand Down