Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

License removal leads back to a basic license #52407

Merged
merged 9 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -45,6 +45,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -353,17 +354,32 @@ protected ClusterStateUpdateResponse newResponse(boolean acknowledged) {
@Override
public ClusterState execute(ClusterState currentState) throws Exception {
MetaData metaData = currentState.metaData();
final LicensesMetaData currentLicenses = metaData.custom(LicensesMetaData.TYPE);
if (currentLicenses.getLicense() != LicensesMetaData.LICENSE_TOMBSTONE) {
final LicensesMetaData currentLicensesMetadata = metaData.custom(LicensesMetaData.TYPE);
final License currentLicense = LicensesMetaData.extractLicense(currentLicensesMetadata);
if (shouldRemove(currentLicense)) {
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
LicensesMetaData newMetadata = new LicensesMetaData(LicensesMetaData.LICENSE_TOMBSTONE,
currentLicenses.getMostRecentTrialVersion());
mdBuilder.putCustom(LicensesMetaData.TYPE, newMetadata);
License.Builder specBuilder = License.builder()
.uid(UUID.randomUUID().toString())
.issuedTo(clusterService.getClusterName().value())
.maxNodes(SELF_GENERATED_LICENSE_MAX_NODES)
.issueDate(clock.millis())
.type(License.LicenseType.BASIC)
.expiryDate(BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS);
License selfGeneratedLicense = SelfGeneratedLicense.create(specBuilder, currentState.nodes());
LicensesMetaData newLicensesMetadata = new LicensesMetaData(selfGeneratedLicense,
currentLicensesMetadata == null ? null : currentLicensesMetadata.getMostRecentTrialVersion());
mdBuilder.putCustom(LicensesMetaData.TYPE, newLicensesMetadata);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge this code and the duplicate from StartBasicClusterTask into a single generateNewBasicLicense() method?

return ClusterState.builder(currentState).metaData(mdBuilder).build();
} else {
return currentState;
}
}

private boolean shouldRemove(License license) {
return false == License.LicenseType.isBasic(license.type())
|| SELF_GENERATED_LICENSE_MAX_NODES != license.maxNodes()
|| BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS != license.expiryDate();
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;

@ClusterScope(scope = TEST, numDataNodes = 0, numClientNodes = 0, maxNumDataNodes = 0)
public class LicenseServiceClusterTests extends AbstractLicensesIntegrationTestCase {
Expand Down Expand Up @@ -73,14 +72,14 @@ public void testClusterRestartWithLicense() throws Exception {
assertThat(licensingClient.prepareGetLicense().get().license(), equalTo(license));
logger.info("--> remove licenses");
licensingClient.prepareDeleteLicense().get();
assertOperationMode(License.OperationMode.MISSING);
assertOperationMode(License.OperationMode.BASIC);

logger.info("--> restart all nodes");
internalCluster().fullRestart();
licensingClient = new LicensingClient(client());
ensureYellow();
assertThat(licensingClient.prepareGetLicense().get().license(), nullValue());
assertOperationMode(License.OperationMode.MISSING);
assertTrue(License.LicenseType.isBasic(licensingClient.prepareGetLicense().get().license().type()));
assertOperationMode(License.OperationMode.BASIC);


wipeAllLicenses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void testRemoveLicenses() throws Exception {
// remove signed licenses
removeAndAckSignedLicenses(licenseService);
licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
assertThat(licensesMetaData.getLicense(), equalTo(LicensesMetaData.LICENSE_TOMBSTONE));
assertTrue(License.LicenseType.isBasic(licensesMetaData.getLicense().type()));
}

private void removeAndAckSignedLicenses(final LicenseService licenseService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void testRemoveLicensesSimple() throws Exception {
assertThat(deleteLicenseResponse.isAcknowledged(), equalTo(true));
// get licenses (expected no licenses)
getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
assertNull(getLicenseResponse.license());
assertTrue(License.LicenseType.isBasic(getLicenseResponse.license().type()));
}

public void testLicenseIsRejectWhenStartDateLaterThanNow() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,23 @@ teardown:
- length: { license: 12 }
- match: { license.uid: "893361dc-9749-4997-93cb-802e3dofh7aa" }
---
"Should throw 404 after license deletion":
"Should revert back to basic license after license deletion":
- do:
license.delete: {}

- match: { acknowledged: true }

- do:
license.get: {}
catch: missing

- match: { license.type: "basic" }
- set: { license.uid: id }

- do: # delete an existing basic license is a no-op
license.delete: {}
- do:
license.get: {}
- match: { license.uid: $id}

---
"Should install a feature type license":
Expand Down