Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.script;
import org.opensearch.ResourceNotFoundException;
import org.opensearch.Version;
import org.opensearch.cluster.ClusterState;
import org.opensearch.cluster.Diff;
import org.opensearch.cluster.DiffableUtils;
import org.opensearch.cluster.NamedDiff;
import org.opensearch.cluster.metadata.Metadata;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.core.common.ParsingException;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.xcontent.ToXContentFragment;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.core.xcontent.XContentParser.Token;
import java.io.IOException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
* {@link ScriptMetadata} is used to store user-defined scripts
* as part of the {@link ClusterState} using only an id as the key.
*
* @opensearch.internal
*/
public final class ScriptMetadata implements Metadata.Custom, Writeable, ToXContentFragment {
/**
* Standard deprecation logger for used to deprecate allowance of empty templates.
*/
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(ScriptMetadata.class);
/**
* A builder used to modify the currently stored scripts data held within
* the {@link ClusterState}. Scripts can be added or deleted, then built
* to generate a new {@link Map} of scripts that will be used to update
* the current {@link ClusterState}.
*
* @opensearch.internal
*/
public static final class Builder {
private final Map scripts;
/**
* @param previous The current {@link ScriptMetadata} or {@code null} if there
* is no existing {@link ScriptMetadata}.
*/
public Builder(ScriptMetadata previous) {
this.scripts = previous == null ? new HashMap<>() : new HashMap<>(previous.scripts);
}
/**
* Add a new script to the existing stored scripts based on a user-specified id. If
* a script with the same id already exists it will be overwritten.
* @param id The user-specified id to use for the look up.
* @param source The user-specified stored script data held in {@link StoredScriptSource}.
*/
public Builder storeScript(String id, StoredScriptSource source) {
scripts.put(id, source);
return this;
}
/**
* Delete a script from the existing stored scripts based on a user-specified id.
* @param id The user-specified id to use for the look up.
*/
public Builder deleteScript(String id) {
StoredScriptSource deleted = scripts.remove(id);
if (deleted == null) {
throw new ResourceNotFoundException("stored script [" + id + "] does not exist and cannot be deleted");
}
return this;
}
/**
* @return A {@link ScriptMetadata} with the updated {@link Map} of scripts.
*/
public ScriptMetadata build() {
return new ScriptMetadata(scripts);
}
}
static final class ScriptMetadataDiff implements NamedDiff {
final Diff