Skip to content

Commit

Permalink
adjusting adapter settings models
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Sep 3, 2023
1 parent 4f3d278 commit e710c30
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
import lombok.Value;
Expand Down Expand Up @@ -107,6 +108,16 @@ public static List<AbstractAdapterSetting> fromAnnotations( Annotation[] annotat
Arrays.stream( ((AdapterSettingDirectory.List) annotation).value() ).forEach( el -> settings.add( AbstractAdapterSettingDirectory.fromAnnotation( el ) ) );
}
}
settings.add( new AbstractAdapterSettingList(
"mode",
false,
null,
true,
false,
Arrays.stream( properties.usedModes() ).map( DeployMode::getName ).collect( Collectors.toList() ),
List.of( DeploySetting.ALL ),
properties.usedModes()[0].getName(),
0 ) );

return settings;
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/org/polypheny/db/adapter/Adapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.polypheny.db.catalog.entity.physical.PhysicalColumn;
import org.polypheny.db.catalog.entity.physical.PhysicalEntity;
import org.polypheny.db.catalog.entity.physical.PhysicalTable;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.catalog.logistic.NamespaceType;
import org.polypheny.db.catalog.snapshot.Snapshot;
import org.polypheny.db.config.Config;
Expand Down Expand Up @@ -83,10 +84,10 @@ public Adapter( long adapterId, String uniqueName, Map<String, String> settings,
this.storeCatalog = catalog;
this.properties = getClass().getAnnotation( AdapterProperties.class );
if ( getClass().getAnnotation( AdapterProperties.class ) == null ) {
throw new RuntimeException( "The used adapter does not annotate its properties correctly." );
throw new GenericRuntimeException( "The used adapter does not annotate its properties correctly." );
}
if ( !settings.containsKey( "mode" ) ) {
throw new RuntimeException( "The adapter does not specify a mode which is necessary." );
throw new GenericRuntimeException( "The adapter does not specify a mode which is necessary." );
}

this.deployMode = DeployMode.fromString( settings.get( "mode" ) );
Expand Down
20 changes: 12 additions & 8 deletions core/src/main/java/org/polypheny/db/adapter/AdapterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.Value;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.polypheny.db.adapter.annotations.AdapterProperties;
Expand Down Expand Up @@ -176,7 +177,7 @@ public List<AdapterInformation> getAvailableAdapters( AdapterType adapterType )
// Merge annotated AdapterSettings into settings
List<AbstractAdapterSetting> settings = AbstractAdapterSetting.fromAnnotations( adapterTemplate.getClazz().getAnnotations(), adapterTemplate.getClazz().getAnnotation( AdapterProperties.class ) );

result.add( new AdapterInformation( properties.name(), properties.description(), adapterType, settings ) );
result.add( new AdapterInformation( properties.name(), properties.description(), adapterType, settings, List.of( properties.usedModes() ) ) );
}
}

Expand All @@ -187,10 +188,10 @@ public List<AdapterInformation> getAvailableAdapters( AdapterType adapterType )
public Adapter<?> addAdapter( String adapterName, String uniqueName, AdapterType adapterType, Map<String, String> settings ) {
uniqueName = uniqueName.toLowerCase();
if ( getAdapters().containsKey( uniqueName ) ) {
throw new RuntimeException( "There is already an adapter with this unique name" );
throw new GenericRuntimeException( "There is already an adapter with this unique name" );
}
if ( !settings.containsKey( "mode" ) ) {
throw new RuntimeException( "The adapter does not specify a mode which is necessary." );
throw new GenericRuntimeException( "The adapter does not specify a mode which is necessary." );
}

AdapterTemplate adapterTemplate = AdapterTemplate.fromString( adapterName, adapterType );
Expand All @@ -204,7 +205,7 @@ public Adapter<?> addAdapter( String adapterName, String uniqueName, AdapterType

} catch ( Exception e ) {
Catalog.getInstance().deleteAdapter( adapterId );
throw new RuntimeException( "Something went wrong while adding a new adapter", e );
throw new GenericRuntimeException( "Something went wrong while adding a new adapter", e );
}
}

