use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.
the class KeyValueViewImpl method marshal.
/**
* Marshal keys to a row.
*
* @param keys Key objects.
* @return Binary rows.
*/
@NotNull
public Collection<BinaryRow> marshal(@NotNull Collection<K> keys) {
final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
List<BinaryRow> keyRows = new ArrayList<>(keys.size());
try {
for (K key : keys) {
final BinaryRow keyRow = marsh.marshal(Objects.requireNonNull(key));
keyRows.add(keyRow);
}
} catch (MarshallerException e) {
throw new IgniteException(e);
}
return keyRows;
}
use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.
the class KeyValueViewImpl method unmarshalPairs.
/**
* Marshal key-value pairs.
*
* @param rows Binary rows.
* @return Key-value pairs.
*/
@NotNull
public Map<K, V> unmarshalPairs(Collection<BinaryRow> rows) {
if (rows.isEmpty()) {
return Collections.emptyMap();
}
final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
Map<K, V> pairs = new HashMap<>(rows.size());
try {
for (Row row : schemaReg.resolve(rows)) {
if (row != null) {
pairs.put(marsh.unmarshalKey(row), marsh.unmarshalValue(row));
}
}
return pairs;
} catch (MarshallerException e) {
throw new IgniteException(e);
}
}
use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.
the class MetaStorageManager method start.
/**
* {@inheritDoc}
*/
@Override
public void start() {
String[] metastorageNodes = this.locCfgMgr.configurationRegistry().getConfiguration(NodeConfiguration.KEY).metastorageNodes().value();
Predicate<ClusterNode> metaStorageNodesContainsLocPred = clusterNode -> Arrays.asList(metastorageNodes).contains(clusterNode.name());
if (metastorageNodes.length > 0) {
metaStorageNodesOnStart = true;
List<ClusterNode> metaStorageMembers = clusterNetSvc.topologyService().allMembers().stream().filter(metaStorageNodesContainsLocPred).collect(Collectors.toList());
// without hosting metastorage, this will be rewritten in init phase https://issues.apache.org/jira/browse/IGNITE-15114
if (metaStorageMembers.isEmpty()) {
throw new IgniteException("Cannot start meta storage manager because there is no node in the cluster that hosts meta storage.");
}
// This will be rewritten in init phase https://issues.apache.org/jira/browse/IGNITE-15114
if (metastorageNodes.length > 1) {
throw new IgniteException("Cannot start meta storage manager because it is not allowed to start several metastorage nodes.");
}
storage.start();
try {
raftGroupServiceFut = raftMgr.prepareRaftGroup(METASTORAGE_RAFT_GROUP_NAME, metaStorageMembers, () -> new MetaStorageListener(storage));
} catch (NodeStoppingException e) {
throw new AssertionError("Loza was stopped before Meta Storage manager", e);
}
this.metaStorageSvcFut = raftGroupServiceFut.thenApply(service -> new MetaStorageServiceImpl(service, clusterNetSvc.topologyService().localMember().id()));
if (hasMetastorageLocally(locCfgMgr)) {
clusterNetSvc.topologyService().addEventHandler(new TopologyEventHandler() {
@Override
public void onAppeared(ClusterNode member) {
// No-op.
}
@Override
public void onDisappeared(ClusterNode member) {
metaStorageSvcFut.thenCompose(svc -> svc.closeCursors(member.id()));
}
});
}
} else {
this.metaStorageSvcFut = new CompletableFuture<>();
}
// TODO: IGNITE-15114 Cluster initialization flow. Here we should complete metaStorageServiceFuture.
// clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
}
use of org.apache.ignite.lang.IgniteException 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.lang.IgniteException in project ignite-3 by apache.
the class IgniteImpl method start.
/**
* Starts ignite node.
*
* @param cfg Optional node configuration based on {@link org.apache.ignite.configuration.schemas.runner.NodeConfigurationSchema} and
* {@link org.apache.ignite.configuration.schemas.network.NetworkConfigurationSchema}. Following rules are used for applying
* the configuration properties:
* <ol>
* <li>Specified property overrides existing one or just applies itself if it wasn't
* previously specified.</li>
* <li>All non-specified properties either use previous value or use default one from
* corresponding configuration schema.</li>
* </ol>
* So that, in case of initial node start (first start ever) specified configuration, supplemented with defaults, is
* used. If no configuration was provided defaults are used for all configuration properties. In case of node
* restart, specified properties override existing ones, non specified properties that also weren't specified
* previously use default values. Please pay attention that previously specified properties are searched in the
* {@code workDir} specified by the user.
*/
public void start(@Nullable String cfg) {
List<IgniteComponent> startedComponents = new ArrayList<>();
try {
// Vault startup.
doStartComponent(name, startedComponents, vaultMgr);
vaultMgr.putName(name).join();
// Node configuration manager startup.
doStartComponent(name, startedComponents, nodeCfgMgr);
// Node configuration manager bootstrap.
if (cfg != null) {
try {
nodeCfgMgr.bootstrap(cfg);
} catch (Exception e) {
throw new IgniteException("Unable to parse user-specific configuration.", e);
}
} else {
nodeCfgMgr.configurationRegistry().initializeDefaults();
}
// Start the remaining components.
List<IgniteComponent> otherComponents = List.of(nettyBootstrapFactory, clusterSvc, raftMgr, txManager, metaStorageMgr, clusterCfgMgr, baselineMgr, distributedTblMgr, qryEngine, restComponent, clientHandlerModule);
for (IgniteComponent component : otherComponents) {
doStartComponent(name, startedComponents, component);
}
notifyConfigurationListeners();
// Deploy all registered watches because all components are ready and have registered their listeners.
metaStorageMgr.deployWatches();
if (!status.compareAndSet(Status.STARTING, Status.STARTED)) {
throw new NodeStoppingException();
}
} catch (Exception e) {
String errMsg = "Unable to start node=[" + name + "].";
LOG.error(errMsg, e);
doStopNode(startedComponents);
throw new IgniteException(errMsg, e);
}
}
Aggregations