use of org.apache.ignite.configuration.validation.ConfigurationValidationException in project ignite-3 by apache.
the class ConfigurationHttpHandlers method handleUpdate.
/**
* Handle a configuration update request as json.
*
* @param req Rest request.
* @param res Rest response.
* @param presentation Configuration presentation.
*/
private static CompletableFuture<RestApiHttpResponse> handleUpdate(RestApiHttpRequest req, RestApiHttpResponse res, ConfigurationPresentation<String> presentation) {
String updateReq = req.request().content().toString(StandardCharsets.UTF_8);
return presentation.update(updateReq).thenApply(v -> res).exceptionally(e -> {
if (e instanceof CompletionException) {
e = e.getCause();
}
ErrorResult errRes;
if (e instanceof IllegalArgumentException) {
errRes = new ErrorResult("INVALID_CONFIG_FORMAT", e.getMessage());
} else if (e instanceof ConfigurationValidationException) {
errRes = new ErrorResult("VALIDATION_EXCEPTION", e.getMessage());
} else if (e instanceof IgniteException) {
errRes = new ErrorResult("APPLICATION_EXCEPTION", e.getMessage());
} else {
throw new CompletionException(e);
}
res.status(BAD_REQUEST);
res.json(Map.of("error", errRes));
return res;
});
}
use of org.apache.ignite.configuration.validation.ConfigurationValidationException in project ignite-3 by apache.
the class ConfigurationChanger method initializeDefaults.
/**
* Initializes the configuration storage - reads data and sets default values for missing configuration properties.
*
* @throws ConfigurationValidationException If configuration validation failed.
* @throws ConfigurationChangeException If configuration framework failed to add default values and save them to storage.
*/
public void initializeDefaults() throws ConfigurationValidationException, ConfigurationChangeException {
try {
ConfigurationSource defaultsCfgSource = new ConfigurationSource() {
/**
* {@inheritDoc}
*/
@Override
public void descend(ConstructableTreeNode node) {
addDefaults((InnerNode) node);
}
};
changeInternally(defaultsCfgSource).get(5, TimeUnit.SECONDS);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof ConfigurationValidationException) {
throw (ConfigurationValidationException) cause;
}
if (cause instanceof ConfigurationChangeException) {
throw (ConfigurationChangeException) cause;
}
throw new ConfigurationChangeException("Failed to write default configuration values into the storage " + storage.getClass(), e);
} catch (InterruptedException | TimeoutException e) {
throw new ConfigurationChangeException("Failed to initialize configuration storage " + storage.getClass(), e);
}
}
use of org.apache.ignite.configuration.validation.ConfigurationValidationException in project ignite-3 by apache.
the class TableManager method createTableAsyncInternal.
/**
* Internal method that creates a new table with the given {@code name} asynchronously. If a table with the same name already exists,
* a future will be completed with {@link TableAlreadyExistsException}.
*
* @param name Table name.
* @param tableInitChange Table changer.
* @return Future representing pending completion of the operation.
* @throws IgniteException If an unspecified platform exception has happened internally. Is thrown when:
* <ul>
* <li>the node is stopping.</li>
* </ul>
* @see TableAlreadyExistsException
*/
private CompletableFuture<Table> createTableAsyncInternal(String name, Consumer<TableChange> tableInitChange) {
CompletableFuture<Table> tblFut = new CompletableFuture<>();
tableAsyncInternal(name).thenAccept(tbl -> {
if (tbl != null) {
tblFut.completeExceptionally(new TableAlreadyExistsException(name));
} else {
tablesCfg.tables().change(change -> {
if (change.get(name) != null) {
throw new TableAlreadyExistsException(name);
}
change.create(name, (ch) -> {
tableInitChange.accept(ch);
var extConfCh = ((ExtendedTableChange) ch);
tableCreateFuts.put(extConfCh.id(), tblFut);
// Affinity assignments calculation.
extConfCh.changeAssignments(ByteUtils.toBytes(AffinityUtils.calculateAssignments(baselineMgr.nodes(), ch.partitions(), ch.replicas()))).changeSchemas(schemasCh -> schemasCh.create(String.valueOf(INITIAL_SCHEMA_VERSION), schemaCh -> {
SchemaDescriptor schemaDesc;
// prepareSchemaDescriptor() method.
try {
schemaDesc = SchemaUtils.prepareSchemaDescriptor(((ExtendedTableView) ch).schemas().size(), ch);
} catch (IllegalArgumentException ex) {
throw new ConfigurationValidationException(ex.getMessage());
}
schemaCh.changeSchema(SchemaSerializerImpl.INSTANCE.serialize(schemaDesc));
}));
});
}).exceptionally(t -> {
Throwable ex = getRootCause(t);
if (ex instanceof TableAlreadyExistsException) {
tblFut.completeExceptionally(ex);
} else {
LOG.error(IgniteStringFormatter.format("Table wasn't created [name={}]", name), ex);
tblFut.completeExceptionally(ex);
tableCreateFuts.values().removeIf(fut -> fut == tblFut);
}
return null;
});
}
});
return tblFut;
}
use of org.apache.ignite.configuration.validation.ConfigurationValidationException in project ignite-3 by apache.
the class TableManager method alterTableAsyncInternal.
/**
* Internal method that alters a cluster table. If an appropriate table does not exist, a future will be
* completed with {@link TableNotFoundException}.
*
* @param name Table name.
* @param tableChange Table changer.
* @return Future representing pending completion of the operation.
* @throws IgniteException If an unspecified platform exception has happened internally. Is thrown when:
* <ul>
* <li>the node is stopping.</li>
* </ul>
* @see TableNotFoundException
*/
@NotNull
private CompletableFuture<Void> alterTableAsyncInternal(String name, Consumer<TableChange> tableChange) {
CompletableFuture<Void> tblFut = new CompletableFuture<>();
tableAsync(name).thenAccept(tbl -> {
if (tbl == null) {
tblFut.completeExceptionally(new TableNotFoundException(name));
} else {
TableImpl tblImpl = (TableImpl) tbl;
tablesCfg.tables().change(ch -> {
if (ch.get(name) == null) {
throw new TableNotFoundException(name);
}
ch.update(name, tblCh -> {
tableChange.accept(tblCh);
((ExtendedTableChange) tblCh).changeSchemas(schemasCh -> schemasCh.createOrUpdate(String.valueOf(schemasCh.size() + 1), schemaCh -> {
ExtendedTableView currTableView = (ExtendedTableView) tablesCfg.tables().get(name).value();
SchemaDescriptor descriptor;
// here to ensure a valid configuration passed to prepareSchemaDescriptor() method.
try {
descriptor = SchemaUtils.prepareSchemaDescriptor(((ExtendedTableView) tblCh).schemas().size(), tblCh);
descriptor.columnMapping(SchemaUtils.columnMapper(tblImpl.schemaView().schema(currTableView.schemas().size()), currTableView, descriptor, tblCh));
} catch (IllegalArgumentException ex) {
// Convert unexpected exceptions here,
// because validation actually happens later,
// when bulk configuration update is applied.
ConfigurationValidationException e = new ConfigurationValidationException(ex.getMessage());
e.addSuppressed(ex);
throw e;
}
schemaCh.changeSchema(SchemaSerializerImpl.INSTANCE.serialize(descriptor));
}));
});
}).whenComplete((res, t) -> {
if (t != null) {
Throwable ex = getRootCause(t);
if (ex instanceof TableNotFoundException) {
tblFut.completeExceptionally(ex);
} else {
LOG.error(IgniteStringFormatter.format("Table wasn't altered [name={}]", name), ex);
tblFut.completeExceptionally(ex);
}
} else {
tblFut.complete(res);
}
});
}
});
return tblFut;
}
Aggregations