25 return 'external-domains';
30 return [
'VirtualDomains',
'services' ];
35 $status = $this->createVirtualDomains();
36 $status->merge( $this->createExternalStoreDomains() );
45 private function createVirtualDomains():
Status {
46 $status =
Status::newGood();
47 foreach ( $this->getVirtualDomains() as $virtualDomain ) {
48 if ( !$this->shouldDoShared()
49 && $this->lbFactory->isSharedVirtualDomain( $virtualDomain )
51 $status->
warning(
'config-skip-shared-domain', $virtualDomain );
55 if ( $this->lbFactory->isLocalDomain( $virtualDomain ) ) {
59 $lb = $this->lbFactory->getLoadBalancer( $virtualDomain );
60 $realDomainId = $this->lbFactory->getMappedDomain( $virtualDomain );
61 $status->merge( $this->maybeCreateDomain( $lb, $realDomainId ) );
67 private function createExternalStoreDomains(): Status {
68 $status = Status::newGood();
69 $localDomainId = $this->lbFactory->getLocalDomainID();
70 foreach ( $this->esFactory->getWriteBaseUrls() as
$url ) {
71 $store = $this->esFactory->getStoreForUrl(
$url );
72 if ( $store instanceof ExternalStoreDB ) {
73 $cluster = $store->getClusterForUrl(
$url );
74 if ( $cluster ===
null ) {
75 throw new \RuntimeException(
"Invalid store url \"$url\"" );
77 $lb = $this->lbFactory->getExternalLB( $cluster );
78 $domainId = $store->getDomainIdForCluster( $cluster );
79 if ( $domainId !==
false && $domainId !== $localDomainId && !$this->shouldDoShared() ) {
81 $status->warning(
'config-skip-shared-domain',
"$cluster/$domainId" );
84 $status->merge( $this->maybeCreateDomain( $lb, $domainId ) );
86 $conn = $lb->getMaintenanceConnectionRef(
DB_PRIMARY, [], $domainId );
87 $conn->setSchemaVars( $this->
getContext()->getSchemaVars() );
88 if ( !$conn->tableExists( $store->getTable( $cluster ), __METHOD__ ) ) {
89 $store->initializeTable( $cluster );
106 private function maybeCreateDomain( $lb, $domainId ) {
107 $databaseCreator = $this->getDatabaseCreator();
108 if ( $domainId ===
false ) {
109 $domainId = $this->lbFactory->getLocalDomainID();
111 $database = DatabaseDomain::newFromId( $domainId )->getDatabase();
112 if ( !$databaseCreator->existsInLoadBalancer( $lb, $database ) ) {
113 return $databaseCreator->createInLoadBalancer( $lb, $database );
115 return Status::newGood();
123 private function shouldDoShared() {
124 return (
bool)$this->getOption(
'Shared' );