Search in sources :

Example 1 with IgniteException

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;
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with IgniteException

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);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) HashMap(java.util.HashMap) IgniteException(org.apache.ignite.lang.IgniteException) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with IgniteException

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) -> {});
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) OperationTimeoutException(org.apache.ignite.internal.metastorage.client.OperationTimeoutException) Arrays(java.util.Arrays) WatchListener(org.apache.ignite.internal.metastorage.client.WatchListener) IgniteLogger(org.apache.ignite.lang.IgniteLogger) CompactedException(org.apache.ignite.internal.metastorage.client.CompactedException) ByteUtils.bytesToLong(org.apache.ignite.internal.util.ByteUtils.bytesToLong) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Map(java.util.Map) KeyCriterion(org.apache.ignite.internal.metastorage.watch.KeyCriterion) NodeConfiguration(org.apache.ignite.configuration.schemas.runner.NodeConfiguration) IgniteComponent(org.apache.ignite.internal.manager.IgniteComponent) KeyValueStorage(org.apache.ignite.internal.metastorage.server.KeyValueStorage) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Cursor(org.apache.ignite.internal.util.Cursor) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager) Collectors(java.util.stream.Collectors) If(org.apache.ignite.internal.metastorage.client.If) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) ClusterNode(org.apache.ignite.network.ClusterNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) Operation(org.apache.ignite.internal.metastorage.client.Operation) StatementResult(org.apache.ignite.internal.metastorage.client.StatementResult) IgniteException(org.apache.ignite.lang.IgniteException) VaultManager(org.apache.ignite.internal.vault.VaultManager) Loza(org.apache.ignite.internal.raft.Loza) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) ByteUtils.longToBytes(org.apache.ignite.internal.util.ByteUtils.longToBytes) MetaStorageServiceImpl(org.apache.ignite.internal.metastorage.client.MetaStorageServiceImpl) TopologyEventHandler(org.apache.ignite.network.TopologyEventHandler) AggregatedWatch(org.apache.ignite.internal.metastorage.watch.AggregatedWatch) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) WatchAggregator(org.apache.ignite.internal.metastorage.watch.WatchAggregator) IgniteSpinBusyLock(org.apache.ignite.internal.util.IgniteSpinBusyLock) NoSuchElementException(java.util.NoSuchElementException) Entry(org.apache.ignite.internal.metastorage.client.Entry) Iterator(java.util.Iterator) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) ByteArray(org.apache.ignite.lang.ByteArray) MetaStorageService(org.apache.ignite.internal.metastorage.client.MetaStorageService) ExecutionException(java.util.concurrent.ExecutionException) ClusterService(org.apache.ignite.network.ClusterService) Condition(org.apache.ignite.internal.metastorage.client.Condition) IgniteUuid(org.apache.ignite.lang.IgniteUuid) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) MetaStorageServiceImpl(org.apache.ignite.internal.metastorage.client.MetaStorageServiceImpl) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener) IgniteException(org.apache.ignite.lang.IgniteException) TopologyEventHandler(org.apache.ignite.network.TopologyEventHandler)

Example 4 with IgniteException

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;
    });
}
Also used : IgniteException(org.apache.ignite.lang.IgniteException) RestHandlersRegister(org.apache.ignite.internal.rest.api.RestHandlersRegister) HoconPresentation(org.apache.ignite.internal.configuration.rest.presentation.hocon.HoconPresentation) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager) StandardCharsets(java.nio.charset.StandardCharsets) RestApiHttpRequest(org.apache.ignite.internal.rest.api.RestApiHttpRequest) RestApiHttpResponse(org.apache.ignite.internal.rest.api.RestApiHttpResponse) BAD_REQUEST(io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST) ConfigurationPresentation(org.apache.ignite.internal.configuration.rest.presentation.ConfigurationPresentation) ErrorResult(org.apache.ignite.internal.rest.api.ErrorResult) APPLICATION_JSON(io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_JSON) Routes(org.apache.ignite.internal.rest.api.Routes) Map(java.util.Map) ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) IgniteException(org.apache.ignite.lang.IgniteException) CompletionException(java.util.concurrent.CompletionException) ErrorResult(org.apache.ignite.internal.rest.api.ErrorResult)

Example 5 with IgniteException

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);
    }
}
Also used : IgniteComponent(org.apache.ignite.internal.manager.IgniteComponent) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) IgniteException(org.apache.ignite.lang.IgniteException) ArrayList(java.util.ArrayList) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteException(org.apache.ignite.lang.IgniteException) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) IOException(java.io.IOException)

Aggregations

IgniteException (org.apache.ignite.lang.IgniteException)39 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)10 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)10 NotNull (org.jetbrains.annotations.NotNull)10 Map (java.util.Map)9 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 HashMap (java.util.HashMap)7 List (java.util.List)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)7 HashSet (java.util.HashSet)6 CompletionException (java.util.concurrent.CompletionException)6 Row (org.apache.ignite.internal.schema.row.Row)6 NoSuchElementException (java.util.NoSuchElementException)5 Set (java.util.Set)5 UUID (java.util.UUID)5 Consumer (java.util.function.Consumer)5 Collectors (java.util.stream.Collectors)5