Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import io.trino.connector.CatalogHandle.CatalogHandleType;
import io.trino.metadata.Catalog;

import java.util.Optional;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;

Expand All @@ -26,20 +28,23 @@ public class CatalogConnector
private final ConnectorServices catalogConnector;
private final ConnectorServices informationSchemaConnector;
private final ConnectorServices systemConnector;
private final Optional<CatalogProperties> catalogProperties;
private final Catalog catalog;

public CatalogConnector(
CatalogHandle catalogHandle,
String connectorName,
ConnectorServices catalogConnector,
ConnectorServices informationSchemaConnector,
ConnectorServices systemConnector)
ConnectorServices systemConnector,
Optional<CatalogProperties> catalogProperties)
{
this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null");
this.connectorName = requireNonNull(connectorName, "connectorName is null");
this.catalogConnector = requireNonNull(catalogConnector, "catalogConnector is null");
this.informationSchemaConnector = requireNonNull(informationSchemaConnector, "informationSchemaConnector is null");
this.systemConnector = requireNonNull(systemConnector, "systemConnector is null");
this.catalogProperties = requireNonNull(catalogProperties, "catalogProperties is null");

this.catalog = new Catalog(
catalogHandle.getCatalogName(),
Expand All @@ -60,6 +65,11 @@ public String getConnectorName()
return connectorName;
}

public Optional<CatalogProperties> getCatalogProperties()
{
return catalogProperties;
}

public Catalog getCatalog()
{
return catalog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

import javax.annotation.concurrent.ThreadSafe;

import java.util.Map;
import java.util.function.Function;

@ThreadSafe
public interface CatalogFactory
{
void addConnectorFactory(ConnectorFactory connectorFactory, Function<CatalogHandle, ClassLoader> duplicatePluginClassLoaderFactory);

CatalogConnector createCatalog(String catalogName, String connectorName, Map<String, String> properties);
CatalogConnector createCatalog(CatalogProperties catalogProperties);

CatalogConnector createCatalog(CatalogHandle catalogHandle, String connectorName, Connector connector);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.connector;

import io.airlift.configuration.Config;

import javax.validation.constraints.NotNull;

public class CatalogManagerConfig
{
public enum CatalogMangerKind
{
STATIC, DYNAMIC
}

private CatalogMangerKind catalogMangerKind = CatalogMangerKind.STATIC;

@NotNull
public CatalogMangerKind getCatalogMangerKind()
{
return catalogMangerKind;
}

@Config("catalog.management")
public CatalogManagerConfig setCatalogMangerKind(CatalogMangerKind catalogMangerKind)
{
this.catalogMangerKind = catalogMangerKind;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
import com.google.inject.Binder;
import com.google.inject.Scopes;
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.trino.connector.system.GlobalSystemConnector;
import io.trino.metadata.CatalogManager;

import javax.inject.Inject;

public class CatalogManagerModule
extends AbstractConfigurationAwareModule
Expand All @@ -30,27 +26,13 @@ protected void setup(Binder binder)
binder.bind(DefaultCatalogFactory.class).in(Scopes.SINGLETON);
binder.bind(LazyCatalogFactory.class).in(Scopes.SINGLETON);
binder.bind(CatalogFactory.class).to(LazyCatalogFactory.class).in(Scopes.SINGLETON);
binder.bind(LazyRegister.class).asEagerSingleton();

binder.bind(ConnectorManager.class).in(Scopes.SINGLETON);
binder.bind(ConnectorServicesProvider.class).to(ConnectorManager.class).in(Scopes.SINGLETON);

binder.bind(CatalogManager.class).in(Scopes.SINGLETON);
CatalogManagerConfig config = buildConfigObject(CatalogManagerConfig.class);
switch (config.getCatalogMangerKind()) {
Comment thread
dain marked this conversation as resolved.
Outdated
case STATIC -> install(new StaticCatalogManagerModule());
case DYNAMIC -> install(new DynamicCatalogManagerModule());
}

install(new CatalogServiceProviderModule());
}

private static class LazyRegister
{
@Inject
public LazyRegister(
DefaultCatalogFactory defaultCatalogFactory,
LazyCatalogFactory lazyCatalogFactory,
ConnectorManager manager,
GlobalSystemConnector globalSystemConnector)
{
lazyCatalogFactory.setCatalogFactory(defaultCatalogFactory);
manager.createCatalog(GlobalSystemConnector.CATALOG_HANDLE, GlobalSystemConnector.NAME, globalSystemConnector);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.connector;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;

import java.util.Map;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;

public class CatalogProperties
{
private final CatalogHandle catalogHandle;
private final String connectorName;
private final Map<String, String> properties;

@JsonCreator
public CatalogProperties(
@JsonProperty("catalogHandle") CatalogHandle catalogHandle,
@JsonProperty("connectorName") String connectorName,
@JsonProperty("properties") Map<String, String> properties)
{
this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null");
this.connectorName = requireNonNull(connectorName, "connectorName is null");
this.properties = ImmutableMap.copyOf(requireNonNull(properties, "properties is null"));
}

@JsonProperty
public CatalogHandle getCatalogHandle()
{
return catalogHandle;
}

@JsonProperty
public String getConnectorName()
{
return connectorName;
}

@JsonProperty
public Map<String, String> getProperties()
{
return properties;
}

@Override
public String toString()
{
return toStringHelper(this)
.add("catalogHandle", catalogHandle)
.add("connectorName", connectorName)
.toString();
}
}
28 changes: 28 additions & 0 deletions core/trino-main/src/main/java/io/trino/connector/CatalogStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.connector;

import com.google.common.collect.ImmutableList;

import java.util.Collection;

public interface CatalogStore
{
CatalogStore NO_STORED_CATALOGS = ImmutableList::of;

/**
* Get all catalogs
*/
Collection<CatalogProperties> getCatalogs();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.connector;

import io.airlift.configuration.Config;

import javax.validation.constraints.NotNull;

public class CatalogStoreConfig
{
public enum CatalogStoreKind
{
NONE, FILE
}

private CatalogStoreKind catalogStoreKind = CatalogStoreKind.FILE;

@NotNull
public CatalogStoreKind getCatalogStoreKind()
{
return catalogStoreKind;
}

@Config("catalog.store")
public CatalogStoreConfig setCatalogStoreKind(CatalogStoreKind catalogStoreKind)
{
this.catalogStoreKind = catalogStoreKind;
return this;
}
}
104 changes: 0 additions & 104 deletions core/trino-main/src/main/java/io/trino/connector/ConnectorManager.java

This file was deleted.

Loading