Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.license;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ContextPreservingActionListener;
import org.elasticsearch.client.Client;
Expand Down Expand Up @@ -159,6 +160,10 @@ public void checkRemoteClusterLicenses(final List<String> clusterAliases, final
@Override
public void onResponse(final XPackInfoResponse xPackInfoResponse) {
final XPackInfoResponse.LicenseInfo licenseInfo = xPackInfoResponse.getLicenseInfo();
if (licenseInfo == null) {
listener.onFailure(new ResourceNotFoundException("license info is missing for cluster [" + clusterAlias.get() + "]"));
return;
}
if ((licenseInfo.getStatus() == LicenseStatus.ACTIVE) == false
|| predicate.test(License.OperationMode.resolve(licenseInfo.getMode())) == false) {
listener.onResponse(LicenseCheck.failure(new RemoteClusterLicenseInfo(clusterAlias.get(), licenseInfo)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.license;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -349,6 +350,41 @@ public void testBuildErrorMessageForInactiveLicense() {
equalTo("the license on cluster [expired-cluster] is not active"));
}

public void testCheckRemoteClusterLicencesNoLicenseMetadata() {
final ThreadPool threadPool = createMockThreadPool();
final Client client = createMockClient(threadPool);
doAnswer(invocationMock -> {
@SuppressWarnings("unchecked") ActionListener<XPackInfoResponse> listener =
(ActionListener<XPackInfoResponse>) invocationMock.getArguments()[2];
listener.onResponse(new XPackInfoResponse(null, null, null));
return null;
}).when(client).execute(same(XPackInfoAction.INSTANCE), any(), any());

final RemoteClusterLicenseChecker licenseChecker =
new RemoteClusterLicenseChecker(client, XPackLicenseState::isPlatinumOrTrialOperationMode);
final AtomicReference<Exception> exception = new AtomicReference<>();

licenseChecker.checkRemoteClusterLicenses(
Collections.singletonList("remote"),
doubleInvocationProtectingListener(new ActionListener<RemoteClusterLicenseChecker.LicenseCheck>() {

@Override
public void onResponse(final RemoteClusterLicenseChecker.LicenseCheck response) {
fail();
}

@Override
public void onFailure(final Exception e) {
exception.set(e);
}

}));

assertNotNull(exception.get());
assertThat(exception.get(), instanceOf(ResourceNotFoundException.class));
assertThat(exception.get().getMessage(), equalTo("license info is missing for cluster [remote]"));
}

private ActionListener<RemoteClusterLicenseChecker.LicenseCheck> doubleInvocationProtectingListener(
final ActionListener<RemoteClusterLicenseChecker.LicenseCheck> listener) {
final AtomicBoolean listenerInvoked = new AtomicBoolean();
Expand Down