Initial skeleton
Original commit: elastic/x-pack-elasticsearch@8a6bf64904
This commit is contained in:
parent
59d517f6b5
commit
01af8a39e6
2
pom.xml
2
pom.xml
|
@ -108,6 +108,8 @@
|
|||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.16</version>
|
||||
<configuration>
|
||||
<forkCount>1</forkCount>
|
||||
<reuseForks>false</reuseForks>
|
||||
<includes>
|
||||
<include>**/*Tests.java</include>
|
||||
</includes>
|
||||
|
|
|
@ -10,10 +10,7 @@ import org.codehaus.jackson.JsonGenerator;
|
|||
import org.codehaus.jackson.JsonNode;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.*;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -22,7 +19,7 @@ public class LicenseUtils {
|
|||
|
||||
public static void dumpLicenseAsJson(ESLicenses esLicenses, OutputStream out) throws IOException {
|
||||
JsonGenerator generator = new JsonFactory().createJsonGenerator(out);
|
||||
generator.useDefaultPrettyPrinter();
|
||||
//generator.useDefaultPrettyPrinter();
|
||||
|
||||
generator.writeStartObject();
|
||||
{
|
||||
|
@ -78,11 +75,15 @@ public class LicenseUtils {
|
|||
|
||||
public static ESLicenses readLicenseFile(File licenseFile) throws IOException {
|
||||
try (FileInputStream fileInputStream = new FileInputStream(licenseFile)) {
|
||||
JsonNode jsonNode = new ObjectMapper().readTree(fileInputStream);
|
||||
return extractLicenseFromJson(jsonNode);
|
||||
return readLicenseFromInputStream(fileInputStream);
|
||||
}
|
||||
}
|
||||
|
||||
public static ESLicenses readLicenseFromInputStream(InputStream inputStream) throws IOException {
|
||||
JsonNode jsonNode = new ObjectMapper().readTree(inputStream);
|
||||
return extractLicenseFromJson(jsonNode);
|
||||
}
|
||||
|
||||
public static ESLicenses readLicensesFromString(String licensesString) throws IOException {
|
||||
JsonNode jsonNode = new ObjectMapper().readTree(licensesString);
|
||||
return extractLicenseFromJson(jsonNode);
|
||||
|
|
|
@ -5,7 +5,15 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin;
|
||||
|
||||
import org.elasticsearch.action.ActionModule;
|
||||
import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.get.TransportGetLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.put.TransportPutLicenseAction;
|
||||
import org.elasticsearch.license.plugin.rest.RestGetLicenseAction;
|
||||
import org.elasticsearch.license.plugin.rest.RestPutLicenseAction;
|
||||
import org.elasticsearch.plugins.AbstractPlugin;
|
||||
import org.elasticsearch.rest.RestModule;
|
||||
|
||||
//TODO: plugin hooks
|
||||
public class LicensePlugin extends AbstractPlugin {
|
||||
|
@ -19,4 +27,15 @@ public class LicensePlugin extends AbstractPlugin {
|
|||
public String description() {
|
||||
return "Internal Elasticsearch Licensing Plugin";
|
||||
}
|
||||
|
||||
public void onModule(RestModule module) {
|
||||
// Register REST endpoint
|
||||
module.addRestAction(RestPutLicenseAction.class);
|
||||
module.addRestAction(RestGetLicenseAction.class);
|
||||
}
|
||||
|
||||
public void onModule(ActionModule module) {
|
||||
module.registerAction(PutLicenseAction.INSTANCE, TransportPutLicenseAction.class);
|
||||
module.registerAction(GetLicenseAction.INSTANCE, TransportGetLicenseAction.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.action.get;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.ClusterAction;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
|
||||
public class GetLicenseAction extends ClusterAction<GetLicenseRequest, GetLicenseResponse, GetLicenseRequestBuilder> {
|
||||
|
||||
public static final GetLicenseAction INSTANCE = new GetLicenseAction();
|
||||
public static final String NAME = "cluster:admin/license/get";
|
||||
|
||||
private GetLicenseAction() {
|
||||
super(NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetLicenseResponse newResponse() {
|
||||
return new GetLicenseResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetLicenseRequestBuilder newRequestBuilder(ClusterAdminClient client) {
|
||||
return new GetLicenseRequestBuilder(client);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.action.get;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequest;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class GetLicenseRequest extends MasterNodeReadOperationRequest<GetLicenseRequest> {
|
||||
|
||||
GetLicenseRequest() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
return null;
|
||||
/*ActionRequestValidationException validationException = null;
|
||||
if (repositories == null) {
|
||||
validationException = addValidationError("repositories is null", validationException);
|
||||
}
|
||||
return validationException;
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
readLocal(in, Version.V_1_0_0_RC2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
writeLocal(out, Version.V_1_0_0_RC2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.action.get;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
|
||||
public class GetLicenseRequestBuilder extends MasterNodeReadOperationRequestBuilder<GetLicenseRequest, GetLicenseResponse, GetLicenseRequestBuilder, ClusterAdminClient> {
|
||||
|
||||
/**
|
||||
* Creates new get repository request builder
|
||||
*
|
||||
* @param clusterAdminClient cluster admin client
|
||||
*/
|
||||
public GetLicenseRequestBuilder(ClusterAdminClient clusterAdminClient) {
|
||||
super(clusterAdminClient, new GetLicenseRequest());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doExecute(ActionListener<GetLicenseResponse> listener) {
|
||||
client.execute(GetLicenseAction.INSTANCE, request, listener);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.action.get;
|
||||
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class GetLicenseResponse extends ActionResponse implements Iterable<RepositoryMetaData> {
|
||||
|
||||
//TODO: use LicenseMetaData instead
|
||||
private ImmutableList<RepositoryMetaData> repositories = ImmutableList.of();
|
||||
|
||||
|
||||
GetLicenseResponse() {
|
||||
}
|
||||
|
||||
GetLicenseResponse(ImmutableList<RepositoryMetaData> repositories) {
|
||||
this.repositories = repositories;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of repositories to return
|
||||
*
|
||||
* @return list or repositories
|
||||
*/
|
||||
public ImmutableList<RepositoryMetaData> repositories() {
|
||||
return repositories;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
int size = in.readVInt();
|
||||
ImmutableList.Builder<RepositoryMetaData> repositoryListBuilder = ImmutableList.builder();
|
||||
for (int j = 0; j < size; j++) {
|
||||
repositoryListBuilder.add(new RepositoryMetaData(
|
||||
in.readString(),
|
||||
in.readString(),
|
||||
ImmutableSettings.readSettingsFromStream(in))
|
||||
);
|
||||
}
|
||||
repositories = repositoryListBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeVInt(repositories.size());
|
||||
for (RepositoryMetaData repository : repositories) {
|
||||
out.writeString(repository.name());
|
||||
out.writeString(repository.type());
|
||||
ImmutableSettings.writeSettingsToStream(repository.settings(), out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator over the repositories data
|
||||
*
|
||||
* @return iterator over the repositories data
|
||||
*/
|
||||
@Override
|
||||
public Iterator<RepositoryMetaData> iterator() {
|
||||
return repositories.iterator();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.action.get;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.action.support.master.TransportMasterNodeReadOperationAction;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.metadata.RepositoriesMetaData;
|
||||
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.repositories.RepositoryMissingException;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
public class TransportGetLicenseAction extends TransportMasterNodeReadOperationAction<GetLicenseRequest, GetLicenseResponse> {
|
||||
|
||||
@Inject
|
||||
public TransportGetLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||
ThreadPool threadPool, ActionFilters actionFilters) {
|
||||
super(settings, GetLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String executor() {
|
||||
return ThreadPool.Names.MANAGEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GetLicenseRequest newRequest() {
|
||||
return new GetLicenseRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GetLicenseResponse newResponse() {
|
||||
return new GetLicenseResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClusterBlockException checkBlock(GetLicenseRequest request, ClusterState state) {
|
||||
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void masterOperation(final GetLicenseRequest request, ClusterState state, final ActionListener<GetLicenseResponse> listener) throws ElasticsearchException {
|
||||
//TODO: impl after custom metadata impl
|
||||
/*
|
||||
MetaData metaData = state.metaData();
|
||||
RepositoriesMetaData repositories = metaData.custom(RepositoriesMetaData.TYPE);
|
||||
if (request.repositories().length == 0 || (request.repositories().length == 1 && "_all".equals(request.repositories()[0]))) {
|
||||
if (repositories != null) {
|
||||
listener.onResponse(new GetRepositoriesResponse(repositories.repositories()));
|
||||
} else {
|
||||
listener.onResponse(new GetRepositoriesResponse(ImmutableList.<RepositoryMetaData>of()));
|
||||
}
|
||||
} else {
|
||||
if (repositories != null) {
|
||||
ImmutableList.Builder<RepositoryMetaData> repositoryListBuilder = ImmutableList.builder();
|
||||
for (String repository : request.repositories()) {
|
||||
RepositoryMetaData repositoryMetaData = repositories.repository(repository);
|
||||
if (repositoryMetaData == null) {
|
||||
listener.onFailure(new RepositoryMissingException(repository));
|
||||
return;
|
||||
}
|
||||
repositoryListBuilder.add(repositoryMetaData);
|
||||
}
|
||||
listener.onResponse(new GetRepositoriesResponse(repositoryListBuilder.build()));
|
||||
} else {
|
||||
listener.onFailure(new RepositoryMissingException(request.repositories()[0]));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.action.put;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.ClusterAction;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
|
||||
public class PutLicenseAction extends ClusterAction<PutLicenseRequest, PutLicenseResponse, PutLicenseRequestBuilder> {
|
||||
|
||||
public static final PutLicenseAction INSTANCE = new PutLicenseAction();
|
||||
public static final String NAME = "cluster:admin/license/put";
|
||||
|
||||
private PutLicenseAction() {
|
||||
super(NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PutLicenseResponse newResponse() {
|
||||
return new PutLicenseResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PutLicenseRequestBuilder newRequestBuilder(ClusterAdminClient client) {
|
||||
return new PutLicenseRequestBuilder(client);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.action.put;
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.license.core.ESLicenses;
|
||||
import org.elasticsearch.license.core.LicenseUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PutLicenseRequest extends AcknowledgedRequest<PutLicenseRequest> {
|
||||
|
||||
private ESLicenses license;
|
||||
|
||||
public PutLicenseRequest() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
return null;
|
||||
/*
|
||||
ActionRequestValidationException validationException = null;
|
||||
if (name == null) {
|
||||
validationException = addValidationError("name is missing", validationException);
|
||||
}
|
||||
if (type == null) {
|
||||
validationException = addValidationError("type is missing", validationException);
|
||||
}
|
||||
return validationException;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses license from json format to an instance of {@link org.elasticsearch.license.core.ESLicenses}
|
||||
* @param licenseDefinition license definition
|
||||
*/
|
||||
public PutLicenseRequest license(String licenseDefinition) {
|
||||
try {
|
||||
return license(LicenseUtils.readLicensesFromString(licenseDefinition));
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchIllegalArgumentException("failed to parse license source", e);
|
||||
}
|
||||
}
|
||||
|
||||
public PutLicenseRequest license(ESLicenses esLicenses) {
|
||||
this.license = esLicenses;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ESLicenses license() {
|
||||
return license;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
license = LicenseUtils.readLicenseFromInputStream(in);
|
||||
readTimeout(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
LicenseUtils.dumpLicenseAsJson(license, out);
|
||||
writeTimeout(out);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.action.put;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
import org.elasticsearch.license.core.ESLicenses;
|
||||
|
||||
/**
|
||||
* Register repository request builder
|
||||
*/
|
||||
public class PutLicenseRequestBuilder extends AcknowledgedRequestBuilder<PutLicenseRequest, PutLicenseResponse, PutLicenseRequestBuilder, ClusterAdminClient> {
|
||||
|
||||
/**
|
||||
* Constructs register repository request
|
||||
*
|
||||
* @param clusterAdminClient cluster admin client
|
||||
*/
|
||||
public PutLicenseRequestBuilder(ClusterAdminClient clusterAdminClient) {
|
||||
super(clusterAdminClient, new PutLicenseRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the license
|
||||
*
|
||||
* @param license license
|
||||
* @return this builder
|
||||
*/
|
||||
public PutLicenseRequestBuilder setLicense(ESLicenses license) {
|
||||
request.license(license);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(ActionListener<PutLicenseResponse> listener) {
|
||||
client.execute(PutLicenseAction.INSTANCE, request, listener);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.action.put;
|
||||
|
||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PutLicenseResponse extends AcknowledgedResponse {
|
||||
|
||||
PutLicenseResponse() {
|
||||
}
|
||||
|
||||
PutLicenseResponse(boolean acknowledged) {
|
||||
super(acknowledged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
readAcknowledged(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
writeAcknowledged(out);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.action.put;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
public class TransportPutLicenseAction extends TransportMasterNodeOperationAction<PutLicenseRequest, PutLicenseResponse> {
|
||||
|
||||
//private final RepositoriesService repositoriesService
|
||||
|
||||
@Inject
|
||||
public TransportPutLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||
ThreadPool threadPool, ActionFilters actionFilters) {
|
||||
super(settings, PutLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String executor() {
|
||||
return ThreadPool.Names.SAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PutLicenseRequest newRequest() {
|
||||
return new PutLicenseRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PutLicenseResponse newResponse() {
|
||||
return new PutLicenseResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClusterBlockException checkBlock(PutLicenseRequest request, ClusterState state) {
|
||||
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void masterOperation(final PutLicenseRequest request, ClusterState state, final ActionListener<PutLicenseResponse> listener) throws ElasticsearchException {
|
||||
//TODO
|
||||
/*
|
||||
repositoriesService.registerRepository(new RepositoriesService.RegisterRepositoryRequest("put_repository [" + request.name() + "]", request.name(), request.type())
|
||||
.settings(request.settings())
|
||||
.masterNodeTimeout(request.masterNodeTimeout())
|
||||
.ackTimeout(request.timeout()), new ActionListener<ClusterStateUpdateResponse>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(ClusterStateUpdateResponse response) {
|
||||
listener.onResponse(new PutRepositoryResponse(response.isAcknowledged()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable e) {
|
||||
listener.onFailure(e);
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.rest;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.metadata.RepositoriesMetaData;
|
||||
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
|
||||
import static org.elasticsearch.client.Requests.getRepositoryRequest;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
public class RestGetLicenseAction extends BaseRestHandler {
|
||||
|
||||
@Inject
|
||||
public RestGetLicenseAction(Settings settings, RestController controller, Client client) {
|
||||
super(settings, controller, client);
|
||||
controller.registerHandler(GET, "/_cluster/license", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
final String[] repositories = request.paramAsStringArray("repository", Strings.EMPTY_ARRAY);
|
||||
//TODO: implement after custom metadata impl
|
||||
/*
|
||||
GetRepositoriesRequest getRepositoriesRequest = getRepositoryRequest(repositories);
|
||||
getRepositoriesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getRepositoriesRequest.masterNodeTimeout()));
|
||||
getRepositoriesRequest.local(request.paramAsBoolean("local", getRepositoriesRequest.local()));
|
||||
client.admin().cluster().getRepositories(getRepositoriesRequest, new RestBuilderListener<GetRepositoriesResponse>(channel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(GetRepositoriesResponse response, XContentBuilder builder) throws Exception {
|
||||
builder.startObject();
|
||||
for (RepositoryMetaData repositoryMetaData : response.repositories()) {
|
||||
RepositoriesMetaData.FACTORY.toXContent(repositoryMetaData, builder, request);
|
||||
}
|
||||
builder.endObject();
|
||||
|
||||
return new BytesRestResponse(OK, builder);
|
||||
}
|
||||
});*/
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.rest;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseRequest;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseResponse;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.action.support.AcknowledgedRestListener;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||
|
||||
public class RestPutLicenseAction extends BaseRestHandler {
|
||||
|
||||
@Inject
|
||||
public RestPutLicenseAction(Settings settings, RestController controller, Client client) {
|
||||
super(settings, controller, client);
|
||||
controller.registerHandler(PUT, "/_cluster/license", this);
|
||||
controller.registerHandler(POST, "/_cluster/license", this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
PutLicenseRequest putLicenseRequest = new PutLicenseRequest();
|
||||
putLicenseRequest.listenerThreaded(false);
|
||||
putLicenseRequest.license(request.content().toUtf8());
|
||||
//TODO hookup new action
|
||||
client.admin().cluster().execute(PutLicenseAction.INSTANCE, putLicenseRequest, new AcknowledgedRestListener<PutLicenseResponse>(channel));
|
||||
}
|
||||
}
|
|
@ -21,7 +21,6 @@ import java.io.IOException;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Ignore("Enable once maven is setup properly; now it throws invalid signature error for all the tests when the tests always pass in intellij")
|
||||
public class LicenseVerificationToolTests {
|
||||
|
||||
private static String pubKeyPath = null;
|
||||
|
|
|
@ -27,7 +27,6 @@ import static org.elasticsearch.license.core.ESLicenses.FeatureType;
|
|||
import static org.elasticsearch.license.core.LicenseUtils.readLicensesFromString;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@Ignore("Enable once maven is setup properly; now it throws invalid signature error for all the tests when the tests always pass in intellij")
|
||||
public class LicenseVerificationTests {
|
||||
|
||||
private static String pubKeyPath = null;
|
||||
|
|
Loading…
Reference in New Issue