Skip to content
Closed
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 @@ -19,6 +19,7 @@

package org.apache.druid.data.input;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
Expand Down Expand Up @@ -60,6 +61,7 @@ public interface InputSource
* Returns true if this inputSource can be processed in parallel using ParallelIndexSupervisorTask. It must be
* castable to SplittableInputSource and the various SplittableInputSource methods must work as documented.
*/
@JsonIgnore
boolean isSplittable();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.druid.data.input.impl;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import org.apache.druid.data.input.AbstractInputSource;
Expand Down Expand Up @@ -51,6 +52,7 @@ public String getData()
}

@Override
@JsonIgnore
public boolean isSplittable()
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,7 @@ default void exportTable(

void createSupervisorsTable();

void createTableDefnTable();

void deleteAllRecords(String tableName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
*/
public class MetadataStorageTablesConfig
{
public static final String CONFIG_BASE = "druid.metadata.storage.tables";

public static MetadataStorageTablesConfig fromBase(String base)
{
return new MetadataStorageTablesConfig(base, null, null, null, null, null, null, null, null, null, null);
return new MetadataStorageTablesConfig(base, null, null, null, null, null, null, null, null, null, null, null);
}

public static final String TASK_ENTRY_TYPE = "task";

private static final String DEFAULT_BASE = "druid";
public static final String DEFAULT_BASE = "druid";

private final Map<String, String> entryTables = new HashMap<>();
private final Map<String, String> logTables = new HashMap<>();
Expand Down Expand Up @@ -76,6 +78,9 @@ public static MetadataStorageTablesConfig fromBase(String base)
@JsonProperty("supervisors")
private final String supervisorTable;

@JsonProperty("tableDefn")
private final String tableDefnTable;

@JsonCreator
public MetadataStorageTablesConfig(
@JsonProperty("base") String base,
Expand All @@ -88,7 +93,8 @@ public MetadataStorageTablesConfig(
@JsonProperty("taskLog") String taskLogTable,
@JsonProperty("taskLock") String taskLockTable,
@JsonProperty("audit") String auditTable,
@JsonProperty("supervisors") String supervisorTable
@JsonProperty("supervisors") String supervisorTable,
@JsonProperty("tableDefn") String tablesTable
)
{
this.base = (base == null) ? DEFAULT_BASE : base;
Expand All @@ -106,6 +112,39 @@ public MetadataStorageTablesConfig(
lockTables.put(TASK_ENTRY_TYPE, this.taskLockTable);
this.auditTable = makeTableName(auditTable, "audit");
this.supervisorTable = makeTableName(supervisorTable, "supervisors");
this.tableDefnTable = makeTableName(tablesTable, "tableDefn");
}

/**
* Shim constructor for backwards compatibility with code that
* cannot be changed due to missing unit tests.
*/
public MetadataStorageTablesConfig(
String base,
String dataSourceTable,
String pendingSegmentsTable,
String segmentsTable,
String rulesTable,
String configTable,
String tasksTable,
String taskLogTable,
String taskLockTable,
String auditTable,
String supervisorTable
)
{
this(
base,
dataSourceTable,
pendingSegmentsTable,
segmentsTable, rulesTable,
configTable,
tasksTable,
taskLogTable,
taskLockTable,
auditTable,
supervisorTable,
null);
}

private String makeTableName(String explicitTableName, String defaultSuffix)
Expand Down Expand Up @@ -194,4 +233,9 @@ public String getTaskLockTable()
{
return taskLockTable;
}

public String getTableDefnTable()
{
return tableDefnTable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.druid.metadata;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class MetadataStorageTablesConfigTest
{
/**
* Pretty lame test: mostly to get the static checks to not complain.
*/
@Test
public void testDefaults()
{
MetadataStorageTablesConfig config = MetadataStorageTablesConfig.fromBase(null);
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE, config.getBase());
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE + "_dataSource", config.getDataSourceTable());
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE + "_pendingSegments", config.getPendingSegmentsTable());
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE + "_segments", config.getSegmentsTable());
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE + "_rules", config.getRulesTable());
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE + "_config", config.getConfigTable());
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE + "_tasks", config.getTasksTable());
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE + "_tasklogs", config.getTaskLogTable());
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE + "_tasklocks", config.getTaskLockTable());
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE + "_audit", config.getAuditTable());
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE + "_supervisors", config.getSupervisorTable());
assertEquals(MetadataStorageTablesConfig.DEFAULT_BASE + "_tableDefn", config.getTableDefnTable());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,13 @@
@SuppressWarnings("nls")
public class SQLServerConnectorTest
{

@Test
public void testIsTransientException()
{
SQLServerConnector connector = new SQLServerConnector(
Suppliers.ofInstance(new MetadataStorageConnectorConfig()),
Suppliers.ofInstance(
new MetadataStorageTablesConfig(
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
)
MetadataStorageTablesConfig.fromBase(null)
)
);

Expand All @@ -69,8 +56,7 @@ public void testLimitClause()
{
SQLServerConnector connector = new SQLServerConnector(
Suppliers.ofInstance(new MetadataStorageConnectorConfig()),
Suppliers.ofInstance(
new MetadataStorageTablesConfig(null, null, null, null, null, null, null, null, null, null, null)
Suppliers.ofInstance(MetadataStorageTablesConfig.fromBase(null)
)
);
Assert.assertEquals("FETCH NEXT 100 ROWS ONLY", connector.limitClause(100));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public String getDriverClassName()
private static final Supplier<MetadataStorageConnectorConfig> CONNECTOR_CONFIG_SUPPLIER =
MetadataStorageConnectorConfig::new;
private static final Supplier<MetadataStorageTablesConfig> TABLES_CONFIG_SUPPLIER =
() -> new MetadataStorageTablesConfig(null, null, null, null, null, null, null, null, null, null, null);
() -> MetadataStorageTablesConfig.fromBase(null);


@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,7 @@ public void testIsTransientException()
PostgreSQLConnector connector = new PostgreSQLConnector(
Suppliers.ofInstance(new MetadataStorageConnectorConfig()),
Suppliers.ofInstance(
new MetadataStorageTablesConfig(
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
)
MetadataStorageTablesConfig.fromBase(null)
),
new PostgreSQLConnectorConfig(),
new PostgreSQLTablesConfig()
Expand Down
104 changes: 104 additions & 0 deletions server/src/main/java/org/apache/druid/catalog/Actions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.druid.catalog;

import com.google.common.collect.ImmutableMap;
import org.apache.druid.server.security.ForbiddenException;

import javax.ws.rs.core.Response;

import java.util.Map;

/**
* Helper functions for the catalog REST API actions.
*/
public class Actions
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you thinking this class would be useful for other server APIs in the future? It seems written in such a way that it would be.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I've already written variations of these several times here and there in Druid. Making it more general is left as a later exercise to minimize the size of this PR.

{
public static final String DUPLICATE_ERROR = "Already exists";
public static final String FAILED_ERROR = "Failed";
public static final String INVALID = "Invalid";
public static final String FORBIDDEN = "Forbidden";
public static final String NOT_FOUND = "Not found";

public static final String ERROR_KEY = "error";
public static final String ERR_MSG_KEY = "errorMessage";

public static Map<String, String> error(String code, String msg)
{
return ImmutableMap.of(ERROR_KEY, code, ERR_MSG_KEY, msg);
}

public static Response exception(Exception e)
{
return Response
.serverError()
.entity(error(FAILED_ERROR, e.getMessage()))
.build();
}

public static Response badRequest(String code, String msg)
{
return Response
.status(Response.Status.BAD_REQUEST)
.entity(error(code, msg))
.build();
}

public static Response notFound(String msg)
{
return Response
.status(Response.Status.NOT_FOUND)
.entity(error(NOT_FOUND, msg))
.build();
}

public static Response ok()
{
return Response.ok().build();
}

public static Response forbidden()
{
return forbidden("Unauthorized");
}

public static Response forbidden(ForbiddenException e)
{
return forbidden(e.getMessage());
}

public static Response forbidden(String msg)
{
// Like ForbiddenExceptionMapper, but in the standard error
// format. Used instead of throwing ForbiddenException
return Response.status(Response.Status.FORBIDDEN)
.entity(error(FORBIDDEN, msg))
.build();
}

public static Response okWithVersion(long version)
{
return Response
.ok()
.entity(ImmutableMap.of("version", version))
.build();

}
}
Loading