Expand Down Expand Up @@ -260,12 +261,15 @@ public List<AdapterInformation> getAvailableAdapters() {


@AllArgsConstructor
@Value
public static class AdapterInformation {

public final String name;
public final String description;
public final AdapterType type;
public final List<AbstractAdapterSetting> settings;
public String name;
public String description;
public AdapterType type;
public List<AbstractAdapterSetting> settings;

public List<DeployMode> modes;


public static JsonSerializer<AdapterInformation> getSerializer() {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/polypheny/db/adapter/DeployMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import java.util.List;
import lombok.Getter;

@Getter
public enum DeployMode {

REMOTE( "remote" ),
DOCKER( "docker" ),
EMBEDDED( "embedded" );

@Getter
private final String name;


Expand All @@ -50,7 +50,7 @@ public enum DeploySetting {
REMOTE( DeployMode.REMOTE ),
DOCKER( DeployMode.DOCKER ),
EMBEDDED( DeployMode.EMBEDDED ),
DEFAULT;
ALL;

private final DeployMode mode;
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

int position() default 100;

DeploySetting[] appliesTo() default DeploySetting.DEFAULT;
DeploySetting[] appliesTo() default DeploySetting.ALL;

String subOf() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

int position() default 100;

DeploySetting[] appliesTo() default DeploySetting.DEFAULT;
DeploySetting[] appliesTo() default DeploySetting.ALL;

String subOf() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

int position() default 100;

DeploySetting[] appliesTo() default DeploySetting.DEFAULT;
DeploySetting[] appliesTo() default DeploySetting.ALL;

String subOf() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

int position() default 100;

DeploySetting[] appliesTo() default DeploySetting.DEFAULT;
DeploySetting[] appliesTo() default DeploySetting.ALL;

String subOf() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

int position() default 100;

DeploySetting[] appliesTo() default DeploySetting.DEFAULT;
DeploySetting[] appliesTo() default DeploySetting.ALL;

String subOf() default "";

Expand Down
23 changes: 15 additions & 8 deletions webui/src/main/java/org/polypheny/db/webui/Crud.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
import org.polypheny.db.webui.models.Uml;
import org.polypheny.db.webui.models.UnderlyingTables;
import org.polypheny.db.webui.models.catalog.AdapterModel;
import org.polypheny.db.webui.models.catalog.AdapterModel.AdapterSettingValueModel;
import org.polypheny.db.webui.models.catalog.UiColumnDefinition;
import org.polypheny.db.webui.models.requests.BatchUpdateRequest;
import org.polypheny.db.webui.models.requests.BatchUpdateRequest.Update;
Expand Down Expand Up @@ -2249,26 +2250,32 @@ void addAdapter( final Context ctx ) throws ServletException, IOException {
Map<String, String> settings = new HashMap<>();

ConnectionMethod method = ConnectionMethod.UPLOAD;
if ( a.settings.containsKey( "method" ) ) {
method = ConnectionMethod.valueOf( a.settings.get( "method" ).getValue().toUpperCase() );
if ( a.settings.stream().anyMatch( s -> s.getName().equalsIgnoreCase( "method" ) ) ) {
method = ConnectionMethod.valueOf( a.settings.stream().filter( s -> s.getName().equalsIgnoreCase( "method" ) ).findFirst().orElseThrow().getValue().toUpperCase() );
}
Adapter<?> adapter = AdapterManager.getInstance().getAdapter( a.id );
Map<String, AbstractAdapterSetting> allSettings = adapter.getAvailableSettings( adapter.getClass() ).stream().collect( Collectors.toMap( e -> e.name, e -> e ) );

for ( Entry<String, AbstractAdapterSetting> entry : a.settings.entrySet() ) {
if ( entry.getValue() instanceof AbstractAdapterSettingDirectory ) {
AbstractAdapterSettingDirectory setting = ((AbstractAdapterSettingDirectory) entry.getValue());
for ( AdapterSettingValueModel entry : a.settings ) {
AbstractAdapterSetting set = allSettings.get( entry.getName() );
if ( set == null ) {
continue;
}
if ( set instanceof AbstractAdapterSettingDirectory ) {
AbstractAdapterSettingDirectory setting = ((AbstractAdapterSettingDirectory) set);
if ( method == ConnectionMethod.LINK ) {
Exception e = handleLinkFiles( ctx, a, setting, a.settings );
Exception e = handleLinkFiles( ctx, a, setting, allSettings );
if ( e != null ) {
ctx.json( RelationalResult.builder().exception( e ).build() );
return;
}
} else {
handleUploadFiles( inputStreams, a, setting );
}
settings.put( entry.getKey(), entry.getValue().getValue() );
settings.put( set.name, entry.getValue() );

} else {
settings.put( entry.getKey(), entry.getValue().getValue() );
settings.put( set.name, entry.getValue() );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.polypheny.db.adapter.AbstractAdapterSetting;
import org.polypheny.db.adapter.AbstractAdapterSetting.AdapterSettingType;
import org.polypheny.db.adapter.AdapterManager.AdapterInformation;
import org.polypheny.db.adapter.DeployMode;
import org.polypheny.db.adapter.DeployMode.DeploySetting;
import org.polypheny.db.catalog.entity.CatalogAdapter.AdapterType;

Expand All @@ -35,22 +36,30 @@ public class AdapterTemplateModel {
public AdapterType adapterType;
public List<AdapterSettingsModel> defaultSettings;
public String description;
public List<DeployMode> modes;


public AdapterTemplateModel(
@NotNull String adapterName,
@NotNull AdapterType adapterType,
@NotNull List<AdapterSettingsModel> defaultSettings,
@NotNull String description ) {
@NotNull String description,
@NotNull List<DeployMode> modes ) {
this.adapterName = adapterName;
this.adapterType = adapterType;
this.defaultSettings = defaultSettings;
this.description = description;
this.modes = modes;
}


public static AdapterTemplateModel from( AdapterInformation template ) {
return new AdapterTemplateModel( template.name, template.type, template.settings.stream().map( AdapterSettingsModel::from ).collect( Collectors.toList() ), template.description );
return new AdapterTemplateModel(
template.name,
template.type,
template.settings.stream().map( AdapterSettingsModel::from ).collect( Collectors.toList() ),
template.description,
template.modes );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
package org.polypheny.db.webui.models.catalog;


import java.util.Map;
import java.util.List;
import java.util.stream.Collectors;
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.experimental.NonFinal;
import org.jetbrains.annotations.Nullable;
import org.polypheny.db.adapter.AbstractAdapterSetting;
import org.polypheny.db.catalog.entity.CatalogAdapter;
import org.polypheny.db.catalog.entity.CatalogAdapter.AdapterType;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
Expand All @@ -35,7 +35,7 @@ public abstract class AdapterModel extends IdEntity {

public String adapterName;
public AdapterType type;
public Map<String, AbstractAdapterSetting> settings;
public List<AdapterSettingValueModel> settings;
public boolean persistent;


Expand All @@ -44,7 +44,7 @@ public AdapterModel(
@Nullable String name,
String adapterName,
AdapterType type,
Map<String, AbstractAdapterSetting> settings,
List<AdapterSettingValueModel> settings,
boolean persistent ) {
super( id, name );
this.adapterName = adapterName;
Expand All @@ -55,27 +55,42 @@ public AdapterModel(


public static AdapterModel from( CatalogAdapter adapter ) {
List<AdapterSettingValueModel> settings = adapter.settings.entrySet().stream().map( s -> AdapterSettingValueModel.from( s.getKey(), s.getValue() ) ).collect( Collectors.toList() );
switch ( adapter.type ) {
case STORE:
return new StoreModel(
adapter.id,
adapter.uniqueName,
adapter.adapterName,
adapter.type,
Map.of(),
settings,
true );
case SOURCE:
return new SourceModel(
adapter.id,
adapter.uniqueName,
adapter.adapterName,
adapter.type,
Map.of(),
settings,
true,
false );
default:
throw new GenericRuntimeException( "Type of adapter is not known" );
}
}


@Value
public static class AdapterSettingValueModel {

String name;
String value;


public static AdapterSettingValueModel from( String name, String value ) {
return new AdapterSettingValueModel( name, value );
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@

package org.polypheny.db.webui.models.catalog;

import java.util.Map;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jetbrains.annotations.Nullable;
import org.polypheny.db.adapter.AbstractAdapterSetting;
import org.polypheny.db.catalog.entity.CatalogAdapter.AdapterType;

@EqualsAndHashCode(callSuper = true)
Expand All @@ -35,7 +34,7 @@ public SourceModel(
@Nullable String name,
String adapterName,
AdapterType type,
Map<String, AbstractAdapterSetting> settings,
List<AdapterSettingValueModel> settings,
boolean persistent,
boolean readOnly ) {
super( id, name, adapterName, type, settings, persistent );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@

package org.polypheny.db.webui.models.catalog;

import java.util.Map;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jetbrains.annotations.Nullable;
import org.polypheny.db.adapter.AbstractAdapterSetting;
import org.polypheny.db.catalog.entity.CatalogAdapter.AdapterType;

@EqualsAndHashCode(callSuper = true)
Expand All @@ -33,7 +32,7 @@ public StoreModel(
@Nullable String name,
String adapterName,
AdapterType type,
Map<String, AbstractAdapterSetting> settings,
List<AdapterSettingValueModel> settings,
boolean persistent ) {
super( id, name, adapterName, type, settings, persistent );
}
Expand Down

0 comments on commit e710c30

Please sign in to comment